1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkcontainer.h"
32 #include "gtkaccelmap.h"
33 #include "gtkclipboard.h"
34 #include "gtkiconfactory.h"
37 #include "gtkmarshalers.h"
39 #include "gtkselection.h"
40 #include "gtksettings.h"
41 #include "gtksizegroup-private.h"
42 #include "gtkwidget.h"
43 #include "gtkwidgetprivate.h"
44 #include "gtkwindowprivate.h"
45 #include "gtkbindings.h"
46 #include "gtkprivate.h"
48 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
49 #include <gobject/gvaluecollector.h>
50 #include <gobject/gobjectnotifyqueue.c>
51 #include <cairo-gobject.h>
52 #include "gdk/gdkkeysyms.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
59 #include "gtkstylecontext.h"
60 #include "gtksymboliccolor.h"
61 #include "gtkcssprovider.h"
62 #include "gtkanimationdescription.h"
63 #include "gtkmodifierstyle.h"
64 #include "gtkversion.h"
70 * @Short_description: Base class for all widgets
73 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
74 * widget lifecycle, states and style.
76 * <refsect2 id="geometry-management">
77 * <title>Height-for-width Geometry Management</title>
79 * GTK+ uses a height-for-width (and width-for-height) geometry management
80 * system. Height-for-width means that a widget can change how much
81 * vertical space it needs, depending on the amount of horizontal space
82 * that it is given (and similar for width-for-height). The most common
83 * example is a label that reflows to fill up the available width, wraps
84 * to fewer lines, and therefore needs less height.
86 * Height-for-width geometry management is implemented in GTK+ by way
87 * of five virtual methods:
89 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
96 * There are some important things to keep in mind when implementing
97 * height-for-width and when using it in container implementations.
99 * The geometry management system will query a widget hierarchy in
100 * only one orientation at a time. When widgets are initially queried
101 * for their minimum sizes it is generally done in two initial passes
102 * in the #GtkSizeRequestMode chosen by the toplevel.
104 * For example, when queried in the normal
105 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
106 * First, the default minimum and natural width for each widget
107 * in the interface will be computed using gtk_width_get_preferred_width().
108 * Because the preferred widths for each container depend on the preferred
109 * widths of their children, this information propagates up the hierarchy,
110 * and finally a minimum and natural width is determined for the entire
111 * toplevel. Next, the toplevel will use the minimum width to query for the
112 * minimum height contextual to that width using
113 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
114 * recursive operation. The minimum height for the minimum width is normally
115 * used to set the minimum size constraint on the toplevel
116 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
118 * After the toplevel window has initially requested its size in both
119 * dimensions it can go on to allocate itself a reasonable size (or a size
120 * previously specified with gtk_window_set_default_size()). During the
121 * recursive allocation process it's important to note that request cycles
122 * will be recursively executed while container widgets allocate their children.
123 * Each container widget, once allocated a size, will go on to first share the
124 * space in one orientation among its children and then request each child's
125 * height for its target allocated width or its width for allocated height,
126 * depending. In this way a #GtkWidget will typically be requested its size
127 * a number of times before actually being allocated a size. The size a
128 * widget is finally allocated can of course differ from the size it has
129 * requested. For this reason, #GtkWidget caches a small number of results
130 * to avoid re-querying for the same sizes in one allocation cycle.
132 * See <link linkend="container-geometry-management">GtkContainer's
133 * geometry management section</link>
134 * to learn more about how height-for-width allocations are performed
135 * by container widgets.
137 * If a widget does move content around to intelligently use up the
138 * allocated size then it must support the request in both
139 * #GtkSizeRequestModes even if the widget in question only
140 * trades sizes in a single orientation.
142 * For instance, a #GtkLabel that does height-for-width word wrapping
143 * will not expect to have #GtkWidgetClass.get_preferred_height() called
144 * because that call is specific to a width-for-height request. In this
145 * case the label must return the height required for its own minimum
146 * possible width. By following this rule any widget that handles
147 * height-for-width or width-for-height requests will always be allocated
148 * at least enough space to fit its own content.
150 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
151 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
153 * <programlisting><![CDATA[
155 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
157 * if (i_am_in_height_for_width_mode)
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
163 * min_height, nat_height);
167 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
168 * it will return the minimum and natural height for the rotated label here.
171 * ]]></programlisting>
173 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
174 * the minimum and natural width:
176 * <programlisting><![CDATA[
178 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
179 * gint *min_width, gint *nat_width)
181 * if (i_am_in_height_for_width_mode)
183 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
187 * ... again if a widget is sometimes operating in width-for-height mode
188 * (like a rotated GtkLabel) it can go ahead and do its real width for
189 * height calculation here.
192 * ]]></programlisting>
194 * Often a widget needs to get its own request during size request or
195 * allocation. For example, when computing height it may need to also
196 * compute width. Or when deciding how to use an allocation, the widget
197 * may need to know its natural size. In these cases, the widget should
198 * be careful to call its virtual methods directly, like this:
200 * <title>Widget calling its own size request method.</title>
202 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
207 * It will not work to use the wrapper functions, such as
208 * gtk_widget_get_preferred_width() inside your own size request
209 * implementation. These return a request adjusted by #GtkSizeGroup
210 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
211 * widget used the wrappers inside its virtual method implementations,
212 * then the adjustments (such as widget margins) would be applied
213 * twice. GTK+ therefore does not allow this and will warn if you try
216 * Of course if you are getting the size request for
217 * <emphasis>another</emphasis> widget, such as a child of a
218 * container, you <emphasis>must</emphasis> use the wrapper APIs.
219 * Otherwise, you would not properly consider widget margins,
220 * #GtkSizeGroup, and so forth.
223 * <refsect2 id="style-properties">
224 * <title>Style Properties</title>
226 * <structname>GtkWidget</structname> introduces <firstterm>style
227 * properties</firstterm> - these are basically object properties that are stored
228 * not on the object, but in the style object associated to the widget. Style
229 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
230 * This mechanism is used for configuring such things as the location of the
231 * scrollbar arrows through the theme, giving theme authors more control over the
232 * look of applications without the need to write a theme engine in C.
235 * Use gtk_widget_class_install_style_property() to install style properties for
236 * a widget class, gtk_widget_class_find_style_property() or
237 * gtk_widget_class_list_style_properties() to get information about existing
238 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
239 * gtk_widget_style_get_valist() to obtain the value of a style property.
242 * <refsect2 id="GtkWidget-BUILDER-UI">
243 * <title>GtkWidget as GtkBuildable</title>
245 * The GtkWidget implementation of the GtkBuildable interface supports a
246 * custom <accelerator> element, which has attributes named key,
247 * modifiers and signal and allows to specify accelerators.
250 * <title>A UI definition fragment specifying an accelerator</title>
251 * <programlisting><![CDATA[
252 * <object class="GtkButton">
253 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
255 * ]]></programlisting>
258 * In addition to accelerators, <structname>GtkWidget</structname> also support a
259 * custom <accessible> element, which supports actions and relations.
260 * Properties on the accessible implementation of an object can be set by accessing the
261 * internal child "accessible" of a <structname>GtkWidget</structname>.
264 * <title>A UI definition fragment specifying an accessible</title>
265 * <programlisting><![CDATA[
266 * <object class="GtkButton" id="label1"/>
267 * <property name="label">I am a Label for a Button</property>
269 * <object class="GtkButton" id="button1">
271 * <action action_name="click" translatable="yes">Click the button.</action>
272 * <relation target="label1" type="labelled-by"/>
274 * <child internal-child="accessible">
275 * <object class="AtkObject" id="a11y-button1">
276 * <property name="AtkObject::name">Clickable Button</property>
280 * ]]></programlisting>
285 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
286 #define INIT_PATH_SIZE (512)
288 struct _GtkWidgetPrivate
290 /* The state of the widget. There are actually only
291 * 5 widget states (defined in "gtkenums.h")
294 guint state_flags : 6;
298 guint in_destruction : 1;
301 guint composite_child : 1;
307 guint parent_sensitive : 1;
310 guint can_default : 1;
311 guint has_default : 1;
312 guint receives_default : 1;
316 guint user_style : 1;
317 guint app_paintable : 1;
318 guint double_buffered : 1;
319 guint redraw_on_alloc : 1;
320 guint no_show_all : 1;
321 guint child_visible : 1;
322 guint multidevice : 1;
323 guint has_shape_mask : 1;
324 guint in_reparent : 1;
325 guint resize_pending : 1;
326 guint alloc_needed : 1;
327 guint width_request_needed : 1;
328 guint height_request_needed : 1;
330 /* Expand-related flags */
331 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
332 guint computed_hexpand : 1; /* computed results (composite of child flags) */
333 guint computed_vexpand : 1;
334 guint hexpand : 1; /* application-forced expand */
336 guint hexpand_set : 1; /* whether to use application-forced */
337 guint vexpand_set : 1; /* instead of computing from children */
339 /* The widget's name. If the widget does not have a name
340 * (the name is NULL), then its name (as returned by
341 * "gtk_widget_get_name") is its class's name.
342 * Among other things, the widget name is used to determine
343 * the style to use for a widget.
347 /* The style for the widget. The style contains the
348 * colors the widget should be drawn in for each state
349 * along with graphics contexts used to draw with and
350 * the font to use for text.
353 GtkStyleContext *context;
355 /* The widget's allocated size.
357 GtkAllocation allocation;
359 /* The widget's requested sizes */
360 SizeRequestCache requests;
362 /* The widget's window or its parent window if it does
363 * not have a window. (Which will be indicated by the
364 * GTK_NO_WINDOW flag being set).
368 /* The widget's parent.
372 /* Widget's path for styling */
402 BUTTON_RELEASE_EVENT,
417 PROPERTY_NOTIFY_EVENT,
418 SELECTION_CLEAR_EVENT,
419 SELECTION_REQUEST_EVENT,
420 SELECTION_NOTIFY_EVENT,
426 VISIBILITY_NOTIFY_EVENT,
440 ACCEL_CLOSURES_CHANGED,
464 PROP_RECEIVES_DEFAULT,
465 PROP_COMPOSITE_CHILD,
473 PROP_DOUBLE_BUFFERED,
488 typedef struct _GtkStateData GtkStateData;
491 STATE_CHANGE_REPLACE,
500 guint parent_sensitive : 1;
501 guint use_forall : 1;
504 /* --- prototypes --- */
505 static void gtk_widget_class_init (GtkWidgetClass *klass);
506 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
507 static void gtk_widget_init (GtkWidget *widget);
508 static void gtk_widget_set_property (GObject *object,
512 static void gtk_widget_get_property (GObject *object,
516 static void gtk_widget_dispose (GObject *object);
517 static void gtk_widget_real_destroy (GtkWidget *object);
518 static void gtk_widget_finalize (GObject *object);
519 static void gtk_widget_real_show (GtkWidget *widget);
520 static void gtk_widget_real_hide (GtkWidget *widget);
521 static void gtk_widget_real_map (GtkWidget *widget);
522 static void gtk_widget_real_unmap (GtkWidget *widget);
523 static void gtk_widget_real_realize (GtkWidget *widget);
524 static void gtk_widget_real_unrealize (GtkWidget *widget);
525 static void gtk_widget_real_size_allocate (GtkWidget *widget,
526 GtkAllocation *allocation);
527 static void gtk_widget_real_style_set (GtkWidget *widget,
528 GtkStyle *previous_style);
529 static void gtk_widget_real_direction_changed(GtkWidget *widget,
530 GtkTextDirection previous_direction);
532 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
533 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
536 gboolean keyboard_tip,
537 GtkTooltip *tooltip);
538 static void gtk_widget_real_style_updated (GtkWidget *widget);
539 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
540 GtkWidgetHelpType help_type);
542 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
544 GParamSpec **pspecs);
545 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
547 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
549 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
550 GdkEventFocus *event);
551 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
552 GdkEventFocus *event);
553 static gboolean gtk_widget_real_focus (GtkWidget *widget,
554 GtkDirectionType direction);
555 static void gtk_widget_real_move_focus (GtkWidget *widget,
556 GtkDirectionType direction);
557 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
558 GtkDirectionType direction);
559 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
560 static void gtk_widget_update_pango_context (GtkWidget *widget);
561 static void gtk_widget_propagate_state (GtkWidget *widget,
563 static void gtk_widget_reset_rc_style (GtkWidget *widget);
564 static void gtk_widget_set_style_internal (GtkWidget *widget,
566 gboolean initial_emission);
567 static gint gtk_widget_event_internal (GtkWidget *widget,
569 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
570 gboolean group_cycling);
571 static void gtk_widget_real_get_width (GtkWidget *widget,
574 static void gtk_widget_real_get_height (GtkWidget *widget,
577 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
579 gint *minimum_height,
580 gint *natural_height);
581 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
584 gint *natural_width);
585 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
586 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
587 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
588 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
589 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
590 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
591 cairo_region_t *region);
592 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
593 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
594 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
597 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
598 gboolean has_tooltip,
600 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
601 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
603 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
604 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
606 const gchar *childname);
607 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
610 const GValue *value);
611 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
614 const gchar *tagname,
615 GMarkupParser *parser,
617 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
620 const gchar *tagname,
622 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
623 GtkBuilder *builder);
625 static void gtk_widget_real_get_width (GtkWidget *widget,
628 static void gtk_widget_real_get_height (GtkWidget *widget,
632 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
635 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
636 GtkOrientation orientation,
639 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
640 GtkOrientation orientation,
644 gint *allocated_size);
646 static void gtk_widget_set_usize_internal (GtkWidget *widget,
649 GtkQueueResizeFlags flags);
651 static void gtk_widget_add_events_internal (GtkWidget *widget,
655 /* --- variables --- */
656 static gpointer gtk_widget_parent_class = NULL;
657 static guint widget_signals[LAST_SIGNAL] = { 0 };
658 static GtkStyle *gtk_default_style = NULL;
659 static guint composite_child_stack = 0;
660 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
661 static GParamSpecPool *style_property_spec_pool = NULL;
663 static GQuark quark_property_parser = 0;
664 static GQuark quark_aux_info = 0;
665 static GQuark quark_accel_path = 0;
666 static GQuark quark_accel_closures = 0;
667 static GQuark quark_event_mask = 0;
668 static GQuark quark_device_event_mask = 0;
669 static GQuark quark_parent_window = 0;
670 static GQuark quark_pointer_window = 0;
671 static GQuark quark_shape_info = 0;
672 static GQuark quark_input_shape_info = 0;
673 static GQuark quark_pango_context = 0;
674 static GQuark quark_rc_style = 0;
675 static GQuark quark_accessible_object = 0;
676 static GQuark quark_mnemonic_labels = 0;
677 static GQuark quark_tooltip_markup = 0;
678 static GQuark quark_has_tooltip = 0;
679 static GQuark quark_tooltip_window = 0;
680 static GQuark quark_visual = 0;
681 static GQuark quark_modifier_style = 0;
682 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
683 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
685 /* --- functions --- */
687 gtk_widget_get_type (void)
689 static GType widget_type = 0;
691 if (G_UNLIKELY (widget_type == 0))
693 const GTypeInfo widget_info =
695 sizeof (GtkWidgetClass),
696 NULL, /* base_init */
697 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
698 (GClassInitFunc) gtk_widget_class_init,
699 NULL, /* class_finalize */
700 NULL, /* class_init */
703 (GInstanceInitFunc) gtk_widget_init,
704 NULL, /* value_table */
707 const GInterfaceInfo accessibility_info =
709 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
710 (GInterfaceFinalizeFunc) NULL,
711 NULL /* interface data */
714 const GInterfaceInfo buildable_info =
716 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
717 (GInterfaceFinalizeFunc) NULL,
718 NULL /* interface data */
721 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
722 &widget_info, G_TYPE_FLAG_ABSTRACT);
724 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
725 &accessibility_info) ;
726 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
734 child_property_notify_dispatcher (GObject *object,
738 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
741 /* We guard against the draw signal callbacks modifying the state of the
742 * cairo context by surounding it with save/restore.
743 * Maybe we should also cairo_new_path() just to be sure?
746 gtk_widget_draw_marshaller (GClosure *closure,
747 GValue *return_value,
748 guint n_param_values,
749 const GValue *param_values,
750 gpointer invocation_hint,
751 gpointer marshal_data)
753 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
757 _gtk_marshal_BOOLEAN__BOXED (closure,
768 gtk_widget_class_init (GtkWidgetClass *klass)
770 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
771 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
772 GtkBindingSet *binding_set;
774 gtk_widget_parent_class = g_type_class_peek_parent (klass);
776 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
777 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
778 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
779 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
780 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
781 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
782 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
783 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
784 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
785 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
786 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
787 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
788 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
789 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
790 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
791 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
792 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
793 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
794 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
796 style_property_spec_pool = g_param_spec_pool_new (FALSE);
797 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
798 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
799 cpn_context.dispatcher = child_property_notify_dispatcher;
800 _gtk_widget_child_property_notify_context = &cpn_context;
802 gobject_class->dispose = gtk_widget_dispose;
803 gobject_class->finalize = gtk_widget_finalize;
804 gobject_class->set_property = gtk_widget_set_property;
805 gobject_class->get_property = gtk_widget_get_property;
807 klass->destroy = gtk_widget_real_destroy;
809 klass->activate_signal = 0;
810 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
811 klass->show = gtk_widget_real_show;
812 klass->show_all = gtk_widget_show;
813 klass->hide = gtk_widget_real_hide;
814 klass->map = gtk_widget_real_map;
815 klass->unmap = gtk_widget_real_unmap;
816 klass->realize = gtk_widget_real_realize;
817 klass->unrealize = gtk_widget_real_unrealize;
818 klass->size_allocate = gtk_widget_real_size_allocate;
819 klass->get_preferred_width = gtk_widget_real_get_width;
820 klass->get_preferred_height = gtk_widget_real_get_height;
821 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
822 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
823 klass->state_changed = NULL;
824 klass->parent_set = NULL;
825 klass->hierarchy_changed = NULL;
826 klass->style_set = gtk_widget_real_style_set;
827 klass->direction_changed = gtk_widget_real_direction_changed;
828 klass->grab_notify = NULL;
829 klass->child_notify = NULL;
831 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
832 klass->grab_focus = gtk_widget_real_grab_focus;
833 klass->focus = gtk_widget_real_focus;
834 klass->move_focus = gtk_widget_real_move_focus;
835 klass->keynav_failed = gtk_widget_real_keynav_failed;
837 klass->button_press_event = NULL;
838 klass->button_release_event = NULL;
839 klass->motion_notify_event = NULL;
840 klass->delete_event = NULL;
841 klass->destroy_event = NULL;
842 klass->key_press_event = gtk_widget_real_key_press_event;
843 klass->key_release_event = gtk_widget_real_key_release_event;
844 klass->enter_notify_event = NULL;
845 klass->leave_notify_event = NULL;
846 klass->configure_event = NULL;
847 klass->focus_in_event = gtk_widget_real_focus_in_event;
848 klass->focus_out_event = gtk_widget_real_focus_out_event;
849 klass->map_event = NULL;
850 klass->unmap_event = NULL;
851 klass->window_state_event = NULL;
852 klass->property_notify_event = _gtk_selection_property_notify;
853 klass->selection_clear_event = _gtk_selection_clear;
854 klass->selection_request_event = _gtk_selection_request;
855 klass->selection_notify_event = _gtk_selection_notify;
856 klass->selection_received = NULL;
857 klass->proximity_in_event = NULL;
858 klass->proximity_out_event = NULL;
859 klass->drag_begin = NULL;
860 klass->drag_end = NULL;
861 klass->drag_data_delete = NULL;
862 klass->drag_leave = NULL;
863 klass->drag_motion = NULL;
864 klass->drag_drop = NULL;
865 klass->drag_data_received = NULL;
866 klass->screen_changed = NULL;
867 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
868 klass->grab_broken_event = NULL;
869 klass->query_tooltip = gtk_widget_real_query_tooltip;
870 klass->style_updated = gtk_widget_real_style_updated;
872 klass->show_help = gtk_widget_real_show_help;
874 /* Accessibility support */
875 klass->get_accessible = gtk_widget_real_get_accessible;
877 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
878 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
880 g_object_class_install_property (gobject_class,
882 g_param_spec_string ("name",
884 P_("The name of the widget"),
886 GTK_PARAM_READWRITE));
887 g_object_class_install_property (gobject_class,
889 g_param_spec_object ("parent",
891 P_("The parent widget of this widget. Must be a Container widget"),
893 GTK_PARAM_READWRITE));
895 g_object_class_install_property (gobject_class,
897 g_param_spec_int ("width-request",
899 P_("Override for width request of the widget, or -1 if natural request should be used"),
903 GTK_PARAM_READWRITE));
904 g_object_class_install_property (gobject_class,
906 g_param_spec_int ("height-request",
907 P_("Height request"),
908 P_("Override for height request of the widget, or -1 if natural request should be used"),
912 GTK_PARAM_READWRITE));
913 g_object_class_install_property (gobject_class,
915 g_param_spec_boolean ("visible",
917 P_("Whether the widget is visible"),
919 GTK_PARAM_READWRITE));
920 g_object_class_install_property (gobject_class,
922 g_param_spec_boolean ("sensitive",
924 P_("Whether the widget responds to input"),
926 GTK_PARAM_READWRITE));
927 g_object_class_install_property (gobject_class,
929 g_param_spec_boolean ("app-paintable",
930 P_("Application paintable"),
931 P_("Whether the application will paint directly on the widget"),
933 GTK_PARAM_READWRITE));
934 g_object_class_install_property (gobject_class,
936 g_param_spec_boolean ("can-focus",
938 P_("Whether the widget can accept the input focus"),
940 GTK_PARAM_READWRITE));
941 g_object_class_install_property (gobject_class,
943 g_param_spec_boolean ("has-focus",
945 P_("Whether the widget has the input focus"),
947 GTK_PARAM_READWRITE));
948 g_object_class_install_property (gobject_class,
950 g_param_spec_boolean ("is-focus",
952 P_("Whether the widget is the focus widget within the toplevel"),
954 GTK_PARAM_READWRITE));
955 g_object_class_install_property (gobject_class,
957 g_param_spec_boolean ("can-default",
959 P_("Whether the widget can be the default widget"),
961 GTK_PARAM_READWRITE));
962 g_object_class_install_property (gobject_class,
964 g_param_spec_boolean ("has-default",
966 P_("Whether the widget is the default widget"),
968 GTK_PARAM_READWRITE));
969 g_object_class_install_property (gobject_class,
970 PROP_RECEIVES_DEFAULT,
971 g_param_spec_boolean ("receives-default",
972 P_("Receives default"),
973 P_("If TRUE, the widget will receive the default action when it is focused"),
975 GTK_PARAM_READWRITE));
976 g_object_class_install_property (gobject_class,
977 PROP_COMPOSITE_CHILD,
978 g_param_spec_boolean ("composite-child",
979 P_("Composite child"),
980 P_("Whether the widget is part of a composite widget"),
982 GTK_PARAM_READABLE));
983 g_object_class_install_property (gobject_class,
985 g_param_spec_object ("style",
987 P_("The style of the widget, which contains information about how it will look (colors etc)"),
989 GTK_PARAM_READWRITE));
990 g_object_class_install_property (gobject_class,
992 g_param_spec_flags ("events",
994 P_("The event mask that decides what kind of GdkEvents this widget gets"),
997 GTK_PARAM_READWRITE));
998 g_object_class_install_property (gobject_class,
1000 g_param_spec_boolean ("no-show-all",
1002 P_("Whether gtk_widget_show_all() should not affect this widget"),
1004 GTK_PARAM_READWRITE));
1007 * GtkWidget:has-tooltip:
1009 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1010 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1011 * the widget will be queried using #GtkWidget::query-tooltip to determine
1012 * whether it will provide a tooltip or not.
1014 * Note that setting this property to %TRUE for the first time will change
1015 * the event masks of the GdkWindows of this widget to include leave-notify
1016 * and motion-notify events. This cannot and will not be undone when the
1017 * property is set to %FALSE again.
1021 g_object_class_install_property (gobject_class,
1023 g_param_spec_boolean ("has-tooltip",
1025 P_("Whether this widget has a tooltip"),
1027 GTK_PARAM_READWRITE));
1029 * GtkWidget:tooltip-text:
1031 * Sets the text of tooltip to be the given string.
1033 * Also see gtk_tooltip_set_text().
1035 * This is a convenience property which will take care of getting the
1036 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1037 * will automatically be set to %TRUE and there will be taken care of
1038 * #GtkWidget::query-tooltip in the default signal handler.
1042 g_object_class_install_property (gobject_class,
1044 g_param_spec_string ("tooltip-text",
1046 P_("The contents of the tooltip for this widget"),
1048 GTK_PARAM_READWRITE));
1050 * GtkWidget:tooltip-markup:
1052 * Sets the text of tooltip to be the given string, which is marked up
1053 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1054 * Also see gtk_tooltip_set_markup().
1056 * This is a convenience property which will take care of getting the
1057 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1058 * will automatically be set to %TRUE and there will be taken care of
1059 * #GtkWidget::query-tooltip in the default signal handler.
1063 g_object_class_install_property (gobject_class,
1064 PROP_TOOLTIP_MARKUP,
1065 g_param_spec_string ("tooltip-markup",
1066 P_("Tooltip markup"),
1067 P_("The contents of the tooltip for this widget"),
1069 GTK_PARAM_READWRITE));
1074 * The widget's window if it is realized, %NULL otherwise.
1078 g_object_class_install_property (gobject_class,
1080 g_param_spec_object ("window",
1082 P_("The widget's window if it is realized"),
1084 GTK_PARAM_READABLE));
1087 * GtkWidget:double-buffered
1089 * Whether the widget is double buffered.
1093 g_object_class_install_property (gobject_class,
1094 PROP_DOUBLE_BUFFERED,
1095 g_param_spec_boolean ("double-buffered",
1096 P_("Double Buffered"),
1097 P_("Whether the widget is double buffered"),
1099 GTK_PARAM_READWRITE));
1104 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1108 g_object_class_install_property (gobject_class,
1110 g_param_spec_enum ("halign",
1111 P_("Horizontal Alignment"),
1112 P_("How to position in extra horizontal space"),
1115 GTK_PARAM_READWRITE));
1120 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1124 g_object_class_install_property (gobject_class,
1126 g_param_spec_enum ("valign",
1127 P_("Vertical Alignment"),
1128 P_("How to position in extra vertical space"),
1131 GTK_PARAM_READWRITE));
1134 * GtkWidget:margin-left
1136 * Margin on left side of widget.
1138 * This property adds margin outside of the widget's normal size
1139 * request, the margin will be added in addition to the size from
1140 * gtk_widget_set_size_request() for example.
1144 g_object_class_install_property (gobject_class,
1146 g_param_spec_int ("margin-left",
1147 P_("Margin on Left"),
1148 P_("Pixels of extra space on the left side"),
1152 GTK_PARAM_READWRITE));
1155 * GtkWidget:margin-right
1157 * Margin on right side of widget.
1159 * This property adds margin outside of the widget's normal size
1160 * request, the margin will be added in addition to the size from
1161 * gtk_widget_set_size_request() for example.
1165 g_object_class_install_property (gobject_class,
1167 g_param_spec_int ("margin-right",
1168 P_("Margin on Right"),
1169 P_("Pixels of extra space on the right side"),
1173 GTK_PARAM_READWRITE));
1176 * GtkWidget:margin-top
1178 * Margin on top side of widget.
1180 * This property adds margin outside of the widget's normal size
1181 * request, the margin will be added in addition to the size from
1182 * gtk_widget_set_size_request() for example.
1186 g_object_class_install_property (gobject_class,
1188 g_param_spec_int ("margin-top",
1189 P_("Margin on Top"),
1190 P_("Pixels of extra space on the top side"),
1194 GTK_PARAM_READWRITE));
1197 * GtkWidget:margin-bottom
1199 * Margin on bottom side of widget.
1201 * This property adds margin outside of the widget's normal size
1202 * request, the margin will be added in addition to the size from
1203 * gtk_widget_set_size_request() for example.
1207 g_object_class_install_property (gobject_class,
1209 g_param_spec_int ("margin-bottom",
1210 P_("Margin on Bottom"),
1211 P_("Pixels of extra space on the bottom side"),
1215 GTK_PARAM_READWRITE));
1220 * Sets all four sides' margin at once. If read, returns max
1221 * margin on any side.
1225 g_object_class_install_property (gobject_class,
1227 g_param_spec_int ("margin",
1229 P_("Pixels of extra space on all four sides"),
1233 GTK_PARAM_READWRITE));
1236 * GtkWidget::destroy:
1237 * @object: the object which received the signal
1239 * Signals that all holders of a reference to the widget should release
1240 * the reference that they hold. May result in finalization of the widget
1241 * if all references are released.
1243 widget_signals[DESTROY] =
1244 g_signal_new (I_("destroy"),
1245 G_TYPE_FROM_CLASS (gobject_class),
1246 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1247 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1249 _gtk_marshal_VOID__VOID,
1255 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1259 g_object_class_install_property (gobject_class,
1261 g_param_spec_boolean ("hexpand",
1262 P_("Horizontal Expand"),
1263 P_("Whether widget wants more horizontal space"),
1265 GTK_PARAM_READWRITE));
1268 * GtkWidget:hexpand-set
1270 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1274 g_object_class_install_property (gobject_class,
1276 g_param_spec_boolean ("hexpand-set",
1277 P_("Horizontal Expand Set"),
1278 P_("Whether to use the hexpand property"),
1280 GTK_PARAM_READWRITE));
1285 * Whether to expand vertically. See gtk_widget_set_vexpand().
1289 g_object_class_install_property (gobject_class,
1291 g_param_spec_boolean ("vexpand",
1292 P_("Vertical Expand"),
1293 P_("Whether widget wants more vertical space"),
1295 GTK_PARAM_READWRITE));
1298 * GtkWidget:vexpand-set
1300 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1304 g_object_class_install_property (gobject_class,
1306 g_param_spec_boolean ("vexpand-set",
1307 P_("Vertical Expand Set"),
1308 P_("Whether to use the vexpand property"),
1310 GTK_PARAM_READWRITE));
1315 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1319 g_object_class_install_property (gobject_class,
1321 g_param_spec_boolean ("expand",
1323 P_("Whether widget wants to expand in both directions"),
1325 GTK_PARAM_READWRITE));
1329 * @widget: the object which received the signal.
1331 widget_signals[SHOW] =
1332 g_signal_new (I_("show"),
1333 G_TYPE_FROM_CLASS (gobject_class),
1335 G_STRUCT_OFFSET (GtkWidgetClass, show),
1337 _gtk_marshal_VOID__VOID,
1342 * @widget: the object which received the signal.
1344 widget_signals[HIDE] =
1345 g_signal_new (I_("hide"),
1346 G_TYPE_FROM_CLASS (gobject_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1350 _gtk_marshal_VOID__VOID,
1355 * @widget: the object which received the signal.
1357 widget_signals[MAP] =
1358 g_signal_new (I_("map"),
1359 G_TYPE_FROM_CLASS (gobject_class),
1361 G_STRUCT_OFFSET (GtkWidgetClass, map),
1363 _gtk_marshal_VOID__VOID,
1368 * @widget: the object which received the signal.
1370 widget_signals[UNMAP] =
1371 g_signal_new (I_("unmap"),
1372 G_TYPE_FROM_CLASS (gobject_class),
1374 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1376 _gtk_marshal_VOID__VOID,
1380 * GtkWidget::realize:
1381 * @widget: the object which received the signal.
1383 widget_signals[REALIZE] =
1384 g_signal_new (I_("realize"),
1385 G_TYPE_FROM_CLASS (gobject_class),
1387 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1389 _gtk_marshal_VOID__VOID,
1393 * GtkWidget::unrealize:
1394 * @widget: the object which received the signal.
1396 widget_signals[UNREALIZE] =
1397 g_signal_new (I_("unrealize"),
1398 G_TYPE_FROM_CLASS (gobject_class),
1400 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1402 _gtk_marshal_VOID__VOID,
1406 * GtkWidget::size-allocate:
1407 * @widget: the object which received the signal.
1410 widget_signals[SIZE_ALLOCATE] =
1411 g_signal_new (I_("size-allocate"),
1412 G_TYPE_FROM_CLASS (gobject_class),
1414 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1416 _gtk_marshal_VOID__BOXED,
1418 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1421 * GtkWidget::state-changed:
1422 * @widget: the object which received the signal.
1423 * @state: the previous state
1425 * The ::state-changed signal is emitted when the widget state changes.
1426 * See gtk_widget_get_state().
1428 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1430 widget_signals[STATE_CHANGED] =
1431 g_signal_new (I_("state-changed"),
1432 G_TYPE_FROM_CLASS (gobject_class),
1434 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1436 _gtk_marshal_VOID__ENUM,
1438 GTK_TYPE_STATE_TYPE);
1441 * GtkWidget::state-flags-changed:
1442 * @widget: the object which received the signal.
1443 * @flags: The previous state flags.
1445 * The ::state-flags-changed signal is emitted when the widget state
1446 * changes, see gtk_widget_get_state_flags().
1450 widget_signals[STATE_FLAGS_CHANGED] =
1451 g_signal_new (I_("state-flags-changed"),
1452 G_TYPE_FROM_CLASS (gobject_class),
1454 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1456 _gtk_marshal_VOID__FLAGS,
1458 GTK_TYPE_STATE_FLAGS);
1461 * GtkWidget::parent-set:
1462 * @widget: the object on which the signal is emitted
1463 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1464 * just got its initial parent.
1466 * The ::parent-set signal is emitted when a new parent
1467 * has been set on a widget.
1469 widget_signals[PARENT_SET] =
1470 g_signal_new (I_("parent-set"),
1471 G_TYPE_FROM_CLASS (gobject_class),
1473 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1475 _gtk_marshal_VOID__OBJECT,
1480 * GtkWidget::hierarchy-changed:
1481 * @widget: the object on which the signal is emitted
1482 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1483 * if the widget was previously unanchored
1485 * The ::hierarchy-changed signal is emitted when the
1486 * anchored state of a widget changes. A widget is
1487 * <firstterm>anchored</firstterm> when its toplevel
1488 * ancestor is a #GtkWindow. This signal is emitted when
1489 * a widget changes from un-anchored to anchored or vice-versa.
1491 widget_signals[HIERARCHY_CHANGED] =
1492 g_signal_new (I_("hierarchy-changed"),
1493 G_TYPE_FROM_CLASS (gobject_class),
1495 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1497 _gtk_marshal_VOID__OBJECT,
1502 * GtkWidget::style-set:
1503 * @widget: the object on which the signal is emitted
1504 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1505 * just got its initial style
1507 * The ::style-set signal is emitted when a new style has been set
1508 * on a widget. Note that style-modifying functions like
1509 * gtk_widget_modify_base() also cause this signal to be emitted.
1511 * Note that this signal is emitted for changes to the deprecated
1512 * #GtkStyle. To track changes to the #GtkStyleContext associated
1513 * with a widget, use the #GtkWidget::style-updated signal.
1515 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1517 widget_signals[STYLE_SET] =
1518 g_signal_new (I_("style-set"),
1519 G_TYPE_FROM_CLASS (gobject_class),
1521 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1523 _gtk_marshal_VOID__OBJECT,
1528 * GtkWidget::style-updated:
1529 * @widget: the object on which the signal is emitted
1531 * The ::style-updated signal is emitted when the #GtkStyleContext
1532 * of a widget is changed. Note that style-modifying functions like
1533 * gtk_widget_override_color() also cause this signal to be emitted.
1537 widget_signals[STYLE_UPDATED] =
1538 g_signal_new (I_("style-updated"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1541 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1543 g_cclosure_marshal_VOID__VOID,
1547 * GtkWidget::direction-changed:
1548 * @widget: the object on which the signal is emitted
1549 * @previous_direction: the previous text direction of @widget
1551 * The ::direction-changed signal is emitted when the text direction
1552 * of a widget changes.
1554 widget_signals[DIRECTION_CHANGED] =
1555 g_signal_new (I_("direction-changed"),
1556 G_TYPE_FROM_CLASS (gobject_class),
1558 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1560 _gtk_marshal_VOID__ENUM,
1562 GTK_TYPE_TEXT_DIRECTION);
1565 * GtkWidget::grab-notify:
1566 * @widget: the object which received the signal
1567 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1568 * if it becomes unshadowed
1570 * The ::grab-notify signal is emitted when a widget becomes
1571 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1572 * another widget, or when it becomes unshadowed due to a grab
1575 * A widget is shadowed by a gtk_grab_add() when the topmost
1576 * grab widget in the grab stack of its window group is not
1579 widget_signals[GRAB_NOTIFY] =
1580 g_signal_new (I_("grab-notify"),
1581 G_TYPE_FROM_CLASS (gobject_class),
1583 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1585 _gtk_marshal_VOID__BOOLEAN,
1590 * GtkWidget::child-notify:
1591 * @widget: the object which received the signal
1592 * @pspec: the #GParamSpec of the changed child property
1594 * The ::child-notify signal is emitted for each
1595 * <link linkend="child-properties">child property</link> that has
1596 * changed on an object. The signal's detail holds the property name.
1598 widget_signals[CHILD_NOTIFY] =
1599 g_signal_new (I_("child-notify"),
1600 G_TYPE_FROM_CLASS (gobject_class),
1601 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1602 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1604 g_cclosure_marshal_VOID__PARAM,
1610 * @widget: the object which received the signal
1611 * @cr: the cairo context to draw to
1613 * This signal is emitted when a widget is supposed to render itself.
1614 * The @widget's top left corner must be painted at the origin of
1615 * the passed in context and be sized to the values returned by
1616 * gtk_widget_get_allocated_width() and
1617 * gtk_widget_get_allocated_height().
1619 * Signal handlers connected to this signal can modify the cairo
1620 * context passed as @cr in any way they like and don't need to
1621 * restore it. The signal emission takes care of calling cairo_save()
1622 * before and cairo_restore() after invoking the handler.
1624 widget_signals[DRAW] =
1625 g_signal_new (I_("draw"),
1626 G_TYPE_FROM_CLASS (gobject_class),
1628 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1629 _gtk_boolean_handled_accumulator, NULL,
1630 gtk_widget_draw_marshaller,
1632 CAIRO_GOBJECT_TYPE_CONTEXT);
1635 * GtkWidget::mnemonic-activate:
1636 * @widget: the object which received the signal.
1639 widget_signals[MNEMONIC_ACTIVATE] =
1640 g_signal_new (I_("mnemonic-activate"),
1641 G_TYPE_FROM_CLASS (gobject_class),
1643 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1644 _gtk_boolean_handled_accumulator, NULL,
1645 _gtk_marshal_BOOLEAN__BOOLEAN,
1650 * GtkWidget::grab-focus:
1651 * @widget: the object which received the signal.
1653 widget_signals[GRAB_FOCUS] =
1654 g_signal_new (I_("grab-focus"),
1655 G_TYPE_FROM_CLASS (gobject_class),
1656 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1657 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1659 _gtk_marshal_VOID__VOID,
1664 * @widget: the object which received the signal.
1667 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1669 widget_signals[FOCUS] =
1670 g_signal_new (I_("focus"),
1671 G_TYPE_FROM_CLASS (klass),
1673 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1674 _gtk_boolean_handled_accumulator, NULL,
1675 _gtk_marshal_BOOLEAN__ENUM,
1677 GTK_TYPE_DIRECTION_TYPE);
1680 * GtkWidget::move-focus:
1681 * @widget: the object which received the signal.
1684 widget_signals[MOVE_FOCUS] =
1685 g_signal_new (I_("move-focus"),
1686 G_TYPE_FROM_CLASS (klass),
1687 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1688 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1690 _gtk_marshal_VOID__ENUM,
1693 GTK_TYPE_DIRECTION_TYPE);
1696 * GtkWidget::keynav-failed:
1697 * @widget: the object which received the signal
1698 * @direction: the direction of movement
1700 * Gets emitted if keyboard navigation fails.
1701 * See gtk_widget_keynav_failed() for details.
1703 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1704 * if the emitting widget should try to handle the keyboard
1705 * navigation attempt in its parent container(s).
1709 widget_signals[KEYNAV_FAILED] =
1710 g_signal_new (I_("keynav-failed"),
1711 G_TYPE_FROM_CLASS (klass),
1713 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1714 _gtk_boolean_handled_accumulator, NULL,
1715 _gtk_marshal_BOOLEAN__ENUM,
1717 GTK_TYPE_DIRECTION_TYPE);
1721 * @widget: the object which received the signal.
1722 * @event: the #GdkEvent which triggered this signal
1724 * The GTK+ main loop will emit three signals for each GDK event delivered
1725 * to a widget: one generic ::event signal, another, more specific,
1726 * signal that matches the type of event delivered (e.g.
1727 * #GtkWidget::key-press-event) and finally a generic
1728 * #GtkWidget::event-after signal.
1730 * Returns: %TRUE to stop other handlers from being invoked for the event
1731 * and to cancel the emission of the second specific ::event signal.
1732 * %FALSE to propagate the event further and to allow the emission of
1733 * the second signal. The ::event-after signal is emitted regardless of
1736 widget_signals[EVENT] =
1737 g_signal_new (I_("event"),
1738 G_TYPE_FROM_CLASS (klass),
1740 G_STRUCT_OFFSET (GtkWidgetClass, event),
1741 _gtk_boolean_handled_accumulator, NULL,
1742 _gtk_marshal_BOOLEAN__BOXED,
1744 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1747 * GtkWidget::event-after:
1748 * @widget: the object which received the signal.
1749 * @event: the #GdkEvent which triggered this signal
1751 * After the emission of the #GtkWidget::event signal and (optionally)
1752 * the second more specific signal, ::event-after will be emitted
1753 * regardless of the previous two signals handlers return values.
1756 widget_signals[EVENT_AFTER] =
1757 g_signal_new (I_("event-after"),
1758 G_TYPE_FROM_CLASS (klass),
1762 _gtk_marshal_VOID__BOXED,
1764 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1767 * GtkWidget::button-press-event:
1768 * @widget: the object which received the signal.
1769 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1772 * The ::button-press-event signal will be emitted when a button
1773 * (typically from a mouse) is pressed.
1775 * To receive this signal, the #GdkWindow associated to the
1776 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1778 * This signal will be sent to the grab widget if there is one.
1780 * Returns: %TRUE to stop other handlers from being invoked for the event.
1781 * %FALSE to propagate the event further.
1783 widget_signals[BUTTON_PRESS_EVENT] =
1784 g_signal_new (I_("button-press-event"),
1785 G_TYPE_FROM_CLASS (klass),
1787 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1788 _gtk_boolean_handled_accumulator, NULL,
1789 _gtk_marshal_BOOLEAN__BOXED,
1791 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1794 * GtkWidget::button-release-event:
1795 * @widget: the object which received the signal.
1796 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1799 * The ::button-release-event signal will be emitted when a button
1800 * (typically from a mouse) is released.
1802 * To receive this signal, the #GdkWindow associated to the
1803 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1805 * This signal will be sent to the grab widget if there is one.
1807 * Returns: %TRUE to stop other handlers from being invoked for the event.
1808 * %FALSE to propagate the event further.
1810 widget_signals[BUTTON_RELEASE_EVENT] =
1811 g_signal_new (I_("button-release-event"),
1812 G_TYPE_FROM_CLASS (klass),
1814 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1815 _gtk_boolean_handled_accumulator, NULL,
1816 _gtk_marshal_BOOLEAN__BOXED,
1818 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1821 * GtkWidget::scroll-event:
1822 * @widget: the object which received the signal.
1823 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1826 * The ::scroll-event signal is emitted when a button in the 4 to 7
1827 * range is pressed. Wheel mice are usually configured to generate
1828 * button press events for buttons 4 and 5 when the wheel is turned.
1830 * To receive this signal, the #GdkWindow associated to the widget needs
1831 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1833 * This signal will be sent to the grab widget if there is one.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event.
1836 * %FALSE to propagate the event further.
1838 widget_signals[SCROLL_EVENT] =
1839 g_signal_new (I_("scroll-event"),
1840 G_TYPE_FROM_CLASS (klass),
1842 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1843 _gtk_boolean_handled_accumulator, NULL,
1844 _gtk_marshal_BOOLEAN__BOXED,
1846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1849 * GtkWidget::motion-notify-event:
1850 * @widget: the object which received the signal.
1851 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1854 * The ::motion-notify-event signal is emitted when the pointer moves
1855 * over the widget's #GdkWindow.
1857 * To receive this signal, the #GdkWindow associated to the widget
1858 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1860 * This signal will be sent to the grab widget if there is one.
1862 * Returns: %TRUE to stop other handlers from being invoked for the event.
1863 * %FALSE to propagate the event further.
1865 widget_signals[MOTION_NOTIFY_EVENT] =
1866 g_signal_new (I_("motion-notify-event"),
1867 G_TYPE_FROM_CLASS (klass),
1869 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1870 _gtk_boolean_handled_accumulator, NULL,
1871 _gtk_marshal_BOOLEAN__BOXED,
1873 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1876 * GtkWidget::composited-changed:
1877 * @widget: the object on which the signal is emitted
1879 * The ::composited-changed signal is emitted when the composited
1880 * status of @widget<!-- -->s screen changes.
1881 * See gdk_screen_is_composited().
1883 widget_signals[COMPOSITED_CHANGED] =
1884 g_signal_new (I_("composited-changed"),
1885 G_TYPE_FROM_CLASS (klass),
1886 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1887 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1889 _gtk_marshal_VOID__VOID,
1893 * GtkWidget::delete-event:
1894 * @widget: the object which received the signal
1895 * @event: the event which triggered this signal
1897 * The ::delete-event signal is emitted if a user requests that
1898 * a toplevel window is closed. The default handler for this signal
1899 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1900 * this signal will cause the window to be hidden instead, so that
1901 * it can later be shown again without reconstructing it.
1903 * Returns: %TRUE to stop other handlers from being invoked for the event.
1904 * %FALSE to propagate the event further.
1906 widget_signals[DELETE_EVENT] =
1907 g_signal_new (I_("delete-event"),
1908 G_TYPE_FROM_CLASS (klass),
1910 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1911 _gtk_boolean_handled_accumulator, NULL,
1912 _gtk_marshal_BOOLEAN__BOXED,
1914 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1917 * GtkWidget::destroy-event:
1918 * @widget: the object which received the signal.
1919 * @event: the event which triggered this signal
1921 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1922 * You rarely get this signal, because most widgets disconnect themselves
1923 * from their window before they destroy it, so no widget owns the
1924 * window at destroy time.
1926 * To receive this signal, the #GdkWindow associated to the widget needs
1927 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1928 * automatically for all new windows.
1930 * Returns: %TRUE to stop other handlers from being invoked for the event.
1931 * %FALSE to propagate the event further.
1933 widget_signals[DESTROY_EVENT] =
1934 g_signal_new (I_("destroy-event"),
1935 G_TYPE_FROM_CLASS (klass),
1937 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1938 _gtk_boolean_handled_accumulator, NULL,
1939 _gtk_marshal_BOOLEAN__BOXED,
1941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1944 * GtkWidget::key-press-event:
1945 * @widget: the object which received the signal
1946 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1948 * The ::key-press-event signal is emitted when a key is pressed.
1950 * To receive this signal, the #GdkWindow associated to the widget needs
1951 * to enable the #GDK_KEY_PRESS_MASK mask.
1953 * This signal will be sent to the grab widget if there is one.
1955 * Returns: %TRUE to stop other handlers from being invoked for the event.
1956 * %FALSE to propagate the event further.
1958 widget_signals[KEY_PRESS_EVENT] =
1959 g_signal_new (I_("key-press-event"),
1960 G_TYPE_FROM_CLASS (klass),
1962 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1963 _gtk_boolean_handled_accumulator, NULL,
1964 _gtk_marshal_BOOLEAN__BOXED,
1966 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1969 * GtkWidget::key-release-event:
1970 * @widget: the object which received the signal
1971 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1973 * The ::key-release-event signal is emitted when a key is pressed.
1975 * To receive this signal, the #GdkWindow associated to the widget needs
1976 * to enable the #GDK_KEY_RELEASE_MASK mask.
1978 * This signal will be sent to the grab widget if there is one.
1980 * Returns: %TRUE to stop other handlers from being invoked for the event.
1981 * %FALSE to propagate the event further.
1983 widget_signals[KEY_RELEASE_EVENT] =
1984 g_signal_new (I_("key-release-event"),
1985 G_TYPE_FROM_CLASS (klass),
1987 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1988 _gtk_boolean_handled_accumulator, NULL,
1989 _gtk_marshal_BOOLEAN__BOXED,
1991 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1994 * GtkWidget::enter-notify-event:
1995 * @widget: the object which received the signal
1996 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1999 * The ::enter-notify-event will be emitted when the pointer enters
2000 * the @widget's window.
2002 * To receive this signal, the #GdkWindow associated to the widget needs
2003 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2005 * This signal will be sent to the grab widget if there is one.
2007 * Returns: %TRUE to stop other handlers from being invoked for the event.
2008 * %FALSE to propagate the event further.
2010 widget_signals[ENTER_NOTIFY_EVENT] =
2011 g_signal_new (I_("enter-notify-event"),
2012 G_TYPE_FROM_CLASS (klass),
2014 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2015 _gtk_boolean_handled_accumulator, NULL,
2016 _gtk_marshal_BOOLEAN__BOXED,
2018 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2021 * GtkWidget::leave-notify-event:
2022 * @widget: the object which received the signal
2023 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2026 * The ::leave-notify-event will be emitted when the pointer leaves
2027 * the @widget's window.
2029 * To receive this signal, the #GdkWindow associated to the widget needs
2030 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2032 * This signal will be sent to the grab widget if there is one.
2034 * Returns: %TRUE to stop other handlers from being invoked for the event.
2035 * %FALSE to propagate the event further.
2037 widget_signals[LEAVE_NOTIFY_EVENT] =
2038 g_signal_new (I_("leave-notify-event"),
2039 G_TYPE_FROM_CLASS (klass),
2041 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2042 _gtk_boolean_handled_accumulator, NULL,
2043 _gtk_marshal_BOOLEAN__BOXED,
2045 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2048 * GtkWidget::configure-event:
2049 * @widget: the object which received the signal
2050 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2053 * The ::configure-event signal will be emitted when the size, position or
2054 * stacking of the @widget's window has changed.
2056 * To receive this signal, the #GdkWindow associated to the widget needs
2057 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2058 * automatically for all new windows.
2060 * Returns: %TRUE to stop other handlers from being invoked for the event.
2061 * %FALSE to propagate the event further.
2063 widget_signals[CONFIGURE_EVENT] =
2064 g_signal_new (I_("configure-event"),
2065 G_TYPE_FROM_CLASS (klass),
2067 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2068 _gtk_boolean_handled_accumulator, NULL,
2069 _gtk_marshal_BOOLEAN__BOXED,
2071 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2074 * GtkWidget::focus-in-event:
2075 * @widget: the object which received the signal
2076 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2079 * The ::focus-in-event signal will be emitted when the keyboard focus
2080 * enters the @widget's window.
2082 * To receive this signal, the #GdkWindow associated to the widget needs
2083 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2085 * Returns: %TRUE to stop other handlers from being invoked for the event.
2086 * %FALSE to propagate the event further.
2088 widget_signals[FOCUS_IN_EVENT] =
2089 g_signal_new (I_("focus-in-event"),
2090 G_TYPE_FROM_CLASS (klass),
2092 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2093 _gtk_boolean_handled_accumulator, NULL,
2094 _gtk_marshal_BOOLEAN__BOXED,
2096 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2099 * GtkWidget::focus-out-event:
2100 * @widget: the object which received the signal
2101 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2104 * The ::focus-out-event signal will be emitted when the keyboard focus
2105 * leaves the @widget's window.
2107 * To receive this signal, the #GdkWindow associated to the widget needs
2108 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2110 * Returns: %TRUE to stop other handlers from being invoked for the event.
2111 * %FALSE to propagate the event further.
2113 widget_signals[FOCUS_OUT_EVENT] =
2114 g_signal_new (I_("focus-out-event"),
2115 G_TYPE_FROM_CLASS (klass),
2117 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2118 _gtk_boolean_handled_accumulator, NULL,
2119 _gtk_marshal_BOOLEAN__BOXED,
2121 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2124 * GtkWidget::map-event:
2125 * @widget: the object which received the signal
2126 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2128 * The ::map-event signal will be emitted when the @widget's window is
2129 * mapped. A window is mapped when it becomes visible on the screen.
2131 * To receive this signal, the #GdkWindow associated to the widget needs
2132 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2133 * automatically for all new windows.
2135 * Returns: %TRUE to stop other handlers from being invoked for the event.
2136 * %FALSE to propagate the event further.
2138 widget_signals[MAP_EVENT] =
2139 g_signal_new (I_("map-event"),
2140 G_TYPE_FROM_CLASS (klass),
2142 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2143 _gtk_boolean_handled_accumulator, NULL,
2144 _gtk_marshal_BOOLEAN__BOXED,
2146 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2149 * GtkWidget::unmap-event:
2150 * @widget: the object which received the signal
2151 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2153 * The ::unmap-event signal may be emitted when the @widget's window is
2154 * unmapped. A window is unmapped when it becomes invisible on the screen.
2156 * For performance reasons GTK+ may not emit ::unmap-event, so one
2157 * should always also implement ::unrealize in order to release
2158 * resources and disconnect signal handlers.
2160 * To receive this signal, the #GdkWindow associated to the widget needs
2161 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2162 * automatically for all new windows.
2164 * Returns: %TRUE to stop other handlers from being invoked for the event.
2165 * %FALSE to propagate the event further.
2167 widget_signals[UNMAP_EVENT] =
2168 g_signal_new (I_("unmap-event"),
2169 G_TYPE_FROM_CLASS (klass),
2171 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2172 _gtk_boolean_handled_accumulator, NULL,
2173 _gtk_marshal_BOOLEAN__BOXED,
2175 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2178 * GtkWidget::property-notify-event:
2179 * @widget: the object which received the signal
2180 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2183 * The ::property-notify-event signal will be emitted when a property on
2184 * the @widget's window has been changed or deleted.
2186 * To receive this signal, the #GdkWindow associated to the widget needs
2187 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2189 * Returns: %TRUE to stop other handlers from being invoked for the event.
2190 * %FALSE to propagate the event further.
2192 widget_signals[PROPERTY_NOTIFY_EVENT] =
2193 g_signal_new (I_("property-notify-event"),
2194 G_TYPE_FROM_CLASS (klass),
2196 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2197 _gtk_boolean_handled_accumulator, NULL,
2198 _gtk_marshal_BOOLEAN__BOXED,
2200 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2203 * GtkWidget::selection-clear-event:
2204 * @widget: the object which received the signal
2205 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2208 * The ::selection-clear-event signal will be emitted when the
2209 * the @widget's window has lost ownership of a selection.
2211 * Returns: %TRUE to stop other handlers from being invoked for the event.
2212 * %FALSE to propagate the event further.
2214 widget_signals[SELECTION_CLEAR_EVENT] =
2215 g_signal_new (I_("selection-clear-event"),
2216 G_TYPE_FROM_CLASS (klass),
2218 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2219 _gtk_boolean_handled_accumulator, NULL,
2220 _gtk_marshal_BOOLEAN__BOXED,
2222 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2225 * GtkWidget::selection-request-event:
2226 * @widget: the object which received the signal
2227 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2230 * The ::selection-request-event signal will be emitted when
2231 * another client requests ownership of the selection owned by
2232 * the @widget's window.
2234 * Returns: %TRUE to stop other handlers from being invoked for the event.
2235 * %FALSE to propagate the event further.
2237 widget_signals[SELECTION_REQUEST_EVENT] =
2238 g_signal_new (I_("selection-request-event"),
2239 G_TYPE_FROM_CLASS (klass),
2241 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2242 _gtk_boolean_handled_accumulator, NULL,
2243 _gtk_marshal_BOOLEAN__BOXED,
2245 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2248 * GtkWidget::selection-notify-event:
2249 * @widget: the object which received the signal.
2252 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2254 widget_signals[SELECTION_NOTIFY_EVENT] =
2255 g_signal_new (I_("selection-notify-event"),
2256 G_TYPE_FROM_CLASS (klass),
2258 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2259 _gtk_boolean_handled_accumulator, NULL,
2260 _gtk_marshal_BOOLEAN__BOXED,
2262 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2265 * GtkWidget::selection-received:
2266 * @widget: the object which received the signal.
2270 widget_signals[SELECTION_RECEIVED] =
2271 g_signal_new (I_("selection-received"),
2272 G_TYPE_FROM_CLASS (klass),
2274 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2276 _gtk_marshal_VOID__BOXED_UINT,
2278 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2282 * GtkWidget::selection-get:
2283 * @widget: the object which received the signal.
2288 widget_signals[SELECTION_GET] =
2289 g_signal_new (I_("selection-get"),
2290 G_TYPE_FROM_CLASS (klass),
2292 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2294 _gtk_marshal_VOID__BOXED_UINT_UINT,
2296 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2301 * GtkWidget::proximity-in-event:
2302 * @widget: the object which received the signal
2303 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2306 * To receive this signal the #GdkWindow associated to the widget needs
2307 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2309 * This signal will be sent to the grab widget if there is one.
2311 * Returns: %TRUE to stop other handlers from being invoked for the event.
2312 * %FALSE to propagate the event further.
2314 widget_signals[PROXIMITY_IN_EVENT] =
2315 g_signal_new (I_("proximity-in-event"),
2316 G_TYPE_FROM_CLASS (klass),
2318 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__BOXED,
2322 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2325 * GtkWidget::proximity-out-event:
2326 * @widget: the object which received the signal
2327 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2330 * To receive this signal the #GdkWindow associated to the widget needs
2331 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2333 * This signal will be sent to the grab widget if there is one.
2335 * Returns: %TRUE to stop other handlers from being invoked for the event.
2336 * %FALSE to propagate the event further.
2338 widget_signals[PROXIMITY_OUT_EVENT] =
2339 g_signal_new (I_("proximity-out-event"),
2340 G_TYPE_FROM_CLASS (klass),
2342 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2343 _gtk_boolean_handled_accumulator, NULL,
2344 _gtk_marshal_BOOLEAN__BOXED,
2346 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2349 * GtkWidget::drag-leave:
2350 * @widget: the object which received the signal.
2351 * @drag_context: the drag context
2352 * @time: the timestamp of the motion event
2354 * The ::drag-leave signal is emitted on the drop site when the cursor
2355 * leaves the widget. A typical reason to connect to this signal is to
2356 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2357 * with gtk_drag_unhighlight()
2359 widget_signals[DRAG_LEAVE] =
2360 g_signal_new (I_("drag-leave"),
2361 G_TYPE_FROM_CLASS (klass),
2363 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2365 _gtk_marshal_VOID__OBJECT_UINT,
2367 GDK_TYPE_DRAG_CONTEXT,
2371 * GtkWidget::drag-begin:
2372 * @widget: the object which received the signal
2373 * @drag_context: the drag context
2375 * The ::drag-begin signal is emitted on the drag source when a drag is
2376 * started. A typical reason to connect to this signal is to set up a
2377 * custom drag icon with gtk_drag_source_set_icon().
2379 * Note that some widgets set up a drag icon in the default handler of
2380 * this signal, so you may have to use g_signal_connect_after() to
2381 * override what the default handler did.
2383 widget_signals[DRAG_BEGIN] =
2384 g_signal_new (I_("drag-begin"),
2385 G_TYPE_FROM_CLASS (klass),
2387 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2389 _gtk_marshal_VOID__OBJECT,
2391 GDK_TYPE_DRAG_CONTEXT);
2394 * GtkWidget::drag-end:
2395 * @widget: the object which received the signal
2396 * @drag_context: the drag context
2398 * The ::drag-end signal is emitted on the drag source when a drag is
2399 * finished. A typical reason to connect to this signal is to undo
2400 * things done in #GtkWidget::drag-begin.
2402 widget_signals[DRAG_END] =
2403 g_signal_new (I_("drag-end"),
2404 G_TYPE_FROM_CLASS (klass),
2406 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2408 _gtk_marshal_VOID__OBJECT,
2410 GDK_TYPE_DRAG_CONTEXT);
2413 * GtkWidget::drag-data-delete:
2414 * @widget: the object which received the signal
2415 * @drag_context: the drag context
2417 * The ::drag-data-delete signal is emitted on the drag source when a drag
2418 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2419 * handler is responsible for deleting the data that has been dropped. What
2420 * "delete" means depends on the context of the drag operation.
2422 widget_signals[DRAG_DATA_DELETE] =
2423 g_signal_new (I_("drag-data-delete"),
2424 G_TYPE_FROM_CLASS (klass),
2426 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2428 _gtk_marshal_VOID__OBJECT,
2430 GDK_TYPE_DRAG_CONTEXT);
2433 * GtkWidget::drag-failed:
2434 * @widget: the object which received the signal
2435 * @drag_context: the drag context
2436 * @result: the result of the drag operation
2438 * The ::drag-failed signal is emitted on the drag source when a drag has
2439 * failed. The signal handler may hook custom code to handle a failed DND
2440 * operation based on the type of error, it returns %TRUE is the failure has
2441 * been already handled (not showing the default "drag operation failed"
2442 * animation), otherwise it returns %FALSE.
2444 * Return value: %TRUE if the failed drag operation has been already handled.
2448 widget_signals[DRAG_FAILED] =
2449 g_signal_new (I_("drag-failed"),
2450 G_TYPE_FROM_CLASS (klass),
2452 0, _gtk_boolean_handled_accumulator, NULL,
2453 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2455 GDK_TYPE_DRAG_CONTEXT,
2456 GTK_TYPE_DRAG_RESULT);
2459 * GtkWidget::drag-motion:
2460 * @widget: the object which received the signal
2461 * @drag_context: the drag context
2462 * @x: the x coordinate of the current cursor position
2463 * @y: the y coordinate of the current cursor position
2464 * @time: the timestamp of the motion event
2465 * @returns: whether the cursor position is in a drop zone
2467 * The drag-motion signal is emitted on the drop site when the user
2468 * moves the cursor over the widget during a drag. The signal handler
2469 * must determine whether the cursor position is in a drop zone or not.
2470 * If it is not in a drop zone, it returns %FALSE and no further processing
2471 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2472 * handler is responsible for providing the necessary information for
2473 * displaying feedback to the user, by calling gdk_drag_status().
2475 * If the decision whether the drop will be accepted or rejected can't be
2476 * made based solely on the cursor position and the type of the data, the
2477 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2478 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2479 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2480 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2481 * when using the drag-motion signal that way.
2483 * Also note that there is no drag-enter signal. The drag receiver has to
2484 * keep track of whether he has received any drag-motion signals since the
2485 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2486 * an "enter" signal. Upon an "enter", the handler will typically highlight
2487 * the drop site with gtk_drag_highlight().
2490 * drag_motion (GtkWidget *widget,
2491 * GdkDragContext *context,
2498 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2500 * if (!private_data->drag_highlight)
2502 * private_data->drag_highlight = 1;
2503 * gtk_drag_highlight (widget);
2506 * target = gtk_drag_dest_find_target (widget, context, NULL);
2507 * if (target == GDK_NONE)
2508 * gdk_drag_status (context, 0, time);
2511 * private_data->pending_status = context->suggested_action;
2512 * gtk_drag_get_data (widget, context, target, time);
2519 * drag_data_received (GtkWidget *widget,
2520 * GdkDragContext *context,
2523 * GtkSelectionData *selection_data,
2527 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2529 * if (private_data->suggested_action)
2531 * private_data->suggested_action = 0;
2533 * /* We are getting this data due to a request in drag_motion,
2534 * * rather than due to a request in drag_drop, so we are just
2535 * * supposed to call gdk_drag_status (), not actually paste in
2538 * str = gtk_selection_data_get_text (selection_data);
2539 * if (!data_is_acceptable (str))
2540 * gdk_drag_status (context, 0, time);
2542 * gdk_drag_status (context, private_data->suggested_action, time);
2546 * /* accept the drop */
2551 widget_signals[DRAG_MOTION] =
2552 g_signal_new (I_("drag-motion"),
2553 G_TYPE_FROM_CLASS (klass),
2555 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2556 _gtk_boolean_handled_accumulator, NULL,
2557 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2559 GDK_TYPE_DRAG_CONTEXT,
2565 * GtkWidget::drag-drop:
2566 * @widget: the object which received the signal
2567 * @drag_context: the drag context
2568 * @x: the x coordinate of the current cursor position
2569 * @y: the y coordinate of the current cursor position
2570 * @time: the timestamp of the motion event
2571 * @returns: whether the cursor position is in a drop zone
2573 * The ::drag-drop signal is emitted on the drop site when the user drops
2574 * the data onto the widget. The signal handler must determine whether
2575 * the cursor position is in a drop zone or not. If it is not in a drop
2576 * zone, it returns %FALSE and no further processing is necessary.
2577 * Otherwise, the handler returns %TRUE. In this case, the handler must
2578 * ensure that gtk_drag_finish() is called to let the source know that
2579 * the drop is done. The call to gtk_drag_finish() can be done either
2580 * directly or in a #GtkWidget::drag-data-received handler which gets
2581 * triggered by calling gtk_drag_get_data() to receive the data for one
2582 * or more of the supported targets.
2584 widget_signals[DRAG_DROP] =
2585 g_signal_new (I_("drag-drop"),
2586 G_TYPE_FROM_CLASS (klass),
2588 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2589 _gtk_boolean_handled_accumulator, NULL,
2590 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2592 GDK_TYPE_DRAG_CONTEXT,
2598 * GtkWidget::drag-data-get:
2599 * @widget: the object which received the signal
2600 * @drag_context: the drag context
2601 * @data: the #GtkSelectionData to be filled with the dragged data
2602 * @info: the info that has been registered with the target in the
2604 * @time: the timestamp at which the data was requested
2606 * The ::drag-data-get signal is emitted on the drag source when the drop
2607 * site requests the data which is dragged. It is the responsibility of
2608 * the signal handler to fill @data with the data in the format which
2609 * is indicated by @info. See gtk_selection_data_set() and
2610 * gtk_selection_data_set_text().
2612 widget_signals[DRAG_DATA_GET] =
2613 g_signal_new (I_("drag-data-get"),
2614 G_TYPE_FROM_CLASS (klass),
2616 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2618 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2620 GDK_TYPE_DRAG_CONTEXT,
2621 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2626 * GtkWidget::drag-data-received:
2627 * @widget: the object which received the signal
2628 * @drag_context: the drag context
2629 * @x: where the drop happened
2630 * @y: where the drop happened
2631 * @data: the received data
2632 * @info: the info that has been registered with the target in the
2634 * @time: the timestamp at which the data was received
2636 * The ::drag-data-received signal is emitted on the drop site when the
2637 * dragged data has been received. If the data was received in order to
2638 * determine whether the drop will be accepted, the handler is expected
2639 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2640 * If the data was received in response to a #GtkWidget::drag-drop signal
2641 * (and this is the last target to be received), the handler for this
2642 * signal is expected to process the received data and then call
2643 * gtk_drag_finish(), setting the @success parameter depending on whether
2644 * the data was processed successfully.
2646 * The handler may inspect and modify @drag_context->action before calling
2647 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2648 * following example:
2651 * drag_data_received (GtkWidget *widget,
2652 * GdkDragContext *drag_context,
2655 * GtkSelectionData *data,
2659 * if ((data->length >= 0) && (data->format == 8))
2661 * if (drag_context->action == GDK_ACTION_ASK)
2663 * GtkWidget *dialog;
2666 * dialog = gtk_message_dialog_new (NULL,
2667 * GTK_DIALOG_MODAL |
2668 * GTK_DIALOG_DESTROY_WITH_PARENT,
2670 * GTK_BUTTONS_YES_NO,
2671 * "Move the data ?\n");
2672 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2673 * gtk_widget_destroy (dialog);
2675 * if (response == GTK_RESPONSE_YES)
2676 * drag_context->action = GDK_ACTION_MOVE;
2678 * drag_context->action = GDK_ACTION_COPY;
2681 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2685 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2689 widget_signals[DRAG_DATA_RECEIVED] =
2690 g_signal_new (I_("drag-data-received"),
2691 G_TYPE_FROM_CLASS (klass),
2693 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2695 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2697 GDK_TYPE_DRAG_CONTEXT,
2700 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2705 * GtkWidget::visibility-notify-event:
2706 * @widget: the object which received the signal
2707 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2708 * triggered this signal.
2710 * The ::visibility-notify-event will be emitted when the @widget's window
2711 * is obscured or unobscured.
2713 * To receive this signal the #GdkWindow associated to the widget needs
2714 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2716 * Returns: %TRUE to stop other handlers from being invoked for the event.
2717 * %FALSE to propagate the event further.
2719 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2720 g_signal_new (I_("visibility-notify-event"),
2721 G_TYPE_FROM_CLASS (klass),
2723 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2724 _gtk_boolean_handled_accumulator, NULL,
2725 _gtk_marshal_BOOLEAN__BOXED,
2727 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2730 * GtkWidget::client-event:
2731 * @widget: the object which received the signal
2732 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2735 * The ::client-event will be emitted when the @widget's window
2736 * receives a message (via a ClientMessage event) from another
2739 * Returns: %TRUE to stop other handlers from being invoked for
2740 * the event. %FALSE to propagate the event further.
2742 widget_signals[CLIENT_EVENT] =
2743 g_signal_new (I_("client-event"),
2744 G_TYPE_FROM_CLASS (klass),
2746 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2747 _gtk_boolean_handled_accumulator, NULL,
2748 _gtk_marshal_BOOLEAN__BOXED,
2750 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2753 * GtkWidget::window-state-event:
2754 * @widget: the object which received the signal
2755 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2756 * triggered this signal.
2758 * The ::window-state-event will be emitted when the state of the
2759 * toplevel window associated to the @widget changes.
2761 * To receive this signal the #GdkWindow associated to the widget
2762 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2763 * this mask automatically for all new windows.
2765 * Returns: %TRUE to stop other handlers from being invoked for the
2766 * event. %FALSE to propagate the event further.
2768 widget_signals[WINDOW_STATE_EVENT] =
2769 g_signal_new (I_("window-state-event"),
2770 G_TYPE_FROM_CLASS (klass),
2772 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2773 _gtk_boolean_handled_accumulator, NULL,
2774 _gtk_marshal_BOOLEAN__BOXED,
2776 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2779 * GtkWidget::damage-event:
2780 * @widget: the object which received the signal
2781 * @event: the #GdkEventExpose event
2783 * Emitted when a redirected window belonging to @widget gets drawn into.
2784 * The region/area members of the event shows what area of the redirected
2785 * drawable was drawn into.
2787 * Returns: %TRUE to stop other handlers from being invoked for the event.
2788 * %FALSE to propagate the event further.
2792 widget_signals[DAMAGE_EVENT] =
2793 g_signal_new (I_("damage-event"),
2794 G_TYPE_FROM_CLASS (klass),
2796 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2797 _gtk_boolean_handled_accumulator, NULL,
2798 _gtk_marshal_BOOLEAN__BOXED,
2800 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2803 * GtkWidget::grab-broken-event:
2804 * @widget: the object which received the signal
2805 * @event: the #GdkEventGrabBroken event
2807 * Emitted when a pointer or keyboard grab on a window belonging
2808 * to @widget gets broken.
2810 * On X11, this happens when the grab window becomes unviewable
2811 * (i.e. it or one of its ancestors is unmapped), or if the same
2812 * application grabs the pointer or keyboard again.
2814 * Returns: %TRUE to stop other handlers from being invoked for
2815 * the event. %FALSE to propagate the event further.
2819 widget_signals[GRAB_BROKEN_EVENT] =
2820 g_signal_new (I_("grab-broken-event"),
2821 G_TYPE_FROM_CLASS (klass),
2823 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2824 _gtk_boolean_handled_accumulator, NULL,
2825 _gtk_marshal_BOOLEAN__BOXED,
2827 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2830 * GtkWidget::query-tooltip:
2831 * @widget: the object which received the signal
2832 * @x: the x coordinate of the cursor position where the request has
2833 * been emitted, relative to @widget->window
2834 * @y: the y coordinate of the cursor position where the request has
2835 * been emitted, relative to @widget->window
2836 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2837 * @tooltip: a #GtkTooltip
2839 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2840 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2841 * focus in keyboard mode.
2843 * Using the given coordinates, the signal handler should determine
2844 * whether a tooltip should be shown for @widget. If this is the case
2845 * %TRUE should be returned, %FALSE otherwise. Note that if
2846 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2847 * should not be used.
2849 * The signal handler is free to manipulate @tooltip with the therefore
2850 * destined function calls.
2852 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2856 widget_signals[QUERY_TOOLTIP] =
2857 g_signal_new (I_("query-tooltip"),
2858 G_TYPE_FROM_CLASS (klass),
2860 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2861 _gtk_boolean_handled_accumulator, NULL,
2862 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2870 * GtkWidget::popup-menu
2871 * @widget: the object which received the signal
2873 * This signal gets emitted whenever a widget should pop up a context
2874 * menu. This usually happens through the standard key binding mechanism;
2875 * by pressing a certain key while a widget is focused, the user can cause
2876 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2877 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2878 * for an example of how to use this signal.
2880 * Returns: %TRUE if a menu was activated
2882 widget_signals[POPUP_MENU] =
2883 g_signal_new (I_("popup-menu"),
2884 G_TYPE_FROM_CLASS (klass),
2885 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2886 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2887 _gtk_boolean_handled_accumulator, NULL,
2888 _gtk_marshal_BOOLEAN__VOID,
2892 * GtkWidget::show-help:
2893 * @widget: the object which received the signal.
2896 widget_signals[SHOW_HELP] =
2897 g_signal_new (I_("show-help"),
2898 G_TYPE_FROM_CLASS (klass),
2899 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2900 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2901 _gtk_boolean_handled_accumulator, NULL,
2902 _gtk_marshal_BOOLEAN__ENUM,
2904 GTK_TYPE_WIDGET_HELP_TYPE);
2907 * GtkWidget::accel-closures-changed:
2908 * @widget: the object which received the signal.
2910 widget_signals[ACCEL_CLOSURES_CHANGED] =
2911 g_signal_new (I_("accel-closures-changed"),
2912 G_TYPE_FROM_CLASS (klass),
2916 _gtk_marshal_VOID__VOID,
2920 * GtkWidget::screen-changed:
2921 * @widget: the object on which the signal is emitted
2922 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2923 * widget was not associated with a screen before
2925 * The ::screen-changed signal gets emitted when the
2926 * screen of a widget has changed.
2928 widget_signals[SCREEN_CHANGED] =
2929 g_signal_new (I_("screen-changed"),
2930 G_TYPE_FROM_CLASS (klass),
2932 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2934 _gtk_marshal_VOID__OBJECT,
2939 * GtkWidget::can-activate-accel:
2940 * @widget: the object which received the signal
2941 * @signal_id: the ID of a signal installed on @widget
2943 * Determines whether an accelerator that activates the signal
2944 * identified by @signal_id can currently be activated.
2945 * This signal is present to allow applications and derived
2946 * widgets to override the default #GtkWidget handling
2947 * for determining whether an accelerator can be activated.
2949 * Returns: %TRUE if the signal can be activated.
2951 widget_signals[CAN_ACTIVATE_ACCEL] =
2952 g_signal_new (I_("can-activate-accel"),
2953 G_TYPE_FROM_CLASS (klass),
2955 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2956 _gtk_boolean_handled_accumulator, NULL,
2957 _gtk_marshal_BOOLEAN__UINT,
2958 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2960 binding_set = gtk_binding_set_by_class (klass);
2961 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2963 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2966 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2968 GTK_TYPE_WIDGET_HELP_TYPE,
2969 GTK_WIDGET_HELP_TOOLTIP);
2970 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2972 GTK_TYPE_WIDGET_HELP_TYPE,
2973 GTK_WIDGET_HELP_TOOLTIP);
2974 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2976 GTK_TYPE_WIDGET_HELP_TYPE,
2977 GTK_WIDGET_HELP_WHATS_THIS);
2978 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2980 GTK_TYPE_WIDGET_HELP_TYPE,
2981 GTK_WIDGET_HELP_WHATS_THIS);
2983 gtk_widget_class_install_style_property (klass,
2984 g_param_spec_boolean ("interior-focus",
2985 P_("Interior Focus"),
2986 P_("Whether to draw the focus indicator inside widgets"),
2988 GTK_PARAM_READABLE));
2990 gtk_widget_class_install_style_property (klass,
2991 g_param_spec_int ("focus-line-width",
2992 P_("Focus linewidth"),
2993 P_("Width, in pixels, of the focus indicator line"),
2995 GTK_PARAM_READABLE));
2997 gtk_widget_class_install_style_property (klass,
2998 g_param_spec_string ("focus-line-pattern",
2999 P_("Focus line dash pattern"),
3000 P_("Dash pattern used to draw the focus indicator"),
3002 GTK_PARAM_READABLE));
3003 gtk_widget_class_install_style_property (klass,
3004 g_param_spec_int ("focus-padding",
3005 P_("Focus padding"),
3006 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3008 GTK_PARAM_READABLE));
3009 gtk_widget_class_install_style_property (klass,
3010 g_param_spec_boxed ("cursor-color",
3012 P_("Color with which to draw insertion cursor"),
3014 GTK_PARAM_READABLE));
3015 gtk_widget_class_install_style_property (klass,
3016 g_param_spec_boxed ("secondary-cursor-color",
3017 P_("Secondary cursor color"),
3018 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3020 GTK_PARAM_READABLE));
3021 gtk_widget_class_install_style_property (klass,
3022 g_param_spec_float ("cursor-aspect-ratio",
3023 P_("Cursor line aspect ratio"),
3024 P_("Aspect ratio with which to draw insertion cursor"),
3026 GTK_PARAM_READABLE));
3028 gtk_widget_class_install_style_property (klass,
3029 g_param_spec_boolean ("window-dragging",
3030 P_("Window dragging"),
3031 P_("Whether windows can be dragged by clicking on empty areas"),
3033 GTK_PARAM_READABLE));
3036 * GtkWidget:link-color:
3038 * The "link-color" style property defines the color of unvisited links.
3042 gtk_widget_class_install_style_property (klass,
3043 g_param_spec_boxed ("link-color",
3044 P_("Unvisited Link Color"),
3045 P_("Color of unvisited links"),
3047 GTK_PARAM_READABLE));
3050 * GtkWidget:visited-link-color:
3052 * The "visited-link-color" style property defines the color of visited links.
3056 gtk_widget_class_install_style_property (klass,
3057 g_param_spec_boxed ("visited-link-color",
3058 P_("Visited Link Color"),
3059 P_("Color of visited links"),
3061 GTK_PARAM_READABLE));
3064 * GtkWidget:wide-separators:
3066 * The "wide-separators" style property defines whether separators have
3067 * configurable width and should be drawn using a box instead of a line.
3071 gtk_widget_class_install_style_property (klass,
3072 g_param_spec_boolean ("wide-separators",
3073 P_("Wide Separators"),
3074 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3076 GTK_PARAM_READABLE));
3079 * GtkWidget:separator-width:
3081 * The "separator-width" style property defines the width of separators.
3082 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3086 gtk_widget_class_install_style_property (klass,
3087 g_param_spec_int ("separator-width",
3088 P_("Separator Width"),
3089 P_("The width of separators if wide-separators is TRUE"),
3091 GTK_PARAM_READABLE));
3094 * GtkWidget:separator-height:
3096 * The "separator-height" style property defines the height of separators.
3097 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3101 gtk_widget_class_install_style_property (klass,
3102 g_param_spec_int ("separator-height",
3103 P_("Separator Height"),
3104 P_("The height of separators if \"wide-separators\" is TRUE"),
3106 GTK_PARAM_READABLE));
3109 * GtkWidget:scroll-arrow-hlength:
3111 * The "scroll-arrow-hlength" style property defines the length of
3112 * horizontal scroll arrows.
3116 gtk_widget_class_install_style_property (klass,
3117 g_param_spec_int ("scroll-arrow-hlength",
3118 P_("Horizontal Scroll Arrow Length"),
3119 P_("The length of horizontal scroll arrows"),
3121 GTK_PARAM_READABLE));
3124 * GtkWidget:scroll-arrow-vlength:
3126 * The "scroll-arrow-vlength" style property defines the length of
3127 * vertical scroll arrows.
3131 gtk_widget_class_install_style_property (klass,
3132 g_param_spec_int ("scroll-arrow-vlength",
3133 P_("Vertical Scroll Arrow Length"),
3134 P_("The length of vertical scroll arrows"),
3136 GTK_PARAM_READABLE));
3138 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3142 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3146 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3147 for (node = list; node; node = node->next)
3149 GParamSpec *pspec = node->data;
3151 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3152 g_param_spec_unref (pspec);
3158 gtk_widget_set_property (GObject *object,
3160 const GValue *value,
3163 GtkWidget *widget = GTK_WIDGET (object);
3168 gchar *tooltip_markup;
3169 const gchar *tooltip_text;
3170 GtkWindow *tooltip_window;
3173 gtk_widget_set_name (widget, g_value_get_string (value));
3176 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3178 case PROP_WIDTH_REQUEST:
3179 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3181 case PROP_HEIGHT_REQUEST:
3182 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3185 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3187 case PROP_SENSITIVE:
3188 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3190 case PROP_APP_PAINTABLE:
3191 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3193 case PROP_CAN_FOCUS:
3194 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3196 case PROP_HAS_FOCUS:
3197 if (g_value_get_boolean (value))
3198 gtk_widget_grab_focus (widget);
3201 if (g_value_get_boolean (value))
3202 gtk_widget_grab_focus (widget);
3204 case PROP_CAN_DEFAULT:
3205 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3207 case PROP_HAS_DEFAULT:
3208 if (g_value_get_boolean (value))
3209 gtk_widget_grab_default (widget);
3211 case PROP_RECEIVES_DEFAULT:
3212 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3215 gtk_widget_set_style (widget, g_value_get_object (value));
3218 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3219 gtk_widget_set_events (widget, g_value_get_flags (value));
3221 case PROP_NO_SHOW_ALL:
3222 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3224 case PROP_HAS_TOOLTIP:
3225 gtk_widget_real_set_has_tooltip (widget,
3226 g_value_get_boolean (value), FALSE);
3228 case PROP_TOOLTIP_MARKUP:
3229 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3230 tooltip_markup = g_value_dup_string (value);
3232 /* Treat an empty string as a NULL string,
3233 * because an empty string would be useless for a tooltip:
3235 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3237 g_free (tooltip_markup);
3238 tooltip_markup = NULL;
3241 g_object_set_qdata_full (object, quark_tooltip_markup,
3242 tooltip_markup, g_free);
3244 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3245 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3246 if (gtk_widget_get_visible (widget))
3247 gtk_widget_queue_tooltip_query (widget);
3249 case PROP_TOOLTIP_TEXT:
3250 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3252 tooltip_text = g_value_get_string (value);
3254 /* Treat an empty string as a NULL string,
3255 * because an empty string would be useless for a tooltip:
3257 if (tooltip_text && (strlen (tooltip_text) == 0))
3258 tooltip_text = NULL;
3260 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3262 g_object_set_qdata_full (object, quark_tooltip_markup,
3263 tooltip_markup, g_free);
3265 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3266 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3267 if (gtk_widget_get_visible (widget))
3268 gtk_widget_queue_tooltip_query (widget);
3270 case PROP_DOUBLE_BUFFERED:
3271 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3274 gtk_widget_set_halign (widget, g_value_get_enum (value));
3277 gtk_widget_set_valign (widget, g_value_get_enum (value));
3279 case PROP_MARGIN_LEFT:
3280 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3282 case PROP_MARGIN_RIGHT:
3283 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3285 case PROP_MARGIN_TOP:
3286 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3288 case PROP_MARGIN_BOTTOM:
3289 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3292 g_object_freeze_notify (G_OBJECT (widget));
3293 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3294 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3295 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3296 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3297 g_object_thaw_notify (G_OBJECT (widget));
3300 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3302 case PROP_HEXPAND_SET:
3303 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3306 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3308 case PROP_VEXPAND_SET:
3309 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3312 g_object_freeze_notify (G_OBJECT (widget));
3313 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3314 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3315 g_object_thaw_notify (G_OBJECT (widget));
3318 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3324 gtk_widget_get_property (GObject *object,
3329 GtkWidget *widget = GTK_WIDGET (object);
3330 GtkWidgetPrivate *priv = widget->priv;
3338 g_value_set_string (value, priv->name);
3340 g_value_set_static_string (value, "");
3343 g_value_set_object (value, priv->parent);
3345 case PROP_WIDTH_REQUEST:
3348 gtk_widget_get_size_request (widget, &w, NULL);
3349 g_value_set_int (value, w);
3352 case PROP_HEIGHT_REQUEST:
3355 gtk_widget_get_size_request (widget, NULL, &h);
3356 g_value_set_int (value, h);
3360 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3362 case PROP_SENSITIVE:
3363 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3365 case PROP_APP_PAINTABLE:
3366 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3368 case PROP_CAN_FOCUS:
3369 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3371 case PROP_HAS_FOCUS:
3372 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3375 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3377 case PROP_CAN_DEFAULT:
3378 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3380 case PROP_HAS_DEFAULT:
3381 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3383 case PROP_RECEIVES_DEFAULT:
3384 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3386 case PROP_COMPOSITE_CHILD:
3387 g_value_set_boolean (value, widget->priv->composite_child);
3390 g_value_set_object (value, gtk_widget_get_style (widget));
3393 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3394 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3396 case PROP_NO_SHOW_ALL:
3397 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3399 case PROP_HAS_TOOLTIP:
3400 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3402 case PROP_TOOLTIP_TEXT:
3404 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3407 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3408 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3410 g_value_take_string (value, text);
3413 case PROP_TOOLTIP_MARKUP:
3414 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3417 g_value_set_object (value, gtk_widget_get_window (widget));
3419 case PROP_DOUBLE_BUFFERED:
3420 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3423 g_value_set_enum (value, gtk_widget_get_halign (widget));
3426 g_value_set_enum (value, gtk_widget_get_valign (widget));
3428 case PROP_MARGIN_LEFT:
3429 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3431 case PROP_MARGIN_RIGHT:
3432 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3434 case PROP_MARGIN_TOP:
3435 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3437 case PROP_MARGIN_BOTTOM:
3438 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3442 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3443 if (aux_info == NULL)
3445 g_value_set_int (value, 0);
3449 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3450 aux_info->margin.right),
3451 MAX (aux_info->margin.top,
3452 aux_info->margin.bottom)));
3457 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3459 case PROP_HEXPAND_SET:
3460 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3463 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3465 case PROP_VEXPAND_SET:
3466 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3469 g_value_set_boolean (value,
3470 gtk_widget_get_hexpand (widget) &&
3471 gtk_widget_get_vexpand (widget));
3474 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3480 gtk_widget_init (GtkWidget *widget)
3482 GtkWidgetPrivate *priv;
3484 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3487 priv = widget->priv;
3489 priv->child_visible = TRUE;
3491 priv->allocation.x = -1;
3492 priv->allocation.y = -1;
3493 priv->allocation.width = 1;
3494 priv->allocation.height = 1;
3495 priv->window = NULL;
3496 priv->parent = NULL;
3498 priv->sensitive = TRUE;
3499 priv->parent_sensitive = TRUE;
3500 priv->composite_child = composite_child_stack != 0;
3501 priv->double_buffered = TRUE;
3502 priv->redraw_on_alloc = TRUE;
3503 priv->width_request_needed = TRUE;
3504 priv->height_request_needed = TRUE;
3505 priv->alloc_needed = TRUE;
3507 /* this will be set to TRUE if the widget gets a child or if the
3508 * expand flag is set on the widget, but until one of those happen
3509 * we know the expand is already properly FALSE.
3511 * We really want to default FALSE here to avoid computing expand
3512 * all over the place while initially building a widget tree.
3514 priv->need_compute_expand = FALSE;
3516 priv->style = gtk_widget_get_default_style ();
3517 g_object_ref (priv->style);
3522 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3524 GParamSpec **pspecs)
3526 GtkWidgetPrivate *priv = widget->priv;
3527 GtkWidget *container = priv->parent;
3530 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3531 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3535 * gtk_widget_freeze_child_notify:
3536 * @widget: a #GtkWidget
3538 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3539 * signals are queued until gtk_widget_thaw_child_notify() is called
3542 * This is the analogue of g_object_freeze_notify() for child properties.
3545 gtk_widget_freeze_child_notify (GtkWidget *widget)
3547 g_return_if_fail (GTK_IS_WIDGET (widget));
3549 if (!G_OBJECT (widget)->ref_count)
3552 g_object_ref (widget);
3553 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3554 g_object_unref (widget);
3558 * gtk_widget_child_notify:
3559 * @widget: a #GtkWidget
3560 * @child_property: the name of a child property installed on the
3561 * class of @widget<!-- -->'s parent
3563 * Emits a #GtkWidget::child-notify signal for the
3564 * <link linkend="child-properties">child property</link> @child_property
3567 * This is the analogue of g_object_notify() for child properties.
3570 gtk_widget_child_notify (GtkWidget *widget,
3571 const gchar *child_property)
3573 GtkWidgetPrivate *priv = widget->priv;
3576 g_return_if_fail (GTK_IS_WIDGET (widget));
3577 g_return_if_fail (child_property != NULL);
3578 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3581 g_object_ref (widget);
3582 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3584 G_OBJECT_TYPE (priv->parent),
3587 g_warning ("%s: container class `%s' has no child property named `%s'",
3589 G_OBJECT_TYPE_NAME (priv->parent),
3593 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3595 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3596 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3598 g_object_unref (widget);
3602 * gtk_widget_thaw_child_notify:
3603 * @widget: a #GtkWidget
3605 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3606 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3610 gtk_widget_thaw_child_notify (GtkWidget *widget)
3612 GObjectNotifyQueue *nqueue;
3614 g_return_if_fail (GTK_IS_WIDGET (widget));
3616 if (!G_OBJECT (widget)->ref_count)
3619 g_object_ref (widget);
3620 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3621 if (!nqueue || !nqueue->freeze_count)
3622 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3623 G_OBJECT_TYPE_NAME (widget), widget);
3625 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3626 g_object_unref (widget);
3632 * @type: type ID of the widget to create
3633 * @first_property_name: name of first property to set
3634 * @Varargs: value of first property, followed by more properties,
3637 * This is a convenience function for creating a widget and setting
3638 * its properties in one go. For example you might write:
3639 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3640 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3641 * g_object_new(), but returns a widget so you don't have to
3642 * cast the object yourself.
3644 * Return value: a new #GtkWidget of type @widget_type
3647 gtk_widget_new (GType type,
3648 const gchar *first_property_name,
3654 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3656 va_start (var_args, first_property_name);
3657 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3664 gtk_widget_queue_draw_child (GtkWidget *widget)
3666 GtkWidgetPrivate *priv = widget->priv;
3669 parent = priv->parent;
3670 if (parent && gtk_widget_is_drawable (parent))
3671 gtk_widget_queue_draw_area (parent,
3674 priv->allocation.width,
3675 priv->allocation.height);
3679 * gtk_widget_unparent:
3680 * @widget: a #GtkWidget
3682 * This function is only for use in widget implementations.
3683 * Should be called by implementations of the remove method
3684 * on #GtkContainer, to dissociate a child from the container.
3687 gtk_widget_unparent (GtkWidget *widget)
3689 GtkWidgetPrivate *priv;
3690 GObjectNotifyQueue *nqueue;
3691 GtkWidget *toplevel;
3692 GtkWidget *old_parent;
3694 g_return_if_fail (GTK_IS_WIDGET (widget));
3696 priv = widget->priv;
3698 if (priv->parent == NULL)
3701 /* keep this function in sync with gtk_menu_detach()
3704 g_object_freeze_notify (G_OBJECT (widget));
3705 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3707 toplevel = gtk_widget_get_toplevel (widget);
3708 if (gtk_widget_is_toplevel (toplevel))
3709 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3711 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3712 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3714 /* If we are unanchoring the child, we save around the toplevel
3715 * to emit hierarchy changed
3717 if (priv->parent->priv->anchored)
3718 g_object_ref (toplevel);
3722 gtk_widget_queue_draw_child (widget);
3724 /* Reset the width and height here, to force reallocation if we
3725 * get added back to a new parent. This won't work if our new
3726 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3727 * (would 0x0 be OK here?)
3729 priv->allocation.width = 1;
3730 priv->allocation.height = 1;
3732 if (gtk_widget_get_realized (widget))
3734 if (priv->in_reparent)
3735 gtk_widget_unmap (widget);
3737 gtk_widget_unrealize (widget);
3740 /* Removing a widget from a container restores the child visible
3741 * flag to the default state, so it doesn't affect the child
3742 * in the next parent.
3744 priv->child_visible = TRUE;
3746 old_parent = priv->parent;
3747 priv->parent = NULL;
3748 gtk_widget_set_parent_window (widget, NULL);
3750 /* parent may no longer expand if the removed
3751 * child was expand=TRUE and could therefore
3754 if (gtk_widget_get_visible (widget) &&
3755 (priv->need_compute_expand ||
3756 priv->computed_hexpand ||
3757 priv->computed_vexpand))
3759 gtk_widget_queue_compute_expand (old_parent);
3762 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3765 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3766 g_object_unref (toplevel);
3769 g_object_notify (G_OBJECT (widget), "parent");
3770 g_object_thaw_notify (G_OBJECT (widget));
3772 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3773 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3774 g_object_unref (widget);
3778 * gtk_widget_destroy:
3779 * @widget: a #GtkWidget
3781 * Destroys a widget.
3784 * destroyed, it will break any references it holds to other objects.
3785 * If the widget is inside a container, the widget will be removed
3786 * from the container. If the widget is a toplevel (derived from
3787 * #GtkWindow), it will be removed from the list of toplevels, and the
3788 * reference GTK+ holds to it will be removed. Removing a
3789 * widget from its container or the list of toplevels results in the
3790 * widget being finalized, unless you've added additional references
3791 * to the widget with g_object_ref().
3793 * In most cases, only toplevel widgets (windows) require explicit
3794 * destruction, because when you destroy a toplevel its children will
3795 * be destroyed as well.
3798 gtk_widget_destroy (GtkWidget *widget)
3800 g_return_if_fail (GTK_IS_WIDGET (widget));
3802 if (!widget->priv->in_destruction)
3803 g_object_run_dispose (G_OBJECT (widget));
3807 * gtk_widget_destroyed:
3808 * @widget: a #GtkWidget
3809 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3811 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3812 * %NULL. It's intended to be used as a callback connected to the
3813 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3814 * as a signal handler, and pass the address of your widget variable
3815 * as user data. Then when the widget is destroyed, the variable will
3816 * be set to %NULL. Useful for example to avoid multiple copies
3817 * of the same dialog.
3820 gtk_widget_destroyed (GtkWidget *widget,
3821 GtkWidget **widget_pointer)
3823 /* Don't make any assumptions about the
3825 * Even check widget_pointer.
3828 *widget_pointer = NULL;
3833 * @widget: a #GtkWidget
3835 * Flags a widget to be displayed. Any widget that isn't shown will
3836 * not appear on the screen. If you want to show all the widgets in a
3837 * container, it's easier to call gtk_widget_show_all() on the
3838 * container, instead of individually showing the widgets.
3840 * Remember that you have to show the containers containing a widget,
3841 * in addition to the widget itself, before it will appear onscreen.
3843 * When a toplevel container is shown, it is immediately realized and
3844 * mapped; other shown widgets are realized and mapped when their
3845 * toplevel container is realized and mapped.
3848 gtk_widget_show (GtkWidget *widget)
3850 g_return_if_fail (GTK_IS_WIDGET (widget));
3852 if (!gtk_widget_get_visible (widget))
3854 g_object_ref (widget);
3855 if (!gtk_widget_is_toplevel (widget))
3856 gtk_widget_queue_resize (widget);
3858 /* see comment in set_parent() for why this should and can be
3861 if (widget->priv->need_compute_expand ||
3862 widget->priv->computed_hexpand ||
3863 widget->priv->computed_vexpand)
3865 if (widget->priv->parent != NULL)
3866 gtk_widget_queue_compute_expand (widget->priv->parent);
3869 g_signal_emit (widget, widget_signals[SHOW], 0);
3870 g_object_notify (G_OBJECT (widget), "visible");
3871 g_object_unref (widget);
3876 gtk_widget_real_show (GtkWidget *widget)
3878 GtkWidgetPrivate *priv = widget->priv;
3880 if (!gtk_widget_get_visible (widget))
3882 priv->visible = TRUE;
3885 gtk_widget_get_mapped (priv->parent) &&
3886 gtk_widget_get_child_visible (widget) &&
3887 !gtk_widget_get_mapped (widget))
3888 gtk_widget_map (widget);
3893 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3896 g_signal_handlers_disconnect_by_func (widget,
3897 gtk_widget_show_map_callback,
3902 * gtk_widget_show_now:
3903 * @widget: a #GtkWidget
3905 * Shows a widget. If the widget is an unmapped toplevel widget
3906 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3907 * loop and wait for the window to actually be mapped. Be careful;
3908 * because the main loop is running, anything can happen during
3912 gtk_widget_show_now (GtkWidget *widget)
3916 g_return_if_fail (GTK_IS_WIDGET (widget));
3918 /* make sure we will get event */
3919 if (!gtk_widget_get_mapped (widget) &&
3920 gtk_widget_is_toplevel (widget))
3922 gtk_widget_show (widget);
3924 g_signal_connect (widget, "map-event",
3925 G_CALLBACK (gtk_widget_show_map_callback),
3929 gtk_main_iteration ();
3932 gtk_widget_show (widget);
3937 * @widget: a #GtkWidget
3939 * Reverses the effects of gtk_widget_show(), causing the widget to be
3940 * hidden (invisible to the user).
3943 gtk_widget_hide (GtkWidget *widget)
3945 g_return_if_fail (GTK_IS_WIDGET (widget));
3947 if (gtk_widget_get_visible (widget))
3949 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3951 g_object_ref (widget);
3952 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3953 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3955 /* a parent may now be expand=FALSE since we're hidden. */
3956 if (widget->priv->need_compute_expand ||
3957 widget->priv->computed_hexpand ||
3958 widget->priv->computed_vexpand)
3960 gtk_widget_queue_compute_expand (widget);
3963 g_signal_emit (widget, widget_signals[HIDE], 0);
3964 if (!gtk_widget_is_toplevel (widget))
3965 gtk_widget_queue_resize (widget);
3966 g_object_notify (G_OBJECT (widget), "visible");
3967 g_object_unref (widget);
3972 gtk_widget_real_hide (GtkWidget *widget)
3974 if (gtk_widget_get_visible (widget))
3976 widget->priv->visible = FALSE;
3978 if (gtk_widget_get_mapped (widget))
3979 gtk_widget_unmap (widget);
3984 * gtk_widget_hide_on_delete:
3985 * @widget: a #GtkWidget
3987 * Utility function; intended to be connected to the #GtkWidget::delete-event
3988 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3989 * argument, then returns %TRUE. If connected to ::delete-event, the
3990 * result is that clicking the close button for a window (on the
3991 * window frame, top right corner usually) will hide but not destroy
3992 * the window. By default, GTK+ destroys windows when ::delete-event
3995 * Return value: %TRUE
3998 gtk_widget_hide_on_delete (GtkWidget *widget)
4000 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4002 gtk_widget_hide (widget);
4008 * gtk_widget_show_all:
4009 * @widget: a #GtkWidget
4011 * Recursively shows a widget, and any child widgets (if the widget is
4015 gtk_widget_show_all (GtkWidget *widget)
4017 GtkWidgetClass *class;
4019 g_return_if_fail (GTK_IS_WIDGET (widget));
4021 if (gtk_widget_get_no_show_all (widget))
4024 class = GTK_WIDGET_GET_CLASS (widget);
4026 if (class->show_all)
4027 class->show_all (widget);
4031 _gtk_widget_notify_state_change (GtkWidget *widget,
4039 case GTK_STATE_FLAG_ACTIVE:
4040 state = GTK_STATE_ACTIVE;
4042 case GTK_STATE_FLAG_PRELIGHT:
4043 state = GTK_STATE_PRELIGHT;
4045 case GTK_STATE_FLAG_SELECTED:
4046 state = GTK_STATE_SELECTED;
4048 case GTK_STATE_FLAG_INSENSITIVE:
4049 state = GTK_STATE_INSENSITIVE;
4051 case GTK_STATE_FLAG_INCONSISTENT:
4052 state = GTK_STATE_INCONSISTENT;
4054 case GTK_STATE_FLAG_FOCUSED:
4055 state = GTK_STATE_FOCUSED;
4061 gtk_style_context_notify_state_change (widget->priv->context,
4062 gtk_widget_get_window (widget),
4063 NULL, state, target);
4066 /* Initializes state transitions for those states that
4067 * were enabled before mapping and have a looping animation.
4070 _gtk_widget_start_state_transitions (GtkWidget *widget)
4072 GtkStateFlags state, flag;
4074 if (!widget->priv->context)
4077 state = gtk_widget_get_state_flags (widget);
4078 flag = GTK_STATE_FLAG_FOCUSED;
4082 GtkAnimationDescription *animation_desc;
4084 if ((state & flag) == 0)
4090 gtk_style_context_get (widget->priv->context, state,
4091 "transition", &animation_desc,
4096 if (_gtk_animation_description_get_loop (animation_desc))
4097 _gtk_widget_notify_state_change (widget, flag, TRUE);
4099 _gtk_animation_description_unref (animation_desc);
4108 * @widget: a #GtkWidget
4110 * This function is only for use in widget implementations. Causes
4111 * a widget to be mapped if it isn't already.
4114 gtk_widget_map (GtkWidget *widget)
4116 GtkWidgetPrivate *priv;
4118 g_return_if_fail (GTK_IS_WIDGET (widget));
4119 g_return_if_fail (gtk_widget_get_visible (widget));
4120 g_return_if_fail (gtk_widget_get_child_visible (widget));
4122 priv = widget->priv;
4124 if (!gtk_widget_get_mapped (widget))
4126 if (!gtk_widget_get_realized (widget))
4127 gtk_widget_realize (widget);
4129 g_signal_emit (widget, widget_signals[MAP], 0);
4131 if (!gtk_widget_get_has_window (widget))
4132 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4134 _gtk_widget_start_state_transitions (widget);
4140 * @widget: a #GtkWidget
4142 * This function is only for use in widget implementations. Causes
4143 * a widget to be unmapped if it's currently mapped.
4146 gtk_widget_unmap (GtkWidget *widget)
4148 GtkWidgetPrivate *priv;
4150 g_return_if_fail (GTK_IS_WIDGET (widget));
4152 priv = widget->priv;
4154 if (gtk_widget_get_mapped (widget))
4156 if (!gtk_widget_get_has_window (widget))
4157 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4158 _gtk_tooltip_hide (widget);
4159 g_signal_emit (widget, widget_signals[UNMAP], 0);
4164 _gtk_widget_enable_device_events (GtkWidget *widget)
4166 GHashTable *device_events;
4167 GHashTableIter iter;
4168 gpointer key, value;
4170 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4175 g_hash_table_iter_init (&iter, device_events);
4177 while (g_hash_table_iter_next (&iter, &key, &value))
4180 GdkEventMask event_mask;
4183 event_mask = GPOINTER_TO_UINT (value);
4184 gtk_widget_add_events_internal (widget, device, event_mask);
4189 * gtk_widget_realize:
4190 * @widget: a #GtkWidget
4192 * Creates the GDK (windowing system) resources associated with a
4193 * widget. For example, @widget->window will be created when a widget
4194 * is realized. Normally realization happens implicitly; if you show
4195 * a widget and all its parent containers, then the widget will be
4196 * realized and mapped automatically.
4198 * Realizing a widget requires all
4199 * the widget's parent widgets to be realized; calling
4200 * gtk_widget_realize() realizes the widget's parents in addition to
4201 * @widget itself. If a widget is not yet inside a toplevel window
4202 * when you realize it, bad things will happen.
4204 * This function is primarily used in widget implementations, and
4205 * isn't very useful otherwise. Many times when you think you might
4206 * need it, a better approach is to connect to a signal that will be
4207 * called after the widget is realized automatically, such as
4208 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4209 * #GtkWidget::realize signal.
4212 gtk_widget_realize (GtkWidget *widget)
4214 GtkWidgetPrivate *priv;
4215 cairo_region_t *region;
4217 g_return_if_fail (GTK_IS_WIDGET (widget));
4218 g_return_if_fail (widget->priv->anchored ||
4219 GTK_IS_INVISIBLE (widget));
4221 priv = widget->priv;
4223 if (!gtk_widget_get_realized (widget))
4226 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4227 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4230 if (priv->parent == NULL &&
4231 !gtk_widget_is_toplevel (widget))
4232 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4233 "inside a toplevel window is not going to work very well. "
4234 "Widgets must be inside a toplevel container before realizing them.");
4236 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4237 gtk_widget_realize (priv->parent);
4239 gtk_widget_ensure_style (widget);
4241 g_signal_emit (widget, widget_signals[REALIZE], 0);
4243 gtk_widget_real_set_has_tooltip (widget,
4244 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4247 if (priv->has_shape_mask)
4249 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4250 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4253 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4255 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4257 if (priv->multidevice)
4258 gdk_window_set_support_multidevice (priv->window, TRUE);
4260 _gtk_widget_enable_device_events (widget);
4265 * gtk_widget_unrealize:
4266 * @widget: a #GtkWidget
4268 * This function is only useful in widget implementations.
4269 * Causes a widget to be unrealized (frees all GDK resources
4270 * associated with the widget, such as @widget->window).
4273 gtk_widget_unrealize (GtkWidget *widget)
4275 g_return_if_fail (GTK_IS_WIDGET (widget));
4277 if (widget->priv->has_shape_mask)
4278 gtk_widget_shape_combine_region (widget, NULL);
4280 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4281 gtk_widget_input_shape_combine_region (widget, NULL);
4283 if (gtk_widget_get_realized (widget))
4285 g_object_ref (widget);
4286 _gtk_tooltip_hide (widget);
4287 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4288 gtk_widget_set_realized (widget, FALSE);
4289 gtk_widget_set_mapped (widget, FALSE);
4290 g_object_unref (widget);
4294 /*****************************************
4296 *****************************************/
4299 * gtk_widget_queue_draw_region:
4300 * @widget: a #GtkWidget
4301 * @region: region to draw
4303 * Invalidates the rectangular area of @widget defined by @region by
4304 * calling gdk_window_invalidate_region() on the widget's window and
4305 * all its child windows. Once the main loop becomes idle (after the
4306 * current batch of events has been processed, roughly), the window
4307 * will receive expose events for the union of all regions that have
4310 * Normally you would only use this function in widget
4311 * implementations. You might also use it to schedule a redraw of a
4312 * #GtkDrawingArea or some portion thereof.
4315 gtk_widget_queue_draw_region (GtkWidget *widget,
4316 cairo_region_t *region)
4318 GtkWidgetPrivate *priv;
4321 g_return_if_fail (GTK_IS_WIDGET (widget));
4323 priv = widget->priv;
4325 if (!gtk_widget_get_realized (widget))
4328 /* Just return if the widget or one of its ancestors isn't mapped */
4329 for (w = widget; w != NULL; w = w->priv->parent)
4330 if (!gtk_widget_get_mapped (w))
4333 gdk_window_invalidate_region (priv->window, region, TRUE);
4337 * gtk_widget_queue_draw_area:
4338 * @widget: a #GtkWidget
4339 * @x: x coordinate of upper-left corner of rectangle to redraw
4340 * @y: y coordinate of upper-left corner of rectangle to redraw
4341 * @width: width of region to draw
4342 * @height: height of region to draw
4344 * Convenience function that calls gtk_widget_queue_draw_region() on
4345 * the region created from the given coordinates.
4348 gtk_widget_queue_draw_area (GtkWidget *widget,
4355 cairo_region_t *region;
4357 g_return_if_fail (GTK_IS_WIDGET (widget));
4362 rect.height = height;
4364 region = cairo_region_create_rectangle (&rect);
4365 gtk_widget_queue_draw_region (widget, region);
4366 cairo_region_destroy (region);
4370 * gtk_widget_queue_draw:
4371 * @widget: a #GtkWidget
4373 * Equivalent to calling gtk_widget_queue_draw_area() for the
4374 * entire area of a widget.
4377 gtk_widget_queue_draw (GtkWidget *widget)
4381 g_return_if_fail (GTK_IS_WIDGET (widget));
4383 gtk_widget_get_allocation (widget, &rect);
4385 if (!gtk_widget_get_has_window (widget))
4386 gtk_widget_queue_draw_area (widget,
4387 rect.x, rect.y, rect.width, rect.height);
4389 gtk_widget_queue_draw_area (widget,
4390 0, 0, rect.width, rect.height);
4394 * gtk_widget_queue_resize:
4395 * @widget: a #GtkWidget
4397 * This function is only for use in widget implementations.
4398 * Flags a widget to have its size renegotiated; should
4399 * be called when a widget for some reason has a new size request.
4400 * For example, when you change the text in a #GtkLabel, #GtkLabel
4401 * queues a resize to ensure there's enough space for the new text.
4403 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4404 * from inside it's implementation of the GtkWidgetClass::size_allocate
4405 * virtual method. Calls to gtk_widget_queue_resize() from inside
4406 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4409 gtk_widget_queue_resize (GtkWidget *widget)
4411 g_return_if_fail (GTK_IS_WIDGET (widget));
4413 if (gtk_widget_get_realized (widget))
4414 gtk_widget_queue_shallow_draw (widget);
4416 _gtk_size_group_queue_resize (widget, 0);
4420 * gtk_widget_queue_resize_no_redraw:
4421 * @widget: a #GtkWidget
4423 * This function works like gtk_widget_queue_resize(),
4424 * except that the widget is not invalidated.
4429 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4431 g_return_if_fail (GTK_IS_WIDGET (widget));
4433 _gtk_size_group_queue_resize (widget, 0);
4437 * gtk_widget_size_request:
4438 * @widget: a #GtkWidget
4439 * @requisition: (out): a #GtkRequisition to be filled in
4441 * This function is typically used when implementing a #GtkContainer
4442 * subclass. Obtains the preferred size of a widget. The container
4443 * uses this information to arrange its child widgets and decide what
4444 * size allocations to give them with gtk_widget_size_allocate().
4446 * You can also call this function from an application, with some
4447 * caveats. Most notably, getting a size request requires the widget
4448 * to be associated with a screen, because font information may be
4449 * needed. Multihead-aware applications should keep this in mind.
4451 * Also remember that the size request is not necessarily the size
4452 * a widget will actually be allocated.
4454 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4457 gtk_widget_size_request (GtkWidget *widget,
4458 GtkRequisition *requisition)
4460 g_return_if_fail (GTK_IS_WIDGET (widget));
4462 gtk_widget_get_preferred_size (widget, requisition, NULL);
4466 * gtk_widget_get_child_requisition:
4467 * @widget: a #GtkWidget
4468 * @requisition: (out): a #GtkRequisition to be filled in
4470 * This function is only for use in widget implementations. Obtains
4471 * @widget->requisition, unless someone has forced a particular
4472 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4473 * in which case it returns that geometry instead of the widget's
4476 * This function differs from gtk_widget_size_request() in that
4477 * it retrieves the last size request value from @widget->requisition,
4478 * while gtk_widget_size_request() actually calls the "size_request" method
4479 * on @widget to compute the size request and fill in @widget->requisition,
4480 * and only then returns @widget->requisition.
4482 * Because this function does not call the "size_request" method, it
4483 * can only be used when you know that @widget->requisition is
4484 * up-to-date, that is, gtk_widget_size_request() has been called
4485 * since the last time a resize was queued. In general, only container
4486 * implementations have this information; applications should use
4487 * gtk_widget_size_request().
4490 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4493 gtk_widget_get_child_requisition (GtkWidget *widget,
4494 GtkRequisition *requisition)
4496 gtk_widget_get_preferred_size (widget, requisition, NULL);
4500 invalidate_predicate (GdkWindow *window,
4505 gdk_window_get_user_data (window, &user_data);
4507 return (user_data == data);
4510 /* Invalidate @region in widget->window and all children
4511 * of widget->window owned by widget. @region is in the
4512 * same coordinates as widget->allocation and will be
4513 * modified by this call.
4516 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4517 cairo_region_t *region)
4519 GtkWidgetPrivate *priv = widget->priv;
4521 if (!gtk_widget_get_realized (widget))
4524 if (gtk_widget_get_has_window (widget) && priv->parent)
4528 gdk_window_get_position (priv->window, &x, &y);
4529 cairo_region_translate (region, -x, -y);
4532 gdk_window_invalidate_maybe_recurse (priv->window, region,
4533 invalidate_predicate, widget);
4537 * gtk_widget_queue_shallow_draw:
4538 * @widget: a #GtkWidget
4540 * Like gtk_widget_queue_draw(), but only windows owned
4541 * by @widget are invalidated.
4544 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4547 cairo_region_t *region;
4549 if (!gtk_widget_get_realized (widget))
4552 gtk_widget_get_allocation (widget, &rect);
4554 region = cairo_region_create_rectangle (&rect);
4555 gtk_widget_invalidate_widget_windows (widget, region);
4556 cairo_region_destroy (region);
4560 * gtk_widget_size_allocate:
4561 * @widget: a #GtkWidget
4562 * @allocation: (inout): position and size to be allocated to @widget
4564 * This function is only used by #GtkContainer subclasses, to assign a size
4565 * and position to their child widgets.
4567 * In this function, the allocation may be adjusted. It will be forced
4568 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4569 * method on the child will be used to adjust the allocation. Standard
4570 * adjustments include removing the widget's margins, and applying the
4571 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4574 gtk_widget_size_allocate (GtkWidget *widget,
4575 GtkAllocation *allocation)
4577 GtkWidgetPrivate *priv;
4578 GdkRectangle real_allocation;
4579 GdkRectangle old_allocation;
4580 GdkRectangle adjusted_allocation;
4581 gboolean alloc_needed;
4582 gboolean size_changed;
4583 gboolean position_changed;
4584 gint natural_width, natural_height, dummy;
4585 gint min_width, min_height;
4587 priv = widget->priv;
4589 g_return_if_fail (GTK_IS_WIDGET (widget));
4591 #ifdef G_ENABLE_DEBUG
4592 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4603 parent = gtk_widget_get_parent (parent);
4606 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4607 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4608 2 * depth, " ", name,
4609 allocation->width, allocation->height);
4611 #endif /* G_ENABLE_DEBUG */
4613 alloc_needed = priv->alloc_needed;
4614 if (!priv->width_request_needed && !priv->height_request_needed)
4615 /* Preserve request/allocate ordering */
4616 priv->alloc_needed = FALSE;
4618 old_allocation = priv->allocation;
4619 real_allocation = *allocation;
4621 adjusted_allocation = real_allocation;
4622 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4624 /* Go ahead and request the height for allocated width, note that the internals
4625 * of get_height_for_width will internally limit the for_size to natural size
4626 * when aligning implicitly.
4628 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4629 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4633 /* Go ahead and request the width for allocated height, note that the internals
4634 * of get_width_for_height will internally limit the for_size to natural size
4635 * when aligning implicitly.
4637 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4638 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4641 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4642 * allocated sizes and possibly limit them to the natural sizes */
4643 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4644 GTK_ORIENTATION_HORIZONTAL,
4647 &adjusted_allocation.x,
4648 &adjusted_allocation.width);
4649 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4650 GTK_ORIENTATION_VERTICAL,
4653 &adjusted_allocation.y,
4654 &adjusted_allocation.height);
4656 if (adjusted_allocation.x < real_allocation.x ||
4657 adjusted_allocation.y < real_allocation.y ||
4658 (adjusted_allocation.x + adjusted_allocation.width) >
4659 (real_allocation.x + real_allocation.width) ||
4660 (adjusted_allocation.y + adjusted_allocation.height >
4661 real_allocation.y + real_allocation.height))
4663 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",
4664 G_OBJECT_TYPE_NAME (widget), widget,
4665 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4666 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4667 adjusted_allocation = real_allocation; /* veto it */
4671 real_allocation = adjusted_allocation;
4674 if (real_allocation.width < 0 || real_allocation.height < 0)
4676 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4677 real_allocation.width,
4678 real_allocation.height);
4681 real_allocation.width = MAX (real_allocation.width, 1);
4682 real_allocation.height = MAX (real_allocation.height, 1);
4684 size_changed = (old_allocation.width != real_allocation.width ||
4685 old_allocation.height != real_allocation.height);
4686 position_changed = (old_allocation.x != real_allocation.x ||
4687 old_allocation.y != real_allocation.y);
4689 if (!alloc_needed && !size_changed && !position_changed)
4692 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4694 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4695 priv->width_request_needed = FALSE;
4696 priv->height_request_needed = FALSE;
4697 priv->alloc_needed = FALSE;
4699 if (gtk_widget_get_mapped (widget))
4701 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4703 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4705 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4706 cairo_region_union_rectangle (invalidate, &old_allocation);
4708 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4709 cairo_region_destroy (invalidate);
4714 if (priv->redraw_on_alloc)
4716 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4718 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4719 cairo_region_union_rectangle (invalidate, &old_allocation);
4721 gtk_widget_invalidate_widget_windows (widget, invalidate);
4722 cairo_region_destroy (invalidate);
4726 if (size_changed || position_changed)
4728 GtkStyleContext *context;
4730 context = gtk_widget_get_style_context (widget);
4731 _gtk_style_context_invalidate_animation_areas (context);
4735 if ((size_changed || position_changed) && priv->parent &&
4736 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4738 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4739 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4740 cairo_region_destroy (invalidate);
4745 * gtk_widget_common_ancestor:
4746 * @widget_a: a #GtkWidget
4747 * @widget_b: a #GtkWidget
4749 * Find the common ancestor of @widget_a and @widget_b that
4750 * is closest to the two widgets.
4752 * Return value: the closest common ancestor of @widget_a and
4753 * @widget_b or %NULL if @widget_a and @widget_b do not
4754 * share a common ancestor.
4757 gtk_widget_common_ancestor (GtkWidget *widget_a,
4758 GtkWidget *widget_b)
4760 GtkWidget *parent_a;
4761 GtkWidget *parent_b;
4765 parent_a = widget_a;
4766 while (parent_a->priv->parent)
4768 parent_a = parent_a->priv->parent;
4772 parent_b = widget_b;
4773 while (parent_b->priv->parent)
4775 parent_b = parent_b->priv->parent;
4779 if (parent_a != parent_b)
4782 while (depth_a > depth_b)
4784 widget_a = widget_a->priv->parent;
4788 while (depth_b > depth_a)
4790 widget_b = widget_b->priv->parent;
4794 while (widget_a != widget_b)
4796 widget_a = widget_a->priv->parent;
4797 widget_b = widget_b->priv->parent;
4804 * gtk_widget_translate_coordinates:
4805 * @src_widget: a #GtkWidget
4806 * @dest_widget: a #GtkWidget
4807 * @src_x: X position relative to @src_widget
4808 * @src_y: Y position relative to @src_widget
4809 * @dest_x: (out): location to store X position relative to @dest_widget
4810 * @dest_y: (out): location to store Y position relative to @dest_widget
4812 * Translate coordinates relative to @src_widget's allocation to coordinates
4813 * relative to @dest_widget's allocations. In order to perform this
4814 * operation, both widgets must be realized, and must share a common
4817 * Return value: %FALSE if either widget was not realized, or there
4818 * was no common ancestor. In this case, nothing is stored in
4819 * *@dest_x and *@dest_y. Otherwise %TRUE.
4822 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4823 GtkWidget *dest_widget,
4829 GtkWidgetPrivate *src_priv = src_widget->priv;
4830 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4831 GtkWidget *ancestor;
4833 GList *dest_list = NULL;
4835 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4836 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4838 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4839 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4842 /* Translate from allocation relative to window relative */
4843 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4846 gdk_window_get_position (src_priv->window, &wx, &wy);
4848 src_x -= wx - src_priv->allocation.x;
4849 src_y -= wy - src_priv->allocation.y;
4853 src_x += src_priv->allocation.x;
4854 src_y += src_priv->allocation.y;
4857 /* Translate to the common ancestor */
4858 window = src_priv->window;
4859 while (window != ancestor->priv->window)
4863 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4868 window = gdk_window_get_effective_parent (window);
4870 if (!window) /* Handle GtkHandleBox */
4875 window = dest_priv->window;
4876 while (window != ancestor->priv->window)
4878 dest_list = g_list_prepend (dest_list, window);
4880 window = gdk_window_get_effective_parent (window);
4882 if (!window) /* Handle GtkHandleBox */
4884 g_list_free (dest_list);
4893 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4898 dest_list = g_list_remove (dest_list, dest_list->data);
4901 /* Translate from window relative to allocation relative */
4902 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4905 gdk_window_get_position (dest_priv->window, &wx, &wy);
4907 src_x += wx - dest_priv->allocation.x;
4908 src_y += wy - dest_priv->allocation.y;
4912 src_x -= dest_priv->allocation.x;
4913 src_y -= dest_priv->allocation.y;
4925 gtk_widget_real_size_allocate (GtkWidget *widget,
4926 GtkAllocation *allocation)
4928 GtkWidgetPrivate *priv = widget->priv;
4930 priv->allocation = *allocation;
4932 if (gtk_widget_get_realized (widget) &&
4933 gtk_widget_get_has_window (widget))
4935 gdk_window_move_resize (priv->window,
4936 allocation->x, allocation->y,
4937 allocation->width, allocation->height);
4942 adjust_for_align(GtkAlign align,
4944 gint *allocated_pos,
4945 gint *allocated_size)
4949 case GTK_ALIGN_FILL:
4950 /* change nothing */
4952 case GTK_ALIGN_START:
4953 /* keep *allocated_pos where it is */
4954 *allocated_size = MIN (*allocated_size, *natural_size);
4957 if (*allocated_size > *natural_size)
4959 *allocated_pos += (*allocated_size - *natural_size);
4960 *allocated_size = *natural_size;
4963 case GTK_ALIGN_CENTER:
4964 if (*allocated_size > *natural_size)
4966 *allocated_pos += (*allocated_size - *natural_size) / 2;
4967 *allocated_size = MIN (*allocated_size, *natural_size);
4974 adjust_for_margin(gint start_margin,
4978 gint *allocated_pos,
4979 gint *allocated_size)
4981 *minimum_size -= (start_margin + end_margin);
4982 *natural_size -= (start_margin + end_margin);
4983 *allocated_pos += start_margin;
4984 *allocated_size -= (start_margin + end_margin);
4988 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4989 GtkOrientation orientation,
4992 gint *allocated_pos,
4993 gint *allocated_size)
4995 const GtkWidgetAuxInfo *aux_info;
4997 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4999 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5001 adjust_for_margin (aux_info->margin.left,
5002 aux_info->margin.right,
5003 minimum_size, natural_size,
5004 allocated_pos, allocated_size);
5005 adjust_for_align (aux_info->halign,
5006 natural_size, allocated_pos, allocated_size);
5010 adjust_for_margin (aux_info->margin.top,
5011 aux_info->margin.bottom,
5012 minimum_size, natural_size,
5013 allocated_pos, allocated_size);
5014 adjust_for_align (aux_info->valign,
5015 natural_size, allocated_pos, allocated_size);
5020 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5023 GtkWidgetPrivate *priv = widget->priv;
5025 /* widgets must be onscreen for accels to take effect */
5026 return gtk_widget_is_sensitive (widget) &&
5027 gtk_widget_is_drawable (widget) &&
5028 gdk_window_is_viewable (priv->window);
5032 * gtk_widget_can_activate_accel:
5033 * @widget: a #GtkWidget
5034 * @signal_id: the ID of a signal installed on @widget
5036 * Determines whether an accelerator that activates the signal
5037 * identified by @signal_id can currently be activated.
5038 * This is done by emitting the #GtkWidget::can-activate-accel
5039 * signal on @widget; if the signal isn't overridden by a
5040 * handler or in a derived widget, then the default check is
5041 * that the widget must be sensitive, and the widget and all
5042 * its ancestors mapped.
5044 * Return value: %TRUE if the accelerator can be activated.
5049 gtk_widget_can_activate_accel (GtkWidget *widget,
5052 gboolean can_activate = FALSE;
5053 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5054 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5055 return can_activate;
5064 closure_accel_activate (GClosure *closure,
5065 GValue *return_value,
5066 guint n_param_values,
5067 const GValue *param_values,
5068 gpointer invocation_hint,
5069 gpointer marshal_data)
5071 AccelClosure *aclosure = (AccelClosure*) closure;
5072 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5075 g_signal_emit (closure->data, aclosure->signal_id, 0);
5077 /* whether accelerator was handled */
5078 g_value_set_boolean (return_value, can_activate);
5082 closures_destroy (gpointer data)
5084 GSList *slist, *closures = data;
5086 for (slist = closures; slist; slist = slist->next)
5088 g_closure_invalidate (slist->data);
5089 g_closure_unref (slist->data);
5091 g_slist_free (closures);
5095 widget_new_accel_closure (GtkWidget *widget,
5098 AccelClosure *aclosure;
5099 GClosure *closure = NULL;
5100 GSList *slist, *closures;
5102 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5103 for (slist = closures; slist; slist = slist->next)
5104 if (!gtk_accel_group_from_accel_closure (slist->data))
5106 /* reuse this closure */
5107 closure = slist->data;
5112 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5113 closures = g_slist_prepend (closures, g_closure_ref (closure));
5114 g_closure_sink (closure);
5115 g_closure_set_marshal (closure, closure_accel_activate);
5117 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5119 aclosure = (AccelClosure*) closure;
5120 g_assert (closure->data == widget);
5121 g_assert (closure->marshal == closure_accel_activate);
5122 aclosure->signal_id = signal_id;
5128 * gtk_widget_add_accelerator
5129 * @widget: widget to install an accelerator on
5130 * @accel_signal: widget signal to emit on accelerator activation
5131 * @accel_group: accel group for this widget, added to its toplevel
5132 * @accel_key: GDK keyval of the accelerator
5133 * @accel_mods: modifier key combination of the accelerator
5134 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5136 * Installs an accelerator for this @widget in @accel_group that causes
5137 * @accel_signal to be emitted if the accelerator is activated.
5138 * The @accel_group needs to be added to the widget's toplevel via
5139 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5140 * Accelerators added through this function are not user changeable during
5141 * runtime. If you want to support accelerators that can be changed by the
5142 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5143 * gtk_menu_item_set_accel_path() instead.
5146 gtk_widget_add_accelerator (GtkWidget *widget,
5147 const gchar *accel_signal,
5148 GtkAccelGroup *accel_group,
5150 GdkModifierType accel_mods,
5151 GtkAccelFlags accel_flags)
5156 g_return_if_fail (GTK_IS_WIDGET (widget));
5157 g_return_if_fail (accel_signal != NULL);
5158 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5160 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5161 if (!query.signal_id ||
5162 !(query.signal_flags & G_SIGNAL_ACTION) ||
5163 query.return_type != G_TYPE_NONE ||
5166 /* hmm, should be elaborate enough */
5167 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5168 G_OBJECT_TYPE_NAME (widget), accel_signal);
5172 closure = widget_new_accel_closure (widget, query.signal_id);
5174 g_object_ref (widget);
5176 /* install the accelerator. since we don't map this onto an accel_path,
5177 * the accelerator will automatically be locked.
5179 gtk_accel_group_connect (accel_group,
5182 accel_flags | GTK_ACCEL_LOCKED,
5185 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5187 g_object_unref (widget);
5191 * gtk_widget_remove_accelerator:
5192 * @widget: widget to install an accelerator on
5193 * @accel_group: accel group for this widget
5194 * @accel_key: GDK keyval of the accelerator
5195 * @accel_mods: modifier key combination of the accelerator
5196 * @returns: whether an accelerator was installed and could be removed
5198 * Removes an accelerator from @widget, previously installed with
5199 * gtk_widget_add_accelerator().
5202 gtk_widget_remove_accelerator (GtkWidget *widget,
5203 GtkAccelGroup *accel_group,
5205 GdkModifierType accel_mods)
5207 GtkAccelGroupEntry *ag_entry;
5208 GList *slist, *clist;
5211 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5212 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5214 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5215 clist = gtk_widget_list_accel_closures (widget);
5216 for (slist = clist; slist; slist = slist->next)
5220 for (i = 0; i < n; i++)
5221 if (slist->data == (gpointer) ag_entry[i].closure)
5223 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5225 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5227 g_list_free (clist);
5232 g_list_free (clist);
5234 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5235 accel_key, accel_mods, accel_group,
5236 G_OBJECT_TYPE_NAME (widget), widget);
5242 * gtk_widget_list_accel_closures:
5243 * @widget: widget to list accelerator closures for
5245 * Lists the closures used by @widget for accelerator group connections
5246 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5247 * The closures can be used to monitor accelerator changes on @widget,
5248 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5249 * #GtkAccelGroup of a closure which can be found out with
5250 * gtk_accel_group_from_accel_closure().
5252 * Return value: (transfer container) (element-type GClosure):
5253 * a newly allocated #GList of closures
5256 gtk_widget_list_accel_closures (GtkWidget *widget)
5259 GList *clist = NULL;
5261 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5263 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5264 if (gtk_accel_group_from_accel_closure (slist->data))
5265 clist = g_list_prepend (clist, slist->data);
5271 GtkAccelGroup *accel_group;
5276 destroy_accel_path (gpointer data)
5278 AccelPath *apath = data;
5280 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5282 /* closures_destroy takes care of unrefing the closure */
5283 g_object_unref (apath->accel_group);
5285 g_slice_free (AccelPath, apath);
5290 * gtk_widget_set_accel_path:
5291 * @widget: a #GtkWidget
5292 * @accel_path: (allow-none): path used to look up the accelerator
5293 * @accel_group: (allow-none): a #GtkAccelGroup.
5295 * Given an accelerator group, @accel_group, and an accelerator path,
5296 * @accel_path, sets up an accelerator in @accel_group so whenever the
5297 * key binding that is defined for @accel_path is pressed, @widget
5298 * will be activated. This removes any accelerators (for any
5299 * accelerator group) installed by previous calls to
5300 * gtk_widget_set_accel_path(). Associating accelerators with
5301 * paths allows them to be modified by the user and the modifications
5302 * to be saved for future use. (See gtk_accel_map_save().)
5304 * This function is a low level function that would most likely
5305 * be used by a menu creation system like #GtkUIManager. If you
5306 * use #GtkUIManager, setting up accelerator paths will be done
5309 * Even when you you aren't using #GtkUIManager, if you only want to
5310 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5311 * provides a somewhat more convenient interface.
5313 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5314 * pass a static string, you can save some memory by interning it first with
5315 * g_intern_static_string().
5318 gtk_widget_set_accel_path (GtkWidget *widget,
5319 const gchar *accel_path,
5320 GtkAccelGroup *accel_group)
5324 g_return_if_fail (GTK_IS_WIDGET (widget));
5325 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5329 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5330 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5332 gtk_accel_map_add_entry (accel_path, 0, 0);
5333 apath = g_slice_new (AccelPath);
5334 apath->accel_group = g_object_ref (accel_group);
5335 apath->path_quark = g_quark_from_string (accel_path);
5336 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5341 /* also removes possible old settings */
5342 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5345 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5347 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5351 _gtk_widget_get_accel_path (GtkWidget *widget,
5356 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5358 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5360 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5361 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5365 * gtk_widget_mnemonic_activate:
5366 * @widget: a #GtkWidget
5367 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5369 * Emits the #GtkWidget::mnemonic-activate signal.
5371 * The default handler for this signal activates the @widget if
5372 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5375 * Returns: %TRUE if the signal has been handled
5378 gtk_widget_mnemonic_activate (GtkWidget *widget,
5379 gboolean group_cycling)
5383 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5385 group_cycling = group_cycling != FALSE;
5386 if (!gtk_widget_is_sensitive (widget))
5389 g_signal_emit (widget,
5390 widget_signals[MNEMONIC_ACTIVATE],
5398 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5399 gboolean group_cycling)
5401 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5402 gtk_widget_activate (widget);
5403 else if (gtk_widget_get_can_focus (widget))
5404 gtk_widget_grab_focus (widget);
5407 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5408 G_OBJECT_TYPE_NAME (widget));
5409 gtk_widget_error_bell (widget);
5414 static const cairo_user_data_key_t event_key;
5417 _gtk_cairo_get_event (cairo_t *cr)
5419 g_return_val_if_fail (cr != NULL, NULL);
5421 return cairo_get_user_data (cr, &event_key);
5425 gtk_cairo_set_event (cairo_t *cr,
5426 GdkEventExpose *event)
5428 cairo_set_user_data (cr, &event_key, event, NULL);
5432 * gtk_cairo_should_draw_window:
5433 * @cr: a cairo context
5434 * @window: the window to check
5436 * This function is supposed to be called in #GtkWidget::draw
5437 * implementations for widgets that support multiple windows.
5438 * @cr must be untransformed from invoking of the draw function.
5439 * This function will return %TRUE if the contents of the given
5440 * @window are supposed to be drawn and %FALSE otherwise. Note
5441 * that when the drawing was not initiated by the windowing
5442 * system this function will return %TRUE for all windows, so
5443 * you need to draw the bottommost window first. Also, do not
5444 * use "else if" statements to check which window should be drawn.
5446 * Returns: %TRUE if @window should be drawn
5449 gtk_cairo_should_draw_window (cairo_t *cr,
5452 GdkEventExpose *event;
5454 g_return_val_if_fail (cr != NULL, FALSE);
5455 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5457 event = _gtk_cairo_get_event (cr);
5459 return event == NULL ||
5460 event->window == window;
5463 /* code shared by gtk_container_propagate_draw() and
5467 _gtk_widget_draw_internal (GtkWidget *widget,
5469 gboolean clip_to_size)
5471 GtkStyleContext *context;
5473 if (!gtk_widget_is_drawable (widget))
5478 cairo_rectangle (cr,
5480 widget->priv->allocation.width,
5481 widget->priv->allocation.height);
5485 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5489 g_signal_emit (widget, widget_signals[DRAW],
5494 context = gtk_widget_get_style_context (widget);
5495 _gtk_style_context_coalesce_animation_areas (context, widget);
5500 * @widget: the widget to draw. It must be drawable (see
5501 * gtk_widget_is_drawable()) and a size must have been allocated.
5502 * @cr: a cairo context to draw to
5504 * Draws @widget to @cr. The top left corner of the widget will be
5505 * drawn to the currently set origin point of @cr.
5507 * You should pass a cairo context as @cr argument that is in an
5508 * original state. Otherwise the resulting drawing is undefined. For
5509 * example changing the operator using cairo_set_operator() or the
5510 * line width using cairo_set_line_width() might have unwanted side
5512 * You may however change the context's transform matrix - like with
5513 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5514 * region with cairo_clip() prior to calling this function. Also, it
5515 * is fine to modify the context with cairo_save() and
5516 * cairo_push_group() prior to calling this function.
5518 * <note><para>Special purpose widgets may contain special code for
5519 * rendering to the screen and might appear differently on screen
5520 * and when rendered using gtk_widget_draw().</para></note>
5523 gtk_widget_draw (GtkWidget *widget,
5526 GdkEventExpose *tmp_event;
5528 g_return_if_fail (GTK_IS_WIDGET (widget));
5529 g_return_if_fail (!widget->priv->alloc_needed);
5530 g_return_if_fail (cr != NULL);
5533 /* We have to reset the event here so that draw functions can call
5534 * gtk_widget_draw() on random other widgets and get the desired
5535 * effect: Drawing all contents, not just the current window.
5537 tmp_event = _gtk_cairo_get_event (cr);
5538 gtk_cairo_set_event (cr, NULL);
5540 _gtk_widget_draw_internal (widget, cr, TRUE);
5542 gtk_cairo_set_event (cr, tmp_event);
5547 gtk_widget_real_key_press_event (GtkWidget *widget,
5550 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5554 gtk_widget_real_key_release_event (GtkWidget *widget,
5557 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5561 gtk_widget_real_focus_in_event (GtkWidget *widget,
5562 GdkEventFocus *event)
5564 gtk_widget_queue_shallow_draw (widget);
5570 gtk_widget_real_focus_out_event (GtkWidget *widget,
5571 GdkEventFocus *event)
5573 gtk_widget_queue_shallow_draw (widget);
5578 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5579 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5583 * @widget: a #GtkWidget
5584 * @event: a #GdkEvent
5586 * Rarely-used function. This function is used to emit
5587 * the event signals on a widget (those signals should never
5588 * be emitted without using this function to do so).
5589 * If you want to synthesize an event though, don't use this function;
5590 * instead, use gtk_main_do_event() so the event will behave as if
5591 * it were in the event queue. Don't synthesize expose events; instead,
5592 * use gdk_window_invalidate_rect() to invalidate a region of the
5595 * Return value: return from the event signal emission (%TRUE if
5596 * the event was handled)
5599 gtk_widget_event (GtkWidget *widget,
5602 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5603 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5605 if (event->type == GDK_EXPOSE)
5607 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5608 "the same effect, call gdk_window_invalidate_rect/region(), "
5609 "followed by gdk_window_process_updates().");
5613 return gtk_widget_event_internal (widget, event);
5616 /* Returns TRUE if a translation should be done */
5618 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5623 GdkWindow *w, *widget_window;
5625 if (!gtk_widget_get_has_window (widget))
5627 *x = -widget->priv->allocation.x;
5628 *y = -widget->priv->allocation.y;
5636 widget_window = gtk_widget_get_window (widget);
5638 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5641 gdk_window_get_position (w, &wx, &wy);
5658 * gtk_cairo_transform_to_window:
5659 * @cr: the cairo context to transform
5660 * @widget: the widget the context is currently centered for
5661 * @window: the window to transform the context to
5663 * Transforms the given cairo context @cr that from @widget-relative
5664 * coordinates to @window-relative coordinates.
5665 * If the @widget's window is not an ancestor of @window, no
5666 * modification will be applied.
5668 * This is the inverse to the transformation GTK applies when
5669 * preparing an expose event to be emitted with the #GtkWidget::draw
5670 * signal. It is intended to help porting multiwindow widgets from
5671 * GTK+ 2 to the rendering architecture of GTK+ 3.
5674 gtk_cairo_transform_to_window (cairo_t *cr,
5680 g_return_if_fail (cr != NULL);
5681 g_return_if_fail (GTK_IS_WIDGET (widget));
5682 g_return_if_fail (GDK_IS_WINDOW (window));
5684 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5685 cairo_translate (cr, x, y);
5689 * gtk_widget_send_expose:
5690 * @widget: a #GtkWidget
5691 * @event: a expose #GdkEvent
5693 * Very rarely-used function. This function is used to emit
5694 * an expose event on a widget. This function is not normally used
5695 * directly. The only time it is used is when propagating an expose
5696 * event to a child %NO_WINDOW widget, and that is normally done
5697 * using gtk_container_propagate_draw().
5699 * If you want to force an area of a window to be redrawn,
5700 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5701 * To cause the redraw to be done immediately, follow that call
5702 * with a call to gdk_window_process_updates().
5704 * Return value: return from the event signal emission (%TRUE if
5705 * the event was handled)
5708 gtk_widget_send_expose (GtkWidget *widget,
5711 gboolean result = FALSE;
5716 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5717 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5718 g_return_val_if_fail (event != NULL, TRUE);
5719 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5721 cr = gdk_cairo_create (event->expose.window);
5722 gtk_cairo_set_event (cr, &event->expose);
5724 gdk_cairo_region (cr, event->expose.region);
5727 do_clip = _gtk_widget_get_translation_to_window (widget,
5728 event->expose.window,
5730 cairo_translate (cr, -x, -y);
5732 _gtk_widget_draw_internal (widget, cr, do_clip);
5734 /* unset here, so if someone keeps a reference to cr we
5735 * don't leak the window. */
5736 gtk_cairo_set_event (cr, NULL);
5743 event_window_is_still_viewable (GdkEvent *event)
5745 /* Check that we think the event's window is viewable before
5746 * delivering the event, to prevent suprises. We do this here
5747 * at the last moment, since the event may have been queued
5748 * up behind other events, held over a recursive main loop, etc.
5750 switch (event->type)
5753 case GDK_MOTION_NOTIFY:
5754 case GDK_BUTTON_PRESS:
5755 case GDK_2BUTTON_PRESS:
5756 case GDK_3BUTTON_PRESS:
5758 case GDK_ENTER_NOTIFY:
5759 case GDK_PROXIMITY_IN:
5761 return event->any.window && gdk_window_is_viewable (event->any.window);
5764 /* The following events are the second half of paired events;
5765 * we always deliver them to deal with widgets that clean up
5766 * on the second half.
5768 case GDK_BUTTON_RELEASE:
5769 case GDK_KEY_RELEASE:
5770 case GDK_LEAVE_NOTIFY:
5771 case GDK_PROXIMITY_OUT:
5775 /* Remaining events would make sense on an not-viewable window,
5776 * or don't have an associated window.
5783 gtk_widget_event_internal (GtkWidget *widget,
5786 gboolean return_val = FALSE;
5788 /* We check only once for is-still-visible; if someone
5789 * hides the window in on of the signals on the widget,
5790 * they are responsible for returning TRUE to terminate
5793 if (!event_window_is_still_viewable (event))
5796 g_object_ref (widget);
5798 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5799 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5804 switch (event->type)
5809 case GDK_BUTTON_PRESS:
5810 case GDK_2BUTTON_PRESS:
5811 case GDK_3BUTTON_PRESS:
5812 signal_num = BUTTON_PRESS_EVENT;
5815 signal_num = SCROLL_EVENT;
5817 case GDK_BUTTON_RELEASE:
5818 signal_num = BUTTON_RELEASE_EVENT;
5820 case GDK_MOTION_NOTIFY:
5821 signal_num = MOTION_NOTIFY_EVENT;
5824 signal_num = DELETE_EVENT;
5827 signal_num = DESTROY_EVENT;
5828 _gtk_tooltip_hide (widget);
5831 signal_num = KEY_PRESS_EVENT;
5833 case GDK_KEY_RELEASE:
5834 signal_num = KEY_RELEASE_EVENT;
5836 case GDK_ENTER_NOTIFY:
5837 signal_num = ENTER_NOTIFY_EVENT;
5839 case GDK_LEAVE_NOTIFY:
5840 signal_num = LEAVE_NOTIFY_EVENT;
5842 case GDK_FOCUS_CHANGE:
5843 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5844 if (event->focus_change.in)
5845 _gtk_tooltip_focus_in (widget);
5847 _gtk_tooltip_focus_out (widget);
5850 signal_num = CONFIGURE_EVENT;
5853 signal_num = MAP_EVENT;
5856 signal_num = UNMAP_EVENT;
5858 case GDK_WINDOW_STATE:
5859 signal_num = WINDOW_STATE_EVENT;
5861 case GDK_PROPERTY_NOTIFY:
5862 signal_num = PROPERTY_NOTIFY_EVENT;
5864 case GDK_SELECTION_CLEAR:
5865 signal_num = SELECTION_CLEAR_EVENT;
5867 case GDK_SELECTION_REQUEST:
5868 signal_num = SELECTION_REQUEST_EVENT;
5870 case GDK_SELECTION_NOTIFY:
5871 signal_num = SELECTION_NOTIFY_EVENT;
5873 case GDK_PROXIMITY_IN:
5874 signal_num = PROXIMITY_IN_EVENT;
5876 case GDK_PROXIMITY_OUT:
5877 signal_num = PROXIMITY_OUT_EVENT;
5879 case GDK_CLIENT_EVENT:
5880 signal_num = CLIENT_EVENT;
5883 signal_num = EXPOSE_EVENT;
5885 case GDK_VISIBILITY_NOTIFY:
5886 signal_num = VISIBILITY_NOTIFY_EVENT;
5888 case GDK_GRAB_BROKEN:
5889 signal_num = GRAB_BROKEN_EVENT;
5892 signal_num = DAMAGE_EVENT;
5895 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5899 if (signal_num != -1)
5900 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5902 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5903 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5907 g_object_unref (widget);
5913 * gtk_widget_activate:
5914 * @widget: a #GtkWidget that's activatable
5916 * For widgets that can be "activated" (buttons, menu items, etc.)
5917 * this function activates them. Activation is what happens when you
5918 * press Enter on a widget during key navigation. If @widget isn't
5919 * activatable, the function returns %FALSE.
5921 * Return value: %TRUE if the widget was activatable
5924 gtk_widget_activate (GtkWidget *widget)
5926 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5928 if (WIDGET_CLASS (widget)->activate_signal)
5930 /* FIXME: we should eventually check the signals signature here */
5931 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5940 gtk_widget_reparent_subwindows (GtkWidget *widget,
5941 GdkWindow *new_window)
5943 GtkWidgetPrivate *priv = widget->priv;
5945 if (!gtk_widget_get_has_window (widget))
5947 GList *children = gdk_window_get_children (priv->window);
5950 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5952 GdkWindow *window = tmp_list->data;
5955 gdk_window_get_user_data (window, &child);
5956 while (child && child != widget)
5957 child = ((GtkWidget*) child)->priv->parent;
5960 gdk_window_reparent (window, new_window, 0, 0);
5963 g_list_free (children);
5968 GList *tmp_list, *children;
5970 parent = gdk_window_get_parent (priv->window);
5973 gdk_window_reparent (priv->window, new_window, 0, 0);
5976 children = gdk_window_get_children (parent);
5978 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5980 GdkWindow *window = tmp_list->data;
5983 gdk_window_get_user_data (window, &child);
5985 if (child == widget)
5986 gdk_window_reparent (window, new_window, 0, 0);
5989 g_list_free (children);
5995 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5996 gpointer client_data)
5998 GtkWidgetPrivate *priv = widget->priv;
6000 g_assert (client_data != NULL);
6002 if (!gtk_widget_get_has_window (widget))
6005 g_object_unref (priv->window);
6006 priv->window = (GdkWindow*) client_data;
6008 g_object_ref (priv->window);
6010 if (GTK_IS_CONTAINER (widget))
6011 gtk_container_forall (GTK_CONTAINER (widget),
6012 gtk_widget_reparent_fixup_child,
6018 * gtk_widget_reparent:
6019 * @widget: a #GtkWidget
6020 * @new_parent: a #GtkContainer to move the widget into
6022 * Moves a widget from one #GtkContainer to another, handling reference
6023 * count issues to avoid destroying the widget.
6026 gtk_widget_reparent (GtkWidget *widget,
6027 GtkWidget *new_parent)
6029 GtkWidgetPrivate *priv;
6031 g_return_if_fail (GTK_IS_WIDGET (widget));
6032 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6033 priv = widget->priv;
6034 g_return_if_fail (priv->parent != NULL);
6036 if (priv->parent != new_parent)
6038 /* First try to see if we can get away without unrealizing
6039 * the widget as we reparent it. if so we set a flag so
6040 * that gtk_widget_unparent doesn't unrealize widget
6042 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6043 priv->in_reparent = TRUE;
6045 g_object_ref (widget);
6046 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6047 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6048 g_object_unref (widget);
6050 if (priv->in_reparent)
6052 priv->in_reparent = FALSE;
6054 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6055 gtk_widget_reparent_fixup_child (widget,
6056 gtk_widget_get_parent_window (widget));
6059 g_object_notify (G_OBJECT (widget), "parent");
6064 * gtk_widget_intersect:
6065 * @widget: a #GtkWidget
6066 * @area: a rectangle
6067 * @intersection: rectangle to store intersection of @widget and @area
6069 * Computes the intersection of a @widget's area and @area, storing
6070 * the intersection in @intersection, and returns %TRUE if there was
6071 * an intersection. @intersection may be %NULL if you're only
6072 * interested in whether there was an intersection.
6074 * Return value: %TRUE if there was an intersection
6077 gtk_widget_intersect (GtkWidget *widget,
6078 const GdkRectangle *area,
6079 GdkRectangle *intersection)
6081 GtkWidgetPrivate *priv;
6086 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6087 g_return_val_if_fail (area != NULL, FALSE);
6089 priv = widget->priv;
6092 dest = intersection;
6096 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6098 if (return_val && intersection && gtk_widget_get_has_window (widget))
6100 intersection->x -= priv->allocation.x;
6101 intersection->y -= priv->allocation.y;
6108 * gtk_widget_region_intersect:
6109 * @widget: a #GtkWidget
6110 * @region: a #cairo_region_t, in the same coordinate system as
6111 * @widget->allocation. That is, relative to @widget->window
6112 * for %NO_WINDOW widgets; relative to the parent window
6113 * of @widget->window for widgets with their own window.
6114 * @returns: A newly allocated region holding the intersection of @widget
6115 * and @region. The coordinates of the return value are
6116 * relative to @widget->window for %NO_WINDOW widgets, and
6117 * relative to the parent window of @widget->window for
6118 * widgets with their own window.
6120 * Computes the intersection of a @widget's area and @region, returning
6121 * the intersection. The result may be empty, use cairo_region_is_empty() to
6125 gtk_widget_region_intersect (GtkWidget *widget,
6126 const cairo_region_t *region)
6129 cairo_region_t *dest;
6131 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6132 g_return_val_if_fail (region != NULL, NULL);
6134 gtk_widget_get_allocation (widget, &rect);
6136 dest = cairo_region_create_rectangle (&rect);
6138 cairo_region_intersect (dest, region);
6144 * _gtk_widget_grab_notify:
6145 * @widget: a #GtkWidget
6146 * @was_grabbed: whether a grab is now in effect
6148 * Emits the #GtkWidget::grab-notify signal on @widget.
6153 _gtk_widget_grab_notify (GtkWidget *widget,
6154 gboolean was_grabbed)
6156 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6160 * gtk_widget_grab_focus:
6161 * @widget: a #GtkWidget
6163 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6164 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6165 * something like #GtkFrame won't work.
6167 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6168 * gtk_widget_set_can_focus() to modify that flag.
6170 * The widget also needs to be realized and mapped. This is indicated by the
6171 * related signals. Grabbing the focus immediately after creating the widget
6172 * will likely fail and cause critical warnings.
6175 gtk_widget_grab_focus (GtkWidget *widget)
6177 g_return_if_fail (GTK_IS_WIDGET (widget));
6179 if (!gtk_widget_is_sensitive (widget))
6182 g_object_ref (widget);
6183 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6184 g_object_notify (G_OBJECT (widget), "has-focus");
6185 g_object_unref (widget);
6189 reset_focus_recurse (GtkWidget *widget,
6192 if (GTK_IS_CONTAINER (widget))
6194 GtkContainer *container;
6196 container = GTK_CONTAINER (widget);
6197 gtk_container_set_focus_child (container, NULL);
6199 gtk_container_foreach (container,
6200 reset_focus_recurse,
6206 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6208 if (gtk_widget_get_can_focus (focus_widget))
6210 GtkWidget *toplevel;
6213 /* clear the current focus setting, break if the current widget
6214 * is the focus widget's parent, since containers above that will
6215 * be set by the next loop.
6217 toplevel = gtk_widget_get_toplevel (focus_widget);
6218 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6220 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6222 if (widget == focus_widget)
6224 /* We call _gtk_window_internal_set_focus() here so that the
6225 * toplevel window can request the focus if necessary.
6226 * This is needed when the toplevel is a GtkPlug
6228 if (!gtk_widget_has_focus (widget))
6229 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6236 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6238 widget = widget->priv->parent;
6239 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6243 else if (toplevel != focus_widget)
6245 /* gtk_widget_grab_focus() operates on a tree without window...
6246 * actually, this is very questionable behaviour.
6249 gtk_container_foreach (GTK_CONTAINER (toplevel),
6250 reset_focus_recurse,
6254 /* now propagate the new focus up the widget tree and finally
6255 * set it on the window
6257 widget = focus_widget;
6258 while (widget->priv->parent)
6260 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6261 widget = widget->priv->parent;
6263 if (GTK_IS_WINDOW (widget))
6264 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6269 gtk_widget_real_query_tooltip (GtkWidget *widget,
6272 gboolean keyboard_tip,
6273 GtkTooltip *tooltip)
6275 gchar *tooltip_markup;
6276 gboolean has_tooltip;
6278 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6279 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6281 if (has_tooltip && tooltip_markup)
6283 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6291 gtk_widget_real_style_updated (GtkWidget *widget)
6293 if (widget->priv->context)
6294 gtk_style_context_invalidate (widget->priv->context);
6295 gtk_widget_queue_resize (widget);
6299 gtk_widget_real_show_help (GtkWidget *widget,
6300 GtkWidgetHelpType help_type)
6302 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6304 _gtk_tooltip_toggle_keyboard_mode (widget);
6313 gtk_widget_real_focus (GtkWidget *widget,
6314 GtkDirectionType direction)
6316 if (!gtk_widget_get_can_focus (widget))
6319 if (!gtk_widget_is_focus (widget))
6321 gtk_widget_grab_focus (widget);
6329 gtk_widget_real_move_focus (GtkWidget *widget,
6330 GtkDirectionType direction)
6332 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6334 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6336 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6342 gtk_widget_real_keynav_failed (GtkWidget *widget,
6343 GtkDirectionType direction)
6345 gboolean cursor_only;
6349 case GTK_DIR_TAB_FORWARD:
6350 case GTK_DIR_TAB_BACKWARD:
6357 g_object_get (gtk_widget_get_settings (widget),
6358 "gtk-keynav-cursor-only", &cursor_only,
6365 gtk_widget_error_bell (widget);
6371 * gtk_widget_set_can_focus:
6372 * @widget: a #GtkWidget
6373 * @can_focus: whether or not @widget can own the input focus.
6375 * Specifies whether @widget can own the input focus. See
6376 * gtk_widget_grab_focus() for actually setting the input focus on a
6382 gtk_widget_set_can_focus (GtkWidget *widget,
6385 g_return_if_fail (GTK_IS_WIDGET (widget));
6387 if (widget->priv->can_focus != can_focus)
6389 widget->priv->can_focus = can_focus;
6391 gtk_widget_queue_resize (widget);
6392 g_object_notify (G_OBJECT (widget), "can-focus");
6397 * gtk_widget_get_can_focus:
6398 * @widget: a #GtkWidget
6400 * Determines whether @widget can own the input focus. See
6401 * gtk_widget_set_can_focus().
6403 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6408 gtk_widget_get_can_focus (GtkWidget *widget)
6410 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6412 return widget->priv->can_focus;
6416 * gtk_widget_has_focus:
6417 * @widget: a #GtkWidget
6419 * Determines if the widget has the global input focus. See
6420 * gtk_widget_is_focus() for the difference between having the global
6421 * input focus, and only having the focus within a toplevel.
6423 * Return value: %TRUE if the widget has the global input focus.
6428 gtk_widget_has_focus (GtkWidget *widget)
6430 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6432 return widget->priv->has_focus;
6436 * gtk_widget_is_focus:
6437 * @widget: a #GtkWidget
6439 * Determines if the widget is the focus widget within its
6440 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6441 * necessarily set; %HAS_FOCUS will only be set if the
6442 * toplevel widget additionally has the global input focus.)
6444 * Return value: %TRUE if the widget is the focus widget.
6447 gtk_widget_is_focus (GtkWidget *widget)
6449 GtkWidget *toplevel;
6451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6453 toplevel = gtk_widget_get_toplevel (widget);
6455 if (GTK_IS_WINDOW (toplevel))
6456 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6462 * gtk_widget_set_can_default:
6463 * @widget: a #GtkWidget
6464 * @can_default: whether or not @widget can be a default widget.
6466 * Specifies whether @widget can be a default widget. See
6467 * gtk_widget_grab_default() for details about the meaning of
6473 gtk_widget_set_can_default (GtkWidget *widget,
6474 gboolean can_default)
6476 g_return_if_fail (GTK_IS_WIDGET (widget));
6478 if (widget->priv->can_default != can_default)
6480 widget->priv->can_default = can_default;
6482 gtk_widget_queue_resize (widget);
6483 g_object_notify (G_OBJECT (widget), "can-default");
6488 * gtk_widget_get_can_default:
6489 * @widget: a #GtkWidget
6491 * Determines whether @widget can be a default widget. See
6492 * gtk_widget_set_can_default().
6494 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6499 gtk_widget_get_can_default (GtkWidget *widget)
6501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6503 return widget->priv->can_default;
6507 * gtk_widget_has_default:
6508 * @widget: a #GtkWidget
6510 * Determines whether @widget is the current default widget within its
6511 * toplevel. See gtk_widget_set_can_default().
6513 * Return value: %TRUE if @widget is the current default widget within
6514 * its toplevel, %FALSE otherwise
6519 gtk_widget_has_default (GtkWidget *widget)
6521 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6523 return widget->priv->has_default;
6527 _gtk_widget_set_has_default (GtkWidget *widget,
6528 gboolean has_default)
6530 widget->priv->has_default = has_default;
6534 * gtk_widget_grab_default:
6535 * @widget: a #GtkWidget
6537 * Causes @widget to become the default widget. @widget must have the
6538 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6539 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6540 * %TRUE)</literal>. The default widget is activated when
6541 * the user presses Enter in a window. Default widgets must be
6542 * activatable, that is, gtk_widget_activate() should affect them. Note
6543 * that #GtkEntry widgets require the "activates-default" property
6544 * set to %TRUE before they activate the default widget when Enter
6545 * is pressed and the #GtkEntry is focused.
6548 gtk_widget_grab_default (GtkWidget *widget)
6552 g_return_if_fail (GTK_IS_WIDGET (widget));
6553 g_return_if_fail (gtk_widget_get_can_default (widget));
6555 window = gtk_widget_get_toplevel (widget);
6557 if (window && gtk_widget_is_toplevel (window))
6558 gtk_window_set_default (GTK_WINDOW (window), widget);
6560 g_warning (G_STRLOC ": widget not within a GtkWindow");
6564 * gtk_widget_set_receives_default:
6565 * @widget: a #GtkWidget
6566 * @receives_default: whether or not @widget can be a default widget.
6568 * Specifies whether @widget will be treated as the default widget
6569 * within its toplevel when it has the focus, even if another widget
6572 * See gtk_widget_grab_default() for details about the meaning of
6578 gtk_widget_set_receives_default (GtkWidget *widget,
6579 gboolean receives_default)
6581 g_return_if_fail (GTK_IS_WIDGET (widget));
6583 if (widget->priv->receives_default != receives_default)
6585 widget->priv->receives_default = receives_default;
6587 g_object_notify (G_OBJECT (widget), "receives-default");
6592 * gtk_widget_get_receives_default:
6593 * @widget: a #GtkWidget
6595 * Determines whether @widget is alyways treated as default widget
6596 * withing its toplevel when it has the focus, even if another widget
6599 * See gtk_widget_set_receives_default().
6601 * Return value: %TRUE if @widget acts as default widget when focussed,
6607 gtk_widget_get_receives_default (GtkWidget *widget)
6609 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6611 return widget->priv->receives_default;
6615 * gtk_widget_has_grab:
6616 * @widget: a #GtkWidget
6618 * Determines whether the widget is currently grabbing events, so it
6619 * is the only widget receiving input events (keyboard and mouse).
6621 * See also gtk_grab_add().
6623 * Return value: %TRUE if the widget is in the grab_widgets stack
6628 gtk_widget_has_grab (GtkWidget *widget)
6630 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6632 return widget->priv->has_grab;
6636 _gtk_widget_set_has_grab (GtkWidget *widget,
6639 widget->priv->has_grab = has_grab;
6643 * gtk_widget_device_is_shadowed:
6644 * @widget: a #GtkWidget
6645 * @device: a #GdkDevice
6647 * Returns %TRUE if @device has been shadowed by a GTK+
6648 * device grab on another widget, so it would stop sending
6649 * events to @widget. This may be used in the
6650 * #GtkWidget::grab-notify signal to check for specific
6651 * devices. See gtk_device_grab_add().
6653 * Returns: %TRUE if there is an ongoing grab on @device
6654 * by another #GtkWidget than @widget.
6659 gtk_widget_device_is_shadowed (GtkWidget *widget,
6662 GtkWindowGroup *group;
6663 GtkWidget *grab_widget, *toplevel;
6665 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6666 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6668 if (!gtk_widget_get_realized (widget))
6671 toplevel = gtk_widget_get_toplevel (widget);
6673 if (GTK_IS_WINDOW (toplevel))
6674 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6676 group = gtk_window_get_group (NULL);
6678 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6680 /* Widget not inside the hierarchy of grab_widget */
6682 widget != grab_widget &&
6683 !gtk_widget_is_ancestor (widget, grab_widget))
6686 grab_widget = gtk_window_group_get_current_grab (group);
6687 if (grab_widget && widget != grab_widget &&
6688 !gtk_widget_is_ancestor (widget, grab_widget))
6695 * gtk_widget_set_name:
6696 * @widget: a #GtkWidget
6697 * @name: name for the widget
6699 * Widgets can be named, which allows you to refer to them from a
6700 * gtkrc file. You can apply a style to widgets with a particular name
6701 * in the gtkrc file. See the documentation for gtkrc files (on the
6702 * same page as the docs for #GtkRcStyle).
6704 * Note that widget names are separated by periods in paths (see
6705 * gtk_widget_path()), so names with embedded periods may cause confusion.
6708 gtk_widget_set_name (GtkWidget *widget,
6711 GtkWidgetPrivate *priv;
6714 g_return_if_fail (GTK_IS_WIDGET (widget));
6716 priv = widget->priv;
6718 new_name = g_strdup (name);
6719 g_free (priv->name);
6720 priv->name = new_name;
6726 pos = gtk_widget_path_length (priv->path) - 1;
6727 gtk_widget_path_iter_set_name (priv->path, pos,
6732 gtk_style_context_set_path (priv->context, priv->path);
6735 gtk_widget_reset_rc_style (widget);
6737 g_object_notify (G_OBJECT (widget), "name");
6741 * gtk_widget_get_name:
6742 * @widget: a #GtkWidget
6744 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6745 * significance of widget names.
6747 * Return value: name of the widget. This string is owned by GTK+ and
6748 * should not be modified or freed
6750 G_CONST_RETURN gchar*
6751 gtk_widget_get_name (GtkWidget *widget)
6753 GtkWidgetPrivate *priv;
6755 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6757 priv = widget->priv;
6761 return G_OBJECT_TYPE_NAME (widget);
6765 _gtk_widget_update_state_flags (GtkWidget *widget,
6766 GtkStateFlags flags,
6769 GtkWidgetPrivate *priv;
6771 priv = widget->priv;
6773 /* Handle insensitive first, since it is propagated
6774 * differently throughout the widget hierarchy.
6776 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6777 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6778 gtk_widget_set_sensitive (widget,
6779 operation != STATE_CHANGE_UNSET);
6781 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6784 operation == STATE_CHANGE_REPLACE)
6789 data.operation = operation;
6790 data.use_forall = FALSE;
6793 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6795 data.parent_sensitive = TRUE;
6797 gtk_widget_propagate_state (widget, &data);
6799 if (gtk_widget_is_drawable (widget))
6800 gtk_widget_queue_draw (widget);
6805 * gtk_widget_set_state_flags:
6806 * @widget: a #GtkWidget
6807 * @flags: State flags to turn on
6808 * @clear: Whether to clear state before turning on @flags
6810 * This function is for use in widget implementations. Turns on flag
6811 * values in the current widget state (insensitive, prelighted, etc.).
6813 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6814 * will be propagated down to all non-internal children if @widget is a
6815 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6816 * down to all #GtkContainer children by different means than turning on the
6817 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6818 * gtk_widget_is_sensitive() will make use of these.
6823 gtk_widget_set_state_flags (GtkWidget *widget,
6824 GtkStateFlags flags,
6827 g_return_if_fail (GTK_IS_WIDGET (widget));
6829 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6830 (clear && widget->priv->state_flags == flags))
6834 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6836 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6840 * gtk_widget_unset_state_flags:
6841 * @widget: a #GtkWidget
6842 * @flags: State flags to turn off
6844 * This function is for use in widget implementations. Turns off flag
6845 * values for the current widget state (insensitive, prelighted, etc.).
6846 * See gtk_widget_set_state_flags().
6851 gtk_widget_unset_state_flags (GtkWidget *widget,
6852 GtkStateFlags flags)
6854 g_return_if_fail (GTK_IS_WIDGET (widget));
6856 if ((widget->priv->state_flags & flags) == 0)
6859 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6863 * gtk_widget_get_state_flags:
6864 * @widget: a #GtkWidget
6866 * Returns the widget state as a flag set. It is worth mentioning
6867 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6868 * returned, that is, also based on parent insensitivity, even if
6869 * @widget itself is sensitive.
6871 * Returns: The state flags for widget
6876 gtk_widget_get_state_flags (GtkWidget *widget)
6878 GtkStateFlags flags;
6880 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6882 flags = widget->priv->state_flags;
6884 if (!gtk_widget_is_sensitive (widget))
6885 flags |= GTK_STATE_FLAG_INSENSITIVE;
6891 * gtk_widget_set_state:
6892 * @widget: a #GtkWidget
6893 * @state: new state for @widget
6895 * This function is for use in widget implementations. Sets the state
6896 * of a widget (insensitive, prelighted, etc.) Usually you should set
6897 * the state using wrapper functions such as gtk_widget_set_sensitive().
6899 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6902 gtk_widget_set_state (GtkWidget *widget,
6905 GtkStateFlags flags;
6907 if (state == gtk_widget_get_state (widget))
6912 case GTK_STATE_ACTIVE:
6913 flags = GTK_STATE_FLAG_ACTIVE;
6915 case GTK_STATE_PRELIGHT:
6916 flags = GTK_STATE_FLAG_PRELIGHT;
6918 case GTK_STATE_SELECTED:
6919 flags = GTK_STATE_FLAG_SELECTED;
6921 case GTK_STATE_INSENSITIVE:
6922 flags = GTK_STATE_FLAG_INSENSITIVE;
6924 case GTK_STATE_INCONSISTENT:
6925 flags = GTK_STATE_FLAG_INCONSISTENT;
6927 case GTK_STATE_FOCUSED:
6928 flags = GTK_STATE_FLAG_FOCUSED;
6930 case GTK_STATE_NORMAL:
6936 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6940 * gtk_widget_get_state:
6941 * @widget: a #GtkWidget
6943 * Returns the widget's state. See gtk_widget_set_state().
6945 * Returns: the state of @widget.
6949 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
6952 gtk_widget_get_state (GtkWidget *widget)
6954 GtkStateFlags flags;
6956 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6958 flags = gtk_widget_get_state_flags (widget);
6960 if (flags & GTK_STATE_FLAG_INSENSITIVE)
6961 return GTK_STATE_INSENSITIVE;
6962 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
6963 return GTK_STATE_INCONSISTENT;
6964 else if (flags & GTK_STATE_FLAG_ACTIVE)
6965 return GTK_STATE_ACTIVE;
6966 else if (flags & GTK_STATE_FLAG_SELECTED)
6967 return GTK_STATE_SELECTED;
6968 else if (flags & GTK_STATE_FLAG_FOCUSED)
6969 return GTK_STATE_FOCUSED;
6970 else if (flags & GTK_STATE_FLAG_PRELIGHT)
6971 return GTK_STATE_PRELIGHT;
6973 return GTK_STATE_NORMAL;
6977 * gtk_widget_set_visible:
6978 * @widget: a #GtkWidget
6979 * @visible: whether the widget should be shown or not
6981 * Sets the visibility state of @widget. Note that setting this to
6982 * %TRUE doesn't mean the widget is actually viewable, see
6983 * gtk_widget_get_visible().
6985 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6986 * but is nicer to use when the visibility of the widget depends on
6992 gtk_widget_set_visible (GtkWidget *widget,
6995 g_return_if_fail (GTK_IS_WIDGET (widget));
6997 if (visible != gtk_widget_get_visible (widget))
7000 gtk_widget_show (widget);
7002 gtk_widget_hide (widget);
7007 _gtk_widget_set_visible_flag (GtkWidget *widget,
7010 widget->priv->visible = visible;
7014 * gtk_widget_get_visible:
7015 * @widget: a #GtkWidget
7017 * Determines whether the widget is visible. Note that this doesn't
7018 * take into account whether the widget's parent is also visible
7019 * or the widget is obscured in any way.
7021 * See gtk_widget_set_visible().
7023 * Return value: %TRUE if the widget is visible
7028 gtk_widget_get_visible (GtkWidget *widget)
7030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7032 return widget->priv->visible;
7036 * gtk_widget_set_has_window:
7037 * @widget: a #GtkWidget
7038 * @has_window: whether or not @widget has a window.
7040 * Specifies whether @widget has a #GdkWindow of its own. Note that
7041 * all realized widgets have a non-%NULL "window" pointer
7042 * (gtk_widget_get_window() never returns a %NULL window when a widget
7043 * is realized), but for many of them it's actually the #GdkWindow of
7044 * one of its parent widgets. Widgets that do not create a %window for
7045 * themselves in #GtkWidget::realize must announce this by
7046 * calling this function with @has_window = %FALSE.
7048 * This function should only be called by widget implementations,
7049 * and they should call it in their init() function.
7054 gtk_widget_set_has_window (GtkWidget *widget,
7055 gboolean has_window)
7057 g_return_if_fail (GTK_IS_WIDGET (widget));
7059 widget->priv->no_window = !has_window;
7063 * gtk_widget_get_has_window:
7064 * @widget: a #GtkWidget
7066 * Determines whether @widget has a #GdkWindow of its own. See
7067 * gtk_widget_set_has_window().
7069 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7074 gtk_widget_get_has_window (GtkWidget *widget)
7076 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7078 return ! widget->priv->no_window;
7082 * gtk_widget_is_toplevel:
7083 * @widget: a #GtkWidget
7085 * Determines whether @widget is a toplevel widget. Currently only
7086 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7087 * widgets have no parent widget.
7089 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7094 gtk_widget_is_toplevel (GtkWidget *widget)
7096 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7098 return widget->priv->toplevel;
7102 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7103 gboolean is_toplevel)
7105 widget->priv->toplevel = is_toplevel;
7109 * gtk_widget_is_drawable:
7110 * @widget: a #GtkWidget
7112 * Determines whether @widget can be drawn to. A widget can be drawn
7113 * to if it is mapped and visible.
7115 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7120 gtk_widget_is_drawable (GtkWidget *widget)
7122 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7124 return (gtk_widget_get_visible (widget) &&
7125 gtk_widget_get_mapped (widget));
7129 * gtk_widget_get_realized:
7130 * @widget: a #GtkWidget
7132 * Determines whether @widget is realized.
7134 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7139 gtk_widget_get_realized (GtkWidget *widget)
7141 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7143 return widget->priv->realized;
7147 * gtk_widget_set_realized:
7148 * @widget: a #GtkWidget
7149 * @realized: %TRUE to mark the widget as realized
7151 * Marks the widget as being realized.
7153 * This function should only ever be called in a derived widget's
7154 * "realize" or "unrealize" implementation.
7159 gtk_widget_set_realized (GtkWidget *widget,
7162 g_return_if_fail (GTK_IS_WIDGET (widget));
7164 widget->priv->realized = realized;
7168 * gtk_widget_get_mapped:
7169 * @widget: a #GtkWidget
7171 * Whether the widget is mapped.
7173 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7178 gtk_widget_get_mapped (GtkWidget *widget)
7180 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7182 return widget->priv->mapped;
7186 * gtk_widget_set_mapped:
7187 * @widget: a #GtkWidget
7188 * @mapped: %TRUE to mark the widget as mapped
7190 * Marks the widget as being realized.
7192 * This function should only ever be called in a derived widget's
7193 * "map" or "unmap" implementation.
7198 gtk_widget_set_mapped (GtkWidget *widget,
7201 g_return_if_fail (GTK_IS_WIDGET (widget));
7203 widget->priv->mapped = mapped;
7207 * gtk_widget_set_app_paintable:
7208 * @widget: a #GtkWidget
7209 * @app_paintable: %TRUE if the application will paint on the widget
7211 * Sets whether the application intends to draw on the widget in
7212 * an #GtkWidget::draw handler.
7214 * This is a hint to the widget and does not affect the behavior of
7215 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7216 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7217 * the effect is to suppress default themed drawing of the widget's
7218 * background. (Children of the widget will still be drawn.) The application
7219 * is then entirely responsible for drawing the widget background.
7221 * Note that the background is still drawn when the widget is mapped.
7224 gtk_widget_set_app_paintable (GtkWidget *widget,
7225 gboolean app_paintable)
7227 g_return_if_fail (GTK_IS_WIDGET (widget));
7229 app_paintable = (app_paintable != FALSE);
7231 if (widget->priv->app_paintable != app_paintable)
7233 widget->priv->app_paintable = app_paintable;
7235 if (gtk_widget_is_drawable (widget))
7236 gtk_widget_queue_draw (widget);
7238 g_object_notify (G_OBJECT (widget), "app-paintable");
7243 * gtk_widget_get_app_paintable:
7244 * @widget: a #GtkWidget
7246 * Determines whether the application intends to draw on the widget in
7247 * an #GtkWidget::draw handler.
7249 * See gtk_widget_set_app_paintable()
7251 * Return value: %TRUE if the widget is app paintable
7256 gtk_widget_get_app_paintable (GtkWidget *widget)
7258 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7260 return widget->priv->app_paintable;
7264 * gtk_widget_set_double_buffered:
7265 * @widget: a #GtkWidget
7266 * @double_buffered: %TRUE to double-buffer a widget
7268 * Widgets are double buffered by default; you can use this function
7269 * to turn off the buffering. "Double buffered" simply means that
7270 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7271 * automatically around expose events sent to the
7272 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7273 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7274 * buffer to the screen. The result is that users see the window
7275 * update in one smooth step, and don't see individual graphics
7276 * primitives being rendered.
7278 * In very simple terms, double buffered widgets don't flicker,
7279 * so you would only use this function to turn off double buffering
7280 * if you had special needs and really knew what you were doing.
7282 * Note: if you turn off double-buffering, you have to handle
7283 * expose events, since even the clearing to the background color or
7284 * pixmap will not happen automatically (as it is done in
7285 * gdk_window_begin_paint()).
7288 gtk_widget_set_double_buffered (GtkWidget *widget,
7289 gboolean double_buffered)
7291 g_return_if_fail (GTK_IS_WIDGET (widget));
7293 double_buffered = (double_buffered != FALSE);
7295 if (widget->priv->double_buffered != double_buffered)
7297 widget->priv->double_buffered = double_buffered;
7299 g_object_notify (G_OBJECT (widget), "double-buffered");
7304 * gtk_widget_get_double_buffered:
7305 * @widget: a #GtkWidget
7307 * Determines whether the widget is double buffered.
7309 * See gtk_widget_set_double_buffered()
7311 * Return value: %TRUE if the widget is double buffered
7316 gtk_widget_get_double_buffered (GtkWidget *widget)
7318 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7320 return widget->priv->double_buffered;
7324 * gtk_widget_set_redraw_on_allocate:
7325 * @widget: a #GtkWidget
7326 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7327 * when it is allocated to a new size. Otherwise, only the
7328 * new portion of the widget will be redrawn.
7330 * Sets whether the entire widget is queued for drawing when its size
7331 * allocation changes. By default, this setting is %TRUE and
7332 * the entire widget is redrawn on every size change. If your widget
7333 * leaves the upper left unchanged when made bigger, turning this
7334 * setting off will improve performance.
7336 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7337 * off all allocation on resizing: the widget will not even redraw if
7338 * its position changes; this is to allow containers that don't draw
7339 * anything to avoid excess invalidations. If you set this flag on a
7340 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7341 * you are responsible for invalidating both the old and new allocation
7342 * of the widget when the widget is moved and responsible for invalidating
7343 * regions newly when the widget increases size.
7346 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7347 gboolean redraw_on_allocate)
7349 g_return_if_fail (GTK_IS_WIDGET (widget));
7351 widget->priv->redraw_on_alloc = redraw_on_allocate;
7355 * gtk_widget_set_sensitive:
7356 * @widget: a #GtkWidget
7357 * @sensitive: %TRUE to make the widget sensitive
7359 * Sets the sensitivity of a widget. A widget is sensitive if the user
7360 * can interact with it. Insensitive widgets are "grayed out" and the
7361 * user can't interact with them. Insensitive widgets are known as
7362 * "inactive", "disabled", or "ghosted" in some other toolkits.
7365 gtk_widget_set_sensitive (GtkWidget *widget,
7368 GtkWidgetPrivate *priv;
7371 g_return_if_fail (GTK_IS_WIDGET (widget));
7373 priv = widget->priv;
7375 sensitive = (sensitive != FALSE);
7377 if (widget->priv->sensitive == sensitive)
7380 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7384 widget->priv->sensitive = TRUE;
7385 data.operation = STATE_CHANGE_UNSET;
7389 widget->priv->sensitive = FALSE;
7390 data.operation = STATE_CHANGE_SET;
7393 data.use_forall = TRUE;
7396 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7398 data.parent_sensitive = TRUE;
7400 gtk_widget_propagate_state (widget, &data);
7402 if (gtk_widget_is_drawable (widget))
7403 gtk_widget_queue_draw (widget);
7405 g_object_notify (G_OBJECT (widget), "sensitive");
7409 * gtk_widget_get_sensitive:
7410 * @widget: a #GtkWidget
7412 * Returns the widget's sensitivity (in the sense of returning
7413 * the value that has been set using gtk_widget_set_sensitive()).
7415 * The effective sensitivity of a widget is however determined by both its
7416 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7418 * Returns: %TRUE if the widget is sensitive
7423 gtk_widget_get_sensitive (GtkWidget *widget)
7425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7427 return widget->priv->sensitive;
7431 * gtk_widget_is_sensitive:
7432 * @widget: a #GtkWidget
7434 * Returns the widget's effective sensitivity, which means
7435 * it is sensitive itself and also its parent widget is sensntive
7437 * Returns: %TRUE if the widget is effectively sensitive
7442 gtk_widget_is_sensitive (GtkWidget *widget)
7444 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7446 return widget->priv->sensitive && widget->priv->parent_sensitive;
7450 _gtk_widget_update_path (GtkWidget *widget)
7452 if (widget->priv->path)
7454 gtk_widget_path_free (widget->priv->path);
7455 widget->priv->path = NULL;
7458 gtk_widget_get_path (widget);
7462 * gtk_widget_set_parent:
7463 * @widget: a #GtkWidget
7464 * @parent: parent container
7466 * This function is useful only when implementing subclasses of
7468 * Sets the container as the parent of @widget, and takes care of
7469 * some details such as updating the state and style of the child
7470 * to reflect its new location. The opposite function is
7471 * gtk_widget_unparent().
7474 gtk_widget_set_parent (GtkWidget *widget,
7477 GtkStateFlags parent_flags;
7478 GtkWidgetPrivate *priv;
7481 g_return_if_fail (GTK_IS_WIDGET (widget));
7482 g_return_if_fail (GTK_IS_WIDGET (parent));
7483 g_return_if_fail (widget != parent);
7485 priv = widget->priv;
7487 if (priv->parent != NULL)
7489 g_warning ("Can't set a parent on widget which has a parent\n");
7492 if (gtk_widget_is_toplevel (widget))
7494 g_warning ("Can't set a parent on a toplevel widget\n");
7498 /* keep this function in sync with gtk_menu_attach_to_widget()
7501 g_object_ref_sink (widget);
7502 priv->parent = parent;
7504 parent_flags = gtk_widget_get_state_flags (parent);
7506 /* Merge both old state and current parent state,
7507 * We don't want the insensitive flag to propagate
7508 * to the new child though */
7509 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7510 data.flags |= priv->state_flags;
7512 data.operation = STATE_CHANGE_REPLACE;
7513 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7514 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7515 gtk_widget_propagate_state (widget, &data);
7517 gtk_widget_reset_rc_styles (widget);
7519 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7520 if (priv->parent->priv->anchored)
7521 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7522 g_object_notify (G_OBJECT (widget), "parent");
7524 /* Enforce realized/mapped invariants
7526 if (gtk_widget_get_realized (priv->parent))
7527 gtk_widget_realize (widget);
7529 if (gtk_widget_get_visible (priv->parent) &&
7530 gtk_widget_get_visible (widget))
7532 if (gtk_widget_get_child_visible (widget) &&
7533 gtk_widget_get_mapped (priv->parent))
7534 gtk_widget_map (widget);
7536 gtk_widget_queue_resize (widget);
7539 /* child may cause parent's expand to change, if the child is
7540 * expanded. If child is not expanded, then it can't modify the
7541 * parent's expand. If the child becomes expanded later then it will
7542 * queue compute_expand then. This optimization plus defaulting
7543 * newly-constructed widgets to need_compute_expand=FALSE should
7544 * mean that initially building a widget tree doesn't have to keep
7545 * walking up setting need_compute_expand on parents over and over.
7547 * We can't change a parent to need to expand unless we're visible.
7549 if (gtk_widget_get_visible (widget) &&
7550 (priv->need_compute_expand ||
7551 priv->computed_hexpand ||
7552 priv->computed_vexpand))
7554 gtk_widget_queue_compute_expand (parent);
7557 if (widget->priv->context)
7559 _gtk_widget_update_path (widget);
7560 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7562 gtk_style_context_set_screen (widget->priv->context,
7563 gtk_widget_get_screen (widget));
7568 * gtk_widget_get_parent:
7569 * @widget: a #GtkWidget
7571 * Returns the parent container of @widget.
7573 * Return value: (transfer none): the parent container of @widget, or %NULL
7576 gtk_widget_get_parent (GtkWidget *widget)
7578 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7580 return widget->priv->parent;
7583 /*****************************************
7585 * see docs/styles.txt
7586 *****************************************/
7589 * gtk_widget_style_attach:
7590 * @widget: a #GtkWidget
7592 * This function attaches the widget's #GtkStyle to the widget's
7593 * #GdkWindow. It is a replacement for
7596 * widget->style = gtk_style_attach (widget->style, widget->window);
7599 * and should only ever be called in a derived widget's "realize"
7600 * implementation which does not chain up to its parent class'
7601 * "realize" implementation, because one of the parent classes
7602 * (finally #GtkWidget) would attach the style itself.
7607 gtk_widget_style_attach (GtkWidget *widget)
7609 GtkWidgetPrivate *priv;
7611 g_return_if_fail (GTK_IS_WIDGET (widget));
7612 g_return_if_fail (gtk_widget_get_realized (widget));
7614 priv = widget->priv;
7616 priv->style = gtk_style_attach (priv->style, priv->window);
7620 * gtk_widget_has_rc_style:
7621 * @widget: a #GtkWidget
7623 * Determines if the widget style has been looked up through the rc mechanism.
7625 * Returns: %TRUE if the widget has been looked up through the rc
7626 * mechanism, %FALSE otherwise.
7630 * Deprecated:3.0: Use #GtkStyleContext instead
7633 gtk_widget_has_rc_style (GtkWidget *widget)
7635 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7637 return widget->priv->rc_style;
7641 * gtk_widget_set_style:
7642 * @widget: a #GtkWidget
7643 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7644 * gtk_widget_set_style() and go back to the default style
7646 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7647 * want to use this function; it interacts badly with themes, because
7648 * themes work by replacing the #GtkStyle. Instead, use
7649 * gtk_widget_modify_style().
7651 * Deprecated:3.0: Use #GtkStyleContext instead
7654 gtk_widget_set_style (GtkWidget *widget,
7657 g_return_if_fail (GTK_IS_WIDGET (widget));
7661 gboolean initial_emission;
7663 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7665 widget->priv->rc_style = FALSE;
7666 widget->priv->user_style = TRUE;
7668 gtk_widget_set_style_internal (widget, style, initial_emission);
7672 if (widget->priv->user_style)
7673 gtk_widget_reset_rc_style (widget);
7678 * gtk_widget_ensure_style:
7679 * @widget: a #GtkWidget
7681 * Ensures that @widget has a style (@widget->style). Not a very useful
7682 * function; most of the time, if you want the style, the widget is
7683 * realized, and realized widgets are guaranteed to have a style
7686 * Deprecated:3.0: Use #GtkStyleContext instead
7689 gtk_widget_ensure_style (GtkWidget *widget)
7691 g_return_if_fail (GTK_IS_WIDGET (widget));
7693 if (!widget->priv->style ||
7694 !gtk_style_has_context (widget->priv->style))
7698 style = g_object_new (GTK_TYPE_STYLE,
7699 "context", gtk_widget_get_style_context (widget),
7702 gtk_widget_set_style_internal (widget, style, TRUE);
7703 g_object_unref (style);
7707 if (!widget->priv->rc_style && !widget->priv->user_style)
7708 gtk_widget_reset_rc_style (widget);
7712 /* Look up the RC style for this widget, unsetting any user style that
7713 * may be in effect currently
7716 gtk_widget_reset_rc_style (GtkWidget *widget)
7718 GtkWidgetPrivate *priv = widget->priv;
7719 GtkStyle *new_style = NULL;
7720 gboolean initial_emission;
7722 initial_emission = !priv->rc_style && !priv->user_style;
7724 priv->user_style = FALSE;
7725 priv->rc_style = TRUE;
7727 if (gtk_widget_has_screen (widget))
7728 new_style = gtk_rc_get_style (widget);
7730 new_style = gtk_widget_get_default_style ();
7732 if (initial_emission || new_style != priv->style)
7733 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7737 * gtk_widget_get_style:
7738 * @widget: a #GtkWidget
7740 * Simply an accessor function that returns @widget->style.
7742 * Return value: (transfer none): the widget's #GtkStyle
7744 * Deprecated:3.0: Use #GtkStyleContext instead
7747 gtk_widget_get_style (GtkWidget *widget)
7749 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7751 return widget->priv->style;
7755 * gtk_widget_modify_style:
7756 * @widget: a #GtkWidget
7757 * @style: the #GtkRcStyle holding the style modifications
7759 * Modifies style values on the widget. Modifications made using this
7760 * technique take precedence over style values set via an RC file,
7761 * however, they will be overriden if a style is explicitely set on
7762 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7763 * is designed so each field can either be set or unset, so it is
7764 * possible, using this function, to modify some style values and
7765 * leave the others unchanged.
7767 * Note that modifications made with this function are not cumulative
7768 * with previous calls to gtk_widget_modify_style() or with such
7769 * functions as gtk_widget_modify_fg(). If you wish to retain
7770 * previous values, you must first call gtk_widget_get_modifier_style(),
7771 * make your modifications to the returned style, then call
7772 * gtk_widget_modify_style() with that style. On the other hand,
7773 * if you first call gtk_widget_modify_style(), subsequent calls
7774 * to such functions gtk_widget_modify_fg() will have a cumulative
7775 * effect with the initial modifications.
7777 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7780 gtk_widget_modify_style (GtkWidget *widget,
7783 g_return_if_fail (GTK_IS_WIDGET (widget));
7784 g_return_if_fail (GTK_IS_RC_STYLE (style));
7786 g_object_set_qdata_full (G_OBJECT (widget),
7788 gtk_rc_style_copy (style),
7789 (GDestroyNotify) g_object_unref);
7791 /* note that "style" may be invalid here if it was the old
7792 * modifier style and the only reference was our own.
7795 if (widget->priv->rc_style)
7796 gtk_widget_reset_rc_style (widget);
7800 * gtk_widget_get_modifier_style:
7801 * @widget: a #GtkWidget
7803 * Returns the current modifier style for the widget. (As set by
7804 * gtk_widget_modify_style().) If no style has previously set, a new
7805 * #GtkRcStyle will be created with all values unset, and set as the
7806 * modifier style for the widget. If you make changes to this rc
7807 * style, you must call gtk_widget_modify_style(), passing in the
7808 * returned rc style, to make sure that your changes take effect.
7810 * Caution: passing the style back to gtk_widget_modify_style() will
7811 * normally end up destroying it, because gtk_widget_modify_style() copies
7812 * the passed-in style and sets the copy as the new modifier style,
7813 * thus dropping any reference to the old modifier style. Add a reference
7814 * to the modifier style if you want to keep it alive.
7816 * Return value: (transfer none): the modifier style for the widget.
7817 * This rc style is owned by the widget. If you want to keep a
7818 * pointer to value this around, you must add a refcount using
7821 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7824 gtk_widget_get_modifier_style (GtkWidget *widget)
7826 GtkRcStyle *rc_style;
7828 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7830 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7834 rc_style = gtk_rc_style_new ();
7835 g_object_set_qdata_full (G_OBJECT (widget),
7838 (GDestroyNotify) g_object_unref);
7845 gtk_widget_modify_color_component (GtkWidget *widget,
7846 GtkRcFlags component,
7848 const GdkColor *color)
7850 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7857 rc_style->fg[state] = *color;
7860 rc_style->bg[state] = *color;
7863 rc_style->text[state] = *color;
7866 rc_style->base[state] = *color;
7869 g_assert_not_reached();
7872 rc_style->color_flags[state] |= component;
7875 rc_style->color_flags[state] &= ~component;
7877 gtk_widget_modify_style (widget, rc_style);
7881 modifier_style_changed (GtkModifierStyle *style,
7884 GtkStyleContext *context;
7886 context = gtk_widget_get_style_context (widget);
7887 gtk_style_context_invalidate (context);
7889 g_signal_emit (widget,
7890 widget_signals[STYLE_SET],
7892 widget->priv->style);
7895 static GtkModifierStyle *
7896 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7898 GtkModifierStyle *style;
7900 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7902 if (G_UNLIKELY (!style))
7904 GtkStyleContext *context;
7906 style = gtk_modifier_style_new ();
7907 g_object_set_qdata_full (G_OBJECT (widget),
7908 quark_modifier_style,
7910 (GDestroyNotify) g_object_unref);
7912 g_signal_connect (style, "changed",
7913 G_CALLBACK (modifier_style_changed), widget);
7915 context = gtk_widget_get_style_context (widget);
7917 gtk_style_context_add_provider (context,
7918 GTK_STYLE_PROVIDER (style),
7919 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7926 * gtk_widget_override_color:
7927 * @widget: a #GtkWidget
7928 * @state: the state for which to set the color
7929 * @color: the color to assign, or %NULL to undo the effect
7930 * of previous calls to gtk_widget_override_color()
7932 * Sets the color to use for a widget. All other style values are left
7937 * This API is mostly meant as a quick way for applications to change a
7938 * widget appearance. If you are developing a widgets library and intend
7939 * this change to be themeable, it is better done by setting meaningful
7940 * CSS classes and regions in your widget/container implementation through
7941 * gtk_style_context_add_class() and gtk_style_context_add_region().
7944 * This way, your widget library can install a #GtkCssProvider with the
7945 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
7946 * default styling for those widgets that need so, and this theming may
7947 * fully overridden by the user's theme.
7953 * Note that for complex widgets this may bring in
7954 * undesired results (such as uniform background color everywhere),
7955 * in these cases it is better to fully style such widgets through a
7956 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7964 gtk_widget_override_color (GtkWidget *widget,
7965 GtkStateFlags state,
7966 const GdkRGBA *color)
7968 GtkModifierStyle *style;
7970 g_return_if_fail (GTK_IS_WIDGET (widget));
7972 style = _gtk_widget_get_modifier_properties (widget);
7973 gtk_modifier_style_set_color (style, state, color);
7977 * gtk_widget_override_background_color:
7978 * @widget: a #GtkWidget
7979 * @state: the state for which to set the background color
7980 * @color: the color to assign, or %NULL to undo the effect
7981 * of previous calls to gtk_widget_override_background_color()
7983 * Sets the background color to use for a widget. All other style values
7984 * are left untouched. See gtk_widget_override_color().
7989 gtk_widget_override_background_color (GtkWidget *widget,
7990 GtkStateFlags state,
7991 const GdkRGBA *color)
7993 GtkModifierStyle *style;
7995 g_return_if_fail (GTK_IS_WIDGET (widget));
7997 style = _gtk_widget_get_modifier_properties (widget);
7998 gtk_modifier_style_set_background_color (style, state, color);
8002 * gtk_widget_override_font:
8003 * @widget: a #GtkWidget
8004 * @font_desc: the font descriptiong to use, or %NULL to undo
8005 * the effect of previous calls to
8006 * gtk_widget_override_font().
8008 * Sets the font to use for a widget. All other style values are
8009 * left untouched. See gtk_widget_override_color().
8014 gtk_widget_override_font (GtkWidget *widget,
8015 const PangoFontDescription *font_desc)
8017 GtkModifierStyle *style;
8019 g_return_if_fail (GTK_IS_WIDGET (widget));
8021 style = _gtk_widget_get_modifier_properties (widget);
8022 gtk_modifier_style_set_font (style, font_desc);
8026 * gtk_widget_override_symbolic_color:
8027 * @widget: a #GtkWidget
8028 * @name: the name of the symbolic color to modify
8029 * @color: (allow-none): the color to assign (does not need to be allocated),
8030 * or %NULL to undo the effect of previous calls to
8031 * gtk_widget_override_symbolic_color().
8033 * Sets a symbolic color for a widget, All other style values are left
8034 * untouched. See gtk_widget_override_color() for overriding the foreground
8035 * or background color.
8040 gtk_widget_override_symbolic_color (GtkWidget *widget,
8042 const GdkRGBA *color)
8044 GtkModifierStyle *style;
8046 g_return_if_fail (GTK_IS_WIDGET (widget));
8048 style = _gtk_widget_get_modifier_properties (widget);
8049 gtk_modifier_style_map_color (style, name, color);
8053 * gtk_widget_override_cursor:
8054 * @widget: a #GtkWidget
8055 * @cursor: the color to use for primary cursor (does not need to be
8056 * allocated), or %NULL to undo the effect of previous calls to
8057 * of gtk_widget_override_cursor().
8058 * @secondary_cursor: the color to use for secondary cursor (does not
8059 * need to be allocated), or %NULL to undo the effect of previous
8060 * calls to of gtk_widget_override_cursor().
8062 * Sets the cursor color to use in a widget, overriding the
8063 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8064 * style properties. All other style values are left untouched.
8065 * See also gtk_widget_modify_style().
8067 * Note that the underlying properties have the #GdkColor type,
8068 * so the alpha value in @primary and @secondary will be ignored.
8073 gtk_widget_override_cursor (GtkWidget *widget,
8074 const GdkRGBA *cursor,
8075 const GdkRGBA *secondary_cursor)
8077 GtkModifierStyle *style;
8079 g_return_if_fail (GTK_IS_WIDGET (widget));
8081 style = _gtk_widget_get_modifier_properties (widget);
8082 gtk_modifier_style_set_color_property (style,
8084 "cursor-color", cursor);
8085 gtk_modifier_style_set_color_property (style,
8087 "secondary-cursor-color",
8092 * gtk_widget_modify_fg:
8093 * @widget: a #GtkWidget
8094 * @state: the state for which to set the foreground color
8095 * @color: (allow-none): the color to assign (does not need to be allocated),
8096 * or %NULL to undo the effect of previous calls to
8097 * of gtk_widget_modify_fg().
8099 * Sets the foreground color for a widget in a particular state.
8100 * All other style values are left untouched. See also
8101 * gtk_widget_modify_style().
8103 * Deprecated:3.0: Use gtk_widget_override_color() instead
8106 gtk_widget_modify_fg (GtkWidget *widget,
8108 const GdkColor *color)
8110 GtkStateFlags flags;
8113 g_return_if_fail (GTK_IS_WIDGET (widget));
8114 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8118 case GTK_STATE_ACTIVE:
8119 flags = GTK_STATE_FLAG_ACTIVE;
8121 case GTK_STATE_PRELIGHT:
8122 flags = GTK_STATE_FLAG_PRELIGHT;
8124 case GTK_STATE_SELECTED:
8125 flags = GTK_STATE_FLAG_SELECTED;
8127 case GTK_STATE_INSENSITIVE:
8128 flags = GTK_STATE_FLAG_INSENSITIVE;
8130 case GTK_STATE_NORMAL:
8137 rgba.red = color->red / 65535.;
8138 rgba.green = color->green / 65535.;
8139 rgba.blue = color->blue / 65535.;
8142 gtk_widget_override_color (widget, state, &rgba);
8145 gtk_widget_override_color (widget, state, NULL);
8149 * gtk_widget_modify_bg:
8150 * @widget: a #GtkWidget
8151 * @state: the state for which to set the background color
8152 * @color: (allow-none): the color to assign (does not need to be allocated),
8153 * or %NULL to undo the effect of previous calls to
8154 * of gtk_widget_modify_bg().
8156 * Sets the background color for a widget in a particular state.
8157 * All other style values are left untouched. See also
8158 * gtk_widget_modify_style().
8160 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8161 * draw on their parent container's window and thus may not draw any
8162 * background themselves. This is the case for e.g. #GtkLabel. To modify
8163 * the background of such widgets, you have to set the background color
8164 * on their parent; if you want to set the background of a rectangular
8165 * area around a label, try placing the label in a #GtkEventBox widget
8166 * and setting the background color on that.
8168 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8171 gtk_widget_modify_bg (GtkWidget *widget,
8173 const GdkColor *color)
8175 GtkStateFlags flags;
8178 g_return_if_fail (GTK_IS_WIDGET (widget));
8179 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8183 case GTK_STATE_ACTIVE:
8184 flags = GTK_STATE_FLAG_ACTIVE;
8186 case GTK_STATE_PRELIGHT:
8187 flags = GTK_STATE_FLAG_PRELIGHT;
8189 case GTK_STATE_SELECTED:
8190 flags = GTK_STATE_FLAG_SELECTED;
8192 case GTK_STATE_INSENSITIVE:
8193 flags = GTK_STATE_FLAG_INSENSITIVE;
8195 case GTK_STATE_NORMAL:
8202 rgba.red = color->red / 65535.;
8203 rgba.green = color->green / 65535.;
8204 rgba.blue = color->blue / 65535.;
8207 gtk_widget_override_background_color (widget, state, &rgba);
8210 gtk_widget_override_background_color (widget, state, NULL);
8214 * gtk_widget_modify_text:
8215 * @widget: a #GtkWidget
8216 * @state: the state for which to set the text color
8217 * @color: (allow-none): the color to assign (does not need to be allocated),
8218 * or %NULL to undo the effect of previous calls to
8219 * of gtk_widget_modify_text().
8221 * Sets the text color for a widget in a particular state. All other
8222 * style values are left untouched. The text color is the foreground
8223 * color used along with the base color (see gtk_widget_modify_base())
8224 * for widgets such as #GtkEntry and #GtkTextView. See also
8225 * gtk_widget_modify_style().
8227 * Deprecated:3.0: Use gtk_widget_override_color() instead
8230 gtk_widget_modify_text (GtkWidget *widget,
8232 const GdkColor *color)
8234 g_return_if_fail (GTK_IS_WIDGET (widget));
8235 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8237 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8241 * gtk_widget_modify_base:
8242 * @widget: a #GtkWidget
8243 * @state: the state for which to set the base color
8244 * @color: (allow-none): the color to assign (does not need to be allocated),
8245 * or %NULL to undo the effect of previous calls to
8246 * of gtk_widget_modify_base().
8248 * Sets the base color for a widget in a particular state.
8249 * All other style values are left untouched. The base color
8250 * is the background color used along with the text color
8251 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8252 * and #GtkTextView. See also gtk_widget_modify_style().
8254 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8255 * draw on their parent container's window and thus may not draw any
8256 * background themselves. This is the case for e.g. #GtkLabel. To modify
8257 * the background of such widgets, you have to set the base color on their
8258 * parent; if you want to set the background of a rectangular area around
8259 * a label, try placing the label in a #GtkEventBox widget and setting
8260 * the base color on that.
8262 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8265 gtk_widget_modify_base (GtkWidget *widget,
8267 const GdkColor *color)
8269 g_return_if_fail (GTK_IS_WIDGET (widget));
8270 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8272 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8276 * gtk_widget_modify_cursor:
8277 * @widget: a #GtkWidget
8278 * @primary: the color to use for primary cursor (does not need to be
8279 * allocated), or %NULL to undo the effect of previous calls to
8280 * of gtk_widget_modify_cursor().
8281 * @secondary: the color to use for secondary cursor (does not need to be
8282 * allocated), or %NULL to undo the effect of previous calls to
8283 * of gtk_widget_modify_cursor().
8285 * Sets the cursor color to use in a widget, overriding the
8286 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8287 * style properties. All other style values are left untouched.
8288 * See also gtk_widget_modify_style().
8292 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8295 gtk_widget_modify_cursor (GtkWidget *widget,
8296 const GdkColor *primary,
8297 const GdkColor *secondary)
8299 GdkRGBA primary_rgba, secondary_rgba;
8301 g_return_if_fail (GTK_IS_WIDGET (widget));
8303 primary_rgba.red = primary->red / 65535.;
8304 primary_rgba.green = primary->green / 65535.;
8305 primary_rgba.blue = primary->blue / 65535.;
8306 primary_rgba.alpha = 1;
8308 secondary_rgba.red = secondary->red / 65535.;
8309 secondary_rgba.green = secondary->green / 65535.;
8310 secondary_rgba.blue = secondary->blue / 65535.;
8311 secondary_rgba.alpha = 1;
8313 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8317 * gtk_widget_modify_font:
8318 * @widget: a #GtkWidget
8319 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8320 * the effect of previous calls to gtk_widget_modify_font().
8322 * Sets the font to use for a widget. All other style values are left
8323 * untouched. See also gtk_widget_modify_style().
8325 * Deprecated:3.0: Use gtk_widget_override_font() instead
8328 gtk_widget_modify_font (GtkWidget *widget,
8329 PangoFontDescription *font_desc)
8331 g_return_if_fail (GTK_IS_WIDGET (widget));
8333 gtk_widget_override_font (widget, font_desc);
8337 gtk_widget_real_direction_changed (GtkWidget *widget,
8338 GtkTextDirection previous_direction)
8340 gtk_widget_queue_resize (widget);
8344 gtk_widget_real_style_set (GtkWidget *widget,
8345 GtkStyle *previous_style)
8347 GtkWidgetPrivate *priv = widget->priv;
8349 if (gtk_widget_get_realized (widget) &&
8350 gtk_widget_get_has_window (widget))
8351 gtk_style_set_background (priv->style, priv->window,
8352 gtk_widget_get_state (widget));
8356 gtk_widget_set_style_internal (GtkWidget *widget,
8358 gboolean initial_emission)
8360 GtkWidgetPrivate *priv = widget->priv;
8362 g_object_ref (widget);
8363 g_object_freeze_notify (G_OBJECT (widget));
8365 if (priv->style != style)
8367 GtkStyle *previous_style;
8369 if (gtk_widget_get_realized (widget))
8370 gtk_style_detach (priv->style);
8372 previous_style = priv->style;
8373 priv->style = style;
8374 g_object_ref (priv->style);
8376 if (gtk_widget_get_realized (widget))
8377 priv->style = gtk_style_attach (priv->style, priv->window);
8379 gtk_widget_update_pango_context (widget);
8380 g_signal_emit (widget,
8381 widget_signals[STYLE_SET],
8383 initial_emission ? NULL : previous_style);
8384 g_object_unref (previous_style);
8386 if (priv->anchored && !initial_emission)
8387 gtk_widget_queue_resize (widget);
8389 else if (initial_emission)
8391 gtk_widget_update_pango_context (widget);
8392 g_signal_emit (widget,
8393 widget_signals[STYLE_SET],
8397 g_object_notify (G_OBJECT (widget), "style");
8398 g_object_thaw_notify (G_OBJECT (widget));
8399 g_object_unref (widget);
8403 GtkWidget *previous_toplevel;
8404 GdkScreen *previous_screen;
8405 GdkScreen *new_screen;
8406 } HierarchyChangedInfo;
8409 do_screen_change (GtkWidget *widget,
8410 GdkScreen *old_screen,
8411 GdkScreen *new_screen)
8413 if (old_screen != new_screen)
8415 GtkStyleContext *context;
8419 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8421 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8424 _gtk_tooltip_hide (widget);
8426 context = gtk_widget_get_style_context (widget);
8427 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8429 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8434 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8435 gpointer client_data)
8437 GtkWidgetPrivate *priv = widget->priv;
8438 HierarchyChangedInfo *info = client_data;
8439 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8440 (priv->parent && priv->parent->priv->anchored);
8442 if (priv->anchored != new_anchored)
8444 g_object_ref (widget);
8446 priv->anchored = new_anchored;
8448 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8449 do_screen_change (widget, info->previous_screen, info->new_screen);
8451 if (GTK_IS_CONTAINER (widget))
8452 gtk_container_forall (GTK_CONTAINER (widget),
8453 gtk_widget_propagate_hierarchy_changed_recurse,
8456 g_object_unref (widget);
8461 * _gtk_widget_propagate_hierarchy_changed:
8462 * @widget: a #GtkWidget
8463 * @previous_toplevel: Previous toplevel
8465 * Propagates changes in the anchored state to a widget and all
8466 * children, unsetting or setting the %ANCHORED flag, and
8467 * emitting #GtkWidget::hierarchy-changed.
8470 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8471 GtkWidget *previous_toplevel)
8473 GtkWidgetPrivate *priv = widget->priv;
8474 HierarchyChangedInfo info;
8476 info.previous_toplevel = previous_toplevel;
8477 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8479 if (gtk_widget_is_toplevel (widget) ||
8480 (priv->parent && priv->parent->priv->anchored))
8481 info.new_screen = gtk_widget_get_screen (widget);
8483 info.new_screen = NULL;
8485 if (info.previous_screen)
8486 g_object_ref (info.previous_screen);
8487 if (previous_toplevel)
8488 g_object_ref (previous_toplevel);
8490 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8492 if (previous_toplevel)
8493 g_object_unref (previous_toplevel);
8494 if (info.previous_screen)
8495 g_object_unref (info.previous_screen);
8499 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8500 gpointer client_data)
8502 HierarchyChangedInfo *info = client_data;
8504 g_object_ref (widget);
8506 do_screen_change (widget, info->previous_screen, info->new_screen);
8508 if (GTK_IS_CONTAINER (widget))
8509 gtk_container_forall (GTK_CONTAINER (widget),
8510 gtk_widget_propagate_screen_changed_recurse,
8513 g_object_unref (widget);
8517 * gtk_widget_is_composited:
8518 * @widget: a #GtkWidget
8520 * Whether @widget can rely on having its alpha channel
8521 * drawn correctly. On X11 this function returns whether a
8522 * compositing manager is running for @widget's screen.
8524 * Please note that the semantics of this call will change
8525 * in the future if used on a widget that has a composited
8526 * window in its hierarchy (as set by gdk_window_set_composited()).
8528 * Return value: %TRUE if the widget can rely on its alpha
8529 * channel being drawn correctly.
8534 gtk_widget_is_composited (GtkWidget *widget)
8538 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8540 screen = gtk_widget_get_screen (widget);
8542 return gdk_screen_is_composited (screen);
8546 propagate_composited_changed (GtkWidget *widget,
8549 if (GTK_IS_CONTAINER (widget))
8551 gtk_container_forall (GTK_CONTAINER (widget),
8552 propagate_composited_changed,
8556 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8560 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8562 propagate_composited_changed (widget, NULL);
8566 * _gtk_widget_propagate_screen_changed:
8567 * @widget: a #GtkWidget
8568 * @previous_screen: Previous screen
8570 * Propagates changes in the screen for a widget to all
8571 * children, emitting #GtkWidget::screen-changed.
8574 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8575 GdkScreen *previous_screen)
8577 HierarchyChangedInfo info;
8579 info.previous_screen = previous_screen;
8580 info.new_screen = gtk_widget_get_screen (widget);
8582 if (previous_screen)
8583 g_object_ref (previous_screen);
8585 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8587 if (previous_screen)
8588 g_object_unref (previous_screen);
8592 reset_style_recurse (GtkWidget *widget, gpointer data)
8595 if (widget->priv->rc_style)
8596 gtk_widget_reset_rc_style (widget);
8599 if (widget->priv->context)
8601 _gtk_widget_update_path (widget);
8602 gtk_style_context_set_path (widget->priv->context,
8603 widget->priv->path);
8606 if (GTK_IS_CONTAINER (widget))
8607 gtk_container_forall (GTK_CONTAINER (widget),
8608 reset_style_recurse,
8613 * gtk_widget_reset_style:
8614 * @widget: a #GtkWidget
8616 * Updates the style context of @widget and all descendents
8617 * by updating its widget path. #GtkContainer<!-- -->s may want
8618 * to use this on a child when reordering it in a way that a different
8619 * style might apply to it. See also gtk_container_get_path_for_child().
8624 gtk_widget_reset_style (GtkWidget *widget)
8626 g_return_if_fail (GTK_IS_WIDGET (widget));
8628 reset_style_recurse (widget, NULL);
8632 * gtk_widget_reset_rc_styles:
8633 * @widget: a #GtkWidget.
8635 * Reset the styles of @widget and all descendents, so when
8636 * they are looked up again, they get the correct values
8637 * for the currently loaded RC file settings.
8639 * This function is not useful for applications.
8641 * Deprecated:3.0: Use #GtkStyleContext instead
8644 gtk_widget_reset_rc_styles (GtkWidget *widget)
8646 g_return_if_fail (GTK_IS_WIDGET (widget));
8648 reset_style_recurse (widget, NULL);
8652 * gtk_widget_get_default_style:
8654 * Returns the default style used by all widgets initially.
8656 * Returns: (transfer none): the default style. This #GtkStyle
8657 * object is owned by GTK+ and should not be modified or freed.
8659 * Deprecated:3.0: Use #GtkStyleContext instead
8662 gtk_widget_get_default_style (void)
8664 if (!gtk_default_style)
8666 gtk_default_style = gtk_style_new ();
8667 g_object_ref (gtk_default_style);
8670 return gtk_default_style;
8673 static PangoContext *
8674 gtk_widget_peek_pango_context (GtkWidget *widget)
8676 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8680 * gtk_widget_get_pango_context:
8681 * @widget: a #GtkWidget
8683 * Gets a #PangoContext with the appropriate font map, font description,
8684 * and base direction for this widget. Unlike the context returned
8685 * by gtk_widget_create_pango_context(), this context is owned by
8686 * the widget (it can be used until the screen for the widget changes
8687 * or the widget is removed from its toplevel), and will be updated to
8688 * match any changes to the widget's attributes.
8690 * If you create and keep a #PangoLayout using this context, you must
8691 * deal with changes to the context by calling pango_layout_context_changed()
8692 * on the layout in response to the #GtkWidget::style-updated and
8693 * #GtkWidget::direction-changed signals for the widget.
8695 * Return value: (transfer none): the #PangoContext for the widget.
8698 gtk_widget_get_pango_context (GtkWidget *widget)
8700 PangoContext *context;
8702 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8704 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8707 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8708 g_object_set_qdata_full (G_OBJECT (widget),
8709 quark_pango_context,
8718 update_pango_context (GtkWidget *widget,
8719 PangoContext *context)
8721 PangoFontDescription *font_desc;
8722 GtkStyleContext *style_context;
8724 style_context = gtk_widget_get_style_context (widget);
8726 gtk_style_context_get (style_context,
8727 gtk_widget_get_state_flags (widget),
8731 pango_context_set_font_description (context, font_desc);
8732 pango_context_set_base_dir (context,
8733 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8734 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8736 pango_font_description_free (font_desc);
8740 gtk_widget_update_pango_context (GtkWidget *widget)
8742 PangoContext *context = gtk_widget_peek_pango_context (widget);
8748 update_pango_context (widget, context);
8750 screen = gtk_widget_get_screen_unchecked (widget);
8753 pango_cairo_context_set_resolution (context,
8754 gdk_screen_get_resolution (screen));
8755 pango_cairo_context_set_font_options (context,
8756 gdk_screen_get_font_options (screen));
8762 * gtk_widget_create_pango_context:
8763 * @widget: a #GtkWidget
8765 * Creates a new #PangoContext with the appropriate font map,
8766 * font description, and base direction for drawing text for
8767 * this widget. See also gtk_widget_get_pango_context().
8769 * Return value: (transfer full): the new #PangoContext
8772 gtk_widget_create_pango_context (GtkWidget *widget)
8775 PangoContext *context;
8777 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8779 screen = gtk_widget_get_screen_unchecked (widget);
8782 GTK_NOTE (MULTIHEAD,
8783 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8785 screen = gdk_screen_get_default ();
8788 context = gdk_pango_context_get_for_screen (screen);
8790 update_pango_context (widget, context);
8791 pango_context_set_language (context, gtk_get_default_language ());
8797 * gtk_widget_create_pango_layout:
8798 * @widget: a #GtkWidget
8799 * @text: text to set on the layout (can be %NULL)
8801 * Creates a new #PangoLayout with the appropriate font map,
8802 * font description, and base direction for drawing text for
8805 * If you keep a #PangoLayout created in this way around, in order to
8806 * notify the layout of changes to the base direction or font of this
8807 * widget, you must call pango_layout_context_changed() in response to
8808 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8811 * Return value: (transfer full): the new #PangoLayout
8814 gtk_widget_create_pango_layout (GtkWidget *widget,
8817 PangoLayout *layout;
8818 PangoContext *context;
8820 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8822 context = gtk_widget_get_pango_context (widget);
8823 layout = pango_layout_new (context);
8826 pango_layout_set_text (layout, text, -1);
8832 * gtk_widget_render_icon_pixbuf:
8833 * @widget: a #GtkWidget
8834 * @stock_id: a stock ID
8835 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8836 * render at the size of the source and don't scale (if there are
8837 * multiple source sizes, GTK+ picks one of the available sizes).
8839 * A convenience function that uses the theme engine and style
8840 * settings for @widget to look up @stock_id and render it to
8841 * a pixbuf. @stock_id should be a stock icon ID such as
8842 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8843 * such as #GTK_ICON_SIZE_MENU.
8845 * The pixels in the returned #GdkPixbuf are shared with the rest of
8846 * the application and should not be modified. The pixbuf should be freed
8847 * after use with g_object_unref().
8849 * Return value: (transfer full): a new pixbuf, or %NULL if the
8850 * stock ID wasn't known
8855 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8856 const gchar *stock_id,
8859 GtkWidgetPrivate *priv;
8860 GtkIconSet *icon_set;
8862 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8863 g_return_val_if_fail (stock_id != NULL, NULL);
8864 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8866 priv = widget->priv;
8868 gtk_widget_ensure_style (widget);
8870 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
8872 if (icon_set == NULL)
8875 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
8879 * gtk_widget_render_icon:
8880 * @widget: a #GtkWidget
8881 * @stock_id: a stock ID
8882 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8883 * render at the size of the source and don't scale (if there are
8884 * multiple source sizes, GTK+ picks one of the available sizes).
8885 * @detail: (allow-none): render detail to pass to theme engine
8887 * A convenience function that uses the theme engine and RC file
8888 * settings for @widget to look up @stock_id and render it to
8889 * a pixbuf. @stock_id should be a stock icon ID such as
8890 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8891 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8892 * identifies the widget or code doing the rendering, so that
8893 * theme engines can special-case rendering for that widget or code.
8895 * The pixels in the returned #GdkPixbuf are shared with the rest of
8896 * the application and should not be modified. The pixbuf should be freed
8897 * after use with g_object_unref().
8899 * Return value: (transfer full): a new pixbuf, or %NULL if the
8900 * stock ID wasn't known
8902 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
8905 gtk_widget_render_icon (GtkWidget *widget,
8906 const gchar *stock_id,
8908 const gchar *detail)
8910 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
8914 * gtk_widget_set_parent_window:
8915 * @widget: a #GtkWidget.
8916 * @parent_window: the new parent window.
8918 * Sets a non default parent window for @widget.
8921 gtk_widget_set_parent_window (GtkWidget *widget,
8922 GdkWindow *parent_window)
8924 GdkWindow *old_parent_window;
8926 g_return_if_fail (GTK_IS_WIDGET (widget));
8928 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8929 quark_parent_window);
8931 if (parent_window != old_parent_window)
8933 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8935 if (old_parent_window)
8936 g_object_unref (old_parent_window);
8938 g_object_ref (parent_window);
8943 * gtk_widget_get_parent_window:
8944 * @widget: a #GtkWidget.
8946 * Gets @widget's parent window.
8948 * Returns: (transfer none): the parent window of @widget.
8951 gtk_widget_get_parent_window (GtkWidget *widget)
8953 GtkWidgetPrivate *priv;
8954 GdkWindow *parent_window;
8956 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8958 priv = widget->priv;
8960 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8962 return (parent_window != NULL) ? parent_window :
8963 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8968 * gtk_widget_set_child_visible:
8969 * @widget: a #GtkWidget
8970 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8972 * Sets whether @widget should be mapped along with its when its parent
8973 * is mapped and @widget has been shown with gtk_widget_show().
8975 * The child visibility can be set for widget before it is added to
8976 * a container with gtk_widget_set_parent(), to avoid mapping
8977 * children unnecessary before immediately unmapping them. However
8978 * it will be reset to its default state of %TRUE when the widget
8979 * is removed from a container.
8981 * Note that changing the child visibility of a widget does not
8982 * queue a resize on the widget. Most of the time, the size of
8983 * a widget is computed from all visible children, whether or
8984 * not they are mapped. If this is not the case, the container
8985 * can queue a resize itself.
8987 * This function is only useful for container implementations and
8988 * never should be called by an application.
8991 gtk_widget_set_child_visible (GtkWidget *widget,
8992 gboolean is_visible)
8994 GtkWidgetPrivate *priv;
8996 g_return_if_fail (GTK_IS_WIDGET (widget));
8997 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8999 priv = widget->priv;
9001 g_object_ref (widget);
9004 priv->child_visible = TRUE;
9007 GtkWidget *toplevel;
9009 priv->child_visible = FALSE;
9011 toplevel = gtk_widget_get_toplevel (widget);
9012 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9013 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9016 if (priv->parent && gtk_widget_get_realized (priv->parent))
9018 if (gtk_widget_get_mapped (priv->parent) &&
9019 priv->child_visible &&
9020 gtk_widget_get_visible (widget))
9021 gtk_widget_map (widget);
9023 gtk_widget_unmap (widget);
9026 g_object_unref (widget);
9030 * gtk_widget_get_child_visible:
9031 * @widget: a #GtkWidget
9033 * Gets the value set with gtk_widget_set_child_visible().
9034 * If you feel a need to use this function, your code probably
9035 * needs reorganization.
9037 * This function is only useful for container implementations and
9038 * never should be called by an application.
9040 * Return value: %TRUE if the widget is mapped with the parent.
9043 gtk_widget_get_child_visible (GtkWidget *widget)
9045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9047 return widget->priv->child_visible;
9051 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9053 GtkWidget *toplevel;
9055 toplevel = gtk_widget_get_toplevel (widget);
9057 if (gtk_widget_is_toplevel (toplevel))
9059 if (GTK_IS_WINDOW (toplevel))
9060 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9061 else if (GTK_IS_INVISIBLE (toplevel))
9062 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9069 * gtk_widget_get_screen:
9070 * @widget: a #GtkWidget
9072 * Get the #GdkScreen from the toplevel window associated with
9073 * this widget. This function can only be called after the widget
9074 * has been added to a widget hierarchy with a #GtkWindow
9077 * In general, you should only create screen specific
9078 * resources when a widget has been realized, and you should
9079 * free those resources when the widget is unrealized.
9081 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9086 gtk_widget_get_screen (GtkWidget *widget)
9090 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9092 screen = gtk_widget_get_screen_unchecked (widget);
9099 g_warning (G_STRLOC ": Can't get associated screen"
9100 " for a widget unless it is inside a toplevel GtkWindow\n"
9101 " widget type is %s associated top level type is %s",
9102 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9103 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9105 return gdk_screen_get_default ();
9110 * gtk_widget_has_screen:
9111 * @widget: a #GtkWidget
9113 * Checks whether there is a #GdkScreen is associated with
9114 * this widget. All toplevel widgets have an associated
9115 * screen, and all widgets added into a hierarchy with a toplevel
9116 * window at the top.
9118 * Return value: %TRUE if there is a #GdkScreen associcated
9124 gtk_widget_has_screen (GtkWidget *widget)
9126 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9128 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9132 * gtk_widget_get_display:
9133 * @widget: a #GtkWidget
9135 * Get the #GdkDisplay for the toplevel window associated with
9136 * this widget. This function can only be called after the widget
9137 * has been added to a widget hierarchy with a #GtkWindow at the top.
9139 * In general, you should only create display specific
9140 * resources when a widget has been realized, and you should
9141 * free those resources when the widget is unrealized.
9143 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9148 gtk_widget_get_display (GtkWidget *widget)
9150 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9152 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9156 * gtk_widget_get_root_window:
9157 * @widget: a #GtkWidget
9159 * Get the root window where this widget is located. This function can
9160 * only be called after the widget has been added to a widget
9161 * hierarchy with #GtkWindow at the top.
9163 * The root window is useful for such purposes as creating a popup
9164 * #GdkWindow associated with the window. In general, you should only
9165 * create display specific resources when a widget has been realized,
9166 * and you should free those resources when the widget is unrealized.
9168 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9173 gtk_widget_get_root_window (GtkWidget *widget)
9175 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9177 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9181 * gtk_widget_child_focus:
9182 * @widget: a #GtkWidget
9183 * @direction: direction of focus movement
9185 * This function is used by custom widget implementations; if you're
9186 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9187 * to a particular widget, and gtk_container_set_focus_chain() to
9188 * change the focus tab order. So you may want to investigate those
9189 * functions instead.
9191 * gtk_widget_child_focus() is called by containers as the user moves
9192 * around the window using keyboard shortcuts. @direction indicates
9193 * what kind of motion is taking place (up, down, left, right, tab
9194 * forward, tab backward). gtk_widget_child_focus() emits the
9195 * #GtkWidget::focus signal; widgets override the default handler
9196 * for this signal in order to implement appropriate focus behavior.
9198 * The default ::focus handler for a widget should return %TRUE if
9199 * moving in @direction left the focus on a focusable location inside
9200 * that widget, and %FALSE if moving in @direction moved the focus
9201 * outside the widget. If returning %TRUE, widgets normally
9202 * call gtk_widget_grab_focus() to place the focus accordingly;
9203 * if returning %FALSE, they don't modify the current focus location.
9205 * Return value: %TRUE if focus ended up inside @widget
9208 gtk_widget_child_focus (GtkWidget *widget,
9209 GtkDirectionType direction)
9211 gboolean return_val;
9213 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9215 if (!gtk_widget_get_visible (widget) ||
9216 !gtk_widget_is_sensitive (widget))
9219 /* child widgets must set CAN_FOCUS, containers
9220 * don't have to though.
9222 if (!GTK_IS_CONTAINER (widget) &&
9223 !gtk_widget_get_can_focus (widget))
9226 g_signal_emit (widget,
9227 widget_signals[FOCUS],
9229 direction, &return_val);
9235 * gtk_widget_keynav_failed:
9236 * @widget: a #GtkWidget
9237 * @direction: direction of focus movement
9239 * This function should be called whenever keyboard navigation within
9240 * a single widget hits a boundary. The function emits the
9241 * #GtkWidget::keynav-failed signal on the widget and its return
9242 * value should be interpreted in a way similar to the return value of
9243 * gtk_widget_child_focus():
9245 * When %TRUE is returned, stay in the widget, the failed keyboard
9246 * navigation is Ok and/or there is nowhere we can/should move the
9249 * When %FALSE is returned, the caller should continue with keyboard
9250 * navigation outside the widget, e.g. by calling
9251 * gtk_widget_child_focus() on the widget's toplevel.
9253 * The default ::keynav-failed handler returns %TRUE for
9254 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9255 * values of #GtkDirectionType, it looks at the
9256 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9257 * if the setting is %TRUE. This way the entire user interface
9258 * becomes cursor-navigatable on input devices such as mobile phones
9259 * which only have cursor keys but no tab key.
9261 * Whenever the default handler returns %TRUE, it also calls
9262 * gtk_widget_error_bell() to notify the user of the failed keyboard
9265 * A use case for providing an own implementation of ::keynav-failed
9266 * (either by connecting to it or by overriding it) would be a row of
9267 * #GtkEntry widgets where the user should be able to navigate the
9268 * entire row with the cursor keys, as e.g. known from user interfaces
9269 * that require entering license keys.
9271 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9272 * if the emitting widget should try to handle the keyboard
9273 * navigation attempt in its parent container(s).
9278 gtk_widget_keynav_failed (GtkWidget *widget,
9279 GtkDirectionType direction)
9281 gboolean return_val;
9283 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9285 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9286 direction, &return_val);
9292 * gtk_widget_error_bell:
9293 * @widget: a #GtkWidget
9295 * Notifies the user about an input-related error on this widget.
9296 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9297 * gdk_window_beep(), otherwise it does nothing.
9299 * Note that the effect of gdk_window_beep() can be configured in many
9300 * ways, depending on the windowing backend and the desktop environment
9301 * or window manager that is used.
9306 gtk_widget_error_bell (GtkWidget *widget)
9308 GtkWidgetPrivate *priv;
9309 GtkSettings* settings;
9312 g_return_if_fail (GTK_IS_WIDGET (widget));
9314 priv = widget->priv;
9316 settings = gtk_widget_get_settings (widget);
9320 g_object_get (settings,
9321 "gtk-error-bell", &beep,
9324 if (beep && priv->window)
9325 gdk_window_beep (priv->window);
9329 gtk_widget_set_usize_internal (GtkWidget *widget,
9332 GtkQueueResizeFlags flags)
9334 GtkWidgetAuxInfo *aux_info;
9335 gboolean changed = FALSE;
9337 g_object_freeze_notify (G_OBJECT (widget));
9339 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9341 if (width > -2 && aux_info->width != width)
9343 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9344 g_object_notify (G_OBJECT (widget), "width-request");
9345 aux_info->width = width;
9348 if (height > -2 && aux_info->height != height)
9350 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9351 g_object_notify (G_OBJECT (widget), "height-request");
9352 aux_info->height = height;
9356 if (gtk_widget_get_visible (widget) && changed)
9358 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9359 gtk_widget_queue_resize (widget);
9361 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9364 g_object_thaw_notify (G_OBJECT (widget));
9368 * gtk_widget_set_size_request:
9369 * @widget: a #GtkWidget
9370 * @width: width @widget should request, or -1 to unset
9371 * @height: height @widget should request, or -1 to unset
9373 * Sets the minimum size of a widget; that is, the widget's size
9374 * request will be @width by @height. You can use this function to
9375 * force a widget to be either larger or smaller than it normally
9378 * In most cases, gtk_window_set_default_size() is a better choice for
9379 * toplevel windows than this function; setting the default size will
9380 * still allow users to shrink the window. Setting the size request
9381 * will force them to leave the window at least as large as the size
9382 * request. When dealing with window sizes,
9383 * gtk_window_set_geometry_hints() can be a useful function as well.
9385 * Note the inherent danger of setting any fixed size - themes,
9386 * translations into other languages, different fonts, and user action
9387 * can all change the appropriate size for a given widget. So, it's
9388 * basically impossible to hardcode a size that will always be
9391 * The size request of a widget is the smallest size a widget can
9392 * accept while still functioning well and drawing itself correctly.
9393 * However in some strange cases a widget may be allocated less than
9394 * its requested size, and in many cases a widget may be allocated more
9395 * space than it requested.
9397 * If the size request in a given direction is -1 (unset), then
9398 * the "natural" size request of the widget will be used instead.
9400 * Widgets can't actually be allocated a size less than 1 by 1, but
9401 * you can pass 0,0 to this function to mean "as small as possible."
9403 * The size request set here does not include any margin from the
9404 * #GtkWidget properties margin-left, margin-right, margin-top, and
9405 * margin-bottom, but it does include pretty much all other padding
9406 * or border properties set by any subclass of #GtkWidget.
9409 gtk_widget_set_size_request (GtkWidget *widget,
9413 g_return_if_fail (GTK_IS_WIDGET (widget));
9414 g_return_if_fail (width >= -1);
9415 g_return_if_fail (height >= -1);
9422 gtk_widget_set_usize_internal (widget, width, height, 0);
9427 * gtk_widget_get_size_request:
9428 * @widget: a #GtkWidget
9429 * @width: (out) (allow-none): return location for width, or %NULL
9430 * @height: (out) (allow-none): return location for height, or %NULL
9432 * Gets the size request that was explicitly set for the widget using
9433 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9434 * @height indicates that that dimension has not been set explicitly
9435 * and the natural requisition of the widget will be used intead. See
9436 * gtk_widget_set_size_request(). To get the size a widget will
9437 * actually request, call gtk_widget_get_preferred_size() instead of
9441 gtk_widget_get_size_request (GtkWidget *widget,
9445 const GtkWidgetAuxInfo *aux_info;
9447 g_return_if_fail (GTK_IS_WIDGET (widget));
9449 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9452 *width = aux_info->width;
9455 *height = aux_info->height;
9459 * _gtk_widget_override_size_request:
9460 * @widget: a #GtkWidget
9461 * @width: new forced minimum width
9462 * @height: new forced minimum height
9463 * @old_width: location to store previous forced minimum width
9464 * @old_width: location to store previous forced minumum height
9466 * Temporarily establishes a forced minimum size for a widget; this
9467 * is used by GtkWindow when calculating the size to add to the
9468 * window's geometry widget. Cached sizes for the widget and its
9469 * parents are invalidated, so that subsequent calls to the size
9470 * negotiation machinery produce the overriden result, but the
9471 * widget is not queued for relayout or redraw. The old size must
9472 * be restored with _gtk_widget_restore_size_request() or things
9476 _gtk_widget_override_size_request (GtkWidget *widget,
9482 gtk_widget_get_size_request (widget, old_width, old_height);
9483 gtk_widget_set_usize_internal (widget, width, height,
9484 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9488 * _gtk_widget_restore_size_request:
9489 * @widget: a #GtkWidget
9490 * @old_width: saved forced minimum size
9491 * @old_height: saved forced minimum size
9493 * Undoes the operation of_gtk_widget_override_size_request().
9496 _gtk_widget_restore_size_request (GtkWidget *widget,
9500 gtk_widget_set_usize_internal (widget, old_width, old_height,
9501 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9505 * gtk_widget_set_events:
9506 * @widget: a #GtkWidget
9507 * @events: event mask
9509 * Sets the event mask (see #GdkEventMask) for a widget. The event
9510 * mask determines which events a widget will receive. Keep in mind
9511 * that different widgets have different default event masks, and by
9512 * changing the event mask you may disrupt a widget's functionality,
9513 * so be careful. This function must be called while a widget is
9514 * unrealized. Consider gtk_widget_add_events() for widgets that are
9515 * already realized, or if you want to preserve the existing event
9516 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9517 * to get events on those widgets, place them inside a #GtkEventBox
9518 * and receive events on the event box.
9521 gtk_widget_set_events (GtkWidget *widget,
9524 g_return_if_fail (GTK_IS_WIDGET (widget));
9525 g_return_if_fail (!gtk_widget_get_realized (widget));
9527 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9528 GINT_TO_POINTER (events));
9529 g_object_notify (G_OBJECT (widget), "events");
9533 * gtk_widget_set_device_events:
9534 * @widget: a #GtkWidget
9535 * @device: a #GdkDevice
9536 * @events: event mask
9538 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9539 * mask determines which events a widget will receive from @device. Keep
9540 * in mind that different widgets have different default event masks, and by
9541 * changing the event mask you may disrupt a widget's functionality,
9542 * so be careful. This function must be called while a widget is
9543 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9544 * already realized, or if you want to preserve the existing event
9545 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9546 * to get events on those widgets, place them inside a #GtkEventBox
9547 * and receive events on the event box.
9552 gtk_widget_set_device_events (GtkWidget *widget,
9554 GdkEventMask events)
9556 GHashTable *device_events;
9558 g_return_if_fail (GTK_IS_WIDGET (widget));
9559 g_return_if_fail (GDK_IS_DEVICE (device));
9560 g_return_if_fail (!gtk_widget_get_realized (widget));
9562 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9564 if (G_UNLIKELY (!device_events))
9566 device_events = g_hash_table_new (NULL, NULL);
9567 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9568 (GDestroyNotify) g_hash_table_unref);
9571 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9575 gtk_widget_add_events_internal_list (GtkWidget *widget,
9582 for (l = window_list; l != NULL; l = l->next)
9584 GdkWindow *window = l->data;
9587 gdk_window_get_user_data (window, &user_data);
9588 if (user_data == widget)
9593 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9595 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9597 children = gdk_window_get_children (window);
9598 gtk_widget_add_events_internal_list (widget, device, events, children);
9599 g_list_free (children);
9605 gtk_widget_add_events_internal (GtkWidget *widget,
9609 GtkWidgetPrivate *priv = widget->priv;
9612 if (!gtk_widget_get_has_window (widget))
9613 window_list = gdk_window_get_children (priv->window);
9615 window_list = g_list_prepend (NULL, priv->window);
9617 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9619 g_list_free (window_list);
9623 * gtk_widget_add_events:
9624 * @widget: a #GtkWidget
9625 * @events: an event mask, see #GdkEventMask
9627 * Adds the events in the bitfield @events to the event mask for
9628 * @widget. See gtk_widget_set_events() for details.
9631 gtk_widget_add_events (GtkWidget *widget,
9636 g_return_if_fail (GTK_IS_WIDGET (widget));
9638 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9639 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9640 GINT_TO_POINTER (old_events | events));
9642 if (gtk_widget_get_realized (widget))
9643 gtk_widget_add_events_internal (widget, NULL, events);
9645 g_object_notify (G_OBJECT (widget), "events");
9649 * gtk_widget_add_device_events:
9650 * @widget: a #GtkWidget
9651 * @device: a #GdkDevice
9652 * @events: an event mask, see #GdkEventMask
9654 * Adds the device events in the bitfield @events to the event mask for
9655 * @widget. See gtk_widget_set_device_events() for details.
9660 gtk_widget_add_device_events (GtkWidget *widget,
9662 GdkEventMask events)
9664 GdkEventMask old_events;
9665 GHashTable *device_events;
9667 g_return_if_fail (GTK_IS_WIDGET (widget));
9668 g_return_if_fail (GDK_IS_DEVICE (device));
9670 old_events = gtk_widget_get_device_events (widget, device);
9672 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9674 if (G_UNLIKELY (!device_events))
9676 device_events = g_hash_table_new (NULL, NULL);
9677 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9678 (GDestroyNotify) g_hash_table_unref);
9681 g_hash_table_insert (device_events, device,
9682 GUINT_TO_POINTER (old_events | events));
9684 if (gtk_widget_get_realized (widget))
9685 gtk_widget_add_events_internal (widget, device, events);
9687 g_object_notify (G_OBJECT (widget), "events");
9691 * gtk_widget_get_toplevel:
9692 * @widget: a #GtkWidget
9694 * This function returns the topmost widget in the container hierarchy
9695 * @widget is a part of. If @widget has no parent widgets, it will be
9696 * returned as the topmost widget. No reference will be added to the
9697 * returned widget; it should not be unreferenced.
9699 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9700 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9702 * %NULL if @widget wasn't inside a toplevel window, and if the
9703 * window was inside a #GtkWindow-derived widget which was in turn
9704 * inside the toplevel #GtkWindow. While the second case may
9705 * seem unlikely, it actually happens when a #GtkPlug is embedded
9706 * inside a #GtkSocket within the same application.
9708 * To reliably find the toplevel #GtkWindow, use
9709 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9710 * is set on the result.
9712 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9713 * if (gtk_widget_is_toplevel (toplevel))
9715 * /* Perform action on toplevel. */
9719 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9720 * if there's no ancestor.
9723 gtk_widget_get_toplevel (GtkWidget *widget)
9725 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9727 while (widget->priv->parent)
9728 widget = widget->priv->parent;
9734 * gtk_widget_get_ancestor:
9735 * @widget: a #GtkWidget
9736 * @widget_type: ancestor type
9738 * Gets the first ancestor of @widget with type @widget_type. For example,
9739 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9740 * the first #GtkBox that's an ancestor of @widget. No reference will be
9741 * added to the returned widget; it should not be unreferenced. See note
9742 * about checking for a toplevel #GtkWindow in the docs for
9743 * gtk_widget_get_toplevel().
9745 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9746 * considers @widget to be an ancestor of itself.
9748 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9751 gtk_widget_get_ancestor (GtkWidget *widget,
9754 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9756 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9757 widget = widget->priv->parent;
9759 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9766 * gtk_widget_set_visual:
9767 * @widget: a #GtkWidget
9768 * @visual: visual to be used or %NULL to unset a previous one
9770 * Sets the visual that should be used for by widget and its children for
9771 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9772 * returned by gdk_widget_get_screen(), so handling the
9773 * #GtkWidget::screen-changed signal is necessary.
9775 * Setting a new @visual will not cause @widget to recreate its windows,
9776 * so you should call this function before @widget is realized.
9779 gtk_widget_set_visual (GtkWidget *widget,
9782 g_return_if_fail (GTK_IS_WIDGET (widget));
9783 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9786 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9789 g_object_set_qdata_full (G_OBJECT (widget),
9791 g_object_ref (visual),
9796 * gtk_widget_get_visual:
9797 * @widget: a #GtkWidget
9799 * Gets the visual that will be used to render @widget.
9801 * Return value: (transfer none): the visual for @widget
9804 gtk_widget_get_visual (GtkWidget *widget)
9810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9812 if (gtk_widget_get_has_window (widget) &&
9813 widget->priv->window)
9814 return gdk_window_get_visual (widget->priv->window);
9816 screen = gtk_widget_get_screen (widget);
9818 for (w = widget; w != NULL; w = w->priv->parent)
9820 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9823 if (gdk_visual_get_screen (visual) == screen)
9826 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9827 gtk_widget_get_name (widget));
9831 return gdk_screen_get_system_visual (screen);
9835 * gtk_widget_get_settings:
9836 * @widget: a #GtkWidget
9838 * Gets the settings object holding the settings (global property
9839 * settings, RC file information, etc) used for this widget.
9841 * Note that this function can only be called when the #GtkWidget
9842 * is attached to a toplevel, since the settings object is specific
9843 * to a particular #GdkScreen.
9845 * Return value: (transfer none): the relevant #GtkSettings object
9848 gtk_widget_get_settings (GtkWidget *widget)
9850 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9852 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9856 * gtk_widget_get_events:
9857 * @widget: a #GtkWidget
9859 * Returns the event mask for the widget (a bitfield containing flags
9860 * from the #GdkEventMask enumeration). These are the events that the widget
9863 * Return value: event mask for @widget
9866 gtk_widget_get_events (GtkWidget *widget)
9868 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9870 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9874 * gtk_widget_get_device_events:
9875 * @widget: a #GtkWidget
9876 * @device: a #GdkDevice
9878 * Returns the events mask for the widget corresponding to an specific device. These
9879 * are the events that the widget will receive when @device operates on it.
9881 * Returns: device event mask for @widget
9886 gtk_widget_get_device_events (GtkWidget *widget,
9889 GHashTable *device_events;
9891 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9892 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9894 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9899 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9903 * gtk_widget_get_pointer:
9904 * @widget: a #GtkWidget
9905 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9906 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9908 * Obtains the location of the mouse pointer in widget coordinates.
9909 * Widget coordinates are a bit odd; for historical reasons, they are
9910 * defined as @widget->window coordinates for widgets that are not
9911 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9912 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9915 gtk_widget_get_pointer (GtkWidget *widget,
9919 GtkWidgetPrivate *priv;
9921 g_return_if_fail (GTK_IS_WIDGET (widget));
9923 priv = widget->priv;
9930 if (gtk_widget_get_realized (widget))
9932 gdk_window_get_pointer (priv->window, x, y, NULL);
9934 if (!gtk_widget_get_has_window (widget))
9937 *x -= priv->allocation.x;
9939 *y -= priv->allocation.y;
9945 * gtk_widget_is_ancestor:
9946 * @widget: a #GtkWidget
9947 * @ancestor: another #GtkWidget
9949 * Determines whether @widget is somewhere inside @ancestor, possibly with
9950 * intermediate containers.
9952 * Return value: %TRUE if @ancestor contains @widget as a child,
9953 * grandchild, great grandchild, etc.
9956 gtk_widget_is_ancestor (GtkWidget *widget,
9957 GtkWidget *ancestor)
9959 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9960 g_return_val_if_fail (ancestor != NULL, FALSE);
9964 if (widget->priv->parent == ancestor)
9966 widget = widget->priv->parent;
9972 static GQuark quark_composite_name = 0;
9975 * gtk_widget_set_composite_name:
9976 * @widget: a #GtkWidget.
9977 * @name: the name to set
9979 * Sets a widgets composite name. The widget must be
9980 * a composite child of its parent; see gtk_widget_push_composite_child().
9983 gtk_widget_set_composite_name (GtkWidget *widget,
9986 g_return_if_fail (GTK_IS_WIDGET (widget));
9987 g_return_if_fail (widget->priv->composite_child);
9988 g_return_if_fail (name != NULL);
9990 if (!quark_composite_name)
9991 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9993 g_object_set_qdata_full (G_OBJECT (widget),
9994 quark_composite_name,
10000 * gtk_widget_get_composite_name:
10001 * @widget: a #GtkWidget
10003 * Obtains the composite name of a widget.
10005 * Returns: the composite name of @widget, or %NULL if @widget is not
10006 * a composite child. The string should be freed when it is no
10010 gtk_widget_get_composite_name (GtkWidget *widget)
10012 GtkWidgetPrivate *priv;
10014 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10016 priv = widget->priv;
10018 if (widget->priv->composite_child && priv->parent)
10019 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10026 * gtk_widget_push_composite_child:
10028 * Makes all newly-created widgets as composite children until
10029 * the corresponding gtk_widget_pop_composite_child() call.
10031 * A composite child is a child that's an implementation detail of the
10032 * container it's inside and should not be visible to people using the
10033 * container. Composite children aren't treated differently by GTK (but
10034 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10035 * builders might want to treat them in a different way.
10037 * Here is a simple example:
10039 * gtk_widget_push_composite_child ();
10040 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10041 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10042 * gtk_widget_pop_composite_child ();
10043 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10044 * GTK_WIDGET (scrolled_window));
10045 * g_object_ref (scrolled_window->hscrollbar);
10049 gtk_widget_push_composite_child (void)
10051 composite_child_stack++;
10055 * gtk_widget_pop_composite_child:
10057 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10060 gtk_widget_pop_composite_child (void)
10062 if (composite_child_stack)
10063 composite_child_stack--;
10067 gtk_widget_emit_direction_changed (GtkWidget *widget,
10068 GtkTextDirection old_dir)
10070 gtk_widget_update_pango_context (widget);
10072 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10076 * gtk_widget_set_direction:
10077 * @widget: a #GtkWidget
10078 * @dir: the new direction
10080 * Sets the reading direction on a particular widget. This direction
10081 * controls the primary direction for widgets containing text,
10082 * and also the direction in which the children of a container are
10083 * packed. The ability to set the direction is present in order
10084 * so that correct localization into languages with right-to-left
10085 * reading directions can be done. Generally, applications will
10086 * let the default reading direction present, except for containers
10087 * where the containers are arranged in an order that is explicitely
10088 * visual rather than logical (such as buttons for text justification).
10090 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10091 * set by gtk_widget_set_default_direction() will be used.
10094 gtk_widget_set_direction (GtkWidget *widget,
10095 GtkTextDirection dir)
10097 GtkTextDirection old_dir;
10099 g_return_if_fail (GTK_IS_WIDGET (widget));
10100 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10102 old_dir = gtk_widget_get_direction (widget);
10104 widget->priv->direction = dir;
10106 if (old_dir != gtk_widget_get_direction (widget))
10108 if (widget->priv->context)
10109 gtk_style_context_set_direction (widget->priv->context,
10110 gtk_widget_get_direction (widget));
10112 gtk_widget_emit_direction_changed (widget, old_dir);
10117 * gtk_widget_get_direction:
10118 * @widget: a #GtkWidget
10120 * Gets the reading direction for a particular widget. See
10121 * gtk_widget_set_direction().
10123 * Return value: the reading direction for the widget.
10126 gtk_widget_get_direction (GtkWidget *widget)
10128 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10130 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10131 return gtk_default_direction;
10133 return widget->priv->direction;
10137 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10139 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10141 g_object_ref (widget);
10143 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10144 gtk_widget_emit_direction_changed (widget, old_dir);
10146 if (GTK_IS_CONTAINER (widget))
10147 gtk_container_forall (GTK_CONTAINER (widget),
10148 gtk_widget_set_default_direction_recurse,
10151 g_object_unref (widget);
10155 * gtk_widget_set_default_direction:
10156 * @dir: the new default direction. This cannot be
10157 * %GTK_TEXT_DIR_NONE.
10159 * Sets the default reading direction for widgets where the
10160 * direction has not been explicitly set by gtk_widget_set_direction().
10163 gtk_widget_set_default_direction (GtkTextDirection dir)
10165 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10167 if (dir != gtk_default_direction)
10169 GList *toplevels, *tmp_list;
10170 GtkTextDirection old_dir = gtk_default_direction;
10172 gtk_default_direction = dir;
10174 tmp_list = toplevels = gtk_window_list_toplevels ();
10175 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10179 gtk_widget_set_default_direction_recurse (tmp_list->data,
10180 GUINT_TO_POINTER (old_dir));
10181 g_object_unref (tmp_list->data);
10182 tmp_list = tmp_list->next;
10185 g_list_free (toplevels);
10190 * gtk_widget_get_default_direction:
10192 * Obtains the current default reading direction. See
10193 * gtk_widget_set_default_direction().
10195 * Return value: the current default direction.
10198 gtk_widget_get_default_direction (void)
10200 return gtk_default_direction;
10204 gtk_widget_dispose (GObject *object)
10206 GtkWidget *widget = GTK_WIDGET (object);
10207 GtkWidgetPrivate *priv = widget->priv;
10210 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10211 else if (gtk_widget_get_visible (widget))
10212 gtk_widget_hide (widget);
10214 priv->visible = FALSE;
10215 if (gtk_widget_get_realized (widget))
10216 gtk_widget_unrealize (widget);
10218 if (!priv->in_destruction)
10220 priv->in_destruction = TRUE;
10221 g_signal_emit (object, widget_signals[DESTROY], 0);
10222 priv->in_destruction = FALSE;
10225 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10229 gtk_widget_real_destroy (GtkWidget *object)
10231 /* gtk_object_destroy() will already hold a refcount on object */
10232 GtkWidget *widget = GTK_WIDGET (object);
10233 GtkWidgetPrivate *priv = widget->priv;
10235 /* wipe accelerator closures (keep order) */
10236 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10237 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10239 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10240 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10242 gtk_grab_remove (widget);
10244 g_object_unref (priv->style);
10245 priv->style = gtk_widget_get_default_style ();
10246 g_object_ref (priv->style);
10250 gtk_widget_finalize (GObject *object)
10252 GtkWidget *widget = GTK_WIDGET (object);
10253 GtkWidgetPrivate *priv = widget->priv;
10254 GtkWidgetAuxInfo *aux_info;
10255 GtkAccessible *accessible;
10257 gtk_grab_remove (widget);
10259 g_object_unref (priv->style);
10260 priv->style = NULL;
10262 g_free (priv->name);
10264 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10266 gtk_widget_aux_info_destroy (aux_info);
10268 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10270 g_object_unref (accessible);
10273 gtk_widget_path_free (priv->path);
10276 g_object_unref (priv->context);
10278 if (g_object_is_floating (object))
10279 g_warning ("A floating object was finalized. This means that someone\n"
10280 "called g_object_unref() on an object that had only a floating\n"
10281 "reference; the initial floating reference is not owned by anyone\n"
10282 "and must be removed with g_object_ref_sink().");
10284 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10287 /*****************************************
10288 * gtk_widget_real_map:
10293 *****************************************/
10296 gtk_widget_real_map (GtkWidget *widget)
10298 GtkWidgetPrivate *priv = widget->priv;
10300 g_assert (gtk_widget_get_realized (widget));
10302 if (!gtk_widget_get_mapped (widget))
10304 gtk_widget_set_mapped (widget, TRUE);
10306 if (gtk_widget_get_has_window (widget))
10307 gdk_window_show (priv->window);
10311 /*****************************************
10312 * gtk_widget_real_unmap:
10317 *****************************************/
10320 gtk_widget_real_unmap (GtkWidget *widget)
10322 GtkWidgetPrivate *priv = widget->priv;
10324 if (gtk_widget_get_mapped (widget))
10326 gtk_widget_set_mapped (widget, FALSE);
10328 if (gtk_widget_get_has_window (widget))
10329 gdk_window_hide (priv->window);
10333 /*****************************************
10334 * gtk_widget_real_realize:
10339 *****************************************/
10342 gtk_widget_real_realize (GtkWidget *widget)
10344 GtkWidgetPrivate *priv = widget->priv;
10346 g_assert (!gtk_widget_get_has_window (widget));
10348 gtk_widget_set_realized (widget, TRUE);
10351 priv->window = gtk_widget_get_parent_window (widget);
10352 g_object_ref (priv->window);
10354 priv->style = gtk_style_attach (priv->style, priv->window);
10357 /*****************************************
10358 * gtk_widget_real_unrealize:
10363 *****************************************/
10366 gtk_widget_real_unrealize (GtkWidget *widget)
10368 GtkWidgetPrivate *priv = widget->priv;
10370 if (gtk_widget_get_mapped (widget))
10371 gtk_widget_real_unmap (widget);
10373 gtk_widget_set_mapped (widget, FALSE);
10375 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10378 /* We must do unrealize child widget BEFORE container widget.
10379 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10380 * So, unrealizing container widget bofore its children causes the problem
10381 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10384 if (GTK_IS_CONTAINER (widget))
10385 gtk_container_forall (GTK_CONTAINER (widget),
10386 (GtkCallback) gtk_widget_unrealize,
10389 gtk_style_detach (priv->style);
10390 if (gtk_widget_get_has_window (widget))
10392 gdk_window_set_user_data (priv->window, NULL);
10393 gdk_window_destroy (priv->window);
10394 priv->window = NULL;
10398 g_object_unref (priv->window);
10399 priv->window = NULL;
10402 gtk_selection_remove_all (widget);
10404 gtk_widget_set_realized (widget, FALSE);
10408 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10409 GtkOrientation orientation,
10410 gint *minimum_size,
10411 gint *natural_size)
10413 const GtkWidgetAuxInfo *aux_info;
10415 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10417 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10418 aux_info->width > 0)
10420 *minimum_size = MAX (*minimum_size, aux_info->width);
10422 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10423 aux_info->height > 0)
10425 *minimum_size = MAX (*minimum_size, aux_info->height);
10428 /* Fix it if set_size_request made natural size smaller than min size.
10429 * This would also silently fix broken widgets, but we warn about them
10430 * in gtksizerequest.c when calling their size request vfuncs.
10432 *natural_size = MAX (*natural_size, *minimum_size);
10434 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10436 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10437 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10441 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10442 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10447 * _gtk_widget_peek_request_cache:
10449 * Returns the address of the widget's request cache (strictly for
10450 * internal use in gtksizerequest.c)
10452 * Return value: the address of @widget's size request cache.
10455 _gtk_widget_peek_request_cache (GtkWidget *widget)
10457 /* Don't bother slowing things down with the return_if_fail guards here */
10458 return &widget->priv->requests;
10462 * _gtk_widget_set_device_window:
10463 * @widget: a #GtkWidget.
10464 * @device: a #GdkDevice.
10465 * @window: the new device window.
10467 * Sets pointer window for @widget and @device. Does not ref @window.
10468 * Actually stores it on the #GdkScreen, but you don't need to know that.
10471 _gtk_widget_set_device_window (GtkWidget *widget,
10475 GtkWidgetPrivate *priv;
10477 GHashTable *device_window;
10479 g_return_if_fail (GTK_IS_WIDGET (widget));
10480 g_return_if_fail (GDK_IS_DEVICE (device));
10481 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10483 priv = widget->priv;
10485 if (!gtk_widget_get_realized (widget))
10488 screen = gdk_window_get_screen (priv->window);
10489 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10491 if (G_UNLIKELY (!device_window))
10493 device_window = g_hash_table_new (NULL, NULL);
10494 g_object_set_qdata_full (G_OBJECT (screen),
10495 quark_pointer_window,
10497 (GDestroyNotify) g_hash_table_destroy);
10501 g_hash_table_insert (device_window, device, window);
10503 g_hash_table_remove (device_window, device);
10507 * _gtk_widget_get_device_window:
10508 * @widget: a #GtkWidget.
10509 * @device: a #GdkDevice.
10511 * Return value: the device window set on the #GdkScreen @widget is attached
10515 _gtk_widget_get_device_window (GtkWidget *widget,
10518 GtkWidgetPrivate *priv;
10520 GHashTable *device_window;
10524 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10525 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10527 priv = widget->priv;
10529 if (!gtk_widget_get_realized (widget))
10532 screen = gdk_window_get_screen (priv->window);
10533 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10535 if (G_UNLIKELY (!device_window))
10538 window = g_hash_table_lookup (device_window, device);
10543 gdk_window_get_user_data (window, (gpointer *) &w);
10552 * _gtk_widget_list_devices:
10553 * @widget: a #GtkWidget.
10555 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10556 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10560 _gtk_widget_list_devices (GtkWidget *widget)
10562 GtkWidgetPrivate *priv;
10564 GHashTableIter iter;
10565 GHashTable *device_window;
10566 GList *devices = NULL;
10567 gpointer key, value;
10569 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10571 priv = widget->priv;
10573 if (!gtk_widget_get_realized (widget))
10576 screen = gdk_window_get_screen (priv->window);
10577 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10579 if (G_UNLIKELY (!device_window))
10582 g_hash_table_iter_init (&iter, device_window);
10584 while (g_hash_table_iter_next (&iter, &key, &value))
10586 GdkDevice *device = key;
10587 GdkWindow *window = value;
10592 gdk_window_get_user_data (window, (gpointer *) &w);
10595 devices = g_list_prepend (devices, device);
10603 synth_crossing (GtkWidget *widget,
10607 GdkCrossingMode mode,
10608 GdkNotifyType detail)
10612 event = gdk_event_new (type);
10614 event->crossing.window = g_object_ref (window);
10615 event->crossing.send_event = TRUE;
10616 event->crossing.subwindow = g_object_ref (window);
10617 event->crossing.time = GDK_CURRENT_TIME;
10618 event->crossing.x = event->crossing.y = 0;
10619 event->crossing.x_root = event->crossing.y_root = 0;
10620 event->crossing.mode = mode;
10621 event->crossing.detail = detail;
10622 event->crossing.focus = FALSE;
10623 event->crossing.state = 0;
10624 gdk_event_set_device (event, device);
10627 widget = gtk_get_event_widget (event);
10630 gtk_widget_event_internal (widget, event);
10632 gdk_event_free (event);
10636 * _gtk_widget_synthesize_crossing:
10637 * @from: the #GtkWidget the virtual pointer is leaving.
10638 * @to: the #GtkWidget the virtual pointer is moving to.
10639 * @mode: the #GdkCrossingMode to place on the synthesized events.
10641 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10643 * The real pointer window is the window that most recently received an enter notify
10644 * event. Windows that don't select for crossing events can't become the real
10645 * poiner window. The real pointer widget that owns the real pointer window. The
10646 * effective pointer window is the same as the real pointer window unless the real
10647 * pointer widget is either insensitive or there is a grab on a widget that is not
10648 * an ancestor of the real pointer widget (in which case the effective pointer
10649 * window should be the root window).
10651 * When the effective pointer window is the same as the real poiner window, we
10652 * receive crossing events from the windowing system. When the effective pointer
10653 * window changes to become different from the real pointer window we synthesize
10654 * crossing events, attempting to follow X protocol rules:
10656 * When the root window becomes the effective pointer window:
10657 * - leave notify on real pointer window, detail Ancestor
10658 * - leave notify on all of its ancestors, detail Virtual
10659 * - enter notify on root window, detail Inferior
10661 * When the root window ceases to be the effective pointer window:
10662 * - leave notify on root window, detail Inferior
10663 * - enter notify on all ancestors of real pointer window, detail Virtual
10664 * - enter notify on real pointer window, detail Ancestor
10667 _gtk_widget_synthesize_crossing (GtkWidget *from,
10670 GdkCrossingMode mode)
10672 GdkWindow *from_window = NULL, *to_window = NULL;
10674 g_return_if_fail (from != NULL || to != NULL);
10678 from_window = _gtk_widget_get_device_window (from, device);
10681 from_window = from->priv->window;
10686 to_window = _gtk_widget_get_device_window (to, device);
10689 to_window = to->priv->window;
10692 if (from_window == NULL && to_window == NULL)
10694 else if (from_window != NULL && to_window == NULL)
10696 GList *from_ancestors = NULL, *list;
10697 GdkWindow *from_ancestor = from_window;
10699 while (from_ancestor != NULL)
10701 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10702 if (from_ancestor == NULL)
10704 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10707 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10708 device, mode, GDK_NOTIFY_ANCESTOR);
10709 for (list = g_list_last (from_ancestors); list; list = list->prev)
10711 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10712 device, mode, GDK_NOTIFY_VIRTUAL);
10715 /* XXX: enter/inferior on root window? */
10717 g_list_free (from_ancestors);
10719 else if (from_window == NULL && to_window != NULL)
10721 GList *to_ancestors = NULL, *list;
10722 GdkWindow *to_ancestor = to_window;
10724 while (to_ancestor != NULL)
10726 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10727 if (to_ancestor == NULL)
10729 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10732 /* XXX: leave/inferior on root window? */
10734 for (list = to_ancestors; list; list = list->next)
10736 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10737 device, mode, GDK_NOTIFY_VIRTUAL);
10739 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10740 device, mode, GDK_NOTIFY_ANCESTOR);
10742 g_list_free (to_ancestors);
10744 else if (from_window == to_window)
10748 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10749 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10751 while (from_ancestor != NULL || to_ancestor != NULL)
10753 if (from_ancestor != NULL)
10755 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10756 if (from_ancestor == to_window)
10759 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10761 if (to_ancestor != NULL)
10763 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10764 if (to_ancestor == from_window)
10767 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10770 if (to_ancestor == from_window)
10772 if (mode != GDK_CROSSING_GTK_UNGRAB)
10773 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10774 device, mode, GDK_NOTIFY_INFERIOR);
10775 for (list = to_ancestors; list; list = list->next)
10776 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10777 device, mode, GDK_NOTIFY_VIRTUAL);
10778 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10779 device, mode, GDK_NOTIFY_ANCESTOR);
10781 else if (from_ancestor == to_window)
10783 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10784 device, mode, GDK_NOTIFY_ANCESTOR);
10785 for (list = g_list_last (from_ancestors); list; list = list->prev)
10787 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10788 device, mode, GDK_NOTIFY_VIRTUAL);
10790 if (mode != GDK_CROSSING_GTK_GRAB)
10791 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10792 device, mode, GDK_NOTIFY_INFERIOR);
10796 while (from_ancestors != NULL && to_ancestors != NULL
10797 && from_ancestors->data == to_ancestors->data)
10799 from_ancestors = g_list_delete_link (from_ancestors,
10801 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10804 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10805 device, mode, GDK_NOTIFY_NONLINEAR);
10807 for (list = g_list_last (from_ancestors); list; list = list->prev)
10809 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10810 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10812 for (list = to_ancestors; list; list = list->next)
10814 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10815 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10817 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10818 device, mode, GDK_NOTIFY_NONLINEAR);
10820 g_list_free (from_ancestors);
10821 g_list_free (to_ancestors);
10826 gtk_widget_propagate_state (GtkWidget *widget,
10827 GtkStateData *data)
10829 GtkWidgetPrivate *priv = widget->priv;
10830 GtkStateFlags new_flags, old_flags = priv->state_flags;
10831 GtkStateType old_state;
10833 old_state = gtk_widget_get_state (widget);
10835 if (!priv->parent_sensitive)
10836 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10838 priv->parent_sensitive = data->parent_sensitive;
10840 switch (data->operation)
10842 case STATE_CHANGE_REPLACE:
10843 priv->state_flags = data->flags;
10845 case STATE_CHANGE_SET:
10846 priv->state_flags |= data->flags;
10848 case STATE_CHANGE_UNSET:
10849 priv->state_flags &= ~(data->flags);
10853 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10857 window = gtk_widget_get_toplevel (widget);
10859 if (window && gtk_widget_is_toplevel (window))
10860 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10863 new_flags = gtk_widget_get_state_flags (widget);
10865 if (old_flags != new_flags)
10867 g_object_ref (widget);
10869 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10870 gtk_grab_remove (widget);
10872 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10873 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10875 if (!priv->shadowed)
10877 GList *event_windows = NULL;
10878 GList *devices, *d;
10880 devices = _gtk_widget_list_devices (widget);
10882 for (d = devices; d; d = d->next)
10888 window = _gtk_widget_get_device_window (widget, device);
10890 /* Do not propagate more than once to the
10891 * same window if non-multidevice aware.
10893 if (!gdk_window_get_support_multidevice (window) &&
10894 g_list_find (event_windows, window))
10897 if (!gtk_widget_is_sensitive (widget))
10898 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10899 GDK_CROSSING_STATE_CHANGED);
10900 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
10901 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10902 GDK_CROSSING_STATE_CHANGED);
10904 event_windows = g_list_prepend (event_windows, window);
10907 g_list_free (event_windows);
10908 g_list_free (devices);
10911 if (GTK_IS_CONTAINER (widget))
10913 data->parent_sensitive = gtk_widget_is_sensitive (widget);
10915 /* Do not propagate insensitive state further */
10916 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
10918 if (data->use_forall)
10919 gtk_container_forall (GTK_CONTAINER (widget),
10920 (GtkCallback) gtk_widget_propagate_state,
10923 gtk_container_foreach (GTK_CONTAINER (widget),
10924 (GtkCallback) gtk_widget_propagate_state,
10928 /* Trigger state change transitions for the widget */
10929 if (priv->context &&
10930 gtk_widget_get_mapped (widget))
10932 gint diff, flag = 1;
10935 diff = old_flags ^ new_flags;
10936 window = gtk_widget_get_window (widget);
10940 if ((diff & flag) != 0)
10944 target = ((new_flags & flag) != 0);
10945 _gtk_widget_notify_state_change (widget, flag, target);
10954 g_object_unref (widget);
10958 static const GtkWidgetAuxInfo default_aux_info = {
10966 * _gtk_widget_get_aux_info:
10967 * @widget: a #GtkWidget
10968 * @create: if %TRUE, create the structure if it doesn't exist
10970 * Get the #GtkWidgetAuxInfo structure for the widget.
10972 * Return value: the #GtkAuxInfo structure for the widget, or
10973 * %NULL if @create is %FALSE and one doesn't already exist.
10976 _gtk_widget_get_aux_info (GtkWidget *widget,
10979 GtkWidgetAuxInfo *aux_info;
10981 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10982 if (!aux_info && create)
10984 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10986 *aux_info = default_aux_info;
10988 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10994 static const GtkWidgetAuxInfo*
10995 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10997 GtkWidgetAuxInfo *aux_info;
10999 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11000 if (aux_info == NULL)
11002 return &default_aux_info;
11010 /*****************************************
11011 * gtk_widget_aux_info_destroy:
11016 *****************************************/
11019 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11021 g_slice_free (GtkWidgetAuxInfo, aux_info);
11025 * gtk_widget_shape_combine_region:
11026 * @widget: a #GtkWidget
11027 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11029 * Sets a shape for this widget's GDK window. This allows for
11030 * transparent windows etc., see gdk_window_shape_combine_region()
11031 * for more information.
11036 gtk_widget_shape_combine_region (GtkWidget *widget,
11037 cairo_region_t *region)
11039 GtkWidgetPrivate *priv;
11041 g_return_if_fail (GTK_IS_WIDGET (widget));
11042 /* set_shape doesn't work on widgets without gdk window */
11043 g_return_if_fail (gtk_widget_get_has_window (widget));
11045 priv = widget->priv;
11047 if (region == NULL)
11049 priv->has_shape_mask = FALSE;
11052 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11054 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11058 priv->has_shape_mask = TRUE;
11060 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11061 cairo_region_copy (region),
11062 (GDestroyNotify) cairo_region_destroy);
11064 /* set shape if widget has a gdk window already.
11065 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11068 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11073 * gtk_widget_input_shape_combine_region:
11074 * @widget: a #GtkWidget
11075 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11077 * Sets an input shape for this widget's GDK window. This allows for
11078 * windows which react to mouse click in a nonrectangular region, see
11079 * gdk_window_input_shape_combine_region() for more information.
11084 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11085 cairo_region_t *region)
11087 GtkWidgetPrivate *priv;
11089 g_return_if_fail (GTK_IS_WIDGET (widget));
11090 /* set_shape doesn't work on widgets without gdk window */
11091 g_return_if_fail (gtk_widget_get_has_window (widget));
11093 priv = widget->priv;
11095 if (region == NULL)
11098 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11100 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11104 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11105 cairo_region_copy (region),
11106 (GDestroyNotify) cairo_region_destroy);
11108 /* set shape if widget has a gdk window already.
11109 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11112 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11117 /* style properties
11121 * gtk_widget_class_install_style_property_parser:
11122 * @klass: a #GtkWidgetClass
11123 * @pspec: the #GParamSpec for the style property
11124 * @parser: the parser for the style property
11126 * Installs a style property on a widget class.
11129 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11131 GtkRcPropertyParser parser)
11133 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11134 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11135 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11136 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11138 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11140 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11141 G_OBJECT_CLASS_NAME (klass),
11146 g_param_spec_ref_sink (pspec);
11147 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11148 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11152 * gtk_widget_class_install_style_property:
11153 * @klass: a #GtkWidgetClass
11154 * @pspec: the #GParamSpec for the property
11156 * Installs a style property on a widget class. The parser for the
11157 * style property is determined by the value type of @pspec.
11160 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11163 GtkRcPropertyParser parser;
11165 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11166 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11168 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11170 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11174 * gtk_widget_class_find_style_property:
11175 * @klass: a #GtkWidgetClass
11176 * @property_name: the name of the style property to find
11177 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11178 * style property with that name.
11180 * Finds a style property of a widget class by name.
11185 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11186 const gchar *property_name)
11188 g_return_val_if_fail (property_name != NULL, NULL);
11190 return g_param_spec_pool_lookup (style_property_spec_pool,
11192 G_OBJECT_CLASS_TYPE (klass),
11197 * gtk_widget_class_list_style_properties:
11198 * @klass: a #GtkWidgetClass
11199 * @n_properties: location to return the number of style properties found
11200 * @returns: an newly allocated array of #GParamSpec*. The array must
11201 * be freed with g_free().
11203 * Returns all style properties of a widget class.
11208 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11209 guint *n_properties)
11211 GParamSpec **pspecs;
11214 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11215 G_OBJECT_CLASS_TYPE (klass),
11224 * gtk_widget_style_get_property:
11225 * @widget: a #GtkWidget
11226 * @property_name: the name of a style property
11227 * @value: location to return the property value
11229 * Gets the value of a style property of @widget.
11232 gtk_widget_style_get_property (GtkWidget *widget,
11233 const gchar *property_name,
11238 g_return_if_fail (GTK_IS_WIDGET (widget));
11239 g_return_if_fail (property_name != NULL);
11240 g_return_if_fail (G_IS_VALUE (value));
11242 g_object_ref (widget);
11243 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11245 G_OBJECT_TYPE (widget),
11248 g_warning ("%s: widget class `%s' has no property named `%s'",
11250 G_OBJECT_TYPE_NAME (widget),
11254 GtkStyleContext *context;
11255 const GValue *peek_value;
11256 GtkStateFlags state;
11258 context = gtk_widget_get_style_context (widget);
11259 state = gtk_widget_get_state_flags (widget);
11261 peek_value = _gtk_style_context_peek_style_property (context,
11262 G_OBJECT_TYPE (widget),
11265 /* auto-conversion of the caller's value type
11267 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11268 g_value_copy (peek_value, value);
11269 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11270 g_value_transform (peek_value, value);
11272 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11274 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11275 G_VALUE_TYPE_NAME (value));
11277 g_object_unref (widget);
11281 * gtk_widget_style_get_valist:
11282 * @widget: a #GtkWidget
11283 * @first_property_name: the name of the first property to get
11284 * @var_args: a <type>va_list</type> of pairs of property names and
11285 * locations to return the property values, starting with the location
11286 * for @first_property_name.
11288 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11292 gtk_widget_style_get_valist (GtkWidget *widget,
11293 const gchar *first_property_name,
11296 GtkStyleContext *context;
11297 GtkStateFlags state;
11300 g_return_if_fail (GTK_IS_WIDGET (widget));
11302 g_object_ref (widget);
11303 context = gtk_widget_get_style_context (widget);
11304 state = gtk_widget_get_state_flags (widget);
11306 name = first_property_name;
11309 const GValue *peek_value;
11313 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11315 G_OBJECT_TYPE (widget),
11319 g_warning ("%s: widget class `%s' has no property named `%s'",
11321 G_OBJECT_TYPE_NAME (widget),
11325 /* style pspecs are always readable so we can spare that check here */
11327 peek_value = _gtk_style_context_peek_style_property (context,
11328 G_OBJECT_TYPE (widget),
11331 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11334 g_warning ("%s: %s", G_STRLOC, error);
11339 name = va_arg (var_args, gchar*);
11342 g_object_unref (widget);
11346 * gtk_widget_style_get:
11347 * @widget: a #GtkWidget
11348 * @first_property_name: the name of the first property to get
11349 * @Varargs: pairs of property names and locations to
11350 * return the property values, starting with the location for
11351 * @first_property_name, terminated by %NULL.
11353 * Gets the values of a multiple style properties of @widget.
11356 gtk_widget_style_get (GtkWidget *widget,
11357 const gchar *first_property_name,
11362 g_return_if_fail (GTK_IS_WIDGET (widget));
11364 va_start (var_args, first_property_name);
11365 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11371 * @widget: a #GtkWidget
11372 * @path_length: (out) (allow-none): location to store length of the path,
11374 * @path: (out) (allow-none): location to store allocated path string,
11376 * @path_reversed: (out) (allow-none): location to store allocated reverse
11377 * path string, or %NULL
11379 * Obtains the full path to @widget. The path is simply the name of a
11380 * widget and all its parents in the container hierarchy, separated by
11381 * periods. The name of a widget comes from
11382 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11383 * in gtkrc configuration files. Widget names are the type of the
11384 * widget by default (e.g. "GtkButton") or can be set to an
11385 * application-specific value with gtk_widget_set_name(). By setting
11386 * the name of a widget, you allow users or theme authors to apply
11387 * styles to that specific widget in their gtkrc
11388 * file. @path_reversed_p fills in the path in reverse order,
11389 * i.e. starting with @widget's name instead of starting with the name
11390 * of @widget's outermost ancestor.
11392 * Deprecated:3.0: Use gtk_widget_get_path() instead
11395 gtk_widget_path (GtkWidget *widget,
11396 guint *path_length,
11398 gchar **path_reversed)
11400 static gchar *rev_path = NULL;
11401 static guint tmp_path_len = 0;
11404 g_return_if_fail (GTK_IS_WIDGET (widget));
11409 const gchar *string;
11414 string = gtk_widget_get_name (widget);
11415 l = strlen (string);
11416 while (tmp_path_len <= len + l + 1)
11418 tmp_path_len += INIT_PATH_SIZE;
11419 rev_path = g_realloc (rev_path, tmp_path_len);
11421 s = string + l - 1;
11422 d = rev_path + len;
11423 while (s >= string)
11427 widget = widget->priv->parent;
11430 rev_path[len++] = '.';
11432 rev_path[len++] = 0;
11437 *path_length = len - 1;
11439 *path_reversed = g_strdup (rev_path);
11442 *path = g_strdup (rev_path);
11443 g_strreverse (*path);
11448 * gtk_widget_class_path:
11449 * @widget: a #GtkWidget
11450 * @path_length: (out) (allow-none): location to store the length of the
11451 * class path, or %NULL
11452 * @path: (out) (allow-none): location to store the class path as an
11453 * allocated string, or %NULL
11454 * @path_reversed: (out) (allow-none): location to store the reverse
11455 * class path as an allocated string, or %NULL
11457 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11458 * never uses a custom name set with gtk_widget_set_name().
11460 * Deprecated:3.0: Use gtk_widget_get_path() instead
11463 gtk_widget_class_path (GtkWidget *widget,
11464 guint *path_length,
11466 gchar **path_reversed)
11468 static gchar *rev_path = NULL;
11469 static guint tmp_path_len = 0;
11472 g_return_if_fail (GTK_IS_WIDGET (widget));
11477 const gchar *string;
11482 string = g_type_name (G_OBJECT_TYPE (widget));
11483 l = strlen (string);
11484 while (tmp_path_len <= len + l + 1)
11486 tmp_path_len += INIT_PATH_SIZE;
11487 rev_path = g_realloc (rev_path, tmp_path_len);
11489 s = string + l - 1;
11490 d = rev_path + len;
11491 while (s >= string)
11495 widget = widget->priv->parent;
11498 rev_path[len++] = '.';
11500 rev_path[len++] = 0;
11505 *path_length = len - 1;
11507 *path_reversed = g_strdup (rev_path);
11510 *path = g_strdup (rev_path);
11511 g_strreverse (*path);
11516 * gtk_requisition_new:
11518 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11520 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11521 * be freed with gtk_requisition_free().
11526 gtk_requisition_new (void)
11528 return g_slice_new0 (GtkRequisition);
11532 * gtk_requisition_copy:
11533 * @requisition: a #GtkRequisition
11535 * Copies a #GtkRequisition.
11537 * Returns: a copy of @requisition
11540 gtk_requisition_copy (const GtkRequisition *requisition)
11542 return g_slice_dup (GtkRequisition, requisition);
11546 * gtk_requisition_free:
11547 * @requisition: a #GtkRequisition
11549 * Frees a #GtkRequisition.
11552 gtk_requisition_free (GtkRequisition *requisition)
11554 g_slice_free (GtkRequisition, requisition);
11557 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11558 gtk_requisition_copy,
11559 gtk_requisition_free)
11562 * gtk_widget_get_accessible:
11563 * @widget: a #GtkWidget
11565 * Returns the accessible object that describes the widget to an
11566 * assistive technology.
11568 * If no accessibility library is loaded (i.e. no ATK implementation library is
11569 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11570 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11571 * if no class-specific #AtkObject implementation is available for the widget
11572 * instance in question, it will inherit an #AtkObject implementation from the
11573 * first ancestor class for which such an implementation is defined.
11575 * The documentation of the
11576 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11577 * library contains more information about accessible objects and their uses.
11579 * Returns: (transfer none): the #AtkObject associated with @widget
11582 gtk_widget_get_accessible (GtkWidget *widget)
11584 GtkWidgetClass *klass;
11586 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11588 klass = GTK_WIDGET_GET_CLASS (widget);
11590 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11592 return klass->get_accessible (widget);
11596 gtk_widget_real_get_accessible (GtkWidget *widget)
11598 AtkObject* accessible;
11600 accessible = g_object_get_qdata (G_OBJECT (widget),
11601 quark_accessible_object);
11604 AtkObjectFactory *factory;
11605 AtkRegistry *default_registry;
11607 default_registry = atk_get_default_registry ();
11608 factory = atk_registry_get_factory (default_registry,
11609 G_TYPE_FROM_INSTANCE (widget));
11611 atk_object_factory_create_accessible (factory,
11612 G_OBJECT (widget));
11613 g_object_set_qdata (G_OBJECT (widget),
11614 quark_accessible_object,
11621 * Initialize a AtkImplementorIface instance's virtual pointers as
11622 * appropriate to this implementor's class (GtkWidget).
11625 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11627 iface->ref_accessible = gtk_widget_ref_accessible;
11631 gtk_widget_ref_accessible (AtkImplementor *implementor)
11633 AtkObject *accessible;
11635 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11637 g_object_ref (accessible);
11642 * Expand flag management
11646 gtk_widget_update_computed_expand (GtkWidget *widget)
11648 GtkWidgetPrivate *priv;
11650 priv = widget->priv;
11652 if (priv->need_compute_expand)
11656 if (priv->hexpand_set)
11661 if (priv->vexpand_set)
11666 /* we don't need to use compute_expand if both expands are
11667 * forced by the app
11669 if (!(priv->hexpand_set && priv->vexpand_set))
11671 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11675 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11676 priv->hexpand_set ? &ignored : &h,
11677 priv->vexpand_set ? &ignored : &v);
11681 priv->need_compute_expand = FALSE;
11682 priv->computed_hexpand = h != FALSE;
11683 priv->computed_vexpand = v != FALSE;
11688 * gtk_widget_queue_compute_expand:
11689 * @widget: a #GtkWidget
11691 * Mark @widget as needing to recompute its expand flags. Call
11692 * this function when setting legacy expand child properties
11693 * on the child of a container.
11695 * See gtk_widget_compute_expand().
11698 gtk_widget_queue_compute_expand (GtkWidget *widget)
11701 gboolean changed_anything;
11703 if (widget->priv->need_compute_expand)
11706 changed_anything = FALSE;
11708 while (parent != NULL)
11710 if (!parent->priv->need_compute_expand)
11712 parent->priv->need_compute_expand = TRUE;
11713 changed_anything = TRUE;
11716 /* Note: if we had an invariant that "if a child needs to
11717 * compute expand, its parents also do" then we could stop going
11718 * up when we got to a parent that already needed to
11719 * compute. However, in general we compute expand lazily (as
11720 * soon as we see something in a subtree that is expand, we know
11721 * we're expanding) and so this invariant does not hold and we
11722 * have to always walk all the way up in case some ancestor
11723 * is not currently need_compute_expand.
11726 parent = parent->priv->parent;
11729 /* recomputing expand always requires
11730 * a relayout as well
11732 if (changed_anything)
11733 gtk_widget_queue_resize (widget);
11737 * gtk_widget_compute_expand:
11738 * @widget: the widget
11739 * @orientation: expand direction
11741 * Computes whether a container should give this widget extra space
11742 * when possible. Containers should check this, rather than
11743 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11745 * This function already checks whether the widget is visible, so
11746 * visibility does not need to be checked separately. Non-visible
11747 * widgets are not expanded.
11749 * The computed expand value uses either the expand setting explicitly
11750 * set on the widget itself, or, if none has been explicitly set,
11751 * the widget may expand if some of its children do.
11753 * Return value: whether widget tree rooted here should be expanded
11756 gtk_widget_compute_expand (GtkWidget *widget,
11757 GtkOrientation orientation)
11759 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11761 /* We never make a widget expand if not even showing. */
11762 if (!gtk_widget_get_visible (widget))
11765 gtk_widget_update_computed_expand (widget);
11767 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11769 return widget->priv->computed_hexpand;
11773 return widget->priv->computed_vexpand;
11778 gtk_widget_set_expand (GtkWidget *widget,
11779 GtkOrientation orientation,
11782 const char *expand_prop;
11783 const char *expand_set_prop;
11785 GtkWidgetPrivate *priv;
11787 g_return_if_fail (GTK_IS_WIDGET (widget));
11789 priv = widget->priv;
11791 expand = expand != FALSE;
11793 was_both = priv->hexpand && priv->vexpand;
11795 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11797 if (priv->hexpand_set &&
11798 priv->hexpand == expand)
11801 priv->hexpand_set = TRUE;
11802 priv->hexpand = expand;
11804 expand_prop = "hexpand";
11805 expand_set_prop = "hexpand-set";
11809 if (priv->vexpand_set &&
11810 priv->vexpand == expand)
11813 priv->vexpand_set = TRUE;
11814 priv->vexpand = expand;
11816 expand_prop = "vexpand";
11817 expand_set_prop = "vexpand-set";
11820 gtk_widget_queue_compute_expand (widget);
11822 g_object_freeze_notify (G_OBJECT (widget));
11823 g_object_notify (G_OBJECT (widget), expand_prop);
11824 g_object_notify (G_OBJECT (widget), expand_set_prop);
11825 if (was_both != (priv->hexpand && priv->vexpand))
11826 g_object_notify (G_OBJECT (widget), "expand");
11827 g_object_thaw_notify (G_OBJECT (widget));
11831 gtk_widget_set_expand_set (GtkWidget *widget,
11832 GtkOrientation orientation,
11835 GtkWidgetPrivate *priv;
11838 priv = widget->priv;
11840 set = set != FALSE;
11842 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11844 if (set == priv->hexpand_set)
11847 priv->hexpand_set = set;
11848 prop = "hexpand-set";
11852 if (set == priv->vexpand_set)
11855 priv->vexpand_set = set;
11856 prop = "vexpand-set";
11859 gtk_widget_queue_compute_expand (widget);
11861 g_object_notify (G_OBJECT (widget), prop);
11865 * gtk_widget_get_hexpand:
11866 * @widget: the widget
11868 * Gets whether the widget would like any available extra horizontal
11869 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11870 * generally receive the extra space. For example, a list or
11871 * scrollable area or document in your window would often be set to
11874 * Containers should use gtk_widget_compute_expand() rather than
11875 * this function, to see whether a widget, or any of its children,
11876 * has the expand flag set. If any child of a widget wants to
11877 * expand, the parent may ask to expand also.
11879 * This function only looks at the widget's own hexpand flag, rather
11880 * than computing whether the entire widget tree rooted at this widget
11883 * Return value: whether hexpand flag is set
11886 gtk_widget_get_hexpand (GtkWidget *widget)
11888 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11890 return widget->priv->hexpand;
11894 * gtk_widget_set_hexpand:
11895 * @widget: the widget
11896 * @expand: whether to expand
11898 * Sets whether the widget would like any available extra horizontal
11899 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11900 * generally receive the extra space. For example, a list or
11901 * scrollable area or document in your window would often be set to
11904 * Call this function to set the expand flag if you would like your
11905 * widget to become larger horizontally when the window has extra
11908 * By default, widgets automatically expand if any of their children
11909 * want to expand. (To see if a widget will automatically expand given
11910 * its current children and state, call gtk_widget_compute_expand(). A
11911 * container can decide how the expandability of children affects the
11912 * expansion of the container by overriding the compute_expand virtual
11913 * method on #GtkWidget.).
11915 * Setting hexpand explicitly with this function will override the
11916 * automatic expand behavior.
11918 * This function forces the widget to expand or not to expand,
11919 * regardless of children. The override occurs because
11920 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11921 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11922 * value to be used, rather than looking at children and widget state.
11925 gtk_widget_set_hexpand (GtkWidget *widget,
11928 g_return_if_fail (GTK_IS_WIDGET (widget));
11930 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11934 * gtk_widget_get_hexpand_set:
11935 * @widget: the widget
11937 * Gets whether gtk_widget_set_hexpand() has been used to
11938 * explicitly set the expand flag on this widget.
11940 * If hexpand is set, then it overrides any computed
11941 * expand value based on child widgets. If hexpand is not
11942 * set, then the expand value depends on whether any
11943 * children of the widget would like to expand.
11945 * There are few reasons to use this function, but it's here
11946 * for completeness and consistency.
11948 * Return value: whether hexpand has been explicitly set
11951 gtk_widget_get_hexpand_set (GtkWidget *widget)
11953 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11955 return widget->priv->hexpand_set;
11959 * gtk_widget_set_hexpand_set:
11960 * @widget: the widget
11961 * @set: value for hexpand-set property
11963 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11966 * The hexpand-set property will be set automatically when you call
11967 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11968 * reason to use this function would be to unset an explicit expand
11971 * If hexpand is set, then it overrides any computed
11972 * expand value based on child widgets. If hexpand is not
11973 * set, then the expand value depends on whether any
11974 * children of the widget would like to expand.
11976 * There are few reasons to use this function, but it's here
11977 * for completeness and consistency.
11980 gtk_widget_set_hexpand_set (GtkWidget *widget,
11983 g_return_if_fail (GTK_IS_WIDGET (widget));
11985 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11990 * gtk_widget_get_vexpand:
11991 * @widget: the widget
11993 * Gets whether the widget would like any available extra vertical
11996 * See gtk_widget_get_hexpand() for more detail.
11998 * Return value: whether vexpand flag is set
12001 gtk_widget_get_vexpand (GtkWidget *widget)
12003 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12005 return widget->priv->vexpand;
12009 * gtk_widget_set_vexpand:
12010 * @widget: the widget
12011 * @expand: whether to expand
12013 * Sets whether the widget would like any available extra vertical
12016 * See gtk_widget_set_hexpand() for more detail.
12019 gtk_widget_set_vexpand (GtkWidget *widget,
12022 g_return_if_fail (GTK_IS_WIDGET (widget));
12024 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12028 * gtk_widget_get_vexpand_set:
12029 * @widget: the widget
12031 * Gets whether gtk_widget_set_vexpand() has been used to
12032 * explicitly set the expand flag on this widget.
12034 * See gtk_widget_get_hexpand_set() for more detail.
12036 * Return value: whether vexpand has been explicitly set
12039 gtk_widget_get_vexpand_set (GtkWidget *widget)
12041 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12043 return widget->priv->vexpand_set;
12047 * gtk_widget_set_vexpand_set:
12048 * @widget: the widget
12049 * @set: value for vexpand-set property
12051 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12054 * See gtk_widget_set_hexpand_set() for more detail.
12057 gtk_widget_set_vexpand_set (GtkWidget *widget,
12060 g_return_if_fail (GTK_IS_WIDGET (widget));
12062 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12066 * GtkBuildable implementation
12068 static GQuark quark_builder_has_default = 0;
12069 static GQuark quark_builder_has_focus = 0;
12070 static GQuark quark_builder_atk_relations = 0;
12071 static GQuark quark_builder_set_name = 0;
12074 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12076 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12077 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12078 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12079 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12081 iface->set_name = gtk_widget_buildable_set_name;
12082 iface->get_name = gtk_widget_buildable_get_name;
12083 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12084 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12085 iface->parser_finished = gtk_widget_buildable_parser_finished;
12086 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12087 iface->custom_finished = gtk_widget_buildable_custom_finished;
12091 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12094 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12095 g_strdup (name), g_free);
12098 static const gchar *
12099 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12101 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12105 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12106 GtkBuilder *builder,
12107 const gchar *childname)
12109 if (strcmp (childname, "accessible") == 0)
12110 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12116 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12117 GtkBuilder *builder,
12119 const GValue *value)
12121 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12122 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12123 GINT_TO_POINTER (TRUE));
12124 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12125 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12126 GINT_TO_POINTER (TRUE));
12128 g_object_set_property (G_OBJECT (buildable), name, value);
12133 gchar *action_name;
12134 GString *description;
12136 gboolean translatable;
12146 free_action (AtkActionData *data, gpointer user_data)
12148 g_free (data->action_name);
12149 g_string_free (data->description, TRUE);
12150 g_free (data->context);
12151 g_slice_free (AtkActionData, data);
12155 free_relation (AtkRelationData *data, gpointer user_data)
12157 g_free (data->target);
12158 g_free (data->type);
12159 g_slice_free (AtkRelationData, data);
12163 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12164 GtkBuilder *builder)
12166 GSList *atk_relations;
12168 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12169 gtk_widget_grab_default (GTK_WIDGET (buildable));
12170 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12171 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12173 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12174 quark_builder_atk_relations);
12177 AtkObject *accessible;
12178 AtkRelationSet *relation_set;
12181 AtkRelationType relation_type;
12182 AtkObject *target_accessible;
12184 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12185 relation_set = atk_object_ref_relation_set (accessible);
12187 for (l = atk_relations; l; l = l->next)
12189 AtkRelationData *relation = (AtkRelationData*)l->data;
12191 target = gtk_builder_get_object (builder, relation->target);
12194 g_warning ("Target object %s in <relation> does not exist",
12198 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12199 g_assert (target_accessible != NULL);
12201 relation_type = atk_relation_type_for_name (relation->type);
12202 if (relation_type == ATK_RELATION_NULL)
12204 g_warning ("<relation> type %s not found",
12208 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12209 target_accessible);
12211 g_object_unref (relation_set);
12213 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12214 g_slist_free (atk_relations);
12215 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12224 } AccessibilitySubParserData;
12227 accessibility_start_element (GMarkupParseContext *context,
12228 const gchar *element_name,
12229 const gchar **names,
12230 const gchar **values,
12231 gpointer user_data,
12234 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12236 gint line_number, char_number;
12238 if (strcmp (element_name, "relation") == 0)
12240 gchar *target = NULL;
12241 gchar *type = NULL;
12242 AtkRelationData *relation;
12244 for (i = 0; names[i]; i++)
12246 if (strcmp (names[i], "target") == 0)
12247 target = g_strdup (values[i]);
12248 else if (strcmp (names[i], "type") == 0)
12249 type = g_strdup (values[i]);
12252 g_markup_parse_context_get_position (context,
12255 g_set_error (error,
12257 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12258 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12260 line_number, char_number, names[i], "relation");
12267 if (!target || !type)
12269 g_markup_parse_context_get_position (context,
12272 g_set_error (error,
12274 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12275 "%s:%d:%d <%s> requires attribute \"%s\"",
12277 line_number, char_number, "relation",
12278 type ? "target" : "type");
12284 relation = g_slice_new (AtkRelationData);
12285 relation->target = target;
12286 relation->type = type;
12288 data->relations = g_slist_prepend (data->relations, relation);
12290 else if (strcmp (element_name, "action") == 0)
12292 const gchar *action_name = NULL;
12293 const gchar *description = NULL;
12294 const gchar *msg_context = NULL;
12295 gboolean translatable = FALSE;
12296 AtkActionData *action;
12298 for (i = 0; names[i]; i++)
12300 if (strcmp (names[i], "action_name") == 0)
12301 action_name = values[i];
12302 else if (strcmp (names[i], "description") == 0)
12303 description = values[i];
12304 else if (strcmp (names[i], "translatable") == 0)
12306 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12309 else if (strcmp (names[i], "comments") == 0)
12311 /* do nothing, comments are for translators */
12313 else if (strcmp (names[i], "context") == 0)
12314 msg_context = values[i];
12317 g_markup_parse_context_get_position (context,
12320 g_set_error (error,
12322 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12323 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12325 line_number, char_number, names[i], "action");
12332 g_markup_parse_context_get_position (context,
12335 g_set_error (error,
12337 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12338 "%s:%d:%d <%s> requires attribute \"%s\"",
12340 line_number, char_number, "action",
12345 action = g_slice_new (AtkActionData);
12346 action->action_name = g_strdup (action_name);
12347 action->description = g_string_new (description);
12348 action->context = g_strdup (msg_context);
12349 action->translatable = translatable;
12351 data->actions = g_slist_prepend (data->actions, action);
12353 else if (strcmp (element_name, "accessibility") == 0)
12356 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12360 accessibility_text (GMarkupParseContext *context,
12363 gpointer user_data,
12366 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12368 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12370 AtkActionData *action = data->actions->data;
12372 g_string_append_len (action->description, text, text_len);
12376 static const GMarkupParser accessibility_parser =
12378 accessibility_start_element,
12380 accessibility_text,
12389 } AccelGroupParserData;
12392 accel_group_start_element (GMarkupParseContext *context,
12393 const gchar *element_name,
12394 const gchar **names,
12395 const gchar **values,
12396 gpointer user_data,
12401 guint modifiers = 0;
12402 gchar *signal = NULL;
12403 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12405 for (i = 0; names[i]; i++)
12407 if (strcmp (names[i], "key") == 0)
12408 key = gdk_keyval_from_name (values[i]);
12409 else if (strcmp (names[i], "modifiers") == 0)
12411 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12417 else if (strcmp (names[i], "signal") == 0)
12418 signal = g_strdup (values[i]);
12421 if (key == 0 || signal == NULL)
12423 g_warning ("<accelerator> requires key and signal attributes");
12426 parser_data->key = key;
12427 parser_data->modifiers = modifiers;
12428 parser_data->signal = signal;
12431 static const GMarkupParser accel_group_parser =
12433 accel_group_start_element,
12437 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12438 GtkBuilder *builder,
12440 const gchar *tagname,
12441 GMarkupParser *parser,
12444 g_assert (buildable);
12446 if (strcmp (tagname, "accelerator") == 0)
12448 AccelGroupParserData *parser_data;
12450 parser_data = g_slice_new0 (AccelGroupParserData);
12451 parser_data->object = g_object_ref (buildable);
12452 *parser = accel_group_parser;
12453 *data = parser_data;
12456 if (strcmp (tagname, "accessibility") == 0)
12458 AccessibilitySubParserData *parser_data;
12460 parser_data = g_slice_new0 (AccessibilitySubParserData);
12461 *parser = accessibility_parser;
12462 *data = parser_data;
12469 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12470 GtkWidget *toplevel,
12471 gpointer user_data)
12473 AccelGroupParserData *accel_data;
12474 GSList *accel_groups;
12475 GtkAccelGroup *accel_group;
12477 g_return_if_fail (GTK_IS_WIDGET (widget));
12478 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12479 g_return_if_fail (user_data != NULL);
12481 accel_data = (AccelGroupParserData*)user_data;
12482 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12483 if (g_slist_length (accel_groups) == 0)
12485 accel_group = gtk_accel_group_new ();
12486 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12490 g_assert (g_slist_length (accel_groups) == 1);
12491 accel_group = g_slist_nth_data (accel_groups, 0);
12494 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12495 accel_data->signal,
12498 accel_data->modifiers,
12499 GTK_ACCEL_VISIBLE);
12501 g_object_unref (accel_data->object);
12502 g_free (accel_data->signal);
12503 g_slice_free (AccelGroupParserData, accel_data);
12507 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12508 GtkBuilder *builder,
12510 const gchar *tagname,
12511 gpointer user_data)
12513 AccelGroupParserData *accel_data;
12514 AccessibilitySubParserData *a11y_data;
12515 GtkWidget *toplevel;
12517 if (strcmp (tagname, "accelerator") == 0)
12519 accel_data = (AccelGroupParserData*)user_data;
12520 g_assert (accel_data->object);
12522 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12524 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12526 else if (strcmp (tagname, "accessibility") == 0)
12528 a11y_data = (AccessibilitySubParserData*)user_data;
12530 if (a11y_data->actions)
12532 AtkObject *accessible;
12537 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12539 action = ATK_ACTION (accessible);
12540 n_actions = atk_action_get_n_actions (action);
12542 for (l = a11y_data->actions; l; l = l->next)
12544 AtkActionData *action_data = (AtkActionData*)l->data;
12546 for (i = 0; i < n_actions; i++)
12547 if (strcmp (atk_action_get_name (action, i),
12548 action_data->action_name) == 0)
12553 gchar *description;
12555 if (action_data->translatable && action_data->description->len)
12556 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12557 action_data->context,
12558 action_data->description->str);
12560 description = action_data->description->str;
12562 atk_action_set_description (action, i, description);
12566 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12567 g_slist_free (a11y_data->actions);
12570 if (a11y_data->relations)
12571 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12572 a11y_data->relations);
12574 g_slice_free (AccessibilitySubParserData, a11y_data);
12579 gtk_widget_real_get_width (GtkWidget *widget,
12580 gint *minimum_size,
12581 gint *natural_size)
12591 gtk_widget_real_get_height (GtkWidget *widget,
12592 gint *minimum_size,
12593 gint *natural_size)
12603 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12605 gint *minimum_height,
12606 gint *natural_height)
12608 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12612 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12614 gint *minimum_width,
12615 gint *natural_width)
12617 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12621 * gtk_widget_get_halign:
12622 * @widget: a #GtkWidget
12624 * Gets the value of the #GtkWidget:halign property.
12626 * Returns: the horizontal alignment of @widget
12629 gtk_widget_get_halign (GtkWidget *widget)
12631 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12632 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12636 * gtk_widget_set_halign:
12637 * @widget: a #GtkWidget
12638 * @align: the horizontal alignment
12640 * Sets the horizontal alignment of @widget.
12641 * See the #GtkWidget:halign property.
12644 gtk_widget_set_halign (GtkWidget *widget,
12647 GtkWidgetAuxInfo *aux_info;
12649 g_return_if_fail (GTK_IS_WIDGET (widget));
12651 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12653 if (aux_info->halign == align)
12656 aux_info->halign = align;
12657 gtk_widget_queue_resize (widget);
12658 g_object_notify (G_OBJECT (widget), "halign");
12662 * gtk_widget_get_valign:
12663 * @widget: a #GtkWidget
12665 * Gets the value of the #GtkWidget:valign property.
12667 * Returns: the vertical alignment of @widget
12670 gtk_widget_get_valign (GtkWidget *widget)
12672 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12673 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12677 * gtk_widget_set_valign:
12678 * @widget: a #GtkWidget
12679 * @align: the vertical alignment
12681 * Sets the vertical alignment of @widget.
12682 * See the #GtkWidget:valign property.
12685 gtk_widget_set_valign (GtkWidget *widget,
12688 GtkWidgetAuxInfo *aux_info;
12690 g_return_if_fail (GTK_IS_WIDGET (widget));
12692 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12694 if (aux_info->valign == align)
12697 aux_info->valign = align;
12698 gtk_widget_queue_resize (widget);
12699 g_object_notify (G_OBJECT (widget), "valign");
12703 * gtk_widget_get_margin_left:
12704 * @widget: a #GtkWidget
12706 * Gets the value of the #GtkWidget:margin-left property.
12708 * Returns: The left margin of @widget
12711 gtk_widget_get_margin_left (GtkWidget *widget)
12713 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12715 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12719 * gtk_widget_set_margin_left:
12720 * @widget: a #GtkWidget
12721 * @margin: the left margin
12723 * Sets the left margin of @widget.
12724 * See the #GtkWidget:margin-left property.
12727 gtk_widget_set_margin_left (GtkWidget *widget,
12730 GtkWidgetAuxInfo *aux_info;
12732 g_return_if_fail (GTK_IS_WIDGET (widget));
12733 g_return_if_fail (margin <= G_MAXINT16);
12735 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12737 if (aux_info->margin.left == margin)
12740 aux_info->margin.left = margin;
12741 gtk_widget_queue_resize (widget);
12742 g_object_notify (G_OBJECT (widget), "margin-left");
12746 * gtk_widget_get_margin_right:
12747 * @widget: a #GtkWidget
12749 * Gets the value of the #GtkWidget:margin-right property.
12751 * Returns: The left margin of @widget
12754 gtk_widget_get_margin_right (GtkWidget *widget)
12756 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12758 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12762 * gtk_widget_set_margin_right:
12763 * @widget: a #GtkWidget
12764 * @margin: the right margin
12766 * Sets the right margin of @widget.
12767 * See the #GtkWidget:margin-right property.
12770 gtk_widget_set_margin_right (GtkWidget *widget,
12773 GtkWidgetAuxInfo *aux_info;
12775 g_return_if_fail (GTK_IS_WIDGET (widget));
12776 g_return_if_fail (margin <= G_MAXINT16);
12778 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12780 if (aux_info->margin.right == margin)
12783 aux_info->margin.right = margin;
12784 gtk_widget_queue_resize (widget);
12785 g_object_notify (G_OBJECT (widget), "margin-right");
12789 * gtk_widget_get_margin_top:
12790 * @widget: a #GtkWidget
12792 * Gets the value of the #GtkWidget:margin-top property.
12794 * Returns: The top margin of @widget
12797 gtk_widget_get_margin_top (GtkWidget *widget)
12799 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12801 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12805 * gtk_widget_set_margin_top:
12806 * @widget: a #GtkWidget
12807 * @margin: the top margin
12809 * Sets the top margin of @widget.
12810 * See the #GtkWidget:margin-top property.
12813 gtk_widget_set_margin_top (GtkWidget *widget,
12816 GtkWidgetAuxInfo *aux_info;
12818 g_return_if_fail (GTK_IS_WIDGET (widget));
12819 g_return_if_fail (margin <= G_MAXINT16);
12821 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12823 if (aux_info->margin.top == margin)
12826 aux_info->margin.top = margin;
12827 gtk_widget_queue_resize (widget);
12828 g_object_notify (G_OBJECT (widget), "margin-top");
12832 * gtk_widget_get_margin_bottom:
12833 * @widget: a #GtkWidget
12835 * Gets the value of the #GtkWidget:margin-bottom property.
12837 * Returns: The bottom margin of @widget
12840 gtk_widget_get_margin_bottom (GtkWidget *widget)
12842 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12844 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12848 * gtk_widget_set_margin_bottom:
12849 * @widget: a #GtkWidget
12850 * @margin: the bottom margin
12852 * Sets the bottom margin of @widget.
12853 * See the #GtkWidget:margin-bottom property.
12856 gtk_widget_set_margin_bottom (GtkWidget *widget,
12859 GtkWidgetAuxInfo *aux_info;
12861 g_return_if_fail (GTK_IS_WIDGET (widget));
12862 g_return_if_fail (margin <= G_MAXINT16);
12864 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12866 if (aux_info->margin.bottom == margin)
12869 aux_info->margin.bottom = margin;
12870 gtk_widget_queue_resize (widget);
12871 g_object_notify (G_OBJECT (widget), "margin-bottom");
12875 * gtk_widget_get_clipboard:
12876 * @widget: a #GtkWidget
12877 * @selection: a #GdkAtom which identifies the clipboard
12878 * to use. %GDK_SELECTION_CLIPBOARD gives the
12879 * default clipboard. Another common value
12880 * is %GDK_SELECTION_PRIMARY, which gives
12881 * the primary X selection.
12883 * Returns the clipboard object for the given selection to
12884 * be used with @widget. @widget must have a #GdkDisplay
12885 * associated with it, so must be attached to a toplevel
12888 * Return value: (transfer none): the appropriate clipboard object. If no
12889 * clipboard already exists, a new one will
12890 * be created. Once a clipboard object has
12891 * been created, it is persistent for all time.
12896 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12898 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12899 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12901 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12906 * gtk_widget_list_mnemonic_labels:
12907 * @widget: a #GtkWidget
12909 * Returns a newly allocated list of the widgets, normally labels, for
12910 * which this widget is the target of a mnemonic (see for example,
12911 * gtk_label_set_mnemonic_widget()).
12913 * The widgets in the list are not individually referenced. If you
12914 * want to iterate through the list and perform actions involving
12915 * callbacks that might destroy the widgets, you
12916 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12917 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12918 * widgets afterwards.
12920 * Return value: (element-type GtkWidget) (transfer container): the list of
12921 * mnemonic labels; free this list
12922 * with g_list_free() when you are done with it.
12927 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12929 GList *list = NULL;
12932 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12934 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12935 list = g_list_prepend (list, l->data);
12941 * gtk_widget_add_mnemonic_label:
12942 * @widget: a #GtkWidget
12943 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12945 * Adds a widget to the list of mnemonic labels for
12946 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12947 * list of mnemonic labels for the widget is cleared when the
12948 * widget is destroyed, so the caller must make sure to update
12949 * its internal state at this point as well, by using a connection
12950 * to the #GtkWidget::destroy signal or a weak notifier.
12955 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12958 GSList *old_list, *new_list;
12960 g_return_if_fail (GTK_IS_WIDGET (widget));
12961 g_return_if_fail (GTK_IS_WIDGET (label));
12963 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12964 new_list = g_slist_prepend (old_list, label);
12966 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12967 new_list, (GDestroyNotify) g_slist_free);
12971 * gtk_widget_remove_mnemonic_label:
12972 * @widget: a #GtkWidget
12973 * @label: a #GtkWidget that was previously set as a mnemnic label for
12974 * @widget with gtk_widget_add_mnemonic_label().
12976 * Removes a widget from the list of mnemonic labels for
12977 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12978 * must have previously been added to the list with
12979 * gtk_widget_add_mnemonic_label().
12984 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12987 GSList *old_list, *new_list;
12989 g_return_if_fail (GTK_IS_WIDGET (widget));
12990 g_return_if_fail (GTK_IS_WIDGET (label));
12992 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12993 new_list = g_slist_remove (old_list, label);
12996 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12997 new_list, (GDestroyNotify) g_slist_free);
13001 * gtk_widget_get_no_show_all:
13002 * @widget: a #GtkWidget
13004 * Returns the current value of the #GtkWidget:no-show-all property,
13005 * which determines whether calls to gtk_widget_show_all()
13006 * will affect this widget.
13008 * Return value: the current value of the "no-show-all" property.
13013 gtk_widget_get_no_show_all (GtkWidget *widget)
13015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13017 return widget->priv->no_show_all;
13021 * gtk_widget_set_no_show_all:
13022 * @widget: a #GtkWidget
13023 * @no_show_all: the new value for the "no-show-all" property
13025 * Sets the #GtkWidget:no-show-all property, which determines whether
13026 * calls to gtk_widget_show_all() will affect this widget.
13028 * This is mostly for use in constructing widget hierarchies with externally
13029 * controlled visibility, see #GtkUIManager.
13034 gtk_widget_set_no_show_all (GtkWidget *widget,
13035 gboolean no_show_all)
13037 g_return_if_fail (GTK_IS_WIDGET (widget));
13039 no_show_all = (no_show_all != FALSE);
13041 if (widget->priv->no_show_all != no_show_all)
13043 widget->priv->no_show_all = no_show_all;
13045 g_object_notify (G_OBJECT (widget), "no-show-all");
13051 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13052 gboolean has_tooltip,
13055 GtkWidgetPrivate *priv = widget->priv;
13056 gboolean priv_has_tooltip;
13058 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13059 quark_has_tooltip));
13061 if (priv_has_tooltip != has_tooltip || force)
13063 priv_has_tooltip = has_tooltip;
13065 if (priv_has_tooltip)
13067 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13068 gdk_window_set_events (priv->window,
13069 gdk_window_get_events (priv->window) |
13070 GDK_LEAVE_NOTIFY_MASK |
13071 GDK_POINTER_MOTION_MASK |
13072 GDK_POINTER_MOTION_HINT_MASK);
13074 if (gtk_widget_get_has_window (widget))
13075 gtk_widget_add_events (widget,
13076 GDK_LEAVE_NOTIFY_MASK |
13077 GDK_POINTER_MOTION_MASK |
13078 GDK_POINTER_MOTION_HINT_MASK);
13081 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13082 GUINT_TO_POINTER (priv_has_tooltip));
13087 * gtk_widget_set_tooltip_window:
13088 * @widget: a #GtkWidget
13089 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13091 * Replaces the default, usually yellow, window used for displaying
13092 * tooltips with @custom_window. GTK+ will take care of showing and
13093 * hiding @custom_window at the right moment, to behave likewise as
13094 * the default tooltip window. If @custom_window is %NULL, the default
13095 * tooltip window will be used.
13097 * If the custom window should have the default theming it needs to
13098 * have the name "gtk-tooltip", see gtk_widget_set_name().
13103 gtk_widget_set_tooltip_window (GtkWidget *widget,
13104 GtkWindow *custom_window)
13106 gboolean has_tooltip;
13107 gchar *tooltip_markup;
13109 g_return_if_fail (GTK_IS_WIDGET (widget));
13110 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13112 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13115 g_object_ref (custom_window);
13117 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13118 custom_window, g_object_unref);
13120 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13121 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13123 if (has_tooltip && gtk_widget_get_visible (widget))
13124 gtk_widget_queue_tooltip_query (widget);
13128 * gtk_widget_get_tooltip_window:
13129 * @widget: a #GtkWidget
13131 * Returns the #GtkWindow of the current tooltip. This can be the
13132 * GtkWindow created by default, or the custom tooltip window set
13133 * using gtk_widget_set_tooltip_window().
13135 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13140 gtk_widget_get_tooltip_window (GtkWidget *widget)
13142 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13144 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13148 * gtk_widget_trigger_tooltip_query:
13149 * @widget: a #GtkWidget
13151 * Triggers a tooltip query on the display where the toplevel of @widget
13152 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13158 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13160 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13163 static guint tooltip_query_id;
13164 static GSList *tooltip_query_displays;
13167 tooltip_query_idle (gpointer data)
13169 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13170 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13171 g_slist_free (tooltip_query_displays);
13173 tooltip_query_displays = NULL;
13174 tooltip_query_id = 0;
13180 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13182 GdkDisplay *display;
13184 display = gtk_widget_get_display (widget);
13186 if (!g_slist_find (tooltip_query_displays, display))
13187 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13189 if (tooltip_query_id == 0)
13190 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13194 * gtk_widget_set_tooltip_text:
13195 * @widget: a #GtkWidget
13196 * @text: the contents of the tooltip for @widget
13198 * Sets @text as the contents of the tooltip. This function will take
13199 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13200 * handler for the #GtkWidget::query-tooltip signal.
13202 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13207 gtk_widget_set_tooltip_text (GtkWidget *widget,
13210 g_return_if_fail (GTK_IS_WIDGET (widget));
13212 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13216 * gtk_widget_get_tooltip_text:
13217 * @widget: a #GtkWidget
13219 * Gets the contents of the tooltip for @widget.
13221 * Return value: the tooltip text, or %NULL. You should free the
13222 * returned string with g_free() when done.
13227 gtk_widget_get_tooltip_text (GtkWidget *widget)
13229 gchar *text = NULL;
13231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13233 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13239 * gtk_widget_set_tooltip_markup:
13240 * @widget: a #GtkWidget
13241 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13243 * Sets @markup as the contents of the tooltip, which is marked up with
13244 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13246 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13247 * and of the default handler for the #GtkWidget::query-tooltip signal.
13249 * See also the #GtkWidget:tooltip-markup property and
13250 * gtk_tooltip_set_markup().
13255 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13256 const gchar *markup)
13258 g_return_if_fail (GTK_IS_WIDGET (widget));
13260 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13264 * gtk_widget_get_tooltip_markup:
13265 * @widget: a #GtkWidget
13267 * Gets the contents of the tooltip for @widget.
13269 * Return value: the tooltip text, or %NULL. You should free the
13270 * returned string with g_free() when done.
13275 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13277 gchar *text = NULL;
13279 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13281 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13287 * gtk_widget_set_has_tooltip:
13288 * @widget: a #GtkWidget
13289 * @has_tooltip: whether or not @widget has a tooltip.
13291 * Sets the has-tooltip property on @widget to @has_tooltip. See
13292 * #GtkWidget:has-tooltip for more information.
13297 gtk_widget_set_has_tooltip (GtkWidget *widget,
13298 gboolean has_tooltip)
13300 g_return_if_fail (GTK_IS_WIDGET (widget));
13302 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13306 * gtk_widget_get_has_tooltip:
13307 * @widget: a #GtkWidget
13309 * Returns the current value of the has-tooltip property. See
13310 * #GtkWidget:has-tooltip for more information.
13312 * Return value: current value of has-tooltip on @widget.
13317 gtk_widget_get_has_tooltip (GtkWidget *widget)
13319 gboolean has_tooltip = FALSE;
13321 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13323 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13325 return has_tooltip;
13329 * gtk_widget_get_allocation:
13330 * @widget: a #GtkWidget
13331 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13333 * Retrieves the widget's allocation.
13335 * Note, when implementing a #GtkContainer: a widget's allocation will
13336 * be its "adjusted" allocation, that is, the widget's parent
13337 * container typically calls gtk_widget_size_allocate() with an
13338 * allocation, and that allocation is then adjusted (to handle margin
13339 * and alignment for example) before assignment to the widget.
13340 * gtk_widget_get_allocation() returns the adjusted allocation that
13341 * was actually assigned to the widget. The adjusted allocation is
13342 * guaranteed to be completely contained within the
13343 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13344 * is guaranteed that its children stay inside the assigned bounds,
13345 * but not that they have exactly the bounds the container assigned.
13346 * There is no way to get the original allocation assigned by
13347 * gtk_widget_size_allocate(), since it isn't stored; if a container
13348 * implementation needs that information it will have to track it itself.
13353 gtk_widget_get_allocation (GtkWidget *widget,
13354 GtkAllocation *allocation)
13356 GtkWidgetPrivate *priv;
13358 g_return_if_fail (GTK_IS_WIDGET (widget));
13359 g_return_if_fail (allocation != NULL);
13361 priv = widget->priv;
13363 *allocation = priv->allocation;
13367 * gtk_widget_set_allocation:
13368 * @widget: a #GtkWidget
13369 * @allocation: a pointer to a #GtkAllocation to copy from
13371 * Sets the widget's allocation. This should not be used
13372 * directly, but from within a widget's size_allocate method.
13374 * The allocation set should be the "adjusted" or actual
13375 * allocation. If you're implementing a #GtkContainer, you want to use
13376 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13377 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13378 * allocation inside gtk_widget_size_allocate() to create an adjusted
13384 gtk_widget_set_allocation (GtkWidget *widget,
13385 const GtkAllocation *allocation)
13387 GtkWidgetPrivate *priv;
13389 g_return_if_fail (GTK_IS_WIDGET (widget));
13390 g_return_if_fail (allocation != NULL);
13392 priv = widget->priv;
13394 priv->allocation = *allocation;
13398 * gtk_widget_get_allocated_width:
13399 * @widget: the widget to query
13401 * Returns the width that has currently been allocated to @widget.
13402 * This function is intended to be used when implementing handlers
13403 * for the #GtkWidget::draw function.
13405 * Returns: the width of the @widget
13408 gtk_widget_get_allocated_width (GtkWidget *widget)
13410 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13412 return widget->priv->allocation.width;
13416 * gtk_widget_get_allocated_height:
13417 * @widget: the widget to query
13419 * Returns the height that has currently been allocated to @widget.
13420 * This function is intended to be used when implementing handlers
13421 * for the #GtkWidget::draw function.
13423 * Returns: the height of the @widget
13426 gtk_widget_get_allocated_height (GtkWidget *widget)
13428 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13430 return widget->priv->allocation.height;
13434 * gtk_widget_get_requisition:
13435 * @widget: a #GtkWidget
13436 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13438 * Retrieves the widget's requisition.
13440 * This function should only be used by widget implementations in
13441 * order to figure whether the widget's requisition has actually
13442 * changed after some internal state change (so that they can call
13443 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13445 * Normally, gtk_widget_size_request() should be used.
13449 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13450 * removed, If you need to cache sizes across requests and allocations,
13451 * add an explicit cache to the widget in question instead.
13454 gtk_widget_get_requisition (GtkWidget *widget,
13455 GtkRequisition *requisition)
13457 g_return_if_fail (GTK_IS_WIDGET (widget));
13458 g_return_if_fail (requisition != NULL);
13460 gtk_widget_get_preferred_size (widget, requisition, NULL);
13464 * gtk_widget_set_window:
13465 * @widget: a #GtkWidget
13466 * @window: a #GdkWindow
13468 * Sets a widget's window. This function should only be used in a
13469 * widget's #GtkWidget::realize implementation. The %window passed is
13470 * usually either new window created with gdk_window_new(), or the
13471 * window of its parent widget as returned by
13472 * gtk_widget_get_parent_window().
13474 * Widgets must indicate whether they will create their own #GdkWindow
13475 * by calling gtk_widget_set_has_window(). This is usually done in the
13476 * widget's init() function.
13478 * <note><para>This function does not add any reference to @window.</para></note>
13483 gtk_widget_set_window (GtkWidget *widget,
13486 GtkWidgetPrivate *priv;
13488 g_return_if_fail (GTK_IS_WIDGET (widget));
13489 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13491 priv = widget->priv;
13493 if (priv->window != window)
13495 priv->window = window;
13496 g_object_notify (G_OBJECT (widget), "window");
13501 * gtk_widget_get_window:
13502 * @widget: a #GtkWidget
13504 * Returns the widget's window if it is realized, %NULL otherwise
13506 * Return value: (transfer none): @widget's window.
13511 gtk_widget_get_window (GtkWidget *widget)
13513 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13515 return widget->priv->window;
13519 * gtk_widget_get_support_multidevice:
13520 * @widget: a #GtkWidget
13522 * Returns %TRUE if @widget is multiple pointer aware. See
13523 * gtk_widget_set_support_multidevice() for more information.
13525 * Returns: %TRUE if @widget is multidevice aware.
13528 gtk_widget_get_support_multidevice (GtkWidget *widget)
13530 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13532 return widget->priv->multidevice;
13536 * gtk_widget_set_support_multidevice:
13537 * @widget: a #GtkWidget
13538 * @support_multidevice: %TRUE to support input from multiple devices.
13540 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13541 * @widget will start receiving multiple, per device enter/leave events. Note
13542 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13543 * gdk_window_set_support_multidevice() will have to be called manually on them.
13548 gtk_widget_set_support_multidevice (GtkWidget *widget,
13549 gboolean support_multidevice)
13551 GtkWidgetPrivate *priv;
13553 g_return_if_fail (GTK_IS_WIDGET (widget));
13555 priv = widget->priv;
13556 priv->multidevice = (support_multidevice == TRUE);
13558 if (gtk_widget_get_realized (widget))
13559 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13563 _gtk_widget_set_has_focus (GtkWidget *widget,
13564 gboolean has_focus)
13566 widget->priv->has_focus = has_focus;
13570 * gtk_widget_send_focus_change:
13571 * @widget: a #GtkWidget
13572 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13574 * Sends the focus change @event to @widget
13576 * This function is not meant to be used by applications. The only time it
13577 * should be used is when it is necessary for a #GtkWidget to assign focus
13578 * to a widget that is semantically owned by the first widget even though
13579 * it's not a direct child - for instance, a search entry in a floating
13580 * window similar to the quick search in #GtkTreeView.
13582 * An example of its usage is:
13585 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13587 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13588 * fevent->focus_change.in = TRUE;
13589 * fevent->focus_change.window = gtk_widget_get_window (widget);
13590 * if (fevent->focus_change.window != NULL)
13591 * g_object_ref (fevent->focus_change.window);
13593 * gtk_widget_send_focus_change (widget, fevent);
13595 * gdk_event_free (event);
13598 * Return value: the return value from the event signal emission: %TRUE
13599 * if the event was handled, and %FALSE otherwise
13604 gtk_widget_send_focus_change (GtkWidget *widget,
13609 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13610 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13612 g_object_ref (widget);
13614 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13616 res = gtk_widget_event (widget, event);
13618 g_object_notify (G_OBJECT (widget), "has-focus");
13620 g_object_unref (widget);
13626 * gtk_widget_in_destruction:
13627 * @widget: a #GtkWidget
13629 * Returns whether the widget is currently being destroyed.
13630 * This information can sometimes be used to avoid doing
13631 * unnecessary work.
13633 * Returns: %TRUE if @widget is being destroyed
13636 gtk_widget_in_destruction (GtkWidget *widget)
13638 return widget->priv->in_destruction;
13642 _gtk_widget_get_resize_pending (GtkWidget *widget)
13644 return widget->priv->resize_pending;
13648 _gtk_widget_set_resize_pending (GtkWidget *widget,
13649 gboolean resize_pending)
13651 widget->priv->resize_pending = resize_pending;
13655 _gtk_widget_get_in_reparent (GtkWidget *widget)
13657 return widget->priv->in_reparent;
13661 _gtk_widget_set_in_reparent (GtkWidget *widget,
13662 gboolean in_reparent)
13664 widget->priv->in_reparent = in_reparent;
13668 _gtk_widget_get_anchored (GtkWidget *widget)
13670 return widget->priv->anchored;
13674 _gtk_widget_set_anchored (GtkWidget *widget,
13677 widget->priv->anchored = anchored;
13681 _gtk_widget_get_shadowed (GtkWidget *widget)
13683 return widget->priv->shadowed;
13687 _gtk_widget_set_shadowed (GtkWidget *widget,
13690 widget->priv->shadowed = shadowed;
13694 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13696 return widget->priv->alloc_needed;
13700 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13701 gboolean alloc_needed)
13703 widget->priv->alloc_needed = alloc_needed;
13707 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13709 return widget->priv->width_request_needed;
13713 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13714 gboolean width_request_needed)
13716 widget->priv->width_request_needed = width_request_needed;
13720 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13722 return widget->priv->height_request_needed;
13726 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13727 gboolean height_request_needed)
13729 widget->priv->height_request_needed = height_request_needed;
13733 * gtk_widget_get_path:
13734 * @widget: a #GtkWidget
13736 * Returns the #GtkWidgetPath representing @widget, if the widget
13737 * is not connected to a toplevel widget, a partial path will be
13740 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13743 gtk_widget_get_path (GtkWidget *widget)
13745 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13747 /* As strange as it may seem, this may happen on object construction.
13748 * init() implementations of parent types may eventually call this function,
13749 * each with its corresponding GType, which could leave a child
13750 * implementation with a wrong widget type in the widget path
13752 if (widget->priv->path &&
13753 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13755 gtk_widget_path_free (widget->priv->path);
13756 widget->priv->path = NULL;
13759 if (!widget->priv->path)
13764 parent = widget->priv->parent;
13767 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13770 /* Widget is either toplevel or unparented, treat both
13771 * as toplevels style wise, since there are situations
13772 * where style properties might be retrieved on that
13775 widget->priv->path = gtk_widget_path_new ();
13778 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13780 if (widget->priv->name)
13781 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13783 if (widget->priv->context)
13784 gtk_style_context_set_path (widget->priv->context,
13785 widget->priv->path);
13788 return widget->priv->path;
13792 style_context_changed (GtkStyleContext *context,
13793 gpointer user_data)
13795 GtkWidget *widget = user_data;
13797 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13801 * gtk_widget_get_style_context:
13802 * @widget: a #GtkWidget
13804 * Returns the style context associated to @widget.
13806 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13807 * must not be freed.
13810 gtk_widget_get_style_context (GtkWidget *widget)
13812 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13814 if (G_UNLIKELY (!widget->priv->context))
13816 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13817 "direction", gtk_widget_get_direction (widget),
13820 g_signal_connect (widget->priv->context, "changed",
13821 G_CALLBACK (style_context_changed), widget);
13823 gtk_style_context_set_screen (widget->priv->context,
13824 gtk_widget_get_screen (widget));
13826 _gtk_widget_update_path (widget);
13827 gtk_style_context_set_path (widget->priv->context,
13828 widget->priv->path);
13832 /* Force widget path regeneration if needed, the
13833 * context will be updated within this function.
13835 gtk_widget_get_path (widget);
13838 return widget->priv->context;