1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
61 #include "gtkstylecontext.h"
62 #include "gtksymboliccolor.h"
63 #include "gtkcssprovider.h"
64 #include "gtkanimationdescription.h"
65 #include "gtkmodifierstyle.h"
66 #include "gtkversion.h"
72 * @Short_description: Base class for all widgets
75 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
76 * widget lifecycle, states and style.
78 * <refsect2 id="geometry-management">
79 * <title>Height-for-width Geometry Management</title>
81 * GTK+ uses a height-for-width (and width-for-height) geometry management
82 * system. Height-for-width means that a widget can change how much
83 * vertical space it needs, depending on the amount of horizontal space
84 * that it is given (and similar for width-for-height). The most common
85 * example is a label that reflows to fill up the available width, wraps
86 * to fewer lines, and therefore needs less height.
88 * Height-for-width geometry management is implemented in GTK+ by way
89 * of five virtual methods:
91 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
95 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
98 * There are some important things to keep in mind when implementing
99 * height-for-width and when using it in container implementations.
101 * The geometry management system will query a widget hierarchy in
102 * only one orientation at a time. When widgets are initially queried
103 * for their minimum sizes it is generally done in two initial passes
104 * in the #GtkSizeRequestMode chosen by the toplevel.
106 * For example, when queried in the normal
107 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
108 * First, the default minimum and natural width for each widget
109 * in the interface will be computed using gtk_width_get_preferred_width().
110 * Because the preferred widths for each container depend on the preferred
111 * widths of their children, this information propagates up the hierarchy,
112 * and finally a minimum and natural width is determined for the entire
113 * toplevel. Next, the toplevel will use the minimum width to query for the
114 * minimum height contextual to that width using
115 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
116 * recursive operation. The minimum height for the minimum width is normally
117 * used to set the minimum size constraint on the toplevel
118 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
120 * After the toplevel window has initially requested its size in both
121 * dimensions it can go on to allocate itself a reasonable size (or a size
122 * previously specified with gtk_window_set_default_size()). During the
123 * recursive allocation process it's important to note that request cycles
124 * will be recursively executed while container widgets allocate their children.
125 * Each container widget, once allocated a size, will go on to first share the
126 * space in one orientation among its children and then request each child's
127 * height for its target allocated width or its width for allocated height,
128 * depending. In this way a #GtkWidget will typically be requested its size
129 * a number of times before actually being allocated a size. The size a
130 * widget is finally allocated can of course differ from the size it has
131 * requested. For this reason, #GtkWidget caches a small number of results
132 * to avoid re-querying for the same sizes in one allocation cycle.
134 * See <link linkend="container-geometry-management">GtkContainer's
135 * geometry management section</link>
136 * to learn more about how height-for-width allocations are performed
137 * by container widgets.
139 * If a widget does move content around to intelligently use up the
140 * allocated size then it must support the request in both
141 * #GtkSizeRequestModes even if the widget in question only
142 * trades sizes in a single orientation.
144 * For instance, a #GtkLabel that does height-for-width word wrapping
145 * will not expect to have #GtkWidgetClass.get_preferred_height() called
146 * because that call is specific to a width-for-height request. In this
147 * case the label must return the height required for its own minimum
148 * possible width. By following this rule any widget that handles
149 * height-for-width or width-for-height requests will always be allocated
150 * at least enough space to fit its own content.
152 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
153 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
155 * <programlisting><![CDATA[
157 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
159 * if (i_am_in_height_for_width_mode)
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
164 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
165 * min_height, nat_height);
169 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
170 * it will return the minimum and natural height for the rotated label here.
173 * ]]></programlisting>
175 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
176 * the minimum and natural width:
178 * <programlisting><![CDATA[
180 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
181 * gint *min_width, gint *nat_width)
183 * if (i_am_in_height_for_width_mode)
185 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
189 * ... again if a widget is sometimes operating in width-for-height mode
190 * (like a rotated GtkLabel) it can go ahead and do its real width for
191 * height calculation here.
194 * ]]></programlisting>
196 * Often a widget needs to get its own request during size request or
197 * allocation. For example, when computing height it may need to also
198 * compute width. Or when deciding how to use an allocation, the widget
199 * may need to know its natural size. In these cases, the widget should
200 * be careful to call its virtual methods directly, like this:
202 * <title>Widget calling its own size request method.</title>
204 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
209 * It will not work to use the wrapper functions, such as
210 * gtk_widget_get_preferred_width() inside your own size request
211 * implementation. These return a request adjusted by #GtkSizeGroup
212 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
213 * widget used the wrappers inside its virtual method implementations,
214 * then the adjustments (such as widget margins) would be applied
215 * twice. GTK+ therefore does not allow this and will warn if you try
218 * Of course if you are getting the size request for
219 * <emphasis>another</emphasis> widget, such as a child of a
220 * container, you <emphasis>must</emphasis> use the wrapper APIs.
221 * Otherwise, you would not properly consider widget margins,
222 * #GtkSizeGroup, and so forth.
225 * <refsect2 id="style-properties">
226 * <title>Style Properties</title>
228 * <structname>GtkWidget</structname> introduces <firstterm>style
229 * properties</firstterm> - these are basically object properties that are stored
230 * not on the object, but in the style object associated to the widget. Style
231 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
232 * This mechanism is used for configuring such things as the location of the
233 * scrollbar arrows through the theme, giving theme authors more control over the
234 * look of applications without the need to write a theme engine in C.
237 * Use gtk_widget_class_install_style_property() to install style properties for
238 * a widget class, gtk_widget_class_find_style_property() or
239 * gtk_widget_class_list_style_properties() to get information about existing
240 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
241 * gtk_widget_style_get_valist() to obtain the value of a style property.
244 * <refsect2 id="GtkWidget-BUILDER-UI">
245 * <title>GtkWidget as GtkBuildable</title>
247 * The GtkWidget implementation of the GtkBuildable interface supports a
248 * custom <accelerator> element, which has attributes named key,
249 * modifiers and signal and allows to specify accelerators.
252 * <title>A UI definition fragment specifying an accelerator</title>
253 * <programlisting><![CDATA[
254 * <object class="GtkButton">
255 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
257 * ]]></programlisting>
260 * In addition to accelerators, <structname>GtkWidget</structname> also support a
261 * custom <accessible> element, which supports actions and relations.
262 * Properties on the accessible implementation of an object can be set by accessing the
263 * internal child "accessible" of a <structname>GtkWidget</structname>.
266 * <title>A UI definition fragment specifying an accessible</title>
267 * <programlisting><![CDATA[
268 * <object class="GtkButton" id="label1"/>
269 * <property name="label">I am a Label for a Button</property>
271 * <object class="GtkButton" id="button1">
273 * <action action_name="click" translatable="yes">Click the button.</action>
274 * <relation target="label1" type="labelled-by"/>
276 * <child internal-child="accessible">
277 * <object class="AtkObject" id="a11y-button1">
278 * <property name="AtkObject::name">Clickable Button</property>
282 * ]]></programlisting>
287 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
288 #define INIT_PATH_SIZE (512)
290 struct _GtkWidgetPrivate
292 /* The state of the widget. There are actually only
293 * 5 widget states (defined in "gtkenums.h")
296 guint state_flags : 6;
300 guint in_destruction : 1;
303 guint composite_child : 1;
309 guint parent_sensitive : 1;
312 guint can_default : 1;
313 guint has_default : 1;
314 guint receives_default : 1;
318 guint user_style : 1;
319 guint app_paintable : 1;
320 guint double_buffered : 1;
321 guint redraw_on_alloc : 1;
322 guint no_show_all : 1;
323 guint child_visible : 1;
324 guint multidevice : 1;
325 guint has_shape_mask : 1;
326 guint in_reparent : 1;
327 guint resize_pending : 1;
328 guint alloc_needed : 1;
329 guint width_request_needed : 1;
330 guint height_request_needed : 1;
332 /* Expand-related flags */
333 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
334 guint computed_hexpand : 1; /* computed results (composite of child flags) */
335 guint computed_vexpand : 1;
336 guint hexpand : 1; /* application-forced expand */
338 guint hexpand_set : 1; /* whether to use application-forced */
339 guint vexpand_set : 1; /* instead of computing from children */
341 /* The widget's name. If the widget does not have a name
342 * (the name is NULL), then its name (as returned by
343 * "gtk_widget_get_name") is its class's name.
344 * Among other things, the widget name is used to determine
345 * the style to use for a widget.
349 /* The style for the widget. The style contains the
350 * colors the widget should be drawn in for each state
351 * along with graphics contexts used to draw with and
352 * the font to use for text.
355 GtkStyleContext *context;
357 /* The widget's allocated size.
359 GtkAllocation allocation;
361 /* The widget's requested sizes */
362 SizeRequestCache requests;
364 /* The widget's window or its parent window if it does
365 * not have a window. (Which will be indicated by the
366 * GTK_NO_WINDOW flag being set).
370 /* The widget's parent.
374 /* Widget's path for styling */
404 BUTTON_RELEASE_EVENT,
419 PROPERTY_NOTIFY_EVENT,
420 SELECTION_CLEAR_EVENT,
421 SELECTION_REQUEST_EVENT,
422 SELECTION_NOTIFY_EVENT,
428 VISIBILITY_NOTIFY_EVENT,
442 ACCEL_CLOSURES_CHANGED,
466 PROP_RECEIVES_DEFAULT,
467 PROP_COMPOSITE_CHILD,
470 PROP_EXTENSION_EVENTS,
476 PROP_DOUBLE_BUFFERED,
491 typedef struct _GtkStateData GtkStateData;
494 STATE_CHANGE_REPLACE,
503 guint parent_sensitive : 1;
504 guint use_forall : 1;
507 /* --- prototypes --- */
508 static void gtk_widget_class_init (GtkWidgetClass *klass);
509 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
510 static void gtk_widget_init (GtkWidget *widget);
511 static void gtk_widget_set_property (GObject *object,
515 static void gtk_widget_get_property (GObject *object,
519 static void gtk_widget_dispose (GObject *object);
520 static void gtk_widget_real_destroy (GtkWidget *object);
521 static void gtk_widget_finalize (GObject *object);
522 static void gtk_widget_real_show (GtkWidget *widget);
523 static void gtk_widget_real_hide (GtkWidget *widget);
524 static void gtk_widget_real_map (GtkWidget *widget);
525 static void gtk_widget_real_unmap (GtkWidget *widget);
526 static void gtk_widget_real_realize (GtkWidget *widget);
527 static void gtk_widget_real_unrealize (GtkWidget *widget);
528 static void gtk_widget_real_size_allocate (GtkWidget *widget,
529 GtkAllocation *allocation);
530 static void gtk_widget_real_style_set (GtkWidget *widget,
531 GtkStyle *previous_style);
532 static void gtk_widget_real_direction_changed(GtkWidget *widget,
533 GtkTextDirection previous_direction);
535 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
536 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
539 gboolean keyboard_tip,
540 GtkTooltip *tooltip);
541 static void gtk_widget_real_style_updated (GtkWidget *widget);
542 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
543 GtkWidgetHelpType help_type);
545 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
547 GParamSpec **pspecs);
548 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
550 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
552 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
553 GdkEventFocus *event);
554 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
555 GdkEventFocus *event);
556 static gboolean gtk_widget_real_focus (GtkWidget *widget,
557 GtkDirectionType direction);
558 static void gtk_widget_real_move_focus (GtkWidget *widget,
559 GtkDirectionType direction);
560 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
561 GtkDirectionType direction);
562 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
563 static void gtk_widget_update_pango_context (GtkWidget *widget);
564 static void gtk_widget_propagate_state (GtkWidget *widget,
566 static void gtk_widget_reset_rc_style (GtkWidget *widget);
567 static void gtk_widget_set_style_internal (GtkWidget *widget,
569 gboolean initial_emission);
570 static gint gtk_widget_event_internal (GtkWidget *widget,
572 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
573 gboolean group_cycling);
574 static void gtk_widget_real_get_width (GtkWidget *widget,
577 static void gtk_widget_real_get_height (GtkWidget *widget,
580 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
582 gint *minimum_height,
583 gint *natural_height);
584 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
587 gint *natural_width);
588 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
589 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
590 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
591 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
592 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
593 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
594 cairo_region_t *region);
595 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
596 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
597 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
600 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
601 gboolean has_tooltip,
603 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
604 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
606 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
607 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
609 const gchar *childname);
610 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
613 const GValue *value);
614 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
617 const gchar *tagname,
618 GMarkupParser *parser,
620 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
623 const gchar *tagname,
625 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
626 GtkBuilder *builder);
628 static void gtk_widget_real_get_width (GtkWidget *widget,
631 static void gtk_widget_real_get_height (GtkWidget *widget,
635 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
638 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
639 GtkOrientation orientation,
642 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
643 GtkOrientation orientation,
647 gint *allocated_size);
649 static void gtk_widget_set_usize_internal (GtkWidget *widget,
652 GtkQueueResizeFlags flags);
654 static void gtk_widget_add_events_internal (GtkWidget *widget,
658 /* --- variables --- */
659 static gpointer gtk_widget_parent_class = NULL;
660 static guint widget_signals[LAST_SIGNAL] = { 0 };
661 static GtkStyle *gtk_default_style = NULL;
662 static guint composite_child_stack = 0;
663 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
664 static GParamSpecPool *style_property_spec_pool = NULL;
666 static GQuark quark_property_parser = 0;
667 static GQuark quark_aux_info = 0;
668 static GQuark quark_accel_path = 0;
669 static GQuark quark_accel_closures = 0;
670 static GQuark quark_event_mask = 0;
671 static GQuark quark_device_event_mask = 0;
672 static GQuark quark_extension_event_mode = 0;
673 static GQuark quark_parent_window = 0;
674 static GQuark quark_pointer_window = 0;
675 static GQuark quark_shape_info = 0;
676 static GQuark quark_input_shape_info = 0;
677 static GQuark quark_pango_context = 0;
678 static GQuark quark_rc_style = 0;
679 static GQuark quark_accessible_object = 0;
680 static GQuark quark_mnemonic_labels = 0;
681 static GQuark quark_tooltip_markup = 0;
682 static GQuark quark_has_tooltip = 0;
683 static GQuark quark_tooltip_window = 0;
684 static GQuark quark_visual = 0;
685 static GQuark quark_modifier_style = 0;
686 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
687 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
689 /* --- functions --- */
691 gtk_widget_get_type (void)
693 static GType widget_type = 0;
695 if (G_UNLIKELY (widget_type == 0))
697 const GTypeInfo widget_info =
699 sizeof (GtkWidgetClass),
700 NULL, /* base_init */
701 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
702 (GClassInitFunc) gtk_widget_class_init,
703 NULL, /* class_finalize */
704 NULL, /* class_init */
707 (GInstanceInitFunc) gtk_widget_init,
708 NULL, /* value_table */
711 const GInterfaceInfo accessibility_info =
713 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
714 (GInterfaceFinalizeFunc) NULL,
715 NULL /* interface data */
718 const GInterfaceInfo buildable_info =
720 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
721 (GInterfaceFinalizeFunc) NULL,
722 NULL /* interface data */
725 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
726 &widget_info, G_TYPE_FLAG_ABSTRACT);
728 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
729 &accessibility_info) ;
730 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
738 child_property_notify_dispatcher (GObject *object,
742 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
745 /* We guard against the draw signal callbacks modifying the state of the
746 * cairo context by surounding it with save/restore.
747 * Maybe we should also cairo_new_path() just to be sure?
750 gtk_widget_draw_marshaller (GClosure *closure,
751 GValue *return_value,
752 guint n_param_values,
753 const GValue *param_values,
754 gpointer invocation_hint,
755 gpointer marshal_data)
757 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
761 _gtk_marshal_BOOLEAN__BOXED (closure,
772 gtk_widget_class_init (GtkWidgetClass *klass)
774 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
775 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
776 GtkBindingSet *binding_set;
778 gtk_widget_parent_class = g_type_class_peek_parent (klass);
780 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
781 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
782 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
783 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
784 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
785 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
786 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
787 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
788 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
789 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
790 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
791 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
792 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
793 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
794 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
795 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
796 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
797 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
798 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
799 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
801 style_property_spec_pool = g_param_spec_pool_new (FALSE);
802 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
803 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
804 cpn_context.dispatcher = child_property_notify_dispatcher;
805 _gtk_widget_child_property_notify_context = &cpn_context;
807 gobject_class->dispose = gtk_widget_dispose;
808 gobject_class->finalize = gtk_widget_finalize;
809 gobject_class->set_property = gtk_widget_set_property;
810 gobject_class->get_property = gtk_widget_get_property;
812 klass->destroy = gtk_widget_real_destroy;
814 klass->activate_signal = 0;
815 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
816 klass->show = gtk_widget_real_show;
817 klass->show_all = gtk_widget_show;
818 klass->hide = gtk_widget_real_hide;
819 klass->map = gtk_widget_real_map;
820 klass->unmap = gtk_widget_real_unmap;
821 klass->realize = gtk_widget_real_realize;
822 klass->unrealize = gtk_widget_real_unrealize;
823 klass->size_allocate = gtk_widget_real_size_allocate;
824 klass->get_preferred_width = gtk_widget_real_get_width;
825 klass->get_preferred_height = gtk_widget_real_get_height;
826 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
827 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
828 klass->state_changed = NULL;
829 klass->parent_set = NULL;
830 klass->hierarchy_changed = NULL;
831 klass->style_set = gtk_widget_real_style_set;
832 klass->direction_changed = gtk_widget_real_direction_changed;
833 klass->grab_notify = NULL;
834 klass->child_notify = NULL;
836 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
837 klass->grab_focus = gtk_widget_real_grab_focus;
838 klass->focus = gtk_widget_real_focus;
839 klass->move_focus = gtk_widget_real_move_focus;
840 klass->keynav_failed = gtk_widget_real_keynav_failed;
842 klass->button_press_event = NULL;
843 klass->button_release_event = NULL;
844 klass->motion_notify_event = NULL;
845 klass->delete_event = NULL;
846 klass->destroy_event = NULL;
847 klass->key_press_event = gtk_widget_real_key_press_event;
848 klass->key_release_event = gtk_widget_real_key_release_event;
849 klass->enter_notify_event = NULL;
850 klass->leave_notify_event = NULL;
851 klass->configure_event = NULL;
852 klass->focus_in_event = gtk_widget_real_focus_in_event;
853 klass->focus_out_event = gtk_widget_real_focus_out_event;
854 klass->map_event = NULL;
855 klass->unmap_event = NULL;
856 klass->window_state_event = NULL;
857 klass->property_notify_event = _gtk_selection_property_notify;
858 klass->selection_clear_event = _gtk_selection_clear;
859 klass->selection_request_event = _gtk_selection_request;
860 klass->selection_notify_event = _gtk_selection_notify;
861 klass->selection_received = NULL;
862 klass->proximity_in_event = NULL;
863 klass->proximity_out_event = NULL;
864 klass->drag_begin = NULL;
865 klass->drag_end = NULL;
866 klass->drag_data_delete = NULL;
867 klass->drag_leave = NULL;
868 klass->drag_motion = NULL;
869 klass->drag_drop = NULL;
870 klass->drag_data_received = NULL;
871 klass->screen_changed = NULL;
872 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
873 klass->grab_broken_event = NULL;
874 klass->query_tooltip = gtk_widget_real_query_tooltip;
875 klass->style_updated = gtk_widget_real_style_updated;
877 klass->show_help = gtk_widget_real_show_help;
879 /* Accessibility support */
880 klass->get_accessible = gtk_widget_real_get_accessible;
882 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
883 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
885 g_object_class_install_property (gobject_class,
887 g_param_spec_string ("name",
889 P_("The name of the widget"),
891 GTK_PARAM_READWRITE));
892 g_object_class_install_property (gobject_class,
894 g_param_spec_object ("parent",
896 P_("The parent widget of this widget. Must be a Container widget"),
898 GTK_PARAM_READWRITE));
900 g_object_class_install_property (gobject_class,
902 g_param_spec_int ("width-request",
904 P_("Override for width request of the widget, or -1 if natural request should be used"),
908 GTK_PARAM_READWRITE));
909 g_object_class_install_property (gobject_class,
911 g_param_spec_int ("height-request",
912 P_("Height request"),
913 P_("Override for height request of the widget, or -1 if natural request should be used"),
917 GTK_PARAM_READWRITE));
918 g_object_class_install_property (gobject_class,
920 g_param_spec_boolean ("visible",
922 P_("Whether the widget is visible"),
924 GTK_PARAM_READWRITE));
925 g_object_class_install_property (gobject_class,
927 g_param_spec_boolean ("sensitive",
929 P_("Whether the widget responds to input"),
931 GTK_PARAM_READWRITE));
932 g_object_class_install_property (gobject_class,
934 g_param_spec_boolean ("app-paintable",
935 P_("Application paintable"),
936 P_("Whether the application will paint directly on the widget"),
938 GTK_PARAM_READWRITE));
939 g_object_class_install_property (gobject_class,
941 g_param_spec_boolean ("can-focus",
943 P_("Whether the widget can accept the input focus"),
945 GTK_PARAM_READWRITE));
946 g_object_class_install_property (gobject_class,
948 g_param_spec_boolean ("has-focus",
950 P_("Whether the widget has the input focus"),
952 GTK_PARAM_READWRITE));
953 g_object_class_install_property (gobject_class,
955 g_param_spec_boolean ("is-focus",
957 P_("Whether the widget is the focus widget within the toplevel"),
959 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_boolean ("can-default",
964 P_("Whether the widget can be the default widget"),
966 GTK_PARAM_READWRITE));
967 g_object_class_install_property (gobject_class,
969 g_param_spec_boolean ("has-default",
971 P_("Whether the widget is the default widget"),
973 GTK_PARAM_READWRITE));
974 g_object_class_install_property (gobject_class,
975 PROP_RECEIVES_DEFAULT,
976 g_param_spec_boolean ("receives-default",
977 P_("Receives default"),
978 P_("If TRUE, the widget will receive the default action when it is focused"),
980 GTK_PARAM_READWRITE));
981 g_object_class_install_property (gobject_class,
982 PROP_COMPOSITE_CHILD,
983 g_param_spec_boolean ("composite-child",
984 P_("Composite child"),
985 P_("Whether the widget is part of a composite widget"),
987 GTK_PARAM_READABLE));
988 g_object_class_install_property (gobject_class,
990 g_param_spec_object ("style",
992 P_("The style of the widget, which contains information about how it will look (colors etc)"),
994 GTK_PARAM_READWRITE));
995 g_object_class_install_property (gobject_class,
997 g_param_spec_flags ("events",
999 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1000 GDK_TYPE_EVENT_MASK,
1002 GTK_PARAM_READWRITE));
1003 g_object_class_install_property (gobject_class,
1004 PROP_EXTENSION_EVENTS,
1005 g_param_spec_enum ("extension-events",
1006 P_("Extension events"),
1007 P_("The mask that decides what kind of extension events this widget gets"),
1008 GDK_TYPE_EXTENSION_MODE,
1009 GDK_EXTENSION_EVENTS_NONE,
1010 GTK_PARAM_READWRITE));
1011 g_object_class_install_property (gobject_class,
1013 g_param_spec_boolean ("no-show-all",
1015 P_("Whether gtk_widget_show_all() should not affect this widget"),
1017 GTK_PARAM_READWRITE));
1020 * GtkWidget:has-tooltip:
1022 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1023 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1024 * the widget will be queried using #GtkWidget::query-tooltip to determine
1025 * whether it will provide a tooltip or not.
1027 * Note that setting this property to %TRUE for the first time will change
1028 * the event masks of the GdkWindows of this widget to include leave-notify
1029 * and motion-notify events. This cannot and will not be undone when the
1030 * property is set to %FALSE again.
1034 g_object_class_install_property (gobject_class,
1036 g_param_spec_boolean ("has-tooltip",
1038 P_("Whether this widget has a tooltip"),
1040 GTK_PARAM_READWRITE));
1042 * GtkWidget:tooltip-text:
1044 * Sets the text of tooltip to be the given string.
1046 * Also see gtk_tooltip_set_text().
1048 * This is a convenience property which will take care of getting the
1049 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1050 * will automatically be set to %TRUE and there will be taken care of
1051 * #GtkWidget::query-tooltip in the default signal handler.
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_string ("tooltip-text",
1059 P_("The contents of the tooltip for this widget"),
1061 GTK_PARAM_READWRITE));
1063 * GtkWidget:tooltip-markup:
1065 * Sets the text of tooltip to be the given string, which is marked up
1066 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1067 * Also see gtk_tooltip_set_markup().
1069 * This is a convenience property which will take care of getting the
1070 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1071 * will automatically be set to %TRUE and there will be taken care of
1072 * #GtkWidget::query-tooltip in the default signal handler.
1076 g_object_class_install_property (gobject_class,
1077 PROP_TOOLTIP_MARKUP,
1078 g_param_spec_string ("tooltip-markup",
1079 P_("Tooltip markup"),
1080 P_("The contents of the tooltip for this widget"),
1082 GTK_PARAM_READWRITE));
1087 * The widget's window if it is realized, %NULL otherwise.
1091 g_object_class_install_property (gobject_class,
1093 g_param_spec_object ("window",
1095 P_("The widget's window if it is realized"),
1097 GTK_PARAM_READABLE));
1100 * GtkWidget:double-buffered
1102 * Whether the widget is double buffered.
1106 g_object_class_install_property (gobject_class,
1107 PROP_DOUBLE_BUFFERED,
1108 g_param_spec_boolean ("double-buffered",
1109 P_("Double Buffered"),
1110 P_("Whether the widget is double buffered"),
1112 GTK_PARAM_READWRITE));
1117 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1121 g_object_class_install_property (gobject_class,
1123 g_param_spec_enum ("halign",
1124 P_("Horizontal Alignment"),
1125 P_("How to position in extra horizontal space"),
1128 GTK_PARAM_READWRITE));
1133 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1137 g_object_class_install_property (gobject_class,
1139 g_param_spec_enum ("valign",
1140 P_("Vertical Alignment"),
1141 P_("How to position in extra vertical space"),
1144 GTK_PARAM_READWRITE));
1147 * GtkWidget:margin-left
1149 * Margin on left side of widget.
1151 * This property adds margin outside of the widget's normal size
1152 * request, the margin will be added in addition to the size from
1153 * gtk_widget_set_size_request() for example.
1157 g_object_class_install_property (gobject_class,
1159 g_param_spec_int ("margin-left",
1160 P_("Margin on Left"),
1161 P_("Pixels of extra space on the left side"),
1165 GTK_PARAM_READWRITE));
1168 * GtkWidget:margin-right
1170 * Margin on right side of widget.
1172 * This property adds margin outside of the widget's normal size
1173 * request, the margin will be added in addition to the size from
1174 * gtk_widget_set_size_request() for example.
1178 g_object_class_install_property (gobject_class,
1180 g_param_spec_int ("margin-right",
1181 P_("Margin on Right"),
1182 P_("Pixels of extra space on the right side"),
1186 GTK_PARAM_READWRITE));
1189 * GtkWidget:margin-top
1191 * Margin on top side of widget.
1193 * This property adds margin outside of the widget's normal size
1194 * request, the margin will be added in addition to the size from
1195 * gtk_widget_set_size_request() for example.
1199 g_object_class_install_property (gobject_class,
1201 g_param_spec_int ("margin-top",
1202 P_("Margin on Top"),
1203 P_("Pixels of extra space on the top side"),
1207 GTK_PARAM_READWRITE));
1210 * GtkWidget:margin-bottom
1212 * Margin on bottom side of widget.
1214 * This property adds margin outside of the widget's normal size
1215 * request, the margin will be added in addition to the size from
1216 * gtk_widget_set_size_request() for example.
1220 g_object_class_install_property (gobject_class,
1222 g_param_spec_int ("margin-bottom",
1223 P_("Margin on Bottom"),
1224 P_("Pixels of extra space on the bottom side"),
1228 GTK_PARAM_READWRITE));
1233 * Sets all four sides' margin at once. If read, returns max
1234 * margin on any side.
1238 g_object_class_install_property (gobject_class,
1240 g_param_spec_int ("margin",
1242 P_("Pixels of extra space on all four sides"),
1246 GTK_PARAM_READWRITE));
1249 * GtkWidget::destroy:
1250 * @object: the object which received the signal
1252 * Signals that all holders of a reference to the widget should release
1253 * the reference that they hold. May result in finalization of the widget
1254 * if all references are released.
1256 widget_signals[DESTROY] =
1257 g_signal_new (I_("destroy"),
1258 G_TYPE_FROM_CLASS (gobject_class),
1259 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1260 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1262 _gtk_marshal_VOID__VOID,
1268 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1272 g_object_class_install_property (gobject_class,
1274 g_param_spec_boolean ("hexpand",
1275 P_("Horizontal Expand"),
1276 P_("Whether widget wants more horizontal space"),
1278 GTK_PARAM_READWRITE));
1281 * GtkWidget:hexpand-set
1283 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1287 g_object_class_install_property (gobject_class,
1289 g_param_spec_boolean ("hexpand-set",
1290 P_("Horizontal Expand Set"),
1291 P_("Whether to use the hexpand property"),
1293 GTK_PARAM_READWRITE));
1298 * Whether to expand vertically. See gtk_widget_set_vexpand().
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_boolean ("vexpand",
1305 P_("Vertical Expand"),
1306 P_("Whether widget wants more vertical space"),
1308 GTK_PARAM_READWRITE));
1311 * GtkWidget:vexpand-set
1313 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1317 g_object_class_install_property (gobject_class,
1319 g_param_spec_boolean ("vexpand-set",
1320 P_("Vertical Expand Set"),
1321 P_("Whether to use the vexpand property"),
1323 GTK_PARAM_READWRITE));
1328 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1332 g_object_class_install_property (gobject_class,
1334 g_param_spec_boolean ("expand",
1336 P_("Whether widget wants to expand in both directions"),
1338 GTK_PARAM_READWRITE));
1342 * @widget: the object which received the signal.
1344 widget_signals[SHOW] =
1345 g_signal_new (I_("show"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, show),
1350 _gtk_marshal_VOID__VOID,
1355 * @widget: the object which received the signal.
1357 widget_signals[HIDE] =
1358 g_signal_new (I_("hide"),
1359 G_TYPE_FROM_CLASS (gobject_class),
1361 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1363 _gtk_marshal_VOID__VOID,
1368 * @widget: the object which received the signal.
1370 widget_signals[MAP] =
1371 g_signal_new (I_("map"),
1372 G_TYPE_FROM_CLASS (gobject_class),
1374 G_STRUCT_OFFSET (GtkWidgetClass, map),
1376 _gtk_marshal_VOID__VOID,
1381 * @widget: the object which received the signal.
1383 widget_signals[UNMAP] =
1384 g_signal_new (I_("unmap"),
1385 G_TYPE_FROM_CLASS (gobject_class),
1387 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1389 _gtk_marshal_VOID__VOID,
1393 * GtkWidget::realize:
1394 * @widget: the object which received the signal.
1396 widget_signals[REALIZE] =
1397 g_signal_new (I_("realize"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1402 _gtk_marshal_VOID__VOID,
1406 * GtkWidget::unrealize:
1407 * @widget: the object which received the signal.
1409 widget_signals[UNREALIZE] =
1410 g_signal_new (I_("unrealize"),
1411 G_TYPE_FROM_CLASS (gobject_class),
1413 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1415 _gtk_marshal_VOID__VOID,
1419 * GtkWidget::size-allocate:
1420 * @widget: the object which received the signal.
1423 widget_signals[SIZE_ALLOCATE] =
1424 g_signal_new (I_("size-allocate"),
1425 G_TYPE_FROM_CLASS (gobject_class),
1427 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1429 _gtk_marshal_VOID__BOXED,
1431 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1434 * GtkWidget::state-changed:
1435 * @widget: the object which received the signal.
1436 * @state: the previous state
1438 * The ::state-changed signal is emitted when the widget state changes.
1439 * See gtk_widget_get_state().
1441 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1443 widget_signals[STATE_CHANGED] =
1444 g_signal_new (I_("state-changed"),
1445 G_TYPE_FROM_CLASS (gobject_class),
1447 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1449 _gtk_marshal_VOID__ENUM,
1451 GTK_TYPE_STATE_TYPE);
1454 * GtkWidget::state-flags-changed:
1455 * @widget: the object which received the signal.
1456 * @flags: The previous state flags.
1458 * The ::state-flags-changed signal is emitted when the widget state
1459 * changes, see gtk_widget_get_state_flags().
1463 widget_signals[STATE_FLAGS_CHANGED] =
1464 g_signal_new (I_("state-flags-changed"),
1465 G_TYPE_FROM_CLASS (gobject_class),
1467 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1469 _gtk_marshal_VOID__FLAGS,
1471 GTK_TYPE_STATE_FLAGS);
1474 * GtkWidget::parent-set:
1475 * @widget: the object on which the signal is emitted
1476 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1477 * just got its initial parent.
1479 * The ::parent-set signal is emitted when a new parent
1480 * has been set on a widget.
1482 widget_signals[PARENT_SET] =
1483 g_signal_new (I_("parent-set"),
1484 G_TYPE_FROM_CLASS (gobject_class),
1486 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1488 _gtk_marshal_VOID__OBJECT,
1493 * GtkWidget::hierarchy-changed:
1494 * @widget: the object on which the signal is emitted
1495 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1496 * if the widget was previously unanchored
1498 * The ::hierarchy-changed signal is emitted when the
1499 * anchored state of a widget changes. A widget is
1500 * <firstterm>anchored</firstterm> when its toplevel
1501 * ancestor is a #GtkWindow. This signal is emitted when
1502 * a widget changes from un-anchored to anchored or vice-versa.
1504 widget_signals[HIERARCHY_CHANGED] =
1505 g_signal_new (I_("hierarchy-changed"),
1506 G_TYPE_FROM_CLASS (gobject_class),
1508 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1510 _gtk_marshal_VOID__OBJECT,
1515 * GtkWidget::style-set:
1516 * @widget: the object on which the signal is emitted
1517 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1518 * just got its initial style
1520 * The ::style-set signal is emitted when a new style has been set
1521 * on a widget. Note that style-modifying functions like
1522 * gtk_widget_modify_base() also cause this signal to be emitted.
1524 * Note that this signal is emitted for changes to the deprecated
1525 * #GtkStyle. To track changes to the #GtkStyleContext associated
1526 * with a widget, use the #GtkWidget::style-updated signal.
1528 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1530 widget_signals[STYLE_SET] =
1531 g_signal_new (I_("style-set"),
1532 G_TYPE_FROM_CLASS (gobject_class),
1534 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1536 _gtk_marshal_VOID__OBJECT,
1541 * GtkWidget::style-updated:
1542 * @widget: the object on which the signal is emitted
1544 * The ::style-updated signal is emitted when the #GtkStyleContext
1545 * of a widget is changed. Note that style-modifying functions like
1546 * gtk_widget_override_color() also cause this signal to be emitted.
1550 widget_signals[STYLE_UPDATED] =
1551 g_signal_new (I_("style-updated"),
1552 G_TYPE_FROM_CLASS (gobject_class),
1554 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1556 g_cclosure_marshal_VOID__VOID,
1560 * GtkWidget::direction-changed:
1561 * @widget: the object on which the signal is emitted
1562 * @previous_direction: the previous text direction of @widget
1564 * The ::direction-changed signal is emitted when the text direction
1565 * of a widget changes.
1567 widget_signals[DIRECTION_CHANGED] =
1568 g_signal_new (I_("direction-changed"),
1569 G_TYPE_FROM_CLASS (gobject_class),
1571 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1573 _gtk_marshal_VOID__ENUM,
1575 GTK_TYPE_TEXT_DIRECTION);
1578 * GtkWidget::grab-notify:
1579 * @widget: the object which received the signal
1580 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1581 * if it becomes unshadowed
1583 * The ::grab-notify signal is emitted when a widget becomes
1584 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1585 * another widget, or when it becomes unshadowed due to a grab
1588 * A widget is shadowed by a gtk_grab_add() when the topmost
1589 * grab widget in the grab stack of its window group is not
1592 widget_signals[GRAB_NOTIFY] =
1593 g_signal_new (I_("grab-notify"),
1594 G_TYPE_FROM_CLASS (gobject_class),
1596 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1598 _gtk_marshal_VOID__BOOLEAN,
1603 * GtkWidget::child-notify:
1604 * @widget: the object which received the signal
1605 * @pspec: the #GParamSpec of the changed child property
1607 * The ::child-notify signal is emitted for each
1608 * <link linkend="child-properties">child property</link> that has
1609 * changed on an object. The signal's detail holds the property name.
1611 widget_signals[CHILD_NOTIFY] =
1612 g_signal_new (I_("child-notify"),
1613 G_TYPE_FROM_CLASS (gobject_class),
1614 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1615 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1617 g_cclosure_marshal_VOID__PARAM,
1623 * @widget: the object which received the signal
1624 * @cr: the cairo context to draw to
1626 * This signal is emitted when a widget is supposed to render itself.
1627 * The @widget's top left corner must be painted at the origin of
1628 * the passed in context and be sized to the values returned by
1629 * gtk_widget_get_allocated_width() and
1630 * gtk_widget_get_allocated_height().
1632 * Signal handlers connected to this signal can modify the cairo
1633 * context passed as @cr in any way they like and don't need to
1634 * restore it. The signal emission takes care of calling cairo_save()
1635 * before and cairo_restore() after invoking the handler.
1637 widget_signals[DRAW] =
1638 g_signal_new (I_("draw"),
1639 G_TYPE_FROM_CLASS (gobject_class),
1641 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1642 _gtk_boolean_handled_accumulator, NULL,
1643 gtk_widget_draw_marshaller,
1645 CAIRO_GOBJECT_TYPE_CONTEXT);
1648 * GtkWidget::mnemonic-activate:
1649 * @widget: the object which received the signal.
1652 widget_signals[MNEMONIC_ACTIVATE] =
1653 g_signal_new (I_("mnemonic-activate"),
1654 G_TYPE_FROM_CLASS (gobject_class),
1656 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1657 _gtk_boolean_handled_accumulator, NULL,
1658 _gtk_marshal_BOOLEAN__BOOLEAN,
1663 * GtkWidget::grab-focus:
1664 * @widget: the object which received the signal.
1666 widget_signals[GRAB_FOCUS] =
1667 g_signal_new (I_("grab-focus"),
1668 G_TYPE_FROM_CLASS (gobject_class),
1669 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1670 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1672 _gtk_marshal_VOID__VOID,
1677 * @widget: the object which received the signal.
1680 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1682 widget_signals[FOCUS] =
1683 g_signal_new (I_("focus"),
1684 G_TYPE_FROM_CLASS (klass),
1686 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1687 _gtk_boolean_handled_accumulator, NULL,
1688 _gtk_marshal_BOOLEAN__ENUM,
1690 GTK_TYPE_DIRECTION_TYPE);
1693 * GtkWidget::move-focus:
1694 * @widget: the object which received the signal.
1697 widget_signals[MOVE_FOCUS] =
1698 g_signal_new (I_("move-focus"),
1699 G_TYPE_FROM_CLASS (klass),
1700 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1701 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1703 _gtk_marshal_VOID__ENUM,
1706 GTK_TYPE_DIRECTION_TYPE);
1709 * GtkWidget::keynav-failed:
1710 * @widget: the object which received the signal
1711 * @direction: the direction of movement
1713 * Gets emitted if keyboard navigation fails.
1714 * See gtk_widget_keynav_failed() for details.
1716 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1717 * if the emitting widget should try to handle the keyboard
1718 * navigation attempt in its parent container(s).
1722 widget_signals[KEYNAV_FAILED] =
1723 g_signal_new (I_("keynav-failed"),
1724 G_TYPE_FROM_CLASS (klass),
1726 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1727 _gtk_boolean_handled_accumulator, NULL,
1728 _gtk_marshal_BOOLEAN__ENUM,
1730 GTK_TYPE_DIRECTION_TYPE);
1734 * @widget: the object which received the signal.
1735 * @event: the #GdkEvent which triggered this signal
1737 * The GTK+ main loop will emit three signals for each GDK event delivered
1738 * to a widget: one generic ::event signal, another, more specific,
1739 * signal that matches the type of event delivered (e.g.
1740 * #GtkWidget::key-press-event) and finally a generic
1741 * #GtkWidget::event-after signal.
1743 * Returns: %TRUE to stop other handlers from being invoked for the event
1744 * and to cancel the emission of the second specific ::event signal.
1745 * %FALSE to propagate the event further and to allow the emission of
1746 * the second signal. The ::event-after signal is emitted regardless of
1749 widget_signals[EVENT] =
1750 g_signal_new (I_("event"),
1751 G_TYPE_FROM_CLASS (klass),
1753 G_STRUCT_OFFSET (GtkWidgetClass, event),
1754 _gtk_boolean_handled_accumulator, NULL,
1755 _gtk_marshal_BOOLEAN__BOXED,
1757 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1760 * GtkWidget::event-after:
1761 * @widget: the object which received the signal.
1762 * @event: the #GdkEvent which triggered this signal
1764 * After the emission of the #GtkWidget::event signal and (optionally)
1765 * the second more specific signal, ::event-after will be emitted
1766 * regardless of the previous two signals handlers return values.
1769 widget_signals[EVENT_AFTER] =
1770 g_signal_new (I_("event-after"),
1771 G_TYPE_FROM_CLASS (klass),
1775 _gtk_marshal_VOID__BOXED,
1777 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1780 * GtkWidget::button-press-event:
1781 * @widget: the object which received the signal.
1782 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1785 * The ::button-press-event signal will be emitted when a button
1786 * (typically from a mouse) is pressed.
1788 * To receive this signal, the #GdkWindow associated to the
1789 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1791 * This signal will be sent to the grab widget if there is one.
1793 * Returns: %TRUE to stop other handlers from being invoked for the event.
1794 * %FALSE to propagate the event further.
1796 widget_signals[BUTTON_PRESS_EVENT] =
1797 g_signal_new (I_("button-press-event"),
1798 G_TYPE_FROM_CLASS (klass),
1800 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1801 _gtk_boolean_handled_accumulator, NULL,
1802 _gtk_marshal_BOOLEAN__BOXED,
1804 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1807 * GtkWidget::button-release-event:
1808 * @widget: the object which received the signal.
1809 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1812 * The ::button-release-event signal will be emitted when a button
1813 * (typically from a mouse) is released.
1815 * To receive this signal, the #GdkWindow associated to the
1816 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1818 * This signal will be sent to the grab widget if there is one.
1820 * Returns: %TRUE to stop other handlers from being invoked for the event.
1821 * %FALSE to propagate the event further.
1823 widget_signals[BUTTON_RELEASE_EVENT] =
1824 g_signal_new (I_("button-release-event"),
1825 G_TYPE_FROM_CLASS (klass),
1827 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1828 _gtk_boolean_handled_accumulator, NULL,
1829 _gtk_marshal_BOOLEAN__BOXED,
1831 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1834 * GtkWidget::scroll-event:
1835 * @widget: the object which received the signal.
1836 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1839 * The ::scroll-event signal is emitted when a button in the 4 to 7
1840 * range is pressed. Wheel mice are usually configured to generate
1841 * button press events for buttons 4 and 5 when the wheel is turned.
1843 * To receive this signal, the #GdkWindow associated to the widget needs
1844 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1846 * This signal will be sent to the grab widget if there is one.
1848 * Returns: %TRUE to stop other handlers from being invoked for the event.
1849 * %FALSE to propagate the event further.
1851 widget_signals[SCROLL_EVENT] =
1852 g_signal_new (I_("scroll-event"),
1853 G_TYPE_FROM_CLASS (klass),
1855 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1856 _gtk_boolean_handled_accumulator, NULL,
1857 _gtk_marshal_BOOLEAN__BOXED,
1859 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1862 * GtkWidget::motion-notify-event:
1863 * @widget: the object which received the signal.
1864 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1867 * The ::motion-notify-event signal is emitted when the pointer moves
1868 * over the widget's #GdkWindow.
1870 * To receive this signal, the #GdkWindow associated to the widget
1871 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1873 * This signal will be sent to the grab widget if there is one.
1875 * Returns: %TRUE to stop other handlers from being invoked for the event.
1876 * %FALSE to propagate the event further.
1878 widget_signals[MOTION_NOTIFY_EVENT] =
1879 g_signal_new (I_("motion-notify-event"),
1880 G_TYPE_FROM_CLASS (klass),
1882 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1883 _gtk_boolean_handled_accumulator, NULL,
1884 _gtk_marshal_BOOLEAN__BOXED,
1886 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1889 * GtkWidget::composited-changed:
1890 * @widget: the object on which the signal is emitted
1892 * The ::composited-changed signal is emitted when the composited
1893 * status of @widget<!-- -->s screen changes.
1894 * See gdk_screen_is_composited().
1896 widget_signals[COMPOSITED_CHANGED] =
1897 g_signal_new (I_("composited-changed"),
1898 G_TYPE_FROM_CLASS (klass),
1899 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1900 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1902 _gtk_marshal_VOID__VOID,
1906 * GtkWidget::delete-event:
1907 * @widget: the object which received the signal
1908 * @event: the event which triggered this signal
1910 * The ::delete-event signal is emitted if a user requests that
1911 * a toplevel window is closed. The default handler for this signal
1912 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1913 * this signal will cause the window to be hidden instead, so that
1914 * it can later be shown again without reconstructing it.
1916 * Returns: %TRUE to stop other handlers from being invoked for the event.
1917 * %FALSE to propagate the event further.
1919 widget_signals[DELETE_EVENT] =
1920 g_signal_new (I_("delete-event"),
1921 G_TYPE_FROM_CLASS (klass),
1923 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1924 _gtk_boolean_handled_accumulator, NULL,
1925 _gtk_marshal_BOOLEAN__BOXED,
1927 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1930 * GtkWidget::destroy-event:
1931 * @widget: the object which received the signal.
1932 * @event: the event which triggered this signal
1934 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1935 * You rarely get this signal, because most widgets disconnect themselves
1936 * from their window before they destroy it, so no widget owns the
1937 * window at destroy time.
1939 * To receive this signal, the #GdkWindow associated to the widget needs
1940 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1941 * automatically for all new windows.
1943 * Returns: %TRUE to stop other handlers from being invoked for the event.
1944 * %FALSE to propagate the event further.
1946 widget_signals[DESTROY_EVENT] =
1947 g_signal_new (I_("destroy-event"),
1948 G_TYPE_FROM_CLASS (klass),
1950 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1951 _gtk_boolean_handled_accumulator, NULL,
1952 _gtk_marshal_BOOLEAN__BOXED,
1954 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1957 * GtkWidget::key-press-event:
1958 * @widget: the object which received the signal
1959 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1961 * The ::key-press-event signal is emitted when a key is pressed.
1963 * To receive this signal, the #GdkWindow associated to the widget needs
1964 * to enable the #GDK_KEY_PRESS_MASK mask.
1966 * This signal will be sent to the grab widget if there is one.
1968 * Returns: %TRUE to stop other handlers from being invoked for the event.
1969 * %FALSE to propagate the event further.
1971 widget_signals[KEY_PRESS_EVENT] =
1972 g_signal_new (I_("key-press-event"),
1973 G_TYPE_FROM_CLASS (klass),
1975 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1976 _gtk_boolean_handled_accumulator, NULL,
1977 _gtk_marshal_BOOLEAN__BOXED,
1979 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1982 * GtkWidget::key-release-event:
1983 * @widget: the object which received the signal
1984 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1986 * The ::key-release-event signal is emitted when a key is pressed.
1988 * To receive this signal, the #GdkWindow associated to the widget needs
1989 * to enable the #GDK_KEY_RELEASE_MASK mask.
1991 * This signal will be sent to the grab widget if there is one.
1993 * Returns: %TRUE to stop other handlers from being invoked for the event.
1994 * %FALSE to propagate the event further.
1996 widget_signals[KEY_RELEASE_EVENT] =
1997 g_signal_new (I_("key-release-event"),
1998 G_TYPE_FROM_CLASS (klass),
2000 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2001 _gtk_boolean_handled_accumulator, NULL,
2002 _gtk_marshal_BOOLEAN__BOXED,
2004 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2007 * GtkWidget::enter-notify-event:
2008 * @widget: the object which received the signal
2009 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2012 * The ::enter-notify-event will be emitted when the pointer enters
2013 * the @widget's window.
2015 * To receive this signal, the #GdkWindow associated to the widget needs
2016 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2018 * This signal will be sent to the grab widget if there is one.
2020 * Returns: %TRUE to stop other handlers from being invoked for the event.
2021 * %FALSE to propagate the event further.
2023 widget_signals[ENTER_NOTIFY_EVENT] =
2024 g_signal_new (I_("enter-notify-event"),
2025 G_TYPE_FROM_CLASS (klass),
2027 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2028 _gtk_boolean_handled_accumulator, NULL,
2029 _gtk_marshal_BOOLEAN__BOXED,
2031 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2034 * GtkWidget::leave-notify-event:
2035 * @widget: the object which received the signal
2036 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2039 * The ::leave-notify-event will be emitted when the pointer leaves
2040 * the @widget's window.
2042 * To receive this signal, the #GdkWindow associated to the widget needs
2043 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2045 * This signal will be sent to the grab widget if there is one.
2047 * Returns: %TRUE to stop other handlers from being invoked for the event.
2048 * %FALSE to propagate the event further.
2050 widget_signals[LEAVE_NOTIFY_EVENT] =
2051 g_signal_new (I_("leave-notify-event"),
2052 G_TYPE_FROM_CLASS (klass),
2054 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2055 _gtk_boolean_handled_accumulator, NULL,
2056 _gtk_marshal_BOOLEAN__BOXED,
2058 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2061 * GtkWidget::configure-event:
2062 * @widget: the object which received the signal
2063 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2066 * The ::configure-event signal will be emitted when the size, position or
2067 * stacking of the @widget's window has changed.
2069 * To receive this signal, the #GdkWindow associated to the widget needs
2070 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2071 * automatically for all new windows.
2073 * Returns: %TRUE to stop other handlers from being invoked for the event.
2074 * %FALSE to propagate the event further.
2076 widget_signals[CONFIGURE_EVENT] =
2077 g_signal_new (I_("configure-event"),
2078 G_TYPE_FROM_CLASS (klass),
2080 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2081 _gtk_boolean_handled_accumulator, NULL,
2082 _gtk_marshal_BOOLEAN__BOXED,
2084 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2087 * GtkWidget::focus-in-event:
2088 * @widget: the object which received the signal
2089 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2092 * The ::focus-in-event signal will be emitted when the keyboard focus
2093 * enters the @widget's window.
2095 * To receive this signal, the #GdkWindow associated to the widget needs
2096 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2098 * Returns: %TRUE to stop other handlers from being invoked for the event.
2099 * %FALSE to propagate the event further.
2101 widget_signals[FOCUS_IN_EVENT] =
2102 g_signal_new (I_("focus-in-event"),
2103 G_TYPE_FROM_CLASS (klass),
2105 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2106 _gtk_boolean_handled_accumulator, NULL,
2107 _gtk_marshal_BOOLEAN__BOXED,
2109 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2112 * GtkWidget::focus-out-event:
2113 * @widget: the object which received the signal
2114 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2117 * The ::focus-out-event signal will be emitted when the keyboard focus
2118 * leaves the @widget's window.
2120 * To receive this signal, the #GdkWindow associated to the widget needs
2121 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2123 * Returns: %TRUE to stop other handlers from being invoked for the event.
2124 * %FALSE to propagate the event further.
2126 widget_signals[FOCUS_OUT_EVENT] =
2127 g_signal_new (I_("focus-out-event"),
2128 G_TYPE_FROM_CLASS (klass),
2130 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2131 _gtk_boolean_handled_accumulator, NULL,
2132 _gtk_marshal_BOOLEAN__BOXED,
2134 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2137 * GtkWidget::map-event:
2138 * @widget: the object which received the signal
2139 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2141 * The ::map-event signal will be emitted when the @widget's window is
2142 * mapped. A window is mapped when it becomes visible on the screen.
2144 * To receive this signal, the #GdkWindow associated to the widget needs
2145 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2146 * automatically for all new windows.
2148 * Returns: %TRUE to stop other handlers from being invoked for the event.
2149 * %FALSE to propagate the event further.
2151 widget_signals[MAP_EVENT] =
2152 g_signal_new (I_("map-event"),
2153 G_TYPE_FROM_CLASS (klass),
2155 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2156 _gtk_boolean_handled_accumulator, NULL,
2157 _gtk_marshal_BOOLEAN__BOXED,
2159 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2162 * GtkWidget::unmap-event:
2163 * @widget: the object which received the signal
2164 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2166 * The ::unmap-event signal may be emitted when the @widget's window is
2167 * unmapped. A window is unmapped when it becomes invisible on the screen.
2169 * For performance reasons GTK+ may not emit ::unmap-event, so one
2170 * should always also implement ::unrealize in order to release
2171 * resources and disconnect signal handlers.
2173 * To receive this signal, the #GdkWindow associated to the widget needs
2174 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2175 * automatically for all new windows.
2177 * Returns: %TRUE to stop other handlers from being invoked for the event.
2178 * %FALSE to propagate the event further.
2180 widget_signals[UNMAP_EVENT] =
2181 g_signal_new (I_("unmap-event"),
2182 G_TYPE_FROM_CLASS (klass),
2184 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2185 _gtk_boolean_handled_accumulator, NULL,
2186 _gtk_marshal_BOOLEAN__BOXED,
2188 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2191 * GtkWidget::property-notify-event:
2192 * @widget: the object which received the signal
2193 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2196 * The ::property-notify-event signal will be emitted when a property on
2197 * the @widget's window has been changed or deleted.
2199 * To receive this signal, the #GdkWindow associated to the widget needs
2200 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2202 * Returns: %TRUE to stop other handlers from being invoked for the event.
2203 * %FALSE to propagate the event further.
2205 widget_signals[PROPERTY_NOTIFY_EVENT] =
2206 g_signal_new (I_("property-notify-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2216 * GtkWidget::selection-clear-event:
2217 * @widget: the object which received the signal
2218 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2221 * The ::selection-clear-event signal will be emitted when the
2222 * the @widget's window has lost ownership of a selection.
2224 * Returns: %TRUE to stop other handlers from being invoked for the event.
2225 * %FALSE to propagate the event further.
2227 widget_signals[SELECTION_CLEAR_EVENT] =
2228 g_signal_new (I_("selection-clear-event"),
2229 G_TYPE_FROM_CLASS (klass),
2231 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2232 _gtk_boolean_handled_accumulator, NULL,
2233 _gtk_marshal_BOOLEAN__BOXED,
2235 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2238 * GtkWidget::selection-request-event:
2239 * @widget: the object which received the signal
2240 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2243 * The ::selection-request-event signal will be emitted when
2244 * another client requests ownership of the selection owned by
2245 * the @widget's window.
2247 * Returns: %TRUE to stop other handlers from being invoked for the event.
2248 * %FALSE to propagate the event further.
2250 widget_signals[SELECTION_REQUEST_EVENT] =
2251 g_signal_new (I_("selection-request-event"),
2252 G_TYPE_FROM_CLASS (klass),
2254 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2255 _gtk_boolean_handled_accumulator, NULL,
2256 _gtk_marshal_BOOLEAN__BOXED,
2258 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2261 * GtkWidget::selection-notify-event:
2262 * @widget: the object which received the signal.
2265 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2267 widget_signals[SELECTION_NOTIFY_EVENT] =
2268 g_signal_new (I_("selection-notify-event"),
2269 G_TYPE_FROM_CLASS (klass),
2271 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2272 _gtk_boolean_handled_accumulator, NULL,
2273 _gtk_marshal_BOOLEAN__BOXED,
2275 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2278 * GtkWidget::selection-received:
2279 * @widget: the object which received the signal.
2283 widget_signals[SELECTION_RECEIVED] =
2284 g_signal_new (I_("selection-received"),
2285 G_TYPE_FROM_CLASS (klass),
2287 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2289 _gtk_marshal_VOID__BOXED_UINT,
2291 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2295 * GtkWidget::selection-get:
2296 * @widget: the object which received the signal.
2301 widget_signals[SELECTION_GET] =
2302 g_signal_new (I_("selection-get"),
2303 G_TYPE_FROM_CLASS (klass),
2305 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2307 _gtk_marshal_VOID__BOXED_UINT_UINT,
2309 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2314 * GtkWidget::proximity-in-event:
2315 * @widget: the object which received the signal
2316 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2319 * To receive this signal the #GdkWindow associated to the widget needs
2320 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2322 * This signal will be sent to the grab widget if there is one.
2324 * Returns: %TRUE to stop other handlers from being invoked for the event.
2325 * %FALSE to propagate the event further.
2327 widget_signals[PROXIMITY_IN_EVENT] =
2328 g_signal_new (I_("proximity-in-event"),
2329 G_TYPE_FROM_CLASS (klass),
2331 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2332 _gtk_boolean_handled_accumulator, NULL,
2333 _gtk_marshal_BOOLEAN__BOXED,
2335 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2338 * GtkWidget::proximity-out-event:
2339 * @widget: the object which received the signal
2340 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2343 * To receive this signal the #GdkWindow associated to the widget needs
2344 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2346 * This signal will be sent to the grab widget if there is one.
2348 * Returns: %TRUE to stop other handlers from being invoked for the event.
2349 * %FALSE to propagate the event further.
2351 widget_signals[PROXIMITY_OUT_EVENT] =
2352 g_signal_new (I_("proximity-out-event"),
2353 G_TYPE_FROM_CLASS (klass),
2355 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2356 _gtk_boolean_handled_accumulator, NULL,
2357 _gtk_marshal_BOOLEAN__BOXED,
2359 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2362 * GtkWidget::drag-leave:
2363 * @widget: the object which received the signal.
2364 * @drag_context: the drag context
2365 * @time: the timestamp of the motion event
2367 * The ::drag-leave signal is emitted on the drop site when the cursor
2368 * leaves the widget. A typical reason to connect to this signal is to
2369 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2370 * with gtk_drag_unhighlight()
2372 widget_signals[DRAG_LEAVE] =
2373 g_signal_new (I_("drag-leave"),
2374 G_TYPE_FROM_CLASS (klass),
2376 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2378 _gtk_marshal_VOID__OBJECT_UINT,
2380 GDK_TYPE_DRAG_CONTEXT,
2384 * GtkWidget::drag-begin:
2385 * @widget: the object which received the signal
2386 * @drag_context: the drag context
2388 * The ::drag-begin signal is emitted on the drag source when a drag is
2389 * started. A typical reason to connect to this signal is to set up a
2390 * custom drag icon with gtk_drag_source_set_icon().
2392 * Note that some widgets set up a drag icon in the default handler of
2393 * this signal, so you may have to use g_signal_connect_after() to
2394 * override what the default handler did.
2396 widget_signals[DRAG_BEGIN] =
2397 g_signal_new (I_("drag-begin"),
2398 G_TYPE_FROM_CLASS (klass),
2400 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2402 _gtk_marshal_VOID__OBJECT,
2404 GDK_TYPE_DRAG_CONTEXT);
2407 * GtkWidget::drag-end:
2408 * @widget: the object which received the signal
2409 * @drag_context: the drag context
2411 * The ::drag-end signal is emitted on the drag source when a drag is
2412 * finished. A typical reason to connect to this signal is to undo
2413 * things done in #GtkWidget::drag-begin.
2415 widget_signals[DRAG_END] =
2416 g_signal_new (I_("drag-end"),
2417 G_TYPE_FROM_CLASS (klass),
2419 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2421 _gtk_marshal_VOID__OBJECT,
2423 GDK_TYPE_DRAG_CONTEXT);
2426 * GtkWidget::drag-data-delete:
2427 * @widget: the object which received the signal
2428 * @drag_context: the drag context
2430 * The ::drag-data-delete signal is emitted on the drag source when a drag
2431 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2432 * handler is responsible for deleting the data that has been dropped. What
2433 * "delete" means depends on the context of the drag operation.
2435 widget_signals[DRAG_DATA_DELETE] =
2436 g_signal_new (I_("drag-data-delete"),
2437 G_TYPE_FROM_CLASS (klass),
2439 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2441 _gtk_marshal_VOID__OBJECT,
2443 GDK_TYPE_DRAG_CONTEXT);
2446 * GtkWidget::drag-failed:
2447 * @widget: the object which received the signal
2448 * @drag_context: the drag context
2449 * @result: the result of the drag operation
2451 * The ::drag-failed signal is emitted on the drag source when a drag has
2452 * failed. The signal handler may hook custom code to handle a failed DND
2453 * operation based on the type of error, it returns %TRUE is the failure has
2454 * been already handled (not showing the default "drag operation failed"
2455 * animation), otherwise it returns %FALSE.
2457 * Return value: %TRUE if the failed drag operation has been already handled.
2461 widget_signals[DRAG_FAILED] =
2462 g_signal_new (I_("drag-failed"),
2463 G_TYPE_FROM_CLASS (klass),
2465 0, _gtk_boolean_handled_accumulator, NULL,
2466 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2468 GDK_TYPE_DRAG_CONTEXT,
2469 GTK_TYPE_DRAG_RESULT);
2472 * GtkWidget::drag-motion:
2473 * @widget: the object which received the signal
2474 * @drag_context: the drag context
2475 * @x: the x coordinate of the current cursor position
2476 * @y: the y coordinate of the current cursor position
2477 * @time: the timestamp of the motion event
2478 * @returns: whether the cursor position is in a drop zone
2480 * The drag-motion signal is emitted on the drop site when the user
2481 * moves the cursor over the widget during a drag. The signal handler
2482 * must determine whether the cursor position is in a drop zone or not.
2483 * If it is not in a drop zone, it returns %FALSE and no further processing
2484 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2485 * handler is responsible for providing the necessary information for
2486 * displaying feedback to the user, by calling gdk_drag_status().
2488 * If the decision whether the drop will be accepted or rejected can't be
2489 * made based solely on the cursor position and the type of the data, the
2490 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2491 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2492 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2493 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2494 * when using the drag-motion signal that way.
2496 * Also note that there is no drag-enter signal. The drag receiver has to
2497 * keep track of whether he has received any drag-motion signals since the
2498 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2499 * an "enter" signal. Upon an "enter", the handler will typically highlight
2500 * the drop site with gtk_drag_highlight().
2503 * drag_motion (GtkWidget *widget,
2504 * GdkDragContext *context,
2511 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2513 * if (!private_data->drag_highlight)
2515 * private_data->drag_highlight = 1;
2516 * gtk_drag_highlight (widget);
2519 * target = gtk_drag_dest_find_target (widget, context, NULL);
2520 * if (target == GDK_NONE)
2521 * gdk_drag_status (context, 0, time);
2524 * private_data->pending_status = context->suggested_action;
2525 * gtk_drag_get_data (widget, context, target, time);
2532 * drag_data_received (GtkWidget *widget,
2533 * GdkDragContext *context,
2536 * GtkSelectionData *selection_data,
2540 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2542 * if (private_data->suggested_action)
2544 * private_data->suggested_action = 0;
2546 * /* We are getting this data due to a request in drag_motion,
2547 * * rather than due to a request in drag_drop, so we are just
2548 * * supposed to call gdk_drag_status (), not actually paste in
2551 * str = gtk_selection_data_get_text (selection_data);
2552 * if (!data_is_acceptable (str))
2553 * gdk_drag_status (context, 0, time);
2555 * gdk_drag_status (context, private_data->suggested_action, time);
2559 * /* accept the drop */
2564 widget_signals[DRAG_MOTION] =
2565 g_signal_new (I_("drag-motion"),
2566 G_TYPE_FROM_CLASS (klass),
2568 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2569 _gtk_boolean_handled_accumulator, NULL,
2570 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2572 GDK_TYPE_DRAG_CONTEXT,
2578 * GtkWidget::drag-drop:
2579 * @widget: the object which received the signal
2580 * @drag_context: the drag context
2581 * @x: the x coordinate of the current cursor position
2582 * @y: the y coordinate of the current cursor position
2583 * @time: the timestamp of the motion event
2584 * @returns: whether the cursor position is in a drop zone
2586 * The ::drag-drop signal is emitted on the drop site when the user drops
2587 * the data onto the widget. The signal handler must determine whether
2588 * the cursor position is in a drop zone or not. If it is not in a drop
2589 * zone, it returns %FALSE and no further processing is necessary.
2590 * Otherwise, the handler returns %TRUE. In this case, the handler must
2591 * ensure that gtk_drag_finish() is called to let the source know that
2592 * the drop is done. The call to gtk_drag_finish() can be done either
2593 * directly or in a #GtkWidget::drag-data-received handler which gets
2594 * triggered by calling gtk_drag_get_data() to receive the data for one
2595 * or more of the supported targets.
2597 widget_signals[DRAG_DROP] =
2598 g_signal_new (I_("drag-drop"),
2599 G_TYPE_FROM_CLASS (klass),
2601 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2602 _gtk_boolean_handled_accumulator, NULL,
2603 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2605 GDK_TYPE_DRAG_CONTEXT,
2611 * GtkWidget::drag-data-get:
2612 * @widget: the object which received the signal
2613 * @drag_context: the drag context
2614 * @data: the #GtkSelectionData to be filled with the dragged data
2615 * @info: the info that has been registered with the target in the
2617 * @time: the timestamp at which the data was requested
2619 * The ::drag-data-get signal is emitted on the drag source when the drop
2620 * site requests the data which is dragged. It is the responsibility of
2621 * the signal handler to fill @data with the data in the format which
2622 * is indicated by @info. See gtk_selection_data_set() and
2623 * gtk_selection_data_set_text().
2625 widget_signals[DRAG_DATA_GET] =
2626 g_signal_new (I_("drag-data-get"),
2627 G_TYPE_FROM_CLASS (klass),
2629 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2631 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2633 GDK_TYPE_DRAG_CONTEXT,
2634 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2639 * GtkWidget::drag-data-received:
2640 * @widget: the object which received the signal
2641 * @drag_context: the drag context
2642 * @x: where the drop happened
2643 * @y: where the drop happened
2644 * @data: the received data
2645 * @info: the info that has been registered with the target in the
2647 * @time: the timestamp at which the data was received
2649 * The ::drag-data-received signal is emitted on the drop site when the
2650 * dragged data has been received. If the data was received in order to
2651 * determine whether the drop will be accepted, the handler is expected
2652 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2653 * If the data was received in response to a #GtkWidget::drag-drop signal
2654 * (and this is the last target to be received), the handler for this
2655 * signal is expected to process the received data and then call
2656 * gtk_drag_finish(), setting the @success parameter depending on whether
2657 * the data was processed successfully.
2659 * The handler may inspect and modify @drag_context->action before calling
2660 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2661 * following example:
2664 * drag_data_received (GtkWidget *widget,
2665 * GdkDragContext *drag_context,
2668 * GtkSelectionData *data,
2672 * if ((data->length >= 0) && (data->format == 8))
2674 * if (drag_context->action == GDK_ACTION_ASK)
2676 * GtkWidget *dialog;
2679 * dialog = gtk_message_dialog_new (NULL,
2680 * GTK_DIALOG_MODAL |
2681 * GTK_DIALOG_DESTROY_WITH_PARENT,
2683 * GTK_BUTTONS_YES_NO,
2684 * "Move the data ?\n");
2685 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2686 * gtk_widget_destroy (dialog);
2688 * if (response == GTK_RESPONSE_YES)
2689 * drag_context->action = GDK_ACTION_MOVE;
2691 * drag_context->action = GDK_ACTION_COPY;
2694 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2698 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2702 widget_signals[DRAG_DATA_RECEIVED] =
2703 g_signal_new (I_("drag-data-received"),
2704 G_TYPE_FROM_CLASS (klass),
2706 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2708 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2710 GDK_TYPE_DRAG_CONTEXT,
2713 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2718 * GtkWidget::visibility-notify-event:
2719 * @widget: the object which received the signal
2720 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2721 * triggered this signal.
2723 * The ::visibility-notify-event will be emitted when the @widget's window
2724 * is obscured or unobscured.
2726 * To receive this signal the #GdkWindow associated to the widget needs
2727 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2729 * Returns: %TRUE to stop other handlers from being invoked for the event.
2730 * %FALSE to propagate the event further.
2732 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2733 g_signal_new (I_("visibility-notify-event"),
2734 G_TYPE_FROM_CLASS (klass),
2736 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2737 _gtk_boolean_handled_accumulator, NULL,
2738 _gtk_marshal_BOOLEAN__BOXED,
2740 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2743 * GtkWidget::client-event:
2744 * @widget: the object which received the signal
2745 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2748 * The ::client-event will be emitted when the @widget's window
2749 * receives a message (via a ClientMessage event) from another
2752 * Returns: %TRUE to stop other handlers from being invoked for
2753 * the event. %FALSE to propagate the event further.
2755 widget_signals[CLIENT_EVENT] =
2756 g_signal_new (I_("client-event"),
2757 G_TYPE_FROM_CLASS (klass),
2759 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2760 _gtk_boolean_handled_accumulator, NULL,
2761 _gtk_marshal_BOOLEAN__BOXED,
2763 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2766 * GtkWidget::window-state-event:
2767 * @widget: the object which received the signal
2768 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2769 * triggered this signal.
2771 * The ::window-state-event will be emitted when the state of the
2772 * toplevel window associated to the @widget changes.
2774 * To receive this signal the #GdkWindow associated to the widget
2775 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2776 * this mask automatically for all new windows.
2778 * Returns: %TRUE to stop other handlers from being invoked for the
2779 * event. %FALSE to propagate the event further.
2781 widget_signals[WINDOW_STATE_EVENT] =
2782 g_signal_new (I_("window-state-event"),
2783 G_TYPE_FROM_CLASS (klass),
2785 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2786 _gtk_boolean_handled_accumulator, NULL,
2787 _gtk_marshal_BOOLEAN__BOXED,
2789 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2792 * GtkWidget::damage-event:
2793 * @widget: the object which received the signal
2794 * @event: the #GdkEventExpose event
2796 * Emitted when a redirected window belonging to @widget gets drawn into.
2797 * The region/area members of the event shows what area of the redirected
2798 * drawable was drawn into.
2800 * Returns: %TRUE to stop other handlers from being invoked for the event.
2801 * %FALSE to propagate the event further.
2805 widget_signals[DAMAGE_EVENT] =
2806 g_signal_new (I_("damage-event"),
2807 G_TYPE_FROM_CLASS (klass),
2809 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2810 _gtk_boolean_handled_accumulator, NULL,
2811 _gtk_marshal_BOOLEAN__BOXED,
2813 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2816 * GtkWidget::grab-broken-event:
2817 * @widget: the object which received the signal
2818 * @event: the #GdkEventGrabBroken event
2820 * Emitted when a pointer or keyboard grab on a window belonging
2821 * to @widget gets broken.
2823 * On X11, this happens when the grab window becomes unviewable
2824 * (i.e. it or one of its ancestors is unmapped), or if the same
2825 * application grabs the pointer or keyboard again.
2827 * Returns: %TRUE to stop other handlers from being invoked for
2828 * the event. %FALSE to propagate the event further.
2832 widget_signals[GRAB_BROKEN_EVENT] =
2833 g_signal_new (I_("grab-broken-event"),
2834 G_TYPE_FROM_CLASS (klass),
2836 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2837 _gtk_boolean_handled_accumulator, NULL,
2838 _gtk_marshal_BOOLEAN__BOXED,
2840 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2843 * GtkWidget::query-tooltip:
2844 * @widget: the object which received the signal
2845 * @x: the x coordinate of the cursor position where the request has
2846 * been emitted, relative to @widget->window
2847 * @y: the y coordinate of the cursor position where the request has
2848 * been emitted, relative to @widget->window
2849 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2850 * @tooltip: a #GtkTooltip
2852 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2853 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2854 * focus in keyboard mode.
2856 * Using the given coordinates, the signal handler should determine
2857 * whether a tooltip should be shown for @widget. If this is the case
2858 * %TRUE should be returned, %FALSE otherwise. Note that if
2859 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2860 * should not be used.
2862 * The signal handler is free to manipulate @tooltip with the therefore
2863 * destined function calls.
2865 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2869 widget_signals[QUERY_TOOLTIP] =
2870 g_signal_new (I_("query-tooltip"),
2871 G_TYPE_FROM_CLASS (klass),
2873 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2874 _gtk_boolean_handled_accumulator, NULL,
2875 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2883 * GtkWidget::popup-menu
2884 * @widget: the object which received the signal
2886 * This signal gets emitted whenever a widget should pop up a context
2887 * menu. This usually happens through the standard key binding mechanism;
2888 * by pressing a certain key while a widget is focused, the user can cause
2889 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2890 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2891 * for an example of how to use this signal.
2893 * Returns: %TRUE if a menu was activated
2895 widget_signals[POPUP_MENU] =
2896 g_signal_new (I_("popup-menu"),
2897 G_TYPE_FROM_CLASS (klass),
2898 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2899 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2900 _gtk_boolean_handled_accumulator, NULL,
2901 _gtk_marshal_BOOLEAN__VOID,
2905 * GtkWidget::show-help:
2906 * @widget: the object which received the signal.
2909 widget_signals[SHOW_HELP] =
2910 g_signal_new (I_("show-help"),
2911 G_TYPE_FROM_CLASS (klass),
2912 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2913 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2914 _gtk_boolean_handled_accumulator, NULL,
2915 _gtk_marshal_BOOLEAN__ENUM,
2917 GTK_TYPE_WIDGET_HELP_TYPE);
2920 * GtkWidget::accel-closures-changed:
2921 * @widget: the object which received the signal.
2923 widget_signals[ACCEL_CLOSURES_CHANGED] =
2924 g_signal_new (I_("accel-closures-changed"),
2925 G_TYPE_FROM_CLASS (klass),
2929 _gtk_marshal_VOID__VOID,
2933 * GtkWidget::screen-changed:
2934 * @widget: the object on which the signal is emitted
2935 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2936 * widget was not associated with a screen before
2938 * The ::screen-changed signal gets emitted when the
2939 * screen of a widget has changed.
2941 widget_signals[SCREEN_CHANGED] =
2942 g_signal_new (I_("screen-changed"),
2943 G_TYPE_FROM_CLASS (klass),
2945 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2947 _gtk_marshal_VOID__OBJECT,
2952 * GtkWidget::can-activate-accel:
2953 * @widget: the object which received the signal
2954 * @signal_id: the ID of a signal installed on @widget
2956 * Determines whether an accelerator that activates the signal
2957 * identified by @signal_id can currently be activated.
2958 * This signal is present to allow applications and derived
2959 * widgets to override the default #GtkWidget handling
2960 * for determining whether an accelerator can be activated.
2962 * Returns: %TRUE if the signal can be activated.
2964 widget_signals[CAN_ACTIVATE_ACCEL] =
2965 g_signal_new (I_("can-activate-accel"),
2966 G_TYPE_FROM_CLASS (klass),
2968 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2969 _gtk_boolean_handled_accumulator, NULL,
2970 _gtk_marshal_BOOLEAN__UINT,
2971 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2973 binding_set = gtk_binding_set_by_class (klass);
2974 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2976 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2979 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2981 GTK_TYPE_WIDGET_HELP_TYPE,
2982 GTK_WIDGET_HELP_TOOLTIP);
2983 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2985 GTK_TYPE_WIDGET_HELP_TYPE,
2986 GTK_WIDGET_HELP_TOOLTIP);
2987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2989 GTK_TYPE_WIDGET_HELP_TYPE,
2990 GTK_WIDGET_HELP_WHATS_THIS);
2991 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2993 GTK_TYPE_WIDGET_HELP_TYPE,
2994 GTK_WIDGET_HELP_WHATS_THIS);
2996 gtk_widget_class_install_style_property (klass,
2997 g_param_spec_boolean ("interior-focus",
2998 P_("Interior Focus"),
2999 P_("Whether to draw the focus indicator inside widgets"),
3001 GTK_PARAM_READABLE));
3003 gtk_widget_class_install_style_property (klass,
3004 g_param_spec_int ("focus-line-width",
3005 P_("Focus linewidth"),
3006 P_("Width, in pixels, of the focus indicator line"),
3008 GTK_PARAM_READABLE));
3010 gtk_widget_class_install_style_property (klass,
3011 g_param_spec_string ("focus-line-pattern",
3012 P_("Focus line dash pattern"),
3013 P_("Dash pattern used to draw the focus indicator"),
3015 GTK_PARAM_READABLE));
3016 gtk_widget_class_install_style_property (klass,
3017 g_param_spec_int ("focus-padding",
3018 P_("Focus padding"),
3019 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3021 GTK_PARAM_READABLE));
3022 gtk_widget_class_install_style_property (klass,
3023 g_param_spec_boxed ("cursor-color",
3025 P_("Color with which to draw insertion cursor"),
3027 GTK_PARAM_READABLE));
3028 gtk_widget_class_install_style_property (klass,
3029 g_param_spec_boxed ("secondary-cursor-color",
3030 P_("Secondary cursor color"),
3031 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3033 GTK_PARAM_READABLE));
3034 gtk_widget_class_install_style_property (klass,
3035 g_param_spec_float ("cursor-aspect-ratio",
3036 P_("Cursor line aspect ratio"),
3037 P_("Aspect ratio with which to draw insertion cursor"),
3039 GTK_PARAM_READABLE));
3041 gtk_widget_class_install_style_property (klass,
3042 g_param_spec_boolean ("window-dragging",
3043 P_("Window dragging"),
3044 P_("Whether windows can be dragged by clicking on empty areas"),
3046 GTK_PARAM_READABLE));
3049 * GtkWidget:link-color:
3051 * The "link-color" style property defines the color of unvisited links.
3055 gtk_widget_class_install_style_property (klass,
3056 g_param_spec_boxed ("link-color",
3057 P_("Unvisited Link Color"),
3058 P_("Color of unvisited links"),
3060 GTK_PARAM_READABLE));
3063 * GtkWidget:visited-link-color:
3065 * The "visited-link-color" style property defines the color of visited links.
3069 gtk_widget_class_install_style_property (klass,
3070 g_param_spec_boxed ("visited-link-color",
3071 P_("Visited Link Color"),
3072 P_("Color of visited links"),
3074 GTK_PARAM_READABLE));
3077 * GtkWidget:wide-separators:
3079 * The "wide-separators" style property defines whether separators have
3080 * configurable width and should be drawn using a box instead of a line.
3084 gtk_widget_class_install_style_property (klass,
3085 g_param_spec_boolean ("wide-separators",
3086 P_("Wide Separators"),
3087 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3089 GTK_PARAM_READABLE));
3092 * GtkWidget:separator-width:
3094 * The "separator-width" style property defines the width of separators.
3095 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3099 gtk_widget_class_install_style_property (klass,
3100 g_param_spec_int ("separator-width",
3101 P_("Separator Width"),
3102 P_("The width of separators if wide-separators is TRUE"),
3104 GTK_PARAM_READABLE));
3107 * GtkWidget:separator-height:
3109 * The "separator-height" style property defines the height of separators.
3110 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3114 gtk_widget_class_install_style_property (klass,
3115 g_param_spec_int ("separator-height",
3116 P_("Separator Height"),
3117 P_("The height of separators if \"wide-separators\" is TRUE"),
3119 GTK_PARAM_READABLE));
3122 * GtkWidget:scroll-arrow-hlength:
3124 * The "scroll-arrow-hlength" style property defines the length of
3125 * horizontal scroll arrows.
3129 gtk_widget_class_install_style_property (klass,
3130 g_param_spec_int ("scroll-arrow-hlength",
3131 P_("Horizontal Scroll Arrow Length"),
3132 P_("The length of horizontal scroll arrows"),
3134 GTK_PARAM_READABLE));
3137 * GtkWidget:scroll-arrow-vlength:
3139 * The "scroll-arrow-vlength" style property defines the length of
3140 * vertical scroll arrows.
3144 gtk_widget_class_install_style_property (klass,
3145 g_param_spec_int ("scroll-arrow-vlength",
3146 P_("Vertical Scroll Arrow Length"),
3147 P_("The length of vertical scroll arrows"),
3149 GTK_PARAM_READABLE));
3151 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3155 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3159 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3160 for (node = list; node; node = node->next)
3162 GParamSpec *pspec = node->data;
3164 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3165 g_param_spec_unref (pspec);
3171 gtk_widget_set_property (GObject *object,
3173 const GValue *value,
3176 GtkWidget *widget = GTK_WIDGET (object);
3181 gchar *tooltip_markup;
3182 const gchar *tooltip_text;
3183 GtkWindow *tooltip_window;
3186 gtk_widget_set_name (widget, g_value_get_string (value));
3189 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3191 case PROP_WIDTH_REQUEST:
3192 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3194 case PROP_HEIGHT_REQUEST:
3195 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3198 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3200 case PROP_SENSITIVE:
3201 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3203 case PROP_APP_PAINTABLE:
3204 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3206 case PROP_CAN_FOCUS:
3207 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3209 case PROP_HAS_FOCUS:
3210 if (g_value_get_boolean (value))
3211 gtk_widget_grab_focus (widget);
3214 if (g_value_get_boolean (value))
3215 gtk_widget_grab_focus (widget);
3217 case PROP_CAN_DEFAULT:
3218 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3220 case PROP_HAS_DEFAULT:
3221 if (g_value_get_boolean (value))
3222 gtk_widget_grab_default (widget);
3224 case PROP_RECEIVES_DEFAULT:
3225 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3228 gtk_widget_set_style (widget, g_value_get_object (value));
3231 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3232 gtk_widget_set_events (widget, g_value_get_flags (value));
3234 case PROP_EXTENSION_EVENTS:
3235 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3237 case PROP_NO_SHOW_ALL:
3238 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3240 case PROP_HAS_TOOLTIP:
3241 gtk_widget_real_set_has_tooltip (widget,
3242 g_value_get_boolean (value), FALSE);
3244 case PROP_TOOLTIP_MARKUP:
3245 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3246 tooltip_markup = g_value_dup_string (value);
3248 /* Treat an empty string as a NULL string,
3249 * because an empty string would be useless for a tooltip:
3251 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3253 g_free (tooltip_markup);
3254 tooltip_markup = NULL;
3257 g_object_set_qdata_full (object, quark_tooltip_markup,
3258 tooltip_markup, g_free);
3260 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3261 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3262 if (gtk_widget_get_visible (widget))
3263 gtk_widget_queue_tooltip_query (widget);
3265 case PROP_TOOLTIP_TEXT:
3266 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3268 tooltip_text = g_value_get_string (value);
3270 /* Treat an empty string as a NULL string,
3271 * because an empty string would be useless for a tooltip:
3273 if (tooltip_text && (strlen (tooltip_text) == 0))
3274 tooltip_text = NULL;
3276 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3278 g_object_set_qdata_full (object, quark_tooltip_markup,
3279 tooltip_markup, g_free);
3281 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3282 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3283 if (gtk_widget_get_visible (widget))
3284 gtk_widget_queue_tooltip_query (widget);
3286 case PROP_DOUBLE_BUFFERED:
3287 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3290 gtk_widget_set_halign (widget, g_value_get_enum (value));
3293 gtk_widget_set_valign (widget, g_value_get_enum (value));
3295 case PROP_MARGIN_LEFT:
3296 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3298 case PROP_MARGIN_RIGHT:
3299 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3301 case PROP_MARGIN_TOP:
3302 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3304 case PROP_MARGIN_BOTTOM:
3305 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3308 g_object_freeze_notify (G_OBJECT (widget));
3309 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3310 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3311 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3312 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3313 g_object_thaw_notify (G_OBJECT (widget));
3316 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3318 case PROP_HEXPAND_SET:
3319 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3322 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3324 case PROP_VEXPAND_SET:
3325 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3328 g_object_freeze_notify (G_OBJECT (widget));
3329 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3330 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3331 g_object_thaw_notify (G_OBJECT (widget));
3334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3340 gtk_widget_get_property (GObject *object,
3345 GtkWidget *widget = GTK_WIDGET (object);
3346 GtkWidgetPrivate *priv = widget->priv;
3355 g_value_set_string (value, priv->name);
3357 g_value_set_static_string (value, "");
3360 g_value_set_object (value, priv->parent);
3362 case PROP_WIDTH_REQUEST:
3365 gtk_widget_get_size_request (widget, &w, NULL);
3366 g_value_set_int (value, w);
3369 case PROP_HEIGHT_REQUEST:
3372 gtk_widget_get_size_request (widget, NULL, &h);
3373 g_value_set_int (value, h);
3377 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3379 case PROP_SENSITIVE:
3380 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3382 case PROP_APP_PAINTABLE:
3383 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3385 case PROP_CAN_FOCUS:
3386 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3388 case PROP_HAS_FOCUS:
3389 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3392 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3394 case PROP_CAN_DEFAULT:
3395 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3397 case PROP_HAS_DEFAULT:
3398 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3400 case PROP_RECEIVES_DEFAULT:
3401 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3403 case PROP_COMPOSITE_CHILD:
3404 g_value_set_boolean (value, widget->priv->composite_child);
3407 g_value_set_object (value, gtk_widget_get_style (widget));
3410 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3411 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3413 case PROP_EXTENSION_EVENTS:
3414 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3415 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3417 case PROP_NO_SHOW_ALL:
3418 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3420 case PROP_HAS_TOOLTIP:
3421 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3423 case PROP_TOOLTIP_TEXT:
3425 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3428 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3429 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3431 g_value_take_string (value, text);
3434 case PROP_TOOLTIP_MARKUP:
3435 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3438 g_value_set_object (value, gtk_widget_get_window (widget));
3440 case PROP_DOUBLE_BUFFERED:
3441 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3444 g_value_set_enum (value, gtk_widget_get_halign (widget));
3447 g_value_set_enum (value, gtk_widget_get_valign (widget));
3449 case PROP_MARGIN_LEFT:
3450 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3452 case PROP_MARGIN_RIGHT:
3453 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3455 case PROP_MARGIN_TOP:
3456 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3458 case PROP_MARGIN_BOTTOM:
3459 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3463 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3464 if (aux_info == NULL)
3466 g_value_set_int (value, 0);
3470 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3471 aux_info->margin.right),
3472 MAX (aux_info->margin.top,
3473 aux_info->margin.bottom)));
3478 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3480 case PROP_HEXPAND_SET:
3481 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3484 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3486 case PROP_VEXPAND_SET:
3487 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3490 g_value_set_boolean (value,
3491 gtk_widget_get_hexpand (widget) &&
3492 gtk_widget_get_vexpand (widget));
3495 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3501 gtk_widget_init (GtkWidget *widget)
3503 GtkWidgetPrivate *priv;
3505 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3508 priv = widget->priv;
3510 priv->child_visible = TRUE;
3512 priv->allocation.x = -1;
3513 priv->allocation.y = -1;
3514 priv->allocation.width = 1;
3515 priv->allocation.height = 1;
3516 priv->window = NULL;
3517 priv->parent = NULL;
3519 priv->sensitive = TRUE;
3520 priv->parent_sensitive = TRUE;
3521 priv->composite_child = composite_child_stack != 0;
3522 priv->double_buffered = TRUE;
3523 priv->redraw_on_alloc = TRUE;
3524 priv->width_request_needed = TRUE;
3525 priv->height_request_needed = TRUE;
3526 priv->alloc_needed = TRUE;
3528 /* this will be set to TRUE if the widget gets a child or if the
3529 * expand flag is set on the widget, but until one of those happen
3530 * we know the expand is already properly FALSE.
3532 * We really want to default FALSE here to avoid computing expand
3533 * all over the place while initially building a widget tree.
3535 priv->need_compute_expand = FALSE;
3537 priv->style = gtk_widget_get_default_style ();
3538 g_object_ref (priv->style);
3543 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3545 GParamSpec **pspecs)
3547 GtkWidgetPrivate *priv = widget->priv;
3548 GtkWidget *container = priv->parent;
3551 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3552 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3556 * gtk_widget_freeze_child_notify:
3557 * @widget: a #GtkWidget
3559 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3560 * signals are queued until gtk_widget_thaw_child_notify() is called
3563 * This is the analogue of g_object_freeze_notify() for child properties.
3566 gtk_widget_freeze_child_notify (GtkWidget *widget)
3568 g_return_if_fail (GTK_IS_WIDGET (widget));
3570 if (!G_OBJECT (widget)->ref_count)
3573 g_object_ref (widget);
3574 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3575 g_object_unref (widget);
3579 * gtk_widget_child_notify:
3580 * @widget: a #GtkWidget
3581 * @child_property: the name of a child property installed on the
3582 * class of @widget<!-- -->'s parent
3584 * Emits a #GtkWidget::child-notify signal for the
3585 * <link linkend="child-properties">child property</link> @child_property
3588 * This is the analogue of g_object_notify() for child properties.
3591 gtk_widget_child_notify (GtkWidget *widget,
3592 const gchar *child_property)
3594 GtkWidgetPrivate *priv = widget->priv;
3597 g_return_if_fail (GTK_IS_WIDGET (widget));
3598 g_return_if_fail (child_property != NULL);
3599 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3602 g_object_ref (widget);
3603 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3605 G_OBJECT_TYPE (priv->parent),
3608 g_warning ("%s: container class `%s' has no child property named `%s'",
3610 G_OBJECT_TYPE_NAME (priv->parent),
3614 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3616 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3617 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3619 g_object_unref (widget);
3623 * gtk_widget_thaw_child_notify:
3624 * @widget: a #GtkWidget
3626 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3627 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3631 gtk_widget_thaw_child_notify (GtkWidget *widget)
3633 GObjectNotifyQueue *nqueue;
3635 g_return_if_fail (GTK_IS_WIDGET (widget));
3637 if (!G_OBJECT (widget)->ref_count)
3640 g_object_ref (widget);
3641 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3642 if (!nqueue || !nqueue->freeze_count)
3643 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3644 G_OBJECT_TYPE_NAME (widget), widget);
3646 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3647 g_object_unref (widget);
3653 * @type: type ID of the widget to create
3654 * @first_property_name: name of first property to set
3655 * @Varargs: value of first property, followed by more properties,
3658 * This is a convenience function for creating a widget and setting
3659 * its properties in one go. For example you might write:
3660 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3661 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3662 * g_object_new(), but returns a widget so you don't have to
3663 * cast the object yourself.
3665 * Return value: a new #GtkWidget of type @widget_type
3668 gtk_widget_new (GType type,
3669 const gchar *first_property_name,
3675 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3677 va_start (var_args, first_property_name);
3678 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3685 gtk_widget_queue_draw_child (GtkWidget *widget)
3687 GtkWidgetPrivate *priv = widget->priv;
3690 parent = priv->parent;
3691 if (parent && gtk_widget_is_drawable (parent))
3692 gtk_widget_queue_draw_area (parent,
3695 priv->allocation.width,
3696 priv->allocation.height);
3700 * gtk_widget_unparent:
3701 * @widget: a #GtkWidget
3703 * This function is only for use in widget implementations.
3704 * Should be called by implementations of the remove method
3705 * on #GtkContainer, to dissociate a child from the container.
3708 gtk_widget_unparent (GtkWidget *widget)
3710 GtkWidgetPrivate *priv;
3711 GObjectNotifyQueue *nqueue;
3712 GtkWidget *toplevel;
3713 GtkWidget *old_parent;
3715 g_return_if_fail (GTK_IS_WIDGET (widget));
3717 priv = widget->priv;
3719 if (priv->parent == NULL)
3722 /* keep this function in sync with gtk_menu_detach()
3725 g_object_freeze_notify (G_OBJECT (widget));
3726 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3728 toplevel = gtk_widget_get_toplevel (widget);
3729 if (gtk_widget_is_toplevel (toplevel))
3730 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3732 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3733 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3735 /* If we are unanchoring the child, we save around the toplevel
3736 * to emit hierarchy changed
3738 if (priv->parent->priv->anchored)
3739 g_object_ref (toplevel);
3743 gtk_widget_queue_draw_child (widget);
3745 /* Reset the width and height here, to force reallocation if we
3746 * get added back to a new parent. This won't work if our new
3747 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3748 * (would 0x0 be OK here?)
3750 priv->allocation.width = 1;
3751 priv->allocation.height = 1;
3753 if (gtk_widget_get_realized (widget))
3755 if (priv->in_reparent)
3756 gtk_widget_unmap (widget);
3758 gtk_widget_unrealize (widget);
3761 /* Removing a widget from a container restores the child visible
3762 * flag to the default state, so it doesn't affect the child
3763 * in the next parent.
3765 priv->child_visible = TRUE;
3767 old_parent = priv->parent;
3768 priv->parent = NULL;
3769 gtk_widget_set_parent_window (widget, NULL);
3771 /* parent may no longer expand if the removed
3772 * child was expand=TRUE and could therefore
3775 if (gtk_widget_get_visible (widget) &&
3776 (priv->need_compute_expand ||
3777 priv->computed_hexpand ||
3778 priv->computed_vexpand))
3780 gtk_widget_queue_compute_expand (old_parent);
3783 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3786 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3787 g_object_unref (toplevel);
3790 g_object_notify (G_OBJECT (widget), "parent");
3791 g_object_thaw_notify (G_OBJECT (widget));
3793 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3794 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3795 g_object_unref (widget);
3799 * gtk_widget_destroy:
3800 * @widget: a #GtkWidget
3802 * Destroys a widget.
3805 * destroyed, it will break any references it holds to other objects.
3806 * If the widget is inside a container, the widget will be removed
3807 * from the container. If the widget is a toplevel (derived from
3808 * #GtkWindow), it will be removed from the list of toplevels, and the
3809 * reference GTK+ holds to it will be removed. Removing a
3810 * widget from its container or the list of toplevels results in the
3811 * widget being finalized, unless you've added additional references
3812 * to the widget with g_object_ref().
3814 * In most cases, only toplevel widgets (windows) require explicit
3815 * destruction, because when you destroy a toplevel its children will
3816 * be destroyed as well.
3819 gtk_widget_destroy (GtkWidget *widget)
3821 g_return_if_fail (GTK_IS_WIDGET (widget));
3823 if (!widget->priv->in_destruction)
3824 g_object_run_dispose (G_OBJECT (widget));
3828 * gtk_widget_destroyed:
3829 * @widget: a #GtkWidget
3830 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3832 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3833 * %NULL. It's intended to be used as a callback connected to the
3834 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3835 * as a signal handler, and pass the address of your widget variable
3836 * as user data. Then when the widget is destroyed, the variable will
3837 * be set to %NULL. Useful for example to avoid multiple copies
3838 * of the same dialog.
3841 gtk_widget_destroyed (GtkWidget *widget,
3842 GtkWidget **widget_pointer)
3844 /* Don't make any assumptions about the
3846 * Even check widget_pointer.
3849 *widget_pointer = NULL;
3854 * @widget: a #GtkWidget
3856 * Flags a widget to be displayed. Any widget that isn't shown will
3857 * not appear on the screen. If you want to show all the widgets in a
3858 * container, it's easier to call gtk_widget_show_all() on the
3859 * container, instead of individually showing the widgets.
3861 * Remember that you have to show the containers containing a widget,
3862 * in addition to the widget itself, before it will appear onscreen.
3864 * When a toplevel container is shown, it is immediately realized and
3865 * mapped; other shown widgets are realized and mapped when their
3866 * toplevel container is realized and mapped.
3869 gtk_widget_show (GtkWidget *widget)
3871 g_return_if_fail (GTK_IS_WIDGET (widget));
3873 if (!gtk_widget_get_visible (widget))
3875 g_object_ref (widget);
3876 if (!gtk_widget_is_toplevel (widget))
3877 gtk_widget_queue_resize (widget);
3879 /* see comment in set_parent() for why this should and can be
3882 if (widget->priv->need_compute_expand ||
3883 widget->priv->computed_hexpand ||
3884 widget->priv->computed_vexpand)
3886 if (widget->priv->parent != NULL)
3887 gtk_widget_queue_compute_expand (widget->priv->parent);
3890 g_signal_emit (widget, widget_signals[SHOW], 0);
3891 g_object_notify (G_OBJECT (widget), "visible");
3892 g_object_unref (widget);
3897 gtk_widget_real_show (GtkWidget *widget)
3899 GtkWidgetPrivate *priv = widget->priv;
3901 if (!gtk_widget_get_visible (widget))
3903 priv->visible = TRUE;
3906 gtk_widget_get_mapped (priv->parent) &&
3907 gtk_widget_get_child_visible (widget) &&
3908 !gtk_widget_get_mapped (widget))
3909 gtk_widget_map (widget);
3914 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3917 g_signal_handlers_disconnect_by_func (widget,
3918 gtk_widget_show_map_callback,
3923 * gtk_widget_show_now:
3924 * @widget: a #GtkWidget
3926 * Shows a widget. If the widget is an unmapped toplevel widget
3927 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3928 * loop and wait for the window to actually be mapped. Be careful;
3929 * because the main loop is running, anything can happen during
3933 gtk_widget_show_now (GtkWidget *widget)
3937 g_return_if_fail (GTK_IS_WIDGET (widget));
3939 /* make sure we will get event */
3940 if (!gtk_widget_get_mapped (widget) &&
3941 gtk_widget_is_toplevel (widget))
3943 gtk_widget_show (widget);
3945 g_signal_connect (widget, "map-event",
3946 G_CALLBACK (gtk_widget_show_map_callback),
3950 gtk_main_iteration ();
3953 gtk_widget_show (widget);
3958 * @widget: a #GtkWidget
3960 * Reverses the effects of gtk_widget_show(), causing the widget to be
3961 * hidden (invisible to the user).
3964 gtk_widget_hide (GtkWidget *widget)
3966 g_return_if_fail (GTK_IS_WIDGET (widget));
3968 if (gtk_widget_get_visible (widget))
3970 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3972 g_object_ref (widget);
3973 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3974 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3976 /* a parent may now be expand=FALSE since we're hidden. */
3977 if (widget->priv->need_compute_expand ||
3978 widget->priv->computed_hexpand ||
3979 widget->priv->computed_vexpand)
3981 gtk_widget_queue_compute_expand (widget);
3984 g_signal_emit (widget, widget_signals[HIDE], 0);
3985 if (!gtk_widget_is_toplevel (widget))
3986 gtk_widget_queue_resize (widget);
3987 g_object_notify (G_OBJECT (widget), "visible");
3988 g_object_unref (widget);
3993 gtk_widget_real_hide (GtkWidget *widget)
3995 if (gtk_widget_get_visible (widget))
3997 widget->priv->visible = FALSE;
3999 if (gtk_widget_get_mapped (widget))
4000 gtk_widget_unmap (widget);
4005 * gtk_widget_hide_on_delete:
4006 * @widget: a #GtkWidget
4008 * Utility function; intended to be connected to the #GtkWidget::delete-event
4009 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4010 * argument, then returns %TRUE. If connected to ::delete-event, the
4011 * result is that clicking the close button for a window (on the
4012 * window frame, top right corner usually) will hide but not destroy
4013 * the window. By default, GTK+ destroys windows when ::delete-event
4016 * Return value: %TRUE
4019 gtk_widget_hide_on_delete (GtkWidget *widget)
4021 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4023 gtk_widget_hide (widget);
4029 * gtk_widget_show_all:
4030 * @widget: a #GtkWidget
4032 * Recursively shows a widget, and any child widgets (if the widget is
4036 gtk_widget_show_all (GtkWidget *widget)
4038 GtkWidgetClass *class;
4040 g_return_if_fail (GTK_IS_WIDGET (widget));
4042 if (gtk_widget_get_no_show_all (widget))
4045 class = GTK_WIDGET_GET_CLASS (widget);
4047 if (class->show_all)
4048 class->show_all (widget);
4052 _gtk_widget_notify_state_change (GtkWidget *widget,
4060 case GTK_STATE_FLAG_ACTIVE:
4061 state = GTK_STATE_ACTIVE;
4063 case GTK_STATE_FLAG_PRELIGHT:
4064 state = GTK_STATE_PRELIGHT;
4066 case GTK_STATE_FLAG_SELECTED:
4067 state = GTK_STATE_SELECTED;
4069 case GTK_STATE_FLAG_INSENSITIVE:
4070 state = GTK_STATE_INSENSITIVE;
4072 case GTK_STATE_FLAG_INCONSISTENT:
4073 state = GTK_STATE_INCONSISTENT;
4075 case GTK_STATE_FLAG_FOCUSED:
4076 state = GTK_STATE_FOCUSED;
4082 gtk_style_context_notify_state_change (widget->priv->context,
4083 gtk_widget_get_window (widget),
4084 NULL, state, target);
4087 /* Initializes state transitions for those states that
4088 * were enabled before mapping and have a looping animation.
4091 _gtk_widget_start_state_transitions (GtkWidget *widget)
4093 GtkStateFlags state, flag;
4095 if (!widget->priv->context)
4098 state = gtk_widget_get_state_flags (widget);
4099 flag = GTK_STATE_FLAG_FOCUSED;
4103 GtkAnimationDescription *animation_desc;
4105 if ((state & flag) == 0)
4111 gtk_style_context_get (widget->priv->context, state,
4112 "transition", &animation_desc,
4117 if (_gtk_animation_description_get_loop (animation_desc))
4118 _gtk_widget_notify_state_change (widget, flag, TRUE);
4120 _gtk_animation_description_unref (animation_desc);
4129 * @widget: a #GtkWidget
4131 * This function is only for use in widget implementations. Causes
4132 * a widget to be mapped if it isn't already.
4135 gtk_widget_map (GtkWidget *widget)
4137 GtkWidgetPrivate *priv;
4139 g_return_if_fail (GTK_IS_WIDGET (widget));
4140 g_return_if_fail (gtk_widget_get_visible (widget));
4141 g_return_if_fail (gtk_widget_get_child_visible (widget));
4143 priv = widget->priv;
4145 if (!gtk_widget_get_mapped (widget))
4147 if (!gtk_widget_get_realized (widget))
4148 gtk_widget_realize (widget);
4150 g_signal_emit (widget, widget_signals[MAP], 0);
4152 if (!gtk_widget_get_has_window (widget))
4153 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4155 _gtk_widget_start_state_transitions (widget);
4161 * @widget: a #GtkWidget
4163 * This function is only for use in widget implementations. Causes
4164 * a widget to be unmapped if it's currently mapped.
4167 gtk_widget_unmap (GtkWidget *widget)
4169 GtkWidgetPrivate *priv;
4171 g_return_if_fail (GTK_IS_WIDGET (widget));
4173 priv = widget->priv;
4175 if (gtk_widget_get_mapped (widget))
4177 if (!gtk_widget_get_has_window (widget))
4178 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4179 _gtk_tooltip_hide (widget);
4180 g_signal_emit (widget, widget_signals[UNMAP], 0);
4185 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4186 GdkExtensionMode mode,
4189 GtkWidgetPrivate *priv = widget->priv;
4190 GList *free_list = NULL;
4193 if (window_list == NULL)
4195 if (gtk_widget_get_has_window (widget))
4196 window_list = g_list_prepend (NULL, priv->window);
4198 window_list = gdk_window_get_children (priv->window);
4200 free_list = window_list;
4203 for (l = window_list; l != NULL; l = l->next)
4205 GdkWindow *window = l->data;
4208 gdk_window_get_user_data (window, &user_data);
4209 if (user_data == widget)
4213 gdk_input_set_extension_events (window,
4214 gdk_window_get_events (window),
4217 children = gdk_window_get_children (window);
4220 gtk_widget_set_extension_events_internal (widget, mode, children);
4221 g_list_free (children);
4227 g_list_free (free_list);
4231 _gtk_widget_enable_device_events (GtkWidget *widget)
4233 GHashTable *device_events;
4234 GHashTableIter iter;
4235 gpointer key, value;
4237 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4242 g_hash_table_iter_init (&iter, device_events);
4244 while (g_hash_table_iter_next (&iter, &key, &value))
4247 GdkEventMask event_mask;
4250 event_mask = GPOINTER_TO_UINT (value);
4251 gtk_widget_add_events_internal (widget, device, event_mask);
4256 * gtk_widget_realize:
4257 * @widget: a #GtkWidget
4259 * Creates the GDK (windowing system) resources associated with a
4260 * widget. For example, @widget->window will be created when a widget
4261 * is realized. Normally realization happens implicitly; if you show
4262 * a widget and all its parent containers, then the widget will be
4263 * realized and mapped automatically.
4265 * Realizing a widget requires all
4266 * the widget's parent widgets to be realized; calling
4267 * gtk_widget_realize() realizes the widget's parents in addition to
4268 * @widget itself. If a widget is not yet inside a toplevel window
4269 * when you realize it, bad things will happen.
4271 * This function is primarily used in widget implementations, and
4272 * isn't very useful otherwise. Many times when you think you might
4273 * need it, a better approach is to connect to a signal that will be
4274 * called after the widget is realized automatically, such as
4275 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4276 * #GtkWidget::realize signal.
4279 gtk_widget_realize (GtkWidget *widget)
4281 GtkWidgetPrivate *priv;
4282 GdkExtensionMode mode;
4283 cairo_region_t *region;
4285 g_return_if_fail (GTK_IS_WIDGET (widget));
4286 g_return_if_fail (widget->priv->anchored ||
4287 GTK_IS_INVISIBLE (widget));
4289 priv = widget->priv;
4291 if (!gtk_widget_get_realized (widget))
4294 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4295 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4298 if (priv->parent == NULL &&
4299 !gtk_widget_is_toplevel (widget))
4300 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4301 "inside a toplevel window is not going to work very well. "
4302 "Widgets must be inside a toplevel container before realizing them.");
4304 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4305 gtk_widget_realize (priv->parent);
4307 gtk_widget_ensure_style (widget);
4309 g_signal_emit (widget, widget_signals[REALIZE], 0);
4311 gtk_widget_real_set_has_tooltip (widget,
4312 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4315 if (priv->has_shape_mask)
4317 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4318 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4321 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4323 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4325 mode = gtk_widget_get_extension_events (widget);
4326 if (mode != GDK_EXTENSION_EVENTS_NONE)
4327 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4329 if (priv->multidevice)
4330 gdk_window_set_support_multidevice (priv->window, TRUE);
4332 _gtk_widget_enable_device_events (widget);
4337 * gtk_widget_unrealize:
4338 * @widget: a #GtkWidget
4340 * This function is only useful in widget implementations.
4341 * Causes a widget to be unrealized (frees all GDK resources
4342 * associated with the widget, such as @widget->window).
4345 gtk_widget_unrealize (GtkWidget *widget)
4347 g_return_if_fail (GTK_IS_WIDGET (widget));
4349 if (widget->priv->has_shape_mask)
4350 gtk_widget_shape_combine_region (widget, NULL);
4352 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4353 gtk_widget_input_shape_combine_region (widget, NULL);
4355 if (gtk_widget_get_realized (widget))
4357 g_object_ref (widget);
4358 _gtk_tooltip_hide (widget);
4359 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4360 gtk_widget_set_realized (widget, FALSE);
4361 gtk_widget_set_mapped (widget, FALSE);
4362 g_object_unref (widget);
4366 /*****************************************
4368 *****************************************/
4371 * gtk_widget_queue_draw_region:
4372 * @widget: a #GtkWidget
4373 * @region: region to draw
4375 * Invalidates the rectangular area of @widget defined by @region by
4376 * calling gdk_window_invalidate_region() on the widget's window and
4377 * all its child windows. Once the main loop becomes idle (after the
4378 * current batch of events has been processed, roughly), the window
4379 * will receive expose events for the union of all regions that have
4382 * Normally you would only use this function in widget
4383 * implementations. You might also use it to schedule a redraw of a
4384 * #GtkDrawingArea or some portion thereof.
4387 gtk_widget_queue_draw_region (GtkWidget *widget,
4388 cairo_region_t *region)
4390 GtkWidgetPrivate *priv;
4393 g_return_if_fail (GTK_IS_WIDGET (widget));
4395 priv = widget->priv;
4397 if (!gtk_widget_get_realized (widget))
4400 /* Just return if the widget or one of its ancestors isn't mapped */
4401 for (w = widget; w != NULL; w = w->priv->parent)
4402 if (!gtk_widget_get_mapped (w))
4405 gdk_window_invalidate_region (priv->window, region, TRUE);
4409 * gtk_widget_queue_draw_area:
4410 * @widget: a #GtkWidget
4411 * @x: x coordinate of upper-left corner of rectangle to redraw
4412 * @y: y coordinate of upper-left corner of rectangle to redraw
4413 * @width: width of region to draw
4414 * @height: height of region to draw
4416 * Convenience function that calls gtk_widget_queue_draw_region() on
4417 * the region created from the given coordinates.
4420 gtk_widget_queue_draw_area (GtkWidget *widget,
4427 cairo_region_t *region;
4429 g_return_if_fail (GTK_IS_WIDGET (widget));
4434 rect.height = height;
4436 region = cairo_region_create_rectangle (&rect);
4437 gtk_widget_queue_draw_region (widget, region);
4438 cairo_region_destroy (region);
4442 * gtk_widget_queue_draw:
4443 * @widget: a #GtkWidget
4445 * Equivalent to calling gtk_widget_queue_draw_area() for the
4446 * entire area of a widget.
4449 gtk_widget_queue_draw (GtkWidget *widget)
4453 g_return_if_fail (GTK_IS_WIDGET (widget));
4455 gtk_widget_get_allocation (widget, &rect);
4457 if (!gtk_widget_get_has_window (widget))
4458 gtk_widget_queue_draw_area (widget,
4459 rect.x, rect.y, rect.width, rect.height);
4461 gtk_widget_queue_draw_area (widget,
4462 0, 0, rect.width, rect.height);
4466 * gtk_widget_queue_resize:
4467 * @widget: a #GtkWidget
4469 * This function is only for use in widget implementations.
4470 * Flags a widget to have its size renegotiated; should
4471 * be called when a widget for some reason has a new size request.
4472 * For example, when you change the text in a #GtkLabel, #GtkLabel
4473 * queues a resize to ensure there's enough space for the new text.
4475 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4476 * from inside it's implementation of the GtkWidgetClass::size_allocate
4477 * virtual method. Calls to gtk_widget_queue_resize() from inside
4478 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4481 gtk_widget_queue_resize (GtkWidget *widget)
4483 g_return_if_fail (GTK_IS_WIDGET (widget));
4485 if (gtk_widget_get_realized (widget))
4486 gtk_widget_queue_shallow_draw (widget);
4488 _gtk_size_group_queue_resize (widget, 0);
4492 * gtk_widget_queue_resize_no_redraw:
4493 * @widget: a #GtkWidget
4495 * This function works like gtk_widget_queue_resize(),
4496 * except that the widget is not invalidated.
4501 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4503 g_return_if_fail (GTK_IS_WIDGET (widget));
4505 _gtk_size_group_queue_resize (widget, 0);
4509 * gtk_widget_size_request:
4510 * @widget: a #GtkWidget
4511 * @requisition: (out): a #GtkRequisition to be filled in
4513 * This function is typically used when implementing a #GtkContainer
4514 * subclass. Obtains the preferred size of a widget. The container
4515 * uses this information to arrange its child widgets and decide what
4516 * size allocations to give them with gtk_widget_size_allocate().
4518 * You can also call this function from an application, with some
4519 * caveats. Most notably, getting a size request requires the widget
4520 * to be associated with a screen, because font information may be
4521 * needed. Multihead-aware applications should keep this in mind.
4523 * Also remember that the size request is not necessarily the size
4524 * a widget will actually be allocated.
4526 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4529 gtk_widget_size_request (GtkWidget *widget,
4530 GtkRequisition *requisition)
4532 g_return_if_fail (GTK_IS_WIDGET (widget));
4534 gtk_widget_get_preferred_size (widget, requisition, NULL);
4538 * gtk_widget_get_child_requisition:
4539 * @widget: a #GtkWidget
4540 * @requisition: (out): a #GtkRequisition to be filled in
4542 * This function is only for use in widget implementations. Obtains
4543 * @widget->requisition, unless someone has forced a particular
4544 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4545 * in which case it returns that geometry instead of the widget's
4548 * This function differs from gtk_widget_size_request() in that
4549 * it retrieves the last size request value from @widget->requisition,
4550 * while gtk_widget_size_request() actually calls the "size_request" method
4551 * on @widget to compute the size request and fill in @widget->requisition,
4552 * and only then returns @widget->requisition.
4554 * Because this function does not call the "size_request" method, it
4555 * can only be used when you know that @widget->requisition is
4556 * up-to-date, that is, gtk_widget_size_request() has been called
4557 * since the last time a resize was queued. In general, only container
4558 * implementations have this information; applications should use
4559 * gtk_widget_size_request().
4562 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4565 gtk_widget_get_child_requisition (GtkWidget *widget,
4566 GtkRequisition *requisition)
4568 gtk_widget_get_preferred_size (widget, requisition, NULL);
4572 invalidate_predicate (GdkWindow *window,
4577 gdk_window_get_user_data (window, &user_data);
4579 return (user_data == data);
4582 /* Invalidate @region in widget->window and all children
4583 * of widget->window owned by widget. @region is in the
4584 * same coordinates as widget->allocation and will be
4585 * modified by this call.
4588 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4589 cairo_region_t *region)
4591 GtkWidgetPrivate *priv = widget->priv;
4593 if (!gtk_widget_get_realized (widget))
4596 if (gtk_widget_get_has_window (widget) && priv->parent)
4600 gdk_window_get_position (priv->window, &x, &y);
4601 cairo_region_translate (region, -x, -y);
4604 gdk_window_invalidate_maybe_recurse (priv->window, region,
4605 invalidate_predicate, widget);
4609 * gtk_widget_queue_shallow_draw:
4610 * @widget: a #GtkWidget
4612 * Like gtk_widget_queue_draw(), but only windows owned
4613 * by @widget are invalidated.
4616 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4619 cairo_region_t *region;
4621 if (!gtk_widget_get_realized (widget))
4624 gtk_widget_get_allocation (widget, &rect);
4626 region = cairo_region_create_rectangle (&rect);
4627 gtk_widget_invalidate_widget_windows (widget, region);
4628 cairo_region_destroy (region);
4632 * gtk_widget_size_allocate:
4633 * @widget: a #GtkWidget
4634 * @allocation: (inout): position and size to be allocated to @widget
4636 * This function is only used by #GtkContainer subclasses, to assign a size
4637 * and position to their child widgets.
4639 * In this function, the allocation may be adjusted. It will be forced
4640 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4641 * method on the child will be used to adjust the allocation. Standard
4642 * adjustments include removing the widget's margins, and applying the
4643 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4646 gtk_widget_size_allocate (GtkWidget *widget,
4647 GtkAllocation *allocation)
4649 GtkWidgetPrivate *priv;
4650 GdkRectangle real_allocation;
4651 GdkRectangle old_allocation;
4652 GdkRectangle adjusted_allocation;
4653 gboolean alloc_needed;
4654 gboolean size_changed;
4655 gboolean position_changed;
4656 gint natural_width, natural_height, dummy;
4657 gint min_width, min_height;
4659 priv = widget->priv;
4661 g_return_if_fail (GTK_IS_WIDGET (widget));
4663 #ifdef G_ENABLE_DEBUG
4664 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4675 parent = gtk_widget_get_parent (parent);
4678 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4679 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4680 2 * depth, " ", name,
4681 allocation->width, allocation->height);
4683 #endif /* G_ENABLE_DEBUG */
4685 alloc_needed = priv->alloc_needed;
4686 if (!priv->width_request_needed && !priv->height_request_needed)
4687 /* Preserve request/allocate ordering */
4688 priv->alloc_needed = FALSE;
4690 old_allocation = priv->allocation;
4691 real_allocation = *allocation;
4693 adjusted_allocation = real_allocation;
4694 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4696 /* Go ahead and request the height for allocated width, note that the internals
4697 * of get_height_for_width will internally limit the for_size to natural size
4698 * when aligning implicitly.
4700 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4701 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4705 /* Go ahead and request the width for allocated height, note that the internals
4706 * of get_width_for_height will internally limit the for_size to natural size
4707 * when aligning implicitly.
4709 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4710 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4713 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4714 * allocated sizes and possibly limit them to the natural sizes */
4715 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4716 GTK_ORIENTATION_HORIZONTAL,
4719 &adjusted_allocation.x,
4720 &adjusted_allocation.width);
4721 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4722 GTK_ORIENTATION_VERTICAL,
4725 &adjusted_allocation.y,
4726 &adjusted_allocation.height);
4728 if (adjusted_allocation.x < real_allocation.x ||
4729 adjusted_allocation.y < real_allocation.y ||
4730 (adjusted_allocation.x + adjusted_allocation.width) >
4731 (real_allocation.x + real_allocation.width) ||
4732 (adjusted_allocation.y + adjusted_allocation.height >
4733 real_allocation.y + real_allocation.height))
4735 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",
4736 G_OBJECT_TYPE_NAME (widget), widget,
4737 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4738 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4739 adjusted_allocation = real_allocation; /* veto it */
4743 real_allocation = adjusted_allocation;
4746 if (real_allocation.width < 0 || real_allocation.height < 0)
4748 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4749 real_allocation.width,
4750 real_allocation.height);
4753 real_allocation.width = MAX (real_allocation.width, 1);
4754 real_allocation.height = MAX (real_allocation.height, 1);
4756 size_changed = (old_allocation.width != real_allocation.width ||
4757 old_allocation.height != real_allocation.height);
4758 position_changed = (old_allocation.x != real_allocation.x ||
4759 old_allocation.y != real_allocation.y);
4761 if (!alloc_needed && !size_changed && !position_changed)
4764 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4766 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4767 priv->width_request_needed = FALSE;
4768 priv->height_request_needed = FALSE;
4769 priv->alloc_needed = FALSE;
4771 if (gtk_widget_get_mapped (widget))
4773 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4775 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4777 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4778 cairo_region_union_rectangle (invalidate, &old_allocation);
4780 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4781 cairo_region_destroy (invalidate);
4786 if (priv->redraw_on_alloc)
4788 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4790 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4791 cairo_region_union_rectangle (invalidate, &old_allocation);
4793 gtk_widget_invalidate_widget_windows (widget, invalidate);
4794 cairo_region_destroy (invalidate);
4798 if (size_changed || position_changed)
4800 GtkStyleContext *context;
4802 context = gtk_widget_get_style_context (widget);
4803 _gtk_style_context_invalidate_animation_areas (context);
4807 if ((size_changed || position_changed) && priv->parent &&
4808 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4810 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4811 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4812 cairo_region_destroy (invalidate);
4817 * gtk_widget_common_ancestor:
4818 * @widget_a: a #GtkWidget
4819 * @widget_b: a #GtkWidget
4821 * Find the common ancestor of @widget_a and @widget_b that
4822 * is closest to the two widgets.
4824 * Return value: the closest common ancestor of @widget_a and
4825 * @widget_b or %NULL if @widget_a and @widget_b do not
4826 * share a common ancestor.
4829 gtk_widget_common_ancestor (GtkWidget *widget_a,
4830 GtkWidget *widget_b)
4832 GtkWidget *parent_a;
4833 GtkWidget *parent_b;
4837 parent_a = widget_a;
4838 while (parent_a->priv->parent)
4840 parent_a = parent_a->priv->parent;
4844 parent_b = widget_b;
4845 while (parent_b->priv->parent)
4847 parent_b = parent_b->priv->parent;
4851 if (parent_a != parent_b)
4854 while (depth_a > depth_b)
4856 widget_a = widget_a->priv->parent;
4860 while (depth_b > depth_a)
4862 widget_b = widget_b->priv->parent;
4866 while (widget_a != widget_b)
4868 widget_a = widget_a->priv->parent;
4869 widget_b = widget_b->priv->parent;
4876 * gtk_widget_translate_coordinates:
4877 * @src_widget: a #GtkWidget
4878 * @dest_widget: a #GtkWidget
4879 * @src_x: X position relative to @src_widget
4880 * @src_y: Y position relative to @src_widget
4881 * @dest_x: (out): location to store X position relative to @dest_widget
4882 * @dest_y: (out): location to store Y position relative to @dest_widget
4884 * Translate coordinates relative to @src_widget's allocation to coordinates
4885 * relative to @dest_widget's allocations. In order to perform this
4886 * operation, both widgets must be realized, and must share a common
4889 * Return value: %FALSE if either widget was not realized, or there
4890 * was no common ancestor. In this case, nothing is stored in
4891 * *@dest_x and *@dest_y. Otherwise %TRUE.
4894 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4895 GtkWidget *dest_widget,
4901 GtkWidgetPrivate *src_priv = src_widget->priv;
4902 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4903 GtkWidget *ancestor;
4905 GList *dest_list = NULL;
4907 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4908 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4910 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4911 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4914 /* Translate from allocation relative to window relative */
4915 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4918 gdk_window_get_position (src_priv->window, &wx, &wy);
4920 src_x -= wx - src_priv->allocation.x;
4921 src_y -= wy - src_priv->allocation.y;
4925 src_x += src_priv->allocation.x;
4926 src_y += src_priv->allocation.y;
4929 /* Translate to the common ancestor */
4930 window = src_priv->window;
4931 while (window != ancestor->priv->window)
4935 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4940 window = gdk_window_get_effective_parent (window);
4942 if (!window) /* Handle GtkHandleBox */
4947 window = dest_priv->window;
4948 while (window != ancestor->priv->window)
4950 dest_list = g_list_prepend (dest_list, window);
4952 window = gdk_window_get_effective_parent (window);
4954 if (!window) /* Handle GtkHandleBox */
4956 g_list_free (dest_list);
4965 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4970 dest_list = g_list_remove (dest_list, dest_list->data);
4973 /* Translate from window relative to allocation relative */
4974 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4977 gdk_window_get_position (dest_priv->window, &wx, &wy);
4979 src_x += wx - dest_priv->allocation.x;
4980 src_y += wy - dest_priv->allocation.y;
4984 src_x -= dest_priv->allocation.x;
4985 src_y -= dest_priv->allocation.y;
4997 gtk_widget_real_size_allocate (GtkWidget *widget,
4998 GtkAllocation *allocation)
5000 GtkWidgetPrivate *priv = widget->priv;
5002 priv->allocation = *allocation;
5004 if (gtk_widget_get_realized (widget) &&
5005 gtk_widget_get_has_window (widget))
5007 gdk_window_move_resize (priv->window,
5008 allocation->x, allocation->y,
5009 allocation->width, allocation->height);
5014 adjust_for_align(GtkAlign align,
5016 gint *allocated_pos,
5017 gint *allocated_size)
5021 case GTK_ALIGN_FILL:
5022 /* change nothing */
5024 case GTK_ALIGN_START:
5025 /* keep *allocated_pos where it is */
5026 *allocated_size = MIN (*allocated_size, *natural_size);
5029 if (*allocated_size > *natural_size)
5031 *allocated_pos += (*allocated_size - *natural_size);
5032 *allocated_size = *natural_size;
5035 case GTK_ALIGN_CENTER:
5036 if (*allocated_size > *natural_size)
5038 *allocated_pos += (*allocated_size - *natural_size) / 2;
5039 *allocated_size = MIN (*allocated_size, *natural_size);
5046 adjust_for_margin(gint start_margin,
5050 gint *allocated_pos,
5051 gint *allocated_size)
5053 *minimum_size -= (start_margin + end_margin);
5054 *natural_size -= (start_margin + end_margin);
5055 *allocated_pos += start_margin;
5056 *allocated_size -= (start_margin + end_margin);
5060 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5061 GtkOrientation orientation,
5064 gint *allocated_pos,
5065 gint *allocated_size)
5067 const GtkWidgetAuxInfo *aux_info;
5069 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5071 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5073 adjust_for_margin (aux_info->margin.left,
5074 aux_info->margin.right,
5075 minimum_size, natural_size,
5076 allocated_pos, allocated_size);
5077 adjust_for_align (aux_info->halign,
5078 natural_size, allocated_pos, allocated_size);
5082 adjust_for_margin (aux_info->margin.top,
5083 aux_info->margin.bottom,
5084 minimum_size, natural_size,
5085 allocated_pos, allocated_size);
5086 adjust_for_align (aux_info->valign,
5087 natural_size, allocated_pos, allocated_size);
5092 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5095 GtkWidgetPrivate *priv = widget->priv;
5097 /* widgets must be onscreen for accels to take effect */
5098 return gtk_widget_is_sensitive (widget) &&
5099 gtk_widget_is_drawable (widget) &&
5100 gdk_window_is_viewable (priv->window);
5104 * gtk_widget_can_activate_accel:
5105 * @widget: a #GtkWidget
5106 * @signal_id: the ID of a signal installed on @widget
5108 * Determines whether an accelerator that activates the signal
5109 * identified by @signal_id can currently be activated.
5110 * This is done by emitting the #GtkWidget::can-activate-accel
5111 * signal on @widget; if the signal isn't overridden by a
5112 * handler or in a derived widget, then the default check is
5113 * that the widget must be sensitive, and the widget and all
5114 * its ancestors mapped.
5116 * Return value: %TRUE if the accelerator can be activated.
5121 gtk_widget_can_activate_accel (GtkWidget *widget,
5124 gboolean can_activate = FALSE;
5125 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5126 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5127 return can_activate;
5136 closure_accel_activate (GClosure *closure,
5137 GValue *return_value,
5138 guint n_param_values,
5139 const GValue *param_values,
5140 gpointer invocation_hint,
5141 gpointer marshal_data)
5143 AccelClosure *aclosure = (AccelClosure*) closure;
5144 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5147 g_signal_emit (closure->data, aclosure->signal_id, 0);
5149 /* whether accelerator was handled */
5150 g_value_set_boolean (return_value, can_activate);
5154 closures_destroy (gpointer data)
5156 GSList *slist, *closures = data;
5158 for (slist = closures; slist; slist = slist->next)
5160 g_closure_invalidate (slist->data);
5161 g_closure_unref (slist->data);
5163 g_slist_free (closures);
5167 widget_new_accel_closure (GtkWidget *widget,
5170 AccelClosure *aclosure;
5171 GClosure *closure = NULL;
5172 GSList *slist, *closures;
5174 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5175 for (slist = closures; slist; slist = slist->next)
5176 if (!gtk_accel_group_from_accel_closure (slist->data))
5178 /* reuse this closure */
5179 closure = slist->data;
5184 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5185 closures = g_slist_prepend (closures, g_closure_ref (closure));
5186 g_closure_sink (closure);
5187 g_closure_set_marshal (closure, closure_accel_activate);
5189 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5191 aclosure = (AccelClosure*) closure;
5192 g_assert (closure->data == widget);
5193 g_assert (closure->marshal == closure_accel_activate);
5194 aclosure->signal_id = signal_id;
5200 * gtk_widget_add_accelerator
5201 * @widget: widget to install an accelerator on
5202 * @accel_signal: widget signal to emit on accelerator activation
5203 * @accel_group: accel group for this widget, added to its toplevel
5204 * @accel_key: GDK keyval of the accelerator
5205 * @accel_mods: modifier key combination of the accelerator
5206 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5208 * Installs an accelerator for this @widget in @accel_group that causes
5209 * @accel_signal to be emitted if the accelerator is activated.
5210 * The @accel_group needs to be added to the widget's toplevel via
5211 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5212 * Accelerators added through this function are not user changeable during
5213 * runtime. If you want to support accelerators that can be changed by the
5214 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5215 * gtk_menu_item_set_accel_path() instead.
5218 gtk_widget_add_accelerator (GtkWidget *widget,
5219 const gchar *accel_signal,
5220 GtkAccelGroup *accel_group,
5222 GdkModifierType accel_mods,
5223 GtkAccelFlags accel_flags)
5228 g_return_if_fail (GTK_IS_WIDGET (widget));
5229 g_return_if_fail (accel_signal != NULL);
5230 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5232 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5233 if (!query.signal_id ||
5234 !(query.signal_flags & G_SIGNAL_ACTION) ||
5235 query.return_type != G_TYPE_NONE ||
5238 /* hmm, should be elaborate enough */
5239 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5240 G_OBJECT_TYPE_NAME (widget), accel_signal);
5244 closure = widget_new_accel_closure (widget, query.signal_id);
5246 g_object_ref (widget);
5248 /* install the accelerator. since we don't map this onto an accel_path,
5249 * the accelerator will automatically be locked.
5251 gtk_accel_group_connect (accel_group,
5254 accel_flags | GTK_ACCEL_LOCKED,
5257 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5259 g_object_unref (widget);
5263 * gtk_widget_remove_accelerator:
5264 * @widget: widget to install an accelerator on
5265 * @accel_group: accel group for this widget
5266 * @accel_key: GDK keyval of the accelerator
5267 * @accel_mods: modifier key combination of the accelerator
5268 * @returns: whether an accelerator was installed and could be removed
5270 * Removes an accelerator from @widget, previously installed with
5271 * gtk_widget_add_accelerator().
5274 gtk_widget_remove_accelerator (GtkWidget *widget,
5275 GtkAccelGroup *accel_group,
5277 GdkModifierType accel_mods)
5279 GtkAccelGroupEntry *ag_entry;
5280 GList *slist, *clist;
5283 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5284 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5286 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5287 clist = gtk_widget_list_accel_closures (widget);
5288 for (slist = clist; slist; slist = slist->next)
5292 for (i = 0; i < n; i++)
5293 if (slist->data == (gpointer) ag_entry[i].closure)
5295 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5297 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5299 g_list_free (clist);
5304 g_list_free (clist);
5306 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5307 accel_key, accel_mods, accel_group,
5308 G_OBJECT_TYPE_NAME (widget), widget);
5314 * gtk_widget_list_accel_closures:
5315 * @widget: widget to list accelerator closures for
5317 * Lists the closures used by @widget for accelerator group connections
5318 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5319 * The closures can be used to monitor accelerator changes on @widget,
5320 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5321 * #GtkAccelGroup of a closure which can be found out with
5322 * gtk_accel_group_from_accel_closure().
5324 * Return value: (transfer container) (element-type GClosure):
5325 * a newly allocated #GList of closures
5328 gtk_widget_list_accel_closures (GtkWidget *widget)
5331 GList *clist = NULL;
5333 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5335 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5336 if (gtk_accel_group_from_accel_closure (slist->data))
5337 clist = g_list_prepend (clist, slist->data);
5343 GtkAccelGroup *accel_group;
5348 destroy_accel_path (gpointer data)
5350 AccelPath *apath = data;
5352 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5354 /* closures_destroy takes care of unrefing the closure */
5355 g_object_unref (apath->accel_group);
5357 g_slice_free (AccelPath, apath);
5362 * gtk_widget_set_accel_path:
5363 * @widget: a #GtkWidget
5364 * @accel_path: (allow-none): path used to look up the accelerator
5365 * @accel_group: (allow-none): a #GtkAccelGroup.
5367 * Given an accelerator group, @accel_group, and an accelerator path,
5368 * @accel_path, sets up an accelerator in @accel_group so whenever the
5369 * key binding that is defined for @accel_path is pressed, @widget
5370 * will be activated. This removes any accelerators (for any
5371 * accelerator group) installed by previous calls to
5372 * gtk_widget_set_accel_path(). Associating accelerators with
5373 * paths allows them to be modified by the user and the modifications
5374 * to be saved for future use. (See gtk_accel_map_save().)
5376 * This function is a low level function that would most likely
5377 * be used by a menu creation system like #GtkUIManager. If you
5378 * use #GtkUIManager, setting up accelerator paths will be done
5381 * Even when you you aren't using #GtkUIManager, if you only want to
5382 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5383 * provides a somewhat more convenient interface.
5385 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5386 * pass a static string, you can save some memory by interning it first with
5387 * g_intern_static_string().
5390 gtk_widget_set_accel_path (GtkWidget *widget,
5391 const gchar *accel_path,
5392 GtkAccelGroup *accel_group)
5396 g_return_if_fail (GTK_IS_WIDGET (widget));
5397 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5401 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5402 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5404 gtk_accel_map_add_entry (accel_path, 0, 0);
5405 apath = g_slice_new (AccelPath);
5406 apath->accel_group = g_object_ref (accel_group);
5407 apath->path_quark = g_quark_from_string (accel_path);
5408 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5413 /* also removes possible old settings */
5414 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5417 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5419 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5423 _gtk_widget_get_accel_path (GtkWidget *widget,
5428 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5430 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5432 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5433 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5437 * gtk_widget_mnemonic_activate:
5438 * @widget: a #GtkWidget
5439 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5441 * Emits the #GtkWidget::mnemonic-activate signal.
5443 * The default handler for this signal activates the @widget if
5444 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5447 * Returns: %TRUE if the signal has been handled
5450 gtk_widget_mnemonic_activate (GtkWidget *widget,
5451 gboolean group_cycling)
5455 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5457 group_cycling = group_cycling != FALSE;
5458 if (!gtk_widget_is_sensitive (widget))
5461 g_signal_emit (widget,
5462 widget_signals[MNEMONIC_ACTIVATE],
5470 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5471 gboolean group_cycling)
5473 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5474 gtk_widget_activate (widget);
5475 else if (gtk_widget_get_can_focus (widget))
5476 gtk_widget_grab_focus (widget);
5479 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5480 G_OBJECT_TYPE_NAME (widget));
5481 gtk_widget_error_bell (widget);
5486 static const cairo_user_data_key_t event_key;
5489 _gtk_cairo_get_event (cairo_t *cr)
5491 g_return_val_if_fail (cr != NULL, NULL);
5493 return cairo_get_user_data (cr, &event_key);
5497 gtk_cairo_set_event (cairo_t *cr,
5498 GdkEventExpose *event)
5500 cairo_set_user_data (cr, &event_key, event, NULL);
5504 * gtk_cairo_should_draw_window:
5505 * @cr: a cairo context
5506 * @window: the window to check
5508 * This function is supposed to be called in #GtkWidget::draw
5509 * implementations for widgets that support multiple windows.
5510 * @cr must be untransformed from invoking of the draw function.
5511 * This function will return %TRUE if the contents of the given
5512 * @window are supposed to be drawn and %FALSE otherwise. Note
5513 * that when the drawing was not initiated by the windowing
5514 * system this function will return %TRUE for all windows, so
5515 * you need to draw the bottommost window first. Also, do not
5516 * use "else if" statements to check which window should be drawn.
5518 * Returns: %TRUE if @window should be drawn
5521 gtk_cairo_should_draw_window (cairo_t *cr,
5524 GdkEventExpose *event;
5526 g_return_val_if_fail (cr != NULL, FALSE);
5527 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5529 event = _gtk_cairo_get_event (cr);
5531 return event == NULL ||
5532 event->window == window;
5535 /* code shared by gtk_container_propagate_draw() and
5539 _gtk_widget_draw_internal (GtkWidget *widget,
5541 gboolean clip_to_size)
5543 GtkStyleContext *context;
5545 if (!gtk_widget_is_drawable (widget))
5550 cairo_rectangle (cr,
5552 widget->priv->allocation.width,
5553 widget->priv->allocation.height);
5557 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5561 g_signal_emit (widget, widget_signals[DRAW],
5566 context = gtk_widget_get_style_context (widget);
5567 _gtk_style_context_coalesce_animation_areas (context, widget);
5572 * @widget: the widget to draw. It must be drawable (see
5573 * gtk_widget_is_drawable()) and a size must have been allocated.
5574 * @cr: a cairo context to draw to
5576 * Draws @widget to @cr. The top left corner of the widget will be
5577 * drawn to the currently set origin point of @cr.
5579 * You should pass a cairo context as @cr argument that is in an
5580 * original state. Otherwise the resulting drawing is undefined. For
5581 * example changing the operator using cairo_set_operator() or the
5582 * line width using cairo_set_line_width() might have unwanted side
5584 * You may however change the context's transform matrix - like with
5585 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5586 * region with cairo_clip() prior to calling this function. Also, it
5587 * is fine to modify the context with cairo_save() and
5588 * cairo_push_group() prior to calling this function.
5590 * <note><para>Special purpose widgets may contain special code for
5591 * rendering to the screen and might appear differently on screen
5592 * and when rendered using gtk_widget_draw().</para></note>
5595 gtk_widget_draw (GtkWidget *widget,
5598 GdkEventExpose *tmp_event;
5600 g_return_if_fail (GTK_IS_WIDGET (widget));
5601 g_return_if_fail (!widget->priv->alloc_needed);
5602 g_return_if_fail (cr != NULL);
5605 /* We have to reset the event here so that draw functions can call
5606 * gtk_widget_draw() on random other widgets and get the desired
5607 * effect: Drawing all contents, not just the current window.
5609 tmp_event = _gtk_cairo_get_event (cr);
5610 gtk_cairo_set_event (cr, NULL);
5612 _gtk_widget_draw_internal (widget, cr, TRUE);
5614 gtk_cairo_set_event (cr, tmp_event);
5619 gtk_widget_real_key_press_event (GtkWidget *widget,
5622 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5626 gtk_widget_real_key_release_event (GtkWidget *widget,
5629 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5633 gtk_widget_real_focus_in_event (GtkWidget *widget,
5634 GdkEventFocus *event)
5636 gtk_widget_queue_shallow_draw (widget);
5642 gtk_widget_real_focus_out_event (GtkWidget *widget,
5643 GdkEventFocus *event)
5645 gtk_widget_queue_shallow_draw (widget);
5650 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5651 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5655 * @widget: a #GtkWidget
5656 * @event: a #GdkEvent
5658 * Rarely-used function. This function is used to emit
5659 * the event signals on a widget (those signals should never
5660 * be emitted without using this function to do so).
5661 * If you want to synthesize an event though, don't use this function;
5662 * instead, use gtk_main_do_event() so the event will behave as if
5663 * it were in the event queue. Don't synthesize expose events; instead,
5664 * use gdk_window_invalidate_rect() to invalidate a region of the
5667 * Return value: return from the event signal emission (%TRUE if
5668 * the event was handled)
5671 gtk_widget_event (GtkWidget *widget,
5674 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5675 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5677 if (event->type == GDK_EXPOSE)
5679 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5680 "the same effect, call gdk_window_invalidate_rect/region(), "
5681 "followed by gdk_window_process_updates().");
5685 return gtk_widget_event_internal (widget, event);
5688 /* Returns TRUE if a translation should be done */
5690 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5695 GdkWindow *w, *widget_window;
5697 if (!gtk_widget_get_has_window (widget))
5699 *x = -widget->priv->allocation.x;
5700 *y = -widget->priv->allocation.y;
5708 widget_window = gtk_widget_get_window (widget);
5710 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5713 gdk_window_get_position (w, &wx, &wy);
5730 * gtk_cairo_transform_to_window:
5731 * @cr: the cairo context to transform
5732 * @widget: the widget the context is currently centered for
5733 * @window: the window to transform the context to
5735 * Transforms the given cairo context @cr that from @widget-relative
5736 * coordinates to @window-relative coordinates.
5737 * If the @widget's window is not an ancestor of @window, no
5738 * modification will be applied.
5740 * This is the inverse to the transformation GTK applies when
5741 * preparing an expose event to be emitted with the #GtkWidget::draw
5742 * signal. It is intended to help porting multiwindow widgets from
5743 * GTK+ 2 to the rendering architecture of GTK+ 3.
5746 gtk_cairo_transform_to_window (cairo_t *cr,
5752 g_return_if_fail (cr != NULL);
5753 g_return_if_fail (GTK_IS_WIDGET (widget));
5754 g_return_if_fail (GDK_IS_WINDOW (window));
5756 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5757 cairo_translate (cr, x, y);
5761 * gtk_widget_send_expose:
5762 * @widget: a #GtkWidget
5763 * @event: a expose #GdkEvent
5765 * Very rarely-used function. This function is used to emit
5766 * an expose event on a widget. This function is not normally used
5767 * directly. The only time it is used is when propagating an expose
5768 * event to a child %NO_WINDOW widget, and that is normally done
5769 * using gtk_container_propagate_draw().
5771 * If you want to force an area of a window to be redrawn,
5772 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5773 * To cause the redraw to be done immediately, follow that call
5774 * with a call to gdk_window_process_updates().
5776 * Return value: return from the event signal emission (%TRUE if
5777 * the event was handled)
5780 gtk_widget_send_expose (GtkWidget *widget,
5783 gboolean result = FALSE;
5788 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5789 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5790 g_return_val_if_fail (event != NULL, TRUE);
5791 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5793 cr = gdk_cairo_create (event->expose.window);
5794 gtk_cairo_set_event (cr, &event->expose);
5796 gdk_cairo_region (cr, event->expose.region);
5799 do_clip = _gtk_widget_get_translation_to_window (widget,
5800 event->expose.window,
5802 cairo_translate (cr, -x, -y);
5804 _gtk_widget_draw_internal (widget, cr, do_clip);
5806 /* unset here, so if someone keeps a reference to cr we
5807 * don't leak the window. */
5808 gtk_cairo_set_event (cr, NULL);
5815 event_window_is_still_viewable (GdkEvent *event)
5817 /* Check that we think the event's window is viewable before
5818 * delivering the event, to prevent suprises. We do this here
5819 * at the last moment, since the event may have been queued
5820 * up behind other events, held over a recursive main loop, etc.
5822 switch (event->type)
5825 case GDK_MOTION_NOTIFY:
5826 case GDK_BUTTON_PRESS:
5827 case GDK_2BUTTON_PRESS:
5828 case GDK_3BUTTON_PRESS:
5830 case GDK_ENTER_NOTIFY:
5831 case GDK_PROXIMITY_IN:
5833 return event->any.window && gdk_window_is_viewable (event->any.window);
5836 /* The following events are the second half of paired events;
5837 * we always deliver them to deal with widgets that clean up
5838 * on the second half.
5840 case GDK_BUTTON_RELEASE:
5841 case GDK_KEY_RELEASE:
5842 case GDK_LEAVE_NOTIFY:
5843 case GDK_PROXIMITY_OUT:
5847 /* Remaining events would make sense on an not-viewable window,
5848 * or don't have an associated window.
5855 gtk_widget_event_internal (GtkWidget *widget,
5858 gboolean return_val = FALSE;
5860 /* We check only once for is-still-visible; if someone
5861 * hides the window in on of the signals on the widget,
5862 * they are responsible for returning TRUE to terminate
5865 if (!event_window_is_still_viewable (event))
5868 g_object_ref (widget);
5870 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5871 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5876 switch (event->type)
5881 case GDK_BUTTON_PRESS:
5882 case GDK_2BUTTON_PRESS:
5883 case GDK_3BUTTON_PRESS:
5884 signal_num = BUTTON_PRESS_EVENT;
5887 signal_num = SCROLL_EVENT;
5889 case GDK_BUTTON_RELEASE:
5890 signal_num = BUTTON_RELEASE_EVENT;
5892 case GDK_MOTION_NOTIFY:
5893 signal_num = MOTION_NOTIFY_EVENT;
5896 signal_num = DELETE_EVENT;
5899 signal_num = DESTROY_EVENT;
5900 _gtk_tooltip_hide (widget);
5903 signal_num = KEY_PRESS_EVENT;
5905 case GDK_KEY_RELEASE:
5906 signal_num = KEY_RELEASE_EVENT;
5908 case GDK_ENTER_NOTIFY:
5909 signal_num = ENTER_NOTIFY_EVENT;
5911 case GDK_LEAVE_NOTIFY:
5912 signal_num = LEAVE_NOTIFY_EVENT;
5914 case GDK_FOCUS_CHANGE:
5915 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5916 if (event->focus_change.in)
5917 _gtk_tooltip_focus_in (widget);
5919 _gtk_tooltip_focus_out (widget);
5922 signal_num = CONFIGURE_EVENT;
5925 signal_num = MAP_EVENT;
5928 signal_num = UNMAP_EVENT;
5930 case GDK_WINDOW_STATE:
5931 signal_num = WINDOW_STATE_EVENT;
5933 case GDK_PROPERTY_NOTIFY:
5934 signal_num = PROPERTY_NOTIFY_EVENT;
5936 case GDK_SELECTION_CLEAR:
5937 signal_num = SELECTION_CLEAR_EVENT;
5939 case GDK_SELECTION_REQUEST:
5940 signal_num = SELECTION_REQUEST_EVENT;
5942 case GDK_SELECTION_NOTIFY:
5943 signal_num = SELECTION_NOTIFY_EVENT;
5945 case GDK_PROXIMITY_IN:
5946 signal_num = PROXIMITY_IN_EVENT;
5948 case GDK_PROXIMITY_OUT:
5949 signal_num = PROXIMITY_OUT_EVENT;
5951 case GDK_CLIENT_EVENT:
5952 signal_num = CLIENT_EVENT;
5955 signal_num = EXPOSE_EVENT;
5957 case GDK_VISIBILITY_NOTIFY:
5958 signal_num = VISIBILITY_NOTIFY_EVENT;
5960 case GDK_GRAB_BROKEN:
5961 signal_num = GRAB_BROKEN_EVENT;
5964 signal_num = DAMAGE_EVENT;
5967 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5971 if (signal_num != -1)
5972 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5974 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5975 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5979 g_object_unref (widget);
5985 * gtk_widget_activate:
5986 * @widget: a #GtkWidget that's activatable
5988 * For widgets that can be "activated" (buttons, menu items, etc.)
5989 * this function activates them. Activation is what happens when you
5990 * press Enter on a widget during key navigation. If @widget isn't
5991 * activatable, the function returns %FALSE.
5993 * Return value: %TRUE if the widget was activatable
5996 gtk_widget_activate (GtkWidget *widget)
5998 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6000 if (WIDGET_CLASS (widget)->activate_signal)
6002 /* FIXME: we should eventually check the signals signature here */
6003 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6012 gtk_widget_reparent_subwindows (GtkWidget *widget,
6013 GdkWindow *new_window)
6015 GtkWidgetPrivate *priv = widget->priv;
6017 if (!gtk_widget_get_has_window (widget))
6019 GList *children = gdk_window_get_children (priv->window);
6022 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6024 GdkWindow *window = tmp_list->data;
6027 gdk_window_get_user_data (window, &child);
6028 while (child && child != widget)
6029 child = ((GtkWidget*) child)->priv->parent;
6032 gdk_window_reparent (window, new_window, 0, 0);
6035 g_list_free (children);
6040 GList *tmp_list, *children;
6042 parent = gdk_window_get_parent (priv->window);
6045 gdk_window_reparent (priv->window, new_window, 0, 0);
6048 children = gdk_window_get_children (parent);
6050 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6052 GdkWindow *window = tmp_list->data;
6055 gdk_window_get_user_data (window, &child);
6057 if (child == widget)
6058 gdk_window_reparent (window, new_window, 0, 0);
6061 g_list_free (children);
6067 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6068 gpointer client_data)
6070 GtkWidgetPrivate *priv = widget->priv;
6072 g_assert (client_data != NULL);
6074 if (!gtk_widget_get_has_window (widget))
6077 g_object_unref (priv->window);
6078 priv->window = (GdkWindow*) client_data;
6080 g_object_ref (priv->window);
6082 if (GTK_IS_CONTAINER (widget))
6083 gtk_container_forall (GTK_CONTAINER (widget),
6084 gtk_widget_reparent_fixup_child,
6090 * gtk_widget_reparent:
6091 * @widget: a #GtkWidget
6092 * @new_parent: a #GtkContainer to move the widget into
6094 * Moves a widget from one #GtkContainer to another, handling reference
6095 * count issues to avoid destroying the widget.
6098 gtk_widget_reparent (GtkWidget *widget,
6099 GtkWidget *new_parent)
6101 GtkWidgetPrivate *priv;
6103 g_return_if_fail (GTK_IS_WIDGET (widget));
6104 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6105 priv = widget->priv;
6106 g_return_if_fail (priv->parent != NULL);
6108 if (priv->parent != new_parent)
6110 /* First try to see if we can get away without unrealizing
6111 * the widget as we reparent it. if so we set a flag so
6112 * that gtk_widget_unparent doesn't unrealize widget
6114 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6115 priv->in_reparent = TRUE;
6117 g_object_ref (widget);
6118 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6119 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6120 g_object_unref (widget);
6122 if (priv->in_reparent)
6124 priv->in_reparent = FALSE;
6126 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6127 gtk_widget_reparent_fixup_child (widget,
6128 gtk_widget_get_parent_window (widget));
6131 g_object_notify (G_OBJECT (widget), "parent");
6136 * gtk_widget_intersect:
6137 * @widget: a #GtkWidget
6138 * @area: a rectangle
6139 * @intersection: rectangle to store intersection of @widget and @area
6141 * Computes the intersection of a @widget's area and @area, storing
6142 * the intersection in @intersection, and returns %TRUE if there was
6143 * an intersection. @intersection may be %NULL if you're only
6144 * interested in whether there was an intersection.
6146 * Return value: %TRUE if there was an intersection
6149 gtk_widget_intersect (GtkWidget *widget,
6150 const GdkRectangle *area,
6151 GdkRectangle *intersection)
6153 GtkWidgetPrivate *priv;
6158 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6159 g_return_val_if_fail (area != NULL, FALSE);
6161 priv = widget->priv;
6164 dest = intersection;
6168 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6170 if (return_val && intersection && gtk_widget_get_has_window (widget))
6172 intersection->x -= priv->allocation.x;
6173 intersection->y -= priv->allocation.y;
6180 * gtk_widget_region_intersect:
6181 * @widget: a #GtkWidget
6182 * @region: a #cairo_region_t, in the same coordinate system as
6183 * @widget->allocation. That is, relative to @widget->window
6184 * for %NO_WINDOW widgets; relative to the parent window
6185 * of @widget->window for widgets with their own window.
6186 * @returns: A newly allocated region holding the intersection of @widget
6187 * and @region. The coordinates of the return value are
6188 * relative to @widget->window for %NO_WINDOW widgets, and
6189 * relative to the parent window of @widget->window for
6190 * widgets with their own window.
6192 * Computes the intersection of a @widget's area and @region, returning
6193 * the intersection. The result may be empty, use cairo_region_is_empty() to
6197 gtk_widget_region_intersect (GtkWidget *widget,
6198 const cairo_region_t *region)
6201 cairo_region_t *dest;
6203 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6204 g_return_val_if_fail (region != NULL, NULL);
6206 gtk_widget_get_allocation (widget, &rect);
6208 dest = cairo_region_create_rectangle (&rect);
6210 cairo_region_intersect (dest, region);
6216 * _gtk_widget_grab_notify:
6217 * @widget: a #GtkWidget
6218 * @was_grabbed: whether a grab is now in effect
6220 * Emits the #GtkWidget::grab-notify signal on @widget.
6225 _gtk_widget_grab_notify (GtkWidget *widget,
6226 gboolean was_grabbed)
6228 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6232 * gtk_widget_grab_focus:
6233 * @widget: a #GtkWidget
6235 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6236 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6237 * something like #GtkFrame won't work.
6239 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6240 * gtk_widget_set_can_focus() to modify that flag.
6242 * The widget also needs to be realized and mapped. This is indicated by the
6243 * related signals. Grabbing the focus immediately after creating the widget
6244 * will likely fail and cause critical warnings.
6247 gtk_widget_grab_focus (GtkWidget *widget)
6249 g_return_if_fail (GTK_IS_WIDGET (widget));
6251 if (!gtk_widget_is_sensitive (widget))
6254 g_object_ref (widget);
6255 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6256 g_object_notify (G_OBJECT (widget), "has-focus");
6257 g_object_unref (widget);
6261 reset_focus_recurse (GtkWidget *widget,
6264 if (GTK_IS_CONTAINER (widget))
6266 GtkContainer *container;
6268 container = GTK_CONTAINER (widget);
6269 gtk_container_set_focus_child (container, NULL);
6271 gtk_container_foreach (container,
6272 reset_focus_recurse,
6278 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6280 if (gtk_widget_get_can_focus (focus_widget))
6282 GtkWidget *toplevel;
6285 /* clear the current focus setting, break if the current widget
6286 * is the focus widget's parent, since containers above that will
6287 * be set by the next loop.
6289 toplevel = gtk_widget_get_toplevel (focus_widget);
6290 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6292 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6294 if (widget == focus_widget)
6296 /* We call _gtk_window_internal_set_focus() here so that the
6297 * toplevel window can request the focus if necessary.
6298 * This is needed when the toplevel is a GtkPlug
6300 if (!gtk_widget_has_focus (widget))
6301 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6308 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6310 widget = widget->priv->parent;
6311 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6315 else if (toplevel != focus_widget)
6317 /* gtk_widget_grab_focus() operates on a tree without window...
6318 * actually, this is very questionable behaviour.
6321 gtk_container_foreach (GTK_CONTAINER (toplevel),
6322 reset_focus_recurse,
6326 /* now propagate the new focus up the widget tree and finally
6327 * set it on the window
6329 widget = focus_widget;
6330 while (widget->priv->parent)
6332 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6333 widget = widget->priv->parent;
6335 if (GTK_IS_WINDOW (widget))
6336 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6341 gtk_widget_real_query_tooltip (GtkWidget *widget,
6344 gboolean keyboard_tip,
6345 GtkTooltip *tooltip)
6347 gchar *tooltip_markup;
6348 gboolean has_tooltip;
6350 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6351 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6353 if (has_tooltip && tooltip_markup)
6355 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6363 gtk_widget_real_style_updated (GtkWidget *widget)
6365 if (widget->priv->context)
6366 gtk_style_context_invalidate (widget->priv->context);
6367 gtk_widget_queue_resize (widget);
6371 gtk_widget_real_show_help (GtkWidget *widget,
6372 GtkWidgetHelpType help_type)
6374 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6376 _gtk_tooltip_toggle_keyboard_mode (widget);
6385 gtk_widget_real_focus (GtkWidget *widget,
6386 GtkDirectionType direction)
6388 if (!gtk_widget_get_can_focus (widget))
6391 if (!gtk_widget_is_focus (widget))
6393 gtk_widget_grab_focus (widget);
6401 gtk_widget_real_move_focus (GtkWidget *widget,
6402 GtkDirectionType direction)
6404 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6406 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6408 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6414 gtk_widget_real_keynav_failed (GtkWidget *widget,
6415 GtkDirectionType direction)
6417 gboolean cursor_only;
6421 case GTK_DIR_TAB_FORWARD:
6422 case GTK_DIR_TAB_BACKWARD:
6429 g_object_get (gtk_widget_get_settings (widget),
6430 "gtk-keynav-cursor-only", &cursor_only,
6437 gtk_widget_error_bell (widget);
6443 * gtk_widget_set_can_focus:
6444 * @widget: a #GtkWidget
6445 * @can_focus: whether or not @widget can own the input focus.
6447 * Specifies whether @widget can own the input focus. See
6448 * gtk_widget_grab_focus() for actually setting the input focus on a
6454 gtk_widget_set_can_focus (GtkWidget *widget,
6457 g_return_if_fail (GTK_IS_WIDGET (widget));
6459 if (widget->priv->can_focus != can_focus)
6461 widget->priv->can_focus = can_focus;
6463 gtk_widget_queue_resize (widget);
6464 g_object_notify (G_OBJECT (widget), "can-focus");
6469 * gtk_widget_get_can_focus:
6470 * @widget: a #GtkWidget
6472 * Determines whether @widget can own the input focus. See
6473 * gtk_widget_set_can_focus().
6475 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6480 gtk_widget_get_can_focus (GtkWidget *widget)
6482 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6484 return widget->priv->can_focus;
6488 * gtk_widget_has_focus:
6489 * @widget: a #GtkWidget
6491 * Determines if the widget has the global input focus. See
6492 * gtk_widget_is_focus() for the difference between having the global
6493 * input focus, and only having the focus within a toplevel.
6495 * Return value: %TRUE if the widget has the global input focus.
6500 gtk_widget_has_focus (GtkWidget *widget)
6502 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6504 return widget->priv->has_focus;
6508 * gtk_widget_is_focus:
6509 * @widget: a #GtkWidget
6511 * Determines if the widget is the focus widget within its
6512 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6513 * necessarily set; %HAS_FOCUS will only be set if the
6514 * toplevel widget additionally has the global input focus.)
6516 * Return value: %TRUE if the widget is the focus widget.
6519 gtk_widget_is_focus (GtkWidget *widget)
6521 GtkWidget *toplevel;
6523 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6525 toplevel = gtk_widget_get_toplevel (widget);
6527 if (GTK_IS_WINDOW (toplevel))
6528 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6534 * gtk_widget_set_can_default:
6535 * @widget: a #GtkWidget
6536 * @can_default: whether or not @widget can be a default widget.
6538 * Specifies whether @widget can be a default widget. See
6539 * gtk_widget_grab_default() for details about the meaning of
6545 gtk_widget_set_can_default (GtkWidget *widget,
6546 gboolean can_default)
6548 g_return_if_fail (GTK_IS_WIDGET (widget));
6550 if (widget->priv->can_default != can_default)
6552 widget->priv->can_default = can_default;
6554 gtk_widget_queue_resize (widget);
6555 g_object_notify (G_OBJECT (widget), "can-default");
6560 * gtk_widget_get_can_default:
6561 * @widget: a #GtkWidget
6563 * Determines whether @widget can be a default widget. See
6564 * gtk_widget_set_can_default().
6566 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6571 gtk_widget_get_can_default (GtkWidget *widget)
6573 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6575 return widget->priv->can_default;
6579 * gtk_widget_has_default:
6580 * @widget: a #GtkWidget
6582 * Determines whether @widget is the current default widget within its
6583 * toplevel. See gtk_widget_set_can_default().
6585 * Return value: %TRUE if @widget is the current default widget within
6586 * its toplevel, %FALSE otherwise
6591 gtk_widget_has_default (GtkWidget *widget)
6593 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6595 return widget->priv->has_default;
6599 _gtk_widget_set_has_default (GtkWidget *widget,
6600 gboolean has_default)
6602 widget->priv->has_default = has_default;
6606 * gtk_widget_grab_default:
6607 * @widget: a #GtkWidget
6609 * Causes @widget to become the default widget. @widget must have the
6610 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6611 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6612 * %TRUE)</literal>. The default widget is activated when
6613 * the user presses Enter in a window. Default widgets must be
6614 * activatable, that is, gtk_widget_activate() should affect them. Note
6615 * that #GtkEntry widgets require the "activates-default" property
6616 * set to %TRUE before they activate the default widget when Enter
6617 * is pressed and the #GtkEntry is focused.
6620 gtk_widget_grab_default (GtkWidget *widget)
6624 g_return_if_fail (GTK_IS_WIDGET (widget));
6625 g_return_if_fail (gtk_widget_get_can_default (widget));
6627 window = gtk_widget_get_toplevel (widget);
6629 if (window && gtk_widget_is_toplevel (window))
6630 gtk_window_set_default (GTK_WINDOW (window), widget);
6632 g_warning (G_STRLOC ": widget not within a GtkWindow");
6636 * gtk_widget_set_receives_default:
6637 * @widget: a #GtkWidget
6638 * @receives_default: whether or not @widget can be a default widget.
6640 * Specifies whether @widget will be treated as the default widget
6641 * within its toplevel when it has the focus, even if another widget
6644 * See gtk_widget_grab_default() for details about the meaning of
6650 gtk_widget_set_receives_default (GtkWidget *widget,
6651 gboolean receives_default)
6653 g_return_if_fail (GTK_IS_WIDGET (widget));
6655 if (widget->priv->receives_default != receives_default)
6657 widget->priv->receives_default = receives_default;
6659 g_object_notify (G_OBJECT (widget), "receives-default");
6664 * gtk_widget_get_receives_default:
6665 * @widget: a #GtkWidget
6667 * Determines whether @widget is alyways treated as default widget
6668 * withing its toplevel when it has the focus, even if another widget
6671 * See gtk_widget_set_receives_default().
6673 * Return value: %TRUE if @widget acts as default widget when focussed,
6679 gtk_widget_get_receives_default (GtkWidget *widget)
6681 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6683 return widget->priv->receives_default;
6687 * gtk_widget_has_grab:
6688 * @widget: a #GtkWidget
6690 * Determines whether the widget is currently grabbing events, so it
6691 * is the only widget receiving input events (keyboard and mouse).
6693 * See also gtk_grab_add().
6695 * Return value: %TRUE if the widget is in the grab_widgets stack
6700 gtk_widget_has_grab (GtkWidget *widget)
6702 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6704 return widget->priv->has_grab;
6708 _gtk_widget_set_has_grab (GtkWidget *widget,
6711 widget->priv->has_grab = has_grab;
6715 * gtk_widget_device_is_shadowed:
6716 * @widget: a #GtkWidget
6717 * @device: a #GdkDevice
6719 * Returns %TRUE if @device has been shadowed by a GTK+
6720 * device grab on another widget, so it would stop sending
6721 * events to @widget. This may be used in the
6722 * #GtkWidget::grab-notify signal to check for specific
6723 * devices. See gtk_device_grab_add().
6725 * Returns: %TRUE if there is an ongoing grab on @device
6726 * by another #GtkWidget than @widget.
6731 gtk_widget_device_is_shadowed (GtkWidget *widget,
6734 GtkWindowGroup *group;
6735 GtkWidget *grab_widget, *toplevel;
6737 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6738 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6740 if (!gtk_widget_get_realized (widget))
6743 toplevel = gtk_widget_get_toplevel (widget);
6745 if (GTK_IS_WINDOW (toplevel))
6746 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6748 group = gtk_window_get_group (NULL);
6750 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6752 /* Widget not inside the hierarchy of grab_widget */
6754 widget != grab_widget &&
6755 !gtk_widget_is_ancestor (widget, grab_widget))
6758 grab_widget = gtk_window_group_get_current_grab (group);
6759 if (grab_widget && widget != grab_widget &&
6760 !gtk_widget_is_ancestor (widget, grab_widget))
6767 * gtk_widget_set_name:
6768 * @widget: a #GtkWidget
6769 * @name: name for the widget
6771 * Widgets can be named, which allows you to refer to them from a
6772 * gtkrc file. You can apply a style to widgets with a particular name
6773 * in the gtkrc file. See the documentation for gtkrc files (on the
6774 * same page as the docs for #GtkRcStyle).
6776 * Note that widget names are separated by periods in paths (see
6777 * gtk_widget_path()), so names with embedded periods may cause confusion.
6780 gtk_widget_set_name (GtkWidget *widget,
6783 GtkWidgetPrivate *priv;
6786 g_return_if_fail (GTK_IS_WIDGET (widget));
6788 priv = widget->priv;
6790 new_name = g_strdup (name);
6791 g_free (priv->name);
6792 priv->name = new_name;
6798 pos = gtk_widget_path_length (priv->path) - 1;
6799 gtk_widget_path_iter_set_name (priv->path, pos,
6804 gtk_style_context_set_path (priv->context, priv->path);
6807 gtk_widget_reset_rc_style (widget);
6809 g_object_notify (G_OBJECT (widget), "name");
6813 * gtk_widget_get_name:
6814 * @widget: a #GtkWidget
6816 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6817 * significance of widget names.
6819 * Return value: name of the widget. This string is owned by GTK+ and
6820 * should not be modified or freed
6822 G_CONST_RETURN gchar*
6823 gtk_widget_get_name (GtkWidget *widget)
6825 GtkWidgetPrivate *priv;
6827 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6829 priv = widget->priv;
6833 return G_OBJECT_TYPE_NAME (widget);
6837 _gtk_widget_update_state_flags (GtkWidget *widget,
6838 GtkStateFlags flags,
6841 GtkWidgetPrivate *priv;
6843 priv = widget->priv;
6845 /* Handle insensitive first, since it is propagated
6846 * differently throughout the widget hierarchy.
6848 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6849 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6850 gtk_widget_set_sensitive (widget,
6851 operation != STATE_CHANGE_UNSET);
6853 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6856 operation == STATE_CHANGE_REPLACE)
6861 data.operation = operation;
6862 data.use_forall = FALSE;
6865 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6867 data.parent_sensitive = TRUE;
6869 gtk_widget_propagate_state (widget, &data);
6871 if (gtk_widget_is_drawable (widget))
6872 gtk_widget_queue_draw (widget);
6877 * gtk_widget_set_state_flags:
6878 * @widget: a #GtkWidget
6879 * @flags: State flags to turn on
6880 * @clear: Whether to clear state before turning on @flags
6882 * This function is for use in widget implementations. Turns on flag
6883 * values in the current widget state (insensitive, prelighted, etc.).
6885 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6886 * will be propagated down to all non-internal children if @widget is a
6887 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6888 * down to all #GtkContainer children by different means than turning on the
6889 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6890 * gtk_widget_is_sensitive() will make use of these.
6895 gtk_widget_set_state_flags (GtkWidget *widget,
6896 GtkStateFlags flags,
6899 g_return_if_fail (GTK_IS_WIDGET (widget));
6901 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6902 (clear && widget->priv->state_flags == flags))
6906 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6908 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6912 * gtk_widget_unset_state_flags:
6913 * @widget: a #GtkWidget
6914 * @flags: State flags to turn off
6916 * This function is for use in widget implementations. Turns off flag
6917 * values for the current widget state (insensitive, prelighted, etc.).
6918 * See gtk_widget_set_state_flags().
6923 gtk_widget_unset_state_flags (GtkWidget *widget,
6924 GtkStateFlags flags)
6926 g_return_if_fail (GTK_IS_WIDGET (widget));
6928 if ((widget->priv->state_flags & flags) == 0)
6931 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6935 * gtk_widget_get_state_flags:
6936 * @widget: a #GtkWidget
6938 * Returns the widget state as a flag set. It is worth mentioning
6939 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6940 * returned, that is, also based on parent insensitivity, even if
6941 * @widget itself is sensitive.
6943 * Returns: The state flags for widget
6948 gtk_widget_get_state_flags (GtkWidget *widget)
6950 GtkStateFlags flags;
6952 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6954 flags = widget->priv->state_flags;
6956 if (!gtk_widget_is_sensitive (widget))
6957 flags |= GTK_STATE_FLAG_INSENSITIVE;
6963 * gtk_widget_set_state:
6964 * @widget: a #GtkWidget
6965 * @state: new state for @widget
6967 * This function is for use in widget implementations. Sets the state
6968 * of a widget (insensitive, prelighted, etc.) Usually you should set
6969 * the state using wrapper functions such as gtk_widget_set_sensitive().
6971 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6974 gtk_widget_set_state (GtkWidget *widget,
6977 GtkStateFlags flags;
6979 if (state == gtk_widget_get_state (widget))
6984 case GTK_STATE_ACTIVE:
6985 flags = GTK_STATE_FLAG_ACTIVE;
6987 case GTK_STATE_PRELIGHT:
6988 flags = GTK_STATE_FLAG_PRELIGHT;
6990 case GTK_STATE_SELECTED:
6991 flags = GTK_STATE_FLAG_SELECTED;
6993 case GTK_STATE_INSENSITIVE:
6994 flags = GTK_STATE_FLAG_INSENSITIVE;
6996 case GTK_STATE_INCONSISTENT:
6997 flags = GTK_STATE_FLAG_INCONSISTENT;
6999 case GTK_STATE_FOCUSED:
7000 flags = GTK_STATE_FLAG_FOCUSED;
7002 case GTK_STATE_NORMAL:
7008 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7012 * gtk_widget_get_state:
7013 * @widget: a #GtkWidget
7015 * Returns the widget's state. See gtk_widget_set_state().
7017 * Returns: the state of @widget.
7021 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7024 gtk_widget_get_state (GtkWidget *widget)
7026 GtkStateFlags flags;
7028 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7030 flags = gtk_widget_get_state_flags (widget);
7032 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7033 return GTK_STATE_INSENSITIVE;
7034 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
7035 return GTK_STATE_INCONSISTENT;
7036 else if (flags & GTK_STATE_FLAG_ACTIVE)
7037 return GTK_STATE_ACTIVE;
7038 else if (flags & GTK_STATE_FLAG_SELECTED)
7039 return GTK_STATE_SELECTED;
7040 else if (flags & GTK_STATE_FLAG_FOCUSED)
7041 return GTK_STATE_FOCUSED;
7042 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7043 return GTK_STATE_PRELIGHT;
7045 return GTK_STATE_NORMAL;
7049 * gtk_widget_set_visible:
7050 * @widget: a #GtkWidget
7051 * @visible: whether the widget should be shown or not
7053 * Sets the visibility state of @widget. Note that setting this to
7054 * %TRUE doesn't mean the widget is actually viewable, see
7055 * gtk_widget_get_visible().
7057 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7058 * but is nicer to use when the visibility of the widget depends on
7064 gtk_widget_set_visible (GtkWidget *widget,
7067 g_return_if_fail (GTK_IS_WIDGET (widget));
7069 if (visible != gtk_widget_get_visible (widget))
7072 gtk_widget_show (widget);
7074 gtk_widget_hide (widget);
7079 _gtk_widget_set_visible_flag (GtkWidget *widget,
7082 widget->priv->visible = visible;
7086 * gtk_widget_get_visible:
7087 * @widget: a #GtkWidget
7089 * Determines whether the widget is visible. Note that this doesn't
7090 * take into account whether the widget's parent is also visible
7091 * or the widget is obscured in any way.
7093 * See gtk_widget_set_visible().
7095 * Return value: %TRUE if the widget is visible
7100 gtk_widget_get_visible (GtkWidget *widget)
7102 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7104 return widget->priv->visible;
7108 * gtk_widget_set_has_window:
7109 * @widget: a #GtkWidget
7110 * @has_window: whether or not @widget has a window.
7112 * Specifies whether @widget has a #GdkWindow of its own. Note that
7113 * all realized widgets have a non-%NULL "window" pointer
7114 * (gtk_widget_get_window() never returns a %NULL window when a widget
7115 * is realized), but for many of them it's actually the #GdkWindow of
7116 * one of its parent widgets. Widgets that do not create a %window for
7117 * themselves in #GtkWidget::realize must announce this by
7118 * calling this function with @has_window = %FALSE.
7120 * This function should only be called by widget implementations,
7121 * and they should call it in their init() function.
7126 gtk_widget_set_has_window (GtkWidget *widget,
7127 gboolean has_window)
7129 g_return_if_fail (GTK_IS_WIDGET (widget));
7131 widget->priv->no_window = !has_window;
7135 * gtk_widget_get_has_window:
7136 * @widget: a #GtkWidget
7138 * Determines whether @widget has a #GdkWindow of its own. See
7139 * gtk_widget_set_has_window().
7141 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7146 gtk_widget_get_has_window (GtkWidget *widget)
7148 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7150 return ! widget->priv->no_window;
7154 * gtk_widget_is_toplevel:
7155 * @widget: a #GtkWidget
7157 * Determines whether @widget is a toplevel widget. Currently only
7158 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7159 * widgets have no parent widget.
7161 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7166 gtk_widget_is_toplevel (GtkWidget *widget)
7168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7170 return widget->priv->toplevel;
7174 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7175 gboolean is_toplevel)
7177 widget->priv->toplevel = is_toplevel;
7181 * gtk_widget_is_drawable:
7182 * @widget: a #GtkWidget
7184 * Determines whether @widget can be drawn to. A widget can be drawn
7185 * to if it is mapped and visible.
7187 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7192 gtk_widget_is_drawable (GtkWidget *widget)
7194 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7196 return (gtk_widget_get_visible (widget) &&
7197 gtk_widget_get_mapped (widget));
7201 * gtk_widget_get_realized:
7202 * @widget: a #GtkWidget
7204 * Determines whether @widget is realized.
7206 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7211 gtk_widget_get_realized (GtkWidget *widget)
7213 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7215 return widget->priv->realized;
7219 * gtk_widget_set_realized:
7220 * @widget: a #GtkWidget
7221 * @realized: %TRUE to mark the widget as realized
7223 * Marks the widget as being realized.
7225 * This function should only ever be called in a derived widget's
7226 * "realize" or "unrealize" implementation.
7231 gtk_widget_set_realized (GtkWidget *widget,
7234 g_return_if_fail (GTK_IS_WIDGET (widget));
7236 widget->priv->realized = realized;
7240 * gtk_widget_get_mapped:
7241 * @widget: a #GtkWidget
7243 * Whether the widget is mapped.
7245 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7250 gtk_widget_get_mapped (GtkWidget *widget)
7252 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7254 return widget->priv->mapped;
7258 * gtk_widget_set_mapped:
7259 * @widget: a #GtkWidget
7260 * @mapped: %TRUE to mark the widget as mapped
7262 * Marks the widget as being realized.
7264 * This function should only ever be called in a derived widget's
7265 * "map" or "unmap" implementation.
7270 gtk_widget_set_mapped (GtkWidget *widget,
7273 g_return_if_fail (GTK_IS_WIDGET (widget));
7275 widget->priv->mapped = mapped;
7279 * gtk_widget_set_app_paintable:
7280 * @widget: a #GtkWidget
7281 * @app_paintable: %TRUE if the application will paint on the widget
7283 * Sets whether the application intends to draw on the widget in
7284 * an #GtkWidget::draw handler.
7286 * This is a hint to the widget and does not affect the behavior of
7287 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7288 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7289 * the effect is to suppress default themed drawing of the widget's
7290 * background. (Children of the widget will still be drawn.) The application
7291 * is then entirely responsible for drawing the widget background.
7293 * Note that the background is still drawn when the widget is mapped.
7296 gtk_widget_set_app_paintable (GtkWidget *widget,
7297 gboolean app_paintable)
7299 g_return_if_fail (GTK_IS_WIDGET (widget));
7301 app_paintable = (app_paintable != FALSE);
7303 if (widget->priv->app_paintable != app_paintable)
7305 widget->priv->app_paintable = app_paintable;
7307 if (gtk_widget_is_drawable (widget))
7308 gtk_widget_queue_draw (widget);
7310 g_object_notify (G_OBJECT (widget), "app-paintable");
7315 * gtk_widget_get_app_paintable:
7316 * @widget: a #GtkWidget
7318 * Determines whether the application intends to draw on the widget in
7319 * an #GtkWidget::draw handler.
7321 * See gtk_widget_set_app_paintable()
7323 * Return value: %TRUE if the widget is app paintable
7328 gtk_widget_get_app_paintable (GtkWidget *widget)
7330 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7332 return widget->priv->app_paintable;
7336 * gtk_widget_set_double_buffered:
7337 * @widget: a #GtkWidget
7338 * @double_buffered: %TRUE to double-buffer a widget
7340 * Widgets are double buffered by default; you can use this function
7341 * to turn off the buffering. "Double buffered" simply means that
7342 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7343 * automatically around expose events sent to the
7344 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7345 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7346 * buffer to the screen. The result is that users see the window
7347 * update in one smooth step, and don't see individual graphics
7348 * primitives being rendered.
7350 * In very simple terms, double buffered widgets don't flicker,
7351 * so you would only use this function to turn off double buffering
7352 * if you had special needs and really knew what you were doing.
7354 * Note: if you turn off double-buffering, you have to handle
7355 * expose events, since even the clearing to the background color or
7356 * pixmap will not happen automatically (as it is done in
7357 * gdk_window_begin_paint()).
7360 gtk_widget_set_double_buffered (GtkWidget *widget,
7361 gboolean double_buffered)
7363 g_return_if_fail (GTK_IS_WIDGET (widget));
7365 double_buffered = (double_buffered != FALSE);
7367 if (widget->priv->double_buffered != double_buffered)
7369 widget->priv->double_buffered = double_buffered;
7371 g_object_notify (G_OBJECT (widget), "double-buffered");
7376 * gtk_widget_get_double_buffered:
7377 * @widget: a #GtkWidget
7379 * Determines whether the widget is double buffered.
7381 * See gtk_widget_set_double_buffered()
7383 * Return value: %TRUE if the widget is double buffered
7388 gtk_widget_get_double_buffered (GtkWidget *widget)
7390 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7392 return widget->priv->double_buffered;
7396 * gtk_widget_set_redraw_on_allocate:
7397 * @widget: a #GtkWidget
7398 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7399 * when it is allocated to a new size. Otherwise, only the
7400 * new portion of the widget will be redrawn.
7402 * Sets whether the entire widget is queued for drawing when its size
7403 * allocation changes. By default, this setting is %TRUE and
7404 * the entire widget is redrawn on every size change. If your widget
7405 * leaves the upper left unchanged when made bigger, turning this
7406 * setting off will improve performance.
7408 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7409 * off all allocation on resizing: the widget will not even redraw if
7410 * its position changes; this is to allow containers that don't draw
7411 * anything to avoid excess invalidations. If you set this flag on a
7412 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7413 * you are responsible for invalidating both the old and new allocation
7414 * of the widget when the widget is moved and responsible for invalidating
7415 * regions newly when the widget increases size.
7418 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7419 gboolean redraw_on_allocate)
7421 g_return_if_fail (GTK_IS_WIDGET (widget));
7423 widget->priv->redraw_on_alloc = redraw_on_allocate;
7427 * gtk_widget_set_sensitive:
7428 * @widget: a #GtkWidget
7429 * @sensitive: %TRUE to make the widget sensitive
7431 * Sets the sensitivity of a widget. A widget is sensitive if the user
7432 * can interact with it. Insensitive widgets are "grayed out" and the
7433 * user can't interact with them. Insensitive widgets are known as
7434 * "inactive", "disabled", or "ghosted" in some other toolkits.
7437 gtk_widget_set_sensitive (GtkWidget *widget,
7440 GtkWidgetPrivate *priv;
7443 g_return_if_fail (GTK_IS_WIDGET (widget));
7445 priv = widget->priv;
7447 sensitive = (sensitive != FALSE);
7449 if (widget->priv->sensitive == sensitive)
7452 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7456 widget->priv->sensitive = TRUE;
7457 data.operation = STATE_CHANGE_UNSET;
7461 widget->priv->sensitive = FALSE;
7462 data.operation = STATE_CHANGE_SET;
7465 data.use_forall = TRUE;
7468 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7470 data.parent_sensitive = TRUE;
7472 gtk_widget_propagate_state (widget, &data);
7474 if (gtk_widget_is_drawable (widget))
7475 gtk_widget_queue_draw (widget);
7477 g_object_notify (G_OBJECT (widget), "sensitive");
7481 * gtk_widget_get_sensitive:
7482 * @widget: a #GtkWidget
7484 * Returns the widget's sensitivity (in the sense of returning
7485 * the value that has been set using gtk_widget_set_sensitive()).
7487 * The effective sensitivity of a widget is however determined by both its
7488 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7490 * Returns: %TRUE if the widget is sensitive
7495 gtk_widget_get_sensitive (GtkWidget *widget)
7497 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7499 return widget->priv->sensitive;
7503 * gtk_widget_is_sensitive:
7504 * @widget: a #GtkWidget
7506 * Returns the widget's effective sensitivity, which means
7507 * it is sensitive itself and also its parent widget is sensntive
7509 * Returns: %TRUE if the widget is effectively sensitive
7514 gtk_widget_is_sensitive (GtkWidget *widget)
7516 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7518 return widget->priv->sensitive && widget->priv->parent_sensitive;
7522 _gtk_widget_update_path (GtkWidget *widget)
7524 if (widget->priv->path)
7526 gtk_widget_path_free (widget->priv->path);
7527 widget->priv->path = NULL;
7530 gtk_widget_get_path (widget);
7534 * gtk_widget_set_parent:
7535 * @widget: a #GtkWidget
7536 * @parent: parent container
7538 * This function is useful only when implementing subclasses of
7540 * Sets the container as the parent of @widget, and takes care of
7541 * some details such as updating the state and style of the child
7542 * to reflect its new location. The opposite function is
7543 * gtk_widget_unparent().
7546 gtk_widget_set_parent (GtkWidget *widget,
7549 GtkStateFlags parent_flags;
7550 GtkWidgetPrivate *priv;
7553 g_return_if_fail (GTK_IS_WIDGET (widget));
7554 g_return_if_fail (GTK_IS_WIDGET (parent));
7555 g_return_if_fail (widget != parent);
7557 priv = widget->priv;
7559 if (priv->parent != NULL)
7561 g_warning ("Can't set a parent on widget which has a parent\n");
7564 if (gtk_widget_is_toplevel (widget))
7566 g_warning ("Can't set a parent on a toplevel widget\n");
7570 /* keep this function in sync with gtk_menu_attach_to_widget()
7573 g_object_ref_sink (widget);
7574 priv->parent = parent;
7576 parent_flags = gtk_widget_get_state_flags (parent);
7578 /* Merge both old state and current parent state,
7579 * We don't want the insensitive flag to propagate
7580 * to the new child though */
7581 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7582 data.flags |= priv->state_flags;
7584 data.operation = STATE_CHANGE_REPLACE;
7585 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7586 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7587 gtk_widget_propagate_state (widget, &data);
7589 gtk_widget_reset_rc_styles (widget);
7591 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7592 if (priv->parent->priv->anchored)
7593 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7594 g_object_notify (G_OBJECT (widget), "parent");
7596 /* Enforce realized/mapped invariants
7598 if (gtk_widget_get_realized (priv->parent))
7599 gtk_widget_realize (widget);
7601 if (gtk_widget_get_visible (priv->parent) &&
7602 gtk_widget_get_visible (widget))
7604 if (gtk_widget_get_child_visible (widget) &&
7605 gtk_widget_get_mapped (priv->parent))
7606 gtk_widget_map (widget);
7608 gtk_widget_queue_resize (widget);
7611 /* child may cause parent's expand to change, if the child is
7612 * expanded. If child is not expanded, then it can't modify the
7613 * parent's expand. If the child becomes expanded later then it will
7614 * queue compute_expand then. This optimization plus defaulting
7615 * newly-constructed widgets to need_compute_expand=FALSE should
7616 * mean that initially building a widget tree doesn't have to keep
7617 * walking up setting need_compute_expand on parents over and over.
7619 * We can't change a parent to need to expand unless we're visible.
7621 if (gtk_widget_get_visible (widget) &&
7622 (priv->need_compute_expand ||
7623 priv->computed_hexpand ||
7624 priv->computed_vexpand))
7626 gtk_widget_queue_compute_expand (parent);
7629 if (widget->priv->context)
7631 _gtk_widget_update_path (widget);
7632 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7634 gtk_style_context_set_screen (widget->priv->context,
7635 gtk_widget_get_screen (widget));
7640 * gtk_widget_get_parent:
7641 * @widget: a #GtkWidget
7643 * Returns the parent container of @widget.
7645 * Return value: (transfer none): the parent container of @widget, or %NULL
7648 gtk_widget_get_parent (GtkWidget *widget)
7650 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7652 return widget->priv->parent;
7655 /*****************************************
7657 * see docs/styles.txt
7658 *****************************************/
7661 * gtk_widget_style_attach:
7662 * @widget: a #GtkWidget
7664 * This function attaches the widget's #GtkStyle to the widget's
7665 * #GdkWindow. It is a replacement for
7668 * widget->style = gtk_style_attach (widget->style, widget->window);
7671 * and should only ever be called in a derived widget's "realize"
7672 * implementation which does not chain up to its parent class'
7673 * "realize" implementation, because one of the parent classes
7674 * (finally #GtkWidget) would attach the style itself.
7679 gtk_widget_style_attach (GtkWidget *widget)
7681 GtkWidgetPrivate *priv;
7683 g_return_if_fail (GTK_IS_WIDGET (widget));
7684 g_return_if_fail (gtk_widget_get_realized (widget));
7686 priv = widget->priv;
7688 priv->style = gtk_style_attach (priv->style, priv->window);
7692 * gtk_widget_has_rc_style:
7693 * @widget: a #GtkWidget
7695 * Determines if the widget style has been looked up through the rc mechanism.
7697 * Returns: %TRUE if the widget has been looked up through the rc
7698 * mechanism, %FALSE otherwise.
7702 * Deprecated:3.0: Use #GtkStyleContext instead
7705 gtk_widget_has_rc_style (GtkWidget *widget)
7707 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7709 return widget->priv->rc_style;
7713 * gtk_widget_set_style:
7714 * @widget: a #GtkWidget
7715 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7716 * gtk_widget_set_style() and go back to the default style
7718 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7719 * want to use this function; it interacts badly with themes, because
7720 * themes work by replacing the #GtkStyle. Instead, use
7721 * gtk_widget_modify_style().
7723 * Deprecated:3.0: Use #GtkStyleContext instead
7726 gtk_widget_set_style (GtkWidget *widget,
7729 g_return_if_fail (GTK_IS_WIDGET (widget));
7733 gboolean initial_emission;
7735 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7737 widget->priv->rc_style = FALSE;
7738 widget->priv->user_style = TRUE;
7740 gtk_widget_set_style_internal (widget, style, initial_emission);
7744 if (widget->priv->user_style)
7745 gtk_widget_reset_rc_style (widget);
7750 * gtk_widget_ensure_style:
7751 * @widget: a #GtkWidget
7753 * Ensures that @widget has a style (@widget->style). Not a very useful
7754 * function; most of the time, if you want the style, the widget is
7755 * realized, and realized widgets are guaranteed to have a style
7758 * Deprecated:3.0: Use #GtkStyleContext instead
7761 gtk_widget_ensure_style (GtkWidget *widget)
7763 g_return_if_fail (GTK_IS_WIDGET (widget));
7765 if (!widget->priv->style ||
7766 !gtk_style_has_context (widget->priv->style))
7770 style = g_object_new (GTK_TYPE_STYLE,
7771 "context", gtk_widget_get_style_context (widget),
7774 gtk_widget_set_style_internal (widget, style, TRUE);
7775 g_object_unref (style);
7779 if (!widget->priv->rc_style && !widget->priv->user_style)
7780 gtk_widget_reset_rc_style (widget);
7784 /* Look up the RC style for this widget, unsetting any user style that
7785 * may be in effect currently
7788 gtk_widget_reset_rc_style (GtkWidget *widget)
7790 GtkWidgetPrivate *priv = widget->priv;
7791 GtkStyle *new_style = NULL;
7792 gboolean initial_emission;
7794 initial_emission = !priv->rc_style && !priv->user_style;
7796 priv->user_style = FALSE;
7797 priv->rc_style = TRUE;
7799 if (gtk_widget_has_screen (widget))
7800 new_style = gtk_rc_get_style (widget);
7802 new_style = gtk_widget_get_default_style ();
7804 if (initial_emission || new_style != priv->style)
7805 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7809 * gtk_widget_get_style:
7810 * @widget: a #GtkWidget
7812 * Simply an accessor function that returns @widget->style.
7814 * Return value: (transfer none): the widget's #GtkStyle
7816 * Deprecated:3.0: Use #GtkStyleContext instead
7819 gtk_widget_get_style (GtkWidget *widget)
7821 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7823 return widget->priv->style;
7827 * gtk_widget_modify_style:
7828 * @widget: a #GtkWidget
7829 * @style: the #GtkRcStyle holding the style modifications
7831 * Modifies style values on the widget. Modifications made using this
7832 * technique take precedence over style values set via an RC file,
7833 * however, they will be overriden if a style is explicitely set on
7834 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7835 * is designed so each field can either be set or unset, so it is
7836 * possible, using this function, to modify some style values and
7837 * leave the others unchanged.
7839 * Note that modifications made with this function are not cumulative
7840 * with previous calls to gtk_widget_modify_style() or with such
7841 * functions as gtk_widget_modify_fg(). If you wish to retain
7842 * previous values, you must first call gtk_widget_get_modifier_style(),
7843 * make your modifications to the returned style, then call
7844 * gtk_widget_modify_style() with that style. On the other hand,
7845 * if you first call gtk_widget_modify_style(), subsequent calls
7846 * to such functions gtk_widget_modify_fg() will have a cumulative
7847 * effect with the initial modifications.
7849 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7852 gtk_widget_modify_style (GtkWidget *widget,
7855 g_return_if_fail (GTK_IS_WIDGET (widget));
7856 g_return_if_fail (GTK_IS_RC_STYLE (style));
7858 g_object_set_qdata_full (G_OBJECT (widget),
7860 gtk_rc_style_copy (style),
7861 (GDestroyNotify) g_object_unref);
7863 /* note that "style" may be invalid here if it was the old
7864 * modifier style and the only reference was our own.
7867 if (widget->priv->rc_style)
7868 gtk_widget_reset_rc_style (widget);
7872 * gtk_widget_get_modifier_style:
7873 * @widget: a #GtkWidget
7875 * Returns the current modifier style for the widget. (As set by
7876 * gtk_widget_modify_style().) If no style has previously set, a new
7877 * #GtkRcStyle will be created with all values unset, and set as the
7878 * modifier style for the widget. If you make changes to this rc
7879 * style, you must call gtk_widget_modify_style(), passing in the
7880 * returned rc style, to make sure that your changes take effect.
7882 * Caution: passing the style back to gtk_widget_modify_style() will
7883 * normally end up destroying it, because gtk_widget_modify_style() copies
7884 * the passed-in style and sets the copy as the new modifier style,
7885 * thus dropping any reference to the old modifier style. Add a reference
7886 * to the modifier style if you want to keep it alive.
7888 * Return value: (transfer none): the modifier style for the widget.
7889 * This rc style is owned by the widget. If you want to keep a
7890 * pointer to value this around, you must add a refcount using
7893 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7896 gtk_widget_get_modifier_style (GtkWidget *widget)
7898 GtkRcStyle *rc_style;
7900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7902 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7906 rc_style = gtk_rc_style_new ();
7907 g_object_set_qdata_full (G_OBJECT (widget),
7910 (GDestroyNotify) g_object_unref);
7917 gtk_widget_modify_color_component (GtkWidget *widget,
7918 GtkRcFlags component,
7920 const GdkColor *color)
7922 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7929 rc_style->fg[state] = *color;
7932 rc_style->bg[state] = *color;
7935 rc_style->text[state] = *color;
7938 rc_style->base[state] = *color;
7941 g_assert_not_reached();
7944 rc_style->color_flags[state] |= component;
7947 rc_style->color_flags[state] &= ~component;
7949 gtk_widget_modify_style (widget, rc_style);
7953 modifier_style_changed (GtkModifierStyle *style,
7956 GtkStyleContext *context;
7958 context = gtk_widget_get_style_context (widget);
7959 gtk_style_context_invalidate (context);
7961 g_signal_emit (widget,
7962 widget_signals[STYLE_SET],
7964 widget->priv->style);
7967 static GtkModifierStyle *
7968 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7970 GtkModifierStyle *style;
7972 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7974 if (G_UNLIKELY (!style))
7976 GtkStyleContext *context;
7978 style = gtk_modifier_style_new ();
7979 g_object_set_qdata_full (G_OBJECT (widget),
7980 quark_modifier_style,
7982 (GDestroyNotify) g_object_unref);
7984 g_signal_connect (style, "changed",
7985 G_CALLBACK (modifier_style_changed), widget);
7987 context = gtk_widget_get_style_context (widget);
7989 gtk_style_context_add_provider (context,
7990 GTK_STYLE_PROVIDER (style),
7991 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7998 * gtk_widget_override_color:
7999 * @widget: a #GtkWidget
8000 * @state: the state for which to set the color
8001 * @color: the color to assign, or %NULL to undo the effect
8002 * of previous calls to gtk_widget_override_color()
8004 * Sets the color to use for a widget. All other style values are left
8009 * This API is mostly meant as a quick way for applications to change a
8010 * widget appearance. If you are developing a widgets library and intend
8011 * this change to be themeable, it is better done by setting meaningful
8012 * CSS classes and regions in your widget/container implementation through
8013 * gtk_style_context_add_class() and gtk_style_context_add_region().
8016 * This way, your widget library can install a #GtkCssProvider with the
8017 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
8018 * default styling for those widgets that need so, and this theming may
8019 * fully overridden by the user's theme.
8025 * Note that for complex widgets this may bring in
8026 * undesired results (such as uniform background color everywhere),
8027 * in these cases it is better to fully style such widgets through a
8028 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8036 gtk_widget_override_color (GtkWidget *widget,
8037 GtkStateFlags state,
8038 const GdkRGBA *color)
8040 GtkModifierStyle *style;
8042 g_return_if_fail (GTK_IS_WIDGET (widget));
8044 style = _gtk_widget_get_modifier_properties (widget);
8045 gtk_modifier_style_set_color (style, state, color);
8049 * gtk_widget_override_background_color:
8050 * @widget: a #GtkWidget
8051 * @state: the state for which to set the background color
8052 * @color: the color to assign, or %NULL to undo the effect
8053 * of previous calls to gtk_widget_override_background_color()
8055 * Sets the background color to use for a widget. All other style values
8056 * are left untouched. See gtk_widget_override_color().
8061 gtk_widget_override_background_color (GtkWidget *widget,
8062 GtkStateFlags state,
8063 const GdkRGBA *color)
8065 GtkModifierStyle *style;
8067 g_return_if_fail (GTK_IS_WIDGET (widget));
8069 style = _gtk_widget_get_modifier_properties (widget);
8070 gtk_modifier_style_set_background_color (style, state, color);
8074 * gtk_widget_override_font:
8075 * @widget: a #GtkWidget
8076 * @font_desc: the font descriptiong to use, or %NULL to undo
8077 * the effect of previous calls to
8078 * gtk_widget_override_font().
8080 * Sets the font to use for a widget. All other style values are
8081 * left untouched. See gtk_widget_override_color().
8086 gtk_widget_override_font (GtkWidget *widget,
8087 const PangoFontDescription *font_desc)
8089 GtkModifierStyle *style;
8091 g_return_if_fail (GTK_IS_WIDGET (widget));
8093 style = _gtk_widget_get_modifier_properties (widget);
8094 gtk_modifier_style_set_font (style, font_desc);
8098 * gtk_widget_override_symbolic_color:
8099 * @widget: a #GtkWidget
8100 * @name: the name of the symbolic color to modify
8101 * @color: (allow-none): the color to assign (does not need to be allocated),
8102 * or %NULL to undo the effect of previous calls to
8103 * gtk_widget_override_symbolic_color().
8105 * Sets a symbolic color for a widget, All other style values are left
8106 * untouched. See gtk_widget_override_color() for overriding the foreground
8107 * or background color.
8112 gtk_widget_override_symbolic_color (GtkWidget *widget,
8114 const GdkRGBA *color)
8116 GtkModifierStyle *style;
8118 g_return_if_fail (GTK_IS_WIDGET (widget));
8120 style = _gtk_widget_get_modifier_properties (widget);
8121 gtk_modifier_style_map_color (style, name, color);
8125 * gtk_widget_override_cursor:
8126 * @widget: a #GtkWidget
8127 * @primary: the color to use for primary cursor (does not need to be
8128 * allocated), or %NULL to undo the effect of previous calls to
8129 * of gtk_widget_override_cursor().
8130 * @secondary: the color to use for secondary cursor (does not need to be
8131 * allocated), or %NULL to undo the effect of previous calls to
8132 * of gtk_widget_override_cursor().
8134 * Sets the cursor color to use in a widget, overriding the
8135 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8136 * style properties. All other style values are left untouched.
8137 * See also gtk_widget_modify_style().
8139 * Note that the underlying properties have the #GdkColor type,
8140 * so the alpha value in @primary and @secondary will be ignored.
8145 gtk_widget_override_cursor (GtkWidget *widget,
8146 const GdkRGBA *cursor,
8147 const GdkRGBA *secondary_cursor)
8149 GtkModifierStyle *style;
8151 g_return_if_fail (GTK_IS_WIDGET (widget));
8153 style = _gtk_widget_get_modifier_properties (widget);
8154 gtk_modifier_style_set_color_property (style,
8156 "cursor-color", cursor);
8157 gtk_modifier_style_set_color_property (style,
8159 "secondary-cursor-color",
8164 * gtk_widget_modify_fg:
8165 * @widget: a #GtkWidget
8166 * @state: the state for which to set the foreground color
8167 * @color: (allow-none): the color to assign (does not need to be allocated),
8168 * or %NULL to undo the effect of previous calls to
8169 * of gtk_widget_modify_fg().
8171 * Sets the foreground color for a widget in a particular state.
8172 * All other style values are left untouched. See also
8173 * gtk_widget_modify_style().
8175 * Deprecated:3.0: Use gtk_widget_override_color() instead
8178 gtk_widget_modify_fg (GtkWidget *widget,
8180 const GdkColor *color)
8182 GtkStateFlags flags;
8185 g_return_if_fail (GTK_IS_WIDGET (widget));
8186 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8190 case GTK_STATE_ACTIVE:
8191 flags = GTK_STATE_FLAG_ACTIVE;
8193 case GTK_STATE_PRELIGHT:
8194 flags = GTK_STATE_FLAG_PRELIGHT;
8196 case GTK_STATE_SELECTED:
8197 flags = GTK_STATE_FLAG_SELECTED;
8199 case GTK_STATE_INSENSITIVE:
8200 flags = GTK_STATE_FLAG_INSENSITIVE;
8202 case GTK_STATE_NORMAL:
8209 rgba.red = color->red / 65535.;
8210 rgba.green = color->green / 65535.;
8211 rgba.blue = color->blue / 65535.;
8214 gtk_widget_override_color (widget, state, &rgba);
8217 gtk_widget_override_color (widget, state, NULL);
8221 * gtk_widget_modify_bg:
8222 * @widget: a #GtkWidget
8223 * @state: the state for which to set the background color
8224 * @color: (allow-none): the color to assign (does not need to be allocated),
8225 * or %NULL to undo the effect of previous calls to
8226 * of gtk_widget_modify_bg().
8228 * Sets the background color for a widget in a particular state.
8229 * All other style values are left untouched. See also
8230 * gtk_widget_modify_style().
8232 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8233 * draw on their parent container's window and thus may not draw any
8234 * background themselves. This is the case for e.g. #GtkLabel. To modify
8235 * the background of such widgets, you have to set the background color
8236 * on their parent; if you want to set the background of a rectangular
8237 * area around a label, try placing the label in a #GtkEventBox widget
8238 * and setting the background color on that.
8240 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8243 gtk_widget_modify_bg (GtkWidget *widget,
8245 const GdkColor *color)
8247 GtkStateFlags flags;
8250 g_return_if_fail (GTK_IS_WIDGET (widget));
8251 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8255 case GTK_STATE_ACTIVE:
8256 flags = GTK_STATE_FLAG_ACTIVE;
8258 case GTK_STATE_PRELIGHT:
8259 flags = GTK_STATE_FLAG_PRELIGHT;
8261 case GTK_STATE_SELECTED:
8262 flags = GTK_STATE_FLAG_SELECTED;
8264 case GTK_STATE_INSENSITIVE:
8265 flags = GTK_STATE_FLAG_INSENSITIVE;
8267 case GTK_STATE_NORMAL:
8274 rgba.red = color->red / 65535.;
8275 rgba.green = color->green / 65535.;
8276 rgba.blue = color->blue / 65535.;
8279 gtk_widget_override_background_color (widget, state, &rgba);
8282 gtk_widget_override_background_color (widget, state, NULL);
8286 * gtk_widget_modify_text:
8287 * @widget: a #GtkWidget
8288 * @state: the state for which to set the text color
8289 * @color: (allow-none): the color to assign (does not need to be allocated),
8290 * or %NULL to undo the effect of previous calls to
8291 * of gtk_widget_modify_text().
8293 * Sets the text color for a widget in a particular state. All other
8294 * style values are left untouched. The text color is the foreground
8295 * color used along with the base color (see gtk_widget_modify_base())
8296 * for widgets such as #GtkEntry and #GtkTextView. See also
8297 * gtk_widget_modify_style().
8299 * Deprecated:3.0: Use gtk_widget_override_color() instead
8302 gtk_widget_modify_text (GtkWidget *widget,
8304 const GdkColor *color)
8306 g_return_if_fail (GTK_IS_WIDGET (widget));
8307 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8309 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8313 * gtk_widget_modify_base:
8314 * @widget: a #GtkWidget
8315 * @state: the state for which to set the base color
8316 * @color: (allow-none): the color to assign (does not need to be allocated),
8317 * or %NULL to undo the effect of previous calls to
8318 * of gtk_widget_modify_base().
8320 * Sets the base color for a widget in a particular state.
8321 * All other style values are left untouched. The base color
8322 * is the background color used along with the text color
8323 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8324 * and #GtkTextView. See also gtk_widget_modify_style().
8326 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8327 * draw on their parent container's window and thus may not draw any
8328 * background themselves. This is the case for e.g. #GtkLabel. To modify
8329 * the background of such widgets, you have to set the base color on their
8330 * parent; if you want to set the background of a rectangular area around
8331 * a label, try placing the label in a #GtkEventBox widget and setting
8332 * the base color on that.
8334 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8337 gtk_widget_modify_base (GtkWidget *widget,
8339 const GdkColor *color)
8341 g_return_if_fail (GTK_IS_WIDGET (widget));
8342 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8344 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8348 * gtk_widget_modify_cursor:
8349 * @widget: a #GtkWidget
8350 * @primary: the color to use for primary cursor (does not need to be
8351 * allocated), or %NULL to undo the effect of previous calls to
8352 * of gtk_widget_modify_cursor().
8353 * @secondary: the color to use for secondary cursor (does not need to be
8354 * allocated), or %NULL to undo the effect of previous calls to
8355 * of gtk_widget_modify_cursor().
8357 * Sets the cursor color to use in a widget, overriding the
8358 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8359 * style properties. All other style values are left untouched.
8360 * See also gtk_widget_modify_style().
8364 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8367 gtk_widget_modify_cursor (GtkWidget *widget,
8368 const GdkColor *primary,
8369 const GdkColor *secondary)
8371 GdkRGBA primary_rgba, secondary_rgba;
8373 g_return_if_fail (GTK_IS_WIDGET (widget));
8375 primary_rgba.red = primary->red / 65535.;
8376 primary_rgba.green = primary->green / 65535.;
8377 primary_rgba.blue = primary->blue / 65535.;
8378 primary_rgba.alpha = 1;
8380 secondary_rgba.red = secondary->red / 65535.;
8381 secondary_rgba.green = secondary->green / 65535.;
8382 secondary_rgba.blue = secondary->blue / 65535.;
8383 secondary_rgba.alpha = 1;
8385 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8389 * gtk_widget_modify_font:
8390 * @widget: a #GtkWidget
8391 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8392 * the effect of previous calls to gtk_widget_modify_font().
8394 * Sets the font to use for a widget. All other style values are left
8395 * untouched. See also gtk_widget_modify_style().
8397 * Deprecated:3.0: Use gtk_widget_override_font() instead
8400 gtk_widget_modify_font (GtkWidget *widget,
8401 PangoFontDescription *font_desc)
8403 g_return_if_fail (GTK_IS_WIDGET (widget));
8405 gtk_widget_override_font (widget, font_desc);
8409 gtk_widget_real_direction_changed (GtkWidget *widget,
8410 GtkTextDirection previous_direction)
8412 gtk_widget_queue_resize (widget);
8416 gtk_widget_real_style_set (GtkWidget *widget,
8417 GtkStyle *previous_style)
8419 GtkWidgetPrivate *priv = widget->priv;
8421 if (gtk_widget_get_realized (widget) &&
8422 gtk_widget_get_has_window (widget))
8423 gtk_style_set_background (priv->style, priv->window,
8424 gtk_widget_get_state (widget));
8428 gtk_widget_set_style_internal (GtkWidget *widget,
8430 gboolean initial_emission)
8432 GtkWidgetPrivate *priv = widget->priv;
8434 g_object_ref (widget);
8435 g_object_freeze_notify (G_OBJECT (widget));
8437 if (priv->style != style)
8439 GtkStyle *previous_style;
8441 if (gtk_widget_get_realized (widget))
8443 gtk_widget_reset_shapes (widget);
8444 gtk_style_detach (priv->style);
8447 previous_style = priv->style;
8448 priv->style = style;
8449 g_object_ref (priv->style);
8451 if (gtk_widget_get_realized (widget))
8452 priv->style = gtk_style_attach (priv->style, priv->window);
8454 gtk_widget_update_pango_context (widget);
8455 g_signal_emit (widget,
8456 widget_signals[STYLE_SET],
8458 initial_emission ? NULL : previous_style);
8459 g_object_unref (previous_style);
8461 if (priv->anchored && !initial_emission)
8462 gtk_widget_queue_resize (widget);
8464 else if (initial_emission)
8466 gtk_widget_update_pango_context (widget);
8467 g_signal_emit (widget,
8468 widget_signals[STYLE_SET],
8472 g_object_notify (G_OBJECT (widget), "style");
8473 g_object_thaw_notify (G_OBJECT (widget));
8474 g_object_unref (widget);
8478 GtkWidget *previous_toplevel;
8479 GdkScreen *previous_screen;
8480 GdkScreen *new_screen;
8481 } HierarchyChangedInfo;
8484 do_screen_change (GtkWidget *widget,
8485 GdkScreen *old_screen,
8486 GdkScreen *new_screen)
8488 if (old_screen != new_screen)
8490 GtkStyleContext *context;
8494 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8496 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8499 _gtk_tooltip_hide (widget);
8501 context = gtk_widget_get_style_context (widget);
8502 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8504 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8509 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8510 gpointer client_data)
8512 GtkWidgetPrivate *priv = widget->priv;
8513 HierarchyChangedInfo *info = client_data;
8514 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8515 (priv->parent && priv->parent->priv->anchored);
8517 if (priv->anchored != new_anchored)
8519 g_object_ref (widget);
8521 priv->anchored = new_anchored;
8523 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8524 do_screen_change (widget, info->previous_screen, info->new_screen);
8526 if (GTK_IS_CONTAINER (widget))
8527 gtk_container_forall (GTK_CONTAINER (widget),
8528 gtk_widget_propagate_hierarchy_changed_recurse,
8531 g_object_unref (widget);
8536 * _gtk_widget_propagate_hierarchy_changed:
8537 * @widget: a #GtkWidget
8538 * @previous_toplevel: Previous toplevel
8540 * Propagates changes in the anchored state to a widget and all
8541 * children, unsetting or setting the %ANCHORED flag, and
8542 * emitting #GtkWidget::hierarchy-changed.
8545 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8546 GtkWidget *previous_toplevel)
8548 GtkWidgetPrivate *priv = widget->priv;
8549 HierarchyChangedInfo info;
8551 info.previous_toplevel = previous_toplevel;
8552 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8554 if (gtk_widget_is_toplevel (widget) ||
8555 (priv->parent && priv->parent->priv->anchored))
8556 info.new_screen = gtk_widget_get_screen (widget);
8558 info.new_screen = NULL;
8560 if (info.previous_screen)
8561 g_object_ref (info.previous_screen);
8562 if (previous_toplevel)
8563 g_object_ref (previous_toplevel);
8565 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8567 if (previous_toplevel)
8568 g_object_unref (previous_toplevel);
8569 if (info.previous_screen)
8570 g_object_unref (info.previous_screen);
8574 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8575 gpointer client_data)
8577 HierarchyChangedInfo *info = client_data;
8579 g_object_ref (widget);
8581 do_screen_change (widget, info->previous_screen, info->new_screen);
8583 if (GTK_IS_CONTAINER (widget))
8584 gtk_container_forall (GTK_CONTAINER (widget),
8585 gtk_widget_propagate_screen_changed_recurse,
8588 g_object_unref (widget);
8592 * gtk_widget_is_composited:
8593 * @widget: a #GtkWidget
8595 * Whether @widget can rely on having its alpha channel
8596 * drawn correctly. On X11 this function returns whether a
8597 * compositing manager is running for @widget's screen.
8599 * Please note that the semantics of this call will change
8600 * in the future if used on a widget that has a composited
8601 * window in its hierarchy (as set by gdk_window_set_composited()).
8603 * Return value: %TRUE if the widget can rely on its alpha
8604 * channel being drawn correctly.
8609 gtk_widget_is_composited (GtkWidget *widget)
8613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8615 screen = gtk_widget_get_screen (widget);
8617 return gdk_screen_is_composited (screen);
8621 propagate_composited_changed (GtkWidget *widget,
8624 if (GTK_IS_CONTAINER (widget))
8626 gtk_container_forall (GTK_CONTAINER (widget),
8627 propagate_composited_changed,
8631 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8635 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8637 propagate_composited_changed (widget, NULL);
8641 * _gtk_widget_propagate_screen_changed:
8642 * @widget: a #GtkWidget
8643 * @previous_screen: Previous screen
8645 * Propagates changes in the screen for a widget to all
8646 * children, emitting #GtkWidget::screen-changed.
8649 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8650 GdkScreen *previous_screen)
8652 HierarchyChangedInfo info;
8654 info.previous_screen = previous_screen;
8655 info.new_screen = gtk_widget_get_screen (widget);
8657 if (previous_screen)
8658 g_object_ref (previous_screen);
8660 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8662 if (previous_screen)
8663 g_object_unref (previous_screen);
8667 reset_style_recurse (GtkWidget *widget, gpointer data)
8670 if (widget->priv->rc_style)
8671 gtk_widget_reset_rc_style (widget);
8674 if (widget->priv->context)
8676 _gtk_widget_update_path (widget);
8677 gtk_style_context_set_path (widget->priv->context,
8678 widget->priv->path);
8681 if (GTK_IS_CONTAINER (widget))
8682 gtk_container_forall (GTK_CONTAINER (widget),
8683 reset_style_recurse,
8688 * gtk_widget_reset_style:
8689 * @widget: a #GtkWidget
8691 * Updates the style context of @widget and all descendents
8692 * by updating its widget path.
8697 gtk_widget_reset_style (GtkWidget *widget)
8699 g_return_if_fail (GTK_IS_WIDGET (widget));
8701 reset_style_recurse (widget, NULL);
8705 * gtk_widget_reset_rc_styles:
8706 * @widget: a #GtkWidget.
8708 * Reset the styles of @widget and all descendents, so when
8709 * they are looked up again, they get the correct values
8710 * for the currently loaded RC file settings.
8712 * This function is not useful for applications.
8714 * Deprecated:3.0: Use #GtkStyleContext instead
8717 gtk_widget_reset_rc_styles (GtkWidget *widget)
8719 g_return_if_fail (GTK_IS_WIDGET (widget));
8721 reset_style_recurse (widget, NULL);
8725 * gtk_widget_get_default_style:
8727 * Returns the default style used by all widgets initially.
8729 * Returns: (transfer none): the default style. This #GtkStyle
8730 * object is owned by GTK+ and should not be modified or freed.
8732 * Deprecated:3.0: Use #GtkStyleContext instead
8735 gtk_widget_get_default_style (void)
8737 if (!gtk_default_style)
8739 gtk_default_style = gtk_style_new ();
8740 g_object_ref (gtk_default_style);
8743 return gtk_default_style;
8746 static PangoContext *
8747 gtk_widget_peek_pango_context (GtkWidget *widget)
8749 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8753 * gtk_widget_get_pango_context:
8754 * @widget: a #GtkWidget
8756 * Gets a #PangoContext with the appropriate font map, font description,
8757 * and base direction for this widget. Unlike the context returned
8758 * by gtk_widget_create_pango_context(), this context is owned by
8759 * the widget (it can be used until the screen for the widget changes
8760 * or the widget is removed from its toplevel), and will be updated to
8761 * match any changes to the widget's attributes.
8763 * If you create and keep a #PangoLayout using this context, you must
8764 * deal with changes to the context by calling pango_layout_context_changed()
8765 * on the layout in response to the #GtkWidget::style-updated and
8766 * #GtkWidget::direction-changed signals for the widget.
8768 * Return value: (transfer none): the #PangoContext for the widget.
8771 gtk_widget_get_pango_context (GtkWidget *widget)
8773 PangoContext *context;
8775 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8777 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8780 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8781 g_object_set_qdata_full (G_OBJECT (widget),
8782 quark_pango_context,
8791 update_pango_context (GtkWidget *widget,
8792 PangoContext *context)
8794 PangoFontDescription *font_desc;
8795 GtkStyleContext *style_context;
8797 style_context = gtk_widget_get_style_context (widget);
8799 gtk_style_context_get (style_context,
8800 gtk_widget_get_state_flags (widget),
8804 pango_context_set_font_description (context, font_desc);
8805 pango_context_set_base_dir (context,
8806 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8807 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8809 pango_font_description_free (font_desc);
8813 gtk_widget_update_pango_context (GtkWidget *widget)
8815 PangoContext *context = gtk_widget_peek_pango_context (widget);
8821 update_pango_context (widget, context);
8823 screen = gtk_widget_get_screen_unchecked (widget);
8826 pango_cairo_context_set_resolution (context,
8827 gdk_screen_get_resolution (screen));
8828 pango_cairo_context_set_font_options (context,
8829 gdk_screen_get_font_options (screen));
8835 * gtk_widget_create_pango_context:
8836 * @widget: a #GtkWidget
8838 * Creates a new #PangoContext with the appropriate font map,
8839 * font description, and base direction for drawing text for
8840 * this widget. See also gtk_widget_get_pango_context().
8842 * Return value: (transfer full): the new #PangoContext
8845 gtk_widget_create_pango_context (GtkWidget *widget)
8848 PangoContext *context;
8850 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8852 screen = gtk_widget_get_screen_unchecked (widget);
8855 GTK_NOTE (MULTIHEAD,
8856 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8858 screen = gdk_screen_get_default ();
8861 context = gdk_pango_context_get_for_screen (screen);
8863 update_pango_context (widget, context);
8864 pango_context_set_language (context, gtk_get_default_language ());
8870 * gtk_widget_create_pango_layout:
8871 * @widget: a #GtkWidget
8872 * @text: text to set on the layout (can be %NULL)
8874 * Creates a new #PangoLayout with the appropriate font map,
8875 * font description, and base direction for drawing text for
8878 * If you keep a #PangoLayout created in this way around, in order to
8879 * notify the layout of changes to the base direction or font of this
8880 * widget, you must call pango_layout_context_changed() in response to
8881 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8884 * Return value: (transfer full): the new #PangoLayout
8887 gtk_widget_create_pango_layout (GtkWidget *widget,
8890 PangoLayout *layout;
8891 PangoContext *context;
8893 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8895 context = gtk_widget_get_pango_context (widget);
8896 layout = pango_layout_new (context);
8899 pango_layout_set_text (layout, text, -1);
8905 * gtk_widget_render_icon_pixbuf:
8906 * @widget: a #GtkWidget
8907 * @stock_id: a stock ID
8908 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8909 * render at the size of the source and don't scale (if there are
8910 * multiple source sizes, GTK+ picks one of the available sizes).
8912 * A convenience function that uses the theme engine and style
8913 * settings for @widget to look up @stock_id and render it to
8914 * a pixbuf. @stock_id should be a stock icon ID such as
8915 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8916 * such as #GTK_ICON_SIZE_MENU.
8918 * The pixels in the returned #GdkPixbuf are shared with the rest of
8919 * the application and should not be modified. The pixbuf should be freed
8920 * after use with g_object_unref().
8922 * Return value: (transfer full): a new pixbuf, or %NULL if the
8923 * stock ID wasn't known
8928 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8929 const gchar *stock_id,
8932 GtkWidgetPrivate *priv;
8933 GtkIconSet *icon_set;
8935 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8936 g_return_val_if_fail (stock_id != NULL, NULL);
8937 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8939 priv = widget->priv;
8941 gtk_widget_ensure_style (widget);
8943 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
8945 if (icon_set == NULL)
8948 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
8952 * gtk_widget_render_icon:
8953 * @widget: a #GtkWidget
8954 * @stock_id: a stock ID
8955 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8956 * render at the size of the source and don't scale (if there are
8957 * multiple source sizes, GTK+ picks one of the available sizes).
8958 * @detail: (allow-none): render detail to pass to theme engine
8960 * A convenience function that uses the theme engine and RC file
8961 * settings for @widget to look up @stock_id and render it to
8962 * a pixbuf. @stock_id should be a stock icon ID such as
8963 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8964 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8965 * identifies the widget or code doing the rendering, so that
8966 * theme engines can special-case rendering for that widget or code.
8968 * The pixels in the returned #GdkPixbuf are shared with the rest of
8969 * the application and should not be modified. The pixbuf should be freed
8970 * after use with g_object_unref().
8972 * Return value: (transfer full): a new pixbuf, or %NULL if the
8973 * stock ID wasn't known
8975 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
8978 gtk_widget_render_icon (GtkWidget *widget,
8979 const gchar *stock_id,
8981 const gchar *detail)
8983 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
8987 * gtk_widget_set_parent_window:
8988 * @widget: a #GtkWidget.
8989 * @parent_window: the new parent window.
8991 * Sets a non default parent window for @widget.
8994 gtk_widget_set_parent_window (GtkWidget *widget,
8995 GdkWindow *parent_window)
8997 GdkWindow *old_parent_window;
8999 g_return_if_fail (GTK_IS_WIDGET (widget));
9001 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9002 quark_parent_window);
9004 if (parent_window != old_parent_window)
9006 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9008 if (old_parent_window)
9009 g_object_unref (old_parent_window);
9011 g_object_ref (parent_window);
9016 * gtk_widget_get_parent_window:
9017 * @widget: a #GtkWidget.
9019 * Gets @widget's parent window.
9021 * Returns: (transfer none): the parent window of @widget.
9024 gtk_widget_get_parent_window (GtkWidget *widget)
9026 GtkWidgetPrivate *priv;
9027 GdkWindow *parent_window;
9029 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9031 priv = widget->priv;
9033 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9035 return (parent_window != NULL) ? parent_window :
9036 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9041 * gtk_widget_set_child_visible:
9042 * @widget: a #GtkWidget
9043 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9045 * Sets whether @widget should be mapped along with its when its parent
9046 * is mapped and @widget has been shown with gtk_widget_show().
9048 * The child visibility can be set for widget before it is added to
9049 * a container with gtk_widget_set_parent(), to avoid mapping
9050 * children unnecessary before immediately unmapping them. However
9051 * it will be reset to its default state of %TRUE when the widget
9052 * is removed from a container.
9054 * Note that changing the child visibility of a widget does not
9055 * queue a resize on the widget. Most of the time, the size of
9056 * a widget is computed from all visible children, whether or
9057 * not they are mapped. If this is not the case, the container
9058 * can queue a resize itself.
9060 * This function is only useful for container implementations and
9061 * never should be called by an application.
9064 gtk_widget_set_child_visible (GtkWidget *widget,
9065 gboolean is_visible)
9067 GtkWidgetPrivate *priv;
9069 g_return_if_fail (GTK_IS_WIDGET (widget));
9070 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9072 priv = widget->priv;
9074 g_object_ref (widget);
9077 priv->child_visible = TRUE;
9080 GtkWidget *toplevel;
9082 priv->child_visible = FALSE;
9084 toplevel = gtk_widget_get_toplevel (widget);
9085 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9086 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9089 if (priv->parent && gtk_widget_get_realized (priv->parent))
9091 if (gtk_widget_get_mapped (priv->parent) &&
9092 priv->child_visible &&
9093 gtk_widget_get_visible (widget))
9094 gtk_widget_map (widget);
9096 gtk_widget_unmap (widget);
9099 g_object_unref (widget);
9103 * gtk_widget_get_child_visible:
9104 * @widget: a #GtkWidget
9106 * Gets the value set with gtk_widget_set_child_visible().
9107 * If you feel a need to use this function, your code probably
9108 * needs reorganization.
9110 * This function is only useful for container implementations and
9111 * never should be called by an application.
9113 * Return value: %TRUE if the widget is mapped with the parent.
9116 gtk_widget_get_child_visible (GtkWidget *widget)
9118 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9120 return widget->priv->child_visible;
9124 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9126 GtkWidget *toplevel;
9128 toplevel = gtk_widget_get_toplevel (widget);
9130 if (gtk_widget_is_toplevel (toplevel))
9132 if (GTK_IS_WINDOW (toplevel))
9133 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9134 else if (GTK_IS_INVISIBLE (toplevel))
9135 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9142 * gtk_widget_get_screen:
9143 * @widget: a #GtkWidget
9145 * Get the #GdkScreen from the toplevel window associated with
9146 * this widget. This function can only be called after the widget
9147 * has been added to a widget hierarchy with a #GtkWindow
9150 * In general, you should only create screen specific
9151 * resources when a widget has been realized, and you should
9152 * free those resources when the widget is unrealized.
9154 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9159 gtk_widget_get_screen (GtkWidget *widget)
9163 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9165 screen = gtk_widget_get_screen_unchecked (widget);
9172 g_warning (G_STRLOC ": Can't get associated screen"
9173 " for a widget unless it is inside a toplevel GtkWindow\n"
9174 " widget type is %s associated top level type is %s",
9175 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9176 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9178 return gdk_screen_get_default ();
9183 * gtk_widget_has_screen:
9184 * @widget: a #GtkWidget
9186 * Checks whether there is a #GdkScreen is associated with
9187 * this widget. All toplevel widgets have an associated
9188 * screen, and all widgets added into a hierarchy with a toplevel
9189 * window at the top.
9191 * Return value: %TRUE if there is a #GdkScreen associcated
9197 gtk_widget_has_screen (GtkWidget *widget)
9199 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9201 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9205 * gtk_widget_get_display:
9206 * @widget: a #GtkWidget
9208 * Get the #GdkDisplay for the toplevel window associated with
9209 * this widget. This function can only be called after the widget
9210 * has been added to a widget hierarchy with a #GtkWindow at the top.
9212 * In general, you should only create display specific
9213 * resources when a widget has been realized, and you should
9214 * free those resources when the widget is unrealized.
9216 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9221 gtk_widget_get_display (GtkWidget *widget)
9223 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9225 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9229 * gtk_widget_get_root_window:
9230 * @widget: a #GtkWidget
9232 * Get the root window where this widget is located. This function can
9233 * only be called after the widget has been added to a widget
9234 * hierarchy with #GtkWindow at the top.
9236 * The root window is useful for such purposes as creating a popup
9237 * #GdkWindow associated with the window. In general, you should only
9238 * create display specific resources when a widget has been realized,
9239 * and you should free those resources when the widget is unrealized.
9241 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9246 gtk_widget_get_root_window (GtkWidget *widget)
9248 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9250 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9254 * gtk_widget_child_focus:
9255 * @widget: a #GtkWidget
9256 * @direction: direction of focus movement
9258 * This function is used by custom widget implementations; if you're
9259 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9260 * to a particular widget, and gtk_container_set_focus_chain() to
9261 * change the focus tab order. So you may want to investigate those
9262 * functions instead.
9264 * gtk_widget_child_focus() is called by containers as the user moves
9265 * around the window using keyboard shortcuts. @direction indicates
9266 * what kind of motion is taking place (up, down, left, right, tab
9267 * forward, tab backward). gtk_widget_child_focus() emits the
9268 * #GtkWidget::focus signal; widgets override the default handler
9269 * for this signal in order to implement appropriate focus behavior.
9271 * The default ::focus handler for a widget should return %TRUE if
9272 * moving in @direction left the focus on a focusable location inside
9273 * that widget, and %FALSE if moving in @direction moved the focus
9274 * outside the widget. If returning %TRUE, widgets normally
9275 * call gtk_widget_grab_focus() to place the focus accordingly;
9276 * if returning %FALSE, they don't modify the current focus location.
9278 * Return value: %TRUE if focus ended up inside @widget
9281 gtk_widget_child_focus (GtkWidget *widget,
9282 GtkDirectionType direction)
9284 gboolean return_val;
9286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9288 if (!gtk_widget_get_visible (widget) ||
9289 !gtk_widget_is_sensitive (widget))
9292 /* child widgets must set CAN_FOCUS, containers
9293 * don't have to though.
9295 if (!GTK_IS_CONTAINER (widget) &&
9296 !gtk_widget_get_can_focus (widget))
9299 g_signal_emit (widget,
9300 widget_signals[FOCUS],
9302 direction, &return_val);
9308 * gtk_widget_keynav_failed:
9309 * @widget: a #GtkWidget
9310 * @direction: direction of focus movement
9312 * This function should be called whenever keyboard navigation within
9313 * a single widget hits a boundary. The function emits the
9314 * #GtkWidget::keynav-failed signal on the widget and its return
9315 * value should be interpreted in a way similar to the return value of
9316 * gtk_widget_child_focus():
9318 * When %TRUE is returned, stay in the widget, the failed keyboard
9319 * navigation is Ok and/or there is nowhere we can/should move the
9322 * When %FALSE is returned, the caller should continue with keyboard
9323 * navigation outside the widget, e.g. by calling
9324 * gtk_widget_child_focus() on the widget's toplevel.
9326 * The default ::keynav-failed handler returns %TRUE for
9327 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9328 * values of #GtkDirectionType, it looks at the
9329 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9330 * if the setting is %TRUE. This way the entire user interface
9331 * becomes cursor-navigatable on input devices such as mobile phones
9332 * which only have cursor keys but no tab key.
9334 * Whenever the default handler returns %TRUE, it also calls
9335 * gtk_widget_error_bell() to notify the user of the failed keyboard
9338 * A use case for providing an own implementation of ::keynav-failed
9339 * (either by connecting to it or by overriding it) would be a row of
9340 * #GtkEntry widgets where the user should be able to navigate the
9341 * entire row with the cursor keys, as e.g. known from user interfaces
9342 * that require entering license keys.
9344 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9345 * if the emitting widget should try to handle the keyboard
9346 * navigation attempt in its parent container(s).
9351 gtk_widget_keynav_failed (GtkWidget *widget,
9352 GtkDirectionType direction)
9354 gboolean return_val;
9356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9358 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9359 direction, &return_val);
9365 * gtk_widget_error_bell:
9366 * @widget: a #GtkWidget
9368 * Notifies the user about an input-related error on this widget.
9369 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9370 * gdk_window_beep(), otherwise it does nothing.
9372 * Note that the effect of gdk_window_beep() can be configured in many
9373 * ways, depending on the windowing backend and the desktop environment
9374 * or window manager that is used.
9379 gtk_widget_error_bell (GtkWidget *widget)
9381 GtkWidgetPrivate *priv;
9382 GtkSettings* settings;
9385 g_return_if_fail (GTK_IS_WIDGET (widget));
9387 priv = widget->priv;
9389 settings = gtk_widget_get_settings (widget);
9393 g_object_get (settings,
9394 "gtk-error-bell", &beep,
9397 if (beep && priv->window)
9398 gdk_window_beep (priv->window);
9402 gtk_widget_set_usize_internal (GtkWidget *widget,
9405 GtkQueueResizeFlags flags)
9407 GtkWidgetAuxInfo *aux_info;
9408 gboolean changed = FALSE;
9410 g_object_freeze_notify (G_OBJECT (widget));
9412 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9414 if (width > -2 && aux_info->width != width)
9416 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9417 g_object_notify (G_OBJECT (widget), "width-request");
9418 aux_info->width = width;
9421 if (height > -2 && aux_info->height != height)
9423 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9424 g_object_notify (G_OBJECT (widget), "height-request");
9425 aux_info->height = height;
9429 if (gtk_widget_get_visible (widget) && changed)
9431 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9432 gtk_widget_queue_resize (widget);
9434 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9437 g_object_thaw_notify (G_OBJECT (widget));
9441 * gtk_widget_set_size_request:
9442 * @widget: a #GtkWidget
9443 * @width: width @widget should request, or -1 to unset
9444 * @height: height @widget should request, or -1 to unset
9446 * Sets the minimum size of a widget; that is, the widget's size
9447 * request will be @width by @height. You can use this function to
9448 * force a widget to be either larger or smaller than it normally
9451 * In most cases, gtk_window_set_default_size() is a better choice for
9452 * toplevel windows than this function; setting the default size will
9453 * still allow users to shrink the window. Setting the size request
9454 * will force them to leave the window at least as large as the size
9455 * request. When dealing with window sizes,
9456 * gtk_window_set_geometry_hints() can be a useful function as well.
9458 * Note the inherent danger of setting any fixed size - themes,
9459 * translations into other languages, different fonts, and user action
9460 * can all change the appropriate size for a given widget. So, it's
9461 * basically impossible to hardcode a size that will always be
9464 * The size request of a widget is the smallest size a widget can
9465 * accept while still functioning well and drawing itself correctly.
9466 * However in some strange cases a widget may be allocated less than
9467 * its requested size, and in many cases a widget may be allocated more
9468 * space than it requested.
9470 * If the size request in a given direction is -1 (unset), then
9471 * the "natural" size request of the widget will be used instead.
9473 * Widgets can't actually be allocated a size less than 1 by 1, but
9474 * you can pass 0,0 to this function to mean "as small as possible."
9476 * The size request set here does not include any margin from the
9477 * #GtkWidget properties margin-left, margin-right, margin-top, and
9478 * margin-bottom, but it does include pretty much all other padding
9479 * or border properties set by any subclass of #GtkWidget.
9482 gtk_widget_set_size_request (GtkWidget *widget,
9486 g_return_if_fail (GTK_IS_WIDGET (widget));
9487 g_return_if_fail (width >= -1);
9488 g_return_if_fail (height >= -1);
9495 gtk_widget_set_usize_internal (widget, width, height, 0);
9500 * gtk_widget_get_size_request:
9501 * @widget: a #GtkWidget
9502 * @width: (out) (allow-none): return location for width, or %NULL
9503 * @height: (out) (allow-none): return location for height, or %NULL
9505 * Gets the size request that was explicitly set for the widget using
9506 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9507 * @height indicates that that dimension has not been set explicitly
9508 * and the natural requisition of the widget will be used intead. See
9509 * gtk_widget_set_size_request(). To get the size a widget will
9510 * actually request, call gtk_widget_get_preferred_size() instead of
9514 gtk_widget_get_size_request (GtkWidget *widget,
9518 const GtkWidgetAuxInfo *aux_info;
9520 g_return_if_fail (GTK_IS_WIDGET (widget));
9522 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9525 *width = aux_info->width;
9528 *height = aux_info->height;
9532 * _gtk_widget_override_size_request:
9533 * @widget: a #GtkWidget
9534 * @width: new forced minimum width
9535 * @height: new forced minimum height
9536 * @old_width: location to store previous forced minimum width
9537 * @old_width: location to store previous forced minumum height
9539 * Temporarily establishes a forced minimum size for a widget; this
9540 * is used by GtkWindow when calculating the size to add to the
9541 * window's geometry widget. Cached sizes for the widget and its
9542 * parents are invalidated, so that subsequent calls to the size
9543 * negotiation machinery produce the overriden result, but the
9544 * widget is not queued for relayout or redraw. The old size must
9545 * be restored with _gtk_widget_restore_size_request() or things
9549 _gtk_widget_override_size_request (GtkWidget *widget,
9555 gtk_widget_get_size_request (widget, old_width, old_height);
9556 gtk_widget_set_usize_internal (widget, width, height,
9557 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9561 * _gtk_widget_restore_size_request:
9562 * @widget: a #GtkWidget
9563 * @old_width: saved forced minimum size
9564 * @old_height: saved forced minimum size
9566 * Undoes the operation of_gtk_widget_override_size_request().
9569 _gtk_widget_restore_size_request (GtkWidget *widget,
9573 gtk_widget_set_usize_internal (widget, old_width, old_height,
9574 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9578 * gtk_widget_set_events:
9579 * @widget: a #GtkWidget
9580 * @events: event mask
9582 * Sets the event mask (see #GdkEventMask) for a widget. The event
9583 * mask determines which events a widget will receive. Keep in mind
9584 * that different widgets have different default event masks, and by
9585 * changing the event mask you may disrupt a widget's functionality,
9586 * so be careful. This function must be called while a widget is
9587 * unrealized. Consider gtk_widget_add_events() for widgets that are
9588 * already realized, or if you want to preserve the existing event
9589 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9590 * to get events on those widgets, place them inside a #GtkEventBox
9591 * and receive events on the event box.
9594 gtk_widget_set_events (GtkWidget *widget,
9597 g_return_if_fail (GTK_IS_WIDGET (widget));
9598 g_return_if_fail (!gtk_widget_get_realized (widget));
9600 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9601 GINT_TO_POINTER (events));
9602 g_object_notify (G_OBJECT (widget), "events");
9606 * gtk_widget_set_device_events:
9607 * @widget: a #GtkWidget
9608 * @device: a #GdkDevice
9609 * @events: event mask
9611 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9612 * mask determines which events a widget will receive from @device. Keep
9613 * in mind that different widgets have different default event masks, and by
9614 * changing the event mask you may disrupt a widget's functionality,
9615 * so be careful. This function must be called while a widget is
9616 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9617 * already realized, or if you want to preserve the existing event
9618 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9619 * to get events on those widgets, place them inside a #GtkEventBox
9620 * and receive events on the event box.
9625 gtk_widget_set_device_events (GtkWidget *widget,
9627 GdkEventMask events)
9629 GHashTable *device_events;
9631 g_return_if_fail (GTK_IS_WIDGET (widget));
9632 g_return_if_fail (GDK_IS_DEVICE (device));
9633 g_return_if_fail (!gtk_widget_get_realized (widget));
9635 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9637 if (G_UNLIKELY (!device_events))
9639 device_events = g_hash_table_new (NULL, NULL);
9640 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9641 (GDestroyNotify) g_hash_table_unref);
9644 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9648 gtk_widget_add_events_internal_list (GtkWidget *widget,
9655 for (l = window_list; l != NULL; l = l->next)
9657 GdkWindow *window = l->data;
9660 gdk_window_get_user_data (window, &user_data);
9661 if (user_data == widget)
9666 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9668 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9670 children = gdk_window_get_children (window);
9671 gtk_widget_add_events_internal_list (widget, device, events, children);
9672 g_list_free (children);
9678 gtk_widget_add_events_internal (GtkWidget *widget,
9682 GtkWidgetPrivate *priv = widget->priv;
9685 if (!gtk_widget_get_has_window (widget))
9686 window_list = gdk_window_get_children (priv->window);
9688 window_list = g_list_prepend (NULL, priv->window);
9690 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9692 g_list_free (window_list);
9696 * gtk_widget_add_events:
9697 * @widget: a #GtkWidget
9698 * @events: an event mask, see #GdkEventMask
9700 * Adds the events in the bitfield @events to the event mask for
9701 * @widget. See gtk_widget_set_events() for details.
9704 gtk_widget_add_events (GtkWidget *widget,
9709 g_return_if_fail (GTK_IS_WIDGET (widget));
9711 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9712 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9713 GINT_TO_POINTER (old_events | events));
9715 if (gtk_widget_get_realized (widget))
9716 gtk_widget_add_events_internal (widget, NULL, events);
9718 g_object_notify (G_OBJECT (widget), "events");
9722 * gtk_widget_add_device_events:
9723 * @widget: a #GtkWidget
9724 * @device: a #GdkDevice
9725 * @events: an event mask, see #GdkEventMask
9727 * Adds the device events in the bitfield @events to the event mask for
9728 * @widget. See gtk_widget_set_device_events() for details.
9733 gtk_widget_add_device_events (GtkWidget *widget,
9735 GdkEventMask events)
9737 GdkEventMask old_events;
9738 GHashTable *device_events;
9740 g_return_if_fail (GTK_IS_WIDGET (widget));
9741 g_return_if_fail (GDK_IS_DEVICE (device));
9743 old_events = gtk_widget_get_device_events (widget, device);
9745 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9747 if (G_UNLIKELY (!device_events))
9749 device_events = g_hash_table_new (NULL, NULL);
9750 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9751 (GDestroyNotify) g_hash_table_unref);
9754 g_hash_table_insert (device_events, device,
9755 GUINT_TO_POINTER (old_events | events));
9757 if (gtk_widget_get_realized (widget))
9758 gtk_widget_add_events_internal (widget, device, events);
9760 g_object_notify (G_OBJECT (widget), "events");
9764 * gtk_widget_set_extension_events:
9765 * @widget: a #GtkWidget
9766 * @mode: bitfield of extension events to receive
9768 * Sets the extension events mask to @mode. See #GdkExtensionMode
9769 * and gdk_input_set_extension_events().
9772 gtk_widget_set_extension_events (GtkWidget *widget,
9773 GdkExtensionMode mode)
9775 g_return_if_fail (GTK_IS_WIDGET (widget));
9777 if (gtk_widget_get_realized (widget))
9778 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9780 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9781 GINT_TO_POINTER (mode));
9782 g_object_notify (G_OBJECT (widget), "extension-events");
9786 * gtk_widget_get_toplevel:
9787 * @widget: a #GtkWidget
9789 * This function returns the topmost widget in the container hierarchy
9790 * @widget is a part of. If @widget has no parent widgets, it will be
9791 * returned as the topmost widget. No reference will be added to the
9792 * returned widget; it should not be unreferenced.
9794 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9795 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9797 * %NULL if @widget wasn't inside a toplevel window, and if the
9798 * window was inside a #GtkWindow-derived widget which was in turn
9799 * inside the toplevel #GtkWindow. While the second case may
9800 * seem unlikely, it actually happens when a #GtkPlug is embedded
9801 * inside a #GtkSocket within the same application.
9803 * To reliably find the toplevel #GtkWindow, use
9804 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9805 * is set on the result.
9807 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9808 * if (gtk_widget_is_toplevel (toplevel))
9810 * /* Perform action on toplevel. */
9814 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9815 * if there's no ancestor.
9818 gtk_widget_get_toplevel (GtkWidget *widget)
9820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9822 while (widget->priv->parent)
9823 widget = widget->priv->parent;
9829 * gtk_widget_get_ancestor:
9830 * @widget: a #GtkWidget
9831 * @widget_type: ancestor type
9833 * Gets the first ancestor of @widget with type @widget_type. For example,
9834 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9835 * the first #GtkBox that's an ancestor of @widget. No reference will be
9836 * added to the returned widget; it should not be unreferenced. See note
9837 * about checking for a toplevel #GtkWindow in the docs for
9838 * gtk_widget_get_toplevel().
9840 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9841 * considers @widget to be an ancestor of itself.
9843 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9846 gtk_widget_get_ancestor (GtkWidget *widget,
9849 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9851 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9852 widget = widget->priv->parent;
9854 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9861 * gtk_widget_set_visual:
9862 * @widget: a #GtkWidget
9863 * @visual: visual to be used or %NULL to unset a previous one
9865 * Sets the visual that should be used for by widget and its children for
9866 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9867 * returned by gdk_widget_get_screen(), so handling the
9868 * #GtkWidget::screen-changed signal is necessary.
9870 * Setting a new @visual will not cause @widget to recreate its windows,
9871 * so you should call this function before @widget is realized.
9874 gtk_widget_set_visual (GtkWidget *widget,
9877 g_return_if_fail (GTK_IS_WIDGET (widget));
9878 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9881 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9884 g_object_set_qdata_full (G_OBJECT (widget),
9886 g_object_ref (visual),
9891 * gtk_widget_get_visual:
9892 * @widget: a #GtkWidget
9894 * Gets the visual that will be used to render @widget.
9896 * Return value: (transfer none): the visual for @widget
9899 gtk_widget_get_visual (GtkWidget *widget)
9905 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9907 if (gtk_widget_get_has_window (widget) &&
9908 widget->priv->window)
9909 return gdk_window_get_visual (widget->priv->window);
9911 screen = gtk_widget_get_screen (widget);
9913 for (w = widget; w != NULL; w = w->priv->parent)
9915 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9918 if (gdk_visual_get_screen (visual) == screen)
9921 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9922 gtk_widget_get_name (widget));
9926 return gdk_screen_get_system_visual (screen);
9930 * gtk_widget_get_settings:
9931 * @widget: a #GtkWidget
9933 * Gets the settings object holding the settings (global property
9934 * settings, RC file information, etc) used for this widget.
9936 * Note that this function can only be called when the #GtkWidget
9937 * is attached to a toplevel, since the settings object is specific
9938 * to a particular #GdkScreen.
9940 * Return value: (transfer none): the relevant #GtkSettings object
9943 gtk_widget_get_settings (GtkWidget *widget)
9945 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9947 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9951 * gtk_widget_get_events:
9952 * @widget: a #GtkWidget
9954 * Returns the event mask for the widget (a bitfield containing flags
9955 * from the #GdkEventMask enumeration). These are the events that the widget
9958 * Return value: event mask for @widget
9961 gtk_widget_get_events (GtkWidget *widget)
9963 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9965 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9969 * gtk_widget_get_device_events:
9970 * @widget: a #GtkWidget
9971 * @device: a #GdkDevice
9973 * Returns the events mask for the widget corresponding to an specific device. These
9974 * are the events that the widget will receive when @device operates on it.
9976 * Returns: device event mask for @widget
9981 gtk_widget_get_device_events (GtkWidget *widget,
9984 GHashTable *device_events;
9986 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9987 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9989 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9994 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9998 * gtk_widget_get_extension_events:
9999 * @widget: a #GtkWidget
10001 * Retrieves the extension events the widget will receive; see
10002 * gdk_input_set_extension_events().
10004 * Return value: extension events for @widget
10007 gtk_widget_get_extension_events (GtkWidget *widget)
10009 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10011 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
10015 * gtk_widget_get_pointer:
10016 * @widget: a #GtkWidget
10017 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10018 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10020 * Obtains the location of the mouse pointer in widget coordinates.
10021 * Widget coordinates are a bit odd; for historical reasons, they are
10022 * defined as @widget->window coordinates for widgets that are not
10023 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10024 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10027 gtk_widget_get_pointer (GtkWidget *widget,
10031 GtkWidgetPrivate *priv;
10033 g_return_if_fail (GTK_IS_WIDGET (widget));
10035 priv = widget->priv;
10042 if (gtk_widget_get_realized (widget))
10044 gdk_window_get_pointer (priv->window, x, y, NULL);
10046 if (!gtk_widget_get_has_window (widget))
10049 *x -= priv->allocation.x;
10051 *y -= priv->allocation.y;
10057 * gtk_widget_is_ancestor:
10058 * @widget: a #GtkWidget
10059 * @ancestor: another #GtkWidget
10061 * Determines whether @widget is somewhere inside @ancestor, possibly with
10062 * intermediate containers.
10064 * Return value: %TRUE if @ancestor contains @widget as a child,
10065 * grandchild, great grandchild, etc.
10068 gtk_widget_is_ancestor (GtkWidget *widget,
10069 GtkWidget *ancestor)
10071 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10072 g_return_val_if_fail (ancestor != NULL, FALSE);
10076 if (widget->priv->parent == ancestor)
10078 widget = widget->priv->parent;
10084 static GQuark quark_composite_name = 0;
10087 * gtk_widget_set_composite_name:
10088 * @widget: a #GtkWidget.
10089 * @name: the name to set
10091 * Sets a widgets composite name. The widget must be
10092 * a composite child of its parent; see gtk_widget_push_composite_child().
10095 gtk_widget_set_composite_name (GtkWidget *widget,
10098 g_return_if_fail (GTK_IS_WIDGET (widget));
10099 g_return_if_fail (widget->priv->composite_child);
10100 g_return_if_fail (name != NULL);
10102 if (!quark_composite_name)
10103 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10105 g_object_set_qdata_full (G_OBJECT (widget),
10106 quark_composite_name,
10112 * gtk_widget_get_composite_name:
10113 * @widget: a #GtkWidget
10115 * Obtains the composite name of a widget.
10117 * Returns: the composite name of @widget, or %NULL if @widget is not
10118 * a composite child. The string should be freed when it is no
10122 gtk_widget_get_composite_name (GtkWidget *widget)
10124 GtkWidgetPrivate *priv;
10126 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10128 priv = widget->priv;
10130 if (widget->priv->composite_child && priv->parent)
10131 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10138 * gtk_widget_push_composite_child:
10140 * Makes all newly-created widgets as composite children until
10141 * the corresponding gtk_widget_pop_composite_child() call.
10143 * A composite child is a child that's an implementation detail of the
10144 * container it's inside and should not be visible to people using the
10145 * container. Composite children aren't treated differently by GTK (but
10146 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10147 * builders might want to treat them in a different way.
10149 * Here is a simple example:
10151 * gtk_widget_push_composite_child ();
10152 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10153 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10154 * gtk_widget_pop_composite_child ();
10155 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10156 * GTK_WIDGET (scrolled_window));
10157 * g_object_ref (scrolled_window->hscrollbar);
10161 gtk_widget_push_composite_child (void)
10163 composite_child_stack++;
10167 * gtk_widget_pop_composite_child:
10169 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10172 gtk_widget_pop_composite_child (void)
10174 if (composite_child_stack)
10175 composite_child_stack--;
10179 gtk_widget_emit_direction_changed (GtkWidget *widget,
10180 GtkTextDirection old_dir)
10182 gtk_widget_update_pango_context (widget);
10184 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10188 * gtk_widget_set_direction:
10189 * @widget: a #GtkWidget
10190 * @dir: the new direction
10192 * Sets the reading direction on a particular widget. This direction
10193 * controls the primary direction for widgets containing text,
10194 * and also the direction in which the children of a container are
10195 * packed. The ability to set the direction is present in order
10196 * so that correct localization into languages with right-to-left
10197 * reading directions can be done. Generally, applications will
10198 * let the default reading direction present, except for containers
10199 * where the containers are arranged in an order that is explicitely
10200 * visual rather than logical (such as buttons for text justification).
10202 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10203 * set by gtk_widget_set_default_direction() will be used.
10206 gtk_widget_set_direction (GtkWidget *widget,
10207 GtkTextDirection dir)
10209 GtkTextDirection old_dir;
10211 g_return_if_fail (GTK_IS_WIDGET (widget));
10212 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10214 old_dir = gtk_widget_get_direction (widget);
10216 widget->priv->direction = dir;
10218 if (old_dir != gtk_widget_get_direction (widget))
10220 if (widget->priv->context)
10221 gtk_style_context_set_direction (widget->priv->context,
10222 gtk_widget_get_direction (widget));
10224 gtk_widget_emit_direction_changed (widget, old_dir);
10229 * gtk_widget_get_direction:
10230 * @widget: a #GtkWidget
10232 * Gets the reading direction for a particular widget. See
10233 * gtk_widget_set_direction().
10235 * Return value: the reading direction for the widget.
10238 gtk_widget_get_direction (GtkWidget *widget)
10240 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10242 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10243 return gtk_default_direction;
10245 return widget->priv->direction;
10249 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10251 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10253 g_object_ref (widget);
10255 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10256 gtk_widget_emit_direction_changed (widget, old_dir);
10258 if (GTK_IS_CONTAINER (widget))
10259 gtk_container_forall (GTK_CONTAINER (widget),
10260 gtk_widget_set_default_direction_recurse,
10263 g_object_unref (widget);
10267 * gtk_widget_set_default_direction:
10268 * @dir: the new default direction. This cannot be
10269 * %GTK_TEXT_DIR_NONE.
10271 * Sets the default reading direction for widgets where the
10272 * direction has not been explicitly set by gtk_widget_set_direction().
10275 gtk_widget_set_default_direction (GtkTextDirection dir)
10277 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10279 if (dir != gtk_default_direction)
10281 GList *toplevels, *tmp_list;
10282 GtkTextDirection old_dir = gtk_default_direction;
10284 gtk_default_direction = dir;
10286 tmp_list = toplevels = gtk_window_list_toplevels ();
10287 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10291 gtk_widget_set_default_direction_recurse (tmp_list->data,
10292 GUINT_TO_POINTER (old_dir));
10293 g_object_unref (tmp_list->data);
10294 tmp_list = tmp_list->next;
10297 g_list_free (toplevels);
10302 * gtk_widget_get_default_direction:
10304 * Obtains the current default reading direction. See
10305 * gtk_widget_set_default_direction().
10307 * Return value: the current default direction.
10310 gtk_widget_get_default_direction (void)
10312 return gtk_default_direction;
10316 gtk_widget_dispose (GObject *object)
10318 GtkWidget *widget = GTK_WIDGET (object);
10319 GtkWidgetPrivate *priv = widget->priv;
10322 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10323 else if (gtk_widget_get_visible (widget))
10324 gtk_widget_hide (widget);
10326 priv->visible = FALSE;
10327 if (gtk_widget_get_realized (widget))
10328 gtk_widget_unrealize (widget);
10330 if (!priv->in_destruction)
10332 priv->in_destruction = TRUE;
10333 g_signal_emit (object, widget_signals[DESTROY], 0);
10334 priv->in_destruction = FALSE;
10337 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10341 gtk_widget_real_destroy (GtkWidget *object)
10343 /* gtk_object_destroy() will already hold a refcount on object */
10344 GtkWidget *widget = GTK_WIDGET (object);
10345 GtkWidgetPrivate *priv = widget->priv;
10347 /* wipe accelerator closures (keep order) */
10348 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10349 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10351 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10352 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10354 gtk_grab_remove (widget);
10356 g_object_unref (priv->style);
10357 priv->style = gtk_widget_get_default_style ();
10358 g_object_ref (priv->style);
10362 gtk_widget_finalize (GObject *object)
10364 GtkWidget *widget = GTK_WIDGET (object);
10365 GtkWidgetPrivate *priv = widget->priv;
10366 GtkWidgetAuxInfo *aux_info;
10367 GtkAccessible *accessible;
10369 gtk_grab_remove (widget);
10371 g_object_unref (priv->style);
10372 priv->style = NULL;
10374 g_free (priv->name);
10376 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10378 gtk_widget_aux_info_destroy (aux_info);
10380 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10382 g_object_unref (accessible);
10385 gtk_widget_path_free (priv->path);
10388 g_object_unref (priv->context);
10390 if (g_object_is_floating (object))
10391 g_warning ("A floating object was finalized. This means that someone\n"
10392 "called g_object_unref() on an object that had only a floating\n"
10393 "reference; the initial floating reference is not owned by anyone\n"
10394 "and must be removed with g_object_ref_sink().");
10396 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10399 /*****************************************
10400 * gtk_widget_real_map:
10405 *****************************************/
10408 gtk_widget_real_map (GtkWidget *widget)
10410 GtkWidgetPrivate *priv = widget->priv;
10412 g_assert (gtk_widget_get_realized (widget));
10414 if (!gtk_widget_get_mapped (widget))
10416 gtk_widget_set_mapped (widget, TRUE);
10418 if (gtk_widget_get_has_window (widget))
10419 gdk_window_show (priv->window);
10423 /*****************************************
10424 * gtk_widget_real_unmap:
10429 *****************************************/
10432 gtk_widget_real_unmap (GtkWidget *widget)
10434 GtkWidgetPrivate *priv = widget->priv;
10436 if (gtk_widget_get_mapped (widget))
10438 gtk_widget_set_mapped (widget, FALSE);
10440 if (gtk_widget_get_has_window (widget))
10441 gdk_window_hide (priv->window);
10445 /*****************************************
10446 * gtk_widget_real_realize:
10451 *****************************************/
10454 gtk_widget_real_realize (GtkWidget *widget)
10456 GtkWidgetPrivate *priv = widget->priv;
10458 g_assert (!gtk_widget_get_has_window (widget));
10460 gtk_widget_set_realized (widget, TRUE);
10463 priv->window = gtk_widget_get_parent_window (widget);
10464 g_object_ref (priv->window);
10466 priv->style = gtk_style_attach (priv->style, priv->window);
10469 /*****************************************
10470 * gtk_widget_real_unrealize:
10475 *****************************************/
10478 gtk_widget_real_unrealize (GtkWidget *widget)
10480 GtkWidgetPrivate *priv = widget->priv;
10482 if (gtk_widget_get_mapped (widget))
10483 gtk_widget_real_unmap (widget);
10485 gtk_widget_set_mapped (widget, FALSE);
10487 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10490 /* We must do unrealize child widget BEFORE container widget.
10491 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10492 * So, unrealizing container widget bofore its children causes the problem
10493 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10496 if (GTK_IS_CONTAINER (widget))
10497 gtk_container_forall (GTK_CONTAINER (widget),
10498 (GtkCallback) gtk_widget_unrealize,
10501 gtk_style_detach (priv->style);
10502 if (gtk_widget_get_has_window (widget))
10504 gdk_window_set_user_data (priv->window, NULL);
10505 gdk_window_destroy (priv->window);
10506 priv->window = NULL;
10510 g_object_unref (priv->window);
10511 priv->window = NULL;
10514 gtk_selection_remove_all (widget);
10516 gtk_widget_set_realized (widget, FALSE);
10520 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10521 GtkOrientation orientation,
10522 gint *minimum_size,
10523 gint *natural_size)
10525 const GtkWidgetAuxInfo *aux_info;
10527 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10529 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10530 aux_info->width > 0)
10532 *minimum_size = MAX (*minimum_size, aux_info->width);
10534 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10535 aux_info->height > 0)
10537 *minimum_size = MAX (*minimum_size, aux_info->height);
10540 /* Fix it if set_size_request made natural size smaller than min size.
10541 * This would also silently fix broken widgets, but we warn about them
10542 * in gtksizerequest.c when calling their size request vfuncs.
10544 *natural_size = MAX (*natural_size, *minimum_size);
10546 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10548 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10549 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10553 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10554 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10559 * _gtk_widget_peek_request_cache:
10561 * Returns the address of the widget's request cache (strictly for
10562 * internal use in gtksizerequest.c)
10564 * Return value: the address of @widget's size request cache.
10567 _gtk_widget_peek_request_cache (GtkWidget *widget)
10569 /* Don't bother slowing things down with the return_if_fail guards here */
10570 return &widget->priv->requests;
10574 * _gtk_widget_set_device_window:
10575 * @widget: a #GtkWidget.
10576 * @device: a #GdkDevice.
10577 * @window: the new device window.
10579 * Sets pointer window for @widget and @device. Does not ref @window.
10580 * Actually stores it on the #GdkScreen, but you don't need to know that.
10583 _gtk_widget_set_device_window (GtkWidget *widget,
10587 GtkWidgetPrivate *priv;
10589 GHashTable *device_window;
10591 g_return_if_fail (GTK_IS_WIDGET (widget));
10592 g_return_if_fail (GDK_IS_DEVICE (device));
10593 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10595 priv = widget->priv;
10597 if (!gtk_widget_get_realized (widget))
10600 screen = gdk_window_get_screen (priv->window);
10601 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10603 if (G_UNLIKELY (!device_window))
10605 device_window = g_hash_table_new (NULL, NULL);
10606 g_object_set_qdata_full (G_OBJECT (screen),
10607 quark_pointer_window,
10609 (GDestroyNotify) g_hash_table_destroy);
10613 g_hash_table_insert (device_window, device, window);
10615 g_hash_table_remove (device_window, device);
10619 * _gtk_widget_get_device_window:
10620 * @widget: a #GtkWidget.
10621 * @device: a #GdkDevice.
10623 * Return value: the device window set on the #GdkScreen @widget is attached
10627 _gtk_widget_get_device_window (GtkWidget *widget,
10630 GtkWidgetPrivate *priv;
10632 GHashTable *device_window;
10636 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10637 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10639 priv = widget->priv;
10641 if (!gtk_widget_get_realized (widget))
10644 screen = gdk_window_get_screen (priv->window);
10645 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10647 if (G_UNLIKELY (!device_window))
10650 window = g_hash_table_lookup (device_window, device);
10655 gdk_window_get_user_data (window, (gpointer *) &w);
10664 * _gtk_widget_list_devices:
10665 * @widget: a #GtkWidget.
10667 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10668 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10672 _gtk_widget_list_devices (GtkWidget *widget)
10674 GtkWidgetPrivate *priv;
10676 GHashTableIter iter;
10677 GHashTable *device_window;
10678 GList *devices = NULL;
10679 gpointer key, value;
10681 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10683 priv = widget->priv;
10685 if (!gtk_widget_get_realized (widget))
10688 screen = gdk_window_get_screen (priv->window);
10689 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10691 if (G_UNLIKELY (!device_window))
10694 g_hash_table_iter_init (&iter, device_window);
10696 while (g_hash_table_iter_next (&iter, &key, &value))
10698 GdkDevice *device = key;
10699 GdkWindow *window = value;
10704 gdk_window_get_user_data (window, (gpointer *) &w);
10707 devices = g_list_prepend (devices, device);
10715 synth_crossing (GtkWidget *widget,
10719 GdkCrossingMode mode,
10720 GdkNotifyType detail)
10724 event = gdk_event_new (type);
10726 event->crossing.window = g_object_ref (window);
10727 event->crossing.send_event = TRUE;
10728 event->crossing.subwindow = g_object_ref (window);
10729 event->crossing.time = GDK_CURRENT_TIME;
10730 event->crossing.x = event->crossing.y = 0;
10731 event->crossing.x_root = event->crossing.y_root = 0;
10732 event->crossing.mode = mode;
10733 event->crossing.detail = detail;
10734 event->crossing.focus = FALSE;
10735 event->crossing.state = 0;
10736 gdk_event_set_device (event, device);
10739 widget = gtk_get_event_widget (event);
10742 gtk_widget_event_internal (widget, event);
10744 gdk_event_free (event);
10748 * _gtk_widget_synthesize_crossing:
10749 * @from: the #GtkWidget the virtual pointer is leaving.
10750 * @to: the #GtkWidget the virtual pointer is moving to.
10751 * @mode: the #GdkCrossingMode to place on the synthesized events.
10753 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10755 * The real pointer window is the window that most recently received an enter notify
10756 * event. Windows that don't select for crossing events can't become the real
10757 * poiner window. The real pointer widget that owns the real pointer window. The
10758 * effective pointer window is the same as the real pointer window unless the real
10759 * pointer widget is either insensitive or there is a grab on a widget that is not
10760 * an ancestor of the real pointer widget (in which case the effective pointer
10761 * window should be the root window).
10763 * When the effective pointer window is the same as the real poiner window, we
10764 * receive crossing events from the windowing system. When the effective pointer
10765 * window changes to become different from the real pointer window we synthesize
10766 * crossing events, attempting to follow X protocol rules:
10768 * When the root window becomes the effective pointer window:
10769 * - leave notify on real pointer window, detail Ancestor
10770 * - leave notify on all of its ancestors, detail Virtual
10771 * - enter notify on root window, detail Inferior
10773 * When the root window ceases to be the effective pointer window:
10774 * - leave notify on root window, detail Inferior
10775 * - enter notify on all ancestors of real pointer window, detail Virtual
10776 * - enter notify on real pointer window, detail Ancestor
10779 _gtk_widget_synthesize_crossing (GtkWidget *from,
10782 GdkCrossingMode mode)
10784 GdkWindow *from_window = NULL, *to_window = NULL;
10786 g_return_if_fail (from != NULL || to != NULL);
10790 from_window = _gtk_widget_get_device_window (from, device);
10793 from_window = from->priv->window;
10798 to_window = _gtk_widget_get_device_window (to, device);
10801 to_window = to->priv->window;
10804 if (from_window == NULL && to_window == NULL)
10806 else if (from_window != NULL && to_window == NULL)
10808 GList *from_ancestors = NULL, *list;
10809 GdkWindow *from_ancestor = from_window;
10811 while (from_ancestor != NULL)
10813 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10814 if (from_ancestor == NULL)
10816 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10819 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10820 device, mode, GDK_NOTIFY_ANCESTOR);
10821 for (list = g_list_last (from_ancestors); list; list = list->prev)
10823 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10824 device, mode, GDK_NOTIFY_VIRTUAL);
10827 /* XXX: enter/inferior on root window? */
10829 g_list_free (from_ancestors);
10831 else if (from_window == NULL && to_window != NULL)
10833 GList *to_ancestors = NULL, *list;
10834 GdkWindow *to_ancestor = to_window;
10836 while (to_ancestor != NULL)
10838 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10839 if (to_ancestor == NULL)
10841 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10844 /* XXX: leave/inferior on root window? */
10846 for (list = to_ancestors; list; list = list->next)
10848 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10849 device, mode, GDK_NOTIFY_VIRTUAL);
10851 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10852 device, mode, GDK_NOTIFY_ANCESTOR);
10854 g_list_free (to_ancestors);
10856 else if (from_window == to_window)
10860 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10861 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10863 while (from_ancestor != NULL || to_ancestor != NULL)
10865 if (from_ancestor != NULL)
10867 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10868 if (from_ancestor == to_window)
10871 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10873 if (to_ancestor != NULL)
10875 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10876 if (to_ancestor == from_window)
10879 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10882 if (to_ancestor == from_window)
10884 if (mode != GDK_CROSSING_GTK_UNGRAB)
10885 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10886 device, mode, GDK_NOTIFY_INFERIOR);
10887 for (list = to_ancestors; list; list = list->next)
10888 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10889 device, mode, GDK_NOTIFY_VIRTUAL);
10890 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10891 device, mode, GDK_NOTIFY_ANCESTOR);
10893 else if (from_ancestor == to_window)
10895 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10896 device, mode, GDK_NOTIFY_ANCESTOR);
10897 for (list = g_list_last (from_ancestors); list; list = list->prev)
10899 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10900 device, mode, GDK_NOTIFY_VIRTUAL);
10902 if (mode != GDK_CROSSING_GTK_GRAB)
10903 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10904 device, mode, GDK_NOTIFY_INFERIOR);
10908 while (from_ancestors != NULL && to_ancestors != NULL
10909 && from_ancestors->data == to_ancestors->data)
10911 from_ancestors = g_list_delete_link (from_ancestors,
10913 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10916 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10917 device, mode, GDK_NOTIFY_NONLINEAR);
10919 for (list = g_list_last (from_ancestors); list; list = list->prev)
10921 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10922 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10924 for (list = to_ancestors; list; list = list->next)
10926 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10927 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10929 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10930 device, mode, GDK_NOTIFY_NONLINEAR);
10932 g_list_free (from_ancestors);
10933 g_list_free (to_ancestors);
10938 gtk_widget_propagate_state (GtkWidget *widget,
10939 GtkStateData *data)
10941 GtkWidgetPrivate *priv = widget->priv;
10942 GtkStateFlags new_flags, old_flags = priv->state_flags;
10943 GtkStateType old_state;
10945 old_state = gtk_widget_get_state (widget);
10947 if (!priv->parent_sensitive)
10948 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10950 priv->parent_sensitive = data->parent_sensitive;
10952 switch (data->operation)
10954 case STATE_CHANGE_REPLACE:
10955 priv->state_flags = data->flags;
10957 case STATE_CHANGE_SET:
10958 priv->state_flags |= data->flags;
10960 case STATE_CHANGE_UNSET:
10961 priv->state_flags &= ~(data->flags);
10965 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10969 window = gtk_widget_get_toplevel (widget);
10971 if (window && gtk_widget_is_toplevel (window))
10972 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10975 new_flags = gtk_widget_get_state_flags (widget);
10977 if (old_flags != new_flags)
10979 g_object_ref (widget);
10981 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10982 gtk_grab_remove (widget);
10984 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10985 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10987 if (!priv->shadowed)
10989 GList *event_windows = NULL;
10990 GList *devices, *d;
10992 devices = _gtk_widget_list_devices (widget);
10994 for (d = devices; d; d = d->next)
11000 window = _gtk_widget_get_device_window (widget, device);
11002 /* Do not propagate more than once to the
11003 * same window if non-multidevice aware.
11005 if (!gdk_window_get_support_multidevice (window) &&
11006 g_list_find (event_windows, window))
11009 if (!gtk_widget_is_sensitive (widget))
11010 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11011 GDK_CROSSING_STATE_CHANGED);
11012 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11013 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11014 GDK_CROSSING_STATE_CHANGED);
11016 event_windows = g_list_prepend (event_windows, window);
11019 g_list_free (event_windows);
11020 g_list_free (devices);
11023 if (GTK_IS_CONTAINER (widget))
11025 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11027 /* Do not propagate insensitive state further */
11028 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
11030 if (data->use_forall)
11031 gtk_container_forall (GTK_CONTAINER (widget),
11032 (GtkCallback) gtk_widget_propagate_state,
11035 gtk_container_foreach (GTK_CONTAINER (widget),
11036 (GtkCallback) gtk_widget_propagate_state,
11040 /* Trigger state change transitions for the widget */
11041 if (priv->context &&
11042 gtk_widget_get_mapped (widget))
11044 gint diff, flag = 1;
11047 diff = old_flags ^ new_flags;
11048 window = gtk_widget_get_window (widget);
11052 if ((diff & flag) != 0)
11056 target = ((new_flags & flag) != 0);
11057 _gtk_widget_notify_state_change (widget, flag, target);
11066 g_object_unref (widget);
11070 static const GtkWidgetAuxInfo default_aux_info = {
11078 * _gtk_widget_get_aux_info:
11079 * @widget: a #GtkWidget
11080 * @create: if %TRUE, create the structure if it doesn't exist
11082 * Get the #GtkWidgetAuxInfo structure for the widget.
11084 * Return value: the #GtkAuxInfo structure for the widget, or
11085 * %NULL if @create is %FALSE and one doesn't already exist.
11088 _gtk_widget_get_aux_info (GtkWidget *widget,
11091 GtkWidgetAuxInfo *aux_info;
11093 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11094 if (!aux_info && create)
11096 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11098 *aux_info = default_aux_info;
11100 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11106 static const GtkWidgetAuxInfo*
11107 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11109 GtkWidgetAuxInfo *aux_info;
11111 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11112 if (aux_info == NULL)
11114 return &default_aux_info;
11122 /*****************************************
11123 * gtk_widget_aux_info_destroy:
11128 *****************************************/
11131 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11133 g_slice_free (GtkWidgetAuxInfo, aux_info);
11137 * gtk_widget_shape_combine_region:
11138 * @widget: a #GtkWidget
11139 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11141 * Sets a shape for this widget's GDK window. This allows for
11142 * transparent windows etc., see gdk_window_shape_combine_region()
11143 * for more information.
11148 gtk_widget_shape_combine_region (GtkWidget *widget,
11149 cairo_region_t *region)
11151 GtkWidgetPrivate *priv;
11153 g_return_if_fail (GTK_IS_WIDGET (widget));
11154 /* set_shape doesn't work on widgets without gdk window */
11155 g_return_if_fail (gtk_widget_get_has_window (widget));
11157 priv = widget->priv;
11159 if (region == NULL)
11161 priv->has_shape_mask = FALSE;
11164 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11166 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11170 priv->has_shape_mask = TRUE;
11172 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11173 cairo_region_copy (region),
11174 (GDestroyNotify) cairo_region_destroy);
11176 /* set shape if widget has a gdk window already.
11177 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11180 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11185 * gtk_widget_input_shape_combine_region:
11186 * @widget: a #GtkWidget
11187 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11189 * Sets an input shape for this widget's GDK window. This allows for
11190 * windows which react to mouse click in a nonrectangular region, see
11191 * gdk_window_input_shape_combine_region() for more information.
11196 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11197 cairo_region_t *region)
11199 GtkWidgetPrivate *priv;
11201 g_return_if_fail (GTK_IS_WIDGET (widget));
11202 /* set_shape doesn't work on widgets without gdk window */
11203 g_return_if_fail (gtk_widget_get_has_window (widget));
11205 priv = widget->priv;
11207 if (region == NULL)
11210 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11212 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11216 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11217 cairo_region_copy (region),
11218 (GDestroyNotify) cairo_region_destroy);
11220 /* set shape if widget has a gdk window already.
11221 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11224 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11230 gtk_reset_shapes_recurse (GtkWidget *widget,
11236 gdk_window_get_user_data (window, &data);
11237 if (data != widget)
11240 gdk_window_shape_combine_region (window, NULL, 0, 0);
11241 for (list = gdk_window_peek_children (window); list; list = list->next)
11242 gtk_reset_shapes_recurse (widget, list->data);
11246 * gtk_widget_reset_shapes:
11247 * @widget: a #GtkWidget
11249 * Recursively resets the shape on this widget and its descendants.
11252 gtk_widget_reset_shapes (GtkWidget *widget)
11254 GtkWidgetPrivate *priv;
11256 g_return_if_fail (GTK_IS_WIDGET (widget));
11257 g_return_if_fail (gtk_widget_get_realized (widget));
11259 priv = widget->priv;
11261 if (!priv->has_shape_mask)
11262 gtk_reset_shapes_recurse (widget, priv->window);
11265 /* style properties
11269 * gtk_widget_class_install_style_property_parser:
11270 * @klass: a #GtkWidgetClass
11271 * @pspec: the #GParamSpec for the style property
11272 * @parser: the parser for the style property
11274 * Installs a style property on a widget class.
11277 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11279 GtkRcPropertyParser parser)
11281 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11282 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11283 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11284 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11286 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11288 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11289 G_OBJECT_CLASS_NAME (klass),
11294 g_param_spec_ref_sink (pspec);
11295 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11296 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11300 * gtk_widget_class_install_style_property:
11301 * @klass: a #GtkWidgetClass
11302 * @pspec: the #GParamSpec for the property
11304 * Installs a style property on a widget class. The parser for the
11305 * style property is determined by the value type of @pspec.
11308 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11311 GtkRcPropertyParser parser;
11313 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11314 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11316 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11318 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11322 * gtk_widget_class_find_style_property:
11323 * @klass: a #GtkWidgetClass
11324 * @property_name: the name of the style property to find
11325 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11326 * style property with that name.
11328 * Finds a style property of a widget class by name.
11333 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11334 const gchar *property_name)
11336 g_return_val_if_fail (property_name != NULL, NULL);
11338 return g_param_spec_pool_lookup (style_property_spec_pool,
11340 G_OBJECT_CLASS_TYPE (klass),
11345 * gtk_widget_class_list_style_properties:
11346 * @klass: a #GtkWidgetClass
11347 * @n_properties: location to return the number of style properties found
11348 * @returns: an newly allocated array of #GParamSpec*. The array must
11349 * be freed with g_free().
11351 * Returns all style properties of a widget class.
11356 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11357 guint *n_properties)
11359 GParamSpec **pspecs;
11362 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11363 G_OBJECT_CLASS_TYPE (klass),
11372 * gtk_widget_style_get_property:
11373 * @widget: a #GtkWidget
11374 * @property_name: the name of a style property
11375 * @value: location to return the property value
11377 * Gets the value of a style property of @widget.
11380 gtk_widget_style_get_property (GtkWidget *widget,
11381 const gchar *property_name,
11386 g_return_if_fail (GTK_IS_WIDGET (widget));
11387 g_return_if_fail (property_name != NULL);
11388 g_return_if_fail (G_IS_VALUE (value));
11390 g_object_ref (widget);
11391 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11393 G_OBJECT_TYPE (widget),
11396 g_warning ("%s: widget class `%s' has no property named `%s'",
11398 G_OBJECT_TYPE_NAME (widget),
11402 GtkStyleContext *context;
11403 const GValue *peek_value;
11404 GtkStateFlags state;
11406 context = gtk_widget_get_style_context (widget);
11407 state = gtk_widget_get_state_flags (widget);
11409 peek_value = _gtk_style_context_peek_style_property (context,
11410 G_OBJECT_TYPE (widget),
11413 /* auto-conversion of the caller's value type
11415 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11416 g_value_copy (peek_value, value);
11417 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11418 g_value_transform (peek_value, value);
11420 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11422 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11423 G_VALUE_TYPE_NAME (value));
11425 g_object_unref (widget);
11429 * gtk_widget_style_get_valist:
11430 * @widget: a #GtkWidget
11431 * @first_property_name: the name of the first property to get
11432 * @var_args: a <type>va_list</type> of pairs of property names and
11433 * locations to return the property values, starting with the location
11434 * for @first_property_name.
11436 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11440 gtk_widget_style_get_valist (GtkWidget *widget,
11441 const gchar *first_property_name,
11444 GtkStyleContext *context;
11445 GtkStateFlags state;
11448 g_return_if_fail (GTK_IS_WIDGET (widget));
11450 g_object_ref (widget);
11451 context = gtk_widget_get_style_context (widget);
11452 state = gtk_widget_get_state_flags (widget);
11454 name = first_property_name;
11457 const GValue *peek_value;
11461 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11463 G_OBJECT_TYPE (widget),
11467 g_warning ("%s: widget class `%s' has no property named `%s'",
11469 G_OBJECT_TYPE_NAME (widget),
11473 /* style pspecs are always readable so we can spare that check here */
11475 peek_value = _gtk_style_context_peek_style_property (context,
11476 G_OBJECT_TYPE (widget),
11479 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11482 g_warning ("%s: %s", G_STRLOC, error);
11487 name = va_arg (var_args, gchar*);
11490 g_object_unref (widget);
11494 * gtk_widget_style_get:
11495 * @widget: a #GtkWidget
11496 * @first_property_name: the name of the first property to get
11497 * @Varargs: pairs of property names and locations to
11498 * return the property values, starting with the location for
11499 * @first_property_name, terminated by %NULL.
11501 * Gets the values of a multiple style properties of @widget.
11504 gtk_widget_style_get (GtkWidget *widget,
11505 const gchar *first_property_name,
11510 g_return_if_fail (GTK_IS_WIDGET (widget));
11512 va_start (var_args, first_property_name);
11513 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11519 * @widget: a #GtkWidget
11520 * @path_length: (out) (allow-none): location to store length of the path,
11522 * @path: (out) (allow-none): location to store allocated path string,
11524 * @path_reversed: (out) (allow-none): location to store allocated reverse
11525 * path string, or %NULL
11527 * Obtains the full path to @widget. The path is simply the name of a
11528 * widget and all its parents in the container hierarchy, separated by
11529 * periods. The name of a widget comes from
11530 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11531 * in gtkrc configuration files. Widget names are the type of the
11532 * widget by default (e.g. "GtkButton") or can be set to an
11533 * application-specific value with gtk_widget_set_name(). By setting
11534 * the name of a widget, you allow users or theme authors to apply
11535 * styles to that specific widget in their gtkrc
11536 * file. @path_reversed_p fills in the path in reverse order,
11537 * i.e. starting with @widget's name instead of starting with the name
11538 * of @widget's outermost ancestor.
11540 * Deprecated:3.0: Use gtk_widget_get_path() instead
11543 gtk_widget_path (GtkWidget *widget,
11544 guint *path_length,
11546 gchar **path_reversed)
11548 static gchar *rev_path = NULL;
11549 static guint tmp_path_len = 0;
11552 g_return_if_fail (GTK_IS_WIDGET (widget));
11557 const gchar *string;
11562 string = gtk_widget_get_name (widget);
11563 l = strlen (string);
11564 while (tmp_path_len <= len + l + 1)
11566 tmp_path_len += INIT_PATH_SIZE;
11567 rev_path = g_realloc (rev_path, tmp_path_len);
11569 s = string + l - 1;
11570 d = rev_path + len;
11571 while (s >= string)
11575 widget = widget->priv->parent;
11578 rev_path[len++] = '.';
11580 rev_path[len++] = 0;
11585 *path_length = len - 1;
11587 *path_reversed = g_strdup (rev_path);
11590 *path = g_strdup (rev_path);
11591 g_strreverse (*path);
11596 * gtk_widget_class_path:
11597 * @widget: a #GtkWidget
11598 * @path_length: (out) (allow-none): location to store the length of the
11599 * class path, or %NULL
11600 * @path: (out) (allow-none): location to store the class path as an
11601 * allocated string, or %NULL
11602 * @path_reversed: (out) (allow-none): location to store the reverse
11603 * class path as an allocated string, or %NULL
11605 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11606 * never uses a custom name set with gtk_widget_set_name().
11608 * Deprecated:3.0: Use gtk_widget_get_path() instead
11611 gtk_widget_class_path (GtkWidget *widget,
11612 guint *path_length,
11614 gchar **path_reversed)
11616 static gchar *rev_path = NULL;
11617 static guint tmp_path_len = 0;
11620 g_return_if_fail (GTK_IS_WIDGET (widget));
11625 const gchar *string;
11630 string = g_type_name (G_OBJECT_TYPE (widget));
11631 l = strlen (string);
11632 while (tmp_path_len <= len + l + 1)
11634 tmp_path_len += INIT_PATH_SIZE;
11635 rev_path = g_realloc (rev_path, tmp_path_len);
11637 s = string + l - 1;
11638 d = rev_path + len;
11639 while (s >= string)
11643 widget = widget->priv->parent;
11646 rev_path[len++] = '.';
11648 rev_path[len++] = 0;
11653 *path_length = len - 1;
11655 *path_reversed = g_strdup (rev_path);
11658 *path = g_strdup (rev_path);
11659 g_strreverse (*path);
11664 * gtk_requisition_new:
11666 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11668 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11669 * be freed with gtk_requisition_free().
11674 gtk_requisition_new (void)
11676 return g_slice_new0 (GtkRequisition);
11680 * gtk_requisition_copy:
11681 * @requisition: a #GtkRequisition
11683 * Copies a #GtkRequisition.
11685 * Returns: a copy of @requisition
11688 gtk_requisition_copy (const GtkRequisition *requisition)
11690 return g_slice_dup (GtkRequisition, requisition);
11694 * gtk_requisition_free:
11695 * @requisition: a #GtkRequisition
11697 * Frees a #GtkRequisition.
11700 gtk_requisition_free (GtkRequisition *requisition)
11702 g_slice_free (GtkRequisition, requisition);
11705 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11706 gtk_requisition_copy,
11707 gtk_requisition_free)
11710 * gtk_widget_get_accessible:
11711 * @widget: a #GtkWidget
11713 * Returns the accessible object that describes the widget to an
11714 * assistive technology.
11716 * If no accessibility library is loaded (i.e. no ATK implementation library is
11717 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11718 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11719 * if no class-specific #AtkObject implementation is available for the widget
11720 * instance in question, it will inherit an #AtkObject implementation from the
11721 * first ancestor class for which such an implementation is defined.
11723 * The documentation of the
11724 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11725 * library contains more information about accessible objects and their uses.
11727 * Returns: (transfer none): the #AtkObject associated with @widget
11730 gtk_widget_get_accessible (GtkWidget *widget)
11732 GtkWidgetClass *klass;
11734 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11736 klass = GTK_WIDGET_GET_CLASS (widget);
11738 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11740 return klass->get_accessible (widget);
11744 gtk_widget_real_get_accessible (GtkWidget *widget)
11746 AtkObject* accessible;
11748 accessible = g_object_get_qdata (G_OBJECT (widget),
11749 quark_accessible_object);
11752 AtkObjectFactory *factory;
11753 AtkRegistry *default_registry;
11755 default_registry = atk_get_default_registry ();
11756 factory = atk_registry_get_factory (default_registry,
11757 G_TYPE_FROM_INSTANCE (widget));
11759 atk_object_factory_create_accessible (factory,
11760 G_OBJECT (widget));
11761 g_object_set_qdata (G_OBJECT (widget),
11762 quark_accessible_object,
11769 * Initialize a AtkImplementorIface instance's virtual pointers as
11770 * appropriate to this implementor's class (GtkWidget).
11773 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11775 iface->ref_accessible = gtk_widget_ref_accessible;
11779 gtk_widget_ref_accessible (AtkImplementor *implementor)
11781 AtkObject *accessible;
11783 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11785 g_object_ref (accessible);
11790 * Expand flag management
11794 gtk_widget_update_computed_expand (GtkWidget *widget)
11796 GtkWidgetPrivate *priv;
11798 priv = widget->priv;
11800 if (priv->need_compute_expand)
11804 if (priv->hexpand_set)
11809 if (priv->vexpand_set)
11814 /* we don't need to use compute_expand if both expands are
11815 * forced by the app
11817 if (!(priv->hexpand_set && priv->vexpand_set))
11819 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11823 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11824 priv->hexpand_set ? &ignored : &h,
11825 priv->vexpand_set ? &ignored : &v);
11829 priv->need_compute_expand = FALSE;
11830 priv->computed_hexpand = h != FALSE;
11831 priv->computed_vexpand = v != FALSE;
11836 * gtk_widget_queue_compute_expand:
11837 * @widget: a #GtkWidget
11839 * Mark @widget as needing to recompute its expand flags. Call
11840 * this function when setting legacy expand child properties
11841 * on the child of a container.
11843 * See gtk_widget_compute_expand().
11846 gtk_widget_queue_compute_expand (GtkWidget *widget)
11849 gboolean changed_anything;
11851 if (widget->priv->need_compute_expand)
11854 changed_anything = FALSE;
11856 while (parent != NULL)
11858 if (!parent->priv->need_compute_expand)
11860 parent->priv->need_compute_expand = TRUE;
11861 changed_anything = TRUE;
11864 /* Note: if we had an invariant that "if a child needs to
11865 * compute expand, its parents also do" then we could stop going
11866 * up when we got to a parent that already needed to
11867 * compute. However, in general we compute expand lazily (as
11868 * soon as we see something in a subtree that is expand, we know
11869 * we're expanding) and so this invariant does not hold and we
11870 * have to always walk all the way up in case some ancestor
11871 * is not currently need_compute_expand.
11874 parent = parent->priv->parent;
11877 /* recomputing expand always requires
11878 * a relayout as well
11880 if (changed_anything)
11881 gtk_widget_queue_resize (widget);
11885 * gtk_widget_compute_expand:
11886 * @widget: the widget
11887 * @orientation: expand direction
11889 * Computes whether a container should give this widget extra space
11890 * when possible. Containers should check this, rather than
11891 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11893 * This function already checks whether the widget is visible, so
11894 * visibility does not need to be checked separately. Non-visible
11895 * widgets are not expanded.
11897 * The computed expand value uses either the expand setting explicitly
11898 * set on the widget itself, or, if none has been explicitly set,
11899 * the widget may expand if some of its children do.
11901 * Return value: whether widget tree rooted here should be expanded
11904 gtk_widget_compute_expand (GtkWidget *widget,
11905 GtkOrientation orientation)
11907 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11909 /* We never make a widget expand if not even showing. */
11910 if (!gtk_widget_get_visible (widget))
11913 gtk_widget_update_computed_expand (widget);
11915 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11917 return widget->priv->computed_hexpand;
11921 return widget->priv->computed_vexpand;
11926 gtk_widget_set_expand (GtkWidget *widget,
11927 GtkOrientation orientation,
11930 const char *expand_prop;
11931 const char *expand_set_prop;
11933 GtkWidgetPrivate *priv;
11935 g_return_if_fail (GTK_IS_WIDGET (widget));
11937 priv = widget->priv;
11939 expand = expand != FALSE;
11941 was_both = priv->hexpand && priv->vexpand;
11943 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11945 if (priv->hexpand_set &&
11946 priv->hexpand == expand)
11949 priv->hexpand_set = TRUE;
11950 priv->hexpand = expand;
11952 expand_prop = "hexpand";
11953 expand_set_prop = "hexpand-set";
11957 if (priv->vexpand_set &&
11958 priv->vexpand == expand)
11961 priv->vexpand_set = TRUE;
11962 priv->vexpand = expand;
11964 expand_prop = "vexpand";
11965 expand_set_prop = "vexpand-set";
11968 gtk_widget_queue_compute_expand (widget);
11970 g_object_freeze_notify (G_OBJECT (widget));
11971 g_object_notify (G_OBJECT (widget), expand_prop);
11972 g_object_notify (G_OBJECT (widget), expand_set_prop);
11973 if (was_both != (priv->hexpand && priv->vexpand))
11974 g_object_notify (G_OBJECT (widget), "expand");
11975 g_object_thaw_notify (G_OBJECT (widget));
11979 gtk_widget_set_expand_set (GtkWidget *widget,
11980 GtkOrientation orientation,
11983 GtkWidgetPrivate *priv;
11986 priv = widget->priv;
11988 set = set != FALSE;
11990 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11992 if (set == priv->hexpand_set)
11995 priv->hexpand_set = set;
11996 prop = "hexpand-set";
12000 if (set == priv->vexpand_set)
12003 priv->vexpand_set = set;
12004 prop = "vexpand-set";
12007 gtk_widget_queue_compute_expand (widget);
12009 g_object_notify (G_OBJECT (widget), prop);
12013 * gtk_widget_get_hexpand:
12014 * @widget: the widget
12016 * Gets whether the widget would like any available extra horizontal
12017 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12018 * generally receive the extra space. For example, a list or
12019 * scrollable area or document in your window would often be set to
12022 * Containers should use gtk_widget_compute_expand() rather than
12023 * this function, to see whether a widget, or any of its children,
12024 * has the expand flag set. If any child of a widget wants to
12025 * expand, the parent may ask to expand also.
12027 * This function only looks at the widget's own hexpand flag, rather
12028 * than computing whether the entire widget tree rooted at this widget
12031 * Return value: whether hexpand flag is set
12034 gtk_widget_get_hexpand (GtkWidget *widget)
12036 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12038 return widget->priv->hexpand;
12042 * gtk_widget_set_hexpand:
12043 * @widget: the widget
12044 * @expand: whether to expand
12046 * Sets whether the widget would like any available extra horizontal
12047 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12048 * generally receive the extra space. For example, a list or
12049 * scrollable area or document in your window would often be set to
12052 * Call this function to set the expand flag if you would like your
12053 * widget to become larger horizontally when the window has extra
12056 * By default, widgets automatically expand if any of their children
12057 * want to expand. (To see if a widget will automatically expand given
12058 * its current children and state, call gtk_widget_compute_expand(). A
12059 * container can decide how the expandability of children affects the
12060 * expansion of the container by overriding the compute_expand virtual
12061 * method on #GtkWidget.).
12063 * Setting hexpand explicitly with this function will override the
12064 * automatic expand behavior.
12066 * This function forces the widget to expand or not to expand,
12067 * regardless of children. The override occurs because
12068 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12069 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12070 * value to be used, rather than looking at children and widget state.
12073 gtk_widget_set_hexpand (GtkWidget *widget,
12076 g_return_if_fail (GTK_IS_WIDGET (widget));
12078 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12082 * gtk_widget_get_hexpand_set:
12083 * @widget: the widget
12085 * Gets whether gtk_widget_set_hexpand() has been used to
12086 * explicitly set the expand flag on this widget.
12088 * If hexpand is set, then it overrides any computed
12089 * expand value based on child widgets. If hexpand is not
12090 * set, then the expand value depends on whether any
12091 * children of the widget would like to expand.
12093 * There are few reasons to use this function, but it's here
12094 * for completeness and consistency.
12096 * Return value: whether hexpand has been explicitly set
12099 gtk_widget_get_hexpand_set (GtkWidget *widget)
12101 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12103 return widget->priv->hexpand_set;
12107 * gtk_widget_set_hexpand_set:
12108 * @widget: the widget
12109 * @set: value for hexpand-set property
12111 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12114 * The hexpand-set property will be set automatically when you call
12115 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12116 * reason to use this function would be to unset an explicit expand
12119 * If hexpand is set, then it overrides any computed
12120 * expand value based on child widgets. If hexpand is not
12121 * set, then the expand value depends on whether any
12122 * children of the widget would like to expand.
12124 * There are few reasons to use this function, but it's here
12125 * for completeness and consistency.
12127 * Return value: whether hexpand has been explicitly set
12130 gtk_widget_set_hexpand_set (GtkWidget *widget,
12133 g_return_if_fail (GTK_IS_WIDGET (widget));
12135 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12140 * gtk_widget_get_vexpand:
12141 * @widget: the widget
12143 * Gets whether the widget would like any available extra vertical
12146 * See gtk_widget_get_hexpand() for more detail.
12148 * Return value: whether vexpand flag is set
12151 gtk_widget_get_vexpand (GtkWidget *widget)
12153 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12155 return widget->priv->vexpand;
12159 * gtk_widget_set_vexpand:
12160 * @widget: the widget
12161 * @expand: whether to expand
12163 * Sets whether the widget would like any available extra vertical
12166 * See gtk_widget_set_hexpand() for more detail.
12169 gtk_widget_set_vexpand (GtkWidget *widget,
12172 g_return_if_fail (GTK_IS_WIDGET (widget));
12174 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12178 * gtk_widget_get_vexpand_set:
12179 * @widget: the widget
12181 * Gets whether gtk_widget_set_vexpand() has been used to
12182 * explicitly set the expand flag on this widget.
12184 * See gtk_widget_get_hexpand_set() for more detail.
12186 * Return value: whether vexpand has been explicitly set
12189 gtk_widget_get_vexpand_set (GtkWidget *widget)
12191 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12193 return widget->priv->vexpand_set;
12197 * gtk_widget_set_vexpand_set:
12198 * @widget: the widget
12199 * @set: value for vexpand-set property
12201 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12204 * See gtk_widget_set_hexpand_set() for more detail.
12206 * Return value: whether vexpand has been explicitly set
12209 gtk_widget_set_vexpand_set (GtkWidget *widget,
12212 g_return_if_fail (GTK_IS_WIDGET (widget));
12214 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12218 * GtkBuildable implementation
12220 static GQuark quark_builder_has_default = 0;
12221 static GQuark quark_builder_has_focus = 0;
12222 static GQuark quark_builder_atk_relations = 0;
12223 static GQuark quark_builder_set_name = 0;
12226 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12228 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12229 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12230 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12231 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12233 iface->set_name = gtk_widget_buildable_set_name;
12234 iface->get_name = gtk_widget_buildable_get_name;
12235 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12236 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12237 iface->parser_finished = gtk_widget_buildable_parser_finished;
12238 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12239 iface->custom_finished = gtk_widget_buildable_custom_finished;
12243 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12246 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12247 g_strdup (name), g_free);
12250 static const gchar *
12251 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12253 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12257 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12258 GtkBuilder *builder,
12259 const gchar *childname)
12261 if (strcmp (childname, "accessible") == 0)
12262 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12268 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12269 GtkBuilder *builder,
12271 const GValue *value)
12273 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12274 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12275 GINT_TO_POINTER (TRUE));
12276 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12277 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12278 GINT_TO_POINTER (TRUE));
12280 g_object_set_property (G_OBJECT (buildable), name, value);
12285 gchar *action_name;
12286 GString *description;
12288 gboolean translatable;
12298 free_action (AtkActionData *data, gpointer user_data)
12300 g_free (data->action_name);
12301 g_string_free (data->description, TRUE);
12302 g_free (data->context);
12303 g_slice_free (AtkActionData, data);
12307 free_relation (AtkRelationData *data, gpointer user_data)
12309 g_free (data->target);
12310 g_free (data->type);
12311 g_slice_free (AtkRelationData, data);
12315 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12316 GtkBuilder *builder)
12318 GSList *atk_relations;
12320 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12321 gtk_widget_grab_default (GTK_WIDGET (buildable));
12322 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12323 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12325 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12326 quark_builder_atk_relations);
12329 AtkObject *accessible;
12330 AtkRelationSet *relation_set;
12333 AtkRelationType relation_type;
12334 AtkObject *target_accessible;
12336 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12337 relation_set = atk_object_ref_relation_set (accessible);
12339 for (l = atk_relations; l; l = l->next)
12341 AtkRelationData *relation = (AtkRelationData*)l->data;
12343 target = gtk_builder_get_object (builder, relation->target);
12346 g_warning ("Target object %s in <relation> does not exist",
12350 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12351 g_assert (target_accessible != NULL);
12353 relation_type = atk_relation_type_for_name (relation->type);
12354 if (relation_type == ATK_RELATION_NULL)
12356 g_warning ("<relation> type %s not found",
12360 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12361 target_accessible);
12363 g_object_unref (relation_set);
12365 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12366 g_slist_free (atk_relations);
12367 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12376 } AccessibilitySubParserData;
12379 accessibility_start_element (GMarkupParseContext *context,
12380 const gchar *element_name,
12381 const gchar **names,
12382 const gchar **values,
12383 gpointer user_data,
12386 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12388 gint line_number, char_number;
12390 if (strcmp (element_name, "relation") == 0)
12392 gchar *target = NULL;
12393 gchar *type = NULL;
12394 AtkRelationData *relation;
12396 for (i = 0; names[i]; i++)
12398 if (strcmp (names[i], "target") == 0)
12399 target = g_strdup (values[i]);
12400 else if (strcmp (names[i], "type") == 0)
12401 type = g_strdup (values[i]);
12404 g_markup_parse_context_get_position (context,
12407 g_set_error (error,
12409 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12410 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12412 line_number, char_number, names[i], "relation");
12419 if (!target || !type)
12421 g_markup_parse_context_get_position (context,
12424 g_set_error (error,
12426 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12427 "%s:%d:%d <%s> requires attribute \"%s\"",
12429 line_number, char_number, "relation",
12430 type ? "target" : "type");
12436 relation = g_slice_new (AtkRelationData);
12437 relation->target = target;
12438 relation->type = type;
12440 data->relations = g_slist_prepend (data->relations, relation);
12442 else if (strcmp (element_name, "action") == 0)
12444 const gchar *action_name = NULL;
12445 const gchar *description = NULL;
12446 const gchar *msg_context = NULL;
12447 gboolean translatable = FALSE;
12448 AtkActionData *action;
12450 for (i = 0; names[i]; i++)
12452 if (strcmp (names[i], "action_name") == 0)
12453 action_name = values[i];
12454 else if (strcmp (names[i], "description") == 0)
12455 description = values[i];
12456 else if (strcmp (names[i], "translatable") == 0)
12458 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12461 else if (strcmp (names[i], "comments") == 0)
12463 /* do nothing, comments are for translators */
12465 else if (strcmp (names[i], "context") == 0)
12466 msg_context = values[i];
12469 g_markup_parse_context_get_position (context,
12472 g_set_error (error,
12474 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12475 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12477 line_number, char_number, names[i], "action");
12484 g_markup_parse_context_get_position (context,
12487 g_set_error (error,
12489 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12490 "%s:%d:%d <%s> requires attribute \"%s\"",
12492 line_number, char_number, "action",
12497 action = g_slice_new (AtkActionData);
12498 action->action_name = g_strdup (action_name);
12499 action->description = g_string_new (description);
12500 action->context = g_strdup (msg_context);
12501 action->translatable = translatable;
12503 data->actions = g_slist_prepend (data->actions, action);
12505 else if (strcmp (element_name, "accessibility") == 0)
12508 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12512 accessibility_text (GMarkupParseContext *context,
12515 gpointer user_data,
12518 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12520 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12522 AtkActionData *action = data->actions->data;
12524 g_string_append_len (action->description, text, text_len);
12528 static const GMarkupParser accessibility_parser =
12530 accessibility_start_element,
12532 accessibility_text,
12541 } AccelGroupParserData;
12544 accel_group_start_element (GMarkupParseContext *context,
12545 const gchar *element_name,
12546 const gchar **names,
12547 const gchar **values,
12548 gpointer user_data,
12553 guint modifiers = 0;
12554 gchar *signal = NULL;
12555 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12557 for (i = 0; names[i]; i++)
12559 if (strcmp (names[i], "key") == 0)
12560 key = gdk_keyval_from_name (values[i]);
12561 else if (strcmp (names[i], "modifiers") == 0)
12563 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12569 else if (strcmp (names[i], "signal") == 0)
12570 signal = g_strdup (values[i]);
12573 if (key == 0 || signal == NULL)
12575 g_warning ("<accelerator> requires key and signal attributes");
12578 parser_data->key = key;
12579 parser_data->modifiers = modifiers;
12580 parser_data->signal = signal;
12583 static const GMarkupParser accel_group_parser =
12585 accel_group_start_element,
12589 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12590 GtkBuilder *builder,
12592 const gchar *tagname,
12593 GMarkupParser *parser,
12596 g_assert (buildable);
12598 if (strcmp (tagname, "accelerator") == 0)
12600 AccelGroupParserData *parser_data;
12602 parser_data = g_slice_new0 (AccelGroupParserData);
12603 parser_data->object = g_object_ref (buildable);
12604 *parser = accel_group_parser;
12605 *data = parser_data;
12608 if (strcmp (tagname, "accessibility") == 0)
12610 AccessibilitySubParserData *parser_data;
12612 parser_data = g_slice_new0 (AccessibilitySubParserData);
12613 *parser = accessibility_parser;
12614 *data = parser_data;
12621 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12622 GtkWidget *toplevel,
12623 gpointer user_data)
12625 AccelGroupParserData *accel_data;
12626 GSList *accel_groups;
12627 GtkAccelGroup *accel_group;
12629 g_return_if_fail (GTK_IS_WIDGET (widget));
12630 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12631 g_return_if_fail (user_data != NULL);
12633 accel_data = (AccelGroupParserData*)user_data;
12634 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12635 if (g_slist_length (accel_groups) == 0)
12637 accel_group = gtk_accel_group_new ();
12638 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12642 g_assert (g_slist_length (accel_groups) == 1);
12643 accel_group = g_slist_nth_data (accel_groups, 0);
12646 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12647 accel_data->signal,
12650 accel_data->modifiers,
12651 GTK_ACCEL_VISIBLE);
12653 g_object_unref (accel_data->object);
12654 g_free (accel_data->signal);
12655 g_slice_free (AccelGroupParserData, accel_data);
12659 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12660 GtkBuilder *builder,
12662 const gchar *tagname,
12663 gpointer user_data)
12665 AccelGroupParserData *accel_data;
12666 AccessibilitySubParserData *a11y_data;
12667 GtkWidget *toplevel;
12669 if (strcmp (tagname, "accelerator") == 0)
12671 accel_data = (AccelGroupParserData*)user_data;
12672 g_assert (accel_data->object);
12674 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12676 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12678 else if (strcmp (tagname, "accessibility") == 0)
12680 a11y_data = (AccessibilitySubParserData*)user_data;
12682 if (a11y_data->actions)
12684 AtkObject *accessible;
12689 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12691 action = ATK_ACTION (accessible);
12692 n_actions = atk_action_get_n_actions (action);
12694 for (l = a11y_data->actions; l; l = l->next)
12696 AtkActionData *action_data = (AtkActionData*)l->data;
12698 for (i = 0; i < n_actions; i++)
12699 if (strcmp (atk_action_get_name (action, i),
12700 action_data->action_name) == 0)
12705 gchar *description;
12707 if (action_data->translatable && action_data->description->len)
12708 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12709 action_data->context,
12710 action_data->description->str);
12712 description = action_data->description->str;
12714 atk_action_set_description (action, i, description);
12718 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12719 g_slist_free (a11y_data->actions);
12722 if (a11y_data->relations)
12723 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12724 a11y_data->relations);
12726 g_slice_free (AccessibilitySubParserData, a11y_data);
12731 gtk_widget_real_get_width (GtkWidget *widget,
12732 gint *minimum_size,
12733 gint *natural_size)
12743 gtk_widget_real_get_height (GtkWidget *widget,
12744 gint *minimum_size,
12745 gint *natural_size)
12755 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12757 gint *minimum_height,
12758 gint *natural_height)
12760 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12764 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12766 gint *minimum_width,
12767 gint *natural_width)
12769 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12773 * gtk_widget_get_halign:
12774 * @widget: a #GtkWidget
12776 * Gets the value of the #GtkWidget:halign property.
12778 * Returns: the horizontal alignment of @widget
12781 gtk_widget_get_halign (GtkWidget *widget)
12783 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12784 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12788 * gtk_widget_set_halign:
12789 * @widget: a #GtkWidget
12790 * @align: the horizontal alignment
12792 * Sets the horizontal alignment of @widget.
12793 * See the #GtkWidget:halign property.
12796 gtk_widget_set_halign (GtkWidget *widget,
12799 GtkWidgetAuxInfo *aux_info;
12801 g_return_if_fail (GTK_IS_WIDGET (widget));
12803 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12805 if (aux_info->halign == align)
12808 aux_info->halign = align;
12809 gtk_widget_queue_resize (widget);
12810 g_object_notify (G_OBJECT (widget), "halign");
12814 * gtk_widget_get_valign:
12815 * @widget: a #GtkWidget
12817 * Gets the value of the #GtkWidget:valign property.
12819 * Returns: the vertical alignment of @widget
12822 gtk_widget_get_valign (GtkWidget *widget)
12824 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12825 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12829 * gtk_widget_set_valign:
12830 * @widget: a #GtkWidget
12831 * @align: the vertical alignment
12833 * Sets the vertical alignment of @widget.
12834 * See the #GtkWidget:valign property.
12837 gtk_widget_set_valign (GtkWidget *widget,
12840 GtkWidgetAuxInfo *aux_info;
12842 g_return_if_fail (GTK_IS_WIDGET (widget));
12844 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12846 if (aux_info->valign == align)
12849 aux_info->valign = align;
12850 gtk_widget_queue_resize (widget);
12851 g_object_notify (G_OBJECT (widget), "valign");
12855 * gtk_widget_get_margin_left:
12856 * @widget: a #GtkWidget
12858 * Gets the value of the #GtkWidget:margin-left property.
12860 * Returns: The left margin of @widget
12863 gtk_widget_get_margin_left (GtkWidget *widget)
12865 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12867 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12871 * gtk_widget_set_margin_left:
12872 * @widget: a #GtkWidget
12873 * @margin: the left margin
12875 * Sets the left margin of @widget.
12876 * See the #GtkWidget:margin-left property.
12879 gtk_widget_set_margin_left (GtkWidget *widget,
12882 GtkWidgetAuxInfo *aux_info;
12884 g_return_if_fail (GTK_IS_WIDGET (widget));
12885 g_return_if_fail (margin <= G_MAXINT16);
12887 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12889 if (aux_info->margin.left == margin)
12892 aux_info->margin.left = margin;
12893 gtk_widget_queue_resize (widget);
12894 g_object_notify (G_OBJECT (widget), "margin-left");
12898 * gtk_widget_get_margin_right:
12899 * @widget: a #GtkWidget
12901 * Gets the value of the #GtkWidget:margin-right property.
12903 * Returns: The left margin of @widget
12906 gtk_widget_get_margin_right (GtkWidget *widget)
12908 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12910 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12914 * gtk_widget_set_margin_right:
12915 * @widget: a #GtkWidget
12916 * @margin: the right margin
12918 * Sets the right margin of @widget.
12919 * See the #GtkWidget:margin-right property.
12922 gtk_widget_set_margin_right (GtkWidget *widget,
12925 GtkWidgetAuxInfo *aux_info;
12927 g_return_if_fail (GTK_IS_WIDGET (widget));
12928 g_return_if_fail (margin <= G_MAXINT16);
12930 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12932 if (aux_info->margin.right == margin)
12935 aux_info->margin.right = margin;
12936 gtk_widget_queue_resize (widget);
12937 g_object_notify (G_OBJECT (widget), "margin-right");
12941 * gtk_widget_get_margin_top:
12942 * @widget: a #GtkWidget
12944 * Gets the value of the #GtkWidget:margin-top property.
12946 * Returns: The top margin of @widget
12949 gtk_widget_get_margin_top (GtkWidget *widget)
12951 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12953 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12957 * gtk_widget_set_margin_top:
12958 * @widget: a #GtkWidget
12959 * @margin: the top margin
12961 * Sets the top margin of @widget.
12962 * See the #GtkWidget:margin-top property.
12965 gtk_widget_set_margin_top (GtkWidget *widget,
12968 GtkWidgetAuxInfo *aux_info;
12970 g_return_if_fail (GTK_IS_WIDGET (widget));
12971 g_return_if_fail (margin <= G_MAXINT16);
12973 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12975 if (aux_info->margin.top == margin)
12978 aux_info->margin.top = margin;
12979 gtk_widget_queue_resize (widget);
12980 g_object_notify (G_OBJECT (widget), "margin-top");
12984 * gtk_widget_get_margin_bottom:
12985 * @widget: a #GtkWidget
12987 * Gets the value of the #GtkWidget:margin-bottom property.
12989 * Returns: The bottom margin of @widget
12992 gtk_widget_get_margin_bottom (GtkWidget *widget)
12994 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12996 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13000 * gtk_widget_set_margin_bottom:
13001 * @widget: a #GtkWidget
13002 * @margin: the bottom margin
13004 * Sets the bottom margin of @widget.
13005 * See the #GtkWidget:margin-bottom property.
13008 gtk_widget_set_margin_bottom (GtkWidget *widget,
13011 GtkWidgetAuxInfo *aux_info;
13013 g_return_if_fail (GTK_IS_WIDGET (widget));
13014 g_return_if_fail (margin <= G_MAXINT16);
13016 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13018 if (aux_info->margin.bottom == margin)
13021 aux_info->margin.bottom = margin;
13022 gtk_widget_queue_resize (widget);
13023 g_object_notify (G_OBJECT (widget), "margin-bottom");
13027 * gtk_widget_get_clipboard:
13028 * @widget: a #GtkWidget
13029 * @selection: a #GdkAtom which identifies the clipboard
13030 * to use. %GDK_SELECTION_CLIPBOARD gives the
13031 * default clipboard. Another common value
13032 * is %GDK_SELECTION_PRIMARY, which gives
13033 * the primary X selection.
13035 * Returns the clipboard object for the given selection to
13036 * be used with @widget. @widget must have a #GdkDisplay
13037 * associated with it, so must be attached to a toplevel
13040 * Return value: (transfer none): the appropriate clipboard object. If no
13041 * clipboard already exists, a new one will
13042 * be created. Once a clipboard object has
13043 * been created, it is persistent for all time.
13048 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13050 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13051 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13053 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13058 * gtk_widget_list_mnemonic_labels:
13059 * @widget: a #GtkWidget
13061 * Returns a newly allocated list of the widgets, normally labels, for
13062 * which this widget is the target of a mnemonic (see for example,
13063 * gtk_label_set_mnemonic_widget()).
13065 * The widgets in the list are not individually referenced. If you
13066 * want to iterate through the list and perform actions involving
13067 * callbacks that might destroy the widgets, you
13068 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13069 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13070 * widgets afterwards.
13072 * Return value: (element-type GtkWidget) (transfer container): the list of
13073 * mnemonic labels; free this list
13074 * with g_list_free() when you are done with it.
13079 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13081 GList *list = NULL;
13084 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13086 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13087 list = g_list_prepend (list, l->data);
13093 * gtk_widget_add_mnemonic_label:
13094 * @widget: a #GtkWidget
13095 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13097 * Adds a widget to the list of mnemonic labels for
13098 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13099 * list of mnemonic labels for the widget is cleared when the
13100 * widget is destroyed, so the caller must make sure to update
13101 * its internal state at this point as well, by using a connection
13102 * to the #GtkWidget::destroy signal or a weak notifier.
13107 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13110 GSList *old_list, *new_list;
13112 g_return_if_fail (GTK_IS_WIDGET (widget));
13113 g_return_if_fail (GTK_IS_WIDGET (label));
13115 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13116 new_list = g_slist_prepend (old_list, label);
13118 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13119 new_list, (GDestroyNotify) g_slist_free);
13123 * gtk_widget_remove_mnemonic_label:
13124 * @widget: a #GtkWidget
13125 * @label: a #GtkWidget that was previously set as a mnemnic label for
13126 * @widget with gtk_widget_add_mnemonic_label().
13128 * Removes a widget from the list of mnemonic labels for
13129 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13130 * must have previously been added to the list with
13131 * gtk_widget_add_mnemonic_label().
13136 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13139 GSList *old_list, *new_list;
13141 g_return_if_fail (GTK_IS_WIDGET (widget));
13142 g_return_if_fail (GTK_IS_WIDGET (label));
13144 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13145 new_list = g_slist_remove (old_list, label);
13148 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13149 new_list, (GDestroyNotify) g_slist_free);
13153 * gtk_widget_get_no_show_all:
13154 * @widget: a #GtkWidget
13156 * Returns the current value of the #GtkWidget:no-show-all property,
13157 * which determines whether calls to gtk_widget_show_all()
13158 * will affect this widget.
13160 * Return value: the current value of the "no-show-all" property.
13165 gtk_widget_get_no_show_all (GtkWidget *widget)
13167 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13169 return widget->priv->no_show_all;
13173 * gtk_widget_set_no_show_all:
13174 * @widget: a #GtkWidget
13175 * @no_show_all: the new value for the "no-show-all" property
13177 * Sets the #GtkWidget:no-show-all property, which determines whether
13178 * calls to gtk_widget_show_all() will affect this widget.
13180 * This is mostly for use in constructing widget hierarchies with externally
13181 * controlled visibility, see #GtkUIManager.
13186 gtk_widget_set_no_show_all (GtkWidget *widget,
13187 gboolean no_show_all)
13189 g_return_if_fail (GTK_IS_WIDGET (widget));
13191 no_show_all = (no_show_all != FALSE);
13193 if (widget->priv->no_show_all != no_show_all)
13195 widget->priv->no_show_all = no_show_all;
13197 g_object_notify (G_OBJECT (widget), "no-show-all");
13203 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13204 gboolean has_tooltip,
13207 GtkWidgetPrivate *priv = widget->priv;
13208 gboolean priv_has_tooltip;
13210 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13211 quark_has_tooltip));
13213 if (priv_has_tooltip != has_tooltip || force)
13215 priv_has_tooltip = has_tooltip;
13217 if (priv_has_tooltip)
13219 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13220 gdk_window_set_events (priv->window,
13221 gdk_window_get_events (priv->window) |
13222 GDK_LEAVE_NOTIFY_MASK |
13223 GDK_POINTER_MOTION_MASK |
13224 GDK_POINTER_MOTION_HINT_MASK);
13226 if (gtk_widget_get_has_window (widget))
13227 gtk_widget_add_events (widget,
13228 GDK_LEAVE_NOTIFY_MASK |
13229 GDK_POINTER_MOTION_MASK |
13230 GDK_POINTER_MOTION_HINT_MASK);
13233 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13234 GUINT_TO_POINTER (priv_has_tooltip));
13239 * gtk_widget_set_tooltip_window:
13240 * @widget: a #GtkWidget
13241 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13243 * Replaces the default, usually yellow, window used for displaying
13244 * tooltips with @custom_window. GTK+ will take care of showing and
13245 * hiding @custom_window at the right moment, to behave likewise as
13246 * the default tooltip window. If @custom_window is %NULL, the default
13247 * tooltip window will be used.
13249 * If the custom window should have the default theming it needs to
13250 * have the name "gtk-tooltip", see gtk_widget_set_name().
13255 gtk_widget_set_tooltip_window (GtkWidget *widget,
13256 GtkWindow *custom_window)
13258 gboolean has_tooltip;
13259 gchar *tooltip_markup;
13261 g_return_if_fail (GTK_IS_WIDGET (widget));
13262 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13264 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13267 g_object_ref (custom_window);
13269 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13270 custom_window, g_object_unref);
13272 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13273 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13275 if (has_tooltip && gtk_widget_get_visible (widget))
13276 gtk_widget_queue_tooltip_query (widget);
13280 * gtk_widget_get_tooltip_window:
13281 * @widget: a #GtkWidget
13283 * Returns the #GtkWindow of the current tooltip. This can be the
13284 * GtkWindow created by default, or the custom tooltip window set
13285 * using gtk_widget_set_tooltip_window().
13287 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13292 gtk_widget_get_tooltip_window (GtkWidget *widget)
13294 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13296 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13300 * gtk_widget_trigger_tooltip_query:
13301 * @widget: a #GtkWidget
13303 * Triggers a tooltip query on the display where the toplevel of @widget
13304 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13310 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13312 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13315 static guint tooltip_query_id;
13316 static GSList *tooltip_query_displays;
13319 tooltip_query_idle (gpointer data)
13321 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13322 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13323 g_slist_free (tooltip_query_displays);
13325 tooltip_query_displays = NULL;
13326 tooltip_query_id = 0;
13332 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13334 GdkDisplay *display;
13336 display = gtk_widget_get_display (widget);
13338 if (!g_slist_find (tooltip_query_displays, display))
13339 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13341 if (tooltip_query_id == 0)
13342 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13346 * gtk_widget_set_tooltip_text:
13347 * @widget: a #GtkWidget
13348 * @text: the contents of the tooltip for @widget
13350 * Sets @text as the contents of the tooltip. This function will take
13351 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13352 * handler for the #GtkWidget::query-tooltip signal.
13354 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13359 gtk_widget_set_tooltip_text (GtkWidget *widget,
13362 g_return_if_fail (GTK_IS_WIDGET (widget));
13364 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13368 * gtk_widget_get_tooltip_text:
13369 * @widget: a #GtkWidget
13371 * Gets the contents of the tooltip for @widget.
13373 * Return value: the tooltip text, or %NULL. You should free the
13374 * returned string with g_free() when done.
13379 gtk_widget_get_tooltip_text (GtkWidget *widget)
13381 gchar *text = NULL;
13383 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13385 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13391 * gtk_widget_set_tooltip_markup:
13392 * @widget: a #GtkWidget
13393 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13395 * Sets @markup as the contents of the tooltip, which is marked up with
13396 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13398 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13399 * and of the default handler for the #GtkWidget::query-tooltip signal.
13401 * See also the #GtkWidget:tooltip-markup property and
13402 * gtk_tooltip_set_markup().
13407 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13408 const gchar *markup)
13410 g_return_if_fail (GTK_IS_WIDGET (widget));
13412 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13416 * gtk_widget_get_tooltip_markup:
13417 * @widget: a #GtkWidget
13419 * Gets the contents of the tooltip for @widget.
13421 * Return value: the tooltip text, or %NULL. You should free the
13422 * returned string with g_free() when done.
13427 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13429 gchar *text = NULL;
13431 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13433 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13439 * gtk_widget_set_has_tooltip:
13440 * @widget: a #GtkWidget
13441 * @has_tooltip: whether or not @widget has a tooltip.
13443 * Sets the has-tooltip property on @widget to @has_tooltip. See
13444 * #GtkWidget:has-tooltip for more information.
13449 gtk_widget_set_has_tooltip (GtkWidget *widget,
13450 gboolean has_tooltip)
13452 g_return_if_fail (GTK_IS_WIDGET (widget));
13454 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13458 * gtk_widget_get_has_tooltip:
13459 * @widget: a #GtkWidget
13461 * Returns the current value of the has-tooltip property. See
13462 * #GtkWidget:has-tooltip for more information.
13464 * Return value: current value of has-tooltip on @widget.
13469 gtk_widget_get_has_tooltip (GtkWidget *widget)
13471 gboolean has_tooltip = FALSE;
13473 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13475 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13477 return has_tooltip;
13481 * gtk_widget_get_allocation:
13482 * @widget: a #GtkWidget
13483 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13485 * Retrieves the widget's allocation.
13487 * Note, when implementing a #GtkContainer: a widget's allocation will
13488 * be its "adjusted" allocation, that is, the widget's parent
13489 * container typically calls gtk_widget_size_allocate() with an
13490 * allocation, and that allocation is then adjusted (to handle margin
13491 * and alignment for example) before assignment to the widget.
13492 * gtk_widget_get_allocation() returns the adjusted allocation that
13493 * was actually assigned to the widget. The adjusted allocation is
13494 * guaranteed to be completely contained within the
13495 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13496 * is guaranteed that its children stay inside the assigned bounds,
13497 * but not that they have exactly the bounds the container assigned.
13498 * There is no way to get the original allocation assigned by
13499 * gtk_widget_size_allocate(), since it isn't stored; if a container
13500 * implementation needs that information it will have to track it itself.
13505 gtk_widget_get_allocation (GtkWidget *widget,
13506 GtkAllocation *allocation)
13508 GtkWidgetPrivate *priv;
13510 g_return_if_fail (GTK_IS_WIDGET (widget));
13511 g_return_if_fail (allocation != NULL);
13513 priv = widget->priv;
13515 *allocation = priv->allocation;
13519 * gtk_widget_set_allocation:
13520 * @widget: a #GtkWidget
13521 * @allocation: a pointer to a #GtkAllocation to copy from
13523 * Sets the widget's allocation. This should not be used
13524 * directly, but from within a widget's size_allocate method.
13526 * The allocation set should be the "adjusted" or actual
13527 * allocation. If you're implementing a #GtkContainer, you want to use
13528 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13529 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13530 * allocation inside gtk_widget_size_allocate() to create an adjusted
13536 gtk_widget_set_allocation (GtkWidget *widget,
13537 const GtkAllocation *allocation)
13539 GtkWidgetPrivate *priv;
13541 g_return_if_fail (GTK_IS_WIDGET (widget));
13542 g_return_if_fail (allocation != NULL);
13544 priv = widget->priv;
13546 priv->allocation = *allocation;
13550 * gtk_widget_get_allocated_width:
13551 * @widget: the widget to query
13553 * Returns the width that has currently been allocated to @widget.
13554 * This function is intended to be used when implementing handlers
13555 * for the #GtkWidget::draw function.
13557 * Returns: the width of the @widget
13560 gtk_widget_get_allocated_width (GtkWidget *widget)
13562 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13564 return widget->priv->allocation.width;
13568 * gtk_widget_get_allocated_height:
13569 * @widget: the widget to query
13571 * Returns the height that has currently been allocated to @widget.
13572 * This function is intended to be used when implementing handlers
13573 * for the #GtkWidget::draw function.
13575 * Returns: the height of the @widget
13578 gtk_widget_get_allocated_height (GtkWidget *widget)
13580 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13582 return widget->priv->allocation.height;
13586 * gtk_widget_get_requisition:
13587 * @widget: a #GtkWidget
13588 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13590 * Retrieves the widget's requisition.
13592 * This function should only be used by widget implementations in
13593 * order to figure whether the widget's requisition has actually
13594 * changed after some internal state change (so that they can call
13595 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13597 * Normally, gtk_widget_size_request() should be used.
13601 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13602 * removed, If you need to cache sizes across requests and allocations,
13603 * add an explicit cache to the widget in question instead.
13606 gtk_widget_get_requisition (GtkWidget *widget,
13607 GtkRequisition *requisition)
13609 g_return_if_fail (GTK_IS_WIDGET (widget));
13610 g_return_if_fail (requisition != NULL);
13612 gtk_widget_get_preferred_size (widget, requisition, NULL);
13616 * gtk_widget_set_window:
13617 * @widget: a #GtkWidget
13618 * @window: a #GdkWindow
13620 * Sets a widget's window. This function should only be used in a
13621 * widget's #GtkWidget::realize implementation. The %window passed is
13622 * usually either new window created with gdk_window_new(), or the
13623 * window of its parent widget as returned by
13624 * gtk_widget_get_parent_window().
13626 * Widgets must indicate whether they will create their own #GdkWindow
13627 * by calling gtk_widget_set_has_window(). This is usually done in the
13628 * widget's init() function.
13630 * <note><para>This function does not add any reference to @window.</para></note>
13635 gtk_widget_set_window (GtkWidget *widget,
13638 GtkWidgetPrivate *priv;
13640 g_return_if_fail (GTK_IS_WIDGET (widget));
13641 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13643 priv = widget->priv;
13645 if (priv->window != window)
13647 priv->window = window;
13648 g_object_notify (G_OBJECT (widget), "window");
13653 * gtk_widget_get_window:
13654 * @widget: a #GtkWidget
13656 * Returns the widget's window if it is realized, %NULL otherwise
13658 * Return value: (transfer none): @widget's window.
13663 gtk_widget_get_window (GtkWidget *widget)
13665 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13667 return widget->priv->window;
13671 * gtk_widget_get_support_multidevice:
13672 * @widget: a #GtkWidget
13674 * Returns %TRUE if @widget is multiple pointer aware. See
13675 * gtk_widget_set_support_multidevice() for more information.
13677 * Returns: %TRUE is @widget is multidevice aware.
13680 gtk_widget_get_support_multidevice (GtkWidget *widget)
13682 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13684 return widget->priv->multidevice;
13688 * gtk_widget_set_support_multidevice:
13689 * @widget: a #GtkWidget
13690 * @support_multidevice: %TRUE to support input from multiple devices.
13692 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13693 * @widget will start receiving multiple, per device enter/leave events. Note
13694 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13695 * gdk_window_set_support_multidevice() will have to be called manually on them.
13700 gtk_widget_set_support_multidevice (GtkWidget *widget,
13701 gboolean support_multidevice)
13703 GtkWidgetPrivate *priv;
13705 g_return_if_fail (GTK_IS_WIDGET (widget));
13707 priv = widget->priv;
13709 if (support_multidevice)
13711 priv->multidevice = TRUE;
13712 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13716 priv->multidevice = FALSE;
13717 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13720 if (gtk_widget_get_realized (widget))
13721 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13725 _gtk_widget_set_has_focus (GtkWidget *widget,
13726 gboolean has_focus)
13728 widget->priv->has_focus = has_focus;
13732 * gtk_widget_send_focus_change:
13733 * @widget: a #GtkWidget
13734 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13736 * Sends the focus change @event to @widget
13738 * This function is not meant to be used by applications. The only time it
13739 * should be used is when it is necessary for a #GtkWidget to assign focus
13740 * to a widget that is semantically owned by the first widget even though
13741 * it's not a direct child - for instance, a search entry in a floating
13742 * window similar to the quick search in #GtkTreeView.
13744 * An example of its usage is:
13747 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13749 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13750 * fevent->focus_change.in = TRUE;
13751 * fevent->focus_change.window = gtk_widget_get_window (widget);
13752 * if (fevent->focus_change.window != NULL)
13753 * g_object_ref (fevent->focus_change.window);
13755 * gtk_widget_send_focus_change (widget, fevent);
13757 * gdk_event_free (event);
13760 * Return value: the return value from the event signal emission: %TRUE
13761 * if the event was handled, and %FALSE otherwise
13766 gtk_widget_send_focus_change (GtkWidget *widget,
13771 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13772 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13774 g_object_ref (widget);
13776 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13778 res = gtk_widget_event (widget, event);
13780 g_object_notify (G_OBJECT (widget), "has-focus");
13782 g_object_unref (widget);
13788 * gtk_widget_in_destruction:
13789 * @widget: a #GtkWidget
13791 * Returns whether the widget is currently being destroyed.
13792 * This information can sometimes be used to avoid doing
13793 * unnecessary work.
13795 * Returns: %TRUE if @widget is being destroyed
13798 gtk_widget_in_destruction (GtkWidget *widget)
13800 return widget->priv->in_destruction;
13804 _gtk_widget_get_resize_pending (GtkWidget *widget)
13806 return widget->priv->resize_pending;
13810 _gtk_widget_set_resize_pending (GtkWidget *widget,
13811 gboolean resize_pending)
13813 widget->priv->resize_pending = resize_pending;
13817 _gtk_widget_get_in_reparent (GtkWidget *widget)
13819 return widget->priv->in_reparent;
13823 _gtk_widget_set_in_reparent (GtkWidget *widget,
13824 gboolean in_reparent)
13826 widget->priv->in_reparent = in_reparent;
13830 _gtk_widget_get_anchored (GtkWidget *widget)
13832 return widget->priv->anchored;
13836 _gtk_widget_set_anchored (GtkWidget *widget,
13839 widget->priv->anchored = anchored;
13843 _gtk_widget_get_shadowed (GtkWidget *widget)
13845 return widget->priv->shadowed;
13849 _gtk_widget_set_shadowed (GtkWidget *widget,
13852 widget->priv->shadowed = shadowed;
13856 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13858 return widget->priv->alloc_needed;
13862 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13863 gboolean alloc_needed)
13865 widget->priv->alloc_needed = alloc_needed;
13869 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13871 return widget->priv->width_request_needed;
13875 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13876 gboolean width_request_needed)
13878 widget->priv->width_request_needed = width_request_needed;
13882 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13884 return widget->priv->height_request_needed;
13888 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13889 gboolean height_request_needed)
13891 widget->priv->height_request_needed = height_request_needed;
13895 * gtk_widget_get_path:
13896 * @widget: a #GtkWidget
13898 * Returns the #GtkWidgetPath representing @widget, if the widget
13899 * is not connected to a toplevel widget, a partial path will be
13902 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13905 gtk_widget_get_path (GtkWidget *widget)
13907 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13909 /* As strange as it may seem, this may happen on object construction.
13910 * init() implementations of parent types may eventually call this function,
13911 * each with its corresponding GType, which could leave a child
13912 * implementation with a wrong widget type in the widget path
13914 if (widget->priv->path &&
13915 G_OBJECT_TYPE (widget) != gtk_widget_path_get_widget_type (widget->priv->path))
13917 gtk_widget_path_free (widget->priv->path);
13918 widget->priv->path = NULL;
13921 if (!widget->priv->path)
13926 parent = widget->priv->parent;
13929 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13932 /* Widget is either toplevel or unparented, treat both
13933 * as toplevels style wise, since there are situations
13934 * where style properties might be retrieved on that
13937 widget->priv->path = gtk_widget_path_new ();
13940 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13942 if (widget->priv->name)
13943 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13945 if (widget->priv->context)
13946 gtk_style_context_set_path (widget->priv->context,
13947 widget->priv->path);
13950 return widget->priv->path;
13954 style_context_changed (GtkStyleContext *context,
13955 gpointer user_data)
13957 GtkWidget *widget = user_data;
13959 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13963 * gtk_widget_get_style_context:
13964 * @widget: a #GtkWidget
13966 * Returns the style context associated to @widget.
13968 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13969 * must not be freed.
13972 gtk_widget_get_style_context (GtkWidget *widget)
13974 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13976 if (G_UNLIKELY (!widget->priv->context))
13978 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13979 "direction", gtk_widget_get_direction (widget),
13982 g_signal_connect (widget->priv->context, "changed",
13983 G_CALLBACK (style_context_changed), widget);
13985 gtk_style_context_set_screen (widget->priv->context,
13986 gtk_widget_get_screen (widget));
13988 _gtk_widget_update_path (widget);
13989 gtk_style_context_set_path (widget->priv->context,
13990 widget->priv->path);
13994 /* Force widget path regeneration if needed, the
13995 * context will be updated within this function.
13997 gtk_widget_get_path (widget);
14000 return widget->priv->context;