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 its parent container whether
89 * it prefers 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 its 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 its 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 its natural width if it was configured to receive extra
111 * expand space from its 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 its 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 this can happen when, for example, a widget or container gets
142 * additional 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 depend on the preferred
160 * widths of their 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 its 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 its target allocated width or its 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 has
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 intelligently 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 height required for its 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 its 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 * Deprecated: 3.0: Either implement
1474 * <link linkend="geometry-management">height-for-width geometry management</link> or
1475 * use gtk_widget_set_size_request() instead of handling this signal.
1477 _size_request_signal_id = widget_signals[SIZE_REQUEST] =
1478 g_signal_new (I_("size-request"),
1479 G_TYPE_FROM_CLASS (gobject_class),
1481 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1483 _gtk_marshal_VOID__BOXED,
1485 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1488 * GtkWidget::size-allocate:
1489 * @widget: the object which received the signal.
1492 widget_signals[SIZE_ALLOCATE] =
1493 g_signal_new (I_("size-allocate"),
1494 G_TYPE_FROM_CLASS (gobject_class),
1496 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1498 _gtk_marshal_VOID__BOXED,
1500 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1503 * GtkWidget::state-changed:
1504 * @widget: the object which received the signal.
1505 * @state: the previous state
1507 * The ::state-changed signal is emitted when the widget state changes.
1508 * See gtk_widget_get_state().
1510 widget_signals[STATE_CHANGED] =
1511 g_signal_new (I_("state-changed"),
1512 G_TYPE_FROM_CLASS (gobject_class),
1514 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1516 _gtk_marshal_VOID__ENUM,
1518 GTK_TYPE_STATE_TYPE);
1521 * GtkWidget::parent-set:
1522 * @widget: the object on which the signal is emitted
1523 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1524 * just got its initial parent.
1526 * The ::parent-set signal is emitted when a new parent
1527 * has been set on a widget.
1529 widget_signals[PARENT_SET] =
1530 g_signal_new (I_("parent-set"),
1531 G_TYPE_FROM_CLASS (gobject_class),
1533 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1535 _gtk_marshal_VOID__OBJECT,
1540 * GtkWidget::hierarchy-changed:
1541 * @widget: the object on which the signal is emitted
1542 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1543 * if the widget was previously unanchored
1545 * The ::hierarchy-changed signal is emitted when the
1546 * anchored state of a widget changes. A widget is
1547 * <firstterm>anchored</firstterm> when its toplevel
1548 * ancestor is a #GtkWindow. This signal is emitted when
1549 * a widget changes from un-anchored to anchored or vice-versa.
1551 widget_signals[HIERARCHY_CHANGED] =
1552 g_signal_new (I_("hierarchy-changed"),
1553 G_TYPE_FROM_CLASS (gobject_class),
1555 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1557 _gtk_marshal_VOID__OBJECT,
1562 * GtkWidget::style-set:
1563 * @widget: the object on which the signal is emitted
1564 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1565 * just got its initial style
1567 * The ::style-set signal is emitted when a new style has been set
1568 * on a widget. Note that style-modifying functions like
1569 * gtk_widget_modify_base() also cause this signal to be emitted.
1571 widget_signals[STYLE_SET] =
1572 g_signal_new (I_("style-set"),
1573 G_TYPE_FROM_CLASS (gobject_class),
1575 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1577 _gtk_marshal_VOID__OBJECT,
1582 * GtkWidget::direction-changed:
1583 * @widget: the object on which the signal is emitted
1584 * @previous_direction: the previous text direction of @widget
1586 * The ::direction-changed signal is emitted when the text direction
1587 * of a widget changes.
1589 widget_signals[DIRECTION_CHANGED] =
1590 g_signal_new (I_("direction-changed"),
1591 G_TYPE_FROM_CLASS (gobject_class),
1593 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1595 _gtk_marshal_VOID__ENUM,
1597 GTK_TYPE_TEXT_DIRECTION);
1600 * GtkWidget::grab-notify:
1601 * @widget: the object which received the signal
1602 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1603 * if it becomes unshadowed
1605 * The ::grab-notify signal is emitted when a widget becomes
1606 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1607 * another widget, or when it becomes unshadowed due to a grab
1610 * A widget is shadowed by a gtk_grab_add() when the topmost
1611 * grab widget in the grab stack of its window group is not
1614 widget_signals[GRAB_NOTIFY] =
1615 g_signal_new (I_("grab-notify"),
1616 G_TYPE_FROM_CLASS (gobject_class),
1618 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1620 _gtk_marshal_VOID__BOOLEAN,
1625 * GtkWidget::child-notify:
1626 * @widget: the object which received the signal
1627 * @pspec: the #GParamSpec of the changed child property
1629 * The ::child-notify signal is emitted for each
1630 * <link linkend="child-properties">child property</link> that has
1631 * changed on an object. The signal's detail holds the property name.
1633 widget_signals[CHILD_NOTIFY] =
1634 g_signal_new (I_("child-notify"),
1635 G_TYPE_FROM_CLASS (gobject_class),
1636 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1637 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1639 g_cclosure_marshal_VOID__PARAM,
1645 * @widget: the object which received the signal
1646 * @cr: the cairo context to draw to
1648 * This signal is emitted when a widget is supposed to render itself.
1649 * The @widget's top left corner must be painted at the origin of
1650 * the passed in context and be sized to the values returned by
1651 * gtk_widget_get_allocated_width() and
1652 * gtk_widget_get_allocated_height().
1654 * Signal handlers connected to this signal can modify the cairo
1655 * context passed as @cr in any way they like and don't need to
1656 * restore it. The signal emission takes care of calling cairo_save()
1657 * before and cairo_restore() after invoking the handler.
1659 widget_signals[DRAW] =
1660 g_signal_new (I_("draw"),
1661 G_TYPE_FROM_CLASS (gobject_class),
1663 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1664 _gtk_boolean_handled_accumulator, NULL,
1665 gtk_widget_draw_marshaller,
1667 CAIRO_GOBJECT_TYPE_CONTEXT);
1670 * GtkWidget::mnemonic-activate:
1671 * @widget: the object which received the signal.
1674 widget_signals[MNEMONIC_ACTIVATE] =
1675 g_signal_new (I_("mnemonic-activate"),
1676 G_TYPE_FROM_CLASS (gobject_class),
1678 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1679 _gtk_boolean_handled_accumulator, NULL,
1680 _gtk_marshal_BOOLEAN__BOOLEAN,
1685 * GtkWidget::grab-focus:
1686 * @widget: the object which received the signal.
1688 widget_signals[GRAB_FOCUS] =
1689 g_signal_new (I_("grab-focus"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1691 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1692 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1694 _gtk_marshal_VOID__VOID,
1699 * @widget: the object which received the signal.
1702 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1704 widget_signals[FOCUS] =
1705 g_signal_new (I_("focus"),
1706 G_TYPE_FROM_CLASS (klass),
1708 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1709 _gtk_boolean_handled_accumulator, NULL,
1710 _gtk_marshal_BOOLEAN__ENUM,
1712 GTK_TYPE_DIRECTION_TYPE);
1715 * GtkWidget::move-focus:
1716 * @widget: the object which received the signal.
1719 widget_signals[MOVE_FOCUS] =
1720 g_signal_new (I_("move-focus"),
1721 G_TYPE_FROM_CLASS (klass),
1722 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1723 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1725 _gtk_marshal_VOID__ENUM,
1728 GTK_TYPE_DIRECTION_TYPE);
1731 * GtkWidget::keynav-failed:
1732 * @widget: the object which received the signal
1733 * @direction: the direction of movement
1735 * Gets emitted if keyboard navigation fails.
1736 * See gtk_widget_keynav_failed() for details.
1738 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1739 * if the emitting widget should try to handle the keyboard
1740 * navigation attempt in its parent container(s).
1744 widget_signals[KEYNAV_FAILED] =
1745 g_signal_new (I_("keynav-failed"),
1746 G_TYPE_FROM_CLASS (klass),
1748 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1749 _gtk_boolean_handled_accumulator, NULL,
1750 _gtk_marshal_BOOLEAN__ENUM,
1752 GTK_TYPE_DIRECTION_TYPE);
1756 * @widget: the object which received the signal.
1757 * @event: the #GdkEvent which triggered this signal
1759 * The GTK+ main loop will emit three signals for each GDK event delivered
1760 * to a widget: one generic ::event signal, another, more specific,
1761 * signal that matches the type of event delivered (e.g.
1762 * #GtkWidget::key-press-event) and finally a generic
1763 * #GtkWidget::event-after signal.
1765 * Returns: %TRUE to stop other handlers from being invoked for the event
1766 * and to cancel the emission of the second specific ::event signal.
1767 * %FALSE to propagate the event further and to allow the emission of
1768 * the second signal. The ::event-after signal is emitted regardless of
1771 widget_signals[EVENT] =
1772 g_signal_new (I_("event"),
1773 G_TYPE_FROM_CLASS (klass),
1775 G_STRUCT_OFFSET (GtkWidgetClass, event),
1776 _gtk_boolean_handled_accumulator, NULL,
1777 _gtk_marshal_BOOLEAN__BOXED,
1779 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1782 * GtkWidget::event-after:
1783 * @widget: the object which received the signal.
1784 * @event: the #GdkEvent which triggered this signal
1786 * After the emission of the #GtkWidget::event signal and (optionally)
1787 * the second more specific signal, ::event-after will be emitted
1788 * regardless of the previous two signals handlers return values.
1791 widget_signals[EVENT_AFTER] =
1792 g_signal_new (I_("event-after"),
1793 G_TYPE_FROM_CLASS (klass),
1797 _gtk_marshal_VOID__BOXED,
1799 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1802 * GtkWidget::button-press-event:
1803 * @widget: the object which received the signal.
1804 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1807 * The ::button-press-event signal will be emitted when a button
1808 * (typically from a mouse) is pressed.
1810 * To receive this signal, the #GdkWindow associated to the
1811 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1813 * This signal will be sent to the grab widget if there is one.
1815 * Returns: %TRUE to stop other handlers from being invoked for the event.
1816 * %FALSE to propagate the event further.
1818 widget_signals[BUTTON_PRESS_EVENT] =
1819 g_signal_new (I_("button-press-event"),
1820 G_TYPE_FROM_CLASS (klass),
1822 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1823 _gtk_boolean_handled_accumulator, NULL,
1824 _gtk_marshal_BOOLEAN__BOXED,
1826 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1829 * GtkWidget::button-release-event:
1830 * @widget: the object which received the signal.
1831 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1834 * The ::button-release-event signal will be emitted when a button
1835 * (typically from a mouse) is released.
1837 * To receive this signal, the #GdkWindow associated to the
1838 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1840 * This signal will be sent to the grab widget if there is one.
1842 * Returns: %TRUE to stop other handlers from being invoked for the event.
1843 * %FALSE to propagate the event further.
1845 widget_signals[BUTTON_RELEASE_EVENT] =
1846 g_signal_new (I_("button-release-event"),
1847 G_TYPE_FROM_CLASS (klass),
1849 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1850 _gtk_boolean_handled_accumulator, NULL,
1851 _gtk_marshal_BOOLEAN__BOXED,
1853 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1856 * GtkWidget::scroll-event:
1857 * @widget: the object which received the signal.
1858 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1861 * The ::scroll-event signal is emitted when a button in the 4 to 7
1862 * range is pressed. Wheel mice are usually configured to generate
1863 * button press events for buttons 4 and 5 when the wheel is turned.
1865 * To receive this signal, the #GdkWindow associated to the widget needs
1866 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1868 * This signal will be sent to the grab widget if there is one.
1870 * Returns: %TRUE to stop other handlers from being invoked for the event.
1871 * %FALSE to propagate the event further.
1873 widget_signals[SCROLL_EVENT] =
1874 g_signal_new (I_("scroll-event"),
1875 G_TYPE_FROM_CLASS (klass),
1877 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1878 _gtk_boolean_handled_accumulator, NULL,
1879 _gtk_marshal_BOOLEAN__BOXED,
1881 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1884 * GtkWidget::motion-notify-event:
1885 * @widget: the object which received the signal.
1886 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1889 * The ::motion-notify-event signal is emitted when the pointer moves
1890 * over the widget's #GdkWindow.
1892 * To receive this signal, the #GdkWindow associated to the widget
1893 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1895 * This signal will be sent to the grab widget if there is one.
1897 * Returns: %TRUE to stop other handlers from being invoked for the event.
1898 * %FALSE to propagate the event further.
1900 widget_signals[MOTION_NOTIFY_EVENT] =
1901 g_signal_new (I_("motion-notify-event"),
1902 G_TYPE_FROM_CLASS (klass),
1904 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1905 _gtk_boolean_handled_accumulator, NULL,
1906 _gtk_marshal_BOOLEAN__BOXED,
1908 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1911 * GtkWidget::composited-changed:
1912 * @widget: the object on which the signal is emitted
1914 * The ::composited-changed signal is emitted when the composited
1915 * status of @widget<!-- -->s screen changes.
1916 * See gdk_screen_is_composited().
1918 widget_signals[COMPOSITED_CHANGED] =
1919 g_signal_new (I_("composited-changed"),
1920 G_TYPE_FROM_CLASS (klass),
1921 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1922 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1924 _gtk_marshal_VOID__VOID,
1928 * GtkWidget::delete-event:
1929 * @widget: the object which received the signal
1930 * @event: the event which triggered this signal
1932 * The ::delete-event signal is emitted if a user requests that
1933 * a toplevel window is closed. The default handler for this signal
1934 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1935 * this signal will cause the window to be hidden instead, so that
1936 * it can later be shown again without reconstructing it.
1938 * Returns: %TRUE to stop other handlers from being invoked for the event.
1939 * %FALSE to propagate the event further.
1941 widget_signals[DELETE_EVENT] =
1942 g_signal_new (I_("delete-event"),
1943 G_TYPE_FROM_CLASS (klass),
1945 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1946 _gtk_boolean_handled_accumulator, NULL,
1947 _gtk_marshal_BOOLEAN__BOXED,
1949 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1952 * GtkWidget::destroy-event:
1953 * @widget: the object which received the signal.
1954 * @event: the event which triggered this signal
1956 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1957 * You rarely get this signal, because most widgets disconnect themselves
1958 * from their window before they destroy it, so no widget owns the
1959 * window at destroy time.
1961 * To receive this signal, the #GdkWindow associated to the widget needs
1962 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1963 * automatically for all new windows.
1965 * Returns: %TRUE to stop other handlers from being invoked for the event.
1966 * %FALSE to propagate the event further.
1968 widget_signals[DESTROY_EVENT] =
1969 g_signal_new (I_("destroy-event"),
1970 G_TYPE_FROM_CLASS (klass),
1972 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1973 _gtk_boolean_handled_accumulator, NULL,
1974 _gtk_marshal_BOOLEAN__BOXED,
1976 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1979 * GtkWidget::key-press-event:
1980 * @widget: the object which received the signal
1981 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1983 * The ::key-press-event signal is emitted when a key is pressed.
1985 * To receive this signal, the #GdkWindow associated to the widget needs
1986 * to enable the #GDK_KEY_PRESS_MASK mask.
1988 * This signal will be sent to the grab widget if there is one.
1990 * Returns: %TRUE to stop other handlers from being invoked for the event.
1991 * %FALSE to propagate the event further.
1993 widget_signals[KEY_PRESS_EVENT] =
1994 g_signal_new (I_("key-press-event"),
1995 G_TYPE_FROM_CLASS (klass),
1997 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1998 _gtk_boolean_handled_accumulator, NULL,
1999 _gtk_marshal_BOOLEAN__BOXED,
2001 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2004 * GtkWidget::key-release-event:
2005 * @widget: the object which received the signal
2006 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2008 * The ::key-release-event signal is emitted when a key is pressed.
2010 * To receive this signal, the #GdkWindow associated to the widget needs
2011 * to enable the #GDK_KEY_RELEASE_MASK mask.
2013 * This signal will be sent to the grab widget if there is one.
2015 * Returns: %TRUE to stop other handlers from being invoked for the event.
2016 * %FALSE to propagate the event further.
2018 widget_signals[KEY_RELEASE_EVENT] =
2019 g_signal_new (I_("key-release-event"),
2020 G_TYPE_FROM_CLASS (klass),
2022 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2023 _gtk_boolean_handled_accumulator, NULL,
2024 _gtk_marshal_BOOLEAN__BOXED,
2026 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2029 * GtkWidget::enter-notify-event:
2030 * @widget: the object which received the signal
2031 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2034 * The ::enter-notify-event will be emitted when the pointer enters
2035 * the @widget's window.
2037 * To receive this signal, the #GdkWindow associated to the widget needs
2038 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2040 * This signal will be sent to the grab widget if there is one.
2042 * Returns: %TRUE to stop other handlers from being invoked for the event.
2043 * %FALSE to propagate the event further.
2045 widget_signals[ENTER_NOTIFY_EVENT] =
2046 g_signal_new (I_("enter-notify-event"),
2047 G_TYPE_FROM_CLASS (klass),
2049 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2050 _gtk_boolean_handled_accumulator, NULL,
2051 _gtk_marshal_BOOLEAN__BOXED,
2053 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2056 * GtkWidget::leave-notify-event:
2057 * @widget: the object which received the signal
2058 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2061 * The ::leave-notify-event will be emitted when the pointer leaves
2062 * the @widget's window.
2064 * To receive this signal, the #GdkWindow associated to the widget needs
2065 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2067 * This signal will be sent to the grab widget if there is one.
2069 * Returns: %TRUE to stop other handlers from being invoked for the event.
2070 * %FALSE to propagate the event further.
2072 widget_signals[LEAVE_NOTIFY_EVENT] =
2073 g_signal_new (I_("leave-notify-event"),
2074 G_TYPE_FROM_CLASS (klass),
2076 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2077 _gtk_boolean_handled_accumulator, NULL,
2078 _gtk_marshal_BOOLEAN__BOXED,
2080 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2083 * GtkWidget::configure-event:
2084 * @widget: the object which received the signal
2085 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2088 * The ::configure-event signal will be emitted when the size, position or
2089 * stacking of the @widget's window has changed.
2091 * To receive this signal, the #GdkWindow associated to the widget needs
2092 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2093 * automatically for all new windows.
2095 * Returns: %TRUE to stop other handlers from being invoked for the event.
2096 * %FALSE to propagate the event further.
2098 widget_signals[CONFIGURE_EVENT] =
2099 g_signal_new (I_("configure-event"),
2100 G_TYPE_FROM_CLASS (klass),
2102 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2103 _gtk_boolean_handled_accumulator, NULL,
2104 _gtk_marshal_BOOLEAN__BOXED,
2106 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2109 * GtkWidget::focus-in-event:
2110 * @widget: the object which received the signal
2111 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2114 * The ::focus-in-event signal will be emitted when the keyboard focus
2115 * enters the @widget's window.
2117 * To receive this signal, the #GdkWindow associated to the widget needs
2118 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2120 * Returns: %TRUE to stop other handlers from being invoked for the event.
2121 * %FALSE to propagate the event further.
2123 widget_signals[FOCUS_IN_EVENT] =
2124 g_signal_new (I_("focus-in-event"),
2125 G_TYPE_FROM_CLASS (klass),
2127 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2128 _gtk_boolean_handled_accumulator, NULL,
2129 _gtk_marshal_BOOLEAN__BOXED,
2131 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2134 * GtkWidget::focus-out-event:
2135 * @widget: the object which received the signal
2136 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2139 * The ::focus-out-event signal will be emitted when the keyboard focus
2140 * leaves the @widget's window.
2142 * To receive this signal, the #GdkWindow associated to the widget needs
2143 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2145 * Returns: %TRUE to stop other handlers from being invoked for the event.
2146 * %FALSE to propagate the event further.
2148 widget_signals[FOCUS_OUT_EVENT] =
2149 g_signal_new (I_("focus-out-event"),
2150 G_TYPE_FROM_CLASS (klass),
2152 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2153 _gtk_boolean_handled_accumulator, NULL,
2154 _gtk_marshal_BOOLEAN__BOXED,
2156 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2159 * GtkWidget::map-event:
2160 * @widget: the object which received the signal
2161 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2163 * The ::map-event signal will be emitted when the @widget's window is
2164 * mapped. A window is mapped when it becomes visible on the screen.
2166 * To receive this signal, the #GdkWindow associated to the widget needs
2167 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2168 * automatically for all new windows.
2170 * Returns: %TRUE to stop other handlers from being invoked for the event.
2171 * %FALSE to propagate the event further.
2173 widget_signals[MAP_EVENT] =
2174 g_signal_new (I_("map-event"),
2175 G_TYPE_FROM_CLASS (klass),
2177 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2178 _gtk_boolean_handled_accumulator, NULL,
2179 _gtk_marshal_BOOLEAN__BOXED,
2181 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2184 * GtkWidget::unmap-event:
2185 * @widget: the object which received the signal
2186 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2188 * The ::unmap-event signal may be emitted when the @widget's window is
2189 * unmapped. A window is unmapped when it becomes invisible on the screen.
2191 * For performance reasons GTK+ may not emit ::unmap-event, so one
2192 * should always also implement ::unrealize in order to release
2193 * resources and disconnect signal handlers.
2195 * To receive this signal, the #GdkWindow associated to the widget needs
2196 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2197 * automatically for all new windows.
2199 * Returns: %TRUE to stop other handlers from being invoked for the event.
2200 * %FALSE to propagate the event further.
2202 widget_signals[UNMAP_EVENT] =
2203 g_signal_new (I_("unmap-event"),
2204 G_TYPE_FROM_CLASS (klass),
2206 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2207 _gtk_boolean_handled_accumulator, NULL,
2208 _gtk_marshal_BOOLEAN__BOXED,
2210 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2213 * GtkWidget::property-notify-event:
2214 * @widget: the object which received the signal
2215 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2218 * The ::property-notify-event signal will be emitted when a property on
2219 * the @widget's window has been changed or deleted.
2221 * To receive this signal, the #GdkWindow associated to the widget needs
2222 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2224 * Returns: %TRUE to stop other handlers from being invoked for the event.
2225 * %FALSE to propagate the event further.
2227 widget_signals[PROPERTY_NOTIFY_EVENT] =
2228 g_signal_new (I_("property-notify-event"),
2229 G_TYPE_FROM_CLASS (klass),
2231 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2232 _gtk_boolean_handled_accumulator, NULL,
2233 _gtk_marshal_BOOLEAN__BOXED,
2235 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2238 * GtkWidget::selection-clear-event:
2239 * @widget: the object which received the signal
2240 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2243 * The ::selection-clear-event signal will be emitted when the
2244 * the @widget's window has lost ownership of a selection.
2246 * Returns: %TRUE to stop other handlers from being invoked for the event.
2247 * %FALSE to propagate the event further.
2249 widget_signals[SELECTION_CLEAR_EVENT] =
2250 g_signal_new (I_("selection-clear-event"),
2251 G_TYPE_FROM_CLASS (klass),
2253 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2254 _gtk_boolean_handled_accumulator, NULL,
2255 _gtk_marshal_BOOLEAN__BOXED,
2257 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2260 * GtkWidget::selection-request-event:
2261 * @widget: the object which received the signal
2262 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2265 * The ::selection-request-event signal will be emitted when
2266 * another client requests ownership of the selection owned by
2267 * the @widget's window.
2269 * Returns: %TRUE to stop other handlers from being invoked for the event.
2270 * %FALSE to propagate the event further.
2272 widget_signals[SELECTION_REQUEST_EVENT] =
2273 g_signal_new (I_("selection-request-event"),
2274 G_TYPE_FROM_CLASS (klass),
2276 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2277 _gtk_boolean_handled_accumulator, NULL,
2278 _gtk_marshal_BOOLEAN__BOXED,
2280 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2283 * GtkWidget::selection-notify-event:
2284 * @widget: the object which received the signal.
2287 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2289 widget_signals[SELECTION_NOTIFY_EVENT] =
2290 g_signal_new (I_("selection-notify-event"),
2291 G_TYPE_FROM_CLASS (klass),
2293 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2294 _gtk_boolean_handled_accumulator, NULL,
2295 _gtk_marshal_BOOLEAN__BOXED,
2297 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2300 * GtkWidget::selection-received:
2301 * @widget: the object which received the signal.
2305 widget_signals[SELECTION_RECEIVED] =
2306 g_signal_new (I_("selection-received"),
2307 G_TYPE_FROM_CLASS (klass),
2309 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2311 _gtk_marshal_VOID__BOXED_UINT,
2313 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2317 * GtkWidget::selection-get:
2318 * @widget: the object which received the signal.
2323 widget_signals[SELECTION_GET] =
2324 g_signal_new (I_("selection-get"),
2325 G_TYPE_FROM_CLASS (klass),
2327 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2329 _gtk_marshal_VOID__BOXED_UINT_UINT,
2331 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2336 * GtkWidget::proximity-in-event:
2337 * @widget: the object which received the signal
2338 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2341 * To receive this signal the #GdkWindow associated to the widget needs
2342 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2344 * This signal will be sent to the grab widget if there is one.
2346 * Returns: %TRUE to stop other handlers from being invoked for the event.
2347 * %FALSE to propagate the event further.
2349 widget_signals[PROXIMITY_IN_EVENT] =
2350 g_signal_new (I_("proximity-in-event"),
2351 G_TYPE_FROM_CLASS (klass),
2353 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2354 _gtk_boolean_handled_accumulator, NULL,
2355 _gtk_marshal_BOOLEAN__BOXED,
2357 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2360 * GtkWidget::proximity-out-event:
2361 * @widget: the object which received the signal
2362 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2365 * To receive this signal the #GdkWindow associated to the widget needs
2366 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2368 * This signal will be sent to the grab widget if there is one.
2370 * Returns: %TRUE to stop other handlers from being invoked for the event.
2371 * %FALSE to propagate the event further.
2373 widget_signals[PROXIMITY_OUT_EVENT] =
2374 g_signal_new (I_("proximity-out-event"),
2375 G_TYPE_FROM_CLASS (klass),
2377 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2378 _gtk_boolean_handled_accumulator, NULL,
2379 _gtk_marshal_BOOLEAN__BOXED,
2381 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2384 * GtkWidget::drag-leave:
2385 * @widget: the object which received the signal.
2386 * @drag_context: the drag context
2387 * @time: the timestamp of the motion event
2389 * The ::drag-leave signal is emitted on the drop site when the cursor
2390 * leaves the widget. A typical reason to connect to this signal is to
2391 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2392 * with gtk_drag_unhighlight()
2394 widget_signals[DRAG_LEAVE] =
2395 g_signal_new (I_("drag-leave"),
2396 G_TYPE_FROM_CLASS (klass),
2398 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2400 _gtk_marshal_VOID__OBJECT_UINT,
2402 GDK_TYPE_DRAG_CONTEXT,
2406 * GtkWidget::drag-begin:
2407 * @widget: the object which received the signal
2408 * @drag_context: the drag context
2410 * The ::drag-begin signal is emitted on the drag source when a drag is
2411 * started. A typical reason to connect to this signal is to set up a
2412 * custom drag icon with gtk_drag_source_set_icon().
2414 * Note that some widgets set up a drag icon in the default handler of
2415 * this signal, so you may have to use g_signal_connect_after() to
2416 * override what the default handler did.
2418 widget_signals[DRAG_BEGIN] =
2419 g_signal_new (I_("drag-begin"),
2420 G_TYPE_FROM_CLASS (klass),
2422 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2424 _gtk_marshal_VOID__OBJECT,
2426 GDK_TYPE_DRAG_CONTEXT);
2429 * GtkWidget::drag-end:
2430 * @widget: the object which received the signal
2431 * @drag_context: the drag context
2433 * The ::drag-end signal is emitted on the drag source when a drag is
2434 * finished. A typical reason to connect to this signal is to undo
2435 * things done in #GtkWidget::drag-begin.
2437 widget_signals[DRAG_END] =
2438 g_signal_new (I_("drag-end"),
2439 G_TYPE_FROM_CLASS (klass),
2441 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2443 _gtk_marshal_VOID__OBJECT,
2445 GDK_TYPE_DRAG_CONTEXT);
2448 * GtkWidget::drag-data-delete:
2449 * @widget: the object which received the signal
2450 * @drag_context: the drag context
2452 * The ::drag-data-delete signal is emitted on the drag source when a drag
2453 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2454 * handler is responsible for deleting the data that has been dropped. What
2455 * "delete" means depends on the context of the drag operation.
2457 widget_signals[DRAG_DATA_DELETE] =
2458 g_signal_new (I_("drag-data-delete"),
2459 G_TYPE_FROM_CLASS (klass),
2461 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2463 _gtk_marshal_VOID__OBJECT,
2465 GDK_TYPE_DRAG_CONTEXT);
2468 * GtkWidget::drag-failed:
2469 * @widget: the object which received the signal
2470 * @drag_context: the drag context
2471 * @result: the result of the drag operation
2473 * The ::drag-failed signal is emitted on the drag source when a drag has
2474 * failed. The signal handler may hook custom code to handle a failed DND
2475 * operation based on the type of error, it returns %TRUE is the failure has
2476 * been already handled (not showing the default "drag operation failed"
2477 * animation), otherwise it returns %FALSE.
2479 * Return value: %TRUE if the failed drag operation has been already handled.
2483 widget_signals[DRAG_FAILED] =
2484 g_signal_new (I_("drag-failed"),
2485 G_TYPE_FROM_CLASS (klass),
2487 0, _gtk_boolean_handled_accumulator, NULL,
2488 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2490 GDK_TYPE_DRAG_CONTEXT,
2491 GTK_TYPE_DRAG_RESULT);
2494 * GtkWidget::drag-motion:
2495 * @widget: the object which received the signal
2496 * @drag_context: the drag context
2497 * @x: the x coordinate of the current cursor position
2498 * @y: the y coordinate of the current cursor position
2499 * @time: the timestamp of the motion event
2500 * @returns: whether the cursor position is in a drop zone
2502 * The drag-motion signal is emitted on the drop site when the user
2503 * moves the cursor over the widget during a drag. The signal handler
2504 * must determine whether the cursor position is in a drop zone or not.
2505 * If it is not in a drop zone, it returns %FALSE and no further processing
2506 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2507 * handler is responsible for providing the necessary information for
2508 * displaying feedback to the user, by calling gdk_drag_status().
2510 * If the decision whether the drop will be accepted or rejected can't be
2511 * made based solely on the cursor position and the type of the data, the
2512 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2513 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2514 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2515 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2516 * when using the drag-motion signal that way.
2518 * Also note that there is no drag-enter signal. The drag receiver has to
2519 * keep track of whether he has received any drag-motion signals since the
2520 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2521 * an "enter" signal. Upon an "enter", the handler will typically highlight
2522 * the drop site with gtk_drag_highlight().
2525 * drag_motion (GtkWidget *widget,
2526 * GdkDragContext *context,
2533 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2535 * if (!private_data->drag_highlight)
2537 * private_data->drag_highlight = 1;
2538 * gtk_drag_highlight (widget);
2541 * target = gtk_drag_dest_find_target (widget, context, NULL);
2542 * if (target == GDK_NONE)
2543 * gdk_drag_status (context, 0, time);
2546 * private_data->pending_status = context->suggested_action;
2547 * gtk_drag_get_data (widget, context, target, time);
2554 * drag_data_received (GtkWidget *widget,
2555 * GdkDragContext *context,
2558 * GtkSelectionData *selection_data,
2562 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2564 * if (private_data->suggested_action)
2566 * private_data->suggested_action = 0;
2568 * /* We are getting this data due to a request in drag_motion,
2569 * * rather than due to a request in drag_drop, so we are just
2570 * * supposed to call gdk_drag_status (), not actually paste in
2573 * str = gtk_selection_data_get_text (selection_data);
2574 * if (!data_is_acceptable (str))
2575 * gdk_drag_status (context, 0, time);
2577 * gdk_drag_status (context, private_data->suggested_action, time);
2581 * /* accept the drop */
2586 widget_signals[DRAG_MOTION] =
2587 g_signal_new (I_("drag-motion"),
2588 G_TYPE_FROM_CLASS (klass),
2590 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2591 _gtk_boolean_handled_accumulator, NULL,
2592 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2594 GDK_TYPE_DRAG_CONTEXT,
2600 * GtkWidget::drag-drop:
2601 * @widget: the object which received the signal
2602 * @drag_context: the drag context
2603 * @x: the x coordinate of the current cursor position
2604 * @y: the y coordinate of the current cursor position
2605 * @time: the timestamp of the motion event
2606 * @returns: whether the cursor position is in a drop zone
2608 * The ::drag-drop signal is emitted on the drop site when the user drops
2609 * the data onto the widget. The signal handler must determine whether
2610 * the cursor position is in a drop zone or not. If it is not in a drop
2611 * zone, it returns %FALSE and no further processing is necessary.
2612 * Otherwise, the handler returns %TRUE. In this case, the handler must
2613 * ensure that gtk_drag_finish() is called to let the source know that
2614 * the drop is done. The call to gtk_drag_finish() can be done either
2615 * directly or in a #GtkWidget::drag-data-received handler which gets
2616 * triggered by calling gtk_drag_get_data() to receive the data for one
2617 * or more of the supported targets.
2619 widget_signals[DRAG_DROP] =
2620 g_signal_new (I_("drag-drop"),
2621 G_TYPE_FROM_CLASS (klass),
2623 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2624 _gtk_boolean_handled_accumulator, NULL,
2625 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2627 GDK_TYPE_DRAG_CONTEXT,
2633 * GtkWidget::drag-data-get:
2634 * @widget: the object which received the signal
2635 * @drag_context: the drag context
2636 * @data: the #GtkSelectionData to be filled with the dragged data
2637 * @info: the info that has been registered with the target in the
2639 * @time: the timestamp at which the data was requested
2641 * The ::drag-data-get signal is emitted on the drag source when the drop
2642 * site requests the data which is dragged. It is the responsibility of
2643 * the signal handler to fill @data with the data in the format which
2644 * is indicated by @info. See gtk_selection_data_set() and
2645 * gtk_selection_data_set_text().
2647 widget_signals[DRAG_DATA_GET] =
2648 g_signal_new (I_("drag-data-get"),
2649 G_TYPE_FROM_CLASS (klass),
2651 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2653 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2655 GDK_TYPE_DRAG_CONTEXT,
2656 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2661 * GtkWidget::drag-data-received:
2662 * @widget: the object which received the signal
2663 * @drag_context: the drag context
2664 * @x: where the drop happened
2665 * @y: where the drop happened
2666 * @data: the received data
2667 * @info: the info that has been registered with the target in the
2669 * @time: the timestamp at which the data was received
2671 * The ::drag-data-received signal is emitted on the drop site when the
2672 * dragged data has been received. If the data was received in order to
2673 * determine whether the drop will be accepted, the handler is expected
2674 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2675 * If the data was received in response to a #GtkWidget::drag-drop signal
2676 * (and this is the last target to be received), the handler for this
2677 * signal is expected to process the received data and then call
2678 * gtk_drag_finish(), setting the @success parameter depending on whether
2679 * the data was processed successfully.
2681 * The handler may inspect and modify @drag_context->action before calling
2682 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2683 * following example:
2686 * drag_data_received (GtkWidget *widget,
2687 * GdkDragContext *drag_context,
2690 * GtkSelectionData *data,
2694 * if ((data->length >= 0) && (data->format == 8))
2696 * if (drag_context->action == GDK_ACTION_ASK)
2698 * GtkWidget *dialog;
2701 * dialog = gtk_message_dialog_new (NULL,
2702 * GTK_DIALOG_MODAL |
2703 * GTK_DIALOG_DESTROY_WITH_PARENT,
2705 * GTK_BUTTONS_YES_NO,
2706 * "Move the data ?\n");
2707 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2708 * gtk_widget_destroy (dialog);
2710 * if (response == GTK_RESPONSE_YES)
2711 * drag_context->action = GDK_ACTION_MOVE;
2713 * drag_context->action = GDK_ACTION_COPY;
2716 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2720 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2724 widget_signals[DRAG_DATA_RECEIVED] =
2725 g_signal_new (I_("drag-data-received"),
2726 G_TYPE_FROM_CLASS (klass),
2728 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2730 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2732 GDK_TYPE_DRAG_CONTEXT,
2735 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2740 * GtkWidget::visibility-notify-event:
2741 * @widget: the object which received the signal
2742 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2743 * triggered this signal.
2745 * The ::visibility-notify-event will be emitted when the @widget's window
2746 * is obscured or unobscured.
2748 * To receive this signal the #GdkWindow associated to the widget needs
2749 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2751 * Returns: %TRUE to stop other handlers from being invoked for the event.
2752 * %FALSE to propagate the event further.
2754 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2755 g_signal_new (I_("visibility-notify-event"),
2756 G_TYPE_FROM_CLASS (klass),
2758 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2759 _gtk_boolean_handled_accumulator, NULL,
2760 _gtk_marshal_BOOLEAN__BOXED,
2762 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2765 * GtkWidget::client-event:
2766 * @widget: the object which received the signal
2767 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2770 * The ::client-event will be emitted when the @widget's window
2771 * receives a message (via a ClientMessage event) from another
2774 * Returns: %TRUE to stop other handlers from being invoked for
2775 * the event. %FALSE to propagate the event further.
2777 widget_signals[CLIENT_EVENT] =
2778 g_signal_new (I_("client-event"),
2779 G_TYPE_FROM_CLASS (klass),
2781 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2782 _gtk_boolean_handled_accumulator, NULL,
2783 _gtk_marshal_BOOLEAN__BOXED,
2785 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2788 * GtkWidget::no-expose-event:
2789 * @widget: the object which received the signal
2790 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2793 * The ::no-expose-event will be emitted when the @widget's window is
2794 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2795 * If the source window was partially obscured #GdkEventExpose events will
2796 * be generated for those areas.
2798 * Returns: %TRUE to stop other handlers from being invoked for the event.
2799 * %FALSE to propagate the event further.
2801 widget_signals[NO_EXPOSE_EVENT] =
2802 g_signal_new (I_("no-expose-event"),
2803 G_TYPE_FROM_CLASS (klass),
2805 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2806 _gtk_boolean_handled_accumulator, NULL,
2807 _gtk_marshal_BOOLEAN__BOXED,
2809 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2812 * GtkWidget::window-state-event:
2813 * @widget: the object which received the signal
2814 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2815 * triggered this signal.
2817 * The ::window-state-event will be emitted when the state of the
2818 * toplevel window associated to the @widget changes.
2820 * To receive this signal the #GdkWindow associated to the widget
2821 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2822 * this mask automatically for all new windows.
2824 * Returns: %TRUE to stop other handlers from being invoked for the
2825 * event. %FALSE to propagate the event further.
2827 widget_signals[WINDOW_STATE_EVENT] =
2828 g_signal_new (I_("window-state-event"),
2829 G_TYPE_FROM_CLASS (klass),
2831 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2832 _gtk_boolean_handled_accumulator, NULL,
2833 _gtk_marshal_BOOLEAN__BOXED,
2835 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2838 * GtkWidget::damage-event:
2839 * @widget: the object which received the signal
2840 * @event: the #GdkEventExpose event
2842 * Emitted when a redirected window belonging to @widget gets drawn into.
2843 * The region/area members of the event shows what area of the redirected
2844 * drawable was drawn into.
2846 * Returns: %TRUE to stop other handlers from being invoked for the event.
2847 * %FALSE to propagate the event further.
2851 widget_signals[DAMAGE_EVENT] =
2852 g_signal_new (I_("damage-event"),
2853 G_TYPE_FROM_CLASS (klass),
2855 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2856 _gtk_boolean_handled_accumulator, NULL,
2857 _gtk_marshal_BOOLEAN__BOXED,
2859 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2862 * GtkWidget::grab-broken-event:
2863 * @widget: the object which received the signal
2864 * @event: the #GdkEventGrabBroken event
2866 * Emitted when a pointer or keyboard grab on a window belonging
2867 * to @widget gets broken.
2869 * On X11, this happens when the grab window becomes unviewable
2870 * (i.e. it or one of its ancestors is unmapped), or if the same
2871 * application grabs the pointer or keyboard again.
2873 * Returns: %TRUE to stop other handlers from being invoked for
2874 * the event. %FALSE to propagate the event further.
2878 widget_signals[GRAB_BROKEN_EVENT] =
2879 g_signal_new (I_("grab-broken-event"),
2880 G_TYPE_FROM_CLASS (klass),
2882 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2883 _gtk_boolean_handled_accumulator, NULL,
2884 _gtk_marshal_BOOLEAN__BOXED,
2886 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2889 * GtkWidget::query-tooltip:
2890 * @widget: the object which received the signal
2891 * @x: the x coordinate of the cursor position where the request has
2892 * been emitted, relative to @widget->window
2893 * @y: the y coordinate of the cursor position where the request has
2894 * been emitted, relative to @widget->window
2895 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2896 * @tooltip: a #GtkTooltip
2898 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2899 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2900 * focus in keyboard mode.
2902 * Using the given coordinates, the signal handler should determine
2903 * whether a tooltip should be shown for @widget. If this is the case
2904 * %TRUE should be returned, %FALSE otherwise. Note that if
2905 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2906 * should not be used.
2908 * The signal handler is free to manipulate @tooltip with the therefore
2909 * destined function calls.
2911 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2915 widget_signals[QUERY_TOOLTIP] =
2916 g_signal_new (I_("query-tooltip"),
2917 G_TYPE_FROM_CLASS (klass),
2919 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2920 _gtk_boolean_handled_accumulator, NULL,
2921 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2929 * GtkWidget::popup-menu
2930 * @widget: the object which received the signal
2932 * This signal gets emitted whenever a widget should pop up a context
2933 * menu. This usually happens through the standard key binding mechanism;
2934 * by pressing a certain key while a widget is focused, the user can cause
2935 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2936 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2937 * for an example of how to use this signal.
2939 * Returns: %TRUE if a menu was activated
2941 widget_signals[POPUP_MENU] =
2942 g_signal_new (I_("popup-menu"),
2943 G_TYPE_FROM_CLASS (klass),
2944 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2945 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2946 _gtk_boolean_handled_accumulator, NULL,
2947 _gtk_marshal_BOOLEAN__VOID,
2951 * GtkWidget::show-help:
2952 * @widget: the object which received the signal.
2955 widget_signals[SHOW_HELP] =
2956 g_signal_new (I_("show-help"),
2957 G_TYPE_FROM_CLASS (klass),
2958 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2959 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2960 _gtk_boolean_handled_accumulator, NULL,
2961 _gtk_marshal_BOOLEAN__ENUM,
2963 GTK_TYPE_WIDGET_HELP_TYPE);
2966 * GtkWidget::accel-closures-changed:
2967 * @widget: the object which received the signal.
2969 widget_signals[ACCEL_CLOSURES_CHANGED] =
2970 g_signal_new (I_("accel-closures-changed"),
2971 G_TYPE_FROM_CLASS (klass),
2975 _gtk_marshal_VOID__VOID,
2979 * GtkWidget::screen-changed:
2980 * @widget: the object on which the signal is emitted
2981 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2982 * widget was not associated with a screen before
2984 * The ::screen-changed signal gets emitted when the
2985 * screen of a widget has changed.
2987 widget_signals[SCREEN_CHANGED] =
2988 g_signal_new (I_("screen-changed"),
2989 G_TYPE_FROM_CLASS (klass),
2991 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2993 _gtk_marshal_VOID__OBJECT,
2998 * GtkWidget::can-activate-accel:
2999 * @widget: the object which received the signal
3000 * @signal_id: the ID of a signal installed on @widget
3002 * Determines whether an accelerator that activates the signal
3003 * identified by @signal_id can currently be activated.
3004 * This signal is present to allow applications and derived
3005 * widgets to override the default #GtkWidget handling
3006 * for determining whether an accelerator can be activated.
3008 * Returns: %TRUE if the signal can be activated.
3010 widget_signals[CAN_ACTIVATE_ACCEL] =
3011 g_signal_new (I_("can-activate-accel"),
3012 G_TYPE_FROM_CLASS (klass),
3014 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3015 _gtk_boolean_handled_accumulator, NULL,
3016 _gtk_marshal_BOOLEAN__UINT,
3017 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3019 binding_set = gtk_binding_set_by_class (klass);
3020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3022 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3025 gtk_binding_entry_add_signal (binding_set, GDK_KEY_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_KP_F1, GDK_CONTROL_MASK,
3031 GTK_TYPE_WIDGET_HELP_TYPE,
3032 GTK_WIDGET_HELP_TOOLTIP);
3033 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3035 GTK_TYPE_WIDGET_HELP_TYPE,
3036 GTK_WIDGET_HELP_WHATS_THIS);
3037 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3039 GTK_TYPE_WIDGET_HELP_TYPE,
3040 GTK_WIDGET_HELP_WHATS_THIS);
3042 gtk_widget_class_install_style_property (klass,
3043 g_param_spec_boolean ("interior-focus",
3044 P_("Interior Focus"),
3045 P_("Whether to draw the focus indicator inside widgets"),
3047 GTK_PARAM_READABLE));
3049 gtk_widget_class_install_style_property (klass,
3050 g_param_spec_int ("focus-line-width",
3051 P_("Focus linewidth"),
3052 P_("Width, in pixels, of the focus indicator line"),
3054 GTK_PARAM_READABLE));
3056 gtk_widget_class_install_style_property (klass,
3057 g_param_spec_string ("focus-line-pattern",
3058 P_("Focus line dash pattern"),
3059 P_("Dash pattern used to draw the focus indicator"),
3061 GTK_PARAM_READABLE));
3062 gtk_widget_class_install_style_property (klass,
3063 g_param_spec_int ("focus-padding",
3064 P_("Focus padding"),
3065 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3067 GTK_PARAM_READABLE));
3068 gtk_widget_class_install_style_property (klass,
3069 g_param_spec_boxed ("cursor-color",
3071 P_("Color with which to draw insertion cursor"),
3073 GTK_PARAM_READABLE));
3074 gtk_widget_class_install_style_property (klass,
3075 g_param_spec_boxed ("secondary-cursor-color",
3076 P_("Secondary cursor color"),
3077 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3079 GTK_PARAM_READABLE));
3080 gtk_widget_class_install_style_property (klass,
3081 g_param_spec_float ("cursor-aspect-ratio",
3082 P_("Cursor line aspect ratio"),
3083 P_("Aspect ratio with which to draw insertion cursor"),
3085 GTK_PARAM_READABLE));
3087 gtk_widget_class_install_style_property (klass,
3088 g_param_spec_boolean ("window-dragging",
3089 P_("Window dragging"),
3090 P_("Whether windows can be dragged by clicking on empty areas"),
3092 GTK_PARAM_READABLE));
3095 * GtkWidget:link-color:
3097 * The "link-color" style property defines the color of unvisited links.
3101 gtk_widget_class_install_style_property (klass,
3102 g_param_spec_boxed ("link-color",
3103 P_("Unvisited Link Color"),
3104 P_("Color of unvisited links"),
3106 GTK_PARAM_READABLE));
3109 * GtkWidget:visited-link-color:
3111 * The "visited-link-color" style property defines the color of visited links.
3115 gtk_widget_class_install_style_property (klass,
3116 g_param_spec_boxed ("visited-link-color",
3117 P_("Visited Link Color"),
3118 P_("Color of visited links"),
3120 GTK_PARAM_READABLE));
3123 * GtkWidget:wide-separators:
3125 * The "wide-separators" style property defines whether separators have
3126 * configurable width and should be drawn using a box instead of a line.
3130 gtk_widget_class_install_style_property (klass,
3131 g_param_spec_boolean ("wide-separators",
3132 P_("Wide Separators"),
3133 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3135 GTK_PARAM_READABLE));
3138 * GtkWidget:separator-width:
3140 * The "separator-width" style property defines the width of separators.
3141 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3145 gtk_widget_class_install_style_property (klass,
3146 g_param_spec_int ("separator-width",
3147 P_("Separator Width"),
3148 P_("The width of separators if wide-separators is TRUE"),
3150 GTK_PARAM_READABLE));
3153 * GtkWidget:separator-height:
3155 * The "separator-height" style property defines the height of separators.
3156 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3160 gtk_widget_class_install_style_property (klass,
3161 g_param_spec_int ("separator-height",
3162 P_("Separator Height"),
3163 P_("The height of separators if \"wide-separators\" is TRUE"),
3165 GTK_PARAM_READABLE));
3168 * GtkWidget:scroll-arrow-hlength:
3170 * The "scroll-arrow-hlength" style property defines the length of
3171 * horizontal scroll arrows.
3175 gtk_widget_class_install_style_property (klass,
3176 g_param_spec_int ("scroll-arrow-hlength",
3177 P_("Horizontal Scroll Arrow Length"),
3178 P_("The length of horizontal scroll arrows"),
3180 GTK_PARAM_READABLE));
3183 * GtkWidget:scroll-arrow-vlength:
3185 * The "scroll-arrow-vlength" style property defines the length of
3186 * vertical scroll arrows.
3190 gtk_widget_class_install_style_property (klass,
3191 g_param_spec_int ("scroll-arrow-vlength",
3192 P_("Vertical Scroll Arrow Length"),
3193 P_("The length of vertical scroll arrows"),
3195 GTK_PARAM_READABLE));
3197 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3201 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3205 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3206 for (node = list; node; node = node->next)
3208 GParamSpec *pspec = node->data;
3210 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3211 g_param_spec_unref (pspec);
3217 gtk_widget_set_property (GObject *object,
3219 const GValue *value,
3222 GtkWidget *widget = GTK_WIDGET (object);
3227 gchar *tooltip_markup;
3228 const gchar *tooltip_text;
3229 GtkWindow *tooltip_window;
3232 gtk_widget_set_name (widget, g_value_get_string (value));
3235 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3237 case PROP_WIDTH_REQUEST:
3238 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3240 case PROP_HEIGHT_REQUEST:
3241 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3244 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3246 case PROP_SENSITIVE:
3247 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3249 case PROP_APP_PAINTABLE:
3250 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3252 case PROP_CAN_FOCUS:
3253 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3255 case PROP_HAS_FOCUS:
3256 if (g_value_get_boolean (value))
3257 gtk_widget_grab_focus (widget);
3260 if (g_value_get_boolean (value))
3261 gtk_widget_grab_focus (widget);
3263 case PROP_CAN_DEFAULT:
3264 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3266 case PROP_HAS_DEFAULT:
3267 if (g_value_get_boolean (value))
3268 gtk_widget_grab_default (widget);
3270 case PROP_RECEIVES_DEFAULT:
3271 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3274 gtk_widget_set_style (widget, g_value_get_object (value));
3277 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3278 gtk_widget_set_events (widget, g_value_get_flags (value));
3280 case PROP_EXTENSION_EVENTS:
3281 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3283 case PROP_NO_SHOW_ALL:
3284 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3286 case PROP_HAS_TOOLTIP:
3287 gtk_widget_real_set_has_tooltip (widget,
3288 g_value_get_boolean (value), FALSE);
3290 case PROP_TOOLTIP_MARKUP:
3291 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3292 tooltip_markup = g_value_dup_string (value);
3294 /* Treat an empty string as a NULL string,
3295 * because an empty string would be useless for a tooltip:
3297 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3299 g_free (tooltip_markup);
3300 tooltip_markup = NULL;
3303 g_object_set_qdata_full (object, quark_tooltip_markup,
3304 tooltip_markup, g_free);
3306 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3307 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3308 if (gtk_widget_get_visible (widget))
3309 gtk_widget_queue_tooltip_query (widget);
3311 case PROP_TOOLTIP_TEXT:
3312 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3314 tooltip_text = g_value_get_string (value);
3316 /* Treat an empty string as a NULL string,
3317 * because an empty string would be useless for a tooltip:
3319 if (tooltip_text && (strlen (tooltip_text) == 0))
3320 tooltip_text = NULL;
3322 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3324 g_object_set_qdata_full (object, quark_tooltip_markup,
3325 tooltip_markup, g_free);
3327 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3328 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3329 if (gtk_widget_get_visible (widget))
3330 gtk_widget_queue_tooltip_query (widget);
3332 case PROP_DOUBLE_BUFFERED:
3333 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3336 gtk_widget_set_halign (widget, g_value_get_enum (value));
3339 gtk_widget_set_valign (widget, g_value_get_enum (value));
3341 case PROP_MARGIN_LEFT:
3342 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3344 case PROP_MARGIN_RIGHT:
3345 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3347 case PROP_MARGIN_TOP:
3348 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3350 case PROP_MARGIN_BOTTOM:
3351 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3354 g_object_freeze_notify (G_OBJECT (widget));
3355 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3356 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3357 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3358 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3359 g_object_thaw_notify (G_OBJECT (widget));
3362 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3364 case PROP_HEXPAND_SET:
3365 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3368 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3370 case PROP_VEXPAND_SET:
3371 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3374 g_object_freeze_notify (G_OBJECT (widget));
3375 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3376 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3377 g_object_thaw_notify (G_OBJECT (widget));
3380 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3386 gtk_widget_get_property (GObject *object,
3391 GtkWidget *widget = GTK_WIDGET (object);
3392 GtkWidgetPrivate *priv = widget->priv;
3401 g_value_set_string (value, priv->name);
3403 g_value_set_static_string (value, "");
3406 g_value_set_object (value, priv->parent);
3408 case PROP_WIDTH_REQUEST:
3411 gtk_widget_get_size_request (widget, &w, NULL);
3412 g_value_set_int (value, w);
3415 case PROP_HEIGHT_REQUEST:
3418 gtk_widget_get_size_request (widget, NULL, &h);
3419 g_value_set_int (value, h);
3423 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3425 case PROP_SENSITIVE:
3426 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3428 case PROP_APP_PAINTABLE:
3429 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3431 case PROP_CAN_FOCUS:
3432 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3434 case PROP_HAS_FOCUS:
3435 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3438 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3440 case PROP_CAN_DEFAULT:
3441 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3443 case PROP_HAS_DEFAULT:
3444 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3446 case PROP_RECEIVES_DEFAULT:
3447 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3449 case PROP_COMPOSITE_CHILD:
3450 g_value_set_boolean (value, widget->priv->composite_child);
3453 g_value_set_object (value, gtk_widget_get_style (widget));
3456 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3457 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3459 case PROP_EXTENSION_EVENTS:
3460 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3461 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3463 case PROP_NO_SHOW_ALL:
3464 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3466 case PROP_HAS_TOOLTIP:
3467 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3469 case PROP_TOOLTIP_TEXT:
3471 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3474 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3475 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3477 g_value_take_string (value, text);
3480 case PROP_TOOLTIP_MARKUP:
3481 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3484 g_value_set_object (value, gtk_widget_get_window (widget));
3486 case PROP_DOUBLE_BUFFERED:
3487 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3490 g_value_set_enum (value, gtk_widget_get_halign (widget));
3493 g_value_set_enum (value, gtk_widget_get_valign (widget));
3495 case PROP_MARGIN_LEFT:
3496 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3498 case PROP_MARGIN_RIGHT:
3499 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3501 case PROP_MARGIN_TOP:
3502 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3504 case PROP_MARGIN_BOTTOM:
3505 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3509 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3510 if (aux_info == NULL)
3512 g_value_set_int (value, 0);
3516 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3517 aux_info->margin.right),
3518 MAX (aux_info->margin.top,
3519 aux_info->margin.bottom)));
3524 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3526 case PROP_HEXPAND_SET:
3527 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3530 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3532 case PROP_VEXPAND_SET:
3533 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3536 g_value_set_boolean (value,
3537 gtk_widget_get_hexpand (widget) &&
3538 gtk_widget_get_vexpand (widget));
3541 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3547 gtk_widget_init (GtkWidget *widget)
3549 GtkWidgetPrivate *priv;
3551 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3554 priv = widget->priv;
3556 priv->child_visible = TRUE;
3557 priv->state = GTK_STATE_NORMAL;
3558 priv->saved_state = GTK_STATE_NORMAL;
3560 priv->allocation.x = -1;
3561 priv->allocation.y = -1;
3562 priv->allocation.width = 1;
3563 priv->allocation.height = 1;
3564 priv->window = NULL;
3565 priv->parent = NULL;
3567 priv->sensitive = TRUE;
3568 priv->parent_sensitive = TRUE;
3569 priv->composite_child = composite_child_stack != 0;
3570 priv->double_buffered = TRUE;
3571 priv->redraw_on_alloc = TRUE;
3572 priv->width_request_needed = TRUE;
3573 priv->height_request_needed = TRUE;
3574 priv->alloc_needed = TRUE;
3576 /* this will be set to TRUE if the widget gets a child or if the
3577 * expand flag is set on the widget, but until one of those happen
3578 * we know the expand is already properly FALSE.
3580 * We really want to default FALSE here to avoid computing expand
3581 * all over the place while initially building a widget tree.
3583 priv->need_compute_expand = FALSE;
3585 priv->style = gtk_widget_get_default_style ();
3586 g_object_ref (priv->style);
3591 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3593 GParamSpec **pspecs)
3595 GtkWidgetPrivate *priv = widget->priv;
3596 GtkWidget *container = priv->parent;
3599 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3600 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3604 * gtk_widget_freeze_child_notify:
3605 * @widget: a #GtkWidget
3607 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3608 * signals are queued until gtk_widget_thaw_child_notify() is called
3611 * This is the analogue of g_object_freeze_notify() for child properties.
3614 gtk_widget_freeze_child_notify (GtkWidget *widget)
3616 g_return_if_fail (GTK_IS_WIDGET (widget));
3618 if (!G_OBJECT (widget)->ref_count)
3621 g_object_ref (widget);
3622 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3623 g_object_unref (widget);
3627 * gtk_widget_child_notify:
3628 * @widget: a #GtkWidget
3629 * @child_property: the name of a child property installed on the
3630 * class of @widget<!-- -->'s parent
3632 * Emits a #GtkWidget::child-notify signal for the
3633 * <link linkend="child-properties">child property</link> @child_property
3636 * This is the analogue of g_object_notify() for child properties.
3639 gtk_widget_child_notify (GtkWidget *widget,
3640 const gchar *child_property)
3642 GtkWidgetPrivate *priv = widget->priv;
3645 g_return_if_fail (GTK_IS_WIDGET (widget));
3646 g_return_if_fail (child_property != NULL);
3647 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3650 g_object_ref (widget);
3651 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3653 G_OBJECT_TYPE (priv->parent),
3656 g_warning ("%s: container class `%s' has no child property named `%s'",
3658 G_OBJECT_TYPE_NAME (priv->parent),
3662 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3664 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3665 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3667 g_object_unref (widget);
3671 * gtk_widget_thaw_child_notify:
3672 * @widget: a #GtkWidget
3674 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3675 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3679 gtk_widget_thaw_child_notify (GtkWidget *widget)
3681 GObjectNotifyQueue *nqueue;
3683 g_return_if_fail (GTK_IS_WIDGET (widget));
3685 if (!G_OBJECT (widget)->ref_count)
3688 g_object_ref (widget);
3689 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3690 if (!nqueue || !nqueue->freeze_count)
3691 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3692 G_OBJECT_TYPE_NAME (widget), widget);
3694 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3695 g_object_unref (widget);
3701 * @type: type ID of the widget to create
3702 * @first_property_name: name of first property to set
3703 * @Varargs: value of first property, followed by more properties,
3706 * This is a convenience function for creating a widget and setting
3707 * its properties in one go. For example you might write:
3708 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3709 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3710 * g_object_new(), but returns a widget so you don't have to
3711 * cast the object yourself.
3713 * Return value: a new #GtkWidget of type @widget_type
3716 gtk_widget_new (GType type,
3717 const gchar *first_property_name,
3723 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3725 va_start (var_args, first_property_name);
3726 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3733 gtk_widget_queue_draw_child (GtkWidget *widget)
3735 GtkWidgetPrivate *priv = widget->priv;
3738 parent = priv->parent;
3739 if (parent && gtk_widget_is_drawable (parent))
3740 gtk_widget_queue_draw_area (parent,
3743 priv->allocation.width,
3744 priv->allocation.height);
3748 * gtk_widget_unparent:
3749 * @widget: a #GtkWidget
3751 * This function is only for use in widget implementations.
3752 * Should be called by implementations of the remove method
3753 * on #GtkContainer, to dissociate a child from the container.
3756 gtk_widget_unparent (GtkWidget *widget)
3758 GtkWidgetPrivate *priv;
3759 GObjectNotifyQueue *nqueue;
3760 GtkWidget *toplevel;
3761 GtkWidget *old_parent;
3763 g_return_if_fail (GTK_IS_WIDGET (widget));
3765 priv = widget->priv;
3767 if (priv->parent == NULL)
3770 /* keep this function in sync with gtk_menu_detach()
3773 g_object_freeze_notify (G_OBJECT (widget));
3774 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3776 toplevel = gtk_widget_get_toplevel (widget);
3777 if (gtk_widget_is_toplevel (toplevel))
3778 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3780 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3781 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3783 /* If we are unanchoring the child, we save around the toplevel
3784 * to emit hierarchy changed
3786 if (priv->parent->priv->anchored)
3787 g_object_ref (toplevel);
3791 gtk_widget_queue_draw_child (widget);
3793 /* Reset the width and height here, to force reallocation if we
3794 * get added back to a new parent. This won't work if our new
3795 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3796 * (would 0x0 be OK here?)
3798 priv->allocation.width = 1;
3799 priv->allocation.height = 1;
3801 if (gtk_widget_get_realized (widget))
3803 if (priv->in_reparent)
3804 gtk_widget_unmap (widget);
3806 gtk_widget_unrealize (widget);
3809 /* Removing a widget from a container restores the child visible
3810 * flag to the default state, so it doesn't affect the child
3811 * in the next parent.
3813 priv->child_visible = TRUE;
3815 old_parent = priv->parent;
3816 priv->parent = NULL;
3817 gtk_widget_set_parent_window (widget, NULL);
3819 /* parent may no longer expand if the removed
3820 * child was expand=TRUE and could therefore
3823 if (gtk_widget_get_visible (widget) &&
3824 (priv->need_compute_expand ||
3825 priv->computed_hexpand ||
3826 priv->computed_vexpand))
3828 gtk_widget_queue_compute_expand (old_parent);
3831 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3834 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3835 g_object_unref (toplevel);
3838 g_object_notify (G_OBJECT (widget), "parent");
3839 g_object_thaw_notify (G_OBJECT (widget));
3841 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3842 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3843 g_object_unref (widget);
3847 * gtk_widget_destroy:
3848 * @widget: a #GtkWidget
3850 * Destroys a widget.
3853 * destroyed, it will break any references it holds to other objects.
3854 * If the widget is inside a container, the widget will be removed
3855 * from the container. If the widget is a toplevel (derived from
3856 * #GtkWindow), it will be removed from the list of toplevels, and the
3857 * reference GTK+ holds to it will be removed. Removing a
3858 * widget from its container or the list of toplevels results in the
3859 * widget being finalized, unless you've added additional references
3860 * to the widget with g_object_ref().
3862 * In most cases, only toplevel widgets (windows) require explicit
3863 * destruction, because when you destroy a toplevel its children will
3864 * be destroyed as well.
3867 gtk_widget_destroy (GtkWidget *widget)
3869 g_return_if_fail (GTK_IS_WIDGET (widget));
3871 if (!widget->priv->in_destruction)
3872 g_object_run_dispose (G_OBJECT (widget));
3876 * gtk_widget_destroyed:
3877 * @widget: a #GtkWidget
3878 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3880 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3881 * %NULL. It's intended to be used as a callback connected to the
3882 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3883 * as a signal handler, and pass the address of your widget variable
3884 * as user data. Then when the widget is destroyed, the variable will
3885 * be set to %NULL. Useful for example to avoid multiple copies
3886 * of the same dialog.
3889 gtk_widget_destroyed (GtkWidget *widget,
3890 GtkWidget **widget_pointer)
3892 /* Don't make any assumptions about the
3894 * Even check widget_pointer.
3897 *widget_pointer = NULL;
3902 * @widget: a #GtkWidget
3904 * Flags a widget to be displayed. Any widget that isn't shown will
3905 * not appear on the screen. If you want to show all the widgets in a
3906 * container, it's easier to call gtk_widget_show_all() on the
3907 * container, instead of individually showing the widgets.
3909 * Remember that you have to show the containers containing a widget,
3910 * in addition to the widget itself, before it will appear onscreen.
3912 * When a toplevel container is shown, it is immediately realized and
3913 * mapped; other shown widgets are realized and mapped when their
3914 * toplevel container is realized and mapped.
3917 gtk_widget_show (GtkWidget *widget)
3919 g_return_if_fail (GTK_IS_WIDGET (widget));
3921 if (!gtk_widget_get_visible (widget))
3923 g_object_ref (widget);
3924 if (!gtk_widget_is_toplevel (widget))
3925 gtk_widget_queue_resize (widget);
3927 /* see comment in set_parent() for why this should and can be
3930 if (widget->priv->need_compute_expand ||
3931 widget->priv->computed_hexpand ||
3932 widget->priv->computed_vexpand)
3934 if (widget->priv->parent != NULL)
3935 gtk_widget_queue_compute_expand (widget->priv->parent);
3938 g_signal_emit (widget, widget_signals[SHOW], 0);
3939 g_object_notify (G_OBJECT (widget), "visible");
3940 g_object_unref (widget);
3945 gtk_widget_real_show (GtkWidget *widget)
3947 GtkWidgetPrivate *priv = widget->priv;
3949 if (!gtk_widget_get_visible (widget))
3951 priv->visible = TRUE;
3954 gtk_widget_get_mapped (priv->parent) &&
3955 gtk_widget_get_child_visible (widget) &&
3956 !gtk_widget_get_mapped (widget))
3957 gtk_widget_map (widget);
3962 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3965 g_signal_handlers_disconnect_by_func (widget,
3966 gtk_widget_show_map_callback,
3971 * gtk_widget_show_now:
3972 * @widget: a #GtkWidget
3974 * Shows a widget. If the widget is an unmapped toplevel widget
3975 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3976 * loop and wait for the window to actually be mapped. Be careful;
3977 * because the main loop is running, anything can happen during
3981 gtk_widget_show_now (GtkWidget *widget)
3985 g_return_if_fail (GTK_IS_WIDGET (widget));
3987 /* make sure we will get event */
3988 if (!gtk_widget_get_mapped (widget) &&
3989 gtk_widget_is_toplevel (widget))
3991 gtk_widget_show (widget);
3993 g_signal_connect (widget, "map-event",
3994 G_CALLBACK (gtk_widget_show_map_callback),
3998 gtk_main_iteration ();
4001 gtk_widget_show (widget);
4006 * @widget: a #GtkWidget
4008 * Reverses the effects of gtk_widget_show(), causing the widget to be
4009 * hidden (invisible to the user).
4012 gtk_widget_hide (GtkWidget *widget)
4014 g_return_if_fail (GTK_IS_WIDGET (widget));
4016 if (gtk_widget_get_visible (widget))
4018 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4020 g_object_ref (widget);
4021 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4022 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4024 /* a parent may now be expand=FALSE since we're hidden. */
4025 if (widget->priv->need_compute_expand ||
4026 widget->priv->computed_hexpand ||
4027 widget->priv->computed_vexpand)
4029 gtk_widget_queue_compute_expand (widget);
4032 g_signal_emit (widget, widget_signals[HIDE], 0);
4033 if (!gtk_widget_is_toplevel (widget))
4034 gtk_widget_queue_resize (widget);
4035 g_object_notify (G_OBJECT (widget), "visible");
4036 g_object_unref (widget);
4041 gtk_widget_real_hide (GtkWidget *widget)
4043 if (gtk_widget_get_visible (widget))
4045 widget->priv->visible = FALSE;
4047 if (gtk_widget_get_mapped (widget))
4048 gtk_widget_unmap (widget);
4053 * gtk_widget_hide_on_delete:
4054 * @widget: a #GtkWidget
4056 * Utility function; intended to be connected to the #GtkWidget::delete-event
4057 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4058 * argument, then returns %TRUE. If connected to ::delete-event, the
4059 * result is that clicking the close button for a window (on the
4060 * window frame, top right corner usually) will hide but not destroy
4061 * the window. By default, GTK+ destroys windows when ::delete-event
4064 * Return value: %TRUE
4067 gtk_widget_hide_on_delete (GtkWidget *widget)
4069 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4071 gtk_widget_hide (widget);
4077 * gtk_widget_show_all:
4078 * @widget: a #GtkWidget
4080 * Recursively shows a widget, and any child widgets (if the widget is
4084 gtk_widget_show_all (GtkWidget *widget)
4086 GtkWidgetClass *class;
4088 g_return_if_fail (GTK_IS_WIDGET (widget));
4090 if (gtk_widget_get_no_show_all (widget))
4093 class = GTK_WIDGET_GET_CLASS (widget);
4095 if (class->show_all)
4096 class->show_all (widget);
4101 * @widget: a #GtkWidget
4103 * This function is only for use in widget implementations. Causes
4104 * a widget to be mapped if it isn't already.
4107 gtk_widget_map (GtkWidget *widget)
4109 GtkWidgetPrivate *priv;
4111 g_return_if_fail (GTK_IS_WIDGET (widget));
4112 g_return_if_fail (gtk_widget_get_visible (widget));
4113 g_return_if_fail (gtk_widget_get_child_visible (widget));
4115 priv = widget->priv;
4117 if (!gtk_widget_get_mapped (widget))
4119 if (!gtk_widget_get_realized (widget))
4120 gtk_widget_realize (widget);
4122 g_signal_emit (widget, widget_signals[MAP], 0);
4124 if (!gtk_widget_get_has_window (widget))
4125 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4131 * @widget: a #GtkWidget
4133 * This function is only for use in widget implementations. Causes
4134 * a widget to be unmapped if it's currently mapped.
4137 gtk_widget_unmap (GtkWidget *widget)
4139 GtkWidgetPrivate *priv;
4141 g_return_if_fail (GTK_IS_WIDGET (widget));
4143 priv = widget->priv;
4145 if (gtk_widget_get_mapped (widget))
4147 if (!gtk_widget_get_has_window (widget))
4148 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4149 _gtk_tooltip_hide (widget);
4150 g_signal_emit (widget, widget_signals[UNMAP], 0);
4155 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4156 GdkExtensionMode mode,
4159 GtkWidgetPrivate *priv = widget->priv;
4160 GList *free_list = NULL;
4163 if (window_list == NULL)
4165 if (gtk_widget_get_has_window (widget))
4166 window_list = g_list_prepend (NULL, priv->window);
4168 window_list = gdk_window_get_children (priv->window);
4170 free_list = window_list;
4173 for (l = window_list; l != NULL; l = l->next)
4175 GdkWindow *window = l->data;
4178 gdk_window_get_user_data (window, &user_data);
4179 if (user_data == widget)
4183 gdk_input_set_extension_events (window,
4184 gdk_window_get_events (window),
4187 children = gdk_window_get_children (window);
4190 gtk_widget_set_extension_events_internal (widget, mode, children);
4191 g_list_free (children);
4197 g_list_free (free_list);
4201 _gtk_widget_enable_device_events (GtkWidget *widget)
4203 GHashTable *device_events;
4204 GHashTableIter iter;
4205 gpointer key, value;
4207 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4212 g_hash_table_iter_init (&iter, device_events);
4214 while (g_hash_table_iter_next (&iter, &key, &value))
4217 GdkEventMask event_mask;
4220 event_mask = GPOINTER_TO_UINT (value);
4221 gtk_widget_add_events_internal (widget, device, event_mask);
4226 * gtk_widget_realize:
4227 * @widget: a #GtkWidget
4229 * Creates the GDK (windowing system) resources associated with a
4230 * widget. For example, @widget->window will be created when a widget
4231 * is realized. Normally realization happens implicitly; if you show
4232 * a widget and all its parent containers, then the widget will be
4233 * realized and mapped automatically.
4235 * Realizing a widget requires all
4236 * the widget's parent widgets to be realized; calling
4237 * gtk_widget_realize() realizes the widget's parents in addition to
4238 * @widget itself. If a widget is not yet inside a toplevel window
4239 * when you realize it, bad things will happen.
4241 * This function is primarily used in widget implementations, and
4242 * isn't very useful otherwise. Many times when you think you might
4243 * need it, a better approach is to connect to a signal that will be
4244 * called after the widget is realized automatically, such as
4245 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4246 * #GtkWidget::realize signal.
4249 gtk_widget_realize (GtkWidget *widget)
4251 GtkWidgetPrivate *priv;
4252 GdkExtensionMode mode;
4253 cairo_region_t *region;
4255 g_return_if_fail (GTK_IS_WIDGET (widget));
4256 g_return_if_fail (widget->priv->anchored ||
4257 GTK_IS_INVISIBLE (widget));
4259 priv = widget->priv;
4261 if (!gtk_widget_get_realized (widget))
4264 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4265 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4268 if (priv->parent == NULL &&
4269 !gtk_widget_is_toplevel (widget))
4270 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4271 "inside a toplevel window is not going to work very well. "
4272 "Widgets must be inside a toplevel container before realizing them.");
4274 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4275 gtk_widget_realize (priv->parent);
4277 gtk_widget_ensure_style (widget);
4279 g_signal_emit (widget, widget_signals[REALIZE], 0);
4281 gtk_widget_real_set_has_tooltip (widget,
4282 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4285 if (priv->has_shape_mask)
4287 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4288 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4291 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4293 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4295 mode = gtk_widget_get_extension_events (widget);
4296 if (mode != GDK_EXTENSION_EVENTS_NONE)
4297 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4299 if (priv->multidevice)
4300 gdk_window_set_support_multidevice (priv->window, TRUE);
4302 _gtk_widget_enable_device_events (widget);
4307 * gtk_widget_unrealize:
4308 * @widget: a #GtkWidget
4310 * This function is only useful in widget implementations.
4311 * Causes a widget to be unrealized (frees all GDK resources
4312 * associated with the widget, such as @widget->window).
4315 gtk_widget_unrealize (GtkWidget *widget)
4317 g_return_if_fail (GTK_IS_WIDGET (widget));
4319 if (widget->priv->has_shape_mask)
4320 gtk_widget_shape_combine_region (widget, NULL);
4322 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4323 gtk_widget_input_shape_combine_region (widget, NULL);
4325 if (gtk_widget_get_realized (widget))
4327 g_object_ref (widget);
4328 _gtk_tooltip_hide (widget);
4329 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4330 gtk_widget_set_realized (widget, FALSE);
4331 gtk_widget_set_mapped (widget, FALSE);
4332 g_object_unref (widget);
4336 /*****************************************
4338 *****************************************/
4341 * gtk_widget_queue_draw_region:
4342 * @widget: a #GtkWidget
4343 * @region: region to draw
4345 * Invalidates the rectangular area of @widget defined by @region by
4346 * calling gdk_window_invalidate_region() on the widget's window and
4347 * all its child windows. Once the main loop becomes idle (after the
4348 * current batch of events has been processed, roughly), the window
4349 * will receive expose events for the union of all regions that have
4352 * Normally you would only use this function in widget
4353 * implementations. You might also use it to schedule a redraw of a
4354 * #GtkDrawingArea or some portion thereof.
4357 gtk_widget_queue_draw_region (GtkWidget *widget,
4358 cairo_region_t *region)
4360 GtkWidgetPrivate *priv;
4363 g_return_if_fail (GTK_IS_WIDGET (widget));
4365 priv = widget->priv;
4367 if (!gtk_widget_get_realized (widget))
4370 /* Just return if the widget or one of its ancestors isn't mapped */
4371 for (w = widget; w != NULL; w = w->priv->parent)
4372 if (!gtk_widget_get_mapped (w))
4375 gdk_window_invalidate_region (priv->window, region, TRUE);
4379 * gtk_widget_queue_draw_area:
4380 * @widget: a #GtkWidget
4381 * @x: x coordinate of upper-left corner of rectangle to redraw
4382 * @y: y coordinate of upper-left corner of rectangle to redraw
4383 * @width: width of region to draw
4384 * @height: height of region to draw
4386 * Convenience function that calls gtk_widget_queue_draw_region() on
4387 * the region created from the given coordinates.
4390 gtk_widget_queue_draw_area (GtkWidget *widget,
4397 cairo_region_t *region;
4399 g_return_if_fail (GTK_IS_WIDGET (widget));
4404 rect.height = height;
4406 region = cairo_region_create_rectangle (&rect);
4407 gtk_widget_queue_draw_region (widget, region);
4408 cairo_region_destroy (region);
4412 * gtk_widget_queue_draw:
4413 * @widget: a #GtkWidget
4415 * Equivalent to calling gtk_widget_queue_draw_area() for the
4416 * entire area of a widget.
4419 gtk_widget_queue_draw (GtkWidget *widget)
4423 g_return_if_fail (GTK_IS_WIDGET (widget));
4425 gtk_widget_get_allocation (widget, &rect);
4427 if (!gtk_widget_get_has_window (widget))
4428 gtk_widget_queue_draw_area (widget,
4429 rect.x, rect.y, rect.width, rect.height);
4431 gtk_widget_queue_draw_area (widget,
4432 0, 0, rect.width, rect.height);
4436 * gtk_widget_queue_resize:
4437 * @widget: a #GtkWidget
4439 * This function is only for use in widget implementations.
4440 * Flags a widget to have its size renegotiated; should
4441 * be called when a widget for some reason has a new size request.
4442 * For example, when you change the text in a #GtkLabel, #GtkLabel
4443 * queues a resize to ensure there's enough space for the new text.
4446 gtk_widget_queue_resize (GtkWidget *widget)
4448 g_return_if_fail (GTK_IS_WIDGET (widget));
4450 if (gtk_widget_get_realized (widget))
4451 gtk_widget_queue_shallow_draw (widget);
4453 _gtk_size_group_queue_resize (widget, 0);
4457 * gtk_widget_queue_resize_no_redraw:
4458 * @widget: a #GtkWidget
4460 * This function works like gtk_widget_queue_resize(),
4461 * except that the widget is not invalidated.
4466 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4468 g_return_if_fail (GTK_IS_WIDGET (widget));
4470 _gtk_size_group_queue_resize (widget, 0);
4474 * gtk_widget_size_request:
4475 * @widget: a #GtkWidget
4476 * @requisition: (out): a #GtkRequisition to be filled in
4478 * This function is typically used when implementing a #GtkContainer
4479 * subclass. Obtains the preferred size of a widget. The container
4480 * uses this information to arrange its child widgets and decide what
4481 * size allocations to give them with gtk_widget_size_allocate().
4483 * You can also call this function from an application, with some
4484 * caveats. Most notably, getting a size request requires the widget
4485 * to be associated with a screen, because font information may be
4486 * needed. Multihead-aware applications should keep this in mind.
4488 * Also remember that the size request is not necessarily the size
4489 * a widget will actually be allocated.
4491 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4494 gtk_widget_size_request (GtkWidget *widget,
4495 GtkRequisition *requisition)
4497 g_return_if_fail (GTK_IS_WIDGET (widget));
4499 gtk_widget_get_preferred_size (widget, requisition, NULL);
4503 * gtk_widget_get_child_requisition:
4504 * @widget: a #GtkWidget
4505 * @requisition: (out): a #GtkRequisition to be filled in
4507 * This function is only for use in widget implementations. Obtains
4508 * @widget->requisition, unless someone has forced a particular
4509 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4510 * in which case it returns that geometry instead of the widget's
4513 * This function differs from gtk_widget_size_request() in that
4514 * it retrieves the last size request value from @widget->requisition,
4515 * while gtk_widget_size_request() actually calls the "size_request" method
4516 * on @widget to compute the size request and fill in @widget->requisition,
4517 * and only then returns @widget->requisition.
4519 * Because this function does not call the "size_request" method, it
4520 * can only be used when you know that @widget->requisition is
4521 * up-to-date, that is, gtk_widget_size_request() has been called
4522 * since the last time a resize was queued. In general, only container
4523 * implementations have this information; applications should use
4524 * gtk_widget_size_request().
4527 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4530 gtk_widget_get_child_requisition (GtkWidget *widget,
4531 GtkRequisition *requisition)
4533 gtk_widget_get_preferred_size (widget, requisition, NULL);
4537 invalidate_predicate (GdkWindow *window,
4542 gdk_window_get_user_data (window, &user_data);
4544 return (user_data == data);
4547 /* Invalidate @region in widget->window and all children
4548 * of widget->window owned by widget. @region is in the
4549 * same coordinates as widget->allocation and will be
4550 * modified by this call.
4553 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4554 cairo_region_t *region)
4556 GtkWidgetPrivate *priv = widget->priv;
4558 if (!gtk_widget_get_realized (widget))
4561 if (gtk_widget_get_has_window (widget) && priv->parent)
4565 gdk_window_get_position (priv->window, &x, &y);
4566 cairo_region_translate (region, -x, -y);
4569 gdk_window_invalidate_maybe_recurse (priv->window, region,
4570 invalidate_predicate, widget);
4574 * gtk_widget_queue_shallow_draw:
4575 * @widget: a #GtkWidget
4577 * Like gtk_widget_queue_draw(), but only windows owned
4578 * by @widget are invalidated.
4581 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4584 cairo_region_t *region;
4586 if (!gtk_widget_get_realized (widget))
4589 gtk_widget_get_allocation (widget, &rect);
4591 region = cairo_region_create_rectangle (&rect);
4592 gtk_widget_invalidate_widget_windows (widget, region);
4593 cairo_region_destroy (region);
4597 * gtk_widget_size_allocate:
4598 * @widget: a #GtkWidget
4599 * @allocation: (inout): position and size to be allocated to @widget
4601 * This function is only used by #GtkContainer subclasses, to assign a size
4602 * and position to their child widgets.
4604 * In this function, the allocation may be adjusted. It will be forced
4605 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4606 * method on the child will be used to adjust the allocation. Standard
4607 * adjustments include removing the widget's margins, and applying the
4608 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4611 gtk_widget_size_allocate (GtkWidget *widget,
4612 GtkAllocation *allocation)
4614 GtkWidgetPrivate *priv;
4615 GdkRectangle real_allocation;
4616 GdkRectangle old_allocation;
4617 GdkRectangle adjusted_allocation;
4618 gboolean alloc_needed;
4619 gboolean size_changed;
4620 gboolean position_changed;
4621 gint natural_width, natural_height;
4622 gint min_width, min_height;
4624 priv = widget->priv;
4626 g_return_if_fail (GTK_IS_WIDGET (widget));
4628 #ifdef G_ENABLE_DEBUG
4629 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4640 parent = gtk_widget_get_parent (parent);
4643 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4644 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4645 2 * depth, " ", name,
4646 allocation->width, allocation->height);
4648 #endif /* G_ENABLE_DEBUG */
4650 alloc_needed = priv->alloc_needed;
4651 if (!priv->width_request_needed && !priv->height_request_needed)
4652 /* Preserve request/allocate ordering */
4653 priv->alloc_needed = FALSE;
4655 old_allocation = priv->allocation;
4656 real_allocation = *allocation;
4658 adjusted_allocation = real_allocation;
4659 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4661 /* Go ahead and request the height for allocated width, note that the internals
4662 * of get_height_for_width will internally limit the for_size to natural size
4663 * when aligning implicitly.
4665 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4666 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4670 /* Go ahead and request the width for allocated height, note that the internals
4671 * of get_width_for_height will internally limit the for_size to natural size
4672 * when aligning implicitly.
4674 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4675 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4678 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4679 * allocated sizes and possibly limit them to the natural sizes */
4680 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4681 GTK_ORIENTATION_HORIZONTAL,
4683 &adjusted_allocation.x,
4684 &adjusted_allocation.width);
4685 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4686 GTK_ORIENTATION_VERTICAL,
4688 &adjusted_allocation.y,
4689 &adjusted_allocation.height);
4691 if (adjusted_allocation.x < real_allocation.x ||
4692 adjusted_allocation.y < real_allocation.y ||
4693 (adjusted_allocation.x + adjusted_allocation.width) >
4694 (real_allocation.x + real_allocation.width) ||
4695 (adjusted_allocation.y + adjusted_allocation.height >
4696 real_allocation.y + real_allocation.height))
4698 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",
4699 G_OBJECT_TYPE_NAME (widget), widget,
4700 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4701 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4702 adjusted_allocation = real_allocation; /* veto it */
4706 real_allocation = adjusted_allocation;
4709 if (real_allocation.width < 0 || real_allocation.height < 0)
4711 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4712 real_allocation.width,
4713 real_allocation.height);
4716 real_allocation.width = MAX (real_allocation.width, 1);
4717 real_allocation.height = MAX (real_allocation.height, 1);
4719 size_changed = (old_allocation.width != real_allocation.width ||
4720 old_allocation.height != real_allocation.height);
4721 position_changed = (old_allocation.x != real_allocation.x ||
4722 old_allocation.y != real_allocation.y);
4724 if (!alloc_needed && !size_changed && !position_changed)
4727 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4729 if (gtk_widget_get_mapped (widget))
4731 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4733 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4735 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4736 cairo_region_union_rectangle (invalidate, &old_allocation);
4738 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4739 cairo_region_destroy (invalidate);
4744 if (priv->redraw_on_alloc)
4746 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4748 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4749 cairo_region_union_rectangle (invalidate, &old_allocation);
4751 gtk_widget_invalidate_widget_windows (widget, invalidate);
4752 cairo_region_destroy (invalidate);
4757 if ((size_changed || position_changed) && priv->parent &&
4758 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4760 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4761 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4762 cairo_region_destroy (invalidate);
4767 * gtk_widget_common_ancestor:
4768 * @widget_a: a #GtkWidget
4769 * @widget_b: a #GtkWidget
4771 * Find the common ancestor of @widget_a and @widget_b that
4772 * is closest to the two widgets.
4774 * Return value: the closest common ancestor of @widget_a and
4775 * @widget_b or %NULL if @widget_a and @widget_b do not
4776 * share a common ancestor.
4779 gtk_widget_common_ancestor (GtkWidget *widget_a,
4780 GtkWidget *widget_b)
4782 GtkWidget *parent_a;
4783 GtkWidget *parent_b;
4787 parent_a = widget_a;
4788 while (parent_a->priv->parent)
4790 parent_a = parent_a->priv->parent;
4794 parent_b = widget_b;
4795 while (parent_b->priv->parent)
4797 parent_b = parent_b->priv->parent;
4801 if (parent_a != parent_b)
4804 while (depth_a > depth_b)
4806 widget_a = widget_a->priv->parent;
4810 while (depth_b > depth_a)
4812 widget_b = widget_b->priv->parent;
4816 while (widget_a != widget_b)
4818 widget_a = widget_a->priv->parent;
4819 widget_b = widget_b->priv->parent;
4826 * gtk_widget_translate_coordinates:
4827 * @src_widget: a #GtkWidget
4828 * @dest_widget: a #GtkWidget
4829 * @src_x: X position relative to @src_widget
4830 * @src_y: Y position relative to @src_widget
4831 * @dest_x: (out): location to store X position relative to @dest_widget
4832 * @dest_y: (out): location to store Y position relative to @dest_widget
4834 * Translate coordinates relative to @src_widget's allocation to coordinates
4835 * relative to @dest_widget's allocations. In order to perform this
4836 * operation, both widgets must be realized, and must share a common
4839 * Return value: %FALSE if either widget was not realized, or there
4840 * was no common ancestor. In this case, nothing is stored in
4841 * *@dest_x and *@dest_y. Otherwise %TRUE.
4844 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4845 GtkWidget *dest_widget,
4851 GtkWidgetPrivate *src_priv = src_widget->priv;
4852 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4853 GtkWidget *ancestor;
4855 GList *dest_list = NULL;
4857 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4858 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4860 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4861 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4864 /* Translate from allocation relative to window relative */
4865 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4868 gdk_window_get_position (src_priv->window, &wx, &wy);
4870 src_x -= wx - src_priv->allocation.x;
4871 src_y -= wy - src_priv->allocation.y;
4875 src_x += src_priv->allocation.x;
4876 src_y += src_priv->allocation.y;
4879 /* Translate to the common ancestor */
4880 window = src_priv->window;
4881 while (window != ancestor->priv->window)
4885 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4890 window = gdk_window_get_effective_parent (window);
4892 if (!window) /* Handle GtkHandleBox */
4897 window = dest_priv->window;
4898 while (window != ancestor->priv->window)
4900 dest_list = g_list_prepend (dest_list, window);
4902 window = gdk_window_get_effective_parent (window);
4904 if (!window) /* Handle GtkHandleBox */
4906 g_list_free (dest_list);
4915 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4920 dest_list = g_list_remove (dest_list, dest_list->data);
4923 /* Translate from window relative to allocation relative */
4924 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4927 gdk_window_get_position (dest_priv->window, &wx, &wy);
4929 src_x += wx - dest_priv->allocation.x;
4930 src_y += wy - dest_priv->allocation.y;
4934 src_x -= dest_priv->allocation.x;
4935 src_y -= dest_priv->allocation.y;
4947 gtk_widget_real_size_allocate (GtkWidget *widget,
4948 GtkAllocation *allocation)
4950 GtkWidgetPrivate *priv = widget->priv;
4952 priv->allocation = *allocation;
4954 if (gtk_widget_get_realized (widget) &&
4955 gtk_widget_get_has_window (widget))
4957 gdk_window_move_resize (priv->window,
4958 allocation->x, allocation->y,
4959 allocation->width, allocation->height);
4964 adjust_for_align(GtkAlign align,
4966 gint *allocated_pos,
4967 gint *allocated_size)
4971 case GTK_ALIGN_FILL:
4972 /* change nothing */
4974 case GTK_ALIGN_START:
4975 /* keep *allocated_pos where it is */
4976 *allocated_size = MIN (*allocated_size, *natural_size);
4979 if (*allocated_size > *natural_size)
4981 *allocated_pos += (*allocated_size - *natural_size);
4982 *allocated_size = *natural_size;
4985 case GTK_ALIGN_CENTER:
4986 if (*allocated_size > *natural_size)
4988 *allocated_pos += (*allocated_size - *natural_size) / 2;
4989 *allocated_size = MIN (*allocated_size, *natural_size);
4996 adjust_for_margin(gint start_margin,
4999 gint *allocated_pos,
5000 gint *allocated_size)
5002 *natural_size -= (start_margin + end_margin);
5003 *allocated_pos += start_margin;
5004 *allocated_size -= (start_margin + end_margin);
5008 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5009 GtkOrientation orientation,
5011 gint *allocated_pos,
5012 gint *allocated_size)
5014 const GtkWidgetAuxInfo *aux_info;
5016 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5018 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5020 adjust_for_margin (aux_info->margin.left,
5021 aux_info->margin.right,
5022 natural_size, allocated_pos, allocated_size);
5023 adjust_for_align (aux_info->halign,
5024 natural_size, allocated_pos, allocated_size);
5028 adjust_for_margin (aux_info->margin.top,
5029 aux_info->margin.bottom,
5030 natural_size, allocated_pos, allocated_size);
5031 adjust_for_align (aux_info->valign,
5032 natural_size, allocated_pos, allocated_size);
5037 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5040 GtkWidgetPrivate *priv = widget->priv;
5042 /* widgets must be onscreen for accels to take effect */
5043 return gtk_widget_is_sensitive (widget) &&
5044 gtk_widget_is_drawable (widget) &&
5045 gdk_window_is_viewable (priv->window);
5049 * gtk_widget_can_activate_accel:
5050 * @widget: a #GtkWidget
5051 * @signal_id: the ID of a signal installed on @widget
5053 * Determines whether an accelerator that activates the signal
5054 * identified by @signal_id can currently be activated.
5055 * This is done by emitting the #GtkWidget::can-activate-accel
5056 * signal on @widget; if the signal isn't overridden by a
5057 * handler or in a derived widget, then the default check is
5058 * that the widget must be sensitive, and the widget and all
5059 * its ancestors mapped.
5061 * Return value: %TRUE if the accelerator can be activated.
5066 gtk_widget_can_activate_accel (GtkWidget *widget,
5069 gboolean can_activate = FALSE;
5070 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5071 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5072 return can_activate;
5081 closure_accel_activate (GClosure *closure,
5082 GValue *return_value,
5083 guint n_param_values,
5084 const GValue *param_values,
5085 gpointer invocation_hint,
5086 gpointer marshal_data)
5088 AccelClosure *aclosure = (AccelClosure*) closure;
5089 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5092 g_signal_emit (closure->data, aclosure->signal_id, 0);
5094 /* whether accelerator was handled */
5095 g_value_set_boolean (return_value, can_activate);
5099 closures_destroy (gpointer data)
5101 GSList *slist, *closures = data;
5103 for (slist = closures; slist; slist = slist->next)
5105 g_closure_invalidate (slist->data);
5106 g_closure_unref (slist->data);
5108 g_slist_free (closures);
5112 widget_new_accel_closure (GtkWidget *widget,
5115 AccelClosure *aclosure;
5116 GClosure *closure = NULL;
5117 GSList *slist, *closures;
5119 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5120 for (slist = closures; slist; slist = slist->next)
5121 if (!gtk_accel_group_from_accel_closure (slist->data))
5123 /* reuse this closure */
5124 closure = slist->data;
5129 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5130 closures = g_slist_prepend (closures, g_closure_ref (closure));
5131 g_closure_sink (closure);
5132 g_closure_set_marshal (closure, closure_accel_activate);
5134 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5136 aclosure = (AccelClosure*) closure;
5137 g_assert (closure->data == widget);
5138 g_assert (closure->marshal == closure_accel_activate);
5139 aclosure->signal_id = signal_id;
5145 * gtk_widget_add_accelerator
5146 * @widget: widget to install an accelerator on
5147 * @accel_signal: widget signal to emit on accelerator activation
5148 * @accel_group: accel group for this widget, added to its toplevel
5149 * @accel_key: GDK keyval of the accelerator
5150 * @accel_mods: modifier key combination of the accelerator
5151 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5153 * Installs an accelerator for this @widget in @accel_group that causes
5154 * @accel_signal to be emitted if the accelerator is activated.
5155 * The @accel_group needs to be added to the widget's toplevel via
5156 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5157 * Accelerators added through this function are not user changeable during
5158 * runtime. If you want to support accelerators that can be changed by the
5159 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5160 * gtk_menu_item_set_accel_path() instead.
5163 gtk_widget_add_accelerator (GtkWidget *widget,
5164 const gchar *accel_signal,
5165 GtkAccelGroup *accel_group,
5167 GdkModifierType accel_mods,
5168 GtkAccelFlags accel_flags)
5173 g_return_if_fail (GTK_IS_WIDGET (widget));
5174 g_return_if_fail (accel_signal != NULL);
5175 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5177 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5178 if (!query.signal_id ||
5179 !(query.signal_flags & G_SIGNAL_ACTION) ||
5180 query.return_type != G_TYPE_NONE ||
5183 /* hmm, should be elaborate enough */
5184 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5185 G_OBJECT_TYPE_NAME (widget), accel_signal);
5189 closure = widget_new_accel_closure (widget, query.signal_id);
5191 g_object_ref (widget);
5193 /* install the accelerator. since we don't map this onto an accel_path,
5194 * the accelerator will automatically be locked.
5196 gtk_accel_group_connect (accel_group,
5199 accel_flags | GTK_ACCEL_LOCKED,
5202 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5204 g_object_unref (widget);
5208 * gtk_widget_remove_accelerator:
5209 * @widget: widget to install an accelerator on
5210 * @accel_group: accel group for this widget
5211 * @accel_key: GDK keyval of the accelerator
5212 * @accel_mods: modifier key combination of the accelerator
5213 * @returns: whether an accelerator was installed and could be removed
5215 * Removes an accelerator from @widget, previously installed with
5216 * gtk_widget_add_accelerator().
5219 gtk_widget_remove_accelerator (GtkWidget *widget,
5220 GtkAccelGroup *accel_group,
5222 GdkModifierType accel_mods)
5224 GtkAccelGroupEntry *ag_entry;
5225 GList *slist, *clist;
5228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5229 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5231 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5232 clist = gtk_widget_list_accel_closures (widget);
5233 for (slist = clist; slist; slist = slist->next)
5237 for (i = 0; i < n; i++)
5238 if (slist->data == (gpointer) ag_entry[i].closure)
5240 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5242 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5244 g_list_free (clist);
5249 g_list_free (clist);
5251 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5252 accel_key, accel_mods, accel_group,
5253 G_OBJECT_TYPE_NAME (widget), widget);
5259 * gtk_widget_list_accel_closures:
5260 * @widget: widget to list accelerator closures for
5262 * Lists the closures used by @widget for accelerator group connections
5263 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5264 * The closures can be used to monitor accelerator changes on @widget,
5265 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5266 * #GtkAccelGroup of a closure which can be found out with
5267 * gtk_accel_group_from_accel_closure().
5269 * Return value: (transfer container) (element-type GClosure):
5270 * a newly allocated #GList of closures
5273 gtk_widget_list_accel_closures (GtkWidget *widget)
5276 GList *clist = NULL;
5278 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5280 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5281 if (gtk_accel_group_from_accel_closure (slist->data))
5282 clist = g_list_prepend (clist, slist->data);
5288 GtkAccelGroup *accel_group;
5293 destroy_accel_path (gpointer data)
5295 AccelPath *apath = data;
5297 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5299 /* closures_destroy takes care of unrefing the closure */
5300 g_object_unref (apath->accel_group);
5302 g_slice_free (AccelPath, apath);
5307 * gtk_widget_set_accel_path:
5308 * @widget: a #GtkWidget
5309 * @accel_path: (allow-none): path used to look up the accelerator
5310 * @accel_group: (allow-none): a #GtkAccelGroup.
5312 * Given an accelerator group, @accel_group, and an accelerator path,
5313 * @accel_path, sets up an accelerator in @accel_group so whenever the
5314 * key binding that is defined for @accel_path is pressed, @widget
5315 * will be activated. This removes any accelerators (for any
5316 * accelerator group) installed by previous calls to
5317 * gtk_widget_set_accel_path(). Associating accelerators with
5318 * paths allows them to be modified by the user and the modifications
5319 * to be saved for future use. (See gtk_accel_map_save().)
5321 * This function is a low level function that would most likely
5322 * be used by a menu creation system like #GtkUIManager. If you
5323 * use #GtkUIManager, setting up accelerator paths will be done
5326 * Even when you you aren't using #GtkUIManager, if you only want to
5327 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5328 * provides a somewhat more convenient interface.
5330 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5331 * pass a static string, you can save some memory by interning it first with
5332 * g_intern_static_string().
5335 gtk_widget_set_accel_path (GtkWidget *widget,
5336 const gchar *accel_path,
5337 GtkAccelGroup *accel_group)
5341 g_return_if_fail (GTK_IS_WIDGET (widget));
5342 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5346 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5347 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5349 gtk_accel_map_add_entry (accel_path, 0, 0);
5350 apath = g_slice_new (AccelPath);
5351 apath->accel_group = g_object_ref (accel_group);
5352 apath->path_quark = g_quark_from_string (accel_path);
5353 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5358 /* also removes possible old settings */
5359 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5362 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5364 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5368 _gtk_widget_get_accel_path (GtkWidget *widget,
5373 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5375 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5377 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5378 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5382 * gtk_widget_mnemonic_activate:
5383 * @widget: a #GtkWidget
5384 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5386 * Emits the #GtkWidget::mnemonic-activate signal.
5388 * The default handler for this signal activates the @widget if
5389 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5392 * Returns: %TRUE if the signal has been handled
5395 gtk_widget_mnemonic_activate (GtkWidget *widget,
5396 gboolean group_cycling)
5400 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5402 group_cycling = group_cycling != FALSE;
5403 if (!gtk_widget_is_sensitive (widget))
5406 g_signal_emit (widget,
5407 widget_signals[MNEMONIC_ACTIVATE],
5415 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5416 gboolean group_cycling)
5418 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5419 gtk_widget_activate (widget);
5420 else if (gtk_widget_get_can_focus (widget))
5421 gtk_widget_grab_focus (widget);
5424 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5425 G_OBJECT_TYPE_NAME (widget));
5426 gtk_widget_error_bell (widget);
5431 static const cairo_user_data_key_t event_key;
5434 _gtk_cairo_get_event (cairo_t *cr)
5436 g_return_val_if_fail (cr != NULL, NULL);
5438 return cairo_get_user_data (cr, &event_key);
5442 gtk_cairo_set_event (cairo_t *cr,
5443 GdkEventExpose *event)
5445 cairo_set_user_data (cr, &event_key, event, NULL);
5449 * gtk_cairo_should_draw_window:
5450 * @cr: a cairo context
5451 * @window: the window to check
5453 * This function is supposed to be called in #GtkWidget::draw
5454 * implementations for widgets that support multiple windows.
5455 * @cr must be untransformed from invoking of the draw function.
5456 * This function will return %TRUE if the contents of the given
5457 * @window are supposed to be drawn and %FALSE otherwise. Note
5458 * that when the drawing was not initiated by the windowing
5459 * system this function will return %TRUE for all windows, so
5460 * you need to draw the bottommost window first. Also, do not
5461 * use "else if" statements to check which window should be drawn.
5463 * Returns: %TRUE if @window should be drawn
5466 gtk_cairo_should_draw_window (cairo_t *cr,
5469 GdkEventExpose *event;
5471 g_return_val_if_fail (cr != NULL, FALSE);
5472 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5474 event = _gtk_cairo_get_event (cr);
5476 return event == NULL ||
5477 event->window == window;
5480 /* code shared by gtk_container_propagate_draw() and
5484 _gtk_widget_draw_internal (GtkWidget *widget,
5486 gboolean clip_to_size)
5488 if (!gtk_widget_is_drawable (widget))
5493 cairo_rectangle (cr,
5495 widget->priv->allocation.width,
5496 widget->priv->allocation.height);
5500 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5504 g_signal_emit (widget, widget_signals[DRAW],
5512 * @widget: the widget to draw. It must be drawable (see
5513 * gtk_widget_is_drawable()) and a size must have been allocated.
5514 * @cr: a cairo context to draw to
5516 * Draws @widget to @cr. The top left corner of the widget will be
5517 * drawn to the currently set origin point of @cr.
5519 * You should pass a cairo context as @cr argument that is in an
5520 * original state. Otherwise the resulting drawing is undefined. For
5521 * example changing the operator using cairo_set_operator() or the
5522 * line width using cairo_set_line_width() might have unwanted side
5524 * You may however change the context's transform matrix - like with
5525 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5526 * region with cairo_clip() prior to calling this function. Also, it
5527 * is fine to modify the context with cairo_save() and
5528 * cairo_push_group() prior to calling this function.
5530 * <note><para>Special purpose widgets may contain special code for
5531 * rendering to the screen and might appear differently on screen
5532 * and when rendered using gtk_widget_draw().</para></note>
5535 gtk_widget_draw (GtkWidget *widget,
5538 GdkEventExpose *tmp_event;
5540 g_return_if_fail (GTK_IS_WIDGET (widget));
5541 g_return_if_fail (!widget->priv->alloc_needed);
5542 g_return_if_fail (cr != NULL);
5545 /* We have to reset the event here so that draw functions can call
5546 * gtk_widget_draw() on random other widgets and get the desired
5547 * effect: Drawing all contents, not just the current window.
5549 tmp_event = _gtk_cairo_get_event (cr);
5550 gtk_cairo_set_event (cr, NULL);
5552 _gtk_widget_draw_internal (widget, cr, TRUE);
5554 gtk_cairo_set_event (cr, tmp_event);
5559 gtk_widget_real_key_press_event (GtkWidget *widget,
5562 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5566 gtk_widget_real_key_release_event (GtkWidget *widget,
5569 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5573 gtk_widget_real_focus_in_event (GtkWidget *widget,
5574 GdkEventFocus *event)
5576 gtk_widget_queue_shallow_draw (widget);
5582 gtk_widget_real_focus_out_event (GtkWidget *widget,
5583 GdkEventFocus *event)
5585 gtk_widget_queue_shallow_draw (widget);
5590 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5591 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5595 * @widget: a #GtkWidget
5596 * @event: a #GdkEvent
5598 * Rarely-used function. This function is used to emit
5599 * the event signals on a widget (those signals should never
5600 * be emitted without using this function to do so).
5601 * If you want to synthesize an event though, don't use this function;
5602 * instead, use gtk_main_do_event() so the event will behave as if
5603 * it were in the event queue. Don't synthesize expose events; instead,
5604 * use gdk_window_invalidate_rect() to invalidate a region of the
5607 * Return value: return from the event signal emission (%TRUE if
5608 * the event was handled)
5611 gtk_widget_event (GtkWidget *widget,
5614 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5615 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5617 if (event->type == GDK_EXPOSE)
5619 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5620 "the same effect, call gdk_window_invalidate_rect/region(), "
5621 "followed by gdk_window_process_updates().");
5625 return gtk_widget_event_internal (widget, event);
5628 /* Returns TRUE if a translation should be done */
5630 gtk_widget_get_translation_to_window (GtkWidget *widget,
5635 GdkWindow *w, *widget_window;
5637 if (!gtk_widget_get_has_window (widget))
5639 *x = -widget->priv->allocation.x;
5640 *y = -widget->priv->allocation.y;
5648 widget_window = gtk_widget_get_window (widget);
5650 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5653 gdk_window_get_position (w, &wx, &wy);
5670 * gtk_cairo_transform_to_window:
5671 * @cr: the cairo context to transform
5672 * @widget: the widget the context is currently centered for
5673 * @window: the window to transform the context to
5675 * Transforms the given cairo context @cr that from @widget-relative
5676 * coordinates to @window-relative coordinates.
5677 * If the @widget's window is not an ancestor of @window, no
5678 * modification will be applied.
5680 * This is the inverse to the transformation GTK applies when
5681 * preparing an expose event to be emitted with the #GtkWidget::draw
5682 * signal. It is intended to help porting multiwindow widgets from
5683 * GTK+ 2 to the rendering architecture of GTK+ 3.
5686 gtk_cairo_transform_to_window (cairo_t *cr,
5692 g_return_if_fail (cr != NULL);
5693 g_return_if_fail (GTK_IS_WIDGET (widget));
5694 g_return_if_fail (GDK_IS_WINDOW (window));
5696 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5697 cairo_translate (cr, x, y);
5701 * gtk_widget_send_expose:
5702 * @widget: a #GtkWidget
5703 * @event: a expose #GdkEvent
5705 * Very rarely-used function. This function is used to emit
5706 * an expose event on a widget. This function is not normally used
5707 * directly. The only time it is used is when propagating an expose
5708 * event to a child %NO_WINDOW widget, and that is normally done
5709 * using gtk_container_propagate_draw().
5711 * If you want to force an area of a window to be redrawn,
5712 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5713 * To cause the redraw to be done immediately, follow that call
5714 * with a call to gdk_window_process_updates().
5716 * Return value: return from the event signal emission (%TRUE if
5717 * the event was handled)
5720 gtk_widget_send_expose (GtkWidget *widget,
5723 gboolean result = FALSE;
5728 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5729 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5730 g_return_val_if_fail (event != NULL, TRUE);
5731 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5733 cr = gdk_cairo_create (event->expose.window);
5734 gtk_cairo_set_event (cr, &event->expose);
5736 gdk_cairo_region (cr, event->expose.region);
5739 do_clip = gtk_widget_get_translation_to_window (widget,
5740 event->expose.window,
5742 cairo_translate (cr, -x, -y);
5744 _gtk_widget_draw_internal (widget, cr, do_clip);
5746 /* unset here, so if someone keeps a reference to cr we
5747 * don't leak the window. */
5748 gtk_cairo_set_event (cr, NULL);
5755 event_window_is_still_viewable (GdkEvent *event)
5757 /* Check that we think the event's window is viewable before
5758 * delivering the event, to prevent suprises. We do this here
5759 * at the last moment, since the event may have been queued
5760 * up behind other events, held over a recursive main loop, etc.
5762 switch (event->type)
5765 case GDK_MOTION_NOTIFY:
5766 case GDK_BUTTON_PRESS:
5767 case GDK_2BUTTON_PRESS:
5768 case GDK_3BUTTON_PRESS:
5770 case GDK_ENTER_NOTIFY:
5771 case GDK_PROXIMITY_IN:
5773 return event->any.window && gdk_window_is_viewable (event->any.window);
5776 /* The following events are the second half of paired events;
5777 * we always deliver them to deal with widgets that clean up
5778 * on the second half.
5780 case GDK_BUTTON_RELEASE:
5781 case GDK_KEY_RELEASE:
5782 case GDK_LEAVE_NOTIFY:
5783 case GDK_PROXIMITY_OUT:
5787 /* Remaining events would make sense on an not-viewable window,
5788 * or don't have an associated window.
5795 gtk_widget_event_internal (GtkWidget *widget,
5798 gboolean return_val = FALSE;
5800 /* We check only once for is-still-visible; if someone
5801 * hides the window in on of the signals on the widget,
5802 * they are responsible for returning TRUE to terminate
5805 if (!event_window_is_still_viewable (event))
5808 g_object_ref (widget);
5810 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5811 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5816 switch (event->type)
5821 case GDK_BUTTON_PRESS:
5822 case GDK_2BUTTON_PRESS:
5823 case GDK_3BUTTON_PRESS:
5824 signal_num = BUTTON_PRESS_EVENT;
5827 signal_num = SCROLL_EVENT;
5829 case GDK_BUTTON_RELEASE:
5830 signal_num = BUTTON_RELEASE_EVENT;
5832 case GDK_MOTION_NOTIFY:
5833 signal_num = MOTION_NOTIFY_EVENT;
5836 signal_num = DELETE_EVENT;
5839 signal_num = DESTROY_EVENT;
5840 _gtk_tooltip_hide (widget);
5843 signal_num = KEY_PRESS_EVENT;
5845 case GDK_KEY_RELEASE:
5846 signal_num = KEY_RELEASE_EVENT;
5848 case GDK_ENTER_NOTIFY:
5849 signal_num = ENTER_NOTIFY_EVENT;
5851 case GDK_LEAVE_NOTIFY:
5852 signal_num = LEAVE_NOTIFY_EVENT;
5854 case GDK_FOCUS_CHANGE:
5855 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5856 if (event->focus_change.in)
5857 _gtk_tooltip_focus_in (widget);
5859 _gtk_tooltip_focus_out (widget);
5862 signal_num = CONFIGURE_EVENT;
5865 signal_num = MAP_EVENT;
5868 signal_num = UNMAP_EVENT;
5870 case GDK_WINDOW_STATE:
5871 signal_num = WINDOW_STATE_EVENT;
5873 case GDK_PROPERTY_NOTIFY:
5874 signal_num = PROPERTY_NOTIFY_EVENT;
5876 case GDK_SELECTION_CLEAR:
5877 signal_num = SELECTION_CLEAR_EVENT;
5879 case GDK_SELECTION_REQUEST:
5880 signal_num = SELECTION_REQUEST_EVENT;
5882 case GDK_SELECTION_NOTIFY:
5883 signal_num = SELECTION_NOTIFY_EVENT;
5885 case GDK_PROXIMITY_IN:
5886 signal_num = PROXIMITY_IN_EVENT;
5888 case GDK_PROXIMITY_OUT:
5889 signal_num = PROXIMITY_OUT_EVENT;
5892 signal_num = NO_EXPOSE_EVENT;
5894 case GDK_CLIENT_EVENT:
5895 signal_num = CLIENT_EVENT;
5898 signal_num = EXPOSE_EVENT;
5900 case GDK_VISIBILITY_NOTIFY:
5901 signal_num = VISIBILITY_NOTIFY_EVENT;
5903 case GDK_GRAB_BROKEN:
5904 signal_num = GRAB_BROKEN_EVENT;
5907 signal_num = DAMAGE_EVENT;
5910 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5914 if (signal_num != -1)
5915 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5917 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5918 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5922 g_object_unref (widget);
5928 * gtk_widget_activate:
5929 * @widget: a #GtkWidget that's activatable
5931 * For widgets that can be "activated" (buttons, menu items, etc.)
5932 * this function activates them. Activation is what happens when you
5933 * press Enter on a widget during key navigation. If @widget isn't
5934 * activatable, the function returns %FALSE.
5936 * Return value: %TRUE if the widget was activatable
5939 gtk_widget_activate (GtkWidget *widget)
5941 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5943 if (WIDGET_CLASS (widget)->activate_signal)
5945 /* FIXME: we should eventually check the signals signature here */
5946 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5955 gtk_widget_reparent_subwindows (GtkWidget *widget,
5956 GdkWindow *new_window)
5958 GtkWidgetPrivate *priv = widget->priv;
5960 if (!gtk_widget_get_has_window (widget))
5962 GList *children = gdk_window_get_children (priv->window);
5965 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5967 GdkWindow *window = tmp_list->data;
5970 gdk_window_get_user_data (window, &child);
5971 while (child && child != widget)
5972 child = ((GtkWidget*) child)->priv->parent;
5975 gdk_window_reparent (window, new_window, 0, 0);
5978 g_list_free (children);
5983 GList *tmp_list, *children;
5985 parent = gdk_window_get_parent (priv->window);
5988 gdk_window_reparent (priv->window, new_window, 0, 0);
5991 children = gdk_window_get_children (parent);
5993 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5995 GdkWindow *window = tmp_list->data;
5998 gdk_window_get_user_data (window, &child);
6000 if (child == widget)
6001 gdk_window_reparent (window, new_window, 0, 0);
6004 g_list_free (children);
6010 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6011 gpointer client_data)
6013 GtkWidgetPrivate *priv = widget->priv;
6015 g_assert (client_data != NULL);
6017 if (!gtk_widget_get_has_window (widget))
6020 g_object_unref (priv->window);
6021 priv->window = (GdkWindow*) client_data;
6023 g_object_ref (priv->window);
6025 if (GTK_IS_CONTAINER (widget))
6026 gtk_container_forall (GTK_CONTAINER (widget),
6027 gtk_widget_reparent_fixup_child,
6033 * gtk_widget_reparent:
6034 * @widget: a #GtkWidget
6035 * @new_parent: a #GtkContainer to move the widget into
6037 * Moves a widget from one #GtkContainer to another, handling reference
6038 * count issues to avoid destroying the widget.
6041 gtk_widget_reparent (GtkWidget *widget,
6042 GtkWidget *new_parent)
6044 GtkWidgetPrivate *priv;
6046 g_return_if_fail (GTK_IS_WIDGET (widget));
6047 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6048 priv = widget->priv;
6049 g_return_if_fail (priv->parent != NULL);
6051 if (priv->parent != new_parent)
6053 /* First try to see if we can get away without unrealizing
6054 * the widget as we reparent it. if so we set a flag so
6055 * that gtk_widget_unparent doesn't unrealize widget
6057 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6058 priv->in_reparent = TRUE;
6060 g_object_ref (widget);
6061 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6062 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6063 g_object_unref (widget);
6065 if (priv->in_reparent)
6067 priv->in_reparent = FALSE;
6069 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6070 gtk_widget_reparent_fixup_child (widget,
6071 gtk_widget_get_parent_window (widget));
6074 g_object_notify (G_OBJECT (widget), "parent");
6079 * gtk_widget_intersect:
6080 * @widget: a #GtkWidget
6081 * @area: a rectangle
6082 * @intersection: rectangle to store intersection of @widget and @area
6084 * Computes the intersection of a @widget's area and @area, storing
6085 * the intersection in @intersection, and returns %TRUE if there was
6086 * an intersection. @intersection may be %NULL if you're only
6087 * interested in whether there was an intersection.
6089 * Return value: %TRUE if there was an intersection
6092 gtk_widget_intersect (GtkWidget *widget,
6093 const GdkRectangle *area,
6094 GdkRectangle *intersection)
6096 GtkWidgetPrivate *priv;
6101 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6102 g_return_val_if_fail (area != NULL, FALSE);
6104 priv = widget->priv;
6107 dest = intersection;
6111 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6113 if (return_val && intersection && gtk_widget_get_has_window (widget))
6115 intersection->x -= priv->allocation.x;
6116 intersection->y -= priv->allocation.y;
6123 * gtk_widget_region_intersect:
6124 * @widget: a #GtkWidget
6125 * @region: a #cairo_region_t, in the same coordinate system as
6126 * @widget->allocation. That is, relative to @widget->window
6127 * for %NO_WINDOW widgets; relative to the parent window
6128 * of @widget->window for widgets with their own window.
6129 * @returns: A newly allocated region holding the intersection of @widget
6130 * and @region. The coordinates of the return value are
6131 * relative to @widget->window for %NO_WINDOW widgets, and
6132 * relative to the parent window of @widget->window for
6133 * widgets with their own window.
6135 * Computes the intersection of a @widget's area and @region, returning
6136 * the intersection. The result may be empty, use cairo_region_is_empty() to
6140 gtk_widget_region_intersect (GtkWidget *widget,
6141 const cairo_region_t *region)
6144 cairo_region_t *dest;
6146 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6147 g_return_val_if_fail (region != NULL, NULL);
6149 gtk_widget_get_allocation (widget, &rect);
6151 dest = cairo_region_create_rectangle (&rect);
6153 cairo_region_intersect (dest, region);
6159 * _gtk_widget_grab_notify:
6160 * @widget: a #GtkWidget
6161 * @was_grabbed: whether a grab is now in effect
6163 * Emits the #GtkWidget::grab-notify signal on @widget.
6168 _gtk_widget_grab_notify (GtkWidget *widget,
6169 gboolean was_grabbed)
6171 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6175 * gtk_widget_grab_focus:
6176 * @widget: a #GtkWidget
6178 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6179 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6180 * something like #GtkFrame won't work.
6182 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6183 * gtk_widget_set_can_focus() to modify that flag.
6185 * The widget also needs to be realized and mapped. This is indicated by the
6186 * related signals. Grabbing the focus immediately after creating the widget
6187 * will likely fail and cause critical warnings.
6190 gtk_widget_grab_focus (GtkWidget *widget)
6192 g_return_if_fail (GTK_IS_WIDGET (widget));
6194 if (!gtk_widget_is_sensitive (widget))
6197 g_object_ref (widget);
6198 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6199 g_object_notify (G_OBJECT (widget), "has-focus");
6200 g_object_unref (widget);
6204 reset_focus_recurse (GtkWidget *widget,
6207 if (GTK_IS_CONTAINER (widget))
6209 GtkContainer *container;
6211 container = GTK_CONTAINER (widget);
6212 gtk_container_set_focus_child (container, NULL);
6214 gtk_container_foreach (container,
6215 reset_focus_recurse,
6221 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6223 if (gtk_widget_get_can_focus (focus_widget))
6225 GtkWidget *toplevel;
6228 /* clear the current focus setting, break if the current widget
6229 * is the focus widget's parent, since containers above that will
6230 * be set by the next loop.
6232 toplevel = gtk_widget_get_toplevel (focus_widget);
6233 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6235 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6237 if (widget == focus_widget)
6239 /* We call _gtk_window_internal_set_focus() here so that the
6240 * toplevel window can request the focus if necessary.
6241 * This is needed when the toplevel is a GtkPlug
6243 if (!gtk_widget_has_focus (widget))
6244 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6251 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6253 widget = widget->priv->parent;
6254 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6258 else if (toplevel != focus_widget)
6260 /* gtk_widget_grab_focus() operates on a tree without window...
6261 * actually, this is very questionable behaviour.
6264 gtk_container_foreach (GTK_CONTAINER (toplevel),
6265 reset_focus_recurse,
6269 /* now propagate the new focus up the widget tree and finally
6270 * set it on the window
6272 widget = focus_widget;
6273 while (widget->priv->parent)
6275 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6276 widget = widget->priv->parent;
6278 if (GTK_IS_WINDOW (widget))
6279 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6284 gtk_widget_real_query_tooltip (GtkWidget *widget,
6287 gboolean keyboard_tip,
6288 GtkTooltip *tooltip)
6290 gchar *tooltip_markup;
6291 gboolean has_tooltip;
6293 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6294 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6296 if (has_tooltip && tooltip_markup)
6298 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6306 gtk_widget_real_show_help (GtkWidget *widget,
6307 GtkWidgetHelpType help_type)
6309 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6311 _gtk_tooltip_toggle_keyboard_mode (widget);
6320 gtk_widget_real_focus (GtkWidget *widget,
6321 GtkDirectionType direction)
6323 if (!gtk_widget_get_can_focus (widget))
6326 if (!gtk_widget_is_focus (widget))
6328 gtk_widget_grab_focus (widget);
6336 gtk_widget_real_move_focus (GtkWidget *widget,
6337 GtkDirectionType direction)
6339 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6341 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6343 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6349 gtk_widget_real_keynav_failed (GtkWidget *widget,
6350 GtkDirectionType direction)
6352 gboolean cursor_only;
6356 case GTK_DIR_TAB_FORWARD:
6357 case GTK_DIR_TAB_BACKWARD:
6364 g_object_get (gtk_widget_get_settings (widget),
6365 "gtk-keynav-cursor-only", &cursor_only,
6372 gtk_widget_error_bell (widget);
6378 * gtk_widget_set_can_focus:
6379 * @widget: a #GtkWidget
6380 * @can_focus: whether or not @widget can own the input focus.
6382 * Specifies whether @widget can own the input focus. See
6383 * gtk_widget_grab_focus() for actually setting the input focus on a
6389 gtk_widget_set_can_focus (GtkWidget *widget,
6392 g_return_if_fail (GTK_IS_WIDGET (widget));
6394 if (widget->priv->can_focus != can_focus)
6396 widget->priv->can_focus = can_focus;
6398 gtk_widget_queue_resize (widget);
6399 g_object_notify (G_OBJECT (widget), "can-focus");
6404 * gtk_widget_get_can_focus:
6405 * @widget: a #GtkWidget
6407 * Determines whether @widget can own the input focus. See
6408 * gtk_widget_set_can_focus().
6410 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6415 gtk_widget_get_can_focus (GtkWidget *widget)
6417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6419 return widget->priv->can_focus;
6423 * gtk_widget_has_focus:
6424 * @widget: a #GtkWidget
6426 * Determines if the widget has the global input focus. See
6427 * gtk_widget_is_focus() for the difference between having the global
6428 * input focus, and only having the focus within a toplevel.
6430 * Return value: %TRUE if the widget has the global input focus.
6435 gtk_widget_has_focus (GtkWidget *widget)
6437 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6439 return widget->priv->has_focus;
6443 * gtk_widget_is_focus:
6444 * @widget: a #GtkWidget
6446 * Determines if the widget is the focus widget within its
6447 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6448 * necessarily set; %HAS_FOCUS will only be set if the
6449 * toplevel widget additionally has the global input focus.)
6451 * Return value: %TRUE if the widget is the focus widget.
6454 gtk_widget_is_focus (GtkWidget *widget)
6456 GtkWidget *toplevel;
6458 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6460 toplevel = gtk_widget_get_toplevel (widget);
6462 if (GTK_IS_WINDOW (toplevel))
6463 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6469 * gtk_widget_set_can_default:
6470 * @widget: a #GtkWidget
6471 * @can_default: whether or not @widget can be a default widget.
6473 * Specifies whether @widget can be a default widget. See
6474 * gtk_widget_grab_default() for details about the meaning of
6480 gtk_widget_set_can_default (GtkWidget *widget,
6481 gboolean can_default)
6483 g_return_if_fail (GTK_IS_WIDGET (widget));
6485 if (widget->priv->can_default != can_default)
6487 widget->priv->can_default = can_default;
6489 gtk_widget_queue_resize (widget);
6490 g_object_notify (G_OBJECT (widget), "can-default");
6495 * gtk_widget_get_can_default:
6496 * @widget: a #GtkWidget
6498 * Determines whether @widget can be a default widget. See
6499 * gtk_widget_set_can_default().
6501 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6506 gtk_widget_get_can_default (GtkWidget *widget)
6508 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6510 return widget->priv->can_default;
6514 * gtk_widget_has_default:
6515 * @widget: a #GtkWidget
6517 * Determines whether @widget is the current default widget within its
6518 * toplevel. See gtk_widget_set_can_default().
6520 * Return value: %TRUE if @widget is the current default widget within
6521 * its toplevel, %FALSE otherwise
6526 gtk_widget_has_default (GtkWidget *widget)
6528 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6530 return widget->priv->has_default;
6534 _gtk_widget_set_has_default (GtkWidget *widget,
6535 gboolean has_default)
6537 widget->priv->has_default = has_default;
6541 * gtk_widget_grab_default:
6542 * @widget: a #GtkWidget
6544 * Causes @widget to become the default widget. @widget must have the
6545 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6546 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6547 * %TRUE)</literal>. The default widget is activated when
6548 * the user presses Enter in a window. Default widgets must be
6549 * activatable, that is, gtk_widget_activate() should affect them. Note
6550 * that #GtkEntry widgets require the "activates-default" property
6551 * set to %TRUE before they activate the default widget when Enter
6552 * is pressed and the #GtkEntry is focused.
6555 gtk_widget_grab_default (GtkWidget *widget)
6559 g_return_if_fail (GTK_IS_WIDGET (widget));
6560 g_return_if_fail (gtk_widget_get_can_default (widget));
6562 window = gtk_widget_get_toplevel (widget);
6564 if (window && gtk_widget_is_toplevel (window))
6565 gtk_window_set_default (GTK_WINDOW (window), widget);
6567 g_warning (G_STRLOC ": widget not within a GtkWindow");
6571 * gtk_widget_set_receives_default:
6572 * @widget: a #GtkWidget
6573 * @receives_default: whether or not @widget can be a default widget.
6575 * Specifies whether @widget will be treated as the default widget
6576 * within its toplevel when it has the focus, even if another widget
6579 * See gtk_widget_grab_default() for details about the meaning of
6585 gtk_widget_set_receives_default (GtkWidget *widget,
6586 gboolean receives_default)
6588 g_return_if_fail (GTK_IS_WIDGET (widget));
6590 if (widget->priv->receives_default != receives_default)
6592 widget->priv->receives_default = receives_default;
6594 g_object_notify (G_OBJECT (widget), "receives-default");
6599 * gtk_widget_get_receives_default:
6600 * @widget: a #GtkWidget
6602 * Determines whether @widget is alyways treated as default widget
6603 * withing its toplevel when it has the focus, even if another widget
6606 * See gtk_widget_set_receives_default().
6608 * Return value: %TRUE if @widget acts as default widget when focussed,
6614 gtk_widget_get_receives_default (GtkWidget *widget)
6616 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6618 return widget->priv->receives_default;
6622 * gtk_widget_has_grab:
6623 * @widget: a #GtkWidget
6625 * Determines whether the widget is currently grabbing events, so it
6626 * is the only widget receiving input events (keyboard and mouse).
6628 * See also gtk_grab_add().
6630 * Return value: %TRUE if the widget is in the grab_widgets stack
6635 gtk_widget_has_grab (GtkWidget *widget)
6637 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6639 return widget->priv->has_grab;
6643 _gtk_widget_set_has_grab (GtkWidget *widget,
6646 widget->priv->has_grab = has_grab;
6650 * gtk_widget_device_is_shadowed:
6651 * @widget: a #GtkWidget
6652 * @device: a #GdkDevice
6654 * Returns %TRUE if @device has been shadowed by a GTK+
6655 * device grab on another widget, so it would stop sending
6656 * events to @widget. This may be used in the
6657 * #GtkWidget::grab-notify signal to check for specific
6658 * devices. See gtk_device_grab_add().
6660 * Returns: %TRUE if there is an ongoing grab on @device
6661 * by another #GtkWidget than @widget.
6666 gtk_widget_device_is_shadowed (GtkWidget *widget,
6669 GtkWindowGroup *group;
6670 GtkWidget *grab_widget, *toplevel;
6672 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6673 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6675 if (!gtk_widget_get_realized (widget))
6678 toplevel = gtk_widget_get_toplevel (widget);
6680 if (GTK_IS_WINDOW (toplevel))
6681 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6683 group = gtk_window_get_group (NULL);
6685 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6687 /* Widget not inside the hierarchy of grab_widget */
6689 widget != grab_widget &&
6690 !gtk_widget_is_ancestor (widget, grab_widget))
6693 grab_widget = gtk_window_group_get_current_grab (group);
6694 if (grab_widget && widget != grab_widget &&
6695 !gtk_widget_is_ancestor (widget, grab_widget))
6702 * gtk_widget_set_name:
6703 * @widget: a #GtkWidget
6704 * @name: name for the widget
6706 * Widgets can be named, which allows you to refer to them from a
6707 * gtkrc file. You can apply a style to widgets with a particular name
6708 * in the gtkrc file. See the documentation for gtkrc files (on the
6709 * same page as the docs for #GtkRcStyle).
6711 * Note that widget names are separated by periods in paths (see
6712 * gtk_widget_path()), so names with embedded periods may cause confusion.
6715 gtk_widget_set_name (GtkWidget *widget,
6718 GtkWidgetPrivate *priv;
6721 g_return_if_fail (GTK_IS_WIDGET (widget));
6723 priv = widget->priv;
6725 new_name = g_strdup (name);
6726 g_free (priv->name);
6727 priv->name = new_name;
6730 gtk_widget_reset_rc_style (widget);
6732 g_object_notify (G_OBJECT (widget), "name");
6736 * gtk_widget_get_name:
6737 * @widget: a #GtkWidget
6739 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6740 * significance of widget names.
6742 * Return value: name of the widget. This string is owned by GTK+ and
6743 * should not be modified or freed
6745 G_CONST_RETURN gchar*
6746 gtk_widget_get_name (GtkWidget *widget)
6748 GtkWidgetPrivate *priv;
6750 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6752 priv = widget->priv;
6756 return G_OBJECT_TYPE_NAME (widget);
6760 * gtk_widget_set_state:
6761 * @widget: a #GtkWidget
6762 * @state: new state for @widget
6764 * This function is for use in widget implementations. Sets the state
6765 * of a widget (insensitive, prelighted, etc.) Usually you should set
6766 * the state using wrapper functions such as gtk_widget_set_sensitive().
6769 gtk_widget_set_state (GtkWidget *widget,
6772 GtkWidgetPrivate *priv;
6774 g_return_if_fail (GTK_IS_WIDGET (widget));
6776 priv = widget->priv;
6778 if (state == gtk_widget_get_state (widget))
6781 if (state == GTK_STATE_INSENSITIVE)
6782 gtk_widget_set_sensitive (widget, FALSE);
6788 data.state_restoration = FALSE;
6789 data.use_forall = FALSE;
6791 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6793 data.parent_sensitive = TRUE;
6795 gtk_widget_propagate_state (widget, &data);
6797 if (gtk_widget_is_drawable (widget))
6798 gtk_widget_queue_draw (widget);
6803 * gtk_widget_get_state:
6804 * @widget: a #GtkWidget
6806 * Returns the widget's state. See gtk_widget_set_state().
6808 * Returns: the state of @widget.
6813 gtk_widget_get_state (GtkWidget *widget)
6815 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6817 return widget->priv->state;
6821 * gtk_widget_set_visible:
6822 * @widget: a #GtkWidget
6823 * @visible: whether the widget should be shown or not
6825 * Sets the visibility state of @widget. Note that setting this to
6826 * %TRUE doesn't mean the widget is actually viewable, see
6827 * gtk_widget_get_visible().
6829 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6830 * but is nicer to use when the visibility of the widget depends on
6836 gtk_widget_set_visible (GtkWidget *widget,
6839 g_return_if_fail (GTK_IS_WIDGET (widget));
6841 if (visible != gtk_widget_get_visible (widget))
6844 gtk_widget_show (widget);
6846 gtk_widget_hide (widget);
6851 _gtk_widget_set_visible_flag (GtkWidget *widget,
6854 widget->priv->visible = visible;
6858 * gtk_widget_get_visible:
6859 * @widget: a #GtkWidget
6861 * Determines whether the widget is visible. Note that this doesn't
6862 * take into account whether the widget's parent is also visible
6863 * or the widget is obscured in any way.
6865 * See gtk_widget_set_visible().
6867 * Return value: %TRUE if the widget is visible
6872 gtk_widget_get_visible (GtkWidget *widget)
6874 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6876 return widget->priv->visible;
6880 * gtk_widget_set_has_window:
6881 * @widget: a #GtkWidget
6882 * @has_window: whether or not @widget has a window.
6884 * Specifies whether @widget has a #GdkWindow of its own. Note that
6885 * all realized widgets have a non-%NULL "window" pointer
6886 * (gtk_widget_get_window() never returns a %NULL window when a widget
6887 * is realized), but for many of them it's actually the #GdkWindow of
6888 * one of its parent widgets. Widgets that do not create a %window for
6889 * themselves in #GtkWidget::realize must announce this by
6890 * calling this function with @has_window = %FALSE.
6892 * This function should only be called by widget implementations,
6893 * and they should call it in their init() function.
6898 gtk_widget_set_has_window (GtkWidget *widget,
6899 gboolean has_window)
6901 g_return_if_fail (GTK_IS_WIDGET (widget));
6903 widget->priv->no_window = !has_window;
6907 * gtk_widget_get_has_window:
6908 * @widget: a #GtkWidget
6910 * Determines whether @widget has a #GdkWindow of its own. See
6911 * gtk_widget_set_has_window().
6913 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6918 gtk_widget_get_has_window (GtkWidget *widget)
6920 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6922 return ! widget->priv->no_window;
6926 * gtk_widget_is_toplevel:
6927 * @widget: a #GtkWidget
6929 * Determines whether @widget is a toplevel widget. Currently only
6930 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6931 * widgets have no parent widget.
6933 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6938 gtk_widget_is_toplevel (GtkWidget *widget)
6940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6942 return widget->priv->toplevel;
6946 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6947 gboolean is_toplevel)
6949 widget->priv->toplevel = is_toplevel;
6953 * gtk_widget_is_drawable:
6954 * @widget: a #GtkWidget
6956 * Determines whether @widget can be drawn to. A widget can be drawn
6957 * to if it is mapped and visible.
6959 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6964 gtk_widget_is_drawable (GtkWidget *widget)
6966 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6968 return (gtk_widget_get_visible (widget) &&
6969 gtk_widget_get_mapped (widget));
6973 * gtk_widget_get_realized:
6974 * @widget: a #GtkWidget
6976 * Determines whether @widget is realized.
6978 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6983 gtk_widget_get_realized (GtkWidget *widget)
6985 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6987 return widget->priv->realized;
6991 * gtk_widget_set_realized:
6992 * @widget: a #GtkWidget
6993 * @realized: %TRUE to mark the widget as realized
6995 * Marks the widget as being realized.
6997 * This function should only ever be called in a derived widget's
6998 * "realize" or "unrealize" implementation.
7003 gtk_widget_set_realized (GtkWidget *widget,
7006 g_return_if_fail (GTK_IS_WIDGET (widget));
7008 widget->priv->realized = realized;
7012 * gtk_widget_get_mapped:
7013 * @widget: a #GtkWidget
7015 * Whether the widget is mapped.
7017 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7022 gtk_widget_get_mapped (GtkWidget *widget)
7024 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7026 return widget->priv->mapped;
7030 * gtk_widget_set_mapped:
7031 * @widget: a #GtkWidget
7032 * @mapped: %TRUE to mark the widget as mapped
7034 * Marks the widget as being realized.
7036 * This function should only ever be called in a derived widget's
7037 * "map" or "unmap" implementation.
7042 gtk_widget_set_mapped (GtkWidget *widget,
7045 g_return_if_fail (GTK_IS_WIDGET (widget));
7047 widget->priv->mapped = mapped;
7051 * gtk_widget_set_app_paintable:
7052 * @widget: a #GtkWidget
7053 * @app_paintable: %TRUE if the application will paint on the widget
7055 * Sets whether the application intends to draw on the widget in
7056 * an #GtkWidget::draw handler.
7058 * This is a hint to the widget and does not affect the behavior of
7059 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7060 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7061 * the effect is to suppress default themed drawing of the widget's
7062 * background. (Children of the widget will still be drawn.) The application
7063 * is then entirely responsible for drawing the widget background.
7065 * Note that the background is still drawn when the widget is mapped.
7068 gtk_widget_set_app_paintable (GtkWidget *widget,
7069 gboolean app_paintable)
7071 g_return_if_fail (GTK_IS_WIDGET (widget));
7073 app_paintable = (app_paintable != FALSE);
7075 if (widget->priv->app_paintable != app_paintable)
7077 widget->priv->app_paintable = app_paintable;
7079 if (gtk_widget_is_drawable (widget))
7080 gtk_widget_queue_draw (widget);
7082 g_object_notify (G_OBJECT (widget), "app-paintable");
7087 * gtk_widget_get_app_paintable:
7088 * @widget: a #GtkWidget
7090 * Determines whether the application intends to draw on the widget in
7091 * an #GtkWidget::draw handler.
7093 * See gtk_widget_set_app_paintable()
7095 * Return value: %TRUE if the widget is app paintable
7100 gtk_widget_get_app_paintable (GtkWidget *widget)
7102 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7104 return widget->priv->app_paintable;
7108 * gtk_widget_set_double_buffered:
7109 * @widget: a #GtkWidget
7110 * @double_buffered: %TRUE to double-buffer a widget
7112 * Widgets are double buffered by default; you can use this function
7113 * to turn off the buffering. "Double buffered" simply means that
7114 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7115 * automatically around expose events sent to the
7116 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7117 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7118 * buffer to the screen. The result is that users see the window
7119 * update in one smooth step, and don't see individual graphics
7120 * primitives being rendered.
7122 * In very simple terms, double buffered widgets don't flicker,
7123 * so you would only use this function to turn off double buffering
7124 * if you had special needs and really knew what you were doing.
7126 * Note: if you turn off double-buffering, you have to handle
7127 * expose events, since even the clearing to the background color or
7128 * pixmap will not happen automatically (as it is done in
7129 * gdk_window_begin_paint()).
7132 gtk_widget_set_double_buffered (GtkWidget *widget,
7133 gboolean double_buffered)
7135 g_return_if_fail (GTK_IS_WIDGET (widget));
7137 double_buffered = (double_buffered != FALSE);
7139 if (widget->priv->double_buffered != double_buffered)
7141 widget->priv->double_buffered = double_buffered;
7143 g_object_notify (G_OBJECT (widget), "double-buffered");
7148 * gtk_widget_get_double_buffered:
7149 * @widget: a #GtkWidget
7151 * Determines whether the widget is double buffered.
7153 * See gtk_widget_set_double_buffered()
7155 * Return value: %TRUE if the widget is double buffered
7160 gtk_widget_get_double_buffered (GtkWidget *widget)
7162 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7164 return widget->priv->double_buffered;
7168 * gtk_widget_set_redraw_on_allocate:
7169 * @widget: a #GtkWidget
7170 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7171 * when it is allocated to a new size. Otherwise, only the
7172 * new portion of the widget will be redrawn.
7174 * Sets whether the entire widget is queued for drawing when its size
7175 * allocation changes. By default, this setting is %TRUE and
7176 * the entire widget is redrawn on every size change. If your widget
7177 * leaves the upper left unchanged when made bigger, turning this
7178 * setting off will improve performance.
7180 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7181 * off all allocation on resizing: the widget will not even redraw if
7182 * its position changes; this is to allow containers that don't draw
7183 * anything to avoid excess invalidations. If you set this flag on a
7184 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7185 * you are responsible for invalidating both the old and new allocation
7186 * of the widget when the widget is moved and responsible for invalidating
7187 * regions newly when the widget increases size.
7190 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7191 gboolean redraw_on_allocate)
7193 g_return_if_fail (GTK_IS_WIDGET (widget));
7195 widget->priv->redraw_on_alloc = redraw_on_allocate;
7199 * gtk_widget_set_sensitive:
7200 * @widget: a #GtkWidget
7201 * @sensitive: %TRUE to make the widget sensitive
7203 * Sets the sensitivity of a widget. A widget is sensitive if the user
7204 * can interact with it. Insensitive widgets are "grayed out" and the
7205 * user can't interact with them. Insensitive widgets are known as
7206 * "inactive", "disabled", or "ghosted" in some other toolkits.
7209 gtk_widget_set_sensitive (GtkWidget *widget,
7212 GtkWidgetPrivate *priv;
7215 g_return_if_fail (GTK_IS_WIDGET (widget));
7217 priv = widget->priv;
7219 sensitive = (sensitive != FALSE);
7221 if (widget->priv->sensitive == sensitive)
7226 widget->priv->sensitive = TRUE;
7227 data.state = priv->saved_state;
7231 widget->priv->sensitive = FALSE;
7232 data.state = gtk_widget_get_state (widget);
7234 data.state_restoration = TRUE;
7235 data.use_forall = TRUE;
7238 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7240 data.parent_sensitive = TRUE;
7242 gtk_widget_propagate_state (widget, &data);
7243 if (gtk_widget_is_drawable (widget))
7244 gtk_widget_queue_draw (widget);
7246 g_object_notify (G_OBJECT (widget), "sensitive");
7250 * gtk_widget_get_sensitive:
7251 * @widget: a #GtkWidget
7253 * Returns the widget's sensitivity (in the sense of returning
7254 * the value that has been set using gtk_widget_set_sensitive()).
7256 * The effective sensitivity of a widget is however determined by both its
7257 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7259 * Returns: %TRUE if the widget is sensitive
7264 gtk_widget_get_sensitive (GtkWidget *widget)
7266 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7268 return widget->priv->sensitive;
7272 * gtk_widget_is_sensitive:
7273 * @widget: a #GtkWidget
7275 * Returns the widget's effective sensitivity, which means
7276 * it is sensitive itself and also its parent widget is sensntive
7278 * Returns: %TRUE if the widget is effectively sensitive
7283 gtk_widget_is_sensitive (GtkWidget *widget)
7285 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7287 return widget->priv->sensitive && widget->priv->parent_sensitive;
7291 * gtk_widget_set_parent:
7292 * @widget: a #GtkWidget
7293 * @parent: parent container
7295 * This function is useful only when implementing subclasses of
7297 * Sets the container as the parent of @widget, and takes care of
7298 * some details such as updating the state and style of the child
7299 * to reflect its new location. The opposite function is
7300 * gtk_widget_unparent().
7303 gtk_widget_set_parent (GtkWidget *widget,
7306 GtkWidgetPrivate *priv;
7309 g_return_if_fail (GTK_IS_WIDGET (widget));
7310 g_return_if_fail (GTK_IS_WIDGET (parent));
7311 g_return_if_fail (widget != parent);
7313 priv = widget->priv;
7315 if (priv->parent != NULL)
7317 g_warning ("Can't set a parent on widget which has a parent\n");
7320 if (gtk_widget_is_toplevel (widget))
7322 g_warning ("Can't set a parent on a toplevel widget\n");
7326 /* keep this function in sync with gtk_menu_attach_to_widget()
7329 g_object_ref_sink (widget);
7330 priv->parent = parent;
7332 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7333 data.state = gtk_widget_get_state (parent);
7335 data.state = gtk_widget_get_state (widget);
7336 data.state_restoration = FALSE;
7337 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7338 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7340 gtk_widget_propagate_state (widget, &data);
7342 gtk_widget_reset_rc_styles (widget);
7344 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7345 if (priv->parent->priv->anchored)
7346 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7347 g_object_notify (G_OBJECT (widget), "parent");
7349 /* Enforce realized/mapped invariants
7351 if (gtk_widget_get_realized (priv->parent))
7352 gtk_widget_realize (widget);
7354 if (gtk_widget_get_visible (priv->parent) &&
7355 gtk_widget_get_visible (widget))
7357 if (gtk_widget_get_child_visible (widget) &&
7358 gtk_widget_get_mapped (priv->parent))
7359 gtk_widget_map (widget);
7361 gtk_widget_queue_resize (widget);
7364 /* child may cause parent's expand to change, if the child is
7365 * expanded. If child is not expanded, then it can't modify the
7366 * parent's expand. If the child becomes expanded later then it will
7367 * queue compute_expand then. This optimization plus defaulting
7368 * newly-constructed widgets to need_compute_expand=FALSE should
7369 * mean that initially building a widget tree doesn't have to keep
7370 * walking up setting need_compute_expand on parents over and over.
7372 * We can't change a parent to need to expand unless we're visible.
7374 if (gtk_widget_get_visible (widget) &&
7375 (priv->need_compute_expand ||
7376 priv->computed_hexpand ||
7377 priv->computed_vexpand))
7379 gtk_widget_queue_compute_expand (parent);
7384 * gtk_widget_get_parent:
7385 * @widget: a #GtkWidget
7387 * Returns the parent container of @widget.
7389 * Return value: (transfer none): the parent container of @widget, or %NULL
7392 gtk_widget_get_parent (GtkWidget *widget)
7394 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7396 return widget->priv->parent;
7399 /*****************************************
7401 * see docs/styles.txt
7402 *****************************************/
7405 * gtk_widget_style_attach:
7406 * @widget: a #GtkWidget
7408 * This function attaches the widget's #GtkStyle to the widget's
7409 * #GdkWindow. It is a replacement for
7412 * widget->style = gtk_style_attach (widget->style, widget->window);
7415 * and should only ever be called in a derived widget's "realize"
7416 * implementation which does not chain up to its parent class'
7417 * "realize" implementation, because one of the parent classes
7418 * (finally #GtkWidget) would attach the style itself.
7423 gtk_widget_style_attach (GtkWidget *widget)
7425 GtkWidgetPrivate *priv;
7427 g_return_if_fail (GTK_IS_WIDGET (widget));
7428 g_return_if_fail (gtk_widget_get_realized (widget));
7430 priv = widget->priv;
7432 priv->style = gtk_style_attach (priv->style, priv->window);
7436 * gtk_widget_has_rc_style:
7437 * @widget: a #GtkWidget
7439 * Determines if the widget style has been looked up through the rc mechanism.
7441 * Returns: %TRUE if the widget has been looked up through the rc
7442 * mechanism, %FALSE otherwise.
7447 gtk_widget_has_rc_style (GtkWidget *widget)
7449 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7451 return widget->priv->rc_style;
7455 * gtk_widget_set_style:
7456 * @widget: a #GtkWidget
7457 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7458 * gtk_widget_set_style() and go back to the default style
7460 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7461 * want to use this function; it interacts badly with themes, because
7462 * themes work by replacing the #GtkStyle. Instead, use
7463 * gtk_widget_modify_style().
7466 gtk_widget_set_style (GtkWidget *widget,
7469 g_return_if_fail (GTK_IS_WIDGET (widget));
7473 gboolean initial_emission;
7475 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7477 widget->priv->rc_style = FALSE;
7478 widget->priv->user_style = TRUE;
7480 gtk_widget_set_style_internal (widget, style, initial_emission);
7484 if (widget->priv->user_style)
7485 gtk_widget_reset_rc_style (widget);
7490 * gtk_widget_ensure_style:
7491 * @widget: a #GtkWidget
7493 * Ensures that @widget has a style (@widget->style). Not a very useful
7494 * function; most of the time, if you want the style, the widget is
7495 * realized, and realized widgets are guaranteed to have a style
7499 gtk_widget_ensure_style (GtkWidget *widget)
7501 g_return_if_fail (GTK_IS_WIDGET (widget));
7503 if (!widget->priv->rc_style && !widget->priv->user_style)
7504 gtk_widget_reset_rc_style (widget);
7507 /* Look up the RC style for this widget, unsetting any user style that
7508 * may be in effect currently
7511 gtk_widget_reset_rc_style (GtkWidget *widget)
7513 GtkWidgetPrivate *priv = widget->priv;
7514 GtkStyle *new_style = NULL;
7515 gboolean initial_emission;
7517 initial_emission = !priv->rc_style && !priv->user_style;
7519 priv->user_style = FALSE;
7520 priv->rc_style = TRUE;
7522 if (gtk_widget_has_screen (widget))
7523 new_style = gtk_rc_get_style (widget);
7525 new_style = gtk_widget_get_default_style ();
7527 if (initial_emission || new_style != priv->style)
7528 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7532 * gtk_widget_get_style:
7533 * @widget: a #GtkWidget
7535 * Simply an accessor function that returns @widget->style.
7537 * Return value: (transfer none): the widget's #GtkStyle
7540 gtk_widget_get_style (GtkWidget *widget)
7542 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7544 return widget->priv->style;
7548 * gtk_widget_modify_style:
7549 * @widget: a #GtkWidget
7550 * @style: the #GtkRcStyle holding the style modifications
7552 * Modifies style values on the widget. Modifications made using this
7553 * technique take precedence over style values set via an RC file,
7554 * however, they will be overriden if a style is explicitely set on
7555 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7556 * is designed so each field can either be set or unset, so it is
7557 * possible, using this function, to modify some style values and
7558 * leave the others unchanged.
7560 * Note that modifications made with this function are not cumulative
7561 * with previous calls to gtk_widget_modify_style() or with such
7562 * functions as gtk_widget_modify_fg(). If you wish to retain
7563 * previous values, you must first call gtk_widget_get_modifier_style(),
7564 * make your modifications to the returned style, then call
7565 * gtk_widget_modify_style() with that style. On the other hand,
7566 * if you first call gtk_widget_modify_style(), subsequent calls
7567 * to such functions gtk_widget_modify_fg() will have a cumulative
7568 * effect with the initial modifications.
7571 gtk_widget_modify_style (GtkWidget *widget,
7574 g_return_if_fail (GTK_IS_WIDGET (widget));
7575 g_return_if_fail (GTK_IS_RC_STYLE (style));
7577 g_object_set_qdata_full (G_OBJECT (widget),
7579 gtk_rc_style_copy (style),
7580 (GDestroyNotify) g_object_unref);
7582 /* note that "style" may be invalid here if it was the old
7583 * modifier style and the only reference was our own.
7586 if (widget->priv->rc_style)
7587 gtk_widget_reset_rc_style (widget);
7591 * gtk_widget_get_modifier_style:
7592 * @widget: a #GtkWidget
7594 * Returns the current modifier style for the widget. (As set by
7595 * gtk_widget_modify_style().) If no style has previously set, a new
7596 * #GtkRcStyle will be created with all values unset, and set as the
7597 * modifier style for the widget. If you make changes to this rc
7598 * style, you must call gtk_widget_modify_style(), passing in the
7599 * returned rc style, to make sure that your changes take effect.
7601 * Caution: passing the style back to gtk_widget_modify_style() will
7602 * normally end up destroying it, because gtk_widget_modify_style() copies
7603 * the passed-in style and sets the copy as the new modifier style,
7604 * thus dropping any reference to the old modifier style. Add a reference
7605 * to the modifier style if you want to keep it alive.
7607 * Return value: (transfer none): the modifier style for the widget. This rc style is
7608 * owned by the widget. If you want to keep a pointer to value this
7609 * around, you must add a refcount using g_object_ref().
7612 gtk_widget_get_modifier_style (GtkWidget *widget)
7614 GtkRcStyle *rc_style;
7616 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7618 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7622 rc_style = gtk_rc_style_new ();
7623 g_object_set_qdata_full (G_OBJECT (widget),
7626 (GDestroyNotify) g_object_unref);
7633 gtk_widget_modify_color_component (GtkWidget *widget,
7634 GtkRcFlags component,
7636 const GdkColor *color)
7638 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7645 rc_style->fg[state] = *color;
7648 rc_style->bg[state] = *color;
7651 rc_style->text[state] = *color;
7654 rc_style->base[state] = *color;
7657 g_assert_not_reached();
7660 rc_style->color_flags[state] |= component;
7663 rc_style->color_flags[state] &= ~component;
7665 gtk_widget_modify_style (widget, rc_style);
7669 * gtk_widget_modify_symbolic_color:
7670 * @widget: a #GtkWidget
7671 * @name: the name of the symbolic color to modify
7672 * @color: (allow-none): the color to assign (does not need to be allocated),
7673 * or %NULL to undo the effect of previous calls to
7674 * of gtk_widget_modify_symbolic_color().
7676 * Sets a symbolic color for a widget.
7677 * All other style values are left untouched. See also
7678 * gtk_widget_modify_style().
7683 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7685 const GdkColor *color)
7687 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7689 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7691 gtk_widget_modify_style (widget, rc_style);
7695 * gtk_widget_modify_fg:
7696 * @widget: a #GtkWidget
7697 * @state: the state for which to set the foreground color
7698 * @color: (allow-none): the color to assign (does not need to be allocated),
7699 * or %NULL to undo the effect of previous calls to
7700 * of gtk_widget_modify_fg().
7702 * Sets the foreground color for a widget in a particular state.
7703 * All other style values are left untouched. See also
7704 * gtk_widget_modify_style().
7707 gtk_widget_modify_fg (GtkWidget *widget,
7709 const GdkColor *color)
7711 g_return_if_fail (GTK_IS_WIDGET (widget));
7712 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7714 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7718 * gtk_widget_modify_bg:
7719 * @widget: a #GtkWidget
7720 * @state: the state for which to set the background color
7721 * @color: (allow-none): the color to assign (does not need to be allocated),
7722 * or %NULL to undo the effect of previous calls to
7723 * of gtk_widget_modify_bg().
7725 * Sets the background color for a widget in a particular state.
7726 * All other style values are left untouched. See also
7727 * gtk_widget_modify_style().
7729 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7730 * draw on their parent container's window and thus may not draw any
7731 * background themselves. This is the case for e.g. #GtkLabel. To modify
7732 * the background of such widgets, you have to set the background color
7733 * on their parent; if you want to set the background of a rectangular
7734 * area around a label, try placing the label in a #GtkEventBox widget
7735 * and setting the background color on that.
7738 gtk_widget_modify_bg (GtkWidget *widget,
7740 const GdkColor *color)
7742 g_return_if_fail (GTK_IS_WIDGET (widget));
7743 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7745 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7749 * gtk_widget_modify_text:
7750 * @widget: a #GtkWidget
7751 * @state: the state for which to set the text color
7752 * @color: (allow-none): the color to assign (does not need to be allocated),
7753 * or %NULL to undo the effect of previous calls to
7754 * of gtk_widget_modify_text().
7756 * Sets the text color for a widget in a particular state. All other
7757 * style values are left untouched. The text color is the foreground
7758 * color used along with the base color (see gtk_widget_modify_base())
7759 * for widgets such as #GtkEntry and #GtkTextView. See also
7760 * gtk_widget_modify_style().
7763 gtk_widget_modify_text (GtkWidget *widget,
7765 const GdkColor *color)
7767 g_return_if_fail (GTK_IS_WIDGET (widget));
7768 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7770 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7774 * gtk_widget_modify_base:
7775 * @widget: a #GtkWidget
7776 * @state: the state for which to set the base color
7777 * @color: (allow-none): the color to assign (does not need to be allocated),
7778 * or %NULL to undo the effect of previous calls to
7779 * of gtk_widget_modify_base().
7781 * Sets the base color for a widget in a particular state.
7782 * All other style values are left untouched. The base color
7783 * is the background color used along with the text color
7784 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7785 * and #GtkTextView. See also gtk_widget_modify_style().
7787 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7788 * draw on their parent container's window and thus may not draw any
7789 * background themselves. This is the case for e.g. #GtkLabel. To modify
7790 * the background of such widgets, you have to set the base color on their
7791 * parent; if you want to set the background of a rectangular area around
7792 * a label, try placing the label in a #GtkEventBox widget and setting
7793 * the base color on that.
7796 gtk_widget_modify_base (GtkWidget *widget,
7798 const GdkColor *color)
7800 g_return_if_fail (GTK_IS_WIDGET (widget));
7801 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7803 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7807 modify_color_property (GtkWidget *widget,
7808 GtkRcStyle *rc_style,
7810 const GdkColor *color)
7812 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7813 GQuark property_name = g_quark_from_string (name);
7817 GtkRcProperty rc_property = {0};
7820 rc_property.type_name = type_name;
7821 rc_property.property_name = property_name;
7822 rc_property.origin = NULL;
7824 color_name = gdk_color_to_string (color);
7825 g_value_init (&rc_property.value, G_TYPE_STRING);
7826 g_value_take_string (&rc_property.value, color_name);
7828 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7830 g_value_unset (&rc_property.value);
7833 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7837 * gtk_widget_modify_cursor:
7838 * @widget: a #GtkWidget
7839 * @primary: the color to use for primary cursor (does not need to be
7840 * allocated), or %NULL to undo the effect of previous calls to
7841 * of gtk_widget_modify_cursor().
7842 * @secondary: the color to use for secondary cursor (does not need to be
7843 * allocated), or %NULL to undo the effect of previous calls to
7844 * of gtk_widget_modify_cursor().
7846 * Sets the cursor color to use in a widget, overriding the
7847 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7848 * style properties. All other style values are left untouched.
7849 * See also gtk_widget_modify_style().
7854 gtk_widget_modify_cursor (GtkWidget *widget,
7855 const GdkColor *primary,
7856 const GdkColor *secondary)
7858 GtkRcStyle *rc_style;
7860 g_return_if_fail (GTK_IS_WIDGET (widget));
7862 rc_style = gtk_widget_get_modifier_style (widget);
7864 modify_color_property (widget, rc_style, "cursor-color", primary);
7865 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7867 gtk_widget_modify_style (widget, rc_style);
7871 * gtk_widget_modify_font:
7872 * @widget: a #GtkWidget
7873 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7874 * the effect of previous calls to gtk_widget_modify_font().
7876 * Sets the font to use for a widget. All other style values are left
7877 * untouched. See also gtk_widget_modify_style().
7880 gtk_widget_modify_font (GtkWidget *widget,
7881 PangoFontDescription *font_desc)
7883 GtkRcStyle *rc_style;
7885 g_return_if_fail (GTK_IS_WIDGET (widget));
7887 rc_style = gtk_widget_get_modifier_style (widget);
7889 if (rc_style->font_desc)
7890 pango_font_description_free (rc_style->font_desc);
7893 rc_style->font_desc = pango_font_description_copy (font_desc);
7895 rc_style->font_desc = NULL;
7897 gtk_widget_modify_style (widget, rc_style);
7901 gtk_widget_real_direction_changed (GtkWidget *widget,
7902 GtkTextDirection previous_direction)
7904 gtk_widget_queue_resize (widget);
7908 gtk_widget_real_style_set (GtkWidget *widget,
7909 GtkStyle *previous_style)
7911 GtkWidgetPrivate *priv = widget->priv;
7913 if (gtk_widget_get_realized (widget) &&
7914 gtk_widget_get_has_window (widget))
7915 gtk_style_set_background (priv->style, priv->window, priv->state);
7919 gtk_widget_set_style_internal (GtkWidget *widget,
7921 gboolean initial_emission)
7923 GtkWidgetPrivate *priv = widget->priv;
7925 g_object_ref (widget);
7926 g_object_freeze_notify (G_OBJECT (widget));
7928 if (priv->style != style)
7930 GtkStyle *previous_style;
7932 if (gtk_widget_get_realized (widget))
7934 gtk_widget_reset_shapes (widget);
7935 gtk_style_detach (priv->style);
7938 previous_style = priv->style;
7939 priv->style = style;
7940 g_object_ref (priv->style);
7942 if (gtk_widget_get_realized (widget))
7943 priv->style = gtk_style_attach (priv->style, priv->window);
7945 gtk_widget_update_pango_context (widget);
7946 g_signal_emit (widget,
7947 widget_signals[STYLE_SET],
7949 initial_emission ? NULL : previous_style);
7950 g_object_unref (previous_style);
7952 if (priv->anchored && !initial_emission)
7953 gtk_widget_queue_resize (widget);
7955 else if (initial_emission)
7957 gtk_widget_update_pango_context (widget);
7958 g_signal_emit (widget,
7959 widget_signals[STYLE_SET],
7963 g_object_notify (G_OBJECT (widget), "style");
7964 g_object_thaw_notify (G_OBJECT (widget));
7965 g_object_unref (widget);
7969 GtkWidget *previous_toplevel;
7970 GdkScreen *previous_screen;
7971 GdkScreen *new_screen;
7972 } HierarchyChangedInfo;
7975 do_screen_change (GtkWidget *widget,
7976 GdkScreen *old_screen,
7977 GdkScreen *new_screen)
7979 if (old_screen != new_screen)
7983 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7985 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7988 _gtk_tooltip_hide (widget);
7989 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7994 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7995 gpointer client_data)
7997 GtkWidgetPrivate *priv = widget->priv;
7998 HierarchyChangedInfo *info = client_data;
7999 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8000 (priv->parent && priv->parent->priv->anchored);
8002 if (priv->anchored != new_anchored)
8004 g_object_ref (widget);
8006 priv->anchored = new_anchored;
8008 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8009 do_screen_change (widget, info->previous_screen, info->new_screen);
8011 if (GTK_IS_CONTAINER (widget))
8012 gtk_container_forall (GTK_CONTAINER (widget),
8013 gtk_widget_propagate_hierarchy_changed_recurse,
8016 g_object_unref (widget);
8021 * _gtk_widget_propagate_hierarchy_changed:
8022 * @widget: a #GtkWidget
8023 * @previous_toplevel: Previous toplevel
8025 * Propagates changes in the anchored state to a widget and all
8026 * children, unsetting or setting the %ANCHORED flag, and
8027 * emitting #GtkWidget::hierarchy-changed.
8030 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8031 GtkWidget *previous_toplevel)
8033 GtkWidgetPrivate *priv = widget->priv;
8034 HierarchyChangedInfo info;
8036 info.previous_toplevel = previous_toplevel;
8037 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8039 if (gtk_widget_is_toplevel (widget) ||
8040 (priv->parent && priv->parent->priv->anchored))
8041 info.new_screen = gtk_widget_get_screen (widget);
8043 info.new_screen = NULL;
8045 if (info.previous_screen)
8046 g_object_ref (info.previous_screen);
8047 if (previous_toplevel)
8048 g_object_ref (previous_toplevel);
8050 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8052 if (previous_toplevel)
8053 g_object_unref (previous_toplevel);
8054 if (info.previous_screen)
8055 g_object_unref (info.previous_screen);
8059 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8060 gpointer client_data)
8062 HierarchyChangedInfo *info = client_data;
8064 g_object_ref (widget);
8066 do_screen_change (widget, info->previous_screen, info->new_screen);
8068 if (GTK_IS_CONTAINER (widget))
8069 gtk_container_forall (GTK_CONTAINER (widget),
8070 gtk_widget_propagate_screen_changed_recurse,
8073 g_object_unref (widget);
8077 * gtk_widget_is_composited:
8078 * @widget: a #GtkWidget
8080 * Whether @widget can rely on having its alpha channel
8081 * drawn correctly. On X11 this function returns whether a
8082 * compositing manager is running for @widget's screen.
8084 * Please note that the semantics of this call will change
8085 * in the future if used on a widget that has a composited
8086 * window in its hierarchy (as set by gdk_window_set_composited()).
8088 * Return value: %TRUE if the widget can rely on its alpha
8089 * channel being drawn correctly.
8094 gtk_widget_is_composited (GtkWidget *widget)
8098 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8100 screen = gtk_widget_get_screen (widget);
8102 return gdk_screen_is_composited (screen);
8106 propagate_composited_changed (GtkWidget *widget,
8109 if (GTK_IS_CONTAINER (widget))
8111 gtk_container_forall (GTK_CONTAINER (widget),
8112 propagate_composited_changed,
8116 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8120 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8122 propagate_composited_changed (widget, NULL);
8126 * _gtk_widget_propagate_screen_changed:
8127 * @widget: a #GtkWidget
8128 * @previous_screen: Previous screen
8130 * Propagates changes in the screen for a widget to all
8131 * children, emitting #GtkWidget::screen-changed.
8134 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8135 GdkScreen *previous_screen)
8137 HierarchyChangedInfo info;
8139 info.previous_screen = previous_screen;
8140 info.new_screen = gtk_widget_get_screen (widget);
8142 if (previous_screen)
8143 g_object_ref (previous_screen);
8145 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8147 if (previous_screen)
8148 g_object_unref (previous_screen);
8152 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
8154 if (widget->priv->rc_style)
8155 gtk_widget_reset_rc_style (widget);
8157 if (GTK_IS_CONTAINER (widget))
8158 gtk_container_forall (GTK_CONTAINER (widget),
8159 reset_rc_styles_recurse,
8165 * gtk_widget_reset_rc_styles:
8166 * @widget: a #GtkWidget.
8168 * Reset the styles of @widget and all descendents, so when
8169 * they are looked up again, they get the correct values
8170 * for the currently loaded RC file settings.
8172 * This function is not useful for applications.
8175 gtk_widget_reset_rc_styles (GtkWidget *widget)
8177 g_return_if_fail (GTK_IS_WIDGET (widget));
8179 reset_rc_styles_recurse (widget, NULL);
8183 * gtk_widget_get_default_style:
8185 * Returns the default style used by all widgets initially.
8187 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8188 * by GTK+ and should not be modified or freed.
8191 gtk_widget_get_default_style (void)
8193 if (!gtk_default_style)
8195 gtk_default_style = gtk_style_new ();
8196 g_object_ref (gtk_default_style);
8199 return gtk_default_style;
8202 static PangoContext *
8203 gtk_widget_peek_pango_context (GtkWidget *widget)
8205 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8209 * gtk_widget_get_pango_context:
8210 * @widget: a #GtkWidget
8212 * Gets a #PangoContext with the appropriate font map, font description,
8213 * and base direction for this widget. Unlike the context returned
8214 * by gtk_widget_create_pango_context(), this context is owned by
8215 * the widget (it can be used until the screen for the widget changes
8216 * or the widget is removed from its toplevel), and will be updated to
8217 * match any changes to the widget's attributes.
8219 * If you create and keep a #PangoLayout using this context, you must
8220 * deal with changes to the context by calling pango_layout_context_changed()
8221 * on the layout in response to the #GtkWidget::style-set and
8222 * #GtkWidget::direction-changed signals for the widget.
8224 * Return value: (transfer none): the #PangoContext for the widget.
8227 gtk_widget_get_pango_context (GtkWidget *widget)
8229 PangoContext *context;
8231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8233 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8236 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8237 g_object_set_qdata_full (G_OBJECT (widget),
8238 quark_pango_context,
8247 update_pango_context (GtkWidget *widget,
8248 PangoContext *context)
8250 GtkWidgetPrivate *priv = widget->priv;
8252 pango_context_set_font_description (context, priv->style->font_desc);
8253 pango_context_set_base_dir (context,
8254 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8255 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8259 gtk_widget_update_pango_context (GtkWidget *widget)
8261 PangoContext *context = gtk_widget_peek_pango_context (widget);
8267 update_pango_context (widget, context);
8269 screen = gtk_widget_get_screen_unchecked (widget);
8272 pango_cairo_context_set_resolution (context,
8273 gdk_screen_get_resolution (screen));
8274 pango_cairo_context_set_font_options (context,
8275 gdk_screen_get_font_options (screen));
8281 * gtk_widget_create_pango_context:
8282 * @widget: a #GtkWidget
8284 * Creates a new #PangoContext with the appropriate font map,
8285 * font description, and base direction for drawing text for
8286 * this widget. See also gtk_widget_get_pango_context().
8288 * Return value: (transfer full): the new #PangoContext
8291 gtk_widget_create_pango_context (GtkWidget *widget)
8294 PangoContext *context;
8296 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8298 screen = gtk_widget_get_screen_unchecked (widget);
8301 GTK_NOTE (MULTIHEAD,
8302 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8304 screen = gdk_screen_get_default ();
8307 context = gdk_pango_context_get_for_screen (screen);
8309 update_pango_context (widget, context);
8310 pango_context_set_language (context, gtk_get_default_language ());
8316 * gtk_widget_create_pango_layout:
8317 * @widget: a #GtkWidget
8318 * @text: text to set on the layout (can be %NULL)
8320 * Creates a new #PangoLayout with the appropriate font map,
8321 * font description, and base direction for drawing text for
8324 * If you keep a #PangoLayout created in this way around, in order to
8325 * notify the layout of changes to the base direction or font of this
8326 * widget, you must call pango_layout_context_changed() in response to
8327 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8330 * Return value: (transfer full): the new #PangoLayout
8333 gtk_widget_create_pango_layout (GtkWidget *widget,
8336 PangoLayout *layout;
8337 PangoContext *context;
8339 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8341 context = gtk_widget_get_pango_context (widget);
8342 layout = pango_layout_new (context);
8345 pango_layout_set_text (layout, text, -1);
8351 * gtk_widget_render_icon:
8352 * @widget: a #GtkWidget
8353 * @stock_id: a stock ID
8354 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8355 * render at the size of the source and don't scale (if there are
8356 * multiple source sizes, GTK+ picks one of the available sizes).
8357 * @detail: (allow-none): render detail to pass to theme engine
8359 * A convenience function that uses the theme engine and RC file
8360 * settings for @widget to look up @stock_id and render it to
8361 * a pixbuf. @stock_id should be a stock icon ID such as
8362 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8363 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8364 * identifies the widget or code doing the rendering, so that
8365 * theme engines can special-case rendering for that widget or code.
8367 * The pixels in the returned #GdkPixbuf are shared with the rest of
8368 * the application and should not be modified. The pixbuf should be freed
8369 * after use with g_object_unref().
8371 * Return value: (transfer full): a new pixbuf, or %NULL if the
8372 * stock ID wasn't known
8375 gtk_widget_render_icon (GtkWidget *widget,
8376 const gchar *stock_id,
8378 const gchar *detail)
8380 GtkWidgetPrivate *priv;
8381 GtkIconSet *icon_set;
8384 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8385 g_return_val_if_fail (stock_id != NULL, NULL);
8386 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8388 priv = widget->priv;
8390 gtk_widget_ensure_style (widget);
8392 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8394 if (icon_set == NULL)
8397 retval = gtk_icon_set_render_icon (icon_set,
8399 gtk_widget_get_direction (widget),
8400 gtk_widget_get_state (widget),
8409 * gtk_widget_set_parent_window:
8410 * @widget: a #GtkWidget.
8411 * @parent_window: the new parent window.
8413 * Sets a non default parent window for @widget.
8416 gtk_widget_set_parent_window (GtkWidget *widget,
8417 GdkWindow *parent_window)
8419 GdkWindow *old_parent_window;
8421 g_return_if_fail (GTK_IS_WIDGET (widget));
8423 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8424 quark_parent_window);
8426 if (parent_window != old_parent_window)
8428 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8430 if (old_parent_window)
8431 g_object_unref (old_parent_window);
8433 g_object_ref (parent_window);
8438 * gtk_widget_get_parent_window:
8439 * @widget: a #GtkWidget.
8441 * Gets @widget's parent window.
8443 * Returns: (transfer none): the parent window of @widget.
8446 gtk_widget_get_parent_window (GtkWidget *widget)
8448 GtkWidgetPrivate *priv;
8449 GdkWindow *parent_window;
8451 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8453 priv = widget->priv;
8455 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8457 return (parent_window != NULL) ? parent_window :
8458 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8463 * gtk_widget_set_child_visible:
8464 * @widget: a #GtkWidget
8465 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8467 * Sets whether @widget should be mapped along with its when its parent
8468 * is mapped and @widget has been shown with gtk_widget_show().
8470 * The child visibility can be set for widget before it is added to
8471 * a container with gtk_widget_set_parent(), to avoid mapping
8472 * children unnecessary before immediately unmapping them. However
8473 * it will be reset to its default state of %TRUE when the widget
8474 * is removed from a container.
8476 * Note that changing the child visibility of a widget does not
8477 * queue a resize on the widget. Most of the time, the size of
8478 * a widget is computed from all visible children, whether or
8479 * not they are mapped. If this is not the case, the container
8480 * can queue a resize itself.
8482 * This function is only useful for container implementations and
8483 * never should be called by an application.
8486 gtk_widget_set_child_visible (GtkWidget *widget,
8487 gboolean is_visible)
8489 GtkWidgetPrivate *priv;
8491 g_return_if_fail (GTK_IS_WIDGET (widget));
8492 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8494 priv = widget->priv;
8496 g_object_ref (widget);
8499 priv->child_visible = TRUE;
8502 GtkWidget *toplevel;
8504 priv->child_visible = FALSE;
8506 toplevel = gtk_widget_get_toplevel (widget);
8507 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8508 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8511 if (priv->parent && gtk_widget_get_realized (priv->parent))
8513 if (gtk_widget_get_mapped (priv->parent) &&
8514 priv->child_visible &&
8515 gtk_widget_get_visible (widget))
8516 gtk_widget_map (widget);
8518 gtk_widget_unmap (widget);
8521 g_object_unref (widget);
8525 * gtk_widget_get_child_visible:
8526 * @widget: a #GtkWidget
8528 * Gets the value set with gtk_widget_set_child_visible().
8529 * If you feel a need to use this function, your code probably
8530 * needs reorganization.
8532 * This function is only useful for container implementations and
8533 * never should be called by an application.
8535 * Return value: %TRUE if the widget is mapped with the parent.
8538 gtk_widget_get_child_visible (GtkWidget *widget)
8540 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8542 return widget->priv->child_visible;
8546 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8548 GtkWidget *toplevel;
8550 toplevel = gtk_widget_get_toplevel (widget);
8552 if (gtk_widget_is_toplevel (toplevel))
8554 if (GTK_IS_WINDOW (toplevel))
8555 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8556 else if (GTK_IS_INVISIBLE (toplevel))
8557 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8564 * gtk_widget_get_screen:
8565 * @widget: a #GtkWidget
8567 * Get the #GdkScreen from the toplevel window associated with
8568 * this widget. This function can only be called after the widget
8569 * has been added to a widget hierarchy with a #GtkWindow
8572 * In general, you should only create screen specific
8573 * resources when a widget has been realized, and you should
8574 * free those resources when the widget is unrealized.
8576 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8581 gtk_widget_get_screen (GtkWidget *widget)
8585 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8587 screen = gtk_widget_get_screen_unchecked (widget);
8594 g_warning (G_STRLOC ": Can't get associated screen"
8595 " for a widget unless it is inside a toplevel GtkWindow\n"
8596 " widget type is %s associated top level type is %s",
8597 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8598 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8600 return gdk_screen_get_default ();
8605 * gtk_widget_has_screen:
8606 * @widget: a #GtkWidget
8608 * Checks whether there is a #GdkScreen is associated with
8609 * this widget. All toplevel widgets have an associated
8610 * screen, and all widgets added into a hierarchy with a toplevel
8611 * window at the top.
8613 * Return value: %TRUE if there is a #GdkScreen associcated
8619 gtk_widget_has_screen (GtkWidget *widget)
8621 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8623 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8627 * gtk_widget_get_display:
8628 * @widget: a #GtkWidget
8630 * Get the #GdkDisplay for the toplevel window associated with
8631 * this widget. This function can only be called after the widget
8632 * has been added to a widget hierarchy with a #GtkWindow at the top.
8634 * In general, you should only create display specific
8635 * resources when a widget has been realized, and you should
8636 * free those resources when the widget is unrealized.
8638 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8643 gtk_widget_get_display (GtkWidget *widget)
8645 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8647 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8651 * gtk_widget_get_root_window:
8652 * @widget: a #GtkWidget
8654 * Get the root window where this widget is located. This function can
8655 * only be called after the widget has been added to a widget
8656 * hierarchy with #GtkWindow at the top.
8658 * The root window is useful for such purposes as creating a popup
8659 * #GdkWindow associated with the window. In general, you should only
8660 * create display specific resources when a widget has been realized,
8661 * and you should free those resources when the widget is unrealized.
8663 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8668 gtk_widget_get_root_window (GtkWidget *widget)
8670 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8672 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8676 * gtk_widget_child_focus:
8677 * @widget: a #GtkWidget
8678 * @direction: direction of focus movement
8680 * This function is used by custom widget implementations; if you're
8681 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8682 * to a particular widget, and gtk_container_set_focus_chain() to
8683 * change the focus tab order. So you may want to investigate those
8684 * functions instead.
8686 * gtk_widget_child_focus() is called by containers as the user moves
8687 * around the window using keyboard shortcuts. @direction indicates
8688 * what kind of motion is taking place (up, down, left, right, tab
8689 * forward, tab backward). gtk_widget_child_focus() emits the
8690 * #GtkWidget::focus signal; widgets override the default handler
8691 * for this signal in order to implement appropriate focus behavior.
8693 * The default ::focus handler for a widget should return %TRUE if
8694 * moving in @direction left the focus on a focusable location inside
8695 * that widget, and %FALSE if moving in @direction moved the focus
8696 * outside the widget. If returning %TRUE, widgets normally
8697 * call gtk_widget_grab_focus() to place the focus accordingly;
8698 * if returning %FALSE, they don't modify the current focus location.
8700 * Return value: %TRUE if focus ended up inside @widget
8703 gtk_widget_child_focus (GtkWidget *widget,
8704 GtkDirectionType direction)
8706 gboolean return_val;
8708 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8710 if (!gtk_widget_get_visible (widget) ||
8711 !gtk_widget_is_sensitive (widget))
8714 /* child widgets must set CAN_FOCUS, containers
8715 * don't have to though.
8717 if (!GTK_IS_CONTAINER (widget) &&
8718 !gtk_widget_get_can_focus (widget))
8721 g_signal_emit (widget,
8722 widget_signals[FOCUS],
8724 direction, &return_val);
8730 * gtk_widget_keynav_failed:
8731 * @widget: a #GtkWidget
8732 * @direction: direction of focus movement
8734 * This function should be called whenever keyboard navigation within
8735 * a single widget hits a boundary. The function emits the
8736 * #GtkWidget::keynav-failed signal on the widget and its return
8737 * value should be interpreted in a way similar to the return value of
8738 * gtk_widget_child_focus():
8740 * When %TRUE is returned, stay in the widget, the failed keyboard
8741 * navigation is Ok and/or there is nowhere we can/should move the
8744 * When %FALSE is returned, the caller should continue with keyboard
8745 * navigation outside the widget, e.g. by calling
8746 * gtk_widget_child_focus() on the widget's toplevel.
8748 * The default ::keynav-failed handler returns %TRUE for
8749 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8750 * values of #GtkDirectionType, it looks at the
8751 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8752 * if the setting is %TRUE. This way the entire user interface
8753 * becomes cursor-navigatable on input devices such as mobile phones
8754 * which only have cursor keys but no tab key.
8756 * Whenever the default handler returns %TRUE, it also calls
8757 * gtk_widget_error_bell() to notify the user of the failed keyboard
8760 * A use case for providing an own implementation of ::keynav-failed
8761 * (either by connecting to it or by overriding it) would be a row of
8762 * #GtkEntry widgets where the user should be able to navigate the
8763 * entire row with the cursor keys, as e.g. known from user interfaces
8764 * that require entering license keys.
8766 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8767 * if the emitting widget should try to handle the keyboard
8768 * navigation attempt in its parent container(s).
8773 gtk_widget_keynav_failed (GtkWidget *widget,
8774 GtkDirectionType direction)
8776 gboolean return_val;
8778 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8780 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8781 direction, &return_val);
8787 * gtk_widget_error_bell:
8788 * @widget: a #GtkWidget
8790 * Notifies the user about an input-related error on this widget.
8791 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8792 * gdk_window_beep(), otherwise it does nothing.
8794 * Note that the effect of gdk_window_beep() can be configured in many
8795 * ways, depending on the windowing backend and the desktop environment
8796 * or window manager that is used.
8801 gtk_widget_error_bell (GtkWidget *widget)
8803 GtkWidgetPrivate *priv;
8804 GtkSettings* settings;
8807 g_return_if_fail (GTK_IS_WIDGET (widget));
8809 priv = widget->priv;
8811 settings = gtk_widget_get_settings (widget);
8815 g_object_get (settings,
8816 "gtk-error-bell", &beep,
8819 if (beep && priv->window)
8820 gdk_window_beep (priv->window);
8824 gtk_widget_set_usize_internal (GtkWidget *widget,
8827 GtkQueueResizeFlags flags)
8829 GtkWidgetAuxInfo *aux_info;
8830 gboolean changed = FALSE;
8832 g_object_freeze_notify (G_OBJECT (widget));
8834 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8836 if (width > -2 && aux_info->width != width)
8838 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8839 g_object_notify (G_OBJECT (widget), "width-request");
8840 aux_info->width = width;
8843 if (height > -2 && aux_info->height != height)
8845 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8846 g_object_notify (G_OBJECT (widget), "height-request");
8847 aux_info->height = height;
8851 if (gtk_widget_get_visible (widget) && changed)
8853 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8854 gtk_widget_queue_resize (widget);
8856 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8859 g_object_thaw_notify (G_OBJECT (widget));
8863 * gtk_widget_set_size_request:
8864 * @widget: a #GtkWidget
8865 * @width: width @widget should request, or -1 to unset
8866 * @height: height @widget should request, or -1 to unset
8868 * Sets the minimum size of a widget; that is, the widget's size
8869 * request will be @width by @height. You can use this function to
8870 * force a widget to be either larger or smaller than it normally
8873 * In most cases, gtk_window_set_default_size() is a better choice for
8874 * toplevel windows than this function; setting the default size will
8875 * still allow users to shrink the window. Setting the size request
8876 * will force them to leave the window at least as large as the size
8877 * request. When dealing with window sizes,
8878 * gtk_window_set_geometry_hints() can be a useful function as well.
8880 * Note the inherent danger of setting any fixed size - themes,
8881 * translations into other languages, different fonts, and user action
8882 * can all change the appropriate size for a given widget. So, it's
8883 * basically impossible to hardcode a size that will always be
8886 * The size request of a widget is the smallest size a widget can
8887 * accept while still functioning well and drawing itself correctly.
8888 * However in some strange cases a widget may be allocated less than
8889 * its requested size, and in many cases a widget may be allocated more
8890 * space than it requested.
8892 * If the size request in a given direction is -1 (unset), then
8893 * the "natural" size request of the widget will be used instead.
8895 * Widgets can't actually be allocated a size less than 1 by 1, but
8896 * you can pass 0,0 to this function to mean "as small as possible."
8898 * The size request set here does not include any margin from the
8899 * #GtkWidget properties margin-left, margin-right, margin-top, and
8900 * margin-bottom, but it does include pretty much all other padding
8901 * or border properties set by any subclass of #GtkWidget.
8904 gtk_widget_set_size_request (GtkWidget *widget,
8908 g_return_if_fail (GTK_IS_WIDGET (widget));
8909 g_return_if_fail (width >= -1);
8910 g_return_if_fail (height >= -1);
8917 gtk_widget_set_usize_internal (widget, width, height, 0);
8922 * gtk_widget_get_size_request:
8923 * @widget: a #GtkWidget
8924 * @width: (out) (allow-none): return location for width, or %NULL
8925 * @height: (out) (allow-none): return location for height, or %NULL
8927 * Gets the size request that was explicitly set for the widget using
8928 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8929 * @height indicates that that dimension has not been set explicitly
8930 * and the natural requisition of the widget will be used intead. See
8931 * gtk_widget_set_size_request(). To get the size a widget will
8932 * actually request, call gtk_widget_get_preferred_size() instead of
8936 gtk_widget_get_size_request (GtkWidget *widget,
8940 const GtkWidgetAuxInfo *aux_info;
8942 g_return_if_fail (GTK_IS_WIDGET (widget));
8944 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8947 *width = aux_info->width;
8950 *height = aux_info->height;
8954 * _gtk_widget_override_size_request:
8955 * @widget: a #GtkWidget
8956 * @width: new forced minimum width
8957 * @height: new forced minimum height
8958 * @old_width: location to store previous forced minimum width
8959 * @old_width: location to store previous forced minumum height
8961 * Temporarily establishes a forced minimum size for a widget; this
8962 * is used by GtkWindow when calculating the size to add to the
8963 * window's geometry widget. Cached sizes for the widget and its
8964 * parents are invalidated, so that subsequent calls to the size
8965 * negotiation machinery produce the overriden result, but the
8966 * widget is not queued for relayout or redraw. The old size must
8967 * be restored with _gtk_widget_restore_size_request() or things
8971 _gtk_widget_override_size_request (GtkWidget *widget,
8977 gtk_widget_get_size_request (widget, old_width, old_height);
8978 gtk_widget_set_usize_internal (widget, width, height,
8979 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8983 * _gtk_widget_restore_size_request:
8984 * @widget: a #GtkWidget
8985 * @old_width: saved forced minimum size
8986 * @old_height: saved forced minimum size
8988 * Undoes the operation of_gtk_widget_override_size_request().
8991 _gtk_widget_restore_size_request (GtkWidget *widget,
8995 gtk_widget_set_usize_internal (widget, old_width, old_height,
8996 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9000 * gtk_widget_set_events:
9001 * @widget: a #GtkWidget
9002 * @events: event mask
9004 * Sets the event mask (see #GdkEventMask) for a widget. The event
9005 * mask determines which events a widget will receive. Keep in mind
9006 * that different widgets have different default event masks, and by
9007 * changing the event mask you may disrupt a widget's functionality,
9008 * so be careful. This function must be called while a widget is
9009 * unrealized. Consider gtk_widget_add_events() for widgets that are
9010 * already realized, or if you want to preserve the existing event
9011 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9012 * to get events on those widgets, place them inside a #GtkEventBox
9013 * and receive events on the event box.
9016 gtk_widget_set_events (GtkWidget *widget,
9019 g_return_if_fail (GTK_IS_WIDGET (widget));
9020 g_return_if_fail (!gtk_widget_get_realized (widget));
9022 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9023 GINT_TO_POINTER (events));
9024 g_object_notify (G_OBJECT (widget), "events");
9028 * gtk_widget_set_device_events:
9029 * @widget: a #GtkWidget
9030 * @device: a #GdkDevice
9031 * @events: event mask
9033 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9034 * mask determines which events a widget will receive from @device. Keep
9035 * in mind that different widgets have different default event masks, and by
9036 * changing the event mask you may disrupt a widget's functionality,
9037 * so be careful. This function must be called while a widget is
9038 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9039 * already realized, or if you want to preserve the existing event
9040 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9041 * to get events on those widgets, place them inside a #GtkEventBox
9042 * and receive events on the event box.
9047 gtk_widget_set_device_events (GtkWidget *widget,
9049 GdkEventMask events)
9051 GHashTable *device_events;
9053 g_return_if_fail (GTK_IS_WIDGET (widget));
9054 g_return_if_fail (GDK_IS_DEVICE (device));
9055 g_return_if_fail (!gtk_widget_get_realized (widget));
9057 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9059 if (G_UNLIKELY (!device_events))
9061 device_events = g_hash_table_new (NULL, NULL);
9062 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9063 (GDestroyNotify) g_hash_table_unref);
9066 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9070 gtk_widget_add_events_internal_list (GtkWidget *widget,
9077 for (l = window_list; l != NULL; l = l->next)
9079 GdkWindow *window = l->data;
9082 gdk_window_get_user_data (window, &user_data);
9083 if (user_data == widget)
9088 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9090 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9092 children = gdk_window_get_children (window);
9093 gtk_widget_add_events_internal_list (widget, device, events, children);
9094 g_list_free (children);
9100 gtk_widget_add_events_internal (GtkWidget *widget,
9104 GtkWidgetPrivate *priv = widget->priv;
9107 if (!gtk_widget_get_has_window (widget))
9108 window_list = gdk_window_get_children (priv->window);
9110 window_list = g_list_prepend (NULL, priv->window);
9112 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9114 g_list_free (window_list);
9118 * gtk_widget_add_events:
9119 * @widget: a #GtkWidget
9120 * @events: an event mask, see #GdkEventMask
9122 * Adds the events in the bitfield @events to the event mask for
9123 * @widget. See gtk_widget_set_events() for details.
9126 gtk_widget_add_events (GtkWidget *widget,
9131 g_return_if_fail (GTK_IS_WIDGET (widget));
9133 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9134 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9135 GINT_TO_POINTER (old_events | events));
9137 if (gtk_widget_get_realized (widget))
9138 gtk_widget_add_events_internal (widget, NULL, events);
9140 g_object_notify (G_OBJECT (widget), "events");
9144 * gtk_widget_add_device_events:
9145 * @widget: a #GtkWidget
9146 * @device: a #GdkDevice
9147 * @events: an event mask, see #GdkEventMask
9149 * Adds the device events in the bitfield @events to the event mask for
9150 * @widget. See gtk_widget_set_device_events() for details.
9155 gtk_widget_add_device_events (GtkWidget *widget,
9157 GdkEventMask events)
9159 GdkEventMask old_events;
9160 GHashTable *device_events;
9162 g_return_if_fail (GTK_IS_WIDGET (widget));
9163 g_return_if_fail (GDK_IS_DEVICE (device));
9165 old_events = gtk_widget_get_device_events (widget, device);
9167 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9169 if (G_UNLIKELY (!device_events))
9171 device_events = g_hash_table_new (NULL, NULL);
9172 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9173 (GDestroyNotify) g_hash_table_unref);
9176 g_hash_table_insert (device_events, device,
9177 GUINT_TO_POINTER (old_events | events));
9179 if (gtk_widget_get_realized (widget))
9180 gtk_widget_add_events_internal (widget, device, events);
9182 g_object_notify (G_OBJECT (widget), "events");
9186 * gtk_widget_set_extension_events:
9187 * @widget: a #GtkWidget
9188 * @mode: bitfield of extension events to receive
9190 * Sets the extension events mask to @mode. See #GdkExtensionMode
9191 * and gdk_input_set_extension_events().
9194 gtk_widget_set_extension_events (GtkWidget *widget,
9195 GdkExtensionMode mode)
9197 g_return_if_fail (GTK_IS_WIDGET (widget));
9199 if (gtk_widget_get_realized (widget))
9200 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9202 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9203 GINT_TO_POINTER (mode));
9204 g_object_notify (G_OBJECT (widget), "extension-events");
9208 * gtk_widget_get_toplevel:
9209 * @widget: a #GtkWidget
9211 * This function returns the topmost widget in the container hierarchy
9212 * @widget is a part of. If @widget has no parent widgets, it will be
9213 * returned as the topmost widget. No reference will be added to the
9214 * returned widget; it should not be unreferenced.
9216 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9217 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9219 * %NULL if @widget wasn't inside a toplevel window, and if the
9220 * window was inside a #GtkWindow-derived widget which was in turn
9221 * inside the toplevel #GtkWindow. While the second case may
9222 * seem unlikely, it actually happens when a #GtkPlug is embedded
9223 * inside a #GtkSocket within the same application.
9225 * To reliably find the toplevel #GtkWindow, use
9226 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9227 * is set on the result.
9229 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9230 * if (gtk_widget_is_toplevel (toplevel))
9232 * /* Perform action on toplevel. */
9236 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9237 * if there's no ancestor.
9240 gtk_widget_get_toplevel (GtkWidget *widget)
9242 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9244 while (widget->priv->parent)
9245 widget = widget->priv->parent;
9251 * gtk_widget_get_ancestor:
9252 * @widget: a #GtkWidget
9253 * @widget_type: ancestor type
9255 * Gets the first ancestor of @widget with type @widget_type. For example,
9256 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9257 * the first #GtkBox that's an ancestor of @widget. No reference will be
9258 * added to the returned widget; it should not be unreferenced. See note
9259 * about checking for a toplevel #GtkWindow in the docs for
9260 * gtk_widget_get_toplevel().
9262 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9263 * considers @widget to be an ancestor of itself.
9265 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9268 gtk_widget_get_ancestor (GtkWidget *widget,
9271 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9273 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9274 widget = widget->priv->parent;
9276 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9283 * gtk_widget_set_visual:
9284 * @widget: a #GtkWidget
9285 * @visual: visual to be used or %NULL to unset a previous one
9287 * Sets the visual that should be used for by widget and its children for
9288 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9289 * returned by gdk_widget_get_screen(), so handling the
9290 * #GtkWidget::screen-changed signal is necessary.
9292 * Setting a new @visual will not cause @widget to recreate its windows,
9293 * so you should call this function before @widget is realized.
9296 gtk_widget_set_visual (GtkWidget *widget,
9299 g_return_if_fail (GTK_IS_WIDGET (widget));
9300 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9303 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9306 g_object_set_qdata_full (G_OBJECT (widget),
9308 g_object_ref (visual),
9313 * gtk_widget_get_visual:
9314 * @widget: a #GtkWidget
9316 * Gets the visual that will be used to render @widget.
9318 * Return value: (transfer none): the visual for @widget
9321 gtk_widget_get_visual (GtkWidget *widget)
9327 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9329 if (gtk_widget_get_has_window (widget) &&
9330 widget->priv->window)
9331 return gdk_window_get_visual (widget->priv->window);
9333 screen = gtk_widget_get_screen (widget);
9335 for (w = widget; w != NULL; w = w->priv->parent)
9337 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9340 if (gdk_visual_get_screen (visual) == screen)
9343 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9344 gtk_widget_get_name (widget));
9348 return gdk_screen_get_system_visual (screen);
9352 * gtk_widget_get_settings:
9353 * @widget: a #GtkWidget
9355 * Gets the settings object holding the settings (global property
9356 * settings, RC file information, etc) used for this widget.
9358 * Note that this function can only be called when the #GtkWidget
9359 * is attached to a toplevel, since the settings object is specific
9360 * to a particular #GdkScreen.
9362 * Return value: (transfer none): the relevant #GtkSettings object
9365 gtk_widget_get_settings (GtkWidget *widget)
9367 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9369 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9373 * gtk_widget_get_events:
9374 * @widget: a #GtkWidget
9376 * Returns the event mask for the widget (a bitfield containing flags
9377 * from the #GdkEventMask enumeration). These are the events that the widget
9380 * Return value: event mask for @widget
9383 gtk_widget_get_events (GtkWidget *widget)
9385 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9387 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9391 * gtk_widget_get_device_events:
9392 * @widget: a #GtkWidget
9393 * @device: a #GdkDevice
9395 * Returns the events mask for the widget corresponding to an specific device. These
9396 * are the events that the widget will receive when @device operates on it.
9398 * Returns: device event mask for @widget
9403 gtk_widget_get_device_events (GtkWidget *widget,
9406 GHashTable *device_events;
9408 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9409 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9411 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9416 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9420 * gtk_widget_get_extension_events:
9421 * @widget: a #GtkWidget
9423 * Retrieves the extension events the widget will receive; see
9424 * gdk_input_set_extension_events().
9426 * Return value: extension events for @widget
9429 gtk_widget_get_extension_events (GtkWidget *widget)
9431 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9433 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9437 * gtk_widget_get_pointer:
9438 * @widget: a #GtkWidget
9439 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9440 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9442 * Obtains the location of the mouse pointer in widget coordinates.
9443 * Widget coordinates are a bit odd; for historical reasons, they are
9444 * defined as @widget->window coordinates for widgets that are not
9445 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9446 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9449 gtk_widget_get_pointer (GtkWidget *widget,
9453 GtkWidgetPrivate *priv;
9455 g_return_if_fail (GTK_IS_WIDGET (widget));
9457 priv = widget->priv;
9464 if (gtk_widget_get_realized (widget))
9466 gdk_window_get_pointer (priv->window, x, y, NULL);
9468 if (!gtk_widget_get_has_window (widget))
9471 *x -= priv->allocation.x;
9473 *y -= priv->allocation.y;
9479 * gtk_widget_is_ancestor:
9480 * @widget: a #GtkWidget
9481 * @ancestor: another #GtkWidget
9483 * Determines whether @widget is somewhere inside @ancestor, possibly with
9484 * intermediate containers.
9486 * Return value: %TRUE if @ancestor contains @widget as a child,
9487 * grandchild, great grandchild, etc.
9490 gtk_widget_is_ancestor (GtkWidget *widget,
9491 GtkWidget *ancestor)
9493 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9494 g_return_val_if_fail (ancestor != NULL, FALSE);
9498 if (widget->priv->parent == ancestor)
9500 widget = widget->priv->parent;
9506 static GQuark quark_composite_name = 0;
9509 * gtk_widget_set_composite_name:
9510 * @widget: a #GtkWidget.
9511 * @name: the name to set
9513 * Sets a widgets composite name. The widget must be
9514 * a composite child of its parent; see gtk_widget_push_composite_child().
9517 gtk_widget_set_composite_name (GtkWidget *widget,
9520 g_return_if_fail (GTK_IS_WIDGET (widget));
9521 g_return_if_fail (widget->priv->composite_child);
9522 g_return_if_fail (name != NULL);
9524 if (!quark_composite_name)
9525 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9527 g_object_set_qdata_full (G_OBJECT (widget),
9528 quark_composite_name,
9534 * gtk_widget_get_composite_name:
9535 * @widget: a #GtkWidget
9537 * Obtains the composite name of a widget.
9539 * Returns: the composite name of @widget, or %NULL if @widget is not
9540 * a composite child. The string should be freed when it is no
9544 gtk_widget_get_composite_name (GtkWidget *widget)
9546 GtkWidgetPrivate *priv;
9548 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9550 priv = widget->priv;
9552 if (widget->priv->composite_child && priv->parent)
9553 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9560 * gtk_widget_push_composite_child:
9562 * Makes all newly-created widgets as composite children until
9563 * the corresponding gtk_widget_pop_composite_child() call.
9565 * A composite child is a child that's an implementation detail of the
9566 * container it's inside and should not be visible to people using the
9567 * container. Composite children aren't treated differently by GTK (but
9568 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9569 * builders might want to treat them in a different way.
9571 * Here is a simple example:
9573 * gtk_widget_push_composite_child ();
9574 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
9575 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9576 * gtk_widget_pop_composite_child ();
9577 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9578 * GTK_WIDGET (scrolled_window));
9579 * g_object_ref (scrolled_window->hscrollbar);
9583 gtk_widget_push_composite_child (void)
9585 composite_child_stack++;
9589 * gtk_widget_pop_composite_child:
9591 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9594 gtk_widget_pop_composite_child (void)
9596 if (composite_child_stack)
9597 composite_child_stack--;
9601 gtk_widget_emit_direction_changed (GtkWidget *widget,
9602 GtkTextDirection old_dir)
9604 gtk_widget_update_pango_context (widget);
9606 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9610 * gtk_widget_set_direction:
9611 * @widget: a #GtkWidget
9612 * @dir: the new direction
9614 * Sets the reading direction on a particular widget. This direction
9615 * controls the primary direction for widgets containing text,
9616 * and also the direction in which the children of a container are
9617 * packed. The ability to set the direction is present in order
9618 * so that correct localization into languages with right-to-left
9619 * reading directions can be done. Generally, applications will
9620 * let the default reading direction present, except for containers
9621 * where the containers are arranged in an order that is explicitely
9622 * visual rather than logical (such as buttons for text justification).
9624 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9625 * set by gtk_widget_set_default_direction() will be used.
9628 gtk_widget_set_direction (GtkWidget *widget,
9629 GtkTextDirection dir)
9631 GtkTextDirection old_dir;
9633 g_return_if_fail (GTK_IS_WIDGET (widget));
9634 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9636 old_dir = gtk_widget_get_direction (widget);
9638 widget->priv->direction = dir;
9640 if (old_dir != gtk_widget_get_direction (widget))
9641 gtk_widget_emit_direction_changed (widget, old_dir);
9645 * gtk_widget_get_direction:
9646 * @widget: a #GtkWidget
9648 * Gets the reading direction for a particular widget. See
9649 * gtk_widget_set_direction().
9651 * Return value: the reading direction for the widget.
9654 gtk_widget_get_direction (GtkWidget *widget)
9656 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9658 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9659 return gtk_default_direction;
9661 return widget->priv->direction;
9665 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9667 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9669 g_object_ref (widget);
9671 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9672 gtk_widget_emit_direction_changed (widget, old_dir);
9674 if (GTK_IS_CONTAINER (widget))
9675 gtk_container_forall (GTK_CONTAINER (widget),
9676 gtk_widget_set_default_direction_recurse,
9679 g_object_unref (widget);
9683 * gtk_widget_set_default_direction:
9684 * @dir: the new default direction. This cannot be
9685 * %GTK_TEXT_DIR_NONE.
9687 * Sets the default reading direction for widgets where the
9688 * direction has not been explicitly set by gtk_widget_set_direction().
9691 gtk_widget_set_default_direction (GtkTextDirection dir)
9693 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9695 if (dir != gtk_default_direction)
9697 GList *toplevels, *tmp_list;
9698 GtkTextDirection old_dir = gtk_default_direction;
9700 gtk_default_direction = dir;
9702 tmp_list = toplevels = gtk_window_list_toplevels ();
9703 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9707 gtk_widget_set_default_direction_recurse (tmp_list->data,
9708 GUINT_TO_POINTER (old_dir));
9709 g_object_unref (tmp_list->data);
9710 tmp_list = tmp_list->next;
9713 g_list_free (toplevels);
9718 * gtk_widget_get_default_direction:
9720 * Obtains the current default reading direction. See
9721 * gtk_widget_set_default_direction().
9723 * Return value: the current default direction.
9726 gtk_widget_get_default_direction (void)
9728 return gtk_default_direction;
9732 gtk_widget_dispose (GObject *object)
9734 GtkWidget *widget = GTK_WIDGET (object);
9735 GtkWidgetPrivate *priv = widget->priv;
9738 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9739 else if (gtk_widget_get_visible (widget))
9740 gtk_widget_hide (widget);
9742 priv->visible = FALSE;
9743 if (gtk_widget_get_realized (widget))
9744 gtk_widget_unrealize (widget);
9746 if (!priv->in_destruction)
9748 priv->in_destruction = TRUE;
9749 g_signal_emit (object, widget_signals[DESTROY], 0);
9750 priv->in_destruction = FALSE;
9753 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9757 gtk_widget_real_destroy (GtkWidget *object)
9759 /* gtk_object_destroy() will already hold a refcount on object */
9760 GtkWidget *widget = GTK_WIDGET (object);
9761 GtkWidgetPrivate *priv = widget->priv;
9763 /* wipe accelerator closures (keep order) */
9764 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9765 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9767 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9768 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9770 gtk_grab_remove (widget);
9772 g_object_unref (priv->style);
9773 priv->style = gtk_widget_get_default_style ();
9774 g_object_ref (priv->style);
9778 gtk_widget_finalize (GObject *object)
9780 GtkWidget *widget = GTK_WIDGET (object);
9781 GtkWidgetPrivate *priv = widget->priv;
9782 GtkWidgetAuxInfo *aux_info;
9783 GtkAccessible *accessible;
9785 gtk_grab_remove (widget);
9787 g_object_unref (priv->style);
9790 g_free (priv->name);
9792 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9794 gtk_widget_aux_info_destroy (aux_info);
9796 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9798 g_object_unref (accessible);
9800 if (g_object_is_floating (object))
9801 g_warning ("A floating object was finalized. This means that someone\n"
9802 "called g_object_unref() on an object that had only a floating\n"
9803 "reference; the initial floating reference is not owned by anyone\n"
9804 "and must be removed with g_object_ref_sink().");
9806 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9809 /*****************************************
9810 * gtk_widget_real_map:
9815 *****************************************/
9818 gtk_widget_real_map (GtkWidget *widget)
9820 GtkWidgetPrivate *priv = widget->priv;
9822 g_assert (gtk_widget_get_realized (widget));
9824 if (!gtk_widget_get_mapped (widget))
9826 gtk_widget_set_mapped (widget, TRUE);
9828 if (gtk_widget_get_has_window (widget))
9829 gdk_window_show (priv->window);
9833 /*****************************************
9834 * gtk_widget_real_unmap:
9839 *****************************************/
9842 gtk_widget_real_unmap (GtkWidget *widget)
9844 GtkWidgetPrivate *priv = widget->priv;
9846 if (gtk_widget_get_mapped (widget))
9848 gtk_widget_set_mapped (widget, FALSE);
9850 if (gtk_widget_get_has_window (widget))
9851 gdk_window_hide (priv->window);
9855 /*****************************************
9856 * gtk_widget_real_realize:
9861 *****************************************/
9864 gtk_widget_real_realize (GtkWidget *widget)
9866 GtkWidgetPrivate *priv = widget->priv;
9868 g_assert (!gtk_widget_get_has_window (widget));
9870 gtk_widget_set_realized (widget, TRUE);
9873 priv->window = gtk_widget_get_parent_window (widget);
9874 g_object_ref (priv->window);
9876 priv->style = gtk_style_attach (priv->style, priv->window);
9879 /*****************************************
9880 * gtk_widget_real_unrealize:
9885 *****************************************/
9888 gtk_widget_real_unrealize (GtkWidget *widget)
9890 GtkWidgetPrivate *priv = widget->priv;
9892 if (gtk_widget_get_mapped (widget))
9893 gtk_widget_real_unmap (widget);
9895 gtk_widget_set_mapped (widget, FALSE);
9897 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9900 /* We must do unrealize child widget BEFORE container widget.
9901 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9902 * So, unrealizing container widget bofore its children causes the problem
9903 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9906 if (GTK_IS_CONTAINER (widget))
9907 gtk_container_forall (GTK_CONTAINER (widget),
9908 (GtkCallback) gtk_widget_unrealize,
9911 gtk_style_detach (priv->style);
9912 if (gtk_widget_get_has_window (widget))
9914 gdk_window_set_user_data (priv->window, NULL);
9915 gdk_window_destroy (priv->window);
9916 priv->window = NULL;
9920 g_object_unref (priv->window);
9921 priv->window = NULL;
9924 gtk_selection_remove_all (widget);
9926 gtk_widget_set_realized (widget, FALSE);
9930 gtk_widget_real_size_request (GtkWidget *widget,
9931 GtkRequisition *requisition)
9933 requisition->width = 0;
9934 requisition->height = 0;
9938 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9939 GtkOrientation orientation,
9943 const GtkWidgetAuxInfo *aux_info;
9945 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9947 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9948 aux_info->width > 0)
9950 *minimum_size = MAX (*minimum_size, aux_info->width);
9952 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9953 aux_info->height > 0)
9955 *minimum_size = MAX (*minimum_size, aux_info->height);
9958 /* Fix it if set_size_request made natural size smaller than min size.
9959 * This would also silently fix broken widgets, but we warn about them
9960 * in gtksizerequest.c when calling their size request vfuncs.
9962 *natural_size = MAX (*natural_size, *minimum_size);
9964 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9966 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9967 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9971 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9972 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9977 * _gtk_widget_peek_request_cache:
9979 * Returns the address of the widget's request cache (strictly for
9980 * internal use in gtksizerequest.c)
9982 * Return value: the address of @widget's size request cache.
9985 _gtk_widget_peek_request_cache (GtkWidget *widget)
9987 /* Don't bother slowing things down with the return_if_fail guards here */
9988 return &widget->priv->requests;
9992 * _gtk_widget_set_device_window:
9993 * @widget: a #GtkWidget.
9994 * @device: a #GdkDevice.
9995 * @window: the new device window.
9997 * Sets pointer window for @widget and @device. Does not ref @window.
9998 * Actually stores it on the #GdkScreen, but you don't need to know that.
10001 _gtk_widget_set_device_window (GtkWidget *widget,
10005 GtkWidgetPrivate *priv;
10007 GHashTable *device_window;
10009 g_return_if_fail (GTK_IS_WIDGET (widget));
10010 g_return_if_fail (GDK_IS_DEVICE (device));
10011 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10013 priv = widget->priv;
10015 if (!gtk_widget_get_realized (widget))
10018 screen = gdk_window_get_screen (priv->window);
10019 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10021 if (G_UNLIKELY (!device_window))
10023 device_window = g_hash_table_new (NULL, NULL);
10024 g_object_set_qdata_full (G_OBJECT (screen),
10025 quark_pointer_window,
10027 (GDestroyNotify) g_hash_table_destroy);
10031 g_hash_table_insert (device_window, device, window);
10033 g_hash_table_remove (device_window, device);
10037 * _gtk_widget_get_device_window:
10038 * @widget: a #GtkWidget.
10039 * @device: a #GdkDevice.
10041 * Return value: the device window set on the #GdkScreen @widget is attached
10045 _gtk_widget_get_device_window (GtkWidget *widget,
10048 GtkWidgetPrivate *priv;
10050 GHashTable *device_window;
10054 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10055 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10057 priv = widget->priv;
10059 if (!gtk_widget_get_realized (widget))
10062 screen = gdk_window_get_screen (priv->window);
10063 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10065 if (G_UNLIKELY (!device_window))
10068 window = g_hash_table_lookup (device_window, device);
10073 gdk_window_get_user_data (window, (gpointer *) &w);
10082 * _gtk_widget_list_devices:
10083 * @widget: a #GtkWidget.
10085 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10086 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10090 _gtk_widget_list_devices (GtkWidget *widget)
10092 GtkWidgetPrivate *priv;
10094 GHashTableIter iter;
10095 GHashTable *device_window;
10096 GList *devices = NULL;
10097 gpointer key, value;
10099 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10101 priv = widget->priv;
10103 if (!gtk_widget_get_realized (widget))
10106 screen = gdk_window_get_screen (priv->window);
10107 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10109 if (G_UNLIKELY (!device_window))
10112 g_hash_table_iter_init (&iter, device_window);
10114 while (g_hash_table_iter_next (&iter, &key, &value))
10116 GdkDevice *device = key;
10117 GdkWindow *window = value;
10122 gdk_window_get_user_data (window, (gpointer *) &w);
10125 devices = g_list_prepend (devices, device);
10133 synth_crossing (GtkWidget *widget,
10137 GdkCrossingMode mode,
10138 GdkNotifyType detail)
10142 event = gdk_event_new (type);
10144 event->crossing.window = g_object_ref (window);
10145 event->crossing.send_event = TRUE;
10146 event->crossing.subwindow = g_object_ref (window);
10147 event->crossing.time = GDK_CURRENT_TIME;
10148 event->crossing.x = event->crossing.y = 0;
10149 event->crossing.x_root = event->crossing.y_root = 0;
10150 event->crossing.mode = mode;
10151 event->crossing.detail = detail;
10152 event->crossing.focus = FALSE;
10153 event->crossing.state = 0;
10154 gdk_event_set_device (event, device);
10157 widget = gtk_get_event_widget (event);
10160 gtk_widget_event_internal (widget, event);
10162 gdk_event_free (event);
10166 * _gtk_widget_synthesize_crossing:
10167 * @from: the #GtkWidget the virtual pointer is leaving.
10168 * @to: the #GtkWidget the virtual pointer is moving to.
10169 * @mode: the #GdkCrossingMode to place on the synthesized events.
10171 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10173 * The real pointer window is the window that most recently received an enter notify
10174 * event. Windows that don't select for crossing events can't become the real
10175 * poiner window. The real pointer widget that owns the real pointer window. The
10176 * effective pointer window is the same as the real pointer window unless the real
10177 * pointer widget is either insensitive or there is a grab on a widget that is not
10178 * an ancestor of the real pointer widget (in which case the effective pointer
10179 * window should be the root window).
10181 * When the effective pointer window is the same as the real poiner window, we
10182 * receive crossing events from the windowing system. When the effective pointer
10183 * window changes to become different from the real pointer window we synthesize
10184 * crossing events, attempting to follow X protocol rules:
10186 * When the root window becomes the effective pointer window:
10187 * - leave notify on real pointer window, detail Ancestor
10188 * - leave notify on all of its ancestors, detail Virtual
10189 * - enter notify on root window, detail Inferior
10191 * When the root window ceases to be the effective pointer window:
10192 * - leave notify on root window, detail Inferior
10193 * - enter notify on all ancestors of real pointer window, detail Virtual
10194 * - enter notify on real pointer window, detail Ancestor
10197 _gtk_widget_synthesize_crossing (GtkWidget *from,
10200 GdkCrossingMode mode)
10202 GdkWindow *from_window = NULL, *to_window = NULL;
10204 g_return_if_fail (from != NULL || to != NULL);
10208 from_window = _gtk_widget_get_device_window (from, device);
10211 from_window = from->priv->window;
10216 to_window = _gtk_widget_get_device_window (to, device);
10219 to_window = to->priv->window;
10222 if (from_window == NULL && to_window == NULL)
10224 else if (from_window != NULL && to_window == NULL)
10226 GList *from_ancestors = NULL, *list;
10227 GdkWindow *from_ancestor = from_window;
10229 while (from_ancestor != NULL)
10231 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10232 if (from_ancestor == NULL)
10234 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10237 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10238 device, mode, GDK_NOTIFY_ANCESTOR);
10239 for (list = g_list_last (from_ancestors); list; list = list->prev)
10241 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10242 device, mode, GDK_NOTIFY_VIRTUAL);
10245 /* XXX: enter/inferior on root window? */
10247 g_list_free (from_ancestors);
10249 else if (from_window == NULL && to_window != NULL)
10251 GList *to_ancestors = NULL, *list;
10252 GdkWindow *to_ancestor = to_window;
10254 while (to_ancestor != NULL)
10256 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10257 if (to_ancestor == NULL)
10259 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10262 /* XXX: leave/inferior on root window? */
10264 for (list = to_ancestors; list; list = list->next)
10266 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10267 device, mode, GDK_NOTIFY_VIRTUAL);
10269 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10270 device, mode, GDK_NOTIFY_ANCESTOR);
10272 g_list_free (to_ancestors);
10274 else if (from_window == to_window)
10278 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10279 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10281 while (from_ancestor != NULL || to_ancestor != NULL)
10283 if (from_ancestor != NULL)
10285 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10286 if (from_ancestor == to_window)
10289 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10291 if (to_ancestor != NULL)
10293 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10294 if (to_ancestor == from_window)
10297 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10300 if (to_ancestor == from_window)
10302 if (mode != GDK_CROSSING_GTK_UNGRAB)
10303 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10304 device, mode, GDK_NOTIFY_INFERIOR);
10305 for (list = to_ancestors; list; list = list->next)
10306 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10307 device, mode, GDK_NOTIFY_VIRTUAL);
10308 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10309 device, mode, GDK_NOTIFY_ANCESTOR);
10311 else if (from_ancestor == to_window)
10313 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10314 device, mode, GDK_NOTIFY_ANCESTOR);
10315 for (list = g_list_last (from_ancestors); list; list = list->prev)
10317 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10318 device, mode, GDK_NOTIFY_VIRTUAL);
10320 if (mode != GDK_CROSSING_GTK_GRAB)
10321 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10322 device, mode, GDK_NOTIFY_INFERIOR);
10326 while (from_ancestors != NULL && to_ancestors != NULL
10327 && from_ancestors->data == to_ancestors->data)
10329 from_ancestors = g_list_delete_link (from_ancestors,
10331 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10334 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10335 device, mode, GDK_NOTIFY_NONLINEAR);
10337 for (list = g_list_last (from_ancestors); list; list = list->prev)
10339 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10340 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10342 for (list = to_ancestors; list; list = list->next)
10344 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10345 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10347 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10348 device, mode, GDK_NOTIFY_NONLINEAR);
10350 g_list_free (from_ancestors);
10351 g_list_free (to_ancestors);
10356 gtk_widget_propagate_state (GtkWidget *widget,
10357 GtkStateData *data)
10359 GtkWidgetPrivate *priv = widget->priv;
10360 guint8 old_state = gtk_widget_get_state (widget);
10361 guint8 old_saved_state = priv->saved_state;
10363 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10364 * parent_sensitive==TRUE on a sensitive widget
10368 priv->parent_sensitive = data->parent_sensitive;
10370 if (gtk_widget_is_sensitive (widget))
10372 if (data->state_restoration)
10373 priv->state = priv->saved_state;
10375 priv->state = data->state;
10379 if (!data->state_restoration)
10381 if (data->state != GTK_STATE_INSENSITIVE)
10382 priv->saved_state = data->state;
10384 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10385 priv->saved_state = gtk_widget_get_state (widget);
10386 priv->state = GTK_STATE_INSENSITIVE;
10389 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10393 window = gtk_widget_get_toplevel (widget);
10394 if (window && gtk_widget_is_toplevel (window))
10395 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10398 if (old_state != gtk_widget_get_state (widget) ||
10399 old_saved_state != priv->saved_state)
10401 g_object_ref (widget);
10403 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10404 gtk_grab_remove (widget);
10406 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10408 if (!priv->shadowed)
10410 GList *event_windows = NULL;
10411 GList *devices, *d;
10413 devices = _gtk_widget_list_devices (widget);
10415 for (d = devices; d; d = d->next)
10421 window = _gtk_widget_get_device_window (widget, device);
10423 /* Do not propagate more than once to the
10424 * same window if non-multidevice aware.
10426 if (!gdk_window_get_support_multidevice (window) &&
10427 g_list_find (event_windows, window))
10430 if (!gtk_widget_is_sensitive (widget))
10431 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10432 GDK_CROSSING_STATE_CHANGED);
10433 else if (old_state == GTK_STATE_INSENSITIVE)
10434 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10435 GDK_CROSSING_STATE_CHANGED);
10437 event_windows = g_list_prepend (event_windows, window);
10440 g_list_free (event_windows);
10441 g_list_free (devices);
10444 if (GTK_IS_CONTAINER (widget))
10446 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10447 if (data->use_forall)
10448 gtk_container_forall (GTK_CONTAINER (widget),
10449 (GtkCallback) gtk_widget_propagate_state,
10452 gtk_container_foreach (GTK_CONTAINER (widget),
10453 (GtkCallback) gtk_widget_propagate_state,
10456 g_object_unref (widget);
10460 static const GtkWidgetAuxInfo default_aux_info = {
10468 * _gtk_widget_get_aux_info:
10469 * @widget: a #GtkWidget
10470 * @create: if %TRUE, create the structure if it doesn't exist
10472 * Get the #GtkWidgetAuxInfo structure for the widget.
10474 * Return value: the #GtkAuxInfo structure for the widget, or
10475 * %NULL if @create is %FALSE and one doesn't already exist.
10478 _gtk_widget_get_aux_info (GtkWidget *widget,
10481 GtkWidgetAuxInfo *aux_info;
10483 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10484 if (!aux_info && create)
10486 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10488 *aux_info = default_aux_info;
10490 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10496 static const GtkWidgetAuxInfo*
10497 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10499 GtkWidgetAuxInfo *aux_info;
10501 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10502 if (aux_info == NULL)
10504 return &default_aux_info;
10512 /*****************************************
10513 * gtk_widget_aux_info_destroy:
10518 *****************************************/
10521 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10523 g_slice_free (GtkWidgetAuxInfo, aux_info);
10527 * gtk_widget_shape_combine_region:
10528 * @widget: a #GtkWidget
10529 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10531 * Sets a shape for this widget's GDK window. This allows for
10532 * transparent windows etc., see gdk_window_shape_combine_region()
10533 * for more information.
10538 gtk_widget_shape_combine_region (GtkWidget *widget,
10539 cairo_region_t *region)
10541 GtkWidgetPrivate *priv;
10543 g_return_if_fail (GTK_IS_WIDGET (widget));
10544 /* set_shape doesn't work on widgets without gdk window */
10545 g_return_if_fail (gtk_widget_get_has_window (widget));
10547 priv = widget->priv;
10549 if (region == NULL)
10551 priv->has_shape_mask = FALSE;
10554 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10556 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10560 priv->has_shape_mask = TRUE;
10562 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10563 cairo_region_copy (region),
10564 (GDestroyNotify) cairo_region_destroy);
10566 /* set shape if widget has a gdk window already.
10567 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10570 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10575 * gtk_widget_input_shape_combine_region:
10576 * @widget: a #GtkWidget
10577 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10579 * Sets an input shape for this widget's GDK window. This allows for
10580 * windows which react to mouse click in a nonrectangular region, see
10581 * gdk_window_input_shape_combine_region() for more information.
10586 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10587 cairo_region_t *region)
10589 GtkWidgetPrivate *priv;
10591 g_return_if_fail (GTK_IS_WIDGET (widget));
10592 /* set_shape doesn't work on widgets without gdk window */
10593 g_return_if_fail (gtk_widget_get_has_window (widget));
10595 priv = widget->priv;
10597 if (region == NULL)
10600 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10602 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10606 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10607 cairo_region_copy (region),
10608 (GDestroyNotify) cairo_region_destroy);
10610 /* set shape if widget has a gdk window already.
10611 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10614 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10620 gtk_reset_shapes_recurse (GtkWidget *widget,
10626 gdk_window_get_user_data (window, &data);
10627 if (data != widget)
10630 gdk_window_shape_combine_region (window, NULL, 0, 0);
10631 for (list = gdk_window_peek_children (window); list; list = list->next)
10632 gtk_reset_shapes_recurse (widget, list->data);
10636 * gtk_widget_reset_shapes:
10637 * @widget: a #GtkWidget
10639 * Recursively resets the shape on this widget and its descendants.
10642 gtk_widget_reset_shapes (GtkWidget *widget)
10644 GtkWidgetPrivate *priv;
10646 g_return_if_fail (GTK_IS_WIDGET (widget));
10647 g_return_if_fail (gtk_widget_get_realized (widget));
10649 priv = widget->priv;
10651 if (!priv->has_shape_mask)
10652 gtk_reset_shapes_recurse (widget, priv->window);
10655 /* style properties
10659 * gtk_widget_class_install_style_property_parser:
10660 * @klass: a #GtkWidgetClass
10661 * @pspec: the #GParamSpec for the style property
10662 * @parser: the parser for the style property
10664 * Installs a style property on a widget class.
10667 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10669 GtkRcPropertyParser parser)
10671 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10672 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10673 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10674 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10676 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10678 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10679 G_OBJECT_CLASS_NAME (klass),
10684 g_param_spec_ref_sink (pspec);
10685 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10686 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10690 * gtk_widget_class_install_style_property:
10691 * @klass: a #GtkWidgetClass
10692 * @pspec: the #GParamSpec for the property
10694 * Installs a style property on a widget class. The parser for the
10695 * style property is determined by the value type of @pspec.
10698 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10701 GtkRcPropertyParser parser;
10703 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10704 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10706 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10708 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10712 * gtk_widget_class_find_style_property:
10713 * @klass: a #GtkWidgetClass
10714 * @property_name: the name of the style property to find
10715 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10716 * style property with that name.
10718 * Finds a style property of a widget class by name.
10723 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10724 const gchar *property_name)
10726 g_return_val_if_fail (property_name != NULL, NULL);
10728 return g_param_spec_pool_lookup (style_property_spec_pool,
10730 G_OBJECT_CLASS_TYPE (klass),
10735 * gtk_widget_class_list_style_properties:
10736 * @klass: a #GtkWidgetClass
10737 * @n_properties: location to return the number of style properties found
10738 * @returns: an newly allocated array of #GParamSpec*. The array must
10739 * be freed with g_free().
10741 * Returns all style properties of a widget class.
10746 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10747 guint *n_properties)
10749 GParamSpec **pspecs;
10752 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10753 G_OBJECT_CLASS_TYPE (klass),
10762 * gtk_widget_style_get_property:
10763 * @widget: a #GtkWidget
10764 * @property_name: the name of a style property
10765 * @value: location to return the property value
10767 * Gets the value of a style property of @widget.
10770 gtk_widget_style_get_property (GtkWidget *widget,
10771 const gchar *property_name,
10774 GtkWidgetPrivate *priv;
10777 g_return_if_fail (GTK_IS_WIDGET (widget));
10778 g_return_if_fail (property_name != NULL);
10779 g_return_if_fail (G_IS_VALUE (value));
10781 priv = widget->priv;
10783 g_object_ref (widget);
10784 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10786 G_OBJECT_TYPE (widget),
10789 g_warning ("%s: widget class `%s' has no property named `%s'",
10791 G_OBJECT_TYPE_NAME (widget),
10795 const GValue *peek_value;
10797 peek_value = _gtk_style_peek_property_value (priv->style,
10798 G_OBJECT_TYPE (widget),
10800 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10802 /* auto-conversion of the caller's value type
10804 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10805 g_value_copy (peek_value, value);
10806 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10807 g_value_transform (peek_value, value);
10809 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10811 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10812 G_VALUE_TYPE_NAME (value));
10814 g_object_unref (widget);
10818 * gtk_widget_style_get_valist:
10819 * @widget: a #GtkWidget
10820 * @first_property_name: the name of the first property to get
10821 * @var_args: a <type>va_list</type> of pairs of property names and
10822 * locations to return the property values, starting with the location
10823 * for @first_property_name.
10825 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10829 gtk_widget_style_get_valist (GtkWidget *widget,
10830 const gchar *first_property_name,
10833 GtkWidgetPrivate *priv;
10836 g_return_if_fail (GTK_IS_WIDGET (widget));
10838 priv = widget->priv;
10840 g_object_ref (widget);
10842 name = first_property_name;
10845 const GValue *peek_value;
10849 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10851 G_OBJECT_TYPE (widget),
10855 g_warning ("%s: widget class `%s' has no property named `%s'",
10857 G_OBJECT_TYPE_NAME (widget),
10861 /* style pspecs are always readable so we can spare that check here */
10863 peek_value = _gtk_style_peek_property_value (priv->style,
10864 G_OBJECT_TYPE (widget),
10866 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10867 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10870 g_warning ("%s: %s", G_STRLOC, error);
10875 name = va_arg (var_args, gchar*);
10878 g_object_unref (widget);
10882 * gtk_widget_style_get:
10883 * @widget: a #GtkWidget
10884 * @first_property_name: the name of the first property to get
10885 * @Varargs: pairs of property names and locations to
10886 * return the property values, starting with the location for
10887 * @first_property_name, terminated by %NULL.
10889 * Gets the values of a multiple style properties of @widget.
10892 gtk_widget_style_get (GtkWidget *widget,
10893 const gchar *first_property_name,
10898 g_return_if_fail (GTK_IS_WIDGET (widget));
10900 va_start (var_args, first_property_name);
10901 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10907 * @widget: a #GtkWidget
10908 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10909 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10910 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10912 * Obtains the full path to @widget. The path is simply the name of a
10913 * widget and all its parents in the container hierarchy, separated by
10914 * periods. The name of a widget comes from
10915 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10916 * in gtkrc configuration files. Widget names are the type of the
10917 * widget by default (e.g. "GtkButton") or can be set to an
10918 * application-specific value with gtk_widget_set_name(). By setting
10919 * the name of a widget, you allow users or theme authors to apply
10920 * styles to that specific widget in their gtkrc
10921 * file. @path_reversed_p fills in the path in reverse order,
10922 * i.e. starting with @widget's name instead of starting with the name
10923 * of @widget's outermost ancestor.
10926 gtk_widget_path (GtkWidget *widget,
10927 guint *path_length,
10929 gchar **path_reversed)
10931 static gchar *rev_path = NULL;
10932 static guint tmp_path_len = 0;
10935 g_return_if_fail (GTK_IS_WIDGET (widget));
10940 const gchar *string;
10945 string = gtk_widget_get_name (widget);
10946 l = strlen (string);
10947 while (tmp_path_len <= len + l + 1)
10949 tmp_path_len += INIT_PATH_SIZE;
10950 rev_path = g_realloc (rev_path, tmp_path_len);
10952 s = string + l - 1;
10953 d = rev_path + len;
10954 while (s >= string)
10958 widget = widget->priv->parent;
10961 rev_path[len++] = '.';
10963 rev_path[len++] = 0;
10968 *path_length = len - 1;
10970 *path_reversed = g_strdup (rev_path);
10973 *path = g_strdup (rev_path);
10974 g_strreverse (*path);
10979 * gtk_widget_class_path:
10980 * @widget: a #GtkWidget
10981 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10982 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10983 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10986 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10987 * never uses a custom name set with gtk_widget_set_name().
10991 gtk_widget_class_path (GtkWidget *widget,
10992 guint *path_length,
10994 gchar **path_reversed)
10996 static gchar *rev_path = NULL;
10997 static guint tmp_path_len = 0;
11000 g_return_if_fail (GTK_IS_WIDGET (widget));
11005 const gchar *string;
11010 string = g_type_name (G_OBJECT_TYPE (widget));
11011 l = strlen (string);
11012 while (tmp_path_len <= len + l + 1)
11014 tmp_path_len += INIT_PATH_SIZE;
11015 rev_path = g_realloc (rev_path, tmp_path_len);
11017 s = string + l - 1;
11018 d = rev_path + len;
11019 while (s >= string)
11023 widget = widget->priv->parent;
11026 rev_path[len++] = '.';
11028 rev_path[len++] = 0;
11033 *path_length = len - 1;
11035 *path_reversed = g_strdup (rev_path);
11038 *path = g_strdup (rev_path);
11039 g_strreverse (*path);
11044 * gtk_requisition_new:
11046 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11048 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11049 * be freed with gtk_requisition_free().
11054 gtk_requisition_new (void)
11056 return g_slice_new0 (GtkRequisition);
11060 * gtk_requisition_copy:
11061 * @requisition: a #GtkRequisition
11063 * Copies a #GtkRequisition.
11065 * Returns: a copy of @requisition
11068 gtk_requisition_copy (const GtkRequisition *requisition)
11070 return g_slice_dup (GtkRequisition, requisition);
11074 * gtk_requisition_free:
11075 * @requisition: a #GtkRequisition
11077 * Frees a #GtkRequisition.
11080 gtk_requisition_free (GtkRequisition *requisition)
11082 g_slice_free (GtkRequisition, requisition);
11085 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11086 gtk_requisition_copy,
11087 gtk_requisition_free)
11090 * gtk_widget_get_accessible:
11091 * @widget: a #GtkWidget
11093 * Returns the accessible object that describes the widget to an
11094 * assistive technology.
11096 * If no accessibility library is loaded (i.e. no ATK implementation library is
11097 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11098 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11099 * if no class-specific #AtkObject implementation is available for the widget
11100 * instance in question, it will inherit an #AtkObject implementation from the
11101 * first ancestor class for which such an implementation is defined.
11103 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
11104 * library contains more information about accessible objects and their uses.
11106 * Returns: (transfer none): the #AtkObject associated with @widget
11109 gtk_widget_get_accessible (GtkWidget *widget)
11111 GtkWidgetClass *klass;
11113 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11115 klass = GTK_WIDGET_GET_CLASS (widget);
11117 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11119 return klass->get_accessible (widget);
11123 gtk_widget_real_get_accessible (GtkWidget *widget)
11125 AtkObject* accessible;
11127 accessible = g_object_get_qdata (G_OBJECT (widget),
11128 quark_accessible_object);
11131 AtkObjectFactory *factory;
11132 AtkRegistry *default_registry;
11134 default_registry = atk_get_default_registry ();
11135 factory = atk_registry_get_factory (default_registry,
11136 G_TYPE_FROM_INSTANCE (widget));
11138 atk_object_factory_create_accessible (factory,
11139 G_OBJECT (widget));
11140 g_object_set_qdata (G_OBJECT (widget),
11141 quark_accessible_object,
11148 * Initialize a AtkImplementorIface instance's virtual pointers as
11149 * appropriate to this implementor's class (GtkWidget).
11152 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11154 iface->ref_accessible = gtk_widget_ref_accessible;
11158 gtk_widget_ref_accessible (AtkImplementor *implementor)
11160 AtkObject *accessible;
11162 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11164 g_object_ref (accessible);
11169 * Expand flag management
11173 gtk_widget_update_computed_expand (GtkWidget *widget)
11175 GtkWidgetPrivate *priv;
11177 priv = widget->priv;
11179 if (priv->need_compute_expand)
11183 if (priv->hexpand_set)
11188 if (priv->vexpand_set)
11193 /* we don't need to use compute_expand if both expands are
11194 * forced by the app
11196 if (!(priv->hexpand_set && priv->vexpand_set))
11198 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11202 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11203 priv->hexpand_set ? &ignored : &h,
11204 priv->vexpand_set ? &ignored : &v);
11208 priv->need_compute_expand = FALSE;
11209 priv->computed_hexpand = h != FALSE;
11210 priv->computed_vexpand = v != FALSE;
11215 * gtk_widget_queue_compute_expand:
11216 * @widget: a #GtkWidget
11218 * Mark @widget as needing to recompute its expand flags. Call
11219 * this function when setting legacy expand child properties
11220 * on the child of a container.
11222 * See gtk_widget_compute_expand().
11225 gtk_widget_queue_compute_expand (GtkWidget *widget)
11228 gboolean changed_anything;
11230 if (widget->priv->need_compute_expand)
11233 changed_anything = FALSE;
11235 while (parent != NULL)
11237 if (!parent->priv->need_compute_expand)
11239 parent->priv->need_compute_expand = TRUE;
11240 changed_anything = TRUE;
11243 /* Note: if we had an invariant that "if a child needs to
11244 * compute expand, its parents also do" then we could stop going
11245 * up when we got to a parent that already needed to
11246 * compute. However, in general we compute expand lazily (as
11247 * soon as we see something in a subtree that is expand, we know
11248 * we're expanding) and so this invariant does not hold and we
11249 * have to always walk all the way up in case some ancestor
11250 * is not currently need_compute_expand.
11253 parent = parent->priv->parent;
11256 /* recomputing expand always requires
11257 * a relayout as well
11259 if (changed_anything)
11260 gtk_widget_queue_resize (widget);
11264 * gtk_widget_compute_expand:
11265 * @widget: the widget
11266 * @orientation: expand direction
11268 * Computes whether a container should give this widget extra space
11269 * when possible. Containers should check this, rather than
11270 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11272 * This function already checks whether the widget is visible, so
11273 * visibility does not need to be checked separately. Non-visible
11274 * widgets are not expanded.
11276 * The computed expand value uses either the expand setting explicitly
11277 * set on the widget itself, or, if none has been explicitly set,
11278 * the widget may expand if some of its children do.
11280 * Return value: whether widget tree rooted here should be expanded
11283 gtk_widget_compute_expand (GtkWidget *widget,
11284 GtkOrientation orientation)
11286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11288 /* We never make a widget expand if not even showing. */
11289 if (!gtk_widget_get_visible (widget))
11292 gtk_widget_update_computed_expand (widget);
11294 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11296 return widget->priv->computed_hexpand;
11300 return widget->priv->computed_vexpand;
11305 gtk_widget_set_expand (GtkWidget *widget,
11306 GtkOrientation orientation,
11309 const char *expand_prop;
11310 const char *expand_set_prop;
11312 GtkWidgetPrivate *priv;
11314 g_return_if_fail (GTK_IS_WIDGET (widget));
11316 priv = widget->priv;
11318 expand = expand != FALSE;
11320 was_both = priv->hexpand && priv->vexpand;
11322 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11324 if (priv->hexpand_set &&
11325 priv->hexpand == expand)
11328 priv->hexpand_set = TRUE;
11329 priv->hexpand = expand;
11331 expand_prop = "hexpand";
11332 expand_set_prop = "hexpand-set";
11336 if (priv->vexpand_set &&
11337 priv->vexpand == expand)
11340 priv->vexpand_set = TRUE;
11341 priv->vexpand = expand;
11343 expand_prop = "vexpand";
11344 expand_set_prop = "vexpand-set";
11347 gtk_widget_queue_compute_expand (widget);
11349 g_object_freeze_notify (G_OBJECT (widget));
11350 g_object_notify (G_OBJECT (widget), expand_prop);
11351 g_object_notify (G_OBJECT (widget), expand_set_prop);
11352 if (was_both != (priv->hexpand && priv->vexpand))
11353 g_object_notify (G_OBJECT (widget), "expand");
11354 g_object_thaw_notify (G_OBJECT (widget));
11358 gtk_widget_set_expand_set (GtkWidget *widget,
11359 GtkOrientation orientation,
11362 GtkWidgetPrivate *priv;
11365 priv = widget->priv;
11367 set = set != FALSE;
11369 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11371 if (set == priv->hexpand_set)
11374 priv->hexpand_set = set;
11375 prop = "hexpand-set";
11379 if (set == priv->vexpand_set)
11382 priv->vexpand_set = set;
11383 prop = "vexpand-set";
11386 gtk_widget_queue_compute_expand (widget);
11388 g_object_notify (G_OBJECT (widget), prop);
11392 * gtk_widget_get_hexpand:
11393 * @widget: the widget
11395 * Gets whether the widget would like any available extra horizontal
11396 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11397 * generally receive the extra space. For example, a list or
11398 * scrollable area or document in your window would often be set to
11401 * Containers should use gtk_widget_compute_expand() rather than
11402 * this function, to see whether a widget, or any of its children,
11403 * has the expand flag set. If any child of a widget wants to
11404 * expand, the parent may ask to expand also.
11406 * This function only looks at the widget's own hexpand flag, rather
11407 * than computing whether the entire widget tree rooted at this widget
11410 * Return value: whether hexpand flag is set
11413 gtk_widget_get_hexpand (GtkWidget *widget)
11415 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11417 return widget->priv->hexpand;
11421 * gtk_widget_set_hexpand:
11422 * @widget: the widget
11423 * @expand: whether to expand
11425 * Sets whether the widget would like any available extra horizontal
11426 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11427 * generally receive the extra space. For example, a list or
11428 * scrollable area or document in your window would often be set to
11431 * Call this function to set the expand flag if you would like your
11432 * widget to become larger horizontally when the window has extra
11435 * By default, widgets automatically expand if any of their children
11436 * want to expand. (To see if a widget will automatically expand given
11437 * its current children and state, call gtk_widget_compute_expand(). A
11438 * container can decide how the expandability of children affects the
11439 * expansion of the container by overriding the compute_expand virtual
11440 * method on #GtkWidget.).
11442 * Setting hexpand explicitly with this function will override the
11443 * automatic expand behavior.
11445 * This function forces the widget to expand or not to expand,
11446 * regardless of children. The override occurs because
11447 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11448 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11449 * value to be used, rather than looking at children and widget state.
11452 gtk_widget_set_hexpand (GtkWidget *widget,
11455 g_return_if_fail (GTK_IS_WIDGET (widget));
11457 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11461 * gtk_widget_get_hexpand_set:
11462 * @widget: the widget
11464 * Gets whether gtk_widget_set_hexpand() has been used to
11465 * explicitly set the expand flag on this widget.
11467 * If hexpand is set, then it overrides any computed
11468 * expand value based on child widgets. If hexpand is not
11469 * set, then the expand value depends on whether any
11470 * children of the widget would like to expand.
11472 * There are few reasons to use this function, but it's here
11473 * for completeness and consistency.
11475 * Return value: whether hexpand has been explicitly set
11478 gtk_widget_get_hexpand_set (GtkWidget *widget)
11480 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11482 return widget->priv->hexpand_set;
11486 * gtk_widget_set_hexpand_set:
11487 * @widget: the widget
11488 * @set: value for hexpand-set property
11490 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11493 * The hexpand-set property will be set automatically when you call
11494 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11495 * reason to use this function would be to unset an explicit expand
11498 * If hexpand is set, then it overrides any computed
11499 * expand value based on child widgets. If hexpand is not
11500 * set, then the expand value depends on whether any
11501 * children of the widget would like to expand.
11503 * There are few reasons to use this function, but it's here
11504 * for completeness and consistency.
11506 * Return value: whether hexpand has been explicitly set
11509 gtk_widget_set_hexpand_set (GtkWidget *widget,
11512 g_return_if_fail (GTK_IS_WIDGET (widget));
11514 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11519 * gtk_widget_get_vexpand:
11520 * @widget: the widget
11522 * Gets whether the widget would like any available extra vertical
11525 * See gtk_widget_get_hexpand() for more detail.
11527 * Return value: whether vexpand flag is set
11530 gtk_widget_get_vexpand (GtkWidget *widget)
11532 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11534 return widget->priv->vexpand;
11538 * gtk_widget_set_vexpand:
11539 * @widget: the widget
11540 * @expand: whether to expand
11542 * Sets whether the widget would like any available extra vertical
11545 * See gtk_widget_set_hexpand() for more detail.
11548 gtk_widget_set_vexpand (GtkWidget *widget,
11551 g_return_if_fail (GTK_IS_WIDGET (widget));
11553 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11557 * gtk_widget_get_vexpand_set:
11558 * @widget: the widget
11560 * Gets whether gtk_widget_set_vexpand() has been used to
11561 * explicitly set the expand flag on this widget.
11563 * See gtk_widget_get_hexpand_set() for more detail.
11565 * Return value: whether vexpand has been explicitly set
11568 gtk_widget_get_vexpand_set (GtkWidget *widget)
11570 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11572 return widget->priv->vexpand_set;
11576 * gtk_widget_set_vexpand_set:
11577 * @widget: the widget
11578 * @set: value for vexpand-set property
11580 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11583 * See gtk_widget_set_hexpand_set() for more detail.
11585 * Return value: whether vexpand has been explicitly set
11588 gtk_widget_set_vexpand_set (GtkWidget *widget,
11591 g_return_if_fail (GTK_IS_WIDGET (widget));
11593 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11597 * GtkBuildable implementation
11599 static GQuark quark_builder_has_default = 0;
11600 static GQuark quark_builder_has_focus = 0;
11601 static GQuark quark_builder_atk_relations = 0;
11602 static GQuark quark_builder_set_name = 0;
11605 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11607 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11608 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11609 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11610 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11612 iface->set_name = gtk_widget_buildable_set_name;
11613 iface->get_name = gtk_widget_buildable_get_name;
11614 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11615 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11616 iface->parser_finished = gtk_widget_buildable_parser_finished;
11617 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11618 iface->custom_finished = gtk_widget_buildable_custom_finished;
11622 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11625 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11626 g_strdup (name), g_free);
11629 static const gchar *
11630 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11632 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11636 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11637 GtkBuilder *builder,
11638 const gchar *childname)
11640 if (strcmp (childname, "accessible") == 0)
11641 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11647 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11648 GtkBuilder *builder,
11650 const GValue *value)
11652 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11653 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11654 GINT_TO_POINTER (TRUE));
11655 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11656 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11657 GINT_TO_POINTER (TRUE));
11659 g_object_set_property (G_OBJECT (buildable), name, value);
11664 gchar *action_name;
11665 GString *description;
11667 gboolean translatable;
11677 free_action (AtkActionData *data, gpointer user_data)
11679 g_free (data->action_name);
11680 g_string_free (data->description, TRUE);
11681 g_free (data->context);
11682 g_slice_free (AtkActionData, data);
11686 free_relation (AtkRelationData *data, gpointer user_data)
11688 g_free (data->target);
11689 g_free (data->type);
11690 g_slice_free (AtkRelationData, data);
11694 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11695 GtkBuilder *builder)
11697 GSList *atk_relations;
11699 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11700 gtk_widget_grab_default (GTK_WIDGET (buildable));
11701 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11702 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11704 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11705 quark_builder_atk_relations);
11708 AtkObject *accessible;
11709 AtkRelationSet *relation_set;
11712 AtkRelationType relation_type;
11713 AtkObject *target_accessible;
11715 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11716 relation_set = atk_object_ref_relation_set (accessible);
11718 for (l = atk_relations; l; l = l->next)
11720 AtkRelationData *relation = (AtkRelationData*)l->data;
11722 target = gtk_builder_get_object (builder, relation->target);
11725 g_warning ("Target object %s in <relation> does not exist",
11729 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11730 g_assert (target_accessible != NULL);
11732 relation_type = atk_relation_type_for_name (relation->type);
11733 if (relation_type == ATK_RELATION_NULL)
11735 g_warning ("<relation> type %s not found",
11739 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11740 target_accessible);
11742 g_object_unref (relation_set);
11744 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11745 g_slist_free (atk_relations);
11746 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11755 } AccessibilitySubParserData;
11758 accessibility_start_element (GMarkupParseContext *context,
11759 const gchar *element_name,
11760 const gchar **names,
11761 const gchar **values,
11762 gpointer user_data,
11765 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11767 gint line_number, char_number;
11769 if (strcmp (element_name, "relation") == 0)
11771 gchar *target = NULL;
11772 gchar *type = NULL;
11773 AtkRelationData *relation;
11775 for (i = 0; names[i]; i++)
11777 if (strcmp (names[i], "target") == 0)
11778 target = g_strdup (values[i]);
11779 else if (strcmp (names[i], "type") == 0)
11780 type = g_strdup (values[i]);
11783 g_markup_parse_context_get_position (context,
11786 g_set_error (error,
11788 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11789 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11791 line_number, char_number, names[i], "relation");
11798 if (!target || !type)
11800 g_markup_parse_context_get_position (context,
11803 g_set_error (error,
11805 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11806 "%s:%d:%d <%s> requires attribute \"%s\"",
11808 line_number, char_number, "relation",
11809 type ? "target" : "type");
11815 relation = g_slice_new (AtkRelationData);
11816 relation->target = target;
11817 relation->type = type;
11819 data->relations = g_slist_prepend (data->relations, relation);
11821 else if (strcmp (element_name, "action") == 0)
11823 const gchar *action_name = NULL;
11824 const gchar *description = NULL;
11825 const gchar *msg_context = NULL;
11826 gboolean translatable = FALSE;
11827 AtkActionData *action;
11829 for (i = 0; names[i]; i++)
11831 if (strcmp (names[i], "action_name") == 0)
11832 action_name = values[i];
11833 else if (strcmp (names[i], "description") == 0)
11834 description = values[i];
11835 else if (strcmp (names[i], "translatable") == 0)
11837 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11840 else if (strcmp (names[i], "comments") == 0)
11842 /* do nothing, comments are for translators */
11844 else if (strcmp (names[i], "context") == 0)
11845 msg_context = values[i];
11848 g_markup_parse_context_get_position (context,
11851 g_set_error (error,
11853 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11854 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11856 line_number, char_number, names[i], "action");
11863 g_markup_parse_context_get_position (context,
11866 g_set_error (error,
11868 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11869 "%s:%d:%d <%s> requires attribute \"%s\"",
11871 line_number, char_number, "action",
11876 action = g_slice_new (AtkActionData);
11877 action->action_name = g_strdup (action_name);
11878 action->description = g_string_new (description);
11879 action->context = g_strdup (msg_context);
11880 action->translatable = translatable;
11882 data->actions = g_slist_prepend (data->actions, action);
11884 else if (strcmp (element_name, "accessibility") == 0)
11887 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11891 accessibility_text (GMarkupParseContext *context,
11894 gpointer user_data,
11897 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11899 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11901 AtkActionData *action = data->actions->data;
11903 g_string_append_len (action->description, text, text_len);
11907 static const GMarkupParser accessibility_parser =
11909 accessibility_start_element,
11911 accessibility_text,
11920 } AccelGroupParserData;
11923 accel_group_start_element (GMarkupParseContext *context,
11924 const gchar *element_name,
11925 const gchar **names,
11926 const gchar **values,
11927 gpointer user_data,
11932 guint modifiers = 0;
11933 gchar *signal = NULL;
11934 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11936 for (i = 0; names[i]; i++)
11938 if (strcmp (names[i], "key") == 0)
11939 key = gdk_keyval_from_name (values[i]);
11940 else if (strcmp (names[i], "modifiers") == 0)
11942 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11948 else if (strcmp (names[i], "signal") == 0)
11949 signal = g_strdup (values[i]);
11952 if (key == 0 || signal == NULL)
11954 g_warning ("<accelerator> requires key and signal attributes");
11957 parser_data->key = key;
11958 parser_data->modifiers = modifiers;
11959 parser_data->signal = signal;
11962 static const GMarkupParser accel_group_parser =
11964 accel_group_start_element,
11968 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11969 GtkBuilder *builder,
11971 const gchar *tagname,
11972 GMarkupParser *parser,
11975 g_assert (buildable);
11977 if (strcmp (tagname, "accelerator") == 0)
11979 AccelGroupParserData *parser_data;
11981 parser_data = g_slice_new0 (AccelGroupParserData);
11982 parser_data->object = g_object_ref (buildable);
11983 *parser = accel_group_parser;
11984 *data = parser_data;
11987 if (strcmp (tagname, "accessibility") == 0)
11989 AccessibilitySubParserData *parser_data;
11991 parser_data = g_slice_new0 (AccessibilitySubParserData);
11992 *parser = accessibility_parser;
11993 *data = parser_data;
12000 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12001 GtkWidget *toplevel,
12002 gpointer user_data)
12004 AccelGroupParserData *accel_data;
12005 GSList *accel_groups;
12006 GtkAccelGroup *accel_group;
12008 g_return_if_fail (GTK_IS_WIDGET (widget));
12009 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12010 g_return_if_fail (user_data != NULL);
12012 accel_data = (AccelGroupParserData*)user_data;
12013 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12014 if (g_slist_length (accel_groups) == 0)
12016 accel_group = gtk_accel_group_new ();
12017 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12021 g_assert (g_slist_length (accel_groups) == 1);
12022 accel_group = g_slist_nth_data (accel_groups, 0);
12025 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12026 accel_data->signal,
12029 accel_data->modifiers,
12030 GTK_ACCEL_VISIBLE);
12032 g_object_unref (accel_data->object);
12033 g_free (accel_data->signal);
12034 g_slice_free (AccelGroupParserData, accel_data);
12038 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12039 GtkBuilder *builder,
12041 const gchar *tagname,
12042 gpointer user_data)
12044 AccelGroupParserData *accel_data;
12045 AccessibilitySubParserData *a11y_data;
12046 GtkWidget *toplevel;
12048 if (strcmp (tagname, "accelerator") == 0)
12050 accel_data = (AccelGroupParserData*)user_data;
12051 g_assert (accel_data->object);
12053 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12055 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12057 else if (strcmp (tagname, "accessibility") == 0)
12059 a11y_data = (AccessibilitySubParserData*)user_data;
12061 if (a11y_data->actions)
12063 AtkObject *accessible;
12068 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12070 action = ATK_ACTION (accessible);
12071 n_actions = atk_action_get_n_actions (action);
12073 for (l = a11y_data->actions; l; l = l->next)
12075 AtkActionData *action_data = (AtkActionData*)l->data;
12077 for (i = 0; i < n_actions; i++)
12078 if (strcmp (atk_action_get_name (action, i),
12079 action_data->action_name) == 0)
12084 gchar *description;
12086 if (action_data->translatable && action_data->description->len)
12087 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12088 action_data->context,
12089 action_data->description->str);
12091 description = action_data->description->str;
12093 atk_action_set_description (action, i, description);
12097 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12098 g_slist_free (a11y_data->actions);
12101 if (a11y_data->relations)
12102 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12103 a11y_data->relations);
12105 g_slice_free (AccessibilitySubParserData, a11y_data);
12110 gtk_widget_real_get_width (GtkWidget *widget,
12111 gint *minimum_size,
12112 gint *natural_size)
12122 gtk_widget_real_get_height (GtkWidget *widget,
12123 gint *minimum_size,
12124 gint *natural_size)
12134 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12136 gint *minimum_height,
12137 gint *natural_height)
12139 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12143 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12145 gint *minimum_width,
12146 gint *natural_width)
12148 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12152 * gtk_widget_get_halign:
12153 * @widget: a #GtkWidget
12155 * Gets the value of the #GtkWidget:halign property.
12157 * Returns: the horizontal alignment of @widget
12160 gtk_widget_get_halign (GtkWidget *widget)
12162 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12163 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12167 * gtk_widget_set_halign:
12168 * @widget: a #GtkWidget
12169 * @align: the horizontal alignment
12171 * Sets the horizontal alignment of @widget.
12172 * See the #GtkWidget:halign property.
12175 gtk_widget_set_halign (GtkWidget *widget,
12178 GtkWidgetAuxInfo *aux_info;
12180 g_return_if_fail (GTK_IS_WIDGET (widget));
12182 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12184 if (aux_info->halign == align)
12187 aux_info->halign = align;
12188 gtk_widget_queue_resize (widget);
12189 g_object_notify (G_OBJECT (widget), "halign");
12193 * gtk_widget_get_valign:
12194 * @widget: a #GtkWidget
12196 * Gets the value of the #GtkWidget:valign property.
12198 * Returns: the vertical alignment of @widget
12201 gtk_widget_get_valign (GtkWidget *widget)
12203 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12204 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12208 * gtk_widget_set_valign:
12209 * @widget: a #GtkWidget
12210 * @align: the vertical alignment
12212 * Sets the vertical alignment of @widget.
12213 * See the #GtkWidget:valign property.
12216 gtk_widget_set_valign (GtkWidget *widget,
12219 GtkWidgetAuxInfo *aux_info;
12221 g_return_if_fail (GTK_IS_WIDGET (widget));
12223 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12225 if (aux_info->valign == align)
12228 aux_info->valign = align;
12229 gtk_widget_queue_resize (widget);
12230 g_object_notify (G_OBJECT (widget), "valign");
12234 * gtk_widget_get_margin_left:
12235 * @widget: a #GtkWidget
12237 * Gets the value of the #GtkWidget:margin-left property.
12239 * Returns: The left margin of @widget
12242 gtk_widget_get_margin_left (GtkWidget *widget)
12244 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12246 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12250 * gtk_widget_set_margin_left:
12251 * @widget: a #GtkWidget
12252 * @margin: the left margin
12254 * Sets the left margin of @widget.
12255 * See the #GtkWidget:margin-left property.
12258 gtk_widget_set_margin_left (GtkWidget *widget,
12261 GtkWidgetAuxInfo *aux_info;
12263 g_return_if_fail (GTK_IS_WIDGET (widget));
12264 g_return_if_fail (margin <= G_MAXINT16);
12266 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12268 if (aux_info->margin.left == margin)
12271 aux_info->margin.left = margin;
12272 gtk_widget_queue_resize (widget);
12273 g_object_notify (G_OBJECT (widget), "margin-left");
12277 * gtk_widget_get_margin_right:
12278 * @widget: a #GtkWidget
12280 * Gets the value of the #GtkWidget:margin-right property.
12282 * Returns: The left margin of @widget
12285 gtk_widget_get_margin_right (GtkWidget *widget)
12287 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12289 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12293 * gtk_widget_set_margin_right:
12294 * @widget: a #GtkWidget
12295 * @margin: the right margin
12297 * Sets the right margin of @widget.
12298 * See the #GtkWidget:margin-right property.
12301 gtk_widget_set_margin_right (GtkWidget *widget,
12304 GtkWidgetAuxInfo *aux_info;
12306 g_return_if_fail (GTK_IS_WIDGET (widget));
12307 g_return_if_fail (margin <= G_MAXINT16);
12309 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12311 if (aux_info->margin.right == margin)
12314 aux_info->margin.right = margin;
12315 gtk_widget_queue_resize (widget);
12316 g_object_notify (G_OBJECT (widget), "margin-right");
12320 * gtk_widget_get_margin_top:
12321 * @widget: a #GtkWidget
12323 * Gets the value of the #GtkWidget:margin-top property.
12325 * Returns: The top margin of @widget
12328 gtk_widget_get_margin_top (GtkWidget *widget)
12330 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12332 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12336 * gtk_widget_set_margin_top:
12337 * @widget: a #GtkWidget
12338 * @margin: the top margin
12340 * Sets the top margin of @widget.
12341 * See the #GtkWidget:margin-top property.
12344 gtk_widget_set_margin_top (GtkWidget *widget,
12347 GtkWidgetAuxInfo *aux_info;
12349 g_return_if_fail (GTK_IS_WIDGET (widget));
12350 g_return_if_fail (margin <= G_MAXINT16);
12352 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12354 if (aux_info->margin.top == margin)
12357 aux_info->margin.top = margin;
12358 gtk_widget_queue_resize (widget);
12359 g_object_notify (G_OBJECT (widget), "margin-top");
12363 * gtk_widget_get_margin_bottom:
12364 * @widget: a #GtkWidget
12366 * Gets the value of the #GtkWidget:margin-bottom property.
12368 * Returns: The bottom margin of @widget
12371 gtk_widget_get_margin_bottom (GtkWidget *widget)
12373 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12375 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12379 * gtk_widget_set_margin_bottom:
12380 * @widget: a #GtkWidget
12381 * @margin: the bottom margin
12383 * Sets the bottom margin of @widget.
12384 * See the #GtkWidget:margin-bottom property.
12387 gtk_widget_set_margin_bottom (GtkWidget *widget,
12390 GtkWidgetAuxInfo *aux_info;
12392 g_return_if_fail (GTK_IS_WIDGET (widget));
12393 g_return_if_fail (margin <= G_MAXINT16);
12395 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12397 if (aux_info->margin.bottom == margin)
12400 aux_info->margin.bottom = margin;
12401 gtk_widget_queue_resize (widget);
12402 g_object_notify (G_OBJECT (widget), "margin-bottom");
12406 * gtk_widget_get_clipboard:
12407 * @widget: a #GtkWidget
12408 * @selection: a #GdkAtom which identifies the clipboard
12409 * to use. %GDK_SELECTION_CLIPBOARD gives the
12410 * default clipboard. Another common value
12411 * is %GDK_SELECTION_PRIMARY, which gives
12412 * the primary X selection.
12414 * Returns the clipboard object for the given selection to
12415 * be used with @widget. @widget must have a #GdkDisplay
12416 * associated with it, so must be attached to a toplevel
12419 * Return value: (transfer none): the appropriate clipboard object. If no
12420 * clipboard already exists, a new one will
12421 * be created. Once a clipboard object has
12422 * been created, it is persistent for all time.
12427 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12429 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12430 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12432 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12437 * gtk_widget_list_mnemonic_labels:
12438 * @widget: a #GtkWidget
12440 * Returns a newly allocated list of the widgets, normally labels, for
12441 * which this widget is the target of a mnemonic (see for example,
12442 * gtk_label_set_mnemonic_widget()).
12444 * The widgets in the list are not individually referenced. If you
12445 * want to iterate through the list and perform actions involving
12446 * callbacks that might destroy the widgets, you
12447 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12448 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12449 * widgets afterwards.
12451 * Return value: (element-type GtkWidget) (transfer container): the list of
12452 * mnemonic labels; free this list
12453 * with g_list_free() when you are done with it.
12458 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12460 GList *list = NULL;
12463 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12465 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12466 list = g_list_prepend (list, l->data);
12472 * gtk_widget_add_mnemonic_label:
12473 * @widget: a #GtkWidget
12474 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12476 * Adds a widget to the list of mnemonic labels for
12477 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12478 * list of mnemonic labels for the widget is cleared when the
12479 * widget is destroyed, so the caller must make sure to update
12480 * its internal state at this point as well, by using a connection
12481 * to the #GtkWidget::destroy signal or a weak notifier.
12486 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12489 GSList *old_list, *new_list;
12491 g_return_if_fail (GTK_IS_WIDGET (widget));
12492 g_return_if_fail (GTK_IS_WIDGET (label));
12494 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12495 new_list = g_slist_prepend (old_list, label);
12497 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12498 new_list, (GDestroyNotify) g_slist_free);
12502 * gtk_widget_remove_mnemonic_label:
12503 * @widget: a #GtkWidget
12504 * @label: a #GtkWidget that was previously set as a mnemnic label for
12505 * @widget with gtk_widget_add_mnemonic_label().
12507 * Removes a widget from the list of mnemonic labels for
12508 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12509 * must have previously been added to the list with
12510 * gtk_widget_add_mnemonic_label().
12515 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12518 GSList *old_list, *new_list;
12520 g_return_if_fail (GTK_IS_WIDGET (widget));
12521 g_return_if_fail (GTK_IS_WIDGET (label));
12523 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12524 new_list = g_slist_remove (old_list, label);
12527 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12528 new_list, (GDestroyNotify) g_slist_free);
12532 * gtk_widget_get_no_show_all:
12533 * @widget: a #GtkWidget
12535 * Returns the current value of the #GtkWidget:no-show-all property,
12536 * which determines whether calls to gtk_widget_show_all()
12537 * will affect this widget.
12539 * Return value: the current value of the "no-show-all" property.
12544 gtk_widget_get_no_show_all (GtkWidget *widget)
12546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12548 return widget->priv->no_show_all;
12552 * gtk_widget_set_no_show_all:
12553 * @widget: a #GtkWidget
12554 * @no_show_all: the new value for the "no-show-all" property
12556 * Sets the #GtkWidget:no-show-all property, which determines whether
12557 * calls to gtk_widget_show_all() will affect this widget.
12559 * This is mostly for use in constructing widget hierarchies with externally
12560 * controlled visibility, see #GtkUIManager.
12565 gtk_widget_set_no_show_all (GtkWidget *widget,
12566 gboolean no_show_all)
12568 g_return_if_fail (GTK_IS_WIDGET (widget));
12570 no_show_all = (no_show_all != FALSE);
12572 if (widget->priv->no_show_all != no_show_all)
12574 widget->priv->no_show_all = no_show_all;
12576 g_object_notify (G_OBJECT (widget), "no-show-all");
12582 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12583 gboolean has_tooltip,
12586 GtkWidgetPrivate *priv = widget->priv;
12587 gboolean priv_has_tooltip;
12589 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12590 quark_has_tooltip));
12592 if (priv_has_tooltip != has_tooltip || force)
12594 priv_has_tooltip = has_tooltip;
12596 if (priv_has_tooltip)
12598 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12599 gdk_window_set_events (priv->window,
12600 gdk_window_get_events (priv->window) |
12601 GDK_LEAVE_NOTIFY_MASK |
12602 GDK_POINTER_MOTION_MASK |
12603 GDK_POINTER_MOTION_HINT_MASK);
12605 if (gtk_widget_get_has_window (widget))
12606 gtk_widget_add_events (widget,
12607 GDK_LEAVE_NOTIFY_MASK |
12608 GDK_POINTER_MOTION_MASK |
12609 GDK_POINTER_MOTION_HINT_MASK);
12612 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12613 GUINT_TO_POINTER (priv_has_tooltip));
12618 * gtk_widget_set_tooltip_window:
12619 * @widget: a #GtkWidget
12620 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12622 * Replaces the default, usually yellow, window used for displaying
12623 * tooltips with @custom_window. GTK+ will take care of showing and
12624 * hiding @custom_window at the right moment, to behave likewise as
12625 * the default tooltip window. If @custom_window is %NULL, the default
12626 * tooltip window will be used.
12628 * If the custom window should have the default theming it needs to
12629 * have the name "gtk-tooltip", see gtk_widget_set_name().
12634 gtk_widget_set_tooltip_window (GtkWidget *widget,
12635 GtkWindow *custom_window)
12637 gboolean has_tooltip;
12638 gchar *tooltip_markup;
12640 g_return_if_fail (GTK_IS_WIDGET (widget));
12641 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12643 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12646 g_object_ref (custom_window);
12648 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12649 custom_window, g_object_unref);
12651 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12652 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12654 if (has_tooltip && gtk_widget_get_visible (widget))
12655 gtk_widget_queue_tooltip_query (widget);
12659 * gtk_widget_get_tooltip_window:
12660 * @widget: a #GtkWidget
12662 * Returns the #GtkWindow of the current tooltip. This can be the
12663 * GtkWindow created by default, or the custom tooltip window set
12664 * using gtk_widget_set_tooltip_window().
12666 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12671 gtk_widget_get_tooltip_window (GtkWidget *widget)
12673 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12675 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12679 * gtk_widget_trigger_tooltip_query:
12680 * @widget: a #GtkWidget
12682 * Triggers a tooltip query on the display where the toplevel of @widget
12683 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12689 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12691 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12694 static guint tooltip_query_id;
12695 static GSList *tooltip_query_displays;
12698 tooltip_query_idle (gpointer data)
12700 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12701 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12702 g_slist_free (tooltip_query_displays);
12704 tooltip_query_displays = NULL;
12705 tooltip_query_id = 0;
12711 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12713 GdkDisplay *display;
12715 display = gtk_widget_get_display (widget);
12717 if (!g_slist_find (tooltip_query_displays, display))
12718 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12720 if (tooltip_query_id == 0)
12721 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12725 * gtk_widget_set_tooltip_text:
12726 * @widget: a #GtkWidget
12727 * @text: the contents of the tooltip for @widget
12729 * Sets @text as the contents of the tooltip. This function will take
12730 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
12731 * handler for the #GtkWidget::query-tooltip signal.
12733 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12738 gtk_widget_set_tooltip_text (GtkWidget *widget,
12741 g_return_if_fail (GTK_IS_WIDGET (widget));
12743 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12747 * gtk_widget_get_tooltip_text:
12748 * @widget: a #GtkWidget
12750 * Gets the contents of the tooltip for @widget.
12752 * Return value: the tooltip text, or %NULL. You should free the
12753 * returned string with g_free() when done.
12758 gtk_widget_get_tooltip_text (GtkWidget *widget)
12760 gchar *text = NULL;
12762 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12764 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12770 * gtk_widget_set_tooltip_markup:
12771 * @widget: a #GtkWidget
12772 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12774 * Sets @markup as the contents of the tooltip, which is marked up with
12775 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12777 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
12778 * and of the default handler for the #GtkWidget::query-tooltip signal.
12780 * See also the #GtkWidget:tooltip-markup property and
12781 * gtk_tooltip_set_markup().
12786 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12787 const gchar *markup)
12789 g_return_if_fail (GTK_IS_WIDGET (widget));
12791 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12795 * gtk_widget_get_tooltip_markup:
12796 * @widget: a #GtkWidget
12798 * Gets the contents of the tooltip for @widget.
12800 * Return value: the tooltip text, or %NULL. You should free the
12801 * returned string with g_free() when done.
12806 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12808 gchar *text = NULL;
12810 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12812 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12818 * gtk_widget_set_has_tooltip:
12819 * @widget: a #GtkWidget
12820 * @has_tooltip: whether or not @widget has a tooltip.
12822 * Sets the has-tooltip property on @widget to @has_tooltip. See
12823 * #GtkWidget:has-tooltip for more information.
12828 gtk_widget_set_has_tooltip (GtkWidget *widget,
12829 gboolean has_tooltip)
12831 g_return_if_fail (GTK_IS_WIDGET (widget));
12833 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12837 * gtk_widget_get_has_tooltip:
12838 * @widget: a #GtkWidget
12840 * Returns the current value of the has-tooltip property. See
12841 * #GtkWidget:has-tooltip for more information.
12843 * Return value: current value of has-tooltip on @widget.
12848 gtk_widget_get_has_tooltip (GtkWidget *widget)
12850 gboolean has_tooltip = FALSE;
12852 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12854 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12856 return has_tooltip;
12860 * gtk_widget_get_allocation:
12861 * @widget: a #GtkWidget
12862 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12864 * Retrieves the widget's allocation.
12866 * Note, when implementing a #GtkContainer: a widget's allocation will
12867 * be its "adjusted" allocation, that is, the widget's parent
12868 * container typically calls gtk_widget_size_allocate() with an
12869 * allocation, and that allocation is then adjusted (to handle margin
12870 * and alignment for example) before assignment to the widget.
12871 * gtk_widget_get_allocation() returns the adjusted allocation that
12872 * was actually assigned to the widget. The adjusted allocation is
12873 * guaranteed to be completely contained within the
12874 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12875 * is guaranteed that its children stay inside the assigned bounds,
12876 * but not that they have exactly the bounds the container assigned.
12877 * There is no way to get the original allocation assigned by
12878 * gtk_widget_size_allocate(), since it isn't stored; if a container
12879 * implementation needs that information it will have to track it itself.
12884 gtk_widget_get_allocation (GtkWidget *widget,
12885 GtkAllocation *allocation)
12887 GtkWidgetPrivate *priv;
12889 g_return_if_fail (GTK_IS_WIDGET (widget));
12890 g_return_if_fail (allocation != NULL);
12892 priv = widget->priv;
12894 *allocation = priv->allocation;
12898 * gtk_widget_set_allocation:
12899 * @widget: a #GtkWidget
12900 * @allocation: a pointer to a #GtkAllocation to copy from
12902 * Sets the widget's allocation. This should not be used
12903 * directly, but from within a widget's size_allocate method.
12905 * The allocation set should be the "adjusted" or actual
12906 * allocation. If you're implementing a #GtkContainer, you want to use
12907 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12908 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12909 * allocation inside gtk_widget_size_allocate() to create an adjusted
12915 gtk_widget_set_allocation (GtkWidget *widget,
12916 const GtkAllocation *allocation)
12918 GtkWidgetPrivate *priv;
12920 g_return_if_fail (GTK_IS_WIDGET (widget));
12921 g_return_if_fail (allocation != NULL);
12923 priv = widget->priv;
12925 priv->allocation = *allocation;
12929 * gtk_widget_get_allocated_width:
12930 * @widget: the widget to query
12932 * Returns the width that has currently been allocated to @widget.
12933 * This function is intended to be used when implementing handlers
12934 * for the #GtkWidget::draw function.
12936 * Returns: the width of the @widget
12939 gtk_widget_get_allocated_width (GtkWidget *widget)
12941 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12943 return widget->priv->allocation.width;
12947 * gtk_widget_get_allocated_height:
12948 * @widget: the widget to query
12950 * Returns the height that has currently been allocated to @widget.
12951 * This function is intended to be used when implementing handlers
12952 * for the #GtkWidget::draw function.
12954 * Returns: the height of the @widget
12957 gtk_widget_get_allocated_height (GtkWidget *widget)
12959 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12961 return widget->priv->allocation.height;
12965 * gtk_widget_get_requisition:
12966 * @widget: a #GtkWidget
12967 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12969 * Retrieves the widget's requisition.
12971 * This function should only be used by widget implementations in
12972 * order to figure whether the widget's requisition has actually
12973 * changed after some internal state change (so that they can call
12974 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12976 * Normally, gtk_widget_size_request() should be used.
12980 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12981 * removed, If you need to cache sizes across requests and allocations,
12982 * add an explicit cache to the widget in question instead.
12985 gtk_widget_get_requisition (GtkWidget *widget,
12986 GtkRequisition *requisition)
12988 g_return_if_fail (GTK_IS_WIDGET (widget));
12989 g_return_if_fail (requisition != NULL);
12991 gtk_widget_get_preferred_size (widget, requisition, NULL);
12995 * gtk_widget_set_window:
12996 * @widget: a #GtkWidget
12997 * @window: a #GdkWindow
12999 * Sets a widget's window. This function should only be used in a
13000 * widget's #GtkWidget::realize implementation. The %window passed is
13001 * usually either new window created with gdk_window_new(), or the
13002 * window of its parent widget as returned by
13003 * gtk_widget_get_parent_window().
13005 * Widgets must indicate whether they will create their own #GdkWindow
13006 * by calling gtk_widget_set_has_window(). This is usually done in the
13007 * widget's init() function.
13009 * <note><para>This function does not add any reference to @window.</para></note>
13014 gtk_widget_set_window (GtkWidget *widget,
13017 GtkWidgetPrivate *priv;
13019 g_return_if_fail (GTK_IS_WIDGET (widget));
13020 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13022 priv = widget->priv;
13024 if (priv->window != window)
13026 priv->window = window;
13027 g_object_notify (G_OBJECT (widget), "window");
13032 * gtk_widget_get_window:
13033 * @widget: a #GtkWidget
13035 * Returns the widget's window if it is realized, %NULL otherwise
13037 * Return value: (transfer none): @widget's window.
13042 gtk_widget_get_window (GtkWidget *widget)
13044 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13046 return widget->priv->window;
13050 * gtk_widget_get_support_multidevice:
13051 * @widget: a #GtkWidget
13053 * Returns %TRUE if @widget is multiple pointer aware. See
13054 * gtk_widget_set_support_multidevice() for more information.
13056 * Returns: %TRUE is @widget is multidevice aware.
13059 gtk_widget_get_support_multidevice (GtkWidget *widget)
13061 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13063 return widget->priv->multidevice;
13067 * gtk_widget_set_support_multidevice:
13068 * @widget: a #GtkWidget
13069 * @support_multidevice: %TRUE to support input from multiple devices.
13071 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13072 * @widget will start receiving multiple, per device enter/leave events. Note
13073 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13074 * gdk_window_set_support_multidevice() will have to be called manually on them.
13079 gtk_widget_set_support_multidevice (GtkWidget *widget,
13080 gboolean support_multidevice)
13082 GtkWidgetPrivate *priv;
13084 g_return_if_fail (GTK_IS_WIDGET (widget));
13086 priv = widget->priv;
13088 if (support_multidevice)
13090 priv->multidevice = TRUE;
13091 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13095 priv->multidevice = FALSE;
13096 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13099 if (gtk_widget_get_realized (widget))
13100 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13104 _gtk_widget_set_has_focus (GtkWidget *widget,
13105 gboolean has_focus)
13107 widget->priv->has_focus = has_focus;
13111 * gtk_widget_send_focus_change:
13112 * @widget: a #GtkWidget
13113 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13115 * Sends the focus change @event to @widget
13117 * This function is not meant to be used by applications. The only time it
13118 * should be used is when it is necessary for a #GtkWidget to assign focus
13119 * to a widget that is semantically owned by the first widget even though
13120 * it's not a direct child - for instance, a search entry in a floating
13121 * window similar to the quick search in #GtkTreeView.
13123 * An example of its usage is:
13126 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13128 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13129 * fevent->focus_change.in = TRUE;
13130 * fevent->focus_change.window = gtk_widget_get_window (widget);
13131 * if (fevent->focus_change.window != NULL)
13132 * g_object_ref (fevent->focus_change.window);
13134 * gtk_widget_send_focus_change (widget, fevent);
13136 * gdk_event_free (event);
13139 * Return value: the return value from the event signal emission: %TRUE
13140 * if the event was handled, and %FALSE otherwise
13145 gtk_widget_send_focus_change (GtkWidget *widget,
13150 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13151 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13153 g_object_ref (widget);
13155 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13157 res = gtk_widget_event (widget, event);
13159 g_object_notify (G_OBJECT (widget), "has-focus");
13161 g_object_unref (widget);
13167 * gtk_widget_in_destruction:
13168 * @widget: a #GtkWidget
13170 * Returns whether the widget is currently being destroyed.
13171 * This information can sometimes be used to avoid doing
13172 * unnecessary work.
13174 * Returns: %TRUE if @widget is being destroyed
13177 gtk_widget_in_destruction (GtkWidget *widget)
13179 return widget->priv->in_destruction;
13183 _gtk_widget_get_resize_pending (GtkWidget *widget)
13185 return widget->priv->resize_pending;
13189 _gtk_widget_set_resize_pending (GtkWidget *widget,
13190 gboolean resize_pending)
13192 widget->priv->resize_pending = resize_pending;
13196 _gtk_widget_get_in_reparent (GtkWidget *widget)
13198 return widget->priv->in_reparent;
13202 _gtk_widget_set_in_reparent (GtkWidget *widget,
13203 gboolean in_reparent)
13205 widget->priv->in_reparent = in_reparent;
13209 _gtk_widget_get_anchored (GtkWidget *widget)
13211 return widget->priv->anchored;
13215 _gtk_widget_set_anchored (GtkWidget *widget,
13218 widget->priv->anchored = anchored;
13222 _gtk_widget_get_shadowed (GtkWidget *widget)
13224 return widget->priv->shadowed;
13228 _gtk_widget_set_shadowed (GtkWidget *widget,
13231 widget->priv->shadowed = shadowed;
13235 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13237 return widget->priv->alloc_needed;
13241 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13242 gboolean alloc_needed)
13244 widget->priv->alloc_needed = alloc_needed;
13248 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13250 return widget->priv->width_request_needed;
13254 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13255 gboolean width_request_needed)
13257 widget->priv->width_request_needed = width_request_needed;
13261 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13263 return widget->priv->height_request_needed;
13267 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13268 gboolean height_request_needed)
13270 widget->priv->height_request_needed = height_request_needed;