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:
86 * <term>#GtkWidgetClass.get_request_mode()</term>
88 * This allows a widget to tell it's parent container whether
89 * it preferrs to be allocated in %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
90 * or %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT mode.
91 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH means the widget prefers to
92 * have #GtkWidgetClass.get_preferred_width() called and then
93 * #GtkWidgetClass.get_preferred_height_for_width() and is the
94 * default return for unimplemented cases.
95 * However it's important to note (as described below) that any
96 * widget which trades height-for-width must respond properly to
97 * both #GtkSizeRequestModes since it might be queried in either
98 * orientation by it's parent container.
102 * <term>#GtkWidgetClass.get_preferred_width()</term>
104 * This is called by containers to obtain the minimum and
105 * natural width of a widget. A widget will never be allocated
106 * a width less than it's minimum and will only ever be allocated
107 * a width greater than the natural width once all of the said
108 * widget's siblings have received their natural widths.
109 * Furthermore a widget will only ever be allocated a width greater
110 * than it's natural width if it was configured to receive extra
111 * expand space from it's parent container.
115 * <term>#GtkWidgetClass.get_preferred_height()</term>
117 * This is called by containers to obtain the minimum and
118 * natural height of a widget.
119 * A widget that does not actually trade any height for width
120 * or width for height only has to implement these two virtual
121 * methods (#GtkWidgetClass.get_preferred_width() and
122 * #GtkWidgetClass.get_preferred_height()).
126 * <term>#GtkWidgetClass.get_preferred_height_for_width()</term>
128 * This is similar to #GtkWidgetClass.get_preferred_height() except
129 * that it is passed a contextual width to request height for. By
130 * implementing this virtual method it is possible for a #GtkLabel
131 * to tell it's parent how much height would be required if the
132 * label were to be allocated a said width.
136 * <term>#GtkWidgetClass.get_preferred_width_for_height()</term>
138 * This is analogous to #GtkWidgetClass.get_preferred_height_for_width()
139 * except that it operates in the oposite orientation. It's rare that
140 * a widget actually does %GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT requests
141 * but can happen when for example; a widget or container gets additional
142 * columns to compensate for a smaller allocated height.
147 * There are some important things to keep in mind when implementing
148 * height-for-width and when using it in container implementations.
150 * The geometry management system will query a widget hierarchy in
151 * only one orientation at a time. When widgets are initially queried
152 * for their minimum sizes it is generally done in two initial passes
153 * in the #GtkSizeRequestMode chosen by the toplevel.
155 * For example, when queried in the normal
156 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
157 * First, the default minimum and natural width for each widget
158 * in the interface will be computed using gtk_width_get_preferred_width().
159 * Because the preferred widths for each container depends on the preferred
160 * widths of thier children, this information propagates up the hierarchy,
161 * and finally a minimum and natural width is determined for the entire
162 * toplevel. Next, the toplevel will use the minimum width to query for the
163 * minimum height contextual to that width using
164 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
165 * recursive operation. The minimum height for the minimum width is normally
166 * used to set the minimum size constraint on the toplevel
167 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
169 * After the toplevel window has initially requested it's size in both
170 * dimensions it can go on to allocate itself a reasonable size (or a size
171 * previously specified with gtk_window_set_default_size()). During the
172 * recursive allocation process it's important to note that request cycles
173 * will be recursively executed while container widgets allocate their children.
174 * Each container widget, once allocated a size will go on to first share the
175 * space in one orientation among its children and then request each child's
176 * height for their target allocated width or width for allocated height
177 * depending. In this way a #GtkWidget will typically be requested its size
178 * a number of times before actually being allocated a size, the size a
179 * widget is finally allocated can of course differ from the size it
180 * requested. For this reason; #GtkWidget caches a small number of results
181 * to avoid re-querying for the same sizes in one allocation cycle.
183 * See <link linkend="container-geometry-management">GtkContainer's
184 * geometry management section</link>
185 * to learn more about how height-for-width allocations are performed
186 * by container widgets.
188 * If a widget does move content around to smartly use up the
189 * allocated size, then it must support the request in both
190 * #GtkSizeRequestModes even if the widget in question only
191 * trades sizes in a single orientation.
193 * For instance, a #GtkLabel that does height-for-width word wrapping
194 * will not expect to have #GtkWidgetClass.get_preferred_height() called
195 * because that call is specific to a width-for-height request. In this
196 * case the label must return the heights required for it's own minimum
197 * possible width. By following this rule any widget that handles
198 * height-for-width or width-for-height requests will always be allocated
199 * at least enough space to fit its own content.
201 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
202 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
204 * <programlisting><![CDATA[
206 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
208 * if (i_am_in_height_for_width_mode)
212 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
213 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
214 * min_height, nat_height);
218 * ... some widgets do both, for instance if a GtkLabel is rotated to 90 degrees
219 * it will return the minimum and natural height for the rotated label here.
222 * ]]></programlisting>
224 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
225 * the minimum and natural width:
227 * <programlisting><![CDATA[
229 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
230 * gint *min_width, gint *nat_width)
232 * if (i_am_in_height_for_width_mode)
234 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
238 * ... again if a widget is sometimes operating in width-for-height mode
239 * (like a rotated GtkLabel) it can go ahead and do it's real width for
240 * height calculation here.
243 * ]]></programlisting>
245 * Often a widget needs to get its own request during size request or
246 * allocation, for example when computing height it may need to also
247 * compute width, or when deciding how to use an allocation the widget
248 * may need to know its natural size. In these cases, the widget should
249 * be careful to call its virtual methods directly, like this:
251 * <title>Widget calling its own size request method.</title>
253 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
258 * It will not work to use the wrapper functions, such as
259 * gtk_widget_get_preferred_width(), inside your own size request
260 * implementation. These return a request adjusted by #GtkSizeGroup
261 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
262 * widget used the wrappers inside its virtual method implementations,
263 * then the adjustments (such as widget margins) would be applied
264 * twice. GTK+ therefore does not allow this and will warn if you try
267 * Of course if you are getting the size request for
268 * <emphasis>another</emphasis> widget, such as a child of a
269 * container, you <emphasis>must</emphasis> use the wrapper APIs;
270 * otherwise, you would not properly consider widget margins,
271 * #GtkSizeGroup, and so forth.
274 * <refsect2 id="style-properties">
275 * <title>Style Properties</title>
277 * <structname>GtkWidget</structname> introduces <firstterm>style
278 * properties</firstterm> - these are basically object properties that are stored
279 * not on the object, but in the style object associated to the widget. Style
280 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
281 * This mechanism is used for configuring such things as the location of the
282 * scrollbar arrows through the theme, giving theme authors more control over the
283 * look of applications without the need to write a theme engine in C.
286 * Use gtk_widget_class_install_style_property() to install style properties for
287 * a widget class, gtk_widget_class_find_style_property() or
288 * gtk_widget_class_list_style_properties() to get information about existing
289 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
290 * gtk_widget_style_get_valist() to obtain the value of a style property.
293 * <refsect2 id="GtkWidget-BUILDER-UI">
294 * <title>GtkWidget as GtkBuildable</title>
296 * The GtkWidget implementation of the GtkBuildable interface supports a
297 * custom <accelerator> element, which has attributes named key,
298 * modifiers and signal and allows to specify accelerators.
301 * <title>A UI definition fragment specifying an accelerator</title>
302 * <programlisting><![CDATA[
303 * <object class="GtkButton">
304 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
306 * ]]></programlisting>
309 * In addition to accelerators, <structname>GtkWidget</structname> also support a
310 * custom <accessible> element, which supports actions and relations.
311 * Properties on the accessible implementation of an object can be set by accessing the
312 * internal child "accessible" of a <structname>GtkWidget</structname>.
315 * <title>A UI definition fragment specifying an accessible</title>
316 * <programlisting><![CDATA[
317 * <object class="GtkButton" id="label1"/>
318 * <property name="label">I am a Label for a Button</property>
320 * <object class="GtkButton" id="button1">
322 * <action action_name="click" translatable="yes">Click the button.</action>
323 * <relation target="label1" type="labelled-by"/>
325 * <child internal-child="accessible">
326 * <object class="AtkObject" id="a11y-button1">
327 * <property name="AtkObject::name">Clickable Button</property>
331 * ]]></programlisting>
336 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
337 #define INIT_PATH_SIZE (512)
339 struct _GtkWidgetPrivate
341 /* The state of the widget. There are actually only
342 * 5 widget states (defined in "gtkenums.h")
347 /* The saved state of the widget. When a widget's state
348 * is changed to GTK_STATE_INSENSITIVE via
349 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
350 * the old state is kept around in this field. The state
351 * will be restored once the widget gets sensitive again.
353 guint saved_state : 3;
357 guint in_destruction : 1;
360 guint composite_child : 1;
366 guint parent_sensitive : 1;
369 guint can_default : 1;
370 guint has_default : 1;
371 guint receives_default : 1;
375 guint user_style : 1;
376 guint app_paintable : 1;
377 guint double_buffered : 1;
378 guint redraw_on_alloc : 1;
379 guint no_show_all : 1;
380 guint child_visible : 1;
381 guint multidevice : 1;
382 guint has_shape_mask : 1;
383 guint in_reparent : 1;
384 guint resize_pending : 1;
385 guint alloc_needed : 1;
386 guint width_request_needed : 1;
387 guint height_request_needed : 1;
389 /* Expand-related flags */
390 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
391 guint computed_hexpand : 1; /* computed results (composite of child flags) */
392 guint computed_vexpand : 1;
393 guint hexpand : 1; /* application-forced expand */
395 guint hexpand_set : 1; /* whether to use application-forced */
396 guint vexpand_set : 1; /* instead of computing from children */
398 /* The widget's name. If the widget does not have a name
399 * (the name is NULL), then its name (as returned by
400 * "gtk_widget_get_name") is its class's name.
401 * Among other things, the widget name is used to determine
402 * the style to use for a widget.
406 /* The style for the widget. The style contains the
407 * colors the widget should be drawn in for each state
408 * along with graphics contexts used to draw with and
409 * the font to use for text.
413 /* The widget's allocated size.
415 GtkAllocation allocation;
417 /* The widget's requested sizes */
418 SizeRequestCache requests;
420 /* The widget's window or its parent window if it does
421 * not have a window. (Which will be indicated by the
422 * GTK_NO_WINDOW flag being set).
426 /* The widget's parent.
457 BUTTON_RELEASE_EVENT,
472 PROPERTY_NOTIFY_EVENT,
473 SELECTION_CLEAR_EVENT,
474 SELECTION_REQUEST_EVENT,
475 SELECTION_NOTIFY_EVENT,
482 VISIBILITY_NOTIFY_EVENT,
496 ACCEL_CLOSURES_CHANGED,
519 PROP_RECEIVES_DEFAULT,
520 PROP_COMPOSITE_CHILD,
523 PROP_EXTENSION_EVENTS,
529 PROP_DOUBLE_BUFFERED,
544 typedef struct _GtkStateData GtkStateData;
549 guint state_restoration : 1;
550 guint parent_sensitive : 1;
551 guint use_forall : 1;
554 /* --- prototypes --- */
555 static void gtk_widget_class_init (GtkWidgetClass *klass);
556 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
557 static void gtk_widget_init (GtkWidget *widget);
558 static void gtk_widget_set_property (GObject *object,
562 static void gtk_widget_get_property (GObject *object,
566 static void gtk_widget_dispose (GObject *object);
567 static void gtk_widget_real_destroy (GtkWidget *object);
568 static void gtk_widget_finalize (GObject *object);
569 static void gtk_widget_real_show (GtkWidget *widget);
570 static void gtk_widget_real_hide (GtkWidget *widget);
571 static void gtk_widget_real_map (GtkWidget *widget);
572 static void gtk_widget_real_unmap (GtkWidget *widget);
573 static void gtk_widget_real_realize (GtkWidget *widget);
574 static void gtk_widget_real_unrealize (GtkWidget *widget);
575 static void gtk_widget_real_size_request (GtkWidget *widget,
576 GtkRequisition *requisition);
577 static void gtk_widget_real_size_allocate (GtkWidget *widget,
578 GtkAllocation *allocation);
579 static void gtk_widget_real_style_set (GtkWidget *widget,
580 GtkStyle *previous_style);
581 static void gtk_widget_real_direction_changed(GtkWidget *widget,
582 GtkTextDirection previous_direction);
584 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
585 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
588 gboolean keyboard_tip,
589 GtkTooltip *tooltip);
590 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
591 GtkWidgetHelpType help_type);
593 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
595 GParamSpec **pspecs);
596 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
598 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
600 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
601 GdkEventFocus *event);
602 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
603 GdkEventFocus *event);
604 static gboolean gtk_widget_real_focus (GtkWidget *widget,
605 GtkDirectionType direction);
606 static void gtk_widget_real_move_focus (GtkWidget *widget,
607 GtkDirectionType direction);
608 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
609 GtkDirectionType direction);
610 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
611 static void gtk_widget_update_pango_context (GtkWidget *widget);
612 static void gtk_widget_propagate_state (GtkWidget *widget,
614 static void gtk_widget_reset_rc_style (GtkWidget *widget);
615 static void gtk_widget_set_style_internal (GtkWidget *widget,
617 gboolean initial_emission);
618 static gint gtk_widget_event_internal (GtkWidget *widget,
620 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
621 gboolean group_cycling);
622 static void gtk_widget_real_get_width (GtkWidget *widget,
625 static void gtk_widget_real_get_height (GtkWidget *widget,
628 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
630 gint *minimum_height,
631 gint *natural_height);
632 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
635 gint *natural_width);
636 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
637 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
638 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
639 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
640 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
641 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
642 cairo_region_t *region);
643 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
644 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
645 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
648 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
649 gboolean has_tooltip,
651 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
652 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
654 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
655 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
657 const gchar *childname);
658 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
661 const GValue *value);
662 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
665 const gchar *tagname,
666 GMarkupParser *parser,
668 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
671 const gchar *tagname,
673 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
674 GtkBuilder *builder);
676 static void gtk_widget_real_get_width (GtkWidget *widget,
679 static void gtk_widget_real_get_height (GtkWidget *widget,
683 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
686 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
687 GtkOrientation orientation,
690 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
691 GtkOrientation orientation,
694 gint *allocated_size);
696 static void gtk_widget_set_usize_internal (GtkWidget *widget,
699 GtkQueueResizeFlags flags);
701 static void gtk_widget_add_events_internal (GtkWidget *widget,
705 /* --- variables --- */
706 static gpointer gtk_widget_parent_class = NULL;
707 static guint widget_signals[LAST_SIGNAL] = { 0 };
708 static GtkStyle *gtk_default_style = NULL;
709 static guint composite_child_stack = 0;
710 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
711 static GParamSpecPool *style_property_spec_pool = NULL;
713 /* XXX Temporarily here to fire warnings from gtksizerequest.c */
714 guint _size_request_signal_id = 0;
716 static GQuark quark_property_parser = 0;
717 static GQuark quark_aux_info = 0;
718 static GQuark quark_accel_path = 0;
719 static GQuark quark_accel_closures = 0;
720 static GQuark quark_event_mask = 0;
721 static GQuark quark_device_event_mask = 0;
722 static GQuark quark_extension_event_mode = 0;
723 static GQuark quark_parent_window = 0;
724 static GQuark quark_pointer_window = 0;
725 static GQuark quark_shape_info = 0;
726 static GQuark quark_input_shape_info = 0;
727 static GQuark quark_pango_context = 0;
728 static GQuark quark_rc_style = 0;
729 static GQuark quark_accessible_object = 0;
730 static GQuark quark_mnemonic_labels = 0;
731 static GQuark quark_tooltip_markup = 0;
732 static GQuark quark_has_tooltip = 0;
733 static GQuark quark_tooltip_window = 0;
734 static GQuark quark_visual = 0;
735 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
736 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
738 /* --- functions --- */
740 gtk_widget_get_type (void)
742 static GType widget_type = 0;
744 if (G_UNLIKELY (widget_type == 0))
746 const GTypeInfo widget_info =
748 sizeof (GtkWidgetClass),
749 NULL, /* base_init */
750 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
751 (GClassInitFunc) gtk_widget_class_init,
752 NULL, /* class_finalize */
753 NULL, /* class_init */
756 (GInstanceInitFunc) gtk_widget_init,
757 NULL, /* value_table */
760 const GInterfaceInfo accessibility_info =
762 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
763 (GInterfaceFinalizeFunc) NULL,
764 NULL /* interface data */
767 const GInterfaceInfo buildable_info =
769 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
770 (GInterfaceFinalizeFunc) NULL,
771 NULL /* interface data */
774 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
775 &widget_info, G_TYPE_FLAG_ABSTRACT);
777 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
778 &accessibility_info) ;
779 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
787 child_property_notify_dispatcher (GObject *object,
791 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
794 /* We guard against the draw signal callbacks modifying the state of the
795 * cairo context by surounding it with save/restore.
796 * Maybe we should also cairo_new_path() just to be sure?
799 gtk_widget_draw_marshaller (GClosure *closure,
800 GValue *return_value,
801 guint n_param_values,
802 const GValue *param_values,
803 gpointer invocation_hint,
804 gpointer marshal_data)
806 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
810 _gtk_marshal_BOOLEAN__BOXED (closure,
821 gtk_widget_class_init (GtkWidgetClass *klass)
823 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
824 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
825 GtkBindingSet *binding_set;
827 gtk_widget_parent_class = g_type_class_peek_parent (klass);
829 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
830 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
831 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
832 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
833 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
834 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
835 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
836 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
837 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
838 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
839 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
840 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
841 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
842 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
843 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
844 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
845 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
846 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
847 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
849 style_property_spec_pool = g_param_spec_pool_new (FALSE);
850 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
851 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
852 cpn_context.dispatcher = child_property_notify_dispatcher;
853 _gtk_widget_child_property_notify_context = &cpn_context;
855 gobject_class->dispose = gtk_widget_dispose;
856 gobject_class->finalize = gtk_widget_finalize;
857 gobject_class->set_property = gtk_widget_set_property;
858 gobject_class->get_property = gtk_widget_get_property;
860 klass->destroy = gtk_widget_real_destroy;
862 klass->activate_signal = 0;
863 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
864 klass->show = gtk_widget_real_show;
865 klass->show_all = gtk_widget_show;
866 klass->hide = gtk_widget_real_hide;
867 klass->map = gtk_widget_real_map;
868 klass->unmap = gtk_widget_real_unmap;
869 klass->realize = gtk_widget_real_realize;
870 klass->unrealize = gtk_widget_real_unrealize;
871 klass->size_request = gtk_widget_real_size_request;
872 klass->size_allocate = gtk_widget_real_size_allocate;
873 klass->get_preferred_width = gtk_widget_real_get_width;
874 klass->get_preferred_height = gtk_widget_real_get_height;
875 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
876 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
877 klass->state_changed = NULL;
878 klass->parent_set = NULL;
879 klass->hierarchy_changed = NULL;
880 klass->style_set = gtk_widget_real_style_set;
881 klass->direction_changed = gtk_widget_real_direction_changed;
882 klass->grab_notify = NULL;
883 klass->child_notify = NULL;
885 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
886 klass->grab_focus = gtk_widget_real_grab_focus;
887 klass->focus = gtk_widget_real_focus;
888 klass->move_focus = gtk_widget_real_move_focus;
889 klass->keynav_failed = gtk_widget_real_keynav_failed;
891 klass->button_press_event = NULL;
892 klass->button_release_event = NULL;
893 klass->motion_notify_event = NULL;
894 klass->delete_event = NULL;
895 klass->destroy_event = NULL;
896 klass->key_press_event = gtk_widget_real_key_press_event;
897 klass->key_release_event = gtk_widget_real_key_release_event;
898 klass->enter_notify_event = NULL;
899 klass->leave_notify_event = NULL;
900 klass->configure_event = NULL;
901 klass->focus_in_event = gtk_widget_real_focus_in_event;
902 klass->focus_out_event = gtk_widget_real_focus_out_event;
903 klass->map_event = NULL;
904 klass->unmap_event = NULL;
905 klass->window_state_event = NULL;
906 klass->property_notify_event = _gtk_selection_property_notify;
907 klass->selection_clear_event = _gtk_selection_clear;
908 klass->selection_request_event = _gtk_selection_request;
909 klass->selection_notify_event = _gtk_selection_notify;
910 klass->selection_received = NULL;
911 klass->proximity_in_event = NULL;
912 klass->proximity_out_event = NULL;
913 klass->drag_begin = NULL;
914 klass->drag_end = NULL;
915 klass->drag_data_delete = NULL;
916 klass->drag_leave = NULL;
917 klass->drag_motion = NULL;
918 klass->drag_drop = NULL;
919 klass->drag_data_received = NULL;
920 klass->screen_changed = NULL;
921 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
922 klass->grab_broken_event = NULL;
923 klass->query_tooltip = gtk_widget_real_query_tooltip;
925 klass->show_help = gtk_widget_real_show_help;
927 /* Accessibility support */
928 klass->get_accessible = gtk_widget_real_get_accessible;
930 klass->no_expose_event = NULL;
932 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
933 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
935 g_object_class_install_property (gobject_class,
937 g_param_spec_string ("name",
939 P_("The name of the widget"),
941 GTK_PARAM_READWRITE));
942 g_object_class_install_property (gobject_class,
944 g_param_spec_object ("parent",
946 P_("The parent widget of this widget. Must be a Container widget"),
948 GTK_PARAM_READWRITE));
950 g_object_class_install_property (gobject_class,
952 g_param_spec_int ("width-request",
954 P_("Override for width request of the widget, or -1 if natural request should be used"),
958 GTK_PARAM_READWRITE));
959 g_object_class_install_property (gobject_class,
961 g_param_spec_int ("height-request",
962 P_("Height request"),
963 P_("Override for height request of the widget, or -1 if natural request should be used"),
967 GTK_PARAM_READWRITE));
968 g_object_class_install_property (gobject_class,
970 g_param_spec_boolean ("visible",
972 P_("Whether the widget is visible"),
974 GTK_PARAM_READWRITE));
975 g_object_class_install_property (gobject_class,
977 g_param_spec_boolean ("sensitive",
979 P_("Whether the widget responds to input"),
981 GTK_PARAM_READWRITE));
982 g_object_class_install_property (gobject_class,
984 g_param_spec_boolean ("app-paintable",
985 P_("Application paintable"),
986 P_("Whether the application will paint directly on the widget"),
988 GTK_PARAM_READWRITE));
989 g_object_class_install_property (gobject_class,
991 g_param_spec_boolean ("can-focus",
993 P_("Whether the widget can accept the input focus"),
995 GTK_PARAM_READWRITE));
996 g_object_class_install_property (gobject_class,
998 g_param_spec_boolean ("has-focus",
1000 P_("Whether the widget has the input focus"),
1002 GTK_PARAM_READWRITE));
1003 g_object_class_install_property (gobject_class,
1005 g_param_spec_boolean ("is-focus",
1007 P_("Whether the widget is the focus widget within the toplevel"),
1009 GTK_PARAM_READWRITE));
1010 g_object_class_install_property (gobject_class,
1012 g_param_spec_boolean ("can-default",
1014 P_("Whether the widget can be the default widget"),
1016 GTK_PARAM_READWRITE));
1017 g_object_class_install_property (gobject_class,
1019 g_param_spec_boolean ("has-default",
1021 P_("Whether the widget is the default widget"),
1023 GTK_PARAM_READWRITE));
1024 g_object_class_install_property (gobject_class,
1025 PROP_RECEIVES_DEFAULT,
1026 g_param_spec_boolean ("receives-default",
1027 P_("Receives default"),
1028 P_("If TRUE, the widget will receive the default action when it is focused"),
1030 GTK_PARAM_READWRITE));
1031 g_object_class_install_property (gobject_class,
1032 PROP_COMPOSITE_CHILD,
1033 g_param_spec_boolean ("composite-child",
1034 P_("Composite child"),
1035 P_("Whether the widget is part of a composite widget"),
1037 GTK_PARAM_READABLE));
1038 g_object_class_install_property (gobject_class,
1040 g_param_spec_object ("style",
1042 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1044 GTK_PARAM_READWRITE));
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_flags ("events",
1049 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1050 GDK_TYPE_EVENT_MASK,
1052 GTK_PARAM_READWRITE));
1053 g_object_class_install_property (gobject_class,
1054 PROP_EXTENSION_EVENTS,
1055 g_param_spec_enum ("extension-events",
1056 P_("Extension events"),
1057 P_("The mask that decides what kind of extension events this widget gets"),
1058 GDK_TYPE_EXTENSION_MODE,
1059 GDK_EXTENSION_EVENTS_NONE,
1060 GTK_PARAM_READWRITE));
1061 g_object_class_install_property (gobject_class,
1063 g_param_spec_boolean ("no-show-all",
1065 P_("Whether gtk_widget_show_all() should not affect this widget"),
1067 GTK_PARAM_READWRITE));
1070 * GtkWidget:has-tooltip:
1072 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1073 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1074 * the widget will be queried using #GtkWidget::query-tooltip to determine
1075 * whether it will provide a tooltip or not.
1077 * Note that setting this property to %TRUE for the first time will change
1078 * the event masks of the GdkWindows of this widget to include leave-notify
1079 * and motion-notify events. This cannot and will not be undone when the
1080 * property is set to %FALSE again.
1084 g_object_class_install_property (gobject_class,
1086 g_param_spec_boolean ("has-tooltip",
1088 P_("Whether this widget has a tooltip"),
1090 GTK_PARAM_READWRITE));
1092 * GtkWidget:tooltip-text:
1094 * Sets the text of tooltip to be the given string.
1096 * Also see gtk_tooltip_set_text().
1098 * This is a convenience property which will take care of getting the
1099 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1100 * will automatically be set to %TRUE and there will be taken care of
1101 * #GtkWidget::query-tooltip in the default signal handler.
1105 g_object_class_install_property (gobject_class,
1107 g_param_spec_string ("tooltip-text",
1109 P_("The contents of the tooltip for this widget"),
1111 GTK_PARAM_READWRITE));
1113 * GtkWidget:tooltip-markup:
1115 * Sets the text of tooltip to be the given string, which is marked up
1116 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1117 * Also see gtk_tooltip_set_markup().
1119 * This is a convenience property which will take care of getting the
1120 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1121 * will automatically be set to %TRUE and there will be taken care of
1122 * #GtkWidget::query-tooltip in the default signal handler.
1126 g_object_class_install_property (gobject_class,
1127 PROP_TOOLTIP_MARKUP,
1128 g_param_spec_string ("tooltip-markup",
1129 P_("Tooltip markup"),
1130 P_("The contents of the tooltip for this widget"),
1132 GTK_PARAM_READWRITE));
1137 * The widget's window if it is realized, %NULL otherwise.
1141 g_object_class_install_property (gobject_class,
1143 g_param_spec_object ("window",
1145 P_("The widget's window if it is realized"),
1147 GTK_PARAM_READABLE));
1150 * GtkWidget:double-buffered
1152 * Whether the widget is double buffered.
1156 g_object_class_install_property (gobject_class,
1157 PROP_DOUBLE_BUFFERED,
1158 g_param_spec_boolean ("double-buffered",
1159 P_("Double Buffered"),
1160 P_("Whether the widget is double buffered"),
1162 GTK_PARAM_READWRITE));
1167 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1171 g_object_class_install_property (gobject_class,
1173 g_param_spec_enum ("halign",
1174 P_("Horizontal Alignment"),
1175 P_("How to position in extra horizontal space"),
1178 GTK_PARAM_READWRITE));
1183 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1187 g_object_class_install_property (gobject_class,
1189 g_param_spec_enum ("valign",
1190 P_("Vertical Alignment"),
1191 P_("How to position in extra vertical space"),
1194 GTK_PARAM_READWRITE));
1197 * GtkWidget:margin-left
1199 * Margin on left side of widget.
1201 * This property adds margin outside of the widget's normal size
1202 * request, the margin will be added in addition to the size from
1203 * gtk_widget_set_size_request() for example.
1207 g_object_class_install_property (gobject_class,
1209 g_param_spec_int ("margin-left",
1210 P_("Margin on Left"),
1211 P_("Pixels of extra space on the left side"),
1215 GTK_PARAM_READWRITE));
1218 * GtkWidget:margin-right
1220 * Margin on right side of widget.
1222 * This property adds margin outside of the widget's normal size
1223 * request, the margin will be added in addition to the size from
1224 * gtk_widget_set_size_request() for example.
1228 g_object_class_install_property (gobject_class,
1230 g_param_spec_int ("margin-right",
1231 P_("Margin on Right"),
1232 P_("Pixels of extra space on the right side"),
1236 GTK_PARAM_READWRITE));
1239 * GtkWidget:margin-top
1241 * Margin on top side of widget.
1243 * This property adds margin outside of the widget's normal size
1244 * request, the margin will be added in addition to the size from
1245 * gtk_widget_set_size_request() for example.
1249 g_object_class_install_property (gobject_class,
1251 g_param_spec_int ("margin-top",
1252 P_("Margin on Top"),
1253 P_("Pixels of extra space on the top side"),
1257 GTK_PARAM_READWRITE));
1260 * GtkWidget:margin-bottom
1262 * Margin on bottom side of widget.
1264 * This property adds margin outside of the widget's normal size
1265 * request, the margin will be added in addition to the size from
1266 * gtk_widget_set_size_request() for example.
1270 g_object_class_install_property (gobject_class,
1272 g_param_spec_int ("margin-bottom",
1273 P_("Margin on Bottom"),
1274 P_("Pixels of extra space on the bottom side"),
1278 GTK_PARAM_READWRITE));
1283 * Sets all four sides' margin at once. If read, returns max
1284 * margin on any side.
1288 g_object_class_install_property (gobject_class,
1290 g_param_spec_int ("margin",
1292 P_("Pixels of extra space on all four sides"),
1296 GTK_PARAM_READWRITE));
1299 * GtkWidget::destroy:
1300 * @object: the object which received the signal
1302 * Signals that all holders of a reference to the widget should release
1303 * the reference that they hold. May result in finalization of the widget
1304 * if all references are released.
1306 widget_signals[DESTROY] =
1307 g_signal_new (I_("destroy"),
1308 G_TYPE_FROM_CLASS (gobject_class),
1309 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1310 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1312 _gtk_marshal_VOID__VOID,
1318 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1322 g_object_class_install_property (gobject_class,
1324 g_param_spec_boolean ("hexpand",
1325 P_("Horizontal Expand"),
1326 P_("Whether widget wants more horizontal space"),
1328 GTK_PARAM_READWRITE));
1331 * GtkWidget:hexpand-set
1333 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1337 g_object_class_install_property (gobject_class,
1339 g_param_spec_boolean ("hexpand-set",
1340 P_("Horizontal Expand Set"),
1341 P_("Whether to use the hexpand property"),
1343 GTK_PARAM_READWRITE));
1348 * Whether to expand vertically. See gtk_widget_set_vexpand().
1352 g_object_class_install_property (gobject_class,
1354 g_param_spec_boolean ("vexpand",
1355 P_("Vertical Expand"),
1356 P_("Whether widget wants more vertical space"),
1358 GTK_PARAM_READWRITE));
1361 * GtkWidget:vexpand-set
1363 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1367 g_object_class_install_property (gobject_class,
1369 g_param_spec_boolean ("vexpand-set",
1370 P_("Vertical Expand Set"),
1371 P_("Whether to use the vexpand property"),
1373 GTK_PARAM_READWRITE));
1378 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1382 g_object_class_install_property (gobject_class,
1384 g_param_spec_boolean ("expand",
1386 P_("Whether widget wants to expand in both directions"),
1388 GTK_PARAM_READWRITE));
1392 * @widget: the object which received the signal.
1394 widget_signals[SHOW] =
1395 g_signal_new (I_("show"),
1396 G_TYPE_FROM_CLASS (gobject_class),
1398 G_STRUCT_OFFSET (GtkWidgetClass, show),
1400 _gtk_marshal_VOID__VOID,
1405 * @widget: the object which received the signal.
1407 widget_signals[HIDE] =
1408 g_signal_new (I_("hide"),
1409 G_TYPE_FROM_CLASS (gobject_class),
1411 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1413 _gtk_marshal_VOID__VOID,
1418 * @widget: the object which received the signal.
1420 widget_signals[MAP] =
1421 g_signal_new (I_("map"),
1422 G_TYPE_FROM_CLASS (gobject_class),
1424 G_STRUCT_OFFSET (GtkWidgetClass, map),
1426 _gtk_marshal_VOID__VOID,
1431 * @widget: the object which received the signal.
1433 widget_signals[UNMAP] =
1434 g_signal_new (I_("unmap"),
1435 G_TYPE_FROM_CLASS (gobject_class),
1437 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1439 _gtk_marshal_VOID__VOID,
1443 * GtkWidget::realize:
1444 * @widget: the object which received the signal.
1446 widget_signals[REALIZE] =
1447 g_signal_new (I_("realize"),
1448 G_TYPE_FROM_CLASS (gobject_class),
1450 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1452 _gtk_marshal_VOID__VOID,
1456 * GtkWidget::unrealize:
1457 * @widget: the object which received the signal.
1459 widget_signals[UNREALIZE] =
1460 g_signal_new (I_("unrealize"),
1461 G_TYPE_FROM_CLASS (gobject_class),
1463 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1465 _gtk_marshal_VOID__VOID,
1469 * GtkWidget::size-request:
1470 * @widget: the object which received the signal.
1473 _size_request_signal_id = widget_signals[SIZE_REQUEST] =
1474 g_signal_new (I_("size-request"),
1475 G_TYPE_FROM_CLASS (gobject_class),
1477 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1479 _gtk_marshal_VOID__BOXED,
1481 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1484 * GtkWidget::size-allocate:
1485 * @widget: the object which received the signal.
1488 widget_signals[SIZE_ALLOCATE] =
1489 g_signal_new (I_("size-allocate"),
1490 G_TYPE_FROM_CLASS (gobject_class),
1492 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1494 _gtk_marshal_VOID__BOXED,
1496 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1499 * GtkWidget::state-changed:
1500 * @widget: the object which received the signal.
1501 * @state: the previous state
1503 * The ::state-changed signal is emitted when the widget state changes.
1504 * See gtk_widget_get_state().
1506 widget_signals[STATE_CHANGED] =
1507 g_signal_new (I_("state-changed"),
1508 G_TYPE_FROM_CLASS (gobject_class),
1510 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1512 _gtk_marshal_VOID__ENUM,
1514 GTK_TYPE_STATE_TYPE);
1517 * GtkWidget::parent-set:
1518 * @widget: the object on which the signal is emitted
1519 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1520 * just got its initial parent.
1522 * The ::parent-set signal is emitted when a new parent
1523 * has been set on a widget.
1525 widget_signals[PARENT_SET] =
1526 g_signal_new (I_("parent-set"),
1527 G_TYPE_FROM_CLASS (gobject_class),
1529 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1531 _gtk_marshal_VOID__OBJECT,
1536 * GtkWidget::hierarchy-changed:
1537 * @widget: the object on which the signal is emitted
1538 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1539 * if the widget was previously unanchored
1541 * The ::hierarchy-changed signal is emitted when the
1542 * anchored state of a widget changes. A widget is
1543 * <firstterm>anchored</firstterm> when its toplevel
1544 * ancestor is a #GtkWindow. This signal is emitted when
1545 * a widget changes from un-anchored to anchored or vice-versa.
1547 widget_signals[HIERARCHY_CHANGED] =
1548 g_signal_new (I_("hierarchy-changed"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1551 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1553 _gtk_marshal_VOID__OBJECT,
1558 * GtkWidget::style-set:
1559 * @widget: the object on which the signal is emitted
1560 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1561 * just got its initial style
1563 * The ::style-set signal is emitted when a new style has been set
1564 * on a widget. Note that style-modifying functions like
1565 * gtk_widget_modify_base() also cause this signal to be emitted.
1567 widget_signals[STYLE_SET] =
1568 g_signal_new (I_("style-set"),
1569 G_TYPE_FROM_CLASS (gobject_class),
1571 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1573 _gtk_marshal_VOID__OBJECT,
1578 * GtkWidget::direction-changed:
1579 * @widget: the object on which the signal is emitted
1580 * @previous_direction: the previous text direction of @widget
1582 * The ::direction-changed signal is emitted when the text direction
1583 * of a widget changes.
1585 widget_signals[DIRECTION_CHANGED] =
1586 g_signal_new (I_("direction-changed"),
1587 G_TYPE_FROM_CLASS (gobject_class),
1589 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1591 _gtk_marshal_VOID__ENUM,
1593 GTK_TYPE_TEXT_DIRECTION);
1596 * GtkWidget::grab-notify:
1597 * @widget: the object which received the signal
1598 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1599 * if it becomes unshadowed
1601 * The ::grab-notify signal is emitted when a widget becomes
1602 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1603 * another widget, or when it becomes unshadowed due to a grab
1606 * A widget is shadowed by a gtk_grab_add() when the topmost
1607 * grab widget in the grab stack of its window group is not
1610 widget_signals[GRAB_NOTIFY] =
1611 g_signal_new (I_("grab-notify"),
1612 G_TYPE_FROM_CLASS (gobject_class),
1614 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1616 _gtk_marshal_VOID__BOOLEAN,
1621 * GtkWidget::child-notify:
1622 * @widget: the object which received the signal
1623 * @pspec: the #GParamSpec of the changed child property
1625 * The ::child-notify signal is emitted for each
1626 * <link linkend="child-properties">child property</link> that has
1627 * changed on an object. The signal's detail holds the property name.
1629 widget_signals[CHILD_NOTIFY] =
1630 g_signal_new (I_("child-notify"),
1631 G_TYPE_FROM_CLASS (gobject_class),
1632 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1633 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1635 g_cclosure_marshal_VOID__PARAM,
1641 * @widget: the object which received the signal
1642 * @cr: the cairo context to draw to
1644 * This signal is emitted when a widget is supposed to render itself.
1645 * The @widget's top left corner must be painted at the origin of
1646 * the passed in context and be sized to the values returned by
1647 * gtk_widget_get_allocated_width() and
1648 * gtk_widget_get_allocated_height().
1650 * Signal handlers connected to this signal can modify the cairo
1651 * context passed as @cr in any way they like and don't need to
1652 * restore it. The signal emission takes care of calling cairo_save()
1653 * before and cairo_restore() after invoking the handler.
1655 widget_signals[DRAW] =
1656 g_signal_new (I_("draw"),
1657 G_TYPE_FROM_CLASS (gobject_class),
1659 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1660 _gtk_boolean_handled_accumulator, NULL,
1661 gtk_widget_draw_marshaller,
1663 CAIRO_GOBJECT_TYPE_CONTEXT);
1666 * GtkWidget::mnemonic-activate:
1667 * @widget: the object which received the signal.
1670 widget_signals[MNEMONIC_ACTIVATE] =
1671 g_signal_new (I_("mnemonic-activate"),
1672 G_TYPE_FROM_CLASS (gobject_class),
1674 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1675 _gtk_boolean_handled_accumulator, NULL,
1676 _gtk_marshal_BOOLEAN__BOOLEAN,
1681 * GtkWidget::grab-focus:
1682 * @widget: the object which received the signal.
1684 widget_signals[GRAB_FOCUS] =
1685 g_signal_new (I_("grab-focus"),
1686 G_TYPE_FROM_CLASS (gobject_class),
1687 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1688 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1690 _gtk_marshal_VOID__VOID,
1695 * @widget: the object which received the signal.
1698 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1700 widget_signals[FOCUS] =
1701 g_signal_new (I_("focus"),
1702 G_TYPE_FROM_CLASS (klass),
1704 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1705 _gtk_boolean_handled_accumulator, NULL,
1706 _gtk_marshal_BOOLEAN__ENUM,
1708 GTK_TYPE_DIRECTION_TYPE);
1711 * GtkWidget::move-focus:
1712 * @widget: the object which received the signal.
1715 widget_signals[MOVE_FOCUS] =
1716 g_signal_new (I_("move-focus"),
1717 G_TYPE_FROM_CLASS (klass),
1718 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1719 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1721 _gtk_marshal_VOID__ENUM,
1724 GTK_TYPE_DIRECTION_TYPE);
1727 * GtkWidget::keynav-failed:
1728 * @widget: the object which received the signal
1729 * @direction: the direction of movement
1731 * Gets emitted if keyboard navigation fails.
1732 * See gtk_widget_keynav_failed() for details.
1734 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1735 * if the emitting widget should try to handle the keyboard
1736 * navigation attempt in its parent container(s).
1740 widget_signals[KEYNAV_FAILED] =
1741 g_signal_new (I_("keynav-failed"),
1742 G_TYPE_FROM_CLASS (klass),
1744 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1745 _gtk_boolean_handled_accumulator, NULL,
1746 _gtk_marshal_BOOLEAN__ENUM,
1748 GTK_TYPE_DIRECTION_TYPE);
1752 * @widget: the object which received the signal.
1753 * @event: the #GdkEvent which triggered this signal
1755 * The GTK+ main loop will emit three signals for each GDK event delivered
1756 * to a widget: one generic ::event signal, another, more specific,
1757 * signal that matches the type of event delivered (e.g.
1758 * #GtkWidget::key-press-event) and finally a generic
1759 * #GtkWidget::event-after signal.
1761 * Returns: %TRUE to stop other handlers from being invoked for the event
1762 * and to cancel the emission of the second specific ::event signal.
1763 * %FALSE to propagate the event further and to allow the emission of
1764 * the second signal. The ::event-after signal is emitted regardless of
1767 widget_signals[EVENT] =
1768 g_signal_new (I_("event"),
1769 G_TYPE_FROM_CLASS (klass),
1771 G_STRUCT_OFFSET (GtkWidgetClass, event),
1772 _gtk_boolean_handled_accumulator, NULL,
1773 _gtk_marshal_BOOLEAN__BOXED,
1775 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1778 * GtkWidget::event-after:
1779 * @widget: the object which received the signal.
1780 * @event: the #GdkEvent which triggered this signal
1782 * After the emission of the #GtkWidget::event signal and (optionally)
1783 * the second more specific signal, ::event-after will be emitted
1784 * regardless of the previous two signals handlers return values.
1787 widget_signals[EVENT_AFTER] =
1788 g_signal_new (I_("event-after"),
1789 G_TYPE_FROM_CLASS (klass),
1793 _gtk_marshal_VOID__BOXED,
1795 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1798 * GtkWidget::button-press-event:
1799 * @widget: the object which received the signal.
1800 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1803 * The ::button-press-event signal will be emitted when a button
1804 * (typically from a mouse) is pressed.
1806 * To receive this signal, the #GdkWindow associated to the
1807 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1809 * This signal will be sent to the grab widget if there is one.
1811 * Returns: %TRUE to stop other handlers from being invoked for the event.
1812 * %FALSE to propagate the event further.
1814 widget_signals[BUTTON_PRESS_EVENT] =
1815 g_signal_new (I_("button-press-event"),
1816 G_TYPE_FROM_CLASS (klass),
1818 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1819 _gtk_boolean_handled_accumulator, NULL,
1820 _gtk_marshal_BOOLEAN__BOXED,
1822 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1825 * GtkWidget::button-release-event:
1826 * @widget: the object which received the signal.
1827 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1830 * The ::button-release-event signal will be emitted when a button
1831 * (typically from a mouse) is released.
1833 * To receive this signal, the #GdkWindow associated to the
1834 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1836 * This signal will be sent to the grab widget if there is one.
1838 * Returns: %TRUE to stop other handlers from being invoked for the event.
1839 * %FALSE to propagate the event further.
1841 widget_signals[BUTTON_RELEASE_EVENT] =
1842 g_signal_new (I_("button-release-event"),
1843 G_TYPE_FROM_CLASS (klass),
1845 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1846 _gtk_boolean_handled_accumulator, NULL,
1847 _gtk_marshal_BOOLEAN__BOXED,
1849 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1852 * GtkWidget::scroll-event:
1853 * @widget: the object which received the signal.
1854 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1857 * The ::scroll-event signal is emitted when a button in the 4 to 7
1858 * range is pressed. Wheel mice are usually configured to generate
1859 * button press events for buttons 4 and 5 when the wheel is turned.
1861 * To receive this signal, the #GdkWindow associated to the widget needs
1862 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1864 * This signal will be sent to the grab widget if there is one.
1866 * Returns: %TRUE to stop other handlers from being invoked for the event.
1867 * %FALSE to propagate the event further.
1869 widget_signals[SCROLL_EVENT] =
1870 g_signal_new (I_("scroll-event"),
1871 G_TYPE_FROM_CLASS (klass),
1873 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1874 _gtk_boolean_handled_accumulator, NULL,
1875 _gtk_marshal_BOOLEAN__BOXED,
1877 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1880 * GtkWidget::motion-notify-event:
1881 * @widget: the object which received the signal.
1882 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1885 * The ::motion-notify-event signal is emitted when the pointer moves
1886 * over the widget's #GdkWindow.
1888 * To receive this signal, the #GdkWindow associated to the widget
1889 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1891 * This signal will be sent to the grab widget if there is one.
1893 * Returns: %TRUE to stop other handlers from being invoked for the event.
1894 * %FALSE to propagate the event further.
1896 widget_signals[MOTION_NOTIFY_EVENT] =
1897 g_signal_new (I_("motion-notify-event"),
1898 G_TYPE_FROM_CLASS (klass),
1900 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1901 _gtk_boolean_handled_accumulator, NULL,
1902 _gtk_marshal_BOOLEAN__BOXED,
1904 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1907 * GtkWidget::composited-changed:
1908 * @widget: the object on which the signal is emitted
1910 * The ::composited-changed signal is emitted when the composited
1911 * status of @widget<!-- -->s screen changes.
1912 * See gdk_screen_is_composited().
1914 widget_signals[COMPOSITED_CHANGED] =
1915 g_signal_new (I_("composited-changed"),
1916 G_TYPE_FROM_CLASS (klass),
1917 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1918 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1920 _gtk_marshal_VOID__VOID,
1924 * GtkWidget::delete-event:
1925 * @widget: the object which received the signal
1926 * @event: the event which triggered this signal
1928 * The ::delete-event signal is emitted if a user requests that
1929 * a toplevel window is closed. The default handler for this signal
1930 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1931 * this signal will cause the window to be hidden instead, so that
1932 * it can later be shown again without reconstructing it.
1934 * Returns: %TRUE to stop other handlers from being invoked for the event.
1935 * %FALSE to propagate the event further.
1937 widget_signals[DELETE_EVENT] =
1938 g_signal_new (I_("delete-event"),
1939 G_TYPE_FROM_CLASS (klass),
1941 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1942 _gtk_boolean_handled_accumulator, NULL,
1943 _gtk_marshal_BOOLEAN__BOXED,
1945 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1948 * GtkWidget::destroy-event:
1949 * @widget: the object which received the signal.
1950 * @event: the event which triggered this signal
1952 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1953 * You rarely get this signal, because most widgets disconnect themselves
1954 * from their window before they destroy it, so no widget owns the
1955 * window at destroy time.
1957 * To receive this signal, the #GdkWindow associated to the widget needs
1958 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1959 * automatically for all new windows.
1961 * Returns: %TRUE to stop other handlers from being invoked for the event.
1962 * %FALSE to propagate the event further.
1964 widget_signals[DESTROY_EVENT] =
1965 g_signal_new (I_("destroy-event"),
1966 G_TYPE_FROM_CLASS (klass),
1968 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1969 _gtk_boolean_handled_accumulator, NULL,
1970 _gtk_marshal_BOOLEAN__BOXED,
1972 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1975 * GtkWidget::key-press-event:
1976 * @widget: the object which received the signal
1977 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1979 * The ::key-press-event signal is emitted when a key is pressed.
1981 * To receive this signal, the #GdkWindow associated to the widget needs
1982 * to enable the #GDK_KEY_PRESS_MASK mask.
1984 * This signal will be sent to the grab widget if there is one.
1986 * Returns: %TRUE to stop other handlers from being invoked for the event.
1987 * %FALSE to propagate the event further.
1989 widget_signals[KEY_PRESS_EVENT] =
1990 g_signal_new (I_("key-press-event"),
1991 G_TYPE_FROM_CLASS (klass),
1993 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1994 _gtk_boolean_handled_accumulator, NULL,
1995 _gtk_marshal_BOOLEAN__BOXED,
1997 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2000 * GtkWidget::key-release-event:
2001 * @widget: the object which received the signal
2002 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2004 * The ::key-release-event signal is emitted when a key is pressed.
2006 * To receive this signal, the #GdkWindow associated to the widget needs
2007 * to enable the #GDK_KEY_RELEASE_MASK mask.
2009 * This signal will be sent to the grab widget if there is one.
2011 * Returns: %TRUE to stop other handlers from being invoked for the event.
2012 * %FALSE to propagate the event further.
2014 widget_signals[KEY_RELEASE_EVENT] =
2015 g_signal_new (I_("key-release-event"),
2016 G_TYPE_FROM_CLASS (klass),
2018 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2019 _gtk_boolean_handled_accumulator, NULL,
2020 _gtk_marshal_BOOLEAN__BOXED,
2022 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2025 * GtkWidget::enter-notify-event:
2026 * @widget: the object which received the signal
2027 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2030 * The ::enter-notify-event will be emitted when the pointer enters
2031 * the @widget's window.
2033 * To receive this signal, the #GdkWindow associated to the widget needs
2034 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2036 * This signal will be sent to the grab widget if there is one.
2038 * Returns: %TRUE to stop other handlers from being invoked for the event.
2039 * %FALSE to propagate the event further.
2041 widget_signals[ENTER_NOTIFY_EVENT] =
2042 g_signal_new (I_("enter-notify-event"),
2043 G_TYPE_FROM_CLASS (klass),
2045 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2046 _gtk_boolean_handled_accumulator, NULL,
2047 _gtk_marshal_BOOLEAN__BOXED,
2049 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2052 * GtkWidget::leave-notify-event:
2053 * @widget: the object which received the signal
2054 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2057 * The ::leave-notify-event will be emitted when the pointer leaves
2058 * the @widget's window.
2060 * To receive this signal, the #GdkWindow associated to the widget needs
2061 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2063 * This signal will be sent to the grab widget if there is one.
2065 * Returns: %TRUE to stop other handlers from being invoked for the event.
2066 * %FALSE to propagate the event further.
2068 widget_signals[LEAVE_NOTIFY_EVENT] =
2069 g_signal_new (I_("leave-notify-event"),
2070 G_TYPE_FROM_CLASS (klass),
2072 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2073 _gtk_boolean_handled_accumulator, NULL,
2074 _gtk_marshal_BOOLEAN__BOXED,
2076 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2079 * GtkWidget::configure-event:
2080 * @widget: the object which received the signal
2081 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2084 * The ::configure-event signal will be emitted when the size, position or
2085 * stacking of the @widget's window has changed.
2087 * To receive this signal, the #GdkWindow associated to the widget needs
2088 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2089 * automatically for all new windows.
2091 * Returns: %TRUE to stop other handlers from being invoked for the event.
2092 * %FALSE to propagate the event further.
2094 widget_signals[CONFIGURE_EVENT] =
2095 g_signal_new (I_("configure-event"),
2096 G_TYPE_FROM_CLASS (klass),
2098 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2099 _gtk_boolean_handled_accumulator, NULL,
2100 _gtk_marshal_BOOLEAN__BOXED,
2102 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2105 * GtkWidget::focus-in-event:
2106 * @widget: the object which received the signal
2107 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2110 * The ::focus-in-event signal will be emitted when the keyboard focus
2111 * enters the @widget's window.
2113 * To receive this signal, the #GdkWindow associated to the widget needs
2114 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2116 * Returns: %TRUE to stop other handlers from being invoked for the event.
2117 * %FALSE to propagate the event further.
2119 widget_signals[FOCUS_IN_EVENT] =
2120 g_signal_new (I_("focus-in-event"),
2121 G_TYPE_FROM_CLASS (klass),
2123 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2124 _gtk_boolean_handled_accumulator, NULL,
2125 _gtk_marshal_BOOLEAN__BOXED,
2127 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2130 * GtkWidget::focus-out-event:
2131 * @widget: the object which received the signal
2132 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2135 * The ::focus-out-event signal will be emitted when the keyboard focus
2136 * leaves the @widget's window.
2138 * To receive this signal, the #GdkWindow associated to the widget needs
2139 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2141 * Returns: %TRUE to stop other handlers from being invoked for the event.
2142 * %FALSE to propagate the event further.
2144 widget_signals[FOCUS_OUT_EVENT] =
2145 g_signal_new (I_("focus-out-event"),
2146 G_TYPE_FROM_CLASS (klass),
2148 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2149 _gtk_boolean_handled_accumulator, NULL,
2150 _gtk_marshal_BOOLEAN__BOXED,
2152 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2155 * GtkWidget::map-event:
2156 * @widget: the object which received the signal
2157 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2159 * The ::map-event signal will be emitted when the @widget's window is
2160 * mapped. A window is mapped when it becomes visible on the screen.
2162 * To receive this signal, the #GdkWindow associated to the widget needs
2163 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2164 * automatically for all new windows.
2166 * Returns: %TRUE to stop other handlers from being invoked for the event.
2167 * %FALSE to propagate the event further.
2169 widget_signals[MAP_EVENT] =
2170 g_signal_new (I_("map-event"),
2171 G_TYPE_FROM_CLASS (klass),
2173 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2174 _gtk_boolean_handled_accumulator, NULL,
2175 _gtk_marshal_BOOLEAN__BOXED,
2177 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2180 * GtkWidget::unmap-event:
2181 * @widget: the object which received the signal
2182 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2184 * The ::unmap-event signal may be emitted when the @widget's window is
2185 * unmapped. A window is unmapped when it becomes invisible on the screen.
2187 * For performance reasons GTK+ may not emit ::unmap-event, so one
2188 * should always also implement ::unrealize in order to release
2189 * resources and disconnect signal handlers.
2191 * To receive this signal, the #GdkWindow associated to the widget needs
2192 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2193 * automatically for all new windows.
2195 * Returns: %TRUE to stop other handlers from being invoked for the event.
2196 * %FALSE to propagate the event further.
2198 widget_signals[UNMAP_EVENT] =
2199 g_signal_new (I_("unmap-event"),
2200 G_TYPE_FROM_CLASS (klass),
2202 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2203 _gtk_boolean_handled_accumulator, NULL,
2204 _gtk_marshal_BOOLEAN__BOXED,
2206 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2209 * GtkWidget::property-notify-event:
2210 * @widget: the object which received the signal
2211 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2214 * The ::property-notify-event signal will be emitted when a property on
2215 * the @widget's window has been changed or deleted.
2217 * To receive this signal, the #GdkWindow associated to the widget needs
2218 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2220 * Returns: %TRUE to stop other handlers from being invoked for the event.
2221 * %FALSE to propagate the event further.
2223 widget_signals[PROPERTY_NOTIFY_EVENT] =
2224 g_signal_new (I_("property-notify-event"),
2225 G_TYPE_FROM_CLASS (klass),
2227 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2228 _gtk_boolean_handled_accumulator, NULL,
2229 _gtk_marshal_BOOLEAN__BOXED,
2231 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2234 * GtkWidget::selection-clear-event:
2235 * @widget: the object which received the signal
2236 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2239 * The ::selection-clear-event signal will be emitted when the
2240 * the @widget's window has lost ownership of a selection.
2242 * Returns: %TRUE to stop other handlers from being invoked for the event.
2243 * %FALSE to propagate the event further.
2245 widget_signals[SELECTION_CLEAR_EVENT] =
2246 g_signal_new (I_("selection-clear-event"),
2247 G_TYPE_FROM_CLASS (klass),
2249 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2250 _gtk_boolean_handled_accumulator, NULL,
2251 _gtk_marshal_BOOLEAN__BOXED,
2253 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2256 * GtkWidget::selection-request-event:
2257 * @widget: the object which received the signal
2258 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2261 * The ::selection-request-event signal will be emitted when
2262 * another client requests ownership of the selection owned by
2263 * the @widget's window.
2265 * Returns: %TRUE to stop other handlers from being invoked for the event.
2266 * %FALSE to propagate the event further.
2268 widget_signals[SELECTION_REQUEST_EVENT] =
2269 g_signal_new (I_("selection-request-event"),
2270 G_TYPE_FROM_CLASS (klass),
2272 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2273 _gtk_boolean_handled_accumulator, NULL,
2274 _gtk_marshal_BOOLEAN__BOXED,
2276 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2279 * GtkWidget::selection-notify-event:
2280 * @widget: the object which received the signal.
2283 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2285 widget_signals[SELECTION_NOTIFY_EVENT] =
2286 g_signal_new (I_("selection-notify-event"),
2287 G_TYPE_FROM_CLASS (klass),
2289 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2290 _gtk_boolean_handled_accumulator, NULL,
2291 _gtk_marshal_BOOLEAN__BOXED,
2293 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2296 * GtkWidget::selection-received:
2297 * @widget: the object which received the signal.
2301 widget_signals[SELECTION_RECEIVED] =
2302 g_signal_new (I_("selection-received"),
2303 G_TYPE_FROM_CLASS (klass),
2305 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2307 _gtk_marshal_VOID__BOXED_UINT,
2309 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2313 * GtkWidget::selection-get:
2314 * @widget: the object which received the signal.
2319 widget_signals[SELECTION_GET] =
2320 g_signal_new (I_("selection-get"),
2321 G_TYPE_FROM_CLASS (klass),
2323 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2325 _gtk_marshal_VOID__BOXED_UINT_UINT,
2327 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2332 * GtkWidget::proximity-in-event:
2333 * @widget: the object which received the signal
2334 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2337 * To receive this signal the #GdkWindow associated to the widget needs
2338 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2340 * This signal will be sent to the grab widget if there is one.
2342 * Returns: %TRUE to stop other handlers from being invoked for the event.
2343 * %FALSE to propagate the event further.
2345 widget_signals[PROXIMITY_IN_EVENT] =
2346 g_signal_new (I_("proximity-in-event"),
2347 G_TYPE_FROM_CLASS (klass),
2349 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2350 _gtk_boolean_handled_accumulator, NULL,
2351 _gtk_marshal_BOOLEAN__BOXED,
2353 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2356 * GtkWidget::proximity-out-event:
2357 * @widget: the object which received the signal
2358 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2361 * To receive this signal the #GdkWindow associated to the widget needs
2362 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2364 * This signal will be sent to the grab widget if there is one.
2366 * Returns: %TRUE to stop other handlers from being invoked for the event.
2367 * %FALSE to propagate the event further.
2369 widget_signals[PROXIMITY_OUT_EVENT] =
2370 g_signal_new (I_("proximity-out-event"),
2371 G_TYPE_FROM_CLASS (klass),
2373 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2374 _gtk_boolean_handled_accumulator, NULL,
2375 _gtk_marshal_BOOLEAN__BOXED,
2377 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2380 * GtkWidget::drag-leave:
2381 * @widget: the object which received the signal.
2382 * @drag_context: the drag context
2383 * @time: the timestamp of the motion event
2385 * The ::drag-leave signal is emitted on the drop site when the cursor
2386 * leaves the widget. A typical reason to connect to this signal is to
2387 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2388 * with gtk_drag_unhighlight()
2390 widget_signals[DRAG_LEAVE] =
2391 g_signal_new (I_("drag-leave"),
2392 G_TYPE_FROM_CLASS (klass),
2394 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2396 _gtk_marshal_VOID__OBJECT_UINT,
2398 GDK_TYPE_DRAG_CONTEXT,
2402 * GtkWidget::drag-begin:
2403 * @widget: the object which received the signal
2404 * @drag_context: the drag context
2406 * The ::drag-begin signal is emitted on the drag source when a drag is
2407 * started. A typical reason to connect to this signal is to set up a
2408 * custom drag icon with gtk_drag_source_set_icon().
2410 * Note that some widgets set up a drag icon in the default handler of
2411 * this signal, so you may have to use g_signal_connect_after() to
2412 * override what the default handler did.
2414 widget_signals[DRAG_BEGIN] =
2415 g_signal_new (I_("drag-begin"),
2416 G_TYPE_FROM_CLASS (klass),
2418 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2420 _gtk_marshal_VOID__OBJECT,
2422 GDK_TYPE_DRAG_CONTEXT);
2425 * GtkWidget::drag-end:
2426 * @widget: the object which received the signal
2427 * @drag_context: the drag context
2429 * The ::drag-end signal is emitted on the drag source when a drag is
2430 * finished. A typical reason to connect to this signal is to undo
2431 * things done in #GtkWidget::drag-begin.
2433 widget_signals[DRAG_END] =
2434 g_signal_new (I_("drag-end"),
2435 G_TYPE_FROM_CLASS (klass),
2437 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2439 _gtk_marshal_VOID__OBJECT,
2441 GDK_TYPE_DRAG_CONTEXT);
2444 * GtkWidget::drag-data-delete:
2445 * @widget: the object which received the signal
2446 * @drag_context: the drag context
2448 * The ::drag-data-delete signal is emitted on the drag source when a drag
2449 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2450 * handler is responsible for deleting the data that has been dropped. What
2451 * "delete" means depends on the context of the drag operation.
2453 widget_signals[DRAG_DATA_DELETE] =
2454 g_signal_new (I_("drag-data-delete"),
2455 G_TYPE_FROM_CLASS (klass),
2457 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2459 _gtk_marshal_VOID__OBJECT,
2461 GDK_TYPE_DRAG_CONTEXT);
2464 * GtkWidget::drag-failed:
2465 * @widget: the object which received the signal
2466 * @drag_context: the drag context
2467 * @result: the result of the drag operation
2469 * The ::drag-failed signal is emitted on the drag source when a drag has
2470 * failed. The signal handler may hook custom code to handle a failed DND
2471 * operation based on the type of error, it returns %TRUE is the failure has
2472 * been already handled (not showing the default "drag operation failed"
2473 * animation), otherwise it returns %FALSE.
2475 * Return value: %TRUE if the failed drag operation has been already handled.
2479 widget_signals[DRAG_FAILED] =
2480 g_signal_new (I_("drag-failed"),
2481 G_TYPE_FROM_CLASS (klass),
2483 0, _gtk_boolean_handled_accumulator, NULL,
2484 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2486 GDK_TYPE_DRAG_CONTEXT,
2487 GTK_TYPE_DRAG_RESULT);
2490 * GtkWidget::drag-motion:
2491 * @widget: the object which received the signal
2492 * @drag_context: the drag context
2493 * @x: the x coordinate of the current cursor position
2494 * @y: the y coordinate of the current cursor position
2495 * @time: the timestamp of the motion event
2496 * @returns: whether the cursor position is in a drop zone
2498 * The drag-motion signal is emitted on the drop site when the user
2499 * moves the cursor over the widget during a drag. The signal handler
2500 * must determine whether the cursor position is in a drop zone or not.
2501 * If it is not in a drop zone, it returns %FALSE and no further processing
2502 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2503 * handler is responsible for providing the necessary information for
2504 * displaying feedback to the user, by calling gdk_drag_status().
2506 * If the decision whether the drop will be accepted or rejected can't be
2507 * made based solely on the cursor position and the type of the data, the
2508 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2509 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2510 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2511 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2512 * when using the drag-motion signal that way.
2514 * Also note that there is no drag-enter signal. The drag receiver has to
2515 * keep track of whether he has received any drag-motion signals since the
2516 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2517 * an "enter" signal. Upon an "enter", the handler will typically highlight
2518 * the drop site with gtk_drag_highlight().
2521 * drag_motion (GtkWidget *widget,
2522 * GdkDragContext *context,
2529 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2531 * if (!private_data->drag_highlight)
2533 * private_data->drag_highlight = 1;
2534 * gtk_drag_highlight (widget);
2537 * target = gtk_drag_dest_find_target (widget, context, NULL);
2538 * if (target == GDK_NONE)
2539 * gdk_drag_status (context, 0, time);
2542 * private_data->pending_status = context->suggested_action;
2543 * gtk_drag_get_data (widget, context, target, time);
2550 * drag_data_received (GtkWidget *widget,
2551 * GdkDragContext *context,
2554 * GtkSelectionData *selection_data,
2558 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2560 * if (private_data->suggested_action)
2562 * private_data->suggested_action = 0;
2564 * /* We are getting this data due to a request in drag_motion,
2565 * * rather than due to a request in drag_drop, so we are just
2566 * * supposed to call gdk_drag_status (), not actually paste in
2569 * str = gtk_selection_data_get_text (selection_data);
2570 * if (!data_is_acceptable (str))
2571 * gdk_drag_status (context, 0, time);
2573 * gdk_drag_status (context, private_data->suggested_action, time);
2577 * /* accept the drop */
2582 widget_signals[DRAG_MOTION] =
2583 g_signal_new (I_("drag-motion"),
2584 G_TYPE_FROM_CLASS (klass),
2586 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2587 _gtk_boolean_handled_accumulator, NULL,
2588 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2590 GDK_TYPE_DRAG_CONTEXT,
2596 * GtkWidget::drag-drop:
2597 * @widget: the object which received the signal
2598 * @drag_context: the drag context
2599 * @x: the x coordinate of the current cursor position
2600 * @y: the y coordinate of the current cursor position
2601 * @time: the timestamp of the motion event
2602 * @returns: whether the cursor position is in a drop zone
2604 * The ::drag-drop signal is emitted on the drop site when the user drops
2605 * the data onto the widget. The signal handler must determine whether
2606 * the cursor position is in a drop zone or not. If it is not in a drop
2607 * zone, it returns %FALSE and no further processing is necessary.
2608 * Otherwise, the handler returns %TRUE. In this case, the handler must
2609 * ensure that gtk_drag_finish() is called to let the source know that
2610 * the drop is done. The call to gtk_drag_finish() can be done either
2611 * directly or in a #GtkWidget::drag-data-received handler which gets
2612 * triggered by calling gtk_drag_get_data() to receive the data for one
2613 * or more of the supported targets.
2615 widget_signals[DRAG_DROP] =
2616 g_signal_new (I_("drag-drop"),
2617 G_TYPE_FROM_CLASS (klass),
2619 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2620 _gtk_boolean_handled_accumulator, NULL,
2621 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2623 GDK_TYPE_DRAG_CONTEXT,
2629 * GtkWidget::drag-data-get:
2630 * @widget: the object which received the signal
2631 * @drag_context: the drag context
2632 * @data: the #GtkSelectionData to be filled with the dragged data
2633 * @info: the info that has been registered with the target in the
2635 * @time: the timestamp at which the data was requested
2637 * The ::drag-data-get signal is emitted on the drag source when the drop
2638 * site requests the data which is dragged. It is the responsibility of
2639 * the signal handler to fill @data with the data in the format which
2640 * is indicated by @info. See gtk_selection_data_set() and
2641 * gtk_selection_data_set_text().
2643 widget_signals[DRAG_DATA_GET] =
2644 g_signal_new (I_("drag-data-get"),
2645 G_TYPE_FROM_CLASS (klass),
2647 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2649 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2651 GDK_TYPE_DRAG_CONTEXT,
2652 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2657 * GtkWidget::drag-data-received:
2658 * @widget: the object which received the signal
2659 * @drag_context: the drag context
2660 * @x: where the drop happened
2661 * @y: where the drop happened
2662 * @data: the received data
2663 * @info: the info that has been registered with the target in the
2665 * @time: the timestamp at which the data was received
2667 * The ::drag-data-received signal is emitted on the drop site when the
2668 * dragged data has been received. If the data was received in order to
2669 * determine whether the drop will be accepted, the handler is expected
2670 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2671 * If the data was received in response to a #GtkWidget::drag-drop signal
2672 * (and this is the last target to be received), the handler for this
2673 * signal is expected to process the received data and then call
2674 * gtk_drag_finish(), setting the @success parameter depending on whether
2675 * the data was processed successfully.
2677 * The handler may inspect and modify @drag_context->action before calling
2678 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2679 * following example:
2682 * drag_data_received (GtkWidget *widget,
2683 * GdkDragContext *drag_context,
2686 * GtkSelectionData *data,
2690 * if ((data->length >= 0) && (data->format == 8))
2692 * if (drag_context->action == GDK_ACTION_ASK)
2694 * GtkWidget *dialog;
2697 * dialog = gtk_message_dialog_new (NULL,
2698 * GTK_DIALOG_MODAL |
2699 * GTK_DIALOG_DESTROY_WITH_PARENT,
2701 * GTK_BUTTONS_YES_NO,
2702 * "Move the data ?\n");
2703 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2704 * gtk_widget_destroy (dialog);
2706 * if (response == GTK_RESPONSE_YES)
2707 * drag_context->action = GDK_ACTION_MOVE;
2709 * drag_context->action = GDK_ACTION_COPY;
2712 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2716 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2720 widget_signals[DRAG_DATA_RECEIVED] =
2721 g_signal_new (I_("drag-data-received"),
2722 G_TYPE_FROM_CLASS (klass),
2724 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2726 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2728 GDK_TYPE_DRAG_CONTEXT,
2731 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2736 * GtkWidget::visibility-notify-event:
2737 * @widget: the object which received the signal
2738 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2739 * triggered this signal.
2741 * The ::visibility-notify-event will be emitted when the @widget's window
2742 * is obscured or unobscured.
2744 * To receive this signal the #GdkWindow associated to the widget needs
2745 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2747 * Returns: %TRUE to stop other handlers from being invoked for the event.
2748 * %FALSE to propagate the event further.
2750 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2751 g_signal_new (I_("visibility-notify-event"),
2752 G_TYPE_FROM_CLASS (klass),
2754 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2755 _gtk_boolean_handled_accumulator, NULL,
2756 _gtk_marshal_BOOLEAN__BOXED,
2758 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2761 * GtkWidget::client-event:
2762 * @widget: the object which received the signal
2763 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2766 * The ::client-event will be emitted when the @widget's window
2767 * receives a message (via a ClientMessage event) from another
2770 * Returns: %TRUE to stop other handlers from being invoked for
2771 * the event. %FALSE to propagate the event further.
2773 widget_signals[CLIENT_EVENT] =
2774 g_signal_new (I_("client-event"),
2775 G_TYPE_FROM_CLASS (klass),
2777 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2778 _gtk_boolean_handled_accumulator, NULL,
2779 _gtk_marshal_BOOLEAN__BOXED,
2781 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2784 * GtkWidget::no-expose-event:
2785 * @widget: the object which received the signal
2786 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2789 * The ::no-expose-event will be emitted when the @widget's window is
2790 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2791 * If the source window was partially obscured #GdkEventExpose events will
2792 * be generated for those areas.
2794 * Returns: %TRUE to stop other handlers from being invoked for the event.
2795 * %FALSE to propagate the event further.
2797 widget_signals[NO_EXPOSE_EVENT] =
2798 g_signal_new (I_("no-expose-event"),
2799 G_TYPE_FROM_CLASS (klass),
2801 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2802 _gtk_boolean_handled_accumulator, NULL,
2803 _gtk_marshal_BOOLEAN__BOXED,
2805 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2808 * GtkWidget::window-state-event:
2809 * @widget: the object which received the signal
2810 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2811 * triggered this signal.
2813 * The ::window-state-event will be emitted when the state of the
2814 * toplevel window associated to the @widget changes.
2816 * To receive this signal the #GdkWindow associated to the widget
2817 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2818 * this mask automatically for all new windows.
2820 * Returns: %TRUE to stop other handlers from being invoked for the
2821 * event. %FALSE to propagate the event further.
2823 widget_signals[WINDOW_STATE_EVENT] =
2824 g_signal_new (I_("window-state-event"),
2825 G_TYPE_FROM_CLASS (klass),
2827 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2828 _gtk_boolean_handled_accumulator, NULL,
2829 _gtk_marshal_BOOLEAN__BOXED,
2831 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2834 * GtkWidget::damage-event:
2835 * @widget: the object which received the signal
2836 * @event: the #GdkEventExpose event
2838 * Emitted when a redirected window belonging to @widget gets drawn into.
2839 * The region/area members of the event shows what area of the redirected
2840 * drawable was drawn into.
2842 * Returns: %TRUE to stop other handlers from being invoked for the event.
2843 * %FALSE to propagate the event further.
2847 widget_signals[DAMAGE_EVENT] =
2848 g_signal_new (I_("damage-event"),
2849 G_TYPE_FROM_CLASS (klass),
2851 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2852 _gtk_boolean_handled_accumulator, NULL,
2853 _gtk_marshal_BOOLEAN__BOXED,
2855 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2858 * GtkWidget::grab-broken-event:
2859 * @widget: the object which received the signal
2860 * @event: the #GdkEventGrabBroken event
2862 * Emitted when a pointer or keyboard grab on a window belonging
2863 * to @widget gets broken.
2865 * On X11, this happens when the grab window becomes unviewable
2866 * (i.e. it or one of its ancestors is unmapped), or if the same
2867 * application grabs the pointer or keyboard again.
2869 * Returns: %TRUE to stop other handlers from being invoked for
2870 * the event. %FALSE to propagate the event further.
2874 widget_signals[GRAB_BROKEN_EVENT] =
2875 g_signal_new (I_("grab-broken-event"),
2876 G_TYPE_FROM_CLASS (klass),
2878 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2879 _gtk_boolean_handled_accumulator, NULL,
2880 _gtk_marshal_BOOLEAN__BOXED,
2882 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2885 * GtkWidget::query-tooltip:
2886 * @widget: the object which received the signal
2887 * @x: the x coordinate of the cursor position where the request has
2888 * been emitted, relative to @widget->window
2889 * @y: the y coordinate of the cursor position where the request has
2890 * been emitted, relative to @widget->window
2891 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2892 * @tooltip: a #GtkTooltip
2894 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2895 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2896 * focus in keyboard mode.
2898 * Using the given coordinates, the signal handler should determine
2899 * whether a tooltip should be shown for @widget. If this is the case
2900 * %TRUE should be returned, %FALSE otherwise. Note that if
2901 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2902 * should not be used.
2904 * The signal handler is free to manipulate @tooltip with the therefore
2905 * destined function calls.
2907 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2911 widget_signals[QUERY_TOOLTIP] =
2912 g_signal_new (I_("query-tooltip"),
2913 G_TYPE_FROM_CLASS (klass),
2915 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2916 _gtk_boolean_handled_accumulator, NULL,
2917 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2925 * GtkWidget::popup-menu
2926 * @widget: the object which received the signal
2928 * This signal gets emitted whenever a widget should pop up a context
2929 * menu. This usually happens through the standard key binding mechanism;
2930 * by pressing a certain key while a widget is focused, the user can cause
2931 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2932 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2933 * for an example of how to use this signal.
2935 * Returns: %TRUE if a menu was activated
2937 widget_signals[POPUP_MENU] =
2938 g_signal_new (I_("popup-menu"),
2939 G_TYPE_FROM_CLASS (klass),
2940 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2941 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2942 _gtk_boolean_handled_accumulator, NULL,
2943 _gtk_marshal_BOOLEAN__VOID,
2947 * GtkWidget::show-help:
2948 * @widget: the object which received the signal.
2951 widget_signals[SHOW_HELP] =
2952 g_signal_new (I_("show-help"),
2953 G_TYPE_FROM_CLASS (klass),
2954 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2955 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2956 _gtk_boolean_handled_accumulator, NULL,
2957 _gtk_marshal_BOOLEAN__ENUM,
2959 GTK_TYPE_WIDGET_HELP_TYPE);
2962 * GtkWidget::accel-closures-changed:
2963 * @widget: the object which received the signal.
2965 widget_signals[ACCEL_CLOSURES_CHANGED] =
2966 g_signal_new (I_("accel-closures-changed"),
2967 G_TYPE_FROM_CLASS (klass),
2971 _gtk_marshal_VOID__VOID,
2975 * GtkWidget::screen-changed:
2976 * @widget: the object on which the signal is emitted
2977 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2978 * widget was not associated with a screen before
2980 * The ::screen-changed signal gets emitted when the
2981 * screen of a widget has changed.
2983 widget_signals[SCREEN_CHANGED] =
2984 g_signal_new (I_("screen-changed"),
2985 G_TYPE_FROM_CLASS (klass),
2987 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2989 _gtk_marshal_VOID__OBJECT,
2994 * GtkWidget::can-activate-accel:
2995 * @widget: the object which received the signal
2996 * @signal_id: the ID of a signal installed on @widget
2998 * Determines whether an accelerator that activates the signal
2999 * identified by @signal_id can currently be activated.
3000 * This signal is present to allow applications and derived
3001 * widgets to override the default #GtkWidget handling
3002 * for determining whether an accelerator can be activated.
3004 * Returns: %TRUE if the signal can be activated.
3006 widget_signals[CAN_ACTIVATE_ACCEL] =
3007 g_signal_new (I_("can-activate-accel"),
3008 G_TYPE_FROM_CLASS (klass),
3010 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3011 _gtk_boolean_handled_accumulator, NULL,
3012 _gtk_marshal_BOOLEAN__UINT,
3013 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3015 binding_set = gtk_binding_set_by_class (klass);
3016 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3018 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3021 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3023 GTK_TYPE_WIDGET_HELP_TYPE,
3024 GTK_WIDGET_HELP_TOOLTIP);
3025 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3027 GTK_TYPE_WIDGET_HELP_TYPE,
3028 GTK_WIDGET_HELP_TOOLTIP);
3029 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3031 GTK_TYPE_WIDGET_HELP_TYPE,
3032 GTK_WIDGET_HELP_WHATS_THIS);
3033 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3035 GTK_TYPE_WIDGET_HELP_TYPE,
3036 GTK_WIDGET_HELP_WHATS_THIS);
3038 gtk_widget_class_install_style_property (klass,
3039 g_param_spec_boolean ("interior-focus",
3040 P_("Interior Focus"),
3041 P_("Whether to draw the focus indicator inside widgets"),
3043 GTK_PARAM_READABLE));
3045 gtk_widget_class_install_style_property (klass,
3046 g_param_spec_int ("focus-line-width",
3047 P_("Focus linewidth"),
3048 P_("Width, in pixels, of the focus indicator line"),
3050 GTK_PARAM_READABLE));
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_string ("focus-line-pattern",
3054 P_("Focus line dash pattern"),
3055 P_("Dash pattern used to draw the focus indicator"),
3057 GTK_PARAM_READABLE));
3058 gtk_widget_class_install_style_property (klass,
3059 g_param_spec_int ("focus-padding",
3060 P_("Focus padding"),
3061 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3063 GTK_PARAM_READABLE));
3064 gtk_widget_class_install_style_property (klass,
3065 g_param_spec_boxed ("cursor-color",
3067 P_("Color with which to draw insertion cursor"),
3069 GTK_PARAM_READABLE));
3070 gtk_widget_class_install_style_property (klass,
3071 g_param_spec_boxed ("secondary-cursor-color",
3072 P_("Secondary cursor color"),
3073 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3075 GTK_PARAM_READABLE));
3076 gtk_widget_class_install_style_property (klass,
3077 g_param_spec_float ("cursor-aspect-ratio",
3078 P_("Cursor line aspect ratio"),
3079 P_("Aspect ratio with which to draw insertion cursor"),
3081 GTK_PARAM_READABLE));
3083 gtk_widget_class_install_style_property (klass,
3084 g_param_spec_boolean ("window-dragging",
3085 P_("Window dragging"),
3086 P_("Whether windows can be dragged by clicking on empty areas"),
3088 GTK_PARAM_READABLE));
3091 * GtkWidget:link-color:
3093 * The "link-color" style property defines the color of unvisited links.
3097 gtk_widget_class_install_style_property (klass,
3098 g_param_spec_boxed ("link-color",
3099 P_("Unvisited Link Color"),
3100 P_("Color of unvisited links"),
3102 GTK_PARAM_READABLE));
3105 * GtkWidget:visited-link-color:
3107 * The "visited-link-color" style property defines the color of visited links.
3111 gtk_widget_class_install_style_property (klass,
3112 g_param_spec_boxed ("visited-link-color",
3113 P_("Visited Link Color"),
3114 P_("Color of visited links"),
3116 GTK_PARAM_READABLE));
3119 * GtkWidget:wide-separators:
3121 * The "wide-separators" style property defines whether separators have
3122 * configurable width and should be drawn using a box instead of a line.
3126 gtk_widget_class_install_style_property (klass,
3127 g_param_spec_boolean ("wide-separators",
3128 P_("Wide Separators"),
3129 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3131 GTK_PARAM_READABLE));
3134 * GtkWidget:separator-width:
3136 * The "separator-width" style property defines the width of separators.
3137 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3141 gtk_widget_class_install_style_property (klass,
3142 g_param_spec_int ("separator-width",
3143 P_("Separator Width"),
3144 P_("The width of separators if wide-separators is TRUE"),
3146 GTK_PARAM_READABLE));
3149 * GtkWidget:separator-height:
3151 * The "separator-height" style property defines the height of separators.
3152 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3156 gtk_widget_class_install_style_property (klass,
3157 g_param_spec_int ("separator-height",
3158 P_("Separator Height"),
3159 P_("The height of separators if \"wide-separators\" is TRUE"),
3161 GTK_PARAM_READABLE));
3164 * GtkWidget:scroll-arrow-hlength:
3166 * The "scroll-arrow-hlength" style property defines the length of
3167 * horizontal scroll arrows.
3171 gtk_widget_class_install_style_property (klass,
3172 g_param_spec_int ("scroll-arrow-hlength",
3173 P_("Horizontal Scroll Arrow Length"),
3174 P_("The length of horizontal scroll arrows"),
3176 GTK_PARAM_READABLE));
3179 * GtkWidget:scroll-arrow-vlength:
3181 * The "scroll-arrow-vlength" style property defines the length of
3182 * vertical scroll arrows.
3186 gtk_widget_class_install_style_property (klass,
3187 g_param_spec_int ("scroll-arrow-vlength",
3188 P_("Vertical Scroll Arrow Length"),
3189 P_("The length of vertical scroll arrows"),
3191 GTK_PARAM_READABLE));
3193 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3197 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3201 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3202 for (node = list; node; node = node->next)
3204 GParamSpec *pspec = node->data;
3206 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3207 g_param_spec_unref (pspec);
3213 gtk_widget_set_property (GObject *object,
3215 const GValue *value,
3218 GtkWidget *widget = GTK_WIDGET (object);
3223 gchar *tooltip_markup;
3224 const gchar *tooltip_text;
3225 GtkWindow *tooltip_window;
3228 gtk_widget_set_name (widget, g_value_get_string (value));
3231 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3233 case PROP_WIDTH_REQUEST:
3234 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3236 case PROP_HEIGHT_REQUEST:
3237 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3240 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3242 case PROP_SENSITIVE:
3243 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3245 case PROP_APP_PAINTABLE:
3246 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3248 case PROP_CAN_FOCUS:
3249 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3251 case PROP_HAS_FOCUS:
3252 if (g_value_get_boolean (value))
3253 gtk_widget_grab_focus (widget);
3256 if (g_value_get_boolean (value))
3257 gtk_widget_grab_focus (widget);
3259 case PROP_CAN_DEFAULT:
3260 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3262 case PROP_HAS_DEFAULT:
3263 if (g_value_get_boolean (value))
3264 gtk_widget_grab_default (widget);
3266 case PROP_RECEIVES_DEFAULT:
3267 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3270 gtk_widget_set_style (widget, g_value_get_object (value));
3273 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3274 gtk_widget_set_events (widget, g_value_get_flags (value));
3276 case PROP_EXTENSION_EVENTS:
3277 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3279 case PROP_NO_SHOW_ALL:
3280 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3282 case PROP_HAS_TOOLTIP:
3283 gtk_widget_real_set_has_tooltip (widget,
3284 g_value_get_boolean (value), FALSE);
3286 case PROP_TOOLTIP_MARKUP:
3287 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3288 tooltip_markup = g_value_dup_string (value);
3290 /* Treat an empty string as a NULL string,
3291 * because an empty string would be useless for a tooltip:
3293 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3295 g_free (tooltip_markup);
3296 tooltip_markup = NULL;
3299 g_object_set_qdata_full (object, quark_tooltip_markup,
3300 tooltip_markup, g_free);
3302 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3303 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3304 if (gtk_widget_get_visible (widget))
3305 gtk_widget_queue_tooltip_query (widget);
3307 case PROP_TOOLTIP_TEXT:
3308 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3310 tooltip_text = g_value_get_string (value);
3312 /* Treat an empty string as a NULL string,
3313 * because an empty string would be useless for a tooltip:
3315 if (tooltip_text && (strlen (tooltip_text) == 0))
3316 tooltip_text = NULL;
3318 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3320 g_object_set_qdata_full (object, quark_tooltip_markup,
3321 tooltip_markup, g_free);
3323 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3324 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3325 if (gtk_widget_get_visible (widget))
3326 gtk_widget_queue_tooltip_query (widget);
3328 case PROP_DOUBLE_BUFFERED:
3329 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3332 gtk_widget_set_halign (widget, g_value_get_enum (value));
3335 gtk_widget_set_valign (widget, g_value_get_enum (value));
3337 case PROP_MARGIN_LEFT:
3338 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3340 case PROP_MARGIN_RIGHT:
3341 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3343 case PROP_MARGIN_TOP:
3344 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3346 case PROP_MARGIN_BOTTOM:
3347 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3350 g_object_freeze_notify (G_OBJECT (widget));
3351 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3352 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3353 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3354 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3355 g_object_thaw_notify (G_OBJECT (widget));
3358 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3360 case PROP_HEXPAND_SET:
3361 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3364 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3366 case PROP_VEXPAND_SET:
3367 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3370 g_object_freeze_notify (G_OBJECT (widget));
3371 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3372 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3373 g_object_thaw_notify (G_OBJECT (widget));
3376 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3382 gtk_widget_get_property (GObject *object,
3387 GtkWidget *widget = GTK_WIDGET (object);
3388 GtkWidgetPrivate *priv = widget->priv;
3397 g_value_set_string (value, priv->name);
3399 g_value_set_static_string (value, "");
3402 g_value_set_object (value, priv->parent);
3404 case PROP_WIDTH_REQUEST:
3407 gtk_widget_get_size_request (widget, &w, NULL);
3408 g_value_set_int (value, w);
3411 case PROP_HEIGHT_REQUEST:
3414 gtk_widget_get_size_request (widget, NULL, &h);
3415 g_value_set_int (value, h);
3419 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3421 case PROP_SENSITIVE:
3422 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3424 case PROP_APP_PAINTABLE:
3425 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3427 case PROP_CAN_FOCUS:
3428 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3430 case PROP_HAS_FOCUS:
3431 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3434 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3436 case PROP_CAN_DEFAULT:
3437 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3439 case PROP_HAS_DEFAULT:
3440 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3442 case PROP_RECEIVES_DEFAULT:
3443 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3445 case PROP_COMPOSITE_CHILD:
3446 g_value_set_boolean (value, widget->priv->composite_child);
3449 g_value_set_object (value, gtk_widget_get_style (widget));
3452 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3453 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3455 case PROP_EXTENSION_EVENTS:
3456 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3457 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3459 case PROP_NO_SHOW_ALL:
3460 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3462 case PROP_HAS_TOOLTIP:
3463 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3465 case PROP_TOOLTIP_TEXT:
3467 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3470 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3471 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3473 g_value_take_string (value, text);
3476 case PROP_TOOLTIP_MARKUP:
3477 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3480 g_value_set_object (value, gtk_widget_get_window (widget));
3482 case PROP_DOUBLE_BUFFERED:
3483 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3486 g_value_set_enum (value, gtk_widget_get_halign (widget));
3489 g_value_set_enum (value, gtk_widget_get_valign (widget));
3491 case PROP_MARGIN_LEFT:
3492 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3494 case PROP_MARGIN_RIGHT:
3495 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3497 case PROP_MARGIN_TOP:
3498 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3500 case PROP_MARGIN_BOTTOM:
3501 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3505 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3506 if (aux_info == NULL)
3508 g_value_set_int (value, 0);
3512 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3513 aux_info->margin.right),
3514 MAX (aux_info->margin.top,
3515 aux_info->margin.bottom)));
3520 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3522 case PROP_HEXPAND_SET:
3523 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3526 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3528 case PROP_VEXPAND_SET:
3529 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3532 g_value_set_boolean (value,
3533 gtk_widget_get_hexpand (widget) &&
3534 gtk_widget_get_vexpand (widget));
3537 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3543 gtk_widget_init (GtkWidget *widget)
3545 GtkWidgetPrivate *priv;
3547 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3550 priv = widget->priv;
3552 priv->child_visible = TRUE;
3553 priv->state = GTK_STATE_NORMAL;
3554 priv->saved_state = GTK_STATE_NORMAL;
3556 priv->allocation.x = -1;
3557 priv->allocation.y = -1;
3558 priv->allocation.width = 1;
3559 priv->allocation.height = 1;
3560 priv->window = NULL;
3561 priv->parent = NULL;
3563 priv->sensitive = TRUE;
3564 priv->parent_sensitive = TRUE;
3565 priv->composite_child = composite_child_stack != 0;
3566 priv->double_buffered = TRUE;
3567 priv->redraw_on_alloc = TRUE;
3568 priv->width_request_needed = TRUE;
3569 priv->height_request_needed = TRUE;
3570 priv->alloc_needed = TRUE;
3572 /* this will be set to TRUE if the widget gets a child or if the
3573 * expand flag is set on the widget, but until one of those happen
3574 * we know the expand is already properly FALSE.
3576 * We really want to default FALSE here to avoid computing expand
3577 * all over the place while initially building a widget tree.
3579 priv->need_compute_expand = FALSE;
3581 priv->style = gtk_widget_get_default_style ();
3582 g_object_ref (priv->style);
3587 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3589 GParamSpec **pspecs)
3591 GtkWidgetPrivate *priv = widget->priv;
3592 GtkWidget *container = priv->parent;
3595 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3596 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3600 * gtk_widget_freeze_child_notify:
3601 * @widget: a #GtkWidget
3603 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3604 * signals are queued until gtk_widget_thaw_child_notify() is called
3607 * This is the analogue of g_object_freeze_notify() for child properties.
3610 gtk_widget_freeze_child_notify (GtkWidget *widget)
3612 g_return_if_fail (GTK_IS_WIDGET (widget));
3614 if (!G_OBJECT (widget)->ref_count)
3617 g_object_ref (widget);
3618 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3619 g_object_unref (widget);
3623 * gtk_widget_child_notify:
3624 * @widget: a #GtkWidget
3625 * @child_property: the name of a child property installed on the
3626 * class of @widget<!-- -->'s parent
3628 * Emits a #GtkWidget::child-notify signal for the
3629 * <link linkend="child-properties">child property</link> @child_property
3632 * This is the analogue of g_object_notify() for child properties.
3635 gtk_widget_child_notify (GtkWidget *widget,
3636 const gchar *child_property)
3638 GtkWidgetPrivate *priv = widget->priv;
3641 g_return_if_fail (GTK_IS_WIDGET (widget));
3642 g_return_if_fail (child_property != NULL);
3643 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3646 g_object_ref (widget);
3647 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3649 G_OBJECT_TYPE (priv->parent),
3652 g_warning ("%s: container class `%s' has no child property named `%s'",
3654 G_OBJECT_TYPE_NAME (priv->parent),
3658 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3660 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3661 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3663 g_object_unref (widget);
3667 * gtk_widget_thaw_child_notify:
3668 * @widget: a #GtkWidget
3670 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3671 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3675 gtk_widget_thaw_child_notify (GtkWidget *widget)
3677 GObjectNotifyQueue *nqueue;
3679 g_return_if_fail (GTK_IS_WIDGET (widget));
3681 if (!G_OBJECT (widget)->ref_count)
3684 g_object_ref (widget);
3685 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3686 if (!nqueue || !nqueue->freeze_count)
3687 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3688 G_OBJECT_TYPE_NAME (widget), widget);
3690 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3691 g_object_unref (widget);
3697 * @type: type ID of the widget to create
3698 * @first_property_name: name of first property to set
3699 * @Varargs: value of first property, followed by more properties,
3702 * This is a convenience function for creating a widget and setting
3703 * its properties in one go. For example you might write:
3704 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3705 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3706 * g_object_new(), but returns a widget so you don't have to
3707 * cast the object yourself.
3709 * Return value: a new #GtkWidget of type @widget_type
3712 gtk_widget_new (GType type,
3713 const gchar *first_property_name,
3719 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3721 va_start (var_args, first_property_name);
3722 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3729 gtk_widget_queue_draw_child (GtkWidget *widget)
3731 GtkWidgetPrivate *priv = widget->priv;
3734 parent = priv->parent;
3735 if (parent && gtk_widget_is_drawable (parent))
3736 gtk_widget_queue_draw_area (parent,
3739 priv->allocation.width,
3740 priv->allocation.height);
3744 * gtk_widget_unparent:
3745 * @widget: a #GtkWidget
3747 * This function is only for use in widget implementations.
3748 * Should be called by implementations of the remove method
3749 * on #GtkContainer, to dissociate a child from the container.
3752 gtk_widget_unparent (GtkWidget *widget)
3754 GtkWidgetPrivate *priv;
3755 GObjectNotifyQueue *nqueue;
3756 GtkWidget *toplevel;
3757 GtkWidget *old_parent;
3759 g_return_if_fail (GTK_IS_WIDGET (widget));
3761 priv = widget->priv;
3763 if (priv->parent == NULL)
3766 /* keep this function in sync with gtk_menu_detach()
3769 g_object_freeze_notify (G_OBJECT (widget));
3770 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3772 toplevel = gtk_widget_get_toplevel (widget);
3773 if (gtk_widget_is_toplevel (toplevel))
3774 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3776 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3777 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3779 /* If we are unanchoring the child, we save around the toplevel
3780 * to emit hierarchy changed
3782 if (priv->parent->priv->anchored)
3783 g_object_ref (toplevel);
3787 gtk_widget_queue_draw_child (widget);
3789 /* Reset the width and height here, to force reallocation if we
3790 * get added back to a new parent. This won't work if our new
3791 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3792 * (would 0x0 be OK here?)
3794 priv->allocation.width = 1;
3795 priv->allocation.height = 1;
3797 if (gtk_widget_get_realized (widget))
3799 if (priv->in_reparent)
3800 gtk_widget_unmap (widget);
3802 gtk_widget_unrealize (widget);
3805 /* Removing a widget from a container restores the child visible
3806 * flag to the default state, so it doesn't affect the child
3807 * in the next parent.
3809 priv->child_visible = TRUE;
3811 old_parent = priv->parent;
3812 priv->parent = NULL;
3813 gtk_widget_set_parent_window (widget, NULL);
3815 /* parent may no longer expand if the removed
3816 * child was expand=TRUE and could therefore
3819 if (gtk_widget_get_visible (widget) &&
3820 (priv->need_compute_expand ||
3821 priv->computed_hexpand ||
3822 priv->computed_vexpand))
3824 gtk_widget_queue_compute_expand (old_parent);
3827 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3830 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3831 g_object_unref (toplevel);
3834 g_object_notify (G_OBJECT (widget), "parent");
3835 g_object_thaw_notify (G_OBJECT (widget));
3837 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3838 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3839 g_object_unref (widget);
3843 * gtk_widget_destroy:
3844 * @widget: a #GtkWidget
3846 * Destroys a widget.
3849 * destroyed, it will break any references it holds to other objects.
3850 * If the widget is inside a container, the widget will be removed
3851 * from the container. If the widget is a toplevel (derived from
3852 * #GtkWindow), it will be removed from the list of toplevels, and the
3853 * reference GTK+ holds to it will be removed. Removing a
3854 * widget from its container or the list of toplevels results in the
3855 * widget being finalized, unless you've added additional references
3856 * to the widget with g_object_ref().
3858 * In most cases, only toplevel widgets (windows) require explicit
3859 * destruction, because when you destroy a toplevel its children will
3860 * be destroyed as well.
3863 gtk_widget_destroy (GtkWidget *widget)
3865 g_return_if_fail (GTK_IS_WIDGET (widget));
3867 if (!widget->priv->in_destruction)
3868 g_object_run_dispose (G_OBJECT (widget));
3872 * gtk_widget_destroyed:
3873 * @widget: a #GtkWidget
3874 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3876 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3877 * %NULL. It's intended to be used as a callback connected to the
3878 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3879 * as a signal handler, and pass the address of your widget variable
3880 * as user data. Then when the widget is destroyed, the variable will
3881 * be set to %NULL. Useful for example to avoid multiple copies
3882 * of the same dialog.
3885 gtk_widget_destroyed (GtkWidget *widget,
3886 GtkWidget **widget_pointer)
3888 /* Don't make any assumptions about the
3890 * Even check widget_pointer.
3893 *widget_pointer = NULL;
3898 * @widget: a #GtkWidget
3900 * Flags a widget to be displayed. Any widget that isn't shown will
3901 * not appear on the screen. If you want to show all the widgets in a
3902 * container, it's easier to call gtk_widget_show_all() on the
3903 * container, instead of individually showing the widgets.
3905 * Remember that you have to show the containers containing a widget,
3906 * in addition to the widget itself, before it will appear onscreen.
3908 * When a toplevel container is shown, it is immediately realized and
3909 * mapped; other shown widgets are realized and mapped when their
3910 * toplevel container is realized and mapped.
3913 gtk_widget_show (GtkWidget *widget)
3915 g_return_if_fail (GTK_IS_WIDGET (widget));
3917 if (!gtk_widget_get_visible (widget))
3919 g_object_ref (widget);
3920 if (!gtk_widget_is_toplevel (widget))
3921 gtk_widget_queue_resize (widget);
3923 /* see comment in set_parent() for why this should and can be
3926 if (widget->priv->need_compute_expand ||
3927 widget->priv->computed_hexpand ||
3928 widget->priv->computed_vexpand)
3930 if (widget->priv->parent != NULL)
3931 gtk_widget_queue_compute_expand (widget->priv->parent);
3934 g_signal_emit (widget, widget_signals[SHOW], 0);
3935 g_object_notify (G_OBJECT (widget), "visible");
3936 g_object_unref (widget);
3941 gtk_widget_real_show (GtkWidget *widget)
3943 GtkWidgetPrivate *priv = widget->priv;
3945 if (!gtk_widget_get_visible (widget))
3947 priv->visible = TRUE;
3950 gtk_widget_get_mapped (priv->parent) &&
3951 gtk_widget_get_child_visible (widget) &&
3952 !gtk_widget_get_mapped (widget))
3953 gtk_widget_map (widget);
3958 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3961 g_signal_handlers_disconnect_by_func (widget,
3962 gtk_widget_show_map_callback,
3967 * gtk_widget_show_now:
3968 * @widget: a #GtkWidget
3970 * Shows a widget. If the widget is an unmapped toplevel widget
3971 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3972 * loop and wait for the window to actually be mapped. Be careful;
3973 * because the main loop is running, anything can happen during
3977 gtk_widget_show_now (GtkWidget *widget)
3981 g_return_if_fail (GTK_IS_WIDGET (widget));
3983 /* make sure we will get event */
3984 if (!gtk_widget_get_mapped (widget) &&
3985 gtk_widget_is_toplevel (widget))
3987 gtk_widget_show (widget);
3989 g_signal_connect (widget, "map-event",
3990 G_CALLBACK (gtk_widget_show_map_callback),
3994 gtk_main_iteration ();
3997 gtk_widget_show (widget);
4002 * @widget: a #GtkWidget
4004 * Reverses the effects of gtk_widget_show(), causing the widget to be
4005 * hidden (invisible to the user).
4008 gtk_widget_hide (GtkWidget *widget)
4010 g_return_if_fail (GTK_IS_WIDGET (widget));
4012 if (gtk_widget_get_visible (widget))
4014 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4016 g_object_ref (widget);
4017 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4018 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4020 /* a parent may now be expand=FALSE since we're hidden. */
4021 if (widget->priv->need_compute_expand ||
4022 widget->priv->computed_hexpand ||
4023 widget->priv->computed_vexpand)
4025 gtk_widget_queue_compute_expand (widget);
4028 g_signal_emit (widget, widget_signals[HIDE], 0);
4029 if (!gtk_widget_is_toplevel (widget))
4030 gtk_widget_queue_resize (widget);
4031 g_object_notify (G_OBJECT (widget), "visible");
4032 g_object_unref (widget);
4037 gtk_widget_real_hide (GtkWidget *widget)
4039 if (gtk_widget_get_visible (widget))
4041 widget->priv->visible = FALSE;
4043 if (gtk_widget_get_mapped (widget))
4044 gtk_widget_unmap (widget);
4049 * gtk_widget_hide_on_delete:
4050 * @widget: a #GtkWidget
4052 * Utility function; intended to be connected to the #GtkWidget::delete-event
4053 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4054 * argument, then returns %TRUE. If connected to ::delete-event, the
4055 * result is that clicking the close button for a window (on the
4056 * window frame, top right corner usually) will hide but not destroy
4057 * the window. By default, GTK+ destroys windows when ::delete-event
4060 * Return value: %TRUE
4063 gtk_widget_hide_on_delete (GtkWidget *widget)
4065 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4067 gtk_widget_hide (widget);
4073 * gtk_widget_show_all:
4074 * @widget: a #GtkWidget
4076 * Recursively shows a widget, and any child widgets (if the widget is
4080 gtk_widget_show_all (GtkWidget *widget)
4082 GtkWidgetClass *class;
4084 g_return_if_fail (GTK_IS_WIDGET (widget));
4086 if (gtk_widget_get_no_show_all (widget))
4089 class = GTK_WIDGET_GET_CLASS (widget);
4091 if (class->show_all)
4092 class->show_all (widget);
4097 * @widget: a #GtkWidget
4099 * This function is only for use in widget implementations. Causes
4100 * a widget to be mapped if it isn't already.
4103 gtk_widget_map (GtkWidget *widget)
4105 GtkWidgetPrivate *priv;
4107 g_return_if_fail (GTK_IS_WIDGET (widget));
4108 g_return_if_fail (gtk_widget_get_visible (widget));
4109 g_return_if_fail (gtk_widget_get_child_visible (widget));
4111 priv = widget->priv;
4113 if (!gtk_widget_get_mapped (widget))
4115 if (!gtk_widget_get_realized (widget))
4116 gtk_widget_realize (widget);
4118 g_signal_emit (widget, widget_signals[MAP], 0);
4120 if (!gtk_widget_get_has_window (widget))
4121 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4127 * @widget: a #GtkWidget
4129 * This function is only for use in widget implementations. Causes
4130 * a widget to be unmapped if it's currently mapped.
4133 gtk_widget_unmap (GtkWidget *widget)
4135 GtkWidgetPrivate *priv;
4137 g_return_if_fail (GTK_IS_WIDGET (widget));
4139 priv = widget->priv;
4141 if (gtk_widget_get_mapped (widget))
4143 if (!gtk_widget_get_has_window (widget))
4144 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4145 _gtk_tooltip_hide (widget);
4146 g_signal_emit (widget, widget_signals[UNMAP], 0);
4151 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4152 GdkExtensionMode mode,
4155 GtkWidgetPrivate *priv = widget->priv;
4156 GList *free_list = NULL;
4159 if (window_list == NULL)
4161 if (gtk_widget_get_has_window (widget))
4162 window_list = g_list_prepend (NULL, priv->window);
4164 window_list = gdk_window_get_children (priv->window);
4166 free_list = window_list;
4169 for (l = window_list; l != NULL; l = l->next)
4171 GdkWindow *window = l->data;
4174 gdk_window_get_user_data (window, &user_data);
4175 if (user_data == widget)
4179 gdk_input_set_extension_events (window,
4180 gdk_window_get_events (window),
4183 children = gdk_window_get_children (window);
4186 gtk_widget_set_extension_events_internal (widget, mode, children);
4187 g_list_free (children);
4193 g_list_free (free_list);
4197 _gtk_widget_enable_device_events (GtkWidget *widget)
4199 GHashTable *device_events;
4200 GHashTableIter iter;
4201 gpointer key, value;
4203 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4208 g_hash_table_iter_init (&iter, device_events);
4210 while (g_hash_table_iter_next (&iter, &key, &value))
4213 GdkEventMask event_mask;
4216 event_mask = GPOINTER_TO_UINT (value);
4217 gtk_widget_add_events_internal (widget, device, event_mask);
4222 * gtk_widget_realize:
4223 * @widget: a #GtkWidget
4225 * Creates the GDK (windowing system) resources associated with a
4226 * widget. For example, @widget->window will be created when a widget
4227 * is realized. Normally realization happens implicitly; if you show
4228 * a widget and all its parent containers, then the widget will be
4229 * realized and mapped automatically.
4231 * Realizing a widget requires all
4232 * the widget's parent widgets to be realized; calling
4233 * gtk_widget_realize() realizes the widget's parents in addition to
4234 * @widget itself. If a widget is not yet inside a toplevel window
4235 * when you realize it, bad things will happen.
4237 * This function is primarily used in widget implementations, and
4238 * isn't very useful otherwise. Many times when you think you might
4239 * need it, a better approach is to connect to a signal that will be
4240 * called after the widget is realized automatically, such as
4241 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4242 * #GtkWidget::realize signal.
4245 gtk_widget_realize (GtkWidget *widget)
4247 GtkWidgetPrivate *priv;
4248 GdkExtensionMode mode;
4249 cairo_region_t *region;
4251 g_return_if_fail (GTK_IS_WIDGET (widget));
4252 g_return_if_fail (widget->priv->anchored ||
4253 GTK_IS_INVISIBLE (widget));
4255 priv = widget->priv;
4257 if (!gtk_widget_get_realized (widget))
4260 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4261 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4264 if (priv->parent == NULL &&
4265 !gtk_widget_is_toplevel (widget))
4266 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4267 "inside a toplevel window is not going to work very well. "
4268 "Widgets must be inside a toplevel container before realizing them.");
4270 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4271 gtk_widget_realize (priv->parent);
4273 gtk_widget_ensure_style (widget);
4275 g_signal_emit (widget, widget_signals[REALIZE], 0);
4277 gtk_widget_real_set_has_tooltip (widget,
4278 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4281 if (priv->has_shape_mask)
4283 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4284 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4287 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4289 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4291 mode = gtk_widget_get_extension_events (widget);
4292 if (mode != GDK_EXTENSION_EVENTS_NONE)
4293 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4295 if (priv->multidevice)
4296 gdk_window_set_support_multidevice (priv->window, TRUE);
4298 _gtk_widget_enable_device_events (widget);
4303 * gtk_widget_unrealize:
4304 * @widget: a #GtkWidget
4306 * This function is only useful in widget implementations.
4307 * Causes a widget to be unrealized (frees all GDK resources
4308 * associated with the widget, such as @widget->window).
4311 gtk_widget_unrealize (GtkWidget *widget)
4313 g_return_if_fail (GTK_IS_WIDGET (widget));
4315 if (widget->priv->has_shape_mask)
4316 gtk_widget_shape_combine_region (widget, NULL);
4318 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4319 gtk_widget_input_shape_combine_region (widget, NULL);
4321 if (gtk_widget_get_realized (widget))
4323 g_object_ref (widget);
4324 _gtk_tooltip_hide (widget);
4325 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4326 gtk_widget_set_realized (widget, FALSE);
4327 gtk_widget_set_mapped (widget, FALSE);
4328 g_object_unref (widget);
4332 /*****************************************
4334 *****************************************/
4337 * gtk_widget_queue_draw_region:
4338 * @widget: a #GtkWidget
4339 * @region: region to draw
4341 * Invalidates the rectangular area of @widget defined by @region by
4342 * calling gdk_window_invalidate_region() on the widget's window and
4343 * all its child windows. Once the main loop becomes idle (after the
4344 * current batch of events has been processed, roughly), the window
4345 * will receive expose events for the union of all regions that have
4348 * Normally you would only use this function in widget
4349 * implementations. You might also use it to schedule a redraw of a
4350 * #GtkDrawingArea or some portion thereof.
4353 gtk_widget_queue_draw_region (GtkWidget *widget,
4354 cairo_region_t *region)
4356 GtkWidgetPrivate *priv;
4359 g_return_if_fail (GTK_IS_WIDGET (widget));
4361 priv = widget->priv;
4363 if (!gtk_widget_get_realized (widget))
4366 /* Just return if the widget or one of its ancestors isn't mapped */
4367 for (w = widget; w != NULL; w = w->priv->parent)
4368 if (!gtk_widget_get_mapped (w))
4371 gdk_window_invalidate_region (priv->window, region, TRUE);
4375 * gtk_widget_queue_draw_area:
4376 * @widget: a #GtkWidget
4377 * @x: x coordinate of upper-left corner of rectangle to redraw
4378 * @y: y coordinate of upper-left corner of rectangle to redraw
4379 * @width: width of region to draw
4380 * @height: height of region to draw
4382 * Convenience function that calls gtk_widget_queue_draw_region() on
4383 * the region created from the given coordinates.
4386 gtk_widget_queue_draw_area (GtkWidget *widget,
4393 cairo_region_t *region;
4395 g_return_if_fail (GTK_IS_WIDGET (widget));
4400 rect.height = height;
4402 region = cairo_region_create_rectangle (&rect);
4403 gtk_widget_queue_draw_region (widget, region);
4404 cairo_region_destroy (region);
4408 * gtk_widget_queue_draw:
4409 * @widget: a #GtkWidget
4411 * Equivalent to calling gtk_widget_queue_draw_area() for the
4412 * entire area of a widget.
4415 gtk_widget_queue_draw (GtkWidget *widget)
4419 g_return_if_fail (GTK_IS_WIDGET (widget));
4421 gtk_widget_get_allocation (widget, &rect);
4423 if (!gtk_widget_get_has_window (widget))
4424 gtk_widget_queue_draw_area (widget,
4425 rect.x, rect.y, rect.width, rect.height);
4427 gtk_widget_queue_draw_area (widget,
4428 0, 0, rect.width, rect.height);
4432 * gtk_widget_queue_resize:
4433 * @widget: a #GtkWidget
4435 * This function is only for use in widget implementations.
4436 * Flags a widget to have its size renegotiated; should
4437 * be called when a widget for some reason has a new size request.
4438 * For example, when you change the text in a #GtkLabel, #GtkLabel
4439 * queues a resize to ensure there's enough space for the new text.
4442 gtk_widget_queue_resize (GtkWidget *widget)
4444 g_return_if_fail (GTK_IS_WIDGET (widget));
4446 if (gtk_widget_get_realized (widget))
4447 gtk_widget_queue_shallow_draw (widget);
4449 _gtk_size_group_queue_resize (widget, 0);
4453 * gtk_widget_queue_resize_no_redraw:
4454 * @widget: a #GtkWidget
4456 * This function works like gtk_widget_queue_resize(),
4457 * except that the widget is not invalidated.
4462 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4464 g_return_if_fail (GTK_IS_WIDGET (widget));
4466 _gtk_size_group_queue_resize (widget, 0);
4470 * gtk_widget_size_request:
4471 * @widget: a #GtkWidget
4472 * @requisition: (out): a #GtkRequisition to be filled in
4474 * This function is typically used when implementing a #GtkContainer
4475 * subclass. Obtains the preferred size of a widget. The container
4476 * uses this information to arrange its child widgets and decide what
4477 * size allocations to give them with gtk_widget_size_allocate().
4479 * You can also call this function from an application, with some
4480 * caveats. Most notably, getting a size request requires the widget
4481 * to be associated with a screen, because font information may be
4482 * needed. Multihead-aware applications should keep this in mind.
4484 * Also remember that the size request is not necessarily the size
4485 * a widget will actually be allocated.
4487 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4490 gtk_widget_size_request (GtkWidget *widget,
4491 GtkRequisition *requisition)
4493 g_return_if_fail (GTK_IS_WIDGET (widget));
4495 gtk_widget_get_preferred_size (widget, requisition, NULL);
4499 * gtk_widget_get_child_requisition:
4500 * @widget: a #GtkWidget
4501 * @requisition: (out): a #GtkRequisition to be filled in
4503 * This function is only for use in widget implementations. Obtains
4504 * @widget->requisition, unless someone has forced a particular
4505 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4506 * in which case it returns that geometry instead of the widget's
4509 * This function differs from gtk_widget_size_request() in that
4510 * it retrieves the last size request value from @widget->requisition,
4511 * while gtk_widget_size_request() actually calls the "size_request" method
4512 * on @widget to compute the size request and fill in @widget->requisition,
4513 * and only then returns @widget->requisition.
4515 * Because this function does not call the "size_request" method, it
4516 * can only be used when you know that @widget->requisition is
4517 * up-to-date, that is, gtk_widget_size_request() has been called
4518 * since the last time a resize was queued. In general, only container
4519 * implementations have this information; applications should use
4520 * gtk_widget_size_request().
4523 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4526 gtk_widget_get_child_requisition (GtkWidget *widget,
4527 GtkRequisition *requisition)
4529 gtk_widget_get_preferred_size (widget, requisition, NULL);
4533 invalidate_predicate (GdkWindow *window,
4538 gdk_window_get_user_data (window, &user_data);
4540 return (user_data == data);
4543 /* Invalidate @region in widget->window and all children
4544 * of widget->window owned by widget. @region is in the
4545 * same coordinates as widget->allocation and will be
4546 * modified by this call.
4549 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4550 cairo_region_t *region)
4552 GtkWidgetPrivate *priv = widget->priv;
4554 if (!gtk_widget_get_realized (widget))
4557 if (gtk_widget_get_has_window (widget) && priv->parent)
4561 gdk_window_get_position (priv->window, &x, &y);
4562 cairo_region_translate (region, -x, -y);
4565 gdk_window_invalidate_maybe_recurse (priv->window, region,
4566 invalidate_predicate, widget);
4570 * gtk_widget_queue_shallow_draw:
4571 * @widget: a #GtkWidget
4573 * Like gtk_widget_queue_draw(), but only windows owned
4574 * by @widget are invalidated.
4577 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4580 cairo_region_t *region;
4582 if (!gtk_widget_get_realized (widget))
4585 gtk_widget_get_allocation (widget, &rect);
4587 region = cairo_region_create_rectangle (&rect);
4588 gtk_widget_invalidate_widget_windows (widget, region);
4589 cairo_region_destroy (region);
4593 * gtk_widget_size_allocate:
4594 * @widget: a #GtkWidget
4595 * @allocation: (inout): position and size to be allocated to @widget
4597 * This function is only used by #GtkContainer subclasses, to assign a size
4598 * and position to their child widgets.
4600 * In this function, the allocation may be adjusted. It will be forced
4601 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4602 * method on the child will be used to adjust the allocation. Standard
4603 * adjustments include removing the widget's margins, and applying the
4604 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4607 gtk_widget_size_allocate (GtkWidget *widget,
4608 GtkAllocation *allocation)
4610 GtkWidgetPrivate *priv;
4611 GdkRectangle real_allocation;
4612 GdkRectangle old_allocation;
4613 GdkRectangle adjusted_allocation;
4614 gboolean alloc_needed;
4615 gboolean size_changed;
4616 gboolean position_changed;
4617 gint natural_width, natural_height;
4618 gint min_width, min_height;
4620 priv = widget->priv;
4622 g_return_if_fail (GTK_IS_WIDGET (widget));
4624 #ifdef G_ENABLE_DEBUG
4625 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4636 parent = gtk_widget_get_parent (parent);
4639 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4640 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4641 2 * depth, " ", name,
4642 allocation->width, allocation->height);
4644 #endif /* G_ENABLE_DEBUG */
4646 alloc_needed = priv->alloc_needed;
4647 if (!priv->width_request_needed && !priv->height_request_needed)
4648 /* Preserve request/allocate ordering */
4649 priv->alloc_needed = FALSE;
4651 old_allocation = priv->allocation;
4652 real_allocation = *allocation;
4654 adjusted_allocation = real_allocation;
4655 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4657 /* Go ahead and request the height for allocated width, note that the internals
4658 * of get_height_for_width will internally limit the for_size to natural size
4659 * when aligning implicitly.
4661 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4662 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4666 /* Go ahead and request the width for allocated height, note that the internals
4667 * of get_width_for_height will internally limit the for_size to natural size
4668 * when aligning implicitly.
4670 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4671 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4674 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4675 * allocated sizes and possibly limit them to the natural sizes */
4676 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4677 GTK_ORIENTATION_HORIZONTAL,
4679 &adjusted_allocation.x,
4680 &adjusted_allocation.width);
4681 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4682 GTK_ORIENTATION_VERTICAL,
4684 &adjusted_allocation.y,
4685 &adjusted_allocation.height);
4687 if (adjusted_allocation.x < real_allocation.x ||
4688 adjusted_allocation.y < real_allocation.y ||
4689 (adjusted_allocation.x + adjusted_allocation.width) >
4690 (real_allocation.x + real_allocation.width) ||
4691 (adjusted_allocation.y + adjusted_allocation.height >
4692 real_allocation.y + real_allocation.height))
4694 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",
4695 G_OBJECT_TYPE_NAME (widget), widget,
4696 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4697 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4698 adjusted_allocation = real_allocation; /* veto it */
4702 real_allocation = adjusted_allocation;
4705 if (real_allocation.width < 0 || real_allocation.height < 0)
4707 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4708 real_allocation.width,
4709 real_allocation.height);
4712 real_allocation.width = MAX (real_allocation.width, 1);
4713 real_allocation.height = MAX (real_allocation.height, 1);
4715 size_changed = (old_allocation.width != real_allocation.width ||
4716 old_allocation.height != real_allocation.height);
4717 position_changed = (old_allocation.x != real_allocation.x ||
4718 old_allocation.y != real_allocation.y);
4720 if (!alloc_needed && !size_changed && !position_changed)
4723 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4725 if (gtk_widget_get_mapped (widget))
4727 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4729 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4731 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4732 cairo_region_union_rectangle (invalidate, &old_allocation);
4734 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4735 cairo_region_destroy (invalidate);
4740 if (priv->redraw_on_alloc)
4742 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4744 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4745 cairo_region_union_rectangle (invalidate, &old_allocation);
4747 gtk_widget_invalidate_widget_windows (widget, invalidate);
4748 cairo_region_destroy (invalidate);
4753 if ((size_changed || position_changed) && priv->parent &&
4754 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4756 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4757 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4758 cairo_region_destroy (invalidate);
4763 * gtk_widget_common_ancestor:
4764 * @widget_a: a #GtkWidget
4765 * @widget_b: a #GtkWidget
4767 * Find the common ancestor of @widget_a and @widget_b that
4768 * is closest to the two widgets.
4770 * Return value: the closest common ancestor of @widget_a and
4771 * @widget_b or %NULL if @widget_a and @widget_b do not
4772 * share a common ancestor.
4775 gtk_widget_common_ancestor (GtkWidget *widget_a,
4776 GtkWidget *widget_b)
4778 GtkWidget *parent_a;
4779 GtkWidget *parent_b;
4783 parent_a = widget_a;
4784 while (parent_a->priv->parent)
4786 parent_a = parent_a->priv->parent;
4790 parent_b = widget_b;
4791 while (parent_b->priv->parent)
4793 parent_b = parent_b->priv->parent;
4797 if (parent_a != parent_b)
4800 while (depth_a > depth_b)
4802 widget_a = widget_a->priv->parent;
4806 while (depth_b > depth_a)
4808 widget_b = widget_b->priv->parent;
4812 while (widget_a != widget_b)
4814 widget_a = widget_a->priv->parent;
4815 widget_b = widget_b->priv->parent;
4822 * gtk_widget_translate_coordinates:
4823 * @src_widget: a #GtkWidget
4824 * @dest_widget: a #GtkWidget
4825 * @src_x: X position relative to @src_widget
4826 * @src_y: Y position relative to @src_widget
4827 * @dest_x: (out): location to store X position relative to @dest_widget
4828 * @dest_y: (out): location to store Y position relative to @dest_widget
4830 * Translate coordinates relative to @src_widget's allocation to coordinates
4831 * relative to @dest_widget's allocations. In order to perform this
4832 * operation, both widgets must be realized, and must share a common
4835 * Return value: %FALSE if either widget was not realized, or there
4836 * was no common ancestor. In this case, nothing is stored in
4837 * *@dest_x and *@dest_y. Otherwise %TRUE.
4840 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4841 GtkWidget *dest_widget,
4847 GtkWidgetPrivate *src_priv = src_widget->priv;
4848 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4849 GtkWidget *ancestor;
4851 GList *dest_list = NULL;
4853 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4854 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4856 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4857 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4860 /* Translate from allocation relative to window relative */
4861 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4864 gdk_window_get_position (src_priv->window, &wx, &wy);
4866 src_x -= wx - src_priv->allocation.x;
4867 src_y -= wy - src_priv->allocation.y;
4871 src_x += src_priv->allocation.x;
4872 src_y += src_priv->allocation.y;
4875 /* Translate to the common ancestor */
4876 window = src_priv->window;
4877 while (window != ancestor->priv->window)
4881 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4886 window = gdk_window_get_effective_parent (window);
4888 if (!window) /* Handle GtkHandleBox */
4893 window = dest_priv->window;
4894 while (window != ancestor->priv->window)
4896 dest_list = g_list_prepend (dest_list, window);
4898 window = gdk_window_get_effective_parent (window);
4900 if (!window) /* Handle GtkHandleBox */
4902 g_list_free (dest_list);
4911 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4916 dest_list = g_list_remove (dest_list, dest_list->data);
4919 /* Translate from window relative to allocation relative */
4920 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4923 gdk_window_get_position (dest_priv->window, &wx, &wy);
4925 src_x += wx - dest_priv->allocation.x;
4926 src_y += wy - dest_priv->allocation.y;
4930 src_x -= dest_priv->allocation.x;
4931 src_y -= dest_priv->allocation.y;
4943 gtk_widget_real_size_allocate (GtkWidget *widget,
4944 GtkAllocation *allocation)
4946 GtkWidgetPrivate *priv = widget->priv;
4948 priv->allocation = *allocation;
4950 if (gtk_widget_get_realized (widget) &&
4951 gtk_widget_get_has_window (widget))
4953 gdk_window_move_resize (priv->window,
4954 allocation->x, allocation->y,
4955 allocation->width, allocation->height);
4960 adjust_for_align(GtkAlign align,
4962 gint *allocated_pos,
4963 gint *allocated_size)
4967 case GTK_ALIGN_FILL:
4968 /* change nothing */
4970 case GTK_ALIGN_START:
4971 /* keep *allocated_pos where it is */
4972 *allocated_size = MIN (*allocated_size, *natural_size);
4975 if (*allocated_size > *natural_size)
4977 *allocated_pos += (*allocated_size - *natural_size);
4978 *allocated_size = *natural_size;
4981 case GTK_ALIGN_CENTER:
4982 if (*allocated_size > *natural_size)
4984 *allocated_pos += (*allocated_size - *natural_size) / 2;
4985 *allocated_size = MIN (*allocated_size, *natural_size);
4992 adjust_for_margin(gint start_margin,
4995 gint *allocated_pos,
4996 gint *allocated_size)
4998 *natural_size -= (start_margin + end_margin);
4999 *allocated_pos += start_margin;
5000 *allocated_size -= (start_margin + end_margin);
5004 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5005 GtkOrientation orientation,
5007 gint *allocated_pos,
5008 gint *allocated_size)
5010 const GtkWidgetAuxInfo *aux_info;
5012 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5014 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5016 adjust_for_margin (aux_info->margin.left,
5017 aux_info->margin.right,
5018 natural_size, allocated_pos, allocated_size);
5019 adjust_for_align (aux_info->halign,
5020 natural_size, allocated_pos, allocated_size);
5024 adjust_for_margin (aux_info->margin.top,
5025 aux_info->margin.bottom,
5026 natural_size, allocated_pos, allocated_size);
5027 adjust_for_align (aux_info->valign,
5028 natural_size, allocated_pos, allocated_size);
5033 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5036 GtkWidgetPrivate *priv = widget->priv;
5038 /* widgets must be onscreen for accels to take effect */
5039 return gtk_widget_is_sensitive (widget) &&
5040 gtk_widget_is_drawable (widget) &&
5041 gdk_window_is_viewable (priv->window);
5045 * gtk_widget_can_activate_accel:
5046 * @widget: a #GtkWidget
5047 * @signal_id: the ID of a signal installed on @widget
5049 * Determines whether an accelerator that activates the signal
5050 * identified by @signal_id can currently be activated.
5051 * This is done by emitting the #GtkWidget::can-activate-accel
5052 * signal on @widget; if the signal isn't overridden by a
5053 * handler or in a derived widget, then the default check is
5054 * that the widget must be sensitive, and the widget and all
5055 * its ancestors mapped.
5057 * Return value: %TRUE if the accelerator can be activated.
5062 gtk_widget_can_activate_accel (GtkWidget *widget,
5065 gboolean can_activate = FALSE;
5066 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5067 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5068 return can_activate;
5077 closure_accel_activate (GClosure *closure,
5078 GValue *return_value,
5079 guint n_param_values,
5080 const GValue *param_values,
5081 gpointer invocation_hint,
5082 gpointer marshal_data)
5084 AccelClosure *aclosure = (AccelClosure*) closure;
5085 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5088 g_signal_emit (closure->data, aclosure->signal_id, 0);
5090 /* whether accelerator was handled */
5091 g_value_set_boolean (return_value, can_activate);
5095 closures_destroy (gpointer data)
5097 GSList *slist, *closures = data;
5099 for (slist = closures; slist; slist = slist->next)
5101 g_closure_invalidate (slist->data);
5102 g_closure_unref (slist->data);
5104 g_slist_free (closures);
5108 widget_new_accel_closure (GtkWidget *widget,
5111 AccelClosure *aclosure;
5112 GClosure *closure = NULL;
5113 GSList *slist, *closures;
5115 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5116 for (slist = closures; slist; slist = slist->next)
5117 if (!gtk_accel_group_from_accel_closure (slist->data))
5119 /* reuse this closure */
5120 closure = slist->data;
5125 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5126 closures = g_slist_prepend (closures, g_closure_ref (closure));
5127 g_closure_sink (closure);
5128 g_closure_set_marshal (closure, closure_accel_activate);
5130 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5132 aclosure = (AccelClosure*) closure;
5133 g_assert (closure->data == widget);
5134 g_assert (closure->marshal == closure_accel_activate);
5135 aclosure->signal_id = signal_id;
5141 * gtk_widget_add_accelerator
5142 * @widget: widget to install an accelerator on
5143 * @accel_signal: widget signal to emit on accelerator activation
5144 * @accel_group: accel group for this widget, added to its toplevel
5145 * @accel_key: GDK keyval of the accelerator
5146 * @accel_mods: modifier key combination of the accelerator
5147 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5149 * Installs an accelerator for this @widget in @accel_group that causes
5150 * @accel_signal to be emitted if the accelerator is activated.
5151 * The @accel_group needs to be added to the widget's toplevel via
5152 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5153 * Accelerators added through this function are not user changeable during
5154 * runtime. If you want to support accelerators that can be changed by the
5155 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5156 * gtk_menu_item_set_accel_path() instead.
5159 gtk_widget_add_accelerator (GtkWidget *widget,
5160 const gchar *accel_signal,
5161 GtkAccelGroup *accel_group,
5163 GdkModifierType accel_mods,
5164 GtkAccelFlags accel_flags)
5169 g_return_if_fail (GTK_IS_WIDGET (widget));
5170 g_return_if_fail (accel_signal != NULL);
5171 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5173 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5174 if (!query.signal_id ||
5175 !(query.signal_flags & G_SIGNAL_ACTION) ||
5176 query.return_type != G_TYPE_NONE ||
5179 /* hmm, should be elaborate enough */
5180 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5181 G_OBJECT_TYPE_NAME (widget), accel_signal);
5185 closure = widget_new_accel_closure (widget, query.signal_id);
5187 g_object_ref (widget);
5189 /* install the accelerator. since we don't map this onto an accel_path,
5190 * the accelerator will automatically be locked.
5192 gtk_accel_group_connect (accel_group,
5195 accel_flags | GTK_ACCEL_LOCKED,
5198 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5200 g_object_unref (widget);
5204 * gtk_widget_remove_accelerator:
5205 * @widget: widget to install an accelerator on
5206 * @accel_group: accel group for this widget
5207 * @accel_key: GDK keyval of the accelerator
5208 * @accel_mods: modifier key combination of the accelerator
5209 * @returns: whether an accelerator was installed and could be removed
5211 * Removes an accelerator from @widget, previously installed with
5212 * gtk_widget_add_accelerator().
5215 gtk_widget_remove_accelerator (GtkWidget *widget,
5216 GtkAccelGroup *accel_group,
5218 GdkModifierType accel_mods)
5220 GtkAccelGroupEntry *ag_entry;
5221 GList *slist, *clist;
5224 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5225 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5227 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5228 clist = gtk_widget_list_accel_closures (widget);
5229 for (slist = clist; slist; slist = slist->next)
5233 for (i = 0; i < n; i++)
5234 if (slist->data == (gpointer) ag_entry[i].closure)
5236 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5238 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5240 g_list_free (clist);
5245 g_list_free (clist);
5247 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5248 accel_key, accel_mods, accel_group,
5249 G_OBJECT_TYPE_NAME (widget), widget);
5255 * gtk_widget_list_accel_closures:
5256 * @widget: widget to list accelerator closures for
5258 * Lists the closures used by @widget for accelerator group connections
5259 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5260 * The closures can be used to monitor accelerator changes on @widget,
5261 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5262 * #GtkAccelGroup of a closure which can be found out with
5263 * gtk_accel_group_from_accel_closure().
5265 * Return value: (transfer container) (element-type GClosure):
5266 * a newly allocated #GList of closures
5269 gtk_widget_list_accel_closures (GtkWidget *widget)
5272 GList *clist = NULL;
5274 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5276 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5277 if (gtk_accel_group_from_accel_closure (slist->data))
5278 clist = g_list_prepend (clist, slist->data);
5284 GtkAccelGroup *accel_group;
5289 destroy_accel_path (gpointer data)
5291 AccelPath *apath = data;
5293 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5295 /* closures_destroy takes care of unrefing the closure */
5296 g_object_unref (apath->accel_group);
5298 g_slice_free (AccelPath, apath);
5303 * gtk_widget_set_accel_path:
5304 * @widget: a #GtkWidget
5305 * @accel_path: (allow-none): path used to look up the accelerator
5306 * @accel_group: (allow-none): a #GtkAccelGroup.
5308 * Given an accelerator group, @accel_group, and an accelerator path,
5309 * @accel_path, sets up an accelerator in @accel_group so whenever the
5310 * key binding that is defined for @accel_path is pressed, @widget
5311 * will be activated. This removes any accelerators (for any
5312 * accelerator group) installed by previous calls to
5313 * gtk_widget_set_accel_path(). Associating accelerators with
5314 * paths allows them to be modified by the user and the modifications
5315 * to be saved for future use. (See gtk_accel_map_save().)
5317 * This function is a low level function that would most likely
5318 * be used by a menu creation system like #GtkUIManager. If you
5319 * use #GtkUIManager, setting up accelerator paths will be done
5322 * Even when you you aren't using #GtkUIManager, if you only want to
5323 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5324 * provides a somewhat more convenient interface.
5326 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5327 * pass a static string, you can save some memory by interning it first with
5328 * g_intern_static_string().
5331 gtk_widget_set_accel_path (GtkWidget *widget,
5332 const gchar *accel_path,
5333 GtkAccelGroup *accel_group)
5337 g_return_if_fail (GTK_IS_WIDGET (widget));
5338 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5342 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5343 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5345 gtk_accel_map_add_entry (accel_path, 0, 0);
5346 apath = g_slice_new (AccelPath);
5347 apath->accel_group = g_object_ref (accel_group);
5348 apath->path_quark = g_quark_from_string (accel_path);
5349 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5354 /* also removes possible old settings */
5355 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5358 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5360 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5364 _gtk_widget_get_accel_path (GtkWidget *widget,
5369 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5371 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5373 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5374 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5378 * gtk_widget_mnemonic_activate:
5379 * @widget: a #GtkWidget
5380 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5382 * Emits the #GtkWidget::mnemonic-activate signal.
5384 * The default handler for this signal activates the @widget if
5385 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5388 * Returns: %TRUE if the signal has been handled
5391 gtk_widget_mnemonic_activate (GtkWidget *widget,
5392 gboolean group_cycling)
5396 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5398 group_cycling = group_cycling != FALSE;
5399 if (!gtk_widget_is_sensitive (widget))
5402 g_signal_emit (widget,
5403 widget_signals[MNEMONIC_ACTIVATE],
5411 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5412 gboolean group_cycling)
5414 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5415 gtk_widget_activate (widget);
5416 else if (gtk_widget_get_can_focus (widget))
5417 gtk_widget_grab_focus (widget);
5420 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5421 G_OBJECT_TYPE_NAME (widget));
5422 gtk_widget_error_bell (widget);
5427 static const cairo_user_data_key_t event_key;
5430 _gtk_cairo_get_event (cairo_t *cr)
5432 g_return_val_if_fail (cr != NULL, NULL);
5434 return cairo_get_user_data (cr, &event_key);
5438 gtk_cairo_set_event (cairo_t *cr,
5439 GdkEventExpose *event)
5441 cairo_set_user_data (cr, &event_key, event, NULL);
5445 * gtk_cairo_should_draw_window:
5446 * @cr: a cairo context
5447 * @window: the window to check
5449 * This function is supposed to be called in #GtkWidget::draw
5450 * implementations for widgets that support multiple windows.
5451 * @cr must be untransformed from invoking of the draw function.
5452 * This function will return %TRUE if the contents of the given
5453 * @window are supposed to be drawn and %FALSE otherwise. Note
5454 * that when the drawing was not initiated by the windowing
5455 * system this function will return %TRUE for all windows, so
5456 * you need to draw the bottommost window first. Also, do not
5457 * use "else if" statements to check which window should be drawn.
5459 * Returns: %TRUE if @window should be drawn
5462 gtk_cairo_should_draw_window (cairo_t *cr,
5465 GdkEventExpose *event;
5467 g_return_val_if_fail (cr != NULL, FALSE);
5468 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5470 event = _gtk_cairo_get_event (cr);
5472 return event == NULL ||
5473 event->window == window;
5476 /* code shared by gtk_container_propagate_draw() and
5480 _gtk_widget_draw_internal (GtkWidget *widget,
5482 gboolean clip_to_size)
5484 if (!gtk_widget_is_drawable (widget))
5489 cairo_rectangle (cr,
5491 widget->priv->allocation.width,
5492 widget->priv->allocation.height);
5496 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5500 g_signal_emit (widget, widget_signals[DRAW],
5508 * @widget: the widget to draw. It must be drawable (see
5509 * gtk_widget_is_drawable()) and a size must have been allocated.
5510 * @cr: a cairo context to draw to
5512 * Draws @widget to @cr. The top left corner of the widget will be
5513 * drawn to the currently set origin point of @cr.
5515 * You should pass a cairo context as @cr argument that is in an
5516 * original state. Otherwise the resulting drawing is undefined. For
5517 * example changing the operator using cairo_set_operator() or the
5518 * line width using cairo_set_line_width() might have unwanted side
5520 * You may however change the context's transform matrix - like with
5521 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5522 * region with cairo_clip() prior to calling this function. Also, it
5523 * is fine to modify the context with cairo_save() and
5524 * cairo_push_group() prior to calling this function.
5526 * <note><para>Special purpose widgets may contain special code for
5527 * rendering to the screen and might appear differently on screen
5528 * and when rendered using gtk_widget_draw().</para></note>
5531 gtk_widget_draw (GtkWidget *widget,
5534 GdkEventExpose *tmp_event;
5536 g_return_if_fail (GTK_IS_WIDGET (widget));
5537 g_return_if_fail (!widget->priv->alloc_needed);
5538 g_return_if_fail (cr != NULL);
5541 /* We have to reset the event here so that draw functions can call
5542 * gtk_widget_draw() on random other widgets and get the desired
5543 * effect: Drawing all contents, not just the current window.
5545 tmp_event = _gtk_cairo_get_event (cr);
5546 gtk_cairo_set_event (cr, NULL);
5548 _gtk_widget_draw_internal (widget, cr, TRUE);
5550 gtk_cairo_set_event (cr, tmp_event);
5555 gtk_widget_real_key_press_event (GtkWidget *widget,
5558 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5562 gtk_widget_real_key_release_event (GtkWidget *widget,
5565 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5569 gtk_widget_real_focus_in_event (GtkWidget *widget,
5570 GdkEventFocus *event)
5572 gtk_widget_queue_shallow_draw (widget);
5578 gtk_widget_real_focus_out_event (GtkWidget *widget,
5579 GdkEventFocus *event)
5581 gtk_widget_queue_shallow_draw (widget);
5586 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5587 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5591 * @widget: a #GtkWidget
5592 * @event: a #GdkEvent
5594 * Rarely-used function. This function is used to emit
5595 * the event signals on a widget (those signals should never
5596 * be emitted without using this function to do so).
5597 * If you want to synthesize an event though, don't use this function;
5598 * instead, use gtk_main_do_event() so the event will behave as if
5599 * it were in the event queue. Don't synthesize expose events; instead,
5600 * use gdk_window_invalidate_rect() to invalidate a region of the
5603 * Return value: return from the event signal emission (%TRUE if
5604 * the event was handled)
5607 gtk_widget_event (GtkWidget *widget,
5610 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5611 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5613 if (event->type == GDK_EXPOSE)
5615 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5616 "the same effect, call gdk_window_invalidate_rect/region(), "
5617 "followed by gdk_window_process_updates().");
5621 return gtk_widget_event_internal (widget, event);
5624 /* Returns TRUE if a translation should be done */
5626 gtk_widget_get_translation_to_window (GtkWidget *widget,
5631 GdkWindow *w, *widget_window;
5633 if (!gtk_widget_get_has_window (widget))
5635 *x = -widget->priv->allocation.x;
5636 *y = -widget->priv->allocation.y;
5644 widget_window = gtk_widget_get_window (widget);
5646 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5649 gdk_window_get_position (w, &wx, &wy);
5666 * gtk_cairo_transform_to_window:
5667 * @cr: the cairo context to transform
5668 * @widget: the widget the context is currently centered for
5669 * @window: the window to transform the context to
5671 * Transforms the given cairo context @cr that from @widget-relative
5672 * coordinates to @window-relative coordinates.
5673 * If the @widget's window is not an ancestor of @window, no
5674 * modification will be applied.
5676 * This is the inverse to the transformation GTK applies when
5677 * preparing an expose event to be emitted with the #GtkWidget::draw
5678 * signal. It is intended to help porting multiwindow widgets from
5679 * GTK+ 2 to the rendering architecture of GTK+ 3.
5682 gtk_cairo_transform_to_window (cairo_t *cr,
5688 g_return_if_fail (cr != NULL);
5689 g_return_if_fail (GTK_IS_WIDGET (widget));
5690 g_return_if_fail (GDK_IS_WINDOW (window));
5692 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5693 cairo_translate (cr, x, y);
5697 * gtk_widget_send_expose:
5698 * @widget: a #GtkWidget
5699 * @event: a expose #GdkEvent
5701 * Very rarely-used function. This function is used to emit
5702 * an expose event on a widget. This function is not normally used
5703 * directly. The only time it is used is when propagating an expose
5704 * event to a child %NO_WINDOW widget, and that is normally done
5705 * using gtk_container_propagate_draw().
5707 * If you want to force an area of a window to be redrawn,
5708 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5709 * To cause the redraw to be done immediately, follow that call
5710 * with a call to gdk_window_process_updates().
5712 * Return value: return from the event signal emission (%TRUE if
5713 * the event was handled)
5716 gtk_widget_send_expose (GtkWidget *widget,
5719 gboolean result = FALSE;
5724 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5725 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5726 g_return_val_if_fail (event != NULL, TRUE);
5727 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5729 cr = gdk_cairo_create (event->expose.window);
5730 gtk_cairo_set_event (cr, &event->expose);
5732 gdk_cairo_region (cr, event->expose.region);
5735 do_clip = gtk_widget_get_translation_to_window (widget,
5736 event->expose.window,
5738 cairo_translate (cr, -x, -y);
5740 _gtk_widget_draw_internal (widget, cr, do_clip);
5742 /* unset here, so if someone keeps a reference to cr we
5743 * don't leak the window. */
5744 gtk_cairo_set_event (cr, NULL);
5751 event_window_is_still_viewable (GdkEvent *event)
5753 /* Check that we think the event's window is viewable before
5754 * delivering the event, to prevent suprises. We do this here
5755 * at the last moment, since the event may have been queued
5756 * up behind other events, held over a recursive main loop, etc.
5758 switch (event->type)
5761 case GDK_MOTION_NOTIFY:
5762 case GDK_BUTTON_PRESS:
5763 case GDK_2BUTTON_PRESS:
5764 case GDK_3BUTTON_PRESS:
5766 case GDK_ENTER_NOTIFY:
5767 case GDK_PROXIMITY_IN:
5769 return event->any.window && gdk_window_is_viewable (event->any.window);
5772 /* The following events are the second half of paired events;
5773 * we always deliver them to deal with widgets that clean up
5774 * on the second half.
5776 case GDK_BUTTON_RELEASE:
5777 case GDK_KEY_RELEASE:
5778 case GDK_LEAVE_NOTIFY:
5779 case GDK_PROXIMITY_OUT:
5783 /* Remaining events would make sense on an not-viewable window,
5784 * or don't have an associated window.
5791 gtk_widget_event_internal (GtkWidget *widget,
5794 gboolean return_val = FALSE;
5796 /* We check only once for is-still-visible; if someone
5797 * hides the window in on of the signals on the widget,
5798 * they are responsible for returning TRUE to terminate
5801 if (!event_window_is_still_viewable (event))
5804 g_object_ref (widget);
5806 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5807 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5812 switch (event->type)
5817 case GDK_BUTTON_PRESS:
5818 case GDK_2BUTTON_PRESS:
5819 case GDK_3BUTTON_PRESS:
5820 signal_num = BUTTON_PRESS_EVENT;
5823 signal_num = SCROLL_EVENT;
5825 case GDK_BUTTON_RELEASE:
5826 signal_num = BUTTON_RELEASE_EVENT;
5828 case GDK_MOTION_NOTIFY:
5829 signal_num = MOTION_NOTIFY_EVENT;
5832 signal_num = DELETE_EVENT;
5835 signal_num = DESTROY_EVENT;
5836 _gtk_tooltip_hide (widget);
5839 signal_num = KEY_PRESS_EVENT;
5841 case GDK_KEY_RELEASE:
5842 signal_num = KEY_RELEASE_EVENT;
5844 case GDK_ENTER_NOTIFY:
5845 signal_num = ENTER_NOTIFY_EVENT;
5847 case GDK_LEAVE_NOTIFY:
5848 signal_num = LEAVE_NOTIFY_EVENT;
5850 case GDK_FOCUS_CHANGE:
5851 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5852 if (event->focus_change.in)
5853 _gtk_tooltip_focus_in (widget);
5855 _gtk_tooltip_focus_out (widget);
5858 signal_num = CONFIGURE_EVENT;
5861 signal_num = MAP_EVENT;
5864 signal_num = UNMAP_EVENT;
5866 case GDK_WINDOW_STATE:
5867 signal_num = WINDOW_STATE_EVENT;
5869 case GDK_PROPERTY_NOTIFY:
5870 signal_num = PROPERTY_NOTIFY_EVENT;
5872 case GDK_SELECTION_CLEAR:
5873 signal_num = SELECTION_CLEAR_EVENT;
5875 case GDK_SELECTION_REQUEST:
5876 signal_num = SELECTION_REQUEST_EVENT;
5878 case GDK_SELECTION_NOTIFY:
5879 signal_num = SELECTION_NOTIFY_EVENT;
5881 case GDK_PROXIMITY_IN:
5882 signal_num = PROXIMITY_IN_EVENT;
5884 case GDK_PROXIMITY_OUT:
5885 signal_num = PROXIMITY_OUT_EVENT;
5888 signal_num = NO_EXPOSE_EVENT;
5890 case GDK_CLIENT_EVENT:
5891 signal_num = CLIENT_EVENT;
5894 signal_num = EXPOSE_EVENT;
5896 case GDK_VISIBILITY_NOTIFY:
5897 signal_num = VISIBILITY_NOTIFY_EVENT;
5899 case GDK_GRAB_BROKEN:
5900 signal_num = GRAB_BROKEN_EVENT;
5903 signal_num = DAMAGE_EVENT;
5906 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5910 if (signal_num != -1)
5911 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5913 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5914 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5918 g_object_unref (widget);
5924 * gtk_widget_activate:
5925 * @widget: a #GtkWidget that's activatable
5927 * For widgets that can be "activated" (buttons, menu items, etc.)
5928 * this function activates them. Activation is what happens when you
5929 * press Enter on a widget during key navigation. If @widget isn't
5930 * activatable, the function returns %FALSE.
5932 * Return value: %TRUE if the widget was activatable
5935 gtk_widget_activate (GtkWidget *widget)
5937 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5939 if (WIDGET_CLASS (widget)->activate_signal)
5941 /* FIXME: we should eventually check the signals signature here */
5942 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5951 gtk_widget_reparent_subwindows (GtkWidget *widget,
5952 GdkWindow *new_window)
5954 GtkWidgetPrivate *priv = widget->priv;
5956 if (!gtk_widget_get_has_window (widget))
5958 GList *children = gdk_window_get_children (priv->window);
5961 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5963 GdkWindow *window = tmp_list->data;
5966 gdk_window_get_user_data (window, &child);
5967 while (child && child != widget)
5968 child = ((GtkWidget*) child)->priv->parent;
5971 gdk_window_reparent (window, new_window, 0, 0);
5974 g_list_free (children);
5979 GList *tmp_list, *children;
5981 parent = gdk_window_get_parent (priv->window);
5984 gdk_window_reparent (priv->window, new_window, 0, 0);
5987 children = gdk_window_get_children (parent);
5989 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5991 GdkWindow *window = tmp_list->data;
5994 gdk_window_get_user_data (window, &child);
5996 if (child == widget)
5997 gdk_window_reparent (window, new_window, 0, 0);
6000 g_list_free (children);
6006 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6007 gpointer client_data)
6009 GtkWidgetPrivate *priv = widget->priv;
6011 g_assert (client_data != NULL);
6013 if (!gtk_widget_get_has_window (widget))
6016 g_object_unref (priv->window);
6017 priv->window = (GdkWindow*) client_data;
6019 g_object_ref (priv->window);
6021 if (GTK_IS_CONTAINER (widget))
6022 gtk_container_forall (GTK_CONTAINER (widget),
6023 gtk_widget_reparent_fixup_child,
6029 * gtk_widget_reparent:
6030 * @widget: a #GtkWidget
6031 * @new_parent: a #GtkContainer to move the widget into
6033 * Moves a widget from one #GtkContainer to another, handling reference
6034 * count issues to avoid destroying the widget.
6037 gtk_widget_reparent (GtkWidget *widget,
6038 GtkWidget *new_parent)
6040 GtkWidgetPrivate *priv;
6042 g_return_if_fail (GTK_IS_WIDGET (widget));
6043 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6044 priv = widget->priv;
6045 g_return_if_fail (priv->parent != NULL);
6047 if (priv->parent != new_parent)
6049 /* First try to see if we can get away without unrealizing
6050 * the widget as we reparent it. if so we set a flag so
6051 * that gtk_widget_unparent doesn't unrealize widget
6053 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6054 priv->in_reparent = TRUE;
6056 g_object_ref (widget);
6057 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6058 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6059 g_object_unref (widget);
6061 if (priv->in_reparent)
6063 priv->in_reparent = FALSE;
6065 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6066 gtk_widget_reparent_fixup_child (widget,
6067 gtk_widget_get_parent_window (widget));
6070 g_object_notify (G_OBJECT (widget), "parent");
6075 * gtk_widget_intersect:
6076 * @widget: a #GtkWidget
6077 * @area: a rectangle
6078 * @intersection: rectangle to store intersection of @widget and @area
6080 * Computes the intersection of a @widget's area and @area, storing
6081 * the intersection in @intersection, and returns %TRUE if there was
6082 * an intersection. @intersection may be %NULL if you're only
6083 * interested in whether there was an intersection.
6085 * Return value: %TRUE if there was an intersection
6088 gtk_widget_intersect (GtkWidget *widget,
6089 const GdkRectangle *area,
6090 GdkRectangle *intersection)
6092 GtkWidgetPrivate *priv;
6097 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6098 g_return_val_if_fail (area != NULL, FALSE);
6100 priv = widget->priv;
6103 dest = intersection;
6107 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6109 if (return_val && intersection && gtk_widget_get_has_window (widget))
6111 intersection->x -= priv->allocation.x;
6112 intersection->y -= priv->allocation.y;
6119 * gtk_widget_region_intersect:
6120 * @widget: a #GtkWidget
6121 * @region: a #cairo_region_t, in the same coordinate system as
6122 * @widget->allocation. That is, relative to @widget->window
6123 * for %NO_WINDOW widgets; relative to the parent window
6124 * of @widget->window for widgets with their own window.
6125 * @returns: A newly allocated region holding the intersection of @widget
6126 * and @region. The coordinates of the return value are
6127 * relative to @widget->window for %NO_WINDOW widgets, and
6128 * relative to the parent window of @widget->window for
6129 * widgets with their own window.
6131 * Computes the intersection of a @widget's area and @region, returning
6132 * the intersection. The result may be empty, use cairo_region_is_empty() to
6136 gtk_widget_region_intersect (GtkWidget *widget,
6137 const cairo_region_t *region)
6140 cairo_region_t *dest;
6142 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6143 g_return_val_if_fail (region != NULL, NULL);
6145 gtk_widget_get_allocation (widget, &rect);
6147 dest = cairo_region_create_rectangle (&rect);
6149 cairo_region_intersect (dest, region);
6155 * _gtk_widget_grab_notify:
6156 * @widget: a #GtkWidget
6157 * @was_grabbed: whether a grab is now in effect
6159 * Emits the #GtkWidget::grab-notify signal on @widget.
6164 _gtk_widget_grab_notify (GtkWidget *widget,
6165 gboolean was_grabbed)
6167 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6171 * gtk_widget_grab_focus:
6172 * @widget: a #GtkWidget
6174 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6175 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6176 * something like #GtkFrame won't work.
6178 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6179 * gtk_widget_set_can_focus() to modify that flag.
6181 * The widget also needs to be realized and mapped. This is indicated by the
6182 * related signals. Grabbing the focus immediately after creating the widget
6183 * will likely fail and cause critical warnings.
6186 gtk_widget_grab_focus (GtkWidget *widget)
6188 g_return_if_fail (GTK_IS_WIDGET (widget));
6190 if (!gtk_widget_is_sensitive (widget))
6193 g_object_ref (widget);
6194 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6195 g_object_notify (G_OBJECT (widget), "has-focus");
6196 g_object_unref (widget);
6200 reset_focus_recurse (GtkWidget *widget,
6203 if (GTK_IS_CONTAINER (widget))
6205 GtkContainer *container;
6207 container = GTK_CONTAINER (widget);
6208 gtk_container_set_focus_child (container, NULL);
6210 gtk_container_foreach (container,
6211 reset_focus_recurse,
6217 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6219 if (gtk_widget_get_can_focus (focus_widget))
6221 GtkWidget *toplevel;
6224 /* clear the current focus setting, break if the current widget
6225 * is the focus widget's parent, since containers above that will
6226 * be set by the next loop.
6228 toplevel = gtk_widget_get_toplevel (focus_widget);
6229 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6231 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6233 if (widget == focus_widget)
6235 /* We call _gtk_window_internal_set_focus() here so that the
6236 * toplevel window can request the focus if necessary.
6237 * This is needed when the toplevel is a GtkPlug
6239 if (!gtk_widget_has_focus (widget))
6240 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6247 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6249 widget = widget->priv->parent;
6250 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6254 else if (toplevel != focus_widget)
6256 /* gtk_widget_grab_focus() operates on a tree without window...
6257 * actually, this is very questionable behaviour.
6260 gtk_container_foreach (GTK_CONTAINER (toplevel),
6261 reset_focus_recurse,
6265 /* now propagate the new focus up the widget tree and finally
6266 * set it on the window
6268 widget = focus_widget;
6269 while (widget->priv->parent)
6271 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6272 widget = widget->priv->parent;
6274 if (GTK_IS_WINDOW (widget))
6275 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6280 gtk_widget_real_query_tooltip (GtkWidget *widget,
6283 gboolean keyboard_tip,
6284 GtkTooltip *tooltip)
6286 gchar *tooltip_markup;
6287 gboolean has_tooltip;
6289 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6290 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6292 if (has_tooltip && tooltip_markup)
6294 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6302 gtk_widget_real_show_help (GtkWidget *widget,
6303 GtkWidgetHelpType help_type)
6305 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6307 _gtk_tooltip_toggle_keyboard_mode (widget);
6316 gtk_widget_real_focus (GtkWidget *widget,
6317 GtkDirectionType direction)
6319 if (!gtk_widget_get_can_focus (widget))
6322 if (!gtk_widget_is_focus (widget))
6324 gtk_widget_grab_focus (widget);
6332 gtk_widget_real_move_focus (GtkWidget *widget,
6333 GtkDirectionType direction)
6335 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6337 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6339 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6345 gtk_widget_real_keynav_failed (GtkWidget *widget,
6346 GtkDirectionType direction)
6348 gboolean cursor_only;
6352 case GTK_DIR_TAB_FORWARD:
6353 case GTK_DIR_TAB_BACKWARD:
6360 g_object_get (gtk_widget_get_settings (widget),
6361 "gtk-keynav-cursor-only", &cursor_only,
6368 gtk_widget_error_bell (widget);
6374 * gtk_widget_set_can_focus:
6375 * @widget: a #GtkWidget
6376 * @can_focus: whether or not @widget can own the input focus.
6378 * Specifies whether @widget can own the input focus. See
6379 * gtk_widget_grab_focus() for actually setting the input focus on a
6385 gtk_widget_set_can_focus (GtkWidget *widget,
6388 g_return_if_fail (GTK_IS_WIDGET (widget));
6390 if (widget->priv->can_focus != can_focus)
6392 widget->priv->can_focus = can_focus;
6394 gtk_widget_queue_resize (widget);
6395 g_object_notify (G_OBJECT (widget), "can-focus");
6400 * gtk_widget_get_can_focus:
6401 * @widget: a #GtkWidget
6403 * Determines whether @widget can own the input focus. See
6404 * gtk_widget_set_can_focus().
6406 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6411 gtk_widget_get_can_focus (GtkWidget *widget)
6413 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6415 return widget->priv->can_focus;
6419 * gtk_widget_has_focus:
6420 * @widget: a #GtkWidget
6422 * Determines if the widget has the global input focus. See
6423 * gtk_widget_is_focus() for the difference between having the global
6424 * input focus, and only having the focus within a toplevel.
6426 * Return value: %TRUE if the widget has the global input focus.
6431 gtk_widget_has_focus (GtkWidget *widget)
6433 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6435 return widget->priv->has_focus;
6439 * gtk_widget_is_focus:
6440 * @widget: a #GtkWidget
6442 * Determines if the widget is the focus widget within its
6443 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6444 * necessarily set; %HAS_FOCUS will only be set if the
6445 * toplevel widget additionally has the global input focus.)
6447 * Return value: %TRUE if the widget is the focus widget.
6450 gtk_widget_is_focus (GtkWidget *widget)
6452 GtkWidget *toplevel;
6454 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6456 toplevel = gtk_widget_get_toplevel (widget);
6458 if (GTK_IS_WINDOW (toplevel))
6459 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6465 * gtk_widget_set_can_default:
6466 * @widget: a #GtkWidget
6467 * @can_default: whether or not @widget can be a default widget.
6469 * Specifies whether @widget can be a default widget. See
6470 * gtk_widget_grab_default() for details about the meaning of
6476 gtk_widget_set_can_default (GtkWidget *widget,
6477 gboolean can_default)
6479 g_return_if_fail (GTK_IS_WIDGET (widget));
6481 if (widget->priv->can_default != can_default)
6483 widget->priv->can_default = can_default;
6485 gtk_widget_queue_resize (widget);
6486 g_object_notify (G_OBJECT (widget), "can-default");
6491 * gtk_widget_get_can_default:
6492 * @widget: a #GtkWidget
6494 * Determines whether @widget can be a default widget. See
6495 * gtk_widget_set_can_default().
6497 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6502 gtk_widget_get_can_default (GtkWidget *widget)
6504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6506 return widget->priv->can_default;
6510 * gtk_widget_has_default:
6511 * @widget: a #GtkWidget
6513 * Determines whether @widget is the current default widget within its
6514 * toplevel. See gtk_widget_set_can_default().
6516 * Return value: %TRUE if @widget is the current default widget within
6517 * its toplevel, %FALSE otherwise
6522 gtk_widget_has_default (GtkWidget *widget)
6524 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6526 return widget->priv->has_default;
6530 _gtk_widget_set_has_default (GtkWidget *widget,
6531 gboolean has_default)
6533 widget->priv->has_default = has_default;
6537 * gtk_widget_grab_default:
6538 * @widget: a #GtkWidget
6540 * Causes @widget to become the default widget. @widget must have the
6541 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6542 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6543 * %TRUE)</literal>. The default widget is activated when
6544 * the user presses Enter in a window. Default widgets must be
6545 * activatable, that is, gtk_widget_activate() should affect them. Note
6546 * that #GtkEntry widgets require the "activates-default" property
6547 * set to %TRUE before they activate the default widget when Enter
6548 * is pressed and the #GtkEntry is focused.
6551 gtk_widget_grab_default (GtkWidget *widget)
6555 g_return_if_fail (GTK_IS_WIDGET (widget));
6556 g_return_if_fail (gtk_widget_get_can_default (widget));
6558 window = gtk_widget_get_toplevel (widget);
6560 if (window && gtk_widget_is_toplevel (window))
6561 gtk_window_set_default (GTK_WINDOW (window), widget);
6563 g_warning (G_STRLOC ": widget not within a GtkWindow");
6567 * gtk_widget_set_receives_default:
6568 * @widget: a #GtkWidget
6569 * @receives_default: whether or not @widget can be a default widget.
6571 * Specifies whether @widget will be treated as the default widget
6572 * within its toplevel when it has the focus, even if another widget
6575 * See gtk_widget_grab_default() for details about the meaning of
6581 gtk_widget_set_receives_default (GtkWidget *widget,
6582 gboolean receives_default)
6584 g_return_if_fail (GTK_IS_WIDGET (widget));
6586 if (widget->priv->receives_default != receives_default)
6588 widget->priv->receives_default = receives_default;
6590 g_object_notify (G_OBJECT (widget), "receives-default");
6595 * gtk_widget_get_receives_default:
6596 * @widget: a #GtkWidget
6598 * Determines whether @widget is alyways treated as default widget
6599 * withing its toplevel when it has the focus, even if another widget
6602 * See gtk_widget_set_receives_default().
6604 * Return value: %TRUE if @widget acts as default widget when focussed,
6610 gtk_widget_get_receives_default (GtkWidget *widget)
6612 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6614 return widget->priv->receives_default;
6618 * gtk_widget_has_grab:
6619 * @widget: a #GtkWidget
6621 * Determines whether the widget is currently grabbing events, so it
6622 * is the only widget receiving input events (keyboard and mouse).
6624 * See also gtk_grab_add().
6626 * Return value: %TRUE if the widget is in the grab_widgets stack
6631 gtk_widget_has_grab (GtkWidget *widget)
6633 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6635 return widget->priv->has_grab;
6639 _gtk_widget_set_has_grab (GtkWidget *widget,
6642 widget->priv->has_grab = has_grab;
6646 * gtk_widget_device_is_shadowed:
6647 * @widget: a #GtkWidget
6648 * @device: a #GdkDevice
6650 * Returns %TRUE if @device has been shadowed by a GTK+
6651 * device grab on another widget, so it would stop sending
6652 * events to @widget. This may be used in the
6653 * #GtkWidget::grab-notify signal to check for specific
6654 * devices. See gtk_device_grab_add().
6656 * Returns: %TRUE if there is an ongoing grab on @device
6657 * by another #GtkWidget than @widget.
6662 gtk_widget_device_is_shadowed (GtkWidget *widget,
6665 GtkWindowGroup *group;
6666 GtkWidget *grab_widget, *toplevel;
6668 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6669 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6671 if (!gtk_widget_get_realized (widget))
6674 toplevel = gtk_widget_get_toplevel (widget);
6676 if (GTK_IS_WINDOW (toplevel))
6677 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6679 group = gtk_window_get_group (NULL);
6681 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6683 /* Widget not inside the hierarchy of grab_widget */
6685 widget != grab_widget &&
6686 !gtk_widget_is_ancestor (widget, grab_widget))
6689 grab_widget = gtk_window_group_get_current_grab (group);
6690 if (grab_widget && widget != grab_widget &&
6691 !gtk_widget_is_ancestor (widget, grab_widget))
6698 * gtk_widget_set_name:
6699 * @widget: a #GtkWidget
6700 * @name: name for the widget
6702 * Widgets can be named, which allows you to refer to them from a
6703 * gtkrc file. You can apply a style to widgets with a particular name
6704 * in the gtkrc file. See the documentation for gtkrc files (on the
6705 * same page as the docs for #GtkRcStyle).
6707 * Note that widget names are separated by periods in paths (see
6708 * gtk_widget_path()), so names with embedded periods may cause confusion.
6711 gtk_widget_set_name (GtkWidget *widget,
6714 GtkWidgetPrivate *priv;
6717 g_return_if_fail (GTK_IS_WIDGET (widget));
6719 priv = widget->priv;
6721 new_name = g_strdup (name);
6722 g_free (priv->name);
6723 priv->name = new_name;
6726 gtk_widget_reset_rc_style (widget);
6728 g_object_notify (G_OBJECT (widget), "name");
6732 * gtk_widget_get_name:
6733 * @widget: a #GtkWidget
6735 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6736 * significance of widget names.
6738 * Return value: name of the widget. This string is owned by GTK+ and
6739 * should not be modified or freed
6741 G_CONST_RETURN gchar*
6742 gtk_widget_get_name (GtkWidget *widget)
6744 GtkWidgetPrivate *priv;
6746 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6748 priv = widget->priv;
6752 return G_OBJECT_TYPE_NAME (widget);
6756 * gtk_widget_set_state:
6757 * @widget: a #GtkWidget
6758 * @state: new state for @widget
6760 * This function is for use in widget implementations. Sets the state
6761 * of a widget (insensitive, prelighted, etc.) Usually you should set
6762 * the state using wrapper functions such as gtk_widget_set_sensitive().
6765 gtk_widget_set_state (GtkWidget *widget,
6768 GtkWidgetPrivate *priv;
6770 g_return_if_fail (GTK_IS_WIDGET (widget));
6772 priv = widget->priv;
6774 if (state == gtk_widget_get_state (widget))
6777 if (state == GTK_STATE_INSENSITIVE)
6778 gtk_widget_set_sensitive (widget, FALSE);
6784 data.state_restoration = FALSE;
6785 data.use_forall = FALSE;
6787 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6789 data.parent_sensitive = TRUE;
6791 gtk_widget_propagate_state (widget, &data);
6793 if (gtk_widget_is_drawable (widget))
6794 gtk_widget_queue_draw (widget);
6799 * gtk_widget_get_state:
6800 * @widget: a #GtkWidget
6802 * Returns the widget's state. See gtk_widget_set_state().
6804 * Returns: the state of @widget.
6809 gtk_widget_get_state (GtkWidget *widget)
6811 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6813 return widget->priv->state;
6817 * gtk_widget_set_visible:
6818 * @widget: a #GtkWidget
6819 * @visible: whether the widget should be shown or not
6821 * Sets the visibility state of @widget. Note that setting this to
6822 * %TRUE doesn't mean the widget is actually viewable, see
6823 * gtk_widget_get_visible().
6825 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6826 * but is nicer to use when the visibility of the widget depends on
6832 gtk_widget_set_visible (GtkWidget *widget,
6835 g_return_if_fail (GTK_IS_WIDGET (widget));
6837 if (visible != gtk_widget_get_visible (widget))
6840 gtk_widget_show (widget);
6842 gtk_widget_hide (widget);
6847 _gtk_widget_set_visible_flag (GtkWidget *widget,
6850 widget->priv->visible = visible;
6854 * gtk_widget_get_visible:
6855 * @widget: a #GtkWidget
6857 * Determines whether the widget is visible. Note that this doesn't
6858 * take into account whether the widget's parent is also visible
6859 * or the widget is obscured in any way.
6861 * See gtk_widget_set_visible().
6863 * Return value: %TRUE if the widget is visible
6868 gtk_widget_get_visible (GtkWidget *widget)
6870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6872 return widget->priv->visible;
6876 * gtk_widget_set_has_window:
6877 * @widget: a #GtkWidget
6878 * @has_window: whether or not @widget has a window.
6880 * Specifies whether @widget has a #GdkWindow of its own. Note that
6881 * all realized widgets have a non-%NULL "window" pointer
6882 * (gtk_widget_get_window() never returns a %NULL window when a widget
6883 * is realized), but for many of them it's actually the #GdkWindow of
6884 * one of its parent widgets. Widgets that do not create a %window for
6885 * themselves in #GtkWidget::realize must announce this by
6886 * calling this function with @has_window = %FALSE.
6888 * This function should only be called by widget implementations,
6889 * and they should call it in their init() function.
6894 gtk_widget_set_has_window (GtkWidget *widget,
6895 gboolean has_window)
6897 g_return_if_fail (GTK_IS_WIDGET (widget));
6899 widget->priv->no_window = !has_window;
6903 * gtk_widget_get_has_window:
6904 * @widget: a #GtkWidget
6906 * Determines whether @widget has a #GdkWindow of its own. See
6907 * gtk_widget_set_has_window().
6909 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6914 gtk_widget_get_has_window (GtkWidget *widget)
6916 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6918 return ! widget->priv->no_window;
6922 * gtk_widget_is_toplevel:
6923 * @widget: a #GtkWidget
6925 * Determines whether @widget is a toplevel widget. Currently only
6926 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6927 * widgets have no parent widget.
6929 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6934 gtk_widget_is_toplevel (GtkWidget *widget)
6936 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6938 return widget->priv->toplevel;
6942 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6943 gboolean is_toplevel)
6945 widget->priv->toplevel = is_toplevel;
6949 * gtk_widget_is_drawable:
6950 * @widget: a #GtkWidget
6952 * Determines whether @widget can be drawn to. A widget can be drawn
6953 * to if it is mapped and visible.
6955 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6960 gtk_widget_is_drawable (GtkWidget *widget)
6962 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6964 return (gtk_widget_get_visible (widget) &&
6965 gtk_widget_get_mapped (widget));
6969 * gtk_widget_get_realized:
6970 * @widget: a #GtkWidget
6972 * Determines whether @widget is realized.
6974 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6979 gtk_widget_get_realized (GtkWidget *widget)
6981 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6983 return widget->priv->realized;
6987 * gtk_widget_set_realized:
6988 * @widget: a #GtkWidget
6989 * @realized: %TRUE to mark the widget as realized
6991 * Marks the widget as being realized.
6993 * This function should only ever be called in a derived widget's
6994 * "realize" or "unrealize" implementation.
6999 gtk_widget_set_realized (GtkWidget *widget,
7002 g_return_if_fail (GTK_IS_WIDGET (widget));
7004 widget->priv->realized = realized;
7008 * gtk_widget_get_mapped:
7009 * @widget: a #GtkWidget
7011 * Whether the widget is mapped.
7013 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7018 gtk_widget_get_mapped (GtkWidget *widget)
7020 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7022 return widget->priv->mapped;
7026 * gtk_widget_set_mapped:
7027 * @widget: a #GtkWidget
7028 * @mapped: %TRUE to mark the widget as mapped
7030 * Marks the widget as being realized.
7032 * This function should only ever be called in a derived widget's
7033 * "map" or "unmap" implementation.
7038 gtk_widget_set_mapped (GtkWidget *widget,
7041 g_return_if_fail (GTK_IS_WIDGET (widget));
7043 widget->priv->mapped = mapped;
7047 * gtk_widget_set_app_paintable:
7048 * @widget: a #GtkWidget
7049 * @app_paintable: %TRUE if the application will paint on the widget
7051 * Sets whether the application intends to draw on the widget in
7052 * an #GtkWidget::draw handler.
7054 * This is a hint to the widget and does not affect the behavior of
7055 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7056 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7057 * the effect is to suppress default themed drawing of the widget's
7058 * background. (Children of the widget will still be drawn.) The application
7059 * is then entirely responsible for drawing the widget background.
7061 * Note that the background is still drawn when the widget is mapped.
7064 gtk_widget_set_app_paintable (GtkWidget *widget,
7065 gboolean app_paintable)
7067 g_return_if_fail (GTK_IS_WIDGET (widget));
7069 app_paintable = (app_paintable != FALSE);
7071 if (widget->priv->app_paintable != app_paintable)
7073 widget->priv->app_paintable = app_paintable;
7075 if (gtk_widget_is_drawable (widget))
7076 gtk_widget_queue_draw (widget);
7078 g_object_notify (G_OBJECT (widget), "app-paintable");
7083 * gtk_widget_get_app_paintable:
7084 * @widget: a #GtkWidget
7086 * Determines whether the application intends to draw on the widget in
7087 * an #GtkWidget::draw handler.
7089 * See gtk_widget_set_app_paintable()
7091 * Return value: %TRUE if the widget is app paintable
7096 gtk_widget_get_app_paintable (GtkWidget *widget)
7098 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7100 return widget->priv->app_paintable;
7104 * gtk_widget_set_double_buffered:
7105 * @widget: a #GtkWidget
7106 * @double_buffered: %TRUE to double-buffer a widget
7108 * Widgets are double buffered by default; you can use this function
7109 * to turn off the buffering. "Double buffered" simply means that
7110 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7111 * automatically around expose events sent to the
7112 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7113 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7114 * buffer to the screen. The result is that users see the window
7115 * update in one smooth step, and don't see individual graphics
7116 * primitives being rendered.
7118 * In very simple terms, double buffered widgets don't flicker,
7119 * so you would only use this function to turn off double buffering
7120 * if you had special needs and really knew what you were doing.
7122 * Note: if you turn off double-buffering, you have to handle
7123 * expose events, since even the clearing to the background color or
7124 * pixmap will not happen automatically (as it is done in
7125 * gdk_window_begin_paint()).
7128 gtk_widget_set_double_buffered (GtkWidget *widget,
7129 gboolean double_buffered)
7131 g_return_if_fail (GTK_IS_WIDGET (widget));
7133 double_buffered = (double_buffered != FALSE);
7135 if (widget->priv->double_buffered != double_buffered)
7137 widget->priv->double_buffered = double_buffered;
7139 g_object_notify (G_OBJECT (widget), "double-buffered");
7144 * gtk_widget_get_double_buffered:
7145 * @widget: a #GtkWidget
7147 * Determines whether the widget is double buffered.
7149 * See gtk_widget_set_double_buffered()
7151 * Return value: %TRUE if the widget is double buffered
7156 gtk_widget_get_double_buffered (GtkWidget *widget)
7158 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7160 return widget->priv->double_buffered;
7164 * gtk_widget_set_redraw_on_allocate:
7165 * @widget: a #GtkWidget
7166 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7167 * when it is allocated to a new size. Otherwise, only the
7168 * new portion of the widget will be redrawn.
7170 * Sets whether the entire widget is queued for drawing when its size
7171 * allocation changes. By default, this setting is %TRUE and
7172 * the entire widget is redrawn on every size change. If your widget
7173 * leaves the upper left unchanged when made bigger, turning this
7174 * setting off will improve performance.
7176 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7177 * off all allocation on resizing: the widget will not even redraw if
7178 * its position changes; this is to allow containers that don't draw
7179 * anything to avoid excess invalidations. If you set this flag on a
7180 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7181 * you are responsible for invalidating both the old and new allocation
7182 * of the widget when the widget is moved and responsible for invalidating
7183 * regions newly when the widget increases size.
7186 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7187 gboolean redraw_on_allocate)
7189 g_return_if_fail (GTK_IS_WIDGET (widget));
7191 widget->priv->redraw_on_alloc = redraw_on_allocate;
7195 * gtk_widget_set_sensitive:
7196 * @widget: a #GtkWidget
7197 * @sensitive: %TRUE to make the widget sensitive
7199 * Sets the sensitivity of a widget. A widget is sensitive if the user
7200 * can interact with it. Insensitive widgets are "grayed out" and the
7201 * user can't interact with them. Insensitive widgets are known as
7202 * "inactive", "disabled", or "ghosted" in some other toolkits.
7205 gtk_widget_set_sensitive (GtkWidget *widget,
7208 GtkWidgetPrivate *priv;
7211 g_return_if_fail (GTK_IS_WIDGET (widget));
7213 priv = widget->priv;
7215 sensitive = (sensitive != FALSE);
7217 if (widget->priv->sensitive == sensitive)
7222 widget->priv->sensitive = TRUE;
7223 data.state = priv->saved_state;
7227 widget->priv->sensitive = FALSE;
7228 data.state = gtk_widget_get_state (widget);
7230 data.state_restoration = TRUE;
7231 data.use_forall = TRUE;
7234 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7236 data.parent_sensitive = TRUE;
7238 gtk_widget_propagate_state (widget, &data);
7239 if (gtk_widget_is_drawable (widget))
7240 gtk_widget_queue_draw (widget);
7242 g_object_notify (G_OBJECT (widget), "sensitive");
7246 * gtk_widget_get_sensitive:
7247 * @widget: a #GtkWidget
7249 * Returns the widget's sensitivity (in the sense of returning
7250 * the value that has been set using gtk_widget_set_sensitive()).
7252 * The effective sensitivity of a widget is however determined by both its
7253 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7255 * Returns: %TRUE if the widget is sensitive
7260 gtk_widget_get_sensitive (GtkWidget *widget)
7262 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7264 return widget->priv->sensitive;
7268 * gtk_widget_is_sensitive:
7269 * @widget: a #GtkWidget
7271 * Returns the widget's effective sensitivity, which means
7272 * it is sensitive itself and also its parent widget is sensntive
7274 * Returns: %TRUE if the widget is effectively sensitive
7279 gtk_widget_is_sensitive (GtkWidget *widget)
7281 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7283 return widget->priv->sensitive && widget->priv->parent_sensitive;
7287 * gtk_widget_set_parent:
7288 * @widget: a #GtkWidget
7289 * @parent: parent container
7291 * This function is useful only when implementing subclasses of
7293 * Sets the container as the parent of @widget, and takes care of
7294 * some details such as updating the state and style of the child
7295 * to reflect its new location. The opposite function is
7296 * gtk_widget_unparent().
7299 gtk_widget_set_parent (GtkWidget *widget,
7302 GtkWidgetPrivate *priv;
7305 g_return_if_fail (GTK_IS_WIDGET (widget));
7306 g_return_if_fail (GTK_IS_WIDGET (parent));
7307 g_return_if_fail (widget != parent);
7309 priv = widget->priv;
7311 if (priv->parent != NULL)
7313 g_warning ("Can't set a parent on widget which has a parent\n");
7316 if (gtk_widget_is_toplevel (widget))
7318 g_warning ("Can't set a parent on a toplevel widget\n");
7322 /* keep this function in sync with gtk_menu_attach_to_widget()
7325 g_object_ref_sink (widget);
7326 priv->parent = parent;
7328 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7329 data.state = gtk_widget_get_state (parent);
7331 data.state = gtk_widget_get_state (widget);
7332 data.state_restoration = FALSE;
7333 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7334 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7336 gtk_widget_propagate_state (widget, &data);
7338 gtk_widget_reset_rc_styles (widget);
7340 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7341 if (priv->parent->priv->anchored)
7342 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7343 g_object_notify (G_OBJECT (widget), "parent");
7345 /* Enforce realized/mapped invariants
7347 if (gtk_widget_get_realized (priv->parent))
7348 gtk_widget_realize (widget);
7350 if (gtk_widget_get_visible (priv->parent) &&
7351 gtk_widget_get_visible (widget))
7353 if (gtk_widget_get_child_visible (widget) &&
7354 gtk_widget_get_mapped (priv->parent))
7355 gtk_widget_map (widget);
7357 gtk_widget_queue_resize (widget);
7360 /* child may cause parent's expand to change, if the child is
7361 * expanded. If child is not expanded, then it can't modify the
7362 * parent's expand. If the child becomes expanded later then it will
7363 * queue compute_expand then. This optimization plus defaulting
7364 * newly-constructed widgets to need_compute_expand=FALSE should
7365 * mean that initially building a widget tree doesn't have to keep
7366 * walking up setting need_compute_expand on parents over and over.
7368 * We can't change a parent to need to expand unless we're visible.
7370 if (gtk_widget_get_visible (widget) &&
7371 (priv->need_compute_expand ||
7372 priv->computed_hexpand ||
7373 priv->computed_vexpand))
7375 gtk_widget_queue_compute_expand (parent);
7380 * gtk_widget_get_parent:
7381 * @widget: a #GtkWidget
7383 * Returns the parent container of @widget.
7385 * Return value: (transfer none): the parent container of @widget, or %NULL
7388 gtk_widget_get_parent (GtkWidget *widget)
7390 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7392 return widget->priv->parent;
7395 /*****************************************
7397 * see docs/styles.txt
7398 *****************************************/
7401 * gtk_widget_style_attach:
7402 * @widget: a #GtkWidget
7404 * This function attaches the widget's #GtkStyle to the widget's
7405 * #GdkWindow. It is a replacement for
7408 * widget->style = gtk_style_attach (widget->style, widget->window);
7411 * and should only ever be called in a derived widget's "realize"
7412 * implementation which does not chain up to its parent class'
7413 * "realize" implementation, because one of the parent classes
7414 * (finally #GtkWidget) would attach the style itself.
7419 gtk_widget_style_attach (GtkWidget *widget)
7421 GtkWidgetPrivate *priv;
7423 g_return_if_fail (GTK_IS_WIDGET (widget));
7424 g_return_if_fail (gtk_widget_get_realized (widget));
7426 priv = widget->priv;
7428 priv->style = gtk_style_attach (priv->style, priv->window);
7432 * gtk_widget_has_rc_style:
7433 * @widget: a #GtkWidget
7435 * Determines if the widget style has been looked up through the rc mechanism.
7437 * Returns: %TRUE if the widget has been looked up through the rc
7438 * mechanism, %FALSE otherwise.
7443 gtk_widget_has_rc_style (GtkWidget *widget)
7445 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7447 return widget->priv->rc_style;
7451 * gtk_widget_set_style:
7452 * @widget: a #GtkWidget
7453 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7454 * gtk_widget_set_style() and go back to the default style
7456 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7457 * want to use this function; it interacts badly with themes, because
7458 * themes work by replacing the #GtkStyle. Instead, use
7459 * gtk_widget_modify_style().
7462 gtk_widget_set_style (GtkWidget *widget,
7465 g_return_if_fail (GTK_IS_WIDGET (widget));
7469 gboolean initial_emission;
7471 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7473 widget->priv->rc_style = FALSE;
7474 widget->priv->user_style = TRUE;
7476 gtk_widget_set_style_internal (widget, style, initial_emission);
7480 if (widget->priv->user_style)
7481 gtk_widget_reset_rc_style (widget);
7486 * gtk_widget_ensure_style:
7487 * @widget: a #GtkWidget
7489 * Ensures that @widget has a style (@widget->style). Not a very useful
7490 * function; most of the time, if you want the style, the widget is
7491 * realized, and realized widgets are guaranteed to have a style
7495 gtk_widget_ensure_style (GtkWidget *widget)
7497 g_return_if_fail (GTK_IS_WIDGET (widget));
7499 if (!widget->priv->rc_style && !widget->priv->user_style)
7500 gtk_widget_reset_rc_style (widget);
7503 /* Look up the RC style for this widget, unsetting any user style that
7504 * may be in effect currently
7507 gtk_widget_reset_rc_style (GtkWidget *widget)
7509 GtkWidgetPrivate *priv = widget->priv;
7510 GtkStyle *new_style = NULL;
7511 gboolean initial_emission;
7513 initial_emission = !priv->rc_style && !priv->user_style;
7515 priv->user_style = FALSE;
7516 priv->rc_style = TRUE;
7518 if (gtk_widget_has_screen (widget))
7519 new_style = gtk_rc_get_style (widget);
7521 new_style = gtk_widget_get_default_style ();
7523 if (initial_emission || new_style != priv->style)
7524 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7528 * gtk_widget_get_style:
7529 * @widget: a #GtkWidget
7531 * Simply an accessor function that returns @widget->style.
7533 * Return value: (transfer none): the widget's #GtkStyle
7536 gtk_widget_get_style (GtkWidget *widget)
7538 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7540 return widget->priv->style;
7544 * gtk_widget_modify_style:
7545 * @widget: a #GtkWidget
7546 * @style: the #GtkRcStyle holding the style modifications
7548 * Modifies style values on the widget. Modifications made using this
7549 * technique take precedence over style values set via an RC file,
7550 * however, they will be overriden if a style is explicitely set on
7551 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7552 * is designed so each field can either be set or unset, so it is
7553 * possible, using this function, to modify some style values and
7554 * leave the others unchanged.
7556 * Note that modifications made with this function are not cumulative
7557 * with previous calls to gtk_widget_modify_style() or with such
7558 * functions as gtk_widget_modify_fg(). If you wish to retain
7559 * previous values, you must first call gtk_widget_get_modifier_style(),
7560 * make your modifications to the returned style, then call
7561 * gtk_widget_modify_style() with that style. On the other hand,
7562 * if you first call gtk_widget_modify_style(), subsequent calls
7563 * to such functions gtk_widget_modify_fg() will have a cumulative
7564 * effect with the initial modifications.
7567 gtk_widget_modify_style (GtkWidget *widget,
7570 g_return_if_fail (GTK_IS_WIDGET (widget));
7571 g_return_if_fail (GTK_IS_RC_STYLE (style));
7573 g_object_set_qdata_full (G_OBJECT (widget),
7575 gtk_rc_style_copy (style),
7576 (GDestroyNotify) g_object_unref);
7578 /* note that "style" may be invalid here if it was the old
7579 * modifier style and the only reference was our own.
7582 if (widget->priv->rc_style)
7583 gtk_widget_reset_rc_style (widget);
7587 * gtk_widget_get_modifier_style:
7588 * @widget: a #GtkWidget
7590 * Returns the current modifier style for the widget. (As set by
7591 * gtk_widget_modify_style().) If no style has previously set, a new
7592 * #GtkRcStyle will be created with all values unset, and set as the
7593 * modifier style for the widget. If you make changes to this rc
7594 * style, you must call gtk_widget_modify_style(), passing in the
7595 * returned rc style, to make sure that your changes take effect.
7597 * Caution: passing the style back to gtk_widget_modify_style() will
7598 * normally end up destroying it, because gtk_widget_modify_style() copies
7599 * the passed-in style and sets the copy as the new modifier style,
7600 * thus dropping any reference to the old modifier style. Add a reference
7601 * to the modifier style if you want to keep it alive.
7603 * Return value: (transfer none): the modifier style for the widget. This rc style is
7604 * owned by the widget. If you want to keep a pointer to value this
7605 * around, you must add a refcount using g_object_ref().
7608 gtk_widget_get_modifier_style (GtkWidget *widget)
7610 GtkRcStyle *rc_style;
7612 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7614 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7618 rc_style = gtk_rc_style_new ();
7619 g_object_set_qdata_full (G_OBJECT (widget),
7622 (GDestroyNotify) g_object_unref);
7629 gtk_widget_modify_color_component (GtkWidget *widget,
7630 GtkRcFlags component,
7632 const GdkColor *color)
7634 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7641 rc_style->fg[state] = *color;
7644 rc_style->bg[state] = *color;
7647 rc_style->text[state] = *color;
7650 rc_style->base[state] = *color;
7653 g_assert_not_reached();
7656 rc_style->color_flags[state] |= component;
7659 rc_style->color_flags[state] &= ~component;
7661 gtk_widget_modify_style (widget, rc_style);
7665 * gtk_widget_modify_symbolic_color:
7666 * @widget: a #GtkWidget
7667 * @name: the name of the symbolic color to modify
7668 * @color: (allow-none): the color to assign (does not need to be allocated),
7669 * or %NULL to undo the effect of previous calls to
7670 * of gtk_widget_modify_symbolic_color().
7672 * Sets a symbolic color for a widget.
7673 * All other style values are left untouched. See also
7674 * gtk_widget_modify_style().
7679 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7681 const GdkColor *color)
7683 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7685 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7687 gtk_widget_modify_style (widget, rc_style);
7691 * gtk_widget_modify_fg:
7692 * @widget: a #GtkWidget
7693 * @state: the state for which to set the foreground color
7694 * @color: (allow-none): the color to assign (does not need to be allocated),
7695 * or %NULL to undo the effect of previous calls to
7696 * of gtk_widget_modify_fg().
7698 * Sets the foreground color for a widget in a particular state.
7699 * All other style values are left untouched. See also
7700 * gtk_widget_modify_style().
7703 gtk_widget_modify_fg (GtkWidget *widget,
7705 const GdkColor *color)
7707 g_return_if_fail (GTK_IS_WIDGET (widget));
7708 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7710 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7714 * gtk_widget_modify_bg:
7715 * @widget: a #GtkWidget
7716 * @state: the state for which to set the background color
7717 * @color: (allow-none): the color to assign (does not need to be allocated),
7718 * or %NULL to undo the effect of previous calls to
7719 * of gtk_widget_modify_bg().
7721 * Sets the background color for a widget in a particular state.
7722 * All other style values are left untouched. See also
7723 * gtk_widget_modify_style().
7725 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7726 * draw on their parent container's window and thus may not draw any
7727 * background themselves. This is the case for e.g. #GtkLabel. To modify
7728 * the background of such widgets, you have to set the background color
7729 * on their parent; if you want to set the background of a rectangular
7730 * area around a label, try placing the label in a #GtkEventBox widget
7731 * and setting the background color on that.
7734 gtk_widget_modify_bg (GtkWidget *widget,
7736 const GdkColor *color)
7738 g_return_if_fail (GTK_IS_WIDGET (widget));
7739 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7741 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7745 * gtk_widget_modify_text:
7746 * @widget: a #GtkWidget
7747 * @state: the state for which to set the text color
7748 * @color: (allow-none): the color to assign (does not need to be allocated),
7749 * or %NULL to undo the effect of previous calls to
7750 * of gtk_widget_modify_text().
7752 * Sets the text color for a widget in a particular state. All other
7753 * style values are left untouched. The text color is the foreground
7754 * color used along with the base color (see gtk_widget_modify_base())
7755 * for widgets such as #GtkEntry and #GtkTextView. See also
7756 * gtk_widget_modify_style().
7759 gtk_widget_modify_text (GtkWidget *widget,
7761 const GdkColor *color)
7763 g_return_if_fail (GTK_IS_WIDGET (widget));
7764 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7766 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7770 * gtk_widget_modify_base:
7771 * @widget: a #GtkWidget
7772 * @state: the state for which to set the base color
7773 * @color: (allow-none): the color to assign (does not need to be allocated),
7774 * or %NULL to undo the effect of previous calls to
7775 * of gtk_widget_modify_base().
7777 * Sets the base color for a widget in a particular state.
7778 * All other style values are left untouched. The base color
7779 * is the background color used along with the text color
7780 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7781 * and #GtkTextView. See also gtk_widget_modify_style().
7783 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7784 * draw on their parent container's window and thus may not draw any
7785 * background themselves. This is the case for e.g. #GtkLabel. To modify
7786 * the background of such widgets, you have to set the base color on their
7787 * parent; if you want to set the background of a rectangular area around
7788 * a label, try placing the label in a #GtkEventBox widget and setting
7789 * the base color on that.
7792 gtk_widget_modify_base (GtkWidget *widget,
7794 const GdkColor *color)
7796 g_return_if_fail (GTK_IS_WIDGET (widget));
7797 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7799 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7803 modify_color_property (GtkWidget *widget,
7804 GtkRcStyle *rc_style,
7806 const GdkColor *color)
7808 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7809 GQuark property_name = g_quark_from_string (name);
7813 GtkRcProperty rc_property = {0};
7816 rc_property.type_name = type_name;
7817 rc_property.property_name = property_name;
7818 rc_property.origin = NULL;
7820 color_name = gdk_color_to_string (color);
7821 g_value_init (&rc_property.value, G_TYPE_STRING);
7822 g_value_take_string (&rc_property.value, color_name);
7824 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7826 g_value_unset (&rc_property.value);
7829 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7833 * gtk_widget_modify_cursor:
7834 * @widget: a #GtkWidget
7835 * @primary: the color to use for primary cursor (does not need to be
7836 * allocated), or %NULL to undo the effect of previous calls to
7837 * of gtk_widget_modify_cursor().
7838 * @secondary: the color to use for secondary cursor (does not need to be
7839 * allocated), or %NULL to undo the effect of previous calls to
7840 * of gtk_widget_modify_cursor().
7842 * Sets the cursor color to use in a widget, overriding the
7843 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7844 * style properties. All other style values are left untouched.
7845 * See also gtk_widget_modify_style().
7850 gtk_widget_modify_cursor (GtkWidget *widget,
7851 const GdkColor *primary,
7852 const GdkColor *secondary)
7854 GtkRcStyle *rc_style;
7856 g_return_if_fail (GTK_IS_WIDGET (widget));
7858 rc_style = gtk_widget_get_modifier_style (widget);
7860 modify_color_property (widget, rc_style, "cursor-color", primary);
7861 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7863 gtk_widget_modify_style (widget, rc_style);
7867 * gtk_widget_modify_font:
7868 * @widget: a #GtkWidget
7869 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7870 * the effect of previous calls to gtk_widget_modify_font().
7872 * Sets the font to use for a widget. All other style values are left
7873 * untouched. See also gtk_widget_modify_style().
7876 gtk_widget_modify_font (GtkWidget *widget,
7877 PangoFontDescription *font_desc)
7879 GtkRcStyle *rc_style;
7881 g_return_if_fail (GTK_IS_WIDGET (widget));
7883 rc_style = gtk_widget_get_modifier_style (widget);
7885 if (rc_style->font_desc)
7886 pango_font_description_free (rc_style->font_desc);
7889 rc_style->font_desc = pango_font_description_copy (font_desc);
7891 rc_style->font_desc = NULL;
7893 gtk_widget_modify_style (widget, rc_style);
7897 gtk_widget_real_direction_changed (GtkWidget *widget,
7898 GtkTextDirection previous_direction)
7900 gtk_widget_queue_resize (widget);
7904 gtk_widget_real_style_set (GtkWidget *widget,
7905 GtkStyle *previous_style)
7907 GtkWidgetPrivate *priv = widget->priv;
7909 if (gtk_widget_get_realized (widget) &&
7910 gtk_widget_get_has_window (widget))
7911 gtk_style_set_background (priv->style, priv->window, priv->state);
7915 gtk_widget_set_style_internal (GtkWidget *widget,
7917 gboolean initial_emission)
7919 GtkWidgetPrivate *priv = widget->priv;
7921 g_object_ref (widget);
7922 g_object_freeze_notify (G_OBJECT (widget));
7924 if (priv->style != style)
7926 GtkStyle *previous_style;
7928 if (gtk_widget_get_realized (widget))
7930 gtk_widget_reset_shapes (widget);
7931 gtk_style_detach (priv->style);
7934 previous_style = priv->style;
7935 priv->style = style;
7936 g_object_ref (priv->style);
7938 if (gtk_widget_get_realized (widget))
7939 priv->style = gtk_style_attach (priv->style, priv->window);
7941 gtk_widget_update_pango_context (widget);
7942 g_signal_emit (widget,
7943 widget_signals[STYLE_SET],
7945 initial_emission ? NULL : previous_style);
7946 g_object_unref (previous_style);
7948 if (priv->anchored && !initial_emission)
7949 gtk_widget_queue_resize (widget);
7951 else if (initial_emission)
7953 gtk_widget_update_pango_context (widget);
7954 g_signal_emit (widget,
7955 widget_signals[STYLE_SET],
7959 g_object_notify (G_OBJECT (widget), "style");
7960 g_object_thaw_notify (G_OBJECT (widget));
7961 g_object_unref (widget);
7965 GtkWidget *previous_toplevel;
7966 GdkScreen *previous_screen;
7967 GdkScreen *new_screen;
7968 } HierarchyChangedInfo;
7971 do_screen_change (GtkWidget *widget,
7972 GdkScreen *old_screen,
7973 GdkScreen *new_screen)
7975 if (old_screen != new_screen)
7979 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7981 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7984 _gtk_tooltip_hide (widget);
7985 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7990 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7991 gpointer client_data)
7993 GtkWidgetPrivate *priv = widget->priv;
7994 HierarchyChangedInfo *info = client_data;
7995 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7996 (priv->parent && priv->parent->priv->anchored);
7998 if (priv->anchored != new_anchored)
8000 g_object_ref (widget);
8002 priv->anchored = new_anchored;
8004 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8005 do_screen_change (widget, info->previous_screen, info->new_screen);
8007 if (GTK_IS_CONTAINER (widget))
8008 gtk_container_forall (GTK_CONTAINER (widget),
8009 gtk_widget_propagate_hierarchy_changed_recurse,
8012 g_object_unref (widget);
8017 * _gtk_widget_propagate_hierarchy_changed:
8018 * @widget: a #GtkWidget
8019 * @previous_toplevel: Previous toplevel
8021 * Propagates changes in the anchored state to a widget and all
8022 * children, unsetting or setting the %ANCHORED flag, and
8023 * emitting #GtkWidget::hierarchy-changed.
8026 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8027 GtkWidget *previous_toplevel)
8029 GtkWidgetPrivate *priv = widget->priv;
8030 HierarchyChangedInfo info;
8032 info.previous_toplevel = previous_toplevel;
8033 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8035 if (gtk_widget_is_toplevel (widget) ||
8036 (priv->parent && priv->parent->priv->anchored))
8037 info.new_screen = gtk_widget_get_screen (widget);
8039 info.new_screen = NULL;
8041 if (info.previous_screen)
8042 g_object_ref (info.previous_screen);
8043 if (previous_toplevel)
8044 g_object_ref (previous_toplevel);
8046 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8048 if (previous_toplevel)
8049 g_object_unref (previous_toplevel);
8050 if (info.previous_screen)
8051 g_object_unref (info.previous_screen);
8055 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8056 gpointer client_data)
8058 HierarchyChangedInfo *info = client_data;
8060 g_object_ref (widget);
8062 do_screen_change (widget, info->previous_screen, info->new_screen);
8064 if (GTK_IS_CONTAINER (widget))
8065 gtk_container_forall (GTK_CONTAINER (widget),
8066 gtk_widget_propagate_screen_changed_recurse,
8069 g_object_unref (widget);
8073 * gtk_widget_is_composited:
8074 * @widget: a #GtkWidget
8076 * Whether @widget can rely on having its alpha channel
8077 * drawn correctly. On X11 this function returns whether a
8078 * compositing manager is running for @widget's screen.
8080 * Please note that the semantics of this call will change
8081 * in the future if used on a widget that has a composited
8082 * window in its hierarchy (as set by gdk_window_set_composited()).
8084 * Return value: %TRUE if the widget can rely on its alpha
8085 * channel being drawn correctly.
8090 gtk_widget_is_composited (GtkWidget *widget)
8094 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8096 screen = gtk_widget_get_screen (widget);
8098 return gdk_screen_is_composited (screen);
8102 propagate_composited_changed (GtkWidget *widget,
8105 if (GTK_IS_CONTAINER (widget))
8107 gtk_container_forall (GTK_CONTAINER (widget),
8108 propagate_composited_changed,
8112 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8116 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8118 propagate_composited_changed (widget, NULL);
8122 * _gtk_widget_propagate_screen_changed:
8123 * @widget: a #GtkWidget
8124 * @previous_screen: Previous screen
8126 * Propagates changes in the screen for a widget to all
8127 * children, emitting #GtkWidget::screen-changed.
8130 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8131 GdkScreen *previous_screen)
8133 HierarchyChangedInfo info;
8135 info.previous_screen = previous_screen;
8136 info.new_screen = gtk_widget_get_screen (widget);
8138 if (previous_screen)
8139 g_object_ref (previous_screen);
8141 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8143 if (previous_screen)
8144 g_object_unref (previous_screen);
8148 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
8150 if (widget->priv->rc_style)
8151 gtk_widget_reset_rc_style (widget);
8153 if (GTK_IS_CONTAINER (widget))
8154 gtk_container_forall (GTK_CONTAINER (widget),
8155 reset_rc_styles_recurse,
8161 * gtk_widget_reset_rc_styles:
8162 * @widget: a #GtkWidget.
8164 * Reset the styles of @widget and all descendents, so when
8165 * they are looked up again, they get the correct values
8166 * for the currently loaded RC file settings.
8168 * This function is not useful for applications.
8171 gtk_widget_reset_rc_styles (GtkWidget *widget)
8173 g_return_if_fail (GTK_IS_WIDGET (widget));
8175 reset_rc_styles_recurse (widget, NULL);
8179 * gtk_widget_get_default_style:
8181 * Returns the default style used by all widgets initially.
8183 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8184 * by GTK+ and should not be modified or freed.
8187 gtk_widget_get_default_style (void)
8189 if (!gtk_default_style)
8191 gtk_default_style = gtk_style_new ();
8192 g_object_ref (gtk_default_style);
8195 return gtk_default_style;
8198 static PangoContext *
8199 gtk_widget_peek_pango_context (GtkWidget *widget)
8201 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8205 * gtk_widget_get_pango_context:
8206 * @widget: a #GtkWidget
8208 * Gets a #PangoContext with the appropriate font map, font description,
8209 * and base direction for this widget. Unlike the context returned
8210 * by gtk_widget_create_pango_context(), this context is owned by
8211 * the widget (it can be used until the screen for the widget changes
8212 * or the widget is removed from its toplevel), and will be updated to
8213 * match any changes to the widget's attributes.
8215 * If you create and keep a #PangoLayout using this context, you must
8216 * deal with changes to the context by calling pango_layout_context_changed()
8217 * on the layout in response to the #GtkWidget::style-set and
8218 * #GtkWidget::direction-changed signals for the widget.
8220 * Return value: (transfer none): the #PangoContext for the widget.
8223 gtk_widget_get_pango_context (GtkWidget *widget)
8225 PangoContext *context;
8227 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8229 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8232 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8233 g_object_set_qdata_full (G_OBJECT (widget),
8234 quark_pango_context,
8243 update_pango_context (GtkWidget *widget,
8244 PangoContext *context)
8246 GtkWidgetPrivate *priv = widget->priv;
8248 pango_context_set_font_description (context, priv->style->font_desc);
8249 pango_context_set_base_dir (context,
8250 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8251 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8255 gtk_widget_update_pango_context (GtkWidget *widget)
8257 PangoContext *context = gtk_widget_peek_pango_context (widget);
8263 update_pango_context (widget, context);
8265 screen = gtk_widget_get_screen_unchecked (widget);
8268 pango_cairo_context_set_resolution (context,
8269 gdk_screen_get_resolution (screen));
8270 pango_cairo_context_set_font_options (context,
8271 gdk_screen_get_font_options (screen));
8277 * gtk_widget_create_pango_context:
8278 * @widget: a #GtkWidget
8280 * Creates a new #PangoContext with the appropriate font map,
8281 * font description, and base direction for drawing text for
8282 * this widget. See also gtk_widget_get_pango_context().
8284 * Return value: (transfer full): the new #PangoContext
8287 gtk_widget_create_pango_context (GtkWidget *widget)
8290 PangoContext *context;
8292 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8294 screen = gtk_widget_get_screen_unchecked (widget);
8297 GTK_NOTE (MULTIHEAD,
8298 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8300 screen = gdk_screen_get_default ();
8303 context = gdk_pango_context_get_for_screen (screen);
8305 update_pango_context (widget, context);
8306 pango_context_set_language (context, gtk_get_default_language ());
8312 * gtk_widget_create_pango_layout:
8313 * @widget: a #GtkWidget
8314 * @text: text to set on the layout (can be %NULL)
8316 * Creates a new #PangoLayout with the appropriate font map,
8317 * font description, and base direction for drawing text for
8320 * If you keep a #PangoLayout created in this way around, in order to
8321 * notify the layout of changes to the base direction or font of this
8322 * widget, you must call pango_layout_context_changed() in response to
8323 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8326 * Return value: (transfer full): the new #PangoLayout
8329 gtk_widget_create_pango_layout (GtkWidget *widget,
8332 PangoLayout *layout;
8333 PangoContext *context;
8335 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8337 context = gtk_widget_get_pango_context (widget);
8338 layout = pango_layout_new (context);
8341 pango_layout_set_text (layout, text, -1);
8347 * gtk_widget_render_icon:
8348 * @widget: a #GtkWidget
8349 * @stock_id: a stock ID
8350 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8351 * render at the size of the source and don't scale (if there are
8352 * multiple source sizes, GTK+ picks one of the available sizes).
8353 * @detail: (allow-none): render detail to pass to theme engine
8355 * A convenience function that uses the theme engine and RC file
8356 * settings for @widget to look up @stock_id and render it to
8357 * a pixbuf. @stock_id should be a stock icon ID such as
8358 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8359 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8360 * identifies the widget or code doing the rendering, so that
8361 * theme engines can special-case rendering for that widget or code.
8363 * The pixels in the returned #GdkPixbuf are shared with the rest of
8364 * the application and should not be modified. The pixbuf should be freed
8365 * after use with g_object_unref().
8367 * Return value: (transfer full): a new pixbuf, or %NULL if the
8368 * stock ID wasn't known
8371 gtk_widget_render_icon (GtkWidget *widget,
8372 const gchar *stock_id,
8374 const gchar *detail)
8376 GtkWidgetPrivate *priv;
8377 GtkIconSet *icon_set;
8380 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8381 g_return_val_if_fail (stock_id != NULL, NULL);
8382 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8384 priv = widget->priv;
8386 gtk_widget_ensure_style (widget);
8388 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8390 if (icon_set == NULL)
8393 retval = gtk_icon_set_render_icon (icon_set,
8395 gtk_widget_get_direction (widget),
8396 gtk_widget_get_state (widget),
8405 * gtk_widget_set_parent_window:
8406 * @widget: a #GtkWidget.
8407 * @parent_window: the new parent window.
8409 * Sets a non default parent window for @widget.
8412 gtk_widget_set_parent_window (GtkWidget *widget,
8413 GdkWindow *parent_window)
8415 GdkWindow *old_parent_window;
8417 g_return_if_fail (GTK_IS_WIDGET (widget));
8419 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8420 quark_parent_window);
8422 if (parent_window != old_parent_window)
8424 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8426 if (old_parent_window)
8427 g_object_unref (old_parent_window);
8429 g_object_ref (parent_window);
8434 * gtk_widget_get_parent_window:
8435 * @widget: a #GtkWidget.
8437 * Gets @widget's parent window.
8439 * Returns: (transfer none): the parent window of @widget.
8442 gtk_widget_get_parent_window (GtkWidget *widget)
8444 GtkWidgetPrivate *priv;
8445 GdkWindow *parent_window;
8447 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8449 priv = widget->priv;
8451 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8453 return (parent_window != NULL) ? parent_window :
8454 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8459 * gtk_widget_set_child_visible:
8460 * @widget: a #GtkWidget
8461 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8463 * Sets whether @widget should be mapped along with its when its parent
8464 * is mapped and @widget has been shown with gtk_widget_show().
8466 * The child visibility can be set for widget before it is added to
8467 * a container with gtk_widget_set_parent(), to avoid mapping
8468 * children unnecessary before immediately unmapping them. However
8469 * it will be reset to its default state of %TRUE when the widget
8470 * is removed from a container.
8472 * Note that changing the child visibility of a widget does not
8473 * queue a resize on the widget. Most of the time, the size of
8474 * a widget is computed from all visible children, whether or
8475 * not they are mapped. If this is not the case, the container
8476 * can queue a resize itself.
8478 * This function is only useful for container implementations and
8479 * never should be called by an application.
8482 gtk_widget_set_child_visible (GtkWidget *widget,
8483 gboolean is_visible)
8485 GtkWidgetPrivate *priv;
8487 g_return_if_fail (GTK_IS_WIDGET (widget));
8488 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8490 priv = widget->priv;
8492 g_object_ref (widget);
8495 priv->child_visible = TRUE;
8498 GtkWidget *toplevel;
8500 priv->child_visible = FALSE;
8502 toplevel = gtk_widget_get_toplevel (widget);
8503 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8504 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8507 if (priv->parent && gtk_widget_get_realized (priv->parent))
8509 if (gtk_widget_get_mapped (priv->parent) &&
8510 priv->child_visible &&
8511 gtk_widget_get_visible (widget))
8512 gtk_widget_map (widget);
8514 gtk_widget_unmap (widget);
8517 g_object_unref (widget);
8521 * gtk_widget_get_child_visible:
8522 * @widget: a #GtkWidget
8524 * Gets the value set with gtk_widget_set_child_visible().
8525 * If you feel a need to use this function, your code probably
8526 * needs reorganization.
8528 * This function is only useful for container implementations and
8529 * never should be called by an application.
8531 * Return value: %TRUE if the widget is mapped with the parent.
8534 gtk_widget_get_child_visible (GtkWidget *widget)
8536 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8538 return widget->priv->child_visible;
8542 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8544 GtkWidget *toplevel;
8546 toplevel = gtk_widget_get_toplevel (widget);
8548 if (gtk_widget_is_toplevel (toplevel))
8550 if (GTK_IS_WINDOW (toplevel))
8551 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8552 else if (GTK_IS_INVISIBLE (toplevel))
8553 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8560 * gtk_widget_get_screen:
8561 * @widget: a #GtkWidget
8563 * Get the #GdkScreen from the toplevel window associated with
8564 * this widget. This function can only be called after the widget
8565 * has been added to a widget hierarchy with a #GtkWindow
8568 * In general, you should only create screen specific
8569 * resources when a widget has been realized, and you should
8570 * free those resources when the widget is unrealized.
8572 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8577 gtk_widget_get_screen (GtkWidget *widget)
8581 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8583 screen = gtk_widget_get_screen_unchecked (widget);
8590 g_warning (G_STRLOC ": Can't get associated screen"
8591 " for a widget unless it is inside a toplevel GtkWindow\n"
8592 " widget type is %s associated top level type is %s",
8593 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8594 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8596 return gdk_screen_get_default ();
8601 * gtk_widget_has_screen:
8602 * @widget: a #GtkWidget
8604 * Checks whether there is a #GdkScreen is associated with
8605 * this widget. All toplevel widgets have an associated
8606 * screen, and all widgets added into a hierarchy with a toplevel
8607 * window at the top.
8609 * Return value: %TRUE if there is a #GdkScreen associcated
8615 gtk_widget_has_screen (GtkWidget *widget)
8617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8619 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8623 * gtk_widget_get_display:
8624 * @widget: a #GtkWidget
8626 * Get the #GdkDisplay for the toplevel window associated with
8627 * this widget. This function can only be called after the widget
8628 * has been added to a widget hierarchy with a #GtkWindow at the top.
8630 * In general, you should only create display specific
8631 * resources when a widget has been realized, and you should
8632 * free those resources when the widget is unrealized.
8634 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8639 gtk_widget_get_display (GtkWidget *widget)
8641 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8643 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8647 * gtk_widget_get_root_window:
8648 * @widget: a #GtkWidget
8650 * Get the root window where this widget is located. This function can
8651 * only be called after the widget has been added to a widget
8652 * hierarchy with #GtkWindow at the top.
8654 * The root window is useful for such purposes as creating a popup
8655 * #GdkWindow associated with the window. In general, you should only
8656 * create display specific resources when a widget has been realized,
8657 * and you should free those resources when the widget is unrealized.
8659 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8664 gtk_widget_get_root_window (GtkWidget *widget)
8666 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8668 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8672 * gtk_widget_child_focus:
8673 * @widget: a #GtkWidget
8674 * @direction: direction of focus movement
8676 * This function is used by custom widget implementations; if you're
8677 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8678 * to a particular widget, and gtk_container_set_focus_chain() to
8679 * change the focus tab order. So you may want to investigate those
8680 * functions instead.
8682 * gtk_widget_child_focus() is called by containers as the user moves
8683 * around the window using keyboard shortcuts. @direction indicates
8684 * what kind of motion is taking place (up, down, left, right, tab
8685 * forward, tab backward). gtk_widget_child_focus() emits the
8686 * #GtkWidget::focus signal; widgets override the default handler
8687 * for this signal in order to implement appropriate focus behavior.
8689 * The default ::focus handler for a widget should return %TRUE if
8690 * moving in @direction left the focus on a focusable location inside
8691 * that widget, and %FALSE if moving in @direction moved the focus
8692 * outside the widget. If returning %TRUE, widgets normally
8693 * call gtk_widget_grab_focus() to place the focus accordingly;
8694 * if returning %FALSE, they don't modify the current focus location.
8696 * Return value: %TRUE if focus ended up inside @widget
8699 gtk_widget_child_focus (GtkWidget *widget,
8700 GtkDirectionType direction)
8702 gboolean return_val;
8704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8706 if (!gtk_widget_get_visible (widget) ||
8707 !gtk_widget_is_sensitive (widget))
8710 /* child widgets must set CAN_FOCUS, containers
8711 * don't have to though.
8713 if (!GTK_IS_CONTAINER (widget) &&
8714 !gtk_widget_get_can_focus (widget))
8717 g_signal_emit (widget,
8718 widget_signals[FOCUS],
8720 direction, &return_val);
8726 * gtk_widget_keynav_failed:
8727 * @widget: a #GtkWidget
8728 * @direction: direction of focus movement
8730 * This function should be called whenever keyboard navigation within
8731 * a single widget hits a boundary. The function emits the
8732 * #GtkWidget::keynav-failed signal on the widget and its return
8733 * value should be interpreted in a way similar to the return value of
8734 * gtk_widget_child_focus():
8736 * When %TRUE is returned, stay in the widget, the failed keyboard
8737 * navigation is Ok and/or there is nowhere we can/should move the
8740 * When %FALSE is returned, the caller should continue with keyboard
8741 * navigation outside the widget, e.g. by calling
8742 * gtk_widget_child_focus() on the widget's toplevel.
8744 * The default ::keynav-failed handler returns %TRUE for
8745 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8746 * values of #GtkDirectionType, it looks at the
8747 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8748 * if the setting is %TRUE. This way the entire user interface
8749 * becomes cursor-navigatable on input devices such as mobile phones
8750 * which only have cursor keys but no tab key.
8752 * Whenever the default handler returns %TRUE, it also calls
8753 * gtk_widget_error_bell() to notify the user of the failed keyboard
8756 * A use case for providing an own implementation of ::keynav-failed
8757 * (either by connecting to it or by overriding it) would be a row of
8758 * #GtkEntry widgets where the user should be able to navigate the
8759 * entire row with the cursor keys, as e.g. known from user interfaces
8760 * that require entering license keys.
8762 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8763 * if the emitting widget should try to handle the keyboard
8764 * navigation attempt in its parent container(s).
8769 gtk_widget_keynav_failed (GtkWidget *widget,
8770 GtkDirectionType direction)
8772 gboolean return_val;
8774 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8776 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8777 direction, &return_val);
8783 * gtk_widget_error_bell:
8784 * @widget: a #GtkWidget
8786 * Notifies the user about an input-related error on this widget.
8787 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8788 * gdk_window_beep(), otherwise it does nothing.
8790 * Note that the effect of gdk_window_beep() can be configured in many
8791 * ways, depending on the windowing backend and the desktop environment
8792 * or window manager that is used.
8797 gtk_widget_error_bell (GtkWidget *widget)
8799 GtkWidgetPrivate *priv;
8800 GtkSettings* settings;
8803 g_return_if_fail (GTK_IS_WIDGET (widget));
8805 priv = widget->priv;
8807 settings = gtk_widget_get_settings (widget);
8811 g_object_get (settings,
8812 "gtk-error-bell", &beep,
8815 if (beep && priv->window)
8816 gdk_window_beep (priv->window);
8820 gtk_widget_set_usize_internal (GtkWidget *widget,
8823 GtkQueueResizeFlags flags)
8825 GtkWidgetAuxInfo *aux_info;
8826 gboolean changed = FALSE;
8828 g_object_freeze_notify (G_OBJECT (widget));
8830 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8832 if (width > -2 && aux_info->width != width)
8834 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8835 g_object_notify (G_OBJECT (widget), "width-request");
8836 aux_info->width = width;
8839 if (height > -2 && aux_info->height != height)
8841 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8842 g_object_notify (G_OBJECT (widget), "height-request");
8843 aux_info->height = height;
8847 if (gtk_widget_get_visible (widget) && changed)
8849 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8850 gtk_widget_queue_resize (widget);
8852 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8855 g_object_thaw_notify (G_OBJECT (widget));
8859 * gtk_widget_set_size_request:
8860 * @widget: a #GtkWidget
8861 * @width: width @widget should request, or -1 to unset
8862 * @height: height @widget should request, or -1 to unset
8864 * Sets the minimum size of a widget; that is, the widget's size
8865 * request will be @width by @height. You can use this function to
8866 * force a widget to be either larger or smaller than it normally
8869 * In most cases, gtk_window_set_default_size() is a better choice for
8870 * toplevel windows than this function; setting the default size will
8871 * still allow users to shrink the window. Setting the size request
8872 * will force them to leave the window at least as large as the size
8873 * request. When dealing with window sizes,
8874 * gtk_window_set_geometry_hints() can be a useful function as well.
8876 * Note the inherent danger of setting any fixed size - themes,
8877 * translations into other languages, different fonts, and user action
8878 * can all change the appropriate size for a given widget. So, it's
8879 * basically impossible to hardcode a size that will always be
8882 * The size request of a widget is the smallest size a widget can
8883 * accept while still functioning well and drawing itself correctly.
8884 * However in some strange cases a widget may be allocated less than
8885 * its requested size, and in many cases a widget may be allocated more
8886 * space than it requested.
8888 * If the size request in a given direction is -1 (unset), then
8889 * the "natural" size request of the widget will be used instead.
8891 * Widgets can't actually be allocated a size less than 1 by 1, but
8892 * you can pass 0,0 to this function to mean "as small as possible."
8894 * The size request set here does not include any margin from the
8895 * #GtkWidget properties margin-left, margin-right, margin-top, and
8896 * margin-bottom, but it does include pretty much all other padding
8897 * or border properties set by any subclass of #GtkWidget.
8900 gtk_widget_set_size_request (GtkWidget *widget,
8904 g_return_if_fail (GTK_IS_WIDGET (widget));
8905 g_return_if_fail (width >= -1);
8906 g_return_if_fail (height >= -1);
8913 gtk_widget_set_usize_internal (widget, width, height, 0);
8918 * gtk_widget_get_size_request:
8919 * @widget: a #GtkWidget
8920 * @width: (out) (allow-none): return location for width, or %NULL
8921 * @height: (out) (allow-none): return location for height, or %NULL
8923 * Gets the size request that was explicitly set for the widget using
8924 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8925 * @height indicates that that dimension has not been set explicitly
8926 * and the natural requisition of the widget will be used intead. See
8927 * gtk_widget_set_size_request(). To get the size a widget will
8928 * actually request, call gtk_widget_get_preferred_size() instead of
8932 gtk_widget_get_size_request (GtkWidget *widget,
8936 const GtkWidgetAuxInfo *aux_info;
8938 g_return_if_fail (GTK_IS_WIDGET (widget));
8940 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8943 *width = aux_info->width;
8946 *height = aux_info->height;
8950 * _gtk_widget_override_size_request:
8951 * @widget: a #GtkWidget
8952 * @width: new forced minimum width
8953 * @height: new forced minimum height
8954 * @old_width: location to store previous forced minimum width
8955 * @old_width: location to store previous forced minumum height
8957 * Temporarily establishes a forced minimum size for a widget; this
8958 * is used by GtkWindow when calculating the size to add to the
8959 * window's geometry widget. Cached sizes for the widget and its
8960 * parents are invalidated, so that subsequent calls to the size
8961 * negotiation machinery produce the overriden result, but the
8962 * widget is not queued for relayout or redraw. The old size must
8963 * be restored with _gtk_widget_restore_size_request() or things
8967 _gtk_widget_override_size_request (GtkWidget *widget,
8973 gtk_widget_get_size_request (widget, old_width, old_height);
8974 gtk_widget_set_usize_internal (widget, width, height,
8975 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8979 * _gtk_widget_restore_size_request:
8980 * @widget: a #GtkWidget
8981 * @old_width: saved forced minimum size
8982 * @old_height: saved forced minimum size
8984 * Undoes the operation of_gtk_widget_override_size_request().
8987 _gtk_widget_restore_size_request (GtkWidget *widget,
8991 gtk_widget_set_usize_internal (widget, old_width, old_height,
8992 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8996 * gtk_widget_set_events:
8997 * @widget: a #GtkWidget
8998 * @events: event mask
9000 * Sets the event mask (see #GdkEventMask) for a widget. The event
9001 * mask determines which events a widget will receive. Keep in mind
9002 * that different widgets have different default event masks, and by
9003 * changing the event mask you may disrupt a widget's functionality,
9004 * so be careful. This function must be called while a widget is
9005 * unrealized. Consider gtk_widget_add_events() for widgets that are
9006 * already realized, or if you want to preserve the existing event
9007 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9008 * to get events on those widgets, place them inside a #GtkEventBox
9009 * and receive events on the event box.
9012 gtk_widget_set_events (GtkWidget *widget,
9015 g_return_if_fail (GTK_IS_WIDGET (widget));
9016 g_return_if_fail (!gtk_widget_get_realized (widget));
9018 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9019 GINT_TO_POINTER (events));
9020 g_object_notify (G_OBJECT (widget), "events");
9024 * gtk_widget_set_device_events:
9025 * @widget: a #GtkWidget
9026 * @device: a #GdkDevice
9027 * @events: event mask
9029 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9030 * mask determines which events a widget will receive from @device. Keep
9031 * in mind that different widgets have different default event masks, and by
9032 * changing the event mask you may disrupt a widget's functionality,
9033 * so be careful. This function must be called while a widget is
9034 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9035 * already realized, or if you want to preserve the existing event
9036 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9037 * to get events on those widgets, place them inside a #GtkEventBox
9038 * and receive events on the event box.
9043 gtk_widget_set_device_events (GtkWidget *widget,
9045 GdkEventMask events)
9047 GHashTable *device_events;
9049 g_return_if_fail (GTK_IS_WIDGET (widget));
9050 g_return_if_fail (GDK_IS_DEVICE (device));
9051 g_return_if_fail (!gtk_widget_get_realized (widget));
9053 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9055 if (G_UNLIKELY (!device_events))
9057 device_events = g_hash_table_new (NULL, NULL);
9058 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9059 (GDestroyNotify) g_hash_table_unref);
9062 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9066 gtk_widget_add_events_internal_list (GtkWidget *widget,
9073 for (l = window_list; l != NULL; l = l->next)
9075 GdkWindow *window = l->data;
9078 gdk_window_get_user_data (window, &user_data);
9079 if (user_data == widget)
9084 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9086 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9088 children = gdk_window_get_children (window);
9089 gtk_widget_add_events_internal_list (widget, device, events, children);
9090 g_list_free (children);
9096 gtk_widget_add_events_internal (GtkWidget *widget,
9100 GtkWidgetPrivate *priv = widget->priv;
9103 if (!gtk_widget_get_has_window (widget))
9104 window_list = gdk_window_get_children (priv->window);
9106 window_list = g_list_prepend (NULL, priv->window);
9108 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9110 g_list_free (window_list);
9114 * gtk_widget_add_events:
9115 * @widget: a #GtkWidget
9116 * @events: an event mask, see #GdkEventMask
9118 * Adds the events in the bitfield @events to the event mask for
9119 * @widget. See gtk_widget_set_events() for details.
9122 gtk_widget_add_events (GtkWidget *widget,
9127 g_return_if_fail (GTK_IS_WIDGET (widget));
9129 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9130 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9131 GINT_TO_POINTER (old_events | events));
9133 if (gtk_widget_get_realized (widget))
9134 gtk_widget_add_events_internal (widget, NULL, events);
9136 g_object_notify (G_OBJECT (widget), "events");
9140 * gtk_widget_add_device_events:
9141 * @widget: a #GtkWidget
9142 * @device: a #GdkDevice
9143 * @events: an event mask, see #GdkEventMask
9145 * Adds the device events in the bitfield @events to the event mask for
9146 * @widget. See gtk_widget_set_device_events() for details.
9151 gtk_widget_add_device_events (GtkWidget *widget,
9153 GdkEventMask events)
9155 GdkEventMask old_events;
9156 GHashTable *device_events;
9158 g_return_if_fail (GTK_IS_WIDGET (widget));
9159 g_return_if_fail (GDK_IS_DEVICE (device));
9161 old_events = gtk_widget_get_device_events (widget, device);
9163 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9165 if (G_UNLIKELY (!device_events))
9167 device_events = g_hash_table_new (NULL, NULL);
9168 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9169 (GDestroyNotify) g_hash_table_unref);
9172 g_hash_table_insert (device_events, device,
9173 GUINT_TO_POINTER (old_events | events));
9175 if (gtk_widget_get_realized (widget))
9176 gtk_widget_add_events_internal (widget, device, events);
9178 g_object_notify (G_OBJECT (widget), "events");
9182 * gtk_widget_set_extension_events:
9183 * @widget: a #GtkWidget
9184 * @mode: bitfield of extension events to receive
9186 * Sets the extension events mask to @mode. See #GdkExtensionMode
9187 * and gdk_input_set_extension_events().
9190 gtk_widget_set_extension_events (GtkWidget *widget,
9191 GdkExtensionMode mode)
9193 g_return_if_fail (GTK_IS_WIDGET (widget));
9195 if (gtk_widget_get_realized (widget))
9196 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9198 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9199 GINT_TO_POINTER (mode));
9200 g_object_notify (G_OBJECT (widget), "extension-events");
9204 * gtk_widget_get_toplevel:
9205 * @widget: a #GtkWidget
9207 * This function returns the topmost widget in the container hierarchy
9208 * @widget is a part of. If @widget has no parent widgets, it will be
9209 * returned as the topmost widget. No reference will be added to the
9210 * returned widget; it should not be unreferenced.
9212 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9213 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9215 * %NULL if @widget wasn't inside a toplevel window, and if the
9216 * window was inside a #GtkWindow-derived widget which was in turn
9217 * inside the toplevel #GtkWindow. While the second case may
9218 * seem unlikely, it actually happens when a #GtkPlug is embedded
9219 * inside a #GtkSocket within the same application.
9221 * To reliably find the toplevel #GtkWindow, use
9222 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9223 * is set on the result.
9225 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9226 * if (gtk_widget_is_toplevel (toplevel))
9228 * /* Perform action on toplevel. */
9232 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9233 * if there's no ancestor.
9236 gtk_widget_get_toplevel (GtkWidget *widget)
9238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9240 while (widget->priv->parent)
9241 widget = widget->priv->parent;
9247 * gtk_widget_get_ancestor:
9248 * @widget: a #GtkWidget
9249 * @widget_type: ancestor type
9251 * Gets the first ancestor of @widget with type @widget_type. For example,
9252 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9253 * the first #GtkBox that's an ancestor of @widget. No reference will be
9254 * added to the returned widget; it should not be unreferenced. See note
9255 * about checking for a toplevel #GtkWindow in the docs for
9256 * gtk_widget_get_toplevel().
9258 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9259 * considers @widget to be an ancestor of itself.
9261 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9264 gtk_widget_get_ancestor (GtkWidget *widget,
9267 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9269 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9270 widget = widget->priv->parent;
9272 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9279 * gtk_widget_set_visual:
9280 * @widget: a #GtkWidget
9281 * @visual: visual to be used or %NULL to unset a previous one
9283 * Sets the visual that should be used for by widget and its children for
9284 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9285 * returned by gdk_widget_get_screen(), so handling the
9286 * #GtkWidget::screen-changed signal is necessary.
9288 * Setting a new @visual will not cause @widget to recreate its windows,
9289 * so you should call this function before @widget is realized.
9292 gtk_widget_set_visual (GtkWidget *widget,
9295 g_return_if_fail (GTK_IS_WIDGET (widget));
9296 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9299 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9302 g_object_set_qdata_full (G_OBJECT (widget),
9304 g_object_ref (visual),
9309 * gtk_widget_get_visual:
9310 * @widget: a #GtkWidget
9312 * Gets the visual that will be used to render @widget.
9314 * Return value: (transfer none): the visual for @widget
9317 gtk_widget_get_visual (GtkWidget *widget)
9323 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9325 if (gtk_widget_get_has_window (widget) &&
9326 widget->priv->window)
9327 return gdk_window_get_visual (widget->priv->window);
9329 screen = gtk_widget_get_screen (widget);
9331 for (w = widget; w != NULL; w = w->priv->parent)
9333 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9336 if (gdk_visual_get_screen (visual) == screen)
9339 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9340 gtk_widget_get_name (widget));
9344 return gdk_screen_get_system_visual (screen);
9348 * gtk_widget_get_settings:
9349 * @widget: a #GtkWidget
9351 * Gets the settings object holding the settings (global property
9352 * settings, RC file information, etc) used for this widget.
9354 * Note that this function can only be called when the #GtkWidget
9355 * is attached to a toplevel, since the settings object is specific
9356 * to a particular #GdkScreen.
9358 * Return value: (transfer none): the relevant #GtkSettings object
9361 gtk_widget_get_settings (GtkWidget *widget)
9363 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9365 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9369 * gtk_widget_get_events:
9370 * @widget: a #GtkWidget
9372 * Returns the event mask for the widget (a bitfield containing flags
9373 * from the #GdkEventMask enumeration). These are the events that the widget
9376 * Return value: event mask for @widget
9379 gtk_widget_get_events (GtkWidget *widget)
9381 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9383 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9387 * gtk_widget_get_device_events:
9388 * @widget: a #GtkWidget
9389 * @device: a #GdkDevice
9391 * Returns the events mask for the widget corresponding to an specific device. These
9392 * are the events that the widget will receive when @device operates on it.
9394 * Returns: device event mask for @widget
9399 gtk_widget_get_device_events (GtkWidget *widget,
9402 GHashTable *device_events;
9404 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9405 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9407 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9412 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9416 * gtk_widget_get_extension_events:
9417 * @widget: a #GtkWidget
9419 * Retrieves the extension events the widget will receive; see
9420 * gdk_input_set_extension_events().
9422 * Return value: extension events for @widget
9425 gtk_widget_get_extension_events (GtkWidget *widget)
9427 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9429 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9433 * gtk_widget_get_pointer:
9434 * @widget: a #GtkWidget
9435 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9436 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9438 * Obtains the location of the mouse pointer in widget coordinates.
9439 * Widget coordinates are a bit odd; for historical reasons, they are
9440 * defined as @widget->window coordinates for widgets that are not
9441 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9442 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9445 gtk_widget_get_pointer (GtkWidget *widget,
9449 GtkWidgetPrivate *priv;
9451 g_return_if_fail (GTK_IS_WIDGET (widget));
9453 priv = widget->priv;
9460 if (gtk_widget_get_realized (widget))
9462 gdk_window_get_pointer (priv->window, x, y, NULL);
9464 if (!gtk_widget_get_has_window (widget))
9467 *x -= priv->allocation.x;
9469 *y -= priv->allocation.y;
9475 * gtk_widget_is_ancestor:
9476 * @widget: a #GtkWidget
9477 * @ancestor: another #GtkWidget
9479 * Determines whether @widget is somewhere inside @ancestor, possibly with
9480 * intermediate containers.
9482 * Return value: %TRUE if @ancestor contains @widget as a child,
9483 * grandchild, great grandchild, etc.
9486 gtk_widget_is_ancestor (GtkWidget *widget,
9487 GtkWidget *ancestor)
9489 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9490 g_return_val_if_fail (ancestor != NULL, FALSE);
9494 if (widget->priv->parent == ancestor)
9496 widget = widget->priv->parent;
9502 static GQuark quark_composite_name = 0;
9505 * gtk_widget_set_composite_name:
9506 * @widget: a #GtkWidget.
9507 * @name: the name to set
9509 * Sets a widgets composite name. The widget must be
9510 * a composite child of its parent; see gtk_widget_push_composite_child().
9513 gtk_widget_set_composite_name (GtkWidget *widget,
9516 g_return_if_fail (GTK_IS_WIDGET (widget));
9517 g_return_if_fail (widget->priv->composite_child);
9518 g_return_if_fail (name != NULL);
9520 if (!quark_composite_name)
9521 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9523 g_object_set_qdata_full (G_OBJECT (widget),
9524 quark_composite_name,
9530 * gtk_widget_get_composite_name:
9531 * @widget: a #GtkWidget
9533 * Obtains the composite name of a widget.
9535 * Returns: the composite name of @widget, or %NULL if @widget is not
9536 * a composite child. The string should be freed when it is no
9540 gtk_widget_get_composite_name (GtkWidget *widget)
9542 GtkWidgetPrivate *priv;
9544 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9546 priv = widget->priv;
9548 if (widget->priv->composite_child && priv->parent)
9549 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9556 * gtk_widget_push_composite_child:
9558 * Makes all newly-created widgets as composite children until
9559 * the corresponding gtk_widget_pop_composite_child() call.
9561 * A composite child is a child that's an implementation detail of the
9562 * container it's inside and should not be visible to people using the
9563 * container. Composite children aren't treated differently by GTK (but
9564 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9565 * builders might want to treat them in a different way.
9567 * Here is a simple example:
9569 * gtk_widget_push_composite_child ();
9570 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9571 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9572 * gtk_widget_pop_composite_child ();
9573 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9574 * GTK_WIDGET (scrolled_window));
9575 * g_object_ref (scrolled_window->hscrollbar);
9579 gtk_widget_push_composite_child (void)
9581 composite_child_stack++;
9585 * gtk_widget_pop_composite_child:
9587 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9590 gtk_widget_pop_composite_child (void)
9592 if (composite_child_stack)
9593 composite_child_stack--;
9597 gtk_widget_emit_direction_changed (GtkWidget *widget,
9598 GtkTextDirection old_dir)
9600 gtk_widget_update_pango_context (widget);
9602 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9606 * gtk_widget_set_direction:
9607 * @widget: a #GtkWidget
9608 * @dir: the new direction
9610 * Sets the reading direction on a particular widget. This direction
9611 * controls the primary direction for widgets containing text,
9612 * and also the direction in which the children of a container are
9613 * packed. The ability to set the direction is present in order
9614 * so that correct localization into languages with right-to-left
9615 * reading directions can be done. Generally, applications will
9616 * let the default reading direction present, except for containers
9617 * where the containers are arranged in an order that is explicitely
9618 * visual rather than logical (such as buttons for text justification).
9620 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9621 * set by gtk_widget_set_default_direction() will be used.
9624 gtk_widget_set_direction (GtkWidget *widget,
9625 GtkTextDirection dir)
9627 GtkTextDirection old_dir;
9629 g_return_if_fail (GTK_IS_WIDGET (widget));
9630 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9632 old_dir = gtk_widget_get_direction (widget);
9634 widget->priv->direction = dir;
9636 if (old_dir != gtk_widget_get_direction (widget))
9637 gtk_widget_emit_direction_changed (widget, old_dir);
9641 * gtk_widget_get_direction:
9642 * @widget: a #GtkWidget
9644 * Gets the reading direction for a particular widget. See
9645 * gtk_widget_set_direction().
9647 * Return value: the reading direction for the widget.
9650 gtk_widget_get_direction (GtkWidget *widget)
9652 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9654 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9655 return gtk_default_direction;
9657 return widget->priv->direction;
9661 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9663 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9665 g_object_ref (widget);
9667 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9668 gtk_widget_emit_direction_changed (widget, old_dir);
9670 if (GTK_IS_CONTAINER (widget))
9671 gtk_container_forall (GTK_CONTAINER (widget),
9672 gtk_widget_set_default_direction_recurse,
9675 g_object_unref (widget);
9679 * gtk_widget_set_default_direction:
9680 * @dir: the new default direction. This cannot be
9681 * %GTK_TEXT_DIR_NONE.
9683 * Sets the default reading direction for widgets where the
9684 * direction has not been explicitly set by gtk_widget_set_direction().
9687 gtk_widget_set_default_direction (GtkTextDirection dir)
9689 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9691 if (dir != gtk_default_direction)
9693 GList *toplevels, *tmp_list;
9694 GtkTextDirection old_dir = gtk_default_direction;
9696 gtk_default_direction = dir;
9698 tmp_list = toplevels = gtk_window_list_toplevels ();
9699 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9703 gtk_widget_set_default_direction_recurse (tmp_list->data,
9704 GUINT_TO_POINTER (old_dir));
9705 g_object_unref (tmp_list->data);
9706 tmp_list = tmp_list->next;
9709 g_list_free (toplevels);
9714 * gtk_widget_get_default_direction:
9716 * Obtains the current default reading direction. See
9717 * gtk_widget_set_default_direction().
9719 * Return value: the current default direction.
9722 gtk_widget_get_default_direction (void)
9724 return gtk_default_direction;
9728 gtk_widget_dispose (GObject *object)
9730 GtkWidget *widget = GTK_WIDGET (object);
9731 GtkWidgetPrivate *priv = widget->priv;
9734 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9735 else if (gtk_widget_get_visible (widget))
9736 gtk_widget_hide (widget);
9738 priv->visible = FALSE;
9739 if (gtk_widget_get_realized (widget))
9740 gtk_widget_unrealize (widget);
9742 if (!priv->in_destruction)
9744 priv->in_destruction = TRUE;
9745 g_signal_emit (object, widget_signals[DESTROY], 0);
9746 priv->in_destruction = FALSE;
9749 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9753 gtk_widget_real_destroy (GtkWidget *object)
9755 /* gtk_object_destroy() will already hold a refcount on object */
9756 GtkWidget *widget = GTK_WIDGET (object);
9757 GtkWidgetPrivate *priv = widget->priv;
9759 /* wipe accelerator closures (keep order) */
9760 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9761 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9763 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9764 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9766 gtk_grab_remove (widget);
9768 g_object_unref (priv->style);
9769 priv->style = gtk_widget_get_default_style ();
9770 g_object_ref (priv->style);
9774 gtk_widget_finalize (GObject *object)
9776 GtkWidget *widget = GTK_WIDGET (object);
9777 GtkWidgetPrivate *priv = widget->priv;
9778 GtkWidgetAuxInfo *aux_info;
9779 GtkAccessible *accessible;
9781 gtk_grab_remove (widget);
9783 g_object_unref (priv->style);
9786 g_free (priv->name);
9788 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9790 gtk_widget_aux_info_destroy (aux_info);
9792 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9794 g_object_unref (accessible);
9796 if (g_object_is_floating (object))
9797 g_warning ("A floating object was finalized. This means that someone\n"
9798 "called g_object_unref() on an object that had only a floating\n"
9799 "reference; the initial floating reference is not owned by anyone\n"
9800 "and must be removed with g_object_ref_sink().");
9802 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9805 /*****************************************
9806 * gtk_widget_real_map:
9811 *****************************************/
9814 gtk_widget_real_map (GtkWidget *widget)
9816 GtkWidgetPrivate *priv = widget->priv;
9818 g_assert (gtk_widget_get_realized (widget));
9820 if (!gtk_widget_get_mapped (widget))
9822 gtk_widget_set_mapped (widget, TRUE);
9824 if (gtk_widget_get_has_window (widget))
9825 gdk_window_show (priv->window);
9829 /*****************************************
9830 * gtk_widget_real_unmap:
9835 *****************************************/
9838 gtk_widget_real_unmap (GtkWidget *widget)
9840 GtkWidgetPrivate *priv = widget->priv;
9842 if (gtk_widget_get_mapped (widget))
9844 gtk_widget_set_mapped (widget, FALSE);
9846 if (gtk_widget_get_has_window (widget))
9847 gdk_window_hide (priv->window);
9851 /*****************************************
9852 * gtk_widget_real_realize:
9857 *****************************************/
9860 gtk_widget_real_realize (GtkWidget *widget)
9862 GtkWidgetPrivate *priv = widget->priv;
9864 g_assert (!gtk_widget_get_has_window (widget));
9866 gtk_widget_set_realized (widget, TRUE);
9869 priv->window = gtk_widget_get_parent_window (widget);
9870 g_object_ref (priv->window);
9872 priv->style = gtk_style_attach (priv->style, priv->window);
9875 /*****************************************
9876 * gtk_widget_real_unrealize:
9881 *****************************************/
9884 gtk_widget_real_unrealize (GtkWidget *widget)
9886 GtkWidgetPrivate *priv = widget->priv;
9888 if (gtk_widget_get_mapped (widget))
9889 gtk_widget_real_unmap (widget);
9891 gtk_widget_set_mapped (widget, FALSE);
9893 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9896 /* We must do unrealize child widget BEFORE container widget.
9897 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9898 * So, unrealizing container widget bofore its children causes the problem
9899 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9902 if (GTK_IS_CONTAINER (widget))
9903 gtk_container_forall (GTK_CONTAINER (widget),
9904 (GtkCallback) gtk_widget_unrealize,
9907 gtk_style_detach (priv->style);
9908 if (gtk_widget_get_has_window (widget))
9910 gdk_window_set_user_data (priv->window, NULL);
9911 gdk_window_destroy (priv->window);
9912 priv->window = NULL;
9916 g_object_unref (priv->window);
9917 priv->window = NULL;
9920 gtk_selection_remove_all (widget);
9922 gtk_widget_set_realized (widget, FALSE);
9926 gtk_widget_real_size_request (GtkWidget *widget,
9927 GtkRequisition *requisition)
9929 requisition->width = 0;
9930 requisition->height = 0;
9934 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9935 GtkOrientation orientation,
9939 const GtkWidgetAuxInfo *aux_info;
9941 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9943 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9944 aux_info->width > 0)
9946 *minimum_size = MAX (*minimum_size, aux_info->width);
9948 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9949 aux_info->height > 0)
9951 *minimum_size = MAX (*minimum_size, aux_info->height);
9954 /* Fix it if set_size_request made natural size smaller than min size.
9955 * This would also silently fix broken widgets, but we warn about them
9956 * in gtksizerequest.c when calling their size request vfuncs.
9958 *natural_size = MAX (*natural_size, *minimum_size);
9960 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9962 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9963 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9967 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9968 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9973 * _gtk_widget_peek_request_cache:
9975 * Returns the address of the widget's request cache (strictly for
9976 * internal use in gtksizerequest.c)
9978 * Return value: the address of @widget's size request cache.
9981 _gtk_widget_peek_request_cache (GtkWidget *widget)
9983 /* Don't bother slowing things down with the return_if_fail guards here */
9984 return &widget->priv->requests;
9988 * _gtk_widget_set_device_window:
9989 * @widget: a #GtkWidget.
9990 * @device: a #GdkDevice.
9991 * @window: the new device window.
9993 * Sets pointer window for @widget and @device. Does not ref @window.
9994 * Actually stores it on the #GdkScreen, but you don't need to know that.
9997 _gtk_widget_set_device_window (GtkWidget *widget,
10001 GtkWidgetPrivate *priv;
10003 GHashTable *device_window;
10005 g_return_if_fail (GTK_IS_WIDGET (widget));
10006 g_return_if_fail (GDK_IS_DEVICE (device));
10007 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10009 priv = widget->priv;
10011 if (!gtk_widget_get_realized (widget))
10014 screen = gdk_window_get_screen (priv->window);
10015 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10017 if (G_UNLIKELY (!device_window))
10019 device_window = g_hash_table_new (NULL, NULL);
10020 g_object_set_qdata_full (G_OBJECT (screen),
10021 quark_pointer_window,
10023 (GDestroyNotify) g_hash_table_destroy);
10027 g_hash_table_insert (device_window, device, window);
10029 g_hash_table_remove (device_window, device);
10033 * _gtk_widget_get_device_window:
10034 * @widget: a #GtkWidget.
10035 * @device: a #GdkDevice.
10037 * Return value: the device window set on the #GdkScreen @widget is attached
10041 _gtk_widget_get_device_window (GtkWidget *widget,
10044 GtkWidgetPrivate *priv;
10046 GHashTable *device_window;
10050 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10051 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10053 priv = widget->priv;
10055 if (!gtk_widget_get_realized (widget))
10058 screen = gdk_window_get_screen (priv->window);
10059 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10061 if (G_UNLIKELY (!device_window))
10064 window = g_hash_table_lookup (device_window, device);
10069 gdk_window_get_user_data (window, (gpointer *) &w);
10078 * _gtk_widget_list_devices:
10079 * @widget: a #GtkWidget.
10081 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10082 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10086 _gtk_widget_list_devices (GtkWidget *widget)
10088 GtkWidgetPrivate *priv;
10090 GHashTableIter iter;
10091 GHashTable *device_window;
10092 GList *devices = NULL;
10093 gpointer key, value;
10095 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10097 priv = widget->priv;
10099 if (!gtk_widget_get_realized (widget))
10102 screen = gdk_window_get_screen (priv->window);
10103 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10105 if (G_UNLIKELY (!device_window))
10108 g_hash_table_iter_init (&iter, device_window);
10110 while (g_hash_table_iter_next (&iter, &key, &value))
10112 GdkDevice *device = key;
10113 GdkWindow *window = value;
10118 gdk_window_get_user_data (window, (gpointer *) &w);
10121 devices = g_list_prepend (devices, device);
10129 synth_crossing (GtkWidget *widget,
10133 GdkCrossingMode mode,
10134 GdkNotifyType detail)
10138 event = gdk_event_new (type);
10140 event->crossing.window = g_object_ref (window);
10141 event->crossing.send_event = TRUE;
10142 event->crossing.subwindow = g_object_ref (window);
10143 event->crossing.time = GDK_CURRENT_TIME;
10144 event->crossing.x = event->crossing.y = 0;
10145 event->crossing.x_root = event->crossing.y_root = 0;
10146 event->crossing.mode = mode;
10147 event->crossing.detail = detail;
10148 event->crossing.focus = FALSE;
10149 event->crossing.state = 0;
10150 gdk_event_set_device (event, device);
10153 widget = gtk_get_event_widget (event);
10156 gtk_widget_event_internal (widget, event);
10158 gdk_event_free (event);
10162 * _gtk_widget_synthesize_crossing:
10163 * @from: the #GtkWidget the virtual pointer is leaving.
10164 * @to: the #GtkWidget the virtual pointer is moving to.
10165 * @mode: the #GdkCrossingMode to place on the synthesized events.
10167 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10169 * The real pointer window is the window that most recently received an enter notify
10170 * event. Windows that don't select for crossing events can't become the real
10171 * poiner window. The real pointer widget that owns the real pointer window. The
10172 * effective pointer window is the same as the real pointer window unless the real
10173 * pointer widget is either insensitive or there is a grab on a widget that is not
10174 * an ancestor of the real pointer widget (in which case the effective pointer
10175 * window should be the root window).
10177 * When the effective pointer window is the same as the real poiner window, we
10178 * receive crossing events from the windowing system. When the effective pointer
10179 * window changes to become different from the real pointer window we synthesize
10180 * crossing events, attempting to follow X protocol rules:
10182 * When the root window becomes the effective pointer window:
10183 * - leave notify on real pointer window, detail Ancestor
10184 * - leave notify on all of its ancestors, detail Virtual
10185 * - enter notify on root window, detail Inferior
10187 * When the root window ceases to be the effective pointer window:
10188 * - leave notify on root window, detail Inferior
10189 * - enter notify on all ancestors of real pointer window, detail Virtual
10190 * - enter notify on real pointer window, detail Ancestor
10193 _gtk_widget_synthesize_crossing (GtkWidget *from,
10196 GdkCrossingMode mode)
10198 GdkWindow *from_window = NULL, *to_window = NULL;
10200 g_return_if_fail (from != NULL || to != NULL);
10204 from_window = _gtk_widget_get_device_window (from, device);
10207 from_window = from->priv->window;
10212 to_window = _gtk_widget_get_device_window (to, device);
10215 to_window = to->priv->window;
10218 if (from_window == NULL && to_window == NULL)
10220 else if (from_window != NULL && to_window == NULL)
10222 GList *from_ancestors = NULL, *list;
10223 GdkWindow *from_ancestor = from_window;
10225 while (from_ancestor != NULL)
10227 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10228 if (from_ancestor == NULL)
10230 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10233 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10234 device, mode, GDK_NOTIFY_ANCESTOR);
10235 for (list = g_list_last (from_ancestors); list; list = list->prev)
10237 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10238 device, mode, GDK_NOTIFY_VIRTUAL);
10241 /* XXX: enter/inferior on root window? */
10243 g_list_free (from_ancestors);
10245 else if (from_window == NULL && to_window != NULL)
10247 GList *to_ancestors = NULL, *list;
10248 GdkWindow *to_ancestor = to_window;
10250 while (to_ancestor != NULL)
10252 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10253 if (to_ancestor == NULL)
10255 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10258 /* XXX: leave/inferior on root window? */
10260 for (list = to_ancestors; list; list = list->next)
10262 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10263 device, mode, GDK_NOTIFY_VIRTUAL);
10265 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10266 device, mode, GDK_NOTIFY_ANCESTOR);
10268 g_list_free (to_ancestors);
10270 else if (from_window == to_window)
10274 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10275 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10277 while (from_ancestor != NULL || to_ancestor != NULL)
10279 if (from_ancestor != NULL)
10281 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10282 if (from_ancestor == to_window)
10285 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10287 if (to_ancestor != NULL)
10289 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10290 if (to_ancestor == from_window)
10293 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10296 if (to_ancestor == from_window)
10298 if (mode != GDK_CROSSING_GTK_UNGRAB)
10299 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10300 device, mode, GDK_NOTIFY_INFERIOR);
10301 for (list = to_ancestors; list; list = list->next)
10302 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10303 device, mode, GDK_NOTIFY_VIRTUAL);
10304 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10305 device, mode, GDK_NOTIFY_ANCESTOR);
10307 else if (from_ancestor == to_window)
10309 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10310 device, mode, GDK_NOTIFY_ANCESTOR);
10311 for (list = g_list_last (from_ancestors); list; list = list->prev)
10313 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10314 device, mode, GDK_NOTIFY_VIRTUAL);
10316 if (mode != GDK_CROSSING_GTK_GRAB)
10317 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10318 device, mode, GDK_NOTIFY_INFERIOR);
10322 while (from_ancestors != NULL && to_ancestors != NULL
10323 && from_ancestors->data == to_ancestors->data)
10325 from_ancestors = g_list_delete_link (from_ancestors,
10327 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10330 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10331 device, mode, GDK_NOTIFY_NONLINEAR);
10333 for (list = g_list_last (from_ancestors); list; list = list->prev)
10335 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10336 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10338 for (list = to_ancestors; list; list = list->next)
10340 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10341 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10343 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10344 device, mode, GDK_NOTIFY_NONLINEAR);
10346 g_list_free (from_ancestors);
10347 g_list_free (to_ancestors);
10352 gtk_widget_propagate_state (GtkWidget *widget,
10353 GtkStateData *data)
10355 GtkWidgetPrivate *priv = widget->priv;
10356 guint8 old_state = gtk_widget_get_state (widget);
10357 guint8 old_saved_state = priv->saved_state;
10359 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10360 * parent_sensitive==TRUE on a sensitive widget
10364 priv->parent_sensitive = data->parent_sensitive;
10366 if (gtk_widget_is_sensitive (widget))
10368 if (data->state_restoration)
10369 priv->state = priv->saved_state;
10371 priv->state = data->state;
10375 if (!data->state_restoration)
10377 if (data->state != GTK_STATE_INSENSITIVE)
10378 priv->saved_state = data->state;
10380 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10381 priv->saved_state = gtk_widget_get_state (widget);
10382 priv->state = GTK_STATE_INSENSITIVE;
10385 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10389 window = gtk_widget_get_toplevel (widget);
10390 if (window && gtk_widget_is_toplevel (window))
10391 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10394 if (old_state != gtk_widget_get_state (widget) ||
10395 old_saved_state != priv->saved_state)
10397 g_object_ref (widget);
10399 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10400 gtk_grab_remove (widget);
10402 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10404 if (!priv->shadowed)
10406 GList *event_windows = NULL;
10407 GList *devices, *d;
10409 devices = _gtk_widget_list_devices (widget);
10411 for (d = devices; d; d = d->next)
10417 window = _gtk_widget_get_device_window (widget, device);
10419 /* Do not propagate more than once to the
10420 * same window if non-multidevice aware.
10422 if (!gdk_window_get_support_multidevice (window) &&
10423 g_list_find (event_windows, window))
10426 if (!gtk_widget_is_sensitive (widget))
10427 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10428 GDK_CROSSING_STATE_CHANGED);
10429 else if (old_state == GTK_STATE_INSENSITIVE)
10430 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10431 GDK_CROSSING_STATE_CHANGED);
10433 event_windows = g_list_prepend (event_windows, window);
10436 g_list_free (event_windows);
10437 g_list_free (devices);
10440 if (GTK_IS_CONTAINER (widget))
10442 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10443 if (data->use_forall)
10444 gtk_container_forall (GTK_CONTAINER (widget),
10445 (GtkCallback) gtk_widget_propagate_state,
10448 gtk_container_foreach (GTK_CONTAINER (widget),
10449 (GtkCallback) gtk_widget_propagate_state,
10452 g_object_unref (widget);
10456 static const GtkWidgetAuxInfo default_aux_info = {
10464 * _gtk_widget_get_aux_info:
10465 * @widget: a #GtkWidget
10466 * @create: if %TRUE, create the structure if it doesn't exist
10468 * Get the #GtkWidgetAuxInfo structure for the widget.
10470 * Return value: the #GtkAuxInfo structure for the widget, or
10471 * %NULL if @create is %FALSE and one doesn't already exist.
10474 _gtk_widget_get_aux_info (GtkWidget *widget,
10477 GtkWidgetAuxInfo *aux_info;
10479 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10480 if (!aux_info && create)
10482 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10484 *aux_info = default_aux_info;
10486 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10492 static const GtkWidgetAuxInfo*
10493 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10495 GtkWidgetAuxInfo *aux_info;
10497 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10498 if (aux_info == NULL)
10500 return &default_aux_info;
10508 /*****************************************
10509 * gtk_widget_aux_info_destroy:
10514 *****************************************/
10517 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10519 g_slice_free (GtkWidgetAuxInfo, aux_info);
10523 * gtk_widget_shape_combine_region:
10524 * @widget: a #GtkWidget
10525 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10527 * Sets a shape for this widget's GDK window. This allows for
10528 * transparent windows etc., see gdk_window_shape_combine_region()
10529 * for more information.
10534 gtk_widget_shape_combine_region (GtkWidget *widget,
10535 cairo_region_t *region)
10537 GtkWidgetPrivate *priv;
10539 g_return_if_fail (GTK_IS_WIDGET (widget));
10540 /* set_shape doesn't work on widgets without gdk window */
10541 g_return_if_fail (gtk_widget_get_has_window (widget));
10543 priv = widget->priv;
10545 if (region == NULL)
10547 priv->has_shape_mask = FALSE;
10550 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10552 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10556 priv->has_shape_mask = TRUE;
10558 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10559 cairo_region_copy (region),
10560 (GDestroyNotify) cairo_region_destroy);
10562 /* set shape if widget has a gdk window already.
10563 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10566 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10571 * gtk_widget_input_shape_combine_region:
10572 * @widget: a #GtkWidget
10573 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10575 * Sets an input shape for this widget's GDK window. This allows for
10576 * windows which react to mouse click in a nonrectangular region, see
10577 * gdk_window_input_shape_combine_region() for more information.
10582 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10583 cairo_region_t *region)
10585 GtkWidgetPrivate *priv;
10587 g_return_if_fail (GTK_IS_WIDGET (widget));
10588 /* set_shape doesn't work on widgets without gdk window */
10589 g_return_if_fail (gtk_widget_get_has_window (widget));
10591 priv = widget->priv;
10593 if (region == NULL)
10596 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10598 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10602 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10603 cairo_region_copy (region),
10604 (GDestroyNotify) cairo_region_destroy);
10606 /* set shape if widget has a gdk window already.
10607 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10610 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10616 gtk_reset_shapes_recurse (GtkWidget *widget,
10622 gdk_window_get_user_data (window, &data);
10623 if (data != widget)
10626 gdk_window_shape_combine_region (window, NULL, 0, 0);
10627 for (list = gdk_window_peek_children (window); list; list = list->next)
10628 gtk_reset_shapes_recurse (widget, list->data);
10632 * gtk_widget_reset_shapes:
10633 * @widget: a #GtkWidget
10635 * Recursively resets the shape on this widget and its descendants.
10638 gtk_widget_reset_shapes (GtkWidget *widget)
10640 GtkWidgetPrivate *priv;
10642 g_return_if_fail (GTK_IS_WIDGET (widget));
10643 g_return_if_fail (gtk_widget_get_realized (widget));
10645 priv = widget->priv;
10647 if (!priv->has_shape_mask)
10648 gtk_reset_shapes_recurse (widget, priv->window);
10651 /* style properties
10655 * gtk_widget_class_install_style_property_parser:
10656 * @klass: a #GtkWidgetClass
10657 * @pspec: the #GParamSpec for the style property
10658 * @parser: the parser for the style property
10660 * Installs a style property on a widget class.
10663 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10665 GtkRcPropertyParser parser)
10667 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10668 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10669 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10670 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10672 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10674 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10675 G_OBJECT_CLASS_NAME (klass),
10680 g_param_spec_ref_sink (pspec);
10681 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10682 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10686 * gtk_widget_class_install_style_property:
10687 * @klass: a #GtkWidgetClass
10688 * @pspec: the #GParamSpec for the property
10690 * Installs a style property on a widget class. The parser for the
10691 * style property is determined by the value type of @pspec.
10694 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10697 GtkRcPropertyParser parser;
10699 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10700 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10702 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10704 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10708 * gtk_widget_class_find_style_property:
10709 * @klass: a #GtkWidgetClass
10710 * @property_name: the name of the style property to find
10711 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10712 * style property with that name.
10714 * Finds a style property of a widget class by name.
10719 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10720 const gchar *property_name)
10722 g_return_val_if_fail (property_name != NULL, NULL);
10724 return g_param_spec_pool_lookup (style_property_spec_pool,
10726 G_OBJECT_CLASS_TYPE (klass),
10731 * gtk_widget_class_list_style_properties:
10732 * @klass: a #GtkWidgetClass
10733 * @n_properties: location to return the number of style properties found
10734 * @returns: an newly allocated array of #GParamSpec*. The array must
10735 * be freed with g_free().
10737 * Returns all style properties of a widget class.
10742 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10743 guint *n_properties)
10745 GParamSpec **pspecs;
10748 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10749 G_OBJECT_CLASS_TYPE (klass),
10758 * gtk_widget_style_get_property:
10759 * @widget: a #GtkWidget
10760 * @property_name: the name of a style property
10761 * @value: location to return the property value
10763 * Gets the value of a style property of @widget.
10766 gtk_widget_style_get_property (GtkWidget *widget,
10767 const gchar *property_name,
10770 GtkWidgetPrivate *priv;
10773 g_return_if_fail (GTK_IS_WIDGET (widget));
10774 g_return_if_fail (property_name != NULL);
10775 g_return_if_fail (G_IS_VALUE (value));
10777 priv = widget->priv;
10779 g_object_ref (widget);
10780 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10782 G_OBJECT_TYPE (widget),
10785 g_warning ("%s: widget class `%s' has no property named `%s'",
10787 G_OBJECT_TYPE_NAME (widget),
10791 const GValue *peek_value;
10793 peek_value = _gtk_style_peek_property_value (priv->style,
10794 G_OBJECT_TYPE (widget),
10796 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10798 /* auto-conversion of the caller's value type
10800 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10801 g_value_copy (peek_value, value);
10802 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10803 g_value_transform (peek_value, value);
10805 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10807 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10808 G_VALUE_TYPE_NAME (value));
10810 g_object_unref (widget);
10814 * gtk_widget_style_get_valist:
10815 * @widget: a #GtkWidget
10816 * @first_property_name: the name of the first property to get
10817 * @var_args: a <type>va_list</type> of pairs of property names and
10818 * locations to return the property values, starting with the location
10819 * for @first_property_name.
10821 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10825 gtk_widget_style_get_valist (GtkWidget *widget,
10826 const gchar *first_property_name,
10829 GtkWidgetPrivate *priv;
10832 g_return_if_fail (GTK_IS_WIDGET (widget));
10834 priv = widget->priv;
10836 g_object_ref (widget);
10838 name = first_property_name;
10841 const GValue *peek_value;
10845 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10847 G_OBJECT_TYPE (widget),
10851 g_warning ("%s: widget class `%s' has no property named `%s'",
10853 G_OBJECT_TYPE_NAME (widget),
10857 /* style pspecs are always readable so we can spare that check here */
10859 peek_value = _gtk_style_peek_property_value (priv->style,
10860 G_OBJECT_TYPE (widget),
10862 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10863 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10866 g_warning ("%s: %s", G_STRLOC, error);
10871 name = va_arg (var_args, gchar*);
10874 g_object_unref (widget);
10878 * gtk_widget_style_get:
10879 * @widget: a #GtkWidget
10880 * @first_property_name: the name of the first property to get
10881 * @Varargs: pairs of property names and locations to
10882 * return the property values, starting with the location for
10883 * @first_property_name, terminated by %NULL.
10885 * Gets the values of a multiple style properties of @widget.
10888 gtk_widget_style_get (GtkWidget *widget,
10889 const gchar *first_property_name,
10894 g_return_if_fail (GTK_IS_WIDGET (widget));
10896 va_start (var_args, first_property_name);
10897 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10903 * @widget: a #GtkWidget
10904 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10905 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10906 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10908 * Obtains the full path to @widget. The path is simply the name of a
10909 * widget and all its parents in the container hierarchy, separated by
10910 * periods. The name of a widget comes from
10911 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10912 * in gtkrc configuration files. Widget names are the type of the
10913 * widget by default (e.g. "GtkButton") or can be set to an
10914 * application-specific value with gtk_widget_set_name(). By setting
10915 * the name of a widget, you allow users or theme authors to apply
10916 * styles to that specific widget in their gtkrc
10917 * file. @path_reversed_p fills in the path in reverse order,
10918 * i.e. starting with @widget's name instead of starting with the name
10919 * of @widget's outermost ancestor.
10922 gtk_widget_path (GtkWidget *widget,
10923 guint *path_length,
10925 gchar **path_reversed)
10927 static gchar *rev_path = NULL;
10928 static guint tmp_path_len = 0;
10931 g_return_if_fail (GTK_IS_WIDGET (widget));
10936 const gchar *string;
10941 string = gtk_widget_get_name (widget);
10942 l = strlen (string);
10943 while (tmp_path_len <= len + l + 1)
10945 tmp_path_len += INIT_PATH_SIZE;
10946 rev_path = g_realloc (rev_path, tmp_path_len);
10948 s = string + l - 1;
10949 d = rev_path + len;
10950 while (s >= string)
10954 widget = widget->priv->parent;
10957 rev_path[len++] = '.';
10959 rev_path[len++] = 0;
10964 *path_length = len - 1;
10966 *path_reversed = g_strdup (rev_path);
10969 *path = g_strdup (rev_path);
10970 g_strreverse (*path);
10975 * gtk_widget_class_path:
10976 * @widget: a #GtkWidget
10977 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10978 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10979 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10982 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10983 * never uses a custom name set with gtk_widget_set_name().
10987 gtk_widget_class_path (GtkWidget *widget,
10988 guint *path_length,
10990 gchar **path_reversed)
10992 static gchar *rev_path = NULL;
10993 static guint tmp_path_len = 0;
10996 g_return_if_fail (GTK_IS_WIDGET (widget));
11001 const gchar *string;
11006 string = g_type_name (G_OBJECT_TYPE (widget));
11007 l = strlen (string);
11008 while (tmp_path_len <= len + l + 1)
11010 tmp_path_len += INIT_PATH_SIZE;
11011 rev_path = g_realloc (rev_path, tmp_path_len);
11013 s = string + l - 1;
11014 d = rev_path + len;
11015 while (s >= string)
11019 widget = widget->priv->parent;
11022 rev_path[len++] = '.';
11024 rev_path[len++] = 0;
11029 *path_length = len - 1;
11031 *path_reversed = g_strdup (rev_path);
11034 *path = g_strdup (rev_path);
11035 g_strreverse (*path);
11040 * gtk_requisition_new:
11042 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11044 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11045 * be freed with gtk_requisition_free().
11050 gtk_requisition_new (void)
11052 return g_slice_new0 (GtkRequisition);
11056 * gtk_requisition_copy:
11057 * @requisition: a #GtkRequisition
11059 * Copies a #GtkRequisition.
11061 * Returns: a copy of @requisition
11064 gtk_requisition_copy (const GtkRequisition *requisition)
11066 return g_slice_dup (GtkRequisition, requisition);
11070 * gtk_requisition_free:
11071 * @requisition: a #GtkRequisition
11073 * Frees a #GtkRequisition.
11076 gtk_requisition_free (GtkRequisition *requisition)
11078 g_slice_free (GtkRequisition, requisition);
11081 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11082 gtk_requisition_copy,
11083 gtk_requisition_free)
11086 * gtk_widget_get_accessible:
11087 * @widget: a #GtkWidget
11089 * Returns the accessible object that describes the widget to an
11090 * assistive technology.
11092 * If no accessibility library is loaded (i.e. no ATK implementation library is
11093 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11094 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11095 * if no class-specific #AtkObject implementation is available for the widget
11096 * instance in question, it will inherit an #AtkObject implementation from the
11097 * first ancestor class for which such an implementation is defined.
11099 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
11100 * library contains more information about accessible objects and their uses.
11102 * Returns: (transfer none): the #AtkObject associated with @widget
11105 gtk_widget_get_accessible (GtkWidget *widget)
11107 GtkWidgetClass *klass;
11109 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11111 klass = GTK_WIDGET_GET_CLASS (widget);
11113 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11115 return klass->get_accessible (widget);
11119 gtk_widget_real_get_accessible (GtkWidget *widget)
11121 AtkObject* accessible;
11123 accessible = g_object_get_qdata (G_OBJECT (widget),
11124 quark_accessible_object);
11127 AtkObjectFactory *factory;
11128 AtkRegistry *default_registry;
11130 default_registry = atk_get_default_registry ();
11131 factory = atk_registry_get_factory (default_registry,
11132 G_TYPE_FROM_INSTANCE (widget));
11134 atk_object_factory_create_accessible (factory,
11135 G_OBJECT (widget));
11136 g_object_set_qdata (G_OBJECT (widget),
11137 quark_accessible_object,
11144 * Initialize a AtkImplementorIface instance's virtual pointers as
11145 * appropriate to this implementor's class (GtkWidget).
11148 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11150 iface->ref_accessible = gtk_widget_ref_accessible;
11154 gtk_widget_ref_accessible (AtkImplementor *implementor)
11156 AtkObject *accessible;
11158 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11160 g_object_ref (accessible);
11165 * Expand flag management
11169 gtk_widget_update_computed_expand (GtkWidget *widget)
11171 GtkWidgetPrivate *priv;
11173 priv = widget->priv;
11175 if (priv->need_compute_expand)
11179 if (priv->hexpand_set)
11184 if (priv->vexpand_set)
11189 /* we don't need to use compute_expand if both expands are
11190 * forced by the app
11192 if (!(priv->hexpand_set && priv->vexpand_set))
11194 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11198 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11199 priv->hexpand_set ? &ignored : &h,
11200 priv->vexpand_set ? &ignored : &v);
11204 priv->need_compute_expand = FALSE;
11205 priv->computed_hexpand = h != FALSE;
11206 priv->computed_vexpand = v != FALSE;
11211 * gtk_widget_queue_compute_expand:
11212 * @widget: a #GtkWidget
11214 * Mark @widget as needing to recompute its expand flags. Call
11215 * this function when setting legacy expand child properties
11216 * on the child of a container.
11218 * See gtk_widget_compute_expand().
11221 gtk_widget_queue_compute_expand (GtkWidget *widget)
11224 gboolean changed_anything;
11226 if (widget->priv->need_compute_expand)
11229 changed_anything = FALSE;
11231 while (parent != NULL)
11233 if (!parent->priv->need_compute_expand)
11235 parent->priv->need_compute_expand = TRUE;
11236 changed_anything = TRUE;
11239 /* Note: if we had an invariant that "if a child needs to
11240 * compute expand, its parents also do" then we could stop going
11241 * up when we got to a parent that already needed to
11242 * compute. However, in general we compute expand lazily (as
11243 * soon as we see something in a subtree that is expand, we know
11244 * we're expanding) and so this invariant does not hold and we
11245 * have to always walk all the way up in case some ancestor
11246 * is not currently need_compute_expand.
11249 parent = parent->priv->parent;
11252 /* recomputing expand always requires
11253 * a relayout as well
11255 if (changed_anything)
11256 gtk_widget_queue_resize (widget);
11260 * gtk_widget_compute_expand:
11261 * @widget: the widget
11262 * @orientation: expand direction
11264 * Computes whether a container should give this widget extra space
11265 * when possible. Containers should check this, rather than
11266 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11268 * This function already checks whether the widget is visible, so
11269 * visibility does not need to be checked separately. Non-visible
11270 * widgets are not expanded.
11272 * The computed expand value uses either the expand setting explicitly
11273 * set on the widget itself, or, if none has been explicitly set,
11274 * the widget may expand if some of its children do.
11276 * Return value: whether widget tree rooted here should be expanded
11279 gtk_widget_compute_expand (GtkWidget *widget,
11280 GtkOrientation orientation)
11282 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11284 /* We never make a widget expand if not even showing. */
11285 if (!gtk_widget_get_visible (widget))
11288 gtk_widget_update_computed_expand (widget);
11290 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11292 return widget->priv->computed_hexpand;
11296 return widget->priv->computed_vexpand;
11301 gtk_widget_set_expand (GtkWidget *widget,
11302 GtkOrientation orientation,
11305 const char *expand_prop;
11306 const char *expand_set_prop;
11308 GtkWidgetPrivate *priv;
11310 g_return_if_fail (GTK_IS_WIDGET (widget));
11312 priv = widget->priv;
11314 expand = expand != FALSE;
11316 was_both = priv->hexpand && priv->vexpand;
11318 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11320 if (priv->hexpand_set &&
11321 priv->hexpand == expand)
11324 priv->hexpand_set = TRUE;
11325 priv->hexpand = expand;
11327 expand_prop = "hexpand";
11328 expand_set_prop = "hexpand-set";
11332 if (priv->vexpand_set &&
11333 priv->vexpand == expand)
11336 priv->vexpand_set = TRUE;
11337 priv->vexpand = expand;
11339 expand_prop = "vexpand";
11340 expand_set_prop = "vexpand-set";
11343 gtk_widget_queue_compute_expand (widget);
11345 g_object_freeze_notify (G_OBJECT (widget));
11346 g_object_notify (G_OBJECT (widget), expand_prop);
11347 g_object_notify (G_OBJECT (widget), expand_set_prop);
11348 if (was_both != (priv->hexpand && priv->vexpand))
11349 g_object_notify (G_OBJECT (widget), "expand");
11350 g_object_thaw_notify (G_OBJECT (widget));
11354 gtk_widget_set_expand_set (GtkWidget *widget,
11355 GtkOrientation orientation,
11358 GtkWidgetPrivate *priv;
11361 priv = widget->priv;
11363 set = set != FALSE;
11365 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11367 if (set == priv->hexpand_set)
11370 priv->hexpand_set = set;
11371 prop = "hexpand-set";
11375 if (set == priv->vexpand_set)
11378 priv->vexpand_set = set;
11379 prop = "vexpand-set";
11382 gtk_widget_queue_compute_expand (widget);
11384 g_object_notify (G_OBJECT (widget), prop);
11388 * gtk_widget_get_hexpand:
11389 * @widget: the widget
11391 * Gets whether the widget would like any available extra horizontal
11392 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11393 * generally receive the extra space. For example, a list or
11394 * scrollable area or document in your window would often be set to
11397 * Containers should use gtk_widget_compute_expand() rather than
11398 * this function, to see whether a widget, or any of its children,
11399 * has the expand flag set. If any child of a widget wants to
11400 * expand, the parent may ask to expand also.
11402 * This function only looks at the widget's own hexpand flag, rather
11403 * than computing whether the entire widget tree rooted at this widget
11406 * Return value: whether hexpand flag is set
11409 gtk_widget_get_hexpand (GtkWidget *widget)
11411 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11413 return widget->priv->hexpand;
11417 * gtk_widget_set_hexpand:
11418 * @widget: the widget
11419 * @expand: whether to expand
11421 * Sets whether the widget would like any available extra horizontal
11422 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11423 * generally receive the extra space. For example, a list or
11424 * scrollable area or document in your window would often be set to
11427 * Call this function to set the expand flag if you would like your
11428 * widget to become larger horizontally when the window has extra
11431 * By default, widgets automatically expand if any of their children
11432 * want to expand. (To see if a widget will automatically expand given
11433 * its current children and state, call gtk_widget_compute_expand(). A
11434 * container can decide how the expandability of children affects the
11435 * expansion of the container by overriding the compute_expand virtual
11436 * method on #GtkWidget.).
11438 * Setting hexpand explicitly with this function will override the
11439 * automatic expand behavior.
11441 * This function forces the widget to expand or not to expand,
11442 * regardless of children. The override occurs because
11443 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11444 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11445 * value to be used, rather than looking at children and widget state.
11448 gtk_widget_set_hexpand (GtkWidget *widget,
11451 g_return_if_fail (GTK_IS_WIDGET (widget));
11453 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11457 * gtk_widget_get_hexpand_set:
11458 * @widget: the widget
11460 * Gets whether gtk_widget_set_hexpand() has been used to
11461 * explicitly set the expand flag on this widget.
11463 * If hexpand is set, then it overrides any computed
11464 * expand value based on child widgets. If hexpand is not
11465 * set, then the expand value depends on whether any
11466 * children of the widget would like to expand.
11468 * There are few reasons to use this function, but it's here
11469 * for completeness and consistency.
11471 * Return value: whether hexpand has been explicitly set
11474 gtk_widget_get_hexpand_set (GtkWidget *widget)
11476 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11478 return widget->priv->hexpand_set;
11482 * gtk_widget_set_hexpand_set:
11483 * @widget: the widget
11484 * @set: value for hexpand-set property
11486 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11489 * The hexpand-set property will be set automatically when you call
11490 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11491 * reason to use this function would be to unset an explicit expand
11494 * If hexpand is set, then it overrides any computed
11495 * expand value based on child widgets. If hexpand is not
11496 * set, then the expand value depends on whether any
11497 * children of the widget would like to expand.
11499 * There are few reasons to use this function, but it's here
11500 * for completeness and consistency.
11502 * Return value: whether hexpand has been explicitly set
11505 gtk_widget_set_hexpand_set (GtkWidget *widget,
11508 g_return_if_fail (GTK_IS_WIDGET (widget));
11510 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11515 * gtk_widget_get_vexpand:
11516 * @widget: the widget
11518 * Gets whether the widget would like any available extra vertical
11521 * See gtk_widget_get_hexpand() for more detail.
11523 * Return value: whether vexpand flag is set
11526 gtk_widget_get_vexpand (GtkWidget *widget)
11528 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11530 return widget->priv->vexpand;
11534 * gtk_widget_set_vexpand:
11535 * @widget: the widget
11536 * @expand: whether to expand
11538 * Sets whether the widget would like any available extra vertical
11541 * See gtk_widget_set_hexpand() for more detail.
11544 gtk_widget_set_vexpand (GtkWidget *widget,
11547 g_return_if_fail (GTK_IS_WIDGET (widget));
11549 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11553 * gtk_widget_get_vexpand_set:
11554 * @widget: the widget
11556 * Gets whether gtk_widget_set_vexpand() has been used to
11557 * explicitly set the expand flag on this widget.
11559 * See gtk_widget_get_hexpand_set() for more detail.
11561 * Return value: whether vexpand has been explicitly set
11564 gtk_widget_get_vexpand_set (GtkWidget *widget)
11566 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11568 return widget->priv->vexpand_set;
11572 * gtk_widget_set_vexpand_set:
11573 * @widget: the widget
11574 * @set: value for vexpand-set property
11576 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11579 * See gtk_widget_set_hexpand_set() for more detail.
11581 * Return value: whether vexpand has been explicitly set
11584 gtk_widget_set_vexpand_set (GtkWidget *widget,
11587 g_return_if_fail (GTK_IS_WIDGET (widget));
11589 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11593 * GtkBuildable implementation
11595 static GQuark quark_builder_has_default = 0;
11596 static GQuark quark_builder_has_focus = 0;
11597 static GQuark quark_builder_atk_relations = 0;
11598 static GQuark quark_builder_set_name = 0;
11601 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11603 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11604 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11605 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11606 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11608 iface->set_name = gtk_widget_buildable_set_name;
11609 iface->get_name = gtk_widget_buildable_get_name;
11610 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11611 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11612 iface->parser_finished = gtk_widget_buildable_parser_finished;
11613 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11614 iface->custom_finished = gtk_widget_buildable_custom_finished;
11618 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11621 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11622 g_strdup (name), g_free);
11625 static const gchar *
11626 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11628 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11632 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11633 GtkBuilder *builder,
11634 const gchar *childname)
11636 if (strcmp (childname, "accessible") == 0)
11637 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11643 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11644 GtkBuilder *builder,
11646 const GValue *value)
11648 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11649 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11650 GINT_TO_POINTER (TRUE));
11651 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11652 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11653 GINT_TO_POINTER (TRUE));
11655 g_object_set_property (G_OBJECT (buildable), name, value);
11660 gchar *action_name;
11661 GString *description;
11663 gboolean translatable;
11673 free_action (AtkActionData *data, gpointer user_data)
11675 g_free (data->action_name);
11676 g_string_free (data->description, TRUE);
11677 g_free (data->context);
11678 g_slice_free (AtkActionData, data);
11682 free_relation (AtkRelationData *data, gpointer user_data)
11684 g_free (data->target);
11685 g_free (data->type);
11686 g_slice_free (AtkRelationData, data);
11690 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11691 GtkBuilder *builder)
11693 GSList *atk_relations;
11695 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11696 gtk_widget_grab_default (GTK_WIDGET (buildable));
11697 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11698 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11700 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11701 quark_builder_atk_relations);
11704 AtkObject *accessible;
11705 AtkRelationSet *relation_set;
11708 AtkRelationType relation_type;
11709 AtkObject *target_accessible;
11711 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11712 relation_set = atk_object_ref_relation_set (accessible);
11714 for (l = atk_relations; l; l = l->next)
11716 AtkRelationData *relation = (AtkRelationData*)l->data;
11718 target = gtk_builder_get_object (builder, relation->target);
11721 g_warning ("Target object %s in <relation> does not exist",
11725 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11726 g_assert (target_accessible != NULL);
11728 relation_type = atk_relation_type_for_name (relation->type);
11729 if (relation_type == ATK_RELATION_NULL)
11731 g_warning ("<relation> type %s not found",
11735 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11736 target_accessible);
11738 g_object_unref (relation_set);
11740 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11741 g_slist_free (atk_relations);
11742 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11751 } AccessibilitySubParserData;
11754 accessibility_start_element (GMarkupParseContext *context,
11755 const gchar *element_name,
11756 const gchar **names,
11757 const gchar **values,
11758 gpointer user_data,
11761 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11763 gint line_number, char_number;
11765 if (strcmp (element_name, "relation") == 0)
11767 gchar *target = NULL;
11768 gchar *type = NULL;
11769 AtkRelationData *relation;
11771 for (i = 0; names[i]; i++)
11773 if (strcmp (names[i], "target") == 0)
11774 target = g_strdup (values[i]);
11775 else if (strcmp (names[i], "type") == 0)
11776 type = g_strdup (values[i]);
11779 g_markup_parse_context_get_position (context,
11782 g_set_error (error,
11784 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11785 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11787 line_number, char_number, names[i], "relation");
11794 if (!target || !type)
11796 g_markup_parse_context_get_position (context,
11799 g_set_error (error,
11801 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11802 "%s:%d:%d <%s> requires attribute \"%s\"",
11804 line_number, char_number, "relation",
11805 type ? "target" : "type");
11811 relation = g_slice_new (AtkRelationData);
11812 relation->target = target;
11813 relation->type = type;
11815 data->relations = g_slist_prepend (data->relations, relation);
11817 else if (strcmp (element_name, "action") == 0)
11819 const gchar *action_name = NULL;
11820 const gchar *description = NULL;
11821 const gchar *msg_context = NULL;
11822 gboolean translatable = FALSE;
11823 AtkActionData *action;
11825 for (i = 0; names[i]; i++)
11827 if (strcmp (names[i], "action_name") == 0)
11828 action_name = values[i];
11829 else if (strcmp (names[i], "description") == 0)
11830 description = values[i];
11831 else if (strcmp (names[i], "translatable") == 0)
11833 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11836 else if (strcmp (names[i], "comments") == 0)
11838 /* do nothing, comments are for translators */
11840 else if (strcmp (names[i], "context") == 0)
11841 msg_context = values[i];
11844 g_markup_parse_context_get_position (context,
11847 g_set_error (error,
11849 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11850 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11852 line_number, char_number, names[i], "action");
11859 g_markup_parse_context_get_position (context,
11862 g_set_error (error,
11864 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11865 "%s:%d:%d <%s> requires attribute \"%s\"",
11867 line_number, char_number, "action",
11872 action = g_slice_new (AtkActionData);
11873 action->action_name = g_strdup (action_name);
11874 action->description = g_string_new (description);
11875 action->context = g_strdup (msg_context);
11876 action->translatable = translatable;
11878 data->actions = g_slist_prepend (data->actions, action);
11880 else if (strcmp (element_name, "accessibility") == 0)
11883 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11887 accessibility_text (GMarkupParseContext *context,
11890 gpointer user_data,
11893 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11895 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11897 AtkActionData *action = data->actions->data;
11899 g_string_append_len (action->description, text, text_len);
11903 static const GMarkupParser accessibility_parser =
11905 accessibility_start_element,
11907 accessibility_text,
11916 } AccelGroupParserData;
11919 accel_group_start_element (GMarkupParseContext *context,
11920 const gchar *element_name,
11921 const gchar **names,
11922 const gchar **values,
11923 gpointer user_data,
11928 guint modifiers = 0;
11929 gchar *signal = NULL;
11930 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11932 for (i = 0; names[i]; i++)
11934 if (strcmp (names[i], "key") == 0)
11935 key = gdk_keyval_from_name (values[i]);
11936 else if (strcmp (names[i], "modifiers") == 0)
11938 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11944 else if (strcmp (names[i], "signal") == 0)
11945 signal = g_strdup (values[i]);
11948 if (key == 0 || signal == NULL)
11950 g_warning ("<accelerator> requires key and signal attributes");
11953 parser_data->key = key;
11954 parser_data->modifiers = modifiers;
11955 parser_data->signal = signal;
11958 static const GMarkupParser accel_group_parser =
11960 accel_group_start_element,
11964 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11965 GtkBuilder *builder,
11967 const gchar *tagname,
11968 GMarkupParser *parser,
11971 g_assert (buildable);
11973 if (strcmp (tagname, "accelerator") == 0)
11975 AccelGroupParserData *parser_data;
11977 parser_data = g_slice_new0 (AccelGroupParserData);
11978 parser_data->object = g_object_ref (buildable);
11979 *parser = accel_group_parser;
11980 *data = parser_data;
11983 if (strcmp (tagname, "accessibility") == 0)
11985 AccessibilitySubParserData *parser_data;
11987 parser_data = g_slice_new0 (AccessibilitySubParserData);
11988 *parser = accessibility_parser;
11989 *data = parser_data;
11996 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11997 GtkWidget *toplevel,
11998 gpointer user_data)
12000 AccelGroupParserData *accel_data;
12001 GSList *accel_groups;
12002 GtkAccelGroup *accel_group;
12004 g_return_if_fail (GTK_IS_WIDGET (widget));
12005 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12006 g_return_if_fail (user_data != NULL);
12008 accel_data = (AccelGroupParserData*)user_data;
12009 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12010 if (g_slist_length (accel_groups) == 0)
12012 accel_group = gtk_accel_group_new ();
12013 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12017 g_assert (g_slist_length (accel_groups) == 1);
12018 accel_group = g_slist_nth_data (accel_groups, 0);
12021 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12022 accel_data->signal,
12025 accel_data->modifiers,
12026 GTK_ACCEL_VISIBLE);
12028 g_object_unref (accel_data->object);
12029 g_free (accel_data->signal);
12030 g_slice_free (AccelGroupParserData, accel_data);
12034 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12035 GtkBuilder *builder,
12037 const gchar *tagname,
12038 gpointer user_data)
12040 AccelGroupParserData *accel_data;
12041 AccessibilitySubParserData *a11y_data;
12042 GtkWidget *toplevel;
12044 if (strcmp (tagname, "accelerator") == 0)
12046 accel_data = (AccelGroupParserData*)user_data;
12047 g_assert (accel_data->object);
12049 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12051 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12053 else if (strcmp (tagname, "accessibility") == 0)
12055 a11y_data = (AccessibilitySubParserData*)user_data;
12057 if (a11y_data->actions)
12059 AtkObject *accessible;
12064 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12066 action = ATK_ACTION (accessible);
12067 n_actions = atk_action_get_n_actions (action);
12069 for (l = a11y_data->actions; l; l = l->next)
12071 AtkActionData *action_data = (AtkActionData*)l->data;
12073 for (i = 0; i < n_actions; i++)
12074 if (strcmp (atk_action_get_name (action, i),
12075 action_data->action_name) == 0)
12080 gchar *description;
12082 if (action_data->translatable && action_data->description->len)
12083 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12084 action_data->context,
12085 action_data->description->str);
12087 description = action_data->description->str;
12089 atk_action_set_description (action, i, description);
12093 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12094 g_slist_free (a11y_data->actions);
12097 if (a11y_data->relations)
12098 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12099 a11y_data->relations);
12101 g_slice_free (AccessibilitySubParserData, a11y_data);
12106 gtk_widget_real_get_width (GtkWidget *widget,
12107 gint *minimum_size,
12108 gint *natural_size)
12118 gtk_widget_real_get_height (GtkWidget *widget,
12119 gint *minimum_size,
12120 gint *natural_size)
12130 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12132 gint *minimum_height,
12133 gint *natural_height)
12135 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12139 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12141 gint *minimum_width,
12142 gint *natural_width)
12144 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12148 * gtk_widget_get_halign:
12149 * @widget: a #GtkWidget
12151 * Gets the value of the #GtkWidget:halign property.
12153 * Returns: the horizontal alignment of @widget
12156 gtk_widget_get_halign (GtkWidget *widget)
12158 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12159 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12163 * gtk_widget_set_halign:
12164 * @widget: a #GtkWidget
12165 * @align: the horizontal alignment
12167 * Sets the horizontal alignment of @widget.
12168 * See the #GtkWidget:halign property.
12171 gtk_widget_set_halign (GtkWidget *widget,
12174 GtkWidgetAuxInfo *aux_info;
12176 g_return_if_fail (GTK_IS_WIDGET (widget));
12178 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12180 if (aux_info->halign == align)
12183 aux_info->halign = align;
12184 gtk_widget_queue_resize (widget);
12185 g_object_notify (G_OBJECT (widget), "halign");
12189 * gtk_widget_get_valign:
12190 * @widget: a #GtkWidget
12192 * Gets the value of the #GtkWidget:valign property.
12194 * Returns: the vertical alignment of @widget
12197 gtk_widget_get_valign (GtkWidget *widget)
12199 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12200 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12204 * gtk_widget_set_valign:
12205 * @widget: a #GtkWidget
12206 * @align: the vertical alignment
12208 * Sets the vertical alignment of @widget.
12209 * See the #GtkWidget:valign property.
12212 gtk_widget_set_valign (GtkWidget *widget,
12215 GtkWidgetAuxInfo *aux_info;
12217 g_return_if_fail (GTK_IS_WIDGET (widget));
12219 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12221 if (aux_info->valign == align)
12224 aux_info->valign = align;
12225 gtk_widget_queue_resize (widget);
12226 g_object_notify (G_OBJECT (widget), "valign");
12230 * gtk_widget_get_margin_left:
12231 * @widget: a #GtkWidget
12233 * Gets the value of the #GtkWidget:margin-left property.
12235 * Returns: The left margin of @widget
12238 gtk_widget_get_margin_left (GtkWidget *widget)
12240 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12242 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12246 * gtk_widget_set_margin_left:
12247 * @widget: a #GtkWidget
12248 * @margin: the left margin
12250 * Sets the left margin of @widget.
12251 * See the #GtkWidget:margin-left property.
12254 gtk_widget_set_margin_left (GtkWidget *widget,
12257 GtkWidgetAuxInfo *aux_info;
12259 g_return_if_fail (GTK_IS_WIDGET (widget));
12260 g_return_if_fail (margin <= G_MAXINT16);
12262 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12264 if (aux_info->margin.left == margin)
12267 aux_info->margin.left = margin;
12268 gtk_widget_queue_resize (widget);
12269 g_object_notify (G_OBJECT (widget), "margin-left");
12273 * gtk_widget_get_margin_right:
12274 * @widget: a #GtkWidget
12276 * Gets the value of the #GtkWidget:margin-right property.
12278 * Returns: The left margin of @widget
12281 gtk_widget_get_margin_right (GtkWidget *widget)
12283 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12285 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12289 * gtk_widget_set_margin_right:
12290 * @widget: a #GtkWidget
12291 * @margin: the right margin
12293 * Sets the right margin of @widget.
12294 * See the #GtkWidget:margin-right property.
12297 gtk_widget_set_margin_right (GtkWidget *widget,
12300 GtkWidgetAuxInfo *aux_info;
12302 g_return_if_fail (GTK_IS_WIDGET (widget));
12303 g_return_if_fail (margin <= G_MAXINT16);
12305 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12307 if (aux_info->margin.right == margin)
12310 aux_info->margin.right = margin;
12311 gtk_widget_queue_resize (widget);
12312 g_object_notify (G_OBJECT (widget), "margin-right");
12316 * gtk_widget_get_margin_top:
12317 * @widget: a #GtkWidget
12319 * Gets the value of the #GtkWidget:margin-top property.
12321 * Returns: The top margin of @widget
12324 gtk_widget_get_margin_top (GtkWidget *widget)
12326 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12328 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12332 * gtk_widget_set_margin_top:
12333 * @widget: a #GtkWidget
12334 * @margin: the top margin
12336 * Sets the top margin of @widget.
12337 * See the #GtkWidget:margin-top property.
12340 gtk_widget_set_margin_top (GtkWidget *widget,
12343 GtkWidgetAuxInfo *aux_info;
12345 g_return_if_fail (GTK_IS_WIDGET (widget));
12346 g_return_if_fail (margin <= G_MAXINT16);
12348 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12350 if (aux_info->margin.top == margin)
12353 aux_info->margin.top = margin;
12354 gtk_widget_queue_resize (widget);
12355 g_object_notify (G_OBJECT (widget), "margin-top");
12359 * gtk_widget_get_margin_bottom:
12360 * @widget: a #GtkWidget
12362 * Gets the value of the #GtkWidget:margin-bottom property.
12364 * Returns: The bottom margin of @widget
12367 gtk_widget_get_margin_bottom (GtkWidget *widget)
12369 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12371 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12375 * gtk_widget_set_margin_bottom:
12376 * @widget: a #GtkWidget
12377 * @margin: the bottom margin
12379 * Sets the bottom margin of @widget.
12380 * See the #GtkWidget:margin-bottom property.
12383 gtk_widget_set_margin_bottom (GtkWidget *widget,
12386 GtkWidgetAuxInfo *aux_info;
12388 g_return_if_fail (GTK_IS_WIDGET (widget));
12389 g_return_if_fail (margin <= G_MAXINT16);
12391 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12393 if (aux_info->margin.bottom == margin)
12396 aux_info->margin.bottom = margin;
12397 gtk_widget_queue_resize (widget);
12398 g_object_notify (G_OBJECT (widget), "margin-bottom");
12402 * gtk_widget_get_clipboard:
12403 * @widget: a #GtkWidget
12404 * @selection: a #GdkAtom which identifies the clipboard
12405 * to use. %GDK_SELECTION_CLIPBOARD gives the
12406 * default clipboard. Another common value
12407 * is %GDK_SELECTION_PRIMARY, which gives
12408 * the primary X selection.
12410 * Returns the clipboard object for the given selection to
12411 * be used with @widget. @widget must have a #GdkDisplay
12412 * associated with it, so must be attached to a toplevel
12415 * Return value: (transfer none): the appropriate clipboard object. If no
12416 * clipboard already exists, a new one will
12417 * be created. Once a clipboard object has
12418 * been created, it is persistent for all time.
12423 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12425 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12426 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12428 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12433 * gtk_widget_list_mnemonic_labels:
12434 * @widget: a #GtkWidget
12436 * Returns a newly allocated list of the widgets, normally labels, for
12437 * which this widget is the target of a mnemonic (see for example,
12438 * gtk_label_set_mnemonic_widget()).
12440 * The widgets in the list are not individually referenced. If you
12441 * want to iterate through the list and perform actions involving
12442 * callbacks that might destroy the widgets, you
12443 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12444 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12445 * widgets afterwards.
12447 * Return value: (element-type GtkWidget) (transfer container): the list of
12448 * mnemonic labels; free this list
12449 * with g_list_free() when you are done with it.
12454 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12456 GList *list = NULL;
12459 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12461 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12462 list = g_list_prepend (list, l->data);
12468 * gtk_widget_add_mnemonic_label:
12469 * @widget: a #GtkWidget
12470 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12472 * Adds a widget to the list of mnemonic labels for
12473 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12474 * list of mnemonic labels for the widget is cleared when the
12475 * widget is destroyed, so the caller must make sure to update
12476 * its internal state at this point as well, by using a connection
12477 * to the #GtkWidget::destroy signal or a weak notifier.
12482 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12485 GSList *old_list, *new_list;
12487 g_return_if_fail (GTK_IS_WIDGET (widget));
12488 g_return_if_fail (GTK_IS_WIDGET (label));
12490 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12491 new_list = g_slist_prepend (old_list, label);
12493 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12494 new_list, (GDestroyNotify) g_slist_free);
12498 * gtk_widget_remove_mnemonic_label:
12499 * @widget: a #GtkWidget
12500 * @label: a #GtkWidget that was previously set as a mnemnic label for
12501 * @widget with gtk_widget_add_mnemonic_label().
12503 * Removes a widget from the list of mnemonic labels for
12504 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12505 * must have previously been added to the list with
12506 * gtk_widget_add_mnemonic_label().
12511 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12514 GSList *old_list, *new_list;
12516 g_return_if_fail (GTK_IS_WIDGET (widget));
12517 g_return_if_fail (GTK_IS_WIDGET (label));
12519 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12520 new_list = g_slist_remove (old_list, label);
12523 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12524 new_list, (GDestroyNotify) g_slist_free);
12528 * gtk_widget_get_no_show_all:
12529 * @widget: a #GtkWidget
12531 * Returns the current value of the #GtkWidget:no-show-all property,
12532 * which determines whether calls to gtk_widget_show_all()
12533 * will affect this widget.
12535 * Return value: the current value of the "no-show-all" property.
12540 gtk_widget_get_no_show_all (GtkWidget *widget)
12542 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12544 return widget->priv->no_show_all;
12548 * gtk_widget_set_no_show_all:
12549 * @widget: a #GtkWidget
12550 * @no_show_all: the new value for the "no-show-all" property
12552 * Sets the #GtkWidget:no-show-all property, which determines whether
12553 * calls to gtk_widget_show_all() will affect this widget.
12555 * This is mostly for use in constructing widget hierarchies with externally
12556 * controlled visibility, see #GtkUIManager.
12561 gtk_widget_set_no_show_all (GtkWidget *widget,
12562 gboolean no_show_all)
12564 g_return_if_fail (GTK_IS_WIDGET (widget));
12566 no_show_all = (no_show_all != FALSE);
12568 if (widget->priv->no_show_all != no_show_all)
12570 widget->priv->no_show_all = no_show_all;
12572 g_object_notify (G_OBJECT (widget), "no-show-all");
12578 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12579 gboolean has_tooltip,
12582 GtkWidgetPrivate *priv = widget->priv;
12583 gboolean priv_has_tooltip;
12585 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12586 quark_has_tooltip));
12588 if (priv_has_tooltip != has_tooltip || force)
12590 priv_has_tooltip = has_tooltip;
12592 if (priv_has_tooltip)
12594 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12595 gdk_window_set_events (priv->window,
12596 gdk_window_get_events (priv->window) |
12597 GDK_LEAVE_NOTIFY_MASK |
12598 GDK_POINTER_MOTION_MASK |
12599 GDK_POINTER_MOTION_HINT_MASK);
12601 if (gtk_widget_get_has_window (widget))
12602 gtk_widget_add_events (widget,
12603 GDK_LEAVE_NOTIFY_MASK |
12604 GDK_POINTER_MOTION_MASK |
12605 GDK_POINTER_MOTION_HINT_MASK);
12608 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12609 GUINT_TO_POINTER (priv_has_tooltip));
12614 * gtk_widget_set_tooltip_window:
12615 * @widget: a #GtkWidget
12616 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12618 * Replaces the default, usually yellow, window used for displaying
12619 * tooltips with @custom_window. GTK+ will take care of showing and
12620 * hiding @custom_window at the right moment, to behave likewise as
12621 * the default tooltip window. If @custom_window is %NULL, the default
12622 * tooltip window will be used.
12624 * If the custom window should have the default theming it needs to
12625 * have the name "gtk-tooltip", see gtk_widget_set_name().
12630 gtk_widget_set_tooltip_window (GtkWidget *widget,
12631 GtkWindow *custom_window)
12633 gboolean has_tooltip;
12634 gchar *tooltip_markup;
12636 g_return_if_fail (GTK_IS_WIDGET (widget));
12637 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12639 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12642 g_object_ref (custom_window);
12644 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12645 custom_window, g_object_unref);
12647 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12648 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12650 if (has_tooltip && gtk_widget_get_visible (widget))
12651 gtk_widget_queue_tooltip_query (widget);
12655 * gtk_widget_get_tooltip_window:
12656 * @widget: a #GtkWidget
12658 * Returns the #GtkWindow of the current tooltip. This can be the
12659 * GtkWindow created by default, or the custom tooltip window set
12660 * using gtk_widget_set_tooltip_window().
12662 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12667 gtk_widget_get_tooltip_window (GtkWidget *widget)
12669 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12671 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12675 * gtk_widget_trigger_tooltip_query:
12676 * @widget: a #GtkWidget
12678 * Triggers a tooltip query on the display where the toplevel of @widget
12679 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12685 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12687 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12690 static guint tooltip_query_id;
12691 static GSList *tooltip_query_displays;
12694 tooltip_query_idle (gpointer data)
12696 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12697 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12698 g_slist_free (tooltip_query_displays);
12700 tooltip_query_displays = NULL;
12701 tooltip_query_id = 0;
12707 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12709 GdkDisplay *display;
12711 display = gtk_widget_get_display (widget);
12713 if (!g_slist_find (tooltip_query_displays, display))
12714 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12716 if (tooltip_query_id == 0)
12717 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12721 * gtk_widget_set_tooltip_text:
12722 * @widget: a #GtkWidget
12723 * @text: the contents of the tooltip for @widget
12725 * Sets @text as the contents of the tooltip. This function will take
12726 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12727 * handler for the #GtkWidget::query-tooltip signal.
12729 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12734 gtk_widget_set_tooltip_text (GtkWidget *widget,
12737 g_return_if_fail (GTK_IS_WIDGET (widget));
12739 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12743 * gtk_widget_get_tooltip_text:
12744 * @widget: a #GtkWidget
12746 * Gets the contents of the tooltip for @widget.
12748 * Return value: the tooltip text, or %NULL. You should free the
12749 * returned string with g_free() when done.
12754 gtk_widget_get_tooltip_text (GtkWidget *widget)
12756 gchar *text = NULL;
12758 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12760 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12766 * gtk_widget_set_tooltip_markup:
12767 * @widget: a #GtkWidget
12768 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12770 * Sets @markup as the contents of the tooltip, which is marked up with
12771 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12773 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12774 * and of the default handler for the #GtkWidget::query-tooltip signal.
12776 * See also the #GtkWidget:tooltip-markup property and
12777 * gtk_tooltip_set_markup().
12782 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12783 const gchar *markup)
12785 g_return_if_fail (GTK_IS_WIDGET (widget));
12787 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12791 * gtk_widget_get_tooltip_markup:
12792 * @widget: a #GtkWidget
12794 * Gets the contents of the tooltip for @widget.
12796 * Return value: the tooltip text, or %NULL. You should free the
12797 * returned string with g_free() when done.
12802 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12804 gchar *text = NULL;
12806 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12808 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12814 * gtk_widget_set_has_tooltip:
12815 * @widget: a #GtkWidget
12816 * @has_tooltip: whether or not @widget has a tooltip.
12818 * Sets the has-tooltip property on @widget to @has_tooltip. See
12819 * #GtkWidget:has-tooltip for more information.
12824 gtk_widget_set_has_tooltip (GtkWidget *widget,
12825 gboolean has_tooltip)
12827 g_return_if_fail (GTK_IS_WIDGET (widget));
12829 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12833 * gtk_widget_get_has_tooltip:
12834 * @widget: a #GtkWidget
12836 * Returns the current value of the has-tooltip property. See
12837 * #GtkWidget:has-tooltip for more information.
12839 * Return value: current value of has-tooltip on @widget.
12844 gtk_widget_get_has_tooltip (GtkWidget *widget)
12846 gboolean has_tooltip = FALSE;
12848 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12850 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12852 return has_tooltip;
12856 * gtk_widget_get_allocation:
12857 * @widget: a #GtkWidget
12858 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12860 * Retrieves the widget's allocation.
12862 * Note, when implementing a #GtkContainer: a widget's allocation will
12863 * be its "adjusted" allocation, that is, the widget's parent
12864 * container typically calls gtk_widget_size_allocate() with an
12865 * allocation, and that allocation is then adjusted (to handle margin
12866 * and alignment for example) before assignment to the widget.
12867 * gtk_widget_get_allocation() returns the adjusted allocation that
12868 * was actually assigned to the widget. The adjusted allocation is
12869 * guaranteed to be completely contained within the
12870 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12871 * is guaranteed that its children stay inside the assigned bounds,
12872 * but not that they have exactly the bounds the container assigned.
12873 * There is no way to get the original allocation assigned by
12874 * gtk_widget_size_allocate(), since it isn't stored; if a container
12875 * implementation needs that information it will have to track it itself.
12880 gtk_widget_get_allocation (GtkWidget *widget,
12881 GtkAllocation *allocation)
12883 GtkWidgetPrivate *priv;
12885 g_return_if_fail (GTK_IS_WIDGET (widget));
12886 g_return_if_fail (allocation != NULL);
12888 priv = widget->priv;
12890 *allocation = priv->allocation;
12894 * gtk_widget_set_allocation:
12895 * @widget: a #GtkWidget
12896 * @allocation: a pointer to a #GtkAllocation to copy from
12898 * Sets the widget's allocation. This should not be used
12899 * directly, but from within a widget's size_allocate method.
12901 * The allocation set should be the "adjusted" or actual
12902 * allocation. If you're implementing a #GtkContainer, you want to use
12903 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12904 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12905 * allocation inside gtk_widget_size_allocate() to create an adjusted
12911 gtk_widget_set_allocation (GtkWidget *widget,
12912 const GtkAllocation *allocation)
12914 GtkWidgetPrivate *priv;
12916 g_return_if_fail (GTK_IS_WIDGET (widget));
12917 g_return_if_fail (allocation != NULL);
12919 priv = widget->priv;
12921 priv->allocation = *allocation;
12925 * gtk_widget_get_allocated_width:
12926 * @widget: the widget to query
12928 * Returns the width that has currently been allocated to @widget.
12929 * This function is intended to be used when implementing handlers
12930 * for the #GtkWidget::draw function.
12932 * Returns: the width of the @widget
12935 gtk_widget_get_allocated_width (GtkWidget *widget)
12937 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12939 return widget->priv->allocation.width;
12943 * gtk_widget_get_allocated_height:
12944 * @widget: the widget to query
12946 * Returns the height that has currently been allocated to @widget.
12947 * This function is intended to be used when implementing handlers
12948 * for the #GtkWidget::draw function.
12950 * Returns: the height of the @widget
12953 gtk_widget_get_allocated_height (GtkWidget *widget)
12955 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12957 return widget->priv->allocation.height;
12961 * gtk_widget_get_requisition:
12962 * @widget: a #GtkWidget
12963 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12965 * Retrieves the widget's requisition.
12967 * This function should only be used by widget implementations in
12968 * order to figure whether the widget's requisition has actually
12969 * changed after some internal state change (so that they can call
12970 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12972 * Normally, gtk_widget_size_request() should be used.
12976 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12977 * removed, If you need to cache sizes across requests and allocations,
12978 * add an explicit cache to the widget in question instead.
12981 gtk_widget_get_requisition (GtkWidget *widget,
12982 GtkRequisition *requisition)
12984 g_return_if_fail (GTK_IS_WIDGET (widget));
12985 g_return_if_fail (requisition != NULL);
12987 gtk_widget_get_preferred_size (widget, requisition, NULL);
12991 * gtk_widget_set_window:
12992 * @widget: a #GtkWidget
12993 * @window: a #GdkWindow
12995 * Sets a widget's window. This function should only be used in a
12996 * widget's #GtkWidget::realize implementation. The %window passed is
12997 * usually either new window created with gdk_window_new(), or the
12998 * window of its parent widget as returned by
12999 * gtk_widget_get_parent_window().
13001 * Widgets must indicate whether they will create their own #GdkWindow
13002 * by calling gtk_widget_set_has_window(). This is usually done in the
13003 * widget's init() function.
13005 * <note><para>This function does not add any reference to @window.</para></note>
13010 gtk_widget_set_window (GtkWidget *widget,
13013 GtkWidgetPrivate *priv;
13015 g_return_if_fail (GTK_IS_WIDGET (widget));
13016 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13018 priv = widget->priv;
13020 if (priv->window != window)
13022 priv->window = window;
13023 g_object_notify (G_OBJECT (widget), "window");
13028 * gtk_widget_get_window:
13029 * @widget: a #GtkWidget
13031 * Returns the widget's window if it is realized, %NULL otherwise
13033 * Return value: (transfer none): @widget's window.
13038 gtk_widget_get_window (GtkWidget *widget)
13040 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13042 return widget->priv->window;
13046 * gtk_widget_get_support_multidevice:
13047 * @widget: a #GtkWidget
13049 * Returns %TRUE if @widget is multiple pointer aware. See
13050 * gtk_widget_set_support_multidevice() for more information.
13052 * Returns: %TRUE is @widget is multidevice aware.
13055 gtk_widget_get_support_multidevice (GtkWidget *widget)
13057 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13059 return widget->priv->multidevice;
13063 * gtk_widget_set_support_multidevice:
13064 * @widget: a #GtkWidget
13065 * @support_multidevice: %TRUE to support input from multiple devices.
13067 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13068 * @widget will start receiving multiple, per device enter/leave events. Note
13069 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13070 * gdk_window_set_support_multidevice() will have to be called manually on them.
13075 gtk_widget_set_support_multidevice (GtkWidget *widget,
13076 gboolean support_multidevice)
13078 GtkWidgetPrivate *priv;
13080 g_return_if_fail (GTK_IS_WIDGET (widget));
13082 priv = widget->priv;
13084 if (support_multidevice)
13086 priv->multidevice = TRUE;
13087 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13091 priv->multidevice = FALSE;
13092 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13095 if (gtk_widget_get_realized (widget))
13096 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13100 _gtk_widget_set_has_focus (GtkWidget *widget,
13101 gboolean has_focus)
13103 widget->priv->has_focus = has_focus;
13107 * gtk_widget_send_focus_change:
13108 * @widget: a #GtkWidget
13109 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13111 * Sends the focus change @event to @widget
13113 * This function is not meant to be used by applications. The only time it
13114 * should be used is when it is necessary for a #GtkWidget to assign focus
13115 * to a widget that is semantically owned by the first widget even though
13116 * it's not a direct child - for instance, a search entry in a floating
13117 * window similar to the quick search in #GtkTreeView.
13119 * An example of its usage is:
13122 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13124 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13125 * fevent->focus_change.in = TRUE;
13126 * fevent->focus_change.window = gtk_widget_get_window (widget);
13127 * if (fevent->focus_change.window != NULL)
13128 * g_object_ref (fevent->focus_change.window);
13130 * gtk_widget_send_focus_change (widget, fevent);
13132 * gdk_event_free (event);
13135 * Return value: the return value from the event signal emission: %TRUE
13136 * if the event was handled, and %FALSE otherwise
13141 gtk_widget_send_focus_change (GtkWidget *widget,
13146 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13147 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13149 g_object_ref (widget);
13151 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13153 res = gtk_widget_event (widget, event);
13155 g_object_notify (G_OBJECT (widget), "has-focus");
13157 g_object_unref (widget);
13163 * gtk_widget_in_destruction:
13164 * @widget: a #GtkWidget
13166 * Returns whether the widget is currently being destroyed.
13167 * This information can sometimes be used to avoid doing
13168 * unnecessary work.
13170 * Returns: %TRUE if @widget is being destroyed
13173 gtk_widget_in_destruction (GtkWidget *widget)
13175 return widget->priv->in_destruction;
13179 _gtk_widget_get_resize_pending (GtkWidget *widget)
13181 return widget->priv->resize_pending;
13185 _gtk_widget_set_resize_pending (GtkWidget *widget,
13186 gboolean resize_pending)
13188 widget->priv->resize_pending = resize_pending;
13192 _gtk_widget_get_in_reparent (GtkWidget *widget)
13194 return widget->priv->in_reparent;
13198 _gtk_widget_set_in_reparent (GtkWidget *widget,
13199 gboolean in_reparent)
13201 widget->priv->in_reparent = in_reparent;
13205 _gtk_widget_get_anchored (GtkWidget *widget)
13207 return widget->priv->anchored;
13211 _gtk_widget_set_anchored (GtkWidget *widget,
13214 widget->priv->anchored = anchored;
13218 _gtk_widget_get_shadowed (GtkWidget *widget)
13220 return widget->priv->shadowed;
13224 _gtk_widget_set_shadowed (GtkWidget *widget,
13227 widget->priv->shadowed = shadowed;
13231 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13233 return widget->priv->alloc_needed;
13237 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13238 gboolean alloc_needed)
13240 widget->priv->alloc_needed = alloc_needed;
13244 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13246 return widget->priv->width_request_needed;
13250 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13251 gboolean width_request_needed)
13253 widget->priv->width_request_needed = width_request_needed;
13257 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13259 return widget->priv->height_request_needed;
13263 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13264 gboolean height_request_needed)
13266 widget->priv->height_request_needed = height_request_needed;