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/.
33 #include <gobject/gvaluecollector.h>
34 #include <gobject/gobjectnotifyqueue.c>
35 #include <cairo-gobject.h>
37 #include "gtkcontainer.h"
38 #include "gtkaccelmap.h"
39 #include "gtkclipboard.h"
40 #include "gtkiconfactory.h"
42 #include "gtkmainprivate.h"
43 #include "gtkmarshalers.h"
45 #include "gtkselection.h"
46 #include "gtksettingsprivate.h"
47 #include "gtksizegroup-private.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.h"
51 #include "gtkbindings.h"
52 #include "gtkprivate.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"
66 #include "gtktypebuiltins.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_width_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="AtkObject::name">Clickable Button</property>
281 * ]]></programlisting>
286 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
287 #define INIT_PATH_SIZE (512)
289 struct _GtkWidgetPrivate
291 /* The state of the widget. There are actually only
292 * 5 widget states (defined in "gtkenums.h")
295 guint state_flags : 6;
299 guint in_destruction : 1;
302 guint composite_child : 1;
308 guint parent_sensitive : 1;
311 guint can_default : 1;
312 guint has_default : 1;
313 guint receives_default : 1;
317 guint style_update_pending : 1;
318 guint app_paintable : 1;
319 guint double_buffered : 1;
320 guint redraw_on_alloc : 1;
321 guint no_show_all : 1;
322 guint child_visible : 1;
323 guint multidevice : 1;
324 guint has_shape_mask : 1;
325 guint in_reparent : 1;
326 guint resize_pending : 1;
327 guint alloc_needed : 1;
328 guint width_request_needed : 1;
329 guint height_request_needed : 1;
331 /* Expand-related flags */
332 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
333 guint computed_hexpand : 1; /* computed results (composite of child flags) */
334 guint computed_vexpand : 1;
335 guint hexpand : 1; /* application-forced expand */
337 guint hexpand_set : 1; /* whether to use application-forced */
338 guint vexpand_set : 1; /* instead of computing from children */
340 /* The widget's name. If the widget does not have a name
341 * (the name is NULL), then its name (as returned by
342 * "gtk_widget_get_name") is its class's name.
343 * Among other things, the widget name is used to determine
344 * the style to use for a widget.
348 /* The style for the widget. The style contains the
349 * colors the widget should be drawn in for each state
350 * along with graphics contexts used to draw with and
351 * the font to use for text.
354 GtkStyleContext *context;
356 /* The widget's allocated size.
358 GtkAllocation allocation;
360 /* The widget's requested sizes */
361 SizeRequestCache requests;
363 /* The widget's window or its parent window if it does
364 * not have a window. (Which will be indicated by the
365 * GTK_NO_WINDOW flag being set).
369 /* The widget's parent.
373 #ifdef G_ENABLE_DEBUG
374 /* Number of gtk_widget_push_verify_invariants () */
375 guint verifying_invariants_count;
376 #endif /* G_ENABLE_DEBUG */
378 /* Widget's path for styling */
408 BUTTON_RELEASE_EVENT,
423 PROPERTY_NOTIFY_EVENT,
424 SELECTION_CLEAR_EVENT,
425 SELECTION_REQUEST_EVENT,
426 SELECTION_NOTIFY_EVENT,
432 VISIBILITY_NOTIFY_EVENT,
446 ACCEL_CLOSURES_CHANGED,
470 PROP_RECEIVES_DEFAULT,
471 PROP_COMPOSITE_CHILD,
479 PROP_DOUBLE_BUFFERED,
494 typedef struct _GtkStateData GtkStateData;
497 STATE_CHANGE_REPLACE,
506 guint parent_sensitive : 1;
507 guint use_forall : 1;
510 /* --- prototypes --- */
511 static void gtk_widget_class_init (GtkWidgetClass *klass);
512 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
513 static void gtk_widget_init (GtkWidget *widget);
514 static void gtk_widget_set_property (GObject *object,
518 static void gtk_widget_get_property (GObject *object,
522 static void gtk_widget_dispose (GObject *object);
523 static void gtk_widget_real_destroy (GtkWidget *object);
524 static void gtk_widget_finalize (GObject *object);
525 static void gtk_widget_real_show (GtkWidget *widget);
526 static void gtk_widget_real_hide (GtkWidget *widget);
527 static void gtk_widget_real_map (GtkWidget *widget);
528 static void gtk_widget_real_unmap (GtkWidget *widget);
529 static void gtk_widget_real_realize (GtkWidget *widget);
530 static void gtk_widget_real_unrealize (GtkWidget *widget);
531 static void gtk_widget_real_size_allocate (GtkWidget *widget,
532 GtkAllocation *allocation);
533 static void gtk_widget_real_style_set (GtkWidget *widget,
534 GtkStyle *previous_style);
535 static void gtk_widget_real_direction_changed(GtkWidget *widget,
536 GtkTextDirection previous_direction);
538 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
539 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
542 gboolean keyboard_tip,
543 GtkTooltip *tooltip);
544 static void gtk_widget_real_style_updated (GtkWidget *widget);
545 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
546 GtkWidgetHelpType help_type);
548 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
550 GParamSpec **pspecs);
551 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
553 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
555 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
556 GdkEventFocus *event);
557 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
558 GdkEventFocus *event);
559 static gboolean gtk_widget_real_focus (GtkWidget *widget,
560 GtkDirectionType direction);
561 static void gtk_widget_real_move_focus (GtkWidget *widget,
562 GtkDirectionType direction);
563 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
564 GtkDirectionType direction);
565 #ifdef G_ENABLE_DEBUG
566 static void gtk_widget_verify_invariants (GtkWidget *widget);
567 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
568 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
570 #define gtk_widget_verify_invariants(widget)
571 #define gtk_widget_push_verify_invariants(widget)
572 #define gtk_widget_pop_verify_invariants(widget)
574 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
575 static void gtk_widget_update_pango_context (GtkWidget *widget);
576 static void gtk_widget_propagate_state (GtkWidget *widget,
579 static gint gtk_widget_event_internal (GtkWidget *widget,
581 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
582 gboolean group_cycling);
583 static void gtk_widget_real_get_width (GtkWidget *widget,
586 static void gtk_widget_real_get_height (GtkWidget *widget,
589 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
591 gint *minimum_height,
592 gint *natural_height);
593 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
596 gint *natural_width);
597 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
598 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
599 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
600 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
601 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
602 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
603 cairo_region_t *region);
604 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
605 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
606 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
609 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
610 gboolean has_tooltip,
612 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
613 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
615 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
616 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
618 const gchar *childname);
619 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
622 const GValue *value);
623 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
626 const gchar *tagname,
627 GMarkupParser *parser,
629 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
632 const gchar *tagname,
634 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
635 GtkBuilder *builder);
637 static void gtk_widget_real_get_width (GtkWidget *widget,
640 static void gtk_widget_real_get_height (GtkWidget *widget,
644 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
647 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
648 GtkOrientation orientation,
651 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
652 GtkOrientation orientation,
656 gint *allocated_size);
658 static void gtk_widget_set_usize_internal (GtkWidget *widget,
661 GtkQueueResizeFlags flags);
663 static void gtk_widget_add_events_internal (GtkWidget *widget,
667 /* --- variables --- */
668 static gpointer gtk_widget_parent_class = NULL;
669 static guint widget_signals[LAST_SIGNAL] = { 0 };
670 static GtkStyle *gtk_default_style = NULL;
671 static guint composite_child_stack = 0;
672 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
673 static GParamSpecPool *style_property_spec_pool = NULL;
675 static GQuark quark_property_parser = 0;
676 static GQuark quark_aux_info = 0;
677 static GQuark quark_accel_path = 0;
678 static GQuark quark_accel_closures = 0;
679 static GQuark quark_event_mask = 0;
680 static GQuark quark_device_event_mask = 0;
681 static GQuark quark_parent_window = 0;
682 static GQuark quark_pointer_window = 0;
683 static GQuark quark_shape_info = 0;
684 static GQuark quark_input_shape_info = 0;
685 static GQuark quark_pango_context = 0;
686 static GQuark quark_rc_style = 0;
687 static GQuark quark_accessible_object = 0;
688 static GQuark quark_mnemonic_labels = 0;
689 static GQuark quark_tooltip_markup = 0;
690 static GQuark quark_has_tooltip = 0;
691 static GQuark quark_tooltip_window = 0;
692 static GQuark quark_visual = 0;
693 static GQuark quark_modifier_style = 0;
694 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
695 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
697 /* --- functions --- */
699 gtk_widget_get_type (void)
701 static GType widget_type = 0;
703 if (G_UNLIKELY (widget_type == 0))
705 const GTypeInfo widget_info =
707 sizeof (GtkWidgetClass),
708 NULL, /* base_init */
709 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
710 (GClassInitFunc) gtk_widget_class_init,
711 NULL, /* class_finalize */
712 NULL, /* class_init */
715 (GInstanceInitFunc) gtk_widget_init,
716 NULL, /* value_table */
719 const GInterfaceInfo accessibility_info =
721 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
722 (GInterfaceFinalizeFunc) NULL,
723 NULL /* interface data */
726 const GInterfaceInfo buildable_info =
728 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
729 (GInterfaceFinalizeFunc) NULL,
730 NULL /* interface data */
733 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
734 &widget_info, G_TYPE_FLAG_ABSTRACT);
736 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
737 &accessibility_info) ;
738 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
746 child_property_notify_dispatcher (GObject *object,
750 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
753 /* We guard against the draw signal callbacks modifying the state of the
754 * cairo context by surounding it with save/restore.
755 * Maybe we should also cairo_new_path() just to be sure?
758 gtk_widget_draw_marshaller (GClosure *closure,
759 GValue *return_value,
760 guint n_param_values,
761 const GValue *param_values,
762 gpointer invocation_hint,
763 gpointer marshal_data)
765 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
769 _gtk_marshal_BOOLEAN__BOXED (closure,
780 gtk_widget_class_init (GtkWidgetClass *klass)
782 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
783 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
784 GtkBindingSet *binding_set;
786 gtk_widget_parent_class = g_type_class_peek_parent (klass);
788 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
789 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
790 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
791 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
792 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
793 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
794 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
795 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
796 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
797 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
798 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
799 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
800 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
801 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
802 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
803 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
804 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
805 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
806 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
808 style_property_spec_pool = g_param_spec_pool_new (FALSE);
809 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
810 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
811 cpn_context.dispatcher = child_property_notify_dispatcher;
812 _gtk_widget_child_property_notify_context = &cpn_context;
814 gobject_class->dispose = gtk_widget_dispose;
815 gobject_class->finalize = gtk_widget_finalize;
816 gobject_class->set_property = gtk_widget_set_property;
817 gobject_class->get_property = gtk_widget_get_property;
819 klass->destroy = gtk_widget_real_destroy;
821 klass->activate_signal = 0;
822 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
823 klass->show = gtk_widget_real_show;
824 klass->show_all = gtk_widget_show;
825 klass->hide = gtk_widget_real_hide;
826 klass->map = gtk_widget_real_map;
827 klass->unmap = gtk_widget_real_unmap;
828 klass->realize = gtk_widget_real_realize;
829 klass->unrealize = gtk_widget_real_unrealize;
830 klass->size_allocate = gtk_widget_real_size_allocate;
831 klass->get_preferred_width = gtk_widget_real_get_width;
832 klass->get_preferred_height = gtk_widget_real_get_height;
833 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
834 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
835 klass->state_changed = NULL;
836 klass->parent_set = NULL;
837 klass->hierarchy_changed = NULL;
838 klass->style_set = gtk_widget_real_style_set;
839 klass->direction_changed = gtk_widget_real_direction_changed;
840 klass->grab_notify = NULL;
841 klass->child_notify = NULL;
843 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
844 klass->grab_focus = gtk_widget_real_grab_focus;
845 klass->focus = gtk_widget_real_focus;
846 klass->move_focus = gtk_widget_real_move_focus;
847 klass->keynav_failed = gtk_widget_real_keynav_failed;
849 klass->button_press_event = NULL;
850 klass->button_release_event = NULL;
851 klass->motion_notify_event = NULL;
852 klass->delete_event = NULL;
853 klass->destroy_event = NULL;
854 klass->key_press_event = gtk_widget_real_key_press_event;
855 klass->key_release_event = gtk_widget_real_key_release_event;
856 klass->enter_notify_event = NULL;
857 klass->leave_notify_event = NULL;
858 klass->configure_event = NULL;
859 klass->focus_in_event = gtk_widget_real_focus_in_event;
860 klass->focus_out_event = gtk_widget_real_focus_out_event;
861 klass->map_event = NULL;
862 klass->unmap_event = NULL;
863 klass->window_state_event = NULL;
864 klass->property_notify_event = _gtk_selection_property_notify;
865 klass->selection_clear_event = _gtk_selection_clear;
866 klass->selection_request_event = _gtk_selection_request;
867 klass->selection_notify_event = _gtk_selection_notify;
868 klass->selection_received = NULL;
869 klass->proximity_in_event = NULL;
870 klass->proximity_out_event = NULL;
871 klass->drag_begin = NULL;
872 klass->drag_end = NULL;
873 klass->drag_data_delete = NULL;
874 klass->drag_leave = NULL;
875 klass->drag_motion = NULL;
876 klass->drag_drop = NULL;
877 klass->drag_data_received = NULL;
878 klass->screen_changed = NULL;
879 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
880 klass->grab_broken_event = NULL;
881 klass->query_tooltip = gtk_widget_real_query_tooltip;
882 klass->style_updated = gtk_widget_real_style_updated;
884 klass->show_help = gtk_widget_real_show_help;
886 /* Accessibility support */
887 klass->get_accessible = gtk_widget_real_get_accessible;
889 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
890 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
892 g_object_class_install_property (gobject_class,
894 g_param_spec_string ("name",
896 P_("The name of the widget"),
898 GTK_PARAM_READWRITE));
899 g_object_class_install_property (gobject_class,
901 g_param_spec_object ("parent",
903 P_("The parent widget of this widget. Must be a Container widget"),
905 GTK_PARAM_READWRITE));
907 g_object_class_install_property (gobject_class,
909 g_param_spec_int ("width-request",
911 P_("Override for width request of the widget, or -1 if natural request should be used"),
915 GTK_PARAM_READWRITE));
916 g_object_class_install_property (gobject_class,
918 g_param_spec_int ("height-request",
919 P_("Height request"),
920 P_("Override for height request of the widget, or -1 if natural request should be used"),
924 GTK_PARAM_READWRITE));
925 g_object_class_install_property (gobject_class,
927 g_param_spec_boolean ("visible",
929 P_("Whether the widget is visible"),
931 GTK_PARAM_READWRITE));
932 g_object_class_install_property (gobject_class,
934 g_param_spec_boolean ("sensitive",
936 P_("Whether the widget responds to input"),
938 GTK_PARAM_READWRITE));
939 g_object_class_install_property (gobject_class,
941 g_param_spec_boolean ("app-paintable",
942 P_("Application paintable"),
943 P_("Whether the application will paint directly on the widget"),
945 GTK_PARAM_READWRITE));
946 g_object_class_install_property (gobject_class,
948 g_param_spec_boolean ("can-focus",
950 P_("Whether the widget can accept the input focus"),
952 GTK_PARAM_READWRITE));
953 g_object_class_install_property (gobject_class,
955 g_param_spec_boolean ("has-focus",
957 P_("Whether the widget has the input focus"),
959 GTK_PARAM_READWRITE));
960 g_object_class_install_property (gobject_class,
962 g_param_spec_boolean ("is-focus",
964 P_("Whether the widget is the focus widget within the toplevel"),
966 GTK_PARAM_READWRITE));
967 g_object_class_install_property (gobject_class,
969 g_param_spec_boolean ("can-default",
971 P_("Whether the widget can be the default widget"),
973 GTK_PARAM_READWRITE));
974 g_object_class_install_property (gobject_class,
976 g_param_spec_boolean ("has-default",
978 P_("Whether the widget is the default widget"),
980 GTK_PARAM_READWRITE));
981 g_object_class_install_property (gobject_class,
982 PROP_RECEIVES_DEFAULT,
983 g_param_spec_boolean ("receives-default",
984 P_("Receives default"),
985 P_("If TRUE, the widget will receive the default action when it is focused"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
989 PROP_COMPOSITE_CHILD,
990 g_param_spec_boolean ("composite-child",
991 P_("Composite child"),
992 P_("Whether the widget is part of a composite widget"),
994 GTK_PARAM_READABLE));
995 g_object_class_install_property (gobject_class,
997 g_param_spec_object ("style",
999 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1001 GTK_PARAM_READWRITE));
1002 g_object_class_install_property (gobject_class,
1004 g_param_spec_flags ("events",
1006 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1007 GDK_TYPE_EVENT_MASK,
1009 GTK_PARAM_READWRITE));
1010 g_object_class_install_property (gobject_class,
1012 g_param_spec_boolean ("no-show-all",
1014 P_("Whether gtk_widget_show_all() should not affect this widget"),
1016 GTK_PARAM_READWRITE));
1019 * GtkWidget:has-tooltip:
1021 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1022 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1023 * the widget will be queried using #GtkWidget::query-tooltip to determine
1024 * whether it will provide a tooltip or not.
1026 * Note that setting this property to %TRUE for the first time will change
1027 * the event masks of the GdkWindows of this widget to include leave-notify
1028 * and motion-notify events. This cannot and will not be undone when the
1029 * property is set to %FALSE again.
1033 g_object_class_install_property (gobject_class,
1035 g_param_spec_boolean ("has-tooltip",
1037 P_("Whether this widget has a tooltip"),
1039 GTK_PARAM_READWRITE));
1041 * GtkWidget:tooltip-text:
1043 * Sets the text of tooltip to be the given string.
1045 * Also see gtk_tooltip_set_text().
1047 * This is a convenience property which will take care of getting the
1048 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1049 * will automatically be set to %TRUE and there will be taken care of
1050 * #GtkWidget::query-tooltip in the default signal handler.
1054 g_object_class_install_property (gobject_class,
1056 g_param_spec_string ("tooltip-text",
1058 P_("The contents of the tooltip for this widget"),
1060 GTK_PARAM_READWRITE));
1062 * GtkWidget:tooltip-markup:
1064 * Sets the text of tooltip to be the given string, which is marked up
1065 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1066 * Also see gtk_tooltip_set_markup().
1068 * This is a convenience property which will take care of getting the
1069 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1070 * will automatically be set to %TRUE and there will be taken care of
1071 * #GtkWidget::query-tooltip in the default signal handler.
1075 g_object_class_install_property (gobject_class,
1076 PROP_TOOLTIP_MARKUP,
1077 g_param_spec_string ("tooltip-markup",
1078 P_("Tooltip markup"),
1079 P_("The contents of the tooltip for this widget"),
1081 GTK_PARAM_READWRITE));
1086 * The widget's window if it is realized, %NULL otherwise.
1090 g_object_class_install_property (gobject_class,
1092 g_param_spec_object ("window",
1094 P_("The widget's window if it is realized"),
1096 GTK_PARAM_READABLE));
1099 * GtkWidget:double-buffered
1101 * Whether the widget is double buffered.
1105 g_object_class_install_property (gobject_class,
1106 PROP_DOUBLE_BUFFERED,
1107 g_param_spec_boolean ("double-buffered",
1108 P_("Double Buffered"),
1109 P_("Whether the widget is double buffered"),
1111 GTK_PARAM_READWRITE));
1116 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1120 g_object_class_install_property (gobject_class,
1122 g_param_spec_enum ("halign",
1123 P_("Horizontal Alignment"),
1124 P_("How to position in extra horizontal space"),
1127 GTK_PARAM_READWRITE));
1132 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1136 g_object_class_install_property (gobject_class,
1138 g_param_spec_enum ("valign",
1139 P_("Vertical Alignment"),
1140 P_("How to position in extra vertical space"),
1143 GTK_PARAM_READWRITE));
1146 * GtkWidget:margin-left
1148 * Margin on left side of widget.
1150 * This property adds margin outside of the widget's normal size
1151 * request, the margin will be added in addition to the size from
1152 * gtk_widget_set_size_request() for example.
1156 g_object_class_install_property (gobject_class,
1158 g_param_spec_int ("margin-left",
1159 P_("Margin on Left"),
1160 P_("Pixels of extra space on the left side"),
1164 GTK_PARAM_READWRITE));
1167 * GtkWidget:margin-right
1169 * Margin on right side of widget.
1171 * This property adds margin outside of the widget's normal size
1172 * request, the margin will be added in addition to the size from
1173 * gtk_widget_set_size_request() for example.
1177 g_object_class_install_property (gobject_class,
1179 g_param_spec_int ("margin-right",
1180 P_("Margin on Right"),
1181 P_("Pixels of extra space on the right side"),
1185 GTK_PARAM_READWRITE));
1188 * GtkWidget:margin-top
1190 * Margin on top side of widget.
1192 * This property adds margin outside of the widget's normal size
1193 * request, the margin will be added in addition to the size from
1194 * gtk_widget_set_size_request() for example.
1198 g_object_class_install_property (gobject_class,
1200 g_param_spec_int ("margin-top",
1201 P_("Margin on Top"),
1202 P_("Pixels of extra space on the top side"),
1206 GTK_PARAM_READWRITE));
1209 * GtkWidget:margin-bottom
1211 * Margin on bottom side of widget.
1213 * This property adds margin outside of the widget's normal size
1214 * request, the margin will be added in addition to the size from
1215 * gtk_widget_set_size_request() for example.
1219 g_object_class_install_property (gobject_class,
1221 g_param_spec_int ("margin-bottom",
1222 P_("Margin on Bottom"),
1223 P_("Pixels of extra space on the bottom side"),
1227 GTK_PARAM_READWRITE));
1232 * Sets all four sides' margin at once. If read, returns max
1233 * margin on any side.
1237 g_object_class_install_property (gobject_class,
1239 g_param_spec_int ("margin",
1241 P_("Pixels of extra space on all four sides"),
1245 GTK_PARAM_READWRITE));
1248 * GtkWidget::destroy:
1249 * @object: the object which received the signal
1251 * Signals that all holders of a reference to the widget should release
1252 * the reference that they hold. May result in finalization of the widget
1253 * if all references are released.
1255 widget_signals[DESTROY] =
1256 g_signal_new (I_("destroy"),
1257 G_TYPE_FROM_CLASS (gobject_class),
1258 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1259 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1261 _gtk_marshal_VOID__VOID,
1267 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1271 g_object_class_install_property (gobject_class,
1273 g_param_spec_boolean ("hexpand",
1274 P_("Horizontal Expand"),
1275 P_("Whether widget wants more horizontal space"),
1277 GTK_PARAM_READWRITE));
1280 * GtkWidget:hexpand-set
1282 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1286 g_object_class_install_property (gobject_class,
1288 g_param_spec_boolean ("hexpand-set",
1289 P_("Horizontal Expand Set"),
1290 P_("Whether to use the hexpand property"),
1292 GTK_PARAM_READWRITE));
1297 * Whether to expand vertically. See gtk_widget_set_vexpand().
1301 g_object_class_install_property (gobject_class,
1303 g_param_spec_boolean ("vexpand",
1304 P_("Vertical Expand"),
1305 P_("Whether widget wants more vertical space"),
1307 GTK_PARAM_READWRITE));
1310 * GtkWidget:vexpand-set
1312 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1316 g_object_class_install_property (gobject_class,
1318 g_param_spec_boolean ("vexpand-set",
1319 P_("Vertical Expand Set"),
1320 P_("Whether to use the vexpand property"),
1322 GTK_PARAM_READWRITE));
1327 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1331 g_object_class_install_property (gobject_class,
1333 g_param_spec_boolean ("expand",
1335 P_("Whether widget wants to expand in both directions"),
1337 GTK_PARAM_READWRITE));
1341 * @widget: the object which received the signal.
1343 widget_signals[SHOW] =
1344 g_signal_new (I_("show"),
1345 G_TYPE_FROM_CLASS (gobject_class),
1347 G_STRUCT_OFFSET (GtkWidgetClass, show),
1349 _gtk_marshal_VOID__VOID,
1354 * @widget: the object which received the signal.
1356 widget_signals[HIDE] =
1357 g_signal_new (I_("hide"),
1358 G_TYPE_FROM_CLASS (gobject_class),
1360 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1362 _gtk_marshal_VOID__VOID,
1367 * @widget: the object which received the signal.
1369 widget_signals[MAP] =
1370 g_signal_new (I_("map"),
1371 G_TYPE_FROM_CLASS (gobject_class),
1373 G_STRUCT_OFFSET (GtkWidgetClass, map),
1375 _gtk_marshal_VOID__VOID,
1380 * @widget: the object which received the signal.
1382 widget_signals[UNMAP] =
1383 g_signal_new (I_("unmap"),
1384 G_TYPE_FROM_CLASS (gobject_class),
1386 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1388 _gtk_marshal_VOID__VOID,
1392 * GtkWidget::realize:
1393 * @widget: the object which received the signal.
1395 widget_signals[REALIZE] =
1396 g_signal_new (I_("realize"),
1397 G_TYPE_FROM_CLASS (gobject_class),
1399 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1401 _gtk_marshal_VOID__VOID,
1405 * GtkWidget::unrealize:
1406 * @widget: the object which received the signal.
1408 widget_signals[UNREALIZE] =
1409 g_signal_new (I_("unrealize"),
1410 G_TYPE_FROM_CLASS (gobject_class),
1412 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1414 _gtk_marshal_VOID__VOID,
1418 * GtkWidget::size-allocate:
1419 * @widget: the object which received the signal.
1422 widget_signals[SIZE_ALLOCATE] =
1423 g_signal_new (I_("size-allocate"),
1424 G_TYPE_FROM_CLASS (gobject_class),
1426 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1428 _gtk_marshal_VOID__BOXED,
1430 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1433 * GtkWidget::state-changed:
1434 * @widget: the object which received the signal.
1435 * @state: the previous state
1437 * The ::state-changed signal is emitted when the widget state changes.
1438 * See gtk_widget_get_state().
1440 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1442 widget_signals[STATE_CHANGED] =
1443 g_signal_new (I_("state-changed"),
1444 G_TYPE_FROM_CLASS (gobject_class),
1446 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1448 _gtk_marshal_VOID__ENUM,
1450 GTK_TYPE_STATE_TYPE);
1453 * GtkWidget::state-flags-changed:
1454 * @widget: the object which received the signal.
1455 * @flags: The previous state flags.
1457 * The ::state-flags-changed signal is emitted when the widget state
1458 * changes, see gtk_widget_get_state_flags().
1462 widget_signals[STATE_FLAGS_CHANGED] =
1463 g_signal_new (I_("state-flags-changed"),
1464 G_TYPE_FROM_CLASS (gobject_class),
1466 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1468 _gtk_marshal_VOID__FLAGS,
1470 GTK_TYPE_STATE_FLAGS);
1473 * GtkWidget::parent-set:
1474 * @widget: the object on which the signal is emitted
1475 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1476 * just got its initial parent.
1478 * The ::parent-set signal is emitted when a new parent
1479 * has been set on a widget.
1481 widget_signals[PARENT_SET] =
1482 g_signal_new (I_("parent-set"),
1483 G_TYPE_FROM_CLASS (gobject_class),
1485 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1487 _gtk_marshal_VOID__OBJECT,
1492 * GtkWidget::hierarchy-changed:
1493 * @widget: the object on which the signal is emitted
1494 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1495 * if the widget was previously unanchored
1497 * The ::hierarchy-changed signal is emitted when the
1498 * anchored state of a widget changes. A widget is
1499 * <firstterm>anchored</firstterm> when its toplevel
1500 * ancestor is a #GtkWindow. This signal is emitted when
1501 * a widget changes from un-anchored to anchored or vice-versa.
1503 widget_signals[HIERARCHY_CHANGED] =
1504 g_signal_new (I_("hierarchy-changed"),
1505 G_TYPE_FROM_CLASS (gobject_class),
1507 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1509 _gtk_marshal_VOID__OBJECT,
1514 * GtkWidget::style-set:
1515 * @widget: the object on which the signal is emitted
1516 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1517 * just got its initial style
1519 * The ::style-set signal is emitted when a new style has been set
1520 * on a widget. Note that style-modifying functions like
1521 * gtk_widget_modify_base() also cause this signal to be emitted.
1523 * Note that this signal is emitted for changes to the deprecated
1524 * #GtkStyle. To track changes to the #GtkStyleContext associated
1525 * with a widget, use the #GtkWidget::style-updated signal.
1527 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1529 widget_signals[STYLE_SET] =
1530 g_signal_new (I_("style-set"),
1531 G_TYPE_FROM_CLASS (gobject_class),
1533 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1535 _gtk_marshal_VOID__OBJECT,
1540 * GtkWidget::style-updated:
1541 * @widget: the object on which the signal is emitted
1543 * The ::style-updated signal is emitted when the #GtkStyleContext
1544 * of a widget is changed. Note that style-modifying functions like
1545 * gtk_widget_override_color() also cause this signal to be emitted.
1549 widget_signals[STYLE_UPDATED] =
1550 g_signal_new (I_("style-updated"),
1551 G_TYPE_FROM_CLASS (gobject_class),
1553 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1555 g_cclosure_marshal_VOID__VOID,
1559 * GtkWidget::direction-changed:
1560 * @widget: the object on which the signal is emitted
1561 * @previous_direction: the previous text direction of @widget
1563 * The ::direction-changed signal is emitted when the text direction
1564 * of a widget changes.
1566 widget_signals[DIRECTION_CHANGED] =
1567 g_signal_new (I_("direction-changed"),
1568 G_TYPE_FROM_CLASS (gobject_class),
1570 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1572 _gtk_marshal_VOID__ENUM,
1574 GTK_TYPE_TEXT_DIRECTION);
1577 * GtkWidget::grab-notify:
1578 * @widget: the object which received the signal
1579 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1580 * if it becomes unshadowed
1582 * The ::grab-notify signal is emitted when a widget becomes
1583 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1584 * another widget, or when it becomes unshadowed due to a grab
1587 * A widget is shadowed by a gtk_grab_add() when the topmost
1588 * grab widget in the grab stack of its window group is not
1591 widget_signals[GRAB_NOTIFY] =
1592 g_signal_new (I_("grab-notify"),
1593 G_TYPE_FROM_CLASS (gobject_class),
1595 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1597 _gtk_marshal_VOID__BOOLEAN,
1602 * GtkWidget::child-notify:
1603 * @widget: the object which received the signal
1604 * @pspec: the #GParamSpec of the changed child property
1606 * The ::child-notify signal is emitted for each
1607 * <link linkend="child-properties">child property</link> that has
1608 * changed on an object. The signal's detail holds the property name.
1610 widget_signals[CHILD_NOTIFY] =
1611 g_signal_new (I_("child-notify"),
1612 G_TYPE_FROM_CLASS (gobject_class),
1613 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1614 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1616 g_cclosure_marshal_VOID__PARAM,
1622 * @widget: the object which received the signal
1623 * @cr: the cairo context to draw to
1625 * This signal is emitted when a widget is supposed to render itself.
1626 * The @widget's top left corner must be painted at the origin of
1627 * the passed in context and be sized to the values returned by
1628 * gtk_widget_get_allocated_width() and
1629 * gtk_widget_get_allocated_height().
1631 * Signal handlers connected to this signal can modify the cairo
1632 * context passed as @cr in any way they like and don't need to
1633 * restore it. The signal emission takes care of calling cairo_save()
1634 * before and cairo_restore() after invoking the handler.
1636 widget_signals[DRAW] =
1637 g_signal_new (I_("draw"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1640 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1641 _gtk_boolean_handled_accumulator, NULL,
1642 gtk_widget_draw_marshaller,
1644 CAIRO_GOBJECT_TYPE_CONTEXT);
1647 * GtkWidget::mnemonic-activate:
1648 * @widget: the object which received the signal.
1651 widget_signals[MNEMONIC_ACTIVATE] =
1652 g_signal_new (I_("mnemonic-activate"),
1653 G_TYPE_FROM_CLASS (gobject_class),
1655 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1656 _gtk_boolean_handled_accumulator, NULL,
1657 _gtk_marshal_BOOLEAN__BOOLEAN,
1662 * GtkWidget::grab-focus:
1663 * @widget: the object which received the signal.
1665 widget_signals[GRAB_FOCUS] =
1666 g_signal_new (I_("grab-focus"),
1667 G_TYPE_FROM_CLASS (gobject_class),
1668 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1669 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1671 _gtk_marshal_VOID__VOID,
1676 * @widget: the object which received the signal.
1679 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1681 widget_signals[FOCUS] =
1682 g_signal_new (I_("focus"),
1683 G_TYPE_FROM_CLASS (klass),
1685 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1686 _gtk_boolean_handled_accumulator, NULL,
1687 _gtk_marshal_BOOLEAN__ENUM,
1689 GTK_TYPE_DIRECTION_TYPE);
1692 * GtkWidget::move-focus:
1693 * @widget: the object which received the signal.
1696 widget_signals[MOVE_FOCUS] =
1697 g_signal_new (I_("move-focus"),
1698 G_TYPE_FROM_CLASS (klass),
1699 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1700 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1702 _gtk_marshal_VOID__ENUM,
1705 GTK_TYPE_DIRECTION_TYPE);
1708 * GtkWidget::keynav-failed:
1709 * @widget: the object which received the signal
1710 * @direction: the direction of movement
1712 * Gets emitted if keyboard navigation fails.
1713 * See gtk_widget_keynav_failed() for details.
1715 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1716 * if the emitting widget should try to handle the keyboard
1717 * navigation attempt in its parent container(s).
1721 widget_signals[KEYNAV_FAILED] =
1722 g_signal_new (I_("keynav-failed"),
1723 G_TYPE_FROM_CLASS (klass),
1725 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1726 _gtk_boolean_handled_accumulator, NULL,
1727 _gtk_marshal_BOOLEAN__ENUM,
1729 GTK_TYPE_DIRECTION_TYPE);
1733 * @widget: the object which received the signal.
1734 * @event: the #GdkEvent which triggered this signal
1736 * The GTK+ main loop will emit three signals for each GDK event delivered
1737 * to a widget: one generic ::event signal, another, more specific,
1738 * signal that matches the type of event delivered (e.g.
1739 * #GtkWidget::key-press-event) and finally a generic
1740 * #GtkWidget::event-after signal.
1742 * Returns: %TRUE to stop other handlers from being invoked for the event
1743 * and to cancel the emission of the second specific ::event signal.
1744 * %FALSE to propagate the event further and to allow the emission of
1745 * the second signal. The ::event-after signal is emitted regardless of
1748 widget_signals[EVENT] =
1749 g_signal_new (I_("event"),
1750 G_TYPE_FROM_CLASS (klass),
1752 G_STRUCT_OFFSET (GtkWidgetClass, event),
1753 _gtk_boolean_handled_accumulator, NULL,
1754 _gtk_marshal_BOOLEAN__BOXED,
1756 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1759 * GtkWidget::event-after:
1760 * @widget: the object which received the signal.
1761 * @event: the #GdkEvent which triggered this signal
1763 * After the emission of the #GtkWidget::event signal and (optionally)
1764 * the second more specific signal, ::event-after will be emitted
1765 * regardless of the previous two signals handlers return values.
1768 widget_signals[EVENT_AFTER] =
1769 g_signal_new (I_("event-after"),
1770 G_TYPE_FROM_CLASS (klass),
1774 _gtk_marshal_VOID__BOXED,
1776 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1779 * GtkWidget::button-press-event:
1780 * @widget: the object which received the signal.
1781 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1784 * The ::button-press-event signal will be emitted when a button
1785 * (typically from a mouse) is pressed.
1787 * To receive this signal, the #GdkWindow associated to the
1788 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1790 * This signal will be sent to the grab widget if there is one.
1792 * Returns: %TRUE to stop other handlers from being invoked for the event.
1793 * %FALSE to propagate the event further.
1795 widget_signals[BUTTON_PRESS_EVENT] =
1796 g_signal_new (I_("button-press-event"),
1797 G_TYPE_FROM_CLASS (klass),
1799 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1800 _gtk_boolean_handled_accumulator, NULL,
1801 _gtk_marshal_BOOLEAN__BOXED,
1803 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1806 * GtkWidget::button-release-event:
1807 * @widget: the object which received the signal.
1808 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1811 * The ::button-release-event signal will be emitted when a button
1812 * (typically from a mouse) is released.
1814 * To receive this signal, the #GdkWindow associated to the
1815 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1817 * This signal will be sent to the grab widget if there is one.
1819 * Returns: %TRUE to stop other handlers from being invoked for the event.
1820 * %FALSE to propagate the event further.
1822 widget_signals[BUTTON_RELEASE_EVENT] =
1823 g_signal_new (I_("button-release-event"),
1824 G_TYPE_FROM_CLASS (klass),
1826 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1827 _gtk_boolean_handled_accumulator, NULL,
1828 _gtk_marshal_BOOLEAN__BOXED,
1830 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1833 * GtkWidget::scroll-event:
1834 * @widget: the object which received the signal.
1835 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1838 * The ::scroll-event signal is emitted when a button in the 4 to 7
1839 * range is pressed. Wheel mice are usually configured to generate
1840 * button press events for buttons 4 and 5 when the wheel is turned.
1842 * To receive this signal, the #GdkWindow associated to the widget needs
1843 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1845 * This signal will be sent to the grab widget if there is one.
1847 * Returns: %TRUE to stop other handlers from being invoked for the event.
1848 * %FALSE to propagate the event further.
1850 widget_signals[SCROLL_EVENT] =
1851 g_signal_new (I_("scroll-event"),
1852 G_TYPE_FROM_CLASS (klass),
1854 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1855 _gtk_boolean_handled_accumulator, NULL,
1856 _gtk_marshal_BOOLEAN__BOXED,
1858 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1861 * GtkWidget::motion-notify-event:
1862 * @widget: the object which received the signal.
1863 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1866 * The ::motion-notify-event signal is emitted when the pointer moves
1867 * over the widget's #GdkWindow.
1869 * To receive this signal, the #GdkWindow associated to the widget
1870 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1872 * This signal will be sent to the grab widget if there is one.
1874 * Returns: %TRUE to stop other handlers from being invoked for the event.
1875 * %FALSE to propagate the event further.
1877 widget_signals[MOTION_NOTIFY_EVENT] =
1878 g_signal_new (I_("motion-notify-event"),
1879 G_TYPE_FROM_CLASS (klass),
1881 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1882 _gtk_boolean_handled_accumulator, NULL,
1883 _gtk_marshal_BOOLEAN__BOXED,
1885 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1888 * GtkWidget::composited-changed:
1889 * @widget: the object on which the signal is emitted
1891 * The ::composited-changed signal is emitted when the composited
1892 * status of @widget<!-- -->s screen changes.
1893 * See gdk_screen_is_composited().
1895 widget_signals[COMPOSITED_CHANGED] =
1896 g_signal_new (I_("composited-changed"),
1897 G_TYPE_FROM_CLASS (klass),
1898 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1899 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1901 _gtk_marshal_VOID__VOID,
1905 * GtkWidget::delete-event:
1906 * @widget: the object which received the signal
1907 * @event: the event which triggered this signal
1909 * The ::delete-event signal is emitted if a user requests that
1910 * a toplevel window is closed. The default handler for this signal
1911 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1912 * this signal will cause the window to be hidden instead, so that
1913 * it can later be shown again without reconstructing it.
1915 * Returns: %TRUE to stop other handlers from being invoked for the event.
1916 * %FALSE to propagate the event further.
1918 widget_signals[DELETE_EVENT] =
1919 g_signal_new (I_("delete-event"),
1920 G_TYPE_FROM_CLASS (klass),
1922 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1923 _gtk_boolean_handled_accumulator, NULL,
1924 _gtk_marshal_BOOLEAN__BOXED,
1926 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1929 * GtkWidget::destroy-event:
1930 * @widget: the object which received the signal.
1931 * @event: the event which triggered this signal
1933 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1934 * You rarely get this signal, because most widgets disconnect themselves
1935 * from their window before they destroy it, so no widget owns the
1936 * window at destroy time.
1938 * To receive this signal, the #GdkWindow associated to the widget needs
1939 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1940 * automatically for all new windows.
1942 * Returns: %TRUE to stop other handlers from being invoked for the event.
1943 * %FALSE to propagate the event further.
1945 widget_signals[DESTROY_EVENT] =
1946 g_signal_new (I_("destroy-event"),
1947 G_TYPE_FROM_CLASS (klass),
1949 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1950 _gtk_boolean_handled_accumulator, NULL,
1951 _gtk_marshal_BOOLEAN__BOXED,
1953 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1956 * GtkWidget::key-press-event:
1957 * @widget: the object which received the signal
1958 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1960 * The ::key-press-event signal is emitted when a key is pressed.
1962 * To receive this signal, the #GdkWindow associated to the widget needs
1963 * to enable the #GDK_KEY_PRESS_MASK mask.
1965 * This signal will be sent to the grab widget if there is one.
1967 * Returns: %TRUE to stop other handlers from being invoked for the event.
1968 * %FALSE to propagate the event further.
1970 widget_signals[KEY_PRESS_EVENT] =
1971 g_signal_new (I_("key-press-event"),
1972 G_TYPE_FROM_CLASS (klass),
1974 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1975 _gtk_boolean_handled_accumulator, NULL,
1976 _gtk_marshal_BOOLEAN__BOXED,
1978 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1981 * GtkWidget::key-release-event:
1982 * @widget: the object which received the signal
1983 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1985 * The ::key-release-event signal is emitted when a key is pressed.
1987 * To receive this signal, the #GdkWindow associated to the widget needs
1988 * to enable the #GDK_KEY_RELEASE_MASK mask.
1990 * This signal will be sent to the grab widget if there is one.
1992 * Returns: %TRUE to stop other handlers from being invoked for the event.
1993 * %FALSE to propagate the event further.
1995 widget_signals[KEY_RELEASE_EVENT] =
1996 g_signal_new (I_("key-release-event"),
1997 G_TYPE_FROM_CLASS (klass),
1999 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2000 _gtk_boolean_handled_accumulator, NULL,
2001 _gtk_marshal_BOOLEAN__BOXED,
2003 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2006 * GtkWidget::enter-notify-event:
2007 * @widget: the object which received the signal
2008 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2011 * The ::enter-notify-event will be emitted when the pointer enters
2012 * the @widget's window.
2014 * To receive this signal, the #GdkWindow associated to the widget needs
2015 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2017 * This signal will be sent to the grab widget if there is one.
2019 * Returns: %TRUE to stop other handlers from being invoked for the event.
2020 * %FALSE to propagate the event further.
2022 widget_signals[ENTER_NOTIFY_EVENT] =
2023 g_signal_new (I_("enter-notify-event"),
2024 G_TYPE_FROM_CLASS (klass),
2026 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2027 _gtk_boolean_handled_accumulator, NULL,
2028 _gtk_marshal_BOOLEAN__BOXED,
2030 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2033 * GtkWidget::leave-notify-event:
2034 * @widget: the object which received the signal
2035 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2038 * The ::leave-notify-event will be emitted when the pointer leaves
2039 * the @widget's window.
2041 * To receive this signal, the #GdkWindow associated to the widget needs
2042 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2044 * This signal will be sent to the grab widget if there is one.
2046 * Returns: %TRUE to stop other handlers from being invoked for the event.
2047 * %FALSE to propagate the event further.
2049 widget_signals[LEAVE_NOTIFY_EVENT] =
2050 g_signal_new (I_("leave-notify-event"),
2051 G_TYPE_FROM_CLASS (klass),
2053 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2054 _gtk_boolean_handled_accumulator, NULL,
2055 _gtk_marshal_BOOLEAN__BOXED,
2057 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2060 * GtkWidget::configure-event:
2061 * @widget: the object which received the signal
2062 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2065 * The ::configure-event signal will be emitted when the size, position or
2066 * stacking of the @widget's window has changed.
2068 * To receive this signal, the #GdkWindow associated to the widget needs
2069 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2070 * automatically for all new windows.
2072 * Returns: %TRUE to stop other handlers from being invoked for the event.
2073 * %FALSE to propagate the event further.
2075 widget_signals[CONFIGURE_EVENT] =
2076 g_signal_new (I_("configure-event"),
2077 G_TYPE_FROM_CLASS (klass),
2079 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2080 _gtk_boolean_handled_accumulator, NULL,
2081 _gtk_marshal_BOOLEAN__BOXED,
2083 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2086 * GtkWidget::focus-in-event:
2087 * @widget: the object which received the signal
2088 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2091 * The ::focus-in-event signal will be emitted when the keyboard focus
2092 * enters the @widget's window.
2094 * To receive this signal, the #GdkWindow associated to the widget needs
2095 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2097 * Returns: %TRUE to stop other handlers from being invoked for the event.
2098 * %FALSE to propagate the event further.
2100 widget_signals[FOCUS_IN_EVENT] =
2101 g_signal_new (I_("focus-in-event"),
2102 G_TYPE_FROM_CLASS (klass),
2104 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2105 _gtk_boolean_handled_accumulator, NULL,
2106 _gtk_marshal_BOOLEAN__BOXED,
2108 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2111 * GtkWidget::focus-out-event:
2112 * @widget: the object which received the signal
2113 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2116 * The ::focus-out-event signal will be emitted when the keyboard focus
2117 * leaves the @widget's window.
2119 * To receive this signal, the #GdkWindow associated to the widget needs
2120 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2122 * Returns: %TRUE to stop other handlers from being invoked for the event.
2123 * %FALSE to propagate the event further.
2125 widget_signals[FOCUS_OUT_EVENT] =
2126 g_signal_new (I_("focus-out-event"),
2127 G_TYPE_FROM_CLASS (klass),
2129 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2130 _gtk_boolean_handled_accumulator, NULL,
2131 _gtk_marshal_BOOLEAN__BOXED,
2133 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2136 * GtkWidget::map-event:
2137 * @widget: the object which received the signal
2138 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2140 * The ::map-event signal will be emitted when the @widget's window is
2141 * mapped. A window is mapped when it becomes visible on the screen.
2143 * To receive this signal, the #GdkWindow associated to the widget needs
2144 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2145 * automatically for all new windows.
2147 * Returns: %TRUE to stop other handlers from being invoked for the event.
2148 * %FALSE to propagate the event further.
2150 widget_signals[MAP_EVENT] =
2151 g_signal_new (I_("map-event"),
2152 G_TYPE_FROM_CLASS (klass),
2154 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2155 _gtk_boolean_handled_accumulator, NULL,
2156 _gtk_marshal_BOOLEAN__BOXED,
2158 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2161 * GtkWidget::unmap-event:
2162 * @widget: the object which received the signal
2163 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2165 * The ::unmap-event signal will be emitted when the @widget's window is
2166 * unmapped. A window is unmapped when it becomes invisible on the screen.
2168 * To receive this signal, the #GdkWindow associated to the widget needs
2169 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2170 * automatically for all new windows.
2172 * Returns: %TRUE to stop other handlers from being invoked for the event.
2173 * %FALSE to propagate the event further.
2175 widget_signals[UNMAP_EVENT] =
2176 g_signal_new (I_("unmap-event"),
2177 G_TYPE_FROM_CLASS (klass),
2179 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2180 _gtk_boolean_handled_accumulator, NULL,
2181 _gtk_marshal_BOOLEAN__BOXED,
2183 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2186 * GtkWidget::property-notify-event:
2187 * @widget: the object which received the signal
2188 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2191 * The ::property-notify-event signal will be emitted when a property on
2192 * the @widget's window has been changed or deleted.
2194 * To receive this signal, the #GdkWindow associated to the widget needs
2195 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2197 * Returns: %TRUE to stop other handlers from being invoked for the event.
2198 * %FALSE to propagate the event further.
2200 widget_signals[PROPERTY_NOTIFY_EVENT] =
2201 g_signal_new (I_("property-notify-event"),
2202 G_TYPE_FROM_CLASS (klass),
2204 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2205 _gtk_boolean_handled_accumulator, NULL,
2206 _gtk_marshal_BOOLEAN__BOXED,
2208 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2211 * GtkWidget::selection-clear-event:
2212 * @widget: the object which received the signal
2213 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2216 * The ::selection-clear-event signal will be emitted when the
2217 * the @widget's window has lost ownership of a selection.
2219 * Returns: %TRUE to stop other handlers from being invoked for the event.
2220 * %FALSE to propagate the event further.
2222 widget_signals[SELECTION_CLEAR_EVENT] =
2223 g_signal_new (I_("selection-clear-event"),
2224 G_TYPE_FROM_CLASS (klass),
2226 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2227 _gtk_boolean_handled_accumulator, NULL,
2228 _gtk_marshal_BOOLEAN__BOXED,
2230 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2233 * GtkWidget::selection-request-event:
2234 * @widget: the object which received the signal
2235 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2238 * The ::selection-request-event signal will be emitted when
2239 * another client requests ownership of the selection owned by
2240 * the @widget's window.
2242 * Returns: %TRUE to stop other handlers from being invoked for the event.
2243 * %FALSE to propagate the event further.
2245 widget_signals[SELECTION_REQUEST_EVENT] =
2246 g_signal_new (I_("selection-request-event"),
2247 G_TYPE_FROM_CLASS (klass),
2249 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2250 _gtk_boolean_handled_accumulator, NULL,
2251 _gtk_marshal_BOOLEAN__BOXED,
2253 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2256 * GtkWidget::selection-notify-event:
2257 * @widget: the object which received the signal.
2260 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2262 widget_signals[SELECTION_NOTIFY_EVENT] =
2263 g_signal_new (I_("selection-notify-event"),
2264 G_TYPE_FROM_CLASS (klass),
2266 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2267 _gtk_boolean_handled_accumulator, NULL,
2268 _gtk_marshal_BOOLEAN__BOXED,
2270 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2273 * GtkWidget::selection-received:
2274 * @widget: the object which received the signal.
2278 widget_signals[SELECTION_RECEIVED] =
2279 g_signal_new (I_("selection-received"),
2280 G_TYPE_FROM_CLASS (klass),
2282 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2284 _gtk_marshal_VOID__BOXED_UINT,
2286 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2290 * GtkWidget::selection-get:
2291 * @widget: the object which received the signal.
2296 widget_signals[SELECTION_GET] =
2297 g_signal_new (I_("selection-get"),
2298 G_TYPE_FROM_CLASS (klass),
2300 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2302 _gtk_marshal_VOID__BOXED_UINT_UINT,
2304 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2309 * GtkWidget::proximity-in-event:
2310 * @widget: the object which received the signal
2311 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2314 * To receive this signal the #GdkWindow associated to the widget needs
2315 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2317 * This signal will be sent to the grab widget if there is one.
2319 * Returns: %TRUE to stop other handlers from being invoked for the event.
2320 * %FALSE to propagate the event further.
2322 widget_signals[PROXIMITY_IN_EVENT] =
2323 g_signal_new (I_("proximity-in-event"),
2324 G_TYPE_FROM_CLASS (klass),
2326 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2327 _gtk_boolean_handled_accumulator, NULL,
2328 _gtk_marshal_BOOLEAN__BOXED,
2330 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2333 * GtkWidget::proximity-out-event:
2334 * @widget: the object which received the signal
2335 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2338 * To receive this signal the #GdkWindow associated to the widget needs
2339 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2341 * This signal will be sent to the grab widget if there is one.
2343 * Returns: %TRUE to stop other handlers from being invoked for the event.
2344 * %FALSE to propagate the event further.
2346 widget_signals[PROXIMITY_OUT_EVENT] =
2347 g_signal_new (I_("proximity-out-event"),
2348 G_TYPE_FROM_CLASS (klass),
2350 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2351 _gtk_boolean_handled_accumulator, NULL,
2352 _gtk_marshal_BOOLEAN__BOXED,
2354 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2357 * GtkWidget::drag-leave:
2358 * @widget: the object which received the signal.
2359 * @drag_context: the drag context
2360 * @time: the timestamp of the motion event
2362 * The ::drag-leave signal is emitted on the drop site when the cursor
2363 * leaves the widget. A typical reason to connect to this signal is to
2364 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2365 * with gtk_drag_unhighlight()
2367 widget_signals[DRAG_LEAVE] =
2368 g_signal_new (I_("drag-leave"),
2369 G_TYPE_FROM_CLASS (klass),
2371 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2373 _gtk_marshal_VOID__OBJECT_UINT,
2375 GDK_TYPE_DRAG_CONTEXT,
2379 * GtkWidget::drag-begin:
2380 * @widget: the object which received the signal
2381 * @drag_context: the drag context
2383 * The ::drag-begin signal is emitted on the drag source when a drag is
2384 * started. A typical reason to connect to this signal is to set up a
2385 * custom drag icon with gtk_drag_source_set_icon().
2387 * Note that some widgets set up a drag icon in the default handler of
2388 * this signal, so you may have to use g_signal_connect_after() to
2389 * override what the default handler did.
2391 widget_signals[DRAG_BEGIN] =
2392 g_signal_new (I_("drag-begin"),
2393 G_TYPE_FROM_CLASS (klass),
2395 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2397 _gtk_marshal_VOID__OBJECT,
2399 GDK_TYPE_DRAG_CONTEXT);
2402 * GtkWidget::drag-end:
2403 * @widget: the object which received the signal
2404 * @drag_context: the drag context
2406 * The ::drag-end signal is emitted on the drag source when a drag is
2407 * finished. A typical reason to connect to this signal is to undo
2408 * things done in #GtkWidget::drag-begin.
2410 widget_signals[DRAG_END] =
2411 g_signal_new (I_("drag-end"),
2412 G_TYPE_FROM_CLASS (klass),
2414 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2416 _gtk_marshal_VOID__OBJECT,
2418 GDK_TYPE_DRAG_CONTEXT);
2421 * GtkWidget::drag-data-delete:
2422 * @widget: the object which received the signal
2423 * @drag_context: the drag context
2425 * The ::drag-data-delete signal is emitted on the drag source when a drag
2426 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2427 * handler is responsible for deleting the data that has been dropped. What
2428 * "delete" means depends on the context of the drag operation.
2430 widget_signals[DRAG_DATA_DELETE] =
2431 g_signal_new (I_("drag-data-delete"),
2432 G_TYPE_FROM_CLASS (klass),
2434 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2436 _gtk_marshal_VOID__OBJECT,
2438 GDK_TYPE_DRAG_CONTEXT);
2441 * GtkWidget::drag-failed:
2442 * @widget: the object which received the signal
2443 * @drag_context: the drag context
2444 * @result: the result of the drag operation
2446 * The ::drag-failed signal is emitted on the drag source when a drag has
2447 * failed. The signal handler may hook custom code to handle a failed DND
2448 * operation based on the type of error, it returns %TRUE is the failure has
2449 * been already handled (not showing the default "drag operation failed"
2450 * animation), otherwise it returns %FALSE.
2452 * Return value: %TRUE if the failed drag operation has been already handled.
2456 widget_signals[DRAG_FAILED] =
2457 g_signal_new (I_("drag-failed"),
2458 G_TYPE_FROM_CLASS (klass),
2460 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2461 _gtk_boolean_handled_accumulator, NULL,
2462 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2464 GDK_TYPE_DRAG_CONTEXT,
2465 GTK_TYPE_DRAG_RESULT);
2468 * GtkWidget::drag-motion:
2469 * @widget: the object which received the signal
2470 * @drag_context: the drag context
2471 * @x: the x coordinate of the current cursor position
2472 * @y: the y coordinate of the current cursor position
2473 * @time: the timestamp of the motion event
2474 * @returns: whether the cursor position is in a drop zone
2476 * The drag-motion signal is emitted on the drop site when the user
2477 * moves the cursor over the widget during a drag. The signal handler
2478 * must determine whether the cursor position is in a drop zone or not.
2479 * If it is not in a drop zone, it returns %FALSE and no further processing
2480 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2481 * handler is responsible for providing the necessary information for
2482 * displaying feedback to the user, by calling gdk_drag_status().
2484 * If the decision whether the drop will be accepted or rejected can't be
2485 * made based solely on the cursor position and the type of the data, the
2486 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2487 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2488 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2489 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2490 * when using the drag-motion signal that way.
2492 * Also note that there is no drag-enter signal. The drag receiver has to
2493 * keep track of whether he has received any drag-motion signals since the
2494 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2495 * an "enter" signal. Upon an "enter", the handler will typically highlight
2496 * the drop site with gtk_drag_highlight().
2499 * drag_motion (GtkWidget *widget,
2500 * GdkDragContext *context,
2507 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2509 * if (!private_data->drag_highlight)
2511 * private_data->drag_highlight = 1;
2512 * gtk_drag_highlight (widget);
2515 * target = gtk_drag_dest_find_target (widget, context, NULL);
2516 * if (target == GDK_NONE)
2517 * gdk_drag_status (context, 0, time);
2520 * private_data->pending_status = context->suggested_action;
2521 * gtk_drag_get_data (widget, context, target, time);
2528 * drag_data_received (GtkWidget *widget,
2529 * GdkDragContext *context,
2532 * GtkSelectionData *selection_data,
2536 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2538 * if (private_data->suggested_action)
2540 * private_data->suggested_action = 0;
2542 * /* We are getting this data due to a request in drag_motion,
2543 * * rather than due to a request in drag_drop, so we are just
2544 * * supposed to call gdk_drag_status (), not actually paste in
2547 * str = gtk_selection_data_get_text (selection_data);
2548 * if (!data_is_acceptable (str))
2549 * gdk_drag_status (context, 0, time);
2551 * gdk_drag_status (context, private_data->suggested_action, time);
2555 * /* accept the drop */
2560 widget_signals[DRAG_MOTION] =
2561 g_signal_new (I_("drag-motion"),
2562 G_TYPE_FROM_CLASS (klass),
2564 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2565 _gtk_boolean_handled_accumulator, NULL,
2566 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2568 GDK_TYPE_DRAG_CONTEXT,
2574 * GtkWidget::drag-drop:
2575 * @widget: the object which received the signal
2576 * @drag_context: the drag context
2577 * @x: the x coordinate of the current cursor position
2578 * @y: the y coordinate of the current cursor position
2579 * @time: the timestamp of the motion event
2580 * @returns: whether the cursor position is in a drop zone
2582 * The ::drag-drop signal is emitted on the drop site when the user drops
2583 * the data onto the widget. The signal handler must determine whether
2584 * the cursor position is in a drop zone or not. If it is not in a drop
2585 * zone, it returns %FALSE and no further processing is necessary.
2586 * Otherwise, the handler returns %TRUE. In this case, the handler must
2587 * ensure that gtk_drag_finish() is called to let the source know that
2588 * the drop is done. The call to gtk_drag_finish() can be done either
2589 * directly or in a #GtkWidget::drag-data-received handler which gets
2590 * triggered by calling gtk_drag_get_data() to receive the data for one
2591 * or more of the supported targets.
2593 widget_signals[DRAG_DROP] =
2594 g_signal_new (I_("drag-drop"),
2595 G_TYPE_FROM_CLASS (klass),
2597 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2598 _gtk_boolean_handled_accumulator, NULL,
2599 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2601 GDK_TYPE_DRAG_CONTEXT,
2607 * GtkWidget::drag-data-get:
2608 * @widget: the object which received the signal
2609 * @drag_context: the drag context
2610 * @data: the #GtkSelectionData to be filled with the dragged data
2611 * @info: the info that has been registered with the target in the
2613 * @time: the timestamp at which the data was requested
2615 * The ::drag-data-get signal is emitted on the drag source when the drop
2616 * site requests the data which is dragged. It is the responsibility of
2617 * the signal handler to fill @data with the data in the format which
2618 * is indicated by @info. See gtk_selection_data_set() and
2619 * gtk_selection_data_set_text().
2621 widget_signals[DRAG_DATA_GET] =
2622 g_signal_new (I_("drag-data-get"),
2623 G_TYPE_FROM_CLASS (klass),
2625 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2627 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2629 GDK_TYPE_DRAG_CONTEXT,
2630 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2635 * GtkWidget::drag-data-received:
2636 * @widget: the object which received the signal
2637 * @drag_context: the drag context
2638 * @x: where the drop happened
2639 * @y: where the drop happened
2640 * @data: the received data
2641 * @info: the info that has been registered with the target in the
2643 * @time: the timestamp at which the data was received
2645 * The ::drag-data-received signal is emitted on the drop site when the
2646 * dragged data has been received. If the data was received in order to
2647 * determine whether the drop will be accepted, the handler is expected
2648 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2649 * If the data was received in response to a #GtkWidget::drag-drop signal
2650 * (and this is the last target to be received), the handler for this
2651 * signal is expected to process the received data and then call
2652 * gtk_drag_finish(), setting the @success parameter depending on whether
2653 * the data was processed successfully.
2655 * The handler may inspect and modify @drag_context->action before calling
2656 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2657 * following example:
2660 * drag_data_received (GtkWidget *widget,
2661 * GdkDragContext *drag_context,
2664 * GtkSelectionData *data,
2668 * if ((data->length >= 0) && (data->format == 8))
2670 * if (drag_context->action == GDK_ACTION_ASK)
2672 * GtkWidget *dialog;
2675 * dialog = gtk_message_dialog_new (NULL,
2676 * GTK_DIALOG_MODAL |
2677 * GTK_DIALOG_DESTROY_WITH_PARENT,
2679 * GTK_BUTTONS_YES_NO,
2680 * "Move the data ?\n");
2681 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2682 * gtk_widget_destroy (dialog);
2684 * if (response == GTK_RESPONSE_YES)
2685 * drag_context->action = GDK_ACTION_MOVE;
2687 * drag_context->action = GDK_ACTION_COPY;
2690 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2694 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2698 widget_signals[DRAG_DATA_RECEIVED] =
2699 g_signal_new (I_("drag-data-received"),
2700 G_TYPE_FROM_CLASS (klass),
2702 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2704 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2706 GDK_TYPE_DRAG_CONTEXT,
2709 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2714 * GtkWidget::visibility-notify-event:
2715 * @widget: the object which received the signal
2716 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2717 * triggered this signal.
2719 * The ::visibility-notify-event will be emitted when the @widget's window
2720 * is obscured or unobscured.
2722 * To receive this signal the #GdkWindow associated to the widget needs
2723 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2725 * Returns: %TRUE to stop other handlers from being invoked for the event.
2726 * %FALSE to propagate the event further.
2728 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2729 g_signal_new (I_("visibility-notify-event"),
2730 G_TYPE_FROM_CLASS (klass),
2732 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2733 _gtk_boolean_handled_accumulator, NULL,
2734 _gtk_marshal_BOOLEAN__BOXED,
2736 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2739 * GtkWidget::client-event:
2740 * @widget: the object which received the signal
2741 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2744 * The ::client-event will be emitted when the @widget's window
2745 * receives a message (via a ClientMessage event) from another
2748 * Returns: %TRUE to stop other handlers from being invoked for
2749 * the event. %FALSE to propagate the event further.
2751 widget_signals[CLIENT_EVENT] =
2752 g_signal_new (I_("client-event"),
2753 G_TYPE_FROM_CLASS (klass),
2755 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2756 _gtk_boolean_handled_accumulator, NULL,
2757 _gtk_marshal_BOOLEAN__BOXED,
2759 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2762 * GtkWidget::window-state-event:
2763 * @widget: the object which received the signal
2764 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2765 * triggered this signal.
2767 * The ::window-state-event will be emitted when the state of the
2768 * toplevel window associated to the @widget changes.
2770 * To receive this signal the #GdkWindow associated to the widget
2771 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2772 * this mask automatically for all new windows.
2774 * Returns: %TRUE to stop other handlers from being invoked for the
2775 * event. %FALSE to propagate the event further.
2777 widget_signals[WINDOW_STATE_EVENT] =
2778 g_signal_new (I_("window-state-event"),
2779 G_TYPE_FROM_CLASS (klass),
2781 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2782 _gtk_boolean_handled_accumulator, NULL,
2783 _gtk_marshal_BOOLEAN__BOXED,
2785 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2788 * GtkWidget::damage-event:
2789 * @widget: the object which received the signal
2790 * @event: the #GdkEventExpose event
2792 * Emitted when a redirected window belonging to @widget gets drawn into.
2793 * The region/area members of the event shows what area of the redirected
2794 * drawable was drawn into.
2796 * Returns: %TRUE to stop other handlers from being invoked for the event.
2797 * %FALSE to propagate the event further.
2801 widget_signals[DAMAGE_EVENT] =
2802 g_signal_new (I_("damage-event"),
2803 G_TYPE_FROM_CLASS (klass),
2805 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2806 _gtk_boolean_handled_accumulator, NULL,
2807 _gtk_marshal_BOOLEAN__BOXED,
2809 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2812 * GtkWidget::grab-broken-event:
2813 * @widget: the object which received the signal
2814 * @event: the #GdkEventGrabBroken event
2816 * Emitted when a pointer or keyboard grab on a window belonging
2817 * to @widget gets broken.
2819 * On X11, this happens when the grab window becomes unviewable
2820 * (i.e. it or one of its ancestors is unmapped), or if the same
2821 * application grabs the pointer or keyboard again.
2823 * Returns: %TRUE to stop other handlers from being invoked for
2824 * the event. %FALSE to propagate the event further.
2828 widget_signals[GRAB_BROKEN_EVENT] =
2829 g_signal_new (I_("grab-broken-event"),
2830 G_TYPE_FROM_CLASS (klass),
2832 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2833 _gtk_boolean_handled_accumulator, NULL,
2834 _gtk_marshal_BOOLEAN__BOXED,
2836 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2839 * GtkWidget::query-tooltip:
2840 * @widget: the object which received the signal
2841 * @x: the x coordinate of the cursor position where the request has
2842 * been emitted, relative to @widget->window
2843 * @y: the y coordinate of the cursor position where the request has
2844 * been emitted, relative to @widget->window
2845 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2846 * @tooltip: a #GtkTooltip
2848 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2849 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2850 * focus in keyboard mode.
2852 * Using the given coordinates, the signal handler should determine
2853 * whether a tooltip should be shown for @widget. If this is the case
2854 * %TRUE should be returned, %FALSE otherwise. Note that if
2855 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2856 * should not be used.
2858 * The signal handler is free to manipulate @tooltip with the therefore
2859 * destined function calls.
2861 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2865 widget_signals[QUERY_TOOLTIP] =
2866 g_signal_new (I_("query-tooltip"),
2867 G_TYPE_FROM_CLASS (klass),
2869 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2870 _gtk_boolean_handled_accumulator, NULL,
2871 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2879 * GtkWidget::popup-menu
2880 * @widget: the object which received the signal
2882 * This signal gets emitted whenever a widget should pop up a context
2883 * menu. This usually happens through the standard key binding mechanism;
2884 * by pressing a certain key while a widget is focused, the user can cause
2885 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2886 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2887 * for an example of how to use this signal.
2889 * Returns: %TRUE if a menu was activated
2891 widget_signals[POPUP_MENU] =
2892 g_signal_new (I_("popup-menu"),
2893 G_TYPE_FROM_CLASS (klass),
2894 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2895 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2896 _gtk_boolean_handled_accumulator, NULL,
2897 _gtk_marshal_BOOLEAN__VOID,
2901 * GtkWidget::show-help:
2902 * @widget: the object which received the signal.
2905 widget_signals[SHOW_HELP] =
2906 g_signal_new (I_("show-help"),
2907 G_TYPE_FROM_CLASS (klass),
2908 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2909 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2910 _gtk_boolean_handled_accumulator, NULL,
2911 _gtk_marshal_BOOLEAN__ENUM,
2913 GTK_TYPE_WIDGET_HELP_TYPE);
2916 * GtkWidget::accel-closures-changed:
2917 * @widget: the object which received the signal.
2919 widget_signals[ACCEL_CLOSURES_CHANGED] =
2920 g_signal_new (I_("accel-closures-changed"),
2921 G_TYPE_FROM_CLASS (klass),
2925 _gtk_marshal_VOID__VOID,
2929 * GtkWidget::screen-changed:
2930 * @widget: the object on which the signal is emitted
2931 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2932 * widget was not associated with a screen before
2934 * The ::screen-changed signal gets emitted when the
2935 * screen of a widget has changed.
2937 widget_signals[SCREEN_CHANGED] =
2938 g_signal_new (I_("screen-changed"),
2939 G_TYPE_FROM_CLASS (klass),
2941 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2943 _gtk_marshal_VOID__OBJECT,
2948 * GtkWidget::can-activate-accel:
2949 * @widget: the object which received the signal
2950 * @signal_id: the ID of a signal installed on @widget
2952 * Determines whether an accelerator that activates the signal
2953 * identified by @signal_id can currently be activated.
2954 * This signal is present to allow applications and derived
2955 * widgets to override the default #GtkWidget handling
2956 * for determining whether an accelerator can be activated.
2958 * Returns: %TRUE if the signal can be activated.
2960 widget_signals[CAN_ACTIVATE_ACCEL] =
2961 g_signal_new (I_("can-activate-accel"),
2962 G_TYPE_FROM_CLASS (klass),
2964 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2965 _gtk_boolean_handled_accumulator, NULL,
2966 _gtk_marshal_BOOLEAN__UINT,
2967 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2969 binding_set = gtk_binding_set_by_class (klass);
2970 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2972 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2975 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2977 GTK_TYPE_WIDGET_HELP_TYPE,
2978 GTK_WIDGET_HELP_TOOLTIP);
2979 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2981 GTK_TYPE_WIDGET_HELP_TYPE,
2982 GTK_WIDGET_HELP_TOOLTIP);
2983 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2985 GTK_TYPE_WIDGET_HELP_TYPE,
2986 GTK_WIDGET_HELP_WHATS_THIS);
2987 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2989 GTK_TYPE_WIDGET_HELP_TYPE,
2990 GTK_WIDGET_HELP_WHATS_THIS);
2992 gtk_widget_class_install_style_property (klass,
2993 g_param_spec_boolean ("interior-focus",
2994 P_("Interior Focus"),
2995 P_("Whether to draw the focus indicator inside widgets"),
2997 GTK_PARAM_READABLE));
2999 gtk_widget_class_install_style_property (klass,
3000 g_param_spec_int ("focus-line-width",
3001 P_("Focus linewidth"),
3002 P_("Width, in pixels, of the focus indicator line"),
3004 GTK_PARAM_READABLE));
3006 gtk_widget_class_install_style_property (klass,
3007 g_param_spec_string ("focus-line-pattern",
3008 P_("Focus line dash pattern"),
3009 P_("Dash pattern used to draw the focus indicator"),
3011 GTK_PARAM_READABLE));
3012 gtk_widget_class_install_style_property (klass,
3013 g_param_spec_int ("focus-padding",
3014 P_("Focus padding"),
3015 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3017 GTK_PARAM_READABLE));
3018 gtk_widget_class_install_style_property (klass,
3019 g_param_spec_boxed ("cursor-color",
3021 P_("Color with which to draw insertion cursor"),
3023 GTK_PARAM_READABLE));
3024 gtk_widget_class_install_style_property (klass,
3025 g_param_spec_boxed ("secondary-cursor-color",
3026 P_("Secondary cursor color"),
3027 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3029 GTK_PARAM_READABLE));
3030 gtk_widget_class_install_style_property (klass,
3031 g_param_spec_float ("cursor-aspect-ratio",
3032 P_("Cursor line aspect ratio"),
3033 P_("Aspect ratio with which to draw insertion cursor"),
3035 GTK_PARAM_READABLE));
3037 gtk_widget_class_install_style_property (klass,
3038 g_param_spec_boolean ("window-dragging",
3039 P_("Window dragging"),
3040 P_("Whether windows can be dragged by clicking on empty areas"),
3042 GTK_PARAM_READABLE));
3045 * GtkWidget:link-color:
3047 * The "link-color" style property defines the color of unvisited links.
3051 gtk_widget_class_install_style_property (klass,
3052 g_param_spec_boxed ("link-color",
3053 P_("Unvisited Link Color"),
3054 P_("Color of unvisited links"),
3056 GTK_PARAM_READABLE));
3059 * GtkWidget:visited-link-color:
3061 * The "visited-link-color" style property defines the color of visited links.
3065 gtk_widget_class_install_style_property (klass,
3066 g_param_spec_boxed ("visited-link-color",
3067 P_("Visited Link Color"),
3068 P_("Color of visited links"),
3070 GTK_PARAM_READABLE));
3073 * GtkWidget:wide-separators:
3075 * The "wide-separators" style property defines whether separators have
3076 * configurable width and should be drawn using a box instead of a line.
3080 gtk_widget_class_install_style_property (klass,
3081 g_param_spec_boolean ("wide-separators",
3082 P_("Wide Separators"),
3083 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3085 GTK_PARAM_READABLE));
3088 * GtkWidget:separator-width:
3090 * The "separator-width" style property defines the width of separators.
3091 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3095 gtk_widget_class_install_style_property (klass,
3096 g_param_spec_int ("separator-width",
3097 P_("Separator Width"),
3098 P_("The width of separators if wide-separators is TRUE"),
3100 GTK_PARAM_READABLE));
3103 * GtkWidget:separator-height:
3105 * The "separator-height" style property defines the height of separators.
3106 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3110 gtk_widget_class_install_style_property (klass,
3111 g_param_spec_int ("separator-height",
3112 P_("Separator Height"),
3113 P_("The height of separators if \"wide-separators\" is TRUE"),
3115 GTK_PARAM_READABLE));
3118 * GtkWidget:scroll-arrow-hlength:
3120 * The "scroll-arrow-hlength" style property defines the length of
3121 * horizontal scroll arrows.
3125 gtk_widget_class_install_style_property (klass,
3126 g_param_spec_int ("scroll-arrow-hlength",
3127 P_("Horizontal Scroll Arrow Length"),
3128 P_("The length of horizontal scroll arrows"),
3130 GTK_PARAM_READABLE));
3133 * GtkWidget:scroll-arrow-vlength:
3135 * The "scroll-arrow-vlength" style property defines the length of
3136 * vertical scroll arrows.
3140 gtk_widget_class_install_style_property (klass,
3141 g_param_spec_int ("scroll-arrow-vlength",
3142 P_("Vertical Scroll Arrow Length"),
3143 P_("The length of vertical scroll arrows"),
3145 GTK_PARAM_READABLE));
3147 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3151 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3155 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3156 for (node = list; node; node = node->next)
3158 GParamSpec *pspec = node->data;
3160 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3161 g_param_spec_unref (pspec);
3167 gtk_widget_set_property (GObject *object,
3169 const GValue *value,
3172 GtkWidget *widget = GTK_WIDGET (object);
3177 gchar *tooltip_markup;
3178 const gchar *tooltip_text;
3179 GtkWindow *tooltip_window;
3182 gtk_widget_set_name (widget, g_value_get_string (value));
3185 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3187 case PROP_WIDTH_REQUEST:
3188 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3190 case PROP_HEIGHT_REQUEST:
3191 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3194 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3196 case PROP_SENSITIVE:
3197 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3199 case PROP_APP_PAINTABLE:
3200 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3202 case PROP_CAN_FOCUS:
3203 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3205 case PROP_HAS_FOCUS:
3206 if (g_value_get_boolean (value))
3207 gtk_widget_grab_focus (widget);
3210 if (g_value_get_boolean (value))
3211 gtk_widget_grab_focus (widget);
3213 case PROP_CAN_DEFAULT:
3214 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3216 case PROP_HAS_DEFAULT:
3217 if (g_value_get_boolean (value))
3218 gtk_widget_grab_default (widget);
3220 case PROP_RECEIVES_DEFAULT:
3221 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3224 gtk_widget_set_style (widget, g_value_get_object (value));
3227 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3228 gtk_widget_set_events (widget, g_value_get_flags (value));
3230 case PROP_NO_SHOW_ALL:
3231 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3233 case PROP_HAS_TOOLTIP:
3234 gtk_widget_real_set_has_tooltip (widget,
3235 g_value_get_boolean (value), FALSE);
3237 case PROP_TOOLTIP_MARKUP:
3238 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3239 tooltip_markup = g_value_dup_string (value);
3241 /* Treat an empty string as a NULL string,
3242 * because an empty string would be useless for a tooltip:
3244 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3246 g_free (tooltip_markup);
3247 tooltip_markup = NULL;
3250 g_object_set_qdata_full (object, quark_tooltip_markup,
3251 tooltip_markup, g_free);
3253 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3254 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3255 if (gtk_widget_get_visible (widget))
3256 gtk_widget_queue_tooltip_query (widget);
3258 case PROP_TOOLTIP_TEXT:
3259 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3261 tooltip_text = g_value_get_string (value);
3263 /* Treat an empty string as a NULL string,
3264 * because an empty string would be useless for a tooltip:
3266 if (tooltip_text && (strlen (tooltip_text) == 0))
3267 tooltip_text = NULL;
3269 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3271 g_object_set_qdata_full (object, quark_tooltip_markup,
3272 tooltip_markup, g_free);
3274 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3275 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3276 if (gtk_widget_get_visible (widget))
3277 gtk_widget_queue_tooltip_query (widget);
3279 case PROP_DOUBLE_BUFFERED:
3280 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3283 gtk_widget_set_halign (widget, g_value_get_enum (value));
3286 gtk_widget_set_valign (widget, g_value_get_enum (value));
3288 case PROP_MARGIN_LEFT:
3289 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3291 case PROP_MARGIN_RIGHT:
3292 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3294 case PROP_MARGIN_TOP:
3295 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3297 case PROP_MARGIN_BOTTOM:
3298 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3301 g_object_freeze_notify (G_OBJECT (widget));
3302 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3303 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3304 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3305 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3306 g_object_thaw_notify (G_OBJECT (widget));
3309 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3311 case PROP_HEXPAND_SET:
3312 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3315 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3317 case PROP_VEXPAND_SET:
3318 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3321 g_object_freeze_notify (G_OBJECT (widget));
3322 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3323 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3324 g_object_thaw_notify (G_OBJECT (widget));
3327 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3333 gtk_widget_get_property (GObject *object,
3338 GtkWidget *widget = GTK_WIDGET (object);
3339 GtkWidgetPrivate *priv = widget->priv;
3347 g_value_set_string (value, priv->name);
3349 g_value_set_static_string (value, "");
3352 g_value_set_object (value, priv->parent);
3354 case PROP_WIDTH_REQUEST:
3357 gtk_widget_get_size_request (widget, &w, NULL);
3358 g_value_set_int (value, w);
3361 case PROP_HEIGHT_REQUEST:
3364 gtk_widget_get_size_request (widget, NULL, &h);
3365 g_value_set_int (value, h);
3369 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3371 case PROP_SENSITIVE:
3372 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3374 case PROP_APP_PAINTABLE:
3375 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3377 case PROP_CAN_FOCUS:
3378 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3380 case PROP_HAS_FOCUS:
3381 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3384 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3386 case PROP_CAN_DEFAULT:
3387 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3389 case PROP_HAS_DEFAULT:
3390 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3392 case PROP_RECEIVES_DEFAULT:
3393 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3395 case PROP_COMPOSITE_CHILD:
3396 g_value_set_boolean (value, widget->priv->composite_child);
3399 g_value_set_object (value, gtk_widget_get_style (widget));
3402 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3403 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3405 case PROP_NO_SHOW_ALL:
3406 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3408 case PROP_HAS_TOOLTIP:
3409 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3411 case PROP_TOOLTIP_TEXT:
3413 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3416 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3417 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3419 g_value_take_string (value, text);
3422 case PROP_TOOLTIP_MARKUP:
3423 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3426 g_value_set_object (value, gtk_widget_get_window (widget));
3428 case PROP_DOUBLE_BUFFERED:
3429 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3432 g_value_set_enum (value, gtk_widget_get_halign (widget));
3435 g_value_set_enum (value, gtk_widget_get_valign (widget));
3437 case PROP_MARGIN_LEFT:
3438 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3440 case PROP_MARGIN_RIGHT:
3441 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3443 case PROP_MARGIN_TOP:
3444 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3446 case PROP_MARGIN_BOTTOM:
3447 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3451 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3452 if (aux_info == NULL)
3454 g_value_set_int (value, 0);
3458 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3459 aux_info->margin.right),
3460 MAX (aux_info->margin.top,
3461 aux_info->margin.bottom)));
3466 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3468 case PROP_HEXPAND_SET:
3469 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3472 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3474 case PROP_VEXPAND_SET:
3475 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3478 g_value_set_boolean (value,
3479 gtk_widget_get_hexpand (widget) &&
3480 gtk_widget_get_vexpand (widget));
3483 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3489 gtk_widget_init (GtkWidget *widget)
3491 GtkWidgetPrivate *priv;
3493 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3496 priv = widget->priv;
3498 priv->child_visible = TRUE;
3500 priv->allocation.x = -1;
3501 priv->allocation.y = -1;
3502 priv->allocation.width = 1;
3503 priv->allocation.height = 1;
3504 priv->window = NULL;
3505 priv->parent = NULL;
3507 priv->sensitive = TRUE;
3508 priv->parent_sensitive = TRUE;
3509 priv->composite_child = composite_child_stack != 0;
3510 priv->double_buffered = TRUE;
3511 priv->redraw_on_alloc = TRUE;
3512 priv->width_request_needed = TRUE;
3513 priv->height_request_needed = TRUE;
3514 priv->alloc_needed = TRUE;
3516 /* this will be set to TRUE if the widget gets a child or if the
3517 * expand flag is set on the widget, but until one of those happen
3518 * we know the expand is already properly FALSE.
3520 * We really want to default FALSE here to avoid computing expand
3521 * all over the place while initially building a widget tree.
3523 priv->need_compute_expand = FALSE;
3525 priv->style = gtk_widget_get_default_style ();
3526 g_object_ref (priv->style);
3531 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3533 GParamSpec **pspecs)
3535 GtkWidgetPrivate *priv = widget->priv;
3536 GtkWidget *container = priv->parent;
3539 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3540 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3544 * gtk_widget_freeze_child_notify:
3545 * @widget: a #GtkWidget
3547 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3548 * signals are queued until gtk_widget_thaw_child_notify() is called
3551 * This is the analogue of g_object_freeze_notify() for child properties.
3554 gtk_widget_freeze_child_notify (GtkWidget *widget)
3556 g_return_if_fail (GTK_IS_WIDGET (widget));
3558 if (!G_OBJECT (widget)->ref_count)
3561 g_object_ref (widget);
3562 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3563 g_object_unref (widget);
3567 * gtk_widget_child_notify:
3568 * @widget: a #GtkWidget
3569 * @child_property: the name of a child property installed on the
3570 * class of @widget<!-- -->'s parent
3572 * Emits a #GtkWidget::child-notify signal for the
3573 * <link linkend="child-properties">child property</link> @child_property
3576 * This is the analogue of g_object_notify() for child properties.
3579 gtk_widget_child_notify (GtkWidget *widget,
3580 const gchar *child_property)
3582 GtkWidgetPrivate *priv = widget->priv;
3585 g_return_if_fail (GTK_IS_WIDGET (widget));
3586 g_return_if_fail (child_property != NULL);
3587 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3590 g_object_ref (widget);
3591 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3593 G_OBJECT_TYPE (priv->parent),
3596 g_warning ("%s: container class `%s' has no child property named `%s'",
3598 G_OBJECT_TYPE_NAME (priv->parent),
3602 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3604 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3605 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3607 g_object_unref (widget);
3611 * gtk_widget_thaw_child_notify:
3612 * @widget: a #GtkWidget
3614 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3615 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3619 gtk_widget_thaw_child_notify (GtkWidget *widget)
3621 GObjectNotifyQueue *nqueue;
3623 g_return_if_fail (GTK_IS_WIDGET (widget));
3625 if (!G_OBJECT (widget)->ref_count)
3628 g_object_ref (widget);
3629 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3630 if (!nqueue || !nqueue->freeze_count)
3631 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3632 G_OBJECT_TYPE_NAME (widget), widget);
3634 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3635 g_object_unref (widget);
3641 * @type: type ID of the widget to create
3642 * @first_property_name: name of first property to set
3643 * @Varargs: value of first property, followed by more properties,
3646 * This is a convenience function for creating a widget and setting
3647 * its properties in one go. For example you might write:
3648 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3649 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3650 * g_object_new(), but returns a widget so you don't have to
3651 * cast the object yourself.
3653 * Return value: a new #GtkWidget of type @widget_type
3656 gtk_widget_new (GType type,
3657 const gchar *first_property_name,
3663 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3665 va_start (var_args, first_property_name);
3666 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3673 gtk_widget_queue_draw_child (GtkWidget *widget)
3675 GtkWidgetPrivate *priv = widget->priv;
3678 parent = priv->parent;
3679 if (parent && gtk_widget_is_drawable (parent))
3680 gtk_widget_queue_draw_area (parent,
3683 priv->allocation.width,
3684 priv->allocation.height);
3688 * gtk_widget_unparent:
3689 * @widget: a #GtkWidget
3691 * This function is only for use in widget implementations.
3692 * Should be called by implementations of the remove method
3693 * on #GtkContainer, to dissociate a child from the container.
3696 gtk_widget_unparent (GtkWidget *widget)
3698 GtkWidgetPrivate *priv;
3699 GObjectNotifyQueue *nqueue;
3700 GtkWidget *toplevel;
3701 GtkWidget *old_parent;
3703 g_return_if_fail (GTK_IS_WIDGET (widget));
3705 priv = widget->priv;
3707 if (priv->parent == NULL)
3710 /* keep this function in sync with gtk_menu_detach() */
3712 gtk_widget_push_verify_invariants (widget);
3714 g_object_freeze_notify (G_OBJECT (widget));
3715 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3717 toplevel = gtk_widget_get_toplevel (widget);
3718 if (gtk_widget_is_toplevel (toplevel))
3719 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3721 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3722 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3724 gtk_widget_queue_draw_child (widget);
3726 /* Reset the width and height here, to force reallocation if we
3727 * get added back to a new parent. This won't work if our new
3728 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3729 * (would 0x0 be OK here?)
3731 priv->allocation.width = 1;
3732 priv->allocation.height = 1;
3734 if (gtk_widget_get_realized (widget))
3736 if (priv->in_reparent)
3737 gtk_widget_unmap (widget);
3739 gtk_widget_unrealize (widget);
3742 /* If we are unanchoring the child, we save around the toplevel
3743 * to emit hierarchy changed
3745 if (priv->parent->priv->anchored)
3746 g_object_ref (toplevel);
3750 /* Removing a widget from a container restores the child visible
3751 * flag to the default state, so it doesn't affect the child
3752 * in the next parent.
3754 priv->child_visible = TRUE;
3756 old_parent = priv->parent;
3757 priv->parent = NULL;
3759 /* parent may no longer expand if the removed
3760 * child was expand=TRUE and could therefore
3763 if (gtk_widget_get_visible (widget) &&
3764 (priv->need_compute_expand ||
3765 priv->computed_hexpand ||
3766 priv->computed_vexpand))
3768 gtk_widget_queue_compute_expand (old_parent);
3771 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3774 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3775 g_object_unref (toplevel);
3778 /* Now that the parent pointer is nullified and the hierarchy-changed
3779 * already passed, go ahead and unset the parent window, if we are unparenting
3780 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
3781 * will fire again for the new subhierarchy.
3783 gtk_widget_set_parent_window (widget, NULL);
3785 g_object_notify (G_OBJECT (widget), "parent");
3786 g_object_thaw_notify (G_OBJECT (widget));
3788 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3789 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3791 gtk_widget_pop_verify_invariants (widget);
3792 g_object_unref (widget);
3796 * gtk_widget_destroy:
3797 * @widget: a #GtkWidget
3799 * Destroys a widget.
3802 * destroyed, it will break any references it holds to other objects.
3803 * If the widget is inside a container, the widget will be removed
3804 * from the container. If the widget is a toplevel (derived from
3805 * #GtkWindow), it will be removed from the list of toplevels, and the
3806 * reference GTK+ holds to it will be removed. Removing a
3807 * widget from its container or the list of toplevels results in the
3808 * widget being finalized, unless you've added additional references
3809 * to the widget with g_object_ref().
3811 * In most cases, only toplevel widgets (windows) require explicit
3812 * destruction, because when you destroy a toplevel its children will
3813 * be destroyed as well.
3816 gtk_widget_destroy (GtkWidget *widget)
3818 g_return_if_fail (GTK_IS_WIDGET (widget));
3820 if (!widget->priv->in_destruction)
3821 g_object_run_dispose (G_OBJECT (widget));
3825 * gtk_widget_destroyed:
3826 * @widget: a #GtkWidget
3827 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3829 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3830 * %NULL. It's intended to be used as a callback connected to the
3831 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3832 * as a signal handler, and pass the address of your widget variable
3833 * as user data. Then when the widget is destroyed, the variable will
3834 * be set to %NULL. Useful for example to avoid multiple copies
3835 * of the same dialog.
3838 gtk_widget_destroyed (GtkWidget *widget,
3839 GtkWidget **widget_pointer)
3841 /* Don't make any assumptions about the
3843 * Even check widget_pointer.
3846 *widget_pointer = NULL;
3851 * @widget: a #GtkWidget
3853 * Flags a widget to be displayed. Any widget that isn't shown will
3854 * not appear on the screen. If you want to show all the widgets in a
3855 * container, it's easier to call gtk_widget_show_all() on the
3856 * container, instead of individually showing the widgets.
3858 * Remember that you have to show the containers containing a widget,
3859 * in addition to the widget itself, before it will appear onscreen.
3861 * When a toplevel container is shown, it is immediately realized and
3862 * mapped; other shown widgets are realized and mapped when their
3863 * toplevel container is realized and mapped.
3866 gtk_widget_show (GtkWidget *widget)
3868 g_return_if_fail (GTK_IS_WIDGET (widget));
3870 if (!gtk_widget_get_visible (widget))
3872 g_object_ref (widget);
3873 gtk_widget_push_verify_invariants (widget);
3875 if (!gtk_widget_is_toplevel (widget))
3876 gtk_widget_queue_resize (widget);
3878 /* see comment in set_parent() for why this should and can be
3881 if (widget->priv->need_compute_expand ||
3882 widget->priv->computed_hexpand ||
3883 widget->priv->computed_vexpand)
3885 if (widget->priv->parent != NULL)
3886 gtk_widget_queue_compute_expand (widget->priv->parent);
3889 g_signal_emit (widget, widget_signals[SHOW], 0);
3890 g_object_notify (G_OBJECT (widget), "visible");
3892 gtk_widget_pop_verify_invariants (widget);
3893 g_object_unref (widget);
3898 gtk_widget_real_show (GtkWidget *widget)
3900 GtkWidgetPrivate *priv = widget->priv;
3902 if (!gtk_widget_get_visible (widget))
3904 priv->visible = TRUE;
3907 gtk_widget_get_mapped (priv->parent) &&
3908 gtk_widget_get_child_visible (widget) &&
3909 !gtk_widget_get_mapped (widget))
3910 gtk_widget_map (widget);
3915 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3918 g_signal_handlers_disconnect_by_func (widget,
3919 gtk_widget_show_map_callback,
3924 * gtk_widget_show_now:
3925 * @widget: a #GtkWidget
3927 * Shows a widget. If the widget is an unmapped toplevel widget
3928 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3929 * loop and wait for the window to actually be mapped. Be careful;
3930 * because the main loop is running, anything can happen during
3934 gtk_widget_show_now (GtkWidget *widget)
3938 g_return_if_fail (GTK_IS_WIDGET (widget));
3940 /* make sure we will get event */
3941 if (!gtk_widget_get_mapped (widget) &&
3942 gtk_widget_is_toplevel (widget))
3944 gtk_widget_show (widget);
3946 g_signal_connect (widget, "map-event",
3947 G_CALLBACK (gtk_widget_show_map_callback),
3951 gtk_main_iteration ();
3954 gtk_widget_show (widget);
3959 * @widget: a #GtkWidget
3961 * Reverses the effects of gtk_widget_show(), causing the widget to be
3962 * hidden (invisible to the user).
3965 gtk_widget_hide (GtkWidget *widget)
3967 g_return_if_fail (GTK_IS_WIDGET (widget));
3969 if (gtk_widget_get_visible (widget))
3971 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3973 g_object_ref (widget);
3974 gtk_widget_push_verify_invariants (widget);
3976 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3977 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3979 /* a parent may now be expand=FALSE since we're hidden. */
3980 if (widget->priv->need_compute_expand ||
3981 widget->priv->computed_hexpand ||
3982 widget->priv->computed_vexpand)
3984 gtk_widget_queue_compute_expand (widget);
3987 g_signal_emit (widget, widget_signals[HIDE], 0);
3988 if (!gtk_widget_is_toplevel (widget))
3989 gtk_widget_queue_resize (widget);
3990 g_object_notify (G_OBJECT (widget), "visible");
3992 gtk_widget_pop_verify_invariants (widget);
3993 g_object_unref (widget);
3998 gtk_widget_real_hide (GtkWidget *widget)
4000 if (gtk_widget_get_visible (widget))
4002 widget->priv->visible = FALSE;
4004 if (gtk_widget_get_mapped (widget))
4005 gtk_widget_unmap (widget);
4010 * gtk_widget_hide_on_delete:
4011 * @widget: a #GtkWidget
4013 * Utility function; intended to be connected to the #GtkWidget::delete-event
4014 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4015 * argument, then returns %TRUE. If connected to ::delete-event, the
4016 * result is that clicking the close button for a window (on the
4017 * window frame, top right corner usually) will hide but not destroy
4018 * the window. By default, GTK+ destroys windows when ::delete-event
4021 * Return value: %TRUE
4024 gtk_widget_hide_on_delete (GtkWidget *widget)
4026 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4028 gtk_widget_hide (widget);
4034 * gtk_widget_show_all:
4035 * @widget: a #GtkWidget
4037 * Recursively shows a widget, and any child widgets (if the widget is
4041 gtk_widget_show_all (GtkWidget *widget)
4043 GtkWidgetClass *class;
4045 g_return_if_fail (GTK_IS_WIDGET (widget));
4047 if (gtk_widget_get_no_show_all (widget))
4050 class = GTK_WIDGET_GET_CLASS (widget);
4052 if (class->show_all)
4053 class->show_all (widget);
4057 _gtk_widget_notify_state_change (GtkWidget *widget,
4065 case GTK_STATE_FLAG_ACTIVE:
4066 state = GTK_STATE_ACTIVE;
4068 case GTK_STATE_FLAG_PRELIGHT:
4069 state = GTK_STATE_PRELIGHT;
4071 case GTK_STATE_FLAG_SELECTED:
4072 state = GTK_STATE_SELECTED;
4074 case GTK_STATE_FLAG_INSENSITIVE:
4075 state = GTK_STATE_INSENSITIVE;
4077 case GTK_STATE_FLAG_INCONSISTENT:
4078 state = GTK_STATE_INCONSISTENT;
4080 case GTK_STATE_FLAG_FOCUSED:
4081 state = GTK_STATE_FOCUSED;
4087 gtk_style_context_notify_state_change (widget->priv->context,
4088 gtk_widget_get_window (widget),
4089 NULL, state, target);
4092 /* Initializes state transitions for those states that
4093 * were enabled before mapping and have a looping animation.
4096 _gtk_widget_start_state_transitions (GtkWidget *widget)
4098 GtkStateFlags state, flag;
4100 if (!widget->priv->context)
4103 state = gtk_widget_get_state_flags (widget);
4104 flag = GTK_STATE_FLAG_FOCUSED;
4108 GtkAnimationDescription *animation_desc;
4110 if ((state & flag) == 0)
4116 gtk_style_context_get (widget->priv->context, state,
4117 "transition", &animation_desc,
4122 if (_gtk_animation_description_get_loop (animation_desc))
4123 _gtk_widget_notify_state_change (widget, flag, TRUE);
4125 _gtk_animation_description_unref (animation_desc);
4134 * @widget: a #GtkWidget
4136 * This function is only for use in widget implementations. Causes
4137 * a widget to be mapped if it isn't already.
4140 gtk_widget_map (GtkWidget *widget)
4142 GtkWidgetPrivate *priv;
4144 g_return_if_fail (GTK_IS_WIDGET (widget));
4145 g_return_if_fail (gtk_widget_get_visible (widget));
4146 g_return_if_fail (gtk_widget_get_child_visible (widget));
4148 priv = widget->priv;
4150 if (!gtk_widget_get_mapped (widget))
4152 gtk_widget_push_verify_invariants (widget);
4154 if (!gtk_widget_get_realized (widget))
4155 gtk_widget_realize (widget);
4157 g_signal_emit (widget, widget_signals[MAP], 0);
4159 if (!gtk_widget_get_has_window (widget))
4160 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4162 gtk_widget_pop_verify_invariants (widget);
4164 _gtk_widget_start_state_transitions (widget);
4170 * @widget: a #GtkWidget
4172 * This function is only for use in widget implementations. Causes
4173 * a widget to be unmapped if it's currently mapped.
4176 gtk_widget_unmap (GtkWidget *widget)
4178 GtkWidgetPrivate *priv;
4180 g_return_if_fail (GTK_IS_WIDGET (widget));
4182 priv = widget->priv;
4184 if (gtk_widget_get_mapped (widget))
4186 gtk_widget_push_verify_invariants (widget);
4188 if (!gtk_widget_get_has_window (widget))
4189 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4190 _gtk_tooltip_hide (widget);
4191 g_signal_emit (widget, widget_signals[UNMAP], 0);
4193 gtk_widget_pop_verify_invariants (widget);
4198 _gtk_widget_enable_device_events (GtkWidget *widget)
4200 GHashTable *device_events;
4201 GHashTableIter iter;
4202 gpointer key, value;
4204 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4209 g_hash_table_iter_init (&iter, device_events);
4211 while (g_hash_table_iter_next (&iter, &key, &value))
4214 GdkEventMask event_mask;
4217 event_mask = GPOINTER_TO_UINT (value);
4218 gtk_widget_add_events_internal (widget, device, event_mask);
4223 * gtk_widget_realize:
4224 * @widget: a #GtkWidget
4226 * Creates the GDK (windowing system) resources associated with a
4227 * widget. For example, @widget->window will be created when a widget
4228 * is realized. Normally realization happens implicitly; if you show
4229 * a widget and all its parent containers, then the widget will be
4230 * realized and mapped automatically.
4232 * Realizing a widget requires all
4233 * the widget's parent widgets to be realized; calling
4234 * gtk_widget_realize() realizes the widget's parents in addition to
4235 * @widget itself. If a widget is not yet inside a toplevel window
4236 * when you realize it, bad things will happen.
4238 * This function is primarily used in widget implementations, and
4239 * isn't very useful otherwise. Many times when you think you might
4240 * need it, a better approach is to connect to a signal that will be
4241 * called after the widget is realized automatically, such as
4242 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4243 * #GtkWidget::realize signal.
4246 gtk_widget_realize (GtkWidget *widget)
4248 GtkWidgetPrivate *priv;
4249 cairo_region_t *region;
4251 g_return_if_fail (GTK_IS_WIDGET (widget));
4252 g_return_if_fail (widget->priv->anchored ||
4253 GTK_IS_INVISIBLE (widget));
4255 priv = widget->priv;
4257 if (!gtk_widget_get_realized (widget))
4259 gtk_widget_push_verify_invariants (widget);
4262 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4263 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4266 if (priv->parent == NULL &&
4267 !gtk_widget_is_toplevel (widget))
4268 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4269 "inside a toplevel window is not going to work very well. "
4270 "Widgets must be inside a toplevel container before realizing them.");
4272 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4273 gtk_widget_realize (priv->parent);
4275 gtk_widget_ensure_style (widget);
4277 if (priv->style_update_pending)
4278 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4280 g_signal_emit (widget, widget_signals[REALIZE], 0);
4282 gtk_widget_real_set_has_tooltip (widget,
4283 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4286 if (priv->has_shape_mask)
4288 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4289 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4292 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4294 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4296 if (priv->multidevice)
4297 gdk_window_set_support_multidevice (priv->window, TRUE);
4299 _gtk_widget_enable_device_events (widget);
4301 gtk_widget_pop_verify_invariants (widget);
4306 * gtk_widget_unrealize:
4307 * @widget: a #GtkWidget
4309 * This function is only useful in widget implementations.
4310 * Causes a widget to be unrealized (frees all GDK resources
4311 * associated with the widget, such as @widget->window).
4314 gtk_widget_unrealize (GtkWidget *widget)
4316 g_return_if_fail (GTK_IS_WIDGET (widget));
4318 gtk_widget_push_verify_invariants (widget);
4320 if (widget->priv->has_shape_mask)
4321 gtk_widget_shape_combine_region (widget, NULL);
4323 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4324 gtk_widget_input_shape_combine_region (widget, NULL);
4326 if (gtk_widget_get_realized (widget))
4328 g_object_ref (widget);
4330 if (widget->priv->mapped)
4331 gtk_widget_unmap (widget);
4333 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4334 g_assert (!widget->priv->mapped);
4335 gtk_widget_set_realized (widget, FALSE);
4337 g_object_unref (widget);
4340 gtk_widget_pop_verify_invariants (widget);
4343 /*****************************************
4345 *****************************************/
4348 * gtk_widget_queue_draw_region:
4349 * @widget: a #GtkWidget
4350 * @region: region to draw
4352 * Invalidates the rectangular area of @widget defined by @region by
4353 * calling gdk_window_invalidate_region() on the widget's window and
4354 * all its child windows. Once the main loop becomes idle (after the
4355 * current batch of events has been processed, roughly), the window
4356 * will receive expose events for the union of all regions that have
4359 * Normally you would only use this function in widget
4360 * implementations. You might also use it to schedule a redraw of a
4361 * #GtkDrawingArea or some portion thereof.
4364 gtk_widget_queue_draw_region (GtkWidget *widget,
4365 cairo_region_t *region)
4367 GtkWidgetPrivate *priv;
4370 g_return_if_fail (GTK_IS_WIDGET (widget));
4372 priv = widget->priv;
4374 if (!gtk_widget_get_realized (widget))
4377 /* Just return if the widget or one of its ancestors isn't mapped */
4378 for (w = widget; w != NULL; w = w->priv->parent)
4379 if (!gtk_widget_get_mapped (w))
4382 gdk_window_invalidate_region (priv->window, region, TRUE);
4386 * gtk_widget_queue_draw_area:
4387 * @widget: a #GtkWidget
4388 * @x: x coordinate of upper-left corner of rectangle to redraw
4389 * @y: y coordinate of upper-left corner of rectangle to redraw
4390 * @width: width of region to draw
4391 * @height: height of region to draw
4393 * Convenience function that calls gtk_widget_queue_draw_region() on
4394 * the region created from the given coordinates.
4397 gtk_widget_queue_draw_area (GtkWidget *widget,
4404 cairo_region_t *region;
4406 g_return_if_fail (GTK_IS_WIDGET (widget));
4411 rect.height = height;
4413 region = cairo_region_create_rectangle (&rect);
4414 gtk_widget_queue_draw_region (widget, region);
4415 cairo_region_destroy (region);
4419 * gtk_widget_queue_draw:
4420 * @widget: a #GtkWidget
4422 * Equivalent to calling gtk_widget_queue_draw_area() for the
4423 * entire area of a widget.
4426 gtk_widget_queue_draw (GtkWidget *widget)
4430 g_return_if_fail (GTK_IS_WIDGET (widget));
4432 gtk_widget_get_allocation (widget, &rect);
4434 if (!gtk_widget_get_has_window (widget))
4435 gtk_widget_queue_draw_area (widget,
4436 rect.x, rect.y, rect.width, rect.height);
4438 gtk_widget_queue_draw_area (widget,
4439 0, 0, rect.width, rect.height);
4443 * gtk_widget_queue_resize:
4444 * @widget: a #GtkWidget
4446 * This function is only for use in widget implementations.
4447 * Flags a widget to have its size renegotiated; should
4448 * be called when a widget for some reason has a new size request.
4449 * For example, when you change the text in a #GtkLabel, #GtkLabel
4450 * queues a resize to ensure there's enough space for the new text.
4452 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4453 * from inside it's implementation of the GtkWidgetClass::size_allocate
4454 * virtual method. Calls to gtk_widget_queue_resize() from inside
4455 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4458 gtk_widget_queue_resize (GtkWidget *widget)
4460 g_return_if_fail (GTK_IS_WIDGET (widget));
4462 if (gtk_widget_get_realized (widget))
4463 gtk_widget_queue_shallow_draw (widget);
4465 _gtk_size_group_queue_resize (widget, 0);
4469 * gtk_widget_queue_resize_no_redraw:
4470 * @widget: a #GtkWidget
4472 * This function works like gtk_widget_queue_resize(),
4473 * except that the widget is not invalidated.
4478 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4480 g_return_if_fail (GTK_IS_WIDGET (widget));
4482 _gtk_size_group_queue_resize (widget, 0);
4486 * gtk_widget_size_request:
4487 * @widget: a #GtkWidget
4488 * @requisition: (out): a #GtkRequisition to be filled in
4490 * This function is typically used when implementing a #GtkContainer
4491 * subclass. Obtains the preferred size of a widget. The container
4492 * uses this information to arrange its child widgets and decide what
4493 * size allocations to give them with gtk_widget_size_allocate().
4495 * You can also call this function from an application, with some
4496 * caveats. Most notably, getting a size request requires the widget
4497 * to be associated with a screen, because font information may be
4498 * needed. Multihead-aware applications should keep this in mind.
4500 * Also remember that the size request is not necessarily the size
4501 * a widget will actually be allocated.
4503 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4506 gtk_widget_size_request (GtkWidget *widget,
4507 GtkRequisition *requisition)
4509 g_return_if_fail (GTK_IS_WIDGET (widget));
4511 gtk_widget_get_preferred_size (widget, requisition, NULL);
4515 * gtk_widget_get_child_requisition:
4516 * @widget: a #GtkWidget
4517 * @requisition: (out): a #GtkRequisition to be filled in
4519 * This function is only for use in widget implementations. Obtains
4520 * @widget->requisition, unless someone has forced a particular
4521 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4522 * in which case it returns that geometry instead of the widget's
4525 * This function differs from gtk_widget_size_request() in that
4526 * it retrieves the last size request value from @widget->requisition,
4527 * while gtk_widget_size_request() actually calls the "size_request" method
4528 * on @widget to compute the size request and fill in @widget->requisition,
4529 * and only then returns @widget->requisition.
4531 * Because this function does not call the "size_request" method, it
4532 * can only be used when you know that @widget->requisition is
4533 * up-to-date, that is, gtk_widget_size_request() has been called
4534 * since the last time a resize was queued. In general, only container
4535 * implementations have this information; applications should use
4536 * gtk_widget_size_request().
4539 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4542 gtk_widget_get_child_requisition (GtkWidget *widget,
4543 GtkRequisition *requisition)
4545 gtk_widget_get_preferred_size (widget, requisition, NULL);
4549 invalidate_predicate (GdkWindow *window,
4554 gdk_window_get_user_data (window, &user_data);
4556 return (user_data == data);
4559 /* Invalidate @region in widget->window and all children
4560 * of widget->window owned by widget. @region is in the
4561 * same coordinates as widget->allocation and will be
4562 * modified by this call.
4565 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4566 cairo_region_t *region)
4568 GtkWidgetPrivate *priv = widget->priv;
4570 if (!gtk_widget_get_realized (widget))
4573 if (gtk_widget_get_has_window (widget) && priv->parent)
4577 gdk_window_get_position (priv->window, &x, &y);
4578 cairo_region_translate (region, -x, -y);
4581 gdk_window_invalidate_maybe_recurse (priv->window, region,
4582 invalidate_predicate, widget);
4586 * gtk_widget_queue_shallow_draw:
4587 * @widget: a #GtkWidget
4589 * Like gtk_widget_queue_draw(), but only windows owned
4590 * by @widget are invalidated.
4593 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4596 cairo_region_t *region;
4598 if (!gtk_widget_get_realized (widget))
4601 gtk_widget_get_allocation (widget, &rect);
4603 region = cairo_region_create_rectangle (&rect);
4604 gtk_widget_invalidate_widget_windows (widget, region);
4605 cairo_region_destroy (region);
4609 * gtk_widget_size_allocate:
4610 * @widget: a #GtkWidget
4611 * @allocation: (inout): position and size to be allocated to @widget
4613 * This function is only used by #GtkContainer subclasses, to assign a size
4614 * and position to their child widgets.
4616 * In this function, the allocation may be adjusted. It will be forced
4617 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4618 * method on the child will be used to adjust the allocation. Standard
4619 * adjustments include removing the widget's margins, and applying the
4620 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4623 gtk_widget_size_allocate (GtkWidget *widget,
4624 GtkAllocation *allocation)
4626 GtkWidgetPrivate *priv;
4627 GdkRectangle real_allocation;
4628 GdkRectangle old_allocation;
4629 GdkRectangle adjusted_allocation;
4630 gboolean alloc_needed;
4631 gboolean size_changed;
4632 gboolean position_changed;
4633 gint natural_width, natural_height, dummy;
4634 gint min_width, min_height;
4636 priv = widget->priv;
4638 g_return_if_fail (GTK_IS_WIDGET (widget));
4640 gtk_widget_push_verify_invariants (widget);
4642 #ifdef G_ENABLE_DEBUG
4643 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4654 parent = gtk_widget_get_parent (parent);
4657 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4658 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4659 2 * depth, " ", name,
4660 allocation->width, allocation->height);
4662 #endif /* G_ENABLE_DEBUG */
4664 alloc_needed = priv->alloc_needed;
4665 if (!priv->width_request_needed && !priv->height_request_needed)
4666 /* Preserve request/allocate ordering */
4667 priv->alloc_needed = FALSE;
4669 old_allocation = priv->allocation;
4670 real_allocation = *allocation;
4672 adjusted_allocation = real_allocation;
4673 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4675 /* Go ahead and request the height for allocated width, note that the internals
4676 * of get_height_for_width will internally limit the for_size to natural size
4677 * when aligning implicitly.
4679 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4680 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
4684 /* Go ahead and request the width for allocated height, note that the internals
4685 * of get_width_for_height will internally limit the for_size to natural size
4686 * when aligning implicitly.
4688 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4689 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
4692 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4693 * allocated sizes and possibly limit them to the natural sizes */
4694 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4695 GTK_ORIENTATION_HORIZONTAL,
4698 &adjusted_allocation.x,
4699 &adjusted_allocation.width);
4700 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4701 GTK_ORIENTATION_VERTICAL,
4704 &adjusted_allocation.y,
4705 &adjusted_allocation.height);
4707 if (adjusted_allocation.x < real_allocation.x ||
4708 adjusted_allocation.y < real_allocation.y ||
4709 (adjusted_allocation.x + adjusted_allocation.width) >
4710 (real_allocation.x + real_allocation.width) ||
4711 (adjusted_allocation.y + adjusted_allocation.height >
4712 real_allocation.y + real_allocation.height))
4714 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",
4715 G_OBJECT_TYPE_NAME (widget), widget,
4716 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4717 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4718 adjusted_allocation = real_allocation; /* veto it */
4722 real_allocation = adjusted_allocation;
4725 if (real_allocation.width < 0 || real_allocation.height < 0)
4727 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4728 real_allocation.width,
4729 real_allocation.height);
4732 real_allocation.width = MAX (real_allocation.width, 1);
4733 real_allocation.height = MAX (real_allocation.height, 1);
4735 size_changed = (old_allocation.width != real_allocation.width ||
4736 old_allocation.height != real_allocation.height);
4737 position_changed = (old_allocation.x != real_allocation.x ||
4738 old_allocation.y != real_allocation.y);
4740 if (!alloc_needed && !size_changed && !position_changed)
4743 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4745 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4746 priv->width_request_needed = FALSE;
4747 priv->height_request_needed = FALSE;
4748 priv->alloc_needed = FALSE;
4750 if (gtk_widget_get_mapped (widget))
4752 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4754 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4756 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4757 cairo_region_union_rectangle (invalidate, &old_allocation);
4759 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4760 cairo_region_destroy (invalidate);
4765 if (priv->redraw_on_alloc)
4767 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4769 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4770 cairo_region_union_rectangle (invalidate, &old_allocation);
4772 gtk_widget_invalidate_widget_windows (widget, invalidate);
4773 cairo_region_destroy (invalidate);
4777 if (size_changed || position_changed)
4779 GtkStyleContext *context;
4781 context = gtk_widget_get_style_context (widget);
4782 _gtk_style_context_invalidate_animation_areas (context);
4786 if ((size_changed || position_changed) && priv->parent &&
4787 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4789 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4790 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4791 cairo_region_destroy (invalidate);
4795 gtk_widget_pop_verify_invariants (widget);
4799 * gtk_widget_common_ancestor:
4800 * @widget_a: a #GtkWidget
4801 * @widget_b: a #GtkWidget
4803 * Find the common ancestor of @widget_a and @widget_b that
4804 * is closest to the two widgets.
4806 * Return value: the closest common ancestor of @widget_a and
4807 * @widget_b or %NULL if @widget_a and @widget_b do not
4808 * share a common ancestor.
4811 gtk_widget_common_ancestor (GtkWidget *widget_a,
4812 GtkWidget *widget_b)
4814 GtkWidget *parent_a;
4815 GtkWidget *parent_b;
4819 parent_a = widget_a;
4820 while (parent_a->priv->parent)
4822 parent_a = parent_a->priv->parent;
4826 parent_b = widget_b;
4827 while (parent_b->priv->parent)
4829 parent_b = parent_b->priv->parent;
4833 if (parent_a != parent_b)
4836 while (depth_a > depth_b)
4838 widget_a = widget_a->priv->parent;
4842 while (depth_b > depth_a)
4844 widget_b = widget_b->priv->parent;
4848 while (widget_a != widget_b)
4850 widget_a = widget_a->priv->parent;
4851 widget_b = widget_b->priv->parent;
4858 * gtk_widget_translate_coordinates:
4859 * @src_widget: a #GtkWidget
4860 * @dest_widget: a #GtkWidget
4861 * @src_x: X position relative to @src_widget
4862 * @src_y: Y position relative to @src_widget
4863 * @dest_x: (out): location to store X position relative to @dest_widget
4864 * @dest_y: (out): location to store Y position relative to @dest_widget
4866 * Translate coordinates relative to @src_widget's allocation to coordinates
4867 * relative to @dest_widget's allocations. In order to perform this
4868 * operation, both widgets must be realized, and must share a common
4871 * Return value: %FALSE if either widget was not realized, or there
4872 * was no common ancestor. In this case, nothing is stored in
4873 * *@dest_x and *@dest_y. Otherwise %TRUE.
4876 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4877 GtkWidget *dest_widget,
4883 GtkWidgetPrivate *src_priv = src_widget->priv;
4884 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4885 GtkWidget *ancestor;
4887 GList *dest_list = NULL;
4889 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4890 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4892 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4893 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4896 /* Translate from allocation relative to window relative */
4897 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4900 gdk_window_get_position (src_priv->window, &wx, &wy);
4902 src_x -= wx - src_priv->allocation.x;
4903 src_y -= wy - src_priv->allocation.y;
4907 src_x += src_priv->allocation.x;
4908 src_y += src_priv->allocation.y;
4911 /* Translate to the common ancestor */
4912 window = src_priv->window;
4913 while (window != ancestor->priv->window)
4917 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4922 window = gdk_window_get_effective_parent (window);
4924 if (!window) /* Handle GtkHandleBox */
4929 window = dest_priv->window;
4930 while (window != ancestor->priv->window)
4932 dest_list = g_list_prepend (dest_list, window);
4934 window = gdk_window_get_effective_parent (window);
4936 if (!window) /* Handle GtkHandleBox */
4938 g_list_free (dest_list);
4947 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4952 dest_list = g_list_remove (dest_list, dest_list->data);
4955 /* Translate from window relative to allocation relative */
4956 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4959 gdk_window_get_position (dest_priv->window, &wx, &wy);
4961 src_x += wx - dest_priv->allocation.x;
4962 src_y += wy - dest_priv->allocation.y;
4966 src_x -= dest_priv->allocation.x;
4967 src_y -= dest_priv->allocation.y;
4979 gtk_widget_real_size_allocate (GtkWidget *widget,
4980 GtkAllocation *allocation)
4982 GtkWidgetPrivate *priv = widget->priv;
4984 priv->allocation = *allocation;
4986 if (gtk_widget_get_realized (widget) &&
4987 gtk_widget_get_has_window (widget))
4989 gdk_window_move_resize (priv->window,
4990 allocation->x, allocation->y,
4991 allocation->width, allocation->height);
4996 adjust_for_align(GtkAlign align,
4998 gint *allocated_pos,
4999 gint *allocated_size)
5003 case GTK_ALIGN_FILL:
5004 /* change nothing */
5006 case GTK_ALIGN_START:
5007 /* keep *allocated_pos where it is */
5008 *allocated_size = MIN (*allocated_size, *natural_size);
5011 if (*allocated_size > *natural_size)
5013 *allocated_pos += (*allocated_size - *natural_size);
5014 *allocated_size = *natural_size;
5017 case GTK_ALIGN_CENTER:
5018 if (*allocated_size > *natural_size)
5020 *allocated_pos += (*allocated_size - *natural_size) / 2;
5021 *allocated_size = MIN (*allocated_size, *natural_size);
5028 adjust_for_margin(gint start_margin,
5032 gint *allocated_pos,
5033 gint *allocated_size)
5035 *minimum_size -= (start_margin + end_margin);
5036 *natural_size -= (start_margin + end_margin);
5037 *allocated_pos += start_margin;
5038 *allocated_size -= (start_margin + end_margin);
5042 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5043 GtkOrientation orientation,
5046 gint *allocated_pos,
5047 gint *allocated_size)
5049 const GtkWidgetAuxInfo *aux_info;
5051 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5053 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5055 adjust_for_margin (aux_info->margin.left,
5056 aux_info->margin.right,
5057 minimum_size, natural_size,
5058 allocated_pos, allocated_size);
5059 adjust_for_align (aux_info->halign,
5060 natural_size, allocated_pos, allocated_size);
5064 adjust_for_margin (aux_info->margin.top,
5065 aux_info->margin.bottom,
5066 minimum_size, natural_size,
5067 allocated_pos, allocated_size);
5068 adjust_for_align (aux_info->valign,
5069 natural_size, allocated_pos, allocated_size);
5074 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5077 GtkWidgetPrivate *priv = widget->priv;
5079 /* widgets must be onscreen for accels to take effect */
5080 return gtk_widget_is_sensitive (widget) &&
5081 gtk_widget_is_drawable (widget) &&
5082 gdk_window_is_viewable (priv->window);
5086 * gtk_widget_can_activate_accel:
5087 * @widget: a #GtkWidget
5088 * @signal_id: the ID of a signal installed on @widget
5090 * Determines whether an accelerator that activates the signal
5091 * identified by @signal_id can currently be activated.
5092 * This is done by emitting the #GtkWidget::can-activate-accel
5093 * signal on @widget; if the signal isn't overridden by a
5094 * handler or in a derived widget, then the default check is
5095 * that the widget must be sensitive, and the widget and all
5096 * its ancestors mapped.
5098 * Return value: %TRUE if the accelerator can be activated.
5103 gtk_widget_can_activate_accel (GtkWidget *widget,
5106 gboolean can_activate = FALSE;
5107 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5108 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5109 return can_activate;
5118 closure_accel_activate (GClosure *closure,
5119 GValue *return_value,
5120 guint n_param_values,
5121 const GValue *param_values,
5122 gpointer invocation_hint,
5123 gpointer marshal_data)
5125 AccelClosure *aclosure = (AccelClosure*) closure;
5126 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5129 g_signal_emit (closure->data, aclosure->signal_id, 0);
5131 /* whether accelerator was handled */
5132 g_value_set_boolean (return_value, can_activate);
5136 closures_destroy (gpointer data)
5138 GSList *slist, *closures = data;
5140 for (slist = closures; slist; slist = slist->next)
5142 g_closure_invalidate (slist->data);
5143 g_closure_unref (slist->data);
5145 g_slist_free (closures);
5149 widget_new_accel_closure (GtkWidget *widget,
5152 AccelClosure *aclosure;
5153 GClosure *closure = NULL;
5154 GSList *slist, *closures;
5156 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5157 for (slist = closures; slist; slist = slist->next)
5158 if (!gtk_accel_group_from_accel_closure (slist->data))
5160 /* reuse this closure */
5161 closure = slist->data;
5166 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5167 closures = g_slist_prepend (closures, g_closure_ref (closure));
5168 g_closure_sink (closure);
5169 g_closure_set_marshal (closure, closure_accel_activate);
5171 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5173 aclosure = (AccelClosure*) closure;
5174 g_assert (closure->data == widget);
5175 g_assert (closure->marshal == closure_accel_activate);
5176 aclosure->signal_id = signal_id;
5182 * gtk_widget_add_accelerator
5183 * @widget: widget to install an accelerator on
5184 * @accel_signal: widget signal to emit on accelerator activation
5185 * @accel_group: accel group for this widget, added to its toplevel
5186 * @accel_key: GDK keyval of the accelerator
5187 * @accel_mods: modifier key combination of the accelerator
5188 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5190 * Installs an accelerator for this @widget in @accel_group that causes
5191 * @accel_signal to be emitted if the accelerator is activated.
5192 * The @accel_group needs to be added to the widget's toplevel via
5193 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5194 * Accelerators added through this function are not user changeable during
5195 * runtime. If you want to support accelerators that can be changed by the
5196 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5197 * gtk_menu_item_set_accel_path() instead.
5200 gtk_widget_add_accelerator (GtkWidget *widget,
5201 const gchar *accel_signal,
5202 GtkAccelGroup *accel_group,
5204 GdkModifierType accel_mods,
5205 GtkAccelFlags accel_flags)
5210 g_return_if_fail (GTK_IS_WIDGET (widget));
5211 g_return_if_fail (accel_signal != NULL);
5212 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5214 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5215 if (!query.signal_id ||
5216 !(query.signal_flags & G_SIGNAL_ACTION) ||
5217 query.return_type != G_TYPE_NONE ||
5220 /* hmm, should be elaborate enough */
5221 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5222 G_OBJECT_TYPE_NAME (widget), accel_signal);
5226 closure = widget_new_accel_closure (widget, query.signal_id);
5228 g_object_ref (widget);
5230 /* install the accelerator. since we don't map this onto an accel_path,
5231 * the accelerator will automatically be locked.
5233 gtk_accel_group_connect (accel_group,
5236 accel_flags | GTK_ACCEL_LOCKED,
5239 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5241 g_object_unref (widget);
5245 * gtk_widget_remove_accelerator:
5246 * @widget: widget to install an accelerator on
5247 * @accel_group: accel group for this widget
5248 * @accel_key: GDK keyval of the accelerator
5249 * @accel_mods: modifier key combination of the accelerator
5250 * @returns: whether an accelerator was installed and could be removed
5252 * Removes an accelerator from @widget, previously installed with
5253 * gtk_widget_add_accelerator().
5256 gtk_widget_remove_accelerator (GtkWidget *widget,
5257 GtkAccelGroup *accel_group,
5259 GdkModifierType accel_mods)
5261 GtkAccelGroupEntry *ag_entry;
5262 GList *slist, *clist;
5265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5266 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5268 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5269 clist = gtk_widget_list_accel_closures (widget);
5270 for (slist = clist; slist; slist = slist->next)
5274 for (i = 0; i < n; i++)
5275 if (slist->data == (gpointer) ag_entry[i].closure)
5277 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5279 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5281 g_list_free (clist);
5286 g_list_free (clist);
5288 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5289 accel_key, accel_mods, accel_group,
5290 G_OBJECT_TYPE_NAME (widget), widget);
5296 * gtk_widget_list_accel_closures:
5297 * @widget: widget to list accelerator closures for
5299 * Lists the closures used by @widget for accelerator group connections
5300 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5301 * The closures can be used to monitor accelerator changes on @widget,
5302 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5303 * #GtkAccelGroup of a closure which can be found out with
5304 * gtk_accel_group_from_accel_closure().
5306 * Return value: (transfer container) (element-type GClosure):
5307 * a newly allocated #GList of closures
5310 gtk_widget_list_accel_closures (GtkWidget *widget)
5313 GList *clist = NULL;
5315 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5317 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5318 if (gtk_accel_group_from_accel_closure (slist->data))
5319 clist = g_list_prepend (clist, slist->data);
5325 GtkAccelGroup *accel_group;
5330 destroy_accel_path (gpointer data)
5332 AccelPath *apath = data;
5334 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5336 /* closures_destroy takes care of unrefing the closure */
5337 g_object_unref (apath->accel_group);
5339 g_slice_free (AccelPath, apath);
5344 * gtk_widget_set_accel_path:
5345 * @widget: a #GtkWidget
5346 * @accel_path: (allow-none): path used to look up the accelerator
5347 * @accel_group: (allow-none): a #GtkAccelGroup.
5349 * Given an accelerator group, @accel_group, and an accelerator path,
5350 * @accel_path, sets up an accelerator in @accel_group so whenever the
5351 * key binding that is defined for @accel_path is pressed, @widget
5352 * will be activated. This removes any accelerators (for any
5353 * accelerator group) installed by previous calls to
5354 * gtk_widget_set_accel_path(). Associating accelerators with
5355 * paths allows them to be modified by the user and the modifications
5356 * to be saved for future use. (See gtk_accel_map_save().)
5358 * This function is a low level function that would most likely
5359 * be used by a menu creation system like #GtkUIManager. If you
5360 * use #GtkUIManager, setting up accelerator paths will be done
5363 * Even when you you aren't using #GtkUIManager, if you only want to
5364 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5365 * provides a somewhat more convenient interface.
5367 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5368 * pass a static string, you can save some memory by interning it first with
5369 * g_intern_static_string().
5372 gtk_widget_set_accel_path (GtkWidget *widget,
5373 const gchar *accel_path,
5374 GtkAccelGroup *accel_group)
5378 g_return_if_fail (GTK_IS_WIDGET (widget));
5379 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5383 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5384 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5386 gtk_accel_map_add_entry (accel_path, 0, 0);
5387 apath = g_slice_new (AccelPath);
5388 apath->accel_group = g_object_ref (accel_group);
5389 apath->path_quark = g_quark_from_string (accel_path);
5390 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5395 /* also removes possible old settings */
5396 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5399 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5401 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5405 _gtk_widget_get_accel_path (GtkWidget *widget,
5410 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5412 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5414 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5415 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5419 * gtk_widget_mnemonic_activate:
5420 * @widget: a #GtkWidget
5421 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5423 * Emits the #GtkWidget::mnemonic-activate signal.
5425 * The default handler for this signal activates the @widget if
5426 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5429 * Returns: %TRUE if the signal has been handled
5432 gtk_widget_mnemonic_activate (GtkWidget *widget,
5433 gboolean group_cycling)
5437 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5439 group_cycling = group_cycling != FALSE;
5440 if (!gtk_widget_is_sensitive (widget))
5443 g_signal_emit (widget,
5444 widget_signals[MNEMONIC_ACTIVATE],
5452 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5453 gboolean group_cycling)
5455 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5456 gtk_widget_activate (widget);
5457 else if (gtk_widget_get_can_focus (widget))
5458 gtk_widget_grab_focus (widget);
5461 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5462 G_OBJECT_TYPE_NAME (widget));
5463 gtk_widget_error_bell (widget);
5468 static const cairo_user_data_key_t event_key;
5471 _gtk_cairo_get_event (cairo_t *cr)
5473 g_return_val_if_fail (cr != NULL, NULL);
5475 return cairo_get_user_data (cr, &event_key);
5479 gtk_cairo_set_event (cairo_t *cr,
5480 GdkEventExpose *event)
5482 cairo_set_user_data (cr, &event_key, event, NULL);
5486 * gtk_cairo_should_draw_window:
5487 * @cr: a cairo context
5488 * @window: the window to check
5490 * This function is supposed to be called in #GtkWidget::draw
5491 * implementations for widgets that support multiple windows.
5492 * @cr must be untransformed from invoking of the draw function.
5493 * This function will return %TRUE if the contents of the given
5494 * @window are supposed to be drawn and %FALSE otherwise. Note
5495 * that when the drawing was not initiated by the windowing
5496 * system this function will return %TRUE for all windows, so
5497 * you need to draw the bottommost window first. Also, do not
5498 * use "else if" statements to check which window should be drawn.
5500 * Returns: %TRUE if @window should be drawn
5503 gtk_cairo_should_draw_window (cairo_t *cr,
5506 GdkEventExpose *event;
5508 g_return_val_if_fail (cr != NULL, FALSE);
5509 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5511 event = _gtk_cairo_get_event (cr);
5513 return event == NULL ||
5514 event->window == window;
5517 /* code shared by gtk_container_propagate_draw() and
5521 _gtk_widget_draw_internal (GtkWidget *widget,
5523 gboolean clip_to_size)
5525 GtkStyleContext *context;
5527 if (!gtk_widget_is_drawable (widget))
5532 cairo_rectangle (cr,
5534 widget->priv->allocation.width,
5535 widget->priv->allocation.height);
5539 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5543 g_signal_emit (widget, widget_signals[DRAW],
5548 context = gtk_widget_get_style_context (widget);
5549 _gtk_style_context_coalesce_animation_areas (context, widget);
5554 * @widget: the widget to draw. It must be drawable (see
5555 * gtk_widget_is_drawable()) and a size must have been allocated.
5556 * @cr: a cairo context to draw to
5558 * Draws @widget to @cr. The top left corner of the widget will be
5559 * drawn to the currently set origin point of @cr.
5561 * You should pass a cairo context as @cr argument that is in an
5562 * original state. Otherwise the resulting drawing is undefined. For
5563 * example changing the operator using cairo_set_operator() or the
5564 * line width using cairo_set_line_width() might have unwanted side
5566 * You may however change the context's transform matrix - like with
5567 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5568 * region with cairo_clip() prior to calling this function. Also, it
5569 * is fine to modify the context with cairo_save() and
5570 * cairo_push_group() prior to calling this function.
5572 * <note><para>Special purpose widgets may contain special code for
5573 * rendering to the screen and might appear differently on screen
5574 * and when rendered using gtk_widget_draw().</para></note>
5577 gtk_widget_draw (GtkWidget *widget,
5580 GdkEventExpose *tmp_event;
5582 g_return_if_fail (GTK_IS_WIDGET (widget));
5583 g_return_if_fail (!widget->priv->alloc_needed);
5584 g_return_if_fail (cr != NULL);
5587 /* We have to reset the event here so that draw functions can call
5588 * gtk_widget_draw() on random other widgets and get the desired
5589 * effect: Drawing all contents, not just the current window.
5591 tmp_event = _gtk_cairo_get_event (cr);
5592 gtk_cairo_set_event (cr, NULL);
5594 _gtk_widget_draw_internal (widget, cr, TRUE);
5596 gtk_cairo_set_event (cr, tmp_event);
5601 gtk_widget_real_key_press_event (GtkWidget *widget,
5604 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5608 gtk_widget_real_key_release_event (GtkWidget *widget,
5611 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5615 gtk_widget_real_focus_in_event (GtkWidget *widget,
5616 GdkEventFocus *event)
5618 gtk_widget_queue_shallow_draw (widget);
5624 gtk_widget_real_focus_out_event (GtkWidget *widget,
5625 GdkEventFocus *event)
5627 gtk_widget_queue_shallow_draw (widget);
5632 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5633 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5637 * @widget: a #GtkWidget
5638 * @event: a #GdkEvent
5640 * Rarely-used function. This function is used to emit
5641 * the event signals on a widget (those signals should never
5642 * be emitted without using this function to do so).
5643 * If you want to synthesize an event though, don't use this function;
5644 * instead, use gtk_main_do_event() so the event will behave as if
5645 * it were in the event queue. Don't synthesize expose events; instead,
5646 * use gdk_window_invalidate_rect() to invalidate a region of the
5649 * Return value: return from the event signal emission (%TRUE if
5650 * the event was handled)
5653 gtk_widget_event (GtkWidget *widget,
5656 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5657 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5659 if (event->type == GDK_EXPOSE)
5661 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5662 "the same effect, call gdk_window_invalidate_rect/region(), "
5663 "followed by gdk_window_process_updates().");
5667 return gtk_widget_event_internal (widget, event);
5670 /* Returns TRUE if a translation should be done */
5672 _gtk_widget_get_translation_to_window (GtkWidget *widget,
5677 GdkWindow *w, *widget_window;
5679 if (!gtk_widget_get_has_window (widget))
5681 *x = -widget->priv->allocation.x;
5682 *y = -widget->priv->allocation.y;
5690 widget_window = gtk_widget_get_window (widget);
5692 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5695 gdk_window_get_position (w, &wx, &wy);
5712 * gtk_cairo_transform_to_window:
5713 * @cr: the cairo context to transform
5714 * @widget: the widget the context is currently centered for
5715 * @window: the window to transform the context to
5717 * Transforms the given cairo context @cr that from @widget-relative
5718 * coordinates to @window-relative coordinates.
5719 * If the @widget's window is not an ancestor of @window, no
5720 * modification will be applied.
5722 * This is the inverse to the transformation GTK applies when
5723 * preparing an expose event to be emitted with the #GtkWidget::draw
5724 * signal. It is intended to help porting multiwindow widgets from
5725 * GTK+ 2 to the rendering architecture of GTK+ 3.
5728 gtk_cairo_transform_to_window (cairo_t *cr,
5734 g_return_if_fail (cr != NULL);
5735 g_return_if_fail (GTK_IS_WIDGET (widget));
5736 g_return_if_fail (GDK_IS_WINDOW (window));
5738 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
5739 cairo_translate (cr, x, y);
5743 * gtk_widget_send_expose:
5744 * @widget: a #GtkWidget
5745 * @event: a expose #GdkEvent
5747 * Very rarely-used function. This function is used to emit
5748 * an expose event on a widget. This function is not normally used
5749 * directly. The only time it is used is when propagating an expose
5750 * event to a child %NO_WINDOW widget, and that is normally done
5751 * using gtk_container_propagate_draw().
5753 * If you want to force an area of a window to be redrawn,
5754 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5755 * To cause the redraw to be done immediately, follow that call
5756 * with a call to gdk_window_process_updates().
5758 * Return value: return from the event signal emission (%TRUE if
5759 * the event was handled)
5762 gtk_widget_send_expose (GtkWidget *widget,
5765 gboolean result = FALSE;
5770 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5771 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5772 g_return_val_if_fail (event != NULL, TRUE);
5773 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5775 cr = gdk_cairo_create (event->expose.window);
5776 gtk_cairo_set_event (cr, &event->expose);
5778 gdk_cairo_region (cr, event->expose.region);
5781 do_clip = _gtk_widget_get_translation_to_window (widget,
5782 event->expose.window,
5784 cairo_translate (cr, -x, -y);
5786 _gtk_widget_draw_internal (widget, cr, do_clip);
5788 /* unset here, so if someone keeps a reference to cr we
5789 * don't leak the window. */
5790 gtk_cairo_set_event (cr, NULL);
5797 event_window_is_still_viewable (GdkEvent *event)
5799 /* Check that we think the event's window is viewable before
5800 * delivering the event, to prevent suprises. We do this here
5801 * at the last moment, since the event may have been queued
5802 * up behind other events, held over a recursive main loop, etc.
5804 switch (event->type)
5807 case GDK_MOTION_NOTIFY:
5808 case GDK_BUTTON_PRESS:
5809 case GDK_2BUTTON_PRESS:
5810 case GDK_3BUTTON_PRESS:
5812 case GDK_ENTER_NOTIFY:
5813 case GDK_PROXIMITY_IN:
5815 return event->any.window && gdk_window_is_viewable (event->any.window);
5818 /* The following events are the second half of paired events;
5819 * we always deliver them to deal with widgets that clean up
5820 * on the second half.
5822 case GDK_BUTTON_RELEASE:
5823 case GDK_KEY_RELEASE:
5824 case GDK_LEAVE_NOTIFY:
5825 case GDK_PROXIMITY_OUT:
5829 /* Remaining events would make sense on an not-viewable window,
5830 * or don't have an associated window.
5837 gtk_widget_event_internal (GtkWidget *widget,
5840 gboolean return_val = FALSE;
5842 /* We check only once for is-still-visible; if someone
5843 * hides the window in on of the signals on the widget,
5844 * they are responsible for returning TRUE to terminate
5847 if (!event_window_is_still_viewable (event))
5850 g_object_ref (widget);
5852 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5853 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5858 switch (event->type)
5863 case GDK_BUTTON_PRESS:
5864 case GDK_2BUTTON_PRESS:
5865 case GDK_3BUTTON_PRESS:
5866 signal_num = BUTTON_PRESS_EVENT;
5869 signal_num = SCROLL_EVENT;
5871 case GDK_BUTTON_RELEASE:
5872 signal_num = BUTTON_RELEASE_EVENT;
5874 case GDK_MOTION_NOTIFY:
5875 signal_num = MOTION_NOTIFY_EVENT;
5878 signal_num = DELETE_EVENT;
5881 signal_num = DESTROY_EVENT;
5882 _gtk_tooltip_hide (widget);
5885 signal_num = KEY_PRESS_EVENT;
5887 case GDK_KEY_RELEASE:
5888 signal_num = KEY_RELEASE_EVENT;
5890 case GDK_ENTER_NOTIFY:
5891 signal_num = ENTER_NOTIFY_EVENT;
5893 case GDK_LEAVE_NOTIFY:
5894 signal_num = LEAVE_NOTIFY_EVENT;
5896 case GDK_FOCUS_CHANGE:
5897 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5898 if (event->focus_change.in)
5899 _gtk_tooltip_focus_in (widget);
5901 _gtk_tooltip_focus_out (widget);
5904 signal_num = CONFIGURE_EVENT;
5907 signal_num = MAP_EVENT;
5910 signal_num = UNMAP_EVENT;
5912 case GDK_WINDOW_STATE:
5913 signal_num = WINDOW_STATE_EVENT;
5915 case GDK_PROPERTY_NOTIFY:
5916 signal_num = PROPERTY_NOTIFY_EVENT;
5918 case GDK_SELECTION_CLEAR:
5919 signal_num = SELECTION_CLEAR_EVENT;
5921 case GDK_SELECTION_REQUEST:
5922 signal_num = SELECTION_REQUEST_EVENT;
5924 case GDK_SELECTION_NOTIFY:
5925 signal_num = SELECTION_NOTIFY_EVENT;
5927 case GDK_PROXIMITY_IN:
5928 signal_num = PROXIMITY_IN_EVENT;
5930 case GDK_PROXIMITY_OUT:
5931 signal_num = PROXIMITY_OUT_EVENT;
5933 case GDK_CLIENT_EVENT:
5934 signal_num = CLIENT_EVENT;
5937 signal_num = EXPOSE_EVENT;
5939 case GDK_VISIBILITY_NOTIFY:
5940 signal_num = VISIBILITY_NOTIFY_EVENT;
5942 case GDK_GRAB_BROKEN:
5943 signal_num = GRAB_BROKEN_EVENT;
5946 signal_num = DAMAGE_EVENT;
5949 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5953 if (signal_num != -1)
5954 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5956 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5957 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5961 g_object_unref (widget);
5967 * gtk_widget_activate:
5968 * @widget: a #GtkWidget that's activatable
5970 * For widgets that can be "activated" (buttons, menu items, etc.)
5971 * this function activates them. Activation is what happens when you
5972 * press Enter on a widget during key navigation. If @widget isn't
5973 * activatable, the function returns %FALSE.
5975 * Return value: %TRUE if the widget was activatable
5978 gtk_widget_activate (GtkWidget *widget)
5980 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5982 if (WIDGET_CLASS (widget)->activate_signal)
5984 /* FIXME: we should eventually check the signals signature here */
5985 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5994 gtk_widget_reparent_subwindows (GtkWidget *widget,
5995 GdkWindow *new_window)
5997 GtkWidgetPrivate *priv = widget->priv;
5999 if (!gtk_widget_get_has_window (widget))
6001 GList *children = gdk_window_get_children (priv->window);
6004 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6006 GdkWindow *window = tmp_list->data;
6009 gdk_window_get_user_data (window, &child);
6010 while (child && child != widget)
6011 child = ((GtkWidget*) child)->priv->parent;
6014 gdk_window_reparent (window, new_window, 0, 0);
6017 g_list_free (children);
6022 GList *tmp_list, *children;
6024 parent = gdk_window_get_parent (priv->window);
6027 gdk_window_reparent (priv->window, new_window, 0, 0);
6030 children = gdk_window_get_children (parent);
6032 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6034 GdkWindow *window = tmp_list->data;
6037 gdk_window_get_user_data (window, &child);
6039 if (child == widget)
6040 gdk_window_reparent (window, new_window, 0, 0);
6043 g_list_free (children);
6049 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6050 gpointer client_data)
6052 GtkWidgetPrivate *priv = widget->priv;
6054 g_assert (client_data != NULL);
6056 if (!gtk_widget_get_has_window (widget))
6059 g_object_unref (priv->window);
6060 priv->window = (GdkWindow*) client_data;
6062 g_object_ref (priv->window);
6064 if (GTK_IS_CONTAINER (widget))
6065 gtk_container_forall (GTK_CONTAINER (widget),
6066 gtk_widget_reparent_fixup_child,
6072 * gtk_widget_reparent:
6073 * @widget: a #GtkWidget
6074 * @new_parent: a #GtkContainer to move the widget into
6076 * Moves a widget from one #GtkContainer to another, handling reference
6077 * count issues to avoid destroying the widget.
6080 gtk_widget_reparent (GtkWidget *widget,
6081 GtkWidget *new_parent)
6083 GtkWidgetPrivate *priv;
6085 g_return_if_fail (GTK_IS_WIDGET (widget));
6086 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6087 priv = widget->priv;
6088 g_return_if_fail (priv->parent != NULL);
6090 if (priv->parent != new_parent)
6092 /* First try to see if we can get away without unrealizing
6093 * the widget as we reparent it. if so we set a flag so
6094 * that gtk_widget_unparent doesn't unrealize widget
6096 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6097 priv->in_reparent = TRUE;
6099 g_object_ref (widget);
6100 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6101 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6102 g_object_unref (widget);
6104 if (priv->in_reparent)
6106 priv->in_reparent = FALSE;
6108 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6109 gtk_widget_reparent_fixup_child (widget,
6110 gtk_widget_get_parent_window (widget));
6113 g_object_notify (G_OBJECT (widget), "parent");
6118 * gtk_widget_intersect:
6119 * @widget: a #GtkWidget
6120 * @area: a rectangle
6121 * @intersection: rectangle to store intersection of @widget and @area
6123 * Computes the intersection of a @widget's area and @area, storing
6124 * the intersection in @intersection, and returns %TRUE if there was
6125 * an intersection. @intersection may be %NULL if you're only
6126 * interested in whether there was an intersection.
6128 * Return value: %TRUE if there was an intersection
6131 gtk_widget_intersect (GtkWidget *widget,
6132 const GdkRectangle *area,
6133 GdkRectangle *intersection)
6135 GtkWidgetPrivate *priv;
6140 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6141 g_return_val_if_fail (area != NULL, FALSE);
6143 priv = widget->priv;
6146 dest = intersection;
6150 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6152 if (return_val && intersection && gtk_widget_get_has_window (widget))
6154 intersection->x -= priv->allocation.x;
6155 intersection->y -= priv->allocation.y;
6162 * gtk_widget_region_intersect:
6163 * @widget: a #GtkWidget
6164 * @region: a #cairo_region_t, in the same coordinate system as
6165 * @widget->allocation. That is, relative to @widget->window
6166 * for %NO_WINDOW widgets; relative to the parent window
6167 * of @widget->window for widgets with their own window.
6168 * @returns: A newly allocated region holding the intersection of @widget
6169 * and @region. The coordinates of the return value are
6170 * relative to @widget->window for %NO_WINDOW widgets, and
6171 * relative to the parent window of @widget->window for
6172 * widgets with their own window.
6174 * Computes the intersection of a @widget's area and @region, returning
6175 * the intersection. The result may be empty, use cairo_region_is_empty() to
6179 gtk_widget_region_intersect (GtkWidget *widget,
6180 const cairo_region_t *region)
6183 cairo_region_t *dest;
6185 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6186 g_return_val_if_fail (region != NULL, NULL);
6188 gtk_widget_get_allocation (widget, &rect);
6190 dest = cairo_region_create_rectangle (&rect);
6192 cairo_region_intersect (dest, region);
6198 * _gtk_widget_grab_notify:
6199 * @widget: a #GtkWidget
6200 * @was_grabbed: whether a grab is now in effect
6202 * Emits the #GtkWidget::grab-notify signal on @widget.
6207 _gtk_widget_grab_notify (GtkWidget *widget,
6208 gboolean was_grabbed)
6210 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6214 * gtk_widget_grab_focus:
6215 * @widget: a #GtkWidget
6217 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6218 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6219 * something like #GtkFrame won't work.
6221 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6222 * gtk_widget_set_can_focus() to modify that flag.
6224 * The widget also needs to be realized and mapped. This is indicated by the
6225 * related signals. Grabbing the focus immediately after creating the widget
6226 * will likely fail and cause critical warnings.
6229 gtk_widget_grab_focus (GtkWidget *widget)
6231 g_return_if_fail (GTK_IS_WIDGET (widget));
6233 if (!gtk_widget_is_sensitive (widget))
6236 g_object_ref (widget);
6237 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6238 g_object_notify (G_OBJECT (widget), "has-focus");
6239 g_object_unref (widget);
6243 reset_focus_recurse (GtkWidget *widget,
6246 if (GTK_IS_CONTAINER (widget))
6248 GtkContainer *container;
6250 container = GTK_CONTAINER (widget);
6251 gtk_container_set_focus_child (container, NULL);
6253 gtk_container_foreach (container,
6254 reset_focus_recurse,
6260 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6262 if (gtk_widget_get_can_focus (focus_widget))
6264 GtkWidget *toplevel;
6267 /* clear the current focus setting, break if the current widget
6268 * is the focus widget's parent, since containers above that will
6269 * be set by the next loop.
6271 toplevel = gtk_widget_get_toplevel (focus_widget);
6272 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6274 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6276 if (widget == focus_widget)
6278 /* We call _gtk_window_internal_set_focus() here so that the
6279 * toplevel window can request the focus if necessary.
6280 * This is needed when the toplevel is a GtkPlug
6282 if (!gtk_widget_has_focus (widget))
6283 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6290 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6292 widget = widget->priv->parent;
6293 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6297 else if (toplevel != focus_widget)
6299 /* gtk_widget_grab_focus() operates on a tree without window...
6300 * actually, this is very questionable behaviour.
6303 gtk_container_foreach (GTK_CONTAINER (toplevel),
6304 reset_focus_recurse,
6308 /* now propagate the new focus up the widget tree and finally
6309 * set it on the window
6311 widget = focus_widget;
6312 while (widget->priv->parent)
6314 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6315 widget = widget->priv->parent;
6317 if (GTK_IS_WINDOW (widget))
6318 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6323 gtk_widget_real_query_tooltip (GtkWidget *widget,
6326 gboolean keyboard_tip,
6327 GtkTooltip *tooltip)
6329 gchar *tooltip_markup;
6330 gboolean has_tooltip;
6332 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6333 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6335 if (has_tooltip && tooltip_markup)
6337 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6345 gtk_widget_real_style_updated (GtkWidget *widget)
6347 if (gtk_widget_get_realized (widget))
6349 /* Trigger ::style-set for old
6350 * widgets not listening to this
6352 g_signal_emit (widget,
6353 widget_signals[STYLE_SET],
6355 widget->priv->style);
6358 if (widget->priv->context)
6360 gtk_style_context_invalidate (widget->priv->context);
6362 if (gtk_widget_get_realized (widget) &&
6363 gtk_widget_get_has_window (widget))
6364 gtk_style_context_set_background (widget->priv->context,
6365 widget->priv->window);
6368 if (widget->priv->anchored)
6369 gtk_widget_queue_resize (widget);
6373 gtk_widget_real_show_help (GtkWidget *widget,
6374 GtkWidgetHelpType help_type)
6376 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6378 _gtk_tooltip_toggle_keyboard_mode (widget);
6387 gtk_widget_real_focus (GtkWidget *widget,
6388 GtkDirectionType direction)
6390 if (!gtk_widget_get_can_focus (widget))
6393 if (!gtk_widget_is_focus (widget))
6395 gtk_widget_grab_focus (widget);
6403 gtk_widget_real_move_focus (GtkWidget *widget,
6404 GtkDirectionType direction)
6406 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6408 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6410 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6416 gtk_widget_real_keynav_failed (GtkWidget *widget,
6417 GtkDirectionType direction)
6419 gboolean cursor_only;
6423 case GTK_DIR_TAB_FORWARD:
6424 case GTK_DIR_TAB_BACKWARD:
6431 g_object_get (gtk_widget_get_settings (widget),
6432 "gtk-keynav-cursor-only", &cursor_only,
6439 gtk_widget_error_bell (widget);
6445 * gtk_widget_set_can_focus:
6446 * @widget: a #GtkWidget
6447 * @can_focus: whether or not @widget can own the input focus.
6449 * Specifies whether @widget can own the input focus. See
6450 * gtk_widget_grab_focus() for actually setting the input focus on a
6456 gtk_widget_set_can_focus (GtkWidget *widget,
6459 g_return_if_fail (GTK_IS_WIDGET (widget));
6461 if (widget->priv->can_focus != can_focus)
6463 widget->priv->can_focus = can_focus;
6465 gtk_widget_queue_resize (widget);
6466 g_object_notify (G_OBJECT (widget), "can-focus");
6471 * gtk_widget_get_can_focus:
6472 * @widget: a #GtkWidget
6474 * Determines whether @widget can own the input focus. See
6475 * gtk_widget_set_can_focus().
6477 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6482 gtk_widget_get_can_focus (GtkWidget *widget)
6484 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6486 return widget->priv->can_focus;
6490 * gtk_widget_has_focus:
6491 * @widget: a #GtkWidget
6493 * Determines if the widget has the global input focus. See
6494 * gtk_widget_is_focus() for the difference between having the global
6495 * input focus, and only having the focus within a toplevel.
6497 * Return value: %TRUE if the widget has the global input focus.
6502 gtk_widget_has_focus (GtkWidget *widget)
6504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6506 return widget->priv->has_focus;
6510 * gtk_widget_is_focus:
6511 * @widget: a #GtkWidget
6513 * Determines if the widget is the focus widget within its
6514 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6515 * necessarily set; %HAS_FOCUS will only be set if the
6516 * toplevel widget additionally has the global input focus.)
6518 * Return value: %TRUE if the widget is the focus widget.
6521 gtk_widget_is_focus (GtkWidget *widget)
6523 GtkWidget *toplevel;
6525 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6527 toplevel = gtk_widget_get_toplevel (widget);
6529 if (GTK_IS_WINDOW (toplevel))
6530 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6536 * gtk_widget_set_can_default:
6537 * @widget: a #GtkWidget
6538 * @can_default: whether or not @widget can be a default widget.
6540 * Specifies whether @widget can be a default widget. See
6541 * gtk_widget_grab_default() for details about the meaning of
6547 gtk_widget_set_can_default (GtkWidget *widget,
6548 gboolean can_default)
6550 g_return_if_fail (GTK_IS_WIDGET (widget));
6552 if (widget->priv->can_default != can_default)
6554 widget->priv->can_default = can_default;
6556 gtk_widget_queue_resize (widget);
6557 g_object_notify (G_OBJECT (widget), "can-default");
6562 * gtk_widget_get_can_default:
6563 * @widget: a #GtkWidget
6565 * Determines whether @widget can be a default widget. See
6566 * gtk_widget_set_can_default().
6568 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6573 gtk_widget_get_can_default (GtkWidget *widget)
6575 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6577 return widget->priv->can_default;
6581 * gtk_widget_has_default:
6582 * @widget: a #GtkWidget
6584 * Determines whether @widget is the current default widget within its
6585 * toplevel. See gtk_widget_set_can_default().
6587 * Return value: %TRUE if @widget is the current default widget within
6588 * its toplevel, %FALSE otherwise
6593 gtk_widget_has_default (GtkWidget *widget)
6595 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6597 return widget->priv->has_default;
6601 _gtk_widget_set_has_default (GtkWidget *widget,
6602 gboolean has_default)
6604 widget->priv->has_default = has_default;
6608 * gtk_widget_grab_default:
6609 * @widget: a #GtkWidget
6611 * Causes @widget to become the default widget. @widget must have the
6612 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6613 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6614 * %TRUE)</literal>. The default widget is activated when
6615 * the user presses Enter in a window. Default widgets must be
6616 * activatable, that is, gtk_widget_activate() should affect them. Note
6617 * that #GtkEntry widgets require the "activates-default" property
6618 * set to %TRUE before they activate the default widget when Enter
6619 * is pressed and the #GtkEntry is focused.
6622 gtk_widget_grab_default (GtkWidget *widget)
6626 g_return_if_fail (GTK_IS_WIDGET (widget));
6627 g_return_if_fail (gtk_widget_get_can_default (widget));
6629 window = gtk_widget_get_toplevel (widget);
6631 if (window && gtk_widget_is_toplevel (window))
6632 gtk_window_set_default (GTK_WINDOW (window), widget);
6634 g_warning (G_STRLOC ": widget not within a GtkWindow");
6638 * gtk_widget_set_receives_default:
6639 * @widget: a #GtkWidget
6640 * @receives_default: whether or not @widget can be a default widget.
6642 * Specifies whether @widget will be treated as the default widget
6643 * within its toplevel when it has the focus, even if another widget
6646 * See gtk_widget_grab_default() for details about the meaning of
6652 gtk_widget_set_receives_default (GtkWidget *widget,
6653 gboolean receives_default)
6655 g_return_if_fail (GTK_IS_WIDGET (widget));
6657 if (widget->priv->receives_default != receives_default)
6659 widget->priv->receives_default = receives_default;
6661 g_object_notify (G_OBJECT (widget), "receives-default");
6666 * gtk_widget_get_receives_default:
6667 * @widget: a #GtkWidget
6669 * Determines whether @widget is alyways treated as default widget
6670 * withing its toplevel when it has the focus, even if another widget
6673 * See gtk_widget_set_receives_default().
6675 * Return value: %TRUE if @widget acts as default widget when focussed,
6681 gtk_widget_get_receives_default (GtkWidget *widget)
6683 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6685 return widget->priv->receives_default;
6689 * gtk_widget_has_grab:
6690 * @widget: a #GtkWidget
6692 * Determines whether the widget is currently grabbing events, so it
6693 * is the only widget receiving input events (keyboard and mouse).
6695 * See also gtk_grab_add().
6697 * Return value: %TRUE if the widget is in the grab_widgets stack
6702 gtk_widget_has_grab (GtkWidget *widget)
6704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6706 return widget->priv->has_grab;
6710 _gtk_widget_set_has_grab (GtkWidget *widget,
6713 widget->priv->has_grab = has_grab;
6717 * gtk_widget_device_is_shadowed:
6718 * @widget: a #GtkWidget
6719 * @device: a #GdkDevice
6721 * Returns %TRUE if @device has been shadowed by a GTK+
6722 * device grab on another widget, so it would stop sending
6723 * events to @widget. This may be used in the
6724 * #GtkWidget::grab-notify signal to check for specific
6725 * devices. See gtk_device_grab_add().
6727 * Returns: %TRUE if there is an ongoing grab on @device
6728 * by another #GtkWidget than @widget.
6733 gtk_widget_device_is_shadowed (GtkWidget *widget,
6736 GtkWindowGroup *group;
6737 GtkWidget *grab_widget, *toplevel;
6739 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6740 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6742 if (!gtk_widget_get_realized (widget))
6745 toplevel = gtk_widget_get_toplevel (widget);
6747 if (GTK_IS_WINDOW (toplevel))
6748 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6750 group = gtk_window_get_group (NULL);
6752 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6754 /* Widget not inside the hierarchy of grab_widget */
6756 widget != grab_widget &&
6757 !gtk_widget_is_ancestor (widget, grab_widget))
6760 grab_widget = gtk_window_group_get_current_grab (group);
6761 if (grab_widget && widget != grab_widget &&
6762 !gtk_widget_is_ancestor (widget, grab_widget))
6769 * gtk_widget_set_name:
6770 * @widget: a #GtkWidget
6771 * @name: name for the widget
6773 * Widgets can be named, which allows you to refer to them from a
6774 * CSS file. You can apply a style to widgets with a particular name
6775 * in the CSS file. See the documentation for the CSS syntax (on the
6776 * same page as the docs for #GtkStyleContext).
6778 * Note that the CSS syntax has certain special characters to delimit
6779 * and represent elements in a selector (period, #, >, *...),
6780 * so using these will make your widget impossible to match by name.
6781 * Any combination of alphanumeric symbols, dashes and underscores will
6785 gtk_widget_set_name (GtkWidget *widget,
6788 GtkWidgetPrivate *priv;
6791 g_return_if_fail (GTK_IS_WIDGET (widget));
6793 priv = widget->priv;
6795 new_name = g_strdup (name);
6796 g_free (priv->name);
6797 priv->name = new_name;
6803 pos = gtk_widget_path_length (priv->path) - 1;
6804 gtk_widget_path_iter_set_name (priv->path, pos,
6809 gtk_style_context_set_path (priv->context, priv->path);
6811 g_object_notify (G_OBJECT (widget), "name");
6815 * gtk_widget_get_name:
6816 * @widget: a #GtkWidget
6818 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6819 * significance of widget names.
6821 * Return value: name of the widget. This string is owned by GTK+ and
6822 * should not be modified or freed
6824 G_CONST_RETURN gchar*
6825 gtk_widget_get_name (GtkWidget *widget)
6827 GtkWidgetPrivate *priv;
6829 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6831 priv = widget->priv;
6835 return G_OBJECT_TYPE_NAME (widget);
6839 _gtk_widget_update_state_flags (GtkWidget *widget,
6840 GtkStateFlags flags,
6843 GtkWidgetPrivate *priv;
6845 priv = widget->priv;
6847 /* Handle insensitive first, since it is propagated
6848 * differently throughout the widget hierarchy.
6850 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6851 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6852 gtk_widget_set_sensitive (widget,
6853 operation != STATE_CHANGE_UNSET);
6855 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6858 operation == STATE_CHANGE_REPLACE)
6863 data.operation = operation;
6864 data.use_forall = FALSE;
6867 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6869 data.parent_sensitive = TRUE;
6871 gtk_widget_propagate_state (widget, &data);
6873 if (gtk_widget_is_drawable (widget))
6874 gtk_widget_queue_draw (widget);
6879 * gtk_widget_set_state_flags:
6880 * @widget: a #GtkWidget
6881 * @flags: State flags to turn on
6882 * @clear: Whether to clear state before turning on @flags
6884 * This function is for use in widget implementations. Turns on flag
6885 * values in the current widget state (insensitive, prelighted, etc.).
6887 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6888 * will be propagated down to all non-internal children if @widget is a
6889 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6890 * down to all #GtkContainer children by different means than turning on the
6891 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6892 * gtk_widget_is_sensitive() will make use of these.
6897 gtk_widget_set_state_flags (GtkWidget *widget,
6898 GtkStateFlags flags,
6901 g_return_if_fail (GTK_IS_WIDGET (widget));
6903 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6904 (clear && widget->priv->state_flags == flags))
6908 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6910 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6914 * gtk_widget_unset_state_flags:
6915 * @widget: a #GtkWidget
6916 * @flags: State flags to turn off
6918 * This function is for use in widget implementations. Turns off flag
6919 * values for the current widget state (insensitive, prelighted, etc.).
6920 * See gtk_widget_set_state_flags().
6925 gtk_widget_unset_state_flags (GtkWidget *widget,
6926 GtkStateFlags flags)
6928 g_return_if_fail (GTK_IS_WIDGET (widget));
6930 if ((widget->priv->state_flags & flags) == 0)
6933 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6937 * gtk_widget_get_state_flags:
6938 * @widget: a #GtkWidget
6940 * Returns the widget state as a flag set. It is worth mentioning
6941 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6942 * returned, that is, also based on parent insensitivity, even if
6943 * @widget itself is sensitive.
6945 * Returns: The state flags for widget
6950 gtk_widget_get_state_flags (GtkWidget *widget)
6952 GtkStateFlags flags;
6954 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6956 flags = widget->priv->state_flags;
6958 if (!gtk_widget_is_sensitive (widget))
6959 flags |= GTK_STATE_FLAG_INSENSITIVE;
6965 * gtk_widget_set_state:
6966 * @widget: a #GtkWidget
6967 * @state: new state for @widget
6969 * This function is for use in widget implementations. Sets the state
6970 * of a widget (insensitive, prelighted, etc.) Usually you should set
6971 * the state using wrapper functions such as gtk_widget_set_sensitive().
6973 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6976 gtk_widget_set_state (GtkWidget *widget,
6979 GtkStateFlags flags;
6981 if (state == gtk_widget_get_state (widget))
6986 case GTK_STATE_ACTIVE:
6987 flags = GTK_STATE_FLAG_ACTIVE;
6989 case GTK_STATE_PRELIGHT:
6990 flags = GTK_STATE_FLAG_PRELIGHT;
6992 case GTK_STATE_SELECTED:
6993 flags = GTK_STATE_FLAG_SELECTED;
6995 case GTK_STATE_INSENSITIVE:
6996 flags = GTK_STATE_FLAG_INSENSITIVE;
6998 case GTK_STATE_INCONSISTENT:
6999 flags = GTK_STATE_FLAG_INCONSISTENT;
7001 case GTK_STATE_FOCUSED:
7002 flags = GTK_STATE_FLAG_FOCUSED;
7004 case GTK_STATE_NORMAL:
7010 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
7014 * gtk_widget_get_state:
7015 * @widget: a #GtkWidget
7017 * Returns the widget's state. See gtk_widget_set_state().
7019 * Returns: the state of @widget.
7023 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7026 gtk_widget_get_state (GtkWidget *widget)
7028 GtkStateFlags flags;
7030 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7032 flags = gtk_widget_get_state_flags (widget);
7034 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7035 return GTK_STATE_INSENSITIVE;
7036 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
7037 return GTK_STATE_INCONSISTENT;
7038 else if (flags & GTK_STATE_FLAG_ACTIVE)
7039 return GTK_STATE_ACTIVE;
7040 else if (flags & GTK_STATE_FLAG_SELECTED)
7041 return GTK_STATE_SELECTED;
7042 else if (flags & GTK_STATE_FLAG_FOCUSED)
7043 return GTK_STATE_FOCUSED;
7044 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7045 return GTK_STATE_PRELIGHT;
7047 return GTK_STATE_NORMAL;
7051 * gtk_widget_set_visible:
7052 * @widget: a #GtkWidget
7053 * @visible: whether the widget should be shown or not
7055 * Sets the visibility state of @widget. Note that setting this to
7056 * %TRUE doesn't mean the widget is actually viewable, see
7057 * gtk_widget_get_visible().
7059 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7060 * but is nicer to use when the visibility of the widget depends on
7066 gtk_widget_set_visible (GtkWidget *widget,
7069 g_return_if_fail (GTK_IS_WIDGET (widget));
7071 if (visible != gtk_widget_get_visible (widget))
7074 gtk_widget_show (widget);
7076 gtk_widget_hide (widget);
7081 _gtk_widget_set_visible_flag (GtkWidget *widget,
7084 widget->priv->visible = visible;
7088 * gtk_widget_get_visible:
7089 * @widget: a #GtkWidget
7091 * Determines whether the widget is visible. Note that this doesn't
7092 * take into account whether the widget's parent is also visible
7093 * or the widget is obscured in any way.
7095 * See gtk_widget_set_visible().
7097 * Return value: %TRUE if the widget is visible
7102 gtk_widget_get_visible (GtkWidget *widget)
7104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7106 return widget->priv->visible;
7110 * gtk_widget_set_has_window:
7111 * @widget: a #GtkWidget
7112 * @has_window: whether or not @widget has a window.
7114 * Specifies whether @widget has a #GdkWindow of its own. Note that
7115 * all realized widgets have a non-%NULL "window" pointer
7116 * (gtk_widget_get_window() never returns a %NULL window when a widget
7117 * is realized), but for many of them it's actually the #GdkWindow of
7118 * one of its parent widgets. Widgets that do not create a %window for
7119 * themselves in #GtkWidget::realize must announce this by
7120 * calling this function with @has_window = %FALSE.
7122 * This function should only be called by widget implementations,
7123 * and they should call it in their init() function.
7128 gtk_widget_set_has_window (GtkWidget *widget,
7129 gboolean has_window)
7131 g_return_if_fail (GTK_IS_WIDGET (widget));
7133 widget->priv->no_window = !has_window;
7137 * gtk_widget_get_has_window:
7138 * @widget: a #GtkWidget
7140 * Determines whether @widget has a #GdkWindow of its own. See
7141 * gtk_widget_set_has_window().
7143 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7148 gtk_widget_get_has_window (GtkWidget *widget)
7150 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7152 return ! widget->priv->no_window;
7156 * gtk_widget_is_toplevel:
7157 * @widget: a #GtkWidget
7159 * Determines whether @widget is a toplevel widget.
7161 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7162 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7165 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7170 gtk_widget_is_toplevel (GtkWidget *widget)
7172 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7174 return widget->priv->toplevel;
7178 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7179 gboolean is_toplevel)
7181 widget->priv->toplevel = is_toplevel;
7185 * gtk_widget_is_drawable:
7186 * @widget: a #GtkWidget
7188 * Determines whether @widget can be drawn to. A widget can be drawn
7189 * to if it is mapped and visible.
7191 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7196 gtk_widget_is_drawable (GtkWidget *widget)
7198 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7200 return (gtk_widget_get_visible (widget) &&
7201 gtk_widget_get_mapped (widget));
7205 * gtk_widget_get_realized:
7206 * @widget: a #GtkWidget
7208 * Determines whether @widget is realized.
7210 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7215 gtk_widget_get_realized (GtkWidget *widget)
7217 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7219 return widget->priv->realized;
7223 * gtk_widget_set_realized:
7224 * @widget: a #GtkWidget
7225 * @realized: %TRUE to mark the widget as realized
7227 * Marks the widget as being realized.
7229 * This function should only ever be called in a derived widget's
7230 * "realize" or "unrealize" implementation.
7235 gtk_widget_set_realized (GtkWidget *widget,
7238 g_return_if_fail (GTK_IS_WIDGET (widget));
7240 widget->priv->realized = realized;
7244 * gtk_widget_get_mapped:
7245 * @widget: a #GtkWidget
7247 * Whether the widget is mapped.
7249 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7254 gtk_widget_get_mapped (GtkWidget *widget)
7256 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7258 return widget->priv->mapped;
7262 * gtk_widget_set_mapped:
7263 * @widget: a #GtkWidget
7264 * @mapped: %TRUE to mark the widget as mapped
7266 * Marks the widget as being realized.
7268 * This function should only ever be called in a derived widget's
7269 * "map" or "unmap" implementation.
7274 gtk_widget_set_mapped (GtkWidget *widget,
7277 g_return_if_fail (GTK_IS_WIDGET (widget));
7279 widget->priv->mapped = mapped;
7283 * gtk_widget_set_app_paintable:
7284 * @widget: a #GtkWidget
7285 * @app_paintable: %TRUE if the application will paint on the widget
7287 * Sets whether the application intends to draw on the widget in
7288 * an #GtkWidget::draw handler.
7290 * This is a hint to the widget and does not affect the behavior of
7291 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7292 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7293 * the effect is to suppress default themed drawing of the widget's
7294 * background. (Children of the widget will still be drawn.) The application
7295 * is then entirely responsible for drawing the widget background.
7297 * Note that the background is still drawn when the widget is mapped.
7300 gtk_widget_set_app_paintable (GtkWidget *widget,
7301 gboolean app_paintable)
7303 g_return_if_fail (GTK_IS_WIDGET (widget));
7305 app_paintable = (app_paintable != FALSE);
7307 if (widget->priv->app_paintable != app_paintable)
7309 widget->priv->app_paintable = app_paintable;
7311 if (gtk_widget_is_drawable (widget))
7312 gtk_widget_queue_draw (widget);
7314 g_object_notify (G_OBJECT (widget), "app-paintable");
7319 * gtk_widget_get_app_paintable:
7320 * @widget: a #GtkWidget
7322 * Determines whether the application intends to draw on the widget in
7323 * an #GtkWidget::draw handler.
7325 * See gtk_widget_set_app_paintable()
7327 * Return value: %TRUE if the widget is app paintable
7332 gtk_widget_get_app_paintable (GtkWidget *widget)
7334 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7336 return widget->priv->app_paintable;
7340 * gtk_widget_set_double_buffered:
7341 * @widget: a #GtkWidget
7342 * @double_buffered: %TRUE to double-buffer a widget
7344 * Widgets are double buffered by default; you can use this function
7345 * to turn off the buffering. "Double buffered" simply means that
7346 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7347 * automatically around expose events sent to the
7348 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7349 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7350 * buffer to the screen. The result is that users see the window
7351 * update in one smooth step, and don't see individual graphics
7352 * primitives being rendered.
7354 * In very simple terms, double buffered widgets don't flicker,
7355 * so you would only use this function to turn off double buffering
7356 * if you had special needs and really knew what you were doing.
7358 * Note: if you turn off double-buffering, you have to handle
7359 * expose events, since even the clearing to the background color or
7360 * pixmap will not happen automatically (as it is done in
7361 * gdk_window_begin_paint()).
7364 gtk_widget_set_double_buffered (GtkWidget *widget,
7365 gboolean double_buffered)
7367 g_return_if_fail (GTK_IS_WIDGET (widget));
7369 double_buffered = (double_buffered != FALSE);
7371 if (widget->priv->double_buffered != double_buffered)
7373 widget->priv->double_buffered = double_buffered;
7375 g_object_notify (G_OBJECT (widget), "double-buffered");
7380 * gtk_widget_get_double_buffered:
7381 * @widget: a #GtkWidget
7383 * Determines whether the widget is double buffered.
7385 * See gtk_widget_set_double_buffered()
7387 * Return value: %TRUE if the widget is double buffered
7392 gtk_widget_get_double_buffered (GtkWidget *widget)
7394 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7396 return widget->priv->double_buffered;
7400 * gtk_widget_set_redraw_on_allocate:
7401 * @widget: a #GtkWidget
7402 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7403 * when it is allocated to a new size. Otherwise, only the
7404 * new portion of the widget will be redrawn.
7406 * Sets whether the entire widget is queued for drawing when its size
7407 * allocation changes. By default, this setting is %TRUE and
7408 * the entire widget is redrawn on every size change. If your widget
7409 * leaves the upper left unchanged when made bigger, turning this
7410 * setting off will improve performance.
7412 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7413 * off all allocation on resizing: the widget will not even redraw if
7414 * its position changes; this is to allow containers that don't draw
7415 * anything to avoid excess invalidations. If you set this flag on a
7416 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7417 * you are responsible for invalidating both the old and new allocation
7418 * of the widget when the widget is moved and responsible for invalidating
7419 * regions newly when the widget increases size.
7422 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7423 gboolean redraw_on_allocate)
7425 g_return_if_fail (GTK_IS_WIDGET (widget));
7427 widget->priv->redraw_on_alloc = redraw_on_allocate;
7431 * gtk_widget_set_sensitive:
7432 * @widget: a #GtkWidget
7433 * @sensitive: %TRUE to make the widget sensitive
7435 * Sets the sensitivity of a widget. A widget is sensitive if the user
7436 * can interact with it. Insensitive widgets are "grayed out" and the
7437 * user can't interact with them. Insensitive widgets are known as
7438 * "inactive", "disabled", or "ghosted" in some other toolkits.
7441 gtk_widget_set_sensitive (GtkWidget *widget,
7444 GtkWidgetPrivate *priv;
7447 g_return_if_fail (GTK_IS_WIDGET (widget));
7449 priv = widget->priv;
7451 sensitive = (sensitive != FALSE);
7453 if (widget->priv->sensitive == sensitive)
7456 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7460 widget->priv->sensitive = TRUE;
7461 data.operation = STATE_CHANGE_UNSET;
7465 widget->priv->sensitive = FALSE;
7466 data.operation = STATE_CHANGE_SET;
7469 data.use_forall = TRUE;
7472 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7474 data.parent_sensitive = TRUE;
7476 gtk_widget_propagate_state (widget, &data);
7478 if (gtk_widget_is_drawable (widget))
7479 gtk_widget_queue_draw (widget);
7481 g_object_notify (G_OBJECT (widget), "sensitive");
7485 * gtk_widget_get_sensitive:
7486 * @widget: a #GtkWidget
7488 * Returns the widget's sensitivity (in the sense of returning
7489 * the value that has been set using gtk_widget_set_sensitive()).
7491 * The effective sensitivity of a widget is however determined by both its
7492 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7494 * Returns: %TRUE if the widget is sensitive
7499 gtk_widget_get_sensitive (GtkWidget *widget)
7501 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7503 return widget->priv->sensitive;
7507 * gtk_widget_is_sensitive:
7508 * @widget: a #GtkWidget
7510 * Returns the widget's effective sensitivity, which means
7511 * it is sensitive itself and also its parent widget is sensntive
7513 * Returns: %TRUE if the widget is effectively sensitive
7518 gtk_widget_is_sensitive (GtkWidget *widget)
7520 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7522 return widget->priv->sensitive && widget->priv->parent_sensitive;
7526 _gtk_widget_update_path (GtkWidget *widget)
7528 if (widget->priv->path)
7530 gtk_widget_path_free (widget->priv->path);
7531 widget->priv->path = NULL;
7534 gtk_widget_get_path (widget);
7538 * gtk_widget_set_parent:
7539 * @widget: a #GtkWidget
7540 * @parent: parent container
7542 * This function is useful only when implementing subclasses of
7544 * Sets the container as the parent of @widget, and takes care of
7545 * some details such as updating the state and style of the child
7546 * to reflect its new location. The opposite function is
7547 * gtk_widget_unparent().
7550 gtk_widget_set_parent (GtkWidget *widget,
7553 GtkStateFlags parent_flags;
7554 GtkWidgetPrivate *priv;
7557 g_return_if_fail (GTK_IS_WIDGET (widget));
7558 g_return_if_fail (GTK_IS_WIDGET (parent));
7559 g_return_if_fail (widget != parent);
7561 priv = widget->priv;
7563 if (priv->parent != NULL)
7565 g_warning ("Can't set a parent on widget which has a parent\n");
7568 if (gtk_widget_is_toplevel (widget))
7570 g_warning ("Can't set a parent on a toplevel widget\n");
7574 /* keep this function in sync with gtk_menu_attach_to_widget()
7577 g_object_ref_sink (widget);
7579 gtk_widget_push_verify_invariants (widget);
7581 priv->parent = parent;
7583 parent_flags = gtk_widget_get_state_flags (parent);
7585 /* Merge both old state and current parent state,
7586 * We don't want the insensitive flag to propagate
7587 * to the new child though */
7588 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7589 data.flags |= priv->state_flags;
7591 data.operation = STATE_CHANGE_REPLACE;
7592 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7593 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7594 gtk_widget_propagate_state (widget, &data);
7596 gtk_widget_reset_rc_styles (widget);
7598 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7599 if (priv->parent->priv->anchored)
7600 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7601 g_object_notify (G_OBJECT (widget), "parent");
7603 /* Enforce realized/mapped invariants
7605 if (gtk_widget_get_realized (priv->parent))
7606 gtk_widget_realize (widget);
7608 if (gtk_widget_get_visible (priv->parent) &&
7609 gtk_widget_get_visible (widget))
7611 if (gtk_widget_get_child_visible (widget) &&
7612 gtk_widget_get_mapped (priv->parent))
7613 gtk_widget_map (widget);
7615 gtk_widget_queue_resize (widget);
7618 /* child may cause parent's expand to change, if the child is
7619 * expanded. If child is not expanded, then it can't modify the
7620 * parent's expand. If the child becomes expanded later then it will
7621 * queue compute_expand then. This optimization plus defaulting
7622 * newly-constructed widgets to need_compute_expand=FALSE should
7623 * mean that initially building a widget tree doesn't have to keep
7624 * walking up setting need_compute_expand on parents over and over.
7626 * We can't change a parent to need to expand unless we're visible.
7628 if (gtk_widget_get_visible (widget) &&
7629 (priv->need_compute_expand ||
7630 priv->computed_hexpand ||
7631 priv->computed_vexpand))
7633 gtk_widget_queue_compute_expand (parent);
7636 if (widget->priv->context)
7638 _gtk_widget_update_path (widget);
7639 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7641 gtk_style_context_set_screen (widget->priv->context,
7642 gtk_widget_get_screen (widget));
7645 gtk_widget_pop_verify_invariants (widget);
7649 * gtk_widget_get_parent:
7650 * @widget: a #GtkWidget
7652 * Returns the parent container of @widget.
7654 * Return value: (transfer none): the parent container of @widget, or %NULL
7657 gtk_widget_get_parent (GtkWidget *widget)
7659 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7661 return widget->priv->parent;
7664 /*****************************************
7666 * see docs/styles.txt
7667 *****************************************/
7670 * gtk_widget_style_attach:
7671 * @widget: a #GtkWidget
7673 * This function attaches the widget's #GtkStyle to the widget's
7674 * #GdkWindow. It is a replacement for
7677 * widget->style = gtk_style_attach (widget->style, widget->window);
7680 * and should only ever be called in a derived widget's "realize"
7681 * implementation which does not chain up to its parent class'
7682 * "realize" implementation, because one of the parent classes
7683 * (finally #GtkWidget) would attach the style itself.
7688 gtk_widget_style_attach (GtkWidget *widget)
7690 GtkWidgetPrivate *priv;
7692 g_return_if_fail (GTK_IS_WIDGET (widget));
7693 g_return_if_fail (gtk_widget_get_realized (widget));
7695 priv = widget->priv;
7697 priv->style = gtk_style_attach (priv->style, priv->window);
7701 * gtk_widget_has_rc_style:
7702 * @widget: a #GtkWidget
7704 * Determines if the widget style has been looked up through the rc mechanism.
7706 * Returns: %TRUE if the widget has been looked up through the rc
7707 * mechanism, %FALSE otherwise.
7711 * Deprecated:3.0: Use #GtkStyleContext instead
7714 gtk_widget_has_rc_style (GtkWidget *widget)
7716 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7718 return widget->priv->rc_style;
7722 * gtk_widget_set_style:
7723 * @widget: a #GtkWidget
7724 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7725 * gtk_widget_set_style() and go back to the default style
7727 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7728 * want to use this function; it interacts badly with themes, because
7729 * themes work by replacing the #GtkStyle. Instead, use
7730 * gtk_widget_modify_style().
7732 * Deprecated:3.0: Use #GtkStyleContext instead
7735 gtk_widget_set_style (GtkWidget *widget,
7738 g_return_if_fail (GTK_IS_WIDGET (widget));
7742 * gtk_widget_ensure_style:
7743 * @widget: a #GtkWidget
7745 * Ensures that @widget has a style (@widget->style). Not a very useful
7746 * function; most of the time, if you want the style, the widget is
7747 * realized, and realized widgets are guaranteed to have a style
7750 * Deprecated:3.0: Use #GtkStyleContext instead
7753 gtk_widget_ensure_style (GtkWidget *widget)
7755 g_return_if_fail (GTK_IS_WIDGET (widget));
7757 if (!widget->priv->style ||
7758 widget->priv->style == gtk_widget_get_default_style ())
7762 if (widget->priv->style)
7763 g_object_unref (widget->priv->style);
7765 style = g_object_new (GTK_TYPE_STYLE,
7766 "context", gtk_widget_get_style_context (widget),
7769 widget->priv->style = g_object_ref (style);
7771 g_signal_emit (widget,
7772 widget_signals[STYLE_SET],
7775 g_object_unref (style);
7780 * gtk_widget_get_style:
7781 * @widget: a #GtkWidget
7783 * Simply an accessor function that returns @widget->style.
7785 * Return value: (transfer none): the widget's #GtkStyle
7787 * Deprecated:3.0: Use #GtkStyleContext instead
7790 gtk_widget_get_style (GtkWidget *widget)
7792 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7794 return widget->priv->style;
7798 * gtk_widget_modify_style:
7799 * @widget: a #GtkWidget
7800 * @style: the #GtkRcStyle holding the style modifications
7802 * Modifies style values on the widget. Modifications made using this
7803 * technique take precedence over style values set via an RC file,
7804 * however, they will be overriden if a style is explicitely set on
7805 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7806 * is designed so each field can either be set or unset, so it is
7807 * possible, using this function, to modify some style values and
7808 * leave the others unchanged.
7810 * Note that modifications made with this function are not cumulative
7811 * with previous calls to gtk_widget_modify_style() or with such
7812 * functions as gtk_widget_modify_fg(). If you wish to retain
7813 * previous values, you must first call gtk_widget_get_modifier_style(),
7814 * make your modifications to the returned style, then call
7815 * gtk_widget_modify_style() with that style. On the other hand,
7816 * if you first call gtk_widget_modify_style(), subsequent calls
7817 * to such functions gtk_widget_modify_fg() will have a cumulative
7818 * effect with the initial modifications.
7820 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7823 gtk_widget_modify_style (GtkWidget *widget,
7826 g_return_if_fail (GTK_IS_WIDGET (widget));
7827 g_return_if_fail (GTK_IS_RC_STYLE (style));
7829 g_object_set_qdata_full (G_OBJECT (widget),
7831 gtk_rc_style_copy (style),
7832 (GDestroyNotify) g_object_unref);
7836 * gtk_widget_get_modifier_style:
7837 * @widget: a #GtkWidget
7839 * Returns the current modifier style for the widget. (As set by
7840 * gtk_widget_modify_style().) If no style has previously set, a new
7841 * #GtkRcStyle will be created with all values unset, and set as the
7842 * modifier style for the widget. If you make changes to this rc
7843 * style, you must call gtk_widget_modify_style(), passing in the
7844 * returned rc style, to make sure that your changes take effect.
7846 * Caution: passing the style back to gtk_widget_modify_style() will
7847 * normally end up destroying it, because gtk_widget_modify_style() copies
7848 * the passed-in style and sets the copy as the new modifier style,
7849 * thus dropping any reference to the old modifier style. Add a reference
7850 * to the modifier style if you want to keep it alive.
7852 * Return value: (transfer none): the modifier style for the widget.
7853 * This rc style is owned by the widget. If you want to keep a
7854 * pointer to value this around, you must add a refcount using
7857 * Deprecated:3.0: Use #GtkStyleContext with a custom #GtkStyleProvider instead
7860 gtk_widget_get_modifier_style (GtkWidget *widget)
7862 GtkRcStyle *rc_style;
7864 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7866 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7870 rc_style = gtk_rc_style_new ();
7871 g_object_set_qdata_full (G_OBJECT (widget),
7874 (GDestroyNotify) g_object_unref);
7881 gtk_widget_modify_color_component (GtkWidget *widget,
7882 GtkRcFlags component,
7884 const GdkColor *color)
7886 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7893 rc_style->fg[state] = *color;
7896 rc_style->bg[state] = *color;
7899 rc_style->text[state] = *color;
7902 rc_style->base[state] = *color;
7905 g_assert_not_reached();
7908 rc_style->color_flags[state] |= component;
7911 rc_style->color_flags[state] &= ~component;
7913 gtk_widget_modify_style (widget, rc_style);
7917 modifier_style_changed (GtkModifierStyle *style,
7920 GtkStyleContext *context;
7922 context = gtk_widget_get_style_context (widget);
7923 gtk_style_context_invalidate (context);
7926 static GtkModifierStyle *
7927 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7929 GtkModifierStyle *style;
7931 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7933 if (G_UNLIKELY (!style))
7935 GtkStyleContext *context;
7937 style = gtk_modifier_style_new ();
7938 g_object_set_qdata_full (G_OBJECT (widget),
7939 quark_modifier_style,
7941 (GDestroyNotify) g_object_unref);
7943 g_signal_connect (style, "changed",
7944 G_CALLBACK (modifier_style_changed), widget);
7946 context = gtk_widget_get_style_context (widget);
7948 gtk_style_context_add_provider (context,
7949 GTK_STYLE_PROVIDER (style),
7950 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7957 * gtk_widget_override_color:
7958 * @widget: a #GtkWidget
7959 * @state: the state for which to set the color
7960 * @color: the color to assign, or %NULL to undo the effect
7961 * of previous calls to gtk_widget_override_color()
7963 * Sets the color to use for a widget. All other style values are left
7968 * This API is mostly meant as a quick way for applications to change a
7969 * widget appearance. If you are developing a widgets library and intend
7970 * this change to be themeable, it is better done by setting meaningful
7971 * CSS classes and regions in your widget/container implementation through
7972 * gtk_style_context_add_class() and gtk_style_context_add_region().
7975 * This way, your widget library can install a #GtkCssProvider with the
7976 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
7977 * default styling for those widgets that need so, and this theming may
7978 * fully overridden by the user's theme.
7984 * Note that for complex widgets this may bring in
7985 * undesired results (such as uniform background color everywhere),
7986 * in these cases it is better to fully style such widgets through a
7987 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7995 gtk_widget_override_color (GtkWidget *widget,
7996 GtkStateFlags state,
7997 const GdkRGBA *color)
7999 GtkModifierStyle *style;
8001 g_return_if_fail (GTK_IS_WIDGET (widget));
8003 style = _gtk_widget_get_modifier_properties (widget);
8004 gtk_modifier_style_set_color (style, state, color);
8008 * gtk_widget_override_background_color:
8009 * @widget: a #GtkWidget
8010 * @state: the state for which to set the background color
8011 * @color: the color to assign, or %NULL to undo the effect
8012 * of previous calls to gtk_widget_override_background_color()
8014 * Sets the background color to use for a widget. All other style values
8015 * are left untouched. See gtk_widget_override_color().
8020 gtk_widget_override_background_color (GtkWidget *widget,
8021 GtkStateFlags state,
8022 const GdkRGBA *color)
8024 GtkModifierStyle *style;
8026 g_return_if_fail (GTK_IS_WIDGET (widget));
8028 style = _gtk_widget_get_modifier_properties (widget);
8029 gtk_modifier_style_set_background_color (style, state, color);
8033 * gtk_widget_override_font:
8034 * @widget: a #GtkWidget
8035 * @font_desc: the font descriptiong to use, or %NULL to undo
8036 * the effect of previous calls to
8037 * gtk_widget_override_font().
8039 * Sets the font to use for a widget. All other style values are
8040 * left untouched. See gtk_widget_override_color().
8045 gtk_widget_override_font (GtkWidget *widget,
8046 const PangoFontDescription *font_desc)
8048 GtkModifierStyle *style;
8050 g_return_if_fail (GTK_IS_WIDGET (widget));
8052 style = _gtk_widget_get_modifier_properties (widget);
8053 gtk_modifier_style_set_font (style, font_desc);
8057 * gtk_widget_override_symbolic_color:
8058 * @widget: a #GtkWidget
8059 * @name: the name of the symbolic color to modify
8060 * @color: (allow-none): the color to assign (does not need to be allocated),
8061 * or %NULL to undo the effect of previous calls to
8062 * gtk_widget_override_symbolic_color().
8064 * Sets a symbolic color for a widget, All other style values are left
8065 * untouched. See gtk_widget_override_color() for overriding the foreground
8066 * or background color.
8071 gtk_widget_override_symbolic_color (GtkWidget *widget,
8073 const GdkRGBA *color)
8075 GtkModifierStyle *style;
8077 g_return_if_fail (GTK_IS_WIDGET (widget));
8079 style = _gtk_widget_get_modifier_properties (widget);
8080 gtk_modifier_style_map_color (style, name, color);
8084 * gtk_widget_override_cursor:
8085 * @widget: a #GtkWidget
8086 * @cursor: the color to use for primary cursor (does not need to be
8087 * allocated), or %NULL to undo the effect of previous calls to
8088 * of gtk_widget_override_cursor().
8089 * @secondary_cursor: the color to use for secondary cursor (does not
8090 * need to be allocated), or %NULL to undo the effect of previous
8091 * calls to of gtk_widget_override_cursor().
8093 * Sets the cursor color to use in a widget, overriding the
8094 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8095 * style properties. All other style values are left untouched.
8096 * See also gtk_widget_modify_style().
8098 * Note that the underlying properties have the #GdkColor type,
8099 * so the alpha value in @primary and @secondary will be ignored.
8104 gtk_widget_override_cursor (GtkWidget *widget,
8105 const GdkRGBA *cursor,
8106 const GdkRGBA *secondary_cursor)
8108 GtkModifierStyle *style;
8110 g_return_if_fail (GTK_IS_WIDGET (widget));
8112 style = _gtk_widget_get_modifier_properties (widget);
8113 gtk_modifier_style_set_color_property (style,
8115 "cursor-color", cursor);
8116 gtk_modifier_style_set_color_property (style,
8118 "secondary-cursor-color",
8123 * gtk_widget_modify_fg:
8124 * @widget: a #GtkWidget
8125 * @state: the state for which to set the foreground color
8126 * @color: (allow-none): the color to assign (does not need to be allocated),
8127 * or %NULL to undo the effect of previous calls to
8128 * of gtk_widget_modify_fg().
8130 * Sets the foreground color for a widget in a particular state.
8131 * All other style values are left untouched. See also
8132 * gtk_widget_modify_style().
8134 * Deprecated:3.0: Use gtk_widget_override_color() instead
8137 gtk_widget_modify_fg (GtkWidget *widget,
8139 const GdkColor *color)
8141 GtkStateFlags flags;
8144 g_return_if_fail (GTK_IS_WIDGET (widget));
8145 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8149 case GTK_STATE_ACTIVE:
8150 flags = GTK_STATE_FLAG_ACTIVE;
8152 case GTK_STATE_PRELIGHT:
8153 flags = GTK_STATE_FLAG_PRELIGHT;
8155 case GTK_STATE_SELECTED:
8156 flags = GTK_STATE_FLAG_SELECTED;
8158 case GTK_STATE_INSENSITIVE:
8159 flags = GTK_STATE_FLAG_INSENSITIVE;
8161 case GTK_STATE_NORMAL:
8168 rgba.red = color->red / 65535.;
8169 rgba.green = color->green / 65535.;
8170 rgba.blue = color->blue / 65535.;
8173 gtk_widget_override_color (widget, state, &rgba);
8176 gtk_widget_override_color (widget, state, NULL);
8180 * gtk_widget_modify_bg:
8181 * @widget: a #GtkWidget
8182 * @state: the state for which to set the background color
8183 * @color: (allow-none): the color to assign (does not need to be allocated),
8184 * or %NULL to undo the effect of previous calls to
8185 * of gtk_widget_modify_bg().
8187 * Sets the background color for a widget in a particular state.
8188 * All other style values are left untouched. See also
8189 * gtk_widget_modify_style().
8191 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8192 * draw on their parent container's window and thus may not draw any
8193 * background themselves. This is the case for e.g. #GtkLabel. To modify
8194 * the background of such widgets, you have to set the background color
8195 * on their parent; if you want to set the background of a rectangular
8196 * area around a label, try placing the label in a #GtkEventBox widget
8197 * and setting the background color on that.
8199 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8202 gtk_widget_modify_bg (GtkWidget *widget,
8204 const GdkColor *color)
8206 GtkStateFlags flags;
8209 g_return_if_fail (GTK_IS_WIDGET (widget));
8210 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8214 case GTK_STATE_ACTIVE:
8215 flags = GTK_STATE_FLAG_ACTIVE;
8217 case GTK_STATE_PRELIGHT:
8218 flags = GTK_STATE_FLAG_PRELIGHT;
8220 case GTK_STATE_SELECTED:
8221 flags = GTK_STATE_FLAG_SELECTED;
8223 case GTK_STATE_INSENSITIVE:
8224 flags = GTK_STATE_FLAG_INSENSITIVE;
8226 case GTK_STATE_NORMAL:
8233 rgba.red = color->red / 65535.;
8234 rgba.green = color->green / 65535.;
8235 rgba.blue = color->blue / 65535.;
8238 gtk_widget_override_background_color (widget, state, &rgba);
8241 gtk_widget_override_background_color (widget, state, NULL);
8245 * gtk_widget_modify_text:
8246 * @widget: a #GtkWidget
8247 * @state: the state for which to set the text color
8248 * @color: (allow-none): the color to assign (does not need to be allocated),
8249 * or %NULL to undo the effect of previous calls to
8250 * of gtk_widget_modify_text().
8252 * Sets the text color for a widget in a particular state. All other
8253 * style values are left untouched. The text color is the foreground
8254 * color used along with the base color (see gtk_widget_modify_base())
8255 * for widgets such as #GtkEntry and #GtkTextView. See also
8256 * gtk_widget_modify_style().
8258 * Deprecated:3.0: Use gtk_widget_override_color() instead
8261 gtk_widget_modify_text (GtkWidget *widget,
8263 const GdkColor *color)
8265 g_return_if_fail (GTK_IS_WIDGET (widget));
8266 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8268 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8272 * gtk_widget_modify_base:
8273 * @widget: a #GtkWidget
8274 * @state: the state for which to set the base color
8275 * @color: (allow-none): the color to assign (does not need to be allocated),
8276 * or %NULL to undo the effect of previous calls to
8277 * of gtk_widget_modify_base().
8279 * Sets the base color for a widget in a particular state.
8280 * All other style values are left untouched. The base color
8281 * is the background color used along with the text color
8282 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8283 * and #GtkTextView. See also gtk_widget_modify_style().
8285 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8286 * draw on their parent container's window and thus may not draw any
8287 * background themselves. This is the case for e.g. #GtkLabel. To modify
8288 * the background of such widgets, you have to set the base color on their
8289 * parent; if you want to set the background of a rectangular area around
8290 * a label, try placing the label in a #GtkEventBox widget and setting
8291 * the base color on that.
8293 * Deprecated:3.0: Use gtk_widget_override_background_color() instead
8296 gtk_widget_modify_base (GtkWidget *widget,
8298 const GdkColor *color)
8300 g_return_if_fail (GTK_IS_WIDGET (widget));
8301 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8303 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8307 * gtk_widget_modify_cursor:
8308 * @widget: a #GtkWidget
8309 * @primary: the color to use for primary cursor (does not need to be
8310 * allocated), or %NULL to undo the effect of previous calls to
8311 * of gtk_widget_modify_cursor().
8312 * @secondary: the color to use for secondary cursor (does not need to be
8313 * allocated), or %NULL to undo the effect of previous calls to
8314 * of gtk_widget_modify_cursor().
8316 * Sets the cursor color to use in a widget, overriding the
8317 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8318 * style properties. All other style values are left untouched.
8319 * See also gtk_widget_modify_style().
8323 * Deprecated: 3.0. Use gtk_widget_override_cursor() instead.
8326 gtk_widget_modify_cursor (GtkWidget *widget,
8327 const GdkColor *primary,
8328 const GdkColor *secondary)
8330 GdkRGBA primary_rgba, secondary_rgba;
8332 g_return_if_fail (GTK_IS_WIDGET (widget));
8334 primary_rgba.red = primary->red / 65535.;
8335 primary_rgba.green = primary->green / 65535.;
8336 primary_rgba.blue = primary->blue / 65535.;
8337 primary_rgba.alpha = 1;
8339 secondary_rgba.red = secondary->red / 65535.;
8340 secondary_rgba.green = secondary->green / 65535.;
8341 secondary_rgba.blue = secondary->blue / 65535.;
8342 secondary_rgba.alpha = 1;
8344 gtk_widget_override_cursor (widget, &primary_rgba, &secondary_rgba);
8348 * gtk_widget_modify_font:
8349 * @widget: a #GtkWidget
8350 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8351 * the effect of previous calls to gtk_widget_modify_font().
8353 * Sets the font to use for a widget. All other style values are left
8354 * untouched. See also gtk_widget_modify_style().
8356 * Deprecated:3.0: Use gtk_widget_override_font() instead
8359 gtk_widget_modify_font (GtkWidget *widget,
8360 PangoFontDescription *font_desc)
8362 g_return_if_fail (GTK_IS_WIDGET (widget));
8364 gtk_widget_override_font (widget, font_desc);
8368 gtk_widget_real_direction_changed (GtkWidget *widget,
8369 GtkTextDirection previous_direction)
8371 gtk_widget_queue_resize (widget);
8375 gtk_widget_real_style_set (GtkWidget *widget,
8376 GtkStyle *previous_style)
8381 GtkWidget *previous_toplevel;
8382 GdkScreen *previous_screen;
8383 GdkScreen *new_screen;
8384 } HierarchyChangedInfo;
8387 do_screen_change (GtkWidget *widget,
8388 GdkScreen *old_screen,
8389 GdkScreen *new_screen)
8391 if (old_screen != new_screen)
8393 GtkStyleContext *context;
8397 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8399 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8402 _gtk_tooltip_hide (widget);
8404 context = gtk_widget_get_style_context (widget);
8405 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8407 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8412 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8413 gpointer client_data)
8415 GtkWidgetPrivate *priv = widget->priv;
8416 HierarchyChangedInfo *info = client_data;
8417 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8418 (priv->parent && priv->parent->priv->anchored);
8420 if (priv->anchored != new_anchored)
8422 g_object_ref (widget);
8424 priv->anchored = new_anchored;
8426 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8427 do_screen_change (widget, info->previous_screen, info->new_screen);
8429 if (GTK_IS_CONTAINER (widget))
8430 gtk_container_forall (GTK_CONTAINER (widget),
8431 gtk_widget_propagate_hierarchy_changed_recurse,
8434 g_object_unref (widget);
8439 * _gtk_widget_propagate_hierarchy_changed:
8440 * @widget: a #GtkWidget
8441 * @previous_toplevel: Previous toplevel
8443 * Propagates changes in the anchored state to a widget and all
8444 * children, unsetting or setting the %ANCHORED flag, and
8445 * emitting #GtkWidget::hierarchy-changed.
8448 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8449 GtkWidget *previous_toplevel)
8451 GtkWidgetPrivate *priv = widget->priv;
8452 HierarchyChangedInfo info;
8454 info.previous_toplevel = previous_toplevel;
8455 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8457 if (gtk_widget_is_toplevel (widget) ||
8458 (priv->parent && priv->parent->priv->anchored))
8459 info.new_screen = gtk_widget_get_screen (widget);
8461 info.new_screen = NULL;
8463 if (info.previous_screen)
8464 g_object_ref (info.previous_screen);
8465 if (previous_toplevel)
8466 g_object_ref (previous_toplevel);
8468 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8470 if (previous_toplevel)
8471 g_object_unref (previous_toplevel);
8472 if (info.previous_screen)
8473 g_object_unref (info.previous_screen);
8477 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8478 gpointer client_data)
8480 HierarchyChangedInfo *info = client_data;
8482 g_object_ref (widget);
8484 do_screen_change (widget, info->previous_screen, info->new_screen);
8486 if (GTK_IS_CONTAINER (widget))
8487 gtk_container_forall (GTK_CONTAINER (widget),
8488 gtk_widget_propagate_screen_changed_recurse,
8491 g_object_unref (widget);
8495 * gtk_widget_is_composited:
8496 * @widget: a #GtkWidget
8498 * Whether @widget can rely on having its alpha channel
8499 * drawn correctly. On X11 this function returns whether a
8500 * compositing manager is running for @widget's screen.
8502 * Please note that the semantics of this call will change
8503 * in the future if used on a widget that has a composited
8504 * window in its hierarchy (as set by gdk_window_set_composited()).
8506 * Return value: %TRUE if the widget can rely on its alpha
8507 * channel being drawn correctly.
8512 gtk_widget_is_composited (GtkWidget *widget)
8516 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8518 screen = gtk_widget_get_screen (widget);
8520 return gdk_screen_is_composited (screen);
8524 propagate_composited_changed (GtkWidget *widget,
8527 if (GTK_IS_CONTAINER (widget))
8529 gtk_container_forall (GTK_CONTAINER (widget),
8530 propagate_composited_changed,
8534 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8538 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8540 propagate_composited_changed (widget, NULL);
8544 * _gtk_widget_propagate_screen_changed:
8545 * @widget: a #GtkWidget
8546 * @previous_screen: Previous screen
8548 * Propagates changes in the screen for a widget to all
8549 * children, emitting #GtkWidget::screen-changed.
8552 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8553 GdkScreen *previous_screen)
8555 HierarchyChangedInfo info;
8557 info.previous_screen = previous_screen;
8558 info.new_screen = gtk_widget_get_screen (widget);
8560 if (previous_screen)
8561 g_object_ref (previous_screen);
8563 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8565 if (previous_screen)
8566 g_object_unref (previous_screen);
8570 reset_style_recurse (GtkWidget *widget, gpointer data)
8572 if (widget->priv->context)
8574 _gtk_widget_update_path (widget);
8575 gtk_style_context_set_path (widget->priv->context,
8576 widget->priv->path);
8579 if (GTK_IS_CONTAINER (widget))
8580 gtk_container_forall (GTK_CONTAINER (widget),
8581 reset_style_recurse,
8586 * gtk_widget_reset_style:
8587 * @widget: a #GtkWidget
8589 * Updates the style context of @widget and all descendents
8590 * by updating its widget path. #GtkContainer<!-- -->s may want
8591 * to use this on a child when reordering it in a way that a different
8592 * style might apply to it. See also gtk_container_get_path_for_child().
8597 gtk_widget_reset_style (GtkWidget *widget)
8599 g_return_if_fail (GTK_IS_WIDGET (widget));
8601 reset_style_recurse (widget, NULL);
8605 * gtk_widget_reset_rc_styles:
8606 * @widget: a #GtkWidget.
8608 * Reset the styles of @widget and all descendents, so when
8609 * they are looked up again, they get the correct values
8610 * for the currently loaded RC file settings.
8612 * This function is not useful for applications.
8614 * Deprecated:3.0: Use #GtkStyleContext instead
8617 gtk_widget_reset_rc_styles (GtkWidget *widget)
8619 g_return_if_fail (GTK_IS_WIDGET (widget));
8621 reset_style_recurse (widget, NULL);
8625 * gtk_widget_get_default_style:
8627 * Returns the default style used by all widgets initially.
8629 * Returns: (transfer none): the default style. This #GtkStyle
8630 * object is owned by GTK+ and should not be modified or freed.
8632 * Deprecated:3.0: Use #GtkStyleContext instead
8635 gtk_widget_get_default_style (void)
8637 if (!gtk_default_style)
8639 gtk_default_style = gtk_style_new ();
8640 g_object_ref (gtk_default_style);
8643 return gtk_default_style;
8646 #ifdef G_ENABLE_DEBUG
8648 /* Verify invariants, see docs/widget_system.txt for notes on much of
8649 * this. Invariants may be temporarily broken while we're in the
8650 * process of updating state, of course, so you can only
8651 * verify_invariants() after a given operation is complete.
8652 * Use push/pop_verify_invariants to help with that.
8655 gtk_widget_verify_invariants (GtkWidget *widget)
8659 if (widget->priv->verifying_invariants_count > 0)
8662 parent = widget->priv->parent;
8664 if (widget->priv->mapped)
8666 /* Mapped implies ... */
8668 if (!widget->priv->realized)
8669 g_warning ("%s %p is mapped but not realized",
8670 G_OBJECT_TYPE_NAME (widget), widget);
8672 if (!widget->priv->visible)
8673 g_warning ("%s %p is mapped but not visible",
8674 G_OBJECT_TYPE_NAME (widget), widget);
8676 if (!widget->priv->toplevel)
8678 if (!widget->priv->child_visible)
8679 g_warning ("%s %p is mapped but not child_visible",
8680 G_OBJECT_TYPE_NAME (widget), widget);
8685 /* Not mapped implies... */
8688 /* This check makes sense for normal toplevels, but for
8689 * something like a toplevel that is embedded within a clutter
8690 * state, mapping may depend on external factors.
8692 if (widget->priv->toplevel)
8694 if (widget->priv->visible)
8695 g_warning ("%s %p toplevel is visible but not mapped",
8696 G_OBJECT_TYPE_NAME (widget), widget);
8701 /* Parent related checks aren't possible if parent has
8702 * verifying_invariants_count > 0 because parent needs to recurse
8703 * children first before the invariants will hold.
8705 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8708 parent->priv->realized)
8710 /* Parent realized implies... */
8713 /* This is in widget_system.txt but appears to fail
8714 * because there's no gtk_container_realize() that
8715 * realizes all children... instead we just lazily
8716 * wait for map to fix things up.
8718 if (!widget->priv->realized)
8719 g_warning ("%s %p is realized but child %s %p is not realized",
8720 G_OBJECT_TYPE_NAME (parent), parent,
8721 G_OBJECT_TYPE_NAME (widget), widget);
8724 else if (!widget->priv->toplevel)
8726 /* No parent or parent not realized on non-toplevel implies... */
8728 if (widget->priv->realized && !widget->priv->in_reparent)
8729 g_warning ("%s %p is not realized but child %s %p is realized",
8730 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8731 G_OBJECT_TYPE_NAME (widget), widget);
8735 parent->priv->mapped &&
8736 widget->priv->visible &&
8737 widget->priv->child_visible)
8739 /* Parent mapped and we are visible implies... */
8741 if (!widget->priv->mapped)
8742 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8743 G_OBJECT_TYPE_NAME (parent), parent,
8744 G_OBJECT_TYPE_NAME (widget), widget);
8746 else if (!widget->priv->toplevel)
8748 /* No parent or parent not mapped on non-toplevel implies... */
8750 if (widget->priv->mapped && !widget->priv->in_reparent)
8751 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8752 G_OBJECT_TYPE_NAME (widget), widget,
8753 widget->priv->visible,
8754 widget->priv->child_visible,
8755 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8756 parent ? parent->priv->mapped : FALSE);
8760 if (!widget->priv->realized)
8762 /* Not realized implies... */
8765 /* widget_system.txt says these hold, but they don't. */
8766 if (widget->priv->resize_pending)
8767 g_warning ("%s %p resize pending but not realized",
8768 G_OBJECT_TYPE_NAME (widget), widget);
8770 if (widget->priv->alloc_needed)
8771 g_warning ("%s %p alloc needed but not realized",
8772 G_OBJECT_TYPE_NAME (widget), widget);
8774 if (widget->priv->width_request_needed)
8775 g_warning ("%s %p width request needed but not realized",
8776 G_OBJECT_TYPE_NAME (widget), widget);
8778 if (widget->priv->height_request_needed)
8779 g_warning ("%s %p height request needed but not realized",
8780 G_OBJECT_TYPE_NAME (widget), widget);
8785 /* The point of this push/pop is that invariants may not hold while
8786 * we're busy making changes. So we only check at the outermost call
8787 * on the call stack, after we finish updating everything.
8790 gtk_widget_push_verify_invariants (GtkWidget *widget)
8792 widget->priv->verifying_invariants_count += 1;
8796 gtk_widget_verify_child_invariants (GtkWidget *widget,
8797 gpointer client_data)
8799 /* We don't recurse further; this is a one-level check. */
8800 gtk_widget_verify_invariants (widget);
8804 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8806 g_assert (widget->priv->verifying_invariants_count > 0);
8808 widget->priv->verifying_invariants_count -= 1;
8810 if (widget->priv->verifying_invariants_count == 0)
8812 gtk_widget_verify_invariants (widget);
8814 if (GTK_IS_CONTAINER (widget))
8816 /* Check one level of children, because our
8817 * push_verify_invariants() will have prevented some of the
8818 * checks. This does not recurse because if recursion is
8819 * needed, it will happen naturally as each child has a
8820 * push/pop on that child. For example if we're recursively
8821 * mapping children, we'll push/pop on each child as we map
8824 gtk_container_forall (GTK_CONTAINER (widget),
8825 gtk_widget_verify_child_invariants,
8830 #endif /* G_ENABLE_DEBUG */
8832 static PangoContext *
8833 gtk_widget_peek_pango_context (GtkWidget *widget)
8835 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8839 * gtk_widget_get_pango_context:
8840 * @widget: a #GtkWidget
8842 * Gets a #PangoContext with the appropriate font map, font description,
8843 * and base direction for this widget. Unlike the context returned
8844 * by gtk_widget_create_pango_context(), this context is owned by
8845 * the widget (it can be used until the screen for the widget changes
8846 * or the widget is removed from its toplevel), and will be updated to
8847 * match any changes to the widget's attributes.
8849 * If you create and keep a #PangoLayout using this context, you must
8850 * deal with changes to the context by calling pango_layout_context_changed()
8851 * on the layout in response to the #GtkWidget::style-updated and
8852 * #GtkWidget::direction-changed signals for the widget.
8854 * Return value: (transfer none): the #PangoContext for the widget.
8857 gtk_widget_get_pango_context (GtkWidget *widget)
8859 PangoContext *context;
8861 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8863 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8866 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8867 g_object_set_qdata_full (G_OBJECT (widget),
8868 quark_pango_context,
8877 update_pango_context (GtkWidget *widget,
8878 PangoContext *context)
8880 PangoFontDescription *font_desc;
8881 GtkStyleContext *style_context;
8883 style_context = gtk_widget_get_style_context (widget);
8885 gtk_style_context_get (style_context,
8886 gtk_widget_get_state_flags (widget),
8890 pango_context_set_font_description (context, font_desc);
8891 pango_context_set_base_dir (context,
8892 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8893 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8895 pango_font_description_free (font_desc);
8899 gtk_widget_update_pango_context (GtkWidget *widget)
8901 PangoContext *context = gtk_widget_peek_pango_context (widget);
8907 update_pango_context (widget, context);
8909 screen = gtk_widget_get_screen_unchecked (widget);
8912 pango_cairo_context_set_resolution (context,
8913 gdk_screen_get_resolution (screen));
8914 pango_cairo_context_set_font_options (context,
8915 gdk_screen_get_font_options (screen));
8921 * gtk_widget_create_pango_context:
8922 * @widget: a #GtkWidget
8924 * Creates a new #PangoContext with the appropriate font map,
8925 * font description, and base direction for drawing text for
8926 * this widget. See also gtk_widget_get_pango_context().
8928 * Return value: (transfer full): the new #PangoContext
8931 gtk_widget_create_pango_context (GtkWidget *widget)
8934 PangoContext *context;
8936 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8938 screen = gtk_widget_get_screen_unchecked (widget);
8941 GTK_NOTE (MULTIHEAD,
8942 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8944 screen = gdk_screen_get_default ();
8947 context = gdk_pango_context_get_for_screen (screen);
8949 update_pango_context (widget, context);
8950 pango_context_set_language (context, gtk_get_default_language ());
8956 * gtk_widget_create_pango_layout:
8957 * @widget: a #GtkWidget
8958 * @text: text to set on the layout (can be %NULL)
8960 * Creates a new #PangoLayout with the appropriate font map,
8961 * font description, and base direction for drawing text for
8964 * If you keep a #PangoLayout created in this way around, in order to
8965 * notify the layout of changes to the base direction or font of this
8966 * widget, you must call pango_layout_context_changed() in response to
8967 * the #GtkWidget::style-updated and #GtkWidget::direction-changed signals
8970 * Return value: (transfer full): the new #PangoLayout
8973 gtk_widget_create_pango_layout (GtkWidget *widget,
8976 PangoLayout *layout;
8977 PangoContext *context;
8979 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8981 context = gtk_widget_get_pango_context (widget);
8982 layout = pango_layout_new (context);
8985 pango_layout_set_text (layout, text, -1);
8991 * gtk_widget_render_icon_pixbuf:
8992 * @widget: a #GtkWidget
8993 * @stock_id: a stock ID
8994 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8995 * render at the size of the source and don't scale (if there are
8996 * multiple source sizes, GTK+ picks one of the available sizes).
8998 * A convenience function that uses the theme engine and style
8999 * settings for @widget to look up @stock_id and render it to
9000 * a pixbuf. @stock_id should be a stock icon ID such as
9001 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9002 * such as #GTK_ICON_SIZE_MENU.
9004 * The pixels in the returned #GdkPixbuf are shared with the rest of
9005 * the application and should not be modified. The pixbuf should be freed
9006 * after use with g_object_unref().
9008 * Return value: (transfer full): a new pixbuf, or %NULL if the
9009 * stock ID wasn't known
9014 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9015 const gchar *stock_id,
9018 GtkWidgetPrivate *priv;
9019 GtkIconSet *icon_set;
9021 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9022 g_return_val_if_fail (stock_id != NULL, NULL);
9023 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9025 priv = widget->priv;
9027 gtk_widget_ensure_style (widget);
9029 icon_set = gtk_style_context_lookup_icon_set (priv->context, stock_id);
9031 if (icon_set == NULL)
9034 return gtk_icon_set_render_icon_pixbuf (icon_set, priv->context, size);
9038 * gtk_widget_render_icon:
9039 * @widget: a #GtkWidget
9040 * @stock_id: a stock ID
9041 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9042 * render at the size of the source and don't scale (if there are
9043 * multiple source sizes, GTK+ picks one of the available sizes).
9044 * @detail: (allow-none): render detail to pass to theme engine
9046 * A convenience function that uses the theme engine and RC file
9047 * settings for @widget to look up @stock_id and render it to
9048 * a pixbuf. @stock_id should be a stock icon ID such as
9049 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9050 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
9051 * identifies the widget or code doing the rendering, so that
9052 * theme engines can special-case rendering for that widget or code.
9054 * The pixels in the returned #GdkPixbuf are shared with the rest of
9055 * the application and should not be modified. The pixbuf should be freed
9056 * after use with g_object_unref().
9058 * Return value: (transfer full): a new pixbuf, or %NULL if the
9059 * stock ID wasn't known
9061 * Deprecated: 3.0: Use gtk_widget_render_icon_pixbuf() instead.
9064 gtk_widget_render_icon (GtkWidget *widget,
9065 const gchar *stock_id,
9067 const gchar *detail)
9069 return gtk_widget_render_icon_pixbuf (widget, stock_id, size);
9073 * gtk_widget_set_parent_window:
9074 * @widget: a #GtkWidget.
9075 * @parent_window: the new parent window.
9077 * Sets a non default parent window for @widget.
9079 * For GtkWindow classes, setting a @parent_window effects whether
9080 * the window is a toplevel window or can be embedded into other
9084 * For GtkWindow classes, this needs to be called before the
9085 * window is realized.
9090 gtk_widget_set_parent_window (GtkWidget *widget,
9091 GdkWindow *parent_window)
9093 GdkWindow *old_parent_window;
9095 g_return_if_fail (GTK_IS_WIDGET (widget));
9097 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9098 quark_parent_window);
9100 if (parent_window != old_parent_window)
9102 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9104 if (old_parent_window)
9105 g_object_unref (old_parent_window);
9107 g_object_ref (parent_window);
9109 /* Unset toplevel flag when adding a parent window to a widget,
9110 * this is the primary entry point to allow toplevels to be
9113 if (GTK_IS_WINDOW (widget) && !GTK_IS_PLUG (widget))
9114 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9119 * gtk_widget_get_parent_window:
9120 * @widget: a #GtkWidget.
9122 * Gets @widget's parent window.
9124 * Returns: (transfer none): the parent window of @widget.
9127 gtk_widget_get_parent_window (GtkWidget *widget)
9129 GtkWidgetPrivate *priv;
9130 GdkWindow *parent_window;
9132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9134 priv = widget->priv;
9136 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9138 return (parent_window != NULL) ? parent_window :
9139 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9144 * gtk_widget_set_child_visible:
9145 * @widget: a #GtkWidget
9146 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9148 * Sets whether @widget should be mapped along with its when its parent
9149 * is mapped and @widget has been shown with gtk_widget_show().
9151 * The child visibility can be set for widget before it is added to
9152 * a container with gtk_widget_set_parent(), to avoid mapping
9153 * children unnecessary before immediately unmapping them. However
9154 * it will be reset to its default state of %TRUE when the widget
9155 * is removed from a container.
9157 * Note that changing the child visibility of a widget does not
9158 * queue a resize on the widget. Most of the time, the size of
9159 * a widget is computed from all visible children, whether or
9160 * not they are mapped. If this is not the case, the container
9161 * can queue a resize itself.
9163 * This function is only useful for container implementations and
9164 * never should be called by an application.
9167 gtk_widget_set_child_visible (GtkWidget *widget,
9168 gboolean is_visible)
9170 GtkWidgetPrivate *priv;
9172 g_return_if_fail (GTK_IS_WIDGET (widget));
9173 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9175 priv = widget->priv;
9177 g_object_ref (widget);
9178 gtk_widget_verify_invariants (widget);
9181 priv->child_visible = TRUE;
9184 GtkWidget *toplevel;
9186 priv->child_visible = FALSE;
9188 toplevel = gtk_widget_get_toplevel (widget);
9189 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9190 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9193 if (priv->parent && gtk_widget_get_realized (priv->parent))
9195 if (gtk_widget_get_mapped (priv->parent) &&
9196 priv->child_visible &&
9197 gtk_widget_get_visible (widget))
9198 gtk_widget_map (widget);
9200 gtk_widget_unmap (widget);
9203 gtk_widget_verify_invariants (widget);
9204 g_object_unref (widget);
9208 * gtk_widget_get_child_visible:
9209 * @widget: a #GtkWidget
9211 * Gets the value set with gtk_widget_set_child_visible().
9212 * If you feel a need to use this function, your code probably
9213 * needs reorganization.
9215 * This function is only useful for container implementations and
9216 * never should be called by an application.
9218 * Return value: %TRUE if the widget is mapped with the parent.
9221 gtk_widget_get_child_visible (GtkWidget *widget)
9223 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9225 return widget->priv->child_visible;
9229 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9231 GtkWidget *toplevel;
9233 toplevel = gtk_widget_get_toplevel (widget);
9235 if (gtk_widget_is_toplevel (toplevel))
9237 if (GTK_IS_WINDOW (toplevel))
9238 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9239 else if (GTK_IS_INVISIBLE (toplevel))
9240 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9247 * gtk_widget_get_screen:
9248 * @widget: a #GtkWidget
9250 * Get the #GdkScreen from the toplevel window associated with
9251 * this widget. This function can only be called after the widget
9252 * has been added to a widget hierarchy with a #GtkWindow
9255 * In general, you should only create screen specific
9256 * resources when a widget has been realized, and you should
9257 * free those resources when the widget is unrealized.
9259 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9264 gtk_widget_get_screen (GtkWidget *widget)
9268 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9270 screen = gtk_widget_get_screen_unchecked (widget);
9277 g_warning (G_STRLOC ": Can't get associated screen"
9278 " for a widget unless it is inside a toplevel GtkWindow\n"
9279 " widget type is %s associated top level type is %s",
9280 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9281 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9283 return gdk_screen_get_default ();
9288 * gtk_widget_has_screen:
9289 * @widget: a #GtkWidget
9291 * Checks whether there is a #GdkScreen is associated with
9292 * this widget. All toplevel widgets have an associated
9293 * screen, and all widgets added into a hierarchy with a toplevel
9294 * window at the top.
9296 * Return value: %TRUE if there is a #GdkScreen associcated
9302 gtk_widget_has_screen (GtkWidget *widget)
9304 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9306 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9310 * gtk_widget_get_display:
9311 * @widget: a #GtkWidget
9313 * Get the #GdkDisplay for the toplevel window associated with
9314 * this widget. This function can only be called after the widget
9315 * has been added to a widget hierarchy with a #GtkWindow at the top.
9317 * In general, you should only create display specific
9318 * resources when a widget has been realized, and you should
9319 * free those resources when the widget is unrealized.
9321 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9326 gtk_widget_get_display (GtkWidget *widget)
9328 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9330 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9334 * gtk_widget_get_root_window:
9335 * @widget: a #GtkWidget
9337 * Get the root window where this widget is located. This function can
9338 * only be called after the widget has been added to a widget
9339 * hierarchy with #GtkWindow at the top.
9341 * The root window is useful for such purposes as creating a popup
9342 * #GdkWindow associated with the window. In general, you should only
9343 * create display specific resources when a widget has been realized,
9344 * and you should free those resources when the widget is unrealized.
9346 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9351 gtk_widget_get_root_window (GtkWidget *widget)
9353 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9355 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9359 * gtk_widget_child_focus:
9360 * @widget: a #GtkWidget
9361 * @direction: direction of focus movement
9363 * This function is used by custom widget implementations; if you're
9364 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9365 * to a particular widget, and gtk_container_set_focus_chain() to
9366 * change the focus tab order. So you may want to investigate those
9367 * functions instead.
9369 * gtk_widget_child_focus() is called by containers as the user moves
9370 * around the window using keyboard shortcuts. @direction indicates
9371 * what kind of motion is taking place (up, down, left, right, tab
9372 * forward, tab backward). gtk_widget_child_focus() emits the
9373 * #GtkWidget::focus signal; widgets override the default handler
9374 * for this signal in order to implement appropriate focus behavior.
9376 * The default ::focus handler for a widget should return %TRUE if
9377 * moving in @direction left the focus on a focusable location inside
9378 * that widget, and %FALSE if moving in @direction moved the focus
9379 * outside the widget. If returning %TRUE, widgets normally
9380 * call gtk_widget_grab_focus() to place the focus accordingly;
9381 * if returning %FALSE, they don't modify the current focus location.
9383 * Return value: %TRUE if focus ended up inside @widget
9386 gtk_widget_child_focus (GtkWidget *widget,
9387 GtkDirectionType direction)
9389 gboolean return_val;
9391 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9393 if (!gtk_widget_get_visible (widget) ||
9394 !gtk_widget_is_sensitive (widget))
9397 /* child widgets must set CAN_FOCUS, containers
9398 * don't have to though.
9400 if (!GTK_IS_CONTAINER (widget) &&
9401 !gtk_widget_get_can_focus (widget))
9404 g_signal_emit (widget,
9405 widget_signals[FOCUS],
9407 direction, &return_val);
9413 * gtk_widget_keynav_failed:
9414 * @widget: a #GtkWidget
9415 * @direction: direction of focus movement
9417 * This function should be called whenever keyboard navigation within
9418 * a single widget hits a boundary. The function emits the
9419 * #GtkWidget::keynav-failed signal on the widget and its return
9420 * value should be interpreted in a way similar to the return value of
9421 * gtk_widget_child_focus():
9423 * When %TRUE is returned, stay in the widget, the failed keyboard
9424 * navigation is Ok and/or there is nowhere we can/should move the
9427 * When %FALSE is returned, the caller should continue with keyboard
9428 * navigation outside the widget, e.g. by calling
9429 * gtk_widget_child_focus() on the widget's toplevel.
9431 * The default ::keynav-failed handler returns %TRUE for
9432 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9433 * values of #GtkDirectionType, it looks at the
9434 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9435 * if the setting is %TRUE. This way the entire user interface
9436 * becomes cursor-navigatable on input devices such as mobile phones
9437 * which only have cursor keys but no tab key.
9439 * Whenever the default handler returns %TRUE, it also calls
9440 * gtk_widget_error_bell() to notify the user of the failed keyboard
9443 * A use case for providing an own implementation of ::keynav-failed
9444 * (either by connecting to it or by overriding it) would be a row of
9445 * #GtkEntry widgets where the user should be able to navigate the
9446 * entire row with the cursor keys, as e.g. known from user interfaces
9447 * that require entering license keys.
9449 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9450 * if the emitting widget should try to handle the keyboard
9451 * navigation attempt in its parent container(s).
9456 gtk_widget_keynav_failed (GtkWidget *widget,
9457 GtkDirectionType direction)
9459 gboolean return_val;
9461 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9463 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9464 direction, &return_val);
9470 * gtk_widget_error_bell:
9471 * @widget: a #GtkWidget
9473 * Notifies the user about an input-related error on this widget.
9474 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9475 * gdk_window_beep(), otherwise it does nothing.
9477 * Note that the effect of gdk_window_beep() can be configured in many
9478 * ways, depending on the windowing backend and the desktop environment
9479 * or window manager that is used.
9484 gtk_widget_error_bell (GtkWidget *widget)
9486 GtkWidgetPrivate *priv;
9487 GtkSettings* settings;
9490 g_return_if_fail (GTK_IS_WIDGET (widget));
9492 priv = widget->priv;
9494 settings = gtk_widget_get_settings (widget);
9498 g_object_get (settings,
9499 "gtk-error-bell", &beep,
9502 if (beep && priv->window)
9503 gdk_window_beep (priv->window);
9507 gtk_widget_set_usize_internal (GtkWidget *widget,
9510 GtkQueueResizeFlags flags)
9512 GtkWidgetAuxInfo *aux_info;
9513 gboolean changed = FALSE;
9515 g_object_freeze_notify (G_OBJECT (widget));
9517 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9519 if (width > -2 && aux_info->width != width)
9521 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9522 g_object_notify (G_OBJECT (widget), "width-request");
9523 aux_info->width = width;
9526 if (height > -2 && aux_info->height != height)
9528 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9529 g_object_notify (G_OBJECT (widget), "height-request");
9530 aux_info->height = height;
9534 if (gtk_widget_get_visible (widget) && changed)
9536 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9537 gtk_widget_queue_resize (widget);
9539 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9542 g_object_thaw_notify (G_OBJECT (widget));
9546 * gtk_widget_set_size_request:
9547 * @widget: a #GtkWidget
9548 * @width: width @widget should request, or -1 to unset
9549 * @height: height @widget should request, or -1 to unset
9551 * Sets the minimum size of a widget; that is, the widget's size
9552 * request will be @width by @height. You can use this function to
9553 * force a widget to be either larger or smaller than it normally
9556 * In most cases, gtk_window_set_default_size() is a better choice for
9557 * toplevel windows than this function; setting the default size will
9558 * still allow users to shrink the window. Setting the size request
9559 * will force them to leave the window at least as large as the size
9560 * request. When dealing with window sizes,
9561 * gtk_window_set_geometry_hints() can be a useful function as well.
9563 * Note the inherent danger of setting any fixed size - themes,
9564 * translations into other languages, different fonts, and user action
9565 * can all change the appropriate size for a given widget. So, it's
9566 * basically impossible to hardcode a size that will always be
9569 * The size request of a widget is the smallest size a widget can
9570 * accept while still functioning well and drawing itself correctly.
9571 * However in some strange cases a widget may be allocated less than
9572 * its requested size, and in many cases a widget may be allocated more
9573 * space than it requested.
9575 * If the size request in a given direction is -1 (unset), then
9576 * the "natural" size request of the widget will be used instead.
9578 * Widgets can't actually be allocated a size less than 1 by 1, but
9579 * you can pass 0,0 to this function to mean "as small as possible."
9581 * The size request set here does not include any margin from the
9582 * #GtkWidget properties margin-left, margin-right, margin-top, and
9583 * margin-bottom, but it does include pretty much all other padding
9584 * or border properties set by any subclass of #GtkWidget.
9587 gtk_widget_set_size_request (GtkWidget *widget,
9591 g_return_if_fail (GTK_IS_WIDGET (widget));
9592 g_return_if_fail (width >= -1);
9593 g_return_if_fail (height >= -1);
9600 gtk_widget_set_usize_internal (widget, width, height, 0);
9605 * gtk_widget_get_size_request:
9606 * @widget: a #GtkWidget
9607 * @width: (out) (allow-none): return location for width, or %NULL
9608 * @height: (out) (allow-none): return location for height, or %NULL
9610 * Gets the size request that was explicitly set for the widget using
9611 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9612 * @height indicates that that dimension has not been set explicitly
9613 * and the natural requisition of the widget will be used intead. See
9614 * gtk_widget_set_size_request(). To get the size a widget will
9615 * actually request, call gtk_widget_get_preferred_size() instead of
9619 gtk_widget_get_size_request (GtkWidget *widget,
9623 const GtkWidgetAuxInfo *aux_info;
9625 g_return_if_fail (GTK_IS_WIDGET (widget));
9627 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9630 *width = aux_info->width;
9633 *height = aux_info->height;
9637 * _gtk_widget_override_size_request:
9638 * @widget: a #GtkWidget
9639 * @width: new forced minimum width
9640 * @height: new forced minimum height
9641 * @old_width: location to store previous forced minimum width
9642 * @old_width: location to store previous forced minumum height
9644 * Temporarily establishes a forced minimum size for a widget; this
9645 * is used by GtkWindow when calculating the size to add to the
9646 * window's geometry widget. Cached sizes for the widget and its
9647 * parents are invalidated, so that subsequent calls to the size
9648 * negotiation machinery produce the overriden result, but the
9649 * widget is not queued for relayout or redraw. The old size must
9650 * be restored with _gtk_widget_restore_size_request() or things
9654 _gtk_widget_override_size_request (GtkWidget *widget,
9660 gtk_widget_get_size_request (widget, old_width, old_height);
9661 gtk_widget_set_usize_internal (widget, width, height,
9662 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9666 * _gtk_widget_restore_size_request:
9667 * @widget: a #GtkWidget
9668 * @old_width: saved forced minimum size
9669 * @old_height: saved forced minimum size
9671 * Undoes the operation of_gtk_widget_override_size_request().
9674 _gtk_widget_restore_size_request (GtkWidget *widget,
9678 gtk_widget_set_usize_internal (widget, old_width, old_height,
9679 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9683 * gtk_widget_set_events:
9684 * @widget: a #GtkWidget
9685 * @events: event mask
9687 * Sets the event mask (see #GdkEventMask) for a widget. The event
9688 * mask determines which events a widget will receive. Keep in mind
9689 * that different widgets have different default event masks, and by
9690 * changing the event mask you may disrupt a widget's functionality,
9691 * so be careful. This function must be called while a widget is
9692 * unrealized. Consider gtk_widget_add_events() for widgets that are
9693 * already realized, or if you want to preserve the existing event
9694 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9695 * to get events on those widgets, place them inside a #GtkEventBox
9696 * and receive events on the event box.
9699 gtk_widget_set_events (GtkWidget *widget,
9702 g_return_if_fail (GTK_IS_WIDGET (widget));
9703 g_return_if_fail (!gtk_widget_get_realized (widget));
9705 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9706 GINT_TO_POINTER (events));
9707 g_object_notify (G_OBJECT (widget), "events");
9711 * gtk_widget_set_device_events:
9712 * @widget: a #GtkWidget
9713 * @device: a #GdkDevice
9714 * @events: event mask
9716 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9717 * mask determines which events a widget will receive from @device. Keep
9718 * in mind that different widgets have different default event masks, and by
9719 * changing the event mask you may disrupt a widget's functionality,
9720 * so be careful. This function must be called while a widget is
9721 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9722 * already realized, or if you want to preserve the existing event
9723 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9724 * to get events on those widgets, place them inside a #GtkEventBox
9725 * and receive events on the event box.
9730 gtk_widget_set_device_events (GtkWidget *widget,
9732 GdkEventMask events)
9734 GHashTable *device_events;
9736 g_return_if_fail (GTK_IS_WIDGET (widget));
9737 g_return_if_fail (GDK_IS_DEVICE (device));
9738 g_return_if_fail (!gtk_widget_get_realized (widget));
9740 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9742 if (G_UNLIKELY (!device_events))
9744 device_events = g_hash_table_new (NULL, NULL);
9745 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9746 (GDestroyNotify) g_hash_table_unref);
9749 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9753 gtk_widget_add_events_internal_list (GtkWidget *widget,
9760 for (l = window_list; l != NULL; l = l->next)
9762 GdkWindow *window = l->data;
9765 gdk_window_get_user_data (window, &user_data);
9766 if (user_data == widget)
9771 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9773 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9775 children = gdk_window_get_children (window);
9776 gtk_widget_add_events_internal_list (widget, device, events, children);
9777 g_list_free (children);
9783 gtk_widget_add_events_internal (GtkWidget *widget,
9787 GtkWidgetPrivate *priv = widget->priv;
9790 if (!gtk_widget_get_has_window (widget))
9791 window_list = gdk_window_get_children (priv->window);
9793 window_list = g_list_prepend (NULL, priv->window);
9795 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9797 g_list_free (window_list);
9801 * gtk_widget_add_events:
9802 * @widget: a #GtkWidget
9803 * @events: an event mask, see #GdkEventMask
9805 * Adds the events in the bitfield @events to the event mask for
9806 * @widget. See gtk_widget_set_events() for details.
9809 gtk_widget_add_events (GtkWidget *widget,
9814 g_return_if_fail (GTK_IS_WIDGET (widget));
9816 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9817 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9818 GINT_TO_POINTER (old_events | events));
9820 if (gtk_widget_get_realized (widget))
9821 gtk_widget_add_events_internal (widget, NULL, events);
9823 g_object_notify (G_OBJECT (widget), "events");
9827 * gtk_widget_add_device_events:
9828 * @widget: a #GtkWidget
9829 * @device: a #GdkDevice
9830 * @events: an event mask, see #GdkEventMask
9832 * Adds the device events in the bitfield @events to the event mask for
9833 * @widget. See gtk_widget_set_device_events() for details.
9838 gtk_widget_add_device_events (GtkWidget *widget,
9840 GdkEventMask events)
9842 GdkEventMask old_events;
9843 GHashTable *device_events;
9845 g_return_if_fail (GTK_IS_WIDGET (widget));
9846 g_return_if_fail (GDK_IS_DEVICE (device));
9848 old_events = gtk_widget_get_device_events (widget, device);
9850 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9852 if (G_UNLIKELY (!device_events))
9854 device_events = g_hash_table_new (NULL, NULL);
9855 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9856 (GDestroyNotify) g_hash_table_unref);
9859 g_hash_table_insert (device_events, device,
9860 GUINT_TO_POINTER (old_events | events));
9862 if (gtk_widget_get_realized (widget))
9863 gtk_widget_add_events_internal (widget, device, events);
9865 g_object_notify (G_OBJECT (widget), "events");
9869 * gtk_widget_get_toplevel:
9870 * @widget: a #GtkWidget
9872 * This function returns the topmost widget in the container hierarchy
9873 * @widget is a part of. If @widget has no parent widgets, it will be
9874 * returned as the topmost widget. No reference will be added to the
9875 * returned widget; it should not be unreferenced.
9877 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9878 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9880 * %NULL if @widget wasn't inside a toplevel window, and if the
9881 * window was inside a #GtkWindow-derived widget which was in turn
9882 * inside the toplevel #GtkWindow. While the second case may
9883 * seem unlikely, it actually happens when a #GtkPlug is embedded
9884 * inside a #GtkSocket within the same application.
9886 * To reliably find the toplevel #GtkWindow, use
9887 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9888 * is set on the result.
9890 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9891 * if (gtk_widget_is_toplevel (toplevel))
9893 * /* Perform action on toplevel. */
9897 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9898 * if there's no ancestor.
9901 gtk_widget_get_toplevel (GtkWidget *widget)
9903 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9905 while (widget->priv->parent)
9906 widget = widget->priv->parent;
9912 * gtk_widget_get_ancestor:
9913 * @widget: a #GtkWidget
9914 * @widget_type: ancestor type
9916 * Gets the first ancestor of @widget with type @widget_type. For example,
9917 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9918 * the first #GtkBox that's an ancestor of @widget. No reference will be
9919 * added to the returned widget; it should not be unreferenced. See note
9920 * about checking for a toplevel #GtkWindow in the docs for
9921 * gtk_widget_get_toplevel().
9923 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9924 * considers @widget to be an ancestor of itself.
9926 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9929 gtk_widget_get_ancestor (GtkWidget *widget,
9932 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9934 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9935 widget = widget->priv->parent;
9937 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9944 * gtk_widget_set_visual:
9945 * @widget: a #GtkWidget
9946 * @visual: visual to be used or %NULL to unset a previous one
9948 * Sets the visual that should be used for by widget and its children for
9949 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9950 * returned by gdk_widget_get_screen(), so handling the
9951 * #GtkWidget::screen-changed signal is necessary.
9953 * Setting a new @visual will not cause @widget to recreate its windows,
9954 * so you should call this function before @widget is realized.
9957 gtk_widget_set_visual (GtkWidget *widget,
9960 g_return_if_fail (GTK_IS_WIDGET (widget));
9961 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9964 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9967 g_object_set_qdata_full (G_OBJECT (widget),
9969 g_object_ref (visual),
9974 * gtk_widget_get_visual:
9975 * @widget: a #GtkWidget
9977 * Gets the visual that will be used to render @widget.
9979 * Return value: (transfer none): the visual for @widget
9982 gtk_widget_get_visual (GtkWidget *widget)
9988 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9990 if (gtk_widget_get_has_window (widget) &&
9991 widget->priv->window)
9992 return gdk_window_get_visual (widget->priv->window);
9994 screen = gtk_widget_get_screen (widget);
9996 for (w = widget; w != NULL; w = w->priv->parent)
9998 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10001 if (gdk_visual_get_screen (visual) == screen)
10004 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10005 gtk_widget_get_name (widget));
10009 return gdk_screen_get_system_visual (screen);
10013 * gtk_widget_get_settings:
10014 * @widget: a #GtkWidget
10016 * Gets the settings object holding the settings (global property
10017 * settings, RC file information, etc) used for this widget.
10019 * Note that this function can only be called when the #GtkWidget
10020 * is attached to a toplevel, since the settings object is specific
10021 * to a particular #GdkScreen.
10023 * Return value: (transfer none): the relevant #GtkSettings object
10026 gtk_widget_get_settings (GtkWidget *widget)
10028 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10030 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10034 * gtk_widget_get_events:
10035 * @widget: a #GtkWidget
10037 * Returns the event mask for the widget (a bitfield containing flags
10038 * from the #GdkEventMask enumeration). These are the events that the widget
10041 * Return value: event mask for @widget
10044 gtk_widget_get_events (GtkWidget *widget)
10046 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10048 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10052 * gtk_widget_get_device_events:
10053 * @widget: a #GtkWidget
10054 * @device: a #GdkDevice
10056 * Returns the events mask for the widget corresponding to an specific device. These
10057 * are the events that the widget will receive when @device operates on it.
10059 * Returns: device event mask for @widget
10064 gtk_widget_get_device_events (GtkWidget *widget,
10067 GHashTable *device_events;
10069 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10070 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10072 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10074 if (!device_events)
10077 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10081 * gtk_widget_get_pointer:
10082 * @widget: a #GtkWidget
10083 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10084 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10086 * Obtains the location of the mouse pointer in widget coordinates.
10087 * Widget coordinates are a bit odd; for historical reasons, they are
10088 * defined as @widget->window coordinates for widgets that are not
10089 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10090 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10093 gtk_widget_get_pointer (GtkWidget *widget,
10097 GtkWidgetPrivate *priv;
10099 g_return_if_fail (GTK_IS_WIDGET (widget));
10101 priv = widget->priv;
10108 if (gtk_widget_get_realized (widget))
10110 gdk_window_get_pointer (priv->window, x, y, NULL);
10112 if (!gtk_widget_get_has_window (widget))
10115 *x -= priv->allocation.x;
10117 *y -= priv->allocation.y;
10123 * gtk_widget_is_ancestor:
10124 * @widget: a #GtkWidget
10125 * @ancestor: another #GtkWidget
10127 * Determines whether @widget is somewhere inside @ancestor, possibly with
10128 * intermediate containers.
10130 * Return value: %TRUE if @ancestor contains @widget as a child,
10131 * grandchild, great grandchild, etc.
10134 gtk_widget_is_ancestor (GtkWidget *widget,
10135 GtkWidget *ancestor)
10137 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10138 g_return_val_if_fail (ancestor != NULL, FALSE);
10142 if (widget->priv->parent == ancestor)
10144 widget = widget->priv->parent;
10150 static GQuark quark_composite_name = 0;
10153 * gtk_widget_set_composite_name:
10154 * @widget: a #GtkWidget.
10155 * @name: the name to set
10157 * Sets a widgets composite name. The widget must be
10158 * a composite child of its parent; see gtk_widget_push_composite_child().
10161 gtk_widget_set_composite_name (GtkWidget *widget,
10164 g_return_if_fail (GTK_IS_WIDGET (widget));
10165 g_return_if_fail (widget->priv->composite_child);
10166 g_return_if_fail (name != NULL);
10168 if (!quark_composite_name)
10169 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10171 g_object_set_qdata_full (G_OBJECT (widget),
10172 quark_composite_name,
10178 * gtk_widget_get_composite_name:
10179 * @widget: a #GtkWidget
10181 * Obtains the composite name of a widget.
10183 * Returns: the composite name of @widget, or %NULL if @widget is not
10184 * a composite child. The string should be freed when it is no
10188 gtk_widget_get_composite_name (GtkWidget *widget)
10190 GtkWidgetPrivate *priv;
10192 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10194 priv = widget->priv;
10196 if (widget->priv->composite_child && priv->parent)
10197 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10204 * gtk_widget_push_composite_child:
10206 * Makes all newly-created widgets as composite children until
10207 * the corresponding gtk_widget_pop_composite_child() call.
10209 * A composite child is a child that's an implementation detail of the
10210 * container it's inside and should not be visible to people using the
10211 * container. Composite children aren't treated differently by GTK (but
10212 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10213 * builders might want to treat them in a different way.
10215 * Here is a simple example:
10217 * gtk_widget_push_composite_child ();
10218 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10219 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10220 * gtk_widget_pop_composite_child ();
10221 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10222 * GTK_WIDGET (scrolled_window));
10223 * g_object_ref (scrolled_window->hscrollbar);
10227 gtk_widget_push_composite_child (void)
10229 composite_child_stack++;
10233 * gtk_widget_pop_composite_child:
10235 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10238 gtk_widget_pop_composite_child (void)
10240 if (composite_child_stack)
10241 composite_child_stack--;
10245 gtk_widget_emit_direction_changed (GtkWidget *widget,
10246 GtkTextDirection old_dir)
10248 gtk_widget_update_pango_context (widget);
10250 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10254 * gtk_widget_set_direction:
10255 * @widget: a #GtkWidget
10256 * @dir: the new direction
10258 * Sets the reading direction on a particular widget. This direction
10259 * controls the primary direction for widgets containing text,
10260 * and also the direction in which the children of a container are
10261 * packed. The ability to set the direction is present in order
10262 * so that correct localization into languages with right-to-left
10263 * reading directions can be done. Generally, applications will
10264 * let the default reading direction present, except for containers
10265 * where the containers are arranged in an order that is explicitely
10266 * visual rather than logical (such as buttons for text justification).
10268 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10269 * set by gtk_widget_set_default_direction() will be used.
10272 gtk_widget_set_direction (GtkWidget *widget,
10273 GtkTextDirection dir)
10275 GtkTextDirection old_dir;
10277 g_return_if_fail (GTK_IS_WIDGET (widget));
10278 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10280 old_dir = gtk_widget_get_direction (widget);
10282 widget->priv->direction = dir;
10284 if (old_dir != gtk_widget_get_direction (widget))
10286 if (widget->priv->context)
10287 gtk_style_context_set_direction (widget->priv->context,
10288 gtk_widget_get_direction (widget));
10290 gtk_widget_emit_direction_changed (widget, old_dir);
10295 * gtk_widget_get_direction:
10296 * @widget: a #GtkWidget
10298 * Gets the reading direction for a particular widget. See
10299 * gtk_widget_set_direction().
10301 * Return value: the reading direction for the widget.
10304 gtk_widget_get_direction (GtkWidget *widget)
10306 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10308 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10309 return gtk_default_direction;
10311 return widget->priv->direction;
10315 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10317 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10319 g_object_ref (widget);
10321 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10322 gtk_widget_emit_direction_changed (widget, old_dir);
10324 if (GTK_IS_CONTAINER (widget))
10325 gtk_container_forall (GTK_CONTAINER (widget),
10326 gtk_widget_set_default_direction_recurse,
10329 g_object_unref (widget);
10333 * gtk_widget_set_default_direction:
10334 * @dir: the new default direction. This cannot be
10335 * %GTK_TEXT_DIR_NONE.
10337 * Sets the default reading direction for widgets where the
10338 * direction has not been explicitly set by gtk_widget_set_direction().
10341 gtk_widget_set_default_direction (GtkTextDirection dir)
10343 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10345 if (dir != gtk_default_direction)
10347 GList *toplevels, *tmp_list;
10348 GtkTextDirection old_dir = gtk_default_direction;
10350 gtk_default_direction = dir;
10352 tmp_list = toplevels = gtk_window_list_toplevels ();
10353 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10357 gtk_widget_set_default_direction_recurse (tmp_list->data,
10358 GUINT_TO_POINTER (old_dir));
10359 g_object_unref (tmp_list->data);
10360 tmp_list = tmp_list->next;
10363 g_list_free (toplevels);
10368 * gtk_widget_get_default_direction:
10370 * Obtains the current default reading direction. See
10371 * gtk_widget_set_default_direction().
10373 * Return value: the current default direction.
10376 gtk_widget_get_default_direction (void)
10378 return gtk_default_direction;
10382 gtk_widget_dispose (GObject *object)
10384 GtkWidget *widget = GTK_WIDGET (object);
10385 GtkWidgetPrivate *priv = widget->priv;
10388 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10389 else if (gtk_widget_get_visible (widget))
10390 gtk_widget_hide (widget);
10392 priv->visible = FALSE;
10393 if (gtk_widget_get_realized (widget))
10394 gtk_widget_unrealize (widget);
10396 if (!priv->in_destruction)
10398 priv->in_destruction = TRUE;
10399 g_signal_emit (object, widget_signals[DESTROY], 0);
10400 priv->in_destruction = FALSE;
10403 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10407 gtk_widget_real_destroy (GtkWidget *object)
10409 /* gtk_object_destroy() will already hold a refcount on object */
10410 GtkWidget *widget = GTK_WIDGET (object);
10411 GtkWidgetPrivate *priv = widget->priv;
10413 /* wipe accelerator closures (keep order) */
10414 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10415 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10417 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10418 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10420 gtk_grab_remove (widget);
10422 g_object_unref (priv->style);
10423 priv->style = gtk_widget_get_default_style ();
10424 g_object_ref (priv->style);
10428 gtk_widget_finalize (GObject *object)
10430 GtkWidget *widget = GTK_WIDGET (object);
10431 GtkWidgetPrivate *priv = widget->priv;
10432 GtkWidgetAuxInfo *aux_info;
10433 GtkAccessible *accessible;
10435 gtk_grab_remove (widget);
10437 g_object_unref (priv->style);
10438 priv->style = NULL;
10440 g_free (priv->name);
10442 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10444 gtk_widget_aux_info_destroy (aux_info);
10446 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10448 g_object_unref (accessible);
10451 gtk_widget_path_free (priv->path);
10454 g_object_unref (priv->context);
10456 if (g_object_is_floating (object))
10457 g_warning ("A floating object was finalized. This means that someone\n"
10458 "called g_object_unref() on an object that had only a floating\n"
10459 "reference; the initial floating reference is not owned by anyone\n"
10460 "and must be removed with g_object_ref_sink().");
10462 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10465 /*****************************************
10466 * gtk_widget_real_map:
10471 *****************************************/
10474 gtk_widget_real_map (GtkWidget *widget)
10476 GtkWidgetPrivate *priv = widget->priv;
10478 g_assert (gtk_widget_get_realized (widget));
10480 if (!gtk_widget_get_mapped (widget))
10482 gtk_widget_set_mapped (widget, TRUE);
10484 if (gtk_widget_get_has_window (widget))
10485 gdk_window_show (priv->window);
10489 /*****************************************
10490 * gtk_widget_real_unmap:
10495 *****************************************/
10498 gtk_widget_real_unmap (GtkWidget *widget)
10500 GtkWidgetPrivate *priv = widget->priv;
10502 if (gtk_widget_get_mapped (widget))
10504 gtk_widget_set_mapped (widget, FALSE);
10506 if (gtk_widget_get_has_window (widget))
10507 gdk_window_hide (priv->window);
10511 /*****************************************
10512 * gtk_widget_real_realize:
10517 *****************************************/
10520 gtk_widget_real_realize (GtkWidget *widget)
10522 GtkWidgetPrivate *priv = widget->priv;
10524 g_assert (!gtk_widget_get_has_window (widget));
10526 gtk_widget_set_realized (widget, TRUE);
10529 priv->window = gtk_widget_get_parent_window (widget);
10530 g_object_ref (priv->window);
10532 priv->style = gtk_style_attach (priv->style, priv->window);
10535 /*****************************************
10536 * gtk_widget_real_unrealize:
10541 *****************************************/
10544 gtk_widget_real_unrealize (GtkWidget *widget)
10546 GtkWidgetPrivate *priv = widget->priv;
10548 g_assert (!widget->priv->mapped);
10550 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10553 /* We must do unrealize child widget BEFORE container widget.
10554 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10555 * So, unrealizing container widget bofore its children causes the problem
10556 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10559 if (GTK_IS_CONTAINER (widget))
10560 gtk_container_forall (GTK_CONTAINER (widget),
10561 (GtkCallback) gtk_widget_unrealize,
10564 gtk_style_detach (priv->style);
10565 if (gtk_widget_get_has_window (widget))
10567 gdk_window_set_user_data (priv->window, NULL);
10568 gdk_window_destroy (priv->window);
10569 priv->window = NULL;
10573 g_object_unref (priv->window);
10574 priv->window = NULL;
10577 gtk_selection_remove_all (widget);
10579 gtk_widget_set_realized (widget, FALSE);
10583 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10584 GtkOrientation orientation,
10585 gint *minimum_size,
10586 gint *natural_size)
10588 const GtkWidgetAuxInfo *aux_info;
10590 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10592 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10593 aux_info->width > 0)
10595 *minimum_size = MAX (*minimum_size, aux_info->width);
10597 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10598 aux_info->height > 0)
10600 *minimum_size = MAX (*minimum_size, aux_info->height);
10603 /* Fix it if set_size_request made natural size smaller than min size.
10604 * This would also silently fix broken widgets, but we warn about them
10605 * in gtksizerequest.c when calling their size request vfuncs.
10607 *natural_size = MAX (*natural_size, *minimum_size);
10609 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10611 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10612 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10616 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10617 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10622 * _gtk_widget_peek_request_cache:
10624 * Returns the address of the widget's request cache (strictly for
10625 * internal use in gtksizerequest.c)
10627 * Return value: the address of @widget's size request cache.
10630 _gtk_widget_peek_request_cache (GtkWidget *widget)
10632 /* Don't bother slowing things down with the return_if_fail guards here */
10633 return &widget->priv->requests;
10637 * _gtk_widget_set_device_window:
10638 * @widget: a #GtkWidget.
10639 * @device: a #GdkDevice.
10640 * @window: the new device window.
10642 * Sets pointer window for @widget and @device. Does not ref @window.
10643 * Actually stores it on the #GdkScreen, but you don't need to know that.
10646 _gtk_widget_set_device_window (GtkWidget *widget,
10650 GtkWidgetPrivate *priv;
10652 GHashTable *device_window;
10654 g_return_if_fail (GTK_IS_WIDGET (widget));
10655 g_return_if_fail (GDK_IS_DEVICE (device));
10656 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10658 priv = widget->priv;
10660 if (!gtk_widget_get_realized (widget))
10663 screen = gdk_window_get_screen (priv->window);
10664 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10666 if (G_UNLIKELY (!device_window))
10668 device_window = g_hash_table_new (NULL, NULL);
10669 g_object_set_qdata_full (G_OBJECT (screen),
10670 quark_pointer_window,
10672 (GDestroyNotify) g_hash_table_destroy);
10676 g_hash_table_insert (device_window, device, window);
10678 g_hash_table_remove (device_window, device);
10682 * _gtk_widget_get_device_window:
10683 * @widget: a #GtkWidget.
10684 * @device: a #GdkDevice.
10686 * Return value: the device window set on the #GdkScreen @widget is attached
10690 _gtk_widget_get_device_window (GtkWidget *widget,
10693 GtkWidgetPrivate *priv;
10695 GHashTable *device_window;
10699 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10700 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10702 priv = widget->priv;
10704 if (!gtk_widget_get_realized (widget))
10707 screen = gdk_window_get_screen (priv->window);
10708 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10710 if (G_UNLIKELY (!device_window))
10713 window = g_hash_table_lookup (device_window, device);
10718 gdk_window_get_user_data (window, (gpointer *) &w);
10727 * _gtk_widget_list_devices:
10728 * @widget: a #GtkWidget.
10730 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10731 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10735 _gtk_widget_list_devices (GtkWidget *widget)
10737 GtkWidgetPrivate *priv;
10739 GHashTableIter iter;
10740 GHashTable *device_window;
10741 GList *devices = NULL;
10742 gpointer key, value;
10744 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10746 priv = widget->priv;
10748 if (!gtk_widget_get_realized (widget))
10751 screen = gdk_window_get_screen (priv->window);
10752 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10754 if (G_UNLIKELY (!device_window))
10757 g_hash_table_iter_init (&iter, device_window);
10759 while (g_hash_table_iter_next (&iter, &key, &value))
10761 GdkDevice *device = key;
10762 GdkWindow *window = value;
10767 gdk_window_get_user_data (window, (gpointer *) &w);
10770 devices = g_list_prepend (devices, device);
10778 synth_crossing (GtkWidget *widget,
10782 GdkCrossingMode mode,
10783 GdkNotifyType detail)
10787 event = gdk_event_new (type);
10789 event->crossing.window = g_object_ref (window);
10790 event->crossing.send_event = TRUE;
10791 event->crossing.subwindow = g_object_ref (window);
10792 event->crossing.time = GDK_CURRENT_TIME;
10793 event->crossing.x = event->crossing.y = 0;
10794 event->crossing.x_root = event->crossing.y_root = 0;
10795 event->crossing.mode = mode;
10796 event->crossing.detail = detail;
10797 event->crossing.focus = FALSE;
10798 event->crossing.state = 0;
10799 gdk_event_set_device (event, device);
10802 widget = gtk_get_event_widget (event);
10805 gtk_widget_event_internal (widget, event);
10807 gdk_event_free (event);
10811 * _gtk_widget_synthesize_crossing:
10812 * @from: the #GtkWidget the virtual pointer is leaving.
10813 * @to: the #GtkWidget the virtual pointer is moving to.
10814 * @mode: the #GdkCrossingMode to place on the synthesized events.
10816 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10818 * The real pointer window is the window that most recently received an enter notify
10819 * event. Windows that don't select for crossing events can't become the real
10820 * poiner window. The real pointer widget that owns the real pointer window. The
10821 * effective pointer window is the same as the real pointer window unless the real
10822 * pointer widget is either insensitive or there is a grab on a widget that is not
10823 * an ancestor of the real pointer widget (in which case the effective pointer
10824 * window should be the root window).
10826 * When the effective pointer window is the same as the real poiner window, we
10827 * receive crossing events from the windowing system. When the effective pointer
10828 * window changes to become different from the real pointer window we synthesize
10829 * crossing events, attempting to follow X protocol rules:
10831 * When the root window becomes the effective pointer window:
10832 * - leave notify on real pointer window, detail Ancestor
10833 * - leave notify on all of its ancestors, detail Virtual
10834 * - enter notify on root window, detail Inferior
10836 * When the root window ceases to be the effective pointer window:
10837 * - leave notify on root window, detail Inferior
10838 * - enter notify on all ancestors of real pointer window, detail Virtual
10839 * - enter notify on real pointer window, detail Ancestor
10842 _gtk_widget_synthesize_crossing (GtkWidget *from,
10845 GdkCrossingMode mode)
10847 GdkWindow *from_window = NULL, *to_window = NULL;
10849 g_return_if_fail (from != NULL || to != NULL);
10853 from_window = _gtk_widget_get_device_window (from, device);
10856 from_window = from->priv->window;
10861 to_window = _gtk_widget_get_device_window (to, device);
10864 to_window = to->priv->window;
10867 if (from_window == NULL && to_window == NULL)
10869 else if (from_window != NULL && to_window == NULL)
10871 GList *from_ancestors = NULL, *list;
10872 GdkWindow *from_ancestor = from_window;
10874 while (from_ancestor != NULL)
10876 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10877 if (from_ancestor == NULL)
10879 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10882 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10883 device, mode, GDK_NOTIFY_ANCESTOR);
10884 for (list = g_list_last (from_ancestors); list; list = list->prev)
10886 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10887 device, mode, GDK_NOTIFY_VIRTUAL);
10890 /* XXX: enter/inferior on root window? */
10892 g_list_free (from_ancestors);
10894 else if (from_window == NULL && to_window != NULL)
10896 GList *to_ancestors = NULL, *list;
10897 GdkWindow *to_ancestor = to_window;
10899 while (to_ancestor != NULL)
10901 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10902 if (to_ancestor == NULL)
10904 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10907 /* XXX: leave/inferior on root window? */
10909 for (list = to_ancestors; list; list = list->next)
10911 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10912 device, mode, GDK_NOTIFY_VIRTUAL);
10914 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10915 device, mode, GDK_NOTIFY_ANCESTOR);
10917 g_list_free (to_ancestors);
10919 else if (from_window == to_window)
10923 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10924 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10926 while (from_ancestor != NULL || to_ancestor != NULL)
10928 if (from_ancestor != NULL)
10930 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10931 if (from_ancestor == to_window)
10934 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10936 if (to_ancestor != NULL)
10938 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10939 if (to_ancestor == from_window)
10942 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10945 if (to_ancestor == from_window)
10947 if (mode != GDK_CROSSING_GTK_UNGRAB)
10948 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10949 device, mode, GDK_NOTIFY_INFERIOR);
10950 for (list = to_ancestors; list; list = list->next)
10951 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10952 device, mode, GDK_NOTIFY_VIRTUAL);
10953 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10954 device, mode, GDK_NOTIFY_ANCESTOR);
10956 else if (from_ancestor == to_window)
10958 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10959 device, mode, GDK_NOTIFY_ANCESTOR);
10960 for (list = g_list_last (from_ancestors); list; list = list->prev)
10962 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10963 device, mode, GDK_NOTIFY_VIRTUAL);
10965 if (mode != GDK_CROSSING_GTK_GRAB)
10966 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10967 device, mode, GDK_NOTIFY_INFERIOR);
10971 while (from_ancestors != NULL && to_ancestors != NULL
10972 && from_ancestors->data == to_ancestors->data)
10974 from_ancestors = g_list_delete_link (from_ancestors,
10976 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10979 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10980 device, mode, GDK_NOTIFY_NONLINEAR);
10982 for (list = g_list_last (from_ancestors); list; list = list->prev)
10984 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10985 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10987 for (list = to_ancestors; list; list = list->next)
10989 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10990 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10992 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10993 device, mode, GDK_NOTIFY_NONLINEAR);
10995 g_list_free (from_ancestors);
10996 g_list_free (to_ancestors);
11001 gtk_widget_propagate_state (GtkWidget *widget,
11002 GtkStateData *data)
11004 GtkWidgetPrivate *priv = widget->priv;
11005 GtkStateFlags new_flags, old_flags = priv->state_flags;
11006 GtkStateType old_state;
11008 old_state = gtk_widget_get_state (widget);
11010 if (!priv->parent_sensitive)
11011 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
11013 priv->parent_sensitive = data->parent_sensitive;
11015 switch (data->operation)
11017 case STATE_CHANGE_REPLACE:
11018 priv->state_flags = data->flags;
11020 case STATE_CHANGE_SET:
11021 priv->state_flags |= data->flags;
11023 case STATE_CHANGE_UNSET:
11024 priv->state_flags &= ~(data->flags);
11028 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11032 window = gtk_widget_get_toplevel (widget);
11034 if (window && gtk_widget_is_toplevel (window))
11035 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11038 new_flags = gtk_widget_get_state_flags (widget);
11040 if (old_flags != new_flags)
11042 g_object_ref (widget);
11044 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11045 gtk_grab_remove (widget);
11047 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11048 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11050 if (!priv->shadowed)
11052 GList *event_windows = NULL;
11053 GList *devices, *d;
11055 devices = _gtk_widget_list_devices (widget);
11057 for (d = devices; d; d = d->next)
11063 window = _gtk_widget_get_device_window (widget, device);
11065 /* Do not propagate more than once to the
11066 * same window if non-multidevice aware.
11068 if (!gdk_window_get_support_multidevice (window) &&
11069 g_list_find (event_windows, window))
11072 if (!gtk_widget_is_sensitive (widget))
11073 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11074 GDK_CROSSING_STATE_CHANGED);
11075 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
11076 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11077 GDK_CROSSING_STATE_CHANGED);
11079 event_windows = g_list_prepend (event_windows, window);
11082 g_list_free (event_windows);
11083 g_list_free (devices);
11086 if (GTK_IS_CONTAINER (widget))
11088 data->parent_sensitive = gtk_widget_is_sensitive (widget);
11090 /* Do not propagate insensitive state further */
11091 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
11093 if (data->use_forall)
11094 gtk_container_forall (GTK_CONTAINER (widget),
11095 (GtkCallback) gtk_widget_propagate_state,
11098 gtk_container_foreach (GTK_CONTAINER (widget),
11099 (GtkCallback) gtk_widget_propagate_state,
11103 /* Trigger state change transitions for the widget */
11104 if (priv->context &&
11105 gtk_widget_get_mapped (widget))
11107 gint diff, flag = 1;
11110 diff = old_flags ^ new_flags;
11111 window = gtk_widget_get_window (widget);
11115 if ((diff & flag) != 0)
11119 target = ((new_flags & flag) != 0);
11120 _gtk_widget_notify_state_change (widget, flag, target);
11129 g_object_unref (widget);
11133 static const GtkWidgetAuxInfo default_aux_info = {
11141 * _gtk_widget_get_aux_info:
11142 * @widget: a #GtkWidget
11143 * @create: if %TRUE, create the structure if it doesn't exist
11145 * Get the #GtkWidgetAuxInfo structure for the widget.
11147 * Return value: the #GtkAuxInfo structure for the widget, or
11148 * %NULL if @create is %FALSE and one doesn't already exist.
11151 _gtk_widget_get_aux_info (GtkWidget *widget,
11154 GtkWidgetAuxInfo *aux_info;
11156 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11157 if (!aux_info && create)
11159 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11161 *aux_info = default_aux_info;
11163 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11169 static const GtkWidgetAuxInfo*
11170 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11172 GtkWidgetAuxInfo *aux_info;
11174 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
11175 if (aux_info == NULL)
11177 return &default_aux_info;
11185 /*****************************************
11186 * gtk_widget_aux_info_destroy:
11191 *****************************************/
11194 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11196 g_slice_free (GtkWidgetAuxInfo, aux_info);
11200 * gtk_widget_shape_combine_region:
11201 * @widget: a #GtkWidget
11202 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11204 * Sets a shape for this widget's GDK window. This allows for
11205 * transparent windows etc., see gdk_window_shape_combine_region()
11206 * for more information.
11211 gtk_widget_shape_combine_region (GtkWidget *widget,
11212 cairo_region_t *region)
11214 GtkWidgetPrivate *priv;
11216 g_return_if_fail (GTK_IS_WIDGET (widget));
11217 /* set_shape doesn't work on widgets without gdk window */
11218 g_return_if_fail (gtk_widget_get_has_window (widget));
11220 priv = widget->priv;
11222 if (region == NULL)
11224 priv->has_shape_mask = FALSE;
11227 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11229 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11233 priv->has_shape_mask = TRUE;
11235 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11236 cairo_region_copy (region),
11237 (GDestroyNotify) cairo_region_destroy);
11239 /* set shape if widget has a gdk window already.
11240 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11243 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11248 * gtk_widget_input_shape_combine_region:
11249 * @widget: a #GtkWidget
11250 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11252 * Sets an input shape for this widget's GDK window. This allows for
11253 * windows which react to mouse click in a nonrectangular region, see
11254 * gdk_window_input_shape_combine_region() for more information.
11259 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11260 cairo_region_t *region)
11262 GtkWidgetPrivate *priv;
11264 g_return_if_fail (GTK_IS_WIDGET (widget));
11265 /* set_shape doesn't work on widgets without gdk window */
11266 g_return_if_fail (gtk_widget_get_has_window (widget));
11268 priv = widget->priv;
11270 if (region == NULL)
11273 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11275 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11279 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11280 cairo_region_copy (region),
11281 (GDestroyNotify) cairo_region_destroy);
11283 /* set shape if widget has a gdk window already.
11284 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11287 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11292 /* style properties
11296 * gtk_widget_class_install_style_property_parser:
11297 * @klass: a #GtkWidgetClass
11298 * @pspec: the #GParamSpec for the style property
11299 * @parser: the parser for the style property
11301 * Installs a style property on a widget class.
11304 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11306 GtkRcPropertyParser parser)
11308 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11309 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11310 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11311 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11313 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11315 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11316 G_OBJECT_CLASS_NAME (klass),
11321 g_param_spec_ref_sink (pspec);
11322 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11323 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11327 * gtk_widget_class_install_style_property:
11328 * @klass: a #GtkWidgetClass
11329 * @pspec: the #GParamSpec for the property
11331 * Installs a style property on a widget class. The parser for the
11332 * style property is determined by the value type of @pspec.
11335 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11338 GtkRcPropertyParser parser;
11340 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11341 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11343 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11345 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11349 * gtk_widget_class_find_style_property:
11350 * @klass: a #GtkWidgetClass
11351 * @property_name: the name of the style property to find
11352 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11353 * style property with that name.
11355 * Finds a style property of a widget class by name.
11360 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11361 const gchar *property_name)
11363 g_return_val_if_fail (property_name != NULL, NULL);
11365 return g_param_spec_pool_lookup (style_property_spec_pool,
11367 G_OBJECT_CLASS_TYPE (klass),
11372 * gtk_widget_class_list_style_properties:
11373 * @klass: a #GtkWidgetClass
11374 * @n_properties: location to return the number of style properties found
11375 * @returns: an newly allocated array of #GParamSpec*. The array must
11376 * be freed with g_free().
11378 * Returns all style properties of a widget class.
11383 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11384 guint *n_properties)
11386 GParamSpec **pspecs;
11389 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11390 G_OBJECT_CLASS_TYPE (klass),
11399 * gtk_widget_style_get_property:
11400 * @widget: a #GtkWidget
11401 * @property_name: the name of a style property
11402 * @value: location to return the property value
11404 * Gets the value of a style property of @widget.
11407 gtk_widget_style_get_property (GtkWidget *widget,
11408 const gchar *property_name,
11413 g_return_if_fail (GTK_IS_WIDGET (widget));
11414 g_return_if_fail (property_name != NULL);
11415 g_return_if_fail (G_IS_VALUE (value));
11417 g_object_ref (widget);
11418 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11420 G_OBJECT_TYPE (widget),
11423 g_warning ("%s: widget class `%s' has no property named `%s'",
11425 G_OBJECT_TYPE_NAME (widget),
11429 GtkStyleContext *context;
11430 const GValue *peek_value;
11431 GtkStateFlags state;
11433 context = gtk_widget_get_style_context (widget);
11434 state = gtk_widget_get_state_flags (widget);
11436 peek_value = _gtk_style_context_peek_style_property (context,
11437 G_OBJECT_TYPE (widget),
11440 /* auto-conversion of the caller's value type
11442 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11443 g_value_copy (peek_value, value);
11444 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11445 g_value_transform (peek_value, value);
11447 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11449 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11450 G_VALUE_TYPE_NAME (value));
11452 g_object_unref (widget);
11456 * gtk_widget_style_get_valist:
11457 * @widget: a #GtkWidget
11458 * @first_property_name: the name of the first property to get
11459 * @var_args: a <type>va_list</type> of pairs of property names and
11460 * locations to return the property values, starting with the location
11461 * for @first_property_name.
11463 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11467 gtk_widget_style_get_valist (GtkWidget *widget,
11468 const gchar *first_property_name,
11471 GtkStyleContext *context;
11472 GtkStateFlags state;
11475 g_return_if_fail (GTK_IS_WIDGET (widget));
11477 g_object_ref (widget);
11478 context = gtk_widget_get_style_context (widget);
11479 state = gtk_widget_get_state_flags (widget);
11481 name = first_property_name;
11484 const GValue *peek_value;
11488 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11490 G_OBJECT_TYPE (widget),
11494 g_warning ("%s: widget class `%s' has no property named `%s'",
11496 G_OBJECT_TYPE_NAME (widget),
11500 /* style pspecs are always readable so we can spare that check here */
11502 peek_value = _gtk_style_context_peek_style_property (context,
11503 G_OBJECT_TYPE (widget),
11506 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11509 g_warning ("%s: %s", G_STRLOC, error);
11514 name = va_arg (var_args, gchar*);
11517 g_object_unref (widget);
11521 * gtk_widget_style_get:
11522 * @widget: a #GtkWidget
11523 * @first_property_name: the name of the first property to get
11524 * @Varargs: pairs of property names and locations to
11525 * return the property values, starting with the location for
11526 * @first_property_name, terminated by %NULL.
11528 * Gets the values of a multiple style properties of @widget.
11531 gtk_widget_style_get (GtkWidget *widget,
11532 const gchar *first_property_name,
11537 g_return_if_fail (GTK_IS_WIDGET (widget));
11539 va_start (var_args, first_property_name);
11540 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11546 * @widget: a #GtkWidget
11547 * @path_length: (out) (allow-none): location to store length of the path,
11549 * @path: (out) (allow-none): location to store allocated path string,
11551 * @path_reversed: (out) (allow-none): location to store allocated reverse
11552 * path string, or %NULL
11554 * Obtains the full path to @widget. The path is simply the name of a
11555 * widget and all its parents in the container hierarchy, separated by
11556 * periods. The name of a widget comes from
11557 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11558 * in gtkrc configuration files. Widget names are the type of the
11559 * widget by default (e.g. "GtkButton") or can be set to an
11560 * application-specific value with gtk_widget_set_name(). By setting
11561 * the name of a widget, you allow users or theme authors to apply
11562 * styles to that specific widget in their gtkrc
11563 * file. @path_reversed_p fills in the path in reverse order,
11564 * i.e. starting with @widget's name instead of starting with the name
11565 * of @widget's outermost ancestor.
11567 * Deprecated:3.0: Use gtk_widget_get_path() instead
11570 gtk_widget_path (GtkWidget *widget,
11571 guint *path_length,
11573 gchar **path_reversed)
11575 static gchar *rev_path = NULL;
11576 static guint tmp_path_len = 0;
11579 g_return_if_fail (GTK_IS_WIDGET (widget));
11584 const gchar *string;
11589 string = gtk_widget_get_name (widget);
11590 l = strlen (string);
11591 while (tmp_path_len <= len + l + 1)
11593 tmp_path_len += INIT_PATH_SIZE;
11594 rev_path = g_realloc (rev_path, tmp_path_len);
11596 s = string + l - 1;
11597 d = rev_path + len;
11598 while (s >= string)
11602 widget = widget->priv->parent;
11605 rev_path[len++] = '.';
11607 rev_path[len++] = 0;
11612 *path_length = len - 1;
11614 *path_reversed = g_strdup (rev_path);
11617 *path = g_strdup (rev_path);
11618 g_strreverse (*path);
11623 * gtk_widget_class_path:
11624 * @widget: a #GtkWidget
11625 * @path_length: (out) (allow-none): location to store the length of the
11626 * class path, or %NULL
11627 * @path: (out) (allow-none): location to store the class path as an
11628 * allocated string, or %NULL
11629 * @path_reversed: (out) (allow-none): location to store the reverse
11630 * class path as an allocated string, or %NULL
11632 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11633 * never uses a custom name set with gtk_widget_set_name().
11635 * Deprecated:3.0: Use gtk_widget_get_path() instead
11638 gtk_widget_class_path (GtkWidget *widget,
11639 guint *path_length,
11641 gchar **path_reversed)
11643 static gchar *rev_path = NULL;
11644 static guint tmp_path_len = 0;
11647 g_return_if_fail (GTK_IS_WIDGET (widget));
11652 const gchar *string;
11657 string = g_type_name (G_OBJECT_TYPE (widget));
11658 l = strlen (string);
11659 while (tmp_path_len <= len + l + 1)
11661 tmp_path_len += INIT_PATH_SIZE;
11662 rev_path = g_realloc (rev_path, tmp_path_len);
11664 s = string + l - 1;
11665 d = rev_path + len;
11666 while (s >= string)
11670 widget = widget->priv->parent;
11673 rev_path[len++] = '.';
11675 rev_path[len++] = 0;
11680 *path_length = len - 1;
11682 *path_reversed = g_strdup (rev_path);
11685 *path = g_strdup (rev_path);
11686 g_strreverse (*path);
11691 * gtk_requisition_new:
11693 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11695 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11696 * be freed with gtk_requisition_free().
11701 gtk_requisition_new (void)
11703 return g_slice_new0 (GtkRequisition);
11707 * gtk_requisition_copy:
11708 * @requisition: a #GtkRequisition
11710 * Copies a #GtkRequisition.
11712 * Returns: a copy of @requisition
11715 gtk_requisition_copy (const GtkRequisition *requisition)
11717 return g_slice_dup (GtkRequisition, requisition);
11721 * gtk_requisition_free:
11722 * @requisition: a #GtkRequisition
11724 * Frees a #GtkRequisition.
11727 gtk_requisition_free (GtkRequisition *requisition)
11729 g_slice_free (GtkRequisition, requisition);
11732 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11733 gtk_requisition_copy,
11734 gtk_requisition_free)
11737 * gtk_widget_get_accessible:
11738 * @widget: a #GtkWidget
11740 * Returns the accessible object that describes the widget to an
11741 * assistive technology.
11743 * If no accessibility library is loaded (i.e. no ATK implementation library is
11744 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11745 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11746 * if no class-specific #AtkObject implementation is available for the widget
11747 * instance in question, it will inherit an #AtkObject implementation from the
11748 * first ancestor class for which such an implementation is defined.
11750 * The documentation of the
11751 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11752 * library contains more information about accessible objects and their uses.
11754 * Returns: (transfer none): the #AtkObject associated with @widget
11757 gtk_widget_get_accessible (GtkWidget *widget)
11759 GtkWidgetClass *klass;
11761 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11763 klass = GTK_WIDGET_GET_CLASS (widget);
11765 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11767 return klass->get_accessible (widget);
11771 gtk_widget_real_get_accessible (GtkWidget *widget)
11773 AtkObject* accessible;
11775 accessible = g_object_get_qdata (G_OBJECT (widget),
11776 quark_accessible_object);
11779 AtkObjectFactory *factory;
11780 AtkRegistry *default_registry;
11782 default_registry = atk_get_default_registry ();
11783 factory = atk_registry_get_factory (default_registry,
11784 G_TYPE_FROM_INSTANCE (widget));
11786 atk_object_factory_create_accessible (factory,
11787 G_OBJECT (widget));
11788 g_object_set_qdata (G_OBJECT (widget),
11789 quark_accessible_object,
11796 * Initialize a AtkImplementorIface instance's virtual pointers as
11797 * appropriate to this implementor's class (GtkWidget).
11800 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11802 iface->ref_accessible = gtk_widget_ref_accessible;
11806 gtk_widget_ref_accessible (AtkImplementor *implementor)
11808 AtkObject *accessible;
11810 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11812 g_object_ref (accessible);
11817 * Expand flag management
11821 gtk_widget_update_computed_expand (GtkWidget *widget)
11823 GtkWidgetPrivate *priv;
11825 priv = widget->priv;
11827 if (priv->need_compute_expand)
11831 if (priv->hexpand_set)
11836 if (priv->vexpand_set)
11841 /* we don't need to use compute_expand if both expands are
11842 * forced by the app
11844 if (!(priv->hexpand_set && priv->vexpand_set))
11846 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11850 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11851 priv->hexpand_set ? &ignored : &h,
11852 priv->vexpand_set ? &ignored : &v);
11856 priv->need_compute_expand = FALSE;
11857 priv->computed_hexpand = h != FALSE;
11858 priv->computed_vexpand = v != FALSE;
11863 * gtk_widget_queue_compute_expand:
11864 * @widget: a #GtkWidget
11866 * Mark @widget as needing to recompute its expand flags. Call
11867 * this function when setting legacy expand child properties
11868 * on the child of a container.
11870 * See gtk_widget_compute_expand().
11873 gtk_widget_queue_compute_expand (GtkWidget *widget)
11876 gboolean changed_anything;
11878 if (widget->priv->need_compute_expand)
11881 changed_anything = FALSE;
11883 while (parent != NULL)
11885 if (!parent->priv->need_compute_expand)
11887 parent->priv->need_compute_expand = TRUE;
11888 changed_anything = TRUE;
11891 /* Note: if we had an invariant that "if a child needs to
11892 * compute expand, its parents also do" then we could stop going
11893 * up when we got to a parent that already needed to
11894 * compute. However, in general we compute expand lazily (as
11895 * soon as we see something in a subtree that is expand, we know
11896 * we're expanding) and so this invariant does not hold and we
11897 * have to always walk all the way up in case some ancestor
11898 * is not currently need_compute_expand.
11901 parent = parent->priv->parent;
11904 /* recomputing expand always requires
11905 * a relayout as well
11907 if (changed_anything)
11908 gtk_widget_queue_resize (widget);
11912 * gtk_widget_compute_expand:
11913 * @widget: the widget
11914 * @orientation: expand direction
11916 * Computes whether a container should give this widget extra space
11917 * when possible. Containers should check this, rather than
11918 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11920 * This function already checks whether the widget is visible, so
11921 * visibility does not need to be checked separately. Non-visible
11922 * widgets are not expanded.
11924 * The computed expand value uses either the expand setting explicitly
11925 * set on the widget itself, or, if none has been explicitly set,
11926 * the widget may expand if some of its children do.
11928 * Return value: whether widget tree rooted here should be expanded
11931 gtk_widget_compute_expand (GtkWidget *widget,
11932 GtkOrientation orientation)
11934 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11936 /* We never make a widget expand if not even showing. */
11937 if (!gtk_widget_get_visible (widget))
11940 gtk_widget_update_computed_expand (widget);
11942 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11944 return widget->priv->computed_hexpand;
11948 return widget->priv->computed_vexpand;
11953 gtk_widget_set_expand (GtkWidget *widget,
11954 GtkOrientation orientation,
11957 const char *expand_prop;
11958 const char *expand_set_prop;
11960 GtkWidgetPrivate *priv;
11962 g_return_if_fail (GTK_IS_WIDGET (widget));
11964 priv = widget->priv;
11966 expand = expand != FALSE;
11968 was_both = priv->hexpand && priv->vexpand;
11970 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11972 if (priv->hexpand_set &&
11973 priv->hexpand == expand)
11976 priv->hexpand_set = TRUE;
11977 priv->hexpand = expand;
11979 expand_prop = "hexpand";
11980 expand_set_prop = "hexpand-set";
11984 if (priv->vexpand_set &&
11985 priv->vexpand == expand)
11988 priv->vexpand_set = TRUE;
11989 priv->vexpand = expand;
11991 expand_prop = "vexpand";
11992 expand_set_prop = "vexpand-set";
11995 gtk_widget_queue_compute_expand (widget);
11997 g_object_freeze_notify (G_OBJECT (widget));
11998 g_object_notify (G_OBJECT (widget), expand_prop);
11999 g_object_notify (G_OBJECT (widget), expand_set_prop);
12000 if (was_both != (priv->hexpand && priv->vexpand))
12001 g_object_notify (G_OBJECT (widget), "expand");
12002 g_object_thaw_notify (G_OBJECT (widget));
12006 gtk_widget_set_expand_set (GtkWidget *widget,
12007 GtkOrientation orientation,
12010 GtkWidgetPrivate *priv;
12013 priv = widget->priv;
12015 set = set != FALSE;
12017 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12019 if (set == priv->hexpand_set)
12022 priv->hexpand_set = set;
12023 prop = "hexpand-set";
12027 if (set == priv->vexpand_set)
12030 priv->vexpand_set = set;
12031 prop = "vexpand-set";
12034 gtk_widget_queue_compute_expand (widget);
12036 g_object_notify (G_OBJECT (widget), prop);
12040 * gtk_widget_get_hexpand:
12041 * @widget: the widget
12043 * Gets whether the widget would like any available extra horizontal
12044 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12045 * generally receive the extra space. For example, a list or
12046 * scrollable area or document in your window would often be set to
12049 * Containers should use gtk_widget_compute_expand() rather than
12050 * this function, to see whether a widget, or any of its children,
12051 * has the expand flag set. If any child of a widget wants to
12052 * expand, the parent may ask to expand also.
12054 * This function only looks at the widget's own hexpand flag, rather
12055 * than computing whether the entire widget tree rooted at this widget
12058 * Return value: whether hexpand flag is set
12061 gtk_widget_get_hexpand (GtkWidget *widget)
12063 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12065 return widget->priv->hexpand;
12069 * gtk_widget_set_hexpand:
12070 * @widget: the widget
12071 * @expand: whether to expand
12073 * Sets whether the widget would like any available extra horizontal
12074 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12075 * generally receive the extra space. For example, a list or
12076 * scrollable area or document in your window would often be set to
12079 * Call this function to set the expand flag if you would like your
12080 * widget to become larger horizontally when the window has extra
12083 * By default, widgets automatically expand if any of their children
12084 * want to expand. (To see if a widget will automatically expand given
12085 * its current children and state, call gtk_widget_compute_expand(). A
12086 * container can decide how the expandability of children affects the
12087 * expansion of the container by overriding the compute_expand virtual
12088 * method on #GtkWidget.).
12090 * Setting hexpand explicitly with this function will override the
12091 * automatic expand behavior.
12093 * This function forces the widget to expand or not to expand,
12094 * regardless of children. The override occurs because
12095 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12096 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12097 * value to be used, rather than looking at children and widget state.
12100 gtk_widget_set_hexpand (GtkWidget *widget,
12103 g_return_if_fail (GTK_IS_WIDGET (widget));
12105 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12109 * gtk_widget_get_hexpand_set:
12110 * @widget: the widget
12112 * Gets whether gtk_widget_set_hexpand() has been used to
12113 * explicitly set the expand flag on this widget.
12115 * If hexpand is set, then it overrides any computed
12116 * expand value based on child widgets. If hexpand is not
12117 * set, then the expand value depends on whether any
12118 * children of the widget would like to expand.
12120 * There are few reasons to use this function, but it's here
12121 * for completeness and consistency.
12123 * Return value: whether hexpand has been explicitly set
12126 gtk_widget_get_hexpand_set (GtkWidget *widget)
12128 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12130 return widget->priv->hexpand_set;
12134 * gtk_widget_set_hexpand_set:
12135 * @widget: the widget
12136 * @set: value for hexpand-set property
12138 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12141 * The hexpand-set property will be set automatically when you call
12142 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12143 * reason to use this function would be to unset an explicit expand
12146 * If hexpand is set, then it overrides any computed
12147 * expand value based on child widgets. If hexpand is not
12148 * set, then the expand value depends on whether any
12149 * children of the widget would like to expand.
12151 * There are few reasons to use this function, but it's here
12152 * for completeness and consistency.
12155 gtk_widget_set_hexpand_set (GtkWidget *widget,
12158 g_return_if_fail (GTK_IS_WIDGET (widget));
12160 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12165 * gtk_widget_get_vexpand:
12166 * @widget: the widget
12168 * Gets whether the widget would like any available extra vertical
12171 * See gtk_widget_get_hexpand() for more detail.
12173 * Return value: whether vexpand flag is set
12176 gtk_widget_get_vexpand (GtkWidget *widget)
12178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12180 return widget->priv->vexpand;
12184 * gtk_widget_set_vexpand:
12185 * @widget: the widget
12186 * @expand: whether to expand
12188 * Sets whether the widget would like any available extra vertical
12191 * See gtk_widget_set_hexpand() for more detail.
12194 gtk_widget_set_vexpand (GtkWidget *widget,
12197 g_return_if_fail (GTK_IS_WIDGET (widget));
12199 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12203 * gtk_widget_get_vexpand_set:
12204 * @widget: the widget
12206 * Gets whether gtk_widget_set_vexpand() has been used to
12207 * explicitly set the expand flag on this widget.
12209 * See gtk_widget_get_hexpand_set() for more detail.
12211 * Return value: whether vexpand has been explicitly set
12214 gtk_widget_get_vexpand_set (GtkWidget *widget)
12216 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12218 return widget->priv->vexpand_set;
12222 * gtk_widget_set_vexpand_set:
12223 * @widget: the widget
12224 * @set: value for vexpand-set property
12226 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12229 * See gtk_widget_set_hexpand_set() for more detail.
12232 gtk_widget_set_vexpand_set (GtkWidget *widget,
12235 g_return_if_fail (GTK_IS_WIDGET (widget));
12237 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12241 * GtkBuildable implementation
12243 static GQuark quark_builder_has_default = 0;
12244 static GQuark quark_builder_has_focus = 0;
12245 static GQuark quark_builder_atk_relations = 0;
12246 static GQuark quark_builder_set_name = 0;
12249 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12251 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12252 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12253 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12254 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12256 iface->set_name = gtk_widget_buildable_set_name;
12257 iface->get_name = gtk_widget_buildable_get_name;
12258 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12259 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12260 iface->parser_finished = gtk_widget_buildable_parser_finished;
12261 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12262 iface->custom_finished = gtk_widget_buildable_custom_finished;
12266 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12269 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12270 g_strdup (name), g_free);
12273 static const gchar *
12274 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12276 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12280 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12281 GtkBuilder *builder,
12282 const gchar *childname)
12284 if (strcmp (childname, "accessible") == 0)
12285 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12291 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12292 GtkBuilder *builder,
12294 const GValue *value)
12296 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12297 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12298 GINT_TO_POINTER (TRUE));
12299 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12300 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12301 GINT_TO_POINTER (TRUE));
12303 g_object_set_property (G_OBJECT (buildable), name, value);
12308 gchar *action_name;
12309 GString *description;
12311 gboolean translatable;
12321 free_action (AtkActionData *data, gpointer user_data)
12323 g_free (data->action_name);
12324 g_string_free (data->description, TRUE);
12325 g_free (data->context);
12326 g_slice_free (AtkActionData, data);
12330 free_relation (AtkRelationData *data, gpointer user_data)
12332 g_free (data->target);
12333 g_free (data->type);
12334 g_slice_free (AtkRelationData, data);
12338 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12339 GtkBuilder *builder)
12341 GSList *atk_relations;
12343 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12344 gtk_widget_grab_default (GTK_WIDGET (buildable));
12345 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12346 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12348 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12349 quark_builder_atk_relations);
12352 AtkObject *accessible;
12353 AtkRelationSet *relation_set;
12356 AtkRelationType relation_type;
12357 AtkObject *target_accessible;
12359 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12360 relation_set = atk_object_ref_relation_set (accessible);
12362 for (l = atk_relations; l; l = l->next)
12364 AtkRelationData *relation = (AtkRelationData*)l->data;
12366 target = gtk_builder_get_object (builder, relation->target);
12369 g_warning ("Target object %s in <relation> does not exist",
12373 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12374 g_assert (target_accessible != NULL);
12376 relation_type = atk_relation_type_for_name (relation->type);
12377 if (relation_type == ATK_RELATION_NULL)
12379 g_warning ("<relation> type %s not found",
12383 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12384 target_accessible);
12386 g_object_unref (relation_set);
12388 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12389 g_slist_free (atk_relations);
12390 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12399 } AccessibilitySubParserData;
12402 accessibility_start_element (GMarkupParseContext *context,
12403 const gchar *element_name,
12404 const gchar **names,
12405 const gchar **values,
12406 gpointer user_data,
12409 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12411 gint line_number, char_number;
12413 if (strcmp (element_name, "relation") == 0)
12415 gchar *target = NULL;
12416 gchar *type = NULL;
12417 AtkRelationData *relation;
12419 for (i = 0; names[i]; i++)
12421 if (strcmp (names[i], "target") == 0)
12422 target = g_strdup (values[i]);
12423 else if (strcmp (names[i], "type") == 0)
12424 type = g_strdup (values[i]);
12427 g_markup_parse_context_get_position (context,
12430 g_set_error (error,
12432 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12433 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12435 line_number, char_number, names[i], "relation");
12442 if (!target || !type)
12444 g_markup_parse_context_get_position (context,
12447 g_set_error (error,
12449 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12450 "%s:%d:%d <%s> requires attribute \"%s\"",
12452 line_number, char_number, "relation",
12453 type ? "target" : "type");
12459 relation = g_slice_new (AtkRelationData);
12460 relation->target = target;
12461 relation->type = type;
12463 data->relations = g_slist_prepend (data->relations, relation);
12465 else if (strcmp (element_name, "action") == 0)
12467 const gchar *action_name = NULL;
12468 const gchar *description = NULL;
12469 const gchar *msg_context = NULL;
12470 gboolean translatable = FALSE;
12471 AtkActionData *action;
12473 for (i = 0; names[i]; i++)
12475 if (strcmp (names[i], "action_name") == 0)
12476 action_name = values[i];
12477 else if (strcmp (names[i], "description") == 0)
12478 description = values[i];
12479 else if (strcmp (names[i], "translatable") == 0)
12481 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12484 else if (strcmp (names[i], "comments") == 0)
12486 /* do nothing, comments are for translators */
12488 else if (strcmp (names[i], "context") == 0)
12489 msg_context = values[i];
12492 g_markup_parse_context_get_position (context,
12495 g_set_error (error,
12497 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12498 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12500 line_number, char_number, names[i], "action");
12507 g_markup_parse_context_get_position (context,
12510 g_set_error (error,
12512 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12513 "%s:%d:%d <%s> requires attribute \"%s\"",
12515 line_number, char_number, "action",
12520 action = g_slice_new (AtkActionData);
12521 action->action_name = g_strdup (action_name);
12522 action->description = g_string_new (description);
12523 action->context = g_strdup (msg_context);
12524 action->translatable = translatable;
12526 data->actions = g_slist_prepend (data->actions, action);
12528 else if (strcmp (element_name, "accessibility") == 0)
12531 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12535 accessibility_text (GMarkupParseContext *context,
12538 gpointer user_data,
12541 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12543 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12545 AtkActionData *action = data->actions->data;
12547 g_string_append_len (action->description, text, text_len);
12551 static const GMarkupParser accessibility_parser =
12553 accessibility_start_element,
12555 accessibility_text,
12564 } AccelGroupParserData;
12567 accel_group_start_element (GMarkupParseContext *context,
12568 const gchar *element_name,
12569 const gchar **names,
12570 const gchar **values,
12571 gpointer user_data,
12576 guint modifiers = 0;
12577 gchar *signal = NULL;
12578 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12580 for (i = 0; names[i]; i++)
12582 if (strcmp (names[i], "key") == 0)
12583 key = gdk_keyval_from_name (values[i]);
12584 else if (strcmp (names[i], "modifiers") == 0)
12586 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12592 else if (strcmp (names[i], "signal") == 0)
12593 signal = g_strdup (values[i]);
12596 if (key == 0 || signal == NULL)
12598 g_warning ("<accelerator> requires key and signal attributes");
12601 parser_data->key = key;
12602 parser_data->modifiers = modifiers;
12603 parser_data->signal = signal;
12606 static const GMarkupParser accel_group_parser =
12608 accel_group_start_element,
12612 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12613 GtkBuilder *builder,
12615 const gchar *tagname,
12616 GMarkupParser *parser,
12619 g_assert (buildable);
12621 if (strcmp (tagname, "accelerator") == 0)
12623 AccelGroupParserData *parser_data;
12625 parser_data = g_slice_new0 (AccelGroupParserData);
12626 parser_data->object = g_object_ref (buildable);
12627 *parser = accel_group_parser;
12628 *data = parser_data;
12631 if (strcmp (tagname, "accessibility") == 0)
12633 AccessibilitySubParserData *parser_data;
12635 parser_data = g_slice_new0 (AccessibilitySubParserData);
12636 *parser = accessibility_parser;
12637 *data = parser_data;
12644 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12645 GtkWidget *toplevel,
12646 gpointer user_data)
12648 AccelGroupParserData *accel_data;
12649 GSList *accel_groups;
12650 GtkAccelGroup *accel_group;
12652 g_return_if_fail (GTK_IS_WIDGET (widget));
12653 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12654 g_return_if_fail (user_data != NULL);
12656 accel_data = (AccelGroupParserData*)user_data;
12657 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12658 if (g_slist_length (accel_groups) == 0)
12660 accel_group = gtk_accel_group_new ();
12661 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12665 g_assert (g_slist_length (accel_groups) == 1);
12666 accel_group = g_slist_nth_data (accel_groups, 0);
12669 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12670 accel_data->signal,
12673 accel_data->modifiers,
12674 GTK_ACCEL_VISIBLE);
12676 g_object_unref (accel_data->object);
12677 g_free (accel_data->signal);
12678 g_slice_free (AccelGroupParserData, accel_data);
12682 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12683 GtkBuilder *builder,
12685 const gchar *tagname,
12686 gpointer user_data)
12688 AccelGroupParserData *accel_data;
12689 AccessibilitySubParserData *a11y_data;
12690 GtkWidget *toplevel;
12692 if (strcmp (tagname, "accelerator") == 0)
12694 accel_data = (AccelGroupParserData*)user_data;
12695 g_assert (accel_data->object);
12697 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12699 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12701 else if (strcmp (tagname, "accessibility") == 0)
12703 a11y_data = (AccessibilitySubParserData*)user_data;
12705 if (a11y_data->actions)
12707 AtkObject *accessible;
12712 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12714 action = ATK_ACTION (accessible);
12715 n_actions = atk_action_get_n_actions (action);
12717 for (l = a11y_data->actions; l; l = l->next)
12719 AtkActionData *action_data = (AtkActionData*)l->data;
12721 for (i = 0; i < n_actions; i++)
12722 if (strcmp (atk_action_get_name (action, i),
12723 action_data->action_name) == 0)
12728 gchar *description;
12730 if (action_data->translatable && action_data->description->len)
12731 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12732 action_data->context,
12733 action_data->description->str);
12735 description = action_data->description->str;
12737 atk_action_set_description (action, i, description);
12741 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12742 g_slist_free (a11y_data->actions);
12745 if (a11y_data->relations)
12746 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12747 a11y_data->relations);
12749 g_slice_free (AccessibilitySubParserData, a11y_data);
12754 gtk_widget_real_get_width (GtkWidget *widget,
12755 gint *minimum_size,
12756 gint *natural_size)
12766 gtk_widget_real_get_height (GtkWidget *widget,
12767 gint *minimum_size,
12768 gint *natural_size)
12778 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12780 gint *minimum_height,
12781 gint *natural_height)
12783 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12787 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12789 gint *minimum_width,
12790 gint *natural_width)
12792 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12796 * gtk_widget_get_halign:
12797 * @widget: a #GtkWidget
12799 * Gets the value of the #GtkWidget:halign property.
12801 * Returns: the horizontal alignment of @widget
12804 gtk_widget_get_halign (GtkWidget *widget)
12806 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12807 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12811 * gtk_widget_set_halign:
12812 * @widget: a #GtkWidget
12813 * @align: the horizontal alignment
12815 * Sets the horizontal alignment of @widget.
12816 * See the #GtkWidget:halign property.
12819 gtk_widget_set_halign (GtkWidget *widget,
12822 GtkWidgetAuxInfo *aux_info;
12824 g_return_if_fail (GTK_IS_WIDGET (widget));
12826 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12828 if (aux_info->halign == align)
12831 aux_info->halign = align;
12832 gtk_widget_queue_resize (widget);
12833 g_object_notify (G_OBJECT (widget), "halign");
12837 * gtk_widget_get_valign:
12838 * @widget: a #GtkWidget
12840 * Gets the value of the #GtkWidget:valign property.
12842 * Returns: the vertical alignment of @widget
12845 gtk_widget_get_valign (GtkWidget *widget)
12847 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12848 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12852 * gtk_widget_set_valign:
12853 * @widget: a #GtkWidget
12854 * @align: the vertical alignment
12856 * Sets the vertical alignment of @widget.
12857 * See the #GtkWidget:valign property.
12860 gtk_widget_set_valign (GtkWidget *widget,
12863 GtkWidgetAuxInfo *aux_info;
12865 g_return_if_fail (GTK_IS_WIDGET (widget));
12867 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12869 if (aux_info->valign == align)
12872 aux_info->valign = align;
12873 gtk_widget_queue_resize (widget);
12874 g_object_notify (G_OBJECT (widget), "valign");
12878 * gtk_widget_get_margin_left:
12879 * @widget: a #GtkWidget
12881 * Gets the value of the #GtkWidget:margin-left property.
12883 * Returns: The left margin of @widget
12886 gtk_widget_get_margin_left (GtkWidget *widget)
12888 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12890 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12894 * gtk_widget_set_margin_left:
12895 * @widget: a #GtkWidget
12896 * @margin: the left margin
12898 * Sets the left margin of @widget.
12899 * See the #GtkWidget:margin-left property.
12902 gtk_widget_set_margin_left (GtkWidget *widget,
12905 GtkWidgetAuxInfo *aux_info;
12907 g_return_if_fail (GTK_IS_WIDGET (widget));
12908 g_return_if_fail (margin <= G_MAXINT16);
12910 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12912 if (aux_info->margin.left == margin)
12915 aux_info->margin.left = margin;
12916 gtk_widget_queue_resize (widget);
12917 g_object_notify (G_OBJECT (widget), "margin-left");
12921 * gtk_widget_get_margin_right:
12922 * @widget: a #GtkWidget
12924 * Gets the value of the #GtkWidget:margin-right property.
12926 * Returns: The left margin of @widget
12929 gtk_widget_get_margin_right (GtkWidget *widget)
12931 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12933 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12937 * gtk_widget_set_margin_right:
12938 * @widget: a #GtkWidget
12939 * @margin: the right margin
12941 * Sets the right margin of @widget.
12942 * See the #GtkWidget:margin-right property.
12945 gtk_widget_set_margin_right (GtkWidget *widget,
12948 GtkWidgetAuxInfo *aux_info;
12950 g_return_if_fail (GTK_IS_WIDGET (widget));
12951 g_return_if_fail (margin <= G_MAXINT16);
12953 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12955 if (aux_info->margin.right == margin)
12958 aux_info->margin.right = margin;
12959 gtk_widget_queue_resize (widget);
12960 g_object_notify (G_OBJECT (widget), "margin-right");
12964 * gtk_widget_get_margin_top:
12965 * @widget: a #GtkWidget
12967 * Gets the value of the #GtkWidget:margin-top property.
12969 * Returns: The top margin of @widget
12972 gtk_widget_get_margin_top (GtkWidget *widget)
12974 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12976 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12980 * gtk_widget_set_margin_top:
12981 * @widget: a #GtkWidget
12982 * @margin: the top margin
12984 * Sets the top margin of @widget.
12985 * See the #GtkWidget:margin-top property.
12988 gtk_widget_set_margin_top (GtkWidget *widget,
12991 GtkWidgetAuxInfo *aux_info;
12993 g_return_if_fail (GTK_IS_WIDGET (widget));
12994 g_return_if_fail (margin <= G_MAXINT16);
12996 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12998 if (aux_info->margin.top == margin)
13001 aux_info->margin.top = margin;
13002 gtk_widget_queue_resize (widget);
13003 g_object_notify (G_OBJECT (widget), "margin-top");
13007 * gtk_widget_get_margin_bottom:
13008 * @widget: a #GtkWidget
13010 * Gets the value of the #GtkWidget:margin-bottom property.
13012 * Returns: The bottom margin of @widget
13015 gtk_widget_get_margin_bottom (GtkWidget *widget)
13017 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13019 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13023 * gtk_widget_set_margin_bottom:
13024 * @widget: a #GtkWidget
13025 * @margin: the bottom margin
13027 * Sets the bottom margin of @widget.
13028 * See the #GtkWidget:margin-bottom property.
13031 gtk_widget_set_margin_bottom (GtkWidget *widget,
13034 GtkWidgetAuxInfo *aux_info;
13036 g_return_if_fail (GTK_IS_WIDGET (widget));
13037 g_return_if_fail (margin <= G_MAXINT16);
13039 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
13041 if (aux_info->margin.bottom == margin)
13044 aux_info->margin.bottom = margin;
13045 gtk_widget_queue_resize (widget);
13046 g_object_notify (G_OBJECT (widget), "margin-bottom");
13050 * gtk_widget_get_clipboard:
13051 * @widget: a #GtkWidget
13052 * @selection: a #GdkAtom which identifies the clipboard
13053 * to use. %GDK_SELECTION_CLIPBOARD gives the
13054 * default clipboard. Another common value
13055 * is %GDK_SELECTION_PRIMARY, which gives
13056 * the primary X selection.
13058 * Returns the clipboard object for the given selection to
13059 * be used with @widget. @widget must have a #GdkDisplay
13060 * associated with it, so must be attached to a toplevel
13063 * Return value: (transfer none): the appropriate clipboard object. If no
13064 * clipboard already exists, a new one will
13065 * be created. Once a clipboard object has
13066 * been created, it is persistent for all time.
13071 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13073 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13074 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13076 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13081 * gtk_widget_list_mnemonic_labels:
13082 * @widget: a #GtkWidget
13084 * Returns a newly allocated list of the widgets, normally labels, for
13085 * which this widget is the target of a mnemonic (see for example,
13086 * gtk_label_set_mnemonic_widget()).
13088 * The widgets in the list are not individually referenced. If you
13089 * want to iterate through the list and perform actions involving
13090 * callbacks that might destroy the widgets, you
13091 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13092 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13093 * widgets afterwards.
13095 * Return value: (element-type GtkWidget) (transfer container): the list of
13096 * mnemonic labels; free this list
13097 * with g_list_free() when you are done with it.
13102 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13104 GList *list = NULL;
13107 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13109 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13110 list = g_list_prepend (list, l->data);
13116 * gtk_widget_add_mnemonic_label:
13117 * @widget: a #GtkWidget
13118 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13120 * Adds a widget to the list of mnemonic labels for
13121 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13122 * list of mnemonic labels for the widget is cleared when the
13123 * widget is destroyed, so the caller must make sure to update
13124 * its internal state at this point as well, by using a connection
13125 * to the #GtkWidget::destroy signal or a weak notifier.
13130 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13133 GSList *old_list, *new_list;
13135 g_return_if_fail (GTK_IS_WIDGET (widget));
13136 g_return_if_fail (GTK_IS_WIDGET (label));
13138 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13139 new_list = g_slist_prepend (old_list, label);
13141 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13142 new_list, (GDestroyNotify) g_slist_free);
13146 * gtk_widget_remove_mnemonic_label:
13147 * @widget: a #GtkWidget
13148 * @label: a #GtkWidget that was previously set as a mnemnic label for
13149 * @widget with gtk_widget_add_mnemonic_label().
13151 * Removes a widget from the list of mnemonic labels for
13152 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13153 * must have previously been added to the list with
13154 * gtk_widget_add_mnemonic_label().
13159 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13162 GSList *old_list, *new_list;
13164 g_return_if_fail (GTK_IS_WIDGET (widget));
13165 g_return_if_fail (GTK_IS_WIDGET (label));
13167 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13168 new_list = g_slist_remove (old_list, label);
13171 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13172 new_list, (GDestroyNotify) g_slist_free);
13176 * gtk_widget_get_no_show_all:
13177 * @widget: a #GtkWidget
13179 * Returns the current value of the #GtkWidget:no-show-all property,
13180 * which determines whether calls to gtk_widget_show_all()
13181 * will affect this widget.
13183 * Return value: the current value of the "no-show-all" property.
13188 gtk_widget_get_no_show_all (GtkWidget *widget)
13190 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13192 return widget->priv->no_show_all;
13196 * gtk_widget_set_no_show_all:
13197 * @widget: a #GtkWidget
13198 * @no_show_all: the new value for the "no-show-all" property
13200 * Sets the #GtkWidget:no-show-all property, which determines whether
13201 * calls to gtk_widget_show_all() will affect this widget.
13203 * This is mostly for use in constructing widget hierarchies with externally
13204 * controlled visibility, see #GtkUIManager.
13209 gtk_widget_set_no_show_all (GtkWidget *widget,
13210 gboolean no_show_all)
13212 g_return_if_fail (GTK_IS_WIDGET (widget));
13214 no_show_all = (no_show_all != FALSE);
13216 if (widget->priv->no_show_all != no_show_all)
13218 widget->priv->no_show_all = no_show_all;
13220 g_object_notify (G_OBJECT (widget), "no-show-all");
13226 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13227 gboolean has_tooltip,
13230 GtkWidgetPrivate *priv = widget->priv;
13231 gboolean priv_has_tooltip;
13233 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13234 quark_has_tooltip));
13236 if (priv_has_tooltip != has_tooltip || force)
13238 priv_has_tooltip = has_tooltip;
13240 if (priv_has_tooltip)
13242 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13243 gdk_window_set_events (priv->window,
13244 gdk_window_get_events (priv->window) |
13245 GDK_LEAVE_NOTIFY_MASK |
13246 GDK_POINTER_MOTION_MASK |
13247 GDK_POINTER_MOTION_HINT_MASK);
13249 if (gtk_widget_get_has_window (widget))
13250 gtk_widget_add_events (widget,
13251 GDK_LEAVE_NOTIFY_MASK |
13252 GDK_POINTER_MOTION_MASK |
13253 GDK_POINTER_MOTION_HINT_MASK);
13256 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13257 GUINT_TO_POINTER (priv_has_tooltip));
13262 * gtk_widget_set_tooltip_window:
13263 * @widget: a #GtkWidget
13264 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13266 * Replaces the default, usually yellow, window used for displaying
13267 * tooltips with @custom_window. GTK+ will take care of showing and
13268 * hiding @custom_window at the right moment, to behave likewise as
13269 * the default tooltip window. If @custom_window is %NULL, the default
13270 * tooltip window will be used.
13272 * If the custom window should have the default theming it needs to
13273 * have the name "gtk-tooltip", see gtk_widget_set_name().
13278 gtk_widget_set_tooltip_window (GtkWidget *widget,
13279 GtkWindow *custom_window)
13281 gboolean has_tooltip;
13282 gchar *tooltip_markup;
13284 g_return_if_fail (GTK_IS_WIDGET (widget));
13285 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13287 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13290 g_object_ref (custom_window);
13292 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13293 custom_window, g_object_unref);
13295 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13296 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13298 if (has_tooltip && gtk_widget_get_visible (widget))
13299 gtk_widget_queue_tooltip_query (widget);
13303 * gtk_widget_get_tooltip_window:
13304 * @widget: a #GtkWidget
13306 * Returns the #GtkWindow of the current tooltip. This can be the
13307 * GtkWindow created by default, or the custom tooltip window set
13308 * using gtk_widget_set_tooltip_window().
13310 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13315 gtk_widget_get_tooltip_window (GtkWidget *widget)
13317 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13319 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13323 * gtk_widget_trigger_tooltip_query:
13324 * @widget: a #GtkWidget
13326 * Triggers a tooltip query on the display where the toplevel of @widget
13327 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13333 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13335 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13338 static guint tooltip_query_id;
13339 static GSList *tooltip_query_displays;
13342 tooltip_query_idle (gpointer data)
13344 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13345 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13346 g_slist_free (tooltip_query_displays);
13348 tooltip_query_displays = NULL;
13349 tooltip_query_id = 0;
13355 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13357 GdkDisplay *display;
13359 display = gtk_widget_get_display (widget);
13361 if (!g_slist_find (tooltip_query_displays, display))
13362 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13364 if (tooltip_query_id == 0)
13365 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13369 * gtk_widget_set_tooltip_text:
13370 * @widget: a #GtkWidget
13371 * @text: the contents of the tooltip for @widget
13373 * Sets @text as the contents of the tooltip. This function will take
13374 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13375 * handler for the #GtkWidget::query-tooltip signal.
13377 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13382 gtk_widget_set_tooltip_text (GtkWidget *widget,
13385 g_return_if_fail (GTK_IS_WIDGET (widget));
13387 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13391 * gtk_widget_get_tooltip_text:
13392 * @widget: a #GtkWidget
13394 * Gets the contents of the tooltip for @widget.
13396 * Return value: the tooltip text, or %NULL. You should free the
13397 * returned string with g_free() when done.
13402 gtk_widget_get_tooltip_text (GtkWidget *widget)
13404 gchar *text = NULL;
13406 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13408 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13414 * gtk_widget_set_tooltip_markup:
13415 * @widget: a #GtkWidget
13416 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13418 * Sets @markup as the contents of the tooltip, which is marked up with
13419 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13421 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13422 * and of the default handler for the #GtkWidget::query-tooltip signal.
13424 * See also the #GtkWidget:tooltip-markup property and
13425 * gtk_tooltip_set_markup().
13430 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13431 const gchar *markup)
13433 g_return_if_fail (GTK_IS_WIDGET (widget));
13435 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13439 * gtk_widget_get_tooltip_markup:
13440 * @widget: a #GtkWidget
13442 * Gets the contents of the tooltip for @widget.
13444 * Return value: the tooltip text, or %NULL. You should free the
13445 * returned string with g_free() when done.
13450 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13452 gchar *text = NULL;
13454 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13456 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13462 * gtk_widget_set_has_tooltip:
13463 * @widget: a #GtkWidget
13464 * @has_tooltip: whether or not @widget has a tooltip.
13466 * Sets the has-tooltip property on @widget to @has_tooltip. See
13467 * #GtkWidget:has-tooltip for more information.
13472 gtk_widget_set_has_tooltip (GtkWidget *widget,
13473 gboolean has_tooltip)
13475 g_return_if_fail (GTK_IS_WIDGET (widget));
13477 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13481 * gtk_widget_get_has_tooltip:
13482 * @widget: a #GtkWidget
13484 * Returns the current value of the has-tooltip property. See
13485 * #GtkWidget:has-tooltip for more information.
13487 * Return value: current value of has-tooltip on @widget.
13492 gtk_widget_get_has_tooltip (GtkWidget *widget)
13494 gboolean has_tooltip = FALSE;
13496 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13498 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13500 return has_tooltip;
13504 * gtk_widget_get_allocation:
13505 * @widget: a #GtkWidget
13506 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13508 * Retrieves the widget's allocation.
13510 * Note, when implementing a #GtkContainer: a widget's allocation will
13511 * be its "adjusted" allocation, that is, the widget's parent
13512 * container typically calls gtk_widget_size_allocate() with an
13513 * allocation, and that allocation is then adjusted (to handle margin
13514 * and alignment for example) before assignment to the widget.
13515 * gtk_widget_get_allocation() returns the adjusted allocation that
13516 * was actually assigned to the widget. The adjusted allocation is
13517 * guaranteed to be completely contained within the
13518 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13519 * is guaranteed that its children stay inside the assigned bounds,
13520 * but not that they have exactly the bounds the container assigned.
13521 * There is no way to get the original allocation assigned by
13522 * gtk_widget_size_allocate(), since it isn't stored; if a container
13523 * implementation needs that information it will have to track it itself.
13528 gtk_widget_get_allocation (GtkWidget *widget,
13529 GtkAllocation *allocation)
13531 GtkWidgetPrivate *priv;
13533 g_return_if_fail (GTK_IS_WIDGET (widget));
13534 g_return_if_fail (allocation != NULL);
13536 priv = widget->priv;
13538 *allocation = priv->allocation;
13542 * gtk_widget_set_allocation:
13543 * @widget: a #GtkWidget
13544 * @allocation: a pointer to a #GtkAllocation to copy from
13546 * Sets the widget's allocation. This should not be used
13547 * directly, but from within a widget's size_allocate method.
13549 * The allocation set should be the "adjusted" or actual
13550 * allocation. If you're implementing a #GtkContainer, you want to use
13551 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13552 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13553 * allocation inside gtk_widget_size_allocate() to create an adjusted
13559 gtk_widget_set_allocation (GtkWidget *widget,
13560 const GtkAllocation *allocation)
13562 GtkWidgetPrivate *priv;
13564 g_return_if_fail (GTK_IS_WIDGET (widget));
13565 g_return_if_fail (allocation != NULL);
13567 priv = widget->priv;
13569 priv->allocation = *allocation;
13573 * gtk_widget_get_allocated_width:
13574 * @widget: the widget to query
13576 * Returns the width that has currently been allocated to @widget.
13577 * This function is intended to be used when implementing handlers
13578 * for the #GtkWidget::draw function.
13580 * Returns: the width of the @widget
13583 gtk_widget_get_allocated_width (GtkWidget *widget)
13585 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13587 return widget->priv->allocation.width;
13591 * gtk_widget_get_allocated_height:
13592 * @widget: the widget to query
13594 * Returns the height that has currently been allocated to @widget.
13595 * This function is intended to be used when implementing handlers
13596 * for the #GtkWidget::draw function.
13598 * Returns: the height of the @widget
13601 gtk_widget_get_allocated_height (GtkWidget *widget)
13603 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13605 return widget->priv->allocation.height;
13609 * gtk_widget_get_requisition:
13610 * @widget: a #GtkWidget
13611 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13613 * Retrieves the widget's requisition.
13615 * This function should only be used by widget implementations in
13616 * order to figure whether the widget's requisition has actually
13617 * changed after some internal state change (so that they can call
13618 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13620 * Normally, gtk_widget_size_request() should be used.
13624 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13625 * removed, If you need to cache sizes across requests and allocations,
13626 * add an explicit cache to the widget in question instead.
13629 gtk_widget_get_requisition (GtkWidget *widget,
13630 GtkRequisition *requisition)
13632 g_return_if_fail (GTK_IS_WIDGET (widget));
13633 g_return_if_fail (requisition != NULL);
13635 gtk_widget_get_preferred_size (widget, requisition, NULL);
13639 * gtk_widget_set_window:
13640 * @widget: a #GtkWidget
13641 * @window: a #GdkWindow
13643 * Sets a widget's window. This function should only be used in a
13644 * widget's #GtkWidget::realize implementation. The %window passed is
13645 * usually either new window created with gdk_window_new(), or the
13646 * window of its parent widget as returned by
13647 * gtk_widget_get_parent_window().
13649 * Widgets must indicate whether they will create their own #GdkWindow
13650 * by calling gtk_widget_set_has_window(). This is usually done in the
13651 * widget's init() function.
13653 * <note><para>This function does not add any reference to @window.</para></note>
13658 gtk_widget_set_window (GtkWidget *widget,
13661 GtkWidgetPrivate *priv;
13663 g_return_if_fail (GTK_IS_WIDGET (widget));
13664 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13666 priv = widget->priv;
13668 if (priv->window != window)
13670 priv->window = window;
13671 g_object_notify (G_OBJECT (widget), "window");
13676 * gtk_widget_get_window:
13677 * @widget: a #GtkWidget
13679 * Returns the widget's window if it is realized, %NULL otherwise
13681 * Return value: (transfer none): @widget's window.
13686 gtk_widget_get_window (GtkWidget *widget)
13688 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13690 return widget->priv->window;
13694 * gtk_widget_get_support_multidevice:
13695 * @widget: a #GtkWidget
13697 * Returns %TRUE if @widget is multiple pointer aware. See
13698 * gtk_widget_set_support_multidevice() for more information.
13700 * Returns: %TRUE if @widget is multidevice aware.
13703 gtk_widget_get_support_multidevice (GtkWidget *widget)
13705 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13707 return widget->priv->multidevice;
13711 * gtk_widget_set_support_multidevice:
13712 * @widget: a #GtkWidget
13713 * @support_multidevice: %TRUE to support input from multiple devices.
13715 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13716 * @widget will start receiving multiple, per device enter/leave events. Note
13717 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13718 * gdk_window_set_support_multidevice() will have to be called manually on them.
13723 gtk_widget_set_support_multidevice (GtkWidget *widget,
13724 gboolean support_multidevice)
13726 GtkWidgetPrivate *priv;
13728 g_return_if_fail (GTK_IS_WIDGET (widget));
13730 priv = widget->priv;
13731 priv->multidevice = (support_multidevice == TRUE);
13733 if (gtk_widget_get_realized (widget))
13734 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13738 _gtk_widget_set_has_focus (GtkWidget *widget,
13739 gboolean has_focus)
13741 widget->priv->has_focus = has_focus;
13745 * gtk_widget_send_focus_change:
13746 * @widget: a #GtkWidget
13747 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13749 * Sends the focus change @event to @widget
13751 * This function is not meant to be used by applications. The only time it
13752 * should be used is when it is necessary for a #GtkWidget to assign focus
13753 * to a widget that is semantically owned by the first widget even though
13754 * it's not a direct child - for instance, a search entry in a floating
13755 * window similar to the quick search in #GtkTreeView.
13757 * An example of its usage is:
13760 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13762 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13763 * fevent->focus_change.in = TRUE;
13764 * fevent->focus_change.window = gtk_widget_get_window (widget);
13765 * if (fevent->focus_change.window != NULL)
13766 * g_object_ref (fevent->focus_change.window);
13768 * gtk_widget_send_focus_change (widget, fevent);
13770 * gdk_event_free (event);
13773 * Return value: the return value from the event signal emission: %TRUE
13774 * if the event was handled, and %FALSE otherwise
13779 gtk_widget_send_focus_change (GtkWidget *widget,
13784 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13785 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13787 g_object_ref (widget);
13789 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13791 res = gtk_widget_event (widget, event);
13793 g_object_notify (G_OBJECT (widget), "has-focus");
13795 g_object_unref (widget);
13801 * gtk_widget_in_destruction:
13802 * @widget: a #GtkWidget
13804 * Returns whether the widget is currently being destroyed.
13805 * This information can sometimes be used to avoid doing
13806 * unnecessary work.
13808 * Returns: %TRUE if @widget is being destroyed
13811 gtk_widget_in_destruction (GtkWidget *widget)
13813 return widget->priv->in_destruction;
13817 _gtk_widget_get_resize_pending (GtkWidget *widget)
13819 return widget->priv->resize_pending;
13823 _gtk_widget_set_resize_pending (GtkWidget *widget,
13824 gboolean resize_pending)
13826 widget->priv->resize_pending = resize_pending;
13830 _gtk_widget_get_in_reparent (GtkWidget *widget)
13832 return widget->priv->in_reparent;
13836 _gtk_widget_set_in_reparent (GtkWidget *widget,
13837 gboolean in_reparent)
13839 widget->priv->in_reparent = in_reparent;
13843 _gtk_widget_get_anchored (GtkWidget *widget)
13845 return widget->priv->anchored;
13849 _gtk_widget_set_anchored (GtkWidget *widget,
13852 widget->priv->anchored = anchored;
13856 _gtk_widget_get_shadowed (GtkWidget *widget)
13858 return widget->priv->shadowed;
13862 _gtk_widget_set_shadowed (GtkWidget *widget,
13865 widget->priv->shadowed = shadowed;
13869 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13871 return widget->priv->alloc_needed;
13875 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13876 gboolean alloc_needed)
13878 widget->priv->alloc_needed = alloc_needed;
13882 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13884 return widget->priv->width_request_needed;
13888 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13889 gboolean width_request_needed)
13891 widget->priv->width_request_needed = width_request_needed;
13895 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13897 return widget->priv->height_request_needed;
13901 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13902 gboolean height_request_needed)
13904 widget->priv->height_request_needed = height_request_needed;
13908 * gtk_widget_get_path:
13909 * @widget: a #GtkWidget
13911 * Returns the #GtkWidgetPath representing @widget, if the widget
13912 * is not connected to a toplevel widget, a partial path will be
13915 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13918 gtk_widget_get_path (GtkWidget *widget)
13920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13922 /* As strange as it may seem, this may happen on object construction.
13923 * init() implementations of parent types may eventually call this function,
13924 * each with its corresponding GType, which could leave a child
13925 * implementation with a wrong widget type in the widget path
13927 if (widget->priv->path &&
13928 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (widget->priv->path))
13930 gtk_widget_path_free (widget->priv->path);
13931 widget->priv->path = NULL;
13934 if (!widget->priv->path)
13939 parent = widget->priv->parent;
13942 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13945 /* Widget is either toplevel or unparented, treat both
13946 * as toplevels style wise, since there are situations
13947 * where style properties might be retrieved on that
13950 widget->priv->path = gtk_widget_path_new ();
13953 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13955 if (widget->priv->name)
13956 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13958 if (widget->priv->context)
13959 gtk_style_context_set_path (widget->priv->context,
13960 widget->priv->path);
13963 return widget->priv->path;
13967 style_context_changed (GtkStyleContext *context,
13968 gpointer user_data)
13970 GtkWidget *widget = user_data;
13972 gtk_widget_update_pango_context (widget);
13974 if (gtk_widget_get_realized (widget))
13975 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13978 /* Compress all style updates so it
13979 * is only emitted once pre-realize.
13981 widget->priv->style_update_pending = TRUE;
13984 if (widget->priv->anchored)
13985 gtk_widget_queue_resize (widget);
13989 * gtk_widget_get_style_context:
13990 * @widget: a #GtkWidget
13992 * Returns the style context associated to @widget.
13994 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13995 * must not be freed.
13998 gtk_widget_get_style_context (GtkWidget *widget)
14000 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14002 if (G_UNLIKELY (!widget->priv->context))
14004 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
14005 "direction", gtk_widget_get_direction (widget),
14008 g_signal_connect (widget->priv->context, "changed",
14009 G_CALLBACK (style_context_changed), widget);
14011 gtk_style_context_set_screen (widget->priv->context,
14012 gtk_widget_get_screen (widget));
14014 _gtk_widget_update_path (widget);
14015 gtk_style_context_set_path (widget->priv->context,
14016 widget->priv->path);
14020 /* Force widget path regeneration if needed, the
14021 * context will be updated within this function.
14023 gtk_widget_get_path (widget);
14026 return widget->priv->context;