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,
646 gint *allocated_size);
648 static void gtk_widget_set_usize_internal (GtkWidget *widget,
651 GtkQueueResizeFlags flags);
653 static void gtk_widget_add_events_internal (GtkWidget *widget,
657 /* --- variables --- */
658 static gpointer gtk_widget_parent_class = NULL;
659 static guint widget_signals[LAST_SIGNAL] = { 0 };
660 static GtkStyle *gtk_default_style = NULL;
661 static guint composite_child_stack = 0;
662 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
663 static GParamSpecPool *style_property_spec_pool = NULL;
665 static GQuark quark_property_parser = 0;
666 static GQuark quark_aux_info = 0;
667 static GQuark quark_accel_path = 0;
668 static GQuark quark_accel_closures = 0;
669 static GQuark quark_event_mask = 0;
670 static GQuark quark_device_event_mask = 0;
671 static GQuark quark_extension_event_mode = 0;
672 static GQuark quark_parent_window = 0;
673 static GQuark quark_pointer_window = 0;
674 static GQuark quark_shape_info = 0;
675 static GQuark quark_input_shape_info = 0;
676 static GQuark quark_pango_context = 0;
677 static GQuark quark_rc_style = 0;
678 static GQuark quark_accessible_object = 0;
679 static GQuark quark_mnemonic_labels = 0;
680 static GQuark quark_tooltip_markup = 0;
681 static GQuark quark_has_tooltip = 0;
682 static GQuark quark_tooltip_window = 0;
683 static GQuark quark_visual = 0;
684 static GQuark quark_modifier_style = 0;
685 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
686 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
688 /* --- functions --- */
690 gtk_widget_get_type (void)
692 static GType widget_type = 0;
694 if (G_UNLIKELY (widget_type == 0))
696 const GTypeInfo widget_info =
698 sizeof (GtkWidgetClass),
699 NULL, /* base_init */
700 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
701 (GClassInitFunc) gtk_widget_class_init,
702 NULL, /* class_finalize */
703 NULL, /* class_init */
706 (GInstanceInitFunc) gtk_widget_init,
707 NULL, /* value_table */
710 const GInterfaceInfo accessibility_info =
712 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
713 (GInterfaceFinalizeFunc) NULL,
714 NULL /* interface data */
717 const GInterfaceInfo buildable_info =
719 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
720 (GInterfaceFinalizeFunc) NULL,
721 NULL /* interface data */
724 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
725 &widget_info, G_TYPE_FLAG_ABSTRACT);
727 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
728 &accessibility_info) ;
729 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
737 child_property_notify_dispatcher (GObject *object,
741 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
744 /* We guard against the draw signal callbacks modifying the state of the
745 * cairo context by surounding it with save/restore.
746 * Maybe we should also cairo_new_path() just to be sure?
749 gtk_widget_draw_marshaller (GClosure *closure,
750 GValue *return_value,
751 guint n_param_values,
752 const GValue *param_values,
753 gpointer invocation_hint,
754 gpointer marshal_data)
756 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
760 _gtk_marshal_BOOLEAN__BOXED (closure,
771 gtk_widget_class_init (GtkWidgetClass *klass)
773 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
774 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
775 GtkBindingSet *binding_set;
777 gtk_widget_parent_class = g_type_class_peek_parent (klass);
779 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
780 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
781 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
782 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
783 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
784 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
785 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
786 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
787 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
788 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
789 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
790 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
791 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
792 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
793 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
794 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
795 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
796 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
797 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
798 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
800 style_property_spec_pool = g_param_spec_pool_new (FALSE);
801 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
802 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
803 cpn_context.dispatcher = child_property_notify_dispatcher;
804 _gtk_widget_child_property_notify_context = &cpn_context;
806 gobject_class->dispose = gtk_widget_dispose;
807 gobject_class->finalize = gtk_widget_finalize;
808 gobject_class->set_property = gtk_widget_set_property;
809 gobject_class->get_property = gtk_widget_get_property;
811 klass->destroy = gtk_widget_real_destroy;
813 klass->activate_signal = 0;
814 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
815 klass->show = gtk_widget_real_show;
816 klass->show_all = gtk_widget_show;
817 klass->hide = gtk_widget_real_hide;
818 klass->map = gtk_widget_real_map;
819 klass->unmap = gtk_widget_real_unmap;
820 klass->realize = gtk_widget_real_realize;
821 klass->unrealize = gtk_widget_real_unrealize;
822 klass->size_allocate = gtk_widget_real_size_allocate;
823 klass->get_preferred_width = gtk_widget_real_get_width;
824 klass->get_preferred_height = gtk_widget_real_get_height;
825 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
826 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
827 klass->state_changed = NULL;
828 klass->parent_set = NULL;
829 klass->hierarchy_changed = NULL;
830 klass->style_set = gtk_widget_real_style_set;
831 klass->direction_changed = gtk_widget_real_direction_changed;
832 klass->grab_notify = NULL;
833 klass->child_notify = NULL;
835 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
836 klass->grab_focus = gtk_widget_real_grab_focus;
837 klass->focus = gtk_widget_real_focus;
838 klass->move_focus = gtk_widget_real_move_focus;
839 klass->keynav_failed = gtk_widget_real_keynav_failed;
841 klass->button_press_event = NULL;
842 klass->button_release_event = NULL;
843 klass->motion_notify_event = NULL;
844 klass->delete_event = NULL;
845 klass->destroy_event = NULL;
846 klass->key_press_event = gtk_widget_real_key_press_event;
847 klass->key_release_event = gtk_widget_real_key_release_event;
848 klass->enter_notify_event = NULL;
849 klass->leave_notify_event = NULL;
850 klass->configure_event = NULL;
851 klass->focus_in_event = gtk_widget_real_focus_in_event;
852 klass->focus_out_event = gtk_widget_real_focus_out_event;
853 klass->map_event = NULL;
854 klass->unmap_event = NULL;
855 klass->window_state_event = NULL;
856 klass->property_notify_event = _gtk_selection_property_notify;
857 klass->selection_clear_event = _gtk_selection_clear;
858 klass->selection_request_event = _gtk_selection_request;
859 klass->selection_notify_event = _gtk_selection_notify;
860 klass->selection_received = NULL;
861 klass->proximity_in_event = NULL;
862 klass->proximity_out_event = NULL;
863 klass->drag_begin = NULL;
864 klass->drag_end = NULL;
865 klass->drag_data_delete = NULL;
866 klass->drag_leave = NULL;
867 klass->drag_motion = NULL;
868 klass->drag_drop = NULL;
869 klass->drag_data_received = NULL;
870 klass->screen_changed = NULL;
871 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
872 klass->grab_broken_event = NULL;
873 klass->query_tooltip = gtk_widget_real_query_tooltip;
874 klass->style_updated = gtk_widget_real_style_updated;
876 klass->show_help = gtk_widget_real_show_help;
878 /* Accessibility support */
879 klass->get_accessible = gtk_widget_real_get_accessible;
881 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
882 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
884 g_object_class_install_property (gobject_class,
886 g_param_spec_string ("name",
888 P_("The name of the widget"),
890 GTK_PARAM_READWRITE));
891 g_object_class_install_property (gobject_class,
893 g_param_spec_object ("parent",
895 P_("The parent widget of this widget. Must be a Container widget"),
897 GTK_PARAM_READWRITE));
899 g_object_class_install_property (gobject_class,
901 g_param_spec_int ("width-request",
903 P_("Override for width request of the widget, or -1 if natural request should be used"),
907 GTK_PARAM_READWRITE));
908 g_object_class_install_property (gobject_class,
910 g_param_spec_int ("height-request",
911 P_("Height request"),
912 P_("Override for height request of the widget, or -1 if natural request should be used"),
916 GTK_PARAM_READWRITE));
917 g_object_class_install_property (gobject_class,
919 g_param_spec_boolean ("visible",
921 P_("Whether the widget is visible"),
923 GTK_PARAM_READWRITE));
924 g_object_class_install_property (gobject_class,
926 g_param_spec_boolean ("sensitive",
928 P_("Whether the widget responds to input"),
930 GTK_PARAM_READWRITE));
931 g_object_class_install_property (gobject_class,
933 g_param_spec_boolean ("app-paintable",
934 P_("Application paintable"),
935 P_("Whether the application will paint directly on the widget"),
937 GTK_PARAM_READWRITE));
938 g_object_class_install_property (gobject_class,
940 g_param_spec_boolean ("can-focus",
942 P_("Whether the widget can accept the input focus"),
944 GTK_PARAM_READWRITE));
945 g_object_class_install_property (gobject_class,
947 g_param_spec_boolean ("has-focus",
949 P_("Whether the widget has the input focus"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_boolean ("is-focus",
956 P_("Whether the widget is the focus widget within the toplevel"),
958 GTK_PARAM_READWRITE));
959 g_object_class_install_property (gobject_class,
961 g_param_spec_boolean ("can-default",
963 P_("Whether the widget can be the default widget"),
965 GTK_PARAM_READWRITE));
966 g_object_class_install_property (gobject_class,
968 g_param_spec_boolean ("has-default",
970 P_("Whether the widget is the default widget"),
972 GTK_PARAM_READWRITE));
973 g_object_class_install_property (gobject_class,
974 PROP_RECEIVES_DEFAULT,
975 g_param_spec_boolean ("receives-default",
976 P_("Receives default"),
977 P_("If TRUE, the widget will receive the default action when it is focused"),
979 GTK_PARAM_READWRITE));
980 g_object_class_install_property (gobject_class,
981 PROP_COMPOSITE_CHILD,
982 g_param_spec_boolean ("composite-child",
983 P_("Composite child"),
984 P_("Whether the widget is part of a composite widget"),
986 GTK_PARAM_READABLE));
987 g_object_class_install_property (gobject_class,
989 g_param_spec_object ("style",
991 P_("The style of the widget, which contains information about how it will look (colors etc)"),
993 GTK_PARAM_READWRITE));
994 g_object_class_install_property (gobject_class,
996 g_param_spec_flags ("events",
998 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1001 GTK_PARAM_READWRITE));
1002 g_object_class_install_property (gobject_class,
1003 PROP_EXTENSION_EVENTS,
1004 g_param_spec_enum ("extension-events",
1005 P_("Extension events"),
1006 P_("The mask that decides what kind of extension events this widget gets"),
1007 GDK_TYPE_EXTENSION_MODE,
1008 GDK_EXTENSION_EVENTS_NONE,
1009 GTK_PARAM_READWRITE));
1010 g_object_class_install_property (gobject_class,
1012 g_param_spec_boolean ("no-show-all",
1014 P_("Whether gtk_widget_show_all() should not affect this widget"),
1016 GTK_PARAM_READWRITE));
1019 * GtkWidget:has-tooltip:
1021 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1022 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1023 * the widget will be queried using #GtkWidget::query-tooltip to determine
1024 * whether it will provide a tooltip or not.
1026 * Note that setting this property to %TRUE for the first time will change
1027 * the event masks of the GdkWindows of this widget to include leave-notify
1028 * and motion-notify events. This cannot and will not be undone when the
1029 * property is set to %FALSE again.
1033 g_object_class_install_property (gobject_class,
1035 g_param_spec_boolean ("has-tooltip",
1037 P_("Whether this widget has a tooltip"),
1039 GTK_PARAM_READWRITE));
1041 * GtkWidget:tooltip-text:
1043 * Sets the text of tooltip to be the given string.
1045 * Also see gtk_tooltip_set_text().
1047 * This is a convenience property which will take care of getting the
1048 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1049 * will automatically be set to %TRUE and there will be taken care of
1050 * #GtkWidget::query-tooltip in the default signal handler.
1054 g_object_class_install_property (gobject_class,
1056 g_param_spec_string ("tooltip-text",
1058 P_("The contents of the tooltip for this widget"),
1060 GTK_PARAM_READWRITE));
1062 * GtkWidget:tooltip-markup:
1064 * Sets the text of tooltip to be the given string, which is marked up
1065 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1066 * Also see gtk_tooltip_set_markup().
1068 * This is a convenience property which will take care of getting the
1069 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1070 * will automatically be set to %TRUE and there will be taken care of
1071 * #GtkWidget::query-tooltip in the default signal handler.
1075 g_object_class_install_property (gobject_class,
1076 PROP_TOOLTIP_MARKUP,
1077 g_param_spec_string ("tooltip-markup",
1078 P_("Tooltip markup"),
1079 P_("The contents of the tooltip for this widget"),
1081 GTK_PARAM_READWRITE));
1086 * The widget's window if it is realized, %NULL otherwise.
1090 g_object_class_install_property (gobject_class,
1092 g_param_spec_object ("window",
1094 P_("The widget's window if it is realized"),
1096 GTK_PARAM_READABLE));
1099 * GtkWidget:double-buffered
1101 * Whether the widget is double buffered.
1105 g_object_class_install_property (gobject_class,
1106 PROP_DOUBLE_BUFFERED,
1107 g_param_spec_boolean ("double-buffered",
1108 P_("Double Buffered"),
1109 P_("Whether the widget is double buffered"),
1111 GTK_PARAM_READWRITE));
1116 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1120 g_object_class_install_property (gobject_class,
1122 g_param_spec_enum ("halign",
1123 P_("Horizontal Alignment"),
1124 P_("How to position in extra horizontal space"),
1127 GTK_PARAM_READWRITE));
1132 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1136 g_object_class_install_property (gobject_class,
1138 g_param_spec_enum ("valign",
1139 P_("Vertical Alignment"),
1140 P_("How to position in extra vertical space"),
1143 GTK_PARAM_READWRITE));
1146 * GtkWidget:margin-left
1148 * Margin on left side of widget.
1150 * This property adds margin outside of the widget's normal size
1151 * request, the margin will be added in addition to the size from
1152 * gtk_widget_set_size_request() for example.
1156 g_object_class_install_property (gobject_class,
1158 g_param_spec_int ("margin-left",
1159 P_("Margin on Left"),
1160 P_("Pixels of extra space on the left side"),
1164 GTK_PARAM_READWRITE));
1167 * GtkWidget:margin-right
1169 * Margin on right side of widget.
1171 * This property adds margin outside of the widget's normal size
1172 * request, the margin will be added in addition to the size from
1173 * gtk_widget_set_size_request() for example.
1177 g_object_class_install_property (gobject_class,
1179 g_param_spec_int ("margin-right",
1180 P_("Margin on Right"),
1181 P_("Pixels of extra space on the right side"),
1185 GTK_PARAM_READWRITE));
1188 * GtkWidget:margin-top
1190 * Margin on top side of widget.
1192 * This property adds margin outside of the widget's normal size
1193 * request, the margin will be added in addition to the size from
1194 * gtk_widget_set_size_request() for example.
1198 g_object_class_install_property (gobject_class,
1200 g_param_spec_int ("margin-top",
1201 P_("Margin on Top"),
1202 P_("Pixels of extra space on the top side"),
1206 GTK_PARAM_READWRITE));
1209 * GtkWidget:margin-bottom
1211 * Margin on bottom side of widget.
1213 * This property adds margin outside of the widget's normal size
1214 * request, the margin will be added in addition to the size from
1215 * gtk_widget_set_size_request() for example.
1219 g_object_class_install_property (gobject_class,
1221 g_param_spec_int ("margin-bottom",
1222 P_("Margin on Bottom"),
1223 P_("Pixels of extra space on the bottom side"),
1227 GTK_PARAM_READWRITE));
1232 * Sets all four sides' margin at once. If read, returns max
1233 * margin on any side.
1237 g_object_class_install_property (gobject_class,
1239 g_param_spec_int ("margin",
1241 P_("Pixels of extra space on all four sides"),
1245 GTK_PARAM_READWRITE));
1248 * GtkWidget::destroy:
1249 * @object: the object which received the signal
1251 * Signals that all holders of a reference to the widget should release
1252 * the reference that they hold. May result in finalization of the widget
1253 * if all references are released.
1255 widget_signals[DESTROY] =
1256 g_signal_new (I_("destroy"),
1257 G_TYPE_FROM_CLASS (gobject_class),
1258 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1259 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1261 _gtk_marshal_VOID__VOID,
1267 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1271 g_object_class_install_property (gobject_class,
1273 g_param_spec_boolean ("hexpand",
1274 P_("Horizontal Expand"),
1275 P_("Whether widget wants more horizontal space"),
1277 GTK_PARAM_READWRITE));
1280 * GtkWidget:hexpand-set
1282 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1286 g_object_class_install_property (gobject_class,
1288 g_param_spec_boolean ("hexpand-set",
1289 P_("Horizontal Expand Set"),
1290 P_("Whether to use the hexpand property"),
1292 GTK_PARAM_READWRITE));
1297 * Whether to expand vertically. See gtk_widget_set_vexpand().
1301 g_object_class_install_property (gobject_class,
1303 g_param_spec_boolean ("vexpand",
1304 P_("Vertical Expand"),
1305 P_("Whether widget wants more vertical space"),
1307 GTK_PARAM_READWRITE));
1310 * GtkWidget:vexpand-set
1312 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1316 g_object_class_install_property (gobject_class,
1318 g_param_spec_boolean ("vexpand-set",
1319 P_("Vertical Expand Set"),
1320 P_("Whether to use the vexpand property"),
1322 GTK_PARAM_READWRITE));
1327 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1331 g_object_class_install_property (gobject_class,
1333 g_param_spec_boolean ("expand",
1335 P_("Whether widget wants to expand in both directions"),
1337 GTK_PARAM_READWRITE));
1341 * @widget: the object which received the signal.
1343 widget_signals[SHOW] =
1344 g_signal_new (I_("show"),
1345 G_TYPE_FROM_CLASS (gobject_class),
1347 G_STRUCT_OFFSET (GtkWidgetClass, show),
1349 _gtk_marshal_VOID__VOID,
1354 * @widget: the object which received the signal.
1356 widget_signals[HIDE] =
1357 g_signal_new (I_("hide"),
1358 G_TYPE_FROM_CLASS (gobject_class),
1360 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1362 _gtk_marshal_VOID__VOID,
1367 * @widget: the object which received the signal.
1369 widget_signals[MAP] =
1370 g_signal_new (I_("map"),
1371 G_TYPE_FROM_CLASS (gobject_class),
1373 G_STRUCT_OFFSET (GtkWidgetClass, map),
1375 _gtk_marshal_VOID__VOID,
1380 * @widget: the object which received the signal.
1382 widget_signals[UNMAP] =
1383 g_signal_new (I_("unmap"),
1384 G_TYPE_FROM_CLASS (gobject_class),
1386 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1388 _gtk_marshal_VOID__VOID,
1392 * GtkWidget::realize:
1393 * @widget: the object which received the signal.
1395 widget_signals[REALIZE] =
1396 g_signal_new (I_("realize"),
1397 G_TYPE_FROM_CLASS (gobject_class),
1399 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1401 _gtk_marshal_VOID__VOID,
1405 * GtkWidget::unrealize:
1406 * @widget: the object which received the signal.
1408 widget_signals[UNREALIZE] =
1409 g_signal_new (I_("unrealize"),
1410 G_TYPE_FROM_CLASS (gobject_class),
1412 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1414 _gtk_marshal_VOID__VOID,
1418 * GtkWidget::size-allocate:
1419 * @widget: the object which received the signal.
1422 widget_signals[SIZE_ALLOCATE] =
1423 g_signal_new (I_("size-allocate"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1428 _gtk_marshal_VOID__BOXED,
1430 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1433 * GtkWidget::state-changed:
1434 * @widget: the object which received the signal.
1435 * @state: the previous state
1437 * The ::state-changed signal is emitted when the widget state changes.
1438 * See gtk_widget_get_state().
1440 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1442 widget_signals[STATE_CHANGED] =
1443 g_signal_new (I_("state-changed"),
1444 G_TYPE_FROM_CLASS (gobject_class),
1446 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1448 _gtk_marshal_VOID__ENUM,
1450 GTK_TYPE_STATE_TYPE);
1453 * GtkWidget::state-flags-changed:
1454 * @widget: the object which received the signal.
1455 * @flags: The previous state flags.
1457 * The ::state-flags-changed signal is emitted when the widget state
1458 * changes, see gtk_widget_get_state_flags().
1462 widget_signals[STATE_FLAGS_CHANGED] =
1463 g_signal_new (I_("state-flags-changed"),
1464 G_TYPE_FROM_CLASS (gobject_class),
1466 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1468 _gtk_marshal_VOID__FLAGS,
1470 GTK_TYPE_STATE_FLAGS);
1473 * GtkWidget::parent-set:
1474 * @widget: the object on which the signal is emitted
1475 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1476 * just got its initial parent.
1478 * The ::parent-set signal is emitted when a new parent
1479 * has been set on a widget.
1481 widget_signals[PARENT_SET] =
1482 g_signal_new (I_("parent-set"),
1483 G_TYPE_FROM_CLASS (gobject_class),
1485 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1487 _gtk_marshal_VOID__OBJECT,
1492 * GtkWidget::hierarchy-changed:
1493 * @widget: the object on which the signal is emitted
1494 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1495 * if the widget was previously unanchored
1497 * The ::hierarchy-changed signal is emitted when the
1498 * anchored state of a widget changes. A widget is
1499 * <firstterm>anchored</firstterm> when its toplevel
1500 * ancestor is a #GtkWindow. This signal is emitted when
1501 * a widget changes from un-anchored to anchored or vice-versa.
1503 widget_signals[HIERARCHY_CHANGED] =
1504 g_signal_new (I_("hierarchy-changed"),
1505 G_TYPE_FROM_CLASS (gobject_class),
1507 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1509 _gtk_marshal_VOID__OBJECT,
1514 * GtkWidget::style-set:
1515 * @widget: the object on which the signal is emitted
1516 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1517 * just got its initial style
1519 * The ::style-set signal is emitted when a new style has been set
1520 * on a widget. Note that style-modifying functions like
1521 * gtk_widget_modify_base() also cause this signal to be emitted.
1523 widget_signals[STYLE_SET] =
1524 g_signal_new (I_("style-set"),
1525 G_TYPE_FROM_CLASS (gobject_class),
1527 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1529 _gtk_marshal_VOID__OBJECT,
1533 widget_signals[STYLE_UPDATED] =
1534 g_signal_new (I_("style-updated"),
1535 G_TYPE_FROM_CLASS (gobject_class),
1537 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1539 g_cclosure_marshal_VOID__VOID,
1543 * GtkWidget::direction-changed:
1544 * @widget: the object on which the signal is emitted
1545 * @previous_direction: the previous text direction of @widget
1547 * The ::direction-changed signal is emitted when the text direction
1548 * of a widget changes.
1550 widget_signals[DIRECTION_CHANGED] =
1551 g_signal_new (I_("direction-changed"),
1552 G_TYPE_FROM_CLASS (gobject_class),
1554 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1556 _gtk_marshal_VOID__ENUM,
1558 GTK_TYPE_TEXT_DIRECTION);
1561 * GtkWidget::grab-notify:
1562 * @widget: the object which received the signal
1563 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1564 * if it becomes unshadowed
1566 * The ::grab-notify signal is emitted when a widget becomes
1567 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1568 * another widget, or when it becomes unshadowed due to a grab
1571 * A widget is shadowed by a gtk_grab_add() when the topmost
1572 * grab widget in the grab stack of its window group is not
1575 widget_signals[GRAB_NOTIFY] =
1576 g_signal_new (I_("grab-notify"),
1577 G_TYPE_FROM_CLASS (gobject_class),
1579 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1581 _gtk_marshal_VOID__BOOLEAN,
1586 * GtkWidget::child-notify:
1587 * @widget: the object which received the signal
1588 * @pspec: the #GParamSpec of the changed child property
1590 * The ::child-notify signal is emitted for each
1591 * <link linkend="child-properties">child property</link> that has
1592 * changed on an object. The signal's detail holds the property name.
1594 widget_signals[CHILD_NOTIFY] =
1595 g_signal_new (I_("child-notify"),
1596 G_TYPE_FROM_CLASS (gobject_class),
1597 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1598 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1600 g_cclosure_marshal_VOID__PARAM,
1606 * @widget: the object which received the signal
1607 * @cr: the cairo context to draw to
1609 * This signal is emitted when a widget is supposed to render itself.
1610 * The @widget's top left corner must be painted at the origin of
1611 * the passed in context and be sized to the values returned by
1612 * gtk_widget_get_allocated_width() and
1613 * gtk_widget_get_allocated_height().
1615 * Signal handlers connected to this signal can modify the cairo
1616 * context passed as @cr in any way they like and don't need to
1617 * restore it. The signal emission takes care of calling cairo_save()
1618 * before and cairo_restore() after invoking the handler.
1620 widget_signals[DRAW] =
1621 g_signal_new (I_("draw"),
1622 G_TYPE_FROM_CLASS (gobject_class),
1624 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1625 _gtk_boolean_handled_accumulator, NULL,
1626 gtk_widget_draw_marshaller,
1628 CAIRO_GOBJECT_TYPE_CONTEXT);
1631 * GtkWidget::mnemonic-activate:
1632 * @widget: the object which received the signal.
1635 widget_signals[MNEMONIC_ACTIVATE] =
1636 g_signal_new (I_("mnemonic-activate"),
1637 G_TYPE_FROM_CLASS (gobject_class),
1639 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1640 _gtk_boolean_handled_accumulator, NULL,
1641 _gtk_marshal_BOOLEAN__BOOLEAN,
1646 * GtkWidget::grab-focus:
1647 * @widget: the object which received the signal.
1649 widget_signals[GRAB_FOCUS] =
1650 g_signal_new (I_("grab-focus"),
1651 G_TYPE_FROM_CLASS (gobject_class),
1652 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1653 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1655 _gtk_marshal_VOID__VOID,
1660 * @widget: the object which received the signal.
1663 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1665 widget_signals[FOCUS] =
1666 g_signal_new (I_("focus"),
1667 G_TYPE_FROM_CLASS (klass),
1669 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1670 _gtk_boolean_handled_accumulator, NULL,
1671 _gtk_marshal_BOOLEAN__ENUM,
1673 GTK_TYPE_DIRECTION_TYPE);
1676 * GtkWidget::move-focus:
1677 * @widget: the object which received the signal.
1680 widget_signals[MOVE_FOCUS] =
1681 g_signal_new (I_("move-focus"),
1682 G_TYPE_FROM_CLASS (klass),
1683 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1684 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1686 _gtk_marshal_VOID__ENUM,
1689 GTK_TYPE_DIRECTION_TYPE);
1692 * GtkWidget::keynav-failed:
1693 * @widget: the object which received the signal
1694 * @direction: the direction of movement
1696 * Gets emitted if keyboard navigation fails.
1697 * See gtk_widget_keynav_failed() for details.
1699 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1700 * if the emitting widget should try to handle the keyboard
1701 * navigation attempt in its parent container(s).
1705 widget_signals[KEYNAV_FAILED] =
1706 g_signal_new (I_("keynav-failed"),
1707 G_TYPE_FROM_CLASS (klass),
1709 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1710 _gtk_boolean_handled_accumulator, NULL,
1711 _gtk_marshal_BOOLEAN__ENUM,
1713 GTK_TYPE_DIRECTION_TYPE);
1717 * @widget: the object which received the signal.
1718 * @event: the #GdkEvent which triggered this signal
1720 * The GTK+ main loop will emit three signals for each GDK event delivered
1721 * to a widget: one generic ::event signal, another, more specific,
1722 * signal that matches the type of event delivered (e.g.
1723 * #GtkWidget::key-press-event) and finally a generic
1724 * #GtkWidget::event-after signal.
1726 * Returns: %TRUE to stop other handlers from being invoked for the event
1727 * and to cancel the emission of the second specific ::event signal.
1728 * %FALSE to propagate the event further and to allow the emission of
1729 * the second signal. The ::event-after signal is emitted regardless of
1732 widget_signals[EVENT] =
1733 g_signal_new (I_("event"),
1734 G_TYPE_FROM_CLASS (klass),
1736 G_STRUCT_OFFSET (GtkWidgetClass, event),
1737 _gtk_boolean_handled_accumulator, NULL,
1738 _gtk_marshal_BOOLEAN__BOXED,
1740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1743 * GtkWidget::event-after:
1744 * @widget: the object which received the signal.
1745 * @event: the #GdkEvent which triggered this signal
1747 * After the emission of the #GtkWidget::event signal and (optionally)
1748 * the second more specific signal, ::event-after will be emitted
1749 * regardless of the previous two signals handlers return values.
1752 widget_signals[EVENT_AFTER] =
1753 g_signal_new (I_("event-after"),
1754 G_TYPE_FROM_CLASS (klass),
1758 _gtk_marshal_VOID__BOXED,
1760 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1763 * GtkWidget::button-press-event:
1764 * @widget: the object which received the signal.
1765 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1768 * The ::button-press-event signal will be emitted when a button
1769 * (typically from a mouse) is pressed.
1771 * To receive this signal, the #GdkWindow associated to the
1772 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1774 * This signal will be sent to the grab widget if there is one.
1776 * Returns: %TRUE to stop other handlers from being invoked for the event.
1777 * %FALSE to propagate the event further.
1779 widget_signals[BUTTON_PRESS_EVENT] =
1780 g_signal_new (I_("button-press-event"),
1781 G_TYPE_FROM_CLASS (klass),
1783 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1784 _gtk_boolean_handled_accumulator, NULL,
1785 _gtk_marshal_BOOLEAN__BOXED,
1787 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1790 * GtkWidget::button-release-event:
1791 * @widget: the object which received the signal.
1792 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1795 * The ::button-release-event signal will be emitted when a button
1796 * (typically from a mouse) is released.
1798 * To receive this signal, the #GdkWindow associated to the
1799 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1801 * This signal will be sent to the grab widget if there is one.
1803 * Returns: %TRUE to stop other handlers from being invoked for the event.
1804 * %FALSE to propagate the event further.
1806 widget_signals[BUTTON_RELEASE_EVENT] =
1807 g_signal_new (I_("button-release-event"),
1808 G_TYPE_FROM_CLASS (klass),
1810 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1811 _gtk_boolean_handled_accumulator, NULL,
1812 _gtk_marshal_BOOLEAN__BOXED,
1814 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1817 * GtkWidget::scroll-event:
1818 * @widget: the object which received the signal.
1819 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1822 * The ::scroll-event signal is emitted when a button in the 4 to 7
1823 * range is pressed. Wheel mice are usually configured to generate
1824 * button press events for buttons 4 and 5 when the wheel is turned.
1826 * To receive this signal, the #GdkWindow associated to the widget needs
1827 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1829 * This signal will be sent to the grab widget if there is one.
1831 * Returns: %TRUE to stop other handlers from being invoked for the event.
1832 * %FALSE to propagate the event further.
1834 widget_signals[SCROLL_EVENT] =
1835 g_signal_new (I_("scroll-event"),
1836 G_TYPE_FROM_CLASS (klass),
1838 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1839 _gtk_boolean_handled_accumulator, NULL,
1840 _gtk_marshal_BOOLEAN__BOXED,
1842 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1845 * GtkWidget::motion-notify-event:
1846 * @widget: the object which received the signal.
1847 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1850 * The ::motion-notify-event signal is emitted when the pointer moves
1851 * over the widget's #GdkWindow.
1853 * To receive this signal, the #GdkWindow associated to the widget
1854 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1856 * This signal will be sent to the grab widget if there is one.
1858 * Returns: %TRUE to stop other handlers from being invoked for the event.
1859 * %FALSE to propagate the event further.
1861 widget_signals[MOTION_NOTIFY_EVENT] =
1862 g_signal_new (I_("motion-notify-event"),
1863 G_TYPE_FROM_CLASS (klass),
1865 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1866 _gtk_boolean_handled_accumulator, NULL,
1867 _gtk_marshal_BOOLEAN__BOXED,
1869 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1872 * GtkWidget::composited-changed:
1873 * @widget: the object on which the signal is emitted
1875 * The ::composited-changed signal is emitted when the composited
1876 * status of @widget<!-- -->s screen changes.
1877 * See gdk_screen_is_composited().
1879 widget_signals[COMPOSITED_CHANGED] =
1880 g_signal_new (I_("composited-changed"),
1881 G_TYPE_FROM_CLASS (klass),
1882 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1883 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1885 _gtk_marshal_VOID__VOID,
1889 * GtkWidget::delete-event:
1890 * @widget: the object which received the signal
1891 * @event: the event which triggered this signal
1893 * The ::delete-event signal is emitted if a user requests that
1894 * a toplevel window is closed. The default handler for this signal
1895 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1896 * this signal will cause the window to be hidden instead, so that
1897 * it can later be shown again without reconstructing it.
1899 * Returns: %TRUE to stop other handlers from being invoked for the event.
1900 * %FALSE to propagate the event further.
1902 widget_signals[DELETE_EVENT] =
1903 g_signal_new (I_("delete-event"),
1904 G_TYPE_FROM_CLASS (klass),
1906 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1907 _gtk_boolean_handled_accumulator, NULL,
1908 _gtk_marshal_BOOLEAN__BOXED,
1910 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1913 * GtkWidget::destroy-event:
1914 * @widget: the object which received the signal.
1915 * @event: the event which triggered this signal
1917 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1918 * You rarely get this signal, because most widgets disconnect themselves
1919 * from their window before they destroy it, so no widget owns the
1920 * window at destroy time.
1922 * To receive this signal, the #GdkWindow associated to the widget needs
1923 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1924 * automatically for all new windows.
1926 * Returns: %TRUE to stop other handlers from being invoked for the event.
1927 * %FALSE to propagate the event further.
1929 widget_signals[DESTROY_EVENT] =
1930 g_signal_new (I_("destroy-event"),
1931 G_TYPE_FROM_CLASS (klass),
1933 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1934 _gtk_boolean_handled_accumulator, NULL,
1935 _gtk_marshal_BOOLEAN__BOXED,
1937 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1940 * GtkWidget::key-press-event:
1941 * @widget: the object which received the signal
1942 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1944 * The ::key-press-event signal is emitted when a key is pressed.
1946 * To receive this signal, the #GdkWindow associated to the widget needs
1947 * to enable the #GDK_KEY_PRESS_MASK mask.
1949 * This signal will be sent to the grab widget if there is one.
1951 * Returns: %TRUE to stop other handlers from being invoked for the event.
1952 * %FALSE to propagate the event further.
1954 widget_signals[KEY_PRESS_EVENT] =
1955 g_signal_new (I_("key-press-event"),
1956 G_TYPE_FROM_CLASS (klass),
1958 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::key-release-event:
1966 * @widget: the object which received the signal
1967 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1969 * The ::key-release-event signal is emitted when a key is pressed.
1971 * To receive this signal, the #GdkWindow associated to the widget needs
1972 * to enable the #GDK_KEY_RELEASE_MASK mask.
1974 * This signal will be sent to the grab widget if there is one.
1976 * Returns: %TRUE to stop other handlers from being invoked for the event.
1977 * %FALSE to propagate the event further.
1979 widget_signals[KEY_RELEASE_EVENT] =
1980 g_signal_new (I_("key-release-event"),
1981 G_TYPE_FROM_CLASS (klass),
1983 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1984 _gtk_boolean_handled_accumulator, NULL,
1985 _gtk_marshal_BOOLEAN__BOXED,
1987 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1990 * GtkWidget::enter-notify-event:
1991 * @widget: the object which received the signal
1992 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1995 * The ::enter-notify-event will be emitted when the pointer enters
1996 * the @widget's window.
1998 * To receive this signal, the #GdkWindow associated to the widget needs
1999 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2001 * This signal will be sent to the grab widget if there is one.
2003 * Returns: %TRUE to stop other handlers from being invoked for the event.
2004 * %FALSE to propagate the event further.
2006 widget_signals[ENTER_NOTIFY_EVENT] =
2007 g_signal_new (I_("enter-notify-event"),
2008 G_TYPE_FROM_CLASS (klass),
2010 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2011 _gtk_boolean_handled_accumulator, NULL,
2012 _gtk_marshal_BOOLEAN__BOXED,
2014 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2017 * GtkWidget::leave-notify-event:
2018 * @widget: the object which received the signal
2019 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2022 * The ::leave-notify-event will be emitted when the pointer leaves
2023 * the @widget's window.
2025 * To receive this signal, the #GdkWindow associated to the widget needs
2026 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2028 * This signal will be sent to the grab widget if there is one.
2030 * Returns: %TRUE to stop other handlers from being invoked for the event.
2031 * %FALSE to propagate the event further.
2033 widget_signals[LEAVE_NOTIFY_EVENT] =
2034 g_signal_new (I_("leave-notify-event"),
2035 G_TYPE_FROM_CLASS (klass),
2037 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2038 _gtk_boolean_handled_accumulator, NULL,
2039 _gtk_marshal_BOOLEAN__BOXED,
2041 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2044 * GtkWidget::configure-event:
2045 * @widget: the object which received the signal
2046 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2049 * The ::configure-event signal will be emitted when the size, position or
2050 * stacking of the @widget's window has changed.
2052 * To receive this signal, the #GdkWindow associated to the widget needs
2053 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2054 * automatically for all new windows.
2056 * Returns: %TRUE to stop other handlers from being invoked for the event.
2057 * %FALSE to propagate the event further.
2059 widget_signals[CONFIGURE_EVENT] =
2060 g_signal_new (I_("configure-event"),
2061 G_TYPE_FROM_CLASS (klass),
2063 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2064 _gtk_boolean_handled_accumulator, NULL,
2065 _gtk_marshal_BOOLEAN__BOXED,
2067 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2070 * GtkWidget::focus-in-event:
2071 * @widget: the object which received the signal
2072 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2075 * The ::focus-in-event signal will be emitted when the keyboard focus
2076 * enters the @widget's window.
2078 * To receive this signal, the #GdkWindow associated to the widget needs
2079 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2081 * Returns: %TRUE to stop other handlers from being invoked for the event.
2082 * %FALSE to propagate the event further.
2084 widget_signals[FOCUS_IN_EVENT] =
2085 g_signal_new (I_("focus-in-event"),
2086 G_TYPE_FROM_CLASS (klass),
2088 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2089 _gtk_boolean_handled_accumulator, NULL,
2090 _gtk_marshal_BOOLEAN__BOXED,
2092 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2095 * GtkWidget::focus-out-event:
2096 * @widget: the object which received the signal
2097 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2100 * The ::focus-out-event signal will be emitted when the keyboard focus
2101 * leaves the @widget's window.
2103 * To receive this signal, the #GdkWindow associated to the widget needs
2104 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2106 * Returns: %TRUE to stop other handlers from being invoked for the event.
2107 * %FALSE to propagate the event further.
2109 widget_signals[FOCUS_OUT_EVENT] =
2110 g_signal_new (I_("focus-out-event"),
2111 G_TYPE_FROM_CLASS (klass),
2113 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2114 _gtk_boolean_handled_accumulator, NULL,
2115 _gtk_marshal_BOOLEAN__BOXED,
2117 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2120 * GtkWidget::map-event:
2121 * @widget: the object which received the signal
2122 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2124 * The ::map-event signal will be emitted when the @widget's window is
2125 * mapped. A window is mapped when it becomes visible on the screen.
2127 * To receive this signal, the #GdkWindow associated to the widget needs
2128 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2129 * automatically for all new windows.
2131 * Returns: %TRUE to stop other handlers from being invoked for the event.
2132 * %FALSE to propagate the event further.
2134 widget_signals[MAP_EVENT] =
2135 g_signal_new (I_("map-event"),
2136 G_TYPE_FROM_CLASS (klass),
2138 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2139 _gtk_boolean_handled_accumulator, NULL,
2140 _gtk_marshal_BOOLEAN__BOXED,
2142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2145 * GtkWidget::unmap-event:
2146 * @widget: the object which received the signal
2147 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2149 * The ::unmap-event signal may be emitted when the @widget's window is
2150 * unmapped. A window is unmapped when it becomes invisible on the screen.
2152 * For performance reasons GTK+ may not emit ::unmap-event, so one
2153 * should always also implement ::unrealize in order to release
2154 * resources and disconnect signal handlers.
2156 * To receive this signal, the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2158 * automatically for all new windows.
2160 * Returns: %TRUE to stop other handlers from being invoked for the event.
2161 * %FALSE to propagate the event further.
2163 widget_signals[UNMAP_EVENT] =
2164 g_signal_new (I_("unmap-event"),
2165 G_TYPE_FROM_CLASS (klass),
2167 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2174 * GtkWidget::property-notify-event:
2175 * @widget: the object which received the signal
2176 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2179 * The ::property-notify-event signal will be emitted when a property on
2180 * the @widget's window has been changed or deleted.
2182 * To receive this signal, the #GdkWindow associated to the widget needs
2183 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2185 * Returns: %TRUE to stop other handlers from being invoked for the event.
2186 * %FALSE to propagate the event further.
2188 widget_signals[PROPERTY_NOTIFY_EVENT] =
2189 g_signal_new (I_("property-notify-event"),
2190 G_TYPE_FROM_CLASS (klass),
2192 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2199 * GtkWidget::selection-clear-event:
2200 * @widget: the object which received the signal
2201 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2204 * The ::selection-clear-event signal will be emitted when the
2205 * the @widget's window has lost ownership of a selection.
2207 * Returns: %TRUE to stop other handlers from being invoked for the event.
2208 * %FALSE to propagate the event further.
2210 widget_signals[SELECTION_CLEAR_EVENT] =
2211 g_signal_new (I_("selection-clear-event"),
2212 G_TYPE_FROM_CLASS (klass),
2214 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2215 _gtk_boolean_handled_accumulator, NULL,
2216 _gtk_marshal_BOOLEAN__BOXED,
2218 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2221 * GtkWidget::selection-request-event:
2222 * @widget: the object which received the signal
2223 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2226 * The ::selection-request-event signal will be emitted when
2227 * another client requests ownership of the selection owned by
2228 * the @widget's window.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[SELECTION_REQUEST_EVENT] =
2234 g_signal_new (I_("selection-request-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2244 * GtkWidget::selection-notify-event:
2245 * @widget: the object which received the signal.
2248 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2250 widget_signals[SELECTION_NOTIFY_EVENT] =
2251 g_signal_new (I_("selection-notify-event"),
2252 G_TYPE_FROM_CLASS (klass),
2254 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2255 _gtk_boolean_handled_accumulator, NULL,
2256 _gtk_marshal_BOOLEAN__BOXED,
2258 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2261 * GtkWidget::selection-received:
2262 * @widget: the object which received the signal.
2266 widget_signals[SELECTION_RECEIVED] =
2267 g_signal_new (I_("selection-received"),
2268 G_TYPE_FROM_CLASS (klass),
2270 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2272 _gtk_marshal_VOID__BOXED_UINT,
2274 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2278 * GtkWidget::selection-get:
2279 * @widget: the object which received the signal.
2284 widget_signals[SELECTION_GET] =
2285 g_signal_new (I_("selection-get"),
2286 G_TYPE_FROM_CLASS (klass),
2288 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2290 _gtk_marshal_VOID__BOXED_UINT_UINT,
2292 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2297 * GtkWidget::proximity-in-event:
2298 * @widget: the object which received the signal
2299 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2302 * To receive this signal the #GdkWindow associated to the widget needs
2303 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2305 * This signal will be sent to the grab widget if there is one.
2307 * Returns: %TRUE to stop other handlers from being invoked for the event.
2308 * %FALSE to propagate the event further.
2310 widget_signals[PROXIMITY_IN_EVENT] =
2311 g_signal_new (I_("proximity-in-event"),
2312 G_TYPE_FROM_CLASS (klass),
2314 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2315 _gtk_boolean_handled_accumulator, NULL,
2316 _gtk_marshal_BOOLEAN__BOXED,
2318 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2321 * GtkWidget::proximity-out-event:
2322 * @widget: the object which received the signal
2323 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2326 * To receive this signal the #GdkWindow associated to the widget needs
2327 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2329 * This signal will be sent to the grab widget if there is one.
2331 * Returns: %TRUE to stop other handlers from being invoked for the event.
2332 * %FALSE to propagate the event further.
2334 widget_signals[PROXIMITY_OUT_EVENT] =
2335 g_signal_new (I_("proximity-out-event"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2339 _gtk_boolean_handled_accumulator, NULL,
2340 _gtk_marshal_BOOLEAN__BOXED,
2342 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2345 * GtkWidget::drag-leave:
2346 * @widget: the object which received the signal.
2347 * @drag_context: the drag context
2348 * @time: the timestamp of the motion event
2350 * The ::drag-leave signal is emitted on the drop site when the cursor
2351 * leaves the widget. A typical reason to connect to this signal is to
2352 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2353 * with gtk_drag_unhighlight()
2355 widget_signals[DRAG_LEAVE] =
2356 g_signal_new (I_("drag-leave"),
2357 G_TYPE_FROM_CLASS (klass),
2359 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2361 _gtk_marshal_VOID__OBJECT_UINT,
2363 GDK_TYPE_DRAG_CONTEXT,
2367 * GtkWidget::drag-begin:
2368 * @widget: the object which received the signal
2369 * @drag_context: the drag context
2371 * The ::drag-begin signal is emitted on the drag source when a drag is
2372 * started. A typical reason to connect to this signal is to set up a
2373 * custom drag icon with gtk_drag_source_set_icon().
2375 * Note that some widgets set up a drag icon in the default handler of
2376 * this signal, so you may have to use g_signal_connect_after() to
2377 * override what the default handler did.
2379 widget_signals[DRAG_BEGIN] =
2380 g_signal_new (I_("drag-begin"),
2381 G_TYPE_FROM_CLASS (klass),
2383 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2385 _gtk_marshal_VOID__OBJECT,
2387 GDK_TYPE_DRAG_CONTEXT);
2390 * GtkWidget::drag-end:
2391 * @widget: the object which received the signal
2392 * @drag_context: the drag context
2394 * The ::drag-end signal is emitted on the drag source when a drag is
2395 * finished. A typical reason to connect to this signal is to undo
2396 * things done in #GtkWidget::drag-begin.
2398 widget_signals[DRAG_END] =
2399 g_signal_new (I_("drag-end"),
2400 G_TYPE_FROM_CLASS (klass),
2402 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2404 _gtk_marshal_VOID__OBJECT,
2406 GDK_TYPE_DRAG_CONTEXT);
2409 * GtkWidget::drag-data-delete:
2410 * @widget: the object which received the signal
2411 * @drag_context: the drag context
2413 * The ::drag-data-delete signal is emitted on the drag source when a drag
2414 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2415 * handler is responsible for deleting the data that has been dropped. What
2416 * "delete" means depends on the context of the drag operation.
2418 widget_signals[DRAG_DATA_DELETE] =
2419 g_signal_new (I_("drag-data-delete"),
2420 G_TYPE_FROM_CLASS (klass),
2422 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2424 _gtk_marshal_VOID__OBJECT,
2426 GDK_TYPE_DRAG_CONTEXT);
2429 * GtkWidget::drag-failed:
2430 * @widget: the object which received the signal
2431 * @drag_context: the drag context
2432 * @result: the result of the drag operation
2434 * The ::drag-failed signal is emitted on the drag source when a drag has
2435 * failed. The signal handler may hook custom code to handle a failed DND
2436 * operation based on the type of error, it returns %TRUE is the failure has
2437 * been already handled (not showing the default "drag operation failed"
2438 * animation), otherwise it returns %FALSE.
2440 * Return value: %TRUE if the failed drag operation has been already handled.
2444 widget_signals[DRAG_FAILED] =
2445 g_signal_new (I_("drag-failed"),
2446 G_TYPE_FROM_CLASS (klass),
2448 0, _gtk_boolean_handled_accumulator, NULL,
2449 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2451 GDK_TYPE_DRAG_CONTEXT,
2452 GTK_TYPE_DRAG_RESULT);
2455 * GtkWidget::drag-motion:
2456 * @widget: the object which received the signal
2457 * @drag_context: the drag context
2458 * @x: the x coordinate of the current cursor position
2459 * @y: the y coordinate of the current cursor position
2460 * @time: the timestamp of the motion event
2461 * @returns: whether the cursor position is in a drop zone
2463 * The drag-motion signal is emitted on the drop site when the user
2464 * moves the cursor over the widget during a drag. The signal handler
2465 * must determine whether the cursor position is in a drop zone or not.
2466 * If it is not in a drop zone, it returns %FALSE and no further processing
2467 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2468 * handler is responsible for providing the necessary information for
2469 * displaying feedback to the user, by calling gdk_drag_status().
2471 * If the decision whether the drop will be accepted or rejected can't be
2472 * made based solely on the cursor position and the type of the data, the
2473 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2474 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2475 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2476 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2477 * when using the drag-motion signal that way.
2479 * Also note that there is no drag-enter signal. The drag receiver has to
2480 * keep track of whether he has received any drag-motion signals since the
2481 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2482 * an "enter" signal. Upon an "enter", the handler will typically highlight
2483 * the drop site with gtk_drag_highlight().
2486 * drag_motion (GtkWidget *widget,
2487 * GdkDragContext *context,
2494 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2496 * if (!private_data->drag_highlight)
2498 * private_data->drag_highlight = 1;
2499 * gtk_drag_highlight (widget);
2502 * target = gtk_drag_dest_find_target (widget, context, NULL);
2503 * if (target == GDK_NONE)
2504 * gdk_drag_status (context, 0, time);
2507 * private_data->pending_status = context->suggested_action;
2508 * gtk_drag_get_data (widget, context, target, time);
2515 * drag_data_received (GtkWidget *widget,
2516 * GdkDragContext *context,
2519 * GtkSelectionData *selection_data,
2523 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2525 * if (private_data->suggested_action)
2527 * private_data->suggested_action = 0;
2529 * /* We are getting this data due to a request in drag_motion,
2530 * * rather than due to a request in drag_drop, so we are just
2531 * * supposed to call gdk_drag_status (), not actually paste in
2534 * str = gtk_selection_data_get_text (selection_data);
2535 * if (!data_is_acceptable (str))
2536 * gdk_drag_status (context, 0, time);
2538 * gdk_drag_status (context, private_data->suggested_action, time);
2542 * /* accept the drop */
2547 widget_signals[DRAG_MOTION] =
2548 g_signal_new (I_("drag-motion"),
2549 G_TYPE_FROM_CLASS (klass),
2551 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2552 _gtk_boolean_handled_accumulator, NULL,
2553 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2555 GDK_TYPE_DRAG_CONTEXT,
2561 * GtkWidget::drag-drop:
2562 * @widget: the object which received the signal
2563 * @drag_context: the drag context
2564 * @x: the x coordinate of the current cursor position
2565 * @y: the y coordinate of the current cursor position
2566 * @time: the timestamp of the motion event
2567 * @returns: whether the cursor position is in a drop zone
2569 * The ::drag-drop signal is emitted on the drop site when the user drops
2570 * the data onto the widget. The signal handler must determine whether
2571 * the cursor position is in a drop zone or not. If it is not in a drop
2572 * zone, it returns %FALSE and no further processing is necessary.
2573 * Otherwise, the handler returns %TRUE. In this case, the handler must
2574 * ensure that gtk_drag_finish() is called to let the source know that
2575 * the drop is done. The call to gtk_drag_finish() can be done either
2576 * directly or in a #GtkWidget::drag-data-received handler which gets
2577 * triggered by calling gtk_drag_get_data() to receive the data for one
2578 * or more of the supported targets.
2580 widget_signals[DRAG_DROP] =
2581 g_signal_new (I_("drag-drop"),
2582 G_TYPE_FROM_CLASS (klass),
2584 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2585 _gtk_boolean_handled_accumulator, NULL,
2586 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2588 GDK_TYPE_DRAG_CONTEXT,
2594 * GtkWidget::drag-data-get:
2595 * @widget: the object which received the signal
2596 * @drag_context: the drag context
2597 * @data: the #GtkSelectionData to be filled with the dragged data
2598 * @info: the info that has been registered with the target in the
2600 * @time: the timestamp at which the data was requested
2602 * The ::drag-data-get signal is emitted on the drag source when the drop
2603 * site requests the data which is dragged. It is the responsibility of
2604 * the signal handler to fill @data with the data in the format which
2605 * is indicated by @info. See gtk_selection_data_set() and
2606 * gtk_selection_data_set_text().
2608 widget_signals[DRAG_DATA_GET] =
2609 g_signal_new (I_("drag-data-get"),
2610 G_TYPE_FROM_CLASS (klass),
2612 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2614 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2616 GDK_TYPE_DRAG_CONTEXT,
2617 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2622 * GtkWidget::drag-data-received:
2623 * @widget: the object which received the signal
2624 * @drag_context: the drag context
2625 * @x: where the drop happened
2626 * @y: where the drop happened
2627 * @data: the received data
2628 * @info: the info that has been registered with the target in the
2630 * @time: the timestamp at which the data was received
2632 * The ::drag-data-received signal is emitted on the drop site when the
2633 * dragged data has been received. If the data was received in order to
2634 * determine whether the drop will be accepted, the handler is expected
2635 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2636 * If the data was received in response to a #GtkWidget::drag-drop signal
2637 * (and this is the last target to be received), the handler for this
2638 * signal is expected to process the received data and then call
2639 * gtk_drag_finish(), setting the @success parameter depending on whether
2640 * the data was processed successfully.
2642 * The handler may inspect and modify @drag_context->action before calling
2643 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2644 * following example:
2647 * drag_data_received (GtkWidget *widget,
2648 * GdkDragContext *drag_context,
2651 * GtkSelectionData *data,
2655 * if ((data->length >= 0) && (data->format == 8))
2657 * if (drag_context->action == GDK_ACTION_ASK)
2659 * GtkWidget *dialog;
2662 * dialog = gtk_message_dialog_new (NULL,
2663 * GTK_DIALOG_MODAL |
2664 * GTK_DIALOG_DESTROY_WITH_PARENT,
2666 * GTK_BUTTONS_YES_NO,
2667 * "Move the data ?\n");
2668 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2669 * gtk_widget_destroy (dialog);
2671 * if (response == GTK_RESPONSE_YES)
2672 * drag_context->action = GDK_ACTION_MOVE;
2674 * drag_context->action = GDK_ACTION_COPY;
2677 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2681 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2685 widget_signals[DRAG_DATA_RECEIVED] =
2686 g_signal_new (I_("drag-data-received"),
2687 G_TYPE_FROM_CLASS (klass),
2689 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2691 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2693 GDK_TYPE_DRAG_CONTEXT,
2696 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2701 * GtkWidget::visibility-notify-event:
2702 * @widget: the object which received the signal
2703 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2704 * triggered this signal.
2706 * The ::visibility-notify-event will be emitted when the @widget's window
2707 * is obscured or unobscured.
2709 * To receive this signal the #GdkWindow associated to the widget needs
2710 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2712 * Returns: %TRUE to stop other handlers from being invoked for the event.
2713 * %FALSE to propagate the event further.
2715 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2716 g_signal_new (I_("visibility-notify-event"),
2717 G_TYPE_FROM_CLASS (klass),
2719 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2720 _gtk_boolean_handled_accumulator, NULL,
2721 _gtk_marshal_BOOLEAN__BOXED,
2723 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2726 * GtkWidget::client-event:
2727 * @widget: the object which received the signal
2728 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2731 * The ::client-event will be emitted when the @widget's window
2732 * receives a message (via a ClientMessage event) from another
2735 * Returns: %TRUE to stop other handlers from being invoked for
2736 * the event. %FALSE to propagate the event further.
2738 widget_signals[CLIENT_EVENT] =
2739 g_signal_new (I_("client-event"),
2740 G_TYPE_FROM_CLASS (klass),
2742 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2743 _gtk_boolean_handled_accumulator, NULL,
2744 _gtk_marshal_BOOLEAN__BOXED,
2746 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2749 * GtkWidget::window-state-event:
2750 * @widget: the object which received the signal
2751 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2752 * triggered this signal.
2754 * The ::window-state-event will be emitted when the state of the
2755 * toplevel window associated to the @widget changes.
2757 * To receive this signal the #GdkWindow associated to the widget
2758 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2759 * this mask automatically for all new windows.
2761 * Returns: %TRUE to stop other handlers from being invoked for the
2762 * event. %FALSE to propagate the event further.
2764 widget_signals[WINDOW_STATE_EVENT] =
2765 g_signal_new (I_("window-state-event"),
2766 G_TYPE_FROM_CLASS (klass),
2768 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2769 _gtk_boolean_handled_accumulator, NULL,
2770 _gtk_marshal_BOOLEAN__BOXED,
2772 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2775 * GtkWidget::damage-event:
2776 * @widget: the object which received the signal
2777 * @event: the #GdkEventExpose event
2779 * Emitted when a redirected window belonging to @widget gets drawn into.
2780 * The region/area members of the event shows what area of the redirected
2781 * drawable was drawn into.
2783 * Returns: %TRUE to stop other handlers from being invoked for the event.
2784 * %FALSE to propagate the event further.
2788 widget_signals[DAMAGE_EVENT] =
2789 g_signal_new (I_("damage-event"),
2790 G_TYPE_FROM_CLASS (klass),
2792 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2793 _gtk_boolean_handled_accumulator, NULL,
2794 _gtk_marshal_BOOLEAN__BOXED,
2796 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2799 * GtkWidget::grab-broken-event:
2800 * @widget: the object which received the signal
2801 * @event: the #GdkEventGrabBroken event
2803 * Emitted when a pointer or keyboard grab on a window belonging
2804 * to @widget gets broken.
2806 * On X11, this happens when the grab window becomes unviewable
2807 * (i.e. it or one of its ancestors is unmapped), or if the same
2808 * application grabs the pointer or keyboard again.
2810 * Returns: %TRUE to stop other handlers from being invoked for
2811 * the event. %FALSE to propagate the event further.
2815 widget_signals[GRAB_BROKEN_EVENT] =
2816 g_signal_new (I_("grab-broken-event"),
2817 G_TYPE_FROM_CLASS (klass),
2819 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2820 _gtk_boolean_handled_accumulator, NULL,
2821 _gtk_marshal_BOOLEAN__BOXED,
2823 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2826 * GtkWidget::query-tooltip:
2827 * @widget: the object which received the signal
2828 * @x: the x coordinate of the cursor position where the request has
2829 * been emitted, relative to @widget->window
2830 * @y: the y coordinate of the cursor position where the request has
2831 * been emitted, relative to @widget->window
2832 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2833 * @tooltip: a #GtkTooltip
2835 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2836 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2837 * focus in keyboard mode.
2839 * Using the given coordinates, the signal handler should determine
2840 * whether a tooltip should be shown for @widget. If this is the case
2841 * %TRUE should be returned, %FALSE otherwise. Note that if
2842 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2843 * should not be used.
2845 * The signal handler is free to manipulate @tooltip with the therefore
2846 * destined function calls.
2848 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2852 widget_signals[QUERY_TOOLTIP] =
2853 g_signal_new (I_("query-tooltip"),
2854 G_TYPE_FROM_CLASS (klass),
2856 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2857 _gtk_boolean_handled_accumulator, NULL,
2858 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2866 * GtkWidget::popup-menu
2867 * @widget: the object which received the signal
2869 * This signal gets emitted whenever a widget should pop up a context
2870 * menu. This usually happens through the standard key binding mechanism;
2871 * by pressing a certain key while a widget is focused, the user can cause
2872 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2873 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2874 * for an example of how to use this signal.
2876 * Returns: %TRUE if a menu was activated
2878 widget_signals[POPUP_MENU] =
2879 g_signal_new (I_("popup-menu"),
2880 G_TYPE_FROM_CLASS (klass),
2881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2882 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2883 _gtk_boolean_handled_accumulator, NULL,
2884 _gtk_marshal_BOOLEAN__VOID,
2888 * GtkWidget::show-help:
2889 * @widget: the object which received the signal.
2892 widget_signals[SHOW_HELP] =
2893 g_signal_new (I_("show-help"),
2894 G_TYPE_FROM_CLASS (klass),
2895 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2896 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2897 _gtk_boolean_handled_accumulator, NULL,
2898 _gtk_marshal_BOOLEAN__ENUM,
2900 GTK_TYPE_WIDGET_HELP_TYPE);
2903 * GtkWidget::accel-closures-changed:
2904 * @widget: the object which received the signal.
2906 widget_signals[ACCEL_CLOSURES_CHANGED] =
2907 g_signal_new (I_("accel-closures-changed"),
2908 G_TYPE_FROM_CLASS (klass),
2912 _gtk_marshal_VOID__VOID,
2916 * GtkWidget::screen-changed:
2917 * @widget: the object on which the signal is emitted
2918 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2919 * widget was not associated with a screen before
2921 * The ::screen-changed signal gets emitted when the
2922 * screen of a widget has changed.
2924 widget_signals[SCREEN_CHANGED] =
2925 g_signal_new (I_("screen-changed"),
2926 G_TYPE_FROM_CLASS (klass),
2928 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2930 _gtk_marshal_VOID__OBJECT,
2935 * GtkWidget::can-activate-accel:
2936 * @widget: the object which received the signal
2937 * @signal_id: the ID of a signal installed on @widget
2939 * Determines whether an accelerator that activates the signal
2940 * identified by @signal_id can currently be activated.
2941 * This signal is present to allow applications and derived
2942 * widgets to override the default #GtkWidget handling
2943 * for determining whether an accelerator can be activated.
2945 * Returns: %TRUE if the signal can be activated.
2947 widget_signals[CAN_ACTIVATE_ACCEL] =
2948 g_signal_new (I_("can-activate-accel"),
2949 G_TYPE_FROM_CLASS (klass),
2951 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2952 _gtk_boolean_handled_accumulator, NULL,
2953 _gtk_marshal_BOOLEAN__UINT,
2954 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2956 binding_set = gtk_binding_set_by_class (klass);
2957 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2959 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2962 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2964 GTK_TYPE_WIDGET_HELP_TYPE,
2965 GTK_WIDGET_HELP_TOOLTIP);
2966 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2968 GTK_TYPE_WIDGET_HELP_TYPE,
2969 GTK_WIDGET_HELP_TOOLTIP);
2970 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2972 GTK_TYPE_WIDGET_HELP_TYPE,
2973 GTK_WIDGET_HELP_WHATS_THIS);
2974 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2976 GTK_TYPE_WIDGET_HELP_TYPE,
2977 GTK_WIDGET_HELP_WHATS_THIS);
2979 gtk_widget_class_install_style_property (klass,
2980 g_param_spec_boolean ("interior-focus",
2981 P_("Interior Focus"),
2982 P_("Whether to draw the focus indicator inside widgets"),
2984 GTK_PARAM_READABLE));
2986 gtk_widget_class_install_style_property (klass,
2987 g_param_spec_int ("focus-line-width",
2988 P_("Focus linewidth"),
2989 P_("Width, in pixels, of the focus indicator line"),
2991 GTK_PARAM_READABLE));
2993 gtk_widget_class_install_style_property (klass,
2994 g_param_spec_string ("focus-line-pattern",
2995 P_("Focus line dash pattern"),
2996 P_("Dash pattern used to draw the focus indicator"),
2998 GTK_PARAM_READABLE));
2999 gtk_widget_class_install_style_property (klass,
3000 g_param_spec_int ("focus-padding",
3001 P_("Focus padding"),
3002 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3004 GTK_PARAM_READABLE));
3005 gtk_widget_class_install_style_property (klass,
3006 g_param_spec_boxed ("cursor-color",
3008 P_("Color with which to draw insertion cursor"),
3010 GTK_PARAM_READABLE));
3011 gtk_widget_class_install_style_property (klass,
3012 g_param_spec_boxed ("secondary-cursor-color",
3013 P_("Secondary cursor color"),
3014 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3016 GTK_PARAM_READABLE));
3017 gtk_widget_class_install_style_property (klass,
3018 g_param_spec_float ("cursor-aspect-ratio",
3019 P_("Cursor line aspect ratio"),
3020 P_("Aspect ratio with which to draw insertion cursor"),
3022 GTK_PARAM_READABLE));
3024 gtk_widget_class_install_style_property (klass,
3025 g_param_spec_boolean ("window-dragging",
3026 P_("Window dragging"),
3027 P_("Whether windows can be dragged by clicking on empty areas"),
3029 GTK_PARAM_READABLE));
3032 * GtkWidget:link-color:
3034 * The "link-color" style property defines the color of unvisited links.
3038 gtk_widget_class_install_style_property (klass,
3039 g_param_spec_boxed ("link-color",
3040 P_("Unvisited Link Color"),
3041 P_("Color of unvisited links"),
3043 GTK_PARAM_READABLE));
3046 * GtkWidget:visited-link-color:
3048 * The "visited-link-color" style property defines the color of visited links.
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_boxed ("visited-link-color",
3054 P_("Visited Link Color"),
3055 P_("Color of visited links"),
3057 GTK_PARAM_READABLE));
3060 * GtkWidget:wide-separators:
3062 * The "wide-separators" style property defines whether separators have
3063 * configurable width and should be drawn using a box instead of a line.
3067 gtk_widget_class_install_style_property (klass,
3068 g_param_spec_boolean ("wide-separators",
3069 P_("Wide Separators"),
3070 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3072 GTK_PARAM_READABLE));
3075 * GtkWidget:separator-width:
3077 * The "separator-width" style property defines the width of separators.
3078 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3082 gtk_widget_class_install_style_property (klass,
3083 g_param_spec_int ("separator-width",
3084 P_("Separator Width"),
3085 P_("The width of separators if wide-separators is TRUE"),
3087 GTK_PARAM_READABLE));
3090 * GtkWidget:separator-height:
3092 * The "separator-height" style property defines the height of separators.
3093 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3097 gtk_widget_class_install_style_property (klass,
3098 g_param_spec_int ("separator-height",
3099 P_("Separator Height"),
3100 P_("The height of separators if \"wide-separators\" is TRUE"),
3102 GTK_PARAM_READABLE));
3105 * GtkWidget:scroll-arrow-hlength:
3107 * The "scroll-arrow-hlength" style property defines the length of
3108 * horizontal scroll arrows.
3112 gtk_widget_class_install_style_property (klass,
3113 g_param_spec_int ("scroll-arrow-hlength",
3114 P_("Horizontal Scroll Arrow Length"),
3115 P_("The length of horizontal scroll arrows"),
3117 GTK_PARAM_READABLE));
3120 * GtkWidget:scroll-arrow-vlength:
3122 * The "scroll-arrow-vlength" style property defines the length of
3123 * vertical scroll arrows.
3127 gtk_widget_class_install_style_property (klass,
3128 g_param_spec_int ("scroll-arrow-vlength",
3129 P_("Vertical Scroll Arrow Length"),
3130 P_("The length of vertical scroll arrows"),
3132 GTK_PARAM_READABLE));
3134 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3138 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3142 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3143 for (node = list; node; node = node->next)
3145 GParamSpec *pspec = node->data;
3147 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3148 g_param_spec_unref (pspec);
3154 gtk_widget_set_property (GObject *object,
3156 const GValue *value,
3159 GtkWidget *widget = GTK_WIDGET (object);
3164 gchar *tooltip_markup;
3165 const gchar *tooltip_text;
3166 GtkWindow *tooltip_window;
3169 gtk_widget_set_name (widget, g_value_get_string (value));
3172 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3174 case PROP_WIDTH_REQUEST:
3175 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3177 case PROP_HEIGHT_REQUEST:
3178 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3181 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3183 case PROP_SENSITIVE:
3184 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3186 case PROP_APP_PAINTABLE:
3187 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3189 case PROP_CAN_FOCUS:
3190 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3192 case PROP_HAS_FOCUS:
3193 if (g_value_get_boolean (value))
3194 gtk_widget_grab_focus (widget);
3197 if (g_value_get_boolean (value))
3198 gtk_widget_grab_focus (widget);
3200 case PROP_CAN_DEFAULT:
3201 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3203 case PROP_HAS_DEFAULT:
3204 if (g_value_get_boolean (value))
3205 gtk_widget_grab_default (widget);
3207 case PROP_RECEIVES_DEFAULT:
3208 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3211 gtk_widget_set_style (widget, g_value_get_object (value));
3214 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3215 gtk_widget_set_events (widget, g_value_get_flags (value));
3217 case PROP_EXTENSION_EVENTS:
3218 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3220 case PROP_NO_SHOW_ALL:
3221 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3223 case PROP_HAS_TOOLTIP:
3224 gtk_widget_real_set_has_tooltip (widget,
3225 g_value_get_boolean (value), FALSE);
3227 case PROP_TOOLTIP_MARKUP:
3228 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3229 tooltip_markup = g_value_dup_string (value);
3231 /* Treat an empty string as a NULL string,
3232 * because an empty string would be useless for a tooltip:
3234 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3236 g_free (tooltip_markup);
3237 tooltip_markup = NULL;
3240 g_object_set_qdata_full (object, quark_tooltip_markup,
3241 tooltip_markup, g_free);
3243 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3244 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3245 if (gtk_widget_get_visible (widget))
3246 gtk_widget_queue_tooltip_query (widget);
3248 case PROP_TOOLTIP_TEXT:
3249 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3251 tooltip_text = g_value_get_string (value);
3253 /* Treat an empty string as a NULL string,
3254 * because an empty string would be useless for a tooltip:
3256 if (tooltip_text && (strlen (tooltip_text) == 0))
3257 tooltip_text = NULL;
3259 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3261 g_object_set_qdata_full (object, quark_tooltip_markup,
3262 tooltip_markup, g_free);
3264 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3265 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3266 if (gtk_widget_get_visible (widget))
3267 gtk_widget_queue_tooltip_query (widget);
3269 case PROP_DOUBLE_BUFFERED:
3270 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3273 gtk_widget_set_halign (widget, g_value_get_enum (value));
3276 gtk_widget_set_valign (widget, g_value_get_enum (value));
3278 case PROP_MARGIN_LEFT:
3279 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3281 case PROP_MARGIN_RIGHT:
3282 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3284 case PROP_MARGIN_TOP:
3285 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3287 case PROP_MARGIN_BOTTOM:
3288 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3291 g_object_freeze_notify (G_OBJECT (widget));
3292 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3293 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3294 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3295 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3296 g_object_thaw_notify (G_OBJECT (widget));
3299 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3301 case PROP_HEXPAND_SET:
3302 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3305 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3307 case PROP_VEXPAND_SET:
3308 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3311 g_object_freeze_notify (G_OBJECT (widget));
3312 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3313 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3314 g_object_thaw_notify (G_OBJECT (widget));
3317 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3323 gtk_widget_get_property (GObject *object,
3328 GtkWidget *widget = GTK_WIDGET (object);
3329 GtkWidgetPrivate *priv = widget->priv;
3338 g_value_set_string (value, priv->name);
3340 g_value_set_static_string (value, "");
3343 g_value_set_object (value, priv->parent);
3345 case PROP_WIDTH_REQUEST:
3348 gtk_widget_get_size_request (widget, &w, NULL);
3349 g_value_set_int (value, w);
3352 case PROP_HEIGHT_REQUEST:
3355 gtk_widget_get_size_request (widget, NULL, &h);
3356 g_value_set_int (value, h);
3360 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3362 case PROP_SENSITIVE:
3363 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3365 case PROP_APP_PAINTABLE:
3366 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3368 case PROP_CAN_FOCUS:
3369 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3371 case PROP_HAS_FOCUS:
3372 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3375 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3377 case PROP_CAN_DEFAULT:
3378 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3380 case PROP_HAS_DEFAULT:
3381 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3383 case PROP_RECEIVES_DEFAULT:
3384 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3386 case PROP_COMPOSITE_CHILD:
3387 g_value_set_boolean (value, widget->priv->composite_child);
3390 g_value_set_object (value, gtk_widget_get_style (widget));
3393 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3394 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3396 case PROP_EXTENSION_EVENTS:
3397 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3398 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3400 case PROP_NO_SHOW_ALL:
3401 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3403 case PROP_HAS_TOOLTIP:
3404 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3406 case PROP_TOOLTIP_TEXT:
3408 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3411 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3412 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3414 g_value_take_string (value, text);
3417 case PROP_TOOLTIP_MARKUP:
3418 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3421 g_value_set_object (value, gtk_widget_get_window (widget));
3423 case PROP_DOUBLE_BUFFERED:
3424 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3427 g_value_set_enum (value, gtk_widget_get_halign (widget));
3430 g_value_set_enum (value, gtk_widget_get_valign (widget));
3432 case PROP_MARGIN_LEFT:
3433 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3435 case PROP_MARGIN_RIGHT:
3436 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3438 case PROP_MARGIN_TOP:
3439 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3441 case PROP_MARGIN_BOTTOM:
3442 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3446 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3447 if (aux_info == NULL)
3449 g_value_set_int (value, 0);
3453 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3454 aux_info->margin.right),
3455 MAX (aux_info->margin.top,
3456 aux_info->margin.bottom)));
3461 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3463 case PROP_HEXPAND_SET:
3464 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3467 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3469 case PROP_VEXPAND_SET:
3470 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3473 g_value_set_boolean (value,
3474 gtk_widget_get_hexpand (widget) &&
3475 gtk_widget_get_vexpand (widget));
3478 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3484 gtk_widget_init (GtkWidget *widget)
3486 GtkWidgetPrivate *priv;
3488 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3491 priv = widget->priv;
3493 priv->child_visible = TRUE;
3495 priv->allocation.x = -1;
3496 priv->allocation.y = -1;
3497 priv->allocation.width = 1;
3498 priv->allocation.height = 1;
3499 priv->window = NULL;
3500 priv->parent = NULL;
3502 priv->sensitive = TRUE;
3503 priv->parent_sensitive = TRUE;
3504 priv->composite_child = composite_child_stack != 0;
3505 priv->double_buffered = TRUE;
3506 priv->redraw_on_alloc = TRUE;
3507 priv->width_request_needed = TRUE;
3508 priv->height_request_needed = TRUE;
3509 priv->alloc_needed = TRUE;
3511 /* this will be set to TRUE if the widget gets a child or if the
3512 * expand flag is set on the widget, but until one of those happen
3513 * we know the expand is already properly FALSE.
3515 * We really want to default FALSE here to avoid computing expand
3516 * all over the place while initially building a widget tree.
3518 priv->need_compute_expand = FALSE;
3520 priv->style = gtk_widget_get_default_style ();
3521 g_object_ref (priv->style);
3526 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3528 GParamSpec **pspecs)
3530 GtkWidgetPrivate *priv = widget->priv;
3531 GtkWidget *container = priv->parent;
3534 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3535 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3539 * gtk_widget_freeze_child_notify:
3540 * @widget: a #GtkWidget
3542 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3543 * signals are queued until gtk_widget_thaw_child_notify() is called
3546 * This is the analogue of g_object_freeze_notify() for child properties.
3549 gtk_widget_freeze_child_notify (GtkWidget *widget)
3551 g_return_if_fail (GTK_IS_WIDGET (widget));
3553 if (!G_OBJECT (widget)->ref_count)
3556 g_object_ref (widget);
3557 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3558 g_object_unref (widget);
3562 * gtk_widget_child_notify:
3563 * @widget: a #GtkWidget
3564 * @child_property: the name of a child property installed on the
3565 * class of @widget<!-- -->'s parent
3567 * Emits a #GtkWidget::child-notify signal for the
3568 * <link linkend="child-properties">child property</link> @child_property
3571 * This is the analogue of g_object_notify() for child properties.
3574 gtk_widget_child_notify (GtkWidget *widget,
3575 const gchar *child_property)
3577 GtkWidgetPrivate *priv = widget->priv;
3580 g_return_if_fail (GTK_IS_WIDGET (widget));
3581 g_return_if_fail (child_property != NULL);
3582 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3585 g_object_ref (widget);
3586 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3588 G_OBJECT_TYPE (priv->parent),
3591 g_warning ("%s: container class `%s' has no child property named `%s'",
3593 G_OBJECT_TYPE_NAME (priv->parent),
3597 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3599 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3600 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3602 g_object_unref (widget);
3606 * gtk_widget_thaw_child_notify:
3607 * @widget: a #GtkWidget
3609 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3610 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3614 gtk_widget_thaw_child_notify (GtkWidget *widget)
3616 GObjectNotifyQueue *nqueue;
3618 g_return_if_fail (GTK_IS_WIDGET (widget));
3620 if (!G_OBJECT (widget)->ref_count)
3623 g_object_ref (widget);
3624 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3625 if (!nqueue || !nqueue->freeze_count)
3626 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3627 G_OBJECT_TYPE_NAME (widget), widget);
3629 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3630 g_object_unref (widget);
3636 * @type: type ID of the widget to create
3637 * @first_property_name: name of first property to set
3638 * @Varargs: value of first property, followed by more properties,
3641 * This is a convenience function for creating a widget and setting
3642 * its properties in one go. For example you might write:
3643 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3644 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3645 * g_object_new(), but returns a widget so you don't have to
3646 * cast the object yourself.
3648 * Return value: a new #GtkWidget of type @widget_type
3651 gtk_widget_new (GType type,
3652 const gchar *first_property_name,
3658 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3660 va_start (var_args, first_property_name);
3661 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3668 gtk_widget_queue_draw_child (GtkWidget *widget)
3670 GtkWidgetPrivate *priv = widget->priv;
3673 parent = priv->parent;
3674 if (parent && gtk_widget_is_drawable (parent))
3675 gtk_widget_queue_draw_area (parent,
3678 priv->allocation.width,
3679 priv->allocation.height);
3683 * gtk_widget_unparent:
3684 * @widget: a #GtkWidget
3686 * This function is only for use in widget implementations.
3687 * Should be called by implementations of the remove method
3688 * on #GtkContainer, to dissociate a child from the container.
3691 gtk_widget_unparent (GtkWidget *widget)
3693 GtkWidgetPrivate *priv;
3694 GObjectNotifyQueue *nqueue;
3695 GtkWidget *toplevel;
3696 GtkWidget *old_parent;
3698 g_return_if_fail (GTK_IS_WIDGET (widget));
3700 priv = widget->priv;
3702 if (priv->parent == NULL)
3705 /* keep this function in sync with gtk_menu_detach()
3708 g_object_freeze_notify (G_OBJECT (widget));
3709 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3711 toplevel = gtk_widget_get_toplevel (widget);
3712 if (gtk_widget_is_toplevel (toplevel))
3713 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3715 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3716 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3718 /* If we are unanchoring the child, we save around the toplevel
3719 * to emit hierarchy changed
3721 if (priv->parent->priv->anchored)
3722 g_object_ref (toplevel);
3726 gtk_widget_queue_draw_child (widget);
3728 /* Reset the width and height here, to force reallocation if we
3729 * get added back to a new parent. This won't work if our new
3730 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3731 * (would 0x0 be OK here?)
3733 priv->allocation.width = 1;
3734 priv->allocation.height = 1;
3736 if (gtk_widget_get_realized (widget))
3738 if (priv->in_reparent)
3739 gtk_widget_unmap (widget);
3741 gtk_widget_unrealize (widget);
3744 /* Removing a widget from a container restores the child visible
3745 * flag to the default state, so it doesn't affect the child
3746 * in the next parent.
3748 priv->child_visible = TRUE;
3750 old_parent = priv->parent;
3751 priv->parent = NULL;
3752 gtk_widget_set_parent_window (widget, NULL);
3754 /* parent may no longer expand if the removed
3755 * child was expand=TRUE and could therefore
3758 if (gtk_widget_get_visible (widget) &&
3759 (priv->need_compute_expand ||
3760 priv->computed_hexpand ||
3761 priv->computed_vexpand))
3763 gtk_widget_queue_compute_expand (old_parent);
3766 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3769 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3770 g_object_unref (toplevel);
3773 g_object_notify (G_OBJECT (widget), "parent");
3774 g_object_thaw_notify (G_OBJECT (widget));
3776 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3777 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3778 g_object_unref (widget);
3782 * gtk_widget_destroy:
3783 * @widget: a #GtkWidget
3785 * Destroys a widget.
3788 * destroyed, it will break any references it holds to other objects.
3789 * If the widget is inside a container, the widget will be removed
3790 * from the container. If the widget is a toplevel (derived from
3791 * #GtkWindow), it will be removed from the list of toplevels, and the
3792 * reference GTK+ holds to it will be removed. Removing a
3793 * widget from its container or the list of toplevels results in the
3794 * widget being finalized, unless you've added additional references
3795 * to the widget with g_object_ref().
3797 * In most cases, only toplevel widgets (windows) require explicit
3798 * destruction, because when you destroy a toplevel its children will
3799 * be destroyed as well.
3802 gtk_widget_destroy (GtkWidget *widget)
3804 g_return_if_fail (GTK_IS_WIDGET (widget));
3806 if (!widget->priv->in_destruction)
3807 g_object_run_dispose (G_OBJECT (widget));
3811 * gtk_widget_destroyed:
3812 * @widget: a #GtkWidget
3813 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3815 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3816 * %NULL. It's intended to be used as a callback connected to the
3817 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3818 * as a signal handler, and pass the address of your widget variable
3819 * as user data. Then when the widget is destroyed, the variable will
3820 * be set to %NULL. Useful for example to avoid multiple copies
3821 * of the same dialog.
3824 gtk_widget_destroyed (GtkWidget *widget,
3825 GtkWidget **widget_pointer)
3827 /* Don't make any assumptions about the
3829 * Even check widget_pointer.
3832 *widget_pointer = NULL;
3837 * @widget: a #GtkWidget
3839 * Flags a widget to be displayed. Any widget that isn't shown will
3840 * not appear on the screen. If you want to show all the widgets in a
3841 * container, it's easier to call gtk_widget_show_all() on the
3842 * container, instead of individually showing the widgets.
3844 * Remember that you have to show the containers containing a widget,
3845 * in addition to the widget itself, before it will appear onscreen.
3847 * When a toplevel container is shown, it is immediately realized and
3848 * mapped; other shown widgets are realized and mapped when their
3849 * toplevel container is realized and mapped.
3852 gtk_widget_show (GtkWidget *widget)
3854 g_return_if_fail (GTK_IS_WIDGET (widget));
3856 if (!gtk_widget_get_visible (widget))
3858 g_object_ref (widget);
3859 if (!gtk_widget_is_toplevel (widget))
3860 gtk_widget_queue_resize (widget);
3862 /* see comment in set_parent() for why this should and can be
3865 if (widget->priv->need_compute_expand ||
3866 widget->priv->computed_hexpand ||
3867 widget->priv->computed_vexpand)
3869 if (widget->priv->parent != NULL)
3870 gtk_widget_queue_compute_expand (widget->priv->parent);
3873 g_signal_emit (widget, widget_signals[SHOW], 0);
3874 g_object_notify (G_OBJECT (widget), "visible");
3875 g_object_unref (widget);
3880 gtk_widget_real_show (GtkWidget *widget)
3882 GtkWidgetPrivate *priv = widget->priv;
3884 if (!gtk_widget_get_visible (widget))
3886 priv->visible = TRUE;
3889 gtk_widget_get_mapped (priv->parent) &&
3890 gtk_widget_get_child_visible (widget) &&
3891 !gtk_widget_get_mapped (widget))
3892 gtk_widget_map (widget);
3897 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3900 g_signal_handlers_disconnect_by_func (widget,
3901 gtk_widget_show_map_callback,
3906 * gtk_widget_show_now:
3907 * @widget: a #GtkWidget
3909 * Shows a widget. If the widget is an unmapped toplevel widget
3910 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3911 * loop and wait for the window to actually be mapped. Be careful;
3912 * because the main loop is running, anything can happen during
3916 gtk_widget_show_now (GtkWidget *widget)
3920 g_return_if_fail (GTK_IS_WIDGET (widget));
3922 /* make sure we will get event */
3923 if (!gtk_widget_get_mapped (widget) &&
3924 gtk_widget_is_toplevel (widget))
3926 gtk_widget_show (widget);
3928 g_signal_connect (widget, "map-event",
3929 G_CALLBACK (gtk_widget_show_map_callback),
3933 gtk_main_iteration ();
3936 gtk_widget_show (widget);
3941 * @widget: a #GtkWidget
3943 * Reverses the effects of gtk_widget_show(), causing the widget to be
3944 * hidden (invisible to the user).
3947 gtk_widget_hide (GtkWidget *widget)
3949 g_return_if_fail (GTK_IS_WIDGET (widget));
3951 if (gtk_widget_get_visible (widget))
3953 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3955 g_object_ref (widget);
3956 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3957 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3959 /* a parent may now be expand=FALSE since we're hidden. */
3960 if (widget->priv->need_compute_expand ||
3961 widget->priv->computed_hexpand ||
3962 widget->priv->computed_vexpand)
3964 gtk_widget_queue_compute_expand (widget);
3967 g_signal_emit (widget, widget_signals[HIDE], 0);
3968 if (!gtk_widget_is_toplevel (widget))
3969 gtk_widget_queue_resize (widget);
3970 g_object_notify (G_OBJECT (widget), "visible");
3971 g_object_unref (widget);
3976 gtk_widget_real_hide (GtkWidget *widget)
3978 if (gtk_widget_get_visible (widget))
3980 widget->priv->visible = FALSE;
3982 if (gtk_widget_get_mapped (widget))
3983 gtk_widget_unmap (widget);
3988 * gtk_widget_hide_on_delete:
3989 * @widget: a #GtkWidget
3991 * Utility function; intended to be connected to the #GtkWidget::delete-event
3992 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3993 * argument, then returns %TRUE. If connected to ::delete-event, the
3994 * result is that clicking the close button for a window (on the
3995 * window frame, top right corner usually) will hide but not destroy
3996 * the window. By default, GTK+ destroys windows when ::delete-event
3999 * Return value: %TRUE
4002 gtk_widget_hide_on_delete (GtkWidget *widget)
4004 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4006 gtk_widget_hide (widget);
4012 * gtk_widget_show_all:
4013 * @widget: a #GtkWidget
4015 * Recursively shows a widget, and any child widgets (if the widget is
4019 gtk_widget_show_all (GtkWidget *widget)
4021 GtkWidgetClass *class;
4023 g_return_if_fail (GTK_IS_WIDGET (widget));
4025 if (gtk_widget_get_no_show_all (widget))
4028 class = GTK_WIDGET_GET_CLASS (widget);
4030 if (class->show_all)
4031 class->show_all (widget);
4035 _gtk_widget_notify_state_change (GtkWidget *widget,
4043 case GTK_STATE_FLAG_ACTIVE:
4044 state = GTK_STATE_ACTIVE;
4046 case GTK_STATE_FLAG_PRELIGHT:
4047 state = GTK_STATE_PRELIGHT;
4049 case GTK_STATE_FLAG_SELECTED:
4050 state = GTK_STATE_SELECTED;
4052 case GTK_STATE_FLAG_INSENSITIVE:
4053 state = GTK_STATE_INSENSITIVE;
4055 case GTK_STATE_FLAG_INCONSISTENT:
4056 state = GTK_STATE_INCONSISTENT;
4058 case GTK_STATE_FLAG_FOCUSED:
4059 state = GTK_STATE_FOCUSED;
4065 gtk_style_context_notify_state_change (widget->priv->context,
4066 gtk_widget_get_window (widget),
4067 NULL, state, target);
4070 /* Initializes state transitions for those states that
4071 * were enabled before mapping and have a looping animation.
4074 _gtk_widget_start_state_transitions (GtkWidget *widget)
4076 GtkStateFlags state, flag;
4078 if (!widget->priv->context)
4081 state = gtk_widget_get_state_flags (widget);
4082 flag = GTK_STATE_FLAG_FOCUSED;
4086 GtkAnimationDescription *animation_desc;
4088 if ((state & flag) == 0)
4094 gtk_style_context_get (widget->priv->context, state,
4095 "transition", &animation_desc,
4100 if (_gtk_animation_description_get_loop (animation_desc))
4101 _gtk_widget_notify_state_change (widget, flag, TRUE);
4103 _gtk_animation_description_unref (animation_desc);
4112 * @widget: a #GtkWidget
4114 * This function is only for use in widget implementations. Causes
4115 * a widget to be mapped if it isn't already.
4118 gtk_widget_map (GtkWidget *widget)
4120 GtkWidgetPrivate *priv;
4122 g_return_if_fail (GTK_IS_WIDGET (widget));
4123 g_return_if_fail (gtk_widget_get_visible (widget));
4124 g_return_if_fail (gtk_widget_get_child_visible (widget));
4126 priv = widget->priv;
4128 if (!gtk_widget_get_mapped (widget))
4130 if (!gtk_widget_get_realized (widget))
4131 gtk_widget_realize (widget);
4133 g_signal_emit (widget, widget_signals[MAP], 0);
4135 if (!gtk_widget_get_has_window (widget))
4136 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4138 _gtk_widget_start_state_transitions (widget);
4144 * @widget: a #GtkWidget
4146 * This function is only for use in widget implementations. Causes
4147 * a widget to be unmapped if it's currently mapped.
4150 gtk_widget_unmap (GtkWidget *widget)
4152 GtkWidgetPrivate *priv;
4154 g_return_if_fail (GTK_IS_WIDGET (widget));
4156 priv = widget->priv;
4158 if (gtk_widget_get_mapped (widget))
4160 if (!gtk_widget_get_has_window (widget))
4161 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4162 _gtk_tooltip_hide (widget);
4163 g_signal_emit (widget, widget_signals[UNMAP], 0);
4168 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4169 GdkExtensionMode mode,
4172 GtkWidgetPrivate *priv = widget->priv;
4173 GList *free_list = NULL;
4176 if (window_list == NULL)
4178 if (gtk_widget_get_has_window (widget))
4179 window_list = g_list_prepend (NULL, priv->window);
4181 window_list = gdk_window_get_children (priv->window);
4183 free_list = window_list;
4186 for (l = window_list; l != NULL; l = l->next)
4188 GdkWindow *window = l->data;
4191 gdk_window_get_user_data (window, &user_data);
4192 if (user_data == widget)
4196 gdk_input_set_extension_events (window,
4197 gdk_window_get_events (window),
4200 children = gdk_window_get_children (window);
4203 gtk_widget_set_extension_events_internal (widget, mode, children);
4204 g_list_free (children);
4210 g_list_free (free_list);
4214 _gtk_widget_enable_device_events (GtkWidget *widget)
4216 GHashTable *device_events;
4217 GHashTableIter iter;
4218 gpointer key, value;
4220 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4225 g_hash_table_iter_init (&iter, device_events);
4227 while (g_hash_table_iter_next (&iter, &key, &value))
4230 GdkEventMask event_mask;
4233 event_mask = GPOINTER_TO_UINT (value);
4234 gtk_widget_add_events_internal (widget, device, event_mask);
4239 * gtk_widget_realize:
4240 * @widget: a #GtkWidget
4242 * Creates the GDK (windowing system) resources associated with a
4243 * widget. For example, @widget->window will be created when a widget
4244 * is realized. Normally realization happens implicitly; if you show
4245 * a widget and all its parent containers, then the widget will be
4246 * realized and mapped automatically.
4248 * Realizing a widget requires all
4249 * the widget's parent widgets to be realized; calling
4250 * gtk_widget_realize() realizes the widget's parents in addition to
4251 * @widget itself. If a widget is not yet inside a toplevel window
4252 * when you realize it, bad things will happen.
4254 * This function is primarily used in widget implementations, and
4255 * isn't very useful otherwise. Many times when you think you might
4256 * need it, a better approach is to connect to a signal that will be
4257 * called after the widget is realized automatically, such as
4258 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4259 * #GtkWidget::realize signal.
4262 gtk_widget_realize (GtkWidget *widget)
4264 GtkWidgetPrivate *priv;
4265 GdkExtensionMode mode;
4266 cairo_region_t *region;
4268 g_return_if_fail (GTK_IS_WIDGET (widget));
4269 g_return_if_fail (widget->priv->anchored ||
4270 GTK_IS_INVISIBLE (widget));
4272 priv = widget->priv;
4274 if (!gtk_widget_get_realized (widget))
4277 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4278 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4281 if (priv->parent == NULL &&
4282 !gtk_widget_is_toplevel (widget))
4283 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4284 "inside a toplevel window is not going to work very well. "
4285 "Widgets must be inside a toplevel container before realizing them.");
4287 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4288 gtk_widget_realize (priv->parent);
4290 gtk_widget_ensure_style (widget);
4292 g_signal_emit (widget, widget_signals[REALIZE], 0);
4294 gtk_widget_real_set_has_tooltip (widget,
4295 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4298 if (priv->has_shape_mask)
4300 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4301 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4304 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4306 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4308 mode = gtk_widget_get_extension_events (widget);
4309 if (mode != GDK_EXTENSION_EVENTS_NONE)
4310 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4312 if (priv->multidevice)
4313 gdk_window_set_support_multidevice (priv->window, TRUE);
4315 _gtk_widget_enable_device_events (widget);
4320 * gtk_widget_unrealize:
4321 * @widget: a #GtkWidget
4323 * This function is only useful in widget implementations.
4324 * Causes a widget to be unrealized (frees all GDK resources
4325 * associated with the widget, such as @widget->window).
4328 gtk_widget_unrealize (GtkWidget *widget)
4330 g_return_if_fail (GTK_IS_WIDGET (widget));
4332 if (widget->priv->has_shape_mask)
4333 gtk_widget_shape_combine_region (widget, NULL);
4335 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4336 gtk_widget_input_shape_combine_region (widget, NULL);
4338 if (gtk_widget_get_realized (widget))
4340 g_object_ref (widget);
4341 _gtk_tooltip_hide (widget);
4342 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4343 gtk_widget_set_realized (widget, FALSE);
4344 gtk_widget_set_mapped (widget, FALSE);
4345 g_object_unref (widget);
4349 /*****************************************
4351 *****************************************/
4354 * gtk_widget_queue_draw_region:
4355 * @widget: a #GtkWidget
4356 * @region: region to draw
4358 * Invalidates the rectangular area of @widget defined by @region by
4359 * calling gdk_window_invalidate_region() on the widget's window and
4360 * all its child windows. Once the main loop becomes idle (after the
4361 * current batch of events has been processed, roughly), the window
4362 * will receive expose events for the union of all regions that have
4365 * Normally you would only use this function in widget
4366 * implementations. You might also use it to schedule a redraw of a
4367 * #GtkDrawingArea or some portion thereof.
4370 gtk_widget_queue_draw_region (GtkWidget *widget,
4371 cairo_region_t *region)
4373 GtkWidgetPrivate *priv;
4376 g_return_if_fail (GTK_IS_WIDGET (widget));
4378 priv = widget->priv;
4380 if (!gtk_widget_get_realized (widget))
4383 /* Just return if the widget or one of its ancestors isn't mapped */
4384 for (w = widget; w != NULL; w = w->priv->parent)
4385 if (!gtk_widget_get_mapped (w))
4388 gdk_window_invalidate_region (priv->window, region, TRUE);
4392 * gtk_widget_queue_draw_area:
4393 * @widget: a #GtkWidget
4394 * @x: x coordinate of upper-left corner of rectangle to redraw
4395 * @y: y coordinate of upper-left corner of rectangle to redraw
4396 * @width: width of region to draw
4397 * @height: height of region to draw
4399 * Convenience function that calls gtk_widget_queue_draw_region() on
4400 * the region created from the given coordinates.
4403 gtk_widget_queue_draw_area (GtkWidget *widget,
4410 cairo_region_t *region;
4412 g_return_if_fail (GTK_IS_WIDGET (widget));
4417 rect.height = height;
4419 region = cairo_region_create_rectangle (&rect);
4420 gtk_widget_queue_draw_region (widget, region);
4421 cairo_region_destroy (region);
4425 * gtk_widget_queue_draw:
4426 * @widget: a #GtkWidget
4428 * Equivalent to calling gtk_widget_queue_draw_area() for the
4429 * entire area of a widget.
4432 gtk_widget_queue_draw (GtkWidget *widget)
4436 g_return_if_fail (GTK_IS_WIDGET (widget));
4438 gtk_widget_get_allocation (widget, &rect);
4440 if (!gtk_widget_get_has_window (widget))
4441 gtk_widget_queue_draw_area (widget,
4442 rect.x, rect.y, rect.width, rect.height);
4444 gtk_widget_queue_draw_area (widget,
4445 0, 0, rect.width, rect.height);
4449 * gtk_widget_queue_resize:
4450 * @widget: a #GtkWidget
4452 * This function is only for use in widget implementations.
4453 * Flags a widget to have its size renegotiated; should
4454 * be called when a widget for some reason has a new size request.
4455 * For example, when you change the text in a #GtkLabel, #GtkLabel
4456 * queues a resize to ensure there's enough space for the new text.
4458 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4459 * from inside it's implementation of the GtkWidgetClass::size_allocate
4460 * virtual method. Calls to gtk_widget_queue_resize() from inside
4461 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4464 gtk_widget_queue_resize (GtkWidget *widget)
4466 g_return_if_fail (GTK_IS_WIDGET (widget));
4468 if (gtk_widget_get_realized (widget))
4469 gtk_widget_queue_shallow_draw (widget);
4471 _gtk_size_group_queue_resize (widget, 0);
4475 * gtk_widget_queue_resize_no_redraw:
4476 * @widget: a #GtkWidget
4478 * This function works like gtk_widget_queue_resize(),
4479 * except that the widget is not invalidated.
4484 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4486 g_return_if_fail (GTK_IS_WIDGET (widget));
4488 _gtk_size_group_queue_resize (widget, 0);
4492 * gtk_widget_size_request:
4493 * @widget: a #GtkWidget
4494 * @requisition: (out): a #GtkRequisition to be filled in
4496 * This function is typically used when implementing a #GtkContainer
4497 * subclass. Obtains the preferred size of a widget. The container
4498 * uses this information to arrange its child widgets and decide what
4499 * size allocations to give them with gtk_widget_size_allocate().
4501 * You can also call this function from an application, with some
4502 * caveats. Most notably, getting a size request requires the widget
4503 * to be associated with a screen, because font information may be
4504 * needed. Multihead-aware applications should keep this in mind.
4506 * Also remember that the size request is not necessarily the size
4507 * a widget will actually be allocated.
4509 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4512 gtk_widget_size_request (GtkWidget *widget,
4513 GtkRequisition *requisition)
4515 g_return_if_fail (GTK_IS_WIDGET (widget));
4517 gtk_widget_get_preferred_size (widget, requisition, NULL);
4521 * gtk_widget_get_child_requisition:
4522 * @widget: a #GtkWidget
4523 * @requisition: (out): a #GtkRequisition to be filled in
4525 * This function is only for use in widget implementations. Obtains
4526 * @widget->requisition, unless someone has forced a particular
4527 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4528 * in which case it returns that geometry instead of the widget's
4531 * This function differs from gtk_widget_size_request() in that
4532 * it retrieves the last size request value from @widget->requisition,
4533 * while gtk_widget_size_request() actually calls the "size_request" method
4534 * on @widget to compute the size request and fill in @widget->requisition,
4535 * and only then returns @widget->requisition.
4537 * Because this function does not call the "size_request" method, it
4538 * can only be used when you know that @widget->requisition is
4539 * up-to-date, that is, gtk_widget_size_request() has been called
4540 * since the last time a resize was queued. In general, only container
4541 * implementations have this information; applications should use
4542 * gtk_widget_size_request().
4545 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4548 gtk_widget_get_child_requisition (GtkWidget *widget,
4549 GtkRequisition *requisition)
4551 gtk_widget_get_preferred_size (widget, requisition, NULL);
4555 invalidate_predicate (GdkWindow *window,
4560 gdk_window_get_user_data (window, &user_data);
4562 return (user_data == data);
4565 /* Invalidate @region in widget->window and all children
4566 * of widget->window owned by widget. @region is in the
4567 * same coordinates as widget->allocation and will be
4568 * modified by this call.
4571 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4572 cairo_region_t *region)
4574 GtkWidgetPrivate *priv = widget->priv;
4576 if (!gtk_widget_get_realized (widget))
4579 if (gtk_widget_get_has_window (widget) && priv->parent)
4583 gdk_window_get_position (priv->window, &x, &y);
4584 cairo_region_translate (region, -x, -y);
4587 gdk_window_invalidate_maybe_recurse (priv->window, region,
4588 invalidate_predicate, widget);
4592 * gtk_widget_queue_shallow_draw:
4593 * @widget: a #GtkWidget
4595 * Like gtk_widget_queue_draw(), but only windows owned
4596 * by @widget are invalidated.
4599 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4602 cairo_region_t *region;
4604 if (!gtk_widget_get_realized (widget))
4607 gtk_widget_get_allocation (widget, &rect);
4609 region = cairo_region_create_rectangle (&rect);
4610 gtk_widget_invalidate_widget_windows (widget, region);
4611 cairo_region_destroy (region);
4615 * gtk_widget_size_allocate:
4616 * @widget: a #GtkWidget
4617 * @allocation: (inout): position and size to be allocated to @widget
4619 * This function is only used by #GtkContainer subclasses, to assign a size
4620 * and position to their child widgets.
4622 * In this function, the allocation may be adjusted. It will be forced
4623 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4624 * method on the child will be used to adjust the allocation. Standard
4625 * adjustments include removing the widget's margins, and applying the
4626 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4629 gtk_widget_size_allocate (GtkWidget *widget,
4630 GtkAllocation *allocation)
4632 GtkWidgetPrivate *priv;
4633 GdkRectangle real_allocation;
4634 GdkRectangle old_allocation;
4635 GdkRectangle adjusted_allocation;
4636 gboolean alloc_needed;
4637 gboolean size_changed;
4638 gboolean position_changed;
4639 gint natural_width, natural_height;
4640 gint min_width, min_height;
4642 priv = widget->priv;
4644 g_return_if_fail (GTK_IS_WIDGET (widget));
4646 #ifdef G_ENABLE_DEBUG
4647 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4658 parent = gtk_widget_get_parent (parent);
4661 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4662 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4663 2 * depth, " ", name,
4664 allocation->width, allocation->height);
4666 #endif /* G_ENABLE_DEBUG */
4668 alloc_needed = priv->alloc_needed;
4669 if (!priv->width_request_needed && !priv->height_request_needed)
4670 /* Preserve request/allocate ordering */
4671 priv->alloc_needed = FALSE;
4673 old_allocation = priv->allocation;
4674 real_allocation = *allocation;
4676 adjusted_allocation = real_allocation;
4677 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4679 /* Go ahead and request the height for allocated width, note that the internals
4680 * of get_height_for_width will internally limit the for_size to natural size
4681 * when aligning implicitly.
4683 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4684 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4688 /* Go ahead and request the width for allocated height, note that the internals
4689 * of get_width_for_height will internally limit the for_size to natural size
4690 * when aligning implicitly.
4692 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4693 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4696 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4697 * allocated sizes and possibly limit them to the natural sizes */
4698 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4699 GTK_ORIENTATION_HORIZONTAL,
4701 &adjusted_allocation.x,
4702 &adjusted_allocation.width);
4703 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4704 GTK_ORIENTATION_VERTICAL,
4706 &adjusted_allocation.y,
4707 &adjusted_allocation.height);
4709 if (adjusted_allocation.x < real_allocation.x ||
4710 adjusted_allocation.y < real_allocation.y ||
4711 (adjusted_allocation.x + adjusted_allocation.width) >
4712 (real_allocation.x + real_allocation.width) ||
4713 (adjusted_allocation.y + adjusted_allocation.height >
4714 real_allocation.y + real_allocation.height))
4716 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",
4717 G_OBJECT_TYPE_NAME (widget), widget,
4718 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4719 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4720 adjusted_allocation = real_allocation; /* veto it */
4724 real_allocation = adjusted_allocation;
4727 if (real_allocation.width < 0 || real_allocation.height < 0)
4729 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4730 real_allocation.width,
4731 real_allocation.height);
4734 real_allocation.width = MAX (real_allocation.width, 1);
4735 real_allocation.height = MAX (real_allocation.height, 1);
4737 size_changed = (old_allocation.width != real_allocation.width ||
4738 old_allocation.height != real_allocation.height);
4739 position_changed = (old_allocation.x != real_allocation.x ||
4740 old_allocation.y != real_allocation.y);
4742 if (!alloc_needed && !size_changed && !position_changed)
4745 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4747 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4748 priv->width_request_needed = FALSE;
4749 priv->height_request_needed = FALSE;
4750 priv->alloc_needed = FALSE;
4752 if (gtk_widget_get_mapped (widget))
4754 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4756 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4758 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4759 cairo_region_union_rectangle (invalidate, &old_allocation);
4761 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4762 cairo_region_destroy (invalidate);
4767 if (priv->redraw_on_alloc)
4769 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4771 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4772 cairo_region_union_rectangle (invalidate, &old_allocation);
4774 gtk_widget_invalidate_widget_windows (widget, invalidate);
4775 cairo_region_destroy (invalidate);
4779 if (size_changed || position_changed)
4781 GtkStyleContext *context;
4783 context = gtk_widget_get_style_context (widget);
4784 _gtk_style_context_invalidate_animation_areas (context);
4788 if ((size_changed || position_changed) && priv->parent &&
4789 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4791 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4792 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4793 cairo_region_destroy (invalidate);
4798 * gtk_widget_common_ancestor:
4799 * @widget_a: a #GtkWidget
4800 * @widget_b: a #GtkWidget
4802 * Find the common ancestor of @widget_a and @widget_b that
4803 * is closest to the two widgets.
4805 * Return value: the closest common ancestor of @widget_a and
4806 * @widget_b or %NULL if @widget_a and @widget_b do not
4807 * share a common ancestor.
4810 gtk_widget_common_ancestor (GtkWidget *widget_a,
4811 GtkWidget *widget_b)
4813 GtkWidget *parent_a;
4814 GtkWidget *parent_b;
4818 parent_a = widget_a;
4819 while (parent_a->priv->parent)
4821 parent_a = parent_a->priv->parent;
4825 parent_b = widget_b;
4826 while (parent_b->priv->parent)
4828 parent_b = parent_b->priv->parent;
4832 if (parent_a != parent_b)
4835 while (depth_a > depth_b)
4837 widget_a = widget_a->priv->parent;
4841 while (depth_b > depth_a)
4843 widget_b = widget_b->priv->parent;
4847 while (widget_a != widget_b)
4849 widget_a = widget_a->priv->parent;
4850 widget_b = widget_b->priv->parent;
4857 * gtk_widget_translate_coordinates:
4858 * @src_widget: a #GtkWidget
4859 * @dest_widget: a #GtkWidget
4860 * @src_x: X position relative to @src_widget
4861 * @src_y: Y position relative to @src_widget
4862 * @dest_x: (out): location to store X position relative to @dest_widget
4863 * @dest_y: (out): location to store Y position relative to @dest_widget
4865 * Translate coordinates relative to @src_widget's allocation to coordinates
4866 * relative to @dest_widget's allocations. In order to perform this
4867 * operation, both widgets must be realized, and must share a common
4870 * Return value: %FALSE if either widget was not realized, or there
4871 * was no common ancestor. In this case, nothing is stored in
4872 * *@dest_x and *@dest_y. Otherwise %TRUE.
4875 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4876 GtkWidget *dest_widget,
4882 GtkWidgetPrivate *src_priv = src_widget->priv;
4883 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4884 GtkWidget *ancestor;
4886 GList *dest_list = NULL;
4888 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4889 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4891 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4892 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4895 /* Translate from allocation relative to window relative */
4896 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4899 gdk_window_get_position (src_priv->window, &wx, &wy);
4901 src_x -= wx - src_priv->allocation.x;
4902 src_y -= wy - src_priv->allocation.y;
4906 src_x += src_priv->allocation.x;
4907 src_y += src_priv->allocation.y;
4910 /* Translate to the common ancestor */
4911 window = src_priv->window;
4912 while (window != ancestor->priv->window)
4916 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4921 window = gdk_window_get_effective_parent (window);
4923 if (!window) /* Handle GtkHandleBox */
4928 window = dest_priv->window;
4929 while (window != ancestor->priv->window)
4931 dest_list = g_list_prepend (dest_list, window);
4933 window = gdk_window_get_effective_parent (window);
4935 if (!window) /* Handle GtkHandleBox */
4937 g_list_free (dest_list);
4946 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4951 dest_list = g_list_remove (dest_list, dest_list->data);
4954 /* Translate from window relative to allocation relative */
4955 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4958 gdk_window_get_position (dest_priv->window, &wx, &wy);
4960 src_x += wx - dest_priv->allocation.x;
4961 src_y += wy - dest_priv->allocation.y;
4965 src_x -= dest_priv->allocation.x;
4966 src_y -= dest_priv->allocation.y;
4978 gtk_widget_real_size_allocate (GtkWidget *widget,
4979 GtkAllocation *allocation)
4981 GtkWidgetPrivate *priv = widget->priv;
4983 priv->allocation = *allocation;
4985 if (gtk_widget_get_realized (widget) &&
4986 gtk_widget_get_has_window (widget))
4988 gdk_window_move_resize (priv->window,
4989 allocation->x, allocation->y,
4990 allocation->width, allocation->height);
4995 adjust_for_align(GtkAlign align,
4997 gint *allocated_pos,
4998 gint *allocated_size)
5002 case GTK_ALIGN_FILL:
5003 /* change nothing */
5005 case GTK_ALIGN_START:
5006 /* keep *allocated_pos where it is */
5007 *allocated_size = MIN (*allocated_size, *natural_size);
5010 if (*allocated_size > *natural_size)
5012 *allocated_pos += (*allocated_size - *natural_size);
5013 *allocated_size = *natural_size;
5016 case GTK_ALIGN_CENTER:
5017 if (*allocated_size > *natural_size)
5019 *allocated_pos += (*allocated_size - *natural_size) / 2;
5020 *allocated_size = MIN (*allocated_size, *natural_size);
5027 adjust_for_margin(gint start_margin,
5030 gint *allocated_pos,
5031 gint *allocated_size)
5033 *natural_size -= (start_margin + end_margin);
5034 *allocated_pos += start_margin;
5035 *allocated_size -= (start_margin + end_margin);
5039 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5040 GtkOrientation orientation,
5042 gint *allocated_pos,
5043 gint *allocated_size)
5045 const GtkWidgetAuxInfo *aux_info;
5047 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5049 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5051 adjust_for_margin (aux_info->margin.left,
5052 aux_info->margin.right,
5053 natural_size, allocated_pos, allocated_size);
5054 adjust_for_align (aux_info->halign,
5055 natural_size, allocated_pos, allocated_size);
5059 adjust_for_margin (aux_info->margin.top,
5060 aux_info->margin.bottom,
5061 natural_size, allocated_pos, allocated_size);
5062 adjust_for_align (aux_info->valign,
5063 natural_size, allocated_pos, allocated_size);
5068 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5071 GtkWidgetPrivate *priv = widget->priv;
5073 /* widgets must be onscreen for accels to take effect */
5074 return gtk_widget_is_sensitive (widget) &&
5075 gtk_widget_is_drawable (widget) &&
5076 gdk_window_is_viewable (priv->window);
5080 * gtk_widget_can_activate_accel:
5081 * @widget: a #GtkWidget
5082 * @signal_id: the ID of a signal installed on @widget
5084 * Determines whether an accelerator that activates the signal
5085 * identified by @signal_id can currently be activated.
5086 * This is done by emitting the #GtkWidget::can-activate-accel
5087 * signal on @widget; if the signal isn't overridden by a
5088 * handler or in a derived widget, then the default check is
5089 * that the widget must be sensitive, and the widget and all
5090 * its ancestors mapped.
5092 * Return value: %TRUE if the accelerator can be activated.
5097 gtk_widget_can_activate_accel (GtkWidget *widget,
5100 gboolean can_activate = FALSE;
5101 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5102 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5103 return can_activate;
5112 closure_accel_activate (GClosure *closure,
5113 GValue *return_value,
5114 guint n_param_values,
5115 const GValue *param_values,
5116 gpointer invocation_hint,
5117 gpointer marshal_data)
5119 AccelClosure *aclosure = (AccelClosure*) closure;
5120 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5123 g_signal_emit (closure->data, aclosure->signal_id, 0);
5125 /* whether accelerator was handled */
5126 g_value_set_boolean (return_value, can_activate);
5130 closures_destroy (gpointer data)
5132 GSList *slist, *closures = data;
5134 for (slist = closures; slist; slist = slist->next)
5136 g_closure_invalidate (slist->data);
5137 g_closure_unref (slist->data);
5139 g_slist_free (closures);
5143 widget_new_accel_closure (GtkWidget *widget,
5146 AccelClosure *aclosure;
5147 GClosure *closure = NULL;
5148 GSList *slist, *closures;
5150 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5151 for (slist = closures; slist; slist = slist->next)
5152 if (!gtk_accel_group_from_accel_closure (slist->data))
5154 /* reuse this closure */
5155 closure = slist->data;
5160 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5161 closures = g_slist_prepend (closures, g_closure_ref (closure));
5162 g_closure_sink (closure);
5163 g_closure_set_marshal (closure, closure_accel_activate);
5165 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5167 aclosure = (AccelClosure*) closure;
5168 g_assert (closure->data == widget);
5169 g_assert (closure->marshal == closure_accel_activate);
5170 aclosure->signal_id = signal_id;
5176 * gtk_widget_add_accelerator
5177 * @widget: widget to install an accelerator on
5178 * @accel_signal: widget signal to emit on accelerator activation
5179 * @accel_group: accel group for this widget, added to its toplevel
5180 * @accel_key: GDK keyval of the accelerator
5181 * @accel_mods: modifier key combination of the accelerator
5182 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5184 * Installs an accelerator for this @widget in @accel_group that causes
5185 * @accel_signal to be emitted if the accelerator is activated.
5186 * The @accel_group needs to be added to the widget's toplevel via
5187 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5188 * Accelerators added through this function are not user changeable during
5189 * runtime. If you want to support accelerators that can be changed by the
5190 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5191 * gtk_menu_item_set_accel_path() instead.
5194 gtk_widget_add_accelerator (GtkWidget *widget,
5195 const gchar *accel_signal,
5196 GtkAccelGroup *accel_group,
5198 GdkModifierType accel_mods,
5199 GtkAccelFlags accel_flags)
5204 g_return_if_fail (GTK_IS_WIDGET (widget));
5205 g_return_if_fail (accel_signal != NULL);
5206 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5208 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5209 if (!query.signal_id ||
5210 !(query.signal_flags & G_SIGNAL_ACTION) ||
5211 query.return_type != G_TYPE_NONE ||
5214 /* hmm, should be elaborate enough */
5215 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5216 G_OBJECT_TYPE_NAME (widget), accel_signal);
5220 closure = widget_new_accel_closure (widget, query.signal_id);
5222 g_object_ref (widget);
5224 /* install the accelerator. since we don't map this onto an accel_path,
5225 * the accelerator will automatically be locked.
5227 gtk_accel_group_connect (accel_group,
5230 accel_flags | GTK_ACCEL_LOCKED,
5233 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5235 g_object_unref (widget);
5239 * gtk_widget_remove_accelerator:
5240 * @widget: widget to install an accelerator on
5241 * @accel_group: accel group for this widget
5242 * @accel_key: GDK keyval of the accelerator
5243 * @accel_mods: modifier key combination of the accelerator
5244 * @returns: whether an accelerator was installed and could be removed
5246 * Removes an accelerator from @widget, previously installed with
5247 * gtk_widget_add_accelerator().
5250 gtk_widget_remove_accelerator (GtkWidget *widget,
5251 GtkAccelGroup *accel_group,
5253 GdkModifierType accel_mods)
5255 GtkAccelGroupEntry *ag_entry;
5256 GList *slist, *clist;
5259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5260 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5262 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5263 clist = gtk_widget_list_accel_closures (widget);
5264 for (slist = clist; slist; slist = slist->next)
5268 for (i = 0; i < n; i++)
5269 if (slist->data == (gpointer) ag_entry[i].closure)
5271 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5273 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5275 g_list_free (clist);
5280 g_list_free (clist);
5282 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5283 accel_key, accel_mods, accel_group,
5284 G_OBJECT_TYPE_NAME (widget), widget);
5290 * gtk_widget_list_accel_closures:
5291 * @widget: widget to list accelerator closures for
5293 * Lists the closures used by @widget for accelerator group connections
5294 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5295 * The closures can be used to monitor accelerator changes on @widget,
5296 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5297 * #GtkAccelGroup of a closure which can be found out with
5298 * gtk_accel_group_from_accel_closure().
5300 * Return value: (transfer container) (element-type GClosure):
5301 * a newly allocated #GList of closures
5304 gtk_widget_list_accel_closures (GtkWidget *widget)
5307 GList *clist = NULL;
5309 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5311 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5312 if (gtk_accel_group_from_accel_closure (slist->data))
5313 clist = g_list_prepend (clist, slist->data);
5319 GtkAccelGroup *accel_group;
5324 destroy_accel_path (gpointer data)
5326 AccelPath *apath = data;
5328 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5330 /* closures_destroy takes care of unrefing the closure */
5331 g_object_unref (apath->accel_group);
5333 g_slice_free (AccelPath, apath);
5338 * gtk_widget_set_accel_path:
5339 * @widget: a #GtkWidget
5340 * @accel_path: (allow-none): path used to look up the accelerator
5341 * @accel_group: (allow-none): a #GtkAccelGroup.
5343 * Given an accelerator group, @accel_group, and an accelerator path,
5344 * @accel_path, sets up an accelerator in @accel_group so whenever the
5345 * key binding that is defined for @accel_path is pressed, @widget
5346 * will be activated. This removes any accelerators (for any
5347 * accelerator group) installed by previous calls to
5348 * gtk_widget_set_accel_path(). Associating accelerators with
5349 * paths allows them to be modified by the user and the modifications
5350 * to be saved for future use. (See gtk_accel_map_save().)
5352 * This function is a low level function that would most likely
5353 * be used by a menu creation system like #GtkUIManager. If you
5354 * use #GtkUIManager, setting up accelerator paths will be done
5357 * Even when you you aren't using #GtkUIManager, if you only want to
5358 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5359 * provides a somewhat more convenient interface.
5361 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5362 * pass a static string, you can save some memory by interning it first with
5363 * g_intern_static_string().
5366 gtk_widget_set_accel_path (GtkWidget *widget,
5367 const gchar *accel_path,
5368 GtkAccelGroup *accel_group)
5372 g_return_if_fail (GTK_IS_WIDGET (widget));
5373 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5377 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5378 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5380 gtk_accel_map_add_entry (accel_path, 0, 0);
5381 apath = g_slice_new (AccelPath);
5382 apath->accel_group = g_object_ref (accel_group);
5383 apath->path_quark = g_quark_from_string (accel_path);
5384 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5389 /* also removes possible old settings */
5390 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5393 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5395 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5399 _gtk_widget_get_accel_path (GtkWidget *widget,
5404 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5406 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5408 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5409 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5413 * gtk_widget_mnemonic_activate:
5414 * @widget: a #GtkWidget
5415 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5417 * Emits the #GtkWidget::mnemonic-activate signal.
5419 * The default handler for this signal activates the @widget if
5420 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5423 * Returns: %TRUE if the signal has been handled
5426 gtk_widget_mnemonic_activate (GtkWidget *widget,
5427 gboolean group_cycling)
5431 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5433 group_cycling = group_cycling != FALSE;
5434 if (!gtk_widget_is_sensitive (widget))
5437 g_signal_emit (widget,
5438 widget_signals[MNEMONIC_ACTIVATE],
5446 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5447 gboolean group_cycling)
5449 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5450 gtk_widget_activate (widget);
5451 else if (gtk_widget_get_can_focus (widget))
5452 gtk_widget_grab_focus (widget);
5455 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5456 G_OBJECT_TYPE_NAME (widget));
5457 gtk_widget_error_bell (widget);
5462 static const cairo_user_data_key_t event_key;
5465 _gtk_cairo_get_event (cairo_t *cr)
5467 g_return_val_if_fail (cr != NULL, NULL);
5469 return cairo_get_user_data (cr, &event_key);
5473 gtk_cairo_set_event (cairo_t *cr,
5474 GdkEventExpose *event)
5476 cairo_set_user_data (cr, &event_key, event, NULL);
5480 * gtk_cairo_should_draw_window:
5481 * @cr: a cairo context
5482 * @window: the window to check
5484 * This function is supposed to be called in #GtkWidget::draw
5485 * implementations for widgets that support multiple windows.
5486 * @cr must be untransformed from invoking of the draw function.
5487 * This function will return %TRUE if the contents of the given
5488 * @window are supposed to be drawn and %FALSE otherwise. Note
5489 * that when the drawing was not initiated by the windowing
5490 * system this function will return %TRUE for all windows, so
5491 * you need to draw the bottommost window first. Also, do not
5492 * use "else if" statements to check which window should be drawn.
5494 * Returns: %TRUE if @window should be drawn
5497 gtk_cairo_should_draw_window (cairo_t *cr,
5500 GdkEventExpose *event;
5502 g_return_val_if_fail (cr != NULL, FALSE);
5503 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5505 event = _gtk_cairo_get_event (cr);
5507 return event == NULL ||
5508 event->window == window;
5511 /* code shared by gtk_container_propagate_draw() and
5515 _gtk_widget_draw_internal (GtkWidget *widget,
5517 gboolean clip_to_size)
5519 GtkStyleContext *context;
5521 if (!gtk_widget_is_drawable (widget))
5526 cairo_rectangle (cr,
5528 widget->priv->allocation.width,
5529 widget->priv->allocation.height);
5533 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5537 g_signal_emit (widget, widget_signals[DRAW],
5542 context = gtk_widget_get_style_context (widget);
5543 _gtk_style_context_coalesce_animation_areas (context,
5544 widget->priv->allocation.x,
5545 widget->priv->allocation.y);
5550 * @widget: the widget to draw. It must be drawable (see
5551 * gtk_widget_is_drawable()) and a size must have been allocated.
5552 * @cr: a cairo context to draw to
5554 * Draws @widget to @cr. The top left corner of the widget will be
5555 * drawn to the currently set origin point of @cr.
5557 * You should pass a cairo context as @cr argument that is in an
5558 * original state. Otherwise the resulting drawing is undefined. For
5559 * example changing the operator using cairo_set_operator() or the
5560 * line width using cairo_set_line_width() might have unwanted side
5562 * You may however change the context's transform matrix - like with
5563 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5564 * region with cairo_clip() prior to calling this function. Also, it
5565 * is fine to modify the context with cairo_save() and
5566 * cairo_push_group() prior to calling this function.
5568 * <note><para>Special purpose widgets may contain special code for
5569 * rendering to the screen and might appear differently on screen
5570 * and when rendered using gtk_widget_draw().</para></note>
5573 gtk_widget_draw (GtkWidget *widget,
5576 GdkEventExpose *tmp_event;
5578 g_return_if_fail (GTK_IS_WIDGET (widget));
5579 g_return_if_fail (!widget->priv->alloc_needed);
5580 g_return_if_fail (cr != NULL);
5583 /* We have to reset the event here so that draw functions can call
5584 * gtk_widget_draw() on random other widgets and get the desired
5585 * effect: Drawing all contents, not just the current window.
5587 tmp_event = _gtk_cairo_get_event (cr);
5588 gtk_cairo_set_event (cr, NULL);
5590 _gtk_widget_draw_internal (widget, cr, TRUE);
5592 gtk_cairo_set_event (cr, tmp_event);
5597 gtk_widget_real_key_press_event (GtkWidget *widget,
5600 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5604 gtk_widget_real_key_release_event (GtkWidget *widget,
5607 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5611 gtk_widget_real_focus_in_event (GtkWidget *widget,
5612 GdkEventFocus *event)
5614 gtk_widget_queue_shallow_draw (widget);
5620 gtk_widget_real_focus_out_event (GtkWidget *widget,
5621 GdkEventFocus *event)
5623 gtk_widget_queue_shallow_draw (widget);
5628 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5629 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5633 * @widget: a #GtkWidget
5634 * @event: a #GdkEvent
5636 * Rarely-used function. This function is used to emit
5637 * the event signals on a widget (those signals should never
5638 * be emitted without using this function to do so).
5639 * If you want to synthesize an event though, don't use this function;
5640 * instead, use gtk_main_do_event() so the event will behave as if
5641 * it were in the event queue. Don't synthesize expose events; instead,
5642 * use gdk_window_invalidate_rect() to invalidate a region of the
5645 * Return value: return from the event signal emission (%TRUE if
5646 * the event was handled)
5649 gtk_widget_event (GtkWidget *widget,
5652 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5653 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5655 if (event->type == GDK_EXPOSE)
5657 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5658 "the same effect, call gdk_window_invalidate_rect/region(), "
5659 "followed by gdk_window_process_updates().");
5663 return gtk_widget_event_internal (widget, event);
5666 /* Returns TRUE if a translation should be done */
5668 gtk_widget_get_translation_to_window (GtkWidget *widget,
5673 GdkWindow *w, *widget_window;
5675 if (!gtk_widget_get_has_window (widget))
5677 *x = -widget->priv->allocation.x;
5678 *y = -widget->priv->allocation.y;
5686 widget_window = gtk_widget_get_window (widget);
5688 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5691 gdk_window_get_position (w, &wx, &wy);
5708 * gtk_cairo_transform_to_window:
5709 * @cr: the cairo context to transform
5710 * @widget: the widget the context is currently centered for
5711 * @window: the window to transform the context to
5713 * Transforms the given cairo context @cr that from @widget-relative
5714 * coordinates to @window-relative coordinates.
5715 * If the @widget's window is not an ancestor of @window, no
5716 * modification will be applied.
5718 * This is the inverse to the transformation GTK applies when
5719 * preparing an expose event to be emitted with the #GtkWidget::draw
5720 * signal. It is intended to help porting multiwindow widgets from
5721 * GTK+ 2 to the rendering architecture of GTK+ 3.
5724 gtk_cairo_transform_to_window (cairo_t *cr,
5730 g_return_if_fail (cr != NULL);
5731 g_return_if_fail (GTK_IS_WIDGET (widget));
5732 g_return_if_fail (GDK_IS_WINDOW (window));
5734 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5735 cairo_translate (cr, x, y);
5739 * gtk_widget_send_expose:
5740 * @widget: a #GtkWidget
5741 * @event: a expose #GdkEvent
5743 * Very rarely-used function. This function is used to emit
5744 * an expose event on a widget. This function is not normally used
5745 * directly. The only time it is used is when propagating an expose
5746 * event to a child %NO_WINDOW widget, and that is normally done
5747 * using gtk_container_propagate_draw().
5749 * If you want to force an area of a window to be redrawn,
5750 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5751 * To cause the redraw to be done immediately, follow that call
5752 * with a call to gdk_window_process_updates().
5754 * Return value: return from the event signal emission (%TRUE if
5755 * the event was handled)
5758 gtk_widget_send_expose (GtkWidget *widget,
5761 gboolean result = FALSE;
5766 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5767 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5768 g_return_val_if_fail (event != NULL, TRUE);
5769 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5771 cr = gdk_cairo_create (event->expose.window);
5772 gtk_cairo_set_event (cr, &event->expose);
5774 gdk_cairo_region (cr, event->expose.region);
5777 do_clip = gtk_widget_get_translation_to_window (widget,
5778 event->expose.window,
5780 cairo_translate (cr, -x, -y);
5782 _gtk_widget_draw_internal (widget, cr, do_clip);
5784 /* unset here, so if someone keeps a reference to cr we
5785 * don't leak the window. */
5786 gtk_cairo_set_event (cr, NULL);
5793 event_window_is_still_viewable (GdkEvent *event)
5795 /* Check that we think the event's window is viewable before
5796 * delivering the event, to prevent suprises. We do this here
5797 * at the last moment, since the event may have been queued
5798 * up behind other events, held over a recursive main loop, etc.
5800 switch (event->type)
5803 case GDK_MOTION_NOTIFY:
5804 case GDK_BUTTON_PRESS:
5805 case GDK_2BUTTON_PRESS:
5806 case GDK_3BUTTON_PRESS:
5808 case GDK_ENTER_NOTIFY:
5809 case GDK_PROXIMITY_IN:
5811 return event->any.window && gdk_window_is_viewable (event->any.window);
5814 /* The following events are the second half of paired events;
5815 * we always deliver them to deal with widgets that clean up
5816 * on the second half.
5818 case GDK_BUTTON_RELEASE:
5819 case GDK_KEY_RELEASE:
5820 case GDK_LEAVE_NOTIFY:
5821 case GDK_PROXIMITY_OUT:
5825 /* Remaining events would make sense on an not-viewable window,
5826 * or don't have an associated window.
5833 gtk_widget_event_internal (GtkWidget *widget,
5836 gboolean return_val = FALSE;
5838 /* We check only once for is-still-visible; if someone
5839 * hides the window in on of the signals on the widget,
5840 * they are responsible for returning TRUE to terminate
5843 if (!event_window_is_still_viewable (event))
5846 g_object_ref (widget);
5848 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5849 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5854 switch (event->type)
5859 case GDK_BUTTON_PRESS:
5860 case GDK_2BUTTON_PRESS:
5861 case GDK_3BUTTON_PRESS:
5862 signal_num = BUTTON_PRESS_EVENT;
5865 signal_num = SCROLL_EVENT;
5867 case GDK_BUTTON_RELEASE:
5868 signal_num = BUTTON_RELEASE_EVENT;
5870 case GDK_MOTION_NOTIFY:
5871 signal_num = MOTION_NOTIFY_EVENT;
5874 signal_num = DELETE_EVENT;
5877 signal_num = DESTROY_EVENT;
5878 _gtk_tooltip_hide (widget);
5881 signal_num = KEY_PRESS_EVENT;
5883 case GDK_KEY_RELEASE:
5884 signal_num = KEY_RELEASE_EVENT;
5886 case GDK_ENTER_NOTIFY:
5887 signal_num = ENTER_NOTIFY_EVENT;
5889 case GDK_LEAVE_NOTIFY:
5890 signal_num = LEAVE_NOTIFY_EVENT;
5892 case GDK_FOCUS_CHANGE:
5893 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5894 if (event->focus_change.in)
5895 _gtk_tooltip_focus_in (widget);
5897 _gtk_tooltip_focus_out (widget);
5900 signal_num = CONFIGURE_EVENT;
5903 signal_num = MAP_EVENT;
5906 signal_num = UNMAP_EVENT;
5908 case GDK_WINDOW_STATE:
5909 signal_num = WINDOW_STATE_EVENT;
5911 case GDK_PROPERTY_NOTIFY:
5912 signal_num = PROPERTY_NOTIFY_EVENT;
5914 case GDK_SELECTION_CLEAR:
5915 signal_num = SELECTION_CLEAR_EVENT;
5917 case GDK_SELECTION_REQUEST:
5918 signal_num = SELECTION_REQUEST_EVENT;
5920 case GDK_SELECTION_NOTIFY:
5921 signal_num = SELECTION_NOTIFY_EVENT;
5923 case GDK_PROXIMITY_IN:
5924 signal_num = PROXIMITY_IN_EVENT;
5926 case GDK_PROXIMITY_OUT:
5927 signal_num = PROXIMITY_OUT_EVENT;
5929 case GDK_CLIENT_EVENT:
5930 signal_num = CLIENT_EVENT;
5933 signal_num = EXPOSE_EVENT;
5935 case GDK_VISIBILITY_NOTIFY:
5936 signal_num = VISIBILITY_NOTIFY_EVENT;
5938 case GDK_GRAB_BROKEN:
5939 signal_num = GRAB_BROKEN_EVENT;
5942 signal_num = DAMAGE_EVENT;
5945 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5949 if (signal_num != -1)
5950 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5952 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5953 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5957 g_object_unref (widget);
5963 * gtk_widget_activate:
5964 * @widget: a #GtkWidget that's activatable
5966 * For widgets that can be "activated" (buttons, menu items, etc.)
5967 * this function activates them. Activation is what happens when you
5968 * press Enter on a widget during key navigation. If @widget isn't
5969 * activatable, the function returns %FALSE.
5971 * Return value: %TRUE if the widget was activatable
5974 gtk_widget_activate (GtkWidget *widget)
5976 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5978 if (WIDGET_CLASS (widget)->activate_signal)
5980 /* FIXME: we should eventually check the signals signature here */
5981 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5990 gtk_widget_reparent_subwindows (GtkWidget *widget,
5991 GdkWindow *new_window)
5993 GtkWidgetPrivate *priv = widget->priv;
5995 if (!gtk_widget_get_has_window (widget))
5997 GList *children = gdk_window_get_children (priv->window);
6000 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6002 GdkWindow *window = tmp_list->data;
6005 gdk_window_get_user_data (window, &child);
6006 while (child && child != widget)
6007 child = ((GtkWidget*) child)->priv->parent;
6010 gdk_window_reparent (window, new_window, 0, 0);
6013 g_list_free (children);
6018 GList *tmp_list, *children;
6020 parent = gdk_window_get_parent (priv->window);
6023 gdk_window_reparent (priv->window, new_window, 0, 0);
6026 children = gdk_window_get_children (parent);
6028 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6030 GdkWindow *window = tmp_list->data;
6033 gdk_window_get_user_data (window, &child);
6035 if (child == widget)
6036 gdk_window_reparent (window, new_window, 0, 0);
6039 g_list_free (children);
6045 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6046 gpointer client_data)
6048 GtkWidgetPrivate *priv = widget->priv;
6050 g_assert (client_data != NULL);
6052 if (!gtk_widget_get_has_window (widget))
6055 g_object_unref (priv->window);
6056 priv->window = (GdkWindow*) client_data;
6058 g_object_ref (priv->window);
6060 if (GTK_IS_CONTAINER (widget))
6061 gtk_container_forall (GTK_CONTAINER (widget),
6062 gtk_widget_reparent_fixup_child,
6068 * gtk_widget_reparent:
6069 * @widget: a #GtkWidget
6070 * @new_parent: a #GtkContainer to move the widget into
6072 * Moves a widget from one #GtkContainer to another, handling reference
6073 * count issues to avoid destroying the widget.
6076 gtk_widget_reparent (GtkWidget *widget,
6077 GtkWidget *new_parent)
6079 GtkWidgetPrivate *priv;
6081 g_return_if_fail (GTK_IS_WIDGET (widget));
6082 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6083 priv = widget->priv;
6084 g_return_if_fail (priv->parent != NULL);
6086 if (priv->parent != new_parent)
6088 /* First try to see if we can get away without unrealizing
6089 * the widget as we reparent it. if so we set a flag so
6090 * that gtk_widget_unparent doesn't unrealize widget
6092 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6093 priv->in_reparent = TRUE;
6095 g_object_ref (widget);
6096 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6097 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6098 g_object_unref (widget);
6100 if (priv->in_reparent)
6102 priv->in_reparent = FALSE;
6104 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6105 gtk_widget_reparent_fixup_child (widget,
6106 gtk_widget_get_parent_window (widget));
6109 g_object_notify (G_OBJECT (widget), "parent");
6114 * gtk_widget_intersect:
6115 * @widget: a #GtkWidget
6116 * @area: a rectangle
6117 * @intersection: rectangle to store intersection of @widget and @area
6119 * Computes the intersection of a @widget's area and @area, storing
6120 * the intersection in @intersection, and returns %TRUE if there was
6121 * an intersection. @intersection may be %NULL if you're only
6122 * interested in whether there was an intersection.
6124 * Return value: %TRUE if there was an intersection
6127 gtk_widget_intersect (GtkWidget *widget,
6128 const GdkRectangle *area,
6129 GdkRectangle *intersection)
6131 GtkWidgetPrivate *priv;
6136 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6137 g_return_val_if_fail (area != NULL, FALSE);
6139 priv = widget->priv;
6142 dest = intersection;
6146 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6148 if (return_val && intersection && gtk_widget_get_has_window (widget))
6150 intersection->x -= priv->allocation.x;
6151 intersection->y -= priv->allocation.y;
6158 * gtk_widget_region_intersect:
6159 * @widget: a #GtkWidget
6160 * @region: a #cairo_region_t, in the same coordinate system as
6161 * @widget->allocation. That is, relative to @widget->window
6162 * for %NO_WINDOW widgets; relative to the parent window
6163 * of @widget->window for widgets with their own window.
6164 * @returns: A newly allocated region holding the intersection of @widget
6165 * and @region. The coordinates of the return value are
6166 * relative to @widget->window for %NO_WINDOW widgets, and
6167 * relative to the parent window of @widget->window for
6168 * widgets with their own window.
6170 * Computes the intersection of a @widget's area and @region, returning
6171 * the intersection. The result may be empty, use cairo_region_is_empty() to
6175 gtk_widget_region_intersect (GtkWidget *widget,
6176 const cairo_region_t *region)
6179 cairo_region_t *dest;
6181 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6182 g_return_val_if_fail (region != NULL, NULL);
6184 gtk_widget_get_allocation (widget, &rect);
6186 dest = cairo_region_create_rectangle (&rect);
6188 cairo_region_intersect (dest, region);
6194 * _gtk_widget_grab_notify:
6195 * @widget: a #GtkWidget
6196 * @was_grabbed: whether a grab is now in effect
6198 * Emits the #GtkWidget::grab-notify signal on @widget.
6203 _gtk_widget_grab_notify (GtkWidget *widget,
6204 gboolean was_grabbed)
6206 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6210 * gtk_widget_grab_focus:
6211 * @widget: a #GtkWidget
6213 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6214 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6215 * something like #GtkFrame won't work.
6217 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6218 * gtk_widget_set_can_focus() to modify that flag.
6220 * The widget also needs to be realized and mapped. This is indicated by the
6221 * related signals. Grabbing the focus immediately after creating the widget
6222 * will likely fail and cause critical warnings.
6225 gtk_widget_grab_focus (GtkWidget *widget)
6227 g_return_if_fail (GTK_IS_WIDGET (widget));
6229 if (!gtk_widget_is_sensitive (widget))
6232 g_object_ref (widget);
6233 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6234 g_object_notify (G_OBJECT (widget), "has-focus");
6235 g_object_unref (widget);
6239 reset_focus_recurse (GtkWidget *widget,
6242 if (GTK_IS_CONTAINER (widget))
6244 GtkContainer *container;
6246 container = GTK_CONTAINER (widget);
6247 gtk_container_set_focus_child (container, NULL);
6249 gtk_container_foreach (container,
6250 reset_focus_recurse,
6256 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6258 if (gtk_widget_get_can_focus (focus_widget))
6260 GtkWidget *toplevel;
6263 /* clear the current focus setting, break if the current widget
6264 * is the focus widget's parent, since containers above that will
6265 * be set by the next loop.
6267 toplevel = gtk_widget_get_toplevel (focus_widget);
6268 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6270 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6272 if (widget == focus_widget)
6274 /* We call _gtk_window_internal_set_focus() here so that the
6275 * toplevel window can request the focus if necessary.
6276 * This is needed when the toplevel is a GtkPlug
6278 if (!gtk_widget_has_focus (widget))
6279 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6286 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6288 widget = widget->priv->parent;
6289 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6293 else if (toplevel != focus_widget)
6295 /* gtk_widget_grab_focus() operates on a tree without window...
6296 * actually, this is very questionable behaviour.
6299 gtk_container_foreach (GTK_CONTAINER (toplevel),
6300 reset_focus_recurse,
6304 /* now propagate the new focus up the widget tree and finally
6305 * set it on the window
6307 widget = focus_widget;
6308 while (widget->priv->parent)
6310 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6311 widget = widget->priv->parent;
6313 if (GTK_IS_WINDOW (widget))
6314 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6319 gtk_widget_real_query_tooltip (GtkWidget *widget,
6322 gboolean keyboard_tip,
6323 GtkTooltip *tooltip)
6325 gchar *tooltip_markup;
6326 gboolean has_tooltip;
6328 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6329 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6331 if (has_tooltip && tooltip_markup)
6333 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6341 gtk_widget_real_style_updated (GtkWidget *widget)
6343 if (widget->priv->context)
6344 gtk_style_context_invalidate (widget->priv->context);
6345 gtk_widget_queue_resize (widget);
6349 gtk_widget_real_show_help (GtkWidget *widget,
6350 GtkWidgetHelpType help_type)
6352 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6354 _gtk_tooltip_toggle_keyboard_mode (widget);
6363 gtk_widget_real_focus (GtkWidget *widget,
6364 GtkDirectionType direction)
6366 if (!gtk_widget_get_can_focus (widget))
6369 if (!gtk_widget_is_focus (widget))
6371 gtk_widget_grab_focus (widget);
6379 gtk_widget_real_move_focus (GtkWidget *widget,
6380 GtkDirectionType direction)
6382 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6384 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6386 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6392 gtk_widget_real_keynav_failed (GtkWidget *widget,
6393 GtkDirectionType direction)
6395 gboolean cursor_only;
6399 case GTK_DIR_TAB_FORWARD:
6400 case GTK_DIR_TAB_BACKWARD:
6407 g_object_get (gtk_widget_get_settings (widget),
6408 "gtk-keynav-cursor-only", &cursor_only,
6415 gtk_widget_error_bell (widget);
6421 * gtk_widget_set_can_focus:
6422 * @widget: a #GtkWidget
6423 * @can_focus: whether or not @widget can own the input focus.
6425 * Specifies whether @widget can own the input focus. See
6426 * gtk_widget_grab_focus() for actually setting the input focus on a
6432 gtk_widget_set_can_focus (GtkWidget *widget,
6435 g_return_if_fail (GTK_IS_WIDGET (widget));
6437 if (widget->priv->can_focus != can_focus)
6439 widget->priv->can_focus = can_focus;
6441 gtk_widget_queue_resize (widget);
6442 g_object_notify (G_OBJECT (widget), "can-focus");
6447 * gtk_widget_get_can_focus:
6448 * @widget: a #GtkWidget
6450 * Determines whether @widget can own the input focus. See
6451 * gtk_widget_set_can_focus().
6453 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6458 gtk_widget_get_can_focus (GtkWidget *widget)
6460 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6462 return widget->priv->can_focus;
6466 * gtk_widget_has_focus:
6467 * @widget: a #GtkWidget
6469 * Determines if the widget has the global input focus. See
6470 * gtk_widget_is_focus() for the difference between having the global
6471 * input focus, and only having the focus within a toplevel.
6473 * Return value: %TRUE if the widget has the global input focus.
6478 gtk_widget_has_focus (GtkWidget *widget)
6480 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6482 return widget->priv->has_focus;
6486 * gtk_widget_is_focus:
6487 * @widget: a #GtkWidget
6489 * Determines if the widget is the focus widget within its
6490 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6491 * necessarily set; %HAS_FOCUS will only be set if the
6492 * toplevel widget additionally has the global input focus.)
6494 * Return value: %TRUE if the widget is the focus widget.
6497 gtk_widget_is_focus (GtkWidget *widget)
6499 GtkWidget *toplevel;
6501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6503 toplevel = gtk_widget_get_toplevel (widget);
6505 if (GTK_IS_WINDOW (toplevel))
6506 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6512 * gtk_widget_set_can_default:
6513 * @widget: a #GtkWidget
6514 * @can_default: whether or not @widget can be a default widget.
6516 * Specifies whether @widget can be a default widget. See
6517 * gtk_widget_grab_default() for details about the meaning of
6523 gtk_widget_set_can_default (GtkWidget *widget,
6524 gboolean can_default)
6526 g_return_if_fail (GTK_IS_WIDGET (widget));
6528 if (widget->priv->can_default != can_default)
6530 widget->priv->can_default = can_default;
6532 gtk_widget_queue_resize (widget);
6533 g_object_notify (G_OBJECT (widget), "can-default");
6538 * gtk_widget_get_can_default:
6539 * @widget: a #GtkWidget
6541 * Determines whether @widget can be a default widget. See
6542 * gtk_widget_set_can_default().
6544 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6549 gtk_widget_get_can_default (GtkWidget *widget)
6551 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6553 return widget->priv->can_default;
6557 * gtk_widget_has_default:
6558 * @widget: a #GtkWidget
6560 * Determines whether @widget is the current default widget within its
6561 * toplevel. See gtk_widget_set_can_default().
6563 * Return value: %TRUE if @widget is the current default widget within
6564 * its toplevel, %FALSE otherwise
6569 gtk_widget_has_default (GtkWidget *widget)
6571 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6573 return widget->priv->has_default;
6577 _gtk_widget_set_has_default (GtkWidget *widget,
6578 gboolean has_default)
6580 widget->priv->has_default = has_default;
6584 * gtk_widget_grab_default:
6585 * @widget: a #GtkWidget
6587 * Causes @widget to become the default widget. @widget must have the
6588 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6589 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6590 * %TRUE)</literal>. The default widget is activated when
6591 * the user presses Enter in a window. Default widgets must be
6592 * activatable, that is, gtk_widget_activate() should affect them. Note
6593 * that #GtkEntry widgets require the "activates-default" property
6594 * set to %TRUE before they activate the default widget when Enter
6595 * is pressed and the #GtkEntry is focused.
6598 gtk_widget_grab_default (GtkWidget *widget)
6602 g_return_if_fail (GTK_IS_WIDGET (widget));
6603 g_return_if_fail (gtk_widget_get_can_default (widget));
6605 window = gtk_widget_get_toplevel (widget);
6607 if (window && gtk_widget_is_toplevel (window))
6608 gtk_window_set_default (GTK_WINDOW (window), widget);
6610 g_warning (G_STRLOC ": widget not within a GtkWindow");
6614 * gtk_widget_set_receives_default:
6615 * @widget: a #GtkWidget
6616 * @receives_default: whether or not @widget can be a default widget.
6618 * Specifies whether @widget will be treated as the default widget
6619 * within its toplevel when it has the focus, even if another widget
6622 * See gtk_widget_grab_default() for details about the meaning of
6628 gtk_widget_set_receives_default (GtkWidget *widget,
6629 gboolean receives_default)
6631 g_return_if_fail (GTK_IS_WIDGET (widget));
6633 if (widget->priv->receives_default != receives_default)
6635 widget->priv->receives_default = receives_default;
6637 g_object_notify (G_OBJECT (widget), "receives-default");
6642 * gtk_widget_get_receives_default:
6643 * @widget: a #GtkWidget
6645 * Determines whether @widget is alyways treated as default widget
6646 * withing its toplevel when it has the focus, even if another widget
6649 * See gtk_widget_set_receives_default().
6651 * Return value: %TRUE if @widget acts as default widget when focussed,
6657 gtk_widget_get_receives_default (GtkWidget *widget)
6659 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6661 return widget->priv->receives_default;
6665 * gtk_widget_has_grab:
6666 * @widget: a #GtkWidget
6668 * Determines whether the widget is currently grabbing events, so it
6669 * is the only widget receiving input events (keyboard and mouse).
6671 * See also gtk_grab_add().
6673 * Return value: %TRUE if the widget is in the grab_widgets stack
6678 gtk_widget_has_grab (GtkWidget *widget)
6680 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6682 return widget->priv->has_grab;
6686 _gtk_widget_set_has_grab (GtkWidget *widget,
6689 widget->priv->has_grab = has_grab;
6693 * gtk_widget_device_is_shadowed:
6694 * @widget: a #GtkWidget
6695 * @device: a #GdkDevice
6697 * Returns %TRUE if @device has been shadowed by a GTK+
6698 * device grab on another widget, so it would stop sending
6699 * events to @widget. This may be used in the
6700 * #GtkWidget::grab-notify signal to check for specific
6701 * devices. See gtk_device_grab_add().
6703 * Returns: %TRUE if there is an ongoing grab on @device
6704 * by another #GtkWidget than @widget.
6709 gtk_widget_device_is_shadowed (GtkWidget *widget,
6712 GtkWindowGroup *group;
6713 GtkWidget *grab_widget, *toplevel;
6715 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6716 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6718 if (!gtk_widget_get_realized (widget))
6721 toplevel = gtk_widget_get_toplevel (widget);
6723 if (GTK_IS_WINDOW (toplevel))
6724 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6726 group = gtk_window_get_group (NULL);
6728 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6730 /* Widget not inside the hierarchy of grab_widget */
6732 widget != grab_widget &&
6733 !gtk_widget_is_ancestor (widget, grab_widget))
6736 grab_widget = gtk_window_group_get_current_grab (group);
6737 if (grab_widget && widget != grab_widget &&
6738 !gtk_widget_is_ancestor (widget, grab_widget))
6745 * gtk_widget_set_name:
6746 * @widget: a #GtkWidget
6747 * @name: name for the widget
6749 * Widgets can be named, which allows you to refer to them from a
6750 * gtkrc file. You can apply a style to widgets with a particular name
6751 * in the gtkrc file. See the documentation for gtkrc files (on the
6752 * same page as the docs for #GtkRcStyle).
6754 * Note that widget names are separated by periods in paths (see
6755 * gtk_widget_path()), so names with embedded periods may cause confusion.
6758 gtk_widget_set_name (GtkWidget *widget,
6761 GtkWidgetPrivate *priv;
6764 g_return_if_fail (GTK_IS_WIDGET (widget));
6766 priv = widget->priv;
6768 new_name = g_strdup (name);
6769 g_free (priv->name);
6770 priv->name = new_name;
6776 pos = gtk_widget_path_length (priv->path) - 1;
6777 gtk_widget_path_iter_set_name (priv->path, pos,
6782 gtk_style_context_set_path (priv->context, priv->path);
6785 gtk_widget_reset_rc_style (widget);
6787 g_object_notify (G_OBJECT (widget), "name");
6791 * gtk_widget_get_name:
6792 * @widget: a #GtkWidget
6794 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6795 * significance of widget names.
6797 * Return value: name of the widget. This string is owned by GTK+ and
6798 * should not be modified or freed
6800 G_CONST_RETURN gchar*
6801 gtk_widget_get_name (GtkWidget *widget)
6803 GtkWidgetPrivate *priv;
6805 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6807 priv = widget->priv;
6811 return G_OBJECT_TYPE_NAME (widget);
6815 _gtk_widget_update_state_flags (GtkWidget *widget,
6816 GtkStateFlags flags,
6819 GtkWidgetPrivate *priv;
6821 priv = widget->priv;
6823 /* Handle insensitive first, since it is propagated
6824 * differently throughout the widget hierarchy.
6826 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6827 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6828 gtk_widget_set_sensitive (widget,
6829 operation != STATE_CHANGE_UNSET);
6831 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6834 operation == STATE_CHANGE_REPLACE)
6839 data.operation = operation;
6840 data.use_forall = FALSE;
6843 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6845 data.parent_sensitive = TRUE;
6847 gtk_widget_propagate_state (widget, &data);
6849 if (gtk_widget_is_drawable (widget))
6850 gtk_widget_queue_draw (widget);
6855 * gtk_widget_set_state_flags:
6856 * @widget: a #GtkWidget
6857 * @flags: State flags to turn on
6858 * @clear: Whether to clear state before turning on @flags
6860 * This function is for use in widget implementations. Turns on flag
6861 * values in the current widget state (insensitive, prelighted, etc.).
6863 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6864 * will be propagated down to all non-internal children if @widget is a
6865 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6866 * down to all #GtkContainer children by different means than turning on the
6867 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6868 * gtk_widget_is_sensitive() will make use of these.
6873 gtk_widget_set_state_flags (GtkWidget *widget,
6874 GtkStateFlags flags,
6877 g_return_if_fail (GTK_IS_WIDGET (widget));
6879 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6880 (clear && widget->priv->state_flags == flags))
6884 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6886 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6890 * gtk_widget_unset_state_flags:
6891 * @widget: a #GtkWidget
6892 * @flags: State flags to turn off
6894 * This function is for use in widget implementations. Turns off flag
6895 * values for the current widget state (insensitive, prelighted, etc.).
6896 * See gtk_widget_set_state_flags().
6901 gtk_widget_unset_state_flags (GtkWidget *widget,
6902 GtkStateFlags flags)
6904 g_return_if_fail (GTK_IS_WIDGET (widget));
6906 if ((widget->priv->state_flags & flags) == 0)
6909 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6913 * gtk_widget_get_state_flags:
6914 * @widget: a #GtkWidget
6916 * Returns the widget state as a flag set. It is worth mentioning
6917 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6918 * returned, that is, also based on parent insensitivity, even if
6919 * @widget itself is sensitive.
6921 * Returns: The state flags for widget
6926 gtk_widget_get_state_flags (GtkWidget *widget)
6928 GtkStateFlags flags;
6930 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6932 flags = widget->priv->state_flags;
6934 if (!gtk_widget_is_sensitive (widget))
6935 flags |= GTK_STATE_FLAG_INSENSITIVE;
6941 * gtk_widget_set_state:
6942 * @widget: a #GtkWidget
6943 * @state: new state for @widget
6945 * This function is for use in widget implementations. Sets the state
6946 * of a widget (insensitive, prelighted, etc.) Usually you should set
6947 * the state using wrapper functions such as gtk_widget_set_sensitive().
6949 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6952 gtk_widget_set_state (GtkWidget *widget,
6955 GtkStateFlags flags;
6957 if (state == gtk_widget_get_state (widget))
6962 case GTK_STATE_ACTIVE:
6963 flags = GTK_STATE_FLAG_ACTIVE;
6965 case GTK_STATE_PRELIGHT:
6966 flags = GTK_STATE_FLAG_PRELIGHT;
6968 case GTK_STATE_SELECTED:
6969 flags = GTK_STATE_FLAG_SELECTED;
6971 case GTK_STATE_INSENSITIVE:
6972 flags = GTK_STATE_FLAG_INSENSITIVE;
6974 case GTK_STATE_INCONSISTENT:
6975 flags = GTK_STATE_FLAG_INCONSISTENT;
6977 case GTK_STATE_FOCUSED:
6978 flags = GTK_STATE_FLAG_FOCUSED;
6980 case GTK_STATE_NORMAL:
6986 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6990 * gtk_widget_get_state:
6991 * @widget: a #GtkWidget
6993 * Returns the widget's state. See gtk_widget_set_state().
6995 * Returns: the state of @widget.
6999 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7002 gtk_widget_get_state (GtkWidget *widget)
7004 GtkStateFlags flags;
7006 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7008 flags = gtk_widget_get_state_flags (widget);
7010 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7011 return GTK_STATE_INSENSITIVE;
7012 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
7013 return GTK_STATE_INCONSISTENT;
7014 else if (flags & GTK_STATE_FLAG_ACTIVE)
7015 return GTK_STATE_ACTIVE;
7016 else if (flags & GTK_STATE_FLAG_SELECTED)
7017 return GTK_STATE_SELECTED;
7018 else if (flags & GTK_STATE_FLAG_FOCUSED)
7019 return GTK_STATE_FOCUSED;
7020 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7021 return GTK_STATE_PRELIGHT;
7023 return GTK_STATE_NORMAL;
7027 * gtk_widget_set_visible:
7028 * @widget: a #GtkWidget
7029 * @visible: whether the widget should be shown or not
7031 * Sets the visibility state of @widget. Note that setting this to
7032 * %TRUE doesn't mean the widget is actually viewable, see
7033 * gtk_widget_get_visible().
7035 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7036 * but is nicer to use when the visibility of the widget depends on
7042 gtk_widget_set_visible (GtkWidget *widget,
7045 g_return_if_fail (GTK_IS_WIDGET (widget));
7047 if (visible != gtk_widget_get_visible (widget))
7050 gtk_widget_show (widget);
7052 gtk_widget_hide (widget);
7057 _gtk_widget_set_visible_flag (GtkWidget *widget,
7060 widget->priv->visible = visible;
7064 * gtk_widget_get_visible:
7065 * @widget: a #GtkWidget
7067 * Determines whether the widget is visible. Note that this doesn't
7068 * take into account whether the widget's parent is also visible
7069 * or the widget is obscured in any way.
7071 * See gtk_widget_set_visible().
7073 * Return value: %TRUE if the widget is visible
7078 gtk_widget_get_visible (GtkWidget *widget)
7080 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7082 return widget->priv->visible;
7086 * gtk_widget_set_has_window:
7087 * @widget: a #GtkWidget
7088 * @has_window: whether or not @widget has a window.
7090 * Specifies whether @widget has a #GdkWindow of its own. Note that
7091 * all realized widgets have a non-%NULL "window" pointer
7092 * (gtk_widget_get_window() never returns a %NULL window when a widget
7093 * is realized), but for many of them it's actually the #GdkWindow of
7094 * one of its parent widgets. Widgets that do not create a %window for
7095 * themselves in #GtkWidget::realize must announce this by
7096 * calling this function with @has_window = %FALSE.
7098 * This function should only be called by widget implementations,
7099 * and they should call it in their init() function.
7104 gtk_widget_set_has_window (GtkWidget *widget,
7105 gboolean has_window)
7107 g_return_if_fail (GTK_IS_WIDGET (widget));
7109 widget->priv->no_window = !has_window;
7113 * gtk_widget_get_has_window:
7114 * @widget: a #GtkWidget
7116 * Determines whether @widget has a #GdkWindow of its own. See
7117 * gtk_widget_set_has_window().
7119 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7124 gtk_widget_get_has_window (GtkWidget *widget)
7126 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7128 return ! widget->priv->no_window;
7132 * gtk_widget_is_toplevel:
7133 * @widget: a #GtkWidget
7135 * Determines whether @widget is a toplevel widget. Currently only
7136 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7137 * widgets have no parent widget.
7139 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7144 gtk_widget_is_toplevel (GtkWidget *widget)
7146 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7148 return widget->priv->toplevel;
7152 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7153 gboolean is_toplevel)
7155 widget->priv->toplevel = is_toplevel;
7159 * gtk_widget_is_drawable:
7160 * @widget: a #GtkWidget
7162 * Determines whether @widget can be drawn to. A widget can be drawn
7163 * to if it is mapped and visible.
7165 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7170 gtk_widget_is_drawable (GtkWidget *widget)
7172 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7174 return (gtk_widget_get_visible (widget) &&
7175 gtk_widget_get_mapped (widget));
7179 * gtk_widget_get_realized:
7180 * @widget: a #GtkWidget
7182 * Determines whether @widget is realized.
7184 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7189 gtk_widget_get_realized (GtkWidget *widget)
7191 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7193 return widget->priv->realized;
7197 * gtk_widget_set_realized:
7198 * @widget: a #GtkWidget
7199 * @realized: %TRUE to mark the widget as realized
7201 * Marks the widget as being realized.
7203 * This function should only ever be called in a derived widget's
7204 * "realize" or "unrealize" implementation.
7209 gtk_widget_set_realized (GtkWidget *widget,
7212 g_return_if_fail (GTK_IS_WIDGET (widget));
7214 widget->priv->realized = realized;
7218 * gtk_widget_get_mapped:
7219 * @widget: a #GtkWidget
7221 * Whether the widget is mapped.
7223 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7228 gtk_widget_get_mapped (GtkWidget *widget)
7230 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7232 return widget->priv->mapped;
7236 * gtk_widget_set_mapped:
7237 * @widget: a #GtkWidget
7238 * @mapped: %TRUE to mark the widget as mapped
7240 * Marks the widget as being realized.
7242 * This function should only ever be called in a derived widget's
7243 * "map" or "unmap" implementation.
7248 gtk_widget_set_mapped (GtkWidget *widget,
7251 g_return_if_fail (GTK_IS_WIDGET (widget));
7253 widget->priv->mapped = mapped;
7257 * gtk_widget_set_app_paintable:
7258 * @widget: a #GtkWidget
7259 * @app_paintable: %TRUE if the application will paint on the widget
7261 * Sets whether the application intends to draw on the widget in
7262 * an #GtkWidget::draw handler.
7264 * This is a hint to the widget and does not affect the behavior of
7265 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7266 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7267 * the effect is to suppress default themed drawing of the widget's
7268 * background. (Children of the widget will still be drawn.) The application
7269 * is then entirely responsible for drawing the widget background.
7271 * Note that the background is still drawn when the widget is mapped.
7274 gtk_widget_set_app_paintable (GtkWidget *widget,
7275 gboolean app_paintable)
7277 g_return_if_fail (GTK_IS_WIDGET (widget));
7279 app_paintable = (app_paintable != FALSE);
7281 if (widget->priv->app_paintable != app_paintable)
7283 widget->priv->app_paintable = app_paintable;
7285 if (gtk_widget_is_drawable (widget))
7286 gtk_widget_queue_draw (widget);
7288 g_object_notify (G_OBJECT (widget), "app-paintable");
7293 * gtk_widget_get_app_paintable:
7294 * @widget: a #GtkWidget
7296 * Determines whether the application intends to draw on the widget in
7297 * an #GtkWidget::draw handler.
7299 * See gtk_widget_set_app_paintable()
7301 * Return value: %TRUE if the widget is app paintable
7306 gtk_widget_get_app_paintable (GtkWidget *widget)
7308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7310 return widget->priv->app_paintable;
7314 * gtk_widget_set_double_buffered:
7315 * @widget: a #GtkWidget
7316 * @double_buffered: %TRUE to double-buffer a widget
7318 * Widgets are double buffered by default; you can use this function
7319 * to turn off the buffering. "Double buffered" simply means that
7320 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7321 * automatically around expose events sent to the
7322 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7323 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7324 * buffer to the screen. The result is that users see the window
7325 * update in one smooth step, and don't see individual graphics
7326 * primitives being rendered.
7328 * In very simple terms, double buffered widgets don't flicker,
7329 * so you would only use this function to turn off double buffering
7330 * if you had special needs and really knew what you were doing.
7332 * Note: if you turn off double-buffering, you have to handle
7333 * expose events, since even the clearing to the background color or
7334 * pixmap will not happen automatically (as it is done in
7335 * gdk_window_begin_paint()).
7338 gtk_widget_set_double_buffered (GtkWidget *widget,
7339 gboolean double_buffered)
7341 g_return_if_fail (GTK_IS_WIDGET (widget));
7343 double_buffered = (double_buffered != FALSE);
7345 if (widget->priv->double_buffered != double_buffered)
7347 widget->priv->double_buffered = double_buffered;
7349 g_object_notify (G_OBJECT (widget), "double-buffered");
7354 * gtk_widget_get_double_buffered:
7355 * @widget: a #GtkWidget
7357 * Determines whether the widget is double buffered.
7359 * See gtk_widget_set_double_buffered()
7361 * Return value: %TRUE if the widget is double buffered
7366 gtk_widget_get_double_buffered (GtkWidget *widget)
7368 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7370 return widget->priv->double_buffered;
7374 * gtk_widget_set_redraw_on_allocate:
7375 * @widget: a #GtkWidget
7376 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7377 * when it is allocated to a new size. Otherwise, only the
7378 * new portion of the widget will be redrawn.
7380 * Sets whether the entire widget is queued for drawing when its size
7381 * allocation changes. By default, this setting is %TRUE and
7382 * the entire widget is redrawn on every size change. If your widget
7383 * leaves the upper left unchanged when made bigger, turning this
7384 * setting off will improve performance.
7386 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7387 * off all allocation on resizing: the widget will not even redraw if
7388 * its position changes; this is to allow containers that don't draw
7389 * anything to avoid excess invalidations. If you set this flag on a
7390 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7391 * you are responsible for invalidating both the old and new allocation
7392 * of the widget when the widget is moved and responsible for invalidating
7393 * regions newly when the widget increases size.
7396 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7397 gboolean redraw_on_allocate)
7399 g_return_if_fail (GTK_IS_WIDGET (widget));
7401 widget->priv->redraw_on_alloc = redraw_on_allocate;
7405 * gtk_widget_set_sensitive:
7406 * @widget: a #GtkWidget
7407 * @sensitive: %TRUE to make the widget sensitive
7409 * Sets the sensitivity of a widget. A widget is sensitive if the user
7410 * can interact with it. Insensitive widgets are "grayed out" and the
7411 * user can't interact with them. Insensitive widgets are known as
7412 * "inactive", "disabled", or "ghosted" in some other toolkits.
7415 gtk_widget_set_sensitive (GtkWidget *widget,
7418 GtkWidgetPrivate *priv;
7421 g_return_if_fail (GTK_IS_WIDGET (widget));
7423 priv = widget->priv;
7425 sensitive = (sensitive != FALSE);
7427 if (widget->priv->sensitive == sensitive)
7430 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7434 widget->priv->sensitive = TRUE;
7435 data.operation = STATE_CHANGE_UNSET;
7439 widget->priv->sensitive = FALSE;
7440 data.operation = STATE_CHANGE_SET;
7443 data.use_forall = TRUE;
7446 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7448 data.parent_sensitive = TRUE;
7450 gtk_widget_propagate_state (widget, &data);
7452 if (gtk_widget_is_drawable (widget))
7453 gtk_widget_queue_draw (widget);
7455 g_object_notify (G_OBJECT (widget), "sensitive");
7459 * gtk_widget_get_sensitive:
7460 * @widget: a #GtkWidget
7462 * Returns the widget's sensitivity (in the sense of returning
7463 * the value that has been set using gtk_widget_set_sensitive()).
7465 * The effective sensitivity of a widget is however determined by both its
7466 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7468 * Returns: %TRUE if the widget is sensitive
7473 gtk_widget_get_sensitive (GtkWidget *widget)
7475 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7477 return widget->priv->sensitive;
7481 * gtk_widget_is_sensitive:
7482 * @widget: a #GtkWidget
7484 * Returns the widget's effective sensitivity, which means
7485 * it is sensitive itself and also its parent widget is sensntive
7487 * Returns: %TRUE if the widget is effectively sensitive
7492 gtk_widget_is_sensitive (GtkWidget *widget)
7494 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7496 return widget->priv->sensitive && widget->priv->parent_sensitive;
7500 _gtk_widget_update_path (GtkWidget *widget)
7502 if (widget->priv->path)
7504 gtk_widget_path_free (widget->priv->path);
7505 widget->priv->path = NULL;
7508 gtk_widget_get_path (widget);
7512 * gtk_widget_set_parent:
7513 * @widget: a #GtkWidget
7514 * @parent: parent container
7516 * This function is useful only when implementing subclasses of
7518 * Sets the container as the parent of @widget, and takes care of
7519 * some details such as updating the state and style of the child
7520 * to reflect its new location. The opposite function is
7521 * gtk_widget_unparent().
7524 gtk_widget_set_parent (GtkWidget *widget,
7527 GtkStateFlags parent_flags;
7528 GtkWidgetPrivate *priv;
7531 g_return_if_fail (GTK_IS_WIDGET (widget));
7532 g_return_if_fail (GTK_IS_WIDGET (parent));
7533 g_return_if_fail (widget != parent);
7535 priv = widget->priv;
7537 if (priv->parent != NULL)
7539 g_warning ("Can't set a parent on widget which has a parent\n");
7542 if (gtk_widget_is_toplevel (widget))
7544 g_warning ("Can't set a parent on a toplevel widget\n");
7548 /* keep this function in sync with gtk_menu_attach_to_widget()
7551 g_object_ref_sink (widget);
7552 priv->parent = parent;
7554 parent_flags = gtk_widget_get_state_flags (parent);
7556 /* Merge both old state and current parent state,
7557 * We don't want the insensitive flag to propagate
7558 * to the new child though */
7559 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7560 data.flags |= priv->state_flags;
7562 data.operation = STATE_CHANGE_REPLACE;
7563 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7564 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7565 gtk_widget_propagate_state (widget, &data);
7567 gtk_widget_reset_rc_styles (widget);
7569 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7570 if (priv->parent->priv->anchored)
7571 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7572 g_object_notify (G_OBJECT (widget), "parent");
7574 /* Enforce realized/mapped invariants
7576 if (gtk_widget_get_realized (priv->parent))
7577 gtk_widget_realize (widget);
7579 if (gtk_widget_get_visible (priv->parent) &&
7580 gtk_widget_get_visible (widget))
7582 if (gtk_widget_get_child_visible (widget) &&
7583 gtk_widget_get_mapped (priv->parent))
7584 gtk_widget_map (widget);
7586 gtk_widget_queue_resize (widget);
7589 /* child may cause parent's expand to change, if the child is
7590 * expanded. If child is not expanded, then it can't modify the
7591 * parent's expand. If the child becomes expanded later then it will
7592 * queue compute_expand then. This optimization plus defaulting
7593 * newly-constructed widgets to need_compute_expand=FALSE should
7594 * mean that initially building a widget tree doesn't have to keep
7595 * walking up setting need_compute_expand on parents over and over.
7597 * We can't change a parent to need to expand unless we're visible.
7599 if (gtk_widget_get_visible (widget) &&
7600 (priv->need_compute_expand ||
7601 priv->computed_hexpand ||
7602 priv->computed_vexpand))
7604 gtk_widget_queue_compute_expand (parent);
7607 if (widget->priv->context)
7609 _gtk_widget_update_path (widget);
7610 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7612 gtk_style_context_set_screen (widget->priv->context,
7613 gtk_widget_get_screen (widget));
7618 * gtk_widget_get_parent:
7619 * @widget: a #GtkWidget
7621 * Returns the parent container of @widget.
7623 * Return value: (transfer none): the parent container of @widget, or %NULL
7626 gtk_widget_get_parent (GtkWidget *widget)
7628 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7630 return widget->priv->parent;
7633 /*****************************************
7635 * see docs/styles.txt
7636 *****************************************/
7639 * gtk_widget_style_attach:
7640 * @widget: a #GtkWidget
7642 * This function attaches the widget's #GtkStyle to the widget's
7643 * #GdkWindow. It is a replacement for
7646 * widget->style = gtk_style_attach (widget->style, widget->window);
7649 * and should only ever be called in a derived widget's "realize"
7650 * implementation which does not chain up to its parent class'
7651 * "realize" implementation, because one of the parent classes
7652 * (finally #GtkWidget) would attach the style itself.
7657 gtk_widget_style_attach (GtkWidget *widget)
7659 GtkWidgetPrivate *priv;
7661 g_return_if_fail (GTK_IS_WIDGET (widget));
7662 g_return_if_fail (gtk_widget_get_realized (widget));
7664 priv = widget->priv;
7666 priv->style = gtk_style_attach (priv->style, priv->window);
7670 * gtk_widget_has_rc_style:
7671 * @widget: a #GtkWidget
7673 * Determines if the widget style has been looked up through the rc mechanism.
7675 * Returns: %TRUE if the widget has been looked up through the rc
7676 * mechanism, %FALSE otherwise.
7680 * Deprecated:3.0: Use #GtkStyleContext instead
7683 gtk_widget_has_rc_style (GtkWidget *widget)
7685 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7687 return widget->priv->rc_style;
7691 * gtk_widget_set_style:
7692 * @widget: a #GtkWidget
7693 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7694 * gtk_widget_set_style() and go back to the default style
7696 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7697 * want to use this function; it interacts badly with themes, because
7698 * themes work by replacing the #GtkStyle. Instead, use
7699 * gtk_widget_modify_style().
7701 * Deprecated:3.0: Use #GtkStyleContext instead
7704 gtk_widget_set_style (GtkWidget *widget,
7707 g_return_if_fail (GTK_IS_WIDGET (widget));
7711 gboolean initial_emission;
7713 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7715 widget->priv->rc_style = FALSE;
7716 widget->priv->user_style = TRUE;
7718 gtk_widget_set_style_internal (widget, style, initial_emission);
7722 if (widget->priv->user_style)
7723 gtk_widget_reset_rc_style (widget);
7728 * gtk_widget_ensure_style:
7729 * @widget: a #GtkWidget
7731 * Ensures that @widget has a style (@widget->style). Not a very useful
7732 * function; most of the time, if you want the style, the widget is
7733 * realized, and realized widgets are guaranteed to have a style
7736 * Deprecated:3.0: Use #GtkStyleContext instead
7739 gtk_widget_ensure_style (GtkWidget *widget)
7741 g_return_if_fail (GTK_IS_WIDGET (widget));
7743 if (!widget->priv->style ||
7744 !gtk_style_has_context (widget->priv->style))
7748 style = g_object_new (GTK_TYPE_STYLE,
7749 "context", gtk_widget_get_style_context (widget),
7752 gtk_widget_set_style_internal (widget, style, TRUE);
7753 g_object_unref (style);
7757 if (!widget->priv->rc_style && !widget->priv->user_style)
7758 gtk_widget_reset_rc_style (widget);
7762 /* Look up the RC style for this widget, unsetting any user style that
7763 * may be in effect currently
7766 gtk_widget_reset_rc_style (GtkWidget *widget)
7768 GtkWidgetPrivate *priv = widget->priv;
7769 GtkStyle *new_style = NULL;
7770 gboolean initial_emission;
7772 initial_emission = !priv->rc_style && !priv->user_style;
7774 priv->user_style = FALSE;
7775 priv->rc_style = TRUE;
7777 if (gtk_widget_has_screen (widget))
7778 new_style = gtk_rc_get_style (widget);
7780 new_style = gtk_widget_get_default_style ();
7782 if (initial_emission || new_style != priv->style)
7783 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7787 * gtk_widget_get_style:
7788 * @widget: a #GtkWidget
7790 * Simply an accessor function that returns @widget->style.
7792 * Return value: (transfer none): the widget's #GtkStyle
7794 * Deprecated:3.0: Use #GtkStyleContext instead
7797 gtk_widget_get_style (GtkWidget *widget)
7799 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7801 return widget->priv->style;
7805 * gtk_widget_modify_style:
7806 * @widget: a #GtkWidget
7807 * @style: the #GtkRcStyle holding the style modifications
7809 * Modifies style values on the widget. Modifications made using this
7810 * technique take precedence over style values set via an RC file,
7811 * however, they will be overriden if a style is explicitely set on
7812 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7813 * is designed so each field can either be set or unset, so it is
7814 * possible, using this function, to modify some style values and
7815 * leave the others unchanged.
7817 * Note that modifications made with this function are not cumulative
7818 * with previous calls to gtk_widget_modify_style() or with such
7819 * functions as gtk_widget_modify_fg(). If you wish to retain
7820 * previous values, you must first call gtk_widget_get_modifier_style(),
7821 * make your modifications to the returned style, then call
7822 * gtk_widget_modify_style() with that style. On the other hand,
7823 * if you first call gtk_widget_modify_style(), subsequent calls
7824 * to such functions gtk_widget_modify_fg() will have a cumulative
7825 * effect with the initial modifications.
7827 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7830 gtk_widget_modify_style (GtkWidget *widget,
7833 g_return_if_fail (GTK_IS_WIDGET (widget));
7834 g_return_if_fail (GTK_IS_RC_STYLE (style));
7836 g_object_set_qdata_full (G_OBJECT (widget),
7838 gtk_rc_style_copy (style),
7839 (GDestroyNotify) g_object_unref);
7841 /* note that "style" may be invalid here if it was the old
7842 * modifier style and the only reference was our own.
7845 if (widget->priv->rc_style)
7846 gtk_widget_reset_rc_style (widget);
7850 * gtk_widget_get_modifier_style:
7851 * @widget: a #GtkWidget
7853 * Returns the current modifier style for the widget. (As set by
7854 * gtk_widget_modify_style().) If no style has previously set, a new
7855 * #GtkRcStyle will be created with all values unset, and set as the
7856 * modifier style for the widget. If you make changes to this rc
7857 * style, you must call gtk_widget_modify_style(), passing in the
7858 * returned rc style, to make sure that your changes take effect.
7860 * Caution: passing the style back to gtk_widget_modify_style() will
7861 * normally end up destroying it, because gtk_widget_modify_style() copies
7862 * the passed-in style and sets the copy as the new modifier style,
7863 * thus dropping any reference to the old modifier style. Add a reference
7864 * to the modifier style if you want to keep it alive.
7866 * Return value: (transfer none): the modifier style for the widget.
7867 * This rc style is owned by the widget. If you want to keep a
7868 * pointer to value this around, you must add a refcount using
7871 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7874 gtk_widget_get_modifier_style (GtkWidget *widget)
7876 GtkRcStyle *rc_style;
7878 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7880 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7884 rc_style = gtk_rc_style_new ();
7885 g_object_set_qdata_full (G_OBJECT (widget),
7888 (GDestroyNotify) g_object_unref);
7895 gtk_widget_modify_color_component (GtkWidget *widget,
7896 GtkRcFlags component,
7898 const GdkColor *color)
7900 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7907 rc_style->fg[state] = *color;
7910 rc_style->bg[state] = *color;
7913 rc_style->text[state] = *color;
7916 rc_style->base[state] = *color;
7919 g_assert_not_reached();
7922 rc_style->color_flags[state] |= component;
7925 rc_style->color_flags[state] &= ~component;
7927 gtk_widget_modify_style (widget, rc_style);
7931 modifier_style_changed (GtkModifierStyle *style,
7934 GtkStyleContext *context;
7936 context = gtk_widget_get_style_context (widget);
7937 gtk_style_context_invalidate (context);
7939 g_signal_emit (widget,
7940 widget_signals[STYLE_SET],
7942 widget->priv->style);
7945 static GtkModifierStyle *
7946 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7948 GtkModifierStyle *style;
7950 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7952 if (G_UNLIKELY (!style))
7954 GtkStyleContext *context;
7956 style = gtk_modifier_style_new ();
7957 g_object_set_qdata_full (G_OBJECT (widget),
7958 quark_modifier_style,
7960 (GDestroyNotify) g_object_unref);
7962 g_signal_connect (style, "changed",
7963 G_CALLBACK (modifier_style_changed), widget);
7965 context = gtk_widget_get_style_context (widget);
7967 gtk_style_context_add_provider (context,
7968 GTK_STYLE_PROVIDER (style),
7969 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7976 * gtk_widget_override_color:
7977 * @widget: a #GtkWidget
7978 * @state: the state for which to set the color
7979 * @color: the color to assign, or %NULL to undo the effect
7980 * of previous calls to gtk_widget_override_color()
7982 * Sets the color to use for a widget. All other style values are left
7987 * This API is mostly meant as a quick way for applications to change a
7988 * widget appearance. If you are developing a widgets library and intend
7989 * this change to be themeable, it is better done by setting meaningful
7990 * CSS classes and regions in your widget/container implementation through
7991 * gtk_style_context_add_class() and gtk_style_context_add_region().
7994 * This way, your widget library can install a #GtkCssProvider with the
7995 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
7996 * default styling for those widgets that need so, and this theming may
7997 * fully overridden by the user's theme.
8003 * Note that for complex widgets this may bring in
8004 * undesired results (such as uniform background color everywhere),
8005 * in these cases it is better to fully style such widgets through a
8006 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8014 gtk_widget_override_color (GtkWidget *widget,
8015 GtkStateFlags state,
8016 const GdkRGBA *color)
8018 GtkModifierStyle *style;
8020 g_return_if_fail (GTK_IS_WIDGET (widget));
8022 style = _gtk_widget_get_modifier_properties (widget);
8023 gtk_modifier_style_set_color (style, state, color);
8027 * gtk_widget_override_background_color:
8028 * @widget: a #GtkWidget
8029 * @state: the state for which to set the background color
8030 * @color: the color to assign, or %NULL to undo the effect
8031 * of previous calls to gtk_widget_override_background_color()
8033 * Sets the background color to use for a widget. All other style values
8034 * are left untouched. See gtk_widget_override_color().
8039 gtk_widget_override_background_color (GtkWidget *widget,
8040 GtkStateFlags state,
8041 const GdkRGBA *color)
8043 GtkModifierStyle *style;
8045 g_return_if_fail (GTK_IS_WIDGET (widget));
8047 style = _gtk_widget_get_modifier_properties (widget);
8048 gtk_modifier_style_set_background_color (style, state, color);
8052 * gtk_widget_override_font:
8053 * @widget: a #GtkWidget
8054 * @font_desc: the font descriptiong to use, or %NULL to undo
8055 * the effect of previous calls to
8056 * gtk_widget_override_font().
8058 * Sets the font to use for a widget. All other style values are
8059 * left untouched. See gtk_widget_override_color().
8064 gtk_widget_override_font (GtkWidget *widget,
8065 const PangoFontDescription *font_desc)
8067 GtkModifierStyle *style;
8069 g_return_if_fail (GTK_IS_WIDGET (widget));
8071 style = _gtk_widget_get_modifier_properties (widget);
8072 gtk_modifier_style_set_font (style, font_desc);
8076 * gtk_widget_override_symbolic_color:
8077 * @widget: a #GtkWidget
8078 * @name: the name of the symbolic color to modify
8079 * @color: (allow-none): the color to assign (does not need to be allocated),
8080 * or %NULL to undo the effect of previous calls to
8081 * gtk_widget_override_symbolic_color().
8083 * Sets a symbolic color for a widget, All other style values are left
8084 * untouched. See gtk_widget_override_color() for overriding the foreground
8085 * or background color.
8090 gtk_widget_override_symbolic_color (GtkWidget *widget,
8092 const GdkRGBA *color)
8094 GtkModifierStyle *style;
8096 g_return_if_fail (GTK_IS_WIDGET (widget));
8098 style = _gtk_widget_get_modifier_properties (widget);
8099 gtk_modifier_style_map_color (style, name, color);
8103 * gtk_widget_override_cursor:
8104 * @widget: a #GtkWidget
8105 * @primary: the color to use for primary cursor (does not need to be
8106 * allocated), or %NULL to undo the effect of previous calls to
8107 * of gtk_widget_override_cursor().
8108 * @secondary: the color to use for secondary cursor (does not need to be
8109 * allocated), or %NULL to undo the effect of previous calls to
8110 * of gtk_widget_override_cursor().
8112 * Sets the cursor color to use in a widget, overriding the
8113 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8114 * style properties. All other style values are left untouched.
8115 * See also gtk_widget_modify_style().
8117 * Note that the underlying properties have the #GdkColor type,
8118 * so the alpha value in @primary and @secondary will be ignored.
8123 gtk_widget_override_cursor (GtkWidget *widget,
8124 const GdkRGBA *cursor,
8125 const GdkRGBA *secondary_cursor)
8127 GtkModifierStyle *style;
8129 g_return_if_fail (GTK_IS_WIDGET (widget));
8131 style = _gtk_widget_get_modifier_properties (widget);
8132 gtk_modifier_style_set_color_property (style,
8134 "cursor-color", cursor);
8135 gtk_modifier_style_set_color_property (style,
8137 "secondary-cursor-color",
8142 * gtk_widget_modify_fg:
8143 * @widget: a #GtkWidget
8144 * @state: the state for which to set the foreground color
8145 * @color: (allow-none): the color to assign (does not need to be allocated),
8146 * or %NULL to undo the effect of previous calls to
8147 * of gtk_widget_modify_fg().
8149 * Sets the foreground color for a widget in a particular state.
8150 * All other style values are left untouched. See also
8151 * gtk_widget_modify_style().
8153 * Deprecated:3.0: Use gtk_widget_override_color() instead
8156 gtk_widget_modify_fg (GtkWidget *widget,
8158 const GdkColor *color)
8160 GtkStateFlags flags;
8163 g_return_if_fail (GTK_IS_WIDGET (widget));
8164 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8168 case GTK_STATE_ACTIVE:
8169 flags = GTK_STATE_FLAG_ACTIVE;
8171 case GTK_STATE_PRELIGHT:
8172 flags = GTK_STATE_FLAG_PRELIGHT;
8174 case GTK_STATE_SELECTED:
8175 flags = GTK_STATE_FLAG_SELECTED;
8177 case GTK_STATE_INSENSITIVE:
8178 flags = GTK_STATE_FLAG_INSENSITIVE;
8180 case GTK_STATE_NORMAL:
8187 rgba.red = color->red / 65535.;
8188 rgba.green = color->green / 65535.;
8189 rgba.blue = color->blue / 65535.;
8192 gtk_widget_override_color (widget, state, &rgba);
8195 gtk_widget_override_color (widget, state, NULL);
8199 * gtk_widget_modify_bg:
8200 * @widget: a #GtkWidget
8201 * @state: the state for which to set the background color
8202 * @color: (allow-none): the color to assign (does not need to be allocated),
8203 * or %NULL to undo the effect of previous calls to
8204 * of gtk_widget_modify_bg().
8206 * Sets the background color for a widget in a particular state.
8207 * All other style values are left untouched. See also
8208 * gtk_widget_modify_style().
8210 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8211 * draw on their parent container's window and thus may not draw any
8212 * background themselves. This is the case for e.g. #GtkLabel. To modify
8213 * the background of such widgets, you have to set the background color
8214 * on their parent; if you want to set the background of a rectangular
8215 * area around a label, try placing the label in a #GtkEventBox widget
8216 * and setting the background color on that.
8218 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8221 gtk_widget_modify_bg (GtkWidget *widget,
8223 const GdkColor *color)
8225 GtkStateFlags flags;
8228 g_return_if_fail (GTK_IS_WIDGET (widget));
8229 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8233 case GTK_STATE_ACTIVE:
8234 flags = GTK_STATE_FLAG_ACTIVE;
8236 case GTK_STATE_PRELIGHT:
8237 flags = GTK_STATE_FLAG_PRELIGHT;
8239 case GTK_STATE_SELECTED:
8240 flags = GTK_STATE_FLAG_SELECTED;
8242 case GTK_STATE_INSENSITIVE:
8243 flags = GTK_STATE_FLAG_INSENSITIVE;
8245 case GTK_STATE_NORMAL:
8252 rgba.red = color->red / 65535.;
8253 rgba.green = color->green / 65535.;
8254 rgba.blue = color->blue / 65535.;
8257 gtk_widget_override_background_color (widget, state, &rgba);
8260 gtk_widget_override_background_color (widget, state, NULL);
8264 * gtk_widget_modify_text:
8265 * @widget: a #GtkWidget
8266 * @state: the state for which to set the text color
8267 * @color: (allow-none): the color to assign (does not need to be allocated),
8268 * or %NULL to undo the effect of previous calls to
8269 * of gtk_widget_modify_text().
8271 * Sets the text color for a widget in a particular state. All other
8272 * style values are left untouched. The text color is the foreground
8273 * color used along with the base color (see gtk_widget_modify_base())
8274 * for widgets such as #GtkEntry and #GtkTextView. See also
8275 * gtk_widget_modify_style().
8277 * Deprecated:3.0: Use gtk_widget_override_color() instead
8280 gtk_widget_modify_text (GtkWidget *widget,
8282 const GdkColor *color)
8284 g_return_if_fail (GTK_IS_WIDGET (widget));
8285 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8287 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8291 * gtk_widget_modify_base:
8292 * @widget: a #GtkWidget
8293 * @state: the state for which to set the base color
8294 * @color: (allow-none): the color to assign (does not need to be allocated),
8295 * or %NULL to undo the effect of previous calls to
8296 * of gtk_widget_modify_base().
8298 * Sets the base color for a widget in a particular state.
8299 * All other style values are left untouched. The base color
8300 * is the background color used along with the text color
8301 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8302 * and #GtkTextView. See also gtk_widget_modify_style().
8304 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8305 * draw on their parent container's window and thus may not draw any
8306 * background themselves. This is the case for e.g. #GtkLabel. To modify
8307 * the background of such widgets, you have to set the base color on their
8308 * parent; if you want to set the background of a rectangular area around
8309 * a label, try placing the label in a #GtkEventBox widget and setting
8310 * the base color on that.
8312 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8315 gtk_widget_modify_base (GtkWidget *widget,
8317 const GdkColor *color)
8319 g_return_if_fail (GTK_IS_WIDGET (widget));
8320 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8322 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8326 modify_color_property (GtkWidget *widget,
8327 GtkRcStyle *rc_style,
8329 const GdkColor *color)
8331 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
8332 GQuark property_name = g_quark_from_string (name);
8336 GtkRcProperty rc_property = {0};
8339 rc_property.type_name = type_name;
8340 rc_property.property_name = property_name;
8341 rc_property.origin = NULL;
8343 color_name = gdk_color_to_string (color);
8344 g_value_init (&rc_property.value, G_TYPE_STRING);
8345 g_value_take_string (&rc_property.value, color_name);
8347 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
8349 g_value_unset (&rc_property.value);
8352 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
8356 * gtk_widget_modify_cursor:
8357 * @widget: a #GtkWidget
8358 * @primary: the color to use for primary cursor (does not need to be
8359 * allocated), or %NULL to undo the effect of previous calls to
8360 * of gtk_widget_modify_cursor().
8361 * @secondary: the color to use for secondary cursor (does not need to be
8362 * allocated), or %NULL to undo the effect of previous calls to
8363 * of gtk_widget_modify_cursor().
8365 * Sets the cursor color to use in a widget, overriding the
8366 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8367 * style properties. All other style values are left untouched.
8368 * See also gtk_widget_modify_style().
8372 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8375 gtk_widget_modify_cursor (GtkWidget *widget,
8376 const GdkColor *primary,
8377 const GdkColor *secondary)
8379 GdkRGBA primary_rgba, secondary_rgba;
8381 g_return_if_fail (GTK_IS_WIDGET (widget));
8383 primary_rgba.red = primary->red / 65535.;
8384 primary_rgba.green = primary->green / 65535.;
8385 primary_rgba.blue = primary->blue / 65535.;
8386 primary_rgba.alpha = 1;
8388 secondary_rgba.red = secondary->red / 65535.;
8389 secondary_rgba.green = secondary->green / 65535.;
8390 secondary_rgba.blue = secondary->blue / 65535.;
8391 secondary_rgba.alpha = 1;
8393 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8397 * gtk_widget_modify_font:
8398 * @widget: a #GtkWidget
8399 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8400 * the effect of previous calls to gtk_widget_modify_font().
8402 * Sets the font to use for a widget. All other style values are left
8403 * untouched. See also gtk_widget_modify_style().
8405 * Deprecated:3.0: Use gtk_widget_override_font() instead
8408 gtk_widget_modify_font (GtkWidget *widget,
8409 PangoFontDescription *font_desc)
8411 g_return_if_fail (GTK_IS_WIDGET (widget));
8413 gtk_widget_override_font (widget, font_desc);
8417 gtk_widget_real_direction_changed (GtkWidget *widget,
8418 GtkTextDirection previous_direction)
8420 gtk_widget_queue_resize (widget);
8424 gtk_widget_real_style_set (GtkWidget *widget,
8425 GtkStyle *previous_style)
8427 GtkWidgetPrivate *priv = widget->priv;
8429 if (gtk_widget_get_realized (widget) &&
8430 gtk_widget_get_has_window (widget))
8431 gtk_style_set_background (priv->style, priv->window,
8432 gtk_widget_get_state (widget));
8436 gtk_widget_set_style_internal (GtkWidget *widget,
8438 gboolean initial_emission)
8440 GtkWidgetPrivate *priv = widget->priv;
8442 g_object_ref (widget);
8443 g_object_freeze_notify (G_OBJECT (widget));
8445 if (priv->style != style)
8447 GtkStyle *previous_style;
8449 if (gtk_widget_get_realized (widget))
8451 gtk_widget_reset_shapes (widget);
8452 gtk_style_detach (priv->style);
8455 previous_style = priv->style;
8456 priv->style = style;
8457 g_object_ref (priv->style);
8459 if (gtk_widget_get_realized (widget))
8460 priv->style = gtk_style_attach (priv->style, priv->window);
8462 gtk_widget_update_pango_context (widget);
8463 g_signal_emit (widget,
8464 widget_signals[STYLE_SET],
8466 initial_emission ? NULL : previous_style);
8467 g_object_unref (previous_style);
8469 if (priv->anchored && !initial_emission)
8470 gtk_widget_queue_resize (widget);
8472 else if (initial_emission)
8474 gtk_widget_update_pango_context (widget);
8475 g_signal_emit (widget,
8476 widget_signals[STYLE_SET],
8480 g_object_notify (G_OBJECT (widget), "style");
8481 g_object_thaw_notify (G_OBJECT (widget));
8482 g_object_unref (widget);
8486 GtkWidget *previous_toplevel;
8487 GdkScreen *previous_screen;
8488 GdkScreen *new_screen;
8489 } HierarchyChangedInfo;
8492 do_screen_change (GtkWidget *widget,
8493 GdkScreen *old_screen,
8494 GdkScreen *new_screen)
8496 if (old_screen != new_screen)
8498 GtkStyleContext *context;
8502 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8504 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8507 _gtk_tooltip_hide (widget);
8509 context = gtk_widget_get_style_context (widget);
8510 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8512 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8517 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8518 gpointer client_data)
8520 GtkWidgetPrivate *priv = widget->priv;
8521 HierarchyChangedInfo *info = client_data;
8522 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8523 (priv->parent && priv->parent->priv->anchored);
8525 if (priv->anchored != new_anchored)
8527 g_object_ref (widget);
8529 priv->anchored = new_anchored;
8531 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8532 do_screen_change (widget, info->previous_screen, info->new_screen);
8534 if (GTK_IS_CONTAINER (widget))
8535 gtk_container_forall (GTK_CONTAINER (widget),
8536 gtk_widget_propagate_hierarchy_changed_recurse,
8539 g_object_unref (widget);
8544 * _gtk_widget_propagate_hierarchy_changed:
8545 * @widget: a #GtkWidget
8546 * @previous_toplevel: Previous toplevel
8548 * Propagates changes in the anchored state to a widget and all
8549 * children, unsetting or setting the %ANCHORED flag, and
8550 * emitting #GtkWidget::hierarchy-changed.
8553 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8554 GtkWidget *previous_toplevel)
8556 GtkWidgetPrivate *priv = widget->priv;
8557 HierarchyChangedInfo info;
8559 info.previous_toplevel = previous_toplevel;
8560 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8562 if (gtk_widget_is_toplevel (widget) ||
8563 (priv->parent && priv->parent->priv->anchored))
8564 info.new_screen = gtk_widget_get_screen (widget);
8566 info.new_screen = NULL;
8568 if (info.previous_screen)
8569 g_object_ref (info.previous_screen);
8570 if (previous_toplevel)
8571 g_object_ref (previous_toplevel);
8573 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8575 if (previous_toplevel)
8576 g_object_unref (previous_toplevel);
8577 if (info.previous_screen)
8578 g_object_unref (info.previous_screen);
8582 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8583 gpointer client_data)
8585 HierarchyChangedInfo *info = client_data;
8587 g_object_ref (widget);
8589 do_screen_change (widget, info->previous_screen, info->new_screen);
8591 if (GTK_IS_CONTAINER (widget))
8592 gtk_container_forall (GTK_CONTAINER (widget),
8593 gtk_widget_propagate_screen_changed_recurse,
8596 g_object_unref (widget);
8600 * gtk_widget_is_composited:
8601 * @widget: a #GtkWidget
8603 * Whether @widget can rely on having its alpha channel
8604 * drawn correctly. On X11 this function returns whether a
8605 * compositing manager is running for @widget's screen.
8607 * Please note that the semantics of this call will change
8608 * in the future if used on a widget that has a composited
8609 * window in its hierarchy (as set by gdk_window_set_composited()).
8611 * Return value: %TRUE if the widget can rely on its alpha
8612 * channel being drawn correctly.
8617 gtk_widget_is_composited (GtkWidget *widget)
8621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8623 screen = gtk_widget_get_screen (widget);
8625 return gdk_screen_is_composited (screen);
8629 propagate_composited_changed (GtkWidget *widget,
8632 if (GTK_IS_CONTAINER (widget))
8634 gtk_container_forall (GTK_CONTAINER (widget),
8635 propagate_composited_changed,
8639 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8643 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8645 propagate_composited_changed (widget, NULL);
8649 * _gtk_widget_propagate_screen_changed:
8650 * @widget: a #GtkWidget
8651 * @previous_screen: Previous screen
8653 * Propagates changes in the screen for a widget to all
8654 * children, emitting #GtkWidget::screen-changed.
8657 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8658 GdkScreen *previous_screen)
8660 HierarchyChangedInfo info;
8662 info.previous_screen = previous_screen;
8663 info.new_screen = gtk_widget_get_screen (widget);
8665 if (previous_screen)
8666 g_object_ref (previous_screen);
8668 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8670 if (previous_screen)
8671 g_object_unref (previous_screen);
8675 reset_style_recurse (GtkWidget *widget, gpointer data)
8678 if (widget->priv->rc_style)
8679 gtk_widget_reset_rc_style (widget);
8682 if (widget->priv->context)
8684 _gtk_widget_update_path (widget);
8685 gtk_style_context_set_path (widget->priv->context,
8686 widget->priv->path);
8689 if (GTK_IS_CONTAINER (widget))
8690 gtk_container_forall (GTK_CONTAINER (widget),
8691 reset_style_recurse,
8696 gtk_widget_reset_style (GtkWidget *widget)
8698 g_return_if_fail (GTK_IS_WIDGET (widget));
8700 reset_style_recurse (widget, NULL);
8704 * gtk_widget_reset_rc_styles:
8705 * @widget: a #GtkWidget.
8707 * Reset the styles of @widget and all descendents, so when
8708 * they are looked up again, they get the correct values
8709 * for the currently loaded RC file settings.
8711 * This function is not useful for applications.
8713 * Deprecated:3.0: Use #GtkStyleContext instead
8716 gtk_widget_reset_rc_styles (GtkWidget *widget)
8718 g_return_if_fail (GTK_IS_WIDGET (widget));
8720 reset_style_recurse (widget, NULL);
8724 * gtk_widget_get_default_style:
8726 * Returns the default style used by all widgets initially.
8728 * Returns: (transfer none): the default style. This #GtkStyle
8729 * object is owned by GTK+ and should not be modified or freed.
8731 * Deprecated:3.0: Use #GtkStyleContext instead
8734 gtk_widget_get_default_style (void)
8736 if (!gtk_default_style)
8738 gtk_default_style = gtk_style_new ();
8739 g_object_ref (gtk_default_style);
8742 return gtk_default_style;
8745 static PangoContext *
8746 gtk_widget_peek_pango_context (GtkWidget *widget)
8748 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8752 * gtk_widget_get_pango_context:
8753 * @widget: a #GtkWidget
8755 * Gets a #PangoContext with the appropriate font map, font description,
8756 * and base direction for this widget. Unlike the context returned
8757 * by gtk_widget_create_pango_context(), this context is owned by
8758 * the widget (it can be used until the screen for the widget changes
8759 * or the widget is removed from its toplevel), and will be updated to
8760 * match any changes to the widget's attributes.
8762 * If you create and keep a #PangoLayout using this context, you must
8763 * deal with changes to the context by calling pango_layout_context_changed()
8764 * on the layout in response to the #GtkWidget::style-set and
8765 * #GtkWidget::direction-changed signals for the widget.
8767 * Return value: (transfer none): the #PangoContext for the widget.
8770 gtk_widget_get_pango_context (GtkWidget *widget)
8772 PangoContext *context;
8774 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8776 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8779 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8780 g_object_set_qdata_full (G_OBJECT (widget),
8781 quark_pango_context,
8790 update_pango_context (GtkWidget *widget,
8791 PangoContext *context)
8793 PangoFontDescription *font_desc;
8794 GtkStyleContext *style_context;
8796 style_context = gtk_widget_get_style_context (widget);
8798 gtk_style_context_get (style_context,
8799 gtk_widget_get_state_flags (widget),
8803 pango_context_set_font_description (context, font_desc);
8804 pango_context_set_base_dir (context,
8805 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8806 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8808 pango_font_description_free (font_desc);
8812 gtk_widget_update_pango_context (GtkWidget *widget)
8814 PangoContext *context = gtk_widget_peek_pango_context (widget);
8820 update_pango_context (widget, context);
8822 screen = gtk_widget_get_screen_unchecked (widget);
8825 pango_cairo_context_set_resolution (context,
8826 gdk_screen_get_resolution (screen));
8827 pango_cairo_context_set_font_options (context,
8828 gdk_screen_get_font_options (screen));
8834 * gtk_widget_create_pango_context:
8835 * @widget: a #GtkWidget
8837 * Creates a new #PangoContext with the appropriate font map,
8838 * font description, and base direction for drawing text for
8839 * this widget. See also gtk_widget_get_pango_context().
8841 * Return value: (transfer full): the new #PangoContext
8844 gtk_widget_create_pango_context (GtkWidget *widget)
8847 PangoContext *context;
8849 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8851 screen = gtk_widget_get_screen_unchecked (widget);
8854 GTK_NOTE (MULTIHEAD,
8855 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8857 screen = gdk_screen_get_default ();
8860 context = gdk_pango_context_get_for_screen (screen);
8862 update_pango_context (widget, context);
8863 pango_context_set_language (context, gtk_get_default_language ());
8869 * gtk_widget_create_pango_layout:
8870 * @widget: a #GtkWidget
8871 * @text: text to set on the layout (can be %NULL)
8873 * Creates a new #PangoLayout with the appropriate font map,
8874 * font description, and base direction for drawing text for
8877 * If you keep a #PangoLayout created in this way around, in order to
8878 * notify the layout of changes to the base direction or font of this
8879 * widget, you must call pango_layout_context_changed() in response to
8880 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8883 * Return value: (transfer full): the new #PangoLayout
8886 gtk_widget_create_pango_layout (GtkWidget *widget,
8889 PangoLayout *layout;
8890 PangoContext *context;
8892 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8894 context = gtk_widget_get_pango_context (widget);
8895 layout = pango_layout_new (context);
8898 pango_layout_set_text (layout, text, -1);
8904 * gtk_widget_render_icon_pixbuf:
8905 * @widget: a #GtkWidget
8906 * @stock_id: a stock ID
8907 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8908 * render at the size of the source and don't scale (if there are
8909 * multiple source sizes, GTK+ picks one of the available sizes).
8911 * A convenience function that uses the theme engine and style
8912 * settings for @widget to look up @stock_id and render it to
8913 * a pixbuf. @stock_id should be a stock icon ID such as
8914 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8915 * such as #GTK_ICON_SIZE_MENU.
8917 * The pixels in the returned #GdkPixbuf are shared with the rest of
8918 * the application and should not be modified. The pixbuf should be freed
8919 * after use with g_object_unref().
8921 * Return value: (transfer full): a new pixbuf, or %NULL if the
8922 * stock ID wasn't known
8927 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8928 const gchar *stock_id,
8931 GtkWidgetPrivate *priv;
8932 GtkIconSet *icon_set;
8934 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8935 g_return_val_if_fail (stock_id != NULL, NULL);
8936 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8938 priv = widget->priv;
8940 gtk_widget_ensure_style (widget);
8942 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
8944 if (icon_set == NULL)
8947 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
8951 * gtk_widget_render_icon:
8952 * @widget: a #GtkWidget
8953 * @stock_id: a stock ID
8954 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8955 * render at the size of the source and don't scale (if there are
8956 * multiple source sizes, GTK+ picks one of the available sizes).
8957 * @detail: (allow-none): render detail to pass to theme engine
8959 * A convenience function that uses the theme engine and RC file
8960 * settings for @widget to look up @stock_id and render it to
8961 * a pixbuf. @stock_id should be a stock icon ID such as
8962 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8963 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8964 * identifies the widget or code doing the rendering, so that
8965 * theme engines can special-case rendering for that widget or code.
8967 * The pixels in the returned #GdkPixbuf are shared with the rest of
8968 * the application and should not be modified. The pixbuf should be freed
8969 * after use with g_object_unref().
8971 * Return value: (transfer full): a new pixbuf, or %NULL if the
8972 * stock ID wasn't known
8974 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
8977 gtk_widget_render_icon (GtkWidget *widget,
8978 const gchar *stock_id,
8980 const gchar *detail)
8982 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
8986 * gtk_widget_set_parent_window:
8987 * @widget: a #GtkWidget.
8988 * @parent_window: the new parent window.
8990 * Sets a non default parent window for @widget.
8993 gtk_widget_set_parent_window (GtkWidget *widget,
8994 GdkWindow *parent_window)
8996 GdkWindow *old_parent_window;
8998 g_return_if_fail (GTK_IS_WIDGET (widget));
9000 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9001 quark_parent_window);
9003 if (parent_window != old_parent_window)
9005 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9007 if (old_parent_window)
9008 g_object_unref (old_parent_window);
9010 g_object_ref (parent_window);
9015 * gtk_widget_get_parent_window:
9016 * @widget: a #GtkWidget.
9018 * Gets @widget's parent window.
9020 * Returns: (transfer none): the parent window of @widget.
9023 gtk_widget_get_parent_window (GtkWidget *widget)
9025 GtkWidgetPrivate *priv;
9026 GdkWindow *parent_window;
9028 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9030 priv = widget->priv;
9032 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9034 return (parent_window != NULL) ? parent_window :
9035 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9040 * gtk_widget_set_child_visible:
9041 * @widget: a #GtkWidget
9042 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9044 * Sets whether @widget should be mapped along with its when its parent
9045 * is mapped and @widget has been shown with gtk_widget_show().
9047 * The child visibility can be set for widget before it is added to
9048 * a container with gtk_widget_set_parent(), to avoid mapping
9049 * children unnecessary before immediately unmapping them. However
9050 * it will be reset to its default state of %TRUE when the widget
9051 * is removed from a container.
9053 * Note that changing the child visibility of a widget does not
9054 * queue a resize on the widget. Most of the time, the size of
9055 * a widget is computed from all visible children, whether or
9056 * not they are mapped. If this is not the case, the container
9057 * can queue a resize itself.
9059 * This function is only useful for container implementations and
9060 * never should be called by an application.
9063 gtk_widget_set_child_visible (GtkWidget *widget,
9064 gboolean is_visible)
9066 GtkWidgetPrivate *priv;
9068 g_return_if_fail (GTK_IS_WIDGET (widget));
9069 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9071 priv = widget->priv;
9073 g_object_ref (widget);
9076 priv->child_visible = TRUE;
9079 GtkWidget *toplevel;
9081 priv->child_visible = FALSE;
9083 toplevel = gtk_widget_get_toplevel (widget);
9084 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9085 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9088 if (priv->parent && gtk_widget_get_realized (priv->parent))
9090 if (gtk_widget_get_mapped (priv->parent) &&
9091 priv->child_visible &&
9092 gtk_widget_get_visible (widget))
9093 gtk_widget_map (widget);
9095 gtk_widget_unmap (widget);
9098 g_object_unref (widget);
9102 * gtk_widget_get_child_visible:
9103 * @widget: a #GtkWidget
9105 * Gets the value set with gtk_widget_set_child_visible().
9106 * If you feel a need to use this function, your code probably
9107 * needs reorganization.
9109 * This function is only useful for container implementations and
9110 * never should be called by an application.
9112 * Return value: %TRUE if the widget is mapped with the parent.
9115 gtk_widget_get_child_visible (GtkWidget *widget)
9117 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9119 return widget->priv->child_visible;
9123 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9125 GtkWidget *toplevel;
9127 toplevel = gtk_widget_get_toplevel (widget);
9129 if (gtk_widget_is_toplevel (toplevel))
9131 if (GTK_IS_WINDOW (toplevel))
9132 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9133 else if (GTK_IS_INVISIBLE (toplevel))
9134 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9141 * gtk_widget_get_screen:
9142 * @widget: a #GtkWidget
9144 * Get the #GdkScreen from the toplevel window associated with
9145 * this widget. This function can only be called after the widget
9146 * has been added to a widget hierarchy with a #GtkWindow
9149 * In general, you should only create screen specific
9150 * resources when a widget has been realized, and you should
9151 * free those resources when the widget is unrealized.
9153 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9158 gtk_widget_get_screen (GtkWidget *widget)
9162 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9164 screen = gtk_widget_get_screen_unchecked (widget);
9171 g_warning (G_STRLOC ": Can't get associated screen"
9172 " for a widget unless it is inside a toplevel GtkWindow\n"
9173 " widget type is %s associated top level type is %s",
9174 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9175 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9177 return gdk_screen_get_default ();
9182 * gtk_widget_has_screen:
9183 * @widget: a #GtkWidget
9185 * Checks whether there is a #GdkScreen is associated with
9186 * this widget. All toplevel widgets have an associated
9187 * screen, and all widgets added into a hierarchy with a toplevel
9188 * window at the top.
9190 * Return value: %TRUE if there is a #GdkScreen associcated
9196 gtk_widget_has_screen (GtkWidget *widget)
9198 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9200 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9204 * gtk_widget_get_display:
9205 * @widget: a #GtkWidget
9207 * Get the #GdkDisplay for the toplevel window associated with
9208 * this widget. This function can only be called after the widget
9209 * has been added to a widget hierarchy with a #GtkWindow at the top.
9211 * In general, you should only create display specific
9212 * resources when a widget has been realized, and you should
9213 * free those resources when the widget is unrealized.
9215 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9220 gtk_widget_get_display (GtkWidget *widget)
9222 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9224 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9228 * gtk_widget_get_root_window:
9229 * @widget: a #GtkWidget
9231 * Get the root window where this widget is located. This function can
9232 * only be called after the widget has been added to a widget
9233 * hierarchy with #GtkWindow at the top.
9235 * The root window is useful for such purposes as creating a popup
9236 * #GdkWindow associated with the window. In general, you should only
9237 * create display specific resources when a widget has been realized,
9238 * and you should free those resources when the widget is unrealized.
9240 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9245 gtk_widget_get_root_window (GtkWidget *widget)
9247 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9249 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9253 * gtk_widget_child_focus:
9254 * @widget: a #GtkWidget
9255 * @direction: direction of focus movement
9257 * This function is used by custom widget implementations; if you're
9258 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9259 * to a particular widget, and gtk_container_set_focus_chain() to
9260 * change the focus tab order. So you may want to investigate those
9261 * functions instead.
9263 * gtk_widget_child_focus() is called by containers as the user moves
9264 * around the window using keyboard shortcuts. @direction indicates
9265 * what kind of motion is taking place (up, down, left, right, tab
9266 * forward, tab backward). gtk_widget_child_focus() emits the
9267 * #GtkWidget::focus signal; widgets override the default handler
9268 * for this signal in order to implement appropriate focus behavior.
9270 * The default ::focus handler for a widget should return %TRUE if
9271 * moving in @direction left the focus on a focusable location inside
9272 * that widget, and %FALSE if moving in @direction moved the focus
9273 * outside the widget. If returning %TRUE, widgets normally
9274 * call gtk_widget_grab_focus() to place the focus accordingly;
9275 * if returning %FALSE, they don't modify the current focus location.
9277 * Return value: %TRUE if focus ended up inside @widget
9280 gtk_widget_child_focus (GtkWidget *widget,
9281 GtkDirectionType direction)
9283 gboolean return_val;
9285 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9287 if (!gtk_widget_get_visible (widget) ||
9288 !gtk_widget_is_sensitive (widget))
9291 /* child widgets must set CAN_FOCUS, containers
9292 * don't have to though.
9294 if (!GTK_IS_CONTAINER (widget) &&
9295 !gtk_widget_get_can_focus (widget))
9298 g_signal_emit (widget,
9299 widget_signals[FOCUS],
9301 direction, &return_val);
9307 * gtk_widget_keynav_failed:
9308 * @widget: a #GtkWidget
9309 * @direction: direction of focus movement
9311 * This function should be called whenever keyboard navigation within
9312 * a single widget hits a boundary. The function emits the
9313 * #GtkWidget::keynav-failed signal on the widget and its return
9314 * value should be interpreted in a way similar to the return value of
9315 * gtk_widget_child_focus():
9317 * When %TRUE is returned, stay in the widget, the failed keyboard
9318 * navigation is Ok and/or there is nowhere we can/should move the
9321 * When %FALSE is returned, the caller should continue with keyboard
9322 * navigation outside the widget, e.g. by calling
9323 * gtk_widget_child_focus() on the widget's toplevel.
9325 * The default ::keynav-failed handler returns %TRUE for
9326 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9327 * values of #GtkDirectionType, it looks at the
9328 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9329 * if the setting is %TRUE. This way the entire user interface
9330 * becomes cursor-navigatable on input devices such as mobile phones
9331 * which only have cursor keys but no tab key.
9333 * Whenever the default handler returns %TRUE, it also calls
9334 * gtk_widget_error_bell() to notify the user of the failed keyboard
9337 * A use case for providing an own implementation of ::keynav-failed
9338 * (either by connecting to it or by overriding it) would be a row of
9339 * #GtkEntry widgets where the user should be able to navigate the
9340 * entire row with the cursor keys, as e.g. known from user interfaces
9341 * that require entering license keys.
9343 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9344 * if the emitting widget should try to handle the keyboard
9345 * navigation attempt in its parent container(s).
9350 gtk_widget_keynav_failed (GtkWidget *widget,
9351 GtkDirectionType direction)
9353 gboolean return_val;
9355 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9357 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9358 direction, &return_val);
9364 * gtk_widget_error_bell:
9365 * @widget: a #GtkWidget
9367 * Notifies the user about an input-related error on this widget.
9368 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9369 * gdk_window_beep(), otherwise it does nothing.
9371 * Note that the effect of gdk_window_beep() can be configured in many
9372 * ways, depending on the windowing backend and the desktop environment
9373 * or window manager that is used.
9378 gtk_widget_error_bell (GtkWidget *widget)
9380 GtkWidgetPrivate *priv;
9381 GtkSettings* settings;
9384 g_return_if_fail (GTK_IS_WIDGET (widget));
9386 priv = widget->priv;
9388 settings = gtk_widget_get_settings (widget);
9392 g_object_get (settings,
9393 "gtk-error-bell", &beep,
9396 if (beep && priv->window)
9397 gdk_window_beep (priv->window);
9401 gtk_widget_set_usize_internal (GtkWidget *widget,
9404 GtkQueueResizeFlags flags)
9406 GtkWidgetAuxInfo *aux_info;
9407 gboolean changed = FALSE;
9409 g_object_freeze_notify (G_OBJECT (widget));
9411 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9413 if (width > -2 && aux_info->width != width)
9415 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9416 g_object_notify (G_OBJECT (widget), "width-request");
9417 aux_info->width = width;
9420 if (height > -2 && aux_info->height != height)
9422 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9423 g_object_notify (G_OBJECT (widget), "height-request");
9424 aux_info->height = height;
9428 if (gtk_widget_get_visible (widget) && changed)
9430 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9431 gtk_widget_queue_resize (widget);
9433 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9436 g_object_thaw_notify (G_OBJECT (widget));
9440 * gtk_widget_set_size_request:
9441 * @widget: a #GtkWidget
9442 * @width: width @widget should request, or -1 to unset
9443 * @height: height @widget should request, or -1 to unset
9445 * Sets the minimum size of a widget; that is, the widget's size
9446 * request will be @width by @height. You can use this function to
9447 * force a widget to be either larger or smaller than it normally
9450 * In most cases, gtk_window_set_default_size() is a better choice for
9451 * toplevel windows than this function; setting the default size will
9452 * still allow users to shrink the window. Setting the size request
9453 * will force them to leave the window at least as large as the size
9454 * request. When dealing with window sizes,
9455 * gtk_window_set_geometry_hints() can be a useful function as well.
9457 * Note the inherent danger of setting any fixed size - themes,
9458 * translations into other languages, different fonts, and user action
9459 * can all change the appropriate size for a given widget. So, it's
9460 * basically impossible to hardcode a size that will always be
9463 * The size request of a widget is the smallest size a widget can
9464 * accept while still functioning well and drawing itself correctly.
9465 * However in some strange cases a widget may be allocated less than
9466 * its requested size, and in many cases a widget may be allocated more
9467 * space than it requested.
9469 * If the size request in a given direction is -1 (unset), then
9470 * the "natural" size request of the widget will be used instead.
9472 * Widgets can't actually be allocated a size less than 1 by 1, but
9473 * you can pass 0,0 to this function to mean "as small as possible."
9475 * The size request set here does not include any margin from the
9476 * #GtkWidget properties margin-left, margin-right, margin-top, and
9477 * margin-bottom, but it does include pretty much all other padding
9478 * or border properties set by any subclass of #GtkWidget.
9481 gtk_widget_set_size_request (GtkWidget *widget,
9485 g_return_if_fail (GTK_IS_WIDGET (widget));
9486 g_return_if_fail (width >= -1);
9487 g_return_if_fail (height >= -1);
9494 gtk_widget_set_usize_internal (widget, width, height, 0);
9499 * gtk_widget_get_size_request:
9500 * @widget: a #GtkWidget
9501 * @width: (out) (allow-none): return location for width, or %NULL
9502 * @height: (out) (allow-none): return location for height, or %NULL
9504 * Gets the size request that was explicitly set for the widget using
9505 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9506 * @height indicates that that dimension has not been set explicitly
9507 * and the natural requisition of the widget will be used intead. See
9508 * gtk_widget_set_size_request(). To get the size a widget will
9509 * actually request, call gtk_widget_get_preferred_size() instead of
9513 gtk_widget_get_size_request (GtkWidget *widget,
9517 const GtkWidgetAuxInfo *aux_info;
9519 g_return_if_fail (GTK_IS_WIDGET (widget));
9521 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9524 *width = aux_info->width;
9527 *height = aux_info->height;
9531 * _gtk_widget_override_size_request:
9532 * @widget: a #GtkWidget
9533 * @width: new forced minimum width
9534 * @height: new forced minimum height
9535 * @old_width: location to store previous forced minimum width
9536 * @old_width: location to store previous forced minumum height
9538 * Temporarily establishes a forced minimum size for a widget; this
9539 * is used by GtkWindow when calculating the size to add to the
9540 * window's geometry widget. Cached sizes for the widget and its
9541 * parents are invalidated, so that subsequent calls to the size
9542 * negotiation machinery produce the overriden result, but the
9543 * widget is not queued for relayout or redraw. The old size must
9544 * be restored with _gtk_widget_restore_size_request() or things
9548 _gtk_widget_override_size_request (GtkWidget *widget,
9554 gtk_widget_get_size_request (widget, old_width, old_height);
9555 gtk_widget_set_usize_internal (widget, width, height,
9556 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9560 * _gtk_widget_restore_size_request:
9561 * @widget: a #GtkWidget
9562 * @old_width: saved forced minimum size
9563 * @old_height: saved forced minimum size
9565 * Undoes the operation of_gtk_widget_override_size_request().
9568 _gtk_widget_restore_size_request (GtkWidget *widget,
9572 gtk_widget_set_usize_internal (widget, old_width, old_height,
9573 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9577 * gtk_widget_set_events:
9578 * @widget: a #GtkWidget
9579 * @events: event mask
9581 * Sets the event mask (see #GdkEventMask) for a widget. The event
9582 * mask determines which events a widget will receive. Keep in mind
9583 * that different widgets have different default event masks, and by
9584 * changing the event mask you may disrupt a widget's functionality,
9585 * so be careful. This function must be called while a widget is
9586 * unrealized. Consider gtk_widget_add_events() for widgets that are
9587 * already realized, or if you want to preserve the existing event
9588 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9589 * to get events on those widgets, place them inside a #GtkEventBox
9590 * and receive events on the event box.
9593 gtk_widget_set_events (GtkWidget *widget,
9596 g_return_if_fail (GTK_IS_WIDGET (widget));
9597 g_return_if_fail (!gtk_widget_get_realized (widget));
9599 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9600 GINT_TO_POINTER (events));
9601 g_object_notify (G_OBJECT (widget), "events");
9605 * gtk_widget_set_device_events:
9606 * @widget: a #GtkWidget
9607 * @device: a #GdkDevice
9608 * @events: event mask
9610 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9611 * mask determines which events a widget will receive from @device. Keep
9612 * in mind that different widgets have different default event masks, and by
9613 * changing the event mask you may disrupt a widget's functionality,
9614 * so be careful. This function must be called while a widget is
9615 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9616 * already realized, or if you want to preserve the existing event
9617 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9618 * to get events on those widgets, place them inside a #GtkEventBox
9619 * and receive events on the event box.
9624 gtk_widget_set_device_events (GtkWidget *widget,
9626 GdkEventMask events)
9628 GHashTable *device_events;
9630 g_return_if_fail (GTK_IS_WIDGET (widget));
9631 g_return_if_fail (GDK_IS_DEVICE (device));
9632 g_return_if_fail (!gtk_widget_get_realized (widget));
9634 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9636 if (G_UNLIKELY (!device_events))
9638 device_events = g_hash_table_new (NULL, NULL);
9639 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9640 (GDestroyNotify) g_hash_table_unref);
9643 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9647 gtk_widget_add_events_internal_list (GtkWidget *widget,
9654 for (l = window_list; l != NULL; l = l->next)
9656 GdkWindow *window = l->data;
9659 gdk_window_get_user_data (window, &user_data);
9660 if (user_data == widget)
9665 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9667 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9669 children = gdk_window_get_children (window);
9670 gtk_widget_add_events_internal_list (widget, device, events, children);
9671 g_list_free (children);
9677 gtk_widget_add_events_internal (GtkWidget *widget,
9681 GtkWidgetPrivate *priv = widget->priv;
9684 if (!gtk_widget_get_has_window (widget))
9685 window_list = gdk_window_get_children (priv->window);
9687 window_list = g_list_prepend (NULL, priv->window);
9689 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9691 g_list_free (window_list);
9695 * gtk_widget_add_events:
9696 * @widget: a #GtkWidget
9697 * @events: an event mask, see #GdkEventMask
9699 * Adds the events in the bitfield @events to the event mask for
9700 * @widget. See gtk_widget_set_events() for details.
9703 gtk_widget_add_events (GtkWidget *widget,
9708 g_return_if_fail (GTK_IS_WIDGET (widget));
9710 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9711 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9712 GINT_TO_POINTER (old_events | events));
9714 if (gtk_widget_get_realized (widget))
9715 gtk_widget_add_events_internal (widget, NULL, events);
9717 g_object_notify (G_OBJECT (widget), "events");
9721 * gtk_widget_add_device_events:
9722 * @widget: a #GtkWidget
9723 * @device: a #GdkDevice
9724 * @events: an event mask, see #GdkEventMask
9726 * Adds the device events in the bitfield @events to the event mask for
9727 * @widget. See gtk_widget_set_device_events() for details.
9732 gtk_widget_add_device_events (GtkWidget *widget,
9734 GdkEventMask events)
9736 GdkEventMask old_events;
9737 GHashTable *device_events;
9739 g_return_if_fail (GTK_IS_WIDGET (widget));
9740 g_return_if_fail (GDK_IS_DEVICE (device));
9742 old_events = gtk_widget_get_device_events (widget, device);
9744 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9746 if (G_UNLIKELY (!device_events))
9748 device_events = g_hash_table_new (NULL, NULL);
9749 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9750 (GDestroyNotify) g_hash_table_unref);
9753 g_hash_table_insert (device_events, device,
9754 GUINT_TO_POINTER (old_events | events));
9756 if (gtk_widget_get_realized (widget))
9757 gtk_widget_add_events_internal (widget, device, events);
9759 g_object_notify (G_OBJECT (widget), "events");
9763 * gtk_widget_set_extension_events:
9764 * @widget: a #GtkWidget
9765 * @mode: bitfield of extension events to receive
9767 * Sets the extension events mask to @mode. See #GdkExtensionMode
9768 * and gdk_input_set_extension_events().
9771 gtk_widget_set_extension_events (GtkWidget *widget,
9772 GdkExtensionMode mode)
9774 g_return_if_fail (GTK_IS_WIDGET (widget));
9776 if (gtk_widget_get_realized (widget))
9777 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9779 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9780 GINT_TO_POINTER (mode));
9781 g_object_notify (G_OBJECT (widget), "extension-events");
9785 * gtk_widget_get_toplevel:
9786 * @widget: a #GtkWidget
9788 * This function returns the topmost widget in the container hierarchy
9789 * @widget is a part of. If @widget has no parent widgets, it will be
9790 * returned as the topmost widget. No reference will be added to the
9791 * returned widget; it should not be unreferenced.
9793 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9794 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9796 * %NULL if @widget wasn't inside a toplevel window, and if the
9797 * window was inside a #GtkWindow-derived widget which was in turn
9798 * inside the toplevel #GtkWindow. While the second case may
9799 * seem unlikely, it actually happens when a #GtkPlug is embedded
9800 * inside a #GtkSocket within the same application.
9802 * To reliably find the toplevel #GtkWindow, use
9803 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9804 * is set on the result.
9806 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9807 * if (gtk_widget_is_toplevel (toplevel))
9809 * /* Perform action on toplevel. */
9813 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9814 * if there's no ancestor.
9817 gtk_widget_get_toplevel (GtkWidget *widget)
9819 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9821 while (widget->priv->parent)
9822 widget = widget->priv->parent;
9828 * gtk_widget_get_ancestor:
9829 * @widget: a #GtkWidget
9830 * @widget_type: ancestor type
9832 * Gets the first ancestor of @widget with type @widget_type. For example,
9833 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9834 * the first #GtkBox that's an ancestor of @widget. No reference will be
9835 * added to the returned widget; it should not be unreferenced. See note
9836 * about checking for a toplevel #GtkWindow in the docs for
9837 * gtk_widget_get_toplevel().
9839 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9840 * considers @widget to be an ancestor of itself.
9842 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9845 gtk_widget_get_ancestor (GtkWidget *widget,
9848 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9850 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9851 widget = widget->priv->parent;
9853 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9860 * gtk_widget_set_visual:
9861 * @widget: a #GtkWidget
9862 * @visual: visual to be used or %NULL to unset a previous one
9864 * Sets the visual that should be used for by widget and its children for
9865 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9866 * returned by gdk_widget_get_screen(), so handling the
9867 * #GtkWidget::screen-changed signal is necessary.
9869 * Setting a new @visual will not cause @widget to recreate its windows,
9870 * so you should call this function before @widget is realized.
9873 gtk_widget_set_visual (GtkWidget *widget,
9876 g_return_if_fail (GTK_IS_WIDGET (widget));
9877 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9880 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9883 g_object_set_qdata_full (G_OBJECT (widget),
9885 g_object_ref (visual),
9890 * gtk_widget_get_visual:
9891 * @widget: a #GtkWidget
9893 * Gets the visual that will be used to render @widget.
9895 * Return value: (transfer none): the visual for @widget
9898 gtk_widget_get_visual (GtkWidget *widget)
9904 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9906 if (gtk_widget_get_has_window (widget) &&
9907 widget->priv->window)
9908 return gdk_window_get_visual (widget->priv->window);
9910 screen = gtk_widget_get_screen (widget);
9912 for (w = widget; w != NULL; w = w->priv->parent)
9914 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9917 if (gdk_visual_get_screen (visual) == screen)
9920 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9921 gtk_widget_get_name (widget));
9925 return gdk_screen_get_system_visual (screen);
9929 * gtk_widget_get_settings:
9930 * @widget: a #GtkWidget
9932 * Gets the settings object holding the settings (global property
9933 * settings, RC file information, etc) used for this widget.
9935 * Note that this function can only be called when the #GtkWidget
9936 * is attached to a toplevel, since the settings object is specific
9937 * to a particular #GdkScreen.
9939 * Return value: (transfer none): the relevant #GtkSettings object
9942 gtk_widget_get_settings (GtkWidget *widget)
9944 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9946 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9950 * gtk_widget_get_events:
9951 * @widget: a #GtkWidget
9953 * Returns the event mask for the widget (a bitfield containing flags
9954 * from the #GdkEventMask enumeration). These are the events that the widget
9957 * Return value: event mask for @widget
9960 gtk_widget_get_events (GtkWidget *widget)
9962 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9964 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9968 * gtk_widget_get_device_events:
9969 * @widget: a #GtkWidget
9970 * @device: a #GdkDevice
9972 * Returns the events mask for the widget corresponding to an specific device. These
9973 * are the events that the widget will receive when @device operates on it.
9975 * Returns: device event mask for @widget
9980 gtk_widget_get_device_events (GtkWidget *widget,
9983 GHashTable *device_events;
9985 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9986 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9988 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9993 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9997 * gtk_widget_get_extension_events:
9998 * @widget: a #GtkWidget
10000 * Retrieves the extension events the widget will receive; see
10001 * gdk_input_set_extension_events().
10003 * Return value: extension events for @widget
10006 gtk_widget_get_extension_events (GtkWidget *widget)
10008 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10010 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
10014 * gtk_widget_get_pointer:
10015 * @widget: a #GtkWidget
10016 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10017 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10019 * Obtains the location of the mouse pointer in widget coordinates.
10020 * Widget coordinates are a bit odd; for historical reasons, they are
10021 * defined as @widget->window coordinates for widgets that are not
10022 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10023 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10026 gtk_widget_get_pointer (GtkWidget *widget,
10030 GtkWidgetPrivate *priv;
10032 g_return_if_fail (GTK_IS_WIDGET (widget));
10034 priv = widget->priv;
10041 if (gtk_widget_get_realized (widget))
10043 gdk_window_get_pointer (priv->window, x, y, NULL);
10045 if (!gtk_widget_get_has_window (widget))
10048 *x -= priv->allocation.x;
10050 *y -= priv->allocation.y;
10056 * gtk_widget_is_ancestor:
10057 * @widget: a #GtkWidget
10058 * @ancestor: another #GtkWidget
10060 * Determines whether @widget is somewhere inside @ancestor, possibly with
10061 * intermediate containers.
10063 * Return value: %TRUE if @ancestor contains @widget as a child,
10064 * grandchild, great grandchild, etc.
10067 gtk_widget_is_ancestor (GtkWidget *widget,
10068 GtkWidget *ancestor)
10070 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10071 g_return_val_if_fail (ancestor != NULL, FALSE);
10075 if (widget->priv->parent == ancestor)
10077 widget = widget->priv->parent;
10083 static GQuark quark_composite_name = 0;
10086 * gtk_widget_set_composite_name:
10087 * @widget: a #GtkWidget.
10088 * @name: the name to set
10090 * Sets a widgets composite name. The widget must be
10091 * a composite child of its parent; see gtk_widget_push_composite_child().
10094 gtk_widget_set_composite_name (GtkWidget *widget,
10097 g_return_if_fail (GTK_IS_WIDGET (widget));
10098 g_return_if_fail (widget->priv->composite_child);
10099 g_return_if_fail (name != NULL);
10101 if (!quark_composite_name)
10102 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10104 g_object_set_qdata_full (G_OBJECT (widget),
10105 quark_composite_name,
10111 * gtk_widget_get_composite_name:
10112 * @widget: a #GtkWidget
10114 * Obtains the composite name of a widget.
10116 * Returns: the composite name of @widget, or %NULL if @widget is not
10117 * a composite child. The string should be freed when it is no
10121 gtk_widget_get_composite_name (GtkWidget *widget)
10123 GtkWidgetPrivate *priv;
10125 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10127 priv = widget->priv;
10129 if (widget->priv->composite_child && priv->parent)
10130 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10137 * gtk_widget_push_composite_child:
10139 * Makes all newly-created widgets as composite children until
10140 * the corresponding gtk_widget_pop_composite_child() call.
10142 * A composite child is a child that's an implementation detail of the
10143 * container it's inside and should not be visible to people using the
10144 * container. Composite children aren't treated differently by GTK (but
10145 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10146 * builders might want to treat them in a different way.
10148 * Here is a simple example:
10150 * gtk_widget_push_composite_child ();
10151 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10152 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10153 * gtk_widget_pop_composite_child ();
10154 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10155 * GTK_WIDGET (scrolled_window));
10156 * g_object_ref (scrolled_window->hscrollbar);
10160 gtk_widget_push_composite_child (void)
10162 composite_child_stack++;
10166 * gtk_widget_pop_composite_child:
10168 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10171 gtk_widget_pop_composite_child (void)
10173 if (composite_child_stack)
10174 composite_child_stack--;
10178 gtk_widget_emit_direction_changed (GtkWidget *widget,
10179 GtkTextDirection old_dir)
10181 gtk_widget_update_pango_context (widget);
10183 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10187 * gtk_widget_set_direction:
10188 * @widget: a #GtkWidget
10189 * @dir: the new direction
10191 * Sets the reading direction on a particular widget. This direction
10192 * controls the primary direction for widgets containing text,
10193 * and also the direction in which the children of a container are
10194 * packed. The ability to set the direction is present in order
10195 * so that correct localization into languages with right-to-left
10196 * reading directions can be done. Generally, applications will
10197 * let the default reading direction present, except for containers
10198 * where the containers are arranged in an order that is explicitely
10199 * visual rather than logical (such as buttons for text justification).
10201 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10202 * set by gtk_widget_set_default_direction() will be used.
10205 gtk_widget_set_direction (GtkWidget *widget,
10206 GtkTextDirection dir)
10208 GtkTextDirection old_dir;
10210 g_return_if_fail (GTK_IS_WIDGET (widget));
10211 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10213 old_dir = gtk_widget_get_direction (widget);
10215 widget->priv->direction = dir;
10217 if (old_dir != gtk_widget_get_direction (widget))
10219 if (widget->priv->context)
10220 gtk_style_context_set_direction (widget->priv->context,
10221 gtk_widget_get_direction (widget));
10223 gtk_widget_emit_direction_changed (widget, old_dir);
10228 * gtk_widget_get_direction:
10229 * @widget: a #GtkWidget
10231 * Gets the reading direction for a particular widget. See
10232 * gtk_widget_set_direction().
10234 * Return value: the reading direction for the widget.
10237 gtk_widget_get_direction (GtkWidget *widget)
10239 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10241 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10242 return gtk_default_direction;
10244 return widget->priv->direction;
10248 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10250 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10252 g_object_ref (widget);
10254 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10255 gtk_widget_emit_direction_changed (widget, old_dir);
10257 if (GTK_IS_CONTAINER (widget))
10258 gtk_container_forall (GTK_CONTAINER (widget),
10259 gtk_widget_set_default_direction_recurse,
10262 g_object_unref (widget);
10266 * gtk_widget_set_default_direction:
10267 * @dir: the new default direction. This cannot be
10268 * %GTK_TEXT_DIR_NONE.
10270 * Sets the default reading direction for widgets where the
10271 * direction has not been explicitly set by gtk_widget_set_direction().
10274 gtk_widget_set_default_direction (GtkTextDirection dir)
10276 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10278 if (dir != gtk_default_direction)
10280 GList *toplevels, *tmp_list;
10281 GtkTextDirection old_dir = gtk_default_direction;
10283 gtk_default_direction = dir;
10285 tmp_list = toplevels = gtk_window_list_toplevels ();
10286 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10290 gtk_widget_set_default_direction_recurse (tmp_list->data,
10291 GUINT_TO_POINTER (old_dir));
10292 g_object_unref (tmp_list->data);
10293 tmp_list = tmp_list->next;
10296 g_list_free (toplevels);
10301 * gtk_widget_get_default_direction:
10303 * Obtains the current default reading direction. See
10304 * gtk_widget_set_default_direction().
10306 * Return value: the current default direction.
10309 gtk_widget_get_default_direction (void)
10311 return gtk_default_direction;
10315 gtk_widget_dispose (GObject *object)
10317 GtkWidget *widget = GTK_WIDGET (object);
10318 GtkWidgetPrivate *priv = widget->priv;
10321 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10322 else if (gtk_widget_get_visible (widget))
10323 gtk_widget_hide (widget);
10325 priv->visible = FALSE;
10326 if (gtk_widget_get_realized (widget))
10327 gtk_widget_unrealize (widget);
10329 if (!priv->in_destruction)
10331 priv->in_destruction = TRUE;
10332 g_signal_emit (object, widget_signals[DESTROY], 0);
10333 priv->in_destruction = FALSE;
10336 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10340 gtk_widget_real_destroy (GtkWidget *object)
10342 /* gtk_object_destroy() will already hold a refcount on object */
10343 GtkWidget *widget = GTK_WIDGET (object);
10344 GtkWidgetPrivate *priv = widget->priv;
10346 /* wipe accelerator closures (keep order) */
10347 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10348 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10350 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10351 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10353 gtk_grab_remove (widget);
10355 g_object_unref (priv->style);
10356 priv->style = gtk_widget_get_default_style ();
10357 g_object_ref (priv->style);
10361 gtk_widget_finalize (GObject *object)
10363 GtkWidget *widget = GTK_WIDGET (object);
10364 GtkWidgetPrivate *priv = widget->priv;
10365 GtkWidgetAuxInfo *aux_info;
10366 GtkAccessible *accessible;
10368 gtk_grab_remove (widget);
10370 g_object_unref (priv->style);
10371 priv->style = NULL;
10373 g_free (priv->name);
10375 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10377 gtk_widget_aux_info_destroy (aux_info);
10379 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10381 g_object_unref (accessible);
10384 gtk_widget_path_free (priv->path);
10387 g_object_unref (priv->context);
10389 if (g_object_is_floating (object))
10390 g_warning ("A floating object was finalized. This means that someone\n"
10391 "called g_object_unref() on an object that had only a floating\n"
10392 "reference; the initial floating reference is not owned by anyone\n"
10393 "and must be removed with g_object_ref_sink().");
10395 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10398 /*****************************************
10399 * gtk_widget_real_map:
10404 *****************************************/
10407 gtk_widget_real_map (GtkWidget *widget)
10409 GtkWidgetPrivate *priv = widget->priv;
10411 g_assert (gtk_widget_get_realized (widget));
10413 if (!gtk_widget_get_mapped (widget))
10415 gtk_widget_set_mapped (widget, TRUE);
10417 if (gtk_widget_get_has_window (widget))
10418 gdk_window_show (priv->window);
10422 /*****************************************
10423 * gtk_widget_real_unmap:
10428 *****************************************/
10431 gtk_widget_real_unmap (GtkWidget *widget)
10433 GtkWidgetPrivate *priv = widget->priv;
10435 if (gtk_widget_get_mapped (widget))
10437 gtk_widget_set_mapped (widget, FALSE);
10439 if (gtk_widget_get_has_window (widget))
10440 gdk_window_hide (priv->window);
10444 /*****************************************
10445 * gtk_widget_real_realize:
10450 *****************************************/
10453 gtk_widget_real_realize (GtkWidget *widget)
10455 GtkWidgetPrivate *priv = widget->priv;
10457 g_assert (!gtk_widget_get_has_window (widget));
10459 gtk_widget_set_realized (widget, TRUE);
10462 priv->window = gtk_widget_get_parent_window (widget);
10463 g_object_ref (priv->window);
10465 priv->style = gtk_style_attach (priv->style, priv->window);
10468 /*****************************************
10469 * gtk_widget_real_unrealize:
10474 *****************************************/
10477 gtk_widget_real_unrealize (GtkWidget *widget)
10479 GtkWidgetPrivate *priv = widget->priv;
10481 if (gtk_widget_get_mapped (widget))
10482 gtk_widget_real_unmap (widget);
10484 gtk_widget_set_mapped (widget, FALSE);
10486 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10489 /* We must do unrealize child widget BEFORE container widget.
10490 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10491 * So, unrealizing container widget bofore its children causes the problem
10492 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10495 if (GTK_IS_CONTAINER (widget))
10496 gtk_container_forall (GTK_CONTAINER (widget),
10497 (GtkCallback) gtk_widget_unrealize,
10500 gtk_style_detach (priv->style);
10501 if (gtk_widget_get_has_window (widget))
10503 gdk_window_set_user_data (priv->window, NULL);
10504 gdk_window_destroy (priv->window);
10505 priv->window = NULL;
10509 g_object_unref (priv->window);
10510 priv->window = NULL;
10513 gtk_selection_remove_all (widget);
10515 gtk_widget_set_realized (widget, FALSE);
10519 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10520 GtkOrientation orientation,
10521 gint *minimum_size,
10522 gint *natural_size)
10524 const GtkWidgetAuxInfo *aux_info;
10526 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10528 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10529 aux_info->width > 0)
10531 *minimum_size = MAX (*minimum_size, aux_info->width);
10533 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10534 aux_info->height > 0)
10536 *minimum_size = MAX (*minimum_size, aux_info->height);
10539 /* Fix it if set_size_request made natural size smaller than min size.
10540 * This would also silently fix broken widgets, but we warn about them
10541 * in gtksizerequest.c when calling their size request vfuncs.
10543 *natural_size = MAX (*natural_size, *minimum_size);
10545 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10547 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10548 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10552 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10553 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10558 * _gtk_widget_peek_request_cache:
10560 * Returns the address of the widget's request cache (strictly for
10561 * internal use in gtksizerequest.c)
10563 * Return value: the address of @widget's size request cache.
10566 _gtk_widget_peek_request_cache (GtkWidget *widget)
10568 /* Don't bother slowing things down with the return_if_fail guards here */
10569 return &widget->priv->requests;
10573 * _gtk_widget_set_device_window:
10574 * @widget: a #GtkWidget.
10575 * @device: a #GdkDevice.
10576 * @window: the new device window.
10578 * Sets pointer window for @widget and @device. Does not ref @window.
10579 * Actually stores it on the #GdkScreen, but you don't need to know that.
10582 _gtk_widget_set_device_window (GtkWidget *widget,
10586 GtkWidgetPrivate *priv;
10588 GHashTable *device_window;
10590 g_return_if_fail (GTK_IS_WIDGET (widget));
10591 g_return_if_fail (GDK_IS_DEVICE (device));
10592 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10594 priv = widget->priv;
10596 if (!gtk_widget_get_realized (widget))
10599 screen = gdk_window_get_screen (priv->window);
10600 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10602 if (G_UNLIKELY (!device_window))
10604 device_window = g_hash_table_new (NULL, NULL);
10605 g_object_set_qdata_full (G_OBJECT (screen),
10606 quark_pointer_window,
10608 (GDestroyNotify) g_hash_table_destroy);
10612 g_hash_table_insert (device_window, device, window);
10614 g_hash_table_remove (device_window, device);
10618 * _gtk_widget_get_device_window:
10619 * @widget: a #GtkWidget.
10620 * @device: a #GdkDevice.
10622 * Return value: the device window set on the #GdkScreen @widget is attached
10626 _gtk_widget_get_device_window (GtkWidget *widget,
10629 GtkWidgetPrivate *priv;
10631 GHashTable *device_window;
10635 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10636 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10638 priv = widget->priv;
10640 if (!gtk_widget_get_realized (widget))
10643 screen = gdk_window_get_screen (priv->window);
10644 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10646 if (G_UNLIKELY (!device_window))
10649 window = g_hash_table_lookup (device_window, device);
10654 gdk_window_get_user_data (window, (gpointer *) &w);
10663 * _gtk_widget_list_devices:
10664 * @widget: a #GtkWidget.
10666 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10667 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10671 _gtk_widget_list_devices (GtkWidget *widget)
10673 GtkWidgetPrivate *priv;
10675 GHashTableIter iter;
10676 GHashTable *device_window;
10677 GList *devices = NULL;
10678 gpointer key, value;
10680 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10682 priv = widget->priv;
10684 if (!gtk_widget_get_realized (widget))
10687 screen = gdk_window_get_screen (priv->window);
10688 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10690 if (G_UNLIKELY (!device_window))
10693 g_hash_table_iter_init (&iter, device_window);
10695 while (g_hash_table_iter_next (&iter, &key, &value))
10697 GdkDevice *device = key;
10698 GdkWindow *window = value;
10703 gdk_window_get_user_data (window, (gpointer *) &w);
10706 devices = g_list_prepend (devices, device);
10714 synth_crossing (GtkWidget *widget,
10718 GdkCrossingMode mode,
10719 GdkNotifyType detail)
10723 event = gdk_event_new (type);
10725 event->crossing.window = g_object_ref (window);
10726 event->crossing.send_event = TRUE;
10727 event->crossing.subwindow = g_object_ref (window);
10728 event->crossing.time = GDK_CURRENT_TIME;
10729 event->crossing.x = event->crossing.y = 0;
10730 event->crossing.x_root = event->crossing.y_root = 0;
10731 event->crossing.mode = mode;
10732 event->crossing.detail = detail;
10733 event->crossing.focus = FALSE;
10734 event->crossing.state = 0;
10735 gdk_event_set_device (event, device);
10738 widget = gtk_get_event_widget (event);
10741 gtk_widget_event_internal (widget, event);
10743 gdk_event_free (event);
10747 * _gtk_widget_synthesize_crossing:
10748 * @from: the #GtkWidget the virtual pointer is leaving.
10749 * @to: the #GtkWidget the virtual pointer is moving to.
10750 * @mode: the #GdkCrossingMode to place on the synthesized events.
10752 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10754 * The real pointer window is the window that most recently received an enter notify
10755 * event. Windows that don't select for crossing events can't become the real
10756 * poiner window. The real pointer widget that owns the real pointer window. The
10757 * effective pointer window is the same as the real pointer window unless the real
10758 * pointer widget is either insensitive or there is a grab on a widget that is not
10759 * an ancestor of the real pointer widget (in which case the effective pointer
10760 * window should be the root window).
10762 * When the effective pointer window is the same as the real poiner window, we
10763 * receive crossing events from the windowing system. When the effective pointer
10764 * window changes to become different from the real pointer window we synthesize
10765 * crossing events, attempting to follow X protocol rules:
10767 * When the root window becomes the effective pointer window:
10768 * - leave notify on real pointer window, detail Ancestor
10769 * - leave notify on all of its ancestors, detail Virtual
10770 * - enter notify on root window, detail Inferior
10772 * When the root window ceases to be the effective pointer window:
10773 * - leave notify on root window, detail Inferior
10774 * - enter notify on all ancestors of real pointer window, detail Virtual
10775 * - enter notify on real pointer window, detail Ancestor
10778 _gtk_widget_synthesize_crossing (GtkWidget *from,
10781 GdkCrossingMode mode)
10783 GdkWindow *from_window = NULL, *to_window = NULL;
10785 g_return_if_fail (from != NULL || to != NULL);
10789 from_window = _gtk_widget_get_device_window (from, device);
10792 from_window = from->priv->window;
10797 to_window = _gtk_widget_get_device_window (to, device);
10800 to_window = to->priv->window;
10803 if (from_window == NULL && to_window == NULL)
10805 else if (from_window != NULL && to_window == NULL)
10807 GList *from_ancestors = NULL, *list;
10808 GdkWindow *from_ancestor = from_window;
10810 while (from_ancestor != NULL)
10812 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10813 if (from_ancestor == NULL)
10815 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10818 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10819 device, mode, GDK_NOTIFY_ANCESTOR);
10820 for (list = g_list_last (from_ancestors); list; list = list->prev)
10822 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10823 device, mode, GDK_NOTIFY_VIRTUAL);
10826 /* XXX: enter/inferior on root window? */
10828 g_list_free (from_ancestors);
10830 else if (from_window == NULL && to_window != NULL)
10832 GList *to_ancestors = NULL, *list;
10833 GdkWindow *to_ancestor = to_window;
10835 while (to_ancestor != NULL)
10837 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10838 if (to_ancestor == NULL)
10840 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10843 /* XXX: leave/inferior on root window? */
10845 for (list = to_ancestors; list; list = list->next)
10847 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10848 device, mode, GDK_NOTIFY_VIRTUAL);
10850 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10851 device, mode, GDK_NOTIFY_ANCESTOR);
10853 g_list_free (to_ancestors);
10855 else if (from_window == to_window)
10859 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10860 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10862 while (from_ancestor != NULL || to_ancestor != NULL)
10864 if (from_ancestor != NULL)
10866 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10867 if (from_ancestor == to_window)
10870 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10872 if (to_ancestor != NULL)
10874 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10875 if (to_ancestor == from_window)
10878 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10881 if (to_ancestor == from_window)
10883 if (mode != GDK_CROSSING_GTK_UNGRAB)
10884 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10885 device, mode, GDK_NOTIFY_INFERIOR);
10886 for (list = to_ancestors; list; list = list->next)
10887 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10888 device, mode, GDK_NOTIFY_VIRTUAL);
10889 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10890 device, mode, GDK_NOTIFY_ANCESTOR);
10892 else if (from_ancestor == to_window)
10894 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10895 device, mode, GDK_NOTIFY_ANCESTOR);
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_VIRTUAL);
10901 if (mode != GDK_CROSSING_GTK_GRAB)
10902 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10903 device, mode, GDK_NOTIFY_INFERIOR);
10907 while (from_ancestors != NULL && to_ancestors != NULL
10908 && from_ancestors->data == to_ancestors->data)
10910 from_ancestors = g_list_delete_link (from_ancestors,
10912 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10915 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10916 device, mode, GDK_NOTIFY_NONLINEAR);
10918 for (list = g_list_last (from_ancestors); list; list = list->prev)
10920 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10921 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10923 for (list = to_ancestors; list; list = list->next)
10925 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10926 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10928 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10929 device, mode, GDK_NOTIFY_NONLINEAR);
10931 g_list_free (from_ancestors);
10932 g_list_free (to_ancestors);
10937 gtk_widget_propagate_state (GtkWidget *widget,
10938 GtkStateData *data)
10940 GtkWidgetPrivate *priv = widget->priv;
10941 GtkStateFlags new_flags, old_flags = priv->state_flags;
10942 GtkStateType old_state;
10944 old_state = gtk_widget_get_state (widget);
10946 if (!priv->parent_sensitive)
10947 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10949 priv->parent_sensitive = data->parent_sensitive;
10951 switch (data->operation)
10953 case STATE_CHANGE_REPLACE:
10954 priv->state_flags = data->flags;
10956 case STATE_CHANGE_SET:
10957 priv->state_flags |= data->flags;
10959 case STATE_CHANGE_UNSET:
10960 priv->state_flags &= ~(data->flags);
10964 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10968 window = gtk_widget_get_toplevel (widget);
10970 if (window && gtk_widget_is_toplevel (window))
10971 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10974 new_flags = gtk_widget_get_state_flags (widget);
10976 if (old_flags != new_flags)
10978 g_object_ref (widget);
10980 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10981 gtk_grab_remove (widget);
10983 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10984 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10986 if (!priv->shadowed)
10988 GList *event_windows = NULL;
10989 GList *devices, *d;
10991 devices = _gtk_widget_list_devices (widget);
10993 for (d = devices; d; d = d->next)
10999 window = _gtk_widget_get_device_window (widget, device);
11001 /* Do not propagate more than once to the
11002 * same window if non-multidevice aware.
11004 if (!gdk_window_get_support_multidevice (window) &&
11005 g_list_find (event_windows, window))
11008 if (!gtk_widget_is_sensitive (widget))
11009 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11010 GDK_CROSSING_STATE_CHANGED);
11011 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11012 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11013 GDK_CROSSING_STATE_CHANGED);
11015 event_windows = g_list_prepend (event_windows, window);
11018 g_list_free (event_windows);
11019 g_list_free (devices);
11022 if (GTK_IS_CONTAINER (widget))
11024 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11026 /* Do not propagate insensitive state further */
11027 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
11029 if (data->use_forall)
11030 gtk_container_forall (GTK_CONTAINER (widget),
11031 (GtkCallback) gtk_widget_propagate_state,
11034 gtk_container_foreach (GTK_CONTAINER (widget),
11035 (GtkCallback) gtk_widget_propagate_state,
11039 /* Trigger state change transitions for the widget */
11040 if (priv->context &&
11041 gtk_widget_get_mapped (widget))
11043 gint diff, flag = 1;
11046 diff = old_flags ^ new_flags;
11047 window = gtk_widget_get_window (widget);
11051 if ((diff & flag) != 0)
11055 target = ((new_flags & flag) != 0);
11056 _gtk_widget_notify_state_change (widget, flag, target);
11065 g_object_unref (widget);
11069 static const GtkWidgetAuxInfo default_aux_info = {
11077 * _gtk_widget_get_aux_info:
11078 * @widget: a #GtkWidget
11079 * @create: if %TRUE, create the structure if it doesn't exist
11081 * Get the #GtkWidgetAuxInfo structure for the widget.
11083 * Return value: the #GtkAuxInfo structure for the widget, or
11084 * %NULL if @create is %FALSE and one doesn't already exist.
11087 _gtk_widget_get_aux_info (GtkWidget *widget,
11090 GtkWidgetAuxInfo *aux_info;
11092 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11093 if (!aux_info && create)
11095 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11097 *aux_info = default_aux_info;
11099 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11105 static const GtkWidgetAuxInfo*
11106 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11108 GtkWidgetAuxInfo *aux_info;
11110 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11111 if (aux_info == NULL)
11113 return &default_aux_info;
11121 /*****************************************
11122 * gtk_widget_aux_info_destroy:
11127 *****************************************/
11130 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11132 g_slice_free (GtkWidgetAuxInfo, aux_info);
11136 * gtk_widget_shape_combine_region:
11137 * @widget: a #GtkWidget
11138 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11140 * Sets a shape for this widget's GDK window. This allows for
11141 * transparent windows etc., see gdk_window_shape_combine_region()
11142 * for more information.
11147 gtk_widget_shape_combine_region (GtkWidget *widget,
11148 cairo_region_t *region)
11150 GtkWidgetPrivate *priv;
11152 g_return_if_fail (GTK_IS_WIDGET (widget));
11153 /* set_shape doesn't work on widgets without gdk window */
11154 g_return_if_fail (gtk_widget_get_has_window (widget));
11156 priv = widget->priv;
11158 if (region == NULL)
11160 priv->has_shape_mask = FALSE;
11163 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11165 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11169 priv->has_shape_mask = TRUE;
11171 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11172 cairo_region_copy (region),
11173 (GDestroyNotify) cairo_region_destroy);
11175 /* set shape if widget has a gdk window already.
11176 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11179 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11184 * gtk_widget_input_shape_combine_region:
11185 * @widget: a #GtkWidget
11186 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11188 * Sets an input shape for this widget's GDK window. This allows for
11189 * windows which react to mouse click in a nonrectangular region, see
11190 * gdk_window_input_shape_combine_region() for more information.
11195 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11196 cairo_region_t *region)
11198 GtkWidgetPrivate *priv;
11200 g_return_if_fail (GTK_IS_WIDGET (widget));
11201 /* set_shape doesn't work on widgets without gdk window */
11202 g_return_if_fail (gtk_widget_get_has_window (widget));
11204 priv = widget->priv;
11206 if (region == NULL)
11209 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11211 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11215 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11216 cairo_region_copy (region),
11217 (GDestroyNotify) cairo_region_destroy);
11219 /* set shape if widget has a gdk window already.
11220 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11223 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11229 gtk_reset_shapes_recurse (GtkWidget *widget,
11235 gdk_window_get_user_data (window, &data);
11236 if (data != widget)
11239 gdk_window_shape_combine_region (window, NULL, 0, 0);
11240 for (list = gdk_window_peek_children (window); list; list = list->next)
11241 gtk_reset_shapes_recurse (widget, list->data);
11245 * gtk_widget_reset_shapes:
11246 * @widget: a #GtkWidget
11248 * Recursively resets the shape on this widget and its descendants.
11251 gtk_widget_reset_shapes (GtkWidget *widget)
11253 GtkWidgetPrivate *priv;
11255 g_return_if_fail (GTK_IS_WIDGET (widget));
11256 g_return_if_fail (gtk_widget_get_realized (widget));
11258 priv = widget->priv;
11260 if (!priv->has_shape_mask)
11261 gtk_reset_shapes_recurse (widget, priv->window);
11264 /* style properties
11268 * gtk_widget_class_install_style_property_parser:
11269 * @klass: a #GtkWidgetClass
11270 * @pspec: the #GParamSpec for the style property
11271 * @parser: the parser for the style property
11273 * Installs a style property on a widget class.
11276 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11278 GtkRcPropertyParser parser)
11280 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11281 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11282 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11283 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11285 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11287 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11288 G_OBJECT_CLASS_NAME (klass),
11293 g_param_spec_ref_sink (pspec);
11294 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11295 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11299 * gtk_widget_class_install_style_property:
11300 * @klass: a #GtkWidgetClass
11301 * @pspec: the #GParamSpec for the property
11303 * Installs a style property on a widget class. The parser for the
11304 * style property is determined by the value type of @pspec.
11307 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11310 GtkRcPropertyParser parser;
11312 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11313 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11315 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11317 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11321 * gtk_widget_class_find_style_property:
11322 * @klass: a #GtkWidgetClass
11323 * @property_name: the name of the style property to find
11324 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11325 * style property with that name.
11327 * Finds a style property of a widget class by name.
11332 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11333 const gchar *property_name)
11335 g_return_val_if_fail (property_name != NULL, NULL);
11337 return g_param_spec_pool_lookup (style_property_spec_pool,
11339 G_OBJECT_CLASS_TYPE (klass),
11344 * gtk_widget_class_list_style_properties:
11345 * @klass: a #GtkWidgetClass
11346 * @n_properties: location to return the number of style properties found
11347 * @returns: an newly allocated array of #GParamSpec*. The array must
11348 * be freed with g_free().
11350 * Returns all style properties of a widget class.
11355 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11356 guint *n_properties)
11358 GParamSpec **pspecs;
11361 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11362 G_OBJECT_CLASS_TYPE (klass),
11371 * gtk_widget_style_get_property:
11372 * @widget: a #GtkWidget
11373 * @property_name: the name of a style property
11374 * @value: location to return the property value
11376 * Gets the value of a style property of @widget.
11379 gtk_widget_style_get_property (GtkWidget *widget,
11380 const gchar *property_name,
11385 g_return_if_fail (GTK_IS_WIDGET (widget));
11386 g_return_if_fail (property_name != NULL);
11387 g_return_if_fail (G_IS_VALUE (value));
11389 g_object_ref (widget);
11390 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11392 G_OBJECT_TYPE (widget),
11395 g_warning ("%s: widget class `%s' has no property named `%s'",
11397 G_OBJECT_TYPE_NAME (widget),
11401 GtkStyleContext *context;
11402 const GValue *peek_value;
11403 GtkStateFlags state;
11405 context = gtk_widget_get_style_context (widget);
11406 state = gtk_widget_get_state_flags (widget);
11408 peek_value = _gtk_style_context_peek_style_property (context,
11409 G_OBJECT_TYPE (widget),
11412 /* auto-conversion of the caller's value type
11414 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11415 g_value_copy (peek_value, value);
11416 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11417 g_value_transform (peek_value, value);
11419 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11421 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11422 G_VALUE_TYPE_NAME (value));
11424 g_object_unref (widget);
11428 * gtk_widget_style_get_valist:
11429 * @widget: a #GtkWidget
11430 * @first_property_name: the name of the first property to get
11431 * @var_args: a <type>va_list</type> of pairs of property names and
11432 * locations to return the property values, starting with the location
11433 * for @first_property_name.
11435 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11439 gtk_widget_style_get_valist (GtkWidget *widget,
11440 const gchar *first_property_name,
11443 GtkStyleContext *context;
11444 GtkStateFlags state;
11447 g_return_if_fail (GTK_IS_WIDGET (widget));
11449 g_object_ref (widget);
11450 context = gtk_widget_get_style_context (widget);
11451 state = gtk_widget_get_state_flags (widget);
11453 name = first_property_name;
11456 const GValue *peek_value;
11460 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11462 G_OBJECT_TYPE (widget),
11466 g_warning ("%s: widget class `%s' has no property named `%s'",
11468 G_OBJECT_TYPE_NAME (widget),
11472 /* style pspecs are always readable so we can spare that check here */
11474 peek_value = _gtk_style_context_peek_style_property (context,
11475 G_OBJECT_TYPE (widget),
11478 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11481 g_warning ("%s: %s", G_STRLOC, error);
11486 name = va_arg (var_args, gchar*);
11489 g_object_unref (widget);
11493 * gtk_widget_style_get:
11494 * @widget: a #GtkWidget
11495 * @first_property_name: the name of the first property to get
11496 * @Varargs: pairs of property names and locations to
11497 * return the property values, starting with the location for
11498 * @first_property_name, terminated by %NULL.
11500 * Gets the values of a multiple style properties of @widget.
11503 gtk_widget_style_get (GtkWidget *widget,
11504 const gchar *first_property_name,
11509 g_return_if_fail (GTK_IS_WIDGET (widget));
11511 va_start (var_args, first_property_name);
11512 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11518 * @widget: a #GtkWidget
11519 * @path_length: (out) (allow-none): location to store length of the path,
11521 * @path: (out) (allow-none): location to store allocated path string,
11523 * @path_reversed: (out) (allow-none): location to store allocated reverse
11524 * path string, or %NULL
11526 * Obtains the full path to @widget. The path is simply the name of a
11527 * widget and all its parents in the container hierarchy, separated by
11528 * periods. The name of a widget comes from
11529 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11530 * in gtkrc configuration files. Widget names are the type of the
11531 * widget by default (e.g. "GtkButton") or can be set to an
11532 * application-specific value with gtk_widget_set_name(). By setting
11533 * the name of a widget, you allow users or theme authors to apply
11534 * styles to that specific widget in their gtkrc
11535 * file. @path_reversed_p fills in the path in reverse order,
11536 * i.e. starting with @widget's name instead of starting with the name
11537 * of @widget's outermost ancestor.
11539 * Deprecated:3.0: Use gtk_widget_get_path() instead
11542 gtk_widget_path (GtkWidget *widget,
11543 guint *path_length,
11545 gchar **path_reversed)
11547 static gchar *rev_path = NULL;
11548 static guint tmp_path_len = 0;
11551 g_return_if_fail (GTK_IS_WIDGET (widget));
11556 const gchar *string;
11561 string = gtk_widget_get_name (widget);
11562 l = strlen (string);
11563 while (tmp_path_len <= len + l + 1)
11565 tmp_path_len += INIT_PATH_SIZE;
11566 rev_path = g_realloc (rev_path, tmp_path_len);
11568 s = string + l - 1;
11569 d = rev_path + len;
11570 while (s >= string)
11574 widget = widget->priv->parent;
11577 rev_path[len++] = '.';
11579 rev_path[len++] = 0;
11584 *path_length = len - 1;
11586 *path_reversed = g_strdup (rev_path);
11589 *path = g_strdup (rev_path);
11590 g_strreverse (*path);
11595 * gtk_widget_class_path:
11596 * @widget: a #GtkWidget
11597 * @path_length: (out) (allow-none): location to store the length of the
11598 * class path, or %NULL
11599 * @path: (out) (allow-none): location to store the class path as an
11600 * allocated string, or %NULL
11601 * @path_reversed: (out) (allow-none): location to store the reverse
11602 * class path as an allocated string, or %NULL
11604 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11605 * never uses a custom name set with gtk_widget_set_name().
11607 * Deprecated:3.0: Use gtk_widget_get_path() instead
11610 gtk_widget_class_path (GtkWidget *widget,
11611 guint *path_length,
11613 gchar **path_reversed)
11615 static gchar *rev_path = NULL;
11616 static guint tmp_path_len = 0;
11619 g_return_if_fail (GTK_IS_WIDGET (widget));
11624 const gchar *string;
11629 string = g_type_name (G_OBJECT_TYPE (widget));
11630 l = strlen (string);
11631 while (tmp_path_len <= len + l + 1)
11633 tmp_path_len += INIT_PATH_SIZE;
11634 rev_path = g_realloc (rev_path, tmp_path_len);
11636 s = string + l - 1;
11637 d = rev_path + len;
11638 while (s >= string)
11642 widget = widget->priv->parent;
11645 rev_path[len++] = '.';
11647 rev_path[len++] = 0;
11652 *path_length = len - 1;
11654 *path_reversed = g_strdup (rev_path);
11657 *path = g_strdup (rev_path);
11658 g_strreverse (*path);
11663 * gtk_requisition_new:
11665 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11667 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11668 * be freed with gtk_requisition_free().
11673 gtk_requisition_new (void)
11675 return g_slice_new0 (GtkRequisition);
11679 * gtk_requisition_copy:
11680 * @requisition: a #GtkRequisition
11682 * Copies a #GtkRequisition.
11684 * Returns: a copy of @requisition
11687 gtk_requisition_copy (const GtkRequisition *requisition)
11689 return g_slice_dup (GtkRequisition, requisition);
11693 * gtk_requisition_free:
11694 * @requisition: a #GtkRequisition
11696 * Frees a #GtkRequisition.
11699 gtk_requisition_free (GtkRequisition *requisition)
11701 g_slice_free (GtkRequisition, requisition);
11704 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11705 gtk_requisition_copy,
11706 gtk_requisition_free)
11709 * gtk_widget_get_accessible:
11710 * @widget: a #GtkWidget
11712 * Returns the accessible object that describes the widget to an
11713 * assistive technology.
11715 * If no accessibility library is loaded (i.e. no ATK implementation library is
11716 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11717 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11718 * if no class-specific #AtkObject implementation is available for the widget
11719 * instance in question, it will inherit an #AtkObject implementation from the
11720 * first ancestor class for which such an implementation is defined.
11722 * The documentation of the
11723 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11724 * library contains more information about accessible objects and their uses.
11726 * Returns: (transfer none): the #AtkObject associated with @widget
11729 gtk_widget_get_accessible (GtkWidget *widget)
11731 GtkWidgetClass *klass;
11733 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11735 klass = GTK_WIDGET_GET_CLASS (widget);
11737 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11739 return klass->get_accessible (widget);
11743 gtk_widget_real_get_accessible (GtkWidget *widget)
11745 AtkObject* accessible;
11747 accessible = g_object_get_qdata (G_OBJECT (widget),
11748 quark_accessible_object);
11751 AtkObjectFactory *factory;
11752 AtkRegistry *default_registry;
11754 default_registry = atk_get_default_registry ();
11755 factory = atk_registry_get_factory (default_registry,
11756 G_TYPE_FROM_INSTANCE (widget));
11758 atk_object_factory_create_accessible (factory,
11759 G_OBJECT (widget));
11760 g_object_set_qdata (G_OBJECT (widget),
11761 quark_accessible_object,
11768 * Initialize a AtkImplementorIface instance's virtual pointers as
11769 * appropriate to this implementor's class (GtkWidget).
11772 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11774 iface->ref_accessible = gtk_widget_ref_accessible;
11778 gtk_widget_ref_accessible (AtkImplementor *implementor)
11780 AtkObject *accessible;
11782 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11784 g_object_ref (accessible);
11789 * Expand flag management
11793 gtk_widget_update_computed_expand (GtkWidget *widget)
11795 GtkWidgetPrivate *priv;
11797 priv = widget->priv;
11799 if (priv->need_compute_expand)
11803 if (priv->hexpand_set)
11808 if (priv->vexpand_set)
11813 /* we don't need to use compute_expand if both expands are
11814 * forced by the app
11816 if (!(priv->hexpand_set && priv->vexpand_set))
11818 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11822 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11823 priv->hexpand_set ? &ignored : &h,
11824 priv->vexpand_set ? &ignored : &v);
11828 priv->need_compute_expand = FALSE;
11829 priv->computed_hexpand = h != FALSE;
11830 priv->computed_vexpand = v != FALSE;
11835 * gtk_widget_queue_compute_expand:
11836 * @widget: a #GtkWidget
11838 * Mark @widget as needing to recompute its expand flags. Call
11839 * this function when setting legacy expand child properties
11840 * on the child of a container.
11842 * See gtk_widget_compute_expand().
11845 gtk_widget_queue_compute_expand (GtkWidget *widget)
11848 gboolean changed_anything;
11850 if (widget->priv->need_compute_expand)
11853 changed_anything = FALSE;
11855 while (parent != NULL)
11857 if (!parent->priv->need_compute_expand)
11859 parent->priv->need_compute_expand = TRUE;
11860 changed_anything = TRUE;
11863 /* Note: if we had an invariant that "if a child needs to
11864 * compute expand, its parents also do" then we could stop going
11865 * up when we got to a parent that already needed to
11866 * compute. However, in general we compute expand lazily (as
11867 * soon as we see something in a subtree that is expand, we know
11868 * we're expanding) and so this invariant does not hold and we
11869 * have to always walk all the way up in case some ancestor
11870 * is not currently need_compute_expand.
11873 parent = parent->priv->parent;
11876 /* recomputing expand always requires
11877 * a relayout as well
11879 if (changed_anything)
11880 gtk_widget_queue_resize (widget);
11884 * gtk_widget_compute_expand:
11885 * @widget: the widget
11886 * @orientation: expand direction
11888 * Computes whether a container should give this widget extra space
11889 * when possible. Containers should check this, rather than
11890 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11892 * This function already checks whether the widget is visible, so
11893 * visibility does not need to be checked separately. Non-visible
11894 * widgets are not expanded.
11896 * The computed expand value uses either the expand setting explicitly
11897 * set on the widget itself, or, if none has been explicitly set,
11898 * the widget may expand if some of its children do.
11900 * Return value: whether widget tree rooted here should be expanded
11903 gtk_widget_compute_expand (GtkWidget *widget,
11904 GtkOrientation orientation)
11906 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11908 /* We never make a widget expand if not even showing. */
11909 if (!gtk_widget_get_visible (widget))
11912 gtk_widget_update_computed_expand (widget);
11914 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11916 return widget->priv->computed_hexpand;
11920 return widget->priv->computed_vexpand;
11925 gtk_widget_set_expand (GtkWidget *widget,
11926 GtkOrientation orientation,
11929 const char *expand_prop;
11930 const char *expand_set_prop;
11932 GtkWidgetPrivate *priv;
11934 g_return_if_fail (GTK_IS_WIDGET (widget));
11936 priv = widget->priv;
11938 expand = expand != FALSE;
11940 was_both = priv->hexpand && priv->vexpand;
11942 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11944 if (priv->hexpand_set &&
11945 priv->hexpand == expand)
11948 priv->hexpand_set = TRUE;
11949 priv->hexpand = expand;
11951 expand_prop = "hexpand";
11952 expand_set_prop = "hexpand-set";
11956 if (priv->vexpand_set &&
11957 priv->vexpand == expand)
11960 priv->vexpand_set = TRUE;
11961 priv->vexpand = expand;
11963 expand_prop = "vexpand";
11964 expand_set_prop = "vexpand-set";
11967 gtk_widget_queue_compute_expand (widget);
11969 g_object_freeze_notify (G_OBJECT (widget));
11970 g_object_notify (G_OBJECT (widget), expand_prop);
11971 g_object_notify (G_OBJECT (widget), expand_set_prop);
11972 if (was_both != (priv->hexpand && priv->vexpand))
11973 g_object_notify (G_OBJECT (widget), "expand");
11974 g_object_thaw_notify (G_OBJECT (widget));
11978 gtk_widget_set_expand_set (GtkWidget *widget,
11979 GtkOrientation orientation,
11982 GtkWidgetPrivate *priv;
11985 priv = widget->priv;
11987 set = set != FALSE;
11989 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11991 if (set == priv->hexpand_set)
11994 priv->hexpand_set = set;
11995 prop = "hexpand-set";
11999 if (set == priv->vexpand_set)
12002 priv->vexpand_set = set;
12003 prop = "vexpand-set";
12006 gtk_widget_queue_compute_expand (widget);
12008 g_object_notify (G_OBJECT (widget), prop);
12012 * gtk_widget_get_hexpand:
12013 * @widget: the widget
12015 * Gets whether the widget would like any available extra horizontal
12016 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12017 * generally receive the extra space. For example, a list or
12018 * scrollable area or document in your window would often be set to
12021 * Containers should use gtk_widget_compute_expand() rather than
12022 * this function, to see whether a widget, or any of its children,
12023 * has the expand flag set. If any child of a widget wants to
12024 * expand, the parent may ask to expand also.
12026 * This function only looks at the widget's own hexpand flag, rather
12027 * than computing whether the entire widget tree rooted at this widget
12030 * Return value: whether hexpand flag is set
12033 gtk_widget_get_hexpand (GtkWidget *widget)
12035 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12037 return widget->priv->hexpand;
12041 * gtk_widget_set_hexpand:
12042 * @widget: the widget
12043 * @expand: whether to expand
12045 * Sets whether the widget would like any available extra horizontal
12046 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12047 * generally receive the extra space. For example, a list or
12048 * scrollable area or document in your window would often be set to
12051 * Call this function to set the expand flag if you would like your
12052 * widget to become larger horizontally when the window has extra
12055 * By default, widgets automatically expand if any of their children
12056 * want to expand. (To see if a widget will automatically expand given
12057 * its current children and state, call gtk_widget_compute_expand(). A
12058 * container can decide how the expandability of children affects the
12059 * expansion of the container by overriding the compute_expand virtual
12060 * method on #GtkWidget.).
12062 * Setting hexpand explicitly with this function will override the
12063 * automatic expand behavior.
12065 * This function forces the widget to expand or not to expand,
12066 * regardless of children. The override occurs because
12067 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12068 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12069 * value to be used, rather than looking at children and widget state.
12072 gtk_widget_set_hexpand (GtkWidget *widget,
12075 g_return_if_fail (GTK_IS_WIDGET (widget));
12077 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12081 * gtk_widget_get_hexpand_set:
12082 * @widget: the widget
12084 * Gets whether gtk_widget_set_hexpand() has been used to
12085 * explicitly set the expand flag on this widget.
12087 * If hexpand is set, then it overrides any computed
12088 * expand value based on child widgets. If hexpand is not
12089 * set, then the expand value depends on whether any
12090 * children of the widget would like to expand.
12092 * There are few reasons to use this function, but it's here
12093 * for completeness and consistency.
12095 * Return value: whether hexpand has been explicitly set
12098 gtk_widget_get_hexpand_set (GtkWidget *widget)
12100 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12102 return widget->priv->hexpand_set;
12106 * gtk_widget_set_hexpand_set:
12107 * @widget: the widget
12108 * @set: value for hexpand-set property
12110 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12113 * The hexpand-set property will be set automatically when you call
12114 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12115 * reason to use this function would be to unset an explicit expand
12118 * If hexpand is set, then it overrides any computed
12119 * expand value based on child widgets. If hexpand is not
12120 * set, then the expand value depends on whether any
12121 * children of the widget would like to expand.
12123 * There are few reasons to use this function, but it's here
12124 * for completeness and consistency.
12126 * Return value: whether hexpand has been explicitly set
12129 gtk_widget_set_hexpand_set (GtkWidget *widget,
12132 g_return_if_fail (GTK_IS_WIDGET (widget));
12134 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12139 * gtk_widget_get_vexpand:
12140 * @widget: the widget
12142 * Gets whether the widget would like any available extra vertical
12145 * See gtk_widget_get_hexpand() for more detail.
12147 * Return value: whether vexpand flag is set
12150 gtk_widget_get_vexpand (GtkWidget *widget)
12152 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12154 return widget->priv->vexpand;
12158 * gtk_widget_set_vexpand:
12159 * @widget: the widget
12160 * @expand: whether to expand
12162 * Sets whether the widget would like any available extra vertical
12165 * See gtk_widget_set_hexpand() for more detail.
12168 gtk_widget_set_vexpand (GtkWidget *widget,
12171 g_return_if_fail (GTK_IS_WIDGET (widget));
12173 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12177 * gtk_widget_get_vexpand_set:
12178 * @widget: the widget
12180 * Gets whether gtk_widget_set_vexpand() has been used to
12181 * explicitly set the expand flag on this widget.
12183 * See gtk_widget_get_hexpand_set() for more detail.
12185 * Return value: whether vexpand has been explicitly set
12188 gtk_widget_get_vexpand_set (GtkWidget *widget)
12190 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12192 return widget->priv->vexpand_set;
12196 * gtk_widget_set_vexpand_set:
12197 * @widget: the widget
12198 * @set: value for vexpand-set property
12200 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12203 * See gtk_widget_set_hexpand_set() for more detail.
12205 * Return value: whether vexpand has been explicitly set
12208 gtk_widget_set_vexpand_set (GtkWidget *widget,
12211 g_return_if_fail (GTK_IS_WIDGET (widget));
12213 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12217 * GtkBuildable implementation
12219 static GQuark quark_builder_has_default = 0;
12220 static GQuark quark_builder_has_focus = 0;
12221 static GQuark quark_builder_atk_relations = 0;
12222 static GQuark quark_builder_set_name = 0;
12225 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12227 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12228 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12229 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12230 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12232 iface->set_name = gtk_widget_buildable_set_name;
12233 iface->get_name = gtk_widget_buildable_get_name;
12234 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12235 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12236 iface->parser_finished = gtk_widget_buildable_parser_finished;
12237 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12238 iface->custom_finished = gtk_widget_buildable_custom_finished;
12242 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12245 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12246 g_strdup (name), g_free);
12249 static const gchar *
12250 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12252 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12256 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12257 GtkBuilder *builder,
12258 const gchar *childname)
12260 if (strcmp (childname, "accessible") == 0)
12261 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12267 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12268 GtkBuilder *builder,
12270 const GValue *value)
12272 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12273 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12274 GINT_TO_POINTER (TRUE));
12275 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12276 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12277 GINT_TO_POINTER (TRUE));
12279 g_object_set_property (G_OBJECT (buildable), name, value);
12284 gchar *action_name;
12285 GString *description;
12287 gboolean translatable;
12297 free_action (AtkActionData *data, gpointer user_data)
12299 g_free (data->action_name);
12300 g_string_free (data->description, TRUE);
12301 g_free (data->context);
12302 g_slice_free (AtkActionData, data);
12306 free_relation (AtkRelationData *data, gpointer user_data)
12308 g_free (data->target);
12309 g_free (data->type);
12310 g_slice_free (AtkRelationData, data);
12314 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12315 GtkBuilder *builder)
12317 GSList *atk_relations;
12319 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12320 gtk_widget_grab_default (GTK_WIDGET (buildable));
12321 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12322 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12324 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12325 quark_builder_atk_relations);
12328 AtkObject *accessible;
12329 AtkRelationSet *relation_set;
12332 AtkRelationType relation_type;
12333 AtkObject *target_accessible;
12335 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12336 relation_set = atk_object_ref_relation_set (accessible);
12338 for (l = atk_relations; l; l = l->next)
12340 AtkRelationData *relation = (AtkRelationData*)l->data;
12342 target = gtk_builder_get_object (builder, relation->target);
12345 g_warning ("Target object %s in <relation> does not exist",
12349 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12350 g_assert (target_accessible != NULL);
12352 relation_type = atk_relation_type_for_name (relation->type);
12353 if (relation_type == ATK_RELATION_NULL)
12355 g_warning ("<relation> type %s not found",
12359 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12360 target_accessible);
12362 g_object_unref (relation_set);
12364 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12365 g_slist_free (atk_relations);
12366 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12375 } AccessibilitySubParserData;
12378 accessibility_start_element (GMarkupParseContext *context,
12379 const gchar *element_name,
12380 const gchar **names,
12381 const gchar **values,
12382 gpointer user_data,
12385 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12387 gint line_number, char_number;
12389 if (strcmp (element_name, "relation") == 0)
12391 gchar *target = NULL;
12392 gchar *type = NULL;
12393 AtkRelationData *relation;
12395 for (i = 0; names[i]; i++)
12397 if (strcmp (names[i], "target") == 0)
12398 target = g_strdup (values[i]);
12399 else if (strcmp (names[i], "type") == 0)
12400 type = g_strdup (values[i]);
12403 g_markup_parse_context_get_position (context,
12406 g_set_error (error,
12408 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12409 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12411 line_number, char_number, names[i], "relation");
12418 if (!target || !type)
12420 g_markup_parse_context_get_position (context,
12423 g_set_error (error,
12425 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12426 "%s:%d:%d <%s> requires attribute \"%s\"",
12428 line_number, char_number, "relation",
12429 type ? "target" : "type");
12435 relation = g_slice_new (AtkRelationData);
12436 relation->target = target;
12437 relation->type = type;
12439 data->relations = g_slist_prepend (data->relations, relation);
12441 else if (strcmp (element_name, "action") == 0)
12443 const gchar *action_name = NULL;
12444 const gchar *description = NULL;
12445 const gchar *msg_context = NULL;
12446 gboolean translatable = FALSE;
12447 AtkActionData *action;
12449 for (i = 0; names[i]; i++)
12451 if (strcmp (names[i], "action_name") == 0)
12452 action_name = values[i];
12453 else if (strcmp (names[i], "description") == 0)
12454 description = values[i];
12455 else if (strcmp (names[i], "translatable") == 0)
12457 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12460 else if (strcmp (names[i], "comments") == 0)
12462 /* do nothing, comments are for translators */
12464 else if (strcmp (names[i], "context") == 0)
12465 msg_context = values[i];
12468 g_markup_parse_context_get_position (context,
12471 g_set_error (error,
12473 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12474 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12476 line_number, char_number, names[i], "action");
12483 g_markup_parse_context_get_position (context,
12486 g_set_error (error,
12488 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12489 "%s:%d:%d <%s> requires attribute \"%s\"",
12491 line_number, char_number, "action",
12496 action = g_slice_new (AtkActionData);
12497 action->action_name = g_strdup (action_name);
12498 action->description = g_string_new (description);
12499 action->context = g_strdup (msg_context);
12500 action->translatable = translatable;
12502 data->actions = g_slist_prepend (data->actions, action);
12504 else if (strcmp (element_name, "accessibility") == 0)
12507 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12511 accessibility_text (GMarkupParseContext *context,
12514 gpointer user_data,
12517 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12519 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12521 AtkActionData *action = data->actions->data;
12523 g_string_append_len (action->description, text, text_len);
12527 static const GMarkupParser accessibility_parser =
12529 accessibility_start_element,
12531 accessibility_text,
12540 } AccelGroupParserData;
12543 accel_group_start_element (GMarkupParseContext *context,
12544 const gchar *element_name,
12545 const gchar **names,
12546 const gchar **values,
12547 gpointer user_data,
12552 guint modifiers = 0;
12553 gchar *signal = NULL;
12554 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12556 for (i = 0; names[i]; i++)
12558 if (strcmp (names[i], "key") == 0)
12559 key = gdk_keyval_from_name (values[i]);
12560 else if (strcmp (names[i], "modifiers") == 0)
12562 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12568 else if (strcmp (names[i], "signal") == 0)
12569 signal = g_strdup (values[i]);
12572 if (key == 0 || signal == NULL)
12574 g_warning ("<accelerator> requires key and signal attributes");
12577 parser_data->key = key;
12578 parser_data->modifiers = modifiers;
12579 parser_data->signal = signal;
12582 static const GMarkupParser accel_group_parser =
12584 accel_group_start_element,
12588 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12589 GtkBuilder *builder,
12591 const gchar *tagname,
12592 GMarkupParser *parser,
12595 g_assert (buildable);
12597 if (strcmp (tagname, "accelerator") == 0)
12599 AccelGroupParserData *parser_data;
12601 parser_data = g_slice_new0 (AccelGroupParserData);
12602 parser_data->object = g_object_ref (buildable);
12603 *parser = accel_group_parser;
12604 *data = parser_data;
12607 if (strcmp (tagname, "accessibility") == 0)
12609 AccessibilitySubParserData *parser_data;
12611 parser_data = g_slice_new0 (AccessibilitySubParserData);
12612 *parser = accessibility_parser;
12613 *data = parser_data;
12620 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12621 GtkWidget *toplevel,
12622 gpointer user_data)
12624 AccelGroupParserData *accel_data;
12625 GSList *accel_groups;
12626 GtkAccelGroup *accel_group;
12628 g_return_if_fail (GTK_IS_WIDGET (widget));
12629 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12630 g_return_if_fail (user_data != NULL);
12632 accel_data = (AccelGroupParserData*)user_data;
12633 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12634 if (g_slist_length (accel_groups) == 0)
12636 accel_group = gtk_accel_group_new ();
12637 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12641 g_assert (g_slist_length (accel_groups) == 1);
12642 accel_group = g_slist_nth_data (accel_groups, 0);
12645 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12646 accel_data->signal,
12649 accel_data->modifiers,
12650 GTK_ACCEL_VISIBLE);
12652 g_object_unref (accel_data->object);
12653 g_free (accel_data->signal);
12654 g_slice_free (AccelGroupParserData, accel_data);
12658 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12659 GtkBuilder *builder,
12661 const gchar *tagname,
12662 gpointer user_data)
12664 AccelGroupParserData *accel_data;
12665 AccessibilitySubParserData *a11y_data;
12666 GtkWidget *toplevel;
12668 if (strcmp (tagname, "accelerator") == 0)
12670 accel_data = (AccelGroupParserData*)user_data;
12671 g_assert (accel_data->object);
12673 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12675 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12677 else if (strcmp (tagname, "accessibility") == 0)
12679 a11y_data = (AccessibilitySubParserData*)user_data;
12681 if (a11y_data->actions)
12683 AtkObject *accessible;
12688 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12690 action = ATK_ACTION (accessible);
12691 n_actions = atk_action_get_n_actions (action);
12693 for (l = a11y_data->actions; l; l = l->next)
12695 AtkActionData *action_data = (AtkActionData*)l->data;
12697 for (i = 0; i < n_actions; i++)
12698 if (strcmp (atk_action_get_name (action, i),
12699 action_data->action_name) == 0)
12704 gchar *description;
12706 if (action_data->translatable && action_data->description->len)
12707 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12708 action_data->context,
12709 action_data->description->str);
12711 description = action_data->description->str;
12713 atk_action_set_description (action, i, description);
12717 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12718 g_slist_free (a11y_data->actions);
12721 if (a11y_data->relations)
12722 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12723 a11y_data->relations);
12725 g_slice_free (AccessibilitySubParserData, a11y_data);
12730 gtk_widget_real_get_width (GtkWidget *widget,
12731 gint *minimum_size,
12732 gint *natural_size)
12742 gtk_widget_real_get_height (GtkWidget *widget,
12743 gint *minimum_size,
12744 gint *natural_size)
12754 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12756 gint *minimum_height,
12757 gint *natural_height)
12759 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12763 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12765 gint *minimum_width,
12766 gint *natural_width)
12768 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12772 * gtk_widget_get_halign:
12773 * @widget: a #GtkWidget
12775 * Gets the value of the #GtkWidget:halign property.
12777 * Returns: the horizontal alignment of @widget
12780 gtk_widget_get_halign (GtkWidget *widget)
12782 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12783 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12787 * gtk_widget_set_halign:
12788 * @widget: a #GtkWidget
12789 * @align: the horizontal alignment
12791 * Sets the horizontal alignment of @widget.
12792 * See the #GtkWidget:halign property.
12795 gtk_widget_set_halign (GtkWidget *widget,
12798 GtkWidgetAuxInfo *aux_info;
12800 g_return_if_fail (GTK_IS_WIDGET (widget));
12802 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12804 if (aux_info->halign == align)
12807 aux_info->halign = align;
12808 gtk_widget_queue_resize (widget);
12809 g_object_notify (G_OBJECT (widget), "halign");
12813 * gtk_widget_get_valign:
12814 * @widget: a #GtkWidget
12816 * Gets the value of the #GtkWidget:valign property.
12818 * Returns: the vertical alignment of @widget
12821 gtk_widget_get_valign (GtkWidget *widget)
12823 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12824 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12828 * gtk_widget_set_valign:
12829 * @widget: a #GtkWidget
12830 * @align: the vertical alignment
12832 * Sets the vertical alignment of @widget.
12833 * See the #GtkWidget:valign property.
12836 gtk_widget_set_valign (GtkWidget *widget,
12839 GtkWidgetAuxInfo *aux_info;
12841 g_return_if_fail (GTK_IS_WIDGET (widget));
12843 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12845 if (aux_info->valign == align)
12848 aux_info->valign = align;
12849 gtk_widget_queue_resize (widget);
12850 g_object_notify (G_OBJECT (widget), "valign");
12854 * gtk_widget_get_margin_left:
12855 * @widget: a #GtkWidget
12857 * Gets the value of the #GtkWidget:margin-left property.
12859 * Returns: The left margin of @widget
12862 gtk_widget_get_margin_left (GtkWidget *widget)
12864 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12866 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12870 * gtk_widget_set_margin_left:
12871 * @widget: a #GtkWidget
12872 * @margin: the left margin
12874 * Sets the left margin of @widget.
12875 * See the #GtkWidget:margin-left property.
12878 gtk_widget_set_margin_left (GtkWidget *widget,
12881 GtkWidgetAuxInfo *aux_info;
12883 g_return_if_fail (GTK_IS_WIDGET (widget));
12884 g_return_if_fail (margin <= G_MAXINT16);
12886 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12888 if (aux_info->margin.left == margin)
12891 aux_info->margin.left = margin;
12892 gtk_widget_queue_resize (widget);
12893 g_object_notify (G_OBJECT (widget), "margin-left");
12897 * gtk_widget_get_margin_right:
12898 * @widget: a #GtkWidget
12900 * Gets the value of the #GtkWidget:margin-right property.
12902 * Returns: The left margin of @widget
12905 gtk_widget_get_margin_right (GtkWidget *widget)
12907 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12909 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12913 * gtk_widget_set_margin_right:
12914 * @widget: a #GtkWidget
12915 * @margin: the right margin
12917 * Sets the right margin of @widget.
12918 * See the #GtkWidget:margin-right property.
12921 gtk_widget_set_margin_right (GtkWidget *widget,
12924 GtkWidgetAuxInfo *aux_info;
12926 g_return_if_fail (GTK_IS_WIDGET (widget));
12927 g_return_if_fail (margin <= G_MAXINT16);
12929 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12931 if (aux_info->margin.right == margin)
12934 aux_info->margin.right = margin;
12935 gtk_widget_queue_resize (widget);
12936 g_object_notify (G_OBJECT (widget), "margin-right");
12940 * gtk_widget_get_margin_top:
12941 * @widget: a #GtkWidget
12943 * Gets the value of the #GtkWidget:margin-top property.
12945 * Returns: The top margin of @widget
12948 gtk_widget_get_margin_top (GtkWidget *widget)
12950 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12952 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12956 * gtk_widget_set_margin_top:
12957 * @widget: a #GtkWidget
12958 * @margin: the top margin
12960 * Sets the top margin of @widget.
12961 * See the #GtkWidget:margin-top property.
12964 gtk_widget_set_margin_top (GtkWidget *widget,
12967 GtkWidgetAuxInfo *aux_info;
12969 g_return_if_fail (GTK_IS_WIDGET (widget));
12970 g_return_if_fail (margin <= G_MAXINT16);
12972 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12974 if (aux_info->margin.top == margin)
12977 aux_info->margin.top = margin;
12978 gtk_widget_queue_resize (widget);
12979 g_object_notify (G_OBJECT (widget), "margin-top");
12983 * gtk_widget_get_margin_bottom:
12984 * @widget: a #GtkWidget
12986 * Gets the value of the #GtkWidget:margin-bottom property.
12988 * Returns: The bottom margin of @widget
12991 gtk_widget_get_margin_bottom (GtkWidget *widget)
12993 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12995 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12999 * gtk_widget_set_margin_bottom:
13000 * @widget: a #GtkWidget
13001 * @margin: the bottom margin
13003 * Sets the bottom margin of @widget.
13004 * See the #GtkWidget:margin-bottom property.
13007 gtk_widget_set_margin_bottom (GtkWidget *widget,
13010 GtkWidgetAuxInfo *aux_info;
13012 g_return_if_fail (GTK_IS_WIDGET (widget));
13013 g_return_if_fail (margin <= G_MAXINT16);
13015 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13017 if (aux_info->margin.bottom == margin)
13020 aux_info->margin.bottom = margin;
13021 gtk_widget_queue_resize (widget);
13022 g_object_notify (G_OBJECT (widget), "margin-bottom");
13026 * gtk_widget_get_clipboard:
13027 * @widget: a #GtkWidget
13028 * @selection: a #GdkAtom which identifies the clipboard
13029 * to use. %GDK_SELECTION_CLIPBOARD gives the
13030 * default clipboard. Another common value
13031 * is %GDK_SELECTION_PRIMARY, which gives
13032 * the primary X selection.
13034 * Returns the clipboard object for the given selection to
13035 * be used with @widget. @widget must have a #GdkDisplay
13036 * associated with it, so must be attached to a toplevel
13039 * Return value: (transfer none): the appropriate clipboard object. If no
13040 * clipboard already exists, a new one will
13041 * be created. Once a clipboard object has
13042 * been created, it is persistent for all time.
13047 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13049 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13050 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13052 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13057 * gtk_widget_list_mnemonic_labels:
13058 * @widget: a #GtkWidget
13060 * Returns a newly allocated list of the widgets, normally labels, for
13061 * which this widget is the target of a mnemonic (see for example,
13062 * gtk_label_set_mnemonic_widget()).
13064 * The widgets in the list are not individually referenced. If you
13065 * want to iterate through the list and perform actions involving
13066 * callbacks that might destroy the widgets, you
13067 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13068 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13069 * widgets afterwards.
13071 * Return value: (element-type GtkWidget) (transfer container): the list of
13072 * mnemonic labels; free this list
13073 * with g_list_free() when you are done with it.
13078 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13080 GList *list = NULL;
13083 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13085 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13086 list = g_list_prepend (list, l->data);
13092 * gtk_widget_add_mnemonic_label:
13093 * @widget: a #GtkWidget
13094 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13096 * Adds a widget to the list of mnemonic labels for
13097 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13098 * list of mnemonic labels for the widget is cleared when the
13099 * widget is destroyed, so the caller must make sure to update
13100 * its internal state at this point as well, by using a connection
13101 * to the #GtkWidget::destroy signal or a weak notifier.
13106 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13109 GSList *old_list, *new_list;
13111 g_return_if_fail (GTK_IS_WIDGET (widget));
13112 g_return_if_fail (GTK_IS_WIDGET (label));
13114 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13115 new_list = g_slist_prepend (old_list, label);
13117 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13118 new_list, (GDestroyNotify) g_slist_free);
13122 * gtk_widget_remove_mnemonic_label:
13123 * @widget: a #GtkWidget
13124 * @label: a #GtkWidget that was previously set as a mnemnic label for
13125 * @widget with gtk_widget_add_mnemonic_label().
13127 * Removes a widget from the list of mnemonic labels for
13128 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13129 * must have previously been added to the list with
13130 * gtk_widget_add_mnemonic_label().
13135 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13138 GSList *old_list, *new_list;
13140 g_return_if_fail (GTK_IS_WIDGET (widget));
13141 g_return_if_fail (GTK_IS_WIDGET (label));
13143 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13144 new_list = g_slist_remove (old_list, label);
13147 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13148 new_list, (GDestroyNotify) g_slist_free);
13152 * gtk_widget_get_no_show_all:
13153 * @widget: a #GtkWidget
13155 * Returns the current value of the #GtkWidget:no-show-all property,
13156 * which determines whether calls to gtk_widget_show_all()
13157 * will affect this widget.
13159 * Return value: the current value of the "no-show-all" property.
13164 gtk_widget_get_no_show_all (GtkWidget *widget)
13166 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13168 return widget->priv->no_show_all;
13172 * gtk_widget_set_no_show_all:
13173 * @widget: a #GtkWidget
13174 * @no_show_all: the new value for the "no-show-all" property
13176 * Sets the #GtkWidget:no-show-all property, which determines whether
13177 * calls to gtk_widget_show_all() will affect this widget.
13179 * This is mostly for use in constructing widget hierarchies with externally
13180 * controlled visibility, see #GtkUIManager.
13185 gtk_widget_set_no_show_all (GtkWidget *widget,
13186 gboolean no_show_all)
13188 g_return_if_fail (GTK_IS_WIDGET (widget));
13190 no_show_all = (no_show_all != FALSE);
13192 if (widget->priv->no_show_all != no_show_all)
13194 widget->priv->no_show_all = no_show_all;
13196 g_object_notify (G_OBJECT (widget), "no-show-all");
13202 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13203 gboolean has_tooltip,
13206 GtkWidgetPrivate *priv = widget->priv;
13207 gboolean priv_has_tooltip;
13209 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13210 quark_has_tooltip));
13212 if (priv_has_tooltip != has_tooltip || force)
13214 priv_has_tooltip = has_tooltip;
13216 if (priv_has_tooltip)
13218 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13219 gdk_window_set_events (priv->window,
13220 gdk_window_get_events (priv->window) |
13221 GDK_LEAVE_NOTIFY_MASK |
13222 GDK_POINTER_MOTION_MASK |
13223 GDK_POINTER_MOTION_HINT_MASK);
13225 if (gtk_widget_get_has_window (widget))
13226 gtk_widget_add_events (widget,
13227 GDK_LEAVE_NOTIFY_MASK |
13228 GDK_POINTER_MOTION_MASK |
13229 GDK_POINTER_MOTION_HINT_MASK);
13232 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13233 GUINT_TO_POINTER (priv_has_tooltip));
13238 * gtk_widget_set_tooltip_window:
13239 * @widget: a #GtkWidget
13240 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13242 * Replaces the default, usually yellow, window used for displaying
13243 * tooltips with @custom_window. GTK+ will take care of showing and
13244 * hiding @custom_window at the right moment, to behave likewise as
13245 * the default tooltip window. If @custom_window is %NULL, the default
13246 * tooltip window will be used.
13248 * If the custom window should have the default theming it needs to
13249 * have the name "gtk-tooltip", see gtk_widget_set_name().
13254 gtk_widget_set_tooltip_window (GtkWidget *widget,
13255 GtkWindow *custom_window)
13257 gboolean has_tooltip;
13258 gchar *tooltip_markup;
13260 g_return_if_fail (GTK_IS_WIDGET (widget));
13261 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13263 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13266 g_object_ref (custom_window);
13268 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13269 custom_window, g_object_unref);
13271 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13272 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13274 if (has_tooltip && gtk_widget_get_visible (widget))
13275 gtk_widget_queue_tooltip_query (widget);
13279 * gtk_widget_get_tooltip_window:
13280 * @widget: a #GtkWidget
13282 * Returns the #GtkWindow of the current tooltip. This can be the
13283 * GtkWindow created by default, or the custom tooltip window set
13284 * using gtk_widget_set_tooltip_window().
13286 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13291 gtk_widget_get_tooltip_window (GtkWidget *widget)
13293 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13295 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13299 * gtk_widget_trigger_tooltip_query:
13300 * @widget: a #GtkWidget
13302 * Triggers a tooltip query on the display where the toplevel of @widget
13303 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13309 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13311 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13314 static guint tooltip_query_id;
13315 static GSList *tooltip_query_displays;
13318 tooltip_query_idle (gpointer data)
13320 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13321 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13322 g_slist_free (tooltip_query_displays);
13324 tooltip_query_displays = NULL;
13325 tooltip_query_id = 0;
13331 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13333 GdkDisplay *display;
13335 display = gtk_widget_get_display (widget);
13337 if (!g_slist_find (tooltip_query_displays, display))
13338 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13340 if (tooltip_query_id == 0)
13341 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13345 * gtk_widget_set_tooltip_text:
13346 * @widget: a #GtkWidget
13347 * @text: the contents of the tooltip for @widget
13349 * Sets @text as the contents of the tooltip. This function will take
13350 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13351 * handler for the #GtkWidget::query-tooltip signal.
13353 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13358 gtk_widget_set_tooltip_text (GtkWidget *widget,
13361 g_return_if_fail (GTK_IS_WIDGET (widget));
13363 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13367 * gtk_widget_get_tooltip_text:
13368 * @widget: a #GtkWidget
13370 * Gets the contents of the tooltip for @widget.
13372 * Return value: the tooltip text, or %NULL. You should free the
13373 * returned string with g_free() when done.
13378 gtk_widget_get_tooltip_text (GtkWidget *widget)
13380 gchar *text = NULL;
13382 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13384 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13390 * gtk_widget_set_tooltip_markup:
13391 * @widget: a #GtkWidget
13392 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13394 * Sets @markup as the contents of the tooltip, which is marked up with
13395 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13397 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13398 * and of the default handler for the #GtkWidget::query-tooltip signal.
13400 * See also the #GtkWidget:tooltip-markup property and
13401 * gtk_tooltip_set_markup().
13406 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13407 const gchar *markup)
13409 g_return_if_fail (GTK_IS_WIDGET (widget));
13411 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13415 * gtk_widget_get_tooltip_markup:
13416 * @widget: a #GtkWidget
13418 * Gets the contents of the tooltip for @widget.
13420 * Return value: the tooltip text, or %NULL. You should free the
13421 * returned string with g_free() when done.
13426 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13428 gchar *text = NULL;
13430 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13432 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13438 * gtk_widget_set_has_tooltip:
13439 * @widget: a #GtkWidget
13440 * @has_tooltip: whether or not @widget has a tooltip.
13442 * Sets the has-tooltip property on @widget to @has_tooltip. See
13443 * #GtkWidget:has-tooltip for more information.
13448 gtk_widget_set_has_tooltip (GtkWidget *widget,
13449 gboolean has_tooltip)
13451 g_return_if_fail (GTK_IS_WIDGET (widget));
13453 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13457 * gtk_widget_get_has_tooltip:
13458 * @widget: a #GtkWidget
13460 * Returns the current value of the has-tooltip property. See
13461 * #GtkWidget:has-tooltip for more information.
13463 * Return value: current value of has-tooltip on @widget.
13468 gtk_widget_get_has_tooltip (GtkWidget *widget)
13470 gboolean has_tooltip = FALSE;
13472 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13474 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13476 return has_tooltip;
13480 * gtk_widget_get_allocation:
13481 * @widget: a #GtkWidget
13482 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13484 * Retrieves the widget's allocation.
13486 * Note, when implementing a #GtkContainer: a widget's allocation will
13487 * be its "adjusted" allocation, that is, the widget's parent
13488 * container typically calls gtk_widget_size_allocate() with an
13489 * allocation, and that allocation is then adjusted (to handle margin
13490 * and alignment for example) before assignment to the widget.
13491 * gtk_widget_get_allocation() returns the adjusted allocation that
13492 * was actually assigned to the widget. The adjusted allocation is
13493 * guaranteed to be completely contained within the
13494 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13495 * is guaranteed that its children stay inside the assigned bounds,
13496 * but not that they have exactly the bounds the container assigned.
13497 * There is no way to get the original allocation assigned by
13498 * gtk_widget_size_allocate(), since it isn't stored; if a container
13499 * implementation needs that information it will have to track it itself.
13504 gtk_widget_get_allocation (GtkWidget *widget,
13505 GtkAllocation *allocation)
13507 GtkWidgetPrivate *priv;
13509 g_return_if_fail (GTK_IS_WIDGET (widget));
13510 g_return_if_fail (allocation != NULL);
13512 priv = widget->priv;
13514 *allocation = priv->allocation;
13518 * gtk_widget_set_allocation:
13519 * @widget: a #GtkWidget
13520 * @allocation: a pointer to a #GtkAllocation to copy from
13522 * Sets the widget's allocation. This should not be used
13523 * directly, but from within a widget's size_allocate method.
13525 * The allocation set should be the "adjusted" or actual
13526 * allocation. If you're implementing a #GtkContainer, you want to use
13527 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13528 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13529 * allocation inside gtk_widget_size_allocate() to create an adjusted
13535 gtk_widget_set_allocation (GtkWidget *widget,
13536 const GtkAllocation *allocation)
13538 GtkWidgetPrivate *priv;
13540 g_return_if_fail (GTK_IS_WIDGET (widget));
13541 g_return_if_fail (allocation != NULL);
13543 priv = widget->priv;
13545 priv->allocation = *allocation;
13549 * gtk_widget_get_allocated_width:
13550 * @widget: the widget to query
13552 * Returns the width that has currently been allocated to @widget.
13553 * This function is intended to be used when implementing handlers
13554 * for the #GtkWidget::draw function.
13556 * Returns: the width of the @widget
13559 gtk_widget_get_allocated_width (GtkWidget *widget)
13561 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13563 return widget->priv->allocation.width;
13567 * gtk_widget_get_allocated_height:
13568 * @widget: the widget to query
13570 * Returns the height that has currently been allocated to @widget.
13571 * This function is intended to be used when implementing handlers
13572 * for the #GtkWidget::draw function.
13574 * Returns: the height of the @widget
13577 gtk_widget_get_allocated_height (GtkWidget *widget)
13579 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13581 return widget->priv->allocation.height;
13585 * gtk_widget_get_requisition:
13586 * @widget: a #GtkWidget
13587 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13589 * Retrieves the widget's requisition.
13591 * This function should only be used by widget implementations in
13592 * order to figure whether the widget's requisition has actually
13593 * changed after some internal state change (so that they can call
13594 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13596 * Normally, gtk_widget_size_request() should be used.
13600 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13601 * removed, If you need to cache sizes across requests and allocations,
13602 * add an explicit cache to the widget in question instead.
13605 gtk_widget_get_requisition (GtkWidget *widget,
13606 GtkRequisition *requisition)
13608 g_return_if_fail (GTK_IS_WIDGET (widget));
13609 g_return_if_fail (requisition != NULL);
13611 gtk_widget_get_preferred_size (widget, requisition, NULL);
13615 * gtk_widget_set_window:
13616 * @widget: a #GtkWidget
13617 * @window: a #GdkWindow
13619 * Sets a widget's window. This function should only be used in a
13620 * widget's #GtkWidget::realize implementation. The %window passed is
13621 * usually either new window created with gdk_window_new(), or the
13622 * window of its parent widget as returned by
13623 * gtk_widget_get_parent_window().
13625 * Widgets must indicate whether they will create their own #GdkWindow
13626 * by calling gtk_widget_set_has_window(). This is usually done in the
13627 * widget's init() function.
13629 * <note><para>This function does not add any reference to @window.</para></note>
13634 gtk_widget_set_window (GtkWidget *widget,
13637 GtkWidgetPrivate *priv;
13639 g_return_if_fail (GTK_IS_WIDGET (widget));
13640 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13642 priv = widget->priv;
13644 if (priv->window != window)
13646 priv->window = window;
13647 g_object_notify (G_OBJECT (widget), "window");
13652 * gtk_widget_get_window:
13653 * @widget: a #GtkWidget
13655 * Returns the widget's window if it is realized, %NULL otherwise
13657 * Return value: (transfer none): @widget's window.
13662 gtk_widget_get_window (GtkWidget *widget)
13664 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13666 return widget->priv->window;
13670 * gtk_widget_get_support_multidevice:
13671 * @widget: a #GtkWidget
13673 * Returns %TRUE if @widget is multiple pointer aware. See
13674 * gtk_widget_set_support_multidevice() for more information.
13676 * Returns: %TRUE is @widget is multidevice aware.
13679 gtk_widget_get_support_multidevice (GtkWidget *widget)
13681 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13683 return widget->priv->multidevice;
13687 * gtk_widget_set_support_multidevice:
13688 * @widget: a #GtkWidget
13689 * @support_multidevice: %TRUE to support input from multiple devices.
13691 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13692 * @widget will start receiving multiple, per device enter/leave events. Note
13693 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13694 * gdk_window_set_support_multidevice() will have to be called manually on them.
13699 gtk_widget_set_support_multidevice (GtkWidget *widget,
13700 gboolean support_multidevice)
13702 GtkWidgetPrivate *priv;
13704 g_return_if_fail (GTK_IS_WIDGET (widget));
13706 priv = widget->priv;
13708 if (support_multidevice)
13710 priv->multidevice = TRUE;
13711 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13715 priv->multidevice = FALSE;
13716 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13719 if (gtk_widget_get_realized (widget))
13720 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13724 _gtk_widget_set_has_focus (GtkWidget *widget,
13725 gboolean has_focus)
13727 widget->priv->has_focus = has_focus;
13731 * gtk_widget_send_focus_change:
13732 * @widget: a #GtkWidget
13733 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13735 * Sends the focus change @event to @widget
13737 * This function is not meant to be used by applications. The only time it
13738 * should be used is when it is necessary for a #GtkWidget to assign focus
13739 * to a widget that is semantically owned by the first widget even though
13740 * it's not a direct child - for instance, a search entry in a floating
13741 * window similar to the quick search in #GtkTreeView.
13743 * An example of its usage is:
13746 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13748 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13749 * fevent->focus_change.in = TRUE;
13750 * fevent->focus_change.window = gtk_widget_get_window (widget);
13751 * if (fevent->focus_change.window != NULL)
13752 * g_object_ref (fevent->focus_change.window);
13754 * gtk_widget_send_focus_change (widget, fevent);
13756 * gdk_event_free (event);
13759 * Return value: the return value from the event signal emission: %TRUE
13760 * if the event was handled, and %FALSE otherwise
13765 gtk_widget_send_focus_change (GtkWidget *widget,
13770 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13771 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13773 g_object_ref (widget);
13775 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13777 res = gtk_widget_event (widget, event);
13779 g_object_notify (G_OBJECT (widget), "has-focus");
13781 g_object_unref (widget);
13787 * gtk_widget_in_destruction:
13788 * @widget: a #GtkWidget
13790 * Returns whether the widget is currently being destroyed.
13791 * This information can sometimes be used to avoid doing
13792 * unnecessary work.
13794 * Returns: %TRUE if @widget is being destroyed
13797 gtk_widget_in_destruction (GtkWidget *widget)
13799 return widget->priv->in_destruction;
13803 _gtk_widget_get_resize_pending (GtkWidget *widget)
13805 return widget->priv->resize_pending;
13809 _gtk_widget_set_resize_pending (GtkWidget *widget,
13810 gboolean resize_pending)
13812 widget->priv->resize_pending = resize_pending;
13816 _gtk_widget_get_in_reparent (GtkWidget *widget)
13818 return widget->priv->in_reparent;
13822 _gtk_widget_set_in_reparent (GtkWidget *widget,
13823 gboolean in_reparent)
13825 widget->priv->in_reparent = in_reparent;
13829 _gtk_widget_get_anchored (GtkWidget *widget)
13831 return widget->priv->anchored;
13835 _gtk_widget_set_anchored (GtkWidget *widget,
13838 widget->priv->anchored = anchored;
13842 _gtk_widget_get_shadowed (GtkWidget *widget)
13844 return widget->priv->shadowed;
13848 _gtk_widget_set_shadowed (GtkWidget *widget,
13851 widget->priv->shadowed = shadowed;
13855 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13857 return widget->priv->alloc_needed;
13861 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13862 gboolean alloc_needed)
13864 widget->priv->alloc_needed = alloc_needed;
13868 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13870 return widget->priv->width_request_needed;
13874 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13875 gboolean width_request_needed)
13877 widget->priv->width_request_needed = width_request_needed;
13881 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13883 return widget->priv->height_request_needed;
13887 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13888 gboolean height_request_needed)
13890 widget->priv->height_request_needed = height_request_needed;
13894 * gtk_widget_get_path:
13895 * @widget: a #GtkWidget
13897 * Returns the #GtkWidgetPath representing @widget, if the widget
13898 * is not connected to a toplevel widget, a partial path will be
13901 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13904 gtk_widget_get_path (GtkWidget *widget)
13906 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13908 /* As strange as it may seem, this may happen on object construction.
13909 * init() implementations of parent types may eventually call this function,
13910 * each with its corresponding GType, which could leave a child
13911 * implementation with a wrong widget type in the widget path
13913 if (widget->priv->path &&
13914 G_OBJECT_TYPE (widget) != gtk_widget_path_get_widget_type (widget->priv->path))
13916 gtk_widget_path_free (widget->priv->path);
13917 widget->priv->path = NULL;
13920 if (!widget->priv->path)
13925 parent = widget->priv->parent;
13928 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13931 /* Widget is either toplevel or unparented, treat both
13932 * as toplevels style wise, since there are situations
13933 * where style properties might be retrieved on that
13936 widget->priv->path = gtk_widget_path_new ();
13939 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13941 if (widget->priv->name)
13942 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13944 if (widget->priv->context)
13945 gtk_style_context_set_path (widget->priv->context,
13946 widget->priv->path);
13949 return widget->priv->path;
13953 style_context_changed (GtkStyleContext *context,
13954 gpointer user_data)
13956 GtkWidget *widget = user_data;
13958 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13962 * gtk_widget_get_style_context:
13963 * @widget: a #GtkWidget
13965 * Returns the style context associated to @widget.
13967 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13968 * must not be freed.
13971 gtk_widget_get_style_context (GtkWidget *widget)
13973 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13975 if (G_UNLIKELY (!widget->priv->context))
13977 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13978 "direction", gtk_widget_get_direction (widget),
13981 g_signal_connect (widget->priv->context, "changed",
13982 G_CALLBACK (style_context_changed), widget);
13984 gtk_style_context_set_screen (widget->priv->context,
13985 gtk_widget_get_screen (widget));
13987 _gtk_widget_update_path (widget);
13988 gtk_style_context_set_path (widget->priv->context,
13989 widget->priv->path);
13993 /* Force widget path regeneration if needed, the
13994 * context will be updated within this function.
13996 gtk_widget_get_path (widget);
13999 return widget->priv->context;