1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
66 * @Short_description: Base class for all widgets
69 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
70 * widget lifecycle, states and style.
72 * <refsect2 id="geometry-management">
73 * <title>Height-for-width Geometry Management</title>
75 * GTK+ uses a height-for-width (and width-for-height) geometry management
76 * system. Height-for-width means that a widget can change how much
77 * vertical space it needs, depending on the amount of horizontal space
78 * that it is given (and similar for width-for-height). The most common
79 * example is a label that reflows to fill up the available width, wraps
80 * to fewer lines, and therefore needs less height.
82 * Height-for-width geometry management is implemented in GTK+ by way
83 * of five virtual methods:
85 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
86 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
87 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
88 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
92 * There are some important things to keep in mind when implementing
93 * height-for-width and when using it in container implementations.
95 * The geometry management system will query a widget hierarchy in
96 * only one orientation at a time. When widgets are initially queried
97 * for their minimum sizes it is generally done in two initial passes
98 * in the #GtkSizeRequestMode chosen by the toplevel.
100 * For example, when queried in the normal
101 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
102 * First, the default minimum and natural width for each widget
103 * in the interface will be computed using gtk_width_get_preferred_width().
104 * Because the preferred widths for each container depend on the preferred
105 * widths of their children, this information propagates up the hierarchy,
106 * and finally a minimum and natural width is determined for the entire
107 * toplevel. Next, the toplevel will use the minimum width to query for the
108 * minimum height contextual to that width using
109 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
110 * recursive operation. The minimum height for the minimum width is normally
111 * used to set the minimum size constraint on the toplevel
112 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
114 * After the toplevel window has initially requested its size in both
115 * dimensions it can go on to allocate itself a reasonable size (or a size
116 * previously specified with gtk_window_set_default_size()). During the
117 * recursive allocation process it's important to note that request cycles
118 * will be recursively executed while container widgets allocate their children.
119 * Each container widget, once allocated a size, will go on to first share the
120 * space in one orientation among its children and then request each child's
121 * height for its target allocated width or its width for allocated height,
122 * depending. In this way a #GtkWidget will typically be requested its size
123 * a number of times before actually being allocated a size. The size a
124 * widget is finally allocated can of course differ from the size it has
125 * requested. For this reason, #GtkWidget caches a small number of results
126 * to avoid re-querying for the same sizes in one allocation cycle.
128 * See <link linkend="container-geometry-management">GtkContainer's
129 * geometry management section</link>
130 * to learn more about how height-for-width allocations are performed
131 * by container widgets.
133 * If a widget does move content around to intelligently use up the
134 * allocated size then it must support the request in both
135 * #GtkSizeRequestModes even if the widget in question only
136 * trades sizes in a single orientation.
138 * For instance, a #GtkLabel that does height-for-width word wrapping
139 * will not expect to have #GtkWidgetClass.get_preferred_height() called
140 * because that call is specific to a width-for-height request. In this
141 * case the label must return the height required for its own minimum
142 * possible width. By following this rule any widget that handles
143 * height-for-width or width-for-height requests will always be allocated
144 * at least enough space to fit its own content.
146 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
147 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
149 * <programlisting><![CDATA[
151 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
153 * if (i_am_in_height_for_width_mode)
157 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
158 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
159 * min_height, nat_height);
163 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
164 * it will return the minimum and natural height for the rotated label here.
167 * ]]></programlisting>
169 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
170 * the minimum and natural width:
172 * <programlisting><![CDATA[
174 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
175 * gint *min_width, gint *nat_width)
177 * if (i_am_in_height_for_width_mode)
179 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
183 * ... again if a widget is sometimes operating in width-for-height mode
184 * (like a rotated GtkLabel) it can go ahead and do its real width for
185 * height calculation here.
188 * ]]></programlisting>
190 * Often a widget needs to get its own request during size request or
191 * allocation. For example, when computing height it may need to also
192 * compute width. Or when deciding how to use an allocation, the widget
193 * may need to know its natural size. In these cases, the widget should
194 * be careful to call its virtual methods directly, like this:
196 * <title>Widget calling its own size request method.</title>
198 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
203 * It will not work to use the wrapper functions, such as
204 * gtk_widget_get_preferred_width() inside your own size request
205 * implementation. These return a request adjusted by #GtkSizeGroup
206 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
207 * widget used the wrappers inside its virtual method implementations,
208 * then the adjustments (such as widget margins) would be applied
209 * twice. GTK+ therefore does not allow this and will warn if you try
212 * Of course if you are getting the size request for
213 * <emphasis>another</emphasis> widget, such as a child of a
214 * container, you <emphasis>must</emphasis> use the wrapper APIs.
215 * Otherwise, you would not properly consider widget margins,
216 * #GtkSizeGroup, and so forth.
219 * <refsect2 id="style-properties">
220 * <title>Style Properties</title>
222 * <structname>GtkWidget</structname> introduces <firstterm>style
223 * properties</firstterm> - these are basically object properties that are stored
224 * not on the object, but in the style object associated to the widget. Style
225 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
226 * This mechanism is used for configuring such things as the location of the
227 * scrollbar arrows through the theme, giving theme authors more control over the
228 * look of applications without the need to write a theme engine in C.
231 * Use gtk_widget_class_install_style_property() to install style properties for
232 * a widget class, gtk_widget_class_find_style_property() or
233 * gtk_widget_class_list_style_properties() to get information about existing
234 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
235 * gtk_widget_style_get_valist() to obtain the value of a style property.
238 * <refsect2 id="GtkWidget-BUILDER-UI">
239 * <title>GtkWidget as GtkBuildable</title>
241 * The GtkWidget implementation of the GtkBuildable interface supports a
242 * custom <accelerator> element, which has attributes named key,
243 * modifiers and signal and allows to specify accelerators.
246 * <title>A UI definition fragment specifying an accelerator</title>
247 * <programlisting><![CDATA[
248 * <object class="GtkButton">
249 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
251 * ]]></programlisting>
254 * In addition to accelerators, <structname>GtkWidget</structname> also support a
255 * custom <accessible> element, which supports actions and relations.
256 * Properties on the accessible implementation of an object can be set by accessing the
257 * internal child "accessible" of a <structname>GtkWidget</structname>.
260 * <title>A UI definition fragment specifying an accessible</title>
261 * <programlisting><![CDATA[
262 * <object class="GtkButton" id="label1"/>
263 * <property name="label">I am a Label for a Button</property>
265 * <object class="GtkButton" id="button1">
267 * <action action_name="click" translatable="yes">Click the button.</action>
268 * <relation target="label1" type="labelled-by"/>
270 * <child internal-child="accessible">
271 * <object class="AtkObject" id="a11y-button1">
272 * <property name="AtkObject::name">Clickable Button</property>
276 * ]]></programlisting>
281 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
282 #define INIT_PATH_SIZE (512)
284 struct _GtkWidgetPrivate
286 /* The state of the widget. There are actually only
287 * 5 widget states (defined in "gtkenums.h")
292 /* The saved state of the widget. When a widget's state
293 * is changed to GTK_STATE_INSENSITIVE via
294 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
295 * the old state is kept around in this field. The state
296 * will be restored once the widget gets sensitive again.
298 guint saved_state : 3;
302 guint in_destruction : 1;
305 guint composite_child : 1;
311 guint parent_sensitive : 1;
314 guint can_default : 1;
315 guint has_default : 1;
316 guint receives_default : 1;
320 guint user_style : 1;
321 guint app_paintable : 1;
322 guint double_buffered : 1;
323 guint redraw_on_alloc : 1;
324 guint no_show_all : 1;
325 guint child_visible : 1;
326 guint multidevice : 1;
327 guint has_shape_mask : 1;
328 guint in_reparent : 1;
329 guint resize_pending : 1;
330 guint alloc_needed : 1;
331 guint width_request_needed : 1;
332 guint height_request_needed : 1;
334 /* Expand-related flags */
335 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
336 guint computed_hexpand : 1; /* computed results (composite of child flags) */
337 guint computed_vexpand : 1;
338 guint hexpand : 1; /* application-forced expand */
340 guint hexpand_set : 1; /* whether to use application-forced */
341 guint vexpand_set : 1; /* instead of computing from children */
343 /* The widget's name. If the widget does not have a name
344 * (the name is NULL), then its name (as returned by
345 * "gtk_widget_get_name") is its class's name.
346 * Among other things, the widget name is used to determine
347 * the style to use for a widget.
351 /* The style for the widget. The style contains the
352 * colors the widget should be drawn in for each state
353 * along with graphics contexts used to draw with and
354 * the font to use for text.
358 /* The widget's allocated size.
360 GtkAllocation allocation;
362 /* The widget's requested sizes */
363 SizeRequestCache requests;
365 /* The widget's window or its parent window if it does
366 * not have a window. (Which will be indicated by the
367 * GTK_NO_WINDOW flag being set).
371 /* The widget's parent.
401 BUTTON_RELEASE_EVENT,
416 PROPERTY_NOTIFY_EVENT,
417 SELECTION_CLEAR_EVENT,
418 SELECTION_REQUEST_EVENT,
419 SELECTION_NOTIFY_EVENT,
425 VISIBILITY_NOTIFY_EVENT,
439 ACCEL_CLOSURES_CHANGED,
462 PROP_RECEIVES_DEFAULT,
463 PROP_COMPOSITE_CHILD,
466 PROP_EXTENSION_EVENTS,
472 PROP_DOUBLE_BUFFERED,
487 typedef struct _GtkStateData GtkStateData;
492 guint state_restoration : 1;
493 guint parent_sensitive : 1;
494 guint use_forall : 1;
497 /* --- prototypes --- */
498 static void gtk_widget_class_init (GtkWidgetClass *klass);
499 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
500 static void gtk_widget_init (GtkWidget *widget);
501 static void gtk_widget_set_property (GObject *object,
505 static void gtk_widget_get_property (GObject *object,
509 static void gtk_widget_dispose (GObject *object);
510 static void gtk_widget_real_destroy (GtkWidget *object);
511 static void gtk_widget_finalize (GObject *object);
512 static void gtk_widget_real_show (GtkWidget *widget);
513 static void gtk_widget_real_hide (GtkWidget *widget);
514 static void gtk_widget_real_map (GtkWidget *widget);
515 static void gtk_widget_real_unmap (GtkWidget *widget);
516 static void gtk_widget_real_realize (GtkWidget *widget);
517 static void gtk_widget_real_unrealize (GtkWidget *widget);
518 static void gtk_widget_real_size_allocate (GtkWidget *widget,
519 GtkAllocation *allocation);
520 static void gtk_widget_real_style_set (GtkWidget *widget,
521 GtkStyle *previous_style);
522 static void gtk_widget_real_direction_changed(GtkWidget *widget,
523 GtkTextDirection previous_direction);
525 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
526 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
529 gboolean keyboard_tip,
530 GtkTooltip *tooltip);
531 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
532 GtkWidgetHelpType help_type);
534 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
536 GParamSpec **pspecs);
537 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
539 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
541 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
542 GdkEventFocus *event);
543 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
544 GdkEventFocus *event);
545 static gboolean gtk_widget_real_focus (GtkWidget *widget,
546 GtkDirectionType direction);
547 static void gtk_widget_real_move_focus (GtkWidget *widget,
548 GtkDirectionType direction);
549 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
550 GtkDirectionType direction);
551 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
552 static void gtk_widget_update_pango_context (GtkWidget *widget);
553 static void gtk_widget_propagate_state (GtkWidget *widget,
555 static void gtk_widget_reset_rc_style (GtkWidget *widget);
556 static void gtk_widget_set_style_internal (GtkWidget *widget,
558 gboolean initial_emission);
559 static gint gtk_widget_event_internal (GtkWidget *widget,
561 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
562 gboolean group_cycling);
563 static void gtk_widget_real_get_width (GtkWidget *widget,
566 static void gtk_widget_real_get_height (GtkWidget *widget,
569 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
571 gint *minimum_height,
572 gint *natural_height);
573 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
576 gint *natural_width);
577 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
578 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
579 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
580 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
581 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
582 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
583 cairo_region_t *region);
584 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
585 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
586 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
589 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
590 gboolean has_tooltip,
592 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
593 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
595 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
596 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
598 const gchar *childname);
599 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
602 const GValue *value);
603 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
606 const gchar *tagname,
607 GMarkupParser *parser,
609 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
612 const gchar *tagname,
614 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
615 GtkBuilder *builder);
617 static void gtk_widget_real_get_width (GtkWidget *widget,
620 static void gtk_widget_real_get_height (GtkWidget *widget,
624 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
627 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
628 GtkOrientation orientation,
631 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
632 GtkOrientation orientation,
635 gint *allocated_size);
637 static void gtk_widget_set_usize_internal (GtkWidget *widget,
640 GtkQueueResizeFlags flags);
642 static void gtk_widget_add_events_internal (GtkWidget *widget,
646 /* --- variables --- */
647 static gpointer gtk_widget_parent_class = NULL;
648 static guint widget_signals[LAST_SIGNAL] = { 0 };
649 static GtkStyle *gtk_default_style = NULL;
650 static guint composite_child_stack = 0;
651 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
652 static GParamSpecPool *style_property_spec_pool = NULL;
654 static GQuark quark_property_parser = 0;
655 static GQuark quark_aux_info = 0;
656 static GQuark quark_accel_path = 0;
657 static GQuark quark_accel_closures = 0;
658 static GQuark quark_event_mask = 0;
659 static GQuark quark_device_event_mask = 0;
660 static GQuark quark_extension_event_mode = 0;
661 static GQuark quark_parent_window = 0;
662 static GQuark quark_pointer_window = 0;
663 static GQuark quark_shape_info = 0;
664 static GQuark quark_input_shape_info = 0;
665 static GQuark quark_pango_context = 0;
666 static GQuark quark_rc_style = 0;
667 static GQuark quark_accessible_object = 0;
668 static GQuark quark_mnemonic_labels = 0;
669 static GQuark quark_tooltip_markup = 0;
670 static GQuark quark_has_tooltip = 0;
671 static GQuark quark_tooltip_window = 0;
672 static GQuark quark_visual = 0;
673 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
674 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
676 /* --- functions --- */
678 gtk_widget_get_type (void)
680 static GType widget_type = 0;
682 if (G_UNLIKELY (widget_type == 0))
684 const GTypeInfo widget_info =
686 sizeof (GtkWidgetClass),
687 NULL, /* base_init */
688 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
689 (GClassInitFunc) gtk_widget_class_init,
690 NULL, /* class_finalize */
691 NULL, /* class_init */
694 (GInstanceInitFunc) gtk_widget_init,
695 NULL, /* value_table */
698 const GInterfaceInfo accessibility_info =
700 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
701 (GInterfaceFinalizeFunc) NULL,
702 NULL /* interface data */
705 const GInterfaceInfo buildable_info =
707 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
708 (GInterfaceFinalizeFunc) NULL,
709 NULL /* interface data */
712 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
713 &widget_info, G_TYPE_FLAG_ABSTRACT);
715 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
716 &accessibility_info) ;
717 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
725 child_property_notify_dispatcher (GObject *object,
729 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
732 /* We guard against the draw signal callbacks modifying the state of the
733 * cairo context by surounding it with save/restore.
734 * Maybe we should also cairo_new_path() just to be sure?
737 gtk_widget_draw_marshaller (GClosure *closure,
738 GValue *return_value,
739 guint n_param_values,
740 const GValue *param_values,
741 gpointer invocation_hint,
742 gpointer marshal_data)
744 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
748 _gtk_marshal_BOOLEAN__BOXED (closure,
759 gtk_widget_class_init (GtkWidgetClass *klass)
761 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
762 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
763 GtkBindingSet *binding_set;
765 gtk_widget_parent_class = g_type_class_peek_parent (klass);
767 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
768 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
769 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
770 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
771 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
772 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
773 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
774 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
775 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
776 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
777 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
778 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
779 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
780 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
781 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
782 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
783 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
784 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
785 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
787 style_property_spec_pool = g_param_spec_pool_new (FALSE);
788 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
789 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
790 cpn_context.dispatcher = child_property_notify_dispatcher;
791 _gtk_widget_child_property_notify_context = &cpn_context;
793 gobject_class->dispose = gtk_widget_dispose;
794 gobject_class->finalize = gtk_widget_finalize;
795 gobject_class->set_property = gtk_widget_set_property;
796 gobject_class->get_property = gtk_widget_get_property;
798 klass->destroy = gtk_widget_real_destroy;
800 klass->activate_signal = 0;
801 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
802 klass->show = gtk_widget_real_show;
803 klass->show_all = gtk_widget_show;
804 klass->hide = gtk_widget_real_hide;
805 klass->map = gtk_widget_real_map;
806 klass->unmap = gtk_widget_real_unmap;
807 klass->realize = gtk_widget_real_realize;
808 klass->unrealize = gtk_widget_real_unrealize;
809 klass->size_allocate = gtk_widget_real_size_allocate;
810 klass->get_preferred_width = gtk_widget_real_get_width;
811 klass->get_preferred_height = gtk_widget_real_get_height;
812 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
813 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
814 klass->state_changed = NULL;
815 klass->parent_set = NULL;
816 klass->hierarchy_changed = NULL;
817 klass->style_set = gtk_widget_real_style_set;
818 klass->direction_changed = gtk_widget_real_direction_changed;
819 klass->grab_notify = NULL;
820 klass->child_notify = NULL;
822 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
823 klass->grab_focus = gtk_widget_real_grab_focus;
824 klass->focus = gtk_widget_real_focus;
825 klass->move_focus = gtk_widget_real_move_focus;
826 klass->keynav_failed = gtk_widget_real_keynav_failed;
828 klass->button_press_event = NULL;
829 klass->button_release_event = NULL;
830 klass->motion_notify_event = NULL;
831 klass->delete_event = NULL;
832 klass->destroy_event = NULL;
833 klass->key_press_event = gtk_widget_real_key_press_event;
834 klass->key_release_event = gtk_widget_real_key_release_event;
835 klass->enter_notify_event = NULL;
836 klass->leave_notify_event = NULL;
837 klass->configure_event = NULL;
838 klass->focus_in_event = gtk_widget_real_focus_in_event;
839 klass->focus_out_event = gtk_widget_real_focus_out_event;
840 klass->map_event = NULL;
841 klass->unmap_event = NULL;
842 klass->window_state_event = NULL;
843 klass->property_notify_event = _gtk_selection_property_notify;
844 klass->selection_clear_event = _gtk_selection_clear;
845 klass->selection_request_event = _gtk_selection_request;
846 klass->selection_notify_event = _gtk_selection_notify;
847 klass->selection_received = NULL;
848 klass->proximity_in_event = NULL;
849 klass->proximity_out_event = NULL;
850 klass->drag_begin = NULL;
851 klass->drag_end = NULL;
852 klass->drag_data_delete = NULL;
853 klass->drag_leave = NULL;
854 klass->drag_motion = NULL;
855 klass->drag_drop = NULL;
856 klass->drag_data_received = NULL;
857 klass->screen_changed = NULL;
858 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
859 klass->grab_broken_event = NULL;
860 klass->query_tooltip = gtk_widget_real_query_tooltip;
862 klass->show_help = gtk_widget_real_show_help;
864 /* Accessibility support */
865 klass->get_accessible = gtk_widget_real_get_accessible;
867 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
868 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
870 g_object_class_install_property (gobject_class,
872 g_param_spec_string ("name",
874 P_("The name of the widget"),
876 GTK_PARAM_READWRITE));
877 g_object_class_install_property (gobject_class,
879 g_param_spec_object ("parent",
881 P_("The parent widget of this widget. Must be a Container widget"),
883 GTK_PARAM_READWRITE));
885 g_object_class_install_property (gobject_class,
887 g_param_spec_int ("width-request",
889 P_("Override for width request of the widget, or -1 if natural request should be used"),
893 GTK_PARAM_READWRITE));
894 g_object_class_install_property (gobject_class,
896 g_param_spec_int ("height-request",
897 P_("Height request"),
898 P_("Override for height request of the widget, or -1 if natural request should be used"),
902 GTK_PARAM_READWRITE));
903 g_object_class_install_property (gobject_class,
905 g_param_spec_boolean ("visible",
907 P_("Whether the widget is visible"),
909 GTK_PARAM_READWRITE));
910 g_object_class_install_property (gobject_class,
912 g_param_spec_boolean ("sensitive",
914 P_("Whether the widget responds to input"),
916 GTK_PARAM_READWRITE));
917 g_object_class_install_property (gobject_class,
919 g_param_spec_boolean ("app-paintable",
920 P_("Application paintable"),
921 P_("Whether the application will paint directly on the widget"),
923 GTK_PARAM_READWRITE));
924 g_object_class_install_property (gobject_class,
926 g_param_spec_boolean ("can-focus",
928 P_("Whether the widget can accept the input focus"),
930 GTK_PARAM_READWRITE));
931 g_object_class_install_property (gobject_class,
933 g_param_spec_boolean ("has-focus",
935 P_("Whether the widget has the input focus"),
937 GTK_PARAM_READWRITE));
938 g_object_class_install_property (gobject_class,
940 g_param_spec_boolean ("is-focus",
942 P_("Whether the widget is the focus widget within the toplevel"),
944 GTK_PARAM_READWRITE));
945 g_object_class_install_property (gobject_class,
947 g_param_spec_boolean ("can-default",
949 P_("Whether the widget can be the default widget"),
951 GTK_PARAM_READWRITE));
952 g_object_class_install_property (gobject_class,
954 g_param_spec_boolean ("has-default",
956 P_("Whether the widget is the default widget"),
958 GTK_PARAM_READWRITE));
959 g_object_class_install_property (gobject_class,
960 PROP_RECEIVES_DEFAULT,
961 g_param_spec_boolean ("receives-default",
962 P_("Receives default"),
963 P_("If TRUE, the widget will receive the default action when it is focused"),
965 GTK_PARAM_READWRITE));
966 g_object_class_install_property (gobject_class,
967 PROP_COMPOSITE_CHILD,
968 g_param_spec_boolean ("composite-child",
969 P_("Composite child"),
970 P_("Whether the widget is part of a composite widget"),
972 GTK_PARAM_READABLE));
973 g_object_class_install_property (gobject_class,
975 g_param_spec_object ("style",
977 P_("The style of the widget, which contains information about how it will look (colors etc)"),
979 GTK_PARAM_READWRITE));
980 g_object_class_install_property (gobject_class,
982 g_param_spec_flags ("events",
984 P_("The event mask that decides what kind of GdkEvents this widget gets"),
987 GTK_PARAM_READWRITE));
988 g_object_class_install_property (gobject_class,
989 PROP_EXTENSION_EVENTS,
990 g_param_spec_enum ("extension-events",
991 P_("Extension events"),
992 P_("The mask that decides what kind of extension events this widget gets"),
993 GDK_TYPE_EXTENSION_MODE,
994 GDK_EXTENSION_EVENTS_NONE,
995 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_boolean ("no-show-all",
1000 P_("Whether gtk_widget_show_all() should not affect this widget"),
1002 GTK_PARAM_READWRITE));
1005 * GtkWidget:has-tooltip:
1007 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1008 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1009 * the widget will be queried using #GtkWidget::query-tooltip to determine
1010 * whether it will provide a tooltip or not.
1012 * Note that setting this property to %TRUE for the first time will change
1013 * the event masks of the GdkWindows of this widget to include leave-notify
1014 * and motion-notify events. This cannot and will not be undone when the
1015 * property is set to %FALSE again.
1019 g_object_class_install_property (gobject_class,
1021 g_param_spec_boolean ("has-tooltip",
1023 P_("Whether this widget has a tooltip"),
1025 GTK_PARAM_READWRITE));
1027 * GtkWidget:tooltip-text:
1029 * Sets the text of tooltip to be the given string.
1031 * Also see gtk_tooltip_set_text().
1033 * This is a convenience property which will take care of getting the
1034 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1035 * will automatically be set to %TRUE and there will be taken care of
1036 * #GtkWidget::query-tooltip in the default signal handler.
1040 g_object_class_install_property (gobject_class,
1042 g_param_spec_string ("tooltip-text",
1044 P_("The contents of the tooltip for this widget"),
1046 GTK_PARAM_READWRITE));
1048 * GtkWidget:tooltip-markup:
1050 * Sets the text of tooltip to be the given string, which is marked up
1051 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1052 * Also see gtk_tooltip_set_markup().
1054 * This is a convenience property which will take care of getting the
1055 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1056 * will automatically be set to %TRUE and there will be taken care of
1057 * #GtkWidget::query-tooltip in the default signal handler.
1061 g_object_class_install_property (gobject_class,
1062 PROP_TOOLTIP_MARKUP,
1063 g_param_spec_string ("tooltip-markup",
1064 P_("Tooltip markup"),
1065 P_("The contents of the tooltip for this widget"),
1067 GTK_PARAM_READWRITE));
1072 * The widget's window if it is realized, %NULL otherwise.
1076 g_object_class_install_property (gobject_class,
1078 g_param_spec_object ("window",
1080 P_("The widget's window if it is realized"),
1082 GTK_PARAM_READABLE));
1085 * GtkWidget:double-buffered
1087 * Whether the widget is double buffered.
1091 g_object_class_install_property (gobject_class,
1092 PROP_DOUBLE_BUFFERED,
1093 g_param_spec_boolean ("double-buffered",
1094 P_("Double Buffered"),
1095 P_("Whether the widget is double buffered"),
1097 GTK_PARAM_READWRITE));
1102 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1106 g_object_class_install_property (gobject_class,
1108 g_param_spec_enum ("halign",
1109 P_("Horizontal Alignment"),
1110 P_("How to position in extra horizontal space"),
1113 GTK_PARAM_READWRITE));
1118 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1122 g_object_class_install_property (gobject_class,
1124 g_param_spec_enum ("valign",
1125 P_("Vertical Alignment"),
1126 P_("How to position in extra vertical space"),
1129 GTK_PARAM_READWRITE));
1132 * GtkWidget:margin-left
1134 * Margin on left side of widget.
1136 * This property adds margin outside of the widget's normal size
1137 * request, the margin will be added in addition to the size from
1138 * gtk_widget_set_size_request() for example.
1142 g_object_class_install_property (gobject_class,
1144 g_param_spec_int ("margin-left",
1145 P_("Margin on Left"),
1146 P_("Pixels of extra space on the left side"),
1150 GTK_PARAM_READWRITE));
1153 * GtkWidget:margin-right
1155 * Margin on right side of widget.
1157 * This property adds margin outside of the widget's normal size
1158 * request, the margin will be added in addition to the size from
1159 * gtk_widget_set_size_request() for example.
1163 g_object_class_install_property (gobject_class,
1165 g_param_spec_int ("margin-right",
1166 P_("Margin on Right"),
1167 P_("Pixels of extra space on the right side"),
1171 GTK_PARAM_READWRITE));
1174 * GtkWidget:margin-top
1176 * Margin on top side of widget.
1178 * This property adds margin outside of the widget's normal size
1179 * request, the margin will be added in addition to the size from
1180 * gtk_widget_set_size_request() for example.
1184 g_object_class_install_property (gobject_class,
1186 g_param_spec_int ("margin-top",
1187 P_("Margin on Top"),
1188 P_("Pixels of extra space on the top side"),
1192 GTK_PARAM_READWRITE));
1195 * GtkWidget:margin-bottom
1197 * Margin on bottom side of widget.
1199 * This property adds margin outside of the widget's normal size
1200 * request, the margin will be added in addition to the size from
1201 * gtk_widget_set_size_request() for example.
1205 g_object_class_install_property (gobject_class,
1207 g_param_spec_int ("margin-bottom",
1208 P_("Margin on Bottom"),
1209 P_("Pixels of extra space on the bottom side"),
1213 GTK_PARAM_READWRITE));
1218 * Sets all four sides' margin at once. If read, returns max
1219 * margin on any side.
1223 g_object_class_install_property (gobject_class,
1225 g_param_spec_int ("margin",
1227 P_("Pixels of extra space on all four sides"),
1231 GTK_PARAM_READWRITE));
1234 * GtkWidget::destroy:
1235 * @object: the object which received the signal
1237 * Signals that all holders of a reference to the widget should release
1238 * the reference that they hold. May result in finalization of the widget
1239 * if all references are released.
1241 widget_signals[DESTROY] =
1242 g_signal_new (I_("destroy"),
1243 G_TYPE_FROM_CLASS (gobject_class),
1244 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1245 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1247 _gtk_marshal_VOID__VOID,
1253 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1257 g_object_class_install_property (gobject_class,
1259 g_param_spec_boolean ("hexpand",
1260 P_("Horizontal Expand"),
1261 P_("Whether widget wants more horizontal space"),
1263 GTK_PARAM_READWRITE));
1266 * GtkWidget:hexpand-set
1268 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1272 g_object_class_install_property (gobject_class,
1274 g_param_spec_boolean ("hexpand-set",
1275 P_("Horizontal Expand Set"),
1276 P_("Whether to use the hexpand property"),
1278 GTK_PARAM_READWRITE));
1283 * Whether to expand vertically. See gtk_widget_set_vexpand().
1287 g_object_class_install_property (gobject_class,
1289 g_param_spec_boolean ("vexpand",
1290 P_("Vertical Expand"),
1291 P_("Whether widget wants more vertical space"),
1293 GTK_PARAM_READWRITE));
1296 * GtkWidget:vexpand-set
1298 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_boolean ("vexpand-set",
1305 P_("Vertical Expand Set"),
1306 P_("Whether to use the vexpand property"),
1308 GTK_PARAM_READWRITE));
1313 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1317 g_object_class_install_property (gobject_class,
1319 g_param_spec_boolean ("expand",
1321 P_("Whether widget wants to expand in both directions"),
1323 GTK_PARAM_READWRITE));
1327 * @widget: the object which received the signal.
1329 widget_signals[SHOW] =
1330 g_signal_new (I_("show"),
1331 G_TYPE_FROM_CLASS (gobject_class),
1333 G_STRUCT_OFFSET (GtkWidgetClass, show),
1335 _gtk_marshal_VOID__VOID,
1340 * @widget: the object which received the signal.
1342 widget_signals[HIDE] =
1343 g_signal_new (I_("hide"),
1344 G_TYPE_FROM_CLASS (gobject_class),
1346 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1348 _gtk_marshal_VOID__VOID,
1353 * @widget: the object which received the signal.
1355 widget_signals[MAP] =
1356 g_signal_new (I_("map"),
1357 G_TYPE_FROM_CLASS (gobject_class),
1359 G_STRUCT_OFFSET (GtkWidgetClass, map),
1361 _gtk_marshal_VOID__VOID,
1366 * @widget: the object which received the signal.
1368 widget_signals[UNMAP] =
1369 g_signal_new (I_("unmap"),
1370 G_TYPE_FROM_CLASS (gobject_class),
1372 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1374 _gtk_marshal_VOID__VOID,
1378 * GtkWidget::realize:
1379 * @widget: the object which received the signal.
1381 widget_signals[REALIZE] =
1382 g_signal_new (I_("realize"),
1383 G_TYPE_FROM_CLASS (gobject_class),
1385 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1387 _gtk_marshal_VOID__VOID,
1391 * GtkWidget::unrealize:
1392 * @widget: the object which received the signal.
1394 widget_signals[UNREALIZE] =
1395 g_signal_new (I_("unrealize"),
1396 G_TYPE_FROM_CLASS (gobject_class),
1398 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1400 _gtk_marshal_VOID__VOID,
1404 * GtkWidget::size-allocate:
1405 * @widget: the object which received the signal.
1408 widget_signals[SIZE_ALLOCATE] =
1409 g_signal_new (I_("size-allocate"),
1410 G_TYPE_FROM_CLASS (gobject_class),
1412 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1414 _gtk_marshal_VOID__BOXED,
1416 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1419 * GtkWidget::state-changed:
1420 * @widget: the object which received the signal.
1421 * @state: the previous state
1423 * The ::state-changed signal is emitted when the widget state changes.
1424 * See gtk_widget_get_state().
1426 widget_signals[STATE_CHANGED] =
1427 g_signal_new (I_("state-changed"),
1428 G_TYPE_FROM_CLASS (gobject_class),
1430 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1432 _gtk_marshal_VOID__ENUM,
1434 GTK_TYPE_STATE_TYPE);
1437 * GtkWidget::parent-set:
1438 * @widget: the object on which the signal is emitted
1439 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1440 * just got its initial parent.
1442 * The ::parent-set signal is emitted when a new parent
1443 * has been set on a widget.
1445 widget_signals[PARENT_SET] =
1446 g_signal_new (I_("parent-set"),
1447 G_TYPE_FROM_CLASS (gobject_class),
1449 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1451 _gtk_marshal_VOID__OBJECT,
1456 * GtkWidget::hierarchy-changed:
1457 * @widget: the object on which the signal is emitted
1458 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1459 * if the widget was previously unanchored
1461 * The ::hierarchy-changed signal is emitted when the
1462 * anchored state of a widget changes. A widget is
1463 * <firstterm>anchored</firstterm> when its toplevel
1464 * ancestor is a #GtkWindow. This signal is emitted when
1465 * a widget changes from un-anchored to anchored or vice-versa.
1467 widget_signals[HIERARCHY_CHANGED] =
1468 g_signal_new (I_("hierarchy-changed"),
1469 G_TYPE_FROM_CLASS (gobject_class),
1471 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1473 _gtk_marshal_VOID__OBJECT,
1478 * GtkWidget::style-set:
1479 * @widget: the object on which the signal is emitted
1480 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1481 * just got its initial style
1483 * The ::style-set signal is emitted when a new style has been set
1484 * on a widget. Note that style-modifying functions like
1485 * gtk_widget_modify_base() also cause this signal to be emitted.
1487 widget_signals[STYLE_SET] =
1488 g_signal_new (I_("style-set"),
1489 G_TYPE_FROM_CLASS (gobject_class),
1491 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1493 _gtk_marshal_VOID__OBJECT,
1498 * GtkWidget::direction-changed:
1499 * @widget: the object on which the signal is emitted
1500 * @previous_direction: the previous text direction of @widget
1502 * The ::direction-changed signal is emitted when the text direction
1503 * of a widget changes.
1505 widget_signals[DIRECTION_CHANGED] =
1506 g_signal_new (I_("direction-changed"),
1507 G_TYPE_FROM_CLASS (gobject_class),
1509 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1511 _gtk_marshal_VOID__ENUM,
1513 GTK_TYPE_TEXT_DIRECTION);
1516 * GtkWidget::grab-notify:
1517 * @widget: the object which received the signal
1518 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1519 * if it becomes unshadowed
1521 * The ::grab-notify signal is emitted when a widget becomes
1522 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1523 * another widget, or when it becomes unshadowed due to a grab
1526 * A widget is shadowed by a gtk_grab_add() when the topmost
1527 * grab widget in the grab stack of its window group is not
1530 widget_signals[GRAB_NOTIFY] =
1531 g_signal_new (I_("grab-notify"),
1532 G_TYPE_FROM_CLASS (gobject_class),
1534 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1536 _gtk_marshal_VOID__BOOLEAN,
1541 * GtkWidget::child-notify:
1542 * @widget: the object which received the signal
1543 * @pspec: the #GParamSpec of the changed child property
1545 * The ::child-notify signal is emitted for each
1546 * <link linkend="child-properties">child property</link> that has
1547 * changed on an object. The signal's detail holds the property name.
1549 widget_signals[CHILD_NOTIFY] =
1550 g_signal_new (I_("child-notify"),
1551 G_TYPE_FROM_CLASS (gobject_class),
1552 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1553 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1555 g_cclosure_marshal_VOID__PARAM,
1561 * @widget: the object which received the signal
1562 * @cr: the cairo context to draw to
1564 * This signal is emitted when a widget is supposed to render itself.
1565 * The @widget's top left corner must be painted at the origin of
1566 * the passed in context and be sized to the values returned by
1567 * gtk_widget_get_allocated_width() and
1568 * gtk_widget_get_allocated_height().
1570 * Signal handlers connected to this signal can modify the cairo
1571 * context passed as @cr in any way they like and don't need to
1572 * restore it. The signal emission takes care of calling cairo_save()
1573 * before and cairo_restore() after invoking the handler.
1575 widget_signals[DRAW] =
1576 g_signal_new (I_("draw"),
1577 G_TYPE_FROM_CLASS (gobject_class),
1579 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1580 _gtk_boolean_handled_accumulator, NULL,
1581 gtk_widget_draw_marshaller,
1583 CAIRO_GOBJECT_TYPE_CONTEXT);
1586 * GtkWidget::mnemonic-activate:
1587 * @widget: the object which received the signal.
1590 widget_signals[MNEMONIC_ACTIVATE] =
1591 g_signal_new (I_("mnemonic-activate"),
1592 G_TYPE_FROM_CLASS (gobject_class),
1594 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1595 _gtk_boolean_handled_accumulator, NULL,
1596 _gtk_marshal_BOOLEAN__BOOLEAN,
1601 * GtkWidget::grab-focus:
1602 * @widget: the object which received the signal.
1604 widget_signals[GRAB_FOCUS] =
1605 g_signal_new (I_("grab-focus"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1607 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1608 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1610 _gtk_marshal_VOID__VOID,
1615 * @widget: the object which received the signal.
1618 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1620 widget_signals[FOCUS] =
1621 g_signal_new (I_("focus"),
1622 G_TYPE_FROM_CLASS (klass),
1624 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1625 _gtk_boolean_handled_accumulator, NULL,
1626 _gtk_marshal_BOOLEAN__ENUM,
1628 GTK_TYPE_DIRECTION_TYPE);
1631 * GtkWidget::move-focus:
1632 * @widget: the object which received the signal.
1635 widget_signals[MOVE_FOCUS] =
1636 g_signal_new (I_("move-focus"),
1637 G_TYPE_FROM_CLASS (klass),
1638 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1639 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1641 _gtk_marshal_VOID__ENUM,
1644 GTK_TYPE_DIRECTION_TYPE);
1647 * GtkWidget::keynav-failed:
1648 * @widget: the object which received the signal
1649 * @direction: the direction of movement
1651 * Gets emitted if keyboard navigation fails.
1652 * See gtk_widget_keynav_failed() for details.
1654 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1655 * if the emitting widget should try to handle the keyboard
1656 * navigation attempt in its parent container(s).
1660 widget_signals[KEYNAV_FAILED] =
1661 g_signal_new (I_("keynav-failed"),
1662 G_TYPE_FROM_CLASS (klass),
1664 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1665 _gtk_boolean_handled_accumulator, NULL,
1666 _gtk_marshal_BOOLEAN__ENUM,
1668 GTK_TYPE_DIRECTION_TYPE);
1672 * @widget: the object which received the signal.
1673 * @event: the #GdkEvent which triggered this signal
1675 * The GTK+ main loop will emit three signals for each GDK event delivered
1676 * to a widget: one generic ::event signal, another, more specific,
1677 * signal that matches the type of event delivered (e.g.
1678 * #GtkWidget::key-press-event) and finally a generic
1679 * #GtkWidget::event-after signal.
1681 * Returns: %TRUE to stop other handlers from being invoked for the event
1682 * and to cancel the emission of the second specific ::event signal.
1683 * %FALSE to propagate the event further and to allow the emission of
1684 * the second signal. The ::event-after signal is emitted regardless of
1687 widget_signals[EVENT] =
1688 g_signal_new (I_("event"),
1689 G_TYPE_FROM_CLASS (klass),
1691 G_STRUCT_OFFSET (GtkWidgetClass, event),
1692 _gtk_boolean_handled_accumulator, NULL,
1693 _gtk_marshal_BOOLEAN__BOXED,
1695 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1698 * GtkWidget::event-after:
1699 * @widget: the object which received the signal.
1700 * @event: the #GdkEvent which triggered this signal
1702 * After the emission of the #GtkWidget::event signal and (optionally)
1703 * the second more specific signal, ::event-after will be emitted
1704 * regardless of the previous two signals handlers return values.
1707 widget_signals[EVENT_AFTER] =
1708 g_signal_new (I_("event-after"),
1709 G_TYPE_FROM_CLASS (klass),
1713 _gtk_marshal_VOID__BOXED,
1715 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1718 * GtkWidget::button-press-event:
1719 * @widget: the object which received the signal.
1720 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1723 * The ::button-press-event signal will be emitted when a button
1724 * (typically from a mouse) is pressed.
1726 * To receive this signal, the #GdkWindow associated to the
1727 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1729 * This signal will be sent to the grab widget if there is one.
1731 * Returns: %TRUE to stop other handlers from being invoked for the event.
1732 * %FALSE to propagate the event further.
1734 widget_signals[BUTTON_PRESS_EVENT] =
1735 g_signal_new (I_("button-press-event"),
1736 G_TYPE_FROM_CLASS (klass),
1738 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1739 _gtk_boolean_handled_accumulator, NULL,
1740 _gtk_marshal_BOOLEAN__BOXED,
1742 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1745 * GtkWidget::button-release-event:
1746 * @widget: the object which received the signal.
1747 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1750 * The ::button-release-event signal will be emitted when a button
1751 * (typically from a mouse) is released.
1753 * To receive this signal, the #GdkWindow associated to the
1754 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1756 * This signal will be sent to the grab widget if there is one.
1758 * Returns: %TRUE to stop other handlers from being invoked for the event.
1759 * %FALSE to propagate the event further.
1761 widget_signals[BUTTON_RELEASE_EVENT] =
1762 g_signal_new (I_("button-release-event"),
1763 G_TYPE_FROM_CLASS (klass),
1765 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1766 _gtk_boolean_handled_accumulator, NULL,
1767 _gtk_marshal_BOOLEAN__BOXED,
1769 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1772 * GtkWidget::scroll-event:
1773 * @widget: the object which received the signal.
1774 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1777 * The ::scroll-event signal is emitted when a button in the 4 to 7
1778 * range is pressed. Wheel mice are usually configured to generate
1779 * button press events for buttons 4 and 5 when the wheel is turned.
1781 * To receive this signal, the #GdkWindow associated to the widget needs
1782 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1784 * This signal will be sent to the grab widget if there is one.
1786 * Returns: %TRUE to stop other handlers from being invoked for the event.
1787 * %FALSE to propagate the event further.
1789 widget_signals[SCROLL_EVENT] =
1790 g_signal_new (I_("scroll-event"),
1791 G_TYPE_FROM_CLASS (klass),
1793 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1794 _gtk_boolean_handled_accumulator, NULL,
1795 _gtk_marshal_BOOLEAN__BOXED,
1797 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1800 * GtkWidget::motion-notify-event:
1801 * @widget: the object which received the signal.
1802 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1805 * The ::motion-notify-event signal is emitted when the pointer moves
1806 * over the widget's #GdkWindow.
1808 * To receive this signal, the #GdkWindow associated to the widget
1809 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1811 * This signal will be sent to the grab widget if there is one.
1813 * Returns: %TRUE to stop other handlers from being invoked for the event.
1814 * %FALSE to propagate the event further.
1816 widget_signals[MOTION_NOTIFY_EVENT] =
1817 g_signal_new (I_("motion-notify-event"),
1818 G_TYPE_FROM_CLASS (klass),
1820 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1821 _gtk_boolean_handled_accumulator, NULL,
1822 _gtk_marshal_BOOLEAN__BOXED,
1824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1827 * GtkWidget::composited-changed:
1828 * @widget: the object on which the signal is emitted
1830 * The ::composited-changed signal is emitted when the composited
1831 * status of @widget<!-- -->s screen changes.
1832 * See gdk_screen_is_composited().
1834 widget_signals[COMPOSITED_CHANGED] =
1835 g_signal_new (I_("composited-changed"),
1836 G_TYPE_FROM_CLASS (klass),
1837 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1838 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1840 _gtk_marshal_VOID__VOID,
1844 * GtkWidget::delete-event:
1845 * @widget: the object which received the signal
1846 * @event: the event which triggered this signal
1848 * The ::delete-event signal is emitted if a user requests that
1849 * a toplevel window is closed. The default handler for this signal
1850 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1851 * this signal will cause the window to be hidden instead, so that
1852 * it can later be shown again without reconstructing it.
1854 * Returns: %TRUE to stop other handlers from being invoked for the event.
1855 * %FALSE to propagate the event further.
1857 widget_signals[DELETE_EVENT] =
1858 g_signal_new (I_("delete-event"),
1859 G_TYPE_FROM_CLASS (klass),
1861 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1862 _gtk_boolean_handled_accumulator, NULL,
1863 _gtk_marshal_BOOLEAN__BOXED,
1865 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1868 * GtkWidget::destroy-event:
1869 * @widget: the object which received the signal.
1870 * @event: the event which triggered this signal
1872 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1873 * You rarely get this signal, because most widgets disconnect themselves
1874 * from their window before they destroy it, so no widget owns the
1875 * window at destroy time.
1877 * To receive this signal, the #GdkWindow associated to the widget needs
1878 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1879 * automatically for all new windows.
1881 * Returns: %TRUE to stop other handlers from being invoked for the event.
1882 * %FALSE to propagate the event further.
1884 widget_signals[DESTROY_EVENT] =
1885 g_signal_new (I_("destroy-event"),
1886 G_TYPE_FROM_CLASS (klass),
1888 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1889 _gtk_boolean_handled_accumulator, NULL,
1890 _gtk_marshal_BOOLEAN__BOXED,
1892 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1895 * GtkWidget::key-press-event:
1896 * @widget: the object which received the signal
1897 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1899 * The ::key-press-event signal is emitted when a key is pressed.
1901 * To receive this signal, the #GdkWindow associated to the widget needs
1902 * to enable the #GDK_KEY_PRESS_MASK mask.
1904 * This signal will be sent to the grab widget if there is one.
1906 * Returns: %TRUE to stop other handlers from being invoked for the event.
1907 * %FALSE to propagate the event further.
1909 widget_signals[KEY_PRESS_EVENT] =
1910 g_signal_new (I_("key-press-event"),
1911 G_TYPE_FROM_CLASS (klass),
1913 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1914 _gtk_boolean_handled_accumulator, NULL,
1915 _gtk_marshal_BOOLEAN__BOXED,
1917 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1920 * GtkWidget::key-release-event:
1921 * @widget: the object which received the signal
1922 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1924 * The ::key-release-event signal is emitted when a key is pressed.
1926 * To receive this signal, the #GdkWindow associated to the widget needs
1927 * to enable the #GDK_KEY_RELEASE_MASK mask.
1929 * This signal will be sent to the grab widget if there is one.
1931 * Returns: %TRUE to stop other handlers from being invoked for the event.
1932 * %FALSE to propagate the event further.
1934 widget_signals[KEY_RELEASE_EVENT] =
1935 g_signal_new (I_("key-release-event"),
1936 G_TYPE_FROM_CLASS (klass),
1938 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1939 _gtk_boolean_handled_accumulator, NULL,
1940 _gtk_marshal_BOOLEAN__BOXED,
1942 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1945 * GtkWidget::enter-notify-event:
1946 * @widget: the object which received the signal
1947 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1950 * The ::enter-notify-event will be emitted when the pointer enters
1951 * the @widget's window.
1953 * To receive this signal, the #GdkWindow associated to the widget needs
1954 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1956 * This signal will be sent to the grab widget if there is one.
1958 * Returns: %TRUE to stop other handlers from being invoked for the event.
1959 * %FALSE to propagate the event further.
1961 widget_signals[ENTER_NOTIFY_EVENT] =
1962 g_signal_new (I_("enter-notify-event"),
1963 G_TYPE_FROM_CLASS (klass),
1965 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1966 _gtk_boolean_handled_accumulator, NULL,
1967 _gtk_marshal_BOOLEAN__BOXED,
1969 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1972 * GtkWidget::leave-notify-event:
1973 * @widget: the object which received the signal
1974 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1977 * The ::leave-notify-event will be emitted when the pointer leaves
1978 * the @widget's window.
1980 * To receive this signal, the #GdkWindow associated to the widget needs
1981 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1983 * This signal will be sent to the grab widget if there is one.
1985 * Returns: %TRUE to stop other handlers from being invoked for the event.
1986 * %FALSE to propagate the event further.
1988 widget_signals[LEAVE_NOTIFY_EVENT] =
1989 g_signal_new (I_("leave-notify-event"),
1990 G_TYPE_FROM_CLASS (klass),
1992 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1993 _gtk_boolean_handled_accumulator, NULL,
1994 _gtk_marshal_BOOLEAN__BOXED,
1996 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1999 * GtkWidget::configure-event:
2000 * @widget: the object which received the signal
2001 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2004 * The ::configure-event signal will be emitted when the size, position or
2005 * stacking of the @widget's window has changed.
2007 * To receive this signal, the #GdkWindow associated to the widget needs
2008 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2009 * automatically for all new windows.
2011 * Returns: %TRUE to stop other handlers from being invoked for the event.
2012 * %FALSE to propagate the event further.
2014 widget_signals[CONFIGURE_EVENT] =
2015 g_signal_new (I_("configure-event"),
2016 G_TYPE_FROM_CLASS (klass),
2018 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2019 _gtk_boolean_handled_accumulator, NULL,
2020 _gtk_marshal_BOOLEAN__BOXED,
2022 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2025 * GtkWidget::focus-in-event:
2026 * @widget: the object which received the signal
2027 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2030 * The ::focus-in-event signal will be emitted when the keyboard focus
2031 * enters the @widget's window.
2033 * To receive this signal, the #GdkWindow associated to the widget needs
2034 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2036 * Returns: %TRUE to stop other handlers from being invoked for the event.
2037 * %FALSE to propagate the event further.
2039 widget_signals[FOCUS_IN_EVENT] =
2040 g_signal_new (I_("focus-in-event"),
2041 G_TYPE_FROM_CLASS (klass),
2043 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2044 _gtk_boolean_handled_accumulator, NULL,
2045 _gtk_marshal_BOOLEAN__BOXED,
2047 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2050 * GtkWidget::focus-out-event:
2051 * @widget: the object which received the signal
2052 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2055 * The ::focus-out-event signal will be emitted when the keyboard focus
2056 * leaves the @widget's window.
2058 * To receive this signal, the #GdkWindow associated to the widget needs
2059 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2061 * Returns: %TRUE to stop other handlers from being invoked for the event.
2062 * %FALSE to propagate the event further.
2064 widget_signals[FOCUS_OUT_EVENT] =
2065 g_signal_new (I_("focus-out-event"),
2066 G_TYPE_FROM_CLASS (klass),
2068 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2069 _gtk_boolean_handled_accumulator, NULL,
2070 _gtk_marshal_BOOLEAN__BOXED,
2072 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2075 * GtkWidget::map-event:
2076 * @widget: the object which received the signal
2077 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2079 * The ::map-event signal will be emitted when the @widget's window is
2080 * mapped. A window is mapped when it becomes visible on the screen.
2082 * To receive this signal, the #GdkWindow associated to the widget needs
2083 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2084 * automatically for all new windows.
2086 * Returns: %TRUE to stop other handlers from being invoked for the event.
2087 * %FALSE to propagate the event further.
2089 widget_signals[MAP_EVENT] =
2090 g_signal_new (I_("map-event"),
2091 G_TYPE_FROM_CLASS (klass),
2093 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2094 _gtk_boolean_handled_accumulator, NULL,
2095 _gtk_marshal_BOOLEAN__BOXED,
2097 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2100 * GtkWidget::unmap-event:
2101 * @widget: the object which received the signal
2102 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2104 * The ::unmap-event signal may be emitted when the @widget's window is
2105 * unmapped. A window is unmapped when it becomes invisible on the screen.
2107 * For performance reasons GTK+ may not emit ::unmap-event, so one
2108 * should always also implement ::unrealize in order to release
2109 * resources and disconnect signal handlers.
2111 * To receive this signal, the #GdkWindow associated to the widget needs
2112 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2113 * automatically for all new windows.
2115 * Returns: %TRUE to stop other handlers from being invoked for the event.
2116 * %FALSE to propagate the event further.
2118 widget_signals[UNMAP_EVENT] =
2119 g_signal_new (I_("unmap-event"),
2120 G_TYPE_FROM_CLASS (klass),
2122 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2123 _gtk_boolean_handled_accumulator, NULL,
2124 _gtk_marshal_BOOLEAN__BOXED,
2126 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2129 * GtkWidget::property-notify-event:
2130 * @widget: the object which received the signal
2131 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2134 * The ::property-notify-event signal will be emitted when a property on
2135 * the @widget's window has been changed or deleted.
2137 * To receive this signal, the #GdkWindow associated to the widget needs
2138 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2140 * Returns: %TRUE to stop other handlers from being invoked for the event.
2141 * %FALSE to propagate the event further.
2143 widget_signals[PROPERTY_NOTIFY_EVENT] =
2144 g_signal_new (I_("property-notify-event"),
2145 G_TYPE_FROM_CLASS (klass),
2147 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2148 _gtk_boolean_handled_accumulator, NULL,
2149 _gtk_marshal_BOOLEAN__BOXED,
2151 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2154 * GtkWidget::selection-clear-event:
2155 * @widget: the object which received the signal
2156 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2159 * The ::selection-clear-event signal will be emitted when the
2160 * the @widget's window has lost ownership of a selection.
2162 * Returns: %TRUE to stop other handlers from being invoked for the event.
2163 * %FALSE to propagate the event further.
2165 widget_signals[SELECTION_CLEAR_EVENT] =
2166 g_signal_new (I_("selection-clear-event"),
2167 G_TYPE_FROM_CLASS (klass),
2169 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2170 _gtk_boolean_handled_accumulator, NULL,
2171 _gtk_marshal_BOOLEAN__BOXED,
2173 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2176 * GtkWidget::selection-request-event:
2177 * @widget: the object which received the signal
2178 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2181 * The ::selection-request-event signal will be emitted when
2182 * another client requests ownership of the selection owned by
2183 * the @widget's window.
2185 * Returns: %TRUE to stop other handlers from being invoked for the event.
2186 * %FALSE to propagate the event further.
2188 widget_signals[SELECTION_REQUEST_EVENT] =
2189 g_signal_new (I_("selection-request-event"),
2190 G_TYPE_FROM_CLASS (klass),
2192 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2199 * GtkWidget::selection-notify-event:
2200 * @widget: the object which received the signal.
2203 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2205 widget_signals[SELECTION_NOTIFY_EVENT] =
2206 g_signal_new (I_("selection-notify-event"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2210 _gtk_boolean_handled_accumulator, NULL,
2211 _gtk_marshal_BOOLEAN__BOXED,
2213 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2216 * GtkWidget::selection-received:
2217 * @widget: the object which received the signal.
2221 widget_signals[SELECTION_RECEIVED] =
2222 g_signal_new (I_("selection-received"),
2223 G_TYPE_FROM_CLASS (klass),
2225 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2227 _gtk_marshal_VOID__BOXED_UINT,
2229 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2233 * GtkWidget::selection-get:
2234 * @widget: the object which received the signal.
2239 widget_signals[SELECTION_GET] =
2240 g_signal_new (I_("selection-get"),
2241 G_TYPE_FROM_CLASS (klass),
2243 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2245 _gtk_marshal_VOID__BOXED_UINT_UINT,
2247 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2252 * GtkWidget::proximity-in-event:
2253 * @widget: the object which received the signal
2254 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2257 * To receive this signal the #GdkWindow associated to the widget needs
2258 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2260 * This signal will be sent to the grab widget if there is one.
2262 * Returns: %TRUE to stop other handlers from being invoked for the event.
2263 * %FALSE to propagate the event further.
2265 widget_signals[PROXIMITY_IN_EVENT] =
2266 g_signal_new (I_("proximity-in-event"),
2267 G_TYPE_FROM_CLASS (klass),
2269 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2270 _gtk_boolean_handled_accumulator, NULL,
2271 _gtk_marshal_BOOLEAN__BOXED,
2273 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2276 * GtkWidget::proximity-out-event:
2277 * @widget: the object which received the signal
2278 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2281 * To receive this signal the #GdkWindow associated to the widget needs
2282 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2284 * This signal will be sent to the grab widget if there is one.
2286 * Returns: %TRUE to stop other handlers from being invoked for the event.
2287 * %FALSE to propagate the event further.
2289 widget_signals[PROXIMITY_OUT_EVENT] =
2290 g_signal_new (I_("proximity-out-event"),
2291 G_TYPE_FROM_CLASS (klass),
2293 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2294 _gtk_boolean_handled_accumulator, NULL,
2295 _gtk_marshal_BOOLEAN__BOXED,
2297 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2300 * GtkWidget::drag-leave:
2301 * @widget: the object which received the signal.
2302 * @drag_context: the drag context
2303 * @time: the timestamp of the motion event
2305 * The ::drag-leave signal is emitted on the drop site when the cursor
2306 * leaves the widget. A typical reason to connect to this signal is to
2307 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2308 * with gtk_drag_unhighlight()
2310 widget_signals[DRAG_LEAVE] =
2311 g_signal_new (I_("drag-leave"),
2312 G_TYPE_FROM_CLASS (klass),
2314 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2316 _gtk_marshal_VOID__OBJECT_UINT,
2318 GDK_TYPE_DRAG_CONTEXT,
2322 * GtkWidget::drag-begin:
2323 * @widget: the object which received the signal
2324 * @drag_context: the drag context
2326 * The ::drag-begin signal is emitted on the drag source when a drag is
2327 * started. A typical reason to connect to this signal is to set up a
2328 * custom drag icon with gtk_drag_source_set_icon().
2330 * Note that some widgets set up a drag icon in the default handler of
2331 * this signal, so you may have to use g_signal_connect_after() to
2332 * override what the default handler did.
2334 widget_signals[DRAG_BEGIN] =
2335 g_signal_new (I_("drag-begin"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2340 _gtk_marshal_VOID__OBJECT,
2342 GDK_TYPE_DRAG_CONTEXT);
2345 * GtkWidget::drag-end:
2346 * @widget: the object which received the signal
2347 * @drag_context: the drag context
2349 * The ::drag-end signal is emitted on the drag source when a drag is
2350 * finished. A typical reason to connect to this signal is to undo
2351 * things done in #GtkWidget::drag-begin.
2353 widget_signals[DRAG_END] =
2354 g_signal_new (I_("drag-end"),
2355 G_TYPE_FROM_CLASS (klass),
2357 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2359 _gtk_marshal_VOID__OBJECT,
2361 GDK_TYPE_DRAG_CONTEXT);
2364 * GtkWidget::drag-data-delete:
2365 * @widget: the object which received the signal
2366 * @drag_context: the drag context
2368 * The ::drag-data-delete signal is emitted on the drag source when a drag
2369 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2370 * handler is responsible for deleting the data that has been dropped. What
2371 * "delete" means depends on the context of the drag operation.
2373 widget_signals[DRAG_DATA_DELETE] =
2374 g_signal_new (I_("drag-data-delete"),
2375 G_TYPE_FROM_CLASS (klass),
2377 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2379 _gtk_marshal_VOID__OBJECT,
2381 GDK_TYPE_DRAG_CONTEXT);
2384 * GtkWidget::drag-failed:
2385 * @widget: the object which received the signal
2386 * @drag_context: the drag context
2387 * @result: the result of the drag operation
2389 * The ::drag-failed signal is emitted on the drag source when a drag has
2390 * failed. The signal handler may hook custom code to handle a failed DND
2391 * operation based on the type of error, it returns %TRUE is the failure has
2392 * been already handled (not showing the default "drag operation failed"
2393 * animation), otherwise it returns %FALSE.
2395 * Return value: %TRUE if the failed drag operation has been already handled.
2399 widget_signals[DRAG_FAILED] =
2400 g_signal_new (I_("drag-failed"),
2401 G_TYPE_FROM_CLASS (klass),
2403 0, _gtk_boolean_handled_accumulator, NULL,
2404 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2406 GDK_TYPE_DRAG_CONTEXT,
2407 GTK_TYPE_DRAG_RESULT);
2410 * GtkWidget::drag-motion:
2411 * @widget: the object which received the signal
2412 * @drag_context: the drag context
2413 * @x: the x coordinate of the current cursor position
2414 * @y: the y coordinate of the current cursor position
2415 * @time: the timestamp of the motion event
2416 * @returns: whether the cursor position is in a drop zone
2418 * The drag-motion signal is emitted on the drop site when the user
2419 * moves the cursor over the widget during a drag. The signal handler
2420 * must determine whether the cursor position is in a drop zone or not.
2421 * If it is not in a drop zone, it returns %FALSE and no further processing
2422 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2423 * handler is responsible for providing the necessary information for
2424 * displaying feedback to the user, by calling gdk_drag_status().
2426 * If the decision whether the drop will be accepted or rejected can't be
2427 * made based solely on the cursor position and the type of the data, the
2428 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2429 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2430 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2431 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2432 * when using the drag-motion signal that way.
2434 * Also note that there is no drag-enter signal. The drag receiver has to
2435 * keep track of whether he has received any drag-motion signals since the
2436 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2437 * an "enter" signal. Upon an "enter", the handler will typically highlight
2438 * the drop site with gtk_drag_highlight().
2441 * drag_motion (GtkWidget *widget,
2442 * GdkDragContext *context,
2449 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2451 * if (!private_data->drag_highlight)
2453 * private_data->drag_highlight = 1;
2454 * gtk_drag_highlight (widget);
2457 * target = gtk_drag_dest_find_target (widget, context, NULL);
2458 * if (target == GDK_NONE)
2459 * gdk_drag_status (context, 0, time);
2462 * private_data->pending_status = context->suggested_action;
2463 * gtk_drag_get_data (widget, context, target, time);
2470 * drag_data_received (GtkWidget *widget,
2471 * GdkDragContext *context,
2474 * GtkSelectionData *selection_data,
2478 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2480 * if (private_data->suggested_action)
2482 * private_data->suggested_action = 0;
2484 * /* We are getting this data due to a request in drag_motion,
2485 * * rather than due to a request in drag_drop, so we are just
2486 * * supposed to call gdk_drag_status (), not actually paste in
2489 * str = gtk_selection_data_get_text (selection_data);
2490 * if (!data_is_acceptable (str))
2491 * gdk_drag_status (context, 0, time);
2493 * gdk_drag_status (context, private_data->suggested_action, time);
2497 * /* accept the drop */
2502 widget_signals[DRAG_MOTION] =
2503 g_signal_new (I_("drag-motion"),
2504 G_TYPE_FROM_CLASS (klass),
2506 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2507 _gtk_boolean_handled_accumulator, NULL,
2508 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2510 GDK_TYPE_DRAG_CONTEXT,
2516 * GtkWidget::drag-drop:
2517 * @widget: the object which received the signal
2518 * @drag_context: the drag context
2519 * @x: the x coordinate of the current cursor position
2520 * @y: the y coordinate of the current cursor position
2521 * @time: the timestamp of the motion event
2522 * @returns: whether the cursor position is in a drop zone
2524 * The ::drag-drop signal is emitted on the drop site when the user drops
2525 * the data onto the widget. The signal handler must determine whether
2526 * the cursor position is in a drop zone or not. If it is not in a drop
2527 * zone, it returns %FALSE and no further processing is necessary.
2528 * Otherwise, the handler returns %TRUE. In this case, the handler must
2529 * ensure that gtk_drag_finish() is called to let the source know that
2530 * the drop is done. The call to gtk_drag_finish() can be done either
2531 * directly or in a #GtkWidget::drag-data-received handler which gets
2532 * triggered by calling gtk_drag_get_data() to receive the data for one
2533 * or more of the supported targets.
2535 widget_signals[DRAG_DROP] =
2536 g_signal_new (I_("drag-drop"),
2537 G_TYPE_FROM_CLASS (klass),
2539 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2540 _gtk_boolean_handled_accumulator, NULL,
2541 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2543 GDK_TYPE_DRAG_CONTEXT,
2549 * GtkWidget::drag-data-get:
2550 * @widget: the object which received the signal
2551 * @drag_context: the drag context
2552 * @data: the #GtkSelectionData to be filled with the dragged data
2553 * @info: the info that has been registered with the target in the
2555 * @time: the timestamp at which the data was requested
2557 * The ::drag-data-get signal is emitted on the drag source when the drop
2558 * site requests the data which is dragged. It is the responsibility of
2559 * the signal handler to fill @data with the data in the format which
2560 * is indicated by @info. See gtk_selection_data_set() and
2561 * gtk_selection_data_set_text().
2563 widget_signals[DRAG_DATA_GET] =
2564 g_signal_new (I_("drag-data-get"),
2565 G_TYPE_FROM_CLASS (klass),
2567 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2569 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2571 GDK_TYPE_DRAG_CONTEXT,
2572 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2577 * GtkWidget::drag-data-received:
2578 * @widget: the object which received the signal
2579 * @drag_context: the drag context
2580 * @x: where the drop happened
2581 * @y: where the drop happened
2582 * @data: the received data
2583 * @info: the info that has been registered with the target in the
2585 * @time: the timestamp at which the data was received
2587 * The ::drag-data-received signal is emitted on the drop site when the
2588 * dragged data has been received. If the data was received in order to
2589 * determine whether the drop will be accepted, the handler is expected
2590 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2591 * If the data was received in response to a #GtkWidget::drag-drop signal
2592 * (and this is the last target to be received), the handler for this
2593 * signal is expected to process the received data and then call
2594 * gtk_drag_finish(), setting the @success parameter depending on whether
2595 * the data was processed successfully.
2597 * The handler may inspect and modify @drag_context->action before calling
2598 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2599 * following example:
2602 * drag_data_received (GtkWidget *widget,
2603 * GdkDragContext *drag_context,
2606 * GtkSelectionData *data,
2610 * if ((data->length >= 0) && (data->format == 8))
2612 * if (drag_context->action == GDK_ACTION_ASK)
2614 * GtkWidget *dialog;
2617 * dialog = gtk_message_dialog_new (NULL,
2618 * GTK_DIALOG_MODAL |
2619 * GTK_DIALOG_DESTROY_WITH_PARENT,
2621 * GTK_BUTTONS_YES_NO,
2622 * "Move the data ?\n");
2623 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2624 * gtk_widget_destroy (dialog);
2626 * if (response == GTK_RESPONSE_YES)
2627 * drag_context->action = GDK_ACTION_MOVE;
2629 * drag_context->action = GDK_ACTION_COPY;
2632 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2636 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2640 widget_signals[DRAG_DATA_RECEIVED] =
2641 g_signal_new (I_("drag-data-received"),
2642 G_TYPE_FROM_CLASS (klass),
2644 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2646 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2648 GDK_TYPE_DRAG_CONTEXT,
2651 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2656 * GtkWidget::visibility-notify-event:
2657 * @widget: the object which received the signal
2658 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2659 * triggered this signal.
2661 * The ::visibility-notify-event will be emitted when the @widget's window
2662 * is obscured or unobscured.
2664 * To receive this signal the #GdkWindow associated to the widget needs
2665 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2667 * Returns: %TRUE to stop other handlers from being invoked for the event.
2668 * %FALSE to propagate the event further.
2670 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2671 g_signal_new (I_("visibility-notify-event"),
2672 G_TYPE_FROM_CLASS (klass),
2674 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2675 _gtk_boolean_handled_accumulator, NULL,
2676 _gtk_marshal_BOOLEAN__BOXED,
2678 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2681 * GtkWidget::client-event:
2682 * @widget: the object which received the signal
2683 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2686 * The ::client-event will be emitted when the @widget's window
2687 * receives a message (via a ClientMessage event) from another
2690 * Returns: %TRUE to stop other handlers from being invoked for
2691 * the event. %FALSE to propagate the event further.
2693 widget_signals[CLIENT_EVENT] =
2694 g_signal_new (I_("client-event"),
2695 G_TYPE_FROM_CLASS (klass),
2697 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2698 _gtk_boolean_handled_accumulator, NULL,
2699 _gtk_marshal_BOOLEAN__BOXED,
2701 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2704 * GtkWidget::window-state-event:
2705 * @widget: the object which received the signal
2706 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2707 * triggered this signal.
2709 * The ::window-state-event will be emitted when the state of the
2710 * toplevel window associated to the @widget changes.
2712 * To receive this signal the #GdkWindow associated to the widget
2713 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2714 * this mask automatically for all new windows.
2716 * Returns: %TRUE to stop other handlers from being invoked for the
2717 * event. %FALSE to propagate the event further.
2719 widget_signals[WINDOW_STATE_EVENT] =
2720 g_signal_new (I_("window-state-event"),
2721 G_TYPE_FROM_CLASS (klass),
2723 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2724 _gtk_boolean_handled_accumulator, NULL,
2725 _gtk_marshal_BOOLEAN__BOXED,
2727 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2730 * GtkWidget::damage-event:
2731 * @widget: the object which received the signal
2732 * @event: the #GdkEventExpose event
2734 * Emitted when a redirected window belonging to @widget gets drawn into.
2735 * The region/area members of the event shows what area of the redirected
2736 * drawable was drawn into.
2738 * Returns: %TRUE to stop other handlers from being invoked for the event.
2739 * %FALSE to propagate the event further.
2743 widget_signals[DAMAGE_EVENT] =
2744 g_signal_new (I_("damage-event"),
2745 G_TYPE_FROM_CLASS (klass),
2747 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2748 _gtk_boolean_handled_accumulator, NULL,
2749 _gtk_marshal_BOOLEAN__BOXED,
2751 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2754 * GtkWidget::grab-broken-event:
2755 * @widget: the object which received the signal
2756 * @event: the #GdkEventGrabBroken event
2758 * Emitted when a pointer or keyboard grab on a window belonging
2759 * to @widget gets broken.
2761 * On X11, this happens when the grab window becomes unviewable
2762 * (i.e. it or one of its ancestors is unmapped), or if the same
2763 * application grabs the pointer or keyboard again.
2765 * Returns: %TRUE to stop other handlers from being invoked for
2766 * the event. %FALSE to propagate the event further.
2770 widget_signals[GRAB_BROKEN_EVENT] =
2771 g_signal_new (I_("grab-broken-event"),
2772 G_TYPE_FROM_CLASS (klass),
2774 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2775 _gtk_boolean_handled_accumulator, NULL,
2776 _gtk_marshal_BOOLEAN__BOXED,
2778 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2781 * GtkWidget::query-tooltip:
2782 * @widget: the object which received the signal
2783 * @x: the x coordinate of the cursor position where the request has
2784 * been emitted, relative to @widget->window
2785 * @y: the y coordinate of the cursor position where the request has
2786 * been emitted, relative to @widget->window
2787 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2788 * @tooltip: a #GtkTooltip
2790 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2791 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2792 * focus in keyboard mode.
2794 * Using the given coordinates, the signal handler should determine
2795 * whether a tooltip should be shown for @widget. If this is the case
2796 * %TRUE should be returned, %FALSE otherwise. Note that if
2797 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2798 * should not be used.
2800 * The signal handler is free to manipulate @tooltip with the therefore
2801 * destined function calls.
2803 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2807 widget_signals[QUERY_TOOLTIP] =
2808 g_signal_new (I_("query-tooltip"),
2809 G_TYPE_FROM_CLASS (klass),
2811 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2812 _gtk_boolean_handled_accumulator, NULL,
2813 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2821 * GtkWidget::popup-menu
2822 * @widget: the object which received the signal
2824 * This signal gets emitted whenever a widget should pop up a context
2825 * menu. This usually happens through the standard key binding mechanism;
2826 * by pressing a certain key while a widget is focused, the user can cause
2827 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2828 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2829 * for an example of how to use this signal.
2831 * Returns: %TRUE if a menu was activated
2833 widget_signals[POPUP_MENU] =
2834 g_signal_new (I_("popup-menu"),
2835 G_TYPE_FROM_CLASS (klass),
2836 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2837 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2838 _gtk_boolean_handled_accumulator, NULL,
2839 _gtk_marshal_BOOLEAN__VOID,
2843 * GtkWidget::show-help:
2844 * @widget: the object which received the signal.
2847 widget_signals[SHOW_HELP] =
2848 g_signal_new (I_("show-help"),
2849 G_TYPE_FROM_CLASS (klass),
2850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2851 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2852 _gtk_boolean_handled_accumulator, NULL,
2853 _gtk_marshal_BOOLEAN__ENUM,
2855 GTK_TYPE_WIDGET_HELP_TYPE);
2858 * GtkWidget::accel-closures-changed:
2859 * @widget: the object which received the signal.
2861 widget_signals[ACCEL_CLOSURES_CHANGED] =
2862 g_signal_new (I_("accel-closures-changed"),
2863 G_TYPE_FROM_CLASS (klass),
2867 _gtk_marshal_VOID__VOID,
2871 * GtkWidget::screen-changed:
2872 * @widget: the object on which the signal is emitted
2873 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2874 * widget was not associated with a screen before
2876 * The ::screen-changed signal gets emitted when the
2877 * screen of a widget has changed.
2879 widget_signals[SCREEN_CHANGED] =
2880 g_signal_new (I_("screen-changed"),
2881 G_TYPE_FROM_CLASS (klass),
2883 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2885 _gtk_marshal_VOID__OBJECT,
2890 * GtkWidget::can-activate-accel:
2891 * @widget: the object which received the signal
2892 * @signal_id: the ID of a signal installed on @widget
2894 * Determines whether an accelerator that activates the signal
2895 * identified by @signal_id can currently be activated.
2896 * This signal is present to allow applications and derived
2897 * widgets to override the default #GtkWidget handling
2898 * for determining whether an accelerator can be activated.
2900 * Returns: %TRUE if the signal can be activated.
2902 widget_signals[CAN_ACTIVATE_ACCEL] =
2903 g_signal_new (I_("can-activate-accel"),
2904 G_TYPE_FROM_CLASS (klass),
2906 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2907 _gtk_boolean_handled_accumulator, NULL,
2908 _gtk_marshal_BOOLEAN__UINT,
2909 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2911 binding_set = gtk_binding_set_by_class (klass);
2912 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2914 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2917 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2919 GTK_TYPE_WIDGET_HELP_TYPE,
2920 GTK_WIDGET_HELP_TOOLTIP);
2921 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2923 GTK_TYPE_WIDGET_HELP_TYPE,
2924 GTK_WIDGET_HELP_TOOLTIP);
2925 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2927 GTK_TYPE_WIDGET_HELP_TYPE,
2928 GTK_WIDGET_HELP_WHATS_THIS);
2929 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2931 GTK_TYPE_WIDGET_HELP_TYPE,
2932 GTK_WIDGET_HELP_WHATS_THIS);
2934 gtk_widget_class_install_style_property (klass,
2935 g_param_spec_boolean ("interior-focus",
2936 P_("Interior Focus"),
2937 P_("Whether to draw the focus indicator inside widgets"),
2939 GTK_PARAM_READABLE));
2941 gtk_widget_class_install_style_property (klass,
2942 g_param_spec_int ("focus-line-width",
2943 P_("Focus linewidth"),
2944 P_("Width, in pixels, of the focus indicator line"),
2946 GTK_PARAM_READABLE));
2948 gtk_widget_class_install_style_property (klass,
2949 g_param_spec_string ("focus-line-pattern",
2950 P_("Focus line dash pattern"),
2951 P_("Dash pattern used to draw the focus indicator"),
2953 GTK_PARAM_READABLE));
2954 gtk_widget_class_install_style_property (klass,
2955 g_param_spec_int ("focus-padding",
2956 P_("Focus padding"),
2957 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2959 GTK_PARAM_READABLE));
2960 gtk_widget_class_install_style_property (klass,
2961 g_param_spec_boxed ("cursor-color",
2963 P_("Color with which to draw insertion cursor"),
2965 GTK_PARAM_READABLE));
2966 gtk_widget_class_install_style_property (klass,
2967 g_param_spec_boxed ("secondary-cursor-color",
2968 P_("Secondary cursor color"),
2969 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2971 GTK_PARAM_READABLE));
2972 gtk_widget_class_install_style_property (klass,
2973 g_param_spec_float ("cursor-aspect-ratio",
2974 P_("Cursor line aspect ratio"),
2975 P_("Aspect ratio with which to draw insertion cursor"),
2977 GTK_PARAM_READABLE));
2979 gtk_widget_class_install_style_property (klass,
2980 g_param_spec_boolean ("window-dragging",
2981 P_("Window dragging"),
2982 P_("Whether windows can be dragged by clicking on empty areas"),
2984 GTK_PARAM_READABLE));
2987 * GtkWidget:link-color:
2989 * The "link-color" style property defines the color of unvisited links.
2993 gtk_widget_class_install_style_property (klass,
2994 g_param_spec_boxed ("link-color",
2995 P_("Unvisited Link Color"),
2996 P_("Color of unvisited links"),
2998 GTK_PARAM_READABLE));
3001 * GtkWidget:visited-link-color:
3003 * The "visited-link-color" style property defines the color of visited links.
3007 gtk_widget_class_install_style_property (klass,
3008 g_param_spec_boxed ("visited-link-color",
3009 P_("Visited Link Color"),
3010 P_("Color of visited links"),
3012 GTK_PARAM_READABLE));
3015 * GtkWidget:wide-separators:
3017 * The "wide-separators" style property defines whether separators have
3018 * configurable width and should be drawn using a box instead of a line.
3022 gtk_widget_class_install_style_property (klass,
3023 g_param_spec_boolean ("wide-separators",
3024 P_("Wide Separators"),
3025 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3027 GTK_PARAM_READABLE));
3030 * GtkWidget:separator-width:
3032 * The "separator-width" style property defines the width of separators.
3033 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3037 gtk_widget_class_install_style_property (klass,
3038 g_param_spec_int ("separator-width",
3039 P_("Separator Width"),
3040 P_("The width of separators if wide-separators is TRUE"),
3042 GTK_PARAM_READABLE));
3045 * GtkWidget:separator-height:
3047 * The "separator-height" style property defines the height of separators.
3048 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_int ("separator-height",
3054 P_("Separator Height"),
3055 P_("The height of separators if \"wide-separators\" is TRUE"),
3057 GTK_PARAM_READABLE));
3060 * GtkWidget:scroll-arrow-hlength:
3062 * The "scroll-arrow-hlength" style property defines the length of
3063 * horizontal scroll arrows.
3067 gtk_widget_class_install_style_property (klass,
3068 g_param_spec_int ("scroll-arrow-hlength",
3069 P_("Horizontal Scroll Arrow Length"),
3070 P_("The length of horizontal scroll arrows"),
3072 GTK_PARAM_READABLE));
3075 * GtkWidget:scroll-arrow-vlength:
3077 * The "scroll-arrow-vlength" style property defines the length of
3078 * vertical scroll arrows.
3082 gtk_widget_class_install_style_property (klass,
3083 g_param_spec_int ("scroll-arrow-vlength",
3084 P_("Vertical Scroll Arrow Length"),
3085 P_("The length of vertical scroll arrows"),
3087 GTK_PARAM_READABLE));
3089 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3093 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3097 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3098 for (node = list; node; node = node->next)
3100 GParamSpec *pspec = node->data;
3102 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3103 g_param_spec_unref (pspec);
3109 gtk_widget_set_property (GObject *object,
3111 const GValue *value,
3114 GtkWidget *widget = GTK_WIDGET (object);
3119 gchar *tooltip_markup;
3120 const gchar *tooltip_text;
3121 GtkWindow *tooltip_window;
3124 gtk_widget_set_name (widget, g_value_get_string (value));
3127 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3129 case PROP_WIDTH_REQUEST:
3130 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3132 case PROP_HEIGHT_REQUEST:
3133 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3136 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3138 case PROP_SENSITIVE:
3139 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3141 case PROP_APP_PAINTABLE:
3142 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3144 case PROP_CAN_FOCUS:
3145 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3147 case PROP_HAS_FOCUS:
3148 if (g_value_get_boolean (value))
3149 gtk_widget_grab_focus (widget);
3152 if (g_value_get_boolean (value))
3153 gtk_widget_grab_focus (widget);
3155 case PROP_CAN_DEFAULT:
3156 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3158 case PROP_HAS_DEFAULT:
3159 if (g_value_get_boolean (value))
3160 gtk_widget_grab_default (widget);
3162 case PROP_RECEIVES_DEFAULT:
3163 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3166 gtk_widget_set_style (widget, g_value_get_object (value));
3169 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3170 gtk_widget_set_events (widget, g_value_get_flags (value));
3172 case PROP_EXTENSION_EVENTS:
3173 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3175 case PROP_NO_SHOW_ALL:
3176 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3178 case PROP_HAS_TOOLTIP:
3179 gtk_widget_real_set_has_tooltip (widget,
3180 g_value_get_boolean (value), FALSE);
3182 case PROP_TOOLTIP_MARKUP:
3183 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3184 tooltip_markup = g_value_dup_string (value);
3186 /* Treat an empty string as a NULL string,
3187 * because an empty string would be useless for a tooltip:
3189 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3191 g_free (tooltip_markup);
3192 tooltip_markup = NULL;
3195 g_object_set_qdata_full (object, quark_tooltip_markup,
3196 tooltip_markup, g_free);
3198 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3199 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3200 if (gtk_widget_get_visible (widget))
3201 gtk_widget_queue_tooltip_query (widget);
3203 case PROP_TOOLTIP_TEXT:
3204 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3206 tooltip_text = g_value_get_string (value);
3208 /* Treat an empty string as a NULL string,
3209 * because an empty string would be useless for a tooltip:
3211 if (tooltip_text && (strlen (tooltip_text) == 0))
3212 tooltip_text = NULL;
3214 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3216 g_object_set_qdata_full (object, quark_tooltip_markup,
3217 tooltip_markup, g_free);
3219 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3220 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3221 if (gtk_widget_get_visible (widget))
3222 gtk_widget_queue_tooltip_query (widget);
3224 case PROP_DOUBLE_BUFFERED:
3225 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3228 gtk_widget_set_halign (widget, g_value_get_enum (value));
3231 gtk_widget_set_valign (widget, g_value_get_enum (value));
3233 case PROP_MARGIN_LEFT:
3234 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3236 case PROP_MARGIN_RIGHT:
3237 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3239 case PROP_MARGIN_TOP:
3240 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3242 case PROP_MARGIN_BOTTOM:
3243 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3246 g_object_freeze_notify (G_OBJECT (widget));
3247 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3248 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3249 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3250 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3251 g_object_thaw_notify (G_OBJECT (widget));
3254 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3256 case PROP_HEXPAND_SET:
3257 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3260 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3262 case PROP_VEXPAND_SET:
3263 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3266 g_object_freeze_notify (G_OBJECT (widget));
3267 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3268 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3269 g_object_thaw_notify (G_OBJECT (widget));
3272 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3278 gtk_widget_get_property (GObject *object,
3283 GtkWidget *widget = GTK_WIDGET (object);
3284 GtkWidgetPrivate *priv = widget->priv;
3293 g_value_set_string (value, priv->name);
3295 g_value_set_static_string (value, "");
3298 g_value_set_object (value, priv->parent);
3300 case PROP_WIDTH_REQUEST:
3303 gtk_widget_get_size_request (widget, &w, NULL);
3304 g_value_set_int (value, w);
3307 case PROP_HEIGHT_REQUEST:
3310 gtk_widget_get_size_request (widget, NULL, &h);
3311 g_value_set_int (value, h);
3315 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3317 case PROP_SENSITIVE:
3318 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3320 case PROP_APP_PAINTABLE:
3321 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3323 case PROP_CAN_FOCUS:
3324 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3326 case PROP_HAS_FOCUS:
3327 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3330 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3332 case PROP_CAN_DEFAULT:
3333 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3335 case PROP_HAS_DEFAULT:
3336 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3338 case PROP_RECEIVES_DEFAULT:
3339 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3341 case PROP_COMPOSITE_CHILD:
3342 g_value_set_boolean (value, widget->priv->composite_child);
3345 g_value_set_object (value, gtk_widget_get_style (widget));
3348 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3349 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3351 case PROP_EXTENSION_EVENTS:
3352 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3353 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3355 case PROP_NO_SHOW_ALL:
3356 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3358 case PROP_HAS_TOOLTIP:
3359 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3361 case PROP_TOOLTIP_TEXT:
3363 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3366 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3367 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3369 g_value_take_string (value, text);
3372 case PROP_TOOLTIP_MARKUP:
3373 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3376 g_value_set_object (value, gtk_widget_get_window (widget));
3378 case PROP_DOUBLE_BUFFERED:
3379 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3382 g_value_set_enum (value, gtk_widget_get_halign (widget));
3385 g_value_set_enum (value, gtk_widget_get_valign (widget));
3387 case PROP_MARGIN_LEFT:
3388 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3390 case PROP_MARGIN_RIGHT:
3391 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3393 case PROP_MARGIN_TOP:
3394 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3396 case PROP_MARGIN_BOTTOM:
3397 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3401 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3402 if (aux_info == NULL)
3404 g_value_set_int (value, 0);
3408 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3409 aux_info->margin.right),
3410 MAX (aux_info->margin.top,
3411 aux_info->margin.bottom)));
3416 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3418 case PROP_HEXPAND_SET:
3419 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3422 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3424 case PROP_VEXPAND_SET:
3425 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3428 g_value_set_boolean (value,
3429 gtk_widget_get_hexpand (widget) &&
3430 gtk_widget_get_vexpand (widget));
3433 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3439 gtk_widget_init (GtkWidget *widget)
3441 GtkWidgetPrivate *priv;
3443 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3446 priv = widget->priv;
3448 priv->child_visible = TRUE;
3449 priv->state = GTK_STATE_NORMAL;
3450 priv->saved_state = GTK_STATE_NORMAL;
3452 priv->allocation.x = -1;
3453 priv->allocation.y = -1;
3454 priv->allocation.width = 1;
3455 priv->allocation.height = 1;
3456 priv->window = NULL;
3457 priv->parent = NULL;
3459 priv->sensitive = TRUE;
3460 priv->parent_sensitive = TRUE;
3461 priv->composite_child = composite_child_stack != 0;
3462 priv->double_buffered = TRUE;
3463 priv->redraw_on_alloc = TRUE;
3464 priv->width_request_needed = TRUE;
3465 priv->height_request_needed = TRUE;
3466 priv->alloc_needed = TRUE;
3468 /* this will be set to TRUE if the widget gets a child or if the
3469 * expand flag is set on the widget, but until one of those happen
3470 * we know the expand is already properly FALSE.
3472 * We really want to default FALSE here to avoid computing expand
3473 * all over the place while initially building a widget tree.
3475 priv->need_compute_expand = FALSE;
3477 priv->style = gtk_widget_get_default_style ();
3478 g_object_ref (priv->style);
3483 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3485 GParamSpec **pspecs)
3487 GtkWidgetPrivate *priv = widget->priv;
3488 GtkWidget *container = priv->parent;
3491 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3492 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3496 * gtk_widget_freeze_child_notify:
3497 * @widget: a #GtkWidget
3499 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3500 * signals are queued until gtk_widget_thaw_child_notify() is called
3503 * This is the analogue of g_object_freeze_notify() for child properties.
3506 gtk_widget_freeze_child_notify (GtkWidget *widget)
3508 g_return_if_fail (GTK_IS_WIDGET (widget));
3510 if (!G_OBJECT (widget)->ref_count)
3513 g_object_ref (widget);
3514 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3515 g_object_unref (widget);
3519 * gtk_widget_child_notify:
3520 * @widget: a #GtkWidget
3521 * @child_property: the name of a child property installed on the
3522 * class of @widget<!-- -->'s parent
3524 * Emits a #GtkWidget::child-notify signal for the
3525 * <link linkend="child-properties">child property</link> @child_property
3528 * This is the analogue of g_object_notify() for child properties.
3531 gtk_widget_child_notify (GtkWidget *widget,
3532 const gchar *child_property)
3534 GtkWidgetPrivate *priv = widget->priv;
3537 g_return_if_fail (GTK_IS_WIDGET (widget));
3538 g_return_if_fail (child_property != NULL);
3539 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3542 g_object_ref (widget);
3543 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3545 G_OBJECT_TYPE (priv->parent),
3548 g_warning ("%s: container class `%s' has no child property named `%s'",
3550 G_OBJECT_TYPE_NAME (priv->parent),
3554 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3556 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3557 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3559 g_object_unref (widget);
3563 * gtk_widget_thaw_child_notify:
3564 * @widget: a #GtkWidget
3566 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3567 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3571 gtk_widget_thaw_child_notify (GtkWidget *widget)
3573 GObjectNotifyQueue *nqueue;
3575 g_return_if_fail (GTK_IS_WIDGET (widget));
3577 if (!G_OBJECT (widget)->ref_count)
3580 g_object_ref (widget);
3581 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3582 if (!nqueue || !nqueue->freeze_count)
3583 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3584 G_OBJECT_TYPE_NAME (widget), widget);
3586 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3587 g_object_unref (widget);
3593 * @type: type ID of the widget to create
3594 * @first_property_name: name of first property to set
3595 * @Varargs: value of first property, followed by more properties,
3598 * This is a convenience function for creating a widget and setting
3599 * its properties in one go. For example you might write:
3600 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3601 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3602 * g_object_new(), but returns a widget so you don't have to
3603 * cast the object yourself.
3605 * Return value: a new #GtkWidget of type @widget_type
3608 gtk_widget_new (GType type,
3609 const gchar *first_property_name,
3615 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3617 va_start (var_args, first_property_name);
3618 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3625 gtk_widget_queue_draw_child (GtkWidget *widget)
3627 GtkWidgetPrivate *priv = widget->priv;
3630 parent = priv->parent;
3631 if (parent && gtk_widget_is_drawable (parent))
3632 gtk_widget_queue_draw_area (parent,
3635 priv->allocation.width,
3636 priv->allocation.height);
3640 * gtk_widget_unparent:
3641 * @widget: a #GtkWidget
3643 * This function is only for use in widget implementations.
3644 * Should be called by implementations of the remove method
3645 * on #GtkContainer, to dissociate a child from the container.
3648 gtk_widget_unparent (GtkWidget *widget)
3650 GtkWidgetPrivate *priv;
3651 GObjectNotifyQueue *nqueue;
3652 GtkWidget *toplevel;
3653 GtkWidget *old_parent;
3655 g_return_if_fail (GTK_IS_WIDGET (widget));
3657 priv = widget->priv;
3659 if (priv->parent == NULL)
3662 /* keep this function in sync with gtk_menu_detach()
3665 g_object_freeze_notify (G_OBJECT (widget));
3666 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3668 toplevel = gtk_widget_get_toplevel (widget);
3669 if (gtk_widget_is_toplevel (toplevel))
3670 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3672 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3673 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3675 /* If we are unanchoring the child, we save around the toplevel
3676 * to emit hierarchy changed
3678 if (priv->parent->priv->anchored)
3679 g_object_ref (toplevel);
3683 gtk_widget_queue_draw_child (widget);
3685 /* Reset the width and height here, to force reallocation if we
3686 * get added back to a new parent. This won't work if our new
3687 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3688 * (would 0x0 be OK here?)
3690 priv->allocation.width = 1;
3691 priv->allocation.height = 1;
3693 if (gtk_widget_get_realized (widget))
3695 if (priv->in_reparent)
3696 gtk_widget_unmap (widget);
3698 gtk_widget_unrealize (widget);
3701 /* Removing a widget from a container restores the child visible
3702 * flag to the default state, so it doesn't affect the child
3703 * in the next parent.
3705 priv->child_visible = TRUE;
3707 old_parent = priv->parent;
3708 priv->parent = NULL;
3709 gtk_widget_set_parent_window (widget, NULL);
3711 /* parent may no longer expand if the removed
3712 * child was expand=TRUE and could therefore
3715 if (gtk_widget_get_visible (widget) &&
3716 (priv->need_compute_expand ||
3717 priv->computed_hexpand ||
3718 priv->computed_vexpand))
3720 gtk_widget_queue_compute_expand (old_parent);
3723 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3726 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3727 g_object_unref (toplevel);
3730 g_object_notify (G_OBJECT (widget), "parent");
3731 g_object_thaw_notify (G_OBJECT (widget));
3733 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3734 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3735 g_object_unref (widget);
3739 * gtk_widget_destroy:
3740 * @widget: a #GtkWidget
3742 * Destroys a widget.
3745 * destroyed, it will break any references it holds to other objects.
3746 * If the widget is inside a container, the widget will be removed
3747 * from the container. If the widget is a toplevel (derived from
3748 * #GtkWindow), it will be removed from the list of toplevels, and the
3749 * reference GTK+ holds to it will be removed. Removing a
3750 * widget from its container or the list of toplevels results in the
3751 * widget being finalized, unless you've added additional references
3752 * to the widget with g_object_ref().
3754 * In most cases, only toplevel widgets (windows) require explicit
3755 * destruction, because when you destroy a toplevel its children will
3756 * be destroyed as well.
3759 gtk_widget_destroy (GtkWidget *widget)
3761 g_return_if_fail (GTK_IS_WIDGET (widget));
3763 if (!widget->priv->in_destruction)
3764 g_object_run_dispose (G_OBJECT (widget));
3768 * gtk_widget_destroyed:
3769 * @widget: a #GtkWidget
3770 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3772 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3773 * %NULL. It's intended to be used as a callback connected to the
3774 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3775 * as a signal handler, and pass the address of your widget variable
3776 * as user data. Then when the widget is destroyed, the variable will
3777 * be set to %NULL. Useful for example to avoid multiple copies
3778 * of the same dialog.
3781 gtk_widget_destroyed (GtkWidget *widget,
3782 GtkWidget **widget_pointer)
3784 /* Don't make any assumptions about the
3786 * Even check widget_pointer.
3789 *widget_pointer = NULL;
3794 * @widget: a #GtkWidget
3796 * Flags a widget to be displayed. Any widget that isn't shown will
3797 * not appear on the screen. If you want to show all the widgets in a
3798 * container, it's easier to call gtk_widget_show_all() on the
3799 * container, instead of individually showing the widgets.
3801 * Remember that you have to show the containers containing a widget,
3802 * in addition to the widget itself, before it will appear onscreen.
3804 * When a toplevel container is shown, it is immediately realized and
3805 * mapped; other shown widgets are realized and mapped when their
3806 * toplevel container is realized and mapped.
3809 gtk_widget_show (GtkWidget *widget)
3811 g_return_if_fail (GTK_IS_WIDGET (widget));
3813 if (!gtk_widget_get_visible (widget))
3815 g_object_ref (widget);
3816 if (!gtk_widget_is_toplevel (widget))
3817 gtk_widget_queue_resize (widget);
3819 /* see comment in set_parent() for why this should and can be
3822 if (widget->priv->need_compute_expand ||
3823 widget->priv->computed_hexpand ||
3824 widget->priv->computed_vexpand)
3826 if (widget->priv->parent != NULL)
3827 gtk_widget_queue_compute_expand (widget->priv->parent);
3830 g_signal_emit (widget, widget_signals[SHOW], 0);
3831 g_object_notify (G_OBJECT (widget), "visible");
3832 g_object_unref (widget);
3837 gtk_widget_real_show (GtkWidget *widget)
3839 GtkWidgetPrivate *priv = widget->priv;
3841 if (!gtk_widget_get_visible (widget))
3843 priv->visible = TRUE;
3846 gtk_widget_get_mapped (priv->parent) &&
3847 gtk_widget_get_child_visible (widget) &&
3848 !gtk_widget_get_mapped (widget))
3849 gtk_widget_map (widget);
3854 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3857 g_signal_handlers_disconnect_by_func (widget,
3858 gtk_widget_show_map_callback,
3863 * gtk_widget_show_now:
3864 * @widget: a #GtkWidget
3866 * Shows a widget. If the widget is an unmapped toplevel widget
3867 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3868 * loop and wait for the window to actually be mapped. Be careful;
3869 * because the main loop is running, anything can happen during
3873 gtk_widget_show_now (GtkWidget *widget)
3877 g_return_if_fail (GTK_IS_WIDGET (widget));
3879 /* make sure we will get event */
3880 if (!gtk_widget_get_mapped (widget) &&
3881 gtk_widget_is_toplevel (widget))
3883 gtk_widget_show (widget);
3885 g_signal_connect (widget, "map-event",
3886 G_CALLBACK (gtk_widget_show_map_callback),
3890 gtk_main_iteration ();
3893 gtk_widget_show (widget);
3898 * @widget: a #GtkWidget
3900 * Reverses the effects of gtk_widget_show(), causing the widget to be
3901 * hidden (invisible to the user).
3904 gtk_widget_hide (GtkWidget *widget)
3906 g_return_if_fail (GTK_IS_WIDGET (widget));
3908 if (gtk_widget_get_visible (widget))
3910 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3912 g_object_ref (widget);
3913 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3914 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3916 /* a parent may now be expand=FALSE since we're hidden. */
3917 if (widget->priv->need_compute_expand ||
3918 widget->priv->computed_hexpand ||
3919 widget->priv->computed_vexpand)
3921 gtk_widget_queue_compute_expand (widget);
3924 g_signal_emit (widget, widget_signals[HIDE], 0);
3925 if (!gtk_widget_is_toplevel (widget))
3926 gtk_widget_queue_resize (widget);
3927 g_object_notify (G_OBJECT (widget), "visible");
3928 g_object_unref (widget);
3933 gtk_widget_real_hide (GtkWidget *widget)
3935 if (gtk_widget_get_visible (widget))
3937 widget->priv->visible = FALSE;
3939 if (gtk_widget_get_mapped (widget))
3940 gtk_widget_unmap (widget);
3945 * gtk_widget_hide_on_delete:
3946 * @widget: a #GtkWidget
3948 * Utility function; intended to be connected to the #GtkWidget::delete-event
3949 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3950 * argument, then returns %TRUE. If connected to ::delete-event, the
3951 * result is that clicking the close button for a window (on the
3952 * window frame, top right corner usually) will hide but not destroy
3953 * the window. By default, GTK+ destroys windows when ::delete-event
3956 * Return value: %TRUE
3959 gtk_widget_hide_on_delete (GtkWidget *widget)
3961 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3963 gtk_widget_hide (widget);
3969 * gtk_widget_show_all:
3970 * @widget: a #GtkWidget
3972 * Recursively shows a widget, and any child widgets (if the widget is
3976 gtk_widget_show_all (GtkWidget *widget)
3978 GtkWidgetClass *class;
3980 g_return_if_fail (GTK_IS_WIDGET (widget));
3982 if (gtk_widget_get_no_show_all (widget))
3985 class = GTK_WIDGET_GET_CLASS (widget);
3987 if (class->show_all)
3988 class->show_all (widget);
3993 * @widget: a #GtkWidget
3995 * This function is only for use in widget implementations. Causes
3996 * a widget to be mapped if it isn't already.
3999 gtk_widget_map (GtkWidget *widget)
4001 GtkWidgetPrivate *priv;
4003 g_return_if_fail (GTK_IS_WIDGET (widget));
4004 g_return_if_fail (gtk_widget_get_visible (widget));
4005 g_return_if_fail (gtk_widget_get_child_visible (widget));
4007 priv = widget->priv;
4009 if (!gtk_widget_get_mapped (widget))
4011 if (!gtk_widget_get_realized (widget))
4012 gtk_widget_realize (widget);
4014 g_signal_emit (widget, widget_signals[MAP], 0);
4016 if (!gtk_widget_get_has_window (widget))
4017 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4023 * @widget: a #GtkWidget
4025 * This function is only for use in widget implementations. Causes
4026 * a widget to be unmapped if it's currently mapped.
4029 gtk_widget_unmap (GtkWidget *widget)
4031 GtkWidgetPrivate *priv;
4033 g_return_if_fail (GTK_IS_WIDGET (widget));
4035 priv = widget->priv;
4037 if (gtk_widget_get_mapped (widget))
4039 if (!gtk_widget_get_has_window (widget))
4040 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4041 _gtk_tooltip_hide (widget);
4042 g_signal_emit (widget, widget_signals[UNMAP], 0);
4047 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4048 GdkExtensionMode mode,
4051 GtkWidgetPrivate *priv = widget->priv;
4052 GList *free_list = NULL;
4055 if (window_list == NULL)
4057 if (gtk_widget_get_has_window (widget))
4058 window_list = g_list_prepend (NULL, priv->window);
4060 window_list = gdk_window_get_children (priv->window);
4062 free_list = window_list;
4065 for (l = window_list; l != NULL; l = l->next)
4067 GdkWindow *window = l->data;
4070 gdk_window_get_user_data (window, &user_data);
4071 if (user_data == widget)
4075 gdk_input_set_extension_events (window,
4076 gdk_window_get_events (window),
4079 children = gdk_window_get_children (window);
4082 gtk_widget_set_extension_events_internal (widget, mode, children);
4083 g_list_free (children);
4089 g_list_free (free_list);
4093 _gtk_widget_enable_device_events (GtkWidget *widget)
4095 GHashTable *device_events;
4096 GHashTableIter iter;
4097 gpointer key, value;
4099 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4104 g_hash_table_iter_init (&iter, device_events);
4106 while (g_hash_table_iter_next (&iter, &key, &value))
4109 GdkEventMask event_mask;
4112 event_mask = GPOINTER_TO_UINT (value);
4113 gtk_widget_add_events_internal (widget, device, event_mask);
4118 * gtk_widget_realize:
4119 * @widget: a #GtkWidget
4121 * Creates the GDK (windowing system) resources associated with a
4122 * widget. For example, @widget->window will be created when a widget
4123 * is realized. Normally realization happens implicitly; if you show
4124 * a widget and all its parent containers, then the widget will be
4125 * realized and mapped automatically.
4127 * Realizing a widget requires all
4128 * the widget's parent widgets to be realized; calling
4129 * gtk_widget_realize() realizes the widget's parents in addition to
4130 * @widget itself. If a widget is not yet inside a toplevel window
4131 * when you realize it, bad things will happen.
4133 * This function is primarily used in widget implementations, and
4134 * isn't very useful otherwise. Many times when you think you might
4135 * need it, a better approach is to connect to a signal that will be
4136 * called after the widget is realized automatically, such as
4137 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4138 * #GtkWidget::realize signal.
4141 gtk_widget_realize (GtkWidget *widget)
4143 GtkWidgetPrivate *priv;
4144 GdkExtensionMode mode;
4145 cairo_region_t *region;
4147 g_return_if_fail (GTK_IS_WIDGET (widget));
4148 g_return_if_fail (widget->priv->anchored ||
4149 GTK_IS_INVISIBLE (widget));
4151 priv = widget->priv;
4153 if (!gtk_widget_get_realized (widget))
4156 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4157 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4160 if (priv->parent == NULL &&
4161 !gtk_widget_is_toplevel (widget))
4162 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4163 "inside a toplevel window is not going to work very well. "
4164 "Widgets must be inside a toplevel container before realizing them.");
4166 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4167 gtk_widget_realize (priv->parent);
4169 gtk_widget_ensure_style (widget);
4171 g_signal_emit (widget, widget_signals[REALIZE], 0);
4173 gtk_widget_real_set_has_tooltip (widget,
4174 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4177 if (priv->has_shape_mask)
4179 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4180 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4183 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4185 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4187 mode = gtk_widget_get_extension_events (widget);
4188 if (mode != GDK_EXTENSION_EVENTS_NONE)
4189 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4191 if (priv->multidevice)
4192 gdk_window_set_support_multidevice (priv->window, TRUE);
4194 _gtk_widget_enable_device_events (widget);
4199 * gtk_widget_unrealize:
4200 * @widget: a #GtkWidget
4202 * This function is only useful in widget implementations.
4203 * Causes a widget to be unrealized (frees all GDK resources
4204 * associated with the widget, such as @widget->window).
4207 gtk_widget_unrealize (GtkWidget *widget)
4209 g_return_if_fail (GTK_IS_WIDGET (widget));
4211 if (widget->priv->has_shape_mask)
4212 gtk_widget_shape_combine_region (widget, NULL);
4214 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4215 gtk_widget_input_shape_combine_region (widget, NULL);
4217 if (gtk_widget_get_realized (widget))
4219 g_object_ref (widget);
4220 _gtk_tooltip_hide (widget);
4221 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4222 gtk_widget_set_realized (widget, FALSE);
4223 gtk_widget_set_mapped (widget, FALSE);
4224 g_object_unref (widget);
4228 /*****************************************
4230 *****************************************/
4233 * gtk_widget_queue_draw_region:
4234 * @widget: a #GtkWidget
4235 * @region: region to draw
4237 * Invalidates the rectangular area of @widget defined by @region by
4238 * calling gdk_window_invalidate_region() on the widget's window and
4239 * all its child windows. Once the main loop becomes idle (after the
4240 * current batch of events has been processed, roughly), the window
4241 * will receive expose events for the union of all regions that have
4244 * Normally you would only use this function in widget
4245 * implementations. You might also use it to schedule a redraw of a
4246 * #GtkDrawingArea or some portion thereof.
4249 gtk_widget_queue_draw_region (GtkWidget *widget,
4250 cairo_region_t *region)
4252 GtkWidgetPrivate *priv;
4255 g_return_if_fail (GTK_IS_WIDGET (widget));
4257 priv = widget->priv;
4259 if (!gtk_widget_get_realized (widget))
4262 /* Just return if the widget or one of its ancestors isn't mapped */
4263 for (w = widget; w != NULL; w = w->priv->parent)
4264 if (!gtk_widget_get_mapped (w))
4267 gdk_window_invalidate_region (priv->window, region, TRUE);
4271 * gtk_widget_queue_draw_area:
4272 * @widget: a #GtkWidget
4273 * @x: x coordinate of upper-left corner of rectangle to redraw
4274 * @y: y coordinate of upper-left corner of rectangle to redraw
4275 * @width: width of region to draw
4276 * @height: height of region to draw
4278 * Convenience function that calls gtk_widget_queue_draw_region() on
4279 * the region created from the given coordinates.
4282 gtk_widget_queue_draw_area (GtkWidget *widget,
4289 cairo_region_t *region;
4291 g_return_if_fail (GTK_IS_WIDGET (widget));
4296 rect.height = height;
4298 region = cairo_region_create_rectangle (&rect);
4299 gtk_widget_queue_draw_region (widget, region);
4300 cairo_region_destroy (region);
4304 * gtk_widget_queue_draw:
4305 * @widget: a #GtkWidget
4307 * Equivalent to calling gtk_widget_queue_draw_area() for the
4308 * entire area of a widget.
4311 gtk_widget_queue_draw (GtkWidget *widget)
4315 g_return_if_fail (GTK_IS_WIDGET (widget));
4317 gtk_widget_get_allocation (widget, &rect);
4319 if (!gtk_widget_get_has_window (widget))
4320 gtk_widget_queue_draw_area (widget,
4321 rect.x, rect.y, rect.width, rect.height);
4323 gtk_widget_queue_draw_area (widget,
4324 0, 0, rect.width, rect.height);
4328 * gtk_widget_queue_resize:
4329 * @widget: a #GtkWidget
4331 * This function is only for use in widget implementations.
4332 * Flags a widget to have its size renegotiated; should
4333 * be called when a widget for some reason has a new size request.
4334 * For example, when you change the text in a #GtkLabel, #GtkLabel
4335 * queues a resize to ensure there's enough space for the new text.
4337 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4338 * from inside it's implementation of the GtkWidgetClass::size_allocate
4339 * virtual method. Calls to gtk_widget_queue_resize() from inside
4340 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4343 gtk_widget_queue_resize (GtkWidget *widget)
4345 g_return_if_fail (GTK_IS_WIDGET (widget));
4347 if (gtk_widget_get_realized (widget))
4348 gtk_widget_queue_shallow_draw (widget);
4350 _gtk_size_group_queue_resize (widget, 0);
4354 * gtk_widget_queue_resize_no_redraw:
4355 * @widget: a #GtkWidget
4357 * This function works like gtk_widget_queue_resize(),
4358 * except that the widget is not invalidated.
4363 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4365 g_return_if_fail (GTK_IS_WIDGET (widget));
4367 _gtk_size_group_queue_resize (widget, 0);
4371 * gtk_widget_size_request:
4372 * @widget: a #GtkWidget
4373 * @requisition: (out): a #GtkRequisition to be filled in
4375 * This function is typically used when implementing a #GtkContainer
4376 * subclass. Obtains the preferred size of a widget. The container
4377 * uses this information to arrange its child widgets and decide what
4378 * size allocations to give them with gtk_widget_size_allocate().
4380 * You can also call this function from an application, with some
4381 * caveats. Most notably, getting a size request requires the widget
4382 * to be associated with a screen, because font information may be
4383 * needed. Multihead-aware applications should keep this in mind.
4385 * Also remember that the size request is not necessarily the size
4386 * a widget will actually be allocated.
4388 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4391 gtk_widget_size_request (GtkWidget *widget,
4392 GtkRequisition *requisition)
4394 g_return_if_fail (GTK_IS_WIDGET (widget));
4396 gtk_widget_get_preferred_size (widget, requisition, NULL);
4400 * gtk_widget_get_child_requisition:
4401 * @widget: a #GtkWidget
4402 * @requisition: (out): a #GtkRequisition to be filled in
4404 * This function is only for use in widget implementations. Obtains
4405 * @widget->requisition, unless someone has forced a particular
4406 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4407 * in which case it returns that geometry instead of the widget's
4410 * This function differs from gtk_widget_size_request() in that
4411 * it retrieves the last size request value from @widget->requisition,
4412 * while gtk_widget_size_request() actually calls the "size_request" method
4413 * on @widget to compute the size request and fill in @widget->requisition,
4414 * and only then returns @widget->requisition.
4416 * Because this function does not call the "size_request" method, it
4417 * can only be used when you know that @widget->requisition is
4418 * up-to-date, that is, gtk_widget_size_request() has been called
4419 * since the last time a resize was queued. In general, only container
4420 * implementations have this information; applications should use
4421 * gtk_widget_size_request().
4424 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4427 gtk_widget_get_child_requisition (GtkWidget *widget,
4428 GtkRequisition *requisition)
4430 gtk_widget_get_preferred_size (widget, requisition, NULL);
4434 invalidate_predicate (GdkWindow *window,
4439 gdk_window_get_user_data (window, &user_data);
4441 return (user_data == data);
4444 /* Invalidate @region in widget->window and all children
4445 * of widget->window owned by widget. @region is in the
4446 * same coordinates as widget->allocation and will be
4447 * modified by this call.
4450 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4451 cairo_region_t *region)
4453 GtkWidgetPrivate *priv = widget->priv;
4455 if (!gtk_widget_get_realized (widget))
4458 if (gtk_widget_get_has_window (widget) && priv->parent)
4462 gdk_window_get_position (priv->window, &x, &y);
4463 cairo_region_translate (region, -x, -y);
4466 gdk_window_invalidate_maybe_recurse (priv->window, region,
4467 invalidate_predicate, widget);
4471 * gtk_widget_queue_shallow_draw:
4472 * @widget: a #GtkWidget
4474 * Like gtk_widget_queue_draw(), but only windows owned
4475 * by @widget are invalidated.
4478 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4481 cairo_region_t *region;
4483 if (!gtk_widget_get_realized (widget))
4486 gtk_widget_get_allocation (widget, &rect);
4488 region = cairo_region_create_rectangle (&rect);
4489 gtk_widget_invalidate_widget_windows (widget, region);
4490 cairo_region_destroy (region);
4494 * gtk_widget_size_allocate:
4495 * @widget: a #GtkWidget
4496 * @allocation: (inout): position and size to be allocated to @widget
4498 * This function is only used by #GtkContainer subclasses, to assign a size
4499 * and position to their child widgets.
4501 * In this function, the allocation may be adjusted. It will be forced
4502 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4503 * method on the child will be used to adjust the allocation. Standard
4504 * adjustments include removing the widget's margins, and applying the
4505 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4508 gtk_widget_size_allocate (GtkWidget *widget,
4509 GtkAllocation *allocation)
4511 GtkWidgetPrivate *priv;
4512 GdkRectangle real_allocation;
4513 GdkRectangle old_allocation;
4514 GdkRectangle adjusted_allocation;
4515 gboolean alloc_needed;
4516 gboolean size_changed;
4517 gboolean position_changed;
4518 gint natural_width, natural_height;
4519 gint min_width, min_height;
4521 priv = widget->priv;
4523 g_return_if_fail (GTK_IS_WIDGET (widget));
4525 #ifdef G_ENABLE_DEBUG
4526 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4537 parent = gtk_widget_get_parent (parent);
4540 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4541 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4542 2 * depth, " ", name,
4543 allocation->width, allocation->height);
4545 #endif /* G_ENABLE_DEBUG */
4547 alloc_needed = priv->alloc_needed;
4548 if (!priv->width_request_needed && !priv->height_request_needed)
4549 /* Preserve request/allocate ordering */
4550 priv->alloc_needed = FALSE;
4552 old_allocation = priv->allocation;
4553 real_allocation = *allocation;
4555 adjusted_allocation = real_allocation;
4556 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4558 /* Go ahead and request the height for allocated width, note that the internals
4559 * of get_height_for_width will internally limit the for_size to natural size
4560 * when aligning implicitly.
4562 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4563 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4567 /* Go ahead and request the width for allocated height, note that the internals
4568 * of get_width_for_height will internally limit the for_size to natural size
4569 * when aligning implicitly.
4571 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4572 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4575 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4576 * allocated sizes and possibly limit them to the natural sizes */
4577 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4578 GTK_ORIENTATION_HORIZONTAL,
4580 &adjusted_allocation.x,
4581 &adjusted_allocation.width);
4582 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4583 GTK_ORIENTATION_VERTICAL,
4585 &adjusted_allocation.y,
4586 &adjusted_allocation.height);
4588 if (adjusted_allocation.x < real_allocation.x ||
4589 adjusted_allocation.y < real_allocation.y ||
4590 (adjusted_allocation.x + adjusted_allocation.width) >
4591 (real_allocation.x + real_allocation.width) ||
4592 (adjusted_allocation.y + adjusted_allocation.height >
4593 real_allocation.y + real_allocation.height))
4595 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",
4596 G_OBJECT_TYPE_NAME (widget), widget,
4597 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4598 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4599 adjusted_allocation = real_allocation; /* veto it */
4603 real_allocation = adjusted_allocation;
4606 if (real_allocation.width < 0 || real_allocation.height < 0)
4608 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4609 real_allocation.width,
4610 real_allocation.height);
4613 real_allocation.width = MAX (real_allocation.width, 1);
4614 real_allocation.height = MAX (real_allocation.height, 1);
4616 size_changed = (old_allocation.width != real_allocation.width ||
4617 old_allocation.height != real_allocation.height);
4618 position_changed = (old_allocation.x != real_allocation.x ||
4619 old_allocation.y != real_allocation.y);
4621 if (!alloc_needed && !size_changed && !position_changed)
4624 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4626 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4627 priv->width_request_needed = FALSE;
4628 priv->height_request_needed = FALSE;
4629 priv->alloc_needed = FALSE;
4631 if (gtk_widget_get_mapped (widget))
4633 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4635 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4637 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4638 cairo_region_union_rectangle (invalidate, &old_allocation);
4640 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4641 cairo_region_destroy (invalidate);
4646 if (priv->redraw_on_alloc)
4648 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4650 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4651 cairo_region_union_rectangle (invalidate, &old_allocation);
4653 gtk_widget_invalidate_widget_windows (widget, invalidate);
4654 cairo_region_destroy (invalidate);
4659 if ((size_changed || position_changed) && priv->parent &&
4660 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4662 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4663 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4664 cairo_region_destroy (invalidate);
4669 * gtk_widget_common_ancestor:
4670 * @widget_a: a #GtkWidget
4671 * @widget_b: a #GtkWidget
4673 * Find the common ancestor of @widget_a and @widget_b that
4674 * is closest to the two widgets.
4676 * Return value: the closest common ancestor of @widget_a and
4677 * @widget_b or %NULL if @widget_a and @widget_b do not
4678 * share a common ancestor.
4681 gtk_widget_common_ancestor (GtkWidget *widget_a,
4682 GtkWidget *widget_b)
4684 GtkWidget *parent_a;
4685 GtkWidget *parent_b;
4689 parent_a = widget_a;
4690 while (parent_a->priv->parent)
4692 parent_a = parent_a->priv->parent;
4696 parent_b = widget_b;
4697 while (parent_b->priv->parent)
4699 parent_b = parent_b->priv->parent;
4703 if (parent_a != parent_b)
4706 while (depth_a > depth_b)
4708 widget_a = widget_a->priv->parent;
4712 while (depth_b > depth_a)
4714 widget_b = widget_b->priv->parent;
4718 while (widget_a != widget_b)
4720 widget_a = widget_a->priv->parent;
4721 widget_b = widget_b->priv->parent;
4728 * gtk_widget_translate_coordinates:
4729 * @src_widget: a #GtkWidget
4730 * @dest_widget: a #GtkWidget
4731 * @src_x: X position relative to @src_widget
4732 * @src_y: Y position relative to @src_widget
4733 * @dest_x: (out): location to store X position relative to @dest_widget
4734 * @dest_y: (out): location to store Y position relative to @dest_widget
4736 * Translate coordinates relative to @src_widget's allocation to coordinates
4737 * relative to @dest_widget's allocations. In order to perform this
4738 * operation, both widgets must be realized, and must share a common
4741 * Return value: %FALSE if either widget was not realized, or there
4742 * was no common ancestor. In this case, nothing is stored in
4743 * *@dest_x and *@dest_y. Otherwise %TRUE.
4746 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4747 GtkWidget *dest_widget,
4753 GtkWidgetPrivate *src_priv = src_widget->priv;
4754 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4755 GtkWidget *ancestor;
4757 GList *dest_list = NULL;
4759 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4760 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4762 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4763 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4766 /* Translate from allocation relative to window relative */
4767 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4770 gdk_window_get_position (src_priv->window, &wx, &wy);
4772 src_x -= wx - src_priv->allocation.x;
4773 src_y -= wy - src_priv->allocation.y;
4777 src_x += src_priv->allocation.x;
4778 src_y += src_priv->allocation.y;
4781 /* Translate to the common ancestor */
4782 window = src_priv->window;
4783 while (window != ancestor->priv->window)
4787 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4792 window = gdk_window_get_effective_parent (window);
4794 if (!window) /* Handle GtkHandleBox */
4799 window = dest_priv->window;
4800 while (window != ancestor->priv->window)
4802 dest_list = g_list_prepend (dest_list, window);
4804 window = gdk_window_get_effective_parent (window);
4806 if (!window) /* Handle GtkHandleBox */
4808 g_list_free (dest_list);
4817 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4822 dest_list = g_list_remove (dest_list, dest_list->data);
4825 /* Translate from window relative to allocation relative */
4826 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4829 gdk_window_get_position (dest_priv->window, &wx, &wy);
4831 src_x += wx - dest_priv->allocation.x;
4832 src_y += wy - dest_priv->allocation.y;
4836 src_x -= dest_priv->allocation.x;
4837 src_y -= dest_priv->allocation.y;
4849 gtk_widget_real_size_allocate (GtkWidget *widget,
4850 GtkAllocation *allocation)
4852 GtkWidgetPrivate *priv = widget->priv;
4854 priv->allocation = *allocation;
4856 if (gtk_widget_get_realized (widget) &&
4857 gtk_widget_get_has_window (widget))
4859 gdk_window_move_resize (priv->window,
4860 allocation->x, allocation->y,
4861 allocation->width, allocation->height);
4866 adjust_for_align(GtkAlign align,
4868 gint *allocated_pos,
4869 gint *allocated_size)
4873 case GTK_ALIGN_FILL:
4874 /* change nothing */
4876 case GTK_ALIGN_START:
4877 /* keep *allocated_pos where it is */
4878 *allocated_size = MIN (*allocated_size, *natural_size);
4881 if (*allocated_size > *natural_size)
4883 *allocated_pos += (*allocated_size - *natural_size);
4884 *allocated_size = *natural_size;
4887 case GTK_ALIGN_CENTER:
4888 if (*allocated_size > *natural_size)
4890 *allocated_pos += (*allocated_size - *natural_size) / 2;
4891 *allocated_size = MIN (*allocated_size, *natural_size);
4898 adjust_for_margin(gint start_margin,
4901 gint *allocated_pos,
4902 gint *allocated_size)
4904 *natural_size -= (start_margin + end_margin);
4905 *allocated_pos += start_margin;
4906 *allocated_size -= (start_margin + end_margin);
4910 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4911 GtkOrientation orientation,
4913 gint *allocated_pos,
4914 gint *allocated_size)
4916 const GtkWidgetAuxInfo *aux_info;
4918 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4920 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4922 adjust_for_margin (aux_info->margin.left,
4923 aux_info->margin.right,
4924 natural_size, allocated_pos, allocated_size);
4925 adjust_for_align (aux_info->halign,
4926 natural_size, allocated_pos, allocated_size);
4930 adjust_for_margin (aux_info->margin.top,
4931 aux_info->margin.bottom,
4932 natural_size, allocated_pos, allocated_size);
4933 adjust_for_align (aux_info->valign,
4934 natural_size, allocated_pos, allocated_size);
4939 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4942 GtkWidgetPrivate *priv = widget->priv;
4944 /* widgets must be onscreen for accels to take effect */
4945 return gtk_widget_is_sensitive (widget) &&
4946 gtk_widget_is_drawable (widget) &&
4947 gdk_window_is_viewable (priv->window);
4951 * gtk_widget_can_activate_accel:
4952 * @widget: a #GtkWidget
4953 * @signal_id: the ID of a signal installed on @widget
4955 * Determines whether an accelerator that activates the signal
4956 * identified by @signal_id can currently be activated.
4957 * This is done by emitting the #GtkWidget::can-activate-accel
4958 * signal on @widget; if the signal isn't overridden by a
4959 * handler or in a derived widget, then the default check is
4960 * that the widget must be sensitive, and the widget and all
4961 * its ancestors mapped.
4963 * Return value: %TRUE if the accelerator can be activated.
4968 gtk_widget_can_activate_accel (GtkWidget *widget,
4971 gboolean can_activate = FALSE;
4972 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4973 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4974 return can_activate;
4983 closure_accel_activate (GClosure *closure,
4984 GValue *return_value,
4985 guint n_param_values,
4986 const GValue *param_values,
4987 gpointer invocation_hint,
4988 gpointer marshal_data)
4990 AccelClosure *aclosure = (AccelClosure*) closure;
4991 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4994 g_signal_emit (closure->data, aclosure->signal_id, 0);
4996 /* whether accelerator was handled */
4997 g_value_set_boolean (return_value, can_activate);
5001 closures_destroy (gpointer data)
5003 GSList *slist, *closures = data;
5005 for (slist = closures; slist; slist = slist->next)
5007 g_closure_invalidate (slist->data);
5008 g_closure_unref (slist->data);
5010 g_slist_free (closures);
5014 widget_new_accel_closure (GtkWidget *widget,
5017 AccelClosure *aclosure;
5018 GClosure *closure = NULL;
5019 GSList *slist, *closures;
5021 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5022 for (slist = closures; slist; slist = slist->next)
5023 if (!gtk_accel_group_from_accel_closure (slist->data))
5025 /* reuse this closure */
5026 closure = slist->data;
5031 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5032 closures = g_slist_prepend (closures, g_closure_ref (closure));
5033 g_closure_sink (closure);
5034 g_closure_set_marshal (closure, closure_accel_activate);
5036 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5038 aclosure = (AccelClosure*) closure;
5039 g_assert (closure->data == widget);
5040 g_assert (closure->marshal == closure_accel_activate);
5041 aclosure->signal_id = signal_id;
5047 * gtk_widget_add_accelerator
5048 * @widget: widget to install an accelerator on
5049 * @accel_signal: widget signal to emit on accelerator activation
5050 * @accel_group: accel group for this widget, added to its toplevel
5051 * @accel_key: GDK keyval of the accelerator
5052 * @accel_mods: modifier key combination of the accelerator
5053 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5055 * Installs an accelerator for this @widget in @accel_group that causes
5056 * @accel_signal to be emitted if the accelerator is activated.
5057 * The @accel_group needs to be added to the widget's toplevel via
5058 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5059 * Accelerators added through this function are not user changeable during
5060 * runtime. If you want to support accelerators that can be changed by the
5061 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5062 * gtk_menu_item_set_accel_path() instead.
5065 gtk_widget_add_accelerator (GtkWidget *widget,
5066 const gchar *accel_signal,
5067 GtkAccelGroup *accel_group,
5069 GdkModifierType accel_mods,
5070 GtkAccelFlags accel_flags)
5075 g_return_if_fail (GTK_IS_WIDGET (widget));
5076 g_return_if_fail (accel_signal != NULL);
5077 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5079 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5080 if (!query.signal_id ||
5081 !(query.signal_flags & G_SIGNAL_ACTION) ||
5082 query.return_type != G_TYPE_NONE ||
5085 /* hmm, should be elaborate enough */
5086 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5087 G_OBJECT_TYPE_NAME (widget), accel_signal);
5091 closure = widget_new_accel_closure (widget, query.signal_id);
5093 g_object_ref (widget);
5095 /* install the accelerator. since we don't map this onto an accel_path,
5096 * the accelerator will automatically be locked.
5098 gtk_accel_group_connect (accel_group,
5101 accel_flags | GTK_ACCEL_LOCKED,
5104 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5106 g_object_unref (widget);
5110 * gtk_widget_remove_accelerator:
5111 * @widget: widget to install an accelerator on
5112 * @accel_group: accel group for this widget
5113 * @accel_key: GDK keyval of the accelerator
5114 * @accel_mods: modifier key combination of the accelerator
5115 * @returns: whether an accelerator was installed and could be removed
5117 * Removes an accelerator from @widget, previously installed with
5118 * gtk_widget_add_accelerator().
5121 gtk_widget_remove_accelerator (GtkWidget *widget,
5122 GtkAccelGroup *accel_group,
5124 GdkModifierType accel_mods)
5126 GtkAccelGroupEntry *ag_entry;
5127 GList *slist, *clist;
5130 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5131 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5133 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5134 clist = gtk_widget_list_accel_closures (widget);
5135 for (slist = clist; slist; slist = slist->next)
5139 for (i = 0; i < n; i++)
5140 if (slist->data == (gpointer) ag_entry[i].closure)
5142 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5144 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5146 g_list_free (clist);
5151 g_list_free (clist);
5153 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5154 accel_key, accel_mods, accel_group,
5155 G_OBJECT_TYPE_NAME (widget), widget);
5161 * gtk_widget_list_accel_closures:
5162 * @widget: widget to list accelerator closures for
5164 * Lists the closures used by @widget for accelerator group connections
5165 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5166 * The closures can be used to monitor accelerator changes on @widget,
5167 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5168 * #GtkAccelGroup of a closure which can be found out with
5169 * gtk_accel_group_from_accel_closure().
5171 * Return value: (transfer container) (element-type GClosure):
5172 * a newly allocated #GList of closures
5175 gtk_widget_list_accel_closures (GtkWidget *widget)
5178 GList *clist = NULL;
5180 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5182 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5183 if (gtk_accel_group_from_accel_closure (slist->data))
5184 clist = g_list_prepend (clist, slist->data);
5190 GtkAccelGroup *accel_group;
5195 destroy_accel_path (gpointer data)
5197 AccelPath *apath = data;
5199 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5201 /* closures_destroy takes care of unrefing the closure */
5202 g_object_unref (apath->accel_group);
5204 g_slice_free (AccelPath, apath);
5209 * gtk_widget_set_accel_path:
5210 * @widget: a #GtkWidget
5211 * @accel_path: (allow-none): path used to look up the accelerator
5212 * @accel_group: (allow-none): a #GtkAccelGroup.
5214 * Given an accelerator group, @accel_group, and an accelerator path,
5215 * @accel_path, sets up an accelerator in @accel_group so whenever the
5216 * key binding that is defined for @accel_path is pressed, @widget
5217 * will be activated. This removes any accelerators (for any
5218 * accelerator group) installed by previous calls to
5219 * gtk_widget_set_accel_path(). Associating accelerators with
5220 * paths allows them to be modified by the user and the modifications
5221 * to be saved for future use. (See gtk_accel_map_save().)
5223 * This function is a low level function that would most likely
5224 * be used by a menu creation system like #GtkUIManager. If you
5225 * use #GtkUIManager, setting up accelerator paths will be done
5228 * Even when you you aren't using #GtkUIManager, if you only want to
5229 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5230 * provides a somewhat more convenient interface.
5232 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5233 * pass a static string, you can save some memory by interning it first with
5234 * g_intern_static_string().
5237 gtk_widget_set_accel_path (GtkWidget *widget,
5238 const gchar *accel_path,
5239 GtkAccelGroup *accel_group)
5243 g_return_if_fail (GTK_IS_WIDGET (widget));
5244 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5248 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5249 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5251 gtk_accel_map_add_entry (accel_path, 0, 0);
5252 apath = g_slice_new (AccelPath);
5253 apath->accel_group = g_object_ref (accel_group);
5254 apath->path_quark = g_quark_from_string (accel_path);
5255 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5260 /* also removes possible old settings */
5261 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5264 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5266 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5270 _gtk_widget_get_accel_path (GtkWidget *widget,
5275 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5277 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5279 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5280 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5284 * gtk_widget_mnemonic_activate:
5285 * @widget: a #GtkWidget
5286 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5288 * Emits the #GtkWidget::mnemonic-activate signal.
5290 * The default handler for this signal activates the @widget if
5291 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5294 * Returns: %TRUE if the signal has been handled
5297 gtk_widget_mnemonic_activate (GtkWidget *widget,
5298 gboolean group_cycling)
5302 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5304 group_cycling = group_cycling != FALSE;
5305 if (!gtk_widget_is_sensitive (widget))
5308 g_signal_emit (widget,
5309 widget_signals[MNEMONIC_ACTIVATE],
5317 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5318 gboolean group_cycling)
5320 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5321 gtk_widget_activate (widget);
5322 else if (gtk_widget_get_can_focus (widget))
5323 gtk_widget_grab_focus (widget);
5326 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5327 G_OBJECT_TYPE_NAME (widget));
5328 gtk_widget_error_bell (widget);
5333 static const cairo_user_data_key_t event_key;
5336 _gtk_cairo_get_event (cairo_t *cr)
5338 g_return_val_if_fail (cr != NULL, NULL);
5340 return cairo_get_user_data (cr, &event_key);
5344 gtk_cairo_set_event (cairo_t *cr,
5345 GdkEventExpose *event)
5347 cairo_set_user_data (cr, &event_key, event, NULL);
5351 * gtk_cairo_should_draw_window:
5352 * @cr: a cairo context
5353 * @window: the window to check
5355 * This function is supposed to be called in #GtkWidget::draw
5356 * implementations for widgets that support multiple windows.
5357 * @cr must be untransformed from invoking of the draw function.
5358 * This function will return %TRUE if the contents of the given
5359 * @window are supposed to be drawn and %FALSE otherwise. Note
5360 * that when the drawing was not initiated by the windowing
5361 * system this function will return %TRUE for all windows, so
5362 * you need to draw the bottommost window first. Also, do not
5363 * use "else if" statements to check which window should be drawn.
5365 * Returns: %TRUE if @window should be drawn
5368 gtk_cairo_should_draw_window (cairo_t *cr,
5371 GdkEventExpose *event;
5373 g_return_val_if_fail (cr != NULL, FALSE);
5374 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5376 event = _gtk_cairo_get_event (cr);
5378 return event == NULL ||
5379 event->window == window;
5382 /* code shared by gtk_container_propagate_draw() and
5386 _gtk_widget_draw_internal (GtkWidget *widget,
5388 gboolean clip_to_size)
5390 if (!gtk_widget_is_drawable (widget))
5395 cairo_rectangle (cr,
5397 widget->priv->allocation.width,
5398 widget->priv->allocation.height);
5402 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5406 g_signal_emit (widget, widget_signals[DRAW],
5414 * @widget: the widget to draw. It must be drawable (see
5415 * gtk_widget_is_drawable()) and a size must have been allocated.
5416 * @cr: a cairo context to draw to
5418 * Draws @widget to @cr. The top left corner of the widget will be
5419 * drawn to the currently set origin point of @cr.
5421 * You should pass a cairo context as @cr argument that is in an
5422 * original state. Otherwise the resulting drawing is undefined. For
5423 * example changing the operator using cairo_set_operator() or the
5424 * line width using cairo_set_line_width() might have unwanted side
5426 * You may however change the context's transform matrix - like with
5427 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5428 * region with cairo_clip() prior to calling this function. Also, it
5429 * is fine to modify the context with cairo_save() and
5430 * cairo_push_group() prior to calling this function.
5432 * <note><para>Special purpose widgets may contain special code for
5433 * rendering to the screen and might appear differently on screen
5434 * and when rendered using gtk_widget_draw().</para></note>
5437 gtk_widget_draw (GtkWidget *widget,
5440 GdkEventExpose *tmp_event;
5442 g_return_if_fail (GTK_IS_WIDGET (widget));
5443 g_return_if_fail (!widget->priv->alloc_needed);
5444 g_return_if_fail (cr != NULL);
5447 /* We have to reset the event here so that draw functions can call
5448 * gtk_widget_draw() on random other widgets and get the desired
5449 * effect: Drawing all contents, not just the current window.
5451 tmp_event = _gtk_cairo_get_event (cr);
5452 gtk_cairo_set_event (cr, NULL);
5454 _gtk_widget_draw_internal (widget, cr, TRUE);
5456 gtk_cairo_set_event (cr, tmp_event);
5461 gtk_widget_real_key_press_event (GtkWidget *widget,
5464 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5468 gtk_widget_real_key_release_event (GtkWidget *widget,
5471 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5475 gtk_widget_real_focus_in_event (GtkWidget *widget,
5476 GdkEventFocus *event)
5478 gtk_widget_queue_shallow_draw (widget);
5484 gtk_widget_real_focus_out_event (GtkWidget *widget,
5485 GdkEventFocus *event)
5487 gtk_widget_queue_shallow_draw (widget);
5492 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5493 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5497 * @widget: a #GtkWidget
5498 * @event: a #GdkEvent
5500 * Rarely-used function. This function is used to emit
5501 * the event signals on a widget (those signals should never
5502 * be emitted without using this function to do so).
5503 * If you want to synthesize an event though, don't use this function;
5504 * instead, use gtk_main_do_event() so the event will behave as if
5505 * it were in the event queue. Don't synthesize expose events; instead,
5506 * use gdk_window_invalidate_rect() to invalidate a region of the
5509 * Return value: return from the event signal emission (%TRUE if
5510 * the event was handled)
5513 gtk_widget_event (GtkWidget *widget,
5516 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5517 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5519 if (event->type == GDK_EXPOSE)
5521 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5522 "the same effect, call gdk_window_invalidate_rect/region(), "
5523 "followed by gdk_window_process_updates().");
5527 return gtk_widget_event_internal (widget, event);
5530 /* Returns TRUE if a translation should be done */
5532 gtk_widget_get_translation_to_window (GtkWidget *widget,
5537 GdkWindow *w, *widget_window;
5539 if (!gtk_widget_get_has_window (widget))
5541 *x = -widget->priv->allocation.x;
5542 *y = -widget->priv->allocation.y;
5550 widget_window = gtk_widget_get_window (widget);
5552 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5555 gdk_window_get_position (w, &wx, &wy);
5572 * gtk_cairo_transform_to_window:
5573 * @cr: the cairo context to transform
5574 * @widget: the widget the context is currently centered for
5575 * @window: the window to transform the context to
5577 * Transforms the given cairo context @cr that from @widget-relative
5578 * coordinates to @window-relative coordinates.
5579 * If the @widget's window is not an ancestor of @window, no
5580 * modification will be applied.
5582 * This is the inverse to the transformation GTK applies when
5583 * preparing an expose event to be emitted with the #GtkWidget::draw
5584 * signal. It is intended to help porting multiwindow widgets from
5585 * GTK+ 2 to the rendering architecture of GTK+ 3.
5588 gtk_cairo_transform_to_window (cairo_t *cr,
5594 g_return_if_fail (cr != NULL);
5595 g_return_if_fail (GTK_IS_WIDGET (widget));
5596 g_return_if_fail (GDK_IS_WINDOW (window));
5598 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5599 cairo_translate (cr, x, y);
5603 * gtk_widget_send_expose:
5604 * @widget: a #GtkWidget
5605 * @event: a expose #GdkEvent
5607 * Very rarely-used function. This function is used to emit
5608 * an expose event on a widget. This function is not normally used
5609 * directly. The only time it is used is when propagating an expose
5610 * event to a child %NO_WINDOW widget, and that is normally done
5611 * using gtk_container_propagate_draw().
5613 * If you want to force an area of a window to be redrawn,
5614 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5615 * To cause the redraw to be done immediately, follow that call
5616 * with a call to gdk_window_process_updates().
5618 * Return value: return from the event signal emission (%TRUE if
5619 * the event was handled)
5622 gtk_widget_send_expose (GtkWidget *widget,
5625 gboolean result = FALSE;
5630 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5631 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5632 g_return_val_if_fail (event != NULL, TRUE);
5633 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5635 cr = gdk_cairo_create (event->expose.window);
5636 gtk_cairo_set_event (cr, &event->expose);
5638 gdk_cairo_region (cr, event->expose.region);
5641 do_clip = gtk_widget_get_translation_to_window (widget,
5642 event->expose.window,
5644 cairo_translate (cr, -x, -y);
5646 _gtk_widget_draw_internal (widget, cr, do_clip);
5648 /* unset here, so if someone keeps a reference to cr we
5649 * don't leak the window. */
5650 gtk_cairo_set_event (cr, NULL);
5657 event_window_is_still_viewable (GdkEvent *event)
5659 /* Check that we think the event's window is viewable before
5660 * delivering the event, to prevent suprises. We do this here
5661 * at the last moment, since the event may have been queued
5662 * up behind other events, held over a recursive main loop, etc.
5664 switch (event->type)
5667 case GDK_MOTION_NOTIFY:
5668 case GDK_BUTTON_PRESS:
5669 case GDK_2BUTTON_PRESS:
5670 case GDK_3BUTTON_PRESS:
5672 case GDK_ENTER_NOTIFY:
5673 case GDK_PROXIMITY_IN:
5675 return event->any.window && gdk_window_is_viewable (event->any.window);
5678 /* The following events are the second half of paired events;
5679 * we always deliver them to deal with widgets that clean up
5680 * on the second half.
5682 case GDK_BUTTON_RELEASE:
5683 case GDK_KEY_RELEASE:
5684 case GDK_LEAVE_NOTIFY:
5685 case GDK_PROXIMITY_OUT:
5689 /* Remaining events would make sense on an not-viewable window,
5690 * or don't have an associated window.
5697 gtk_widget_event_internal (GtkWidget *widget,
5700 gboolean return_val = FALSE;
5702 /* We check only once for is-still-visible; if someone
5703 * hides the window in on of the signals on the widget,
5704 * they are responsible for returning TRUE to terminate
5707 if (!event_window_is_still_viewable (event))
5710 g_object_ref (widget);
5712 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5713 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5718 switch (event->type)
5723 case GDK_BUTTON_PRESS:
5724 case GDK_2BUTTON_PRESS:
5725 case GDK_3BUTTON_PRESS:
5726 signal_num = BUTTON_PRESS_EVENT;
5729 signal_num = SCROLL_EVENT;
5731 case GDK_BUTTON_RELEASE:
5732 signal_num = BUTTON_RELEASE_EVENT;
5734 case GDK_MOTION_NOTIFY:
5735 signal_num = MOTION_NOTIFY_EVENT;
5738 signal_num = DELETE_EVENT;
5741 signal_num = DESTROY_EVENT;
5742 _gtk_tooltip_hide (widget);
5745 signal_num = KEY_PRESS_EVENT;
5747 case GDK_KEY_RELEASE:
5748 signal_num = KEY_RELEASE_EVENT;
5750 case GDK_ENTER_NOTIFY:
5751 signal_num = ENTER_NOTIFY_EVENT;
5753 case GDK_LEAVE_NOTIFY:
5754 signal_num = LEAVE_NOTIFY_EVENT;
5756 case GDK_FOCUS_CHANGE:
5757 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5758 if (event->focus_change.in)
5759 _gtk_tooltip_focus_in (widget);
5761 _gtk_tooltip_focus_out (widget);
5764 signal_num = CONFIGURE_EVENT;
5767 signal_num = MAP_EVENT;
5770 signal_num = UNMAP_EVENT;
5772 case GDK_WINDOW_STATE:
5773 signal_num = WINDOW_STATE_EVENT;
5775 case GDK_PROPERTY_NOTIFY:
5776 signal_num = PROPERTY_NOTIFY_EVENT;
5778 case GDK_SELECTION_CLEAR:
5779 signal_num = SELECTION_CLEAR_EVENT;
5781 case GDK_SELECTION_REQUEST:
5782 signal_num = SELECTION_REQUEST_EVENT;
5784 case GDK_SELECTION_NOTIFY:
5785 signal_num = SELECTION_NOTIFY_EVENT;
5787 case GDK_PROXIMITY_IN:
5788 signal_num = PROXIMITY_IN_EVENT;
5790 case GDK_PROXIMITY_OUT:
5791 signal_num = PROXIMITY_OUT_EVENT;
5793 case GDK_CLIENT_EVENT:
5794 signal_num = CLIENT_EVENT;
5797 signal_num = EXPOSE_EVENT;
5799 case GDK_VISIBILITY_NOTIFY:
5800 signal_num = VISIBILITY_NOTIFY_EVENT;
5802 case GDK_GRAB_BROKEN:
5803 signal_num = GRAB_BROKEN_EVENT;
5806 signal_num = DAMAGE_EVENT;
5809 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5813 if (signal_num != -1)
5814 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5816 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5817 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5821 g_object_unref (widget);
5827 * gtk_widget_activate:
5828 * @widget: a #GtkWidget that's activatable
5830 * For widgets that can be "activated" (buttons, menu items, etc.)
5831 * this function activates them. Activation is what happens when you
5832 * press Enter on a widget during key navigation. If @widget isn't
5833 * activatable, the function returns %FALSE.
5835 * Return value: %TRUE if the widget was activatable
5838 gtk_widget_activate (GtkWidget *widget)
5840 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5842 if (WIDGET_CLASS (widget)->activate_signal)
5844 /* FIXME: we should eventually check the signals signature here */
5845 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5854 gtk_widget_reparent_subwindows (GtkWidget *widget,
5855 GdkWindow *new_window)
5857 GtkWidgetPrivate *priv = widget->priv;
5859 if (!gtk_widget_get_has_window (widget))
5861 GList *children = gdk_window_get_children (priv->window);
5864 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5866 GdkWindow *window = tmp_list->data;
5869 gdk_window_get_user_data (window, &child);
5870 while (child && child != widget)
5871 child = ((GtkWidget*) child)->priv->parent;
5874 gdk_window_reparent (window, new_window, 0, 0);
5877 g_list_free (children);
5882 GList *tmp_list, *children;
5884 parent = gdk_window_get_parent (priv->window);
5887 gdk_window_reparent (priv->window, new_window, 0, 0);
5890 children = gdk_window_get_children (parent);
5892 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5894 GdkWindow *window = tmp_list->data;
5897 gdk_window_get_user_data (window, &child);
5899 if (child == widget)
5900 gdk_window_reparent (window, new_window, 0, 0);
5903 g_list_free (children);
5909 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5910 gpointer client_data)
5912 GtkWidgetPrivate *priv = widget->priv;
5914 g_assert (client_data != NULL);
5916 if (!gtk_widget_get_has_window (widget))
5919 g_object_unref (priv->window);
5920 priv->window = (GdkWindow*) client_data;
5922 g_object_ref (priv->window);
5924 if (GTK_IS_CONTAINER (widget))
5925 gtk_container_forall (GTK_CONTAINER (widget),
5926 gtk_widget_reparent_fixup_child,
5932 * gtk_widget_reparent:
5933 * @widget: a #GtkWidget
5934 * @new_parent: a #GtkContainer to move the widget into
5936 * Moves a widget from one #GtkContainer to another, handling reference
5937 * count issues to avoid destroying the widget.
5940 gtk_widget_reparent (GtkWidget *widget,
5941 GtkWidget *new_parent)
5943 GtkWidgetPrivate *priv;
5945 g_return_if_fail (GTK_IS_WIDGET (widget));
5946 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5947 priv = widget->priv;
5948 g_return_if_fail (priv->parent != NULL);
5950 if (priv->parent != new_parent)
5952 /* First try to see if we can get away without unrealizing
5953 * the widget as we reparent it. if so we set a flag so
5954 * that gtk_widget_unparent doesn't unrealize widget
5956 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5957 priv->in_reparent = TRUE;
5959 g_object_ref (widget);
5960 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5961 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5962 g_object_unref (widget);
5964 if (priv->in_reparent)
5966 priv->in_reparent = FALSE;
5968 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5969 gtk_widget_reparent_fixup_child (widget,
5970 gtk_widget_get_parent_window (widget));
5973 g_object_notify (G_OBJECT (widget), "parent");
5978 * gtk_widget_intersect:
5979 * @widget: a #GtkWidget
5980 * @area: a rectangle
5981 * @intersection: rectangle to store intersection of @widget and @area
5983 * Computes the intersection of a @widget's area and @area, storing
5984 * the intersection in @intersection, and returns %TRUE if there was
5985 * an intersection. @intersection may be %NULL if you're only
5986 * interested in whether there was an intersection.
5988 * Return value: %TRUE if there was an intersection
5991 gtk_widget_intersect (GtkWidget *widget,
5992 const GdkRectangle *area,
5993 GdkRectangle *intersection)
5995 GtkWidgetPrivate *priv;
6000 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6001 g_return_val_if_fail (area != NULL, FALSE);
6003 priv = widget->priv;
6006 dest = intersection;
6010 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6012 if (return_val && intersection && gtk_widget_get_has_window (widget))
6014 intersection->x -= priv->allocation.x;
6015 intersection->y -= priv->allocation.y;
6022 * gtk_widget_region_intersect:
6023 * @widget: a #GtkWidget
6024 * @region: a #cairo_region_t, in the same coordinate system as
6025 * @widget->allocation. That is, relative to @widget->window
6026 * for %NO_WINDOW widgets; relative to the parent window
6027 * of @widget->window for widgets with their own window.
6028 * @returns: A newly allocated region holding the intersection of @widget
6029 * and @region. The coordinates of the return value are
6030 * relative to @widget->window for %NO_WINDOW widgets, and
6031 * relative to the parent window of @widget->window for
6032 * widgets with their own window.
6034 * Computes the intersection of a @widget's area and @region, returning
6035 * the intersection. The result may be empty, use cairo_region_is_empty() to
6039 gtk_widget_region_intersect (GtkWidget *widget,
6040 const cairo_region_t *region)
6043 cairo_region_t *dest;
6045 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6046 g_return_val_if_fail (region != NULL, NULL);
6048 gtk_widget_get_allocation (widget, &rect);
6050 dest = cairo_region_create_rectangle (&rect);
6052 cairo_region_intersect (dest, region);
6058 * _gtk_widget_grab_notify:
6059 * @widget: a #GtkWidget
6060 * @was_grabbed: whether a grab is now in effect
6062 * Emits the #GtkWidget::grab-notify signal on @widget.
6067 _gtk_widget_grab_notify (GtkWidget *widget,
6068 gboolean was_grabbed)
6070 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6074 * gtk_widget_grab_focus:
6075 * @widget: a #GtkWidget
6077 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6078 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6079 * something like #GtkFrame won't work.
6081 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6082 * gtk_widget_set_can_focus() to modify that flag.
6084 * The widget also needs to be realized and mapped. This is indicated by the
6085 * related signals. Grabbing the focus immediately after creating the widget
6086 * will likely fail and cause critical warnings.
6089 gtk_widget_grab_focus (GtkWidget *widget)
6091 g_return_if_fail (GTK_IS_WIDGET (widget));
6093 if (!gtk_widget_is_sensitive (widget))
6096 g_object_ref (widget);
6097 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6098 g_object_notify (G_OBJECT (widget), "has-focus");
6099 g_object_unref (widget);
6103 reset_focus_recurse (GtkWidget *widget,
6106 if (GTK_IS_CONTAINER (widget))
6108 GtkContainer *container;
6110 container = GTK_CONTAINER (widget);
6111 gtk_container_set_focus_child (container, NULL);
6113 gtk_container_foreach (container,
6114 reset_focus_recurse,
6120 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6122 if (gtk_widget_get_can_focus (focus_widget))
6124 GtkWidget *toplevel;
6127 /* clear the current focus setting, break if the current widget
6128 * is the focus widget's parent, since containers above that will
6129 * be set by the next loop.
6131 toplevel = gtk_widget_get_toplevel (focus_widget);
6132 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6134 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6136 if (widget == focus_widget)
6138 /* We call _gtk_window_internal_set_focus() here so that the
6139 * toplevel window can request the focus if necessary.
6140 * This is needed when the toplevel is a GtkPlug
6142 if (!gtk_widget_has_focus (widget))
6143 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6150 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6152 widget = widget->priv->parent;
6153 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6157 else if (toplevel != focus_widget)
6159 /* gtk_widget_grab_focus() operates on a tree without window...
6160 * actually, this is very questionable behaviour.
6163 gtk_container_foreach (GTK_CONTAINER (toplevel),
6164 reset_focus_recurse,
6168 /* now propagate the new focus up the widget tree and finally
6169 * set it on the window
6171 widget = focus_widget;
6172 while (widget->priv->parent)
6174 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6175 widget = widget->priv->parent;
6177 if (GTK_IS_WINDOW (widget))
6178 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6183 gtk_widget_real_query_tooltip (GtkWidget *widget,
6186 gboolean keyboard_tip,
6187 GtkTooltip *tooltip)
6189 gchar *tooltip_markup;
6190 gboolean has_tooltip;
6192 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6193 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6195 if (has_tooltip && tooltip_markup)
6197 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6205 gtk_widget_real_show_help (GtkWidget *widget,
6206 GtkWidgetHelpType help_type)
6208 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6210 _gtk_tooltip_toggle_keyboard_mode (widget);
6219 gtk_widget_real_focus (GtkWidget *widget,
6220 GtkDirectionType direction)
6222 if (!gtk_widget_get_can_focus (widget))
6225 if (!gtk_widget_is_focus (widget))
6227 gtk_widget_grab_focus (widget);
6235 gtk_widget_real_move_focus (GtkWidget *widget,
6236 GtkDirectionType direction)
6238 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6240 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6242 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6248 gtk_widget_real_keynav_failed (GtkWidget *widget,
6249 GtkDirectionType direction)
6251 gboolean cursor_only;
6255 case GTK_DIR_TAB_FORWARD:
6256 case GTK_DIR_TAB_BACKWARD:
6263 g_object_get (gtk_widget_get_settings (widget),
6264 "gtk-keynav-cursor-only", &cursor_only,
6271 gtk_widget_error_bell (widget);
6277 * gtk_widget_set_can_focus:
6278 * @widget: a #GtkWidget
6279 * @can_focus: whether or not @widget can own the input focus.
6281 * Specifies whether @widget can own the input focus. See
6282 * gtk_widget_grab_focus() for actually setting the input focus on a
6288 gtk_widget_set_can_focus (GtkWidget *widget,
6291 g_return_if_fail (GTK_IS_WIDGET (widget));
6293 if (widget->priv->can_focus != can_focus)
6295 widget->priv->can_focus = can_focus;
6297 gtk_widget_queue_resize (widget);
6298 g_object_notify (G_OBJECT (widget), "can-focus");
6303 * gtk_widget_get_can_focus:
6304 * @widget: a #GtkWidget
6306 * Determines whether @widget can own the input focus. See
6307 * gtk_widget_set_can_focus().
6309 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6314 gtk_widget_get_can_focus (GtkWidget *widget)
6316 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6318 return widget->priv->can_focus;
6322 * gtk_widget_has_focus:
6323 * @widget: a #GtkWidget
6325 * Determines if the widget has the global input focus. See
6326 * gtk_widget_is_focus() for the difference between having the global
6327 * input focus, and only having the focus within a toplevel.
6329 * Return value: %TRUE if the widget has the global input focus.
6334 gtk_widget_has_focus (GtkWidget *widget)
6336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6338 return widget->priv->has_focus;
6342 * gtk_widget_is_focus:
6343 * @widget: a #GtkWidget
6345 * Determines if the widget is the focus widget within its
6346 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6347 * necessarily set; %HAS_FOCUS will only be set if the
6348 * toplevel widget additionally has the global input focus.)
6350 * Return value: %TRUE if the widget is the focus widget.
6353 gtk_widget_is_focus (GtkWidget *widget)
6355 GtkWidget *toplevel;
6357 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6359 toplevel = gtk_widget_get_toplevel (widget);
6361 if (GTK_IS_WINDOW (toplevel))
6362 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6368 * gtk_widget_set_can_default:
6369 * @widget: a #GtkWidget
6370 * @can_default: whether or not @widget can be a default widget.
6372 * Specifies whether @widget can be a default widget. See
6373 * gtk_widget_grab_default() for details about the meaning of
6379 gtk_widget_set_can_default (GtkWidget *widget,
6380 gboolean can_default)
6382 g_return_if_fail (GTK_IS_WIDGET (widget));
6384 if (widget->priv->can_default != can_default)
6386 widget->priv->can_default = can_default;
6388 gtk_widget_queue_resize (widget);
6389 g_object_notify (G_OBJECT (widget), "can-default");
6394 * gtk_widget_get_can_default:
6395 * @widget: a #GtkWidget
6397 * Determines whether @widget can be a default widget. See
6398 * gtk_widget_set_can_default().
6400 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6405 gtk_widget_get_can_default (GtkWidget *widget)
6407 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6409 return widget->priv->can_default;
6413 * gtk_widget_has_default:
6414 * @widget: a #GtkWidget
6416 * Determines whether @widget is the current default widget within its
6417 * toplevel. See gtk_widget_set_can_default().
6419 * Return value: %TRUE if @widget is the current default widget within
6420 * its toplevel, %FALSE otherwise
6425 gtk_widget_has_default (GtkWidget *widget)
6427 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6429 return widget->priv->has_default;
6433 _gtk_widget_set_has_default (GtkWidget *widget,
6434 gboolean has_default)
6436 widget->priv->has_default = has_default;
6440 * gtk_widget_grab_default:
6441 * @widget: a #GtkWidget
6443 * Causes @widget to become the default widget. @widget must have the
6444 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6445 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6446 * %TRUE)</literal>. The default widget is activated when
6447 * the user presses Enter in a window. Default widgets must be
6448 * activatable, that is, gtk_widget_activate() should affect them. Note
6449 * that #GtkEntry widgets require the "activates-default" property
6450 * set to %TRUE before they activate the default widget when Enter
6451 * is pressed and the #GtkEntry is focused.
6454 gtk_widget_grab_default (GtkWidget *widget)
6458 g_return_if_fail (GTK_IS_WIDGET (widget));
6459 g_return_if_fail (gtk_widget_get_can_default (widget));
6461 window = gtk_widget_get_toplevel (widget);
6463 if (window && gtk_widget_is_toplevel (window))
6464 gtk_window_set_default (GTK_WINDOW (window), widget);
6466 g_warning (G_STRLOC ": widget not within a GtkWindow");
6470 * gtk_widget_set_receives_default:
6471 * @widget: a #GtkWidget
6472 * @receives_default: whether or not @widget can be a default widget.
6474 * Specifies whether @widget will be treated as the default widget
6475 * within its toplevel when it has the focus, even if another widget
6478 * See gtk_widget_grab_default() for details about the meaning of
6484 gtk_widget_set_receives_default (GtkWidget *widget,
6485 gboolean receives_default)
6487 g_return_if_fail (GTK_IS_WIDGET (widget));
6489 if (widget->priv->receives_default != receives_default)
6491 widget->priv->receives_default = receives_default;
6493 g_object_notify (G_OBJECT (widget), "receives-default");
6498 * gtk_widget_get_receives_default:
6499 * @widget: a #GtkWidget
6501 * Determines whether @widget is alyways treated as default widget
6502 * withing its toplevel when it has the focus, even if another widget
6505 * See gtk_widget_set_receives_default().
6507 * Return value: %TRUE if @widget acts as default widget when focussed,
6513 gtk_widget_get_receives_default (GtkWidget *widget)
6515 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6517 return widget->priv->receives_default;
6521 * gtk_widget_has_grab:
6522 * @widget: a #GtkWidget
6524 * Determines whether the widget is currently grabbing events, so it
6525 * is the only widget receiving input events (keyboard and mouse).
6527 * See also gtk_grab_add().
6529 * Return value: %TRUE if the widget is in the grab_widgets stack
6534 gtk_widget_has_grab (GtkWidget *widget)
6536 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6538 return widget->priv->has_grab;
6542 _gtk_widget_set_has_grab (GtkWidget *widget,
6545 widget->priv->has_grab = has_grab;
6549 * gtk_widget_device_is_shadowed:
6550 * @widget: a #GtkWidget
6551 * @device: a #GdkDevice
6553 * Returns %TRUE if @device has been shadowed by a GTK+
6554 * device grab on another widget, so it would stop sending
6555 * events to @widget. This may be used in the
6556 * #GtkWidget::grab-notify signal to check for specific
6557 * devices. See gtk_device_grab_add().
6559 * Returns: %TRUE if there is an ongoing grab on @device
6560 * by another #GtkWidget than @widget.
6565 gtk_widget_device_is_shadowed (GtkWidget *widget,
6568 GtkWindowGroup *group;
6569 GtkWidget *grab_widget, *toplevel;
6571 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6572 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6574 if (!gtk_widget_get_realized (widget))
6577 toplevel = gtk_widget_get_toplevel (widget);
6579 if (GTK_IS_WINDOW (toplevel))
6580 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6582 group = gtk_window_get_group (NULL);
6584 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6586 /* Widget not inside the hierarchy of grab_widget */
6588 widget != grab_widget &&
6589 !gtk_widget_is_ancestor (widget, grab_widget))
6592 grab_widget = gtk_window_group_get_current_grab (group);
6593 if (grab_widget && widget != grab_widget &&
6594 !gtk_widget_is_ancestor (widget, grab_widget))
6601 * gtk_widget_set_name:
6602 * @widget: a #GtkWidget
6603 * @name: name for the widget
6605 * Widgets can be named, which allows you to refer to them from a
6606 * gtkrc file. You can apply a style to widgets with a particular name
6607 * in the gtkrc file. See the documentation for gtkrc files (on the
6608 * same page as the docs for #GtkRcStyle).
6610 * Note that widget names are separated by periods in paths (see
6611 * gtk_widget_path()), so names with embedded periods may cause confusion.
6614 gtk_widget_set_name (GtkWidget *widget,
6617 GtkWidgetPrivate *priv;
6620 g_return_if_fail (GTK_IS_WIDGET (widget));
6622 priv = widget->priv;
6624 new_name = g_strdup (name);
6625 g_free (priv->name);
6626 priv->name = new_name;
6629 gtk_widget_reset_rc_style (widget);
6631 g_object_notify (G_OBJECT (widget), "name");
6635 * gtk_widget_get_name:
6636 * @widget: a #GtkWidget
6638 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6639 * significance of widget names.
6641 * Return value: name of the widget. This string is owned by GTK+ and
6642 * should not be modified or freed
6644 G_CONST_RETURN gchar*
6645 gtk_widget_get_name (GtkWidget *widget)
6647 GtkWidgetPrivate *priv;
6649 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6651 priv = widget->priv;
6655 return G_OBJECT_TYPE_NAME (widget);
6659 * gtk_widget_set_state:
6660 * @widget: a #GtkWidget
6661 * @state: new state for @widget
6663 * This function is for use in widget implementations. Sets the state
6664 * of a widget (insensitive, prelighted, etc.) Usually you should set
6665 * the state using wrapper functions such as gtk_widget_set_sensitive().
6668 gtk_widget_set_state (GtkWidget *widget,
6671 GtkWidgetPrivate *priv;
6673 g_return_if_fail (GTK_IS_WIDGET (widget));
6675 priv = widget->priv;
6677 if (state == gtk_widget_get_state (widget))
6680 if (state == GTK_STATE_INSENSITIVE)
6681 gtk_widget_set_sensitive (widget, FALSE);
6687 data.state_restoration = FALSE;
6688 data.use_forall = FALSE;
6690 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6692 data.parent_sensitive = TRUE;
6694 gtk_widget_propagate_state (widget, &data);
6696 if (gtk_widget_is_drawable (widget))
6697 gtk_widget_queue_draw (widget);
6702 * gtk_widget_get_state:
6703 * @widget: a #GtkWidget
6705 * Returns the widget's state. See gtk_widget_set_state().
6707 * Returns: the state of @widget.
6712 gtk_widget_get_state (GtkWidget *widget)
6714 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6716 return widget->priv->state;
6720 * gtk_widget_set_visible:
6721 * @widget: a #GtkWidget
6722 * @visible: whether the widget should be shown or not
6724 * Sets the visibility state of @widget. Note that setting this to
6725 * %TRUE doesn't mean the widget is actually viewable, see
6726 * gtk_widget_get_visible().
6728 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6729 * but is nicer to use when the visibility of the widget depends on
6735 gtk_widget_set_visible (GtkWidget *widget,
6738 g_return_if_fail (GTK_IS_WIDGET (widget));
6740 if (visible != gtk_widget_get_visible (widget))
6743 gtk_widget_show (widget);
6745 gtk_widget_hide (widget);
6750 _gtk_widget_set_visible_flag (GtkWidget *widget,
6753 widget->priv->visible = visible;
6757 * gtk_widget_get_visible:
6758 * @widget: a #GtkWidget
6760 * Determines whether the widget is visible. Note that this doesn't
6761 * take into account whether the widget's parent is also visible
6762 * or the widget is obscured in any way.
6764 * See gtk_widget_set_visible().
6766 * Return value: %TRUE if the widget is visible
6771 gtk_widget_get_visible (GtkWidget *widget)
6773 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6775 return widget->priv->visible;
6779 * gtk_widget_set_has_window:
6780 * @widget: a #GtkWidget
6781 * @has_window: whether or not @widget has a window.
6783 * Specifies whether @widget has a #GdkWindow of its own. Note that
6784 * all realized widgets have a non-%NULL "window" pointer
6785 * (gtk_widget_get_window() never returns a %NULL window when a widget
6786 * is realized), but for many of them it's actually the #GdkWindow of
6787 * one of its parent widgets. Widgets that do not create a %window for
6788 * themselves in #GtkWidget::realize must announce this by
6789 * calling this function with @has_window = %FALSE.
6791 * This function should only be called by widget implementations,
6792 * and they should call it in their init() function.
6797 gtk_widget_set_has_window (GtkWidget *widget,
6798 gboolean has_window)
6800 g_return_if_fail (GTK_IS_WIDGET (widget));
6802 widget->priv->no_window = !has_window;
6806 * gtk_widget_get_has_window:
6807 * @widget: a #GtkWidget
6809 * Determines whether @widget has a #GdkWindow of its own. See
6810 * gtk_widget_set_has_window().
6812 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6817 gtk_widget_get_has_window (GtkWidget *widget)
6819 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6821 return ! widget->priv->no_window;
6825 * gtk_widget_is_toplevel:
6826 * @widget: a #GtkWidget
6828 * Determines whether @widget is a toplevel widget. Currently only
6829 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6830 * widgets have no parent widget.
6832 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6837 gtk_widget_is_toplevel (GtkWidget *widget)
6839 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6841 return widget->priv->toplevel;
6845 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6846 gboolean is_toplevel)
6848 widget->priv->toplevel = is_toplevel;
6852 * gtk_widget_is_drawable:
6853 * @widget: a #GtkWidget
6855 * Determines whether @widget can be drawn to. A widget can be drawn
6856 * to if it is mapped and visible.
6858 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6863 gtk_widget_is_drawable (GtkWidget *widget)
6865 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6867 return (gtk_widget_get_visible (widget) &&
6868 gtk_widget_get_mapped (widget));
6872 * gtk_widget_get_realized:
6873 * @widget: a #GtkWidget
6875 * Determines whether @widget is realized.
6877 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6882 gtk_widget_get_realized (GtkWidget *widget)
6884 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6886 return widget->priv->realized;
6890 * gtk_widget_set_realized:
6891 * @widget: a #GtkWidget
6892 * @realized: %TRUE to mark the widget as realized
6894 * Marks the widget as being realized.
6896 * This function should only ever be called in a derived widget's
6897 * "realize" or "unrealize" implementation.
6902 gtk_widget_set_realized (GtkWidget *widget,
6905 g_return_if_fail (GTK_IS_WIDGET (widget));
6907 widget->priv->realized = realized;
6911 * gtk_widget_get_mapped:
6912 * @widget: a #GtkWidget
6914 * Whether the widget is mapped.
6916 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6921 gtk_widget_get_mapped (GtkWidget *widget)
6923 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6925 return widget->priv->mapped;
6929 * gtk_widget_set_mapped:
6930 * @widget: a #GtkWidget
6931 * @mapped: %TRUE to mark the widget as mapped
6933 * Marks the widget as being realized.
6935 * This function should only ever be called in a derived widget's
6936 * "map" or "unmap" implementation.
6941 gtk_widget_set_mapped (GtkWidget *widget,
6944 g_return_if_fail (GTK_IS_WIDGET (widget));
6946 widget->priv->mapped = mapped;
6950 * gtk_widget_set_app_paintable:
6951 * @widget: a #GtkWidget
6952 * @app_paintable: %TRUE if the application will paint on the widget
6954 * Sets whether the application intends to draw on the widget in
6955 * an #GtkWidget::draw handler.
6957 * This is a hint to the widget and does not affect the behavior of
6958 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6959 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6960 * the effect is to suppress default themed drawing of the widget's
6961 * background. (Children of the widget will still be drawn.) The application
6962 * is then entirely responsible for drawing the widget background.
6964 * Note that the background is still drawn when the widget is mapped.
6967 gtk_widget_set_app_paintable (GtkWidget *widget,
6968 gboolean app_paintable)
6970 g_return_if_fail (GTK_IS_WIDGET (widget));
6972 app_paintable = (app_paintable != FALSE);
6974 if (widget->priv->app_paintable != app_paintable)
6976 widget->priv->app_paintable = app_paintable;
6978 if (gtk_widget_is_drawable (widget))
6979 gtk_widget_queue_draw (widget);
6981 g_object_notify (G_OBJECT (widget), "app-paintable");
6986 * gtk_widget_get_app_paintable:
6987 * @widget: a #GtkWidget
6989 * Determines whether the application intends to draw on the widget in
6990 * an #GtkWidget::draw handler.
6992 * See gtk_widget_set_app_paintable()
6994 * Return value: %TRUE if the widget is app paintable
6999 gtk_widget_get_app_paintable (GtkWidget *widget)
7001 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7003 return widget->priv->app_paintable;
7007 * gtk_widget_set_double_buffered:
7008 * @widget: a #GtkWidget
7009 * @double_buffered: %TRUE to double-buffer a widget
7011 * Widgets are double buffered by default; you can use this function
7012 * to turn off the buffering. "Double buffered" simply means that
7013 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7014 * automatically around expose events sent to the
7015 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7016 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7017 * buffer to the screen. The result is that users see the window
7018 * update in one smooth step, and don't see individual graphics
7019 * primitives being rendered.
7021 * In very simple terms, double buffered widgets don't flicker,
7022 * so you would only use this function to turn off double buffering
7023 * if you had special needs and really knew what you were doing.
7025 * Note: if you turn off double-buffering, you have to handle
7026 * expose events, since even the clearing to the background color or
7027 * pixmap will not happen automatically (as it is done in
7028 * gdk_window_begin_paint()).
7031 gtk_widget_set_double_buffered (GtkWidget *widget,
7032 gboolean double_buffered)
7034 g_return_if_fail (GTK_IS_WIDGET (widget));
7036 double_buffered = (double_buffered != FALSE);
7038 if (widget->priv->double_buffered != double_buffered)
7040 widget->priv->double_buffered = double_buffered;
7042 g_object_notify (G_OBJECT (widget), "double-buffered");
7047 * gtk_widget_get_double_buffered:
7048 * @widget: a #GtkWidget
7050 * Determines whether the widget is double buffered.
7052 * See gtk_widget_set_double_buffered()
7054 * Return value: %TRUE if the widget is double buffered
7059 gtk_widget_get_double_buffered (GtkWidget *widget)
7061 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7063 return widget->priv->double_buffered;
7067 * gtk_widget_set_redraw_on_allocate:
7068 * @widget: a #GtkWidget
7069 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7070 * when it is allocated to a new size. Otherwise, only the
7071 * new portion of the widget will be redrawn.
7073 * Sets whether the entire widget is queued for drawing when its size
7074 * allocation changes. By default, this setting is %TRUE and
7075 * the entire widget is redrawn on every size change. If your widget
7076 * leaves the upper left unchanged when made bigger, turning this
7077 * setting off will improve performance.
7079 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7080 * off all allocation on resizing: the widget will not even redraw if
7081 * its position changes; this is to allow containers that don't draw
7082 * anything to avoid excess invalidations. If you set this flag on a
7083 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7084 * you are responsible for invalidating both the old and new allocation
7085 * of the widget when the widget is moved and responsible for invalidating
7086 * regions newly when the widget increases size.
7089 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7090 gboolean redraw_on_allocate)
7092 g_return_if_fail (GTK_IS_WIDGET (widget));
7094 widget->priv->redraw_on_alloc = redraw_on_allocate;
7098 * gtk_widget_set_sensitive:
7099 * @widget: a #GtkWidget
7100 * @sensitive: %TRUE to make the widget sensitive
7102 * Sets the sensitivity of a widget. A widget is sensitive if the user
7103 * can interact with it. Insensitive widgets are "grayed out" and the
7104 * user can't interact with them. Insensitive widgets are known as
7105 * "inactive", "disabled", or "ghosted" in some other toolkits.
7108 gtk_widget_set_sensitive (GtkWidget *widget,
7111 GtkWidgetPrivate *priv;
7114 g_return_if_fail (GTK_IS_WIDGET (widget));
7116 priv = widget->priv;
7118 sensitive = (sensitive != FALSE);
7120 if (widget->priv->sensitive == sensitive)
7125 widget->priv->sensitive = TRUE;
7126 data.state = priv->saved_state;
7130 widget->priv->sensitive = FALSE;
7131 data.state = gtk_widget_get_state (widget);
7133 data.state_restoration = TRUE;
7134 data.use_forall = TRUE;
7137 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7139 data.parent_sensitive = TRUE;
7141 gtk_widget_propagate_state (widget, &data);
7142 if (gtk_widget_is_drawable (widget))
7143 gtk_widget_queue_draw (widget);
7145 g_object_notify (G_OBJECT (widget), "sensitive");
7149 * gtk_widget_get_sensitive:
7150 * @widget: a #GtkWidget
7152 * Returns the widget's sensitivity (in the sense of returning
7153 * the value that has been set using gtk_widget_set_sensitive()).
7155 * The effective sensitivity of a widget is however determined by both its
7156 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7158 * Returns: %TRUE if the widget is sensitive
7163 gtk_widget_get_sensitive (GtkWidget *widget)
7165 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7167 return widget->priv->sensitive;
7171 * gtk_widget_is_sensitive:
7172 * @widget: a #GtkWidget
7174 * Returns the widget's effective sensitivity, which means
7175 * it is sensitive itself and also its parent widget is sensntive
7177 * Returns: %TRUE if the widget is effectively sensitive
7182 gtk_widget_is_sensitive (GtkWidget *widget)
7184 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7186 return widget->priv->sensitive && widget->priv->parent_sensitive;
7190 * gtk_widget_set_parent:
7191 * @widget: a #GtkWidget
7192 * @parent: parent container
7194 * This function is useful only when implementing subclasses of
7196 * Sets the container as the parent of @widget, and takes care of
7197 * some details such as updating the state and style of the child
7198 * to reflect its new location. The opposite function is
7199 * gtk_widget_unparent().
7202 gtk_widget_set_parent (GtkWidget *widget,
7205 GtkWidgetPrivate *priv;
7208 g_return_if_fail (GTK_IS_WIDGET (widget));
7209 g_return_if_fail (GTK_IS_WIDGET (parent));
7210 g_return_if_fail (widget != parent);
7212 priv = widget->priv;
7214 if (priv->parent != NULL)
7216 g_warning ("Can't set a parent on widget which has a parent\n");
7219 if (gtk_widget_is_toplevel (widget))
7221 g_warning ("Can't set a parent on a toplevel widget\n");
7225 /* keep this function in sync with gtk_menu_attach_to_widget()
7228 g_object_ref_sink (widget);
7229 priv->parent = parent;
7231 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7232 data.state = gtk_widget_get_state (parent);
7234 data.state = gtk_widget_get_state (widget);
7235 data.state_restoration = FALSE;
7236 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7237 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7239 gtk_widget_propagate_state (widget, &data);
7241 gtk_widget_reset_rc_styles (widget);
7243 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7244 if (priv->parent->priv->anchored)
7245 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7246 g_object_notify (G_OBJECT (widget), "parent");
7248 /* Enforce realized/mapped invariants
7250 if (gtk_widget_get_realized (priv->parent))
7251 gtk_widget_realize (widget);
7253 if (gtk_widget_get_visible (priv->parent) &&
7254 gtk_widget_get_visible (widget))
7256 if (gtk_widget_get_child_visible (widget) &&
7257 gtk_widget_get_mapped (priv->parent))
7258 gtk_widget_map (widget);
7260 gtk_widget_queue_resize (widget);
7263 /* child may cause parent's expand to change, if the child is
7264 * expanded. If child is not expanded, then it can't modify the
7265 * parent's expand. If the child becomes expanded later then it will
7266 * queue compute_expand then. This optimization plus defaulting
7267 * newly-constructed widgets to need_compute_expand=FALSE should
7268 * mean that initially building a widget tree doesn't have to keep
7269 * walking up setting need_compute_expand on parents over and over.
7271 * We can't change a parent to need to expand unless we're visible.
7273 if (gtk_widget_get_visible (widget) &&
7274 (priv->need_compute_expand ||
7275 priv->computed_hexpand ||
7276 priv->computed_vexpand))
7278 gtk_widget_queue_compute_expand (parent);
7283 * gtk_widget_get_parent:
7284 * @widget: a #GtkWidget
7286 * Returns the parent container of @widget.
7288 * Return value: (transfer none): the parent container of @widget, or %NULL
7291 gtk_widget_get_parent (GtkWidget *widget)
7293 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7295 return widget->priv->parent;
7298 /*****************************************
7300 * see docs/styles.txt
7301 *****************************************/
7304 * gtk_widget_style_attach:
7305 * @widget: a #GtkWidget
7307 * This function attaches the widget's #GtkStyle to the widget's
7308 * #GdkWindow. It is a replacement for
7311 * widget->style = gtk_style_attach (widget->style, widget->window);
7314 * and should only ever be called in a derived widget's "realize"
7315 * implementation which does not chain up to its parent class'
7316 * "realize" implementation, because one of the parent classes
7317 * (finally #GtkWidget) would attach the style itself.
7322 gtk_widget_style_attach (GtkWidget *widget)
7324 GtkWidgetPrivate *priv;
7326 g_return_if_fail (GTK_IS_WIDGET (widget));
7327 g_return_if_fail (gtk_widget_get_realized (widget));
7329 priv = widget->priv;
7331 priv->style = gtk_style_attach (priv->style, priv->window);
7335 * gtk_widget_has_rc_style:
7336 * @widget: a #GtkWidget
7338 * Determines if the widget style has been looked up through the rc mechanism.
7340 * Returns: %TRUE if the widget has been looked up through the rc
7341 * mechanism, %FALSE otherwise.
7346 gtk_widget_has_rc_style (GtkWidget *widget)
7348 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7350 return widget->priv->rc_style;
7354 * gtk_widget_set_style:
7355 * @widget: a #GtkWidget
7356 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7357 * gtk_widget_set_style() and go back to the default style
7359 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7360 * want to use this function; it interacts badly with themes, because
7361 * themes work by replacing the #GtkStyle. Instead, use
7362 * gtk_widget_modify_style().
7365 gtk_widget_set_style (GtkWidget *widget,
7368 g_return_if_fail (GTK_IS_WIDGET (widget));
7372 gboolean initial_emission;
7374 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7376 widget->priv->rc_style = FALSE;
7377 widget->priv->user_style = TRUE;
7379 gtk_widget_set_style_internal (widget, style, initial_emission);
7383 if (widget->priv->user_style)
7384 gtk_widget_reset_rc_style (widget);
7389 * gtk_widget_ensure_style:
7390 * @widget: a #GtkWidget
7392 * Ensures that @widget has a style (@widget->style). Not a very useful
7393 * function; most of the time, if you want the style, the widget is
7394 * realized, and realized widgets are guaranteed to have a style
7398 gtk_widget_ensure_style (GtkWidget *widget)
7400 g_return_if_fail (GTK_IS_WIDGET (widget));
7402 if (!widget->priv->rc_style && !widget->priv->user_style)
7403 gtk_widget_reset_rc_style (widget);
7406 /* Look up the RC style for this widget, unsetting any user style that
7407 * may be in effect currently
7410 gtk_widget_reset_rc_style (GtkWidget *widget)
7412 GtkWidgetPrivate *priv = widget->priv;
7413 GtkStyle *new_style = NULL;
7414 gboolean initial_emission;
7416 initial_emission = !priv->rc_style && !priv->user_style;
7418 priv->user_style = FALSE;
7419 priv->rc_style = TRUE;
7421 if (gtk_widget_has_screen (widget))
7422 new_style = gtk_rc_get_style (widget);
7424 new_style = gtk_widget_get_default_style ();
7426 if (initial_emission || new_style != priv->style)
7427 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7431 * gtk_widget_get_style:
7432 * @widget: a #GtkWidget
7434 * Simply an accessor function that returns @widget->style.
7436 * Return value: (transfer none): the widget's #GtkStyle
7439 gtk_widget_get_style (GtkWidget *widget)
7441 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7443 return widget->priv->style;
7447 * gtk_widget_modify_style:
7448 * @widget: a #GtkWidget
7449 * @style: the #GtkRcStyle holding the style modifications
7451 * Modifies style values on the widget. Modifications made using this
7452 * technique take precedence over style values set via an RC file,
7453 * however, they will be overriden if a style is explicitely set on
7454 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7455 * is designed so each field can either be set or unset, so it is
7456 * possible, using this function, to modify some style values and
7457 * leave the others unchanged.
7459 * Note that modifications made with this function are not cumulative
7460 * with previous calls to gtk_widget_modify_style() or with such
7461 * functions as gtk_widget_modify_fg(). If you wish to retain
7462 * previous values, you must first call gtk_widget_get_modifier_style(),
7463 * make your modifications to the returned style, then call
7464 * gtk_widget_modify_style() with that style. On the other hand,
7465 * if you first call gtk_widget_modify_style(), subsequent calls
7466 * to such functions gtk_widget_modify_fg() will have a cumulative
7467 * effect with the initial modifications.
7470 gtk_widget_modify_style (GtkWidget *widget,
7473 g_return_if_fail (GTK_IS_WIDGET (widget));
7474 g_return_if_fail (GTK_IS_RC_STYLE (style));
7476 g_object_set_qdata_full (G_OBJECT (widget),
7478 gtk_rc_style_copy (style),
7479 (GDestroyNotify) g_object_unref);
7481 /* note that "style" may be invalid here if it was the old
7482 * modifier style and the only reference was our own.
7485 if (widget->priv->rc_style)
7486 gtk_widget_reset_rc_style (widget);
7490 * gtk_widget_get_modifier_style:
7491 * @widget: a #GtkWidget
7493 * Returns the current modifier style for the widget. (As set by
7494 * gtk_widget_modify_style().) If no style has previously set, a new
7495 * #GtkRcStyle will be created with all values unset, and set as the
7496 * modifier style for the widget. If you make changes to this rc
7497 * style, you must call gtk_widget_modify_style(), passing in the
7498 * returned rc style, to make sure that your changes take effect.
7500 * Caution: passing the style back to gtk_widget_modify_style() will
7501 * normally end up destroying it, because gtk_widget_modify_style() copies
7502 * the passed-in style and sets the copy as the new modifier style,
7503 * thus dropping any reference to the old modifier style. Add a reference
7504 * to the modifier style if you want to keep it alive.
7506 * Return value: (transfer none): the modifier style for the widget. This rc style is
7507 * owned by the widget. If you want to keep a pointer to value this
7508 * around, you must add a refcount using g_object_ref().
7511 gtk_widget_get_modifier_style (GtkWidget *widget)
7513 GtkRcStyle *rc_style;
7515 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7517 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7521 rc_style = gtk_rc_style_new ();
7522 g_object_set_qdata_full (G_OBJECT (widget),
7525 (GDestroyNotify) g_object_unref);
7532 gtk_widget_modify_color_component (GtkWidget *widget,
7533 GtkRcFlags component,
7535 const GdkColor *color)
7537 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7544 rc_style->fg[state] = *color;
7547 rc_style->bg[state] = *color;
7550 rc_style->text[state] = *color;
7553 rc_style->base[state] = *color;
7556 g_assert_not_reached();
7559 rc_style->color_flags[state] |= component;
7562 rc_style->color_flags[state] &= ~component;
7564 gtk_widget_modify_style (widget, rc_style);
7568 * gtk_widget_modify_symbolic_color:
7569 * @widget: a #GtkWidget
7570 * @name: the name of the symbolic color to modify
7571 * @color: (allow-none): the color to assign (does not need to be allocated),
7572 * or %NULL to undo the effect of previous calls to
7573 * of gtk_widget_modify_symbolic_color().
7575 * Sets a symbolic color for a widget.
7576 * All other style values are left untouched. See also
7577 * gtk_widget_modify_style().
7582 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7584 const GdkColor *color)
7586 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7588 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7590 gtk_widget_modify_style (widget, rc_style);
7594 * gtk_widget_modify_fg:
7595 * @widget: a #GtkWidget
7596 * @state: the state for which to set the foreground color
7597 * @color: (allow-none): the color to assign (does not need to be allocated),
7598 * or %NULL to undo the effect of previous calls to
7599 * of gtk_widget_modify_fg().
7601 * Sets the foreground color for a widget in a particular state.
7602 * All other style values are left untouched. See also
7603 * gtk_widget_modify_style().
7606 gtk_widget_modify_fg (GtkWidget *widget,
7608 const GdkColor *color)
7610 g_return_if_fail (GTK_IS_WIDGET (widget));
7611 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7613 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7617 * gtk_widget_modify_bg:
7618 * @widget: a #GtkWidget
7619 * @state: the state for which to set the background color
7620 * @color: (allow-none): the color to assign (does not need to be allocated),
7621 * or %NULL to undo the effect of previous calls to
7622 * of gtk_widget_modify_bg().
7624 * Sets the background color for a widget in a particular state.
7625 * All other style values are left untouched. See also
7626 * gtk_widget_modify_style().
7628 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7629 * draw on their parent container's window and thus may not draw any
7630 * background themselves. This is the case for e.g. #GtkLabel. To modify
7631 * the background of such widgets, you have to set the background color
7632 * on their parent; if you want to set the background of a rectangular
7633 * area around a label, try placing the label in a #GtkEventBox widget
7634 * and setting the background color on that.
7637 gtk_widget_modify_bg (GtkWidget *widget,
7639 const GdkColor *color)
7641 g_return_if_fail (GTK_IS_WIDGET (widget));
7642 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7644 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7648 * gtk_widget_modify_text:
7649 * @widget: a #GtkWidget
7650 * @state: the state for which to set the text color
7651 * @color: (allow-none): the color to assign (does not need to be allocated),
7652 * or %NULL to undo the effect of previous calls to
7653 * of gtk_widget_modify_text().
7655 * Sets the text color for a widget in a particular state. All other
7656 * style values are left untouched. The text color is the foreground
7657 * color used along with the base color (see gtk_widget_modify_base())
7658 * for widgets such as #GtkEntry and #GtkTextView. See also
7659 * gtk_widget_modify_style().
7662 gtk_widget_modify_text (GtkWidget *widget,
7664 const GdkColor *color)
7666 g_return_if_fail (GTK_IS_WIDGET (widget));
7667 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7669 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7673 * gtk_widget_modify_base:
7674 * @widget: a #GtkWidget
7675 * @state: the state for which to set the base color
7676 * @color: (allow-none): the color to assign (does not need to be allocated),
7677 * or %NULL to undo the effect of previous calls to
7678 * of gtk_widget_modify_base().
7680 * Sets the base color for a widget in a particular state.
7681 * All other style values are left untouched. The base color
7682 * is the background color used along with the text color
7683 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7684 * and #GtkTextView. See also gtk_widget_modify_style().
7686 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7687 * draw on their parent container's window and thus may not draw any
7688 * background themselves. This is the case for e.g. #GtkLabel. To modify
7689 * the background of such widgets, you have to set the base color on their
7690 * parent; if you want to set the background of a rectangular area around
7691 * a label, try placing the label in a #GtkEventBox widget and setting
7692 * the base color on that.
7695 gtk_widget_modify_base (GtkWidget *widget,
7697 const GdkColor *color)
7699 g_return_if_fail (GTK_IS_WIDGET (widget));
7700 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7702 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7706 modify_color_property (GtkWidget *widget,
7707 GtkRcStyle *rc_style,
7709 const GdkColor *color)
7711 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7712 GQuark property_name = g_quark_from_string (name);
7716 GtkRcProperty rc_property = {0};
7719 rc_property.type_name = type_name;
7720 rc_property.property_name = property_name;
7721 rc_property.origin = NULL;
7723 color_name = gdk_color_to_string (color);
7724 g_value_init (&rc_property.value, G_TYPE_STRING);
7725 g_value_take_string (&rc_property.value, color_name);
7727 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7729 g_value_unset (&rc_property.value);
7732 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7736 * gtk_widget_modify_cursor:
7737 * @widget: a #GtkWidget
7738 * @primary: the color to use for primary cursor (does not need to be
7739 * allocated), or %NULL to undo the effect of previous calls to
7740 * of gtk_widget_modify_cursor().
7741 * @secondary: the color to use for secondary cursor (does not need to be
7742 * allocated), or %NULL to undo the effect of previous calls to
7743 * of gtk_widget_modify_cursor().
7745 * Sets the cursor color to use in a widget, overriding the
7746 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7747 * style properties. All other style values are left untouched.
7748 * See also gtk_widget_modify_style().
7753 gtk_widget_modify_cursor (GtkWidget *widget,
7754 const GdkColor *primary,
7755 const GdkColor *secondary)
7757 GtkRcStyle *rc_style;
7759 g_return_if_fail (GTK_IS_WIDGET (widget));
7761 rc_style = gtk_widget_get_modifier_style (widget);
7763 modify_color_property (widget, rc_style, "cursor-color", primary);
7764 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7766 gtk_widget_modify_style (widget, rc_style);
7770 * gtk_widget_modify_font:
7771 * @widget: a #GtkWidget
7772 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7773 * the effect of previous calls to gtk_widget_modify_font().
7775 * Sets the font to use for a widget. All other style values are left
7776 * untouched. See also gtk_widget_modify_style().
7779 gtk_widget_modify_font (GtkWidget *widget,
7780 PangoFontDescription *font_desc)
7782 GtkRcStyle *rc_style;
7784 g_return_if_fail (GTK_IS_WIDGET (widget));
7786 rc_style = gtk_widget_get_modifier_style (widget);
7788 if (rc_style->font_desc)
7789 pango_font_description_free (rc_style->font_desc);
7792 rc_style->font_desc = pango_font_description_copy (font_desc);
7794 rc_style->font_desc = NULL;
7796 gtk_widget_modify_style (widget, rc_style);
7800 gtk_widget_real_direction_changed (GtkWidget *widget,
7801 GtkTextDirection previous_direction)
7803 gtk_widget_queue_resize (widget);
7807 gtk_widget_real_style_set (GtkWidget *widget,
7808 GtkStyle *previous_style)
7810 GtkWidgetPrivate *priv = widget->priv;
7812 if (gtk_widget_get_realized (widget) &&
7813 gtk_widget_get_has_window (widget))
7814 gtk_style_set_background (priv->style, priv->window, priv->state);
7818 gtk_widget_set_style_internal (GtkWidget *widget,
7820 gboolean initial_emission)
7822 GtkWidgetPrivate *priv = widget->priv;
7824 g_object_ref (widget);
7825 g_object_freeze_notify (G_OBJECT (widget));
7827 if (priv->style != style)
7829 GtkStyle *previous_style;
7831 if (gtk_widget_get_realized (widget))
7833 gtk_widget_reset_shapes (widget);
7834 gtk_style_detach (priv->style);
7837 previous_style = priv->style;
7838 priv->style = style;
7839 g_object_ref (priv->style);
7841 if (gtk_widget_get_realized (widget))
7842 priv->style = gtk_style_attach (priv->style, priv->window);
7844 gtk_widget_update_pango_context (widget);
7845 g_signal_emit (widget,
7846 widget_signals[STYLE_SET],
7848 initial_emission ? NULL : previous_style);
7849 g_object_unref (previous_style);
7851 if (priv->anchored && !initial_emission)
7852 gtk_widget_queue_resize (widget);
7854 else if (initial_emission)
7856 gtk_widget_update_pango_context (widget);
7857 g_signal_emit (widget,
7858 widget_signals[STYLE_SET],
7862 g_object_notify (G_OBJECT (widget), "style");
7863 g_object_thaw_notify (G_OBJECT (widget));
7864 g_object_unref (widget);
7868 GtkWidget *previous_toplevel;
7869 GdkScreen *previous_screen;
7870 GdkScreen *new_screen;
7871 } HierarchyChangedInfo;
7874 do_screen_change (GtkWidget *widget,
7875 GdkScreen *old_screen,
7876 GdkScreen *new_screen)
7878 if (old_screen != new_screen)
7882 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7884 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7887 _gtk_tooltip_hide (widget);
7888 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7893 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7894 gpointer client_data)
7896 GtkWidgetPrivate *priv = widget->priv;
7897 HierarchyChangedInfo *info = client_data;
7898 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7899 (priv->parent && priv->parent->priv->anchored);
7901 if (priv->anchored != new_anchored)
7903 g_object_ref (widget);
7905 priv->anchored = new_anchored;
7907 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7908 do_screen_change (widget, info->previous_screen, info->new_screen);
7910 if (GTK_IS_CONTAINER (widget))
7911 gtk_container_forall (GTK_CONTAINER (widget),
7912 gtk_widget_propagate_hierarchy_changed_recurse,
7915 g_object_unref (widget);
7920 * _gtk_widget_propagate_hierarchy_changed:
7921 * @widget: a #GtkWidget
7922 * @previous_toplevel: Previous toplevel
7924 * Propagates changes in the anchored state to a widget and all
7925 * children, unsetting or setting the %ANCHORED flag, and
7926 * emitting #GtkWidget::hierarchy-changed.
7929 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7930 GtkWidget *previous_toplevel)
7932 GtkWidgetPrivate *priv = widget->priv;
7933 HierarchyChangedInfo info;
7935 info.previous_toplevel = previous_toplevel;
7936 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7938 if (gtk_widget_is_toplevel (widget) ||
7939 (priv->parent && priv->parent->priv->anchored))
7940 info.new_screen = gtk_widget_get_screen (widget);
7942 info.new_screen = NULL;
7944 if (info.previous_screen)
7945 g_object_ref (info.previous_screen);
7946 if (previous_toplevel)
7947 g_object_ref (previous_toplevel);
7949 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7951 if (previous_toplevel)
7952 g_object_unref (previous_toplevel);
7953 if (info.previous_screen)
7954 g_object_unref (info.previous_screen);
7958 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7959 gpointer client_data)
7961 HierarchyChangedInfo *info = client_data;
7963 g_object_ref (widget);
7965 do_screen_change (widget, info->previous_screen, info->new_screen);
7967 if (GTK_IS_CONTAINER (widget))
7968 gtk_container_forall (GTK_CONTAINER (widget),
7969 gtk_widget_propagate_screen_changed_recurse,
7972 g_object_unref (widget);
7976 * gtk_widget_is_composited:
7977 * @widget: a #GtkWidget
7979 * Whether @widget can rely on having its alpha channel
7980 * drawn correctly. On X11 this function returns whether a
7981 * compositing manager is running for @widget's screen.
7983 * Please note that the semantics of this call will change
7984 * in the future if used on a widget that has a composited
7985 * window in its hierarchy (as set by gdk_window_set_composited()).
7987 * Return value: %TRUE if the widget can rely on its alpha
7988 * channel being drawn correctly.
7993 gtk_widget_is_composited (GtkWidget *widget)
7997 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7999 screen = gtk_widget_get_screen (widget);
8001 return gdk_screen_is_composited (screen);
8005 propagate_composited_changed (GtkWidget *widget,
8008 if (GTK_IS_CONTAINER (widget))
8010 gtk_container_forall (GTK_CONTAINER (widget),
8011 propagate_composited_changed,
8015 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8019 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8021 propagate_composited_changed (widget, NULL);
8025 * _gtk_widget_propagate_screen_changed:
8026 * @widget: a #GtkWidget
8027 * @previous_screen: Previous screen
8029 * Propagates changes in the screen for a widget to all
8030 * children, emitting #GtkWidget::screen-changed.
8033 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8034 GdkScreen *previous_screen)
8036 HierarchyChangedInfo info;
8038 info.previous_screen = previous_screen;
8039 info.new_screen = gtk_widget_get_screen (widget);
8041 if (previous_screen)
8042 g_object_ref (previous_screen);
8044 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8046 if (previous_screen)
8047 g_object_unref (previous_screen);
8051 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
8053 if (widget->priv->rc_style)
8054 gtk_widget_reset_rc_style (widget);
8056 if (GTK_IS_CONTAINER (widget))
8057 gtk_container_forall (GTK_CONTAINER (widget),
8058 reset_rc_styles_recurse,
8064 * gtk_widget_reset_rc_styles:
8065 * @widget: a #GtkWidget.
8067 * Reset the styles of @widget and all descendents, so when
8068 * they are looked up again, they get the correct values
8069 * for the currently loaded RC file settings.
8071 * This function is not useful for applications.
8074 gtk_widget_reset_rc_styles (GtkWidget *widget)
8076 g_return_if_fail (GTK_IS_WIDGET (widget));
8078 reset_rc_styles_recurse (widget, NULL);
8082 * gtk_widget_get_default_style:
8084 * Returns the default style used by all widgets initially.
8086 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8087 * by GTK+ and should not be modified or freed.
8090 gtk_widget_get_default_style (void)
8092 if (!gtk_default_style)
8094 gtk_default_style = gtk_style_new ();
8095 g_object_ref (gtk_default_style);
8098 return gtk_default_style;
8101 static PangoContext *
8102 gtk_widget_peek_pango_context (GtkWidget *widget)
8104 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8108 * gtk_widget_get_pango_context:
8109 * @widget: a #GtkWidget
8111 * Gets a #PangoContext with the appropriate font map, font description,
8112 * and base direction for this widget. Unlike the context returned
8113 * by gtk_widget_create_pango_context(), this context is owned by
8114 * the widget (it can be used until the screen for the widget changes
8115 * or the widget is removed from its toplevel), and will be updated to
8116 * match any changes to the widget's attributes.
8118 * If you create and keep a #PangoLayout using this context, you must
8119 * deal with changes to the context by calling pango_layout_context_changed()
8120 * on the layout in response to the #GtkWidget::style-set and
8121 * #GtkWidget::direction-changed signals for the widget.
8123 * Return value: (transfer none): the #PangoContext for the widget.
8126 gtk_widget_get_pango_context (GtkWidget *widget)
8128 PangoContext *context;
8130 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8132 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8135 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8136 g_object_set_qdata_full (G_OBJECT (widget),
8137 quark_pango_context,
8146 update_pango_context (GtkWidget *widget,
8147 PangoContext *context)
8149 GtkWidgetPrivate *priv = widget->priv;
8151 pango_context_set_font_description (context, priv->style->font_desc);
8152 pango_context_set_base_dir (context,
8153 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8154 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8158 gtk_widget_update_pango_context (GtkWidget *widget)
8160 PangoContext *context = gtk_widget_peek_pango_context (widget);
8166 update_pango_context (widget, context);
8168 screen = gtk_widget_get_screen_unchecked (widget);
8171 pango_cairo_context_set_resolution (context,
8172 gdk_screen_get_resolution (screen));
8173 pango_cairo_context_set_font_options (context,
8174 gdk_screen_get_font_options (screen));
8180 * gtk_widget_create_pango_context:
8181 * @widget: a #GtkWidget
8183 * Creates a new #PangoContext with the appropriate font map,
8184 * font description, and base direction for drawing text for
8185 * this widget. See also gtk_widget_get_pango_context().
8187 * Return value: (transfer full): the new #PangoContext
8190 gtk_widget_create_pango_context (GtkWidget *widget)
8193 PangoContext *context;
8195 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8197 screen = gtk_widget_get_screen_unchecked (widget);
8200 GTK_NOTE (MULTIHEAD,
8201 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8203 screen = gdk_screen_get_default ();
8206 context = gdk_pango_context_get_for_screen (screen);
8208 update_pango_context (widget, context);
8209 pango_context_set_language (context, gtk_get_default_language ());
8215 * gtk_widget_create_pango_layout:
8216 * @widget: a #GtkWidget
8217 * @text: text to set on the layout (can be %NULL)
8219 * Creates a new #PangoLayout with the appropriate font map,
8220 * font description, and base direction for drawing text for
8223 * If you keep a #PangoLayout created in this way around, in order to
8224 * notify the layout of changes to the base direction or font of this
8225 * widget, you must call pango_layout_context_changed() in response to
8226 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8229 * Return value: (transfer full): the new #PangoLayout
8232 gtk_widget_create_pango_layout (GtkWidget *widget,
8235 PangoLayout *layout;
8236 PangoContext *context;
8238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8240 context = gtk_widget_get_pango_context (widget);
8241 layout = pango_layout_new (context);
8244 pango_layout_set_text (layout, text, -1);
8250 * gtk_widget_render_icon:
8251 * @widget: a #GtkWidget
8252 * @stock_id: a stock ID
8253 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8254 * render at the size of the source and don't scale (if there are
8255 * multiple source sizes, GTK+ picks one of the available sizes).
8256 * @detail: (allow-none): render detail to pass to theme engine
8258 * A convenience function that uses the theme engine and RC file
8259 * settings for @widget to look up @stock_id and render it to
8260 * a pixbuf. @stock_id should be a stock icon ID such as
8261 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8262 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8263 * identifies the widget or code doing the rendering, so that
8264 * theme engines can special-case rendering for that widget or code.
8266 * The pixels in the returned #GdkPixbuf are shared with the rest of
8267 * the application and should not be modified. The pixbuf should be freed
8268 * after use with g_object_unref().
8270 * Return value: (transfer full): a new pixbuf, or %NULL if the
8271 * stock ID wasn't known
8274 gtk_widget_render_icon (GtkWidget *widget,
8275 const gchar *stock_id,
8277 const gchar *detail)
8279 GtkWidgetPrivate *priv;
8280 GtkIconSet *icon_set;
8283 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8284 g_return_val_if_fail (stock_id != NULL, NULL);
8285 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8287 priv = widget->priv;
8289 gtk_widget_ensure_style (widget);
8291 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8293 if (icon_set == NULL)
8296 retval = gtk_icon_set_render_icon (icon_set,
8298 gtk_widget_get_direction (widget),
8299 gtk_widget_get_state (widget),
8308 * gtk_widget_set_parent_window:
8309 * @widget: a #GtkWidget.
8310 * @parent_window: the new parent window.
8312 * Sets a non default parent window for @widget.
8315 gtk_widget_set_parent_window (GtkWidget *widget,
8316 GdkWindow *parent_window)
8318 GdkWindow *old_parent_window;
8320 g_return_if_fail (GTK_IS_WIDGET (widget));
8322 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8323 quark_parent_window);
8325 if (parent_window != old_parent_window)
8327 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8329 if (old_parent_window)
8330 g_object_unref (old_parent_window);
8332 g_object_ref (parent_window);
8337 * gtk_widget_get_parent_window:
8338 * @widget: a #GtkWidget.
8340 * Gets @widget's parent window.
8342 * Returns: (transfer none): the parent window of @widget.
8345 gtk_widget_get_parent_window (GtkWidget *widget)
8347 GtkWidgetPrivate *priv;
8348 GdkWindow *parent_window;
8350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8352 priv = widget->priv;
8354 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8356 return (parent_window != NULL) ? parent_window :
8357 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8362 * gtk_widget_set_child_visible:
8363 * @widget: a #GtkWidget
8364 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8366 * Sets whether @widget should be mapped along with its when its parent
8367 * is mapped and @widget has been shown with gtk_widget_show().
8369 * The child visibility can be set for widget before it is added to
8370 * a container with gtk_widget_set_parent(), to avoid mapping
8371 * children unnecessary before immediately unmapping them. However
8372 * it will be reset to its default state of %TRUE when the widget
8373 * is removed from a container.
8375 * Note that changing the child visibility of a widget does not
8376 * queue a resize on the widget. Most of the time, the size of
8377 * a widget is computed from all visible children, whether or
8378 * not they are mapped. If this is not the case, the container
8379 * can queue a resize itself.
8381 * This function is only useful for container implementations and
8382 * never should be called by an application.
8385 gtk_widget_set_child_visible (GtkWidget *widget,
8386 gboolean is_visible)
8388 GtkWidgetPrivate *priv;
8390 g_return_if_fail (GTK_IS_WIDGET (widget));
8391 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8393 priv = widget->priv;
8395 g_object_ref (widget);
8398 priv->child_visible = TRUE;
8401 GtkWidget *toplevel;
8403 priv->child_visible = FALSE;
8405 toplevel = gtk_widget_get_toplevel (widget);
8406 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8407 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8410 if (priv->parent && gtk_widget_get_realized (priv->parent))
8412 if (gtk_widget_get_mapped (priv->parent) &&
8413 priv->child_visible &&
8414 gtk_widget_get_visible (widget))
8415 gtk_widget_map (widget);
8417 gtk_widget_unmap (widget);
8420 g_object_unref (widget);
8424 * gtk_widget_get_child_visible:
8425 * @widget: a #GtkWidget
8427 * Gets the value set with gtk_widget_set_child_visible().
8428 * If you feel a need to use this function, your code probably
8429 * needs reorganization.
8431 * This function is only useful for container implementations and
8432 * never should be called by an application.
8434 * Return value: %TRUE if the widget is mapped with the parent.
8437 gtk_widget_get_child_visible (GtkWidget *widget)
8439 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8441 return widget->priv->child_visible;
8445 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8447 GtkWidget *toplevel;
8449 toplevel = gtk_widget_get_toplevel (widget);
8451 if (gtk_widget_is_toplevel (toplevel))
8453 if (GTK_IS_WINDOW (toplevel))
8454 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8455 else if (GTK_IS_INVISIBLE (toplevel))
8456 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8463 * gtk_widget_get_screen:
8464 * @widget: a #GtkWidget
8466 * Get the #GdkScreen from the toplevel window associated with
8467 * this widget. This function can only be called after the widget
8468 * has been added to a widget hierarchy with a #GtkWindow
8471 * In general, you should only create screen specific
8472 * resources when a widget has been realized, and you should
8473 * free those resources when the widget is unrealized.
8475 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8480 gtk_widget_get_screen (GtkWidget *widget)
8484 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8486 screen = gtk_widget_get_screen_unchecked (widget);
8493 g_warning (G_STRLOC ": Can't get associated screen"
8494 " for a widget unless it is inside a toplevel GtkWindow\n"
8495 " widget type is %s associated top level type is %s",
8496 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8497 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8499 return gdk_screen_get_default ();
8504 * gtk_widget_has_screen:
8505 * @widget: a #GtkWidget
8507 * Checks whether there is a #GdkScreen is associated with
8508 * this widget. All toplevel widgets have an associated
8509 * screen, and all widgets added into a hierarchy with a toplevel
8510 * window at the top.
8512 * Return value: %TRUE if there is a #GdkScreen associcated
8518 gtk_widget_has_screen (GtkWidget *widget)
8520 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8522 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8526 * gtk_widget_get_display:
8527 * @widget: a #GtkWidget
8529 * Get the #GdkDisplay for the toplevel window associated with
8530 * this widget. This function can only be called after the widget
8531 * has been added to a widget hierarchy with a #GtkWindow at the top.
8533 * In general, you should only create display specific
8534 * resources when a widget has been realized, and you should
8535 * free those resources when the widget is unrealized.
8537 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8542 gtk_widget_get_display (GtkWidget *widget)
8544 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8546 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8550 * gtk_widget_get_root_window:
8551 * @widget: a #GtkWidget
8553 * Get the root window where this widget is located. This function can
8554 * only be called after the widget has been added to a widget
8555 * hierarchy with #GtkWindow at the top.
8557 * The root window is useful for such purposes as creating a popup
8558 * #GdkWindow associated with the window. In general, you should only
8559 * create display specific resources when a widget has been realized,
8560 * and you should free those resources when the widget is unrealized.
8562 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8567 gtk_widget_get_root_window (GtkWidget *widget)
8569 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8571 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8575 * gtk_widget_child_focus:
8576 * @widget: a #GtkWidget
8577 * @direction: direction of focus movement
8579 * This function is used by custom widget implementations; if you're
8580 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8581 * to a particular widget, and gtk_container_set_focus_chain() to
8582 * change the focus tab order. So you may want to investigate those
8583 * functions instead.
8585 * gtk_widget_child_focus() is called by containers as the user moves
8586 * around the window using keyboard shortcuts. @direction indicates
8587 * what kind of motion is taking place (up, down, left, right, tab
8588 * forward, tab backward). gtk_widget_child_focus() emits the
8589 * #GtkWidget::focus signal; widgets override the default handler
8590 * for this signal in order to implement appropriate focus behavior.
8592 * The default ::focus handler for a widget should return %TRUE if
8593 * moving in @direction left the focus on a focusable location inside
8594 * that widget, and %FALSE if moving in @direction moved the focus
8595 * outside the widget. If returning %TRUE, widgets normally
8596 * call gtk_widget_grab_focus() to place the focus accordingly;
8597 * if returning %FALSE, they don't modify the current focus location.
8599 * Return value: %TRUE if focus ended up inside @widget
8602 gtk_widget_child_focus (GtkWidget *widget,
8603 GtkDirectionType direction)
8605 gboolean return_val;
8607 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8609 if (!gtk_widget_get_visible (widget) ||
8610 !gtk_widget_is_sensitive (widget))
8613 /* child widgets must set CAN_FOCUS, containers
8614 * don't have to though.
8616 if (!GTK_IS_CONTAINER (widget) &&
8617 !gtk_widget_get_can_focus (widget))
8620 g_signal_emit (widget,
8621 widget_signals[FOCUS],
8623 direction, &return_val);
8629 * gtk_widget_keynav_failed:
8630 * @widget: a #GtkWidget
8631 * @direction: direction of focus movement
8633 * This function should be called whenever keyboard navigation within
8634 * a single widget hits a boundary. The function emits the
8635 * #GtkWidget::keynav-failed signal on the widget and its return
8636 * value should be interpreted in a way similar to the return value of
8637 * gtk_widget_child_focus():
8639 * When %TRUE is returned, stay in the widget, the failed keyboard
8640 * navigation is Ok and/or there is nowhere we can/should move the
8643 * When %FALSE is returned, the caller should continue with keyboard
8644 * navigation outside the widget, e.g. by calling
8645 * gtk_widget_child_focus() on the widget's toplevel.
8647 * The default ::keynav-failed handler returns %TRUE for
8648 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8649 * values of #GtkDirectionType, it looks at the
8650 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8651 * if the setting is %TRUE. This way the entire user interface
8652 * becomes cursor-navigatable on input devices such as mobile phones
8653 * which only have cursor keys but no tab key.
8655 * Whenever the default handler returns %TRUE, it also calls
8656 * gtk_widget_error_bell() to notify the user of the failed keyboard
8659 * A use case for providing an own implementation of ::keynav-failed
8660 * (either by connecting to it or by overriding it) would be a row of
8661 * #GtkEntry widgets where the user should be able to navigate the
8662 * entire row with the cursor keys, as e.g. known from user interfaces
8663 * that require entering license keys.
8665 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8666 * if the emitting widget should try to handle the keyboard
8667 * navigation attempt in its parent container(s).
8672 gtk_widget_keynav_failed (GtkWidget *widget,
8673 GtkDirectionType direction)
8675 gboolean return_val;
8677 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8679 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8680 direction, &return_val);
8686 * gtk_widget_error_bell:
8687 * @widget: a #GtkWidget
8689 * Notifies the user about an input-related error on this widget.
8690 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8691 * gdk_window_beep(), otherwise it does nothing.
8693 * Note that the effect of gdk_window_beep() can be configured in many
8694 * ways, depending on the windowing backend and the desktop environment
8695 * or window manager that is used.
8700 gtk_widget_error_bell (GtkWidget *widget)
8702 GtkWidgetPrivate *priv;
8703 GtkSettings* settings;
8706 g_return_if_fail (GTK_IS_WIDGET (widget));
8708 priv = widget->priv;
8710 settings = gtk_widget_get_settings (widget);
8714 g_object_get (settings,
8715 "gtk-error-bell", &beep,
8718 if (beep && priv->window)
8719 gdk_window_beep (priv->window);
8723 gtk_widget_set_usize_internal (GtkWidget *widget,
8726 GtkQueueResizeFlags flags)
8728 GtkWidgetAuxInfo *aux_info;
8729 gboolean changed = FALSE;
8731 g_object_freeze_notify (G_OBJECT (widget));
8733 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8735 if (width > -2 && aux_info->width != width)
8737 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8738 g_object_notify (G_OBJECT (widget), "width-request");
8739 aux_info->width = width;
8742 if (height > -2 && aux_info->height != height)
8744 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8745 g_object_notify (G_OBJECT (widget), "height-request");
8746 aux_info->height = height;
8750 if (gtk_widget_get_visible (widget) && changed)
8752 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8753 gtk_widget_queue_resize (widget);
8755 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8758 g_object_thaw_notify (G_OBJECT (widget));
8762 * gtk_widget_set_size_request:
8763 * @widget: a #GtkWidget
8764 * @width: width @widget should request, or -1 to unset
8765 * @height: height @widget should request, or -1 to unset
8767 * Sets the minimum size of a widget; that is, the widget's size
8768 * request will be @width by @height. You can use this function to
8769 * force a widget to be either larger or smaller than it normally
8772 * In most cases, gtk_window_set_default_size() is a better choice for
8773 * toplevel windows than this function; setting the default size will
8774 * still allow users to shrink the window. Setting the size request
8775 * will force them to leave the window at least as large as the size
8776 * request. When dealing with window sizes,
8777 * gtk_window_set_geometry_hints() can be a useful function as well.
8779 * Note the inherent danger of setting any fixed size - themes,
8780 * translations into other languages, different fonts, and user action
8781 * can all change the appropriate size for a given widget. So, it's
8782 * basically impossible to hardcode a size that will always be
8785 * The size request of a widget is the smallest size a widget can
8786 * accept while still functioning well and drawing itself correctly.
8787 * However in some strange cases a widget may be allocated less than
8788 * its requested size, and in many cases a widget may be allocated more
8789 * space than it requested.
8791 * If the size request in a given direction is -1 (unset), then
8792 * the "natural" size request of the widget will be used instead.
8794 * Widgets can't actually be allocated a size less than 1 by 1, but
8795 * you can pass 0,0 to this function to mean "as small as possible."
8797 * The size request set here does not include any margin from the
8798 * #GtkWidget properties margin-left, margin-right, margin-top, and
8799 * margin-bottom, but it does include pretty much all other padding
8800 * or border properties set by any subclass of #GtkWidget.
8803 gtk_widget_set_size_request (GtkWidget *widget,
8807 g_return_if_fail (GTK_IS_WIDGET (widget));
8808 g_return_if_fail (width >= -1);
8809 g_return_if_fail (height >= -1);
8816 gtk_widget_set_usize_internal (widget, width, height, 0);
8821 * gtk_widget_get_size_request:
8822 * @widget: a #GtkWidget
8823 * @width: (out) (allow-none): return location for width, or %NULL
8824 * @height: (out) (allow-none): return location for height, or %NULL
8826 * Gets the size request that was explicitly set for the widget using
8827 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8828 * @height indicates that that dimension has not been set explicitly
8829 * and the natural requisition of the widget will be used intead. See
8830 * gtk_widget_set_size_request(). To get the size a widget will
8831 * actually request, call gtk_widget_get_preferred_size() instead of
8835 gtk_widget_get_size_request (GtkWidget *widget,
8839 const GtkWidgetAuxInfo *aux_info;
8841 g_return_if_fail (GTK_IS_WIDGET (widget));
8843 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8846 *width = aux_info->width;
8849 *height = aux_info->height;
8853 * _gtk_widget_override_size_request:
8854 * @widget: a #GtkWidget
8855 * @width: new forced minimum width
8856 * @height: new forced minimum height
8857 * @old_width: location to store previous forced minimum width
8858 * @old_width: location to store previous forced minumum height
8860 * Temporarily establishes a forced minimum size for a widget; this
8861 * is used by GtkWindow when calculating the size to add to the
8862 * window's geometry widget. Cached sizes for the widget and its
8863 * parents are invalidated, so that subsequent calls to the size
8864 * negotiation machinery produce the overriden result, but the
8865 * widget is not queued for relayout or redraw. The old size must
8866 * be restored with _gtk_widget_restore_size_request() or things
8870 _gtk_widget_override_size_request (GtkWidget *widget,
8876 gtk_widget_get_size_request (widget, old_width, old_height);
8877 gtk_widget_set_usize_internal (widget, width, height,
8878 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8882 * _gtk_widget_restore_size_request:
8883 * @widget: a #GtkWidget
8884 * @old_width: saved forced minimum size
8885 * @old_height: saved forced minimum size
8887 * Undoes the operation of_gtk_widget_override_size_request().
8890 _gtk_widget_restore_size_request (GtkWidget *widget,
8894 gtk_widget_set_usize_internal (widget, old_width, old_height,
8895 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8899 * gtk_widget_set_events:
8900 * @widget: a #GtkWidget
8901 * @events: event mask
8903 * Sets the event mask (see #GdkEventMask) for a widget. The event
8904 * mask determines which events a widget will receive. Keep in mind
8905 * that different widgets have different default event masks, and by
8906 * changing the event mask you may disrupt a widget's functionality,
8907 * so be careful. This function must be called while a widget is
8908 * unrealized. Consider gtk_widget_add_events() for widgets that are
8909 * already realized, or if you want to preserve the existing event
8910 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8911 * to get events on those widgets, place them inside a #GtkEventBox
8912 * and receive events on the event box.
8915 gtk_widget_set_events (GtkWidget *widget,
8918 g_return_if_fail (GTK_IS_WIDGET (widget));
8919 g_return_if_fail (!gtk_widget_get_realized (widget));
8921 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8922 GINT_TO_POINTER (events));
8923 g_object_notify (G_OBJECT (widget), "events");
8927 * gtk_widget_set_device_events:
8928 * @widget: a #GtkWidget
8929 * @device: a #GdkDevice
8930 * @events: event mask
8932 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8933 * mask determines which events a widget will receive from @device. Keep
8934 * in mind that different widgets have different default event masks, and by
8935 * changing the event mask you may disrupt a widget's functionality,
8936 * so be careful. This function must be called while a widget is
8937 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8938 * already realized, or if you want to preserve the existing event
8939 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8940 * to get events on those widgets, place them inside a #GtkEventBox
8941 * and receive events on the event box.
8946 gtk_widget_set_device_events (GtkWidget *widget,
8948 GdkEventMask events)
8950 GHashTable *device_events;
8952 g_return_if_fail (GTK_IS_WIDGET (widget));
8953 g_return_if_fail (GDK_IS_DEVICE (device));
8954 g_return_if_fail (!gtk_widget_get_realized (widget));
8956 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8958 if (G_UNLIKELY (!device_events))
8960 device_events = g_hash_table_new (NULL, NULL);
8961 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8962 (GDestroyNotify) g_hash_table_unref);
8965 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8969 gtk_widget_add_events_internal_list (GtkWidget *widget,
8976 for (l = window_list; l != NULL; l = l->next)
8978 GdkWindow *window = l->data;
8981 gdk_window_get_user_data (window, &user_data);
8982 if (user_data == widget)
8987 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8989 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8991 children = gdk_window_get_children (window);
8992 gtk_widget_add_events_internal_list (widget, device, events, children);
8993 g_list_free (children);
8999 gtk_widget_add_events_internal (GtkWidget *widget,
9003 GtkWidgetPrivate *priv = widget->priv;
9006 if (!gtk_widget_get_has_window (widget))
9007 window_list = gdk_window_get_children (priv->window);
9009 window_list = g_list_prepend (NULL, priv->window);
9011 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9013 g_list_free (window_list);
9017 * gtk_widget_add_events:
9018 * @widget: a #GtkWidget
9019 * @events: an event mask, see #GdkEventMask
9021 * Adds the events in the bitfield @events to the event mask for
9022 * @widget. See gtk_widget_set_events() for details.
9025 gtk_widget_add_events (GtkWidget *widget,
9030 g_return_if_fail (GTK_IS_WIDGET (widget));
9032 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9033 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9034 GINT_TO_POINTER (old_events | events));
9036 if (gtk_widget_get_realized (widget))
9037 gtk_widget_add_events_internal (widget, NULL, events);
9039 g_object_notify (G_OBJECT (widget), "events");
9043 * gtk_widget_add_device_events:
9044 * @widget: a #GtkWidget
9045 * @device: a #GdkDevice
9046 * @events: an event mask, see #GdkEventMask
9048 * Adds the device events in the bitfield @events to the event mask for
9049 * @widget. See gtk_widget_set_device_events() for details.
9054 gtk_widget_add_device_events (GtkWidget *widget,
9056 GdkEventMask events)
9058 GdkEventMask old_events;
9059 GHashTable *device_events;
9061 g_return_if_fail (GTK_IS_WIDGET (widget));
9062 g_return_if_fail (GDK_IS_DEVICE (device));
9064 old_events = gtk_widget_get_device_events (widget, device);
9066 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9068 if (G_UNLIKELY (!device_events))
9070 device_events = g_hash_table_new (NULL, NULL);
9071 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9072 (GDestroyNotify) g_hash_table_unref);
9075 g_hash_table_insert (device_events, device,
9076 GUINT_TO_POINTER (old_events | events));
9078 if (gtk_widget_get_realized (widget))
9079 gtk_widget_add_events_internal (widget, device, events);
9081 g_object_notify (G_OBJECT (widget), "events");
9085 * gtk_widget_set_extension_events:
9086 * @widget: a #GtkWidget
9087 * @mode: bitfield of extension events to receive
9089 * Sets the extension events mask to @mode. See #GdkExtensionMode
9090 * and gdk_input_set_extension_events().
9093 gtk_widget_set_extension_events (GtkWidget *widget,
9094 GdkExtensionMode mode)
9096 g_return_if_fail (GTK_IS_WIDGET (widget));
9098 if (gtk_widget_get_realized (widget))
9099 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9101 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9102 GINT_TO_POINTER (mode));
9103 g_object_notify (G_OBJECT (widget), "extension-events");
9107 * gtk_widget_get_toplevel:
9108 * @widget: a #GtkWidget
9110 * This function returns the topmost widget in the container hierarchy
9111 * @widget is a part of. If @widget has no parent widgets, it will be
9112 * returned as the topmost widget. No reference will be added to the
9113 * returned widget; it should not be unreferenced.
9115 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9116 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9118 * %NULL if @widget wasn't inside a toplevel window, and if the
9119 * window was inside a #GtkWindow-derived widget which was in turn
9120 * inside the toplevel #GtkWindow. While the second case may
9121 * seem unlikely, it actually happens when a #GtkPlug is embedded
9122 * inside a #GtkSocket within the same application.
9124 * To reliably find the toplevel #GtkWindow, use
9125 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9126 * is set on the result.
9128 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9129 * if (gtk_widget_is_toplevel (toplevel))
9131 * /* Perform action on toplevel. */
9135 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9136 * if there's no ancestor.
9139 gtk_widget_get_toplevel (GtkWidget *widget)
9141 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9143 while (widget->priv->parent)
9144 widget = widget->priv->parent;
9150 * gtk_widget_get_ancestor:
9151 * @widget: a #GtkWidget
9152 * @widget_type: ancestor type
9154 * Gets the first ancestor of @widget with type @widget_type. For example,
9155 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9156 * the first #GtkBox that's an ancestor of @widget. No reference will be
9157 * added to the returned widget; it should not be unreferenced. See note
9158 * about checking for a toplevel #GtkWindow in the docs for
9159 * gtk_widget_get_toplevel().
9161 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9162 * considers @widget to be an ancestor of itself.
9164 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9167 gtk_widget_get_ancestor (GtkWidget *widget,
9170 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9172 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9173 widget = widget->priv->parent;
9175 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9182 * gtk_widget_set_visual:
9183 * @widget: a #GtkWidget
9184 * @visual: visual to be used or %NULL to unset a previous one
9186 * Sets the visual that should be used for by widget and its children for
9187 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9188 * returned by gdk_widget_get_screen(), so handling the
9189 * #GtkWidget::screen-changed signal is necessary.
9191 * Setting a new @visual will not cause @widget to recreate its windows,
9192 * so you should call this function before @widget is realized.
9195 gtk_widget_set_visual (GtkWidget *widget,
9198 g_return_if_fail (GTK_IS_WIDGET (widget));
9199 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9202 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9205 g_object_set_qdata_full (G_OBJECT (widget),
9207 g_object_ref (visual),
9212 * gtk_widget_get_visual:
9213 * @widget: a #GtkWidget
9215 * Gets the visual that will be used to render @widget.
9217 * Return value: (transfer none): the visual for @widget
9220 gtk_widget_get_visual (GtkWidget *widget)
9226 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9228 if (gtk_widget_get_has_window (widget) &&
9229 widget->priv->window)
9230 return gdk_window_get_visual (widget->priv->window);
9232 screen = gtk_widget_get_screen (widget);
9234 for (w = widget; w != NULL; w = w->priv->parent)
9236 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9239 if (gdk_visual_get_screen (visual) == screen)
9242 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9243 gtk_widget_get_name (widget));
9247 return gdk_screen_get_system_visual (screen);
9251 * gtk_widget_get_settings:
9252 * @widget: a #GtkWidget
9254 * Gets the settings object holding the settings (global property
9255 * settings, RC file information, etc) used for this widget.
9257 * Note that this function can only be called when the #GtkWidget
9258 * is attached to a toplevel, since the settings object is specific
9259 * to a particular #GdkScreen.
9261 * Return value: (transfer none): the relevant #GtkSettings object
9264 gtk_widget_get_settings (GtkWidget *widget)
9266 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9268 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9272 * gtk_widget_get_events:
9273 * @widget: a #GtkWidget
9275 * Returns the event mask for the widget (a bitfield containing flags
9276 * from the #GdkEventMask enumeration). These are the events that the widget
9279 * Return value: event mask for @widget
9282 gtk_widget_get_events (GtkWidget *widget)
9284 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9286 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9290 * gtk_widget_get_device_events:
9291 * @widget: a #GtkWidget
9292 * @device: a #GdkDevice
9294 * Returns the events mask for the widget corresponding to an specific device. These
9295 * are the events that the widget will receive when @device operates on it.
9297 * Returns: device event mask for @widget
9302 gtk_widget_get_device_events (GtkWidget *widget,
9305 GHashTable *device_events;
9307 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9308 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9310 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9315 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9319 * gtk_widget_get_extension_events:
9320 * @widget: a #GtkWidget
9322 * Retrieves the extension events the widget will receive; see
9323 * gdk_input_set_extension_events().
9325 * Return value: extension events for @widget
9328 gtk_widget_get_extension_events (GtkWidget *widget)
9330 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9332 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9336 * gtk_widget_get_pointer:
9337 * @widget: a #GtkWidget
9338 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9339 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9341 * Obtains the location of the mouse pointer in widget coordinates.
9342 * Widget coordinates are a bit odd; for historical reasons, they are
9343 * defined as @widget->window coordinates for widgets that are not
9344 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9345 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9348 gtk_widget_get_pointer (GtkWidget *widget,
9352 GtkWidgetPrivate *priv;
9354 g_return_if_fail (GTK_IS_WIDGET (widget));
9356 priv = widget->priv;
9363 if (gtk_widget_get_realized (widget))
9365 gdk_window_get_pointer (priv->window, x, y, NULL);
9367 if (!gtk_widget_get_has_window (widget))
9370 *x -= priv->allocation.x;
9372 *y -= priv->allocation.y;
9378 * gtk_widget_is_ancestor:
9379 * @widget: a #GtkWidget
9380 * @ancestor: another #GtkWidget
9382 * Determines whether @widget is somewhere inside @ancestor, possibly with
9383 * intermediate containers.
9385 * Return value: %TRUE if @ancestor contains @widget as a child,
9386 * grandchild, great grandchild, etc.
9389 gtk_widget_is_ancestor (GtkWidget *widget,
9390 GtkWidget *ancestor)
9392 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9393 g_return_val_if_fail (ancestor != NULL, FALSE);
9397 if (widget->priv->parent == ancestor)
9399 widget = widget->priv->parent;
9405 static GQuark quark_composite_name = 0;
9408 * gtk_widget_set_composite_name:
9409 * @widget: a #GtkWidget.
9410 * @name: the name to set
9412 * Sets a widgets composite name. The widget must be
9413 * a composite child of its parent; see gtk_widget_push_composite_child().
9416 gtk_widget_set_composite_name (GtkWidget *widget,
9419 g_return_if_fail (GTK_IS_WIDGET (widget));
9420 g_return_if_fail (widget->priv->composite_child);
9421 g_return_if_fail (name != NULL);
9423 if (!quark_composite_name)
9424 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9426 g_object_set_qdata_full (G_OBJECT (widget),
9427 quark_composite_name,
9433 * gtk_widget_get_composite_name:
9434 * @widget: a #GtkWidget
9436 * Obtains the composite name of a widget.
9438 * Returns: the composite name of @widget, or %NULL if @widget is not
9439 * a composite child. The string should be freed when it is no
9443 gtk_widget_get_composite_name (GtkWidget *widget)
9445 GtkWidgetPrivate *priv;
9447 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9449 priv = widget->priv;
9451 if (widget->priv->composite_child && priv->parent)
9452 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9459 * gtk_widget_push_composite_child:
9461 * Makes all newly-created widgets as composite children until
9462 * the corresponding gtk_widget_pop_composite_child() call.
9464 * A composite child is a child that's an implementation detail of the
9465 * container it's inside and should not be visible to people using the
9466 * container. Composite children aren't treated differently by GTK (but
9467 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9468 * builders might want to treat them in a different way.
9470 * Here is a simple example:
9472 * gtk_widget_push_composite_child ();
9473 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9474 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9475 * gtk_widget_pop_composite_child ();
9476 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9477 * GTK_WIDGET (scrolled_window));
9478 * g_object_ref (scrolled_window->hscrollbar);
9482 gtk_widget_push_composite_child (void)
9484 composite_child_stack++;
9488 * gtk_widget_pop_composite_child:
9490 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9493 gtk_widget_pop_composite_child (void)
9495 if (composite_child_stack)
9496 composite_child_stack--;
9500 gtk_widget_emit_direction_changed (GtkWidget *widget,
9501 GtkTextDirection old_dir)
9503 gtk_widget_update_pango_context (widget);
9505 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9509 * gtk_widget_set_direction:
9510 * @widget: a #GtkWidget
9511 * @dir: the new direction
9513 * Sets the reading direction on a particular widget. This direction
9514 * controls the primary direction for widgets containing text,
9515 * and also the direction in which the children of a container are
9516 * packed. The ability to set the direction is present in order
9517 * so that correct localization into languages with right-to-left
9518 * reading directions can be done. Generally, applications will
9519 * let the default reading direction present, except for containers
9520 * where the containers are arranged in an order that is explicitely
9521 * visual rather than logical (such as buttons for text justification).
9523 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9524 * set by gtk_widget_set_default_direction() will be used.
9527 gtk_widget_set_direction (GtkWidget *widget,
9528 GtkTextDirection dir)
9530 GtkTextDirection old_dir;
9532 g_return_if_fail (GTK_IS_WIDGET (widget));
9533 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9535 old_dir = gtk_widget_get_direction (widget);
9537 widget->priv->direction = dir;
9539 if (old_dir != gtk_widget_get_direction (widget))
9540 gtk_widget_emit_direction_changed (widget, old_dir);
9544 * gtk_widget_get_direction:
9545 * @widget: a #GtkWidget
9547 * Gets the reading direction for a particular widget. See
9548 * gtk_widget_set_direction().
9550 * Return value: the reading direction for the widget.
9553 gtk_widget_get_direction (GtkWidget *widget)
9555 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9557 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9558 return gtk_default_direction;
9560 return widget->priv->direction;
9564 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9566 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9568 g_object_ref (widget);
9570 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9571 gtk_widget_emit_direction_changed (widget, old_dir);
9573 if (GTK_IS_CONTAINER (widget))
9574 gtk_container_forall (GTK_CONTAINER (widget),
9575 gtk_widget_set_default_direction_recurse,
9578 g_object_unref (widget);
9582 * gtk_widget_set_default_direction:
9583 * @dir: the new default direction. This cannot be
9584 * %GTK_TEXT_DIR_NONE.
9586 * Sets the default reading direction for widgets where the
9587 * direction has not been explicitly set by gtk_widget_set_direction().
9590 gtk_widget_set_default_direction (GtkTextDirection dir)
9592 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9594 if (dir != gtk_default_direction)
9596 GList *toplevels, *tmp_list;
9597 GtkTextDirection old_dir = gtk_default_direction;
9599 gtk_default_direction = dir;
9601 tmp_list = toplevels = gtk_window_list_toplevels ();
9602 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9606 gtk_widget_set_default_direction_recurse (tmp_list->data,
9607 GUINT_TO_POINTER (old_dir));
9608 g_object_unref (tmp_list->data);
9609 tmp_list = tmp_list->next;
9612 g_list_free (toplevels);
9617 * gtk_widget_get_default_direction:
9619 * Obtains the current default reading direction. See
9620 * gtk_widget_set_default_direction().
9622 * Return value: the current default direction.
9625 gtk_widget_get_default_direction (void)
9627 return gtk_default_direction;
9631 gtk_widget_dispose (GObject *object)
9633 GtkWidget *widget = GTK_WIDGET (object);
9634 GtkWidgetPrivate *priv = widget->priv;
9637 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9638 else if (gtk_widget_get_visible (widget))
9639 gtk_widget_hide (widget);
9641 priv->visible = FALSE;
9642 if (gtk_widget_get_realized (widget))
9643 gtk_widget_unrealize (widget);
9645 if (!priv->in_destruction)
9647 priv->in_destruction = TRUE;
9648 g_signal_emit (object, widget_signals[DESTROY], 0);
9649 priv->in_destruction = FALSE;
9652 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9656 gtk_widget_real_destroy (GtkWidget *object)
9658 /* gtk_object_destroy() will already hold a refcount on object */
9659 GtkWidget *widget = GTK_WIDGET (object);
9660 GtkWidgetPrivate *priv = widget->priv;
9662 /* wipe accelerator closures (keep order) */
9663 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9664 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9666 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9667 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9669 gtk_grab_remove (widget);
9671 g_object_unref (priv->style);
9672 priv->style = gtk_widget_get_default_style ();
9673 g_object_ref (priv->style);
9677 gtk_widget_finalize (GObject *object)
9679 GtkWidget *widget = GTK_WIDGET (object);
9680 GtkWidgetPrivate *priv = widget->priv;
9681 GtkWidgetAuxInfo *aux_info;
9682 GtkAccessible *accessible;
9684 gtk_grab_remove (widget);
9686 g_object_unref (priv->style);
9689 g_free (priv->name);
9691 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9693 gtk_widget_aux_info_destroy (aux_info);
9695 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9697 g_object_unref (accessible);
9699 if (g_object_is_floating (object))
9700 g_warning ("A floating object was finalized. This means that someone\n"
9701 "called g_object_unref() on an object that had only a floating\n"
9702 "reference; the initial floating reference is not owned by anyone\n"
9703 "and must be removed with g_object_ref_sink().");
9705 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9708 /*****************************************
9709 * gtk_widget_real_map:
9714 *****************************************/
9717 gtk_widget_real_map (GtkWidget *widget)
9719 GtkWidgetPrivate *priv = widget->priv;
9721 g_assert (gtk_widget_get_realized (widget));
9723 if (!gtk_widget_get_mapped (widget))
9725 gtk_widget_set_mapped (widget, TRUE);
9727 if (gtk_widget_get_has_window (widget))
9728 gdk_window_show (priv->window);
9732 /*****************************************
9733 * gtk_widget_real_unmap:
9738 *****************************************/
9741 gtk_widget_real_unmap (GtkWidget *widget)
9743 GtkWidgetPrivate *priv = widget->priv;
9745 if (gtk_widget_get_mapped (widget))
9747 gtk_widget_set_mapped (widget, FALSE);
9749 if (gtk_widget_get_has_window (widget))
9750 gdk_window_hide (priv->window);
9754 /*****************************************
9755 * gtk_widget_real_realize:
9760 *****************************************/
9763 gtk_widget_real_realize (GtkWidget *widget)
9765 GtkWidgetPrivate *priv = widget->priv;
9767 g_assert (!gtk_widget_get_has_window (widget));
9769 gtk_widget_set_realized (widget, TRUE);
9772 priv->window = gtk_widget_get_parent_window (widget);
9773 g_object_ref (priv->window);
9775 priv->style = gtk_style_attach (priv->style, priv->window);
9778 /*****************************************
9779 * gtk_widget_real_unrealize:
9784 *****************************************/
9787 gtk_widget_real_unrealize (GtkWidget *widget)
9789 GtkWidgetPrivate *priv = widget->priv;
9791 if (gtk_widget_get_mapped (widget))
9792 gtk_widget_real_unmap (widget);
9794 gtk_widget_set_mapped (widget, FALSE);
9796 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9799 /* We must do unrealize child widget BEFORE container widget.
9800 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9801 * So, unrealizing container widget bofore its children causes the problem
9802 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9805 if (GTK_IS_CONTAINER (widget))
9806 gtk_container_forall (GTK_CONTAINER (widget),
9807 (GtkCallback) gtk_widget_unrealize,
9810 gtk_style_detach (priv->style);
9811 if (gtk_widget_get_has_window (widget))
9813 gdk_window_set_user_data (priv->window, NULL);
9814 gdk_window_destroy (priv->window);
9815 priv->window = NULL;
9819 g_object_unref (priv->window);
9820 priv->window = NULL;
9823 gtk_selection_remove_all (widget);
9825 gtk_widget_set_realized (widget, FALSE);
9829 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9830 GtkOrientation orientation,
9834 const GtkWidgetAuxInfo *aux_info;
9836 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9838 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9839 aux_info->width > 0)
9841 *minimum_size = MAX (*minimum_size, aux_info->width);
9843 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9844 aux_info->height > 0)
9846 *minimum_size = MAX (*minimum_size, aux_info->height);
9849 /* Fix it if set_size_request made natural size smaller than min size.
9850 * This would also silently fix broken widgets, but we warn about them
9851 * in gtksizerequest.c when calling their size request vfuncs.
9853 *natural_size = MAX (*natural_size, *minimum_size);
9855 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9857 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9858 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9862 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9863 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9868 * _gtk_widget_peek_request_cache:
9870 * Returns the address of the widget's request cache (strictly for
9871 * internal use in gtksizerequest.c)
9873 * Return value: the address of @widget's size request cache.
9876 _gtk_widget_peek_request_cache (GtkWidget *widget)
9878 /* Don't bother slowing things down with the return_if_fail guards here */
9879 return &widget->priv->requests;
9883 * _gtk_widget_set_device_window:
9884 * @widget: a #GtkWidget.
9885 * @device: a #GdkDevice.
9886 * @window: the new device window.
9888 * Sets pointer window for @widget and @device. Does not ref @window.
9889 * Actually stores it on the #GdkScreen, but you don't need to know that.
9892 _gtk_widget_set_device_window (GtkWidget *widget,
9896 GtkWidgetPrivate *priv;
9898 GHashTable *device_window;
9900 g_return_if_fail (GTK_IS_WIDGET (widget));
9901 g_return_if_fail (GDK_IS_DEVICE (device));
9902 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9904 priv = widget->priv;
9906 if (!gtk_widget_get_realized (widget))
9909 screen = gdk_window_get_screen (priv->window);
9910 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9912 if (G_UNLIKELY (!device_window))
9914 device_window = g_hash_table_new (NULL, NULL);
9915 g_object_set_qdata_full (G_OBJECT (screen),
9916 quark_pointer_window,
9918 (GDestroyNotify) g_hash_table_destroy);
9922 g_hash_table_insert (device_window, device, window);
9924 g_hash_table_remove (device_window, device);
9928 * _gtk_widget_get_device_window:
9929 * @widget: a #GtkWidget.
9930 * @device: a #GdkDevice.
9932 * Return value: the device window set on the #GdkScreen @widget is attached
9936 _gtk_widget_get_device_window (GtkWidget *widget,
9939 GtkWidgetPrivate *priv;
9941 GHashTable *device_window;
9945 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9946 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9948 priv = widget->priv;
9950 if (!gtk_widget_get_realized (widget))
9953 screen = gdk_window_get_screen (priv->window);
9954 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9956 if (G_UNLIKELY (!device_window))
9959 window = g_hash_table_lookup (device_window, device);
9964 gdk_window_get_user_data (window, (gpointer *) &w);
9973 * _gtk_widget_list_devices:
9974 * @widget: a #GtkWidget.
9976 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9977 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9981 _gtk_widget_list_devices (GtkWidget *widget)
9983 GtkWidgetPrivate *priv;
9985 GHashTableIter iter;
9986 GHashTable *device_window;
9987 GList *devices = NULL;
9988 gpointer key, value;
9990 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9992 priv = widget->priv;
9994 if (!gtk_widget_get_realized (widget))
9997 screen = gdk_window_get_screen (priv->window);
9998 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10000 if (G_UNLIKELY (!device_window))
10003 g_hash_table_iter_init (&iter, device_window);
10005 while (g_hash_table_iter_next (&iter, &key, &value))
10007 GdkDevice *device = key;
10008 GdkWindow *window = value;
10013 gdk_window_get_user_data (window, (gpointer *) &w);
10016 devices = g_list_prepend (devices, device);
10024 synth_crossing (GtkWidget *widget,
10028 GdkCrossingMode mode,
10029 GdkNotifyType detail)
10033 event = gdk_event_new (type);
10035 event->crossing.window = g_object_ref (window);
10036 event->crossing.send_event = TRUE;
10037 event->crossing.subwindow = g_object_ref (window);
10038 event->crossing.time = GDK_CURRENT_TIME;
10039 event->crossing.x = event->crossing.y = 0;
10040 event->crossing.x_root = event->crossing.y_root = 0;
10041 event->crossing.mode = mode;
10042 event->crossing.detail = detail;
10043 event->crossing.focus = FALSE;
10044 event->crossing.state = 0;
10045 gdk_event_set_device (event, device);
10048 widget = gtk_get_event_widget (event);
10051 gtk_widget_event_internal (widget, event);
10053 gdk_event_free (event);
10057 * _gtk_widget_synthesize_crossing:
10058 * @from: the #GtkWidget the virtual pointer is leaving.
10059 * @to: the #GtkWidget the virtual pointer is moving to.
10060 * @mode: the #GdkCrossingMode to place on the synthesized events.
10062 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10064 * The real pointer window is the window that most recently received an enter notify
10065 * event. Windows that don't select for crossing events can't become the real
10066 * poiner window. The real pointer widget that owns the real pointer window. The
10067 * effective pointer window is the same as the real pointer window unless the real
10068 * pointer widget is either insensitive or there is a grab on a widget that is not
10069 * an ancestor of the real pointer widget (in which case the effective pointer
10070 * window should be the root window).
10072 * When the effective pointer window is the same as the real poiner window, we
10073 * receive crossing events from the windowing system. When the effective pointer
10074 * window changes to become different from the real pointer window we synthesize
10075 * crossing events, attempting to follow X protocol rules:
10077 * When the root window becomes the effective pointer window:
10078 * - leave notify on real pointer window, detail Ancestor
10079 * - leave notify on all of its ancestors, detail Virtual
10080 * - enter notify on root window, detail Inferior
10082 * When the root window ceases to be the effective pointer window:
10083 * - leave notify on root window, detail Inferior
10084 * - enter notify on all ancestors of real pointer window, detail Virtual
10085 * - enter notify on real pointer window, detail Ancestor
10088 _gtk_widget_synthesize_crossing (GtkWidget *from,
10091 GdkCrossingMode mode)
10093 GdkWindow *from_window = NULL, *to_window = NULL;
10095 g_return_if_fail (from != NULL || to != NULL);
10099 from_window = _gtk_widget_get_device_window (from, device);
10102 from_window = from->priv->window;
10107 to_window = _gtk_widget_get_device_window (to, device);
10110 to_window = to->priv->window;
10113 if (from_window == NULL && to_window == NULL)
10115 else if (from_window != NULL && to_window == NULL)
10117 GList *from_ancestors = NULL, *list;
10118 GdkWindow *from_ancestor = from_window;
10120 while (from_ancestor != NULL)
10122 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10123 if (from_ancestor == NULL)
10125 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10128 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10129 device, mode, GDK_NOTIFY_ANCESTOR);
10130 for (list = g_list_last (from_ancestors); list; list = list->prev)
10132 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10133 device, mode, GDK_NOTIFY_VIRTUAL);
10136 /* XXX: enter/inferior on root window? */
10138 g_list_free (from_ancestors);
10140 else if (from_window == NULL && to_window != NULL)
10142 GList *to_ancestors = NULL, *list;
10143 GdkWindow *to_ancestor = to_window;
10145 while (to_ancestor != NULL)
10147 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10148 if (to_ancestor == NULL)
10150 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10153 /* XXX: leave/inferior on root window? */
10155 for (list = to_ancestors; list; list = list->next)
10157 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10158 device, mode, GDK_NOTIFY_VIRTUAL);
10160 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10161 device, mode, GDK_NOTIFY_ANCESTOR);
10163 g_list_free (to_ancestors);
10165 else if (from_window == to_window)
10169 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10170 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10172 while (from_ancestor != NULL || to_ancestor != NULL)
10174 if (from_ancestor != NULL)
10176 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10177 if (from_ancestor == to_window)
10180 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10182 if (to_ancestor != NULL)
10184 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10185 if (to_ancestor == from_window)
10188 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10191 if (to_ancestor == from_window)
10193 if (mode != GDK_CROSSING_GTK_UNGRAB)
10194 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10195 device, mode, GDK_NOTIFY_INFERIOR);
10196 for (list = to_ancestors; list; list = list->next)
10197 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10198 device, mode, GDK_NOTIFY_VIRTUAL);
10199 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10200 device, mode, GDK_NOTIFY_ANCESTOR);
10202 else if (from_ancestor == to_window)
10204 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10205 device, mode, GDK_NOTIFY_ANCESTOR);
10206 for (list = g_list_last (from_ancestors); list; list = list->prev)
10208 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10209 device, mode, GDK_NOTIFY_VIRTUAL);
10211 if (mode != GDK_CROSSING_GTK_GRAB)
10212 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10213 device, mode, GDK_NOTIFY_INFERIOR);
10217 while (from_ancestors != NULL && to_ancestors != NULL
10218 && from_ancestors->data == to_ancestors->data)
10220 from_ancestors = g_list_delete_link (from_ancestors,
10222 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10225 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10226 device, mode, GDK_NOTIFY_NONLINEAR);
10228 for (list = g_list_last (from_ancestors); list; list = list->prev)
10230 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10231 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10233 for (list = to_ancestors; list; list = list->next)
10235 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10236 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10238 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10239 device, mode, GDK_NOTIFY_NONLINEAR);
10241 g_list_free (from_ancestors);
10242 g_list_free (to_ancestors);
10247 gtk_widget_propagate_state (GtkWidget *widget,
10248 GtkStateData *data)
10250 GtkWidgetPrivate *priv = widget->priv;
10251 guint8 old_state = gtk_widget_get_state (widget);
10252 guint8 old_saved_state = priv->saved_state;
10254 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10255 * parent_sensitive==TRUE on a sensitive widget
10259 priv->parent_sensitive = data->parent_sensitive;
10261 if (gtk_widget_is_sensitive (widget))
10263 if (data->state_restoration)
10264 priv->state = priv->saved_state;
10266 priv->state = data->state;
10270 if (!data->state_restoration)
10272 if (data->state != GTK_STATE_INSENSITIVE)
10273 priv->saved_state = data->state;
10275 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10276 priv->saved_state = gtk_widget_get_state (widget);
10277 priv->state = GTK_STATE_INSENSITIVE;
10280 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10284 window = gtk_widget_get_toplevel (widget);
10285 if (window && gtk_widget_is_toplevel (window))
10286 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10289 if (old_state != gtk_widget_get_state (widget) ||
10290 old_saved_state != priv->saved_state)
10292 g_object_ref (widget);
10294 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10295 gtk_grab_remove (widget);
10297 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10299 if (!priv->shadowed)
10301 GList *event_windows = NULL;
10302 GList *devices, *d;
10304 devices = _gtk_widget_list_devices (widget);
10306 for (d = devices; d; d = d->next)
10312 window = _gtk_widget_get_device_window (widget, device);
10314 /* Do not propagate more than once to the
10315 * same window if non-multidevice aware.
10317 if (!gdk_window_get_support_multidevice (window) &&
10318 g_list_find (event_windows, window))
10321 if (!gtk_widget_is_sensitive (widget))
10322 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10323 GDK_CROSSING_STATE_CHANGED);
10324 else if (old_state == GTK_STATE_INSENSITIVE)
10325 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10326 GDK_CROSSING_STATE_CHANGED);
10328 event_windows = g_list_prepend (event_windows, window);
10331 g_list_free (event_windows);
10332 g_list_free (devices);
10335 if (GTK_IS_CONTAINER (widget))
10337 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10338 if (data->use_forall)
10339 gtk_container_forall (GTK_CONTAINER (widget),
10340 (GtkCallback) gtk_widget_propagate_state,
10343 gtk_container_foreach (GTK_CONTAINER (widget),
10344 (GtkCallback) gtk_widget_propagate_state,
10347 g_object_unref (widget);
10351 static const GtkWidgetAuxInfo default_aux_info = {
10359 * _gtk_widget_get_aux_info:
10360 * @widget: a #GtkWidget
10361 * @create: if %TRUE, create the structure if it doesn't exist
10363 * Get the #GtkWidgetAuxInfo structure for the widget.
10365 * Return value: the #GtkAuxInfo structure for the widget, or
10366 * %NULL if @create is %FALSE and one doesn't already exist.
10369 _gtk_widget_get_aux_info (GtkWidget *widget,
10372 GtkWidgetAuxInfo *aux_info;
10374 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10375 if (!aux_info && create)
10377 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10379 *aux_info = default_aux_info;
10381 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10387 static const GtkWidgetAuxInfo*
10388 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10390 GtkWidgetAuxInfo *aux_info;
10392 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10393 if (aux_info == NULL)
10395 return &default_aux_info;
10403 /*****************************************
10404 * gtk_widget_aux_info_destroy:
10409 *****************************************/
10412 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10414 g_slice_free (GtkWidgetAuxInfo, aux_info);
10418 * gtk_widget_shape_combine_region:
10419 * @widget: a #GtkWidget
10420 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10422 * Sets a shape for this widget's GDK window. This allows for
10423 * transparent windows etc., see gdk_window_shape_combine_region()
10424 * for more information.
10429 gtk_widget_shape_combine_region (GtkWidget *widget,
10430 cairo_region_t *region)
10432 GtkWidgetPrivate *priv;
10434 g_return_if_fail (GTK_IS_WIDGET (widget));
10435 /* set_shape doesn't work on widgets without gdk window */
10436 g_return_if_fail (gtk_widget_get_has_window (widget));
10438 priv = widget->priv;
10440 if (region == NULL)
10442 priv->has_shape_mask = FALSE;
10445 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10447 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10451 priv->has_shape_mask = TRUE;
10453 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10454 cairo_region_copy (region),
10455 (GDestroyNotify) cairo_region_destroy);
10457 /* set shape if widget has a gdk window already.
10458 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10461 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10466 * gtk_widget_input_shape_combine_region:
10467 * @widget: a #GtkWidget
10468 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10470 * Sets an input shape for this widget's GDK window. This allows for
10471 * windows which react to mouse click in a nonrectangular region, see
10472 * gdk_window_input_shape_combine_region() for more information.
10477 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10478 cairo_region_t *region)
10480 GtkWidgetPrivate *priv;
10482 g_return_if_fail (GTK_IS_WIDGET (widget));
10483 /* set_shape doesn't work on widgets without gdk window */
10484 g_return_if_fail (gtk_widget_get_has_window (widget));
10486 priv = widget->priv;
10488 if (region == NULL)
10491 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10493 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10497 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10498 cairo_region_copy (region),
10499 (GDestroyNotify) cairo_region_destroy);
10501 /* set shape if widget has a gdk window already.
10502 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10505 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10511 gtk_reset_shapes_recurse (GtkWidget *widget,
10517 gdk_window_get_user_data (window, &data);
10518 if (data != widget)
10521 gdk_window_shape_combine_region (window, NULL, 0, 0);
10522 for (list = gdk_window_peek_children (window); list; list = list->next)
10523 gtk_reset_shapes_recurse (widget, list->data);
10527 * gtk_widget_reset_shapes:
10528 * @widget: a #GtkWidget
10530 * Recursively resets the shape on this widget and its descendants.
10533 gtk_widget_reset_shapes (GtkWidget *widget)
10535 GtkWidgetPrivate *priv;
10537 g_return_if_fail (GTK_IS_WIDGET (widget));
10538 g_return_if_fail (gtk_widget_get_realized (widget));
10540 priv = widget->priv;
10542 if (!priv->has_shape_mask)
10543 gtk_reset_shapes_recurse (widget, priv->window);
10546 /* style properties
10550 * gtk_widget_class_install_style_property_parser:
10551 * @klass: a #GtkWidgetClass
10552 * @pspec: the #GParamSpec for the style property
10553 * @parser: the parser for the style property
10555 * Installs a style property on a widget class.
10558 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10560 GtkRcPropertyParser parser)
10562 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10563 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10564 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10565 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10567 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10569 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10570 G_OBJECT_CLASS_NAME (klass),
10575 g_param_spec_ref_sink (pspec);
10576 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10577 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10581 * gtk_widget_class_install_style_property:
10582 * @klass: a #GtkWidgetClass
10583 * @pspec: the #GParamSpec for the property
10585 * Installs a style property on a widget class. The parser for the
10586 * style property is determined by the value type of @pspec.
10589 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10592 GtkRcPropertyParser parser;
10594 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10595 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10597 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10599 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10603 * gtk_widget_class_find_style_property:
10604 * @klass: a #GtkWidgetClass
10605 * @property_name: the name of the style property to find
10606 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10607 * style property with that name.
10609 * Finds a style property of a widget class by name.
10614 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10615 const gchar *property_name)
10617 g_return_val_if_fail (property_name != NULL, NULL);
10619 return g_param_spec_pool_lookup (style_property_spec_pool,
10621 G_OBJECT_CLASS_TYPE (klass),
10626 * gtk_widget_class_list_style_properties:
10627 * @klass: a #GtkWidgetClass
10628 * @n_properties: location to return the number of style properties found
10629 * @returns: an newly allocated array of #GParamSpec*. The array must
10630 * be freed with g_free().
10632 * Returns all style properties of a widget class.
10637 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10638 guint *n_properties)
10640 GParamSpec **pspecs;
10643 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10644 G_OBJECT_CLASS_TYPE (klass),
10653 * gtk_widget_style_get_property:
10654 * @widget: a #GtkWidget
10655 * @property_name: the name of a style property
10656 * @value: location to return the property value
10658 * Gets the value of a style property of @widget.
10661 gtk_widget_style_get_property (GtkWidget *widget,
10662 const gchar *property_name,
10665 GtkWidgetPrivate *priv;
10668 g_return_if_fail (GTK_IS_WIDGET (widget));
10669 g_return_if_fail (property_name != NULL);
10670 g_return_if_fail (G_IS_VALUE (value));
10672 priv = widget->priv;
10674 g_object_ref (widget);
10675 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10677 G_OBJECT_TYPE (widget),
10680 g_warning ("%s: widget class `%s' has no property named `%s'",
10682 G_OBJECT_TYPE_NAME (widget),
10686 const GValue *peek_value;
10688 peek_value = _gtk_style_peek_property_value (priv->style,
10689 G_OBJECT_TYPE (widget),
10691 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10693 /* auto-conversion of the caller's value type
10695 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10696 g_value_copy (peek_value, value);
10697 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10698 g_value_transform (peek_value, value);
10700 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10702 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10703 G_VALUE_TYPE_NAME (value));
10705 g_object_unref (widget);
10709 * gtk_widget_style_get_valist:
10710 * @widget: a #GtkWidget
10711 * @first_property_name: the name of the first property to get
10712 * @var_args: a <type>va_list</type> of pairs of property names and
10713 * locations to return the property values, starting with the location
10714 * for @first_property_name.
10716 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10720 gtk_widget_style_get_valist (GtkWidget *widget,
10721 const gchar *first_property_name,
10724 GtkWidgetPrivate *priv;
10727 g_return_if_fail (GTK_IS_WIDGET (widget));
10729 priv = widget->priv;
10731 g_object_ref (widget);
10733 name = first_property_name;
10736 const GValue *peek_value;
10740 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10742 G_OBJECT_TYPE (widget),
10746 g_warning ("%s: widget class `%s' has no property named `%s'",
10748 G_OBJECT_TYPE_NAME (widget),
10752 /* style pspecs are always readable so we can spare that check here */
10754 peek_value = _gtk_style_peek_property_value (priv->style,
10755 G_OBJECT_TYPE (widget),
10757 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10758 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10761 g_warning ("%s: %s", G_STRLOC, error);
10766 name = va_arg (var_args, gchar*);
10769 g_object_unref (widget);
10773 * gtk_widget_style_get:
10774 * @widget: a #GtkWidget
10775 * @first_property_name: the name of the first property to get
10776 * @Varargs: pairs of property names and locations to
10777 * return the property values, starting with the location for
10778 * @first_property_name, terminated by %NULL.
10780 * Gets the values of a multiple style properties of @widget.
10783 gtk_widget_style_get (GtkWidget *widget,
10784 const gchar *first_property_name,
10789 g_return_if_fail (GTK_IS_WIDGET (widget));
10791 va_start (var_args, first_property_name);
10792 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10798 * @widget: a #GtkWidget
10799 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10800 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10801 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10803 * Obtains the full path to @widget. The path is simply the name of a
10804 * widget and all its parents in the container hierarchy, separated by
10805 * periods. The name of a widget comes from
10806 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10807 * in gtkrc configuration files. Widget names are the type of the
10808 * widget by default (e.g. "GtkButton") or can be set to an
10809 * application-specific value with gtk_widget_set_name(). By setting
10810 * the name of a widget, you allow users or theme authors to apply
10811 * styles to that specific widget in their gtkrc
10812 * file. @path_reversed_p fills in the path in reverse order,
10813 * i.e. starting with @widget's name instead of starting with the name
10814 * of @widget's outermost ancestor.
10817 gtk_widget_path (GtkWidget *widget,
10818 guint *path_length,
10820 gchar **path_reversed)
10822 static gchar *rev_path = NULL;
10823 static guint tmp_path_len = 0;
10826 g_return_if_fail (GTK_IS_WIDGET (widget));
10831 const gchar *string;
10836 string = gtk_widget_get_name (widget);
10837 l = strlen (string);
10838 while (tmp_path_len <= len + l + 1)
10840 tmp_path_len += INIT_PATH_SIZE;
10841 rev_path = g_realloc (rev_path, tmp_path_len);
10843 s = string + l - 1;
10844 d = rev_path + len;
10845 while (s >= string)
10849 widget = widget->priv->parent;
10852 rev_path[len++] = '.';
10854 rev_path[len++] = 0;
10859 *path_length = len - 1;
10861 *path_reversed = g_strdup (rev_path);
10864 *path = g_strdup (rev_path);
10865 g_strreverse (*path);
10870 * gtk_widget_class_path:
10871 * @widget: a #GtkWidget
10872 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10873 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10874 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10877 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10878 * never uses a custom name set with gtk_widget_set_name().
10882 gtk_widget_class_path (GtkWidget *widget,
10883 guint *path_length,
10885 gchar **path_reversed)
10887 static gchar *rev_path = NULL;
10888 static guint tmp_path_len = 0;
10891 g_return_if_fail (GTK_IS_WIDGET (widget));
10896 const gchar *string;
10901 string = g_type_name (G_OBJECT_TYPE (widget));
10902 l = strlen (string);
10903 while (tmp_path_len <= len + l + 1)
10905 tmp_path_len += INIT_PATH_SIZE;
10906 rev_path = g_realloc (rev_path, tmp_path_len);
10908 s = string + l - 1;
10909 d = rev_path + len;
10910 while (s >= string)
10914 widget = widget->priv->parent;
10917 rev_path[len++] = '.';
10919 rev_path[len++] = 0;
10924 *path_length = len - 1;
10926 *path_reversed = g_strdup (rev_path);
10929 *path = g_strdup (rev_path);
10930 g_strreverse (*path);
10935 * gtk_requisition_new:
10937 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10939 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10940 * be freed with gtk_requisition_free().
10945 gtk_requisition_new (void)
10947 return g_slice_new0 (GtkRequisition);
10951 * gtk_requisition_copy:
10952 * @requisition: a #GtkRequisition
10954 * Copies a #GtkRequisition.
10956 * Returns: a copy of @requisition
10959 gtk_requisition_copy (const GtkRequisition *requisition)
10961 return g_slice_dup (GtkRequisition, requisition);
10965 * gtk_requisition_free:
10966 * @requisition: a #GtkRequisition
10968 * Frees a #GtkRequisition.
10971 gtk_requisition_free (GtkRequisition *requisition)
10973 g_slice_free (GtkRequisition, requisition);
10976 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10977 gtk_requisition_copy,
10978 gtk_requisition_free)
10981 * gtk_widget_get_accessible:
10982 * @widget: a #GtkWidget
10984 * Returns the accessible object that describes the widget to an
10985 * assistive technology.
10987 * If no accessibility library is loaded (i.e. no ATK implementation library is
10988 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10989 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10990 * if no class-specific #AtkObject implementation is available for the widget
10991 * instance in question, it will inherit an #AtkObject implementation from the
10992 * first ancestor class for which such an implementation is defined.
10994 * The documentation of the
10995 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
10996 * library contains more information about accessible objects and their uses.
10998 * Returns: (transfer none): the #AtkObject associated with @widget
11001 gtk_widget_get_accessible (GtkWidget *widget)
11003 GtkWidgetClass *klass;
11005 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11007 klass = GTK_WIDGET_GET_CLASS (widget);
11009 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11011 return klass->get_accessible (widget);
11015 gtk_widget_real_get_accessible (GtkWidget *widget)
11017 AtkObject* accessible;
11019 accessible = g_object_get_qdata (G_OBJECT (widget),
11020 quark_accessible_object);
11023 AtkObjectFactory *factory;
11024 AtkRegistry *default_registry;
11026 default_registry = atk_get_default_registry ();
11027 factory = atk_registry_get_factory (default_registry,
11028 G_TYPE_FROM_INSTANCE (widget));
11030 atk_object_factory_create_accessible (factory,
11031 G_OBJECT (widget));
11032 g_object_set_qdata (G_OBJECT (widget),
11033 quark_accessible_object,
11040 * Initialize a AtkImplementorIface instance's virtual pointers as
11041 * appropriate to this implementor's class (GtkWidget).
11044 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11046 iface->ref_accessible = gtk_widget_ref_accessible;
11050 gtk_widget_ref_accessible (AtkImplementor *implementor)
11052 AtkObject *accessible;
11054 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11056 g_object_ref (accessible);
11061 * Expand flag management
11065 gtk_widget_update_computed_expand (GtkWidget *widget)
11067 GtkWidgetPrivate *priv;
11069 priv = widget->priv;
11071 if (priv->need_compute_expand)
11075 if (priv->hexpand_set)
11080 if (priv->vexpand_set)
11085 /* we don't need to use compute_expand if both expands are
11086 * forced by the app
11088 if (!(priv->hexpand_set && priv->vexpand_set))
11090 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11094 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11095 priv->hexpand_set ? &ignored : &h,
11096 priv->vexpand_set ? &ignored : &v);
11100 priv->need_compute_expand = FALSE;
11101 priv->computed_hexpand = h != FALSE;
11102 priv->computed_vexpand = v != FALSE;
11107 * gtk_widget_queue_compute_expand:
11108 * @widget: a #GtkWidget
11110 * Mark @widget as needing to recompute its expand flags. Call
11111 * this function when setting legacy expand child properties
11112 * on the child of a container.
11114 * See gtk_widget_compute_expand().
11117 gtk_widget_queue_compute_expand (GtkWidget *widget)
11120 gboolean changed_anything;
11122 if (widget->priv->need_compute_expand)
11125 changed_anything = FALSE;
11127 while (parent != NULL)
11129 if (!parent->priv->need_compute_expand)
11131 parent->priv->need_compute_expand = TRUE;
11132 changed_anything = TRUE;
11135 /* Note: if we had an invariant that "if a child needs to
11136 * compute expand, its parents also do" then we could stop going
11137 * up when we got to a parent that already needed to
11138 * compute. However, in general we compute expand lazily (as
11139 * soon as we see something in a subtree that is expand, we know
11140 * we're expanding) and so this invariant does not hold and we
11141 * have to always walk all the way up in case some ancestor
11142 * is not currently need_compute_expand.
11145 parent = parent->priv->parent;
11148 /* recomputing expand always requires
11149 * a relayout as well
11151 if (changed_anything)
11152 gtk_widget_queue_resize (widget);
11156 * gtk_widget_compute_expand:
11157 * @widget: the widget
11158 * @orientation: expand direction
11160 * Computes whether a container should give this widget extra space
11161 * when possible. Containers should check this, rather than
11162 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11164 * This function already checks whether the widget is visible, so
11165 * visibility does not need to be checked separately. Non-visible
11166 * widgets are not expanded.
11168 * The computed expand value uses either the expand setting explicitly
11169 * set on the widget itself, or, if none has been explicitly set,
11170 * the widget may expand if some of its children do.
11172 * Return value: whether widget tree rooted here should be expanded
11175 gtk_widget_compute_expand (GtkWidget *widget,
11176 GtkOrientation orientation)
11178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11180 /* We never make a widget expand if not even showing. */
11181 if (!gtk_widget_get_visible (widget))
11184 gtk_widget_update_computed_expand (widget);
11186 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11188 return widget->priv->computed_hexpand;
11192 return widget->priv->computed_vexpand;
11197 gtk_widget_set_expand (GtkWidget *widget,
11198 GtkOrientation orientation,
11201 const char *expand_prop;
11202 const char *expand_set_prop;
11204 GtkWidgetPrivate *priv;
11206 g_return_if_fail (GTK_IS_WIDGET (widget));
11208 priv = widget->priv;
11210 expand = expand != FALSE;
11212 was_both = priv->hexpand && priv->vexpand;
11214 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11216 if (priv->hexpand_set &&
11217 priv->hexpand == expand)
11220 priv->hexpand_set = TRUE;
11221 priv->hexpand = expand;
11223 expand_prop = "hexpand";
11224 expand_set_prop = "hexpand-set";
11228 if (priv->vexpand_set &&
11229 priv->vexpand == expand)
11232 priv->vexpand_set = TRUE;
11233 priv->vexpand = expand;
11235 expand_prop = "vexpand";
11236 expand_set_prop = "vexpand-set";
11239 gtk_widget_queue_compute_expand (widget);
11241 g_object_freeze_notify (G_OBJECT (widget));
11242 g_object_notify (G_OBJECT (widget), expand_prop);
11243 g_object_notify (G_OBJECT (widget), expand_set_prop);
11244 if (was_both != (priv->hexpand && priv->vexpand))
11245 g_object_notify (G_OBJECT (widget), "expand");
11246 g_object_thaw_notify (G_OBJECT (widget));
11250 gtk_widget_set_expand_set (GtkWidget *widget,
11251 GtkOrientation orientation,
11254 GtkWidgetPrivate *priv;
11257 priv = widget->priv;
11259 set = set != FALSE;
11261 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11263 if (set == priv->hexpand_set)
11266 priv->hexpand_set = set;
11267 prop = "hexpand-set";
11271 if (set == priv->vexpand_set)
11274 priv->vexpand_set = set;
11275 prop = "vexpand-set";
11278 gtk_widget_queue_compute_expand (widget);
11280 g_object_notify (G_OBJECT (widget), prop);
11284 * gtk_widget_get_hexpand:
11285 * @widget: the widget
11287 * Gets whether the widget would like any available extra horizontal
11288 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11289 * generally receive the extra space. For example, a list or
11290 * scrollable area or document in your window would often be set to
11293 * Containers should use gtk_widget_compute_expand() rather than
11294 * this function, to see whether a widget, or any of its children,
11295 * has the expand flag set. If any child of a widget wants to
11296 * expand, the parent may ask to expand also.
11298 * This function only looks at the widget's own hexpand flag, rather
11299 * than computing whether the entire widget tree rooted at this widget
11302 * Return value: whether hexpand flag is set
11305 gtk_widget_get_hexpand (GtkWidget *widget)
11307 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11309 return widget->priv->hexpand;
11313 * gtk_widget_set_hexpand:
11314 * @widget: the widget
11315 * @expand: whether to expand
11317 * Sets whether the widget would like any available extra horizontal
11318 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11319 * generally receive the extra space. For example, a list or
11320 * scrollable area or document in your window would often be set to
11323 * Call this function to set the expand flag if you would like your
11324 * widget to become larger horizontally when the window has extra
11327 * By default, widgets automatically expand if any of their children
11328 * want to expand. (To see if a widget will automatically expand given
11329 * its current children and state, call gtk_widget_compute_expand(). A
11330 * container can decide how the expandability of children affects the
11331 * expansion of the container by overriding the compute_expand virtual
11332 * method on #GtkWidget.).
11334 * Setting hexpand explicitly with this function will override the
11335 * automatic expand behavior.
11337 * This function forces the widget to expand or not to expand,
11338 * regardless of children. The override occurs because
11339 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11340 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11341 * value to be used, rather than looking at children and widget state.
11344 gtk_widget_set_hexpand (GtkWidget *widget,
11347 g_return_if_fail (GTK_IS_WIDGET (widget));
11349 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11353 * gtk_widget_get_hexpand_set:
11354 * @widget: the widget
11356 * Gets whether gtk_widget_set_hexpand() has been used to
11357 * explicitly set the expand flag on this widget.
11359 * If hexpand is set, then it overrides any computed
11360 * expand value based on child widgets. If hexpand is not
11361 * set, then the expand value depends on whether any
11362 * children of the widget would like to expand.
11364 * There are few reasons to use this function, but it's here
11365 * for completeness and consistency.
11367 * Return value: whether hexpand has been explicitly set
11370 gtk_widget_get_hexpand_set (GtkWidget *widget)
11372 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11374 return widget->priv->hexpand_set;
11378 * gtk_widget_set_hexpand_set:
11379 * @widget: the widget
11380 * @set: value for hexpand-set property
11382 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11385 * The hexpand-set property will be set automatically when you call
11386 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11387 * reason to use this function would be to unset an explicit expand
11390 * If hexpand is set, then it overrides any computed
11391 * expand value based on child widgets. If hexpand is not
11392 * set, then the expand value depends on whether any
11393 * children of the widget would like to expand.
11395 * There are few reasons to use this function, but it's here
11396 * for completeness and consistency.
11398 * Return value: whether hexpand has been explicitly set
11401 gtk_widget_set_hexpand_set (GtkWidget *widget,
11404 g_return_if_fail (GTK_IS_WIDGET (widget));
11406 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11411 * gtk_widget_get_vexpand:
11412 * @widget: the widget
11414 * Gets whether the widget would like any available extra vertical
11417 * See gtk_widget_get_hexpand() for more detail.
11419 * Return value: whether vexpand flag is set
11422 gtk_widget_get_vexpand (GtkWidget *widget)
11424 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11426 return widget->priv->vexpand;
11430 * gtk_widget_set_vexpand:
11431 * @widget: the widget
11432 * @expand: whether to expand
11434 * Sets whether the widget would like any available extra vertical
11437 * See gtk_widget_set_hexpand() for more detail.
11440 gtk_widget_set_vexpand (GtkWidget *widget,
11443 g_return_if_fail (GTK_IS_WIDGET (widget));
11445 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11449 * gtk_widget_get_vexpand_set:
11450 * @widget: the widget
11452 * Gets whether gtk_widget_set_vexpand() has been used to
11453 * explicitly set the expand flag on this widget.
11455 * See gtk_widget_get_hexpand_set() for more detail.
11457 * Return value: whether vexpand has been explicitly set
11460 gtk_widget_get_vexpand_set (GtkWidget *widget)
11462 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11464 return widget->priv->vexpand_set;
11468 * gtk_widget_set_vexpand_set:
11469 * @widget: the widget
11470 * @set: value for vexpand-set property
11472 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11475 * See gtk_widget_set_hexpand_set() for more detail.
11477 * Return value: whether vexpand has been explicitly set
11480 gtk_widget_set_vexpand_set (GtkWidget *widget,
11483 g_return_if_fail (GTK_IS_WIDGET (widget));
11485 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11489 * GtkBuildable implementation
11491 static GQuark quark_builder_has_default = 0;
11492 static GQuark quark_builder_has_focus = 0;
11493 static GQuark quark_builder_atk_relations = 0;
11494 static GQuark quark_builder_set_name = 0;
11497 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11499 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11500 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11501 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11502 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11504 iface->set_name = gtk_widget_buildable_set_name;
11505 iface->get_name = gtk_widget_buildable_get_name;
11506 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11507 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11508 iface->parser_finished = gtk_widget_buildable_parser_finished;
11509 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11510 iface->custom_finished = gtk_widget_buildable_custom_finished;
11514 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11517 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11518 g_strdup (name), g_free);
11521 static const gchar *
11522 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11524 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11528 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11529 GtkBuilder *builder,
11530 const gchar *childname)
11532 if (strcmp (childname, "accessible") == 0)
11533 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11539 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11540 GtkBuilder *builder,
11542 const GValue *value)
11544 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11545 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11546 GINT_TO_POINTER (TRUE));
11547 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11548 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11549 GINT_TO_POINTER (TRUE));
11551 g_object_set_property (G_OBJECT (buildable), name, value);
11556 gchar *action_name;
11557 GString *description;
11559 gboolean translatable;
11569 free_action (AtkActionData *data, gpointer user_data)
11571 g_free (data->action_name);
11572 g_string_free (data->description, TRUE);
11573 g_free (data->context);
11574 g_slice_free (AtkActionData, data);
11578 free_relation (AtkRelationData *data, gpointer user_data)
11580 g_free (data->target);
11581 g_free (data->type);
11582 g_slice_free (AtkRelationData, data);
11586 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11587 GtkBuilder *builder)
11589 GSList *atk_relations;
11591 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11592 gtk_widget_grab_default (GTK_WIDGET (buildable));
11593 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11594 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11596 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11597 quark_builder_atk_relations);
11600 AtkObject *accessible;
11601 AtkRelationSet *relation_set;
11604 AtkRelationType relation_type;
11605 AtkObject *target_accessible;
11607 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11608 relation_set = atk_object_ref_relation_set (accessible);
11610 for (l = atk_relations; l; l = l->next)
11612 AtkRelationData *relation = (AtkRelationData*)l->data;
11614 target = gtk_builder_get_object (builder, relation->target);
11617 g_warning ("Target object %s in <relation> does not exist",
11621 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11622 g_assert (target_accessible != NULL);
11624 relation_type = atk_relation_type_for_name (relation->type);
11625 if (relation_type == ATK_RELATION_NULL)
11627 g_warning ("<relation> type %s not found",
11631 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11632 target_accessible);
11634 g_object_unref (relation_set);
11636 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11637 g_slist_free (atk_relations);
11638 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11647 } AccessibilitySubParserData;
11650 accessibility_start_element (GMarkupParseContext *context,
11651 const gchar *element_name,
11652 const gchar **names,
11653 const gchar **values,
11654 gpointer user_data,
11657 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11659 gint line_number, char_number;
11661 if (strcmp (element_name, "relation") == 0)
11663 gchar *target = NULL;
11664 gchar *type = NULL;
11665 AtkRelationData *relation;
11667 for (i = 0; names[i]; i++)
11669 if (strcmp (names[i], "target") == 0)
11670 target = g_strdup (values[i]);
11671 else if (strcmp (names[i], "type") == 0)
11672 type = g_strdup (values[i]);
11675 g_markup_parse_context_get_position (context,
11678 g_set_error (error,
11680 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11681 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11683 line_number, char_number, names[i], "relation");
11690 if (!target || !type)
11692 g_markup_parse_context_get_position (context,
11695 g_set_error (error,
11697 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11698 "%s:%d:%d <%s> requires attribute \"%s\"",
11700 line_number, char_number, "relation",
11701 type ? "target" : "type");
11707 relation = g_slice_new (AtkRelationData);
11708 relation->target = target;
11709 relation->type = type;
11711 data->relations = g_slist_prepend (data->relations, relation);
11713 else if (strcmp (element_name, "action") == 0)
11715 const gchar *action_name = NULL;
11716 const gchar *description = NULL;
11717 const gchar *msg_context = NULL;
11718 gboolean translatable = FALSE;
11719 AtkActionData *action;
11721 for (i = 0; names[i]; i++)
11723 if (strcmp (names[i], "action_name") == 0)
11724 action_name = values[i];
11725 else if (strcmp (names[i], "description") == 0)
11726 description = values[i];
11727 else if (strcmp (names[i], "translatable") == 0)
11729 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11732 else if (strcmp (names[i], "comments") == 0)
11734 /* do nothing, comments are for translators */
11736 else if (strcmp (names[i], "context") == 0)
11737 msg_context = values[i];
11740 g_markup_parse_context_get_position (context,
11743 g_set_error (error,
11745 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11746 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11748 line_number, char_number, names[i], "action");
11755 g_markup_parse_context_get_position (context,
11758 g_set_error (error,
11760 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11761 "%s:%d:%d <%s> requires attribute \"%s\"",
11763 line_number, char_number, "action",
11768 action = g_slice_new (AtkActionData);
11769 action->action_name = g_strdup (action_name);
11770 action->description = g_string_new (description);
11771 action->context = g_strdup (msg_context);
11772 action->translatable = translatable;
11774 data->actions = g_slist_prepend (data->actions, action);
11776 else if (strcmp (element_name, "accessibility") == 0)
11779 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11783 accessibility_text (GMarkupParseContext *context,
11786 gpointer user_data,
11789 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11791 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11793 AtkActionData *action = data->actions->data;
11795 g_string_append_len (action->description, text, text_len);
11799 static const GMarkupParser accessibility_parser =
11801 accessibility_start_element,
11803 accessibility_text,
11812 } AccelGroupParserData;
11815 accel_group_start_element (GMarkupParseContext *context,
11816 const gchar *element_name,
11817 const gchar **names,
11818 const gchar **values,
11819 gpointer user_data,
11824 guint modifiers = 0;
11825 gchar *signal = NULL;
11826 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11828 for (i = 0; names[i]; i++)
11830 if (strcmp (names[i], "key") == 0)
11831 key = gdk_keyval_from_name (values[i]);
11832 else if (strcmp (names[i], "modifiers") == 0)
11834 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11840 else if (strcmp (names[i], "signal") == 0)
11841 signal = g_strdup (values[i]);
11844 if (key == 0 || signal == NULL)
11846 g_warning ("<accelerator> requires key and signal attributes");
11849 parser_data->key = key;
11850 parser_data->modifiers = modifiers;
11851 parser_data->signal = signal;
11854 static const GMarkupParser accel_group_parser =
11856 accel_group_start_element,
11860 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11861 GtkBuilder *builder,
11863 const gchar *tagname,
11864 GMarkupParser *parser,
11867 g_assert (buildable);
11869 if (strcmp (tagname, "accelerator") == 0)
11871 AccelGroupParserData *parser_data;
11873 parser_data = g_slice_new0 (AccelGroupParserData);
11874 parser_data->object = g_object_ref (buildable);
11875 *parser = accel_group_parser;
11876 *data = parser_data;
11879 if (strcmp (tagname, "accessibility") == 0)
11881 AccessibilitySubParserData *parser_data;
11883 parser_data = g_slice_new0 (AccessibilitySubParserData);
11884 *parser = accessibility_parser;
11885 *data = parser_data;
11892 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11893 GtkWidget *toplevel,
11894 gpointer user_data)
11896 AccelGroupParserData *accel_data;
11897 GSList *accel_groups;
11898 GtkAccelGroup *accel_group;
11900 g_return_if_fail (GTK_IS_WIDGET (widget));
11901 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11902 g_return_if_fail (user_data != NULL);
11904 accel_data = (AccelGroupParserData*)user_data;
11905 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11906 if (g_slist_length (accel_groups) == 0)
11908 accel_group = gtk_accel_group_new ();
11909 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11913 g_assert (g_slist_length (accel_groups) == 1);
11914 accel_group = g_slist_nth_data (accel_groups, 0);
11917 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11918 accel_data->signal,
11921 accel_data->modifiers,
11922 GTK_ACCEL_VISIBLE);
11924 g_object_unref (accel_data->object);
11925 g_free (accel_data->signal);
11926 g_slice_free (AccelGroupParserData, accel_data);
11930 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11931 GtkBuilder *builder,
11933 const gchar *tagname,
11934 gpointer user_data)
11936 AccelGroupParserData *accel_data;
11937 AccessibilitySubParserData *a11y_data;
11938 GtkWidget *toplevel;
11940 if (strcmp (tagname, "accelerator") == 0)
11942 accel_data = (AccelGroupParserData*)user_data;
11943 g_assert (accel_data->object);
11945 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11947 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11949 else if (strcmp (tagname, "accessibility") == 0)
11951 a11y_data = (AccessibilitySubParserData*)user_data;
11953 if (a11y_data->actions)
11955 AtkObject *accessible;
11960 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11962 action = ATK_ACTION (accessible);
11963 n_actions = atk_action_get_n_actions (action);
11965 for (l = a11y_data->actions; l; l = l->next)
11967 AtkActionData *action_data = (AtkActionData*)l->data;
11969 for (i = 0; i < n_actions; i++)
11970 if (strcmp (atk_action_get_name (action, i),
11971 action_data->action_name) == 0)
11976 gchar *description;
11978 if (action_data->translatable && action_data->description->len)
11979 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11980 action_data->context,
11981 action_data->description->str);
11983 description = action_data->description->str;
11985 atk_action_set_description (action, i, description);
11989 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11990 g_slist_free (a11y_data->actions);
11993 if (a11y_data->relations)
11994 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11995 a11y_data->relations);
11997 g_slice_free (AccessibilitySubParserData, a11y_data);
12002 gtk_widget_real_get_width (GtkWidget *widget,
12003 gint *minimum_size,
12004 gint *natural_size)
12014 gtk_widget_real_get_height (GtkWidget *widget,
12015 gint *minimum_size,
12016 gint *natural_size)
12026 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12028 gint *minimum_height,
12029 gint *natural_height)
12031 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12035 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12037 gint *minimum_width,
12038 gint *natural_width)
12040 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12044 * gtk_widget_get_halign:
12045 * @widget: a #GtkWidget
12047 * Gets the value of the #GtkWidget:halign property.
12049 * Returns: the horizontal alignment of @widget
12052 gtk_widget_get_halign (GtkWidget *widget)
12054 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12055 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12059 * gtk_widget_set_halign:
12060 * @widget: a #GtkWidget
12061 * @align: the horizontal alignment
12063 * Sets the horizontal alignment of @widget.
12064 * See the #GtkWidget:halign property.
12067 gtk_widget_set_halign (GtkWidget *widget,
12070 GtkWidgetAuxInfo *aux_info;
12072 g_return_if_fail (GTK_IS_WIDGET (widget));
12074 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12076 if (aux_info->halign == align)
12079 aux_info->halign = align;
12080 gtk_widget_queue_resize (widget);
12081 g_object_notify (G_OBJECT (widget), "halign");
12085 * gtk_widget_get_valign:
12086 * @widget: a #GtkWidget
12088 * Gets the value of the #GtkWidget:valign property.
12090 * Returns: the vertical alignment of @widget
12093 gtk_widget_get_valign (GtkWidget *widget)
12095 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12096 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12100 * gtk_widget_set_valign:
12101 * @widget: a #GtkWidget
12102 * @align: the vertical alignment
12104 * Sets the vertical alignment of @widget.
12105 * See the #GtkWidget:valign property.
12108 gtk_widget_set_valign (GtkWidget *widget,
12111 GtkWidgetAuxInfo *aux_info;
12113 g_return_if_fail (GTK_IS_WIDGET (widget));
12115 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12117 if (aux_info->valign == align)
12120 aux_info->valign = align;
12121 gtk_widget_queue_resize (widget);
12122 g_object_notify (G_OBJECT (widget), "valign");
12126 * gtk_widget_get_margin_left:
12127 * @widget: a #GtkWidget
12129 * Gets the value of the #GtkWidget:margin-left property.
12131 * Returns: The left margin of @widget
12134 gtk_widget_get_margin_left (GtkWidget *widget)
12136 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12138 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12142 * gtk_widget_set_margin_left:
12143 * @widget: a #GtkWidget
12144 * @margin: the left margin
12146 * Sets the left margin of @widget.
12147 * See the #GtkWidget:margin-left property.
12150 gtk_widget_set_margin_left (GtkWidget *widget,
12153 GtkWidgetAuxInfo *aux_info;
12155 g_return_if_fail (GTK_IS_WIDGET (widget));
12156 g_return_if_fail (margin <= G_MAXINT16);
12158 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12160 if (aux_info->margin.left == margin)
12163 aux_info->margin.left = margin;
12164 gtk_widget_queue_resize (widget);
12165 g_object_notify (G_OBJECT (widget), "margin-left");
12169 * gtk_widget_get_margin_right:
12170 * @widget: a #GtkWidget
12172 * Gets the value of the #GtkWidget:margin-right property.
12174 * Returns: The left margin of @widget
12177 gtk_widget_get_margin_right (GtkWidget *widget)
12179 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12181 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12185 * gtk_widget_set_margin_right:
12186 * @widget: a #GtkWidget
12187 * @margin: the right margin
12189 * Sets the right margin of @widget.
12190 * See the #GtkWidget:margin-right property.
12193 gtk_widget_set_margin_right (GtkWidget *widget,
12196 GtkWidgetAuxInfo *aux_info;
12198 g_return_if_fail (GTK_IS_WIDGET (widget));
12199 g_return_if_fail (margin <= G_MAXINT16);
12201 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12203 if (aux_info->margin.right == margin)
12206 aux_info->margin.right = margin;
12207 gtk_widget_queue_resize (widget);
12208 g_object_notify (G_OBJECT (widget), "margin-right");
12212 * gtk_widget_get_margin_top:
12213 * @widget: a #GtkWidget
12215 * Gets the value of the #GtkWidget:margin-top property.
12217 * Returns: The top margin of @widget
12220 gtk_widget_get_margin_top (GtkWidget *widget)
12222 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12224 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12228 * gtk_widget_set_margin_top:
12229 * @widget: a #GtkWidget
12230 * @margin: the top margin
12232 * Sets the top margin of @widget.
12233 * See the #GtkWidget:margin-top property.
12236 gtk_widget_set_margin_top (GtkWidget *widget,
12239 GtkWidgetAuxInfo *aux_info;
12241 g_return_if_fail (GTK_IS_WIDGET (widget));
12242 g_return_if_fail (margin <= G_MAXINT16);
12244 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12246 if (aux_info->margin.top == margin)
12249 aux_info->margin.top = margin;
12250 gtk_widget_queue_resize (widget);
12251 g_object_notify (G_OBJECT (widget), "margin-top");
12255 * gtk_widget_get_margin_bottom:
12256 * @widget: a #GtkWidget
12258 * Gets the value of the #GtkWidget:margin-bottom property.
12260 * Returns: The bottom margin of @widget
12263 gtk_widget_get_margin_bottom (GtkWidget *widget)
12265 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12267 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12271 * gtk_widget_set_margin_bottom:
12272 * @widget: a #GtkWidget
12273 * @margin: the bottom margin
12275 * Sets the bottom margin of @widget.
12276 * See the #GtkWidget:margin-bottom property.
12279 gtk_widget_set_margin_bottom (GtkWidget *widget,
12282 GtkWidgetAuxInfo *aux_info;
12284 g_return_if_fail (GTK_IS_WIDGET (widget));
12285 g_return_if_fail (margin <= G_MAXINT16);
12287 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12289 if (aux_info->margin.bottom == margin)
12292 aux_info->margin.bottom = margin;
12293 gtk_widget_queue_resize (widget);
12294 g_object_notify (G_OBJECT (widget), "margin-bottom");
12298 * gtk_widget_get_clipboard:
12299 * @widget: a #GtkWidget
12300 * @selection: a #GdkAtom which identifies the clipboard
12301 * to use. %GDK_SELECTION_CLIPBOARD gives the
12302 * default clipboard. Another common value
12303 * is %GDK_SELECTION_PRIMARY, which gives
12304 * the primary X selection.
12306 * Returns the clipboard object for the given selection to
12307 * be used with @widget. @widget must have a #GdkDisplay
12308 * associated with it, so must be attached to a toplevel
12311 * Return value: (transfer none): the appropriate clipboard object. If no
12312 * clipboard already exists, a new one will
12313 * be created. Once a clipboard object has
12314 * been created, it is persistent for all time.
12319 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12321 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12322 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12324 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12329 * gtk_widget_list_mnemonic_labels:
12330 * @widget: a #GtkWidget
12332 * Returns a newly allocated list of the widgets, normally labels, for
12333 * which this widget is the target of a mnemonic (see for example,
12334 * gtk_label_set_mnemonic_widget()).
12336 * The widgets in the list are not individually referenced. If you
12337 * want to iterate through the list and perform actions involving
12338 * callbacks that might destroy the widgets, you
12339 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12340 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12341 * widgets afterwards.
12343 * Return value: (element-type GtkWidget) (transfer container): the list of
12344 * mnemonic labels; free this list
12345 * with g_list_free() when you are done with it.
12350 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12352 GList *list = NULL;
12355 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12357 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12358 list = g_list_prepend (list, l->data);
12364 * gtk_widget_add_mnemonic_label:
12365 * @widget: a #GtkWidget
12366 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12368 * Adds a widget to the list of mnemonic labels for
12369 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12370 * list of mnemonic labels for the widget is cleared when the
12371 * widget is destroyed, so the caller must make sure to update
12372 * its internal state at this point as well, by using a connection
12373 * to the #GtkWidget::destroy signal or a weak notifier.
12378 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12381 GSList *old_list, *new_list;
12383 g_return_if_fail (GTK_IS_WIDGET (widget));
12384 g_return_if_fail (GTK_IS_WIDGET (label));
12386 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12387 new_list = g_slist_prepend (old_list, label);
12389 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12390 new_list, (GDestroyNotify) g_slist_free);
12394 * gtk_widget_remove_mnemonic_label:
12395 * @widget: a #GtkWidget
12396 * @label: a #GtkWidget that was previously set as a mnemnic label for
12397 * @widget with gtk_widget_add_mnemonic_label().
12399 * Removes a widget from the list of mnemonic labels for
12400 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12401 * must have previously been added to the list with
12402 * gtk_widget_add_mnemonic_label().
12407 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12410 GSList *old_list, *new_list;
12412 g_return_if_fail (GTK_IS_WIDGET (widget));
12413 g_return_if_fail (GTK_IS_WIDGET (label));
12415 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12416 new_list = g_slist_remove (old_list, label);
12419 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12420 new_list, (GDestroyNotify) g_slist_free);
12424 * gtk_widget_get_no_show_all:
12425 * @widget: a #GtkWidget
12427 * Returns the current value of the #GtkWidget:no-show-all property,
12428 * which determines whether calls to gtk_widget_show_all()
12429 * will affect this widget.
12431 * Return value: the current value of the "no-show-all" property.
12436 gtk_widget_get_no_show_all (GtkWidget *widget)
12438 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12440 return widget->priv->no_show_all;
12444 * gtk_widget_set_no_show_all:
12445 * @widget: a #GtkWidget
12446 * @no_show_all: the new value for the "no-show-all" property
12448 * Sets the #GtkWidget:no-show-all property, which determines whether
12449 * calls to gtk_widget_show_all() will affect this widget.
12451 * This is mostly for use in constructing widget hierarchies with externally
12452 * controlled visibility, see #GtkUIManager.
12457 gtk_widget_set_no_show_all (GtkWidget *widget,
12458 gboolean no_show_all)
12460 g_return_if_fail (GTK_IS_WIDGET (widget));
12462 no_show_all = (no_show_all != FALSE);
12464 if (widget->priv->no_show_all != no_show_all)
12466 widget->priv->no_show_all = no_show_all;
12468 g_object_notify (G_OBJECT (widget), "no-show-all");
12474 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12475 gboolean has_tooltip,
12478 GtkWidgetPrivate *priv = widget->priv;
12479 gboolean priv_has_tooltip;
12481 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12482 quark_has_tooltip));
12484 if (priv_has_tooltip != has_tooltip || force)
12486 priv_has_tooltip = has_tooltip;
12488 if (priv_has_tooltip)
12490 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12491 gdk_window_set_events (priv->window,
12492 gdk_window_get_events (priv->window) |
12493 GDK_LEAVE_NOTIFY_MASK |
12494 GDK_POINTER_MOTION_MASK |
12495 GDK_POINTER_MOTION_HINT_MASK);
12497 if (gtk_widget_get_has_window (widget))
12498 gtk_widget_add_events (widget,
12499 GDK_LEAVE_NOTIFY_MASK |
12500 GDK_POINTER_MOTION_MASK |
12501 GDK_POINTER_MOTION_HINT_MASK);
12504 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12505 GUINT_TO_POINTER (priv_has_tooltip));
12510 * gtk_widget_set_tooltip_window:
12511 * @widget: a #GtkWidget
12512 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12514 * Replaces the default, usually yellow, window used for displaying
12515 * tooltips with @custom_window. GTK+ will take care of showing and
12516 * hiding @custom_window at the right moment, to behave likewise as
12517 * the default tooltip window. If @custom_window is %NULL, the default
12518 * tooltip window will be used.
12520 * If the custom window should have the default theming it needs to
12521 * have the name "gtk-tooltip", see gtk_widget_set_name().
12526 gtk_widget_set_tooltip_window (GtkWidget *widget,
12527 GtkWindow *custom_window)
12529 gboolean has_tooltip;
12530 gchar *tooltip_markup;
12532 g_return_if_fail (GTK_IS_WIDGET (widget));
12533 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12535 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12538 g_object_ref (custom_window);
12540 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12541 custom_window, g_object_unref);
12543 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12544 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12546 if (has_tooltip && gtk_widget_get_visible (widget))
12547 gtk_widget_queue_tooltip_query (widget);
12551 * gtk_widget_get_tooltip_window:
12552 * @widget: a #GtkWidget
12554 * Returns the #GtkWindow of the current tooltip. This can be the
12555 * GtkWindow created by default, or the custom tooltip window set
12556 * using gtk_widget_set_tooltip_window().
12558 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12563 gtk_widget_get_tooltip_window (GtkWidget *widget)
12565 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12567 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12571 * gtk_widget_trigger_tooltip_query:
12572 * @widget: a #GtkWidget
12574 * Triggers a tooltip query on the display where the toplevel of @widget
12575 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12581 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12583 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12586 static guint tooltip_query_id;
12587 static GSList *tooltip_query_displays;
12590 tooltip_query_idle (gpointer data)
12592 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12593 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12594 g_slist_free (tooltip_query_displays);
12596 tooltip_query_displays = NULL;
12597 tooltip_query_id = 0;
12603 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12605 GdkDisplay *display;
12607 display = gtk_widget_get_display (widget);
12609 if (!g_slist_find (tooltip_query_displays, display))
12610 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12612 if (tooltip_query_id == 0)
12613 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12617 * gtk_widget_set_tooltip_text:
12618 * @widget: a #GtkWidget
12619 * @text: the contents of the tooltip for @widget
12621 * Sets @text as the contents of the tooltip. This function will take
12622 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12623 * handler for the #GtkWidget::query-tooltip signal.
12625 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12630 gtk_widget_set_tooltip_text (GtkWidget *widget,
12633 g_return_if_fail (GTK_IS_WIDGET (widget));
12635 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12639 * gtk_widget_get_tooltip_text:
12640 * @widget: a #GtkWidget
12642 * Gets the contents of the tooltip for @widget.
12644 * Return value: the tooltip text, or %NULL. You should free the
12645 * returned string with g_free() when done.
12650 gtk_widget_get_tooltip_text (GtkWidget *widget)
12652 gchar *text = NULL;
12654 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12656 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12662 * gtk_widget_set_tooltip_markup:
12663 * @widget: a #GtkWidget
12664 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12666 * Sets @markup as the contents of the tooltip, which is marked up with
12667 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12669 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12670 * and of the default handler for the #GtkWidget::query-tooltip signal.
12672 * See also the #GtkWidget:tooltip-markup property and
12673 * gtk_tooltip_set_markup().
12678 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12679 const gchar *markup)
12681 g_return_if_fail (GTK_IS_WIDGET (widget));
12683 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12687 * gtk_widget_get_tooltip_markup:
12688 * @widget: a #GtkWidget
12690 * Gets the contents of the tooltip for @widget.
12692 * Return value: the tooltip text, or %NULL. You should free the
12693 * returned string with g_free() when done.
12698 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12700 gchar *text = NULL;
12702 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12704 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12710 * gtk_widget_set_has_tooltip:
12711 * @widget: a #GtkWidget
12712 * @has_tooltip: whether or not @widget has a tooltip.
12714 * Sets the has-tooltip property on @widget to @has_tooltip. See
12715 * #GtkWidget:has-tooltip for more information.
12720 gtk_widget_set_has_tooltip (GtkWidget *widget,
12721 gboolean has_tooltip)
12723 g_return_if_fail (GTK_IS_WIDGET (widget));
12725 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12729 * gtk_widget_get_has_tooltip:
12730 * @widget: a #GtkWidget
12732 * Returns the current value of the has-tooltip property. See
12733 * #GtkWidget:has-tooltip for more information.
12735 * Return value: current value of has-tooltip on @widget.
12740 gtk_widget_get_has_tooltip (GtkWidget *widget)
12742 gboolean has_tooltip = FALSE;
12744 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12746 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12748 return has_tooltip;
12752 * gtk_widget_get_allocation:
12753 * @widget: a #GtkWidget
12754 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12756 * Retrieves the widget's allocation.
12758 * Note, when implementing a #GtkContainer: a widget's allocation will
12759 * be its "adjusted" allocation, that is, the widget's parent
12760 * container typically calls gtk_widget_size_allocate() with an
12761 * allocation, and that allocation is then adjusted (to handle margin
12762 * and alignment for example) before assignment to the widget.
12763 * gtk_widget_get_allocation() returns the adjusted allocation that
12764 * was actually assigned to the widget. The adjusted allocation is
12765 * guaranteed to be completely contained within the
12766 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12767 * is guaranteed that its children stay inside the assigned bounds,
12768 * but not that they have exactly the bounds the container assigned.
12769 * There is no way to get the original allocation assigned by
12770 * gtk_widget_size_allocate(), since it isn't stored; if a container
12771 * implementation needs that information it will have to track it itself.
12776 gtk_widget_get_allocation (GtkWidget *widget,
12777 GtkAllocation *allocation)
12779 GtkWidgetPrivate *priv;
12781 g_return_if_fail (GTK_IS_WIDGET (widget));
12782 g_return_if_fail (allocation != NULL);
12784 priv = widget->priv;
12786 *allocation = priv->allocation;
12790 * gtk_widget_set_allocation:
12791 * @widget: a #GtkWidget
12792 * @allocation: a pointer to a #GtkAllocation to copy from
12794 * Sets the widget's allocation. This should not be used
12795 * directly, but from within a widget's size_allocate method.
12797 * The allocation set should be the "adjusted" or actual
12798 * allocation. If you're implementing a #GtkContainer, you want to use
12799 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12800 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12801 * allocation inside gtk_widget_size_allocate() to create an adjusted
12807 gtk_widget_set_allocation (GtkWidget *widget,
12808 const GtkAllocation *allocation)
12810 GtkWidgetPrivate *priv;
12812 g_return_if_fail (GTK_IS_WIDGET (widget));
12813 g_return_if_fail (allocation != NULL);
12815 priv = widget->priv;
12817 priv->allocation = *allocation;
12821 * gtk_widget_get_allocated_width:
12822 * @widget: the widget to query
12824 * Returns the width that has currently been allocated to @widget.
12825 * This function is intended to be used when implementing handlers
12826 * for the #GtkWidget::draw function.
12828 * Returns: the width of the @widget
12831 gtk_widget_get_allocated_width (GtkWidget *widget)
12833 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12835 return widget->priv->allocation.width;
12839 * gtk_widget_get_allocated_height:
12840 * @widget: the widget to query
12842 * Returns the height that has currently been allocated to @widget.
12843 * This function is intended to be used when implementing handlers
12844 * for the #GtkWidget::draw function.
12846 * Returns: the height of the @widget
12849 gtk_widget_get_allocated_height (GtkWidget *widget)
12851 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12853 return widget->priv->allocation.height;
12857 * gtk_widget_get_requisition:
12858 * @widget: a #GtkWidget
12859 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12861 * Retrieves the widget's requisition.
12863 * This function should only be used by widget implementations in
12864 * order to figure whether the widget's requisition has actually
12865 * changed after some internal state change (so that they can call
12866 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12868 * Normally, gtk_widget_size_request() should be used.
12872 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12873 * removed, If you need to cache sizes across requests and allocations,
12874 * add an explicit cache to the widget in question instead.
12877 gtk_widget_get_requisition (GtkWidget *widget,
12878 GtkRequisition *requisition)
12880 g_return_if_fail (GTK_IS_WIDGET (widget));
12881 g_return_if_fail (requisition != NULL);
12883 gtk_widget_get_preferred_size (widget, requisition, NULL);
12887 * gtk_widget_set_window:
12888 * @widget: a #GtkWidget
12889 * @window: a #GdkWindow
12891 * Sets a widget's window. This function should only be used in a
12892 * widget's #GtkWidget::realize implementation. The %window passed is
12893 * usually either new window created with gdk_window_new(), or the
12894 * window of its parent widget as returned by
12895 * gtk_widget_get_parent_window().
12897 * Widgets must indicate whether they will create their own #GdkWindow
12898 * by calling gtk_widget_set_has_window(). This is usually done in the
12899 * widget's init() function.
12901 * <note><para>This function does not add any reference to @window.</para></note>
12906 gtk_widget_set_window (GtkWidget *widget,
12909 GtkWidgetPrivate *priv;
12911 g_return_if_fail (GTK_IS_WIDGET (widget));
12912 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12914 priv = widget->priv;
12916 if (priv->window != window)
12918 priv->window = window;
12919 g_object_notify (G_OBJECT (widget), "window");
12924 * gtk_widget_get_window:
12925 * @widget: a #GtkWidget
12927 * Returns the widget's window if it is realized, %NULL otherwise
12929 * Return value: (transfer none): @widget's window.
12934 gtk_widget_get_window (GtkWidget *widget)
12936 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12938 return widget->priv->window;
12942 * gtk_widget_get_support_multidevice:
12943 * @widget: a #GtkWidget
12945 * Returns %TRUE if @widget is multiple pointer aware. See
12946 * gtk_widget_set_support_multidevice() for more information.
12948 * Returns: %TRUE is @widget is multidevice aware.
12951 gtk_widget_get_support_multidevice (GtkWidget *widget)
12953 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12955 return widget->priv->multidevice;
12959 * gtk_widget_set_support_multidevice:
12960 * @widget: a #GtkWidget
12961 * @support_multidevice: %TRUE to support input from multiple devices.
12963 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12964 * @widget will start receiving multiple, per device enter/leave events. Note
12965 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12966 * gdk_window_set_support_multidevice() will have to be called manually on them.
12971 gtk_widget_set_support_multidevice (GtkWidget *widget,
12972 gboolean support_multidevice)
12974 GtkWidgetPrivate *priv;
12976 g_return_if_fail (GTK_IS_WIDGET (widget));
12978 priv = widget->priv;
12980 if (support_multidevice)
12982 priv->multidevice = TRUE;
12983 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12987 priv->multidevice = FALSE;
12988 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12991 if (gtk_widget_get_realized (widget))
12992 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12996 _gtk_widget_set_has_focus (GtkWidget *widget,
12997 gboolean has_focus)
12999 widget->priv->has_focus = has_focus;
13003 * gtk_widget_send_focus_change:
13004 * @widget: a #GtkWidget
13005 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13007 * Sends the focus change @event to @widget
13009 * This function is not meant to be used by applications. The only time it
13010 * should be used is when it is necessary for a #GtkWidget to assign focus
13011 * to a widget that is semantically owned by the first widget even though
13012 * it's not a direct child - for instance, a search entry in a floating
13013 * window similar to the quick search in #GtkTreeView.
13015 * An example of its usage is:
13018 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13020 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13021 * fevent->focus_change.in = TRUE;
13022 * fevent->focus_change.window = gtk_widget_get_window (widget);
13023 * if (fevent->focus_change.window != NULL)
13024 * g_object_ref (fevent->focus_change.window);
13026 * gtk_widget_send_focus_change (widget, fevent);
13028 * gdk_event_free (event);
13031 * Return value: the return value from the event signal emission: %TRUE
13032 * if the event was handled, and %FALSE otherwise
13037 gtk_widget_send_focus_change (GtkWidget *widget,
13042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13043 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13045 g_object_ref (widget);
13047 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13049 res = gtk_widget_event (widget, event);
13051 g_object_notify (G_OBJECT (widget), "has-focus");
13053 g_object_unref (widget);
13059 * gtk_widget_in_destruction:
13060 * @widget: a #GtkWidget
13062 * Returns whether the widget is currently being destroyed.
13063 * This information can sometimes be used to avoid doing
13064 * unnecessary work.
13066 * Returns: %TRUE if @widget is being destroyed
13069 gtk_widget_in_destruction (GtkWidget *widget)
13071 return widget->priv->in_destruction;
13075 _gtk_widget_get_resize_pending (GtkWidget *widget)
13077 return widget->priv->resize_pending;
13081 _gtk_widget_set_resize_pending (GtkWidget *widget,
13082 gboolean resize_pending)
13084 widget->priv->resize_pending = resize_pending;
13088 _gtk_widget_get_in_reparent (GtkWidget *widget)
13090 return widget->priv->in_reparent;
13094 _gtk_widget_set_in_reparent (GtkWidget *widget,
13095 gboolean in_reparent)
13097 widget->priv->in_reparent = in_reparent;
13101 _gtk_widget_get_anchored (GtkWidget *widget)
13103 return widget->priv->anchored;
13107 _gtk_widget_set_anchored (GtkWidget *widget,
13110 widget->priv->anchored = anchored;
13114 _gtk_widget_get_shadowed (GtkWidget *widget)
13116 return widget->priv->shadowed;
13120 _gtk_widget_set_shadowed (GtkWidget *widget,
13123 widget->priv->shadowed = shadowed;
13127 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13129 return widget->priv->alloc_needed;
13133 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13134 gboolean alloc_needed)
13136 widget->priv->alloc_needed = alloc_needed;
13140 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13142 return widget->priv->width_request_needed;
13146 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13147 gboolean width_request_needed)
13149 widget->priv->width_request_needed = width_request_needed;
13153 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13155 return widget->priv->height_request_needed;
13159 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13160 gboolean height_request_needed)
13162 widget->priv->height_request_needed = height_request_needed;