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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include <gobject/gvaluecollector.h>
33 #include <gobject/gobjectnotifyqueue.c>
34 #include <cairo-gobject.h>
36 #include "gtkcontainer.h"
37 #include "gtkaccelmapprivate.h"
38 #include "gtkclipboard.h"
39 #include "gtkcssstylepropertyprivate.h"
40 #include "gtkcssnumbervalueprivate.h"
41 #include "gtkiconfactory.h"
43 #include "gtkmarshalers.h"
44 #include "gtkselectionprivate.h"
45 #include "gtksettingsprivate.h"
46 #include "gtksizegroup-private.h"
47 #include "gtksizerequestcacheprivate.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.h"
51 #include "gtkcontainerprivate.h"
52 #include "gtkbindings.h"
53 #include "gtkprivate.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
60 #include "gtkstylecontextprivate.h"
61 #include "gtkcssprovider.h"
62 #include "gtkmodifierstyle.h"
63 #include "gtkversion.h"
66 #include "gtktypebuiltins.h"
67 #include "a11y/gtkwidgetaccessible.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_widget_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="accessible-name">Clickable Button</property>
281 * ]]></programlisting>
284 * Finally, GtkWidget allows style information such as style classes to
285 * be associated with widgets, using the custom <style> element:
287 * <title>A UI definition fragment specifying an style class</title>
288 * <programlisting><![CDATA[
289 * <object class="GtkButton" id="button1">
291 * <class name="my-special-button-class"/>
292 * <class name="dark-button"/>
295 * ]]></programlisting>
301 /* Add flags here that should not be propagated to children. By default,
302 * all flags will be set on children (think prelight or active), but we
303 * might want to not do this for some.
305 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
306 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
308 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
310 #define GTK_STATE_FLAGS_BITS 9
312 struct _GtkWidgetPrivate
314 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
315 * (defined in "gtkenums.h").
317 guint state_flags : GTK_STATE_FLAGS_BITS;
321 guint in_destruction : 1;
324 guint composite_child : 1;
332 guint can_default : 1;
333 guint has_default : 1;
334 guint receives_default : 1;
337 guint style_update_pending : 1;
338 guint app_paintable : 1;
339 guint double_buffered : 1;
340 guint redraw_on_alloc : 1;
341 guint no_show_all : 1;
342 guint child_visible : 1;
343 guint multidevice : 1;
344 guint has_shape_mask : 1;
345 guint in_reparent : 1;
347 /* Queue-resize related flags */
348 guint alloc_needed : 1;
350 /* Expand-related flags */
351 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
352 guint computed_hexpand : 1; /* computed results (composite of child flags) */
353 guint computed_vexpand : 1;
354 guint hexpand : 1; /* application-forced expand */
356 guint hexpand_set : 1; /* whether to use application-forced */
357 guint vexpand_set : 1; /* instead of computing from children */
359 /* SizeGroup related flags */
360 guint have_size_groups : 1;
362 guint norender_children : 1;
363 guint norender : 1; /* Don't expose windows, instead recurse via draw */
368 /* The widget's name. If the widget does not have a name
369 * (the name is NULL), then its name (as returned by
370 * "gtk_widget_get_name") is its class's name.
371 * Among other things, the widget name is used to determine
372 * the style to use for a widget.
376 /* The list of attached windows to this widget.
377 * We keep a list in order to call reset_style to all of them,
379 GList *attached_windows;
381 /* The style for the widget. The style contains the
382 * colors the widget should be drawn in for each state
383 * along with graphics contexts used to draw with and
384 * the font to use for text.
387 GtkStyleContext *context;
389 /* Widget's path for styling */
392 /* The widget's allocated size */
393 GtkAllocation allocation;
395 /* The widget's requested sizes */
396 SizeRequestCache requests;
398 /* actions attached to this or any parent widget */
401 /* The widget's window or its parent window if it does
402 * not have a window. (Which will be indicated by the
403 * GTK_NO_WINDOW flag being set).
406 GList *registered_windows;
408 /* The widget's parent */
411 #ifdef G_ENABLE_DEBUG
412 /* Number of gtk_widget_push_verify_invariants () */
413 guint verifying_invariants_count;
414 #endif /* G_ENABLE_DEBUG */
417 struct _GtkWidgetClassPrivate
419 GType accessible_type;
420 AtkRole accessible_role;
449 BUTTON_RELEASE_EVENT,
463 PROPERTY_NOTIFY_EVENT,
464 SELECTION_CLEAR_EVENT,
465 SELECTION_REQUEST_EVENT,
466 SELECTION_NOTIFY_EVENT,
471 VISIBILITY_NOTIFY_EVENT,
485 ACCEL_CLOSURES_CHANGED,
510 PROP_RECEIVES_DEFAULT,
511 PROP_COMPOSITE_CHILD,
520 PROP_DOUBLE_BUFFERED,
535 typedef struct _GtkStateData GtkStateData;
540 guint flags_to_unset;
543 /* --- prototypes --- */
544 static void gtk_widget_base_class_init (gpointer g_class);
545 static void gtk_widget_class_init (GtkWidgetClass *klass);
546 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
547 static void gtk_widget_init (GtkWidget *widget);
548 static void gtk_widget_set_property (GObject *object,
552 static void gtk_widget_get_property (GObject *object,
556 static void gtk_widget_constructed (GObject *object);
557 static void gtk_widget_dispose (GObject *object);
558 static void gtk_widget_real_destroy (GtkWidget *object);
559 static void gtk_widget_finalize (GObject *object);
560 static void gtk_widget_real_show (GtkWidget *widget);
561 static void gtk_widget_real_hide (GtkWidget *widget);
562 static void gtk_widget_real_map (GtkWidget *widget);
563 static void gtk_widget_real_unmap (GtkWidget *widget);
564 static void gtk_widget_real_realize (GtkWidget *widget);
565 static void gtk_widget_real_unrealize (GtkWidget *widget);
566 static void gtk_widget_real_size_allocate (GtkWidget *widget,
567 GtkAllocation *allocation);
568 static void gtk_widget_real_style_set (GtkWidget *widget,
569 GtkStyle *previous_style);
570 static void gtk_widget_real_direction_changed(GtkWidget *widget,
571 GtkTextDirection previous_direction);
573 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
574 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
577 gboolean keyboard_tip,
578 GtkTooltip *tooltip);
579 static void gtk_widget_real_style_updated (GtkWidget *widget);
580 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
581 GtkWidgetHelpType help_type);
583 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
585 GParamSpec **pspecs);
586 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
588 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
590 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
591 GdkEventFocus *event);
592 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
593 GdkEventFocus *event);
594 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
595 GdkEventTouch *event);
596 static gboolean gtk_widget_real_focus (GtkWidget *widget,
597 GtkDirectionType direction);
598 static void gtk_widget_real_move_focus (GtkWidget *widget,
599 GtkDirectionType direction);
600 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
601 GtkDirectionType direction);
602 #ifdef G_ENABLE_DEBUG
603 static void gtk_widget_verify_invariants (GtkWidget *widget);
604 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
605 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
607 #define gtk_widget_verify_invariants(widget)
608 #define gtk_widget_push_verify_invariants(widget)
609 #define gtk_widget_pop_verify_invariants(widget)
611 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
612 static void gtk_widget_update_pango_context (GtkWidget *widget);
613 static void gtk_widget_propagate_state (GtkWidget *widget,
615 static void gtk_widget_update_alpha (GtkWidget *widget);
617 static gint gtk_widget_event_internal (GtkWidget *widget,
619 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
620 gboolean group_cycling);
621 static void gtk_widget_real_get_width (GtkWidget *widget,
624 static void gtk_widget_real_get_height (GtkWidget *widget,
627 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
629 gint *minimum_height,
630 gint *natural_height);
631 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
634 gint *natural_width);
635 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
636 GtkStateFlags old_state);
637 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
638 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
640 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
641 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
642 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
643 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
644 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
645 cairo_region_t *region);
646 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
647 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
650 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
651 gboolean has_tooltip,
653 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
654 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
656 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
657 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
659 const gchar *childname);
660 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
663 const GValue *value);
664 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
667 const gchar *tagname,
668 GMarkupParser *parser,
670 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
673 const gchar *tagname,
675 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
676 GtkBuilder *builder);
678 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
679 static void gtk_widget_real_get_width (GtkWidget *widget,
682 static void gtk_widget_real_get_height (GtkWidget *widget,
686 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
689 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
690 GtkOrientation orientation,
693 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
694 GtkOrientation orientation,
698 gint *allocated_size);
700 static void gtk_widget_set_usize_internal (GtkWidget *widget,
703 GtkQueueResizeFlags flags);
705 static void gtk_widget_add_events_internal (GtkWidget *widget,
708 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
712 static gboolean event_window_is_still_viewable (GdkEvent *event);
713 static void gtk_cairo_set_event (cairo_t *cr,
714 GdkEventExpose *event);
715 static void gtk_widget_propagate_alpha (GtkWidget *widget);
717 /* --- variables --- */
718 static gpointer gtk_widget_parent_class = NULL;
719 static guint widget_signals[LAST_SIGNAL] = { 0 };
720 static guint composite_child_stack = 0;
721 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
722 static GParamSpecPool *style_property_spec_pool = NULL;
724 static GQuark quark_property_parser = 0;
725 static GQuark quark_aux_info = 0;
726 static GQuark quark_accel_path = 0;
727 static GQuark quark_accel_closures = 0;
728 static GQuark quark_event_mask = 0;
729 static GQuark quark_device_event_mask = 0;
730 static GQuark quark_parent_window = 0;
731 static GQuark quark_pointer_window = 0;
732 static GQuark quark_shape_info = 0;
733 static GQuark quark_input_shape_info = 0;
734 static GQuark quark_pango_context = 0;
735 static GQuark quark_accessible_object = 0;
736 static GQuark quark_mnemonic_labels = 0;
737 static GQuark quark_tooltip_markup = 0;
738 static GQuark quark_has_tooltip = 0;
739 static GQuark quark_tooltip_window = 0;
740 static GQuark quark_visual = 0;
741 static GQuark quark_modifier_style = 0;
742 static GQuark quark_enabled_devices = 0;
743 static GQuark quark_size_groups = 0;
744 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
745 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
747 /* --- functions --- */
749 gtk_widget_get_type (void)
751 static GType widget_type = 0;
753 if (G_UNLIKELY (widget_type == 0))
755 const GTypeInfo widget_info =
757 sizeof (GtkWidgetClass),
758 gtk_widget_base_class_init,
759 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
760 (GClassInitFunc) gtk_widget_class_init,
761 NULL, /* class_finalize */
762 NULL, /* class_init */
765 (GInstanceInitFunc) gtk_widget_init,
766 NULL, /* value_table */
769 const GInterfaceInfo accessibility_info =
771 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
772 (GInterfaceFinalizeFunc) NULL,
773 NULL /* interface data */
776 const GInterfaceInfo buildable_info =
778 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
779 (GInterfaceFinalizeFunc) NULL,
780 NULL /* interface data */
783 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
784 &widget_info, G_TYPE_FLAG_ABSTRACT);
786 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
788 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
789 &accessibility_info) ;
790 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
798 gtk_widget_base_class_init (gpointer g_class)
800 GtkWidgetClass *klass = g_class;
802 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
806 child_property_notify_dispatcher (GObject *object,
810 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
813 /* We guard against the draw signal callbacks modifying the state of the
814 * cairo context by surounding it with save/restore.
815 * Maybe we should also cairo_new_path() just to be sure?
818 gtk_widget_draw_marshaller (GClosure *closure,
819 GValue *return_value,
820 guint n_param_values,
821 const GValue *param_values,
822 gpointer invocation_hint,
823 gpointer marshal_data)
825 GtkWidget *widget = g_value_get_object (¶m_values[0]);
826 GdkEventExpose *tmp_event;
828 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
831 tmp_event = _gtk_cairo_get_event (cr);
834 widget->priv->alpha != 255 &&
835 (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
839 cairo_push_group (cr);
840 gtk_cairo_set_event (cr, NULL);
843 _gtk_marshal_BOOLEAN__BOXED (closure,
853 cairo_pop_group_to_source (cr);
854 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
855 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
858 gtk_cairo_set_event (cr, tmp_event);
863 gtk_widget_draw_marshallerv (GClosure *closure,
864 GValue *return_value,
867 gpointer marshal_data,
871 GtkWidget *widget = GTK_WIDGET (instance);
872 GdkEventExpose *tmp_event;
877 G_VA_COPY (args_copy, args);
878 cr = va_arg (args_copy, gpointer);
881 tmp_event = _gtk_cairo_get_event (cr);
884 widget->priv->alpha != 255 &&
885 (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
889 cairo_push_group (cr);
890 gtk_cairo_set_event (cr, NULL);
893 _gtk_marshal_BOOLEAN__BOXEDv (closure,
904 cairo_pop_group_to_source (cr);
905 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
906 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
909 gtk_cairo_set_event (cr, tmp_event);
916 gtk_widget_class_init (GtkWidgetClass *klass)
918 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
919 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
920 GtkBindingSet *binding_set;
922 gtk_widget_parent_class = g_type_class_peek_parent (klass);
924 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
925 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
926 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
927 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
928 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
929 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
930 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
931 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
932 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
933 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
934 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
935 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
936 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
937 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
938 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
939 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
940 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
941 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
942 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
943 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
945 style_property_spec_pool = g_param_spec_pool_new (FALSE);
946 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
947 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
948 cpn_context.dispatcher = child_property_notify_dispatcher;
949 _gtk_widget_child_property_notify_context = &cpn_context;
951 gobject_class->constructed = gtk_widget_constructed;
952 gobject_class->dispose = gtk_widget_dispose;
953 gobject_class->finalize = gtk_widget_finalize;
954 gobject_class->set_property = gtk_widget_set_property;
955 gobject_class->get_property = gtk_widget_get_property;
957 klass->destroy = gtk_widget_real_destroy;
959 klass->activate_signal = 0;
960 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
961 klass->show = gtk_widget_real_show;
962 klass->show_all = gtk_widget_show;
963 klass->hide = gtk_widget_real_hide;
964 klass->map = gtk_widget_real_map;
965 klass->unmap = gtk_widget_real_unmap;
966 klass->realize = gtk_widget_real_realize;
967 klass->unrealize = gtk_widget_real_unrealize;
968 klass->size_allocate = gtk_widget_real_size_allocate;
969 klass->get_request_mode = gtk_widget_real_get_request_mode;
970 klass->get_preferred_width = gtk_widget_real_get_width;
971 klass->get_preferred_height = gtk_widget_real_get_height;
972 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
973 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
974 klass->state_changed = NULL;
975 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
976 klass->parent_set = NULL;
977 klass->hierarchy_changed = NULL;
978 klass->style_set = gtk_widget_real_style_set;
979 klass->direction_changed = gtk_widget_real_direction_changed;
980 klass->grab_notify = NULL;
981 klass->child_notify = NULL;
983 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
984 klass->grab_focus = gtk_widget_real_grab_focus;
985 klass->focus = gtk_widget_real_focus;
986 klass->move_focus = gtk_widget_real_move_focus;
987 klass->keynav_failed = gtk_widget_real_keynav_failed;
989 klass->button_press_event = NULL;
990 klass->button_release_event = NULL;
991 klass->motion_notify_event = NULL;
992 klass->touch_event = gtk_widget_real_touch_event;
993 klass->delete_event = NULL;
994 klass->destroy_event = NULL;
995 klass->key_press_event = gtk_widget_real_key_press_event;
996 klass->key_release_event = gtk_widget_real_key_release_event;
997 klass->enter_notify_event = NULL;
998 klass->leave_notify_event = NULL;
999 klass->configure_event = NULL;
1000 klass->focus_in_event = gtk_widget_real_focus_in_event;
1001 klass->focus_out_event = gtk_widget_real_focus_out_event;
1002 klass->map_event = NULL;
1003 klass->unmap_event = NULL;
1004 klass->window_state_event = NULL;
1005 klass->property_notify_event = _gtk_selection_property_notify;
1006 klass->selection_clear_event = _gtk_selection_clear;
1007 klass->selection_request_event = _gtk_selection_request;
1008 klass->selection_notify_event = _gtk_selection_notify;
1009 klass->selection_received = NULL;
1010 klass->proximity_in_event = NULL;
1011 klass->proximity_out_event = NULL;
1012 klass->drag_begin = NULL;
1013 klass->drag_end = NULL;
1014 klass->drag_data_delete = NULL;
1015 klass->drag_leave = NULL;
1016 klass->drag_motion = NULL;
1017 klass->drag_drop = NULL;
1018 klass->drag_data_received = NULL;
1019 klass->screen_changed = NULL;
1020 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1021 klass->grab_broken_event = NULL;
1022 klass->query_tooltip = gtk_widget_real_query_tooltip;
1023 klass->style_updated = gtk_widget_real_style_updated;
1025 klass->show_help = gtk_widget_real_show_help;
1027 /* Accessibility support */
1028 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1029 klass->priv->accessible_role = ATK_ROLE_INVALID;
1030 klass->get_accessible = gtk_widget_real_get_accessible;
1032 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1033 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1035 g_object_class_install_property (gobject_class,
1037 g_param_spec_string ("name",
1039 P_("The name of the widget"),
1041 GTK_PARAM_READWRITE));
1042 g_object_class_install_property (gobject_class,
1044 g_param_spec_object ("parent",
1045 P_("Parent widget"),
1046 P_("The parent widget of this widget. Must be a Container widget"),
1048 GTK_PARAM_READWRITE));
1050 g_object_class_install_property (gobject_class,
1052 g_param_spec_int ("width-request",
1053 P_("Width request"),
1054 P_("Override for width request of the widget, or -1 if natural request should be used"),
1058 GTK_PARAM_READWRITE));
1059 g_object_class_install_property (gobject_class,
1060 PROP_HEIGHT_REQUEST,
1061 g_param_spec_int ("height-request",
1062 P_("Height request"),
1063 P_("Override for height request of the widget, or -1 if natural request should be used"),
1067 GTK_PARAM_READWRITE));
1068 g_object_class_install_property (gobject_class,
1070 g_param_spec_boolean ("visible",
1072 P_("Whether the widget is visible"),
1074 GTK_PARAM_READWRITE));
1075 g_object_class_install_property (gobject_class,
1077 g_param_spec_boolean ("sensitive",
1079 P_("Whether the widget responds to input"),
1081 GTK_PARAM_READWRITE));
1082 g_object_class_install_property (gobject_class,
1084 g_param_spec_boolean ("app-paintable",
1085 P_("Application paintable"),
1086 P_("Whether the application will paint directly on the widget"),
1088 GTK_PARAM_READWRITE));
1089 g_object_class_install_property (gobject_class,
1091 g_param_spec_boolean ("can-focus",
1093 P_("Whether the widget can accept the input focus"),
1095 GTK_PARAM_READWRITE));
1096 g_object_class_install_property (gobject_class,
1098 g_param_spec_boolean ("has-focus",
1100 P_("Whether the widget has the input focus"),
1102 GTK_PARAM_READWRITE));
1103 g_object_class_install_property (gobject_class,
1105 g_param_spec_boolean ("is-focus",
1107 P_("Whether the widget is the focus widget within the toplevel"),
1109 GTK_PARAM_READWRITE));
1110 g_object_class_install_property (gobject_class,
1112 g_param_spec_boolean ("can-default",
1114 P_("Whether the widget can be the default widget"),
1116 GTK_PARAM_READWRITE));
1117 g_object_class_install_property (gobject_class,
1119 g_param_spec_boolean ("has-default",
1121 P_("Whether the widget is the default widget"),
1123 GTK_PARAM_READWRITE));
1124 g_object_class_install_property (gobject_class,
1125 PROP_RECEIVES_DEFAULT,
1126 g_param_spec_boolean ("receives-default",
1127 P_("Receives default"),
1128 P_("If TRUE, the widget will receive the default action when it is focused"),
1130 GTK_PARAM_READWRITE));
1131 g_object_class_install_property (gobject_class,
1132 PROP_COMPOSITE_CHILD,
1133 g_param_spec_boolean ("composite-child",
1134 P_("Composite child"),
1135 P_("Whether the widget is part of a composite widget"),
1137 GTK_PARAM_READABLE));
1138 g_object_class_install_property (gobject_class,
1140 g_param_spec_object ("style",
1142 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1144 GTK_PARAM_READWRITE));
1145 g_object_class_install_property (gobject_class,
1147 g_param_spec_flags ("events",
1149 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1150 GDK_TYPE_EVENT_MASK,
1152 GTK_PARAM_READWRITE));
1153 g_object_class_install_property (gobject_class,
1155 g_param_spec_boolean ("no-show-all",
1157 P_("Whether gtk_widget_show_all() should not affect this widget"),
1159 GTK_PARAM_READWRITE));
1162 * GtkWidget:has-tooltip:
1164 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1165 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1166 * the widget will be queried using #GtkWidget::query-tooltip to determine
1167 * whether it will provide a tooltip or not.
1169 * Note that setting this property to %TRUE for the first time will change
1170 * the event masks of the GdkWindows of this widget to include leave-notify
1171 * and motion-notify events. This cannot and will not be undone when the
1172 * property is set to %FALSE again.
1176 g_object_class_install_property (gobject_class,
1178 g_param_spec_boolean ("has-tooltip",
1180 P_("Whether this widget has a tooltip"),
1182 GTK_PARAM_READWRITE));
1184 * GtkWidget:tooltip-text:
1186 * Sets the text of tooltip to be the given string.
1188 * Also see gtk_tooltip_set_text().
1190 * This is a convenience property which will take care of getting the
1191 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1192 * will automatically be set to %TRUE and there will be taken care of
1193 * #GtkWidget::query-tooltip in the default signal handler.
1197 g_object_class_install_property (gobject_class,
1199 g_param_spec_string ("tooltip-text",
1201 P_("The contents of the tooltip for this widget"),
1203 GTK_PARAM_READWRITE));
1205 * GtkWidget:tooltip-markup:
1207 * Sets the text of tooltip to be the given string, which is marked up
1208 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1209 * Also see gtk_tooltip_set_markup().
1211 * This is a convenience property which will take care of getting the
1212 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1213 * will automatically be set to %TRUE and there will be taken care of
1214 * #GtkWidget::query-tooltip in the default signal handler.
1218 g_object_class_install_property (gobject_class,
1219 PROP_TOOLTIP_MARKUP,
1220 g_param_spec_string ("tooltip-markup",
1221 P_("Tooltip markup"),
1222 P_("The contents of the tooltip for this widget"),
1224 GTK_PARAM_READWRITE));
1229 * The widget's window if it is realized, %NULL otherwise.
1233 g_object_class_install_property (gobject_class,
1235 g_param_spec_object ("window",
1237 P_("The widget's window if it is realized"),
1239 GTK_PARAM_READABLE));
1242 * GtkWidget:double-buffered:
1244 * Whether the widget is double buffered.
1248 g_object_class_install_property (gobject_class,
1249 PROP_DOUBLE_BUFFERED,
1250 g_param_spec_boolean ("double-buffered",
1251 P_("Double Buffered"),
1252 P_("Whether the widget is double buffered"),
1254 GTK_PARAM_READWRITE));
1259 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1263 g_object_class_install_property (gobject_class,
1265 g_param_spec_enum ("halign",
1266 P_("Horizontal Alignment"),
1267 P_("How to position in extra horizontal space"),
1270 GTK_PARAM_READWRITE));
1275 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1279 g_object_class_install_property (gobject_class,
1281 g_param_spec_enum ("valign",
1282 P_("Vertical Alignment"),
1283 P_("How to position in extra vertical space"),
1286 GTK_PARAM_READWRITE));
1289 * GtkWidget:margin-left:
1291 * Margin on left side of widget.
1293 * This property adds margin outside of the widget's normal size
1294 * request, the margin will be added in addition to the size from
1295 * gtk_widget_set_size_request() for example.
1299 g_object_class_install_property (gobject_class,
1301 g_param_spec_int ("margin-left",
1302 P_("Margin on Left"),
1303 P_("Pixels of extra space on the left side"),
1307 GTK_PARAM_READWRITE));
1310 * GtkWidget:margin-right:
1312 * Margin on right side of widget.
1314 * This property adds margin outside of the widget's normal size
1315 * request, the margin will be added in addition to the size from
1316 * gtk_widget_set_size_request() for example.
1320 g_object_class_install_property (gobject_class,
1322 g_param_spec_int ("margin-right",
1323 P_("Margin on Right"),
1324 P_("Pixels of extra space on the right side"),
1328 GTK_PARAM_READWRITE));
1331 * GtkWidget:margin-top:
1333 * Margin on top side of widget.
1335 * This property adds margin outside of the widget's normal size
1336 * request, the margin will be added in addition to the size from
1337 * gtk_widget_set_size_request() for example.
1341 g_object_class_install_property (gobject_class,
1343 g_param_spec_int ("margin-top",
1344 P_("Margin on Top"),
1345 P_("Pixels of extra space on the top side"),
1349 GTK_PARAM_READWRITE));
1352 * GtkWidget:margin-bottom:
1354 * Margin on bottom side of widget.
1356 * This property adds margin outside of the widget's normal size
1357 * request, the margin will be added in addition to the size from
1358 * gtk_widget_set_size_request() for example.
1362 g_object_class_install_property (gobject_class,
1364 g_param_spec_int ("margin-bottom",
1365 P_("Margin on Bottom"),
1366 P_("Pixels of extra space on the bottom side"),
1370 GTK_PARAM_READWRITE));
1375 * Sets all four sides' margin at once. If read, returns max
1376 * margin on any side.
1380 g_object_class_install_property (gobject_class,
1382 g_param_spec_int ("margin",
1384 P_("Pixels of extra space on all four sides"),
1388 GTK_PARAM_READWRITE));
1391 * GtkWidget::destroy:
1392 * @object: the object which received the signal
1394 * Signals that all holders of a reference to the widget should release
1395 * the reference that they hold. May result in finalization of the widget
1396 * if all references are released.
1398 widget_signals[DESTROY] =
1399 g_signal_new (I_("destroy"),
1400 G_TYPE_FROM_CLASS (gobject_class),
1401 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1402 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1404 _gtk_marshal_VOID__VOID,
1408 * GtkWidget:hexpand:
1410 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1414 g_object_class_install_property (gobject_class,
1416 g_param_spec_boolean ("hexpand",
1417 P_("Horizontal Expand"),
1418 P_("Whether widget wants more horizontal space"),
1420 GTK_PARAM_READWRITE));
1423 * GtkWidget:hexpand-set:
1425 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1429 g_object_class_install_property (gobject_class,
1431 g_param_spec_boolean ("hexpand-set",
1432 P_("Horizontal Expand Set"),
1433 P_("Whether to use the hexpand property"),
1435 GTK_PARAM_READWRITE));
1438 * GtkWidget:vexpand:
1440 * Whether to expand vertically. See gtk_widget_set_vexpand().
1444 g_object_class_install_property (gobject_class,
1446 g_param_spec_boolean ("vexpand",
1447 P_("Vertical Expand"),
1448 P_("Whether widget wants more vertical space"),
1450 GTK_PARAM_READWRITE));
1453 * GtkWidget:vexpand-set:
1455 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1459 g_object_class_install_property (gobject_class,
1461 g_param_spec_boolean ("vexpand-set",
1462 P_("Vertical Expand Set"),
1463 P_("Whether to use the vexpand property"),
1465 GTK_PARAM_READWRITE));
1470 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1474 g_object_class_install_property (gobject_class,
1476 g_param_spec_boolean ("expand",
1478 P_("Whether widget wants to expand in both directions"),
1480 GTK_PARAM_READWRITE));
1483 * GtkWidget:opacity:
1485 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1486 * more details about window opacity.
1488 * Before 3.8 this was only availible in GtkWindow
1492 g_object_class_install_property (gobject_class,
1494 g_param_spec_double ("opacity",
1495 P_("Opacity for Widget"),
1496 P_("The opacity of the widget, from 0 to 1"),
1500 GTK_PARAM_READWRITE));
1503 * @widget: the object which received the signal.
1505 widget_signals[SHOW] =
1506 g_signal_new (I_("show"),
1507 G_TYPE_FROM_CLASS (gobject_class),
1509 G_STRUCT_OFFSET (GtkWidgetClass, show),
1511 _gtk_marshal_VOID__VOID,
1516 * @widget: the object which received the signal.
1518 widget_signals[HIDE] =
1519 g_signal_new (I_("hide"),
1520 G_TYPE_FROM_CLASS (gobject_class),
1522 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1524 _gtk_marshal_VOID__VOID,
1529 * @widget: the object which received the signal.
1531 widget_signals[MAP] =
1532 g_signal_new (I_("map"),
1533 G_TYPE_FROM_CLASS (gobject_class),
1535 G_STRUCT_OFFSET (GtkWidgetClass, map),
1537 _gtk_marshal_VOID__VOID,
1542 * @widget: the object which received the signal.
1544 widget_signals[UNMAP] =
1545 g_signal_new (I_("unmap"),
1546 G_TYPE_FROM_CLASS (gobject_class),
1548 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1550 _gtk_marshal_VOID__VOID,
1554 * GtkWidget::realize:
1555 * @widget: the object which received the signal.
1557 widget_signals[REALIZE] =
1558 g_signal_new (I_("realize"),
1559 G_TYPE_FROM_CLASS (gobject_class),
1561 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1563 _gtk_marshal_VOID__VOID,
1567 * GtkWidget::unrealize:
1568 * @widget: the object which received the signal.
1570 widget_signals[UNREALIZE] =
1571 g_signal_new (I_("unrealize"),
1572 G_TYPE_FROM_CLASS (gobject_class),
1574 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1576 _gtk_marshal_VOID__VOID,
1580 * GtkWidget::size-allocate:
1581 * @widget: the object which received the signal.
1584 widget_signals[SIZE_ALLOCATE] =
1585 g_signal_new (I_("size-allocate"),
1586 G_TYPE_FROM_CLASS (gobject_class),
1588 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1590 _gtk_marshal_VOID__BOXED,
1592 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1595 * GtkWidget::state-changed:
1596 * @widget: the object which received the signal.
1597 * @state: the previous state
1599 * The ::state-changed signal is emitted when the widget state changes.
1600 * See gtk_widget_get_state().
1602 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1604 widget_signals[STATE_CHANGED] =
1605 g_signal_new (I_("state-changed"),
1606 G_TYPE_FROM_CLASS (gobject_class),
1608 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1610 _gtk_marshal_VOID__ENUM,
1612 GTK_TYPE_STATE_TYPE);
1615 * GtkWidget::state-flags-changed:
1616 * @widget: the object which received the signal.
1617 * @flags: The previous state flags.
1619 * The ::state-flags-changed signal is emitted when the widget state
1620 * changes, see gtk_widget_get_state_flags().
1624 widget_signals[STATE_FLAGS_CHANGED] =
1625 g_signal_new (I_("state-flags-changed"),
1626 G_TYPE_FROM_CLASS (gobject_class),
1628 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1630 _gtk_marshal_VOID__FLAGS,
1632 GTK_TYPE_STATE_FLAGS);
1635 * GtkWidget::parent-set:
1636 * @widget: the object on which the signal is emitted
1637 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1638 * just got its initial parent.
1640 * The ::parent-set signal is emitted when a new parent
1641 * has been set on a widget.
1643 widget_signals[PARENT_SET] =
1644 g_signal_new (I_("parent-set"),
1645 G_TYPE_FROM_CLASS (gobject_class),
1647 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1649 _gtk_marshal_VOID__OBJECT,
1654 * GtkWidget::hierarchy-changed:
1655 * @widget: the object on which the signal is emitted
1656 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1657 * if the widget was previously unanchored
1659 * The ::hierarchy-changed signal is emitted when the
1660 * anchored state of a widget changes. A widget is
1661 * <firstterm>anchored</firstterm> when its toplevel
1662 * ancestor is a #GtkWindow. This signal is emitted when
1663 * a widget changes from un-anchored to anchored or vice-versa.
1665 widget_signals[HIERARCHY_CHANGED] =
1666 g_signal_new (I_("hierarchy-changed"),
1667 G_TYPE_FROM_CLASS (gobject_class),
1669 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1671 _gtk_marshal_VOID__OBJECT,
1676 * GtkWidget::style-set:
1677 * @widget: the object on which the signal is emitted
1678 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1679 * just got its initial style
1681 * The ::style-set signal is emitted when a new style has been set
1682 * on a widget. Note that style-modifying functions like
1683 * gtk_widget_modify_base() also cause this signal to be emitted.
1685 * Note that this signal is emitted for changes to the deprecated
1686 * #GtkStyle. To track changes to the #GtkStyleContext associated
1687 * with a widget, use the #GtkWidget::style-updated signal.
1689 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1691 widget_signals[STYLE_SET] =
1692 g_signal_new (I_("style-set"),
1693 G_TYPE_FROM_CLASS (gobject_class),
1695 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1697 _gtk_marshal_VOID__OBJECT,
1702 * GtkWidget::style-updated:
1703 * @widget: the object on which the signal is emitted
1705 * The ::style-updated signal is emitted when the #GtkStyleContext
1706 * of a widget is changed. Note that style-modifying functions like
1707 * gtk_widget_override_color() also cause this signal to be emitted.
1711 widget_signals[STYLE_UPDATED] =
1712 g_signal_new (I_("style-updated"),
1713 G_TYPE_FROM_CLASS (gobject_class),
1715 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1717 g_cclosure_marshal_VOID__VOID,
1721 * GtkWidget::direction-changed:
1722 * @widget: the object on which the signal is emitted
1723 * @previous_direction: the previous text direction of @widget
1725 * The ::direction-changed signal is emitted when the text direction
1726 * of a widget changes.
1728 widget_signals[DIRECTION_CHANGED] =
1729 g_signal_new (I_("direction-changed"),
1730 G_TYPE_FROM_CLASS (gobject_class),
1732 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1734 _gtk_marshal_VOID__ENUM,
1736 GTK_TYPE_TEXT_DIRECTION);
1739 * GtkWidget::grab-notify:
1740 * @widget: the object which received the signal
1741 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1742 * if it becomes unshadowed
1744 * The ::grab-notify signal is emitted when a widget becomes
1745 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1746 * another widget, or when it becomes unshadowed due to a grab
1749 * A widget is shadowed by a gtk_grab_add() when the topmost
1750 * grab widget in the grab stack of its window group is not
1753 widget_signals[GRAB_NOTIFY] =
1754 g_signal_new (I_("grab-notify"),
1755 G_TYPE_FROM_CLASS (gobject_class),
1757 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1759 _gtk_marshal_VOID__BOOLEAN,
1764 * GtkWidget::child-notify:
1765 * @widget: the object which received the signal
1766 * @child_property: the #GParamSpec of the changed child property
1768 * The ::child-notify signal is emitted for each
1769 * <link linkend="child-properties">child property</link> that has
1770 * changed on an object. The signal's detail holds the property name.
1772 widget_signals[CHILD_NOTIFY] =
1773 g_signal_new (I_("child-notify"),
1774 G_TYPE_FROM_CLASS (gobject_class),
1775 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1776 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1778 g_cclosure_marshal_VOID__PARAM,
1784 * @widget: the object which received the signal
1785 * @cr: the cairo context to draw to
1787 * This signal is emitted when a widget is supposed to render itself.
1788 * The @widget's top left corner must be painted at the origin of
1789 * the passed in context and be sized to the values returned by
1790 * gtk_widget_get_allocated_width() and
1791 * gtk_widget_get_allocated_height().
1793 * Signal handlers connected to this signal can modify the cairo
1794 * context passed as @cr in any way they like and don't need to
1795 * restore it. The signal emission takes care of calling cairo_save()
1796 * before and cairo_restore() after invoking the handler.
1798 * Returns: %TRUE to stop other handlers from being invoked for the event.
1799 % %FALSE to propagate the event further.
1803 widget_signals[DRAW] =
1804 g_signal_new (I_("draw"),
1805 G_TYPE_FROM_CLASS (gobject_class),
1807 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 gtk_widget_draw_marshaller,
1811 CAIRO_GOBJECT_TYPE_CONTEXT);
1812 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1813 gtk_widget_draw_marshallerv);
1816 * GtkWidget::mnemonic-activate:
1817 * @widget: the object which received the signal.
1820 * Returns: %TRUE to stop other handlers from being invoked for the event.
1821 * %FALSE to propagate the event further.
1823 widget_signals[MNEMONIC_ACTIVATE] =
1824 g_signal_new (I_("mnemonic-activate"),
1825 G_TYPE_FROM_CLASS (gobject_class),
1827 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1828 _gtk_boolean_handled_accumulator, NULL,
1829 _gtk_marshal_BOOLEAN__BOOLEAN,
1834 * GtkWidget::grab-focus:
1835 * @widget: the object which received the signal.
1837 widget_signals[GRAB_FOCUS] =
1838 g_signal_new (I_("grab-focus"),
1839 G_TYPE_FROM_CLASS (gobject_class),
1840 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1841 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1843 _gtk_marshal_VOID__VOID,
1848 * @widget: the object which received the signal.
1851 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1853 widget_signals[FOCUS] =
1854 g_signal_new (I_("focus"),
1855 G_TYPE_FROM_CLASS (klass),
1857 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1858 _gtk_boolean_handled_accumulator, NULL,
1859 _gtk_marshal_BOOLEAN__ENUM,
1861 GTK_TYPE_DIRECTION_TYPE);
1864 * GtkWidget::move-focus:
1865 * @widget: the object which received the signal.
1868 widget_signals[MOVE_FOCUS] =
1869 g_signal_new (I_("move-focus"),
1870 G_TYPE_FROM_CLASS (klass),
1871 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1872 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1874 _gtk_marshal_VOID__ENUM,
1877 GTK_TYPE_DIRECTION_TYPE);
1880 * GtkWidget::keynav-failed:
1881 * @widget: the object which received the signal
1882 * @direction: the direction of movement
1884 * Gets emitted if keyboard navigation fails.
1885 * See gtk_widget_keynav_failed() for details.
1887 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1888 * if the emitting widget should try to handle the keyboard
1889 * navigation attempt in its parent container(s).
1893 widget_signals[KEYNAV_FAILED] =
1894 g_signal_new (I_("keynav-failed"),
1895 G_TYPE_FROM_CLASS (klass),
1897 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1898 _gtk_boolean_handled_accumulator, NULL,
1899 _gtk_marshal_BOOLEAN__ENUM,
1901 GTK_TYPE_DIRECTION_TYPE);
1905 * @widget: the object which received the signal.
1906 * @event: the #GdkEvent which triggered this signal
1908 * The GTK+ main loop will emit three signals for each GDK event delivered
1909 * to a widget: one generic ::event signal, another, more specific,
1910 * signal that matches the type of event delivered (e.g.
1911 * #GtkWidget::key-press-event) and finally a generic
1912 * #GtkWidget::event-after signal.
1914 * Returns: %TRUE to stop other handlers from being invoked for the event
1915 * and to cancel the emission of the second specific ::event signal.
1916 * %FALSE to propagate the event further and to allow the emission of
1917 * the second signal. The ::event-after signal is emitted regardless of
1920 widget_signals[EVENT] =
1921 g_signal_new (I_("event"),
1922 G_TYPE_FROM_CLASS (klass),
1924 G_STRUCT_OFFSET (GtkWidgetClass, event),
1925 _gtk_boolean_handled_accumulator, NULL,
1926 _gtk_marshal_BOOLEAN__BOXED,
1928 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1929 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1930 _gtk_marshal_BOOLEAN__BOXEDv);
1933 * GtkWidget::event-after:
1934 * @widget: the object which received the signal.
1935 * @event: the #GdkEvent which triggered this signal
1937 * After the emission of the #GtkWidget::event signal and (optionally)
1938 * the second more specific signal, ::event-after will be emitted
1939 * regardless of the previous two signals handlers return values.
1942 widget_signals[EVENT_AFTER] =
1943 g_signal_new (I_("event-after"),
1944 G_TYPE_FROM_CLASS (klass),
1948 _gtk_marshal_VOID__BOXED,
1950 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1951 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1952 _gtk_marshal_BOOLEAN__BOXEDv);
1955 * GtkWidget::button-press-event:
1956 * @widget: the object which received the signal.
1957 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1960 * The ::button-press-event signal will be emitted when a button
1961 * (typically from a mouse) is pressed.
1963 * To receive this signal, the #GdkWindow associated to the
1964 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1966 * This signal will be sent to the grab widget if there is one.
1968 * Returns: %TRUE to stop other handlers from being invoked for the event.
1969 * %FALSE to propagate the event further.
1971 widget_signals[BUTTON_PRESS_EVENT] =
1972 g_signal_new (I_("button-press-event"),
1973 G_TYPE_FROM_CLASS (klass),
1975 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1976 _gtk_boolean_handled_accumulator, NULL,
1977 _gtk_marshal_BOOLEAN__BOXED,
1979 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1980 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1981 _gtk_marshal_BOOLEAN__BOXEDv);
1984 * GtkWidget::button-release-event:
1985 * @widget: the object which received the signal.
1986 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1989 * The ::button-release-event signal will be emitted when a button
1990 * (typically from a mouse) is released.
1992 * To receive this signal, the #GdkWindow associated to the
1993 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1995 * This signal will be sent to the grab widget if there is one.
1997 * Returns: %TRUE to stop other handlers from being invoked for the event.
1998 * %FALSE to propagate the event further.
2000 widget_signals[BUTTON_RELEASE_EVENT] =
2001 g_signal_new (I_("button-release-event"),
2002 G_TYPE_FROM_CLASS (klass),
2004 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__BOXED,
2008 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2009 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2010 _gtk_marshal_BOOLEAN__BOXEDv);
2012 widget_signals[TOUCH_EVENT] =
2013 g_signal_new (I_("touch-event"),
2014 G_TYPE_FROM_CLASS (klass),
2016 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2017 _gtk_boolean_handled_accumulator, NULL,
2018 _gtk_marshal_BOOLEAN__BOXED,
2020 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2021 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2022 _gtk_marshal_BOOLEAN__BOXEDv);
2025 * GtkWidget::scroll-event:
2026 * @widget: the object which received the signal.
2027 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2030 * The ::scroll-event signal is emitted when a button in the 4 to 7
2031 * range is pressed. Wheel mice are usually configured to generate
2032 * button press events for buttons 4 and 5 when the wheel is turned.
2034 * To receive this signal, the #GdkWindow associated to the widget needs
2035 * to enable the #GDK_SCROLL_MASK mask.
2037 * This signal will be sent to the grab widget if there is one.
2039 * Returns: %TRUE to stop other handlers from being invoked for the event.
2040 * %FALSE to propagate the event further.
2042 widget_signals[SCROLL_EVENT] =
2043 g_signal_new (I_("scroll-event"),
2044 G_TYPE_FROM_CLASS (klass),
2046 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2047 _gtk_boolean_handled_accumulator, NULL,
2048 _gtk_marshal_BOOLEAN__BOXED,
2050 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2051 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2052 _gtk_marshal_BOOLEAN__BOXEDv);
2055 * GtkWidget::motion-notify-event:
2056 * @widget: the object which received the signal.
2057 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2060 * The ::motion-notify-event signal is emitted when the pointer moves
2061 * over the widget's #GdkWindow.
2063 * To receive this signal, the #GdkWindow associated to the widget
2064 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2066 * This signal will be sent to the grab widget if there is one.
2068 * Returns: %TRUE to stop other handlers from being invoked for the event.
2069 * %FALSE to propagate the event further.
2071 widget_signals[MOTION_NOTIFY_EVENT] =
2072 g_signal_new (I_("motion-notify-event"),
2073 G_TYPE_FROM_CLASS (klass),
2075 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2076 _gtk_boolean_handled_accumulator, NULL,
2077 _gtk_marshal_BOOLEAN__BOXED,
2079 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2080 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2081 _gtk_marshal_BOOLEAN__BOXEDv);
2084 * GtkWidget::composited-changed:
2085 * @widget: the object on which the signal is emitted
2087 * The ::composited-changed signal is emitted when the composited
2088 * status of @widget<!-- -->s screen changes.
2089 * See gdk_screen_is_composited().
2091 widget_signals[COMPOSITED_CHANGED] =
2092 g_signal_new (I_("composited-changed"),
2093 G_TYPE_FROM_CLASS (klass),
2094 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2095 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2097 _gtk_marshal_VOID__VOID,
2101 * GtkWidget::delete-event:
2102 * @widget: the object which received the signal
2103 * @event: the event which triggered this signal
2105 * The ::delete-event signal is emitted if a user requests that
2106 * a toplevel window is closed. The default handler for this signal
2107 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2108 * this signal will cause the window to be hidden instead, so that
2109 * it can later be shown again without reconstructing it.
2111 * Returns: %TRUE to stop other handlers from being invoked for the event.
2112 * %FALSE to propagate the event further.
2114 widget_signals[DELETE_EVENT] =
2115 g_signal_new (I_("delete-event"),
2116 G_TYPE_FROM_CLASS (klass),
2118 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2119 _gtk_boolean_handled_accumulator, NULL,
2120 _gtk_marshal_BOOLEAN__BOXED,
2122 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2123 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2124 _gtk_marshal_BOOLEAN__BOXEDv);
2127 * GtkWidget::destroy-event:
2128 * @widget: the object which received the signal.
2129 * @event: the event which triggered this signal
2131 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2132 * You rarely get this signal, because most widgets disconnect themselves
2133 * from their window before they destroy it, so no widget owns the
2134 * window at destroy time.
2136 * To receive this signal, the #GdkWindow associated to the widget needs
2137 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2138 * automatically for all new windows.
2140 * Returns: %TRUE to stop other handlers from being invoked for the event.
2141 * %FALSE to propagate the event further.
2143 widget_signals[DESTROY_EVENT] =
2144 g_signal_new (I_("destroy-event"),
2145 G_TYPE_FROM_CLASS (klass),
2147 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2148 _gtk_boolean_handled_accumulator, NULL,
2149 _gtk_marshal_BOOLEAN__BOXED,
2151 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2152 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2153 _gtk_marshal_BOOLEAN__BOXEDv);
2156 * GtkWidget::key-press-event:
2157 * @widget: the object which received the signal
2158 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2160 * The ::key-press-event signal is emitted when a key is pressed. The signal
2161 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2163 * To receive this signal, the #GdkWindow associated to the widget needs
2164 * to enable the #GDK_KEY_PRESS_MASK mask.
2166 * This signal will be sent to the grab widget if there is one.
2168 * Returns: %TRUE to stop other handlers from being invoked for the event.
2169 * %FALSE to propagate the event further.
2171 widget_signals[KEY_PRESS_EVENT] =
2172 g_signal_new (I_("key-press-event"),
2173 G_TYPE_FROM_CLASS (klass),
2175 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2176 _gtk_boolean_handled_accumulator, NULL,
2177 _gtk_marshal_BOOLEAN__BOXED,
2179 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2180 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2181 _gtk_marshal_BOOLEAN__BOXEDv);
2184 * GtkWidget::key-release-event:
2185 * @widget: the object which received the signal
2186 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2188 * The ::key-release-event signal is emitted when a key is released.
2190 * To receive this signal, the #GdkWindow associated to the widget needs
2191 * to enable the #GDK_KEY_RELEASE_MASK mask.
2193 * This signal will be sent to the grab widget if there is one.
2195 * Returns: %TRUE to stop other handlers from being invoked for the event.
2196 * %FALSE to propagate the event further.
2198 widget_signals[KEY_RELEASE_EVENT] =
2199 g_signal_new (I_("key-release-event"),
2200 G_TYPE_FROM_CLASS (klass),
2202 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2203 _gtk_boolean_handled_accumulator, NULL,
2204 _gtk_marshal_BOOLEAN__BOXED,
2206 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2207 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2208 _gtk_marshal_BOOLEAN__BOXEDv);
2211 * GtkWidget::enter-notify-event:
2212 * @widget: the object which received the signal
2213 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2216 * The ::enter-notify-event will be emitted when the pointer enters
2217 * the @widget's window.
2219 * To receive this signal, the #GdkWindow associated to the widget needs
2220 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2222 * This signal will be sent to the grab widget if there is one.
2224 * Returns: %TRUE to stop other handlers from being invoked for the event.
2225 * %FALSE to propagate the event further.
2227 widget_signals[ENTER_NOTIFY_EVENT] =
2228 g_signal_new (I_("enter-notify-event"),
2229 G_TYPE_FROM_CLASS (klass),
2231 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2232 _gtk_boolean_handled_accumulator, NULL,
2233 _gtk_marshal_BOOLEAN__BOXED,
2235 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2236 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2237 _gtk_marshal_BOOLEAN__BOXEDv);
2240 * GtkWidget::leave-notify-event:
2241 * @widget: the object which received the signal
2242 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2245 * The ::leave-notify-event will be emitted when the pointer leaves
2246 * the @widget's window.
2248 * To receive this signal, the #GdkWindow associated to the widget needs
2249 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2251 * This signal will be sent to the grab widget if there is one.
2253 * Returns: %TRUE to stop other handlers from being invoked for the event.
2254 * %FALSE to propagate the event further.
2256 widget_signals[LEAVE_NOTIFY_EVENT] =
2257 g_signal_new (I_("leave-notify-event"),
2258 G_TYPE_FROM_CLASS (klass),
2260 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2261 _gtk_boolean_handled_accumulator, NULL,
2262 _gtk_marshal_BOOLEAN__BOXED,
2264 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2265 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2266 _gtk_marshal_BOOLEAN__BOXEDv);
2269 * GtkWidget::configure-event:
2270 * @widget: the object which received the signal
2271 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2274 * The ::configure-event signal will be emitted when the size, position or
2275 * stacking of the @widget's window has changed.
2277 * To receive this signal, the #GdkWindow associated to the widget needs
2278 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2279 * automatically for all new windows.
2281 * Returns: %TRUE to stop other handlers from being invoked for the event.
2282 * %FALSE to propagate the event further.
2284 widget_signals[CONFIGURE_EVENT] =
2285 g_signal_new (I_("configure-event"),
2286 G_TYPE_FROM_CLASS (klass),
2288 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2289 _gtk_boolean_handled_accumulator, NULL,
2290 _gtk_marshal_BOOLEAN__BOXED,
2292 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2293 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2294 _gtk_marshal_BOOLEAN__BOXEDv);
2297 * GtkWidget::focus-in-event:
2298 * @widget: the object which received the signal
2299 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2302 * The ::focus-in-event signal will be emitted when the keyboard focus
2303 * enters the @widget's window.
2305 * To receive this signal, the #GdkWindow associated to the widget needs
2306 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2308 * Returns: %TRUE to stop other handlers from being invoked for the event.
2309 * %FALSE to propagate the event further.
2311 widget_signals[FOCUS_IN_EVENT] =
2312 g_signal_new (I_("focus-in-event"),
2313 G_TYPE_FROM_CLASS (klass),
2315 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2316 _gtk_boolean_handled_accumulator, NULL,
2317 _gtk_marshal_BOOLEAN__BOXED,
2319 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2320 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2321 _gtk_marshal_BOOLEAN__BOXEDv);
2324 * GtkWidget::focus-out-event:
2325 * @widget: the object which received the signal
2326 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2329 * The ::focus-out-event signal will be emitted when the keyboard focus
2330 * leaves the @widget's window.
2332 * To receive this signal, the #GdkWindow associated to the widget needs
2333 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2335 * Returns: %TRUE to stop other handlers from being invoked for the event.
2336 * %FALSE to propagate the event further.
2338 widget_signals[FOCUS_OUT_EVENT] =
2339 g_signal_new (I_("focus-out-event"),
2340 G_TYPE_FROM_CLASS (klass),
2342 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2343 _gtk_boolean_handled_accumulator, NULL,
2344 _gtk_marshal_BOOLEAN__BOXED,
2346 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2347 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2348 _gtk_marshal_BOOLEAN__BOXEDv);
2351 * GtkWidget::map-event:
2352 * @widget: the object which received the signal
2353 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2355 * The ::map-event signal will be emitted when the @widget's window is
2356 * mapped. A window is mapped when it becomes visible on the screen.
2358 * To receive this signal, the #GdkWindow associated to the widget needs
2359 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2360 * automatically for all new windows.
2362 * Returns: %TRUE to stop other handlers from being invoked for the event.
2363 * %FALSE to propagate the event further.
2365 widget_signals[MAP_EVENT] =
2366 g_signal_new (I_("map-event"),
2367 G_TYPE_FROM_CLASS (klass),
2369 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2370 _gtk_boolean_handled_accumulator, NULL,
2371 _gtk_marshal_BOOLEAN__BOXED,
2373 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2374 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2375 _gtk_marshal_BOOLEAN__BOXEDv);
2378 * GtkWidget::unmap-event:
2379 * @widget: the object which received the signal
2380 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2382 * The ::unmap-event signal will be emitted when the @widget's window is
2383 * unmapped. A window is unmapped when it becomes invisible on the screen.
2385 * To receive this signal, the #GdkWindow associated to the widget needs
2386 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2387 * automatically for all new windows.
2389 * Returns: %TRUE to stop other handlers from being invoked for the event.
2390 * %FALSE to propagate the event further.
2392 widget_signals[UNMAP_EVENT] =
2393 g_signal_new (I_("unmap-event"),
2394 G_TYPE_FROM_CLASS (klass),
2396 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2397 _gtk_boolean_handled_accumulator, NULL,
2398 _gtk_marshal_BOOLEAN__BOXED,
2400 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2401 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2402 _gtk_marshal_BOOLEAN__BOXEDv);
2405 * GtkWidget::property-notify-event:
2406 * @widget: the object which received the signal
2407 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2410 * The ::property-notify-event signal will be emitted when a property on
2411 * the @widget's window has been changed or deleted.
2413 * To receive this signal, the #GdkWindow associated to the widget needs
2414 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2416 * Returns: %TRUE to stop other handlers from being invoked for the event.
2417 * %FALSE to propagate the event further.
2419 widget_signals[PROPERTY_NOTIFY_EVENT] =
2420 g_signal_new (I_("property-notify-event"),
2421 G_TYPE_FROM_CLASS (klass),
2423 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2424 _gtk_boolean_handled_accumulator, NULL,
2425 _gtk_marshal_BOOLEAN__BOXED,
2427 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2428 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2429 _gtk_marshal_BOOLEAN__BOXEDv);
2432 * GtkWidget::selection-clear-event:
2433 * @widget: the object which received the signal
2434 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2437 * The ::selection-clear-event signal will be emitted when the
2438 * the @widget's window has lost ownership of a selection.
2440 * Returns: %TRUE to stop other handlers from being invoked for the event.
2441 * %FALSE to propagate the event further.
2443 widget_signals[SELECTION_CLEAR_EVENT] =
2444 g_signal_new (I_("selection-clear-event"),
2445 G_TYPE_FROM_CLASS (klass),
2447 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2448 _gtk_boolean_handled_accumulator, NULL,
2449 _gtk_marshal_BOOLEAN__BOXED,
2451 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2452 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2453 _gtk_marshal_BOOLEAN__BOXEDv);
2456 * GtkWidget::selection-request-event:
2457 * @widget: the object which received the signal
2458 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2461 * The ::selection-request-event signal will be emitted when
2462 * another client requests ownership of the selection owned by
2463 * the @widget's window.
2465 * Returns: %TRUE to stop other handlers from being invoked for the event.
2466 * %FALSE to propagate the event further.
2468 widget_signals[SELECTION_REQUEST_EVENT] =
2469 g_signal_new (I_("selection-request-event"),
2470 G_TYPE_FROM_CLASS (klass),
2472 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2473 _gtk_boolean_handled_accumulator, NULL,
2474 _gtk_marshal_BOOLEAN__BOXED,
2476 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2477 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2478 _gtk_marshal_BOOLEAN__BOXEDv);
2481 * GtkWidget::selection-notify-event:
2482 * @widget: the object which received the signal.
2483 * @event: (type Gdk.EventSelection):
2485 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2487 widget_signals[SELECTION_NOTIFY_EVENT] =
2488 g_signal_new (I_("selection-notify-event"),
2489 G_TYPE_FROM_CLASS (klass),
2491 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2492 _gtk_boolean_handled_accumulator, NULL,
2493 _gtk_marshal_BOOLEAN__BOXED,
2495 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2496 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2497 _gtk_marshal_BOOLEAN__BOXEDv);
2500 * GtkWidget::selection-received:
2501 * @widget: the object which received the signal.
2505 widget_signals[SELECTION_RECEIVED] =
2506 g_signal_new (I_("selection-received"),
2507 G_TYPE_FROM_CLASS (klass),
2509 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2511 _gtk_marshal_VOID__BOXED_UINT,
2513 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2517 * GtkWidget::selection-get:
2518 * @widget: the object which received the signal.
2523 widget_signals[SELECTION_GET] =
2524 g_signal_new (I_("selection-get"),
2525 G_TYPE_FROM_CLASS (klass),
2527 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2529 _gtk_marshal_VOID__BOXED_UINT_UINT,
2531 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2536 * GtkWidget::proximity-in-event:
2537 * @widget: the object which received the signal
2538 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2541 * To receive this signal the #GdkWindow associated to the widget needs
2542 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2544 * This signal will be sent to the grab widget if there is one.
2546 * Returns: %TRUE to stop other handlers from being invoked for the event.
2547 * %FALSE to propagate the event further.
2549 widget_signals[PROXIMITY_IN_EVENT] =
2550 g_signal_new (I_("proximity-in-event"),
2551 G_TYPE_FROM_CLASS (klass),
2553 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2554 _gtk_boolean_handled_accumulator, NULL,
2555 _gtk_marshal_BOOLEAN__BOXED,
2557 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2558 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2559 _gtk_marshal_BOOLEAN__BOXEDv);
2562 * GtkWidget::proximity-out-event:
2563 * @widget: the object which received the signal
2564 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2567 * To receive this signal the #GdkWindow associated to the widget needs
2568 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2570 * This signal will be sent to the grab widget if there is one.
2572 * Returns: %TRUE to stop other handlers from being invoked for the event.
2573 * %FALSE to propagate the event further.
2575 widget_signals[PROXIMITY_OUT_EVENT] =
2576 g_signal_new (I_("proximity-out-event"),
2577 G_TYPE_FROM_CLASS (klass),
2579 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2580 _gtk_boolean_handled_accumulator, NULL,
2581 _gtk_marshal_BOOLEAN__BOXED,
2583 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2584 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2585 _gtk_marshal_BOOLEAN__BOXEDv);
2588 * GtkWidget::drag-leave:
2589 * @widget: the object which received the signal.
2590 * @context: the drag context
2591 * @time: the timestamp of the motion event
2593 * The ::drag-leave signal is emitted on the drop site when the cursor
2594 * leaves the widget. A typical reason to connect to this signal is to
2595 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2596 * with gtk_drag_unhighlight()
2598 widget_signals[DRAG_LEAVE] =
2599 g_signal_new (I_("drag-leave"),
2600 G_TYPE_FROM_CLASS (klass),
2602 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2604 _gtk_marshal_VOID__OBJECT_UINT,
2606 GDK_TYPE_DRAG_CONTEXT,
2610 * GtkWidget::drag-begin:
2611 * @widget: the object which received the signal
2612 * @context: the drag context
2614 * The ::drag-begin signal is emitted on the drag source when a drag is
2615 * started. A typical reason to connect to this signal is to set up a
2616 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2618 * Note that some widgets set up a drag icon in the default handler of
2619 * this signal, so you may have to use g_signal_connect_after() to
2620 * override what the default handler did.
2622 widget_signals[DRAG_BEGIN] =
2623 g_signal_new (I_("drag-begin"),
2624 G_TYPE_FROM_CLASS (klass),
2626 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2628 _gtk_marshal_VOID__OBJECT,
2630 GDK_TYPE_DRAG_CONTEXT);
2633 * GtkWidget::drag-end:
2634 * @widget: the object which received the signal
2635 * @context: the drag context
2637 * The ::drag-end signal is emitted on the drag source when a drag is
2638 * finished. A typical reason to connect to this signal is to undo
2639 * things done in #GtkWidget::drag-begin.
2641 widget_signals[DRAG_END] =
2642 g_signal_new (I_("drag-end"),
2643 G_TYPE_FROM_CLASS (klass),
2645 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2647 _gtk_marshal_VOID__OBJECT,
2649 GDK_TYPE_DRAG_CONTEXT);
2652 * GtkWidget::drag-data-delete:
2653 * @widget: the object which received the signal
2654 * @context: the drag context
2656 * The ::drag-data-delete signal is emitted on the drag source when a drag
2657 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2658 * handler is responsible for deleting the data that has been dropped. What
2659 * "delete" means depends on the context of the drag operation.
2661 widget_signals[DRAG_DATA_DELETE] =
2662 g_signal_new (I_("drag-data-delete"),
2663 G_TYPE_FROM_CLASS (klass),
2665 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2667 _gtk_marshal_VOID__OBJECT,
2669 GDK_TYPE_DRAG_CONTEXT);
2672 * GtkWidget::drag-failed:
2673 * @widget: the object which received the signal
2674 * @context: the drag context
2675 * @result: the result of the drag operation
2677 * The ::drag-failed signal is emitted on the drag source when a drag has
2678 * failed. The signal handler may hook custom code to handle a failed DND
2679 * operation based on the type of error, it returns %TRUE is the failure has
2680 * been already handled (not showing the default "drag operation failed"
2681 * animation), otherwise it returns %FALSE.
2683 * Return value: %TRUE if the failed drag operation has been already handled.
2687 widget_signals[DRAG_FAILED] =
2688 g_signal_new (I_("drag-failed"),
2689 G_TYPE_FROM_CLASS (klass),
2691 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2692 _gtk_boolean_handled_accumulator, NULL,
2693 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2695 GDK_TYPE_DRAG_CONTEXT,
2696 GTK_TYPE_DRAG_RESULT);
2699 * GtkWidget::drag-motion:
2700 * @widget: the object which received the signal
2701 * @context: the drag context
2702 * @x: the x coordinate of the current cursor position
2703 * @y: the y coordinate of the current cursor position
2704 * @time: the timestamp of the motion event
2706 * The ::drag-motion signal is emitted on the drop site when the user
2707 * moves the cursor over the widget during a drag. The signal handler
2708 * must determine whether the cursor position is in a drop zone or not.
2709 * If it is not in a drop zone, it returns %FALSE and no further processing
2710 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2711 * handler is responsible for providing the necessary information for
2712 * displaying feedback to the user, by calling gdk_drag_status().
2714 * If the decision whether the drop will be accepted or rejected can't be
2715 * made based solely on the cursor position and the type of the data, the
2716 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2717 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2718 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2719 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2720 * when using the drag-motion signal that way.
2722 * Also note that there is no drag-enter signal. The drag receiver has to
2723 * keep track of whether he has received any drag-motion signals since the
2724 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2725 * an "enter" signal. Upon an "enter", the handler will typically highlight
2726 * the drop site with gtk_drag_highlight().
2729 * drag_motion (GtkWidget *widget,
2730 * GdkDragContext *context,
2737 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2739 * if (!private_data->drag_highlight)
2741 * private_data->drag_highlight = 1;
2742 * gtk_drag_highlight (widget);
2745 * target = gtk_drag_dest_find_target (widget, context, NULL);
2746 * if (target == GDK_NONE)
2747 * gdk_drag_status (context, 0, time);
2750 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2751 * gtk_drag_get_data (widget, context, target, time);
2758 * drag_data_received (GtkWidget *widget,
2759 * GdkDragContext *context,
2762 * GtkSelectionData *selection_data,
2766 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2768 * if (private_data->suggested_action)
2770 * private_data->suggested_action = 0;
2772 * /* We are getting this data due to a request in drag_motion,
2773 * * rather than due to a request in drag_drop, so we are just
2774 * * supposed to call gdk_drag_status(), not actually paste in
2777 * str = gtk_selection_data_get_text (selection_data);
2778 * if (!data_is_acceptable (str))
2779 * gdk_drag_status (context, 0, time);
2781 * gdk_drag_status (context, private_data->suggested_action, time);
2785 * /* accept the drop */
2790 * Returns: whether the cursor position is in a drop zone
2792 widget_signals[DRAG_MOTION] =
2793 g_signal_new (I_("drag-motion"),
2794 G_TYPE_FROM_CLASS (klass),
2796 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2797 _gtk_boolean_handled_accumulator, NULL,
2798 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2800 GDK_TYPE_DRAG_CONTEXT,
2806 * GtkWidget::drag-drop:
2807 * @widget: the object which received the signal
2808 * @context: the drag context
2809 * @x: the x coordinate of the current cursor position
2810 * @y: the y coordinate of the current cursor position
2811 * @time: the timestamp of the motion event
2813 * The ::drag-drop signal is emitted on the drop site when the user drops
2814 * the data onto the widget. The signal handler must determine whether
2815 * the cursor position is in a drop zone or not. If it is not in a drop
2816 * zone, it returns %FALSE and no further processing is necessary.
2817 * Otherwise, the handler returns %TRUE. In this case, the handler must
2818 * ensure that gtk_drag_finish() is called to let the source know that
2819 * the drop is done. The call to gtk_drag_finish() can be done either
2820 * directly or in a #GtkWidget::drag-data-received handler which gets
2821 * triggered by calling gtk_drag_get_data() to receive the data for one
2822 * or more of the supported targets.
2824 * Returns: whether the cursor position is in a drop zone
2826 widget_signals[DRAG_DROP] =
2827 g_signal_new (I_("drag-drop"),
2828 G_TYPE_FROM_CLASS (klass),
2830 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2831 _gtk_boolean_handled_accumulator, NULL,
2832 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2834 GDK_TYPE_DRAG_CONTEXT,
2840 * GtkWidget::drag-data-get:
2841 * @widget: the object which received the signal
2842 * @context: the drag context
2843 * @data: the #GtkSelectionData to be filled with the dragged data
2844 * @info: the info that has been registered with the target in the
2846 * @time: the timestamp at which the data was requested
2848 * The ::drag-data-get signal is emitted on the drag source when the drop
2849 * site requests the data which is dragged. It is the responsibility of
2850 * the signal handler to fill @data with the data in the format which
2851 * is indicated by @info. See gtk_selection_data_set() and
2852 * gtk_selection_data_set_text().
2854 widget_signals[DRAG_DATA_GET] =
2855 g_signal_new (I_("drag-data-get"),
2856 G_TYPE_FROM_CLASS (klass),
2858 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2860 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2862 GDK_TYPE_DRAG_CONTEXT,
2863 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2868 * GtkWidget::drag-data-received:
2869 * @widget: the object which received the signal
2870 * @context: the drag context
2871 * @x: where the drop happened
2872 * @y: where the drop happened
2873 * @data: the received data
2874 * @info: the info that has been registered with the target in the
2876 * @time: the timestamp at which the data was received
2878 * The ::drag-data-received signal is emitted on the drop site when the
2879 * dragged data has been received. If the data was received in order to
2880 * determine whether the drop will be accepted, the handler is expected
2881 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2882 * If the data was received in response to a #GtkWidget::drag-drop signal
2883 * (and this is the last target to be received), the handler for this
2884 * signal is expected to process the received data and then call
2885 * gtk_drag_finish(), setting the @success parameter depending on
2886 * whether the data was processed successfully.
2888 * The handler may inspect the selected action with
2889 * gdk_drag_context_get_selected_action() before calling
2890 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2891 * shown in the following example:
2894 * drag_data_received (GtkWidget *widget,
2895 * GdkDragContext *context,
2898 * GtkSelectionData *data,
2902 * if ((data->length >= 0) && (data->format == 8))
2904 * GdkDragAction action;
2906 * /* handle data here */
2908 * action = gdk_drag_context_get_selected_action (context);
2909 * if (action == GDK_ACTION_ASK)
2911 * GtkWidget *dialog;
2914 * dialog = gtk_message_dialog_new (NULL,
2915 * GTK_DIALOG_MODAL |
2916 * GTK_DIALOG_DESTROY_WITH_PARENT,
2918 * GTK_BUTTONS_YES_NO,
2919 * "Move the data ?\n");
2920 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2921 * gtk_widget_destroy (dialog);
2923 * if (response == GTK_RESPONSE_YES)
2924 * action = GDK_ACTION_MOVE;
2926 * action = GDK_ACTION_COPY;
2929 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2932 * gtk_drag_finish (context, FALSE, FALSE, time);
2936 widget_signals[DRAG_DATA_RECEIVED] =
2937 g_signal_new (I_("drag-data-received"),
2938 G_TYPE_FROM_CLASS (klass),
2940 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2942 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2944 GDK_TYPE_DRAG_CONTEXT,
2947 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2952 * GtkWidget::visibility-notify-event:
2953 * @widget: the object which received the signal
2954 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2955 * triggered this signal.
2957 * The ::visibility-notify-event will be emitted when the @widget's window
2958 * is obscured or unobscured.
2960 * To receive this signal the #GdkWindow associated to the widget needs
2961 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2963 * Returns: %TRUE to stop other handlers from being invoked for the event.
2964 * %FALSE to propagate the event further.
2966 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2967 g_signal_new (I_("visibility-notify-event"),
2968 G_TYPE_FROM_CLASS (klass),
2970 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2971 _gtk_boolean_handled_accumulator, NULL,
2972 _gtk_marshal_BOOLEAN__BOXED,
2974 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2977 * GtkWidget::window-state-event:
2978 * @widget: the object which received the signal
2979 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2980 * triggered this signal.
2982 * The ::window-state-event will be emitted when the state of the
2983 * toplevel window associated to the @widget changes.
2985 * To receive this signal the #GdkWindow associated to the widget
2986 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2987 * this mask automatically for all new windows.
2989 * Returns: %TRUE to stop other handlers from being invoked for the
2990 * event. %FALSE to propagate the event further.
2992 widget_signals[WINDOW_STATE_EVENT] =
2993 g_signal_new (I_("window-state-event"),
2994 G_TYPE_FROM_CLASS (klass),
2996 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2997 _gtk_boolean_handled_accumulator, NULL,
2998 _gtk_marshal_BOOLEAN__BOXED,
3000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3001 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3002 _gtk_marshal_BOOLEAN__BOXEDv);
3005 * GtkWidget::damage-event:
3006 * @widget: the object which received the signal
3007 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3009 * Emitted when a redirected window belonging to @widget gets drawn into.
3010 * The region/area members of the event shows what area of the redirected
3011 * drawable was drawn into.
3013 * Returns: %TRUE to stop other handlers from being invoked for the event.
3014 * %FALSE to propagate the event further.
3018 widget_signals[DAMAGE_EVENT] =
3019 g_signal_new (I_("damage-event"),
3020 G_TYPE_FROM_CLASS (klass),
3022 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3023 _gtk_boolean_handled_accumulator, NULL,
3024 _gtk_marshal_BOOLEAN__BOXED,
3026 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3027 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3028 _gtk_marshal_BOOLEAN__BOXEDv);
3031 * GtkWidget::grab-broken-event:
3032 * @widget: the object which received the signal
3033 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3035 * Emitted when a pointer or keyboard grab on a window belonging
3036 * to @widget gets broken.
3038 * On X11, this happens when the grab window becomes unviewable
3039 * (i.e. it or one of its ancestors is unmapped), or if the same
3040 * application grabs the pointer or keyboard again.
3042 * Returns: %TRUE to stop other handlers from being invoked for
3043 * the event. %FALSE to propagate the event further.
3047 widget_signals[GRAB_BROKEN_EVENT] =
3048 g_signal_new (I_("grab-broken-event"),
3049 G_TYPE_FROM_CLASS (klass),
3051 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3052 _gtk_boolean_handled_accumulator, NULL,
3053 _gtk_marshal_BOOLEAN__BOXED,
3055 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3056 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3057 _gtk_marshal_BOOLEAN__BOXEDv);
3060 * GtkWidget::query-tooltip:
3061 * @widget: the object which received the signal
3062 * @x: the x coordinate of the cursor position where the request has
3063 * been emitted, relative to @widget's left side
3064 * @y: the y coordinate of the cursor position where the request has
3065 * been emitted, relative to @widget's top
3066 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3067 * @tooltip: a #GtkTooltip
3069 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3070 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3071 * focus in keyboard mode.
3073 * Using the given coordinates, the signal handler should determine
3074 * whether a tooltip should be shown for @widget. If this is the case
3075 * %TRUE should be returned, %FALSE otherwise. Note that if
3076 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3077 * should not be used.
3079 * The signal handler is free to manipulate @tooltip with the therefore
3080 * destined function calls.
3082 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3086 widget_signals[QUERY_TOOLTIP] =
3087 g_signal_new (I_("query-tooltip"),
3088 G_TYPE_FROM_CLASS (klass),
3090 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3091 _gtk_boolean_handled_accumulator, NULL,
3092 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3100 * GtkWidget::popup-menu:
3101 * @widget: the object which received the signal
3103 * This signal gets emitted whenever a widget should pop up a context
3104 * menu. This usually happens through the standard key binding mechanism;
3105 * by pressing a certain key while a widget is focused, the user can cause
3106 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3107 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3108 * for an example of how to use this signal.
3110 * Returns: %TRUE if a menu was activated
3112 widget_signals[POPUP_MENU] =
3113 g_signal_new (I_("popup-menu"),
3114 G_TYPE_FROM_CLASS (klass),
3115 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3116 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3117 _gtk_boolean_handled_accumulator, NULL,
3118 _gtk_marshal_BOOLEAN__VOID,
3122 * GtkWidget::show-help:
3123 * @widget: the object which received the signal.
3126 * Returns: %TRUE to stop other handlers from being invoked for the event.
3127 * %FALSE to propagate the event further.
3129 widget_signals[SHOW_HELP] =
3130 g_signal_new (I_("show-help"),
3131 G_TYPE_FROM_CLASS (klass),
3132 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3133 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3134 _gtk_boolean_handled_accumulator, NULL,
3135 _gtk_marshal_BOOLEAN__ENUM,
3137 GTK_TYPE_WIDGET_HELP_TYPE);
3140 * GtkWidget::accel-closures-changed:
3141 * @widget: the object which received the signal.
3143 widget_signals[ACCEL_CLOSURES_CHANGED] =
3144 g_signal_new (I_("accel-closures-changed"),
3145 G_TYPE_FROM_CLASS (klass),
3149 _gtk_marshal_VOID__VOID,
3153 * GtkWidget::screen-changed:
3154 * @widget: the object on which the signal is emitted
3155 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3156 * widget was not associated with a screen before
3158 * The ::screen-changed signal gets emitted when the
3159 * screen of a widget has changed.
3161 widget_signals[SCREEN_CHANGED] =
3162 g_signal_new (I_("screen-changed"),
3163 G_TYPE_FROM_CLASS (klass),
3165 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3167 _gtk_marshal_VOID__OBJECT,
3172 * GtkWidget::can-activate-accel:
3173 * @widget: the object which received the signal
3174 * @signal_id: the ID of a signal installed on @widget
3176 * Determines whether an accelerator that activates the signal
3177 * identified by @signal_id can currently be activated.
3178 * This signal is present to allow applications and derived
3179 * widgets to override the default #GtkWidget handling
3180 * for determining whether an accelerator can be activated.
3182 * Returns: %TRUE if the signal can be activated.
3184 widget_signals[CAN_ACTIVATE_ACCEL] =
3185 g_signal_new (I_("can-activate-accel"),
3186 G_TYPE_FROM_CLASS (klass),
3188 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3189 _gtk_boolean_handled_accumulator, NULL,
3190 _gtk_marshal_BOOLEAN__UINT,
3191 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3193 binding_set = gtk_binding_set_by_class (klass);
3194 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3196 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3199 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3201 GTK_TYPE_WIDGET_HELP_TYPE,
3202 GTK_WIDGET_HELP_TOOLTIP);
3203 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3205 GTK_TYPE_WIDGET_HELP_TYPE,
3206 GTK_WIDGET_HELP_TOOLTIP);
3207 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3209 GTK_TYPE_WIDGET_HELP_TYPE,
3210 GTK_WIDGET_HELP_WHATS_THIS);
3211 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3213 GTK_TYPE_WIDGET_HELP_TYPE,
3214 GTK_WIDGET_HELP_WHATS_THIS);
3216 gtk_widget_class_install_style_property (klass,
3217 g_param_spec_boolean ("interior-focus",
3218 P_("Interior Focus"),
3219 P_("Whether to draw the focus indicator inside widgets"),
3221 GTK_PARAM_READABLE));
3223 gtk_widget_class_install_style_property (klass,
3224 g_param_spec_int ("focus-line-width",
3225 P_("Focus linewidth"),
3226 P_("Width, in pixels, of the focus indicator line"),
3228 GTK_PARAM_READABLE));
3230 gtk_widget_class_install_style_property (klass,
3231 g_param_spec_string ("focus-line-pattern",
3232 P_("Focus line dash pattern"),
3233 P_("Dash pattern used to draw the focus indicator"),
3235 GTK_PARAM_READABLE));
3236 gtk_widget_class_install_style_property (klass,
3237 g_param_spec_int ("focus-padding",
3238 P_("Focus padding"),
3239 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3241 GTK_PARAM_READABLE));
3242 gtk_widget_class_install_style_property (klass,
3243 g_param_spec_boxed ("cursor-color",
3245 P_("Color with which to draw insertion cursor"),
3247 GTK_PARAM_READABLE));
3248 gtk_widget_class_install_style_property (klass,
3249 g_param_spec_boxed ("secondary-cursor-color",
3250 P_("Secondary cursor color"),
3251 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3253 GTK_PARAM_READABLE));
3254 gtk_widget_class_install_style_property (klass,
3255 g_param_spec_float ("cursor-aspect-ratio",
3256 P_("Cursor line aspect ratio"),
3257 P_("Aspect ratio with which to draw insertion cursor"),
3259 GTK_PARAM_READABLE));
3261 gtk_widget_class_install_style_property (klass,
3262 g_param_spec_boolean ("window-dragging",
3263 P_("Window dragging"),
3264 P_("Whether windows can be dragged by clicking on empty areas"),
3266 GTK_PARAM_READABLE));
3269 * GtkWidget:link-color:
3271 * The "link-color" style property defines the color of unvisited links.
3275 gtk_widget_class_install_style_property (klass,
3276 g_param_spec_boxed ("link-color",
3277 P_("Unvisited Link Color"),
3278 P_("Color of unvisited links"),
3280 GTK_PARAM_READABLE));
3283 * GtkWidget:visited-link-color:
3285 * The "visited-link-color" style property defines the color of visited links.
3289 gtk_widget_class_install_style_property (klass,
3290 g_param_spec_boxed ("visited-link-color",
3291 P_("Visited Link Color"),
3292 P_("Color of visited links"),
3294 GTK_PARAM_READABLE));
3297 * GtkWidget:wide-separators:
3299 * The "wide-separators" style property defines whether separators have
3300 * configurable width and should be drawn using a box instead of a line.
3304 gtk_widget_class_install_style_property (klass,
3305 g_param_spec_boolean ("wide-separators",
3306 P_("Wide Separators"),
3307 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3309 GTK_PARAM_READABLE));
3312 * GtkWidget:separator-width:
3314 * The "separator-width" style property defines the width of separators.
3315 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3319 gtk_widget_class_install_style_property (klass,
3320 g_param_spec_int ("separator-width",
3321 P_("Separator Width"),
3322 P_("The width of separators if wide-separators is TRUE"),
3324 GTK_PARAM_READABLE));
3327 * GtkWidget:separator-height:
3329 * The "separator-height" style property defines the height of separators.
3330 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3334 gtk_widget_class_install_style_property (klass,
3335 g_param_spec_int ("separator-height",
3336 P_("Separator Height"),
3337 P_("The height of separators if \"wide-separators\" is TRUE"),
3339 GTK_PARAM_READABLE));
3342 * GtkWidget:scroll-arrow-hlength:
3344 * The "scroll-arrow-hlength" style property defines the length of
3345 * horizontal scroll arrows.
3349 gtk_widget_class_install_style_property (klass,
3350 g_param_spec_int ("scroll-arrow-hlength",
3351 P_("Horizontal Scroll Arrow Length"),
3352 P_("The length of horizontal scroll arrows"),
3354 GTK_PARAM_READABLE));
3357 * GtkWidget:scroll-arrow-vlength:
3359 * The "scroll-arrow-vlength" style property defines the length of
3360 * vertical scroll arrows.
3364 gtk_widget_class_install_style_property (klass,
3365 g_param_spec_int ("scroll-arrow-vlength",
3366 P_("Vertical Scroll Arrow Length"),
3367 P_("The length of vertical scroll arrows"),
3369 GTK_PARAM_READABLE));
3371 gtk_widget_class_install_style_property (klass,
3372 g_param_spec_int ("text-handle-width",
3373 P_("Width of text selection handles"),
3374 P_("Width of text selection handles"),
3376 GTK_PARAM_READABLE));
3377 gtk_widget_class_install_style_property (klass,
3378 g_param_spec_int ("text-handle-height",
3379 P_("Height of text selection handles"),
3380 P_("Height of text selection handles"),
3382 GTK_PARAM_READABLE));
3384 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3386 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3390 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3394 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3395 for (node = list; node; node = node->next)
3397 GParamSpec *pspec = node->data;
3399 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3400 g_param_spec_unref (pspec);
3406 gtk_widget_set_property (GObject *object,
3408 const GValue *value,
3411 GtkWidget *widget = GTK_WIDGET (object);
3416 gchar *tooltip_markup;
3417 const gchar *tooltip_text;
3418 GtkWindow *tooltip_window;
3421 gtk_widget_set_name (widget, g_value_get_string (value));
3424 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3426 case PROP_WIDTH_REQUEST:
3427 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3429 case PROP_HEIGHT_REQUEST:
3430 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3433 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3435 case PROP_SENSITIVE:
3436 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3438 case PROP_APP_PAINTABLE:
3439 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3441 case PROP_CAN_FOCUS:
3442 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3444 case PROP_HAS_FOCUS:
3445 if (g_value_get_boolean (value))
3446 gtk_widget_grab_focus (widget);
3449 if (g_value_get_boolean (value))
3450 gtk_widget_grab_focus (widget);
3452 case PROP_CAN_DEFAULT:
3453 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3455 case PROP_HAS_DEFAULT:
3456 if (g_value_get_boolean (value))
3457 gtk_widget_grab_default (widget);
3459 case PROP_RECEIVES_DEFAULT:
3460 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3463 gtk_widget_set_style (widget, g_value_get_object (value));
3466 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3467 gtk_widget_set_events (widget, g_value_get_flags (value));
3469 case PROP_NO_SHOW_ALL:
3470 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3472 case PROP_HAS_TOOLTIP:
3473 gtk_widget_real_set_has_tooltip (widget,
3474 g_value_get_boolean (value), FALSE);
3476 case PROP_TOOLTIP_MARKUP:
3477 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3478 tooltip_markup = g_value_dup_string (value);
3480 /* Treat an empty string as a NULL string,
3481 * because an empty string would be useless for a tooltip:
3483 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3485 g_free (tooltip_markup);
3486 tooltip_markup = NULL;
3489 g_object_set_qdata_full (object, quark_tooltip_markup,
3490 tooltip_markup, g_free);
3492 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3493 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3494 if (gtk_widget_get_visible (widget))
3495 gtk_widget_queue_tooltip_query (widget);
3497 case PROP_TOOLTIP_TEXT:
3498 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3500 tooltip_text = g_value_get_string (value);
3502 /* Treat an empty string as a NULL string,
3503 * because an empty string would be useless for a tooltip:
3505 if (tooltip_text && (strlen (tooltip_text) == 0))
3506 tooltip_text = NULL;
3508 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3510 g_object_set_qdata_full (object, quark_tooltip_markup,
3511 tooltip_markup, g_free);
3513 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3514 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3515 if (gtk_widget_get_visible (widget))
3516 gtk_widget_queue_tooltip_query (widget);
3518 case PROP_DOUBLE_BUFFERED:
3519 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3522 gtk_widget_set_halign (widget, g_value_get_enum (value));
3525 gtk_widget_set_valign (widget, g_value_get_enum (value));
3527 case PROP_MARGIN_LEFT:
3528 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3530 case PROP_MARGIN_RIGHT:
3531 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3533 case PROP_MARGIN_TOP:
3534 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3536 case PROP_MARGIN_BOTTOM:
3537 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3540 g_object_freeze_notify (G_OBJECT (widget));
3541 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3542 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3543 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3544 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3545 g_object_thaw_notify (G_OBJECT (widget));
3548 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3550 case PROP_HEXPAND_SET:
3551 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3554 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3556 case PROP_VEXPAND_SET:
3557 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3560 g_object_freeze_notify (G_OBJECT (widget));
3561 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3562 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3563 g_object_thaw_notify (G_OBJECT (widget));
3566 gtk_widget_set_opacity (widget, g_value_get_double (value));
3569 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3575 gtk_widget_get_property (GObject *object,
3580 GtkWidget *widget = GTK_WIDGET (object);
3581 GtkWidgetPrivate *priv = widget->priv;
3589 g_value_set_string (value, priv->name);
3591 g_value_set_static_string (value, "");
3594 g_value_set_object (value, priv->parent);
3596 case PROP_WIDTH_REQUEST:
3599 gtk_widget_get_size_request (widget, &w, NULL);
3600 g_value_set_int (value, w);
3603 case PROP_HEIGHT_REQUEST:
3606 gtk_widget_get_size_request (widget, NULL, &h);
3607 g_value_set_int (value, h);
3611 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3613 case PROP_SENSITIVE:
3614 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3616 case PROP_APP_PAINTABLE:
3617 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3619 case PROP_CAN_FOCUS:
3620 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3622 case PROP_HAS_FOCUS:
3623 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3626 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3628 case PROP_CAN_DEFAULT:
3629 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3631 case PROP_HAS_DEFAULT:
3632 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3634 case PROP_RECEIVES_DEFAULT:
3635 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3637 case PROP_COMPOSITE_CHILD:
3638 g_value_set_boolean (value, widget->priv->composite_child);
3641 g_value_set_object (value, gtk_widget_get_style (widget));
3644 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3645 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3647 case PROP_NO_SHOW_ALL:
3648 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3650 case PROP_HAS_TOOLTIP:
3651 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3653 case PROP_TOOLTIP_TEXT:
3655 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3658 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3659 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3661 g_value_take_string (value, text);
3664 case PROP_TOOLTIP_MARKUP:
3665 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3668 g_value_set_object (value, gtk_widget_get_window (widget));
3670 case PROP_DOUBLE_BUFFERED:
3671 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3674 g_value_set_enum (value, gtk_widget_get_halign (widget));
3677 g_value_set_enum (value, gtk_widget_get_valign (widget));
3679 case PROP_MARGIN_LEFT:
3680 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3682 case PROP_MARGIN_RIGHT:
3683 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3685 case PROP_MARGIN_TOP:
3686 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3688 case PROP_MARGIN_BOTTOM:
3689 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3693 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3694 if (aux_info == NULL)
3696 g_value_set_int (value, 0);
3700 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3701 aux_info->margin.right),
3702 MAX (aux_info->margin.top,
3703 aux_info->margin.bottom)));
3708 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3710 case PROP_HEXPAND_SET:
3711 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3714 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3716 case PROP_VEXPAND_SET:
3717 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3720 g_value_set_boolean (value,
3721 gtk_widget_get_hexpand (widget) &&
3722 gtk_widget_get_vexpand (widget));
3725 g_value_set_double (value, gtk_widget_get_opacity (widget));
3728 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3734 gtk_widget_init (GtkWidget *widget)
3736 GtkWidgetPrivate *priv;
3738 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3741 priv = widget->priv;
3743 priv->child_visible = TRUE;
3745 priv->allocation.x = -1;
3746 priv->allocation.y = -1;
3747 priv->allocation.width = 1;
3748 priv->allocation.height = 1;
3749 priv->user_alpha = 255;
3751 priv->window = NULL;
3752 priv->parent = NULL;
3754 priv->sensitive = TRUE;
3755 priv->composite_child = composite_child_stack != 0;
3756 priv->double_buffered = TRUE;
3757 priv->redraw_on_alloc = TRUE;
3758 priv->alloc_needed = TRUE;
3760 switch (gtk_widget_get_direction (widget))
3762 case GTK_TEXT_DIR_LTR:
3763 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3766 case GTK_TEXT_DIR_RTL:
3767 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3770 case GTK_TEXT_DIR_NONE:
3772 g_assert_not_reached ();
3777 /* this will be set to TRUE if the widget gets a child or if the
3778 * expand flag is set on the widget, but until one of those happen
3779 * we know the expand is already properly FALSE.
3781 * We really want to default FALSE here to avoid computing expand
3782 * all over the place while initially building a widget tree.
3784 priv->need_compute_expand = FALSE;
3786 _gtk_size_request_cache_init (&priv->requests);
3788 priv->style = gtk_widget_get_default_style ();
3789 g_object_ref (priv->style);
3794 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3796 GParamSpec **pspecs)
3798 GtkWidgetPrivate *priv = widget->priv;
3799 GtkWidget *container = priv->parent;
3802 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3803 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3807 * gtk_widget_freeze_child_notify:
3808 * @widget: a #GtkWidget
3810 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3811 * signals are queued until gtk_widget_thaw_child_notify() is called
3814 * This is the analogue of g_object_freeze_notify() for child properties.
3817 gtk_widget_freeze_child_notify (GtkWidget *widget)
3819 g_return_if_fail (GTK_IS_WIDGET (widget));
3821 if (!G_OBJECT (widget)->ref_count)
3824 g_object_ref (widget);
3825 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3826 g_object_unref (widget);
3830 * gtk_widget_child_notify:
3831 * @widget: a #GtkWidget
3832 * @child_property: the name of a child property installed on the
3833 * class of @widget<!-- -->'s parent
3835 * Emits a #GtkWidget::child-notify signal for the
3836 * <link linkend="child-properties">child property</link> @child_property
3839 * This is the analogue of g_object_notify() for child properties.
3841 * Also see gtk_container_child_notify().
3844 gtk_widget_child_notify (GtkWidget *widget,
3845 const gchar *child_property)
3847 if (widget->priv->parent == NULL)
3850 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3854 * gtk_widget_thaw_child_notify:
3855 * @widget: a #GtkWidget
3857 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3858 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3862 gtk_widget_thaw_child_notify (GtkWidget *widget)
3864 GObjectNotifyQueue *nqueue;
3866 g_return_if_fail (GTK_IS_WIDGET (widget));
3868 if (!G_OBJECT (widget)->ref_count)
3871 g_object_ref (widget);
3872 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3873 if (!nqueue || !nqueue->freeze_count)
3874 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3875 G_OBJECT_TYPE_NAME (widget), widget);
3877 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3878 g_object_unref (widget);
3884 * @type: type ID of the widget to create
3885 * @first_property_name: name of first property to set
3886 * @...: value of first property, followed by more properties,
3889 * This is a convenience function for creating a widget and setting
3890 * its properties in one go. For example you might write:
3891 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3892 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3893 * g_object_new(), but returns a widget so you don't have to
3894 * cast the object yourself.
3896 * Return value: a new #GtkWidget of type @widget_type
3899 gtk_widget_new (GType type,
3900 const gchar *first_property_name,
3906 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3908 va_start (var_args, first_property_name);
3909 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3916 gtk_widget_queue_draw_child (GtkWidget *widget)
3918 GtkWidgetPrivate *priv = widget->priv;
3921 parent = priv->parent;
3922 if (parent && gtk_widget_is_drawable (parent))
3923 gtk_widget_queue_draw_area (parent,
3926 priv->allocation.width,
3927 priv->allocation.height);
3931 * gtk_widget_unparent:
3932 * @widget: a #GtkWidget
3934 * This function is only for use in widget implementations.
3935 * Should be called by implementations of the remove method
3936 * on #GtkContainer, to dissociate a child from the container.
3939 gtk_widget_unparent (GtkWidget *widget)
3941 GtkWidgetPrivate *priv;
3942 GObjectNotifyQueue *nqueue;
3943 GtkWidget *toplevel;
3944 GtkWidget *old_parent;
3946 g_return_if_fail (GTK_IS_WIDGET (widget));
3948 priv = widget->priv;
3950 if (priv->parent == NULL)
3953 /* keep this function in sync with gtk_menu_detach() */
3955 gtk_widget_push_verify_invariants (widget);
3957 g_object_freeze_notify (G_OBJECT (widget));
3958 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3960 toplevel = gtk_widget_get_toplevel (widget);
3961 if (gtk_widget_is_toplevel (toplevel))
3962 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3964 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3965 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3967 gtk_widget_queue_draw_child (widget);
3969 /* Reset the width and height here, to force reallocation if we
3970 * get added back to a new parent. This won't work if our new
3971 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3972 * (would 0x0 be OK here?)
3974 priv->allocation.width = 1;
3975 priv->allocation.height = 1;
3977 if (gtk_widget_get_realized (widget))
3979 if (priv->in_reparent)
3980 gtk_widget_unmap (widget);
3982 gtk_widget_unrealize (widget);
3985 /* If we are unanchoring the child, we save around the toplevel
3986 * to emit hierarchy changed
3988 if (priv->parent->priv->anchored)
3989 g_object_ref (toplevel);
3993 /* Removing a widget from a container restores the child visible
3994 * flag to the default state, so it doesn't affect the child
3995 * in the next parent.
3997 priv->child_visible = TRUE;
3999 old_parent = priv->parent;
4000 priv->parent = NULL;
4002 /* parent may no longer expand if the removed
4003 * child was expand=TRUE and could therefore
4006 if (gtk_widget_get_visible (widget) &&
4007 (priv->need_compute_expand ||
4008 priv->computed_hexpand ||
4009 priv->computed_vexpand))
4011 gtk_widget_queue_compute_expand (old_parent);
4014 /* Unset BACKDROP since we are no longer inside a toplevel window */
4015 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4017 gtk_style_context_set_parent (priv->context, NULL);
4019 _gtk_widget_update_parent_muxer (widget);
4021 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4024 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4025 g_object_unref (toplevel);
4028 /* Now that the parent pointer is nullified and the hierarchy-changed
4029 * already passed, go ahead and unset the parent window, if we are unparenting
4030 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4031 * will fire again for the new subhierarchy.
4033 gtk_widget_set_parent_window (widget, NULL);
4035 g_object_notify (G_OBJECT (widget), "parent");
4036 g_object_thaw_notify (G_OBJECT (widget));
4038 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4039 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4041 gtk_widget_propagate_alpha (widget);
4043 gtk_widget_pop_verify_invariants (widget);
4044 g_object_unref (widget);
4048 * gtk_widget_destroy:
4049 * @widget: a #GtkWidget
4051 * Destroys a widget.
4054 * destroyed, it will break any references it holds to other objects.
4055 * If the widget is inside a container, the widget will be removed
4056 * from the container. If the widget is a toplevel (derived from
4057 * #GtkWindow), it will be removed from the list of toplevels, and the
4058 * reference GTK+ holds to it will be removed. Removing a
4059 * widget from its container or the list of toplevels results in the
4060 * widget being finalized, unless you've added additional references
4061 * to the widget with g_object_ref().
4063 * In most cases, only toplevel widgets (windows) require explicit
4064 * destruction, because when you destroy a toplevel its children will
4065 * be destroyed as well.
4068 gtk_widget_destroy (GtkWidget *widget)
4070 g_return_if_fail (GTK_IS_WIDGET (widget));
4072 if (!widget->priv->in_destruction)
4073 g_object_run_dispose (G_OBJECT (widget));
4077 * gtk_widget_destroyed:
4078 * @widget: a #GtkWidget
4079 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4081 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4082 * %NULL. It's intended to be used as a callback connected to the
4083 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4084 * as a signal handler, and pass the address of your widget variable
4085 * as user data. Then when the widget is destroyed, the variable will
4086 * be set to %NULL. Useful for example to avoid multiple copies
4087 * of the same dialog.
4090 gtk_widget_destroyed (GtkWidget *widget,
4091 GtkWidget **widget_pointer)
4093 /* Don't make any assumptions about the
4095 * Even check widget_pointer.
4098 *widget_pointer = NULL;
4103 * @widget: a #GtkWidget
4105 * Flags a widget to be displayed. Any widget that isn't shown will
4106 * not appear on the screen. If you want to show all the widgets in a
4107 * container, it's easier to call gtk_widget_show_all() on the
4108 * container, instead of individually showing the widgets.
4110 * Remember that you have to show the containers containing a widget,
4111 * in addition to the widget itself, before it will appear onscreen.
4113 * When a toplevel container is shown, it is immediately realized and
4114 * mapped; other shown widgets are realized and mapped when their
4115 * toplevel container is realized and mapped.
4118 gtk_widget_show (GtkWidget *widget)
4120 g_return_if_fail (GTK_IS_WIDGET (widget));
4122 if (!gtk_widget_get_visible (widget))
4124 g_object_ref (widget);
4125 gtk_widget_push_verify_invariants (widget);
4127 if (!gtk_widget_is_toplevel (widget))
4128 gtk_widget_queue_resize (widget);
4130 /* see comment in set_parent() for why this should and can be
4133 if (widget->priv->need_compute_expand ||
4134 widget->priv->computed_hexpand ||
4135 widget->priv->computed_vexpand)
4137 if (widget->priv->parent != NULL)
4138 gtk_widget_queue_compute_expand (widget->priv->parent);
4141 g_signal_emit (widget, widget_signals[SHOW], 0);
4142 g_object_notify (G_OBJECT (widget), "visible");
4144 gtk_widget_pop_verify_invariants (widget);
4145 g_object_unref (widget);
4150 gtk_widget_real_show (GtkWidget *widget)
4152 GtkWidgetPrivate *priv = widget->priv;
4154 if (!gtk_widget_get_visible (widget))
4156 priv->visible = TRUE;
4159 gtk_widget_get_mapped (priv->parent) &&
4160 gtk_widget_get_child_visible (widget) &&
4161 !gtk_widget_get_mapped (widget))
4162 gtk_widget_map (widget);
4167 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4170 g_signal_handlers_disconnect_by_func (widget,
4171 gtk_widget_show_map_callback,
4176 * gtk_widget_show_now:
4177 * @widget: a #GtkWidget
4179 * Shows a widget. If the widget is an unmapped toplevel widget
4180 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4181 * loop and wait for the window to actually be mapped. Be careful;
4182 * because the main loop is running, anything can happen during
4186 gtk_widget_show_now (GtkWidget *widget)
4190 g_return_if_fail (GTK_IS_WIDGET (widget));
4192 /* make sure we will get event */
4193 if (!gtk_widget_get_mapped (widget) &&
4194 gtk_widget_is_toplevel (widget))
4196 gtk_widget_show (widget);
4198 g_signal_connect (widget, "map-event",
4199 G_CALLBACK (gtk_widget_show_map_callback),
4203 gtk_main_iteration ();
4206 gtk_widget_show (widget);
4211 * @widget: a #GtkWidget
4213 * Reverses the effects of gtk_widget_show(), causing the widget to be
4214 * hidden (invisible to the user).
4217 gtk_widget_hide (GtkWidget *widget)
4219 g_return_if_fail (GTK_IS_WIDGET (widget));
4221 if (gtk_widget_get_visible (widget))
4223 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4225 g_object_ref (widget);
4226 gtk_widget_push_verify_invariants (widget);
4228 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4229 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4231 /* a parent may now be expand=FALSE since we're hidden. */
4232 if (widget->priv->need_compute_expand ||
4233 widget->priv->computed_hexpand ||
4234 widget->priv->computed_vexpand)
4236 gtk_widget_queue_compute_expand (widget);
4239 g_signal_emit (widget, widget_signals[HIDE], 0);
4240 if (!gtk_widget_is_toplevel (widget))
4241 gtk_widget_queue_resize (widget);
4242 g_object_notify (G_OBJECT (widget), "visible");
4244 gtk_widget_pop_verify_invariants (widget);
4245 g_object_unref (widget);
4250 gtk_widget_real_hide (GtkWidget *widget)
4252 if (gtk_widget_get_visible (widget))
4254 widget->priv->visible = FALSE;
4256 if (gtk_widget_get_mapped (widget))
4257 gtk_widget_unmap (widget);
4262 * gtk_widget_hide_on_delete:
4263 * @widget: a #GtkWidget
4265 * Utility function; intended to be connected to the #GtkWidget::delete-event
4266 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4267 * argument, then returns %TRUE. If connected to ::delete-event, the
4268 * result is that clicking the close button for a window (on the
4269 * window frame, top right corner usually) will hide but not destroy
4270 * the window. By default, GTK+ destroys windows when ::delete-event
4273 * Return value: %TRUE
4276 gtk_widget_hide_on_delete (GtkWidget *widget)
4278 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4280 gtk_widget_hide (widget);
4286 * gtk_widget_show_all:
4287 * @widget: a #GtkWidget
4289 * Recursively shows a widget, and any child widgets (if the widget is
4293 gtk_widget_show_all (GtkWidget *widget)
4295 GtkWidgetClass *class;
4297 g_return_if_fail (GTK_IS_WIDGET (widget));
4299 if (gtk_widget_get_no_show_all (widget))
4302 class = GTK_WIDGET_GET_CLASS (widget);
4304 if (class->show_all)
4305 class->show_all (widget);
4310 * @widget: a #GtkWidget
4312 * This function is only for use in widget implementations. Causes
4313 * a widget to be mapped if it isn't already.
4316 gtk_widget_map (GtkWidget *widget)
4318 GtkWidgetPrivate *priv;
4320 g_return_if_fail (GTK_IS_WIDGET (widget));
4321 g_return_if_fail (gtk_widget_get_visible (widget));
4322 g_return_if_fail (gtk_widget_get_child_visible (widget));
4324 priv = widget->priv;
4326 if (!gtk_widget_get_mapped (widget))
4328 gtk_widget_push_verify_invariants (widget);
4330 if (!gtk_widget_get_realized (widget))
4331 gtk_widget_realize (widget);
4333 g_signal_emit (widget, widget_signals[MAP], 0);
4335 if (!gtk_widget_get_has_window (widget))
4336 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4338 if (widget->priv->context)
4339 _gtk_style_context_update_animating (widget->priv->context);
4341 gtk_widget_pop_verify_invariants (widget);
4347 * @widget: a #GtkWidget
4349 * This function is only for use in widget implementations. Causes
4350 * a widget to be unmapped if it's currently mapped.
4353 gtk_widget_unmap (GtkWidget *widget)
4355 GtkWidgetPrivate *priv;
4357 g_return_if_fail (GTK_IS_WIDGET (widget));
4359 priv = widget->priv;
4361 if (gtk_widget_get_mapped (widget))
4363 gtk_widget_push_verify_invariants (widget);
4365 if (!gtk_widget_get_has_window (widget))
4366 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4367 _gtk_tooltip_hide (widget);
4369 if (widget->priv->context)
4370 _gtk_style_context_update_animating (widget->priv->context);
4372 g_signal_emit (widget, widget_signals[UNMAP], 0);
4374 gtk_widget_pop_verify_invariants (widget);
4376 /* Unset pointer/window info */
4377 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4382 _gtk_widget_enable_device_events (GtkWidget *widget)
4384 GHashTable *device_events;
4385 GHashTableIter iter;
4386 gpointer key, value;
4388 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4393 g_hash_table_iter_init (&iter, device_events);
4395 while (g_hash_table_iter_next (&iter, &key, &value))
4398 GdkEventMask event_mask;
4401 event_mask = GPOINTER_TO_UINT (value);
4402 gtk_widget_add_events_internal (widget, device, event_mask);
4407 get_widget_windows (GtkWidget *widget)
4409 GList *window_list, *last, *l, *children, *ret;
4411 if (gtk_widget_get_has_window (widget))
4412 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4414 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4416 last = g_list_last (window_list);
4419 for (l = window_list; l; l = l->next)
4421 GtkWidget *window_widget = NULL;
4423 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4425 if (widget != window_widget)
4428 ret = g_list_prepend (ret, l->data);
4429 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4433 last = g_list_concat (last, children);
4434 last = g_list_last (last);
4438 g_list_free (window_list);
4444 device_enable_foreach (GtkWidget *widget,
4447 GdkDevice *device = user_data;
4448 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4452 device_disable_foreach (GtkWidget *widget,
4455 GdkDevice *device = user_data;
4456 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4460 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4465 GList *window_list, *l;
4467 window_list = get_widget_windows (widget);
4469 for (l = window_list; l; l = l->next)
4471 GdkEventMask events = 0;
4477 events = gdk_window_get_events (window);
4479 gdk_window_set_device_events (window, device, events);
4482 if (recurse && GTK_IS_CONTAINER (widget))
4485 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4487 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4490 g_list_free (window_list);
4494 gtk_widget_update_devices_mask (GtkWidget *widget,
4497 GList *enabled_devices, *l;
4499 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4501 for (l = enabled_devices; l; l = l->next)
4502 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4506 * gtk_widget_realize:
4507 * @widget: a #GtkWidget
4509 * Creates the GDK (windowing system) resources associated with a
4510 * widget. For example, @widget->window will be created when a widget
4511 * is realized. Normally realization happens implicitly; if you show
4512 * a widget and all its parent containers, then the widget will be
4513 * realized and mapped automatically.
4515 * Realizing a widget requires all
4516 * the widget's parent widgets to be realized; calling
4517 * gtk_widget_realize() realizes the widget's parents in addition to
4518 * @widget itself. If a widget is not yet inside a toplevel window
4519 * when you realize it, bad things will happen.
4521 * This function is primarily used in widget implementations, and
4522 * isn't very useful otherwise. Many times when you think you might
4523 * need it, a better approach is to connect to a signal that will be
4524 * called after the widget is realized automatically, such as
4525 * #GtkWidget::draw. Or simply g_signal_connect () to the
4526 * #GtkWidget::realize signal.
4529 gtk_widget_realize (GtkWidget *widget)
4531 GtkWidgetPrivate *priv;
4532 cairo_region_t *region;
4534 g_return_if_fail (GTK_IS_WIDGET (widget));
4535 g_return_if_fail (widget->priv->anchored ||
4536 GTK_IS_INVISIBLE (widget));
4538 priv = widget->priv;
4540 if (!gtk_widget_get_realized (widget))
4542 gtk_widget_push_verify_invariants (widget);
4545 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4546 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4549 if (priv->parent == NULL &&
4550 !gtk_widget_is_toplevel (widget))
4551 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4552 "inside a toplevel window is not going to work very well. "
4553 "Widgets must be inside a toplevel container before realizing them.");
4555 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4556 gtk_widget_realize (priv->parent);
4558 gtk_widget_ensure_style (widget);
4560 if (priv->style_update_pending)
4561 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4563 g_signal_emit (widget, widget_signals[REALIZE], 0);
4565 gtk_widget_real_set_has_tooltip (widget,
4566 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4569 if (priv->has_shape_mask)
4571 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4572 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4575 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4577 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4579 if (priv->multidevice)
4580 gdk_window_set_support_multidevice (priv->window, TRUE);
4582 _gtk_widget_enable_device_events (widget);
4583 gtk_widget_update_devices_mask (widget, TRUE);
4585 gtk_widget_pop_verify_invariants (widget);
4590 * gtk_widget_unrealize:
4591 * @widget: a #GtkWidget
4593 * This function is only useful in widget implementations.
4594 * Causes a widget to be unrealized (frees all GDK resources
4595 * associated with the widget, such as @widget->window).
4598 gtk_widget_unrealize (GtkWidget *widget)
4600 g_return_if_fail (GTK_IS_WIDGET (widget));
4602 gtk_widget_push_verify_invariants (widget);
4604 if (widget->priv->has_shape_mask)
4605 gtk_widget_shape_combine_region (widget, NULL);
4607 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4608 gtk_widget_input_shape_combine_region (widget, NULL);
4610 if (gtk_widget_get_realized (widget))
4612 g_object_ref (widget);
4614 if (widget->priv->mapped)
4615 gtk_widget_unmap (widget);
4617 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4618 g_assert (!widget->priv->mapped);
4619 gtk_widget_set_realized (widget, FALSE);
4621 g_object_unref (widget);
4624 gtk_widget_pop_verify_invariants (widget);
4627 /*****************************************
4629 *****************************************/
4632 * gtk_widget_queue_draw_region:
4633 * @widget: a #GtkWidget
4634 * @region: region to draw
4636 * Invalidates the rectangular area of @widget defined by @region by
4637 * calling gdk_window_invalidate_region() on the widget's window and
4638 * all its child windows. Once the main loop becomes idle (after the
4639 * current batch of events has been processed, roughly), the window
4640 * will receive expose events for the union of all regions that have
4643 * Normally you would only use this function in widget
4644 * implementations. You might also use it to schedule a redraw of a
4645 * #GtkDrawingArea or some portion thereof.
4650 gtk_widget_queue_draw_region (GtkWidget *widget,
4651 const cairo_region_t *region)
4653 GtkWidgetPrivate *priv;
4656 g_return_if_fail (GTK_IS_WIDGET (widget));
4658 priv = widget->priv;
4660 if (!gtk_widget_get_realized (widget))
4663 /* Just return if the widget or one of its ancestors isn't mapped */
4664 for (w = widget; w != NULL; w = w->priv->parent)
4665 if (!gtk_widget_get_mapped (w))
4668 gdk_window_invalidate_region (priv->window, region, TRUE);
4672 * gtk_widget_queue_draw_area:
4673 * @widget: a #GtkWidget
4674 * @x: x coordinate of upper-left corner of rectangle to redraw
4675 * @y: y coordinate of upper-left corner of rectangle to redraw
4676 * @width: width of region to draw
4677 * @height: height of region to draw
4679 * Convenience function that calls gtk_widget_queue_draw_region() on
4680 * the region created from the given coordinates.
4682 * The region here is specified in widget coordinates.
4683 * Widget coordinates are a bit odd; for historical reasons, they are
4684 * defined as @widget->window coordinates for widgets that are not
4685 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4686 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4689 gtk_widget_queue_draw_area (GtkWidget *widget,
4696 cairo_region_t *region;
4698 g_return_if_fail (GTK_IS_WIDGET (widget));
4703 rect.height = height;
4705 region = cairo_region_create_rectangle (&rect);
4706 gtk_widget_queue_draw_region (widget, region);
4707 cairo_region_destroy (region);
4711 * gtk_widget_queue_draw:
4712 * @widget: a #GtkWidget
4714 * Equivalent to calling gtk_widget_queue_draw_area() for the
4715 * entire area of a widget.
4718 gtk_widget_queue_draw (GtkWidget *widget)
4722 g_return_if_fail (GTK_IS_WIDGET (widget));
4724 gtk_widget_get_allocation (widget, &rect);
4726 if (!gtk_widget_get_has_window (widget))
4727 gtk_widget_queue_draw_area (widget,
4728 rect.x, rect.y, rect.width, rect.height);
4730 gtk_widget_queue_draw_area (widget,
4731 0, 0, rect.width, rect.height);
4735 * gtk_widget_queue_resize:
4736 * @widget: a #GtkWidget
4738 * This function is only for use in widget implementations.
4739 * Flags a widget to have its size renegotiated; should
4740 * be called when a widget for some reason has a new size request.
4741 * For example, when you change the text in a #GtkLabel, #GtkLabel
4742 * queues a resize to ensure there's enough space for the new text.
4744 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4745 * from inside its implementation of the GtkWidgetClass::size_allocate
4746 * virtual method. Calls to gtk_widget_queue_resize() from inside
4747 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4750 gtk_widget_queue_resize (GtkWidget *widget)
4752 g_return_if_fail (GTK_IS_WIDGET (widget));
4754 if (gtk_widget_get_realized (widget))
4755 gtk_widget_queue_draw (widget);
4757 _gtk_size_group_queue_resize (widget, 0);
4761 * gtk_widget_queue_resize_no_redraw:
4762 * @widget: a #GtkWidget
4764 * This function works like gtk_widget_queue_resize(),
4765 * except that the widget is not invalidated.
4770 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4772 g_return_if_fail (GTK_IS_WIDGET (widget));
4774 _gtk_size_group_queue_resize (widget, 0);
4778 * gtk_widget_size_request:
4779 * @widget: a #GtkWidget
4780 * @requisition: (out): a #GtkRequisition to be filled in
4782 * This function is typically used when implementing a #GtkContainer
4783 * subclass. Obtains the preferred size of a widget. The container
4784 * uses this information to arrange its child widgets and decide what
4785 * size allocations to give them with gtk_widget_size_allocate().
4787 * You can also call this function from an application, with some
4788 * caveats. Most notably, getting a size request requires the widget
4789 * to be associated with a screen, because font information may be
4790 * needed. Multihead-aware applications should keep this in mind.
4792 * Also remember that the size request is not necessarily the size
4793 * a widget will actually be allocated.
4795 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4798 gtk_widget_size_request (GtkWidget *widget,
4799 GtkRequisition *requisition)
4801 g_return_if_fail (GTK_IS_WIDGET (widget));
4803 gtk_widget_get_preferred_size (widget, requisition, NULL);
4807 * gtk_widget_get_child_requisition:
4808 * @widget: a #GtkWidget
4809 * @requisition: (out): a #GtkRequisition to be filled in
4811 * This function is only for use in widget implementations. Obtains
4812 * @widget->requisition, unless someone has forced a particular
4813 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4814 * in which case it returns that geometry instead of the widget's
4817 * This function differs from gtk_widget_size_request() in that
4818 * it retrieves the last size request value from @widget->requisition,
4819 * while gtk_widget_size_request() actually calls the "size_request" method
4820 * on @widget to compute the size request and fill in @widget->requisition,
4821 * and only then returns @widget->requisition.
4823 * Because this function does not call the "size_request" method, it
4824 * can only be used when you know that @widget->requisition is
4825 * up-to-date, that is, gtk_widget_size_request() has been called
4826 * since the last time a resize was queued. In general, only container
4827 * implementations have this information; applications should use
4828 * gtk_widget_size_request().
4831 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4834 gtk_widget_get_child_requisition (GtkWidget *widget,
4835 GtkRequisition *requisition)
4837 gtk_widget_get_preferred_size (widget, requisition, NULL);
4841 invalidate_predicate (GdkWindow *window,
4846 gdk_window_get_user_data (window, &user_data);
4848 return (user_data == data);
4851 /* Invalidate @region in widget->window and all children
4852 * of widget->window owned by widget. @region is in the
4853 * same coordinates as widget->allocation and will be
4854 * modified by this call.
4857 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4858 cairo_region_t *region)
4860 GtkWidgetPrivate *priv = widget->priv;
4862 if (!gtk_widget_get_realized (widget))
4865 if (gtk_widget_get_has_window (widget) && priv->parent)
4869 gdk_window_get_position (priv->window, &x, &y);
4870 cairo_region_translate (region, -x, -y);
4873 gdk_window_invalidate_maybe_recurse (priv->window, region,
4874 invalidate_predicate, widget);
4878 * gtk_widget_size_allocate:
4879 * @widget: a #GtkWidget
4880 * @allocation: position and size to be allocated to @widget
4882 * This function is only used by #GtkContainer subclasses, to assign a size
4883 * and position to their child widgets.
4885 * In this function, the allocation may be adjusted. It will be forced
4886 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4887 * method on the child will be used to adjust the allocation. Standard
4888 * adjustments include removing the widget's margins, and applying the
4889 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4892 gtk_widget_size_allocate (GtkWidget *widget,
4893 GtkAllocation *allocation)
4895 GtkWidgetPrivate *priv;
4896 GdkRectangle real_allocation;
4897 GdkRectangle old_allocation;
4898 GdkRectangle adjusted_allocation;
4899 gboolean alloc_needed;
4900 gboolean size_changed;
4901 gboolean position_changed;
4902 gint natural_width, natural_height, dummy;
4903 gint min_width, min_height;
4905 priv = widget->priv;
4907 g_return_if_fail (GTK_IS_WIDGET (widget));
4909 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4912 gtk_widget_push_verify_invariants (widget);
4914 #ifdef G_ENABLE_DEBUG
4915 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4926 parent = gtk_widget_get_parent (parent);
4929 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4930 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4931 2 * depth, " ", name,
4932 allocation->width, allocation->height);
4934 #endif /* G_ENABLE_DEBUG */
4936 alloc_needed = priv->alloc_needed;
4937 /* Preserve request/allocate ordering */
4938 priv->alloc_needed = FALSE;
4940 old_allocation = priv->allocation;
4941 real_allocation = *allocation;
4943 adjusted_allocation = real_allocation;
4944 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4946 /* Go ahead and request the height for allocated width, note that the internals
4947 * of get_height_for_width will internally limit the for_size to natural size
4948 * when aligning implicitly.
4950 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4951 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4955 /* Go ahead and request the width for allocated height, note that the internals
4956 * of get_width_for_height will internally limit the for_size to natural size
4957 * when aligning implicitly.
4959 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4960 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4963 #ifdef G_ENABLE_DEBUG
4964 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4966 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4967 !GTK_IS_SCROLLABLE (widget))
4968 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4969 "Allocation is %dx%d, but minimum required size is %dx%d.",
4970 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4971 G_OBJECT_TYPE_NAME (widget), widget,
4972 real_allocation.width, real_allocation.height,
4973 min_width, min_height);
4976 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4977 * allocated sizes and possibly limit them to the natural sizes */
4978 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4979 GTK_ORIENTATION_HORIZONTAL,
4982 &adjusted_allocation.x,
4983 &adjusted_allocation.width);
4984 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4985 GTK_ORIENTATION_VERTICAL,
4988 &adjusted_allocation.y,
4989 &adjusted_allocation.height);
4991 if (adjusted_allocation.x < real_allocation.x ||
4992 adjusted_allocation.y < real_allocation.y ||
4993 (adjusted_allocation.x + adjusted_allocation.width) >
4994 (real_allocation.x + real_allocation.width) ||
4995 (adjusted_allocation.y + adjusted_allocation.height >
4996 real_allocation.y + real_allocation.height))
4998 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",
4999 G_OBJECT_TYPE_NAME (widget), widget,
5000 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5001 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5002 adjusted_allocation = real_allocation; /* veto it */
5006 real_allocation = adjusted_allocation;
5009 if (real_allocation.width < 0 || real_allocation.height < 0)
5011 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5012 real_allocation.width,
5013 real_allocation.height);
5016 real_allocation.width = MAX (real_allocation.width, 1);
5017 real_allocation.height = MAX (real_allocation.height, 1);
5019 size_changed = (old_allocation.width != real_allocation.width ||
5020 old_allocation.height != real_allocation.height);
5021 position_changed = (old_allocation.x != real_allocation.x ||
5022 old_allocation.y != real_allocation.y);
5024 if (!alloc_needed && !size_changed && !position_changed)
5027 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5029 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5030 priv->alloc_needed = FALSE;
5032 if (gtk_widget_get_mapped (widget))
5034 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5036 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5038 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5039 cairo_region_union_rectangle (invalidate, &old_allocation);
5041 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5042 cairo_region_destroy (invalidate);
5047 if (priv->redraw_on_alloc)
5049 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5051 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5052 cairo_region_union_rectangle (invalidate, &old_allocation);
5054 gtk_widget_invalidate_widget_windows (widget, invalidate);
5055 cairo_region_destroy (invalidate);
5060 if ((size_changed || position_changed) && priv->parent &&
5061 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5063 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5064 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5065 cairo_region_destroy (invalidate);
5069 gtk_widget_pop_verify_invariants (widget);
5073 * gtk_widget_common_ancestor:
5074 * @widget_a: a #GtkWidget
5075 * @widget_b: a #GtkWidget
5077 * Find the common ancestor of @widget_a and @widget_b that
5078 * is closest to the two widgets.
5080 * Return value: the closest common ancestor of @widget_a and
5081 * @widget_b or %NULL if @widget_a and @widget_b do not
5082 * share a common ancestor.
5085 gtk_widget_common_ancestor (GtkWidget *widget_a,
5086 GtkWidget *widget_b)
5088 GtkWidget *parent_a;
5089 GtkWidget *parent_b;
5093 parent_a = widget_a;
5094 while (parent_a->priv->parent)
5096 parent_a = parent_a->priv->parent;
5100 parent_b = widget_b;
5101 while (parent_b->priv->parent)
5103 parent_b = parent_b->priv->parent;
5107 if (parent_a != parent_b)
5110 while (depth_a > depth_b)
5112 widget_a = widget_a->priv->parent;
5116 while (depth_b > depth_a)
5118 widget_b = widget_b->priv->parent;
5122 while (widget_a != widget_b)
5124 widget_a = widget_a->priv->parent;
5125 widget_b = widget_b->priv->parent;
5132 * gtk_widget_translate_coordinates:
5133 * @src_widget: a #GtkWidget
5134 * @dest_widget: a #GtkWidget
5135 * @src_x: X position relative to @src_widget
5136 * @src_y: Y position relative to @src_widget
5137 * @dest_x: (out): location to store X position relative to @dest_widget
5138 * @dest_y: (out): location to store Y position relative to @dest_widget
5140 * Translate coordinates relative to @src_widget's allocation to coordinates
5141 * relative to @dest_widget's allocations. In order to perform this
5142 * operation, both widgets must be realized, and must share a common
5145 * Return value: %FALSE if either widget was not realized, or there
5146 * was no common ancestor. In this case, nothing is stored in
5147 * *@dest_x and *@dest_y. Otherwise %TRUE.
5150 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5151 GtkWidget *dest_widget,
5157 GtkWidgetPrivate *src_priv = src_widget->priv;
5158 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5159 GtkWidget *ancestor;
5161 GList *dest_list = NULL;
5163 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5164 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5166 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5167 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5170 /* Translate from allocation relative to window relative */
5171 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5174 gdk_window_get_position (src_priv->window, &wx, &wy);
5176 src_x -= wx - src_priv->allocation.x;
5177 src_y -= wy - src_priv->allocation.y;
5181 src_x += src_priv->allocation.x;
5182 src_y += src_priv->allocation.y;
5185 /* Translate to the common ancestor */
5186 window = src_priv->window;
5187 while (window != ancestor->priv->window)
5191 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5196 window = gdk_window_get_effective_parent (window);
5198 if (!window) /* Handle GtkHandleBox */
5203 window = dest_priv->window;
5204 while (window != ancestor->priv->window)
5206 dest_list = g_list_prepend (dest_list, window);
5208 window = gdk_window_get_effective_parent (window);
5210 if (!window) /* Handle GtkHandleBox */
5212 g_list_free (dest_list);
5221 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5226 dest_list = g_list_remove (dest_list, dest_list->data);
5229 /* Translate from window relative to allocation relative */
5230 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5233 gdk_window_get_position (dest_priv->window, &wx, &wy);
5235 src_x += wx - dest_priv->allocation.x;
5236 src_y += wy - dest_priv->allocation.y;
5240 src_x -= dest_priv->allocation.x;
5241 src_y -= dest_priv->allocation.y;
5253 gtk_widget_real_size_allocate (GtkWidget *widget,
5254 GtkAllocation *allocation)
5256 GtkWidgetPrivate *priv = widget->priv;
5258 priv->allocation = *allocation;
5260 if (gtk_widget_get_realized (widget) &&
5261 gtk_widget_get_has_window (widget))
5263 gdk_window_move_resize (priv->window,
5264 allocation->x, allocation->y,
5265 allocation->width, allocation->height);
5269 /* translate initial/final into start/end */
5271 effective_align (GtkAlign align,
5272 GtkTextDirection direction)
5276 case GTK_ALIGN_START:
5277 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5279 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5286 adjust_for_align (GtkAlign align,
5288 gint *allocated_pos,
5289 gint *allocated_size)
5293 case GTK_ALIGN_FILL:
5294 /* change nothing */
5296 case GTK_ALIGN_START:
5297 /* keep *allocated_pos where it is */
5298 *allocated_size = MIN (*allocated_size, *natural_size);
5301 if (*allocated_size > *natural_size)
5303 *allocated_pos += (*allocated_size - *natural_size);
5304 *allocated_size = *natural_size;
5307 case GTK_ALIGN_CENTER:
5308 if (*allocated_size > *natural_size)
5310 *allocated_pos += (*allocated_size - *natural_size) / 2;
5311 *allocated_size = MIN (*allocated_size, *natural_size);
5318 adjust_for_margin(gint start_margin,
5322 gint *allocated_pos,
5323 gint *allocated_size)
5325 *minimum_size -= (start_margin + end_margin);
5326 *natural_size -= (start_margin + end_margin);
5327 *allocated_pos += start_margin;
5328 *allocated_size -= (start_margin + end_margin);
5332 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5333 GtkOrientation orientation,
5336 gint *allocated_pos,
5337 gint *allocated_size)
5339 const GtkWidgetAuxInfo *aux_info;
5341 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5343 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5345 adjust_for_margin (aux_info->margin.left,
5346 aux_info->margin.right,
5347 minimum_size, natural_size,
5348 allocated_pos, allocated_size);
5349 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5350 natural_size, allocated_pos, allocated_size);
5354 adjust_for_margin (aux_info->margin.top,
5355 aux_info->margin.bottom,
5356 minimum_size, natural_size,
5357 allocated_pos, allocated_size);
5358 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5359 natural_size, allocated_pos, allocated_size);
5364 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5367 GtkWidgetPrivate *priv = widget->priv;
5369 /* widgets must be onscreen for accels to take effect */
5370 return gtk_widget_is_sensitive (widget) &&
5371 gtk_widget_is_drawable (widget) &&
5372 gdk_window_is_viewable (priv->window);
5376 * gtk_widget_can_activate_accel:
5377 * @widget: a #GtkWidget
5378 * @signal_id: the ID of a signal installed on @widget
5380 * Determines whether an accelerator that activates the signal
5381 * identified by @signal_id can currently be activated.
5382 * This is done by emitting the #GtkWidget::can-activate-accel
5383 * signal on @widget; if the signal isn't overridden by a
5384 * handler or in a derived widget, then the default check is
5385 * that the widget must be sensitive, and the widget and all
5386 * its ancestors mapped.
5388 * Return value: %TRUE if the accelerator can be activated.
5393 gtk_widget_can_activate_accel (GtkWidget *widget,
5396 gboolean can_activate = FALSE;
5397 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5398 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5399 return can_activate;
5408 closure_accel_activate (GClosure *closure,
5409 GValue *return_value,
5410 guint n_param_values,
5411 const GValue *param_values,
5412 gpointer invocation_hint,
5413 gpointer marshal_data)
5415 AccelClosure *aclosure = (AccelClosure*) closure;
5416 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5419 g_signal_emit (closure->data, aclosure->signal_id, 0);
5421 /* whether accelerator was handled */
5422 g_value_set_boolean (return_value, can_activate);
5426 closures_destroy (gpointer data)
5428 GSList *slist, *closures = data;
5430 for (slist = closures; slist; slist = slist->next)
5432 g_closure_invalidate (slist->data);
5433 g_closure_unref (slist->data);
5435 g_slist_free (closures);
5439 widget_new_accel_closure (GtkWidget *widget,
5442 AccelClosure *aclosure;
5443 GClosure *closure = NULL;
5444 GSList *slist, *closures;
5446 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5447 for (slist = closures; slist; slist = slist->next)
5448 if (!gtk_accel_group_from_accel_closure (slist->data))
5450 /* reuse this closure */
5451 closure = slist->data;
5456 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5457 closures = g_slist_prepend (closures, g_closure_ref (closure));
5458 g_closure_sink (closure);
5459 g_closure_set_marshal (closure, closure_accel_activate);
5461 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5463 aclosure = (AccelClosure*) closure;
5464 g_assert (closure->data == widget);
5465 g_assert (closure->marshal == closure_accel_activate);
5466 aclosure->signal_id = signal_id;
5472 * gtk_widget_add_accelerator:
5473 * @widget: widget to install an accelerator on
5474 * @accel_signal: widget signal to emit on accelerator activation
5475 * @accel_group: accel group for this widget, added to its toplevel
5476 * @accel_key: GDK keyval of the accelerator
5477 * @accel_mods: modifier key combination of the accelerator
5478 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5480 * Installs an accelerator for this @widget in @accel_group that causes
5481 * @accel_signal to be emitted if the accelerator is activated.
5482 * The @accel_group needs to be added to the widget's toplevel via
5483 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5484 * Accelerators added through this function are not user changeable during
5485 * runtime. If you want to support accelerators that can be changed by the
5486 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5487 * gtk_menu_item_set_accel_path() instead.
5490 gtk_widget_add_accelerator (GtkWidget *widget,
5491 const gchar *accel_signal,
5492 GtkAccelGroup *accel_group,
5494 GdkModifierType accel_mods,
5495 GtkAccelFlags accel_flags)
5500 g_return_if_fail (GTK_IS_WIDGET (widget));
5501 g_return_if_fail (accel_signal != NULL);
5502 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5504 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5505 if (!query.signal_id ||
5506 !(query.signal_flags & G_SIGNAL_ACTION) ||
5507 query.return_type != G_TYPE_NONE ||
5510 /* hmm, should be elaborate enough */
5511 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5512 G_OBJECT_TYPE_NAME (widget), accel_signal);
5516 closure = widget_new_accel_closure (widget, query.signal_id);
5518 g_object_ref (widget);
5520 /* install the accelerator. since we don't map this onto an accel_path,
5521 * the accelerator will automatically be locked.
5523 gtk_accel_group_connect (accel_group,
5526 accel_flags | GTK_ACCEL_LOCKED,
5529 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5531 g_object_unref (widget);
5535 * gtk_widget_remove_accelerator:
5536 * @widget: widget to install an accelerator on
5537 * @accel_group: accel group for this widget
5538 * @accel_key: GDK keyval of the accelerator
5539 * @accel_mods: modifier key combination of the accelerator
5541 * Removes an accelerator from @widget, previously installed with
5542 * gtk_widget_add_accelerator().
5544 * Returns: whether an accelerator was installed and could be removed
5547 gtk_widget_remove_accelerator (GtkWidget *widget,
5548 GtkAccelGroup *accel_group,
5550 GdkModifierType accel_mods)
5552 GtkAccelGroupEntry *ag_entry;
5553 GList *slist, *clist;
5556 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5557 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5559 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5560 clist = gtk_widget_list_accel_closures (widget);
5561 for (slist = clist; slist; slist = slist->next)
5565 for (i = 0; i < n; i++)
5566 if (slist->data == (gpointer) ag_entry[i].closure)
5568 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5570 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5572 g_list_free (clist);
5577 g_list_free (clist);
5579 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5580 accel_key, accel_mods, accel_group,
5581 G_OBJECT_TYPE_NAME (widget), widget);
5587 * gtk_widget_list_accel_closures:
5588 * @widget: widget to list accelerator closures for
5590 * Lists the closures used by @widget for accelerator group connections
5591 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5592 * The closures can be used to monitor accelerator changes on @widget,
5593 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5594 * #GtkAccelGroup of a closure which can be found out with
5595 * gtk_accel_group_from_accel_closure().
5597 * Return value: (transfer container) (element-type GClosure):
5598 * a newly allocated #GList of closures
5601 gtk_widget_list_accel_closures (GtkWidget *widget)
5604 GList *clist = NULL;
5606 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5608 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5609 if (gtk_accel_group_from_accel_closure (slist->data))
5610 clist = g_list_prepend (clist, slist->data);
5616 GtkAccelGroup *accel_group;
5621 destroy_accel_path (gpointer data)
5623 AccelPath *apath = data;
5625 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5627 /* closures_destroy takes care of unrefing the closure */
5628 g_object_unref (apath->accel_group);
5630 g_slice_free (AccelPath, apath);
5635 * gtk_widget_set_accel_path:
5636 * @widget: a #GtkWidget
5637 * @accel_path: (allow-none): path used to look up the accelerator
5638 * @accel_group: (allow-none): a #GtkAccelGroup.
5640 * Given an accelerator group, @accel_group, and an accelerator path,
5641 * @accel_path, sets up an accelerator in @accel_group so whenever the
5642 * key binding that is defined for @accel_path is pressed, @widget
5643 * will be activated. This removes any accelerators (for any
5644 * accelerator group) installed by previous calls to
5645 * gtk_widget_set_accel_path(). Associating accelerators with
5646 * paths allows them to be modified by the user and the modifications
5647 * to be saved for future use. (See gtk_accel_map_save().)
5649 * This function is a low level function that would most likely
5650 * be used by a menu creation system like #GtkUIManager. If you
5651 * use #GtkUIManager, setting up accelerator paths will be done
5654 * Even when you you aren't using #GtkUIManager, if you only want to
5655 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5656 * provides a somewhat more convenient interface.
5658 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5659 * pass a static string, you can save some memory by interning it first with
5660 * g_intern_static_string().
5663 gtk_widget_set_accel_path (GtkWidget *widget,
5664 const gchar *accel_path,
5665 GtkAccelGroup *accel_group)
5669 g_return_if_fail (GTK_IS_WIDGET (widget));
5670 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5674 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5675 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5677 gtk_accel_map_add_entry (accel_path, 0, 0);
5678 apath = g_slice_new (AccelPath);
5679 apath->accel_group = g_object_ref (accel_group);
5680 apath->path_quark = g_quark_from_string (accel_path);
5681 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5686 /* also removes possible old settings */
5687 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5690 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5692 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5696 _gtk_widget_get_accel_path (GtkWidget *widget,
5701 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5703 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5705 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5706 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5710 * gtk_widget_mnemonic_activate:
5711 * @widget: a #GtkWidget
5712 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5714 * Emits the #GtkWidget::mnemonic-activate signal.
5716 * The default handler for this signal activates the @widget if
5717 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5720 * Returns: %TRUE if the signal has been handled
5723 gtk_widget_mnemonic_activate (GtkWidget *widget,
5724 gboolean group_cycling)
5728 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5730 group_cycling = group_cycling != FALSE;
5731 if (!gtk_widget_is_sensitive (widget))
5734 g_signal_emit (widget,
5735 widget_signals[MNEMONIC_ACTIVATE],
5743 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5744 gboolean group_cycling)
5746 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5747 gtk_widget_activate (widget);
5748 else if (gtk_widget_get_can_focus (widget))
5749 gtk_widget_grab_focus (widget);
5752 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5753 G_OBJECT_TYPE_NAME (widget));
5754 gtk_widget_error_bell (widget);
5759 static const cairo_user_data_key_t event_key;
5762 _gtk_cairo_get_event (cairo_t *cr)
5764 g_return_val_if_fail (cr != NULL, NULL);
5766 return cairo_get_user_data (cr, &event_key);
5770 gtk_cairo_set_event (cairo_t *cr,
5771 GdkEventExpose *event)
5773 cairo_set_user_data (cr, &event_key, event, NULL);
5777 * gtk_cairo_should_draw_window:
5778 * @cr: a cairo context
5779 * @window: the window to check. @window may not be an input-only
5782 * This function is supposed to be called in #GtkWidget::draw
5783 * implementations for widgets that support multiple windows.
5784 * @cr must be untransformed from invoking of the draw function.
5785 * This function will return %TRUE if the contents of the given
5786 * @window are supposed to be drawn and %FALSE otherwise. Note
5787 * that when the drawing was not initiated by the windowing
5788 * system this function will return %TRUE for all windows, so
5789 * you need to draw the bottommost window first. Also, do not
5790 * use "else if" statements to check which window should be drawn.
5792 * Returns: %TRUE if @window should be drawn
5797 gtk_cairo_should_draw_window (cairo_t *cr,
5800 GdkEventExpose *event;
5802 g_return_val_if_fail (cr != NULL, FALSE);
5803 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5805 event = _gtk_cairo_get_event (cr);
5807 return event == NULL ||
5808 event->window == window;
5812 gtk_widget_get_clip_draw (GtkWidget *widget)
5814 /* labels are not clipped, because clipping them would cause
5815 * mnemonics to not appear on characters that go beyond the
5817 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5819 if (GTK_IS_LABEL (widget))
5825 /* code shared by gtk_container_propagate_draw() and
5829 _gtk_widget_draw_internal (GtkWidget *widget,
5831 gboolean clip_to_size)
5833 if (!gtk_widget_is_drawable (widget))
5836 clip_to_size &= gtk_widget_get_clip_draw (widget);
5840 cairo_rectangle (cr,
5842 widget->priv->allocation.width,
5843 widget->priv->allocation.height);
5847 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5851 g_signal_emit (widget, widget_signals[DRAW],
5855 if (cairo_status (cr) &&
5856 _gtk_cairo_get_event (cr))
5858 /* We check the event so we only warn about internal GTK calls.
5859 * Errors might come from PDF streams having write failures and
5860 * we don't want to spam stderr in that case.
5861 * We do want to catch errors from
5863 g_warning ("drawing failure for widget `%s': %s",
5864 G_OBJECT_TYPE_NAME (widget),
5865 cairo_status_to_string (cairo_status (cr)));
5872 * @widget: the widget to draw. It must be drawable (see
5873 * gtk_widget_is_drawable()) and a size must have been allocated.
5874 * @cr: a cairo context to draw to
5876 * Draws @widget to @cr. The top left corner of the widget will be
5877 * drawn to the currently set origin point of @cr.
5879 * You should pass a cairo context as @cr argument that is in an
5880 * original state. Otherwise the resulting drawing is undefined. For
5881 * example changing the operator using cairo_set_operator() or the
5882 * line width using cairo_set_line_width() might have unwanted side
5884 * You may however change the context's transform matrix - like with
5885 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5886 * region with cairo_clip() prior to calling this function. Also, it
5887 * is fine to modify the context with cairo_save() and
5888 * cairo_push_group() prior to calling this function.
5890 * <note><para>Special purpose widgets may contain special code for
5891 * rendering to the screen and might appear differently on screen
5892 * and when rendered using gtk_widget_draw().</para></note>
5897 gtk_widget_draw (GtkWidget *widget,
5900 GdkEventExpose *tmp_event;
5902 g_return_if_fail (GTK_IS_WIDGET (widget));
5903 g_return_if_fail (!widget->priv->alloc_needed);
5904 g_return_if_fail (cr != NULL);
5907 /* We have to reset the event here so that draw functions can call
5908 * gtk_widget_draw() on random other widgets and get the desired
5909 * effect: Drawing all contents, not just the current window.
5911 tmp_event = _gtk_cairo_get_event (cr);
5912 gtk_cairo_set_event (cr, NULL);
5914 _gtk_widget_draw_internal (widget, cr, TRUE);
5916 gtk_cairo_set_event (cr, tmp_event);
5921 gtk_widget_real_key_press_event (GtkWidget *widget,
5924 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5928 gtk_widget_real_key_release_event (GtkWidget *widget,
5931 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5935 gtk_widget_real_focus_in_event (GtkWidget *widget,
5936 GdkEventFocus *event)
5938 gtk_widget_queue_draw (widget);
5944 gtk_widget_real_focus_out_event (GtkWidget *widget,
5945 GdkEventFocus *event)
5947 gtk_widget_queue_draw (widget);
5953 gtk_widget_real_touch_event (GtkWidget *widget,
5954 GdkEventTouch *event)
5957 gboolean return_val;
5960 if (!event->emulating_pointer)
5963 if (event->type == GDK_TOUCH_BEGIN ||
5964 event->type == GDK_TOUCH_END)
5968 if (event->type == GDK_TOUCH_BEGIN)
5970 type = GDK_BUTTON_PRESS;
5971 signum = BUTTON_PRESS_EVENT;
5975 type = GDK_BUTTON_RELEASE;
5976 signum = BUTTON_RELEASE_EVENT;
5978 bevent = gdk_event_new (type);
5979 bevent->any.window = g_object_ref (event->window);
5980 bevent->any.send_event = FALSE;
5981 bevent->button.time = event->time;
5982 bevent->button.state = event->state;
5983 bevent->button.button = 1;
5984 bevent->button.x_root = event->x_root;
5985 bevent->button.y_root = event->y_root;
5986 bevent->button.x = event->x;
5987 bevent->button.y = event->y;
5988 bevent->button.device = event->device;
5989 bevent->button.axes = g_memdup (event->axes,
5990 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5991 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5993 else if (event->type == GDK_TOUCH_UPDATE)
5995 signum = MOTION_NOTIFY_EVENT;
5996 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5997 bevent->any.window = g_object_ref (event->window);
5998 bevent->any.send_event = FALSE;
5999 bevent->motion.time = event->time;
6000 bevent->motion.state = event->state;
6001 bevent->motion.x_root = event->x_root;
6002 bevent->motion.y_root = event->y_root;
6003 bevent->motion.x = event->x;
6004 bevent->motion.y = event->y;
6005 bevent->motion.device = event->device;
6006 bevent->motion.is_hint = FALSE;
6007 bevent->motion.axes = g_memdup (event->axes,
6008 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6009 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6014 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6016 gdk_event_free (bevent);
6022 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6023 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6027 * @widget: a #GtkWidget
6028 * @event: a #GdkEvent
6030 * Rarely-used function. This function is used to emit
6031 * the event signals on a widget (those signals should never
6032 * be emitted without using this function to do so).
6033 * If you want to synthesize an event though, don't use this function;
6034 * instead, use gtk_main_do_event() so the event will behave as if
6035 * it were in the event queue. Don't synthesize expose events; instead,
6036 * use gdk_window_invalidate_rect() to invalidate a region of the
6039 * Return value: return from the event signal emission (%TRUE if
6040 * the event was handled)
6043 gtk_widget_event (GtkWidget *widget,
6046 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6047 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6049 if (event->type == GDK_EXPOSE)
6051 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6052 "the same effect, call gdk_window_invalidate_rect/region(), "
6053 "followed by gdk_window_process_updates().");
6057 return gtk_widget_event_internal (widget, event);
6061 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6062 GtkCapturedEventHandler callback)
6064 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6068 _gtk_widget_captured_event (GtkWidget *widget,
6071 gboolean return_val = FALSE;
6072 GtkCapturedEventHandler handler;
6074 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6075 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6077 if (event->type == GDK_EXPOSE)
6079 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6080 "the same effect, call gdk_window_invalidate_rect/region(), "
6081 "followed by gdk_window_process_updates().");
6085 if (!event_window_is_still_viewable (event))
6088 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6092 g_object_ref (widget);
6094 return_val = handler (widget, event);
6095 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6097 /* The widget that was originally to receive the event
6098 * handles motion hints, but the capturing widget might
6099 * not, so ensure we get further motion events.
6102 event->type == GDK_MOTION_NOTIFY &&
6103 event->motion.is_hint &&
6104 (gdk_window_get_events (event->any.window) &
6105 GDK_POINTER_MOTION_HINT_MASK) != 0)
6106 gdk_event_request_motions (&event->motion);
6108 g_object_unref (widget);
6113 /* Returns TRUE if a translation should be done */
6115 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6120 GdkWindow *w, *widget_window;
6122 if (!gtk_widget_get_has_window (widget))
6124 *x = -widget->priv->allocation.x;
6125 *y = -widget->priv->allocation.y;
6133 widget_window = gtk_widget_get_window (widget);
6135 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6138 gdk_window_get_position (w, &wx, &wy);
6155 * gtk_cairo_transform_to_window:
6156 * @cr: the cairo context to transform
6157 * @widget: the widget the context is currently centered for
6158 * @window: the window to transform the context to
6160 * Transforms the given cairo context @cr that from @widget-relative
6161 * coordinates to @window-relative coordinates.
6162 * If the @widget's window is not an ancestor of @window, no
6163 * modification will be applied.
6165 * This is the inverse to the transformation GTK applies when
6166 * preparing an expose event to be emitted with the #GtkWidget::draw
6167 * signal. It is intended to help porting multiwindow widgets from
6168 * GTK+ 2 to the rendering architecture of GTK+ 3.
6173 gtk_cairo_transform_to_window (cairo_t *cr,
6179 g_return_if_fail (cr != NULL);
6180 g_return_if_fail (GTK_IS_WIDGET (widget));
6181 g_return_if_fail (GDK_IS_WINDOW (window));
6183 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6184 cairo_translate (cr, x, y);
6188 * gtk_widget_send_expose:
6189 * @widget: a #GtkWidget
6190 * @event: a expose #GdkEvent
6192 * Very rarely-used function. This function is used to emit
6193 * an expose event on a widget. This function is not normally used
6194 * directly. The only time it is used is when propagating an expose
6195 * event to a child %NO_WINDOW widget, and that is normally done
6196 * using gtk_container_propagate_draw().
6198 * If you want to force an area of a window to be redrawn,
6199 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6200 * To cause the redraw to be done immediately, follow that call
6201 * with a call to gdk_window_process_updates().
6203 * Return value: return from the event signal emission (%TRUE if
6204 * the event was handled)
6207 gtk_widget_send_expose (GtkWidget *widget,
6210 gboolean result = FALSE;
6215 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6216 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6217 g_return_val_if_fail (event != NULL, TRUE);
6218 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6220 cr = gdk_cairo_create (event->expose.window);
6221 gtk_cairo_set_event (cr, &event->expose);
6223 gdk_cairo_region (cr, event->expose.region);
6226 do_clip = _gtk_widget_get_translation_to_window (widget,
6227 event->expose.window,
6229 cairo_translate (cr, -x, -y);
6231 _gtk_widget_draw_internal (widget, cr, do_clip);
6233 /* unset here, so if someone keeps a reference to cr we
6234 * don't leak the window. */
6235 gtk_cairo_set_event (cr, NULL);
6242 event_window_is_still_viewable (GdkEvent *event)
6244 /* Check that we think the event's window is viewable before
6245 * delivering the event, to prevent suprises. We do this here
6246 * at the last moment, since the event may have been queued
6247 * up behind other events, held over a recursive main loop, etc.
6249 switch (event->type)
6252 case GDK_MOTION_NOTIFY:
6253 case GDK_BUTTON_PRESS:
6254 case GDK_2BUTTON_PRESS:
6255 case GDK_3BUTTON_PRESS:
6257 case GDK_ENTER_NOTIFY:
6258 case GDK_PROXIMITY_IN:
6260 return event->any.window && gdk_window_is_viewable (event->any.window);
6263 /* The following events are the second half of paired events;
6264 * we always deliver them to deal with widgets that clean up
6265 * on the second half.
6267 case GDK_BUTTON_RELEASE:
6268 case GDK_KEY_RELEASE:
6269 case GDK_LEAVE_NOTIFY:
6270 case GDK_PROXIMITY_OUT:
6274 /* Remaining events would make sense on an not-viewable window,
6275 * or don't have an associated window.
6282 gtk_widget_event_internal (GtkWidget *widget,
6285 gboolean return_val = FALSE;
6287 /* We check only once for is-still-visible; if someone
6288 * hides the window in on of the signals on the widget,
6289 * they are responsible for returning TRUE to terminate
6292 if (!event_window_is_still_viewable (event))
6295 g_object_ref (widget);
6297 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6298 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6303 switch (event->type)
6309 case GDK_BUTTON_PRESS:
6310 case GDK_2BUTTON_PRESS:
6311 case GDK_3BUTTON_PRESS:
6312 signal_num = BUTTON_PRESS_EVENT;
6314 case GDK_TOUCH_BEGIN:
6315 case GDK_TOUCH_UPDATE:
6317 case GDK_TOUCH_CANCEL:
6318 signal_num = TOUCH_EVENT;
6321 signal_num = SCROLL_EVENT;
6323 case GDK_BUTTON_RELEASE:
6324 signal_num = BUTTON_RELEASE_EVENT;
6326 case GDK_MOTION_NOTIFY:
6327 signal_num = MOTION_NOTIFY_EVENT;
6330 signal_num = DELETE_EVENT;
6333 signal_num = DESTROY_EVENT;
6334 _gtk_tooltip_hide (widget);
6337 signal_num = KEY_PRESS_EVENT;
6339 case GDK_KEY_RELEASE:
6340 signal_num = KEY_RELEASE_EVENT;
6342 case GDK_ENTER_NOTIFY:
6343 signal_num = ENTER_NOTIFY_EVENT;
6345 case GDK_LEAVE_NOTIFY:
6346 signal_num = LEAVE_NOTIFY_EVENT;
6348 case GDK_FOCUS_CHANGE:
6349 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6350 if (event->focus_change.in)
6351 _gtk_tooltip_focus_in (widget);
6353 _gtk_tooltip_focus_out (widget);
6356 signal_num = CONFIGURE_EVENT;
6359 signal_num = MAP_EVENT;
6362 signal_num = UNMAP_EVENT;
6364 case GDK_WINDOW_STATE:
6365 signal_num = WINDOW_STATE_EVENT;
6367 case GDK_PROPERTY_NOTIFY:
6368 signal_num = PROPERTY_NOTIFY_EVENT;
6370 case GDK_SELECTION_CLEAR:
6371 signal_num = SELECTION_CLEAR_EVENT;
6373 case GDK_SELECTION_REQUEST:
6374 signal_num = SELECTION_REQUEST_EVENT;
6376 case GDK_SELECTION_NOTIFY:
6377 signal_num = SELECTION_NOTIFY_EVENT;
6379 case GDK_PROXIMITY_IN:
6380 signal_num = PROXIMITY_IN_EVENT;
6382 case GDK_PROXIMITY_OUT:
6383 signal_num = PROXIMITY_OUT_EVENT;
6385 case GDK_VISIBILITY_NOTIFY:
6386 signal_num = VISIBILITY_NOTIFY_EVENT;
6388 case GDK_GRAB_BROKEN:
6389 signal_num = GRAB_BROKEN_EVENT;
6392 signal_num = DAMAGE_EVENT;
6395 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6399 if (signal_num != -1)
6400 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6402 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6403 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6407 g_object_unref (widget);
6413 * gtk_widget_activate:
6414 * @widget: a #GtkWidget that's activatable
6416 * For widgets that can be "activated" (buttons, menu items, etc.)
6417 * this function activates them. Activation is what happens when you
6418 * press Enter on a widget during key navigation. If @widget isn't
6419 * activatable, the function returns %FALSE.
6421 * Return value: %TRUE if the widget was activatable
6424 gtk_widget_activate (GtkWidget *widget)
6426 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6428 if (WIDGET_CLASS (widget)->activate_signal)
6430 /* FIXME: we should eventually check the signals signature here */
6431 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6440 gtk_widget_reparent_subwindows (GtkWidget *widget,
6441 GdkWindow *new_window)
6443 GtkWidgetPrivate *priv = widget->priv;
6445 if (!gtk_widget_get_has_window (widget))
6447 GList *children = gdk_window_get_children (priv->window);
6450 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6452 GdkWindow *window = tmp_list->data;
6455 gdk_window_get_user_data (window, &child);
6456 while (child && child != widget)
6457 child = ((GtkWidget*) child)->priv->parent;
6460 gdk_window_reparent (window, new_window, 0, 0);
6463 g_list_free (children);
6468 GList *tmp_list, *children;
6470 parent = gdk_window_get_parent (priv->window);
6473 gdk_window_reparent (priv->window, new_window, 0, 0);
6476 children = gdk_window_get_children (parent);
6478 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6480 GdkWindow *window = tmp_list->data;
6483 gdk_window_get_user_data (window, &child);
6485 if (child == widget)
6486 gdk_window_reparent (window, new_window, 0, 0);
6489 g_list_free (children);
6495 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6496 gpointer client_data)
6498 GtkWidgetPrivate *priv = widget->priv;
6500 g_assert (client_data != NULL);
6502 if (!gtk_widget_get_has_window (widget))
6505 g_object_unref (priv->window);
6506 priv->window = (GdkWindow*) client_data;
6508 g_object_ref (priv->window);
6510 if (GTK_IS_CONTAINER (widget))
6511 gtk_container_forall (GTK_CONTAINER (widget),
6512 gtk_widget_reparent_fixup_child,
6518 * gtk_widget_reparent:
6519 * @widget: a #GtkWidget
6520 * @new_parent: a #GtkContainer to move the widget into
6522 * Moves a widget from one #GtkContainer to another, handling reference
6523 * count issues to avoid destroying the widget.
6526 gtk_widget_reparent (GtkWidget *widget,
6527 GtkWidget *new_parent)
6529 GtkWidgetPrivate *priv;
6531 g_return_if_fail (GTK_IS_WIDGET (widget));
6532 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6533 priv = widget->priv;
6534 g_return_if_fail (priv->parent != NULL);
6536 if (priv->parent != new_parent)
6538 /* First try to see if we can get away without unrealizing
6539 * the widget as we reparent it. if so we set a flag so
6540 * that gtk_widget_unparent doesn't unrealize widget
6542 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6543 priv->in_reparent = TRUE;
6545 g_object_ref (widget);
6546 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6547 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6548 g_object_unref (widget);
6550 if (priv->in_reparent)
6552 priv->in_reparent = FALSE;
6554 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6555 gtk_widget_reparent_fixup_child (widget,
6556 gtk_widget_get_parent_window (widget));
6559 g_object_notify (G_OBJECT (widget), "parent");
6564 * gtk_widget_intersect:
6565 * @widget: a #GtkWidget
6566 * @area: a rectangle
6567 * @intersection: rectangle to store intersection of @widget and @area
6569 * Computes the intersection of a @widget's area and @area, storing
6570 * the intersection in @intersection, and returns %TRUE if there was
6571 * an intersection. @intersection may be %NULL if you're only
6572 * interested in whether there was an intersection.
6574 * Return value: %TRUE if there was an intersection
6577 gtk_widget_intersect (GtkWidget *widget,
6578 const GdkRectangle *area,
6579 GdkRectangle *intersection)
6581 GtkWidgetPrivate *priv;
6586 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6587 g_return_val_if_fail (area != NULL, FALSE);
6589 priv = widget->priv;
6592 dest = intersection;
6596 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6598 if (return_val && intersection && gtk_widget_get_has_window (widget))
6600 intersection->x -= priv->allocation.x;
6601 intersection->y -= priv->allocation.y;
6608 * gtk_widget_region_intersect:
6609 * @widget: a #GtkWidget
6610 * @region: a #cairo_region_t, in the same coordinate system as
6611 * @widget->allocation. That is, relative to @widget->window
6612 * for %NO_WINDOW widgets; relative to the parent window
6613 * of @widget->window for widgets with their own window.
6615 * Computes the intersection of a @widget's area and @region, returning
6616 * the intersection. The result may be empty, use cairo_region_is_empty() to
6619 * Returns: A newly allocated region holding the intersection of @widget
6620 * and @region. The coordinates of the return value are relative to
6621 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6622 * window of @widget->window for widgets with their own window.
6625 gtk_widget_region_intersect (GtkWidget *widget,
6626 const cairo_region_t *region)
6629 cairo_region_t *dest;
6631 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6632 g_return_val_if_fail (region != NULL, NULL);
6634 gtk_widget_get_allocation (widget, &rect);
6636 dest = cairo_region_create_rectangle (&rect);
6638 cairo_region_intersect (dest, region);
6644 * _gtk_widget_grab_notify:
6645 * @widget: a #GtkWidget
6646 * @was_grabbed: whether a grab is now in effect
6648 * Emits the #GtkWidget::grab-notify signal on @widget.
6653 _gtk_widget_grab_notify (GtkWidget *widget,
6654 gboolean was_grabbed)
6656 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6660 * gtk_widget_grab_focus:
6661 * @widget: a #GtkWidget
6663 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6664 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6665 * something like #GtkFrame won't work.
6667 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6668 * gtk_widget_set_can_focus() to modify that flag.
6670 * The widget also needs to be realized and mapped. This is indicated by the
6671 * related signals. Grabbing the focus immediately after creating the widget
6672 * will likely fail and cause critical warnings.
6675 gtk_widget_grab_focus (GtkWidget *widget)
6677 g_return_if_fail (GTK_IS_WIDGET (widget));
6679 if (!gtk_widget_is_sensitive (widget))
6682 g_object_ref (widget);
6683 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6684 g_object_notify (G_OBJECT (widget), "has-focus");
6685 g_object_unref (widget);
6689 reset_focus_recurse (GtkWidget *widget,
6692 if (GTK_IS_CONTAINER (widget))
6694 GtkContainer *container;
6696 container = GTK_CONTAINER (widget);
6697 gtk_container_set_focus_child (container, NULL);
6699 gtk_container_foreach (container,
6700 reset_focus_recurse,
6706 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6708 if (gtk_widget_get_can_focus (focus_widget))
6710 GtkWidget *toplevel;
6713 /* clear the current focus setting, break if the current widget
6714 * is the focus widget's parent, since containers above that will
6715 * be set by the next loop.
6717 toplevel = gtk_widget_get_toplevel (focus_widget);
6718 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6720 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6722 if (widget == focus_widget)
6724 /* We call _gtk_window_internal_set_focus() here so that the
6725 * toplevel window can request the focus if necessary.
6726 * This is needed when the toplevel is a GtkPlug
6728 if (!gtk_widget_has_focus (widget))
6729 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6736 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6738 if (widget != common_ancestor)
6740 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6742 widget = widget->priv->parent;
6743 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6748 else if (toplevel != focus_widget)
6750 /* gtk_widget_grab_focus() operates on a tree without window...
6751 * actually, this is very questionable behaviour.
6754 gtk_container_foreach (GTK_CONTAINER (toplevel),
6755 reset_focus_recurse,
6759 /* now propagate the new focus up the widget tree and finally
6760 * set it on the window
6762 widget = focus_widget;
6763 while (widget->priv->parent)
6765 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6766 widget = widget->priv->parent;
6768 if (GTK_IS_WINDOW (widget))
6769 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6774 gtk_widget_real_query_tooltip (GtkWidget *widget,
6777 gboolean keyboard_tip,
6778 GtkTooltip *tooltip)
6780 gchar *tooltip_markup;
6781 gboolean has_tooltip;
6783 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6784 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6786 if (has_tooltip && tooltip_markup)
6788 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6796 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6797 GtkStateFlags old_state)
6799 gtk_widget_update_pango_context (widget);
6803 gtk_widget_real_style_updated (GtkWidget *widget)
6805 GtkWidgetPrivate *priv = widget->priv;
6807 gtk_widget_update_pango_context (widget);
6808 gtk_widget_update_alpha (widget);
6810 if (priv->style != NULL &&
6811 priv->style != gtk_widget_get_default_style ())
6813 /* Trigger ::style-set for old
6814 * widgets not listening to this
6816 g_signal_emit (widget,
6817 widget_signals[STYLE_SET],
6819 widget->priv->style);
6822 if (widget->priv->context)
6824 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6826 if (gtk_widget_get_realized (widget) &&
6827 gtk_widget_get_has_window (widget) &&
6828 !gtk_widget_get_app_paintable (widget))
6829 gtk_style_context_set_background (widget->priv->context,
6830 widget->priv->window);
6832 if (widget->priv->anchored)
6834 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6835 gtk_widget_queue_resize (widget);
6837 gtk_widget_queue_draw (widget);
6842 if (widget->priv->anchored)
6843 gtk_widget_queue_resize (widget);
6848 gtk_widget_real_show_help (GtkWidget *widget,
6849 GtkWidgetHelpType help_type)
6851 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6853 _gtk_tooltip_toggle_keyboard_mode (widget);
6862 gtk_widget_real_focus (GtkWidget *widget,
6863 GtkDirectionType direction)
6865 if (!gtk_widget_get_can_focus (widget))
6868 if (!gtk_widget_is_focus (widget))
6870 gtk_widget_grab_focus (widget);
6878 gtk_widget_real_move_focus (GtkWidget *widget,
6879 GtkDirectionType direction)
6881 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6883 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6885 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6891 gtk_widget_real_keynav_failed (GtkWidget *widget,
6892 GtkDirectionType direction)
6894 gboolean cursor_only;
6898 case GTK_DIR_TAB_FORWARD:
6899 case GTK_DIR_TAB_BACKWARD:
6906 g_object_get (gtk_widget_get_settings (widget),
6907 "gtk-keynav-cursor-only", &cursor_only,
6914 gtk_widget_error_bell (widget);
6920 * gtk_widget_set_can_focus:
6921 * @widget: a #GtkWidget
6922 * @can_focus: whether or not @widget can own the input focus.
6924 * Specifies whether @widget can own the input focus. See
6925 * gtk_widget_grab_focus() for actually setting the input focus on a
6931 gtk_widget_set_can_focus (GtkWidget *widget,
6934 g_return_if_fail (GTK_IS_WIDGET (widget));
6936 if (widget->priv->can_focus != can_focus)
6938 widget->priv->can_focus = can_focus;
6940 gtk_widget_queue_resize (widget);
6941 g_object_notify (G_OBJECT (widget), "can-focus");
6946 * gtk_widget_get_can_focus:
6947 * @widget: a #GtkWidget
6949 * Determines whether @widget can own the input focus. See
6950 * gtk_widget_set_can_focus().
6952 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6957 gtk_widget_get_can_focus (GtkWidget *widget)
6959 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6961 return widget->priv->can_focus;
6965 * gtk_widget_has_focus:
6966 * @widget: a #GtkWidget
6968 * Determines if the widget has the global input focus. See
6969 * gtk_widget_is_focus() for the difference between having the global
6970 * input focus, and only having the focus within a toplevel.
6972 * Return value: %TRUE if the widget has the global input focus.
6977 gtk_widget_has_focus (GtkWidget *widget)
6979 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6981 return widget->priv->has_focus;
6985 * gtk_widget_has_visible_focus:
6986 * @widget: a #GtkWidget
6988 * Determines if the widget should show a visible indication that
6989 * it has the global input focus. This is a convenience function for
6990 * use in ::draw handlers that takes into account whether focus
6991 * indication should currently be shown in the toplevel window of
6992 * @widget. See gtk_window_get_focus_visible() for more information
6993 * about focus indication.
6995 * To find out if the widget has the global input focus, use
6996 * gtk_widget_has_focus().
6998 * Return value: %TRUE if the widget should display a 'focus rectangle'
7003 gtk_widget_has_visible_focus (GtkWidget *widget)
7005 gboolean draw_focus;
7007 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7009 if (widget->priv->has_focus)
7011 GtkWidget *toplevel;
7013 toplevel = gtk_widget_get_toplevel (widget);
7015 if (GTK_IS_WINDOW (toplevel))
7016 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7027 * gtk_widget_is_focus:
7028 * @widget: a #GtkWidget
7030 * Determines if the widget is the focus widget within its
7031 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7032 * necessarily set; %HAS_FOCUS will only be set if the
7033 * toplevel widget additionally has the global input focus.)
7035 * Return value: %TRUE if the widget is the focus widget.
7038 gtk_widget_is_focus (GtkWidget *widget)
7040 GtkWidget *toplevel;
7042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7044 toplevel = gtk_widget_get_toplevel (widget);
7046 if (GTK_IS_WINDOW (toplevel))
7047 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7053 * gtk_widget_set_can_default:
7054 * @widget: a #GtkWidget
7055 * @can_default: whether or not @widget can be a default widget.
7057 * Specifies whether @widget can be a default widget. See
7058 * gtk_widget_grab_default() for details about the meaning of
7064 gtk_widget_set_can_default (GtkWidget *widget,
7065 gboolean can_default)
7067 g_return_if_fail (GTK_IS_WIDGET (widget));
7069 if (widget->priv->can_default != can_default)
7071 widget->priv->can_default = can_default;
7073 gtk_widget_queue_resize (widget);
7074 g_object_notify (G_OBJECT (widget), "can-default");
7079 * gtk_widget_get_can_default:
7080 * @widget: a #GtkWidget
7082 * Determines whether @widget can be a default widget. See
7083 * gtk_widget_set_can_default().
7085 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7090 gtk_widget_get_can_default (GtkWidget *widget)
7092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7094 return widget->priv->can_default;
7098 * gtk_widget_has_default:
7099 * @widget: a #GtkWidget
7101 * Determines whether @widget is the current default widget within its
7102 * toplevel. See gtk_widget_set_can_default().
7104 * Return value: %TRUE if @widget is the current default widget within
7105 * its toplevel, %FALSE otherwise
7110 gtk_widget_has_default (GtkWidget *widget)
7112 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7114 return widget->priv->has_default;
7118 _gtk_widget_set_has_default (GtkWidget *widget,
7119 gboolean has_default)
7121 GtkStyleContext *context;
7123 widget->priv->has_default = has_default;
7125 context = gtk_widget_get_style_context (widget);
7128 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7130 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7134 * gtk_widget_grab_default:
7135 * @widget: a #GtkWidget
7137 * Causes @widget to become the default widget. @widget must be able to be
7138 * a default widget; typically you would ensure this yourself
7139 * by calling gtk_widget_set_can_default() with a %TRUE value.
7140 * The default widget is activated when
7141 * the user presses Enter in a window. Default widgets must be
7142 * activatable, that is, gtk_widget_activate() should affect them. Note
7143 * that #GtkEntry widgets require the "activates-default" property
7144 * set to %TRUE before they activate the default widget when Enter
7145 * is pressed and the #GtkEntry is focused.
7148 gtk_widget_grab_default (GtkWidget *widget)
7152 g_return_if_fail (GTK_IS_WIDGET (widget));
7153 g_return_if_fail (gtk_widget_get_can_default (widget));
7155 window = gtk_widget_get_toplevel (widget);
7157 if (window && gtk_widget_is_toplevel (window))
7158 gtk_window_set_default (GTK_WINDOW (window), widget);
7160 g_warning (G_STRLOC ": widget not within a GtkWindow");
7164 * gtk_widget_set_receives_default:
7165 * @widget: a #GtkWidget
7166 * @receives_default: whether or not @widget can be a default widget.
7168 * Specifies whether @widget will be treated as the default widget
7169 * within its toplevel when it has the focus, even if another widget
7172 * See gtk_widget_grab_default() for details about the meaning of
7178 gtk_widget_set_receives_default (GtkWidget *widget,
7179 gboolean receives_default)
7181 g_return_if_fail (GTK_IS_WIDGET (widget));
7183 if (widget->priv->receives_default != receives_default)
7185 widget->priv->receives_default = receives_default;
7187 g_object_notify (G_OBJECT (widget), "receives-default");
7192 * gtk_widget_get_receives_default:
7193 * @widget: a #GtkWidget
7195 * Determines whether @widget is alyways treated as default widget
7196 * withing its toplevel when it has the focus, even if another widget
7199 * See gtk_widget_set_receives_default().
7201 * Return value: %TRUE if @widget acts as default widget when focussed,
7207 gtk_widget_get_receives_default (GtkWidget *widget)
7209 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7211 return widget->priv->receives_default;
7215 * gtk_widget_has_grab:
7216 * @widget: a #GtkWidget
7218 * Determines whether the widget is currently grabbing events, so it
7219 * is the only widget receiving input events (keyboard and mouse).
7221 * See also gtk_grab_add().
7223 * Return value: %TRUE if the widget is in the grab_widgets stack
7228 gtk_widget_has_grab (GtkWidget *widget)
7230 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7232 return widget->priv->has_grab;
7236 _gtk_widget_set_has_grab (GtkWidget *widget,
7239 widget->priv->has_grab = has_grab;
7243 * gtk_widget_device_is_shadowed:
7244 * @widget: a #GtkWidget
7245 * @device: a #GdkDevice
7247 * Returns %TRUE if @device has been shadowed by a GTK+
7248 * device grab on another widget, so it would stop sending
7249 * events to @widget. This may be used in the
7250 * #GtkWidget::grab-notify signal to check for specific
7251 * devices. See gtk_device_grab_add().
7253 * Returns: %TRUE if there is an ongoing grab on @device
7254 * by another #GtkWidget than @widget.
7259 gtk_widget_device_is_shadowed (GtkWidget *widget,
7262 GtkWindowGroup *group;
7263 GtkWidget *grab_widget, *toplevel;
7265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7266 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7268 if (!gtk_widget_get_realized (widget))
7271 toplevel = gtk_widget_get_toplevel (widget);
7273 if (GTK_IS_WINDOW (toplevel))
7274 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7276 group = gtk_window_get_group (NULL);
7278 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7280 /* Widget not inside the hierarchy of grab_widget */
7282 widget != grab_widget &&
7283 !gtk_widget_is_ancestor (widget, grab_widget))
7286 grab_widget = gtk_window_group_get_current_grab (group);
7287 if (grab_widget && widget != grab_widget &&
7288 !gtk_widget_is_ancestor (widget, grab_widget))
7295 * gtk_widget_set_name:
7296 * @widget: a #GtkWidget
7297 * @name: name for the widget
7299 * Widgets can be named, which allows you to refer to them from a
7300 * CSS file. You can apply a style to widgets with a particular name
7301 * in the CSS file. See the documentation for the CSS syntax (on the
7302 * same page as the docs for #GtkStyleContext).
7304 * Note that the CSS syntax has certain special characters to delimit
7305 * and represent elements in a selector (period, #, >, *...),
7306 * so using these will make your widget impossible to match by name.
7307 * Any combination of alphanumeric symbols, dashes and underscores will
7311 gtk_widget_set_name (GtkWidget *widget,
7314 GtkWidgetPrivate *priv;
7317 g_return_if_fail (GTK_IS_WIDGET (widget));
7319 priv = widget->priv;
7321 new_name = g_strdup (name);
7322 g_free (priv->name);
7323 priv->name = new_name;
7325 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7327 g_object_notify (G_OBJECT (widget), "name");
7331 * gtk_widget_get_name:
7332 * @widget: a #GtkWidget
7334 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7335 * significance of widget names.
7337 * Return value: name of the widget. This string is owned by GTK+ and
7338 * should not be modified or freed
7341 gtk_widget_get_name (GtkWidget *widget)
7343 GtkWidgetPrivate *priv;
7345 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7347 priv = widget->priv;
7351 return G_OBJECT_TYPE_NAME (widget);
7355 gtk_widget_update_state_flags (GtkWidget *widget,
7356 GtkStateFlags flags_to_set,
7357 GtkStateFlags flags_to_unset)
7359 GtkWidgetPrivate *priv;
7361 priv = widget->priv;
7363 /* Handle insensitive first, since it is propagated
7364 * differently throughout the widget hierarchy.
7366 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7367 gtk_widget_set_sensitive (widget, TRUE);
7368 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7369 gtk_widget_set_sensitive (widget, FALSE);
7371 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7372 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7374 if (flags_to_set != 0 || flags_to_unset != 0)
7378 data.flags_to_set = flags_to_set;
7379 data.flags_to_unset = flags_to_unset;
7381 gtk_widget_propagate_state (widget, &data);
7386 * gtk_widget_set_state_flags:
7387 * @widget: a #GtkWidget
7388 * @flags: State flags to turn on
7389 * @clear: Whether to clear state before turning on @flags
7391 * This function is for use in widget implementations. Turns on flag
7392 * values in the current widget state (insensitive, prelighted, etc.).
7394 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7395 * will be propagated down to all non-internal children if @widget is a
7396 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7397 * down to all #GtkContainer children by different means than turning on the
7398 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7399 * gtk_widget_is_sensitive() will make use of these.
7404 gtk_widget_set_state_flags (GtkWidget *widget,
7405 GtkStateFlags flags,
7408 g_return_if_fail (GTK_IS_WIDGET (widget));
7410 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7411 (clear && widget->priv->state_flags == flags))
7415 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7417 gtk_widget_update_state_flags (widget, flags, 0);
7421 * gtk_widget_unset_state_flags:
7422 * @widget: a #GtkWidget
7423 * @flags: State flags to turn off
7425 * This function is for use in widget implementations. Turns off flag
7426 * values for the current widget state (insensitive, prelighted, etc.).
7427 * See gtk_widget_set_state_flags().
7432 gtk_widget_unset_state_flags (GtkWidget *widget,
7433 GtkStateFlags flags)
7435 g_return_if_fail (GTK_IS_WIDGET (widget));
7437 if ((widget->priv->state_flags & flags) == 0)
7440 gtk_widget_update_state_flags (widget, 0, flags);
7444 * gtk_widget_get_state_flags:
7445 * @widget: a #GtkWidget
7447 * Returns the widget state as a flag set. It is worth mentioning
7448 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7449 * returned, that is, also based on parent insensitivity, even if
7450 * @widget itself is sensitive.
7452 * Returns: The state flags for widget
7457 gtk_widget_get_state_flags (GtkWidget *widget)
7459 GtkStateFlags flags;
7461 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7463 flags = widget->priv->state_flags;
7465 if (gtk_widget_has_focus (widget))
7466 flags |= GTK_STATE_FLAG_FOCUSED;
7472 * gtk_widget_set_state:
7473 * @widget: a #GtkWidget
7474 * @state: new state for @widget
7476 * This function is for use in widget implementations. Sets the state
7477 * of a widget (insensitive, prelighted, etc.) Usually you should set
7478 * the state using wrapper functions such as gtk_widget_set_sensitive().
7480 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7483 gtk_widget_set_state (GtkWidget *widget,
7486 GtkStateFlags flags;
7488 if (state == gtk_widget_get_state (widget))
7493 case GTK_STATE_ACTIVE:
7494 flags = GTK_STATE_FLAG_ACTIVE;
7496 case GTK_STATE_PRELIGHT:
7497 flags = GTK_STATE_FLAG_PRELIGHT;
7499 case GTK_STATE_SELECTED:
7500 flags = GTK_STATE_FLAG_SELECTED;
7502 case GTK_STATE_INSENSITIVE:
7503 flags = GTK_STATE_FLAG_INSENSITIVE;
7505 case GTK_STATE_INCONSISTENT:
7506 flags = GTK_STATE_FLAG_INCONSISTENT;
7508 case GTK_STATE_FOCUSED:
7509 flags = GTK_STATE_FLAG_FOCUSED;
7511 case GTK_STATE_NORMAL:
7517 gtk_widget_update_state_flags (widget,
7519 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7520 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7524 * gtk_widget_get_state:
7525 * @widget: a #GtkWidget
7527 * Returns the widget's state. See gtk_widget_set_state().
7529 * Returns: the state of @widget.
7533 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7536 gtk_widget_get_state (GtkWidget *widget)
7538 GtkStateFlags flags;
7540 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7542 flags = gtk_widget_get_state_flags (widget);
7544 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7545 return GTK_STATE_INSENSITIVE;
7546 else if (flags & GTK_STATE_FLAG_ACTIVE)
7547 return GTK_STATE_ACTIVE;
7548 else if (flags & GTK_STATE_FLAG_SELECTED)
7549 return GTK_STATE_SELECTED;
7550 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7551 return GTK_STATE_PRELIGHT;
7553 return GTK_STATE_NORMAL;
7557 * gtk_widget_set_visible:
7558 * @widget: a #GtkWidget
7559 * @visible: whether the widget should be shown or not
7561 * Sets the visibility state of @widget. Note that setting this to
7562 * %TRUE doesn't mean the widget is actually viewable, see
7563 * gtk_widget_get_visible().
7565 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7566 * but is nicer to use when the visibility of the widget depends on
7572 gtk_widget_set_visible (GtkWidget *widget,
7575 g_return_if_fail (GTK_IS_WIDGET (widget));
7577 if (visible != gtk_widget_get_visible (widget))
7580 gtk_widget_show (widget);
7582 gtk_widget_hide (widget);
7587 _gtk_widget_set_visible_flag (GtkWidget *widget,
7590 GtkWidgetPrivate *priv = widget->priv;
7592 priv->visible = visible;
7596 priv->allocation.x = -1;
7597 priv->allocation.y = -1;
7598 priv->allocation.width = 1;
7599 priv->allocation.height = 1;
7604 * gtk_widget_get_visible:
7605 * @widget: a #GtkWidget
7607 * Determines whether the widget is visible. If you want to
7608 * take into account whether the widget's parent is also marked as
7609 * visible, use gtk_widget_is_visible() instead.
7611 * This function does not check if the widget is obscured in any way.
7613 * See gtk_widget_set_visible().
7615 * Return value: %TRUE if the widget is visible
7620 gtk_widget_get_visible (GtkWidget *widget)
7622 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7624 return widget->priv->visible;
7628 * gtk_widget_is_visible:
7629 * @widget: a #GtkWidget
7631 * Determines whether the widget and all its parents are marked as
7634 * This function does not check if the widget is obscured in any way.
7636 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7638 * Return value: %TRUE if the widget and all its parents are visible
7643 gtk_widget_is_visible (GtkWidget *widget)
7645 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7649 GtkWidgetPrivate *priv = widget->priv;
7654 widget = priv->parent;
7661 * gtk_widget_set_has_window:
7662 * @widget: a #GtkWidget
7663 * @has_window: whether or not @widget has a window.
7665 * Specifies whether @widget has a #GdkWindow of its own. Note that
7666 * all realized widgets have a non-%NULL "window" pointer
7667 * (gtk_widget_get_window() never returns a %NULL window when a widget
7668 * is realized), but for many of them it's actually the #GdkWindow of
7669 * one of its parent widgets. Widgets that do not create a %window for
7670 * themselves in #GtkWidget::realize must announce this by
7671 * calling this function with @has_window = %FALSE.
7673 * This function should only be called by widget implementations,
7674 * and they should call it in their init() function.
7679 gtk_widget_set_has_window (GtkWidget *widget,
7680 gboolean has_window)
7682 g_return_if_fail (GTK_IS_WIDGET (widget));
7684 widget->priv->no_window = !has_window;
7688 * gtk_widget_get_has_window:
7689 * @widget: a #GtkWidget
7691 * Determines whether @widget has a #GdkWindow of its own. See
7692 * gtk_widget_set_has_window().
7694 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7699 gtk_widget_get_has_window (GtkWidget *widget)
7701 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7703 return ! widget->priv->no_window;
7707 * gtk_widget_is_toplevel:
7708 * @widget: a #GtkWidget
7710 * Determines whether @widget is a toplevel widget.
7712 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7713 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7716 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7721 gtk_widget_is_toplevel (GtkWidget *widget)
7723 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7725 return widget->priv->toplevel;
7729 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7730 gboolean is_toplevel)
7732 widget->priv->toplevel = is_toplevel;
7736 * gtk_widget_is_drawable:
7737 * @widget: a #GtkWidget
7739 * Determines whether @widget can be drawn to. A widget can be drawn
7740 * to if it is mapped and visible.
7742 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7747 gtk_widget_is_drawable (GtkWidget *widget)
7749 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7751 return (gtk_widget_get_visible (widget) &&
7752 gtk_widget_get_mapped (widget));
7756 * gtk_widget_get_realized:
7757 * @widget: a #GtkWidget
7759 * Determines whether @widget is realized.
7761 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7766 gtk_widget_get_realized (GtkWidget *widget)
7768 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7770 return widget->priv->realized;
7774 * gtk_widget_set_realized:
7775 * @widget: a #GtkWidget
7776 * @realized: %TRUE to mark the widget as realized
7778 * Marks the widget as being realized.
7780 * This function should only ever be called in a derived widget's
7781 * "realize" or "unrealize" implementation.
7786 gtk_widget_set_realized (GtkWidget *widget,
7789 g_return_if_fail (GTK_IS_WIDGET (widget));
7791 widget->priv->realized = realized;
7795 * gtk_widget_get_mapped:
7796 * @widget: a #GtkWidget
7798 * Whether the widget is mapped.
7800 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7805 gtk_widget_get_mapped (GtkWidget *widget)
7807 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7809 return widget->priv->mapped;
7813 * gtk_widget_set_mapped:
7814 * @widget: a #GtkWidget
7815 * @mapped: %TRUE to mark the widget as mapped
7817 * Marks the widget as being realized.
7819 * This function should only ever be called in a derived widget's
7820 * "map" or "unmap" implementation.
7825 gtk_widget_set_mapped (GtkWidget *widget,
7828 g_return_if_fail (GTK_IS_WIDGET (widget));
7830 widget->priv->mapped = mapped;
7834 * gtk_widget_set_app_paintable:
7835 * @widget: a #GtkWidget
7836 * @app_paintable: %TRUE if the application will paint on the widget
7838 * Sets whether the application intends to draw on the widget in
7839 * an #GtkWidget::draw handler.
7841 * This is a hint to the widget and does not affect the behavior of
7842 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7843 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7844 * the effect is to suppress default themed drawing of the widget's
7845 * background. (Children of the widget will still be drawn.) The application
7846 * is then entirely responsible for drawing the widget background.
7848 * Note that the background is still drawn when the widget is mapped.
7851 gtk_widget_set_app_paintable (GtkWidget *widget,
7852 gboolean app_paintable)
7854 g_return_if_fail (GTK_IS_WIDGET (widget));
7856 app_paintable = (app_paintable != FALSE);
7858 if (widget->priv->app_paintable != app_paintable)
7860 widget->priv->app_paintable = app_paintable;
7862 if (gtk_widget_is_drawable (widget))
7863 gtk_widget_queue_draw (widget);
7865 g_object_notify (G_OBJECT (widget), "app-paintable");
7870 * gtk_widget_get_app_paintable:
7871 * @widget: a #GtkWidget
7873 * Determines whether the application intends to draw on the widget in
7874 * an #GtkWidget::draw handler.
7876 * See gtk_widget_set_app_paintable()
7878 * Return value: %TRUE if the widget is app paintable
7883 gtk_widget_get_app_paintable (GtkWidget *widget)
7885 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7887 return widget->priv->app_paintable;
7891 * gtk_widget_set_double_buffered:
7892 * @widget: a #GtkWidget
7893 * @double_buffered: %TRUE to double-buffer a widget
7895 * Widgets are double buffered by default; you can use this function
7896 * to turn off the buffering. "Double buffered" simply means that
7897 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7898 * automatically around expose events sent to the
7899 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7900 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7901 * buffer to the screen. The result is that users see the window
7902 * update in one smooth step, and don't see individual graphics
7903 * primitives being rendered.
7905 * In very simple terms, double buffered widgets don't flicker,
7906 * so you would only use this function to turn off double buffering
7907 * if you had special needs and really knew what you were doing.
7909 * Note: if you turn off double-buffering, you have to handle
7910 * expose events, since even the clearing to the background color or
7911 * pixmap will not happen automatically (as it is done in
7912 * gdk_window_begin_paint_region()).
7915 gtk_widget_set_double_buffered (GtkWidget *widget,
7916 gboolean double_buffered)
7918 g_return_if_fail (GTK_IS_WIDGET (widget));
7920 double_buffered = (double_buffered != FALSE);
7922 if (widget->priv->double_buffered != double_buffered)
7924 widget->priv->double_buffered = double_buffered;
7926 g_object_notify (G_OBJECT (widget), "double-buffered");
7931 * gtk_widget_get_double_buffered:
7932 * @widget: a #GtkWidget
7934 * Determines whether the widget is double buffered.
7936 * See gtk_widget_set_double_buffered()
7938 * Return value: %TRUE if the widget is double buffered
7943 gtk_widget_get_double_buffered (GtkWidget *widget)
7945 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7947 return widget->priv->double_buffered;
7951 * gtk_widget_set_redraw_on_allocate:
7952 * @widget: a #GtkWidget
7953 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7954 * when it is allocated to a new size. Otherwise, only the
7955 * new portion of the widget will be redrawn.
7957 * Sets whether the entire widget is queued for drawing when its size
7958 * allocation changes. By default, this setting is %TRUE and
7959 * the entire widget is redrawn on every size change. If your widget
7960 * leaves the upper left unchanged when made bigger, turning this
7961 * setting off will improve performance.
7963 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7964 * off all allocation on resizing: the widget will not even redraw if
7965 * its position changes; this is to allow containers that don't draw
7966 * anything to avoid excess invalidations. If you set this flag on a
7967 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7968 * you are responsible for invalidating both the old and new allocation
7969 * of the widget when the widget is moved and responsible for invalidating
7970 * regions newly when the widget increases size.
7973 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7974 gboolean redraw_on_allocate)
7976 g_return_if_fail (GTK_IS_WIDGET (widget));
7978 widget->priv->redraw_on_alloc = redraw_on_allocate;
7982 * gtk_widget_set_sensitive:
7983 * @widget: a #GtkWidget
7984 * @sensitive: %TRUE to make the widget sensitive
7986 * Sets the sensitivity of a widget. A widget is sensitive if the user
7987 * can interact with it. Insensitive widgets are "grayed out" and the
7988 * user can't interact with them. Insensitive widgets are known as
7989 * "inactive", "disabled", or "ghosted" in some other toolkits.
7992 gtk_widget_set_sensitive (GtkWidget *widget,
7995 GtkWidgetPrivate *priv;
7997 g_return_if_fail (GTK_IS_WIDGET (widget));
7999 priv = widget->priv;
8001 sensitive = (sensitive != FALSE);
8003 if (priv->sensitive == sensitive)
8006 priv->sensitive = sensitive;
8008 if (priv->parent == NULL
8009 || gtk_widget_is_sensitive (priv->parent))
8015 data.flags_to_set = 0;
8016 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8020 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8021 data.flags_to_unset = 0;
8024 gtk_widget_propagate_state (widget, &data);
8026 gtk_widget_queue_resize (widget);
8029 g_object_notify (G_OBJECT (widget), "sensitive");
8033 * gtk_widget_get_sensitive:
8034 * @widget: a #GtkWidget
8036 * Returns the widget's sensitivity (in the sense of returning
8037 * the value that has been set using gtk_widget_set_sensitive()).
8039 * The effective sensitivity of a widget is however determined by both its
8040 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8042 * Returns: %TRUE if the widget is sensitive
8047 gtk_widget_get_sensitive (GtkWidget *widget)
8049 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8051 return widget->priv->sensitive;
8055 * gtk_widget_is_sensitive:
8056 * @widget: a #GtkWidget
8058 * Returns the widget's effective sensitivity, which means
8059 * it is sensitive itself and also its parent widget is sensitive
8061 * Returns: %TRUE if the widget is effectively sensitive
8066 gtk_widget_is_sensitive (GtkWidget *widget)
8068 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8070 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8074 * gtk_widget_set_parent:
8075 * @widget: a #GtkWidget
8076 * @parent: parent container
8078 * This function is useful only when implementing subclasses of
8080 * Sets the container as the parent of @widget, and takes care of
8081 * some details such as updating the state and style of the child
8082 * to reflect its new location. The opposite function is
8083 * gtk_widget_unparent().
8086 gtk_widget_set_parent (GtkWidget *widget,
8089 GtkStateFlags parent_flags;
8090 GtkWidgetPrivate *priv;
8093 g_return_if_fail (GTK_IS_WIDGET (widget));
8094 g_return_if_fail (GTK_IS_WIDGET (parent));
8095 g_return_if_fail (widget != parent);
8097 priv = widget->priv;
8099 if (priv->parent != NULL)
8101 g_warning ("Can't set a parent on widget which has a parent\n");
8104 if (gtk_widget_is_toplevel (widget))
8106 g_warning ("Can't set a parent on a toplevel widget\n");
8110 /* keep this function in sync with gtk_menu_attach_to_widget()
8113 g_object_ref_sink (widget);
8115 gtk_widget_push_verify_invariants (widget);
8117 priv->parent = parent;
8119 parent_flags = gtk_widget_get_state_flags (parent);
8121 /* Merge both old state and current parent state,
8122 * making sure to only propagate the right states */
8123 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8124 data.flags_to_unset = 0;
8125 gtk_widget_propagate_state (widget, &data);
8128 gtk_style_context_set_parent (priv->context,
8129 gtk_widget_get_style_context (parent));
8131 _gtk_widget_update_parent_muxer (widget);
8133 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8134 if (priv->parent->priv->anchored)
8135 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8136 g_object_notify (G_OBJECT (widget), "parent");
8138 /* Enforce realized/mapped invariants
8140 if (gtk_widget_get_realized (priv->parent))
8141 gtk_widget_realize (widget);
8143 if (gtk_widget_get_visible (priv->parent) &&
8144 gtk_widget_get_visible (widget))
8146 if (gtk_widget_get_child_visible (widget) &&
8147 gtk_widget_get_mapped (priv->parent))
8148 gtk_widget_map (widget);
8150 gtk_widget_queue_resize (widget);
8153 /* child may cause parent's expand to change, if the child is
8154 * expanded. If child is not expanded, then it can't modify the
8155 * parent's expand. If the child becomes expanded later then it will
8156 * queue compute_expand then. This optimization plus defaulting
8157 * newly-constructed widgets to need_compute_expand=FALSE should
8158 * mean that initially building a widget tree doesn't have to keep
8159 * walking up setting need_compute_expand on parents over and over.
8161 * We can't change a parent to need to expand unless we're visible.
8163 if (gtk_widget_get_visible (widget) &&
8164 (priv->need_compute_expand ||
8165 priv->computed_hexpand ||
8166 priv->computed_vexpand))
8168 gtk_widget_queue_compute_expand (parent);
8171 gtk_widget_propagate_alpha (widget);
8173 gtk_widget_pop_verify_invariants (widget);
8177 * gtk_widget_get_parent:
8178 * @widget: a #GtkWidget
8180 * Returns the parent container of @widget.
8182 * Return value: (transfer none): the parent container of @widget, or %NULL
8185 gtk_widget_get_parent (GtkWidget *widget)
8187 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8189 return widget->priv->parent;
8193 modifier_style_changed (GtkModifierStyle *style,
8196 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8199 static GtkModifierStyle *
8200 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8202 GtkModifierStyle *style;
8204 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8206 if (G_UNLIKELY (!style))
8208 GtkStyleContext *context;
8210 style = _gtk_modifier_style_new ();
8211 g_object_set_qdata_full (G_OBJECT (widget),
8212 quark_modifier_style,
8214 (GDestroyNotify) g_object_unref);
8216 g_signal_connect (style, "changed",
8217 G_CALLBACK (modifier_style_changed), widget);
8219 context = gtk_widget_get_style_context (widget);
8221 gtk_style_context_add_provider (context,
8222 GTK_STYLE_PROVIDER (style),
8223 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8230 * gtk_widget_override_color:
8231 * @widget: a #GtkWidget
8232 * @state: the state for which to set the color
8233 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8234 * of previous calls to gtk_widget_override_color()
8236 * Sets the color to use for a widget.
8238 * All other style values are left untouched.
8241 * This API is mostly meant as a quick way for applications to
8242 * change a widget appearance. If you are developing a widgets
8243 * library and intend this change to be themeable, it is better
8244 * done by setting meaningful CSS classes and regions in your
8245 * widget/container implementation through gtk_style_context_add_class()
8246 * and gtk_style_context_add_region().
8248 * This way, your widget library can install a #GtkCssProvider
8249 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8250 * to provide a default styling for those widgets that need so, and
8251 * this theming may fully overridden by the user's theme.
8254 * Note that for complex widgets this may bring in undesired
8255 * results (such as uniform background color everywhere), in
8256 * these cases it is better to fully style such widgets through a
8257 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8264 gtk_widget_override_color (GtkWidget *widget,
8265 GtkStateFlags state,
8266 const GdkRGBA *color)
8268 GtkModifierStyle *style;
8270 g_return_if_fail (GTK_IS_WIDGET (widget));
8272 style = _gtk_widget_get_modifier_properties (widget);
8273 _gtk_modifier_style_set_color (style, state, color);
8277 * gtk_widget_override_background_color:
8278 * @widget: a #GtkWidget
8279 * @state: the state for which to set the background color
8280 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8281 * of previous calls to gtk_widget_override_background_color()
8283 * Sets the background color to use for a widget.
8285 * All other style values are left untouched.
8286 * See gtk_widget_override_color().
8291 gtk_widget_override_background_color (GtkWidget *widget,
8292 GtkStateFlags state,
8293 const GdkRGBA *color)
8295 GtkModifierStyle *style;
8297 g_return_if_fail (GTK_IS_WIDGET (widget));
8299 style = _gtk_widget_get_modifier_properties (widget);
8300 _gtk_modifier_style_set_background_color (style, state, color);
8304 * gtk_widget_override_font:
8305 * @widget: a #GtkWidget
8306 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8307 * the effect of previous calls to gtk_widget_override_font()
8309 * Sets the font to use for a widget. All other style values are
8310 * left untouched. See gtk_widget_override_color().
8315 gtk_widget_override_font (GtkWidget *widget,
8316 const PangoFontDescription *font_desc)
8318 GtkModifierStyle *style;
8320 g_return_if_fail (GTK_IS_WIDGET (widget));
8322 style = _gtk_widget_get_modifier_properties (widget);
8323 _gtk_modifier_style_set_font (style, font_desc);
8327 * gtk_widget_override_symbolic_color:
8328 * @widget: a #GtkWidget
8329 * @name: the name of the symbolic color to modify
8330 * @color: (allow-none): the color to assign (does not need
8331 * to be allocated), or %NULL to undo the effect of previous
8332 * calls to gtk_widget_override_symbolic_color()
8334 * Sets a symbolic color for a widget.
8336 * All other style values are left untouched.
8337 * See gtk_widget_override_color() for overriding the foreground
8338 * or background color.
8343 gtk_widget_override_symbolic_color (GtkWidget *widget,
8345 const GdkRGBA *color)
8347 GtkModifierStyle *style;
8349 g_return_if_fail (GTK_IS_WIDGET (widget));
8351 style = _gtk_widget_get_modifier_properties (widget);
8352 _gtk_modifier_style_map_color (style, name, color);
8356 * gtk_widget_override_cursor:
8357 * @widget: a #GtkWidget
8358 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8359 * allocated), or %NULL to undo the effect of previous calls to
8360 * of gtk_widget_override_cursor().
8361 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8362 * need to be allocated), or %NULL to undo the effect of previous
8363 * calls to of gtk_widget_override_cursor().
8365 * Sets the cursor color to use in a widget, overriding the
8366 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8367 * style properties. All other style values are left untouched.
8368 * See also gtk_widget_modify_style().
8370 * Note that the underlying properties have the #GdkColor type,
8371 * so the alpha value in @primary and @secondary will be ignored.
8376 gtk_widget_override_cursor (GtkWidget *widget,
8377 const GdkRGBA *cursor,
8378 const GdkRGBA *secondary_cursor)
8380 GtkModifierStyle *style;
8382 g_return_if_fail (GTK_IS_WIDGET (widget));
8384 style = _gtk_widget_get_modifier_properties (widget);
8385 _gtk_modifier_style_set_color_property (style,
8387 "cursor-color", cursor);
8388 _gtk_modifier_style_set_color_property (style,
8390 "secondary-cursor-color",
8395 gtk_widget_real_direction_changed (GtkWidget *widget,
8396 GtkTextDirection previous_direction)
8398 gtk_widget_queue_resize (widget);
8402 gtk_widget_real_style_set (GtkWidget *widget,
8403 GtkStyle *previous_style)
8408 GtkWidget *previous_toplevel;
8409 GdkScreen *previous_screen;
8410 GdkScreen *new_screen;
8411 } HierarchyChangedInfo;
8414 do_screen_change (GtkWidget *widget,
8415 GdkScreen *old_screen,
8416 GdkScreen *new_screen)
8418 if (old_screen != new_screen)
8420 GtkWidgetPrivate *priv = widget->priv;
8424 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8426 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8429 _gtk_tooltip_hide (widget);
8431 if (new_screen && priv->context)
8432 gtk_style_context_set_screen (priv->context, new_screen);
8434 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8439 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8440 gpointer client_data)
8442 GtkWidgetPrivate *priv = widget->priv;
8443 HierarchyChangedInfo *info = client_data;
8444 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8445 (priv->parent && priv->parent->priv->anchored);
8447 if (priv->anchored != new_anchored)
8449 g_object_ref (widget);
8451 priv->anchored = new_anchored;
8453 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8454 do_screen_change (widget, info->previous_screen, info->new_screen);
8456 if (GTK_IS_CONTAINER (widget))
8457 gtk_container_forall (GTK_CONTAINER (widget),
8458 gtk_widget_propagate_hierarchy_changed_recurse,
8461 g_object_unref (widget);
8466 * _gtk_widget_propagate_hierarchy_changed:
8467 * @widget: a #GtkWidget
8468 * @previous_toplevel: Previous toplevel
8470 * Propagates changes in the anchored state to a widget and all
8471 * children, unsetting or setting the %ANCHORED flag, and
8472 * emitting #GtkWidget::hierarchy-changed.
8475 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8476 GtkWidget *previous_toplevel)
8478 GtkWidgetPrivate *priv = widget->priv;
8479 HierarchyChangedInfo info;
8481 info.previous_toplevel = previous_toplevel;
8482 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8484 if (gtk_widget_is_toplevel (widget) ||
8485 (priv->parent && priv->parent->priv->anchored))
8486 info.new_screen = gtk_widget_get_screen (widget);
8488 info.new_screen = NULL;
8490 if (info.previous_screen)
8491 g_object_ref (info.previous_screen);
8492 if (previous_toplevel)
8493 g_object_ref (previous_toplevel);
8495 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8497 if (previous_toplevel)
8498 g_object_unref (previous_toplevel);
8499 if (info.previous_screen)
8500 g_object_unref (info.previous_screen);
8504 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8505 gpointer client_data)
8507 HierarchyChangedInfo *info = client_data;
8509 g_object_ref (widget);
8511 do_screen_change (widget, info->previous_screen, info->new_screen);
8513 if (GTK_IS_CONTAINER (widget))
8514 gtk_container_forall (GTK_CONTAINER (widget),
8515 gtk_widget_propagate_screen_changed_recurse,
8518 g_object_unref (widget);
8522 * gtk_widget_is_composited:
8523 * @widget: a #GtkWidget
8525 * Whether @widget can rely on having its alpha channel
8526 * drawn correctly. On X11 this function returns whether a
8527 * compositing manager is running for @widget's screen.
8529 * Please note that the semantics of this call will change
8530 * in the future if used on a widget that has a composited
8531 * window in its hierarchy (as set by gdk_window_set_composited()).
8533 * Return value: %TRUE if the widget can rely on its alpha
8534 * channel being drawn correctly.
8539 gtk_widget_is_composited (GtkWidget *widget)
8543 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8545 screen = gtk_widget_get_screen (widget);
8547 return gdk_screen_is_composited (screen);
8551 propagate_composited_changed (GtkWidget *widget,
8554 if (GTK_IS_CONTAINER (widget))
8556 gtk_container_forall (GTK_CONTAINER (widget),
8557 propagate_composited_changed,
8561 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8565 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8567 propagate_composited_changed (widget, NULL);
8571 * _gtk_widget_propagate_screen_changed:
8572 * @widget: a #GtkWidget
8573 * @previous_screen: Previous screen
8575 * Propagates changes in the screen for a widget to all
8576 * children, emitting #GtkWidget::screen-changed.
8579 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8580 GdkScreen *previous_screen)
8582 HierarchyChangedInfo info;
8584 info.previous_screen = previous_screen;
8585 info.new_screen = gtk_widget_get_screen (widget);
8587 if (previous_screen)
8588 g_object_ref (previous_screen);
8590 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8592 if (previous_screen)
8593 g_object_unref (previous_screen);
8597 reset_style_recurse (GtkWidget *widget, gpointer data)
8599 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8601 if (GTK_IS_CONTAINER (widget))
8602 gtk_container_forall (GTK_CONTAINER (widget),
8603 reset_style_recurse,
8608 * gtk_widget_reset_style:
8609 * @widget: a #GtkWidget
8611 * Updates the style context of @widget and all descendents
8612 * by updating its widget path. #GtkContainer<!-- -->s may want
8613 * to use this on a child when reordering it in a way that a different
8614 * style might apply to it. See also gtk_container_get_path_for_child().
8619 gtk_widget_reset_style (GtkWidget *widget)
8621 g_return_if_fail (GTK_IS_WIDGET (widget));
8623 reset_style_recurse (widget, NULL);
8625 g_list_foreach (widget->priv->attached_windows,
8626 (GFunc) reset_style_recurse, NULL);
8629 #ifdef G_ENABLE_DEBUG
8631 /* Verify invariants, see docs/widget_system.txt for notes on much of
8632 * this. Invariants may be temporarily broken while we're in the
8633 * process of updating state, of course, so you can only
8634 * verify_invariants() after a given operation is complete.
8635 * Use push/pop_verify_invariants to help with that.
8638 gtk_widget_verify_invariants (GtkWidget *widget)
8642 if (widget->priv->verifying_invariants_count > 0)
8645 parent = widget->priv->parent;
8647 if (widget->priv->mapped)
8649 /* Mapped implies ... */
8651 if (!widget->priv->realized)
8652 g_warning ("%s %p is mapped but not realized",
8653 G_OBJECT_TYPE_NAME (widget), widget);
8655 if (!widget->priv->visible)
8656 g_warning ("%s %p is mapped but not visible",
8657 G_OBJECT_TYPE_NAME (widget), widget);
8659 if (!widget->priv->toplevel)
8661 if (!widget->priv->child_visible)
8662 g_warning ("%s %p is mapped but not child_visible",
8663 G_OBJECT_TYPE_NAME (widget), widget);
8668 /* Not mapped implies... */
8671 /* This check makes sense for normal toplevels, but for
8672 * something like a toplevel that is embedded within a clutter
8673 * state, mapping may depend on external factors.
8675 if (widget->priv->toplevel)
8677 if (widget->priv->visible)
8678 g_warning ("%s %p toplevel is visible but not mapped",
8679 G_OBJECT_TYPE_NAME (widget), widget);
8684 /* Parent related checks aren't possible if parent has
8685 * verifying_invariants_count > 0 because parent needs to recurse
8686 * children first before the invariants will hold.
8688 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8691 parent->priv->realized)
8693 /* Parent realized implies... */
8696 /* This is in widget_system.txt but appears to fail
8697 * because there's no gtk_container_realize() that
8698 * realizes all children... instead we just lazily
8699 * wait for map to fix things up.
8701 if (!widget->priv->realized)
8702 g_warning ("%s %p is realized but child %s %p is not realized",
8703 G_OBJECT_TYPE_NAME (parent), parent,
8704 G_OBJECT_TYPE_NAME (widget), widget);
8707 else if (!widget->priv->toplevel)
8709 /* No parent or parent not realized on non-toplevel implies... */
8711 if (widget->priv->realized && !widget->priv->in_reparent)
8712 g_warning ("%s %p is not realized but child %s %p is realized",
8713 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8714 G_OBJECT_TYPE_NAME (widget), widget);
8718 parent->priv->mapped &&
8719 widget->priv->visible &&
8720 widget->priv->child_visible)
8722 /* Parent mapped and we are visible implies... */
8724 if (!widget->priv->mapped)
8725 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8726 G_OBJECT_TYPE_NAME (parent), parent,
8727 G_OBJECT_TYPE_NAME (widget), widget);
8729 else if (!widget->priv->toplevel)
8731 /* No parent or parent not mapped on non-toplevel implies... */
8733 if (widget->priv->mapped && !widget->priv->in_reparent)
8734 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8735 G_OBJECT_TYPE_NAME (widget), widget,
8736 widget->priv->visible,
8737 widget->priv->child_visible,
8738 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8739 parent ? parent->priv->mapped : FALSE);
8743 if (!widget->priv->realized)
8745 /* Not realized implies... */
8748 /* widget_system.txt says these hold, but they don't. */
8749 if (widget->priv->alloc_needed)
8750 g_warning ("%s %p alloc needed but not realized",
8751 G_OBJECT_TYPE_NAME (widget), widget);
8753 if (widget->priv->width_request_needed)
8754 g_warning ("%s %p width request needed but not realized",
8755 G_OBJECT_TYPE_NAME (widget), widget);
8757 if (widget->priv->height_request_needed)
8758 g_warning ("%s %p height request needed but not realized",
8759 G_OBJECT_TYPE_NAME (widget), widget);
8764 /* The point of this push/pop is that invariants may not hold while
8765 * we're busy making changes. So we only check at the outermost call
8766 * on the call stack, after we finish updating everything.
8769 gtk_widget_push_verify_invariants (GtkWidget *widget)
8771 widget->priv->verifying_invariants_count += 1;
8775 gtk_widget_verify_child_invariants (GtkWidget *widget,
8776 gpointer client_data)
8778 /* We don't recurse further; this is a one-level check. */
8779 gtk_widget_verify_invariants (widget);
8783 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8785 g_assert (widget->priv->verifying_invariants_count > 0);
8787 widget->priv->verifying_invariants_count -= 1;
8789 if (widget->priv->verifying_invariants_count == 0)
8791 gtk_widget_verify_invariants (widget);
8793 if (GTK_IS_CONTAINER (widget))
8795 /* Check one level of children, because our
8796 * push_verify_invariants() will have prevented some of the
8797 * checks. This does not recurse because if recursion is
8798 * needed, it will happen naturally as each child has a
8799 * push/pop on that child. For example if we're recursively
8800 * mapping children, we'll push/pop on each child as we map
8803 gtk_container_forall (GTK_CONTAINER (widget),
8804 gtk_widget_verify_child_invariants,
8809 #endif /* G_ENABLE_DEBUG */
8811 static PangoContext *
8812 gtk_widget_peek_pango_context (GtkWidget *widget)
8814 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8818 * gtk_widget_get_pango_context:
8819 * @widget: a #GtkWidget
8821 * Gets a #PangoContext with the appropriate font map, font description,
8822 * and base direction for this widget. Unlike the context returned
8823 * by gtk_widget_create_pango_context(), this context is owned by
8824 * the widget (it can be used until the screen for the widget changes
8825 * or the widget is removed from its toplevel), and will be updated to
8826 * match any changes to the widget's attributes. This can be tracked
8827 * by using the #GtkWidget::screen-changed signal on the widget.
8829 * Return value: (transfer none): the #PangoContext for the widget.
8832 gtk_widget_get_pango_context (GtkWidget *widget)
8834 PangoContext *context;
8836 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8838 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8841 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8842 g_object_set_qdata_full (G_OBJECT (widget),
8843 quark_pango_context,
8852 update_pango_context (GtkWidget *widget,
8853 PangoContext *context)
8855 PangoFontDescription *font_desc;
8856 GtkStyleContext *style_context;
8858 style_context = gtk_widget_get_style_context (widget);
8859 gtk_style_context_get (style_context,
8860 gtk_widget_get_state_flags (widget),
8864 pango_context_set_font_description (context, font_desc);
8865 pango_context_set_base_dir (context,
8866 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8867 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8869 pango_font_description_free (font_desc);
8873 gtk_widget_update_pango_context (GtkWidget *widget)
8875 PangoContext *context = gtk_widget_peek_pango_context (widget);
8881 update_pango_context (widget, context);
8883 screen = gtk_widget_get_screen_unchecked (widget);
8886 pango_cairo_context_set_resolution (context,
8887 gdk_screen_get_resolution (screen));
8888 pango_cairo_context_set_font_options (context,
8889 gdk_screen_get_font_options (screen));
8895 * gtk_widget_create_pango_context:
8896 * @widget: a #GtkWidget
8898 * Creates a new #PangoContext with the appropriate font map,
8899 * font description, and base direction for drawing text for
8900 * this widget. See also gtk_widget_get_pango_context().
8902 * Return value: (transfer full): the new #PangoContext
8905 gtk_widget_create_pango_context (GtkWidget *widget)
8908 PangoContext *context;
8910 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8912 screen = gtk_widget_get_screen_unchecked (widget);
8915 GTK_NOTE (MULTIHEAD,
8916 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8918 screen = gdk_screen_get_default ();
8921 context = gdk_pango_context_get_for_screen (screen);
8923 update_pango_context (widget, context);
8924 pango_context_set_language (context, gtk_get_default_language ());
8930 * gtk_widget_create_pango_layout:
8931 * @widget: a #GtkWidget
8932 * @text: text to set on the layout (can be %NULL)
8934 * Creates a new #PangoLayout with the appropriate font map,
8935 * font description, and base direction for drawing text for
8938 * If you keep a #PangoLayout created in this way around, you need
8939 * to re-create it when the widget #PangoContext is replaced.
8940 * This can be tracked by using the #GtkWidget::screen-changed signal
8943 * Return value: (transfer full): the new #PangoLayout
8946 gtk_widget_create_pango_layout (GtkWidget *widget,
8949 PangoLayout *layout;
8950 PangoContext *context;
8952 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8954 context = gtk_widget_get_pango_context (widget);
8955 layout = pango_layout_new (context);
8958 pango_layout_set_text (layout, text, -1);
8964 * gtk_widget_render_icon_pixbuf:
8965 * @widget: a #GtkWidget
8966 * @stock_id: a stock ID
8967 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8968 * render at the size of the source and don't scale (if there are
8969 * multiple source sizes, GTK+ picks one of the available sizes).
8971 * A convenience function that uses the theme engine and style
8972 * settings for @widget to look up @stock_id and render it to
8973 * a pixbuf. @stock_id should be a stock icon ID such as
8974 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8975 * such as #GTK_ICON_SIZE_MENU.
8977 * The pixels in the returned #GdkPixbuf are shared with the rest of
8978 * the application and should not be modified. The pixbuf should be freed
8979 * after use with g_object_unref().
8981 * Return value: (transfer full): a new pixbuf, or %NULL if the
8982 * stock ID wasn't known
8987 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8988 const gchar *stock_id,
8991 GtkStyleContext *context;
8992 GtkIconSet *icon_set;
8994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8995 g_return_val_if_fail (stock_id != NULL, NULL);
8996 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8998 context = gtk_widget_get_style_context (widget);
8999 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9001 if (icon_set == NULL)
9004 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9008 * gtk_widget_set_parent_window:
9009 * @widget: a #GtkWidget.
9010 * @parent_window: the new parent window.
9012 * Sets a non default parent window for @widget.
9014 * For GtkWindow classes, setting a @parent_window effects whether
9015 * the window is a toplevel window or can be embedded into other
9019 * For GtkWindow classes, this needs to be called before the
9020 * window is realized.
9025 gtk_widget_set_parent_window (GtkWidget *widget,
9026 GdkWindow *parent_window)
9028 GdkWindow *old_parent_window;
9030 g_return_if_fail (GTK_IS_WIDGET (widget));
9032 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9033 quark_parent_window);
9035 if (parent_window != old_parent_window)
9039 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9041 if (old_parent_window)
9042 g_object_unref (old_parent_window);
9044 g_object_ref (parent_window);
9046 /* Unset toplevel flag when adding a parent window to a widget,
9047 * this is the primary entry point to allow toplevels to be
9050 #ifdef GDK_WINDOWING_X11
9051 is_plug = GTK_IS_PLUG (widget);
9055 if (GTK_IS_WINDOW (widget) && !is_plug)
9056 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9061 * gtk_widget_get_parent_window:
9062 * @widget: a #GtkWidget.
9064 * Gets @widget's parent window.
9066 * Returns: (transfer none): the parent window of @widget.
9069 gtk_widget_get_parent_window (GtkWidget *widget)
9071 GtkWidgetPrivate *priv;
9072 GdkWindow *parent_window;
9074 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9076 priv = widget->priv;
9078 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9080 return (parent_window != NULL) ? parent_window :
9081 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9086 * gtk_widget_set_child_visible:
9087 * @widget: a #GtkWidget
9088 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9090 * Sets whether @widget should be mapped along with its when its parent
9091 * is mapped and @widget has been shown with gtk_widget_show().
9093 * The child visibility can be set for widget before it is added to
9094 * a container with gtk_widget_set_parent(), to avoid mapping
9095 * children unnecessary before immediately unmapping them. However
9096 * it will be reset to its default state of %TRUE when the widget
9097 * is removed from a container.
9099 * Note that changing the child visibility of a widget does not
9100 * queue a resize on the widget. Most of the time, the size of
9101 * a widget is computed from all visible children, whether or
9102 * not they are mapped. If this is not the case, the container
9103 * can queue a resize itself.
9105 * This function is only useful for container implementations and
9106 * never should be called by an application.
9109 gtk_widget_set_child_visible (GtkWidget *widget,
9110 gboolean is_visible)
9112 GtkWidgetPrivate *priv;
9114 g_return_if_fail (GTK_IS_WIDGET (widget));
9115 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9117 priv = widget->priv;
9119 g_object_ref (widget);
9120 gtk_widget_verify_invariants (widget);
9123 priv->child_visible = TRUE;
9126 GtkWidget *toplevel;
9128 priv->child_visible = FALSE;
9130 toplevel = gtk_widget_get_toplevel (widget);
9131 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9132 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9135 if (priv->parent && gtk_widget_get_realized (priv->parent))
9137 if (gtk_widget_get_mapped (priv->parent) &&
9138 priv->child_visible &&
9139 gtk_widget_get_visible (widget))
9140 gtk_widget_map (widget);
9142 gtk_widget_unmap (widget);
9145 gtk_widget_verify_invariants (widget);
9146 g_object_unref (widget);
9150 * gtk_widget_get_child_visible:
9151 * @widget: a #GtkWidget
9153 * Gets the value set with gtk_widget_set_child_visible().
9154 * If you feel a need to use this function, your code probably
9155 * needs reorganization.
9157 * This function is only useful for container implementations and
9158 * never should be called by an application.
9160 * Return value: %TRUE if the widget is mapped with the parent.
9163 gtk_widget_get_child_visible (GtkWidget *widget)
9165 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9167 return widget->priv->child_visible;
9171 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9173 GtkWidget *toplevel;
9175 toplevel = gtk_widget_get_toplevel (widget);
9177 if (gtk_widget_is_toplevel (toplevel))
9179 if (GTK_IS_WINDOW (toplevel))
9180 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9181 else if (GTK_IS_INVISIBLE (toplevel))
9182 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9189 * gtk_widget_get_screen:
9190 * @widget: a #GtkWidget
9192 * Get the #GdkScreen from the toplevel window associated with
9193 * this widget. This function can only be called after the widget
9194 * has been added to a widget hierarchy with a #GtkWindow
9197 * In general, you should only create screen specific
9198 * resources when a widget has been realized, and you should
9199 * free those resources when the widget is unrealized.
9201 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9206 gtk_widget_get_screen (GtkWidget *widget)
9210 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9212 screen = gtk_widget_get_screen_unchecked (widget);
9219 g_warning (G_STRLOC ": Can't get associated screen"
9220 " for a widget unless it is inside a toplevel GtkWindow\n"
9221 " widget type is %s associated top level type is %s",
9222 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9223 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9225 return gdk_screen_get_default ();
9230 * gtk_widget_has_screen:
9231 * @widget: a #GtkWidget
9233 * Checks whether there is a #GdkScreen is associated with
9234 * this widget. All toplevel widgets have an associated
9235 * screen, and all widgets added into a hierarchy with a toplevel
9236 * window at the top.
9238 * Return value: %TRUE if there is a #GdkScreen associcated
9244 gtk_widget_has_screen (GtkWidget *widget)
9246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9248 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9252 * gtk_widget_get_display:
9253 * @widget: a #GtkWidget
9255 * Get the #GdkDisplay for the toplevel window associated with
9256 * this widget. This function can only be called after the widget
9257 * has been added to a widget hierarchy with a #GtkWindow at the top.
9259 * In general, you should only create display specific
9260 * resources when a widget has been realized, and you should
9261 * free those resources when the widget is unrealized.
9263 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9268 gtk_widget_get_display (GtkWidget *widget)
9270 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9272 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9276 * gtk_widget_get_root_window:
9277 * @widget: a #GtkWidget
9279 * Get the root window where this widget is located. This function can
9280 * only be called after the widget has been added to a widget
9281 * hierarchy with #GtkWindow at the top.
9283 * The root window is useful for such purposes as creating a popup
9284 * #GdkWindow associated with the window. In general, you should only
9285 * create display specific resources when a widget has been realized,
9286 * and you should free those resources when the widget is unrealized.
9288 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9293 gtk_widget_get_root_window (GtkWidget *widget)
9295 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9297 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9301 * gtk_widget_child_focus:
9302 * @widget: a #GtkWidget
9303 * @direction: direction of focus movement
9305 * This function is used by custom widget implementations; if you're
9306 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9307 * to a particular widget, and gtk_container_set_focus_chain() to
9308 * change the focus tab order. So you may want to investigate those
9309 * functions instead.
9311 * gtk_widget_child_focus() is called by containers as the user moves
9312 * around the window using keyboard shortcuts. @direction indicates
9313 * what kind of motion is taking place (up, down, left, right, tab
9314 * forward, tab backward). gtk_widget_child_focus() emits the
9315 * #GtkWidget::focus signal; widgets override the default handler
9316 * for this signal in order to implement appropriate focus behavior.
9318 * The default ::focus handler for a widget should return %TRUE if
9319 * moving in @direction left the focus on a focusable location inside
9320 * that widget, and %FALSE if moving in @direction moved the focus
9321 * outside the widget. If returning %TRUE, widgets normally
9322 * call gtk_widget_grab_focus() to place the focus accordingly;
9323 * if returning %FALSE, they don't modify the current focus location.
9325 * Return value: %TRUE if focus ended up inside @widget
9328 gtk_widget_child_focus (GtkWidget *widget,
9329 GtkDirectionType direction)
9331 gboolean return_val;
9333 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9335 if (!gtk_widget_get_visible (widget) ||
9336 !gtk_widget_is_sensitive (widget))
9339 /* child widgets must set CAN_FOCUS, containers
9340 * don't have to though.
9342 if (!GTK_IS_CONTAINER (widget) &&
9343 !gtk_widget_get_can_focus (widget))
9346 g_signal_emit (widget,
9347 widget_signals[FOCUS],
9349 direction, &return_val);
9355 * gtk_widget_keynav_failed:
9356 * @widget: a #GtkWidget
9357 * @direction: direction of focus movement
9359 * This function should be called whenever keyboard navigation within
9360 * a single widget hits a boundary. The function emits the
9361 * #GtkWidget::keynav-failed signal on the widget and its return
9362 * value should be interpreted in a way similar to the return value of
9363 * gtk_widget_child_focus():
9365 * When %TRUE is returned, stay in the widget, the failed keyboard
9366 * navigation is Ok and/or there is nowhere we can/should move the
9369 * When %FALSE is returned, the caller should continue with keyboard
9370 * navigation outside the widget, e.g. by calling
9371 * gtk_widget_child_focus() on the widget's toplevel.
9373 * The default ::keynav-failed handler returns %TRUE for
9374 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9375 * values of #GtkDirectionType, it looks at the
9376 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9377 * if the setting is %TRUE. This way the entire user interface
9378 * becomes cursor-navigatable on input devices such as mobile phones
9379 * which only have cursor keys but no tab key.
9381 * Whenever the default handler returns %TRUE, it also calls
9382 * gtk_widget_error_bell() to notify the user of the failed keyboard
9385 * A use case for providing an own implementation of ::keynav-failed
9386 * (either by connecting to it or by overriding it) would be a row of
9387 * #GtkEntry widgets where the user should be able to navigate the
9388 * entire row with the cursor keys, as e.g. known from user interfaces
9389 * that require entering license keys.
9391 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9392 * if the emitting widget should try to handle the keyboard
9393 * navigation attempt in its parent container(s).
9398 gtk_widget_keynav_failed (GtkWidget *widget,
9399 GtkDirectionType direction)
9401 gboolean return_val;
9403 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9405 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9406 direction, &return_val);
9412 * gtk_widget_error_bell:
9413 * @widget: a #GtkWidget
9415 * Notifies the user about an input-related error on this widget.
9416 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9417 * gdk_window_beep(), otherwise it does nothing.
9419 * Note that the effect of gdk_window_beep() can be configured in many
9420 * ways, depending on the windowing backend and the desktop environment
9421 * or window manager that is used.
9426 gtk_widget_error_bell (GtkWidget *widget)
9428 GtkWidgetPrivate *priv;
9429 GtkSettings* settings;
9432 g_return_if_fail (GTK_IS_WIDGET (widget));
9434 priv = widget->priv;
9436 settings = gtk_widget_get_settings (widget);
9440 g_object_get (settings,
9441 "gtk-error-bell", &beep,
9444 if (beep && priv->window)
9445 gdk_window_beep (priv->window);
9449 gtk_widget_set_usize_internal (GtkWidget *widget,
9452 GtkQueueResizeFlags flags)
9454 GtkWidgetAuxInfo *aux_info;
9455 gboolean changed = FALSE;
9457 g_object_freeze_notify (G_OBJECT (widget));
9459 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9461 if (width > -2 && aux_info->width != width)
9463 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9464 g_object_notify (G_OBJECT (widget), "width-request");
9465 aux_info->width = width;
9468 if (height > -2 && aux_info->height != height)
9470 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9471 g_object_notify (G_OBJECT (widget), "height-request");
9472 aux_info->height = height;
9476 if (gtk_widget_get_visible (widget) && changed)
9478 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9479 gtk_widget_queue_resize (widget);
9481 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9484 g_object_thaw_notify (G_OBJECT (widget));
9488 * gtk_widget_set_size_request:
9489 * @widget: a #GtkWidget
9490 * @width: width @widget should request, or -1 to unset
9491 * @height: height @widget should request, or -1 to unset
9493 * Sets the minimum size of a widget; that is, the widget's size
9494 * request will be at least @width by @height. You can use this
9495 * function to force a widget to be larger than it normally would be.
9497 * In most cases, gtk_window_set_default_size() is a better choice for
9498 * toplevel windows than this function; setting the default size will
9499 * still allow users to shrink the window. Setting the size request
9500 * will force them to leave the window at least as large as the size
9501 * request. When dealing with window sizes,
9502 * gtk_window_set_geometry_hints() can be a useful function as well.
9504 * Note the inherent danger of setting any fixed size - themes,
9505 * translations into other languages, different fonts, and user action
9506 * can all change the appropriate size for a given widget. So, it's
9507 * basically impossible to hardcode a size that will always be
9510 * The size request of a widget is the smallest size a widget can
9511 * accept while still functioning well and drawing itself correctly.
9512 * However in some strange cases a widget may be allocated less than
9513 * its requested size, and in many cases a widget may be allocated more
9514 * space than it requested.
9516 * If the size request in a given direction is -1 (unset), then
9517 * the "natural" size request of the widget will be used instead.
9519 * The size request set here does not include any margin from the
9520 * #GtkWidget properties margin-left, margin-right, margin-top, and
9521 * margin-bottom, but it does include pretty much all other padding
9522 * or border properties set by any subclass of #GtkWidget.
9525 gtk_widget_set_size_request (GtkWidget *widget,
9529 g_return_if_fail (GTK_IS_WIDGET (widget));
9530 g_return_if_fail (width >= -1);
9531 g_return_if_fail (height >= -1);
9538 gtk_widget_set_usize_internal (widget, width, height, 0);
9543 * gtk_widget_get_size_request:
9544 * @widget: a #GtkWidget
9545 * @width: (out) (allow-none): return location for width, or %NULL
9546 * @height: (out) (allow-none): return location for height, or %NULL
9548 * Gets the size request that was explicitly set for the widget using
9549 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9550 * @height indicates that that dimension has not been set explicitly
9551 * and the natural requisition of the widget will be used intead. See
9552 * gtk_widget_set_size_request(). To get the size a widget will
9553 * actually request, call gtk_widget_get_preferred_size() instead of
9557 gtk_widget_get_size_request (GtkWidget *widget,
9561 const GtkWidgetAuxInfo *aux_info;
9563 g_return_if_fail (GTK_IS_WIDGET (widget));
9565 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9568 *width = aux_info->width;
9571 *height = aux_info->height;
9575 * _gtk_widget_override_size_request:
9576 * @widget: a #GtkWidget
9577 * @width: new forced minimum width
9578 * @height: new forced minimum height
9579 * @old_width: location to store previous forced minimum width
9580 * @old_height: location to store previous forced minumum height
9582 * Temporarily establishes a forced minimum size for a widget; this
9583 * is used by GtkWindow when calculating the size to add to the
9584 * window's geometry widget. Cached sizes for the widget and its
9585 * parents are invalidated, so that subsequent calls to the size
9586 * negotiation machinery produce the overriden result, but the
9587 * widget is not queued for relayout or redraw. The old size must
9588 * be restored with _gtk_widget_restore_size_request() or things
9592 _gtk_widget_override_size_request (GtkWidget *widget,
9598 gtk_widget_get_size_request (widget, old_width, old_height);
9599 gtk_widget_set_usize_internal (widget, width, height,
9600 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9604 * _gtk_widget_restore_size_request:
9605 * @widget: a #GtkWidget
9606 * @old_width: saved forced minimum size
9607 * @old_height: saved forced minimum size
9609 * Undoes the operation of_gtk_widget_override_size_request().
9612 _gtk_widget_restore_size_request (GtkWidget *widget,
9616 gtk_widget_set_usize_internal (widget, old_width, old_height,
9617 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9621 * gtk_widget_set_events:
9622 * @widget: a #GtkWidget
9623 * @events: event mask
9625 * Sets the event mask (see #GdkEventMask) for a widget. The event
9626 * mask determines which events a widget will receive. Keep in mind
9627 * that different widgets have different default event masks, and by
9628 * changing the event mask you may disrupt a widget's functionality,
9629 * so be careful. This function must be called while a widget is
9630 * unrealized. Consider gtk_widget_add_events() for widgets that are
9631 * already realized, or if you want to preserve the existing event
9632 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9633 * to get events on those widgets, place them inside a #GtkEventBox
9634 * and receive events on the event box.
9637 gtk_widget_set_events (GtkWidget *widget,
9640 g_return_if_fail (GTK_IS_WIDGET (widget));
9641 g_return_if_fail (!gtk_widget_get_realized (widget));
9643 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9644 GINT_TO_POINTER (events));
9645 g_object_notify (G_OBJECT (widget), "events");
9649 * gtk_widget_set_device_events:
9650 * @widget: a #GtkWidget
9651 * @device: a #GdkDevice
9652 * @events: event mask
9654 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9655 * mask determines which events a widget will receive from @device. Keep
9656 * in mind that different widgets have different default event masks, and by
9657 * changing the event mask you may disrupt a widget's functionality,
9658 * so be careful. This function must be called while a widget is
9659 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9660 * already realized, or if you want to preserve the existing event
9661 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9662 * to get events on those widgets, place them inside a #GtkEventBox
9663 * and receive events on the event box.
9668 gtk_widget_set_device_events (GtkWidget *widget,
9670 GdkEventMask events)
9672 GHashTable *device_events;
9674 g_return_if_fail (GTK_IS_WIDGET (widget));
9675 g_return_if_fail (GDK_IS_DEVICE (device));
9676 g_return_if_fail (!gtk_widget_get_realized (widget));
9678 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9680 if (G_UNLIKELY (!device_events))
9682 device_events = g_hash_table_new (NULL, NULL);
9683 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9684 (GDestroyNotify) g_hash_table_unref);
9687 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9691 * gtk_widget_set_device_enabled:
9692 * @widget: a #GtkWidget
9693 * @device: a #GdkDevice
9694 * @enabled: whether to enable the device
9696 * Enables or disables a #GdkDevice to interact with @widget
9697 * and all its children.
9699 * It does so by descending through the #GdkWindow hierarchy
9700 * and enabling the same mask that is has for core events
9701 * (i.e. the one that gdk_window_get_events() returns).
9706 gtk_widget_set_device_enabled (GtkWidget *widget,
9710 GList *enabled_devices;
9712 g_return_if_fail (GTK_IS_WIDGET (widget));
9713 g_return_if_fail (GDK_IS_DEVICE (device));
9715 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9716 enabled_devices = g_list_append (enabled_devices, device);
9718 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9719 enabled_devices, (GDestroyNotify) g_list_free);;
9721 if (gtk_widget_get_realized (widget))
9722 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9726 * gtk_widget_get_device_enabled:
9727 * @widget: a #GtkWidget
9728 * @device: a #GdkDevice
9730 * Returns whether @device can interact with @widget and its
9731 * children. See gtk_widget_set_device_enabled().
9733 * Return value: %TRUE is @device is enabled for @widget
9738 gtk_widget_get_device_enabled (GtkWidget *widget,
9741 GList *enabled_devices;
9743 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9744 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9746 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9748 return g_list_find (enabled_devices, device) != NULL;
9752 gtk_widget_add_events_internal_list (GtkWidget *widget,
9759 for (l = window_list; l != NULL; l = l->next)
9761 GdkWindow *window = l->data;
9764 gdk_window_get_user_data (window, &user_data);
9765 if (user_data == widget)
9770 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9772 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9774 children = gdk_window_get_children (window);
9775 gtk_widget_add_events_internal_list (widget, device, events, children);
9776 g_list_free (children);
9782 gtk_widget_add_events_internal (GtkWidget *widget,
9786 GtkWidgetPrivate *priv = widget->priv;
9789 if (!gtk_widget_get_has_window (widget))
9790 window_list = gdk_window_get_children (priv->window);
9792 window_list = g_list_prepend (NULL, priv->window);
9794 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9796 g_list_free (window_list);
9800 * gtk_widget_add_events:
9801 * @widget: a #GtkWidget
9802 * @events: an event mask, see #GdkEventMask
9804 * Adds the events in the bitfield @events to the event mask for
9805 * @widget. See gtk_widget_set_events() for details.
9808 gtk_widget_add_events (GtkWidget *widget,
9813 g_return_if_fail (GTK_IS_WIDGET (widget));
9815 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9816 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9817 GINT_TO_POINTER (old_events | events));
9819 if (gtk_widget_get_realized (widget))
9821 gtk_widget_add_events_internal (widget, NULL, events);
9822 gtk_widget_update_devices_mask (widget, FALSE);
9825 g_object_notify (G_OBJECT (widget), "events");
9829 * gtk_widget_add_device_events:
9830 * @widget: a #GtkWidget
9831 * @device: a #GdkDevice
9832 * @events: an event mask, see #GdkEventMask
9834 * Adds the device events in the bitfield @events to the event mask for
9835 * @widget. See gtk_widget_set_device_events() for details.
9840 gtk_widget_add_device_events (GtkWidget *widget,
9842 GdkEventMask events)
9844 GdkEventMask old_events;
9845 GHashTable *device_events;
9847 g_return_if_fail (GTK_IS_WIDGET (widget));
9848 g_return_if_fail (GDK_IS_DEVICE (device));
9850 old_events = gtk_widget_get_device_events (widget, device);
9852 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9854 if (G_UNLIKELY (!device_events))
9856 device_events = g_hash_table_new (NULL, NULL);
9857 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9858 (GDestroyNotify) g_hash_table_unref);
9861 g_hash_table_insert (device_events, device,
9862 GUINT_TO_POINTER (old_events | events));
9864 if (gtk_widget_get_realized (widget))
9865 gtk_widget_add_events_internal (widget, device, events);
9867 g_object_notify (G_OBJECT (widget), "events");
9871 * gtk_widget_get_toplevel:
9872 * @widget: a #GtkWidget
9874 * This function returns the topmost widget in the container hierarchy
9875 * @widget is a part of. If @widget has no parent widgets, it will be
9876 * returned as the topmost widget. No reference will be added to the
9877 * returned widget; it should not be unreferenced.
9879 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9880 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9882 * %NULL if @widget wasn't inside a toplevel window, and if the
9883 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9884 * inside the toplevel #GtkWindow. While the second case may
9885 * seem unlikely, it actually happens when a #GtkPlug is embedded
9886 * inside a #GtkSocket within the same application.
9888 * To reliably find the toplevel #GtkWindow, use
9889 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9890 * is set on the result.
9892 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9893 * if (gtk_widget_is_toplevel (toplevel))
9895 * /* Perform action on toplevel. */
9899 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9900 * if there's no ancestor.
9903 gtk_widget_get_toplevel (GtkWidget *widget)
9905 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9907 while (widget->priv->parent)
9908 widget = widget->priv->parent;
9914 * gtk_widget_get_ancestor:
9915 * @widget: a #GtkWidget
9916 * @widget_type: ancestor type
9918 * Gets the first ancestor of @widget with type @widget_type. For example,
9919 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9920 * the first #GtkBox that's an ancestor of @widget. No reference will be
9921 * added to the returned widget; it should not be unreferenced. See note
9922 * about checking for a toplevel #GtkWindow in the docs for
9923 * gtk_widget_get_toplevel().
9925 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9926 * considers @widget to be an ancestor of itself.
9928 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9931 gtk_widget_get_ancestor (GtkWidget *widget,
9934 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9936 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9937 widget = widget->priv->parent;
9939 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9946 * gtk_widget_set_visual:
9947 * @widget: a #GtkWidget
9948 * @visual: visual to be used or %NULL to unset a previous one
9950 * Sets the visual that should be used for by widget and its children for
9951 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9952 * returned by gtk_widget_get_screen(), so handling the
9953 * #GtkWidget::screen-changed signal is necessary.
9955 * Setting a new @visual will not cause @widget to recreate its windows,
9956 * so you should call this function before @widget is realized.
9959 gtk_widget_set_visual (GtkWidget *widget,
9962 g_return_if_fail (GTK_IS_WIDGET (widget));
9963 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9966 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9969 g_object_set_qdata_full (G_OBJECT (widget),
9971 g_object_ref (visual),
9976 * gtk_widget_get_visual:
9977 * @widget: a #GtkWidget
9979 * Gets the visual that will be used to render @widget.
9981 * Return value: (transfer none): the visual for @widget
9984 gtk_widget_get_visual (GtkWidget *widget)
9990 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9992 if (gtk_widget_get_has_window (widget) &&
9993 widget->priv->window)
9994 return gdk_window_get_visual (widget->priv->window);
9996 screen = gtk_widget_get_screen (widget);
9998 for (w = widget; w != NULL; w = w->priv->parent)
10000 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10003 if (gdk_visual_get_screen (visual) == screen)
10006 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10007 gtk_widget_get_name (widget));
10011 return gdk_screen_get_system_visual (screen);
10015 * gtk_widget_get_settings:
10016 * @widget: a #GtkWidget
10018 * Gets the settings object holding the settings used for this widget.
10020 * Note that this function can only be called when the #GtkWidget
10021 * is attached to a toplevel, since the settings object is specific
10022 * to a particular #GdkScreen.
10024 * Return value: (transfer none): the relevant #GtkSettings object
10027 gtk_widget_get_settings (GtkWidget *widget)
10029 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10031 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10035 * gtk_widget_get_events:
10036 * @widget: a #GtkWidget
10038 * Returns the event mask for the widget (a bitfield containing flags
10039 * from the #GdkEventMask enumeration). These are the events that the widget
10042 * Return value: event mask for @widget
10045 gtk_widget_get_events (GtkWidget *widget)
10047 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10049 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10053 * gtk_widget_get_device_events:
10054 * @widget: a #GtkWidget
10055 * @device: a #GdkDevice
10057 * Returns the events mask for the widget corresponding to an specific device. These
10058 * are the events that the widget will receive when @device operates on it.
10060 * Returns: device event mask for @widget
10065 gtk_widget_get_device_events (GtkWidget *widget,
10068 GHashTable *device_events;
10070 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10071 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10073 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10075 if (!device_events)
10078 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10082 * gtk_widget_get_pointer:
10083 * @widget: a #GtkWidget
10084 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10085 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10087 * Obtains the location of the mouse pointer in widget coordinates.
10088 * Widget coordinates are a bit odd; for historical reasons, they are
10089 * defined as @widget->window coordinates for widgets that are not
10090 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10091 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10093 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10096 gtk_widget_get_pointer (GtkWidget *widget,
10100 GtkWidgetPrivate *priv;
10102 g_return_if_fail (GTK_IS_WIDGET (widget));
10104 priv = widget->priv;
10111 if (gtk_widget_get_realized (widget))
10113 gdk_window_get_device_position (priv->window,
10114 gdk_device_manager_get_client_pointer (
10115 gdk_display_get_device_manager (
10116 gtk_widget_get_display (widget))),
10119 if (!gtk_widget_get_has_window (widget))
10122 *x -= priv->allocation.x;
10124 *y -= priv->allocation.y;
10130 * gtk_widget_is_ancestor:
10131 * @widget: a #GtkWidget
10132 * @ancestor: another #GtkWidget
10134 * Determines whether @widget is somewhere inside @ancestor, possibly with
10135 * intermediate containers.
10137 * Return value: %TRUE if @ancestor contains @widget as a child,
10138 * grandchild, great grandchild, etc.
10141 gtk_widget_is_ancestor (GtkWidget *widget,
10142 GtkWidget *ancestor)
10144 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10145 g_return_val_if_fail (ancestor != NULL, FALSE);
10149 if (widget->priv->parent == ancestor)
10151 widget = widget->priv->parent;
10157 static GQuark quark_composite_name = 0;
10160 * gtk_widget_set_composite_name:
10161 * @widget: a #GtkWidget.
10162 * @name: the name to set
10164 * Sets a widgets composite name. The widget must be
10165 * a composite child of its parent; see gtk_widget_push_composite_child().
10168 gtk_widget_set_composite_name (GtkWidget *widget,
10171 g_return_if_fail (GTK_IS_WIDGET (widget));
10172 g_return_if_fail (widget->priv->composite_child);
10173 g_return_if_fail (name != NULL);
10175 if (!quark_composite_name)
10176 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10178 g_object_set_qdata_full (G_OBJECT (widget),
10179 quark_composite_name,
10185 * gtk_widget_get_composite_name:
10186 * @widget: a #GtkWidget
10188 * Obtains the composite name of a widget.
10190 * Returns: the composite name of @widget, or %NULL if @widget is not
10191 * a composite child. The string should be freed when it is no
10195 gtk_widget_get_composite_name (GtkWidget *widget)
10197 GtkWidgetPrivate *priv;
10199 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10201 priv = widget->priv;
10203 if (widget->priv->composite_child && priv->parent)
10204 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10211 * gtk_widget_push_composite_child:
10213 * Makes all newly-created widgets as composite children until
10214 * the corresponding gtk_widget_pop_composite_child() call.
10216 * A composite child is a child that's an implementation detail of the
10217 * container it's inside and should not be visible to people using the
10218 * container. Composite children aren't treated differently by GTK (but
10219 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10220 * builders might want to treat them in a different way.
10222 * Here is a simple example:
10224 * gtk_widget_push_composite_child ();
10225 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10226 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10227 * gtk_widget_pop_composite_child ();
10228 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10229 * GTK_WIDGET (scrolled_window));
10230 * g_object_ref (scrolled_window->hscrollbar);
10234 gtk_widget_push_composite_child (void)
10236 composite_child_stack++;
10240 * gtk_widget_pop_composite_child:
10242 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10245 gtk_widget_pop_composite_child (void)
10247 if (composite_child_stack)
10248 composite_child_stack--;
10252 gtk_widget_emit_direction_changed (GtkWidget *widget,
10253 GtkTextDirection old_dir)
10255 GtkTextDirection direction;
10256 GtkStateFlags state;
10258 gtk_widget_update_pango_context (widget);
10260 direction = gtk_widget_get_direction (widget);
10261 state = widget->priv->state_flags;
10262 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10266 case GTK_TEXT_DIR_LTR:
10267 state |= GTK_STATE_FLAG_DIR_LTR;
10270 case GTK_TEXT_DIR_RTL:
10271 state |= GTK_STATE_FLAG_DIR_RTL;
10274 case GTK_TEXT_DIR_NONE:
10276 g_assert_not_reached ();
10280 gtk_widget_set_state_flags (widget, state, TRUE);
10282 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10286 * gtk_widget_set_direction:
10287 * @widget: a #GtkWidget
10288 * @dir: the new direction
10290 * Sets the reading direction on a particular widget. This direction
10291 * controls the primary direction for widgets containing text,
10292 * and also the direction in which the children of a container are
10293 * packed. The ability to set the direction is present in order
10294 * so that correct localization into languages with right-to-left
10295 * reading directions can be done. Generally, applications will
10296 * let the default reading direction present, except for containers
10297 * where the containers are arranged in an order that is explicitely
10298 * visual rather than logical (such as buttons for text justification).
10300 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10301 * set by gtk_widget_set_default_direction() will be used.
10304 gtk_widget_set_direction (GtkWidget *widget,
10305 GtkTextDirection dir)
10307 GtkTextDirection old_dir;
10309 g_return_if_fail (GTK_IS_WIDGET (widget));
10310 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10312 old_dir = gtk_widget_get_direction (widget);
10314 widget->priv->direction = dir;
10316 if (old_dir != gtk_widget_get_direction (widget))
10317 gtk_widget_emit_direction_changed (widget, old_dir);
10321 * gtk_widget_get_direction:
10322 * @widget: a #GtkWidget
10324 * Gets the reading direction for a particular widget. See
10325 * gtk_widget_set_direction().
10327 * Return value: the reading direction for the widget.
10330 gtk_widget_get_direction (GtkWidget *widget)
10332 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10334 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10335 return gtk_default_direction;
10337 return widget->priv->direction;
10341 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10343 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10345 g_object_ref (widget);
10347 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10348 gtk_widget_emit_direction_changed (widget, old_dir);
10350 if (GTK_IS_CONTAINER (widget))
10351 gtk_container_forall (GTK_CONTAINER (widget),
10352 gtk_widget_set_default_direction_recurse,
10355 g_object_unref (widget);
10359 * gtk_widget_set_default_direction:
10360 * @dir: the new default direction. This cannot be
10361 * %GTK_TEXT_DIR_NONE.
10363 * Sets the default reading direction for widgets where the
10364 * direction has not been explicitly set by gtk_widget_set_direction().
10367 gtk_widget_set_default_direction (GtkTextDirection dir)
10369 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10371 if (dir != gtk_default_direction)
10373 GList *toplevels, *tmp_list;
10374 GtkTextDirection old_dir = gtk_default_direction;
10376 gtk_default_direction = dir;
10378 tmp_list = toplevels = gtk_window_list_toplevels ();
10379 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10383 gtk_widget_set_default_direction_recurse (tmp_list->data,
10384 GUINT_TO_POINTER (old_dir));
10385 g_object_unref (tmp_list->data);
10386 tmp_list = tmp_list->next;
10389 g_list_free (toplevels);
10394 * gtk_widget_get_default_direction:
10396 * Obtains the current default reading direction. See
10397 * gtk_widget_set_default_direction().
10399 * Return value: the current default direction.
10402 gtk_widget_get_default_direction (void)
10404 return gtk_default_direction;
10408 gtk_widget_constructed (GObject *object)
10410 GtkWidget *widget = GTK_WIDGET (object);
10411 GtkWidgetPrivate *priv = widget->priv;
10413 /* As strange as it may seem, this may happen on object construction.
10414 * init() implementations of parent types may eventually call this function,
10415 * each with its corresponding GType, which could leave a child
10416 * implementation with a wrong widget type in the widget path
10419 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10421 gtk_widget_path_free (priv->path);
10425 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10429 gtk_widget_dispose (GObject *object)
10431 GtkWidget *widget = GTK_WIDGET (object);
10432 GtkWidgetPrivate *priv = widget->priv;
10435 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10436 else if (gtk_widget_get_visible (widget))
10437 gtk_widget_hide (widget);
10439 priv->visible = FALSE;
10440 if (gtk_widget_get_realized (widget))
10441 gtk_widget_unrealize (widget);
10443 if (!priv->in_destruction)
10445 priv->in_destruction = TRUE;
10446 g_signal_emit (object, widget_signals[DESTROY], 0);
10447 priv->in_destruction = FALSE;
10450 g_clear_object (&priv->muxer);
10452 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10456 gtk_widget_real_destroy (GtkWidget *object)
10458 /* gtk_object_destroy() will already hold a refcount on object */
10459 GtkWidget *widget = GTK_WIDGET (object);
10460 GtkWidgetPrivate *priv = widget->priv;
10462 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10464 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10468 gtk_accessible_set_widget (accessible, NULL);
10469 g_object_unref (accessible);
10473 /* wipe accelerator closures (keep order) */
10474 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10475 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10477 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10478 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10480 gtk_grab_remove (widget);
10483 g_object_unref (priv->style);
10484 priv->style = gtk_widget_get_default_style ();
10485 g_object_ref (priv->style);
10489 gtk_widget_finalize (GObject *object)
10491 GtkWidget *widget = GTK_WIDGET (object);
10492 GtkWidgetPrivate *priv = widget->priv;
10493 GtkWidgetAuxInfo *aux_info;
10494 GtkAccessible *accessible;
10496 gtk_grab_remove (widget);
10498 g_object_unref (priv->style);
10499 priv->style = NULL;
10501 g_free (priv->name);
10503 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10505 gtk_widget_aux_info_destroy (aux_info);
10507 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10509 g_object_unref (accessible);
10512 gtk_widget_path_free (priv->path);
10516 _gtk_style_context_set_widget (priv->context, NULL);
10517 g_object_unref (priv->context);
10520 _gtk_size_request_cache_free (&priv->requests);
10522 if (g_object_is_floating (object))
10523 g_warning ("A floating object was finalized. This means that someone\n"
10524 "called g_object_unref() on an object that had only a floating\n"
10525 "reference; the initial floating reference is not owned by anyone\n"
10526 "and must be removed with g_object_ref_sink().");
10528 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10531 /*****************************************
10532 * gtk_widget_real_map:
10537 *****************************************/
10540 gtk_widget_real_map (GtkWidget *widget)
10542 GtkWidgetPrivate *priv = widget->priv;
10544 g_assert (gtk_widget_get_realized (widget));
10546 if (!gtk_widget_get_mapped (widget))
10548 gtk_widget_set_mapped (widget, TRUE);
10550 if (gtk_widget_get_has_window (widget))
10551 gdk_window_show (priv->window);
10555 /*****************************************
10556 * gtk_widget_real_unmap:
10561 *****************************************/
10564 gtk_widget_real_unmap (GtkWidget *widget)
10566 GtkWidgetPrivate *priv = widget->priv;
10568 if (gtk_widget_get_mapped (widget))
10570 gtk_widget_set_mapped (widget, FALSE);
10572 if (gtk_widget_get_has_window (widget))
10573 gdk_window_hide (priv->window);
10577 /*****************************************
10578 * gtk_widget_real_realize:
10583 *****************************************/
10586 gtk_widget_real_realize (GtkWidget *widget)
10588 GtkWidgetPrivate *priv = widget->priv;
10590 g_assert (!gtk_widget_get_has_window (widget));
10592 gtk_widget_set_realized (widget, TRUE);
10595 priv->window = gtk_widget_get_parent_window (widget);
10596 g_object_ref (priv->window);
10600 /*****************************************
10601 * gtk_widget_real_unrealize:
10606 *****************************************/
10609 gtk_widget_real_unrealize (GtkWidget *widget)
10611 GtkWidgetPrivate *priv = widget->priv;
10613 g_assert (!widget->priv->mapped);
10615 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10618 /* We must do unrealize child widget BEFORE container widget.
10619 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10620 * So, unrealizing container widget bofore its children causes the problem
10621 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10624 if (GTK_IS_CONTAINER (widget))
10625 gtk_container_forall (GTK_CONTAINER (widget),
10626 (GtkCallback) gtk_widget_unrealize,
10629 if (gtk_widget_get_has_window (widget))
10631 gtk_widget_unregister_window (widget, priv->window);
10632 gdk_window_destroy (priv->window);
10633 priv->window = NULL;
10637 g_object_unref (priv->window);
10638 priv->window = NULL;
10641 gtk_selection_remove_all (widget);
10643 gtk_widget_set_realized (widget, FALSE);
10647 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10648 GtkOrientation orientation,
10649 gint *minimum_size,
10650 gint *natural_size)
10652 const GtkWidgetAuxInfo *aux_info;
10654 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10656 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10657 aux_info->width > 0)
10659 *minimum_size = MAX (*minimum_size, aux_info->width);
10661 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10662 aux_info->height > 0)
10664 *minimum_size = MAX (*minimum_size, aux_info->height);
10667 /* Fix it if set_size_request made natural size smaller than min size.
10668 * This would also silently fix broken widgets, but we warn about them
10669 * in gtksizerequest.c when calling their size request vfuncs.
10671 *natural_size = MAX (*natural_size, *minimum_size);
10673 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10675 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10676 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10680 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10681 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10686 * _gtk_widget_peek_request_cache:
10688 * Returns the address of the widget's request cache (strictly for
10689 * internal use in gtksizerequest.c)
10691 * Return value: the address of @widget's size request cache.
10694 _gtk_widget_peek_request_cache (GtkWidget *widget)
10696 /* Don't bother slowing things down with the return_if_fail guards here */
10697 return &widget->priv->requests;
10701 * _gtk_widget_set_device_window:
10702 * @widget: a #GtkWidget
10703 * @device: a #GdkDevice
10704 * @window: the new device window
10706 * Sets pointer window for @widget and @device.
10707 * Does not ref @window.
10710 _gtk_widget_set_device_window (GtkWidget *widget,
10714 GHashTable *device_window;
10716 g_return_if_fail (GTK_IS_WIDGET (widget));
10717 g_return_if_fail (GDK_IS_DEVICE (device));
10718 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10720 if (!gtk_widget_get_mapped (widget))
10723 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10725 if (!device_window && window)
10727 device_window = g_hash_table_new (NULL, NULL);
10728 g_object_set_qdata_full (G_OBJECT (widget),
10729 quark_pointer_window,
10731 (GDestroyNotify) g_hash_table_destroy);
10735 g_hash_table_insert (device_window, device, window);
10736 else if (device_window)
10738 g_hash_table_remove (device_window, device);
10740 if (g_hash_table_size (device_window) == 0)
10741 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10746 * _gtk_widget_get_device_window:
10747 * @widget: a #GtkWidget
10748 * @device: a #GdkDevice
10750 * Return value: the device window set on @widget, or %NULL
10753 _gtk_widget_get_device_window (GtkWidget *widget,
10756 GHashTable *device_window;
10758 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10759 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10761 if (!gtk_widget_get_mapped (widget))
10764 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10766 if (!device_window)
10769 return g_hash_table_lookup (device_window, device);
10773 * _gtk_widget_list_devices:
10774 * @widget: a #GtkWidget
10776 * Returns the list of #GdkDevices that is currently on top
10777 * of any window belonging to @widget.
10778 * Free the list with g_list_free(), the elements are owned
10779 * by GTK+ and must not be freed.
10782 _gtk_widget_list_devices (GtkWidget *widget)
10784 GHashTableIter iter;
10785 GHashTable *device_window;
10786 GList *devices = NULL;
10787 gpointer key, value;
10789 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10791 if (!gtk_widget_get_mapped (widget))
10794 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10796 if (G_UNLIKELY (!device_window))
10799 g_hash_table_iter_init (&iter, device_window);
10801 while (g_hash_table_iter_next (&iter, &key, &value))
10802 devices = g_list_prepend (devices, key);
10808 synth_crossing (GtkWidget *widget,
10812 GdkCrossingMode mode,
10813 GdkNotifyType detail)
10817 event = gdk_event_new (type);
10819 event->crossing.window = g_object_ref (window);
10820 event->crossing.send_event = TRUE;
10821 event->crossing.subwindow = g_object_ref (window);
10822 event->crossing.time = GDK_CURRENT_TIME;
10823 event->crossing.x = event->crossing.y = 0;
10824 event->crossing.x_root = event->crossing.y_root = 0;
10825 event->crossing.mode = mode;
10826 event->crossing.detail = detail;
10827 event->crossing.focus = FALSE;
10828 event->crossing.state = 0;
10829 gdk_event_set_device (event, device);
10832 widget = gtk_get_event_widget (event);
10835 gtk_widget_event_internal (widget, event);
10837 gdk_event_free (event);
10841 * _gtk_widget_synthesize_crossing:
10842 * @from: the #GtkWidget the virtual pointer is leaving.
10843 * @to: the #GtkWidget the virtual pointer is moving to.
10844 * @mode: the #GdkCrossingMode to place on the synthesized events.
10846 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10848 * The real pointer window is the window that most recently received an enter notify
10849 * event. Windows that don't select for crossing events can't become the real
10850 * poiner window. The real pointer widget that owns the real pointer window. The
10851 * effective pointer window is the same as the real pointer window unless the real
10852 * pointer widget is either insensitive or there is a grab on a widget that is not
10853 * an ancestor of the real pointer widget (in which case the effective pointer
10854 * window should be the root window).
10856 * When the effective pointer window is the same as the real poiner window, we
10857 * receive crossing events from the windowing system. When the effective pointer
10858 * window changes to become different from the real pointer window we synthesize
10859 * crossing events, attempting to follow X protocol rules:
10861 * When the root window becomes the effective pointer window:
10862 * - leave notify on real pointer window, detail Ancestor
10863 * - leave notify on all of its ancestors, detail Virtual
10864 * - enter notify on root window, detail Inferior
10866 * When the root window ceases to be the effective pointer window:
10867 * - leave notify on root window, detail Inferior
10868 * - enter notify on all ancestors of real pointer window, detail Virtual
10869 * - enter notify on real pointer window, detail Ancestor
10872 _gtk_widget_synthesize_crossing (GtkWidget *from,
10875 GdkCrossingMode mode)
10877 GdkWindow *from_window = NULL, *to_window = NULL;
10879 g_return_if_fail (from != NULL || to != NULL);
10883 from_window = _gtk_widget_get_device_window (from, device);
10886 from_window = from->priv->window;
10891 to_window = _gtk_widget_get_device_window (to, device);
10894 to_window = to->priv->window;
10897 if (from_window == NULL && to_window == NULL)
10899 else if (from_window != NULL && to_window == NULL)
10901 GList *from_ancestors = NULL, *list;
10902 GdkWindow *from_ancestor = from_window;
10904 while (from_ancestor != NULL)
10906 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10907 if (from_ancestor == NULL)
10909 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10912 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10913 device, mode, GDK_NOTIFY_ANCESTOR);
10914 for (list = g_list_last (from_ancestors); list; list = list->prev)
10916 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10917 device, mode, GDK_NOTIFY_VIRTUAL);
10920 /* XXX: enter/inferior on root window? */
10922 g_list_free (from_ancestors);
10924 else if (from_window == NULL && to_window != NULL)
10926 GList *to_ancestors = NULL, *list;
10927 GdkWindow *to_ancestor = to_window;
10929 while (to_ancestor != NULL)
10931 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10932 if (to_ancestor == NULL)
10934 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10937 /* XXX: leave/inferior on root window? */
10939 for (list = to_ancestors; list; list = list->next)
10941 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10942 device, mode, GDK_NOTIFY_VIRTUAL);
10944 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10945 device, mode, GDK_NOTIFY_ANCESTOR);
10947 g_list_free (to_ancestors);
10949 else if (from_window == to_window)
10953 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10954 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10956 while (from_ancestor != NULL || to_ancestor != NULL)
10958 if (from_ancestor != NULL)
10960 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10961 if (from_ancestor == to_window)
10964 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10966 if (to_ancestor != NULL)
10968 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10969 if (to_ancestor == from_window)
10972 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10975 if (to_ancestor == from_window)
10977 if (mode != GDK_CROSSING_GTK_UNGRAB)
10978 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10979 device, mode, GDK_NOTIFY_INFERIOR);
10980 for (list = to_ancestors; list; list = list->next)
10981 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10982 device, mode, GDK_NOTIFY_VIRTUAL);
10983 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10984 device, mode, GDK_NOTIFY_ANCESTOR);
10986 else if (from_ancestor == to_window)
10988 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10989 device, mode, GDK_NOTIFY_ANCESTOR);
10990 for (list = g_list_last (from_ancestors); list; list = list->prev)
10992 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10993 device, mode, GDK_NOTIFY_VIRTUAL);
10995 if (mode != GDK_CROSSING_GTK_GRAB)
10996 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10997 device, mode, GDK_NOTIFY_INFERIOR);
11001 while (from_ancestors != NULL && to_ancestors != NULL
11002 && from_ancestors->data == to_ancestors->data)
11004 from_ancestors = g_list_delete_link (from_ancestors,
11006 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11009 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11010 device, mode, GDK_NOTIFY_NONLINEAR);
11012 for (list = g_list_last (from_ancestors); list; list = list->prev)
11014 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11015 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11017 for (list = to_ancestors; list; list = list->next)
11019 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11020 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11022 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11023 device, mode, GDK_NOTIFY_NONLINEAR);
11025 g_list_free (from_ancestors);
11026 g_list_free (to_ancestors);
11031 gtk_widget_propagate_state (GtkWidget *widget,
11032 GtkStateData *data)
11034 GtkWidgetPrivate *priv = widget->priv;
11035 GtkStateFlags new_flags, old_flags = priv->state_flags;
11036 GtkStateType old_state;
11038 old_state = gtk_widget_get_state (widget);
11040 priv->state_flags |= data->flags_to_set;
11041 priv->state_flags &= ~(data->flags_to_unset);
11043 /* make insensitivity unoverridable */
11044 if (!priv->sensitive)
11045 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11047 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11051 window = gtk_widget_get_toplevel (widget);
11053 if (window && gtk_widget_is_toplevel (window))
11054 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11057 new_flags = priv->state_flags;
11059 if (old_flags != new_flags)
11061 g_object_ref (widget);
11063 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11064 gtk_grab_remove (widget);
11066 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11068 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11069 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11071 if (!priv->shadowed &&
11072 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11074 GList *event_windows = NULL;
11075 GList *devices, *d;
11077 devices = _gtk_widget_list_devices (widget);
11079 for (d = devices; d; d = d->next)
11085 window = _gtk_widget_get_device_window (widget, device);
11087 /* Do not propagate more than once to the
11088 * same window if non-multidevice aware.
11090 if (!gdk_window_get_support_multidevice (window) &&
11091 g_list_find (event_windows, window))
11094 if (!gtk_widget_is_sensitive (widget))
11095 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11096 GDK_CROSSING_STATE_CHANGED);
11098 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11099 GDK_CROSSING_STATE_CHANGED);
11101 event_windows = g_list_prepend (event_windows, window);
11104 g_list_free (event_windows);
11105 g_list_free (devices);
11108 if (GTK_IS_CONTAINER (widget))
11110 GtkStateData child_data;
11112 /* Make sure to only propate the right states further */
11113 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11114 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11116 gtk_container_forall (GTK_CONTAINER (widget),
11117 (GtkCallback) gtk_widget_propagate_state,
11121 g_object_unref (widget);
11125 static const GtkWidgetAuxInfo default_aux_info = {
11133 * gtk_widget_get_aux_info:
11134 * @widget: a #GtkWidget
11135 * @create: if %TRUE, create the structure if it doesn't exist
11137 * Get the #GtkWidgetAuxInfo structure for the widget.
11139 * Return value: the #GtkAuxInfo structure for the widget, or
11140 * %NULL if @create is %FALSE and one doesn't already exist.
11142 static GtkWidgetAuxInfo *
11143 gtk_widget_get_aux_info (GtkWidget *widget,
11146 GtkWidgetAuxInfo *aux_info;
11148 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11149 if (!aux_info && create)
11151 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11153 *aux_info = default_aux_info;
11155 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11161 static const GtkWidgetAuxInfo*
11162 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11164 GtkWidgetAuxInfo *aux_info;
11166 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11167 if (aux_info == NULL)
11169 return &default_aux_info;
11177 /*****************************************
11178 * gtk_widget_aux_info_destroy:
11183 *****************************************/
11186 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11188 g_slice_free (GtkWidgetAuxInfo, aux_info);
11192 * gtk_widget_shape_combine_region:
11193 * @widget: a #GtkWidget
11194 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11196 * Sets a shape for this widget's GDK window. This allows for
11197 * transparent windows etc., see gdk_window_shape_combine_region()
11198 * for more information.
11203 gtk_widget_shape_combine_region (GtkWidget *widget,
11204 cairo_region_t *region)
11206 GtkWidgetPrivate *priv;
11208 g_return_if_fail (GTK_IS_WIDGET (widget));
11209 /* set_shape doesn't work on widgets without gdk window */
11210 g_return_if_fail (gtk_widget_get_has_window (widget));
11212 priv = widget->priv;
11214 if (region == NULL)
11216 priv->has_shape_mask = FALSE;
11219 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11221 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11225 priv->has_shape_mask = TRUE;
11227 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11228 cairo_region_copy (region),
11229 (GDestroyNotify) cairo_region_destroy);
11231 /* set shape if widget has a gdk window already.
11232 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11235 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11240 * gtk_widget_input_shape_combine_region:
11241 * @widget: a #GtkWidget
11242 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11244 * Sets an input shape for this widget's GDK window. This allows for
11245 * windows which react to mouse click in a nonrectangular region, see
11246 * gdk_window_input_shape_combine_region() for more information.
11251 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11252 cairo_region_t *region)
11254 GtkWidgetPrivate *priv;
11256 g_return_if_fail (GTK_IS_WIDGET (widget));
11257 /* set_shape doesn't work on widgets without gdk window */
11258 g_return_if_fail (gtk_widget_get_has_window (widget));
11260 priv = widget->priv;
11262 if (region == NULL)
11265 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11267 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11271 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11272 cairo_region_copy (region),
11273 (GDestroyNotify) cairo_region_destroy);
11275 /* set shape if widget has a gdk window already.
11276 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11279 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11284 /* style properties
11288 * gtk_widget_class_install_style_property_parser: (skip)
11289 * @klass: a #GtkWidgetClass
11290 * @pspec: the #GParamSpec for the style property
11291 * @parser: the parser for the style property
11293 * Installs a style property on a widget class.
11296 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11298 GtkRcPropertyParser parser)
11300 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11301 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11302 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11303 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11305 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11307 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11308 G_OBJECT_CLASS_NAME (klass),
11313 g_param_spec_ref_sink (pspec);
11314 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11315 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11319 * gtk_widget_class_install_style_property:
11320 * @klass: a #GtkWidgetClass
11321 * @pspec: the #GParamSpec for the property
11323 * Installs a style property on a widget class. The parser for the
11324 * style property is determined by the value type of @pspec.
11327 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11330 GtkRcPropertyParser parser;
11332 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11333 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11335 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11337 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11341 * gtk_widget_class_find_style_property:
11342 * @klass: a #GtkWidgetClass
11343 * @property_name: the name of the style property to find
11345 * Finds a style property of a widget class by name.
11347 * Returns: (transfer none): the #GParamSpec of the style property or
11348 * %NULL if @class has no style property with that name.
11353 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11354 const gchar *property_name)
11356 g_return_val_if_fail (property_name != NULL, NULL);
11358 return g_param_spec_pool_lookup (style_property_spec_pool,
11360 G_OBJECT_CLASS_TYPE (klass),
11365 * gtk_widget_class_list_style_properties:
11366 * @klass: a #GtkWidgetClass
11367 * @n_properties: location to return the number of style properties found
11369 * Returns all style properties of a widget class.
11371 * Returns: (array length=n_properties) (transfer container): a
11372 * newly allocated array of #GParamSpec*. The array must be
11373 * freed with g_free().
11378 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11379 guint *n_properties)
11381 GParamSpec **pspecs;
11384 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11385 G_OBJECT_CLASS_TYPE (klass),
11394 * gtk_widget_style_get_property:
11395 * @widget: a #GtkWidget
11396 * @property_name: the name of a style property
11397 * @value: location to return the property value
11399 * Gets the value of a style property of @widget.
11402 gtk_widget_style_get_property (GtkWidget *widget,
11403 const gchar *property_name,
11408 g_return_if_fail (GTK_IS_WIDGET (widget));
11409 g_return_if_fail (property_name != NULL);
11410 g_return_if_fail (G_IS_VALUE (value));
11412 g_object_ref (widget);
11413 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11415 G_OBJECT_TYPE (widget),
11418 g_warning ("%s: widget class `%s' has no property named `%s'",
11420 G_OBJECT_TYPE_NAME (widget),
11424 GtkStyleContext *context;
11425 const GValue *peek_value;
11426 GtkStateFlags state;
11428 context = gtk_widget_get_style_context (widget);
11429 state = gtk_widget_get_state_flags (widget);
11431 peek_value = _gtk_style_context_peek_style_property (context,
11432 G_OBJECT_TYPE (widget),
11435 /* auto-conversion of the caller's value type
11437 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11438 g_value_copy (peek_value, value);
11439 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11440 g_value_transform (peek_value, value);
11442 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11444 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11445 G_VALUE_TYPE_NAME (value));
11447 g_object_unref (widget);
11451 * gtk_widget_style_get_valist:
11452 * @widget: a #GtkWidget
11453 * @first_property_name: the name of the first property to get
11454 * @var_args: a <type>va_list</type> of pairs of property names and
11455 * locations to return the property values, starting with the location
11456 * for @first_property_name.
11458 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11462 gtk_widget_style_get_valist (GtkWidget *widget,
11463 const gchar *first_property_name,
11466 GtkStyleContext *context;
11467 GtkStateFlags state;
11470 g_return_if_fail (GTK_IS_WIDGET (widget));
11472 g_object_ref (widget);
11473 context = gtk_widget_get_style_context (widget);
11474 state = gtk_widget_get_state_flags (widget);
11476 name = first_property_name;
11479 const GValue *peek_value;
11483 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11485 G_OBJECT_TYPE (widget),
11489 g_warning ("%s: widget class `%s' has no property named `%s'",
11491 G_OBJECT_TYPE_NAME (widget),
11495 /* style pspecs are always readable so we can spare that check here */
11497 peek_value = _gtk_style_context_peek_style_property (context,
11498 G_OBJECT_TYPE (widget),
11501 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11504 g_warning ("%s: %s", G_STRLOC, error);
11509 name = va_arg (var_args, gchar*);
11512 g_object_unref (widget);
11516 * gtk_widget_style_get:
11517 * @widget: a #GtkWidget
11518 * @first_property_name: the name of the first property to get
11519 * @...: pairs of property names and locations to return the
11520 * property values, starting with the location for
11521 * @first_property_name, terminated by %NULL.
11523 * Gets the values of a multiple style properties of @widget.
11526 gtk_widget_style_get (GtkWidget *widget,
11527 const gchar *first_property_name,
11532 g_return_if_fail (GTK_IS_WIDGET (widget));
11534 va_start (var_args, first_property_name);
11535 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11540 * gtk_requisition_new:
11542 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11544 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11545 * be freed with gtk_requisition_free().
11550 gtk_requisition_new (void)
11552 return g_slice_new0 (GtkRequisition);
11556 * gtk_requisition_copy:
11557 * @requisition: a #GtkRequisition
11559 * Copies a #GtkRequisition.
11561 * Returns: a copy of @requisition
11564 gtk_requisition_copy (const GtkRequisition *requisition)
11566 return g_slice_dup (GtkRequisition, requisition);
11570 * gtk_requisition_free:
11571 * @requisition: a #GtkRequisition
11573 * Frees a #GtkRequisition.
11576 gtk_requisition_free (GtkRequisition *requisition)
11578 g_slice_free (GtkRequisition, requisition);
11581 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11582 gtk_requisition_copy,
11583 gtk_requisition_free)
11586 * gtk_widget_class_set_accessible_type:
11587 * @widget_class: class to set the accessible type for
11588 * @type: The object type that implements the accessible for @widget_class
11590 * Sets the type to be used for creating accessibles for widgets of
11591 * @widget_class. The given @type must be a subtype of the type used for
11592 * accessibles of the parent class.
11594 * This function should only be called from class init functions of widgets.
11599 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11602 GtkWidgetClassPrivate *priv;
11604 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11605 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11607 priv = widget_class->priv;
11609 priv->accessible_type = type;
11610 /* reset this - honoring the type's role is better. */
11611 priv->accessible_role = ATK_ROLE_INVALID;
11615 * gtk_widget_class_set_accessible_role:
11616 * @widget_class: class to set the accessible role for
11617 * @role: The role to use for accessibles created for @widget_class
11619 * Sets the default #AtkRole to be set on accessibles created for
11620 * widgets of @widget_class. Accessibles may decide to not honor this
11621 * setting if their role reporting is more refined. Calls to
11622 * gtk_widget_class_set_accessible_type() will reset this value.
11624 * In cases where you want more fine-grained control over the role of
11625 * accessibles created for @widget_class, you should provide your own
11626 * accessible type and use gtk_widget_class_set_accessible_type()
11629 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11630 * and the accessible's default role will be used instead.
11632 * This function should only be called from class init functions of widgets.
11637 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11640 GtkWidgetClassPrivate *priv;
11642 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11644 priv = widget_class->priv;
11646 priv->accessible_role = role;
11650 * _gtk_widget_peek_accessible:
11651 * @widget: a #GtkWidget
11653 * Gets the accessible for @widget, if it has been created yet.
11654 * Otherwise, this function returns %NULL. If the @widget's implementation
11655 * does not use the default way to create accessibles, %NULL will always be
11658 * Returns: the accessible for @widget or %NULL if none has been
11662 _gtk_widget_peek_accessible (GtkWidget *widget)
11664 return g_object_get_qdata (G_OBJECT (widget),
11665 quark_accessible_object);
11669 * gtk_widget_get_accessible:
11670 * @widget: a #GtkWidget
11672 * Returns the accessible object that describes the widget to an
11673 * assistive technology.
11675 * If accessibility support is not available, this #AtkObject
11676 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11677 * implementation is available for the widget instance in question,
11678 * it will inherit an #AtkObject implementation from the first ancestor
11679 * class for which such an implementation is defined.
11681 * The documentation of the
11682 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11683 * library contains more information about accessible objects and their uses.
11685 * Returns: (transfer none): the #AtkObject associated with @widget
11688 gtk_widget_get_accessible (GtkWidget *widget)
11690 GtkWidgetClass *klass;
11692 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11694 klass = GTK_WIDGET_GET_CLASS (widget);
11696 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11698 return klass->get_accessible (widget);
11702 gtk_widget_real_get_accessible (GtkWidget *widget)
11704 AtkObject* accessible;
11706 accessible = g_object_get_qdata (G_OBJECT (widget),
11707 quark_accessible_object);
11710 GtkWidgetClass *widget_class;
11711 GtkWidgetClassPrivate *priv;
11712 AtkObjectFactory *factory;
11713 AtkRegistry *default_registry;
11715 widget_class = GTK_WIDGET_GET_CLASS (widget);
11716 priv = widget_class->priv;
11718 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11720 default_registry = atk_get_default_registry ();
11721 factory = atk_registry_get_factory (default_registry,
11722 G_TYPE_FROM_INSTANCE (widget));
11724 atk_object_factory_create_accessible (factory,
11725 G_OBJECT (widget));
11727 if (priv->accessible_role != ATK_ROLE_INVALID)
11728 atk_object_set_role (accessible, priv->accessible_role);
11730 g_object_set_qdata (G_OBJECT (widget),
11731 quark_accessible_object,
11736 accessible = g_object_new (priv->accessible_type,
11739 if (priv->accessible_role != ATK_ROLE_INVALID)
11740 atk_object_set_role (accessible, priv->accessible_role);
11742 g_object_set_qdata (G_OBJECT (widget),
11743 quark_accessible_object,
11746 atk_object_initialize (accessible, widget);
11748 /* Set the role again, since we don't want a role set
11749 * in some parent initialize() function to override
11752 if (priv->accessible_role != ATK_ROLE_INVALID)
11753 atk_object_set_role (accessible, priv->accessible_role);
11760 * Initialize a AtkImplementorIface instance's virtual pointers as
11761 * appropriate to this implementor's class (GtkWidget).
11764 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11766 iface->ref_accessible = gtk_widget_ref_accessible;
11770 gtk_widget_ref_accessible (AtkImplementor *implementor)
11772 AtkObject *accessible;
11774 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11776 g_object_ref (accessible);
11781 * Expand flag management
11785 gtk_widget_update_computed_expand (GtkWidget *widget)
11787 GtkWidgetPrivate *priv;
11789 priv = widget->priv;
11791 if (priv->need_compute_expand)
11795 if (priv->hexpand_set)
11800 if (priv->vexpand_set)
11805 /* we don't need to use compute_expand if both expands are
11806 * forced by the app
11808 if (!(priv->hexpand_set && priv->vexpand_set))
11810 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11814 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11815 priv->hexpand_set ? &ignored : &h,
11816 priv->vexpand_set ? &ignored : &v);
11820 priv->need_compute_expand = FALSE;
11821 priv->computed_hexpand = h != FALSE;
11822 priv->computed_vexpand = v != FALSE;
11827 * gtk_widget_queue_compute_expand:
11828 * @widget: a #GtkWidget
11830 * Mark @widget as needing to recompute its expand flags. Call
11831 * this function when setting legacy expand child properties
11832 * on the child of a container.
11834 * See gtk_widget_compute_expand().
11837 gtk_widget_queue_compute_expand (GtkWidget *widget)
11840 gboolean changed_anything;
11842 if (widget->priv->need_compute_expand)
11845 changed_anything = FALSE;
11847 while (parent != NULL)
11849 if (!parent->priv->need_compute_expand)
11851 parent->priv->need_compute_expand = TRUE;
11852 changed_anything = TRUE;
11855 /* Note: if we had an invariant that "if a child needs to
11856 * compute expand, its parents also do" then we could stop going
11857 * up when we got to a parent that already needed to
11858 * compute. However, in general we compute expand lazily (as
11859 * soon as we see something in a subtree that is expand, we know
11860 * we're expanding) and so this invariant does not hold and we
11861 * have to always walk all the way up in case some ancestor
11862 * is not currently need_compute_expand.
11865 parent = parent->priv->parent;
11868 /* recomputing expand always requires
11869 * a relayout as well
11871 if (changed_anything)
11872 gtk_widget_queue_resize (widget);
11876 * gtk_widget_compute_expand:
11877 * @widget: the widget
11878 * @orientation: expand direction
11880 * Computes whether a container should give this widget extra space
11881 * when possible. Containers should check this, rather than
11882 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11884 * This function already checks whether the widget is visible, so
11885 * visibility does not need to be checked separately. Non-visible
11886 * widgets are not expanded.
11888 * The computed expand value uses either the expand setting explicitly
11889 * set on the widget itself, or, if none has been explicitly set,
11890 * the widget may expand if some of its children do.
11892 * Return value: whether widget tree rooted here should be expanded
11895 gtk_widget_compute_expand (GtkWidget *widget,
11896 GtkOrientation orientation)
11898 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11900 /* We never make a widget expand if not even showing. */
11901 if (!gtk_widget_get_visible (widget))
11904 gtk_widget_update_computed_expand (widget);
11906 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11908 return widget->priv->computed_hexpand;
11912 return widget->priv->computed_vexpand;
11917 gtk_widget_set_expand (GtkWidget *widget,
11918 GtkOrientation orientation,
11921 const char *expand_prop;
11922 const char *expand_set_prop;
11924 GtkWidgetPrivate *priv;
11926 g_return_if_fail (GTK_IS_WIDGET (widget));
11928 priv = widget->priv;
11930 expand = expand != FALSE;
11932 was_both = priv->hexpand && priv->vexpand;
11934 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11936 if (priv->hexpand_set &&
11937 priv->hexpand == expand)
11940 priv->hexpand_set = TRUE;
11941 priv->hexpand = expand;
11943 expand_prop = "hexpand";
11944 expand_set_prop = "hexpand-set";
11948 if (priv->vexpand_set &&
11949 priv->vexpand == expand)
11952 priv->vexpand_set = TRUE;
11953 priv->vexpand = expand;
11955 expand_prop = "vexpand";
11956 expand_set_prop = "vexpand-set";
11959 gtk_widget_queue_compute_expand (widget);
11961 g_object_freeze_notify (G_OBJECT (widget));
11962 g_object_notify (G_OBJECT (widget), expand_prop);
11963 g_object_notify (G_OBJECT (widget), expand_set_prop);
11964 if (was_both != (priv->hexpand && priv->vexpand))
11965 g_object_notify (G_OBJECT (widget), "expand");
11966 g_object_thaw_notify (G_OBJECT (widget));
11970 gtk_widget_set_expand_set (GtkWidget *widget,
11971 GtkOrientation orientation,
11974 GtkWidgetPrivate *priv;
11977 priv = widget->priv;
11979 set = set != FALSE;
11981 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11983 if (set == priv->hexpand_set)
11986 priv->hexpand_set = set;
11987 prop = "hexpand-set";
11991 if (set == priv->vexpand_set)
11994 priv->vexpand_set = set;
11995 prop = "vexpand-set";
11998 gtk_widget_queue_compute_expand (widget);
12000 g_object_notify (G_OBJECT (widget), prop);
12004 * gtk_widget_get_hexpand:
12005 * @widget: the widget
12007 * Gets whether the widget would like any available extra horizontal
12008 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12009 * generally receive the extra space. For example, a list or
12010 * scrollable area or document in your window would often be set to
12013 * Containers should use gtk_widget_compute_expand() rather than
12014 * this function, to see whether a widget, or any of its children,
12015 * has the expand flag set. If any child of a widget wants to
12016 * expand, the parent may ask to expand also.
12018 * This function only looks at the widget's own hexpand flag, rather
12019 * than computing whether the entire widget tree rooted at this widget
12022 * Return value: whether hexpand flag is set
12025 gtk_widget_get_hexpand (GtkWidget *widget)
12027 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12029 return widget->priv->hexpand;
12033 * gtk_widget_set_hexpand:
12034 * @widget: the widget
12035 * @expand: whether to expand
12037 * Sets whether the widget would like any available extra horizontal
12038 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12039 * generally receive the extra space. For example, a list or
12040 * scrollable area or document in your window would often be set to
12043 * Call this function to set the expand flag if you would like your
12044 * widget to become larger horizontally when the window has extra
12047 * By default, widgets automatically expand if any of their children
12048 * want to expand. (To see if a widget will automatically expand given
12049 * its current children and state, call gtk_widget_compute_expand(). A
12050 * container can decide how the expandability of children affects the
12051 * expansion of the container by overriding the compute_expand virtual
12052 * method on #GtkWidget.).
12054 * Setting hexpand explicitly with this function will override the
12055 * automatic expand behavior.
12057 * This function forces the widget to expand or not to expand,
12058 * regardless of children. The override occurs because
12059 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12060 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12061 * value to be used, rather than looking at children and widget state.
12064 gtk_widget_set_hexpand (GtkWidget *widget,
12067 g_return_if_fail (GTK_IS_WIDGET (widget));
12069 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12073 * gtk_widget_get_hexpand_set:
12074 * @widget: the widget
12076 * Gets whether gtk_widget_set_hexpand() has been used to
12077 * explicitly set the expand flag on this widget.
12079 * If hexpand is set, then it overrides any computed
12080 * expand value based on child widgets. If hexpand is not
12081 * set, then the expand value depends on whether any
12082 * children of the widget would like to expand.
12084 * There are few reasons to use this function, but it's here
12085 * for completeness and consistency.
12087 * Return value: whether hexpand has been explicitly set
12090 gtk_widget_get_hexpand_set (GtkWidget *widget)
12092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12094 return widget->priv->hexpand_set;
12098 * gtk_widget_set_hexpand_set:
12099 * @widget: the widget
12100 * @set: value for hexpand-set property
12102 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12105 * The hexpand-set property will be set automatically when you call
12106 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12107 * reason to use this function would be to unset an explicit expand
12110 * If hexpand is set, then it overrides any computed
12111 * expand value based on child widgets. If hexpand is not
12112 * set, then the expand value depends on whether any
12113 * children of the widget would like to expand.
12115 * There are few reasons to use this function, but it's here
12116 * for completeness and consistency.
12119 gtk_widget_set_hexpand_set (GtkWidget *widget,
12122 g_return_if_fail (GTK_IS_WIDGET (widget));
12124 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12129 * gtk_widget_get_vexpand:
12130 * @widget: the widget
12132 * Gets whether the widget would like any available extra vertical
12135 * See gtk_widget_get_hexpand() for more detail.
12137 * Return value: whether vexpand flag is set
12140 gtk_widget_get_vexpand (GtkWidget *widget)
12142 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12144 return widget->priv->vexpand;
12148 * gtk_widget_set_vexpand:
12149 * @widget: the widget
12150 * @expand: whether to expand
12152 * Sets whether the widget would like any available extra vertical
12155 * See gtk_widget_set_hexpand() for more detail.
12158 gtk_widget_set_vexpand (GtkWidget *widget,
12161 g_return_if_fail (GTK_IS_WIDGET (widget));
12163 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12167 * gtk_widget_get_vexpand_set:
12168 * @widget: the widget
12170 * Gets whether gtk_widget_set_vexpand() has been used to
12171 * explicitly set the expand flag on this widget.
12173 * See gtk_widget_get_hexpand_set() for more detail.
12175 * Return value: whether vexpand has been explicitly set
12178 gtk_widget_get_vexpand_set (GtkWidget *widget)
12180 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12182 return widget->priv->vexpand_set;
12186 * gtk_widget_set_vexpand_set:
12187 * @widget: the widget
12188 * @set: value for vexpand-set property
12190 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12193 * See gtk_widget_set_hexpand_set() for more detail.
12196 gtk_widget_set_vexpand_set (GtkWidget *widget,
12199 g_return_if_fail (GTK_IS_WIDGET (widget));
12201 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12205 * GtkBuildable implementation
12207 static GQuark quark_builder_has_default = 0;
12208 static GQuark quark_builder_has_focus = 0;
12209 static GQuark quark_builder_atk_relations = 0;
12210 static GQuark quark_builder_set_name = 0;
12213 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12215 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12216 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12217 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12218 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12220 iface->set_name = gtk_widget_buildable_set_name;
12221 iface->get_name = gtk_widget_buildable_get_name;
12222 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12223 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12224 iface->parser_finished = gtk_widget_buildable_parser_finished;
12225 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12226 iface->custom_finished = gtk_widget_buildable_custom_finished;
12230 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12233 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12234 g_strdup (name), g_free);
12237 static const gchar *
12238 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12240 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12244 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12245 GtkBuilder *builder,
12246 const gchar *childname)
12248 if (strcmp (childname, "accessible") == 0)
12249 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12255 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12256 GtkBuilder *builder,
12258 const GValue *value)
12260 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12261 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12262 GINT_TO_POINTER (TRUE));
12263 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12264 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12265 GINT_TO_POINTER (TRUE));
12267 g_object_set_property (G_OBJECT (buildable), name, value);
12272 gchar *action_name;
12273 GString *description;
12275 gboolean translatable;
12285 free_action (AtkActionData *data, gpointer user_data)
12287 g_free (data->action_name);
12288 g_string_free (data->description, TRUE);
12289 g_free (data->context);
12290 g_slice_free (AtkActionData, data);
12294 free_relation (AtkRelationData *data, gpointer user_data)
12296 g_free (data->target);
12297 g_free (data->type);
12298 g_slice_free (AtkRelationData, data);
12302 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12303 GtkBuilder *builder)
12305 GSList *atk_relations;
12307 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12308 gtk_widget_grab_default (GTK_WIDGET (buildable));
12309 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12310 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12312 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12313 quark_builder_atk_relations);
12316 AtkObject *accessible;
12317 AtkRelationSet *relation_set;
12320 AtkRelationType relation_type;
12321 AtkObject *target_accessible;
12323 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12324 relation_set = atk_object_ref_relation_set (accessible);
12326 for (l = atk_relations; l; l = l->next)
12328 AtkRelationData *relation = (AtkRelationData*)l->data;
12330 target = gtk_builder_get_object (builder, relation->target);
12333 g_warning ("Target object %s in <relation> does not exist",
12337 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12338 g_assert (target_accessible != NULL);
12340 relation_type = atk_relation_type_for_name (relation->type);
12341 if (relation_type == ATK_RELATION_NULL)
12343 g_warning ("<relation> type %s not found",
12347 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12348 target_accessible);
12350 g_object_unref (relation_set);
12352 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12353 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12362 } AccessibilitySubParserData;
12365 accessibility_start_element (GMarkupParseContext *context,
12366 const gchar *element_name,
12367 const gchar **names,
12368 const gchar **values,
12369 gpointer user_data,
12372 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12374 gint line_number, char_number;
12376 if (strcmp (element_name, "relation") == 0)
12378 gchar *target = NULL;
12379 gchar *type = NULL;
12380 AtkRelationData *relation;
12382 for (i = 0; names[i]; i++)
12384 if (strcmp (names[i], "target") == 0)
12385 target = g_strdup (values[i]);
12386 else if (strcmp (names[i], "type") == 0)
12387 type = g_strdup (values[i]);
12390 g_markup_parse_context_get_position (context,
12393 g_set_error (error,
12395 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12396 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12398 line_number, char_number, names[i], "relation");
12405 if (!target || !type)
12407 g_markup_parse_context_get_position (context,
12410 g_set_error (error,
12412 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12413 "%s:%d:%d <%s> requires attribute \"%s\"",
12415 line_number, char_number, "relation",
12416 type ? "target" : "type");
12422 relation = g_slice_new (AtkRelationData);
12423 relation->target = target;
12424 relation->type = type;
12426 data->relations = g_slist_prepend (data->relations, relation);
12428 else if (strcmp (element_name, "action") == 0)
12430 const gchar *action_name = NULL;
12431 const gchar *description = NULL;
12432 const gchar *msg_context = NULL;
12433 gboolean translatable = FALSE;
12434 AtkActionData *action;
12436 for (i = 0; names[i]; i++)
12438 if (strcmp (names[i], "action_name") == 0)
12439 action_name = values[i];
12440 else if (strcmp (names[i], "description") == 0)
12441 description = values[i];
12442 else if (strcmp (names[i], "translatable") == 0)
12444 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12447 else if (strcmp (names[i], "comments") == 0)
12449 /* do nothing, comments are for translators */
12451 else if (strcmp (names[i], "context") == 0)
12452 msg_context = values[i];
12455 g_markup_parse_context_get_position (context,
12458 g_set_error (error,
12460 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12461 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12463 line_number, char_number, names[i], "action");
12470 g_markup_parse_context_get_position (context,
12473 g_set_error (error,
12475 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12476 "%s:%d:%d <%s> requires attribute \"%s\"",
12478 line_number, char_number, "action",
12483 action = g_slice_new (AtkActionData);
12484 action->action_name = g_strdup (action_name);
12485 action->description = g_string_new (description);
12486 action->context = g_strdup (msg_context);
12487 action->translatable = translatable;
12489 data->actions = g_slist_prepend (data->actions, action);
12491 else if (strcmp (element_name, "accessibility") == 0)
12494 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12498 accessibility_text (GMarkupParseContext *context,
12501 gpointer user_data,
12504 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12506 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12508 AtkActionData *action = data->actions->data;
12510 g_string_append_len (action->description, text, text_len);
12514 static const GMarkupParser accessibility_parser =
12516 accessibility_start_element,
12518 accessibility_text,
12527 } AccelGroupParserData;
12530 accel_group_start_element (GMarkupParseContext *context,
12531 const gchar *element_name,
12532 const gchar **names,
12533 const gchar **values,
12534 gpointer user_data,
12539 guint modifiers = 0;
12540 gchar *signal = NULL;
12541 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12543 for (i = 0; names[i]; i++)
12545 if (strcmp (names[i], "key") == 0)
12546 key = gdk_keyval_from_name (values[i]);
12547 else if (strcmp (names[i], "modifiers") == 0)
12549 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12555 else if (strcmp (names[i], "signal") == 0)
12556 signal = g_strdup (values[i]);
12559 if (key == 0 || signal == NULL)
12561 g_warning ("<accelerator> requires key and signal attributes");
12564 parser_data->key = key;
12565 parser_data->modifiers = modifiers;
12566 parser_data->signal = signal;
12569 static const GMarkupParser accel_group_parser =
12571 accel_group_start_element,
12580 style_start_element (GMarkupParseContext *context,
12581 const gchar *element_name,
12582 const gchar **names,
12583 const gchar **values,
12584 gpointer user_data,
12587 StyleParserData *style_data = (StyleParserData *)user_data;
12590 if (strcmp (element_name, "class") == 0)
12592 if (g_markup_collect_attributes (element_name,
12596 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12597 G_MARKUP_COLLECT_INVALID))
12599 style_data->classes = g_slist_append (style_data->classes, class_name);
12602 else if (strcmp (element_name, "style") == 0)
12605 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12608 static const GMarkupParser style_parser =
12610 style_start_element,
12614 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12615 GtkBuilder *builder,
12617 const gchar *tagname,
12618 GMarkupParser *parser,
12621 g_assert (buildable);
12623 if (strcmp (tagname, "accelerator") == 0)
12625 AccelGroupParserData *parser_data;
12627 parser_data = g_slice_new0 (AccelGroupParserData);
12628 parser_data->object = g_object_ref (buildable);
12629 *parser = accel_group_parser;
12630 *data = parser_data;
12633 if (strcmp (tagname, "accessibility") == 0)
12635 AccessibilitySubParserData *parser_data;
12637 parser_data = g_slice_new0 (AccessibilitySubParserData);
12638 *parser = accessibility_parser;
12639 *data = parser_data;
12642 if (strcmp (tagname, "style") == 0)
12644 StyleParserData *parser_data;
12646 parser_data = g_slice_new0 (StyleParserData);
12647 *parser = style_parser;
12648 *data = parser_data;
12656 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12657 GtkWidget *toplevel,
12658 gpointer user_data)
12660 AccelGroupParserData *accel_data;
12661 GSList *accel_groups;
12662 GtkAccelGroup *accel_group;
12664 g_return_if_fail (GTK_IS_WIDGET (widget));
12665 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12666 g_return_if_fail (user_data != NULL);
12668 accel_data = (AccelGroupParserData*)user_data;
12669 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12670 if (g_slist_length (accel_groups) == 0)
12672 accel_group = gtk_accel_group_new ();
12673 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12677 g_assert (g_slist_length (accel_groups) == 1);
12678 accel_group = g_slist_nth_data (accel_groups, 0);
12681 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12682 accel_data->signal,
12685 accel_data->modifiers,
12686 GTK_ACCEL_VISIBLE);
12688 g_object_unref (accel_data->object);
12689 g_free (accel_data->signal);
12690 g_slice_free (AccelGroupParserData, accel_data);
12694 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12695 GtkBuilder *builder,
12697 const gchar *tagname,
12698 gpointer user_data)
12700 if (strcmp (tagname, "accelerator") == 0)
12702 AccelGroupParserData *accel_data;
12703 GtkWidget *toplevel;
12705 accel_data = (AccelGroupParserData*)user_data;
12706 g_assert (accel_data->object);
12708 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12710 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12712 else if (strcmp (tagname, "accessibility") == 0)
12714 AccessibilitySubParserData *a11y_data;
12716 a11y_data = (AccessibilitySubParserData*)user_data;
12718 if (a11y_data->actions)
12720 AtkObject *accessible;
12725 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12727 if (ATK_IS_ACTION (accessible))
12729 action = ATK_ACTION (accessible);
12730 n_actions = atk_action_get_n_actions (action);
12732 for (l = a11y_data->actions; l; l = l->next)
12734 AtkActionData *action_data = (AtkActionData*)l->data;
12736 for (i = 0; i < n_actions; i++)
12737 if (strcmp (atk_action_get_name (action, i),
12738 action_data->action_name) == 0)
12743 gchar *description;
12745 if (action_data->translatable && action_data->description->len)
12746 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12747 action_data->context,
12748 action_data->description->str);
12750 description = action_data->description->str;
12752 atk_action_set_description (action, i, description);
12757 g_warning ("accessibility action on a widget that does not implement AtkAction");
12759 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12762 if (a11y_data->relations)
12763 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12764 a11y_data->relations);
12766 g_slice_free (AccessibilitySubParserData, a11y_data);
12768 else if (strcmp (tagname, "style") == 0)
12770 StyleParserData *style_data = (StyleParserData *)user_data;
12771 GtkStyleContext *context;
12774 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12776 for (l = style_data->classes; l; l = l->next)
12777 gtk_style_context_add_class (context, (const gchar *)l->data);
12779 gtk_widget_reset_style (GTK_WIDGET (buildable));
12781 g_slist_free_full (style_data->classes, g_free);
12782 g_slice_free (StyleParserData, style_data);
12786 static GtkSizeRequestMode
12787 gtk_widget_real_get_request_mode (GtkWidget *widget)
12789 /* By default widgets dont trade size at all. */
12790 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12794 gtk_widget_real_get_width (GtkWidget *widget,
12795 gint *minimum_size,
12796 gint *natural_size)
12806 gtk_widget_real_get_height (GtkWidget *widget,
12807 gint *minimum_size,
12808 gint *natural_size)
12818 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12820 gint *minimum_height,
12821 gint *natural_height)
12823 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12827 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12829 gint *minimum_width,
12830 gint *natural_width)
12832 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12836 * gtk_widget_get_halign:
12837 * @widget: a #GtkWidget
12839 * Gets the value of the #GtkWidget:halign property.
12841 * Returns: the horizontal alignment of @widget
12844 gtk_widget_get_halign (GtkWidget *widget)
12846 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12847 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12851 * gtk_widget_set_halign:
12852 * @widget: a #GtkWidget
12853 * @align: the horizontal alignment
12855 * Sets the horizontal alignment of @widget.
12856 * See the #GtkWidget:halign property.
12859 gtk_widget_set_halign (GtkWidget *widget,
12862 GtkWidgetAuxInfo *aux_info;
12864 g_return_if_fail (GTK_IS_WIDGET (widget));
12866 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12868 if (aux_info->halign == align)
12871 aux_info->halign = align;
12872 gtk_widget_queue_resize (widget);
12873 g_object_notify (G_OBJECT (widget), "halign");
12877 * gtk_widget_get_valign:
12878 * @widget: a #GtkWidget
12880 * Gets the value of the #GtkWidget:valign property.
12882 * Returns: the vertical alignment of @widget
12885 gtk_widget_get_valign (GtkWidget *widget)
12887 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12888 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12892 * gtk_widget_set_valign:
12893 * @widget: a #GtkWidget
12894 * @align: the vertical alignment
12896 * Sets the vertical alignment of @widget.
12897 * See the #GtkWidget:valign property.
12900 gtk_widget_set_valign (GtkWidget *widget,
12903 GtkWidgetAuxInfo *aux_info;
12905 g_return_if_fail (GTK_IS_WIDGET (widget));
12907 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12909 if (aux_info->valign == align)
12912 aux_info->valign = align;
12913 gtk_widget_queue_resize (widget);
12914 g_object_notify (G_OBJECT (widget), "valign");
12918 * gtk_widget_get_margin_left:
12919 * @widget: a #GtkWidget
12921 * Gets the value of the #GtkWidget:margin-left property.
12923 * Returns: The left margin of @widget
12928 gtk_widget_get_margin_left (GtkWidget *widget)
12930 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12932 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12936 * gtk_widget_set_margin_left:
12937 * @widget: a #GtkWidget
12938 * @margin: the left margin
12940 * Sets the left margin of @widget.
12941 * See the #GtkWidget:margin-left property.
12946 gtk_widget_set_margin_left (GtkWidget *widget,
12949 GtkWidgetAuxInfo *aux_info;
12951 g_return_if_fail (GTK_IS_WIDGET (widget));
12952 g_return_if_fail (margin <= G_MAXINT16);
12954 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12956 if (aux_info->margin.left == margin)
12959 aux_info->margin.left = margin;
12960 gtk_widget_queue_resize (widget);
12961 g_object_notify (G_OBJECT (widget), "margin-left");
12965 * gtk_widget_get_margin_right:
12966 * @widget: a #GtkWidget
12968 * Gets the value of the #GtkWidget:margin-right property.
12970 * Returns: The right margin of @widget
12975 gtk_widget_get_margin_right (GtkWidget *widget)
12977 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12979 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12983 * gtk_widget_set_margin_right:
12984 * @widget: a #GtkWidget
12985 * @margin: the right margin
12987 * Sets the right margin of @widget.
12988 * See the #GtkWidget:margin-right property.
12993 gtk_widget_set_margin_right (GtkWidget *widget,
12996 GtkWidgetAuxInfo *aux_info;
12998 g_return_if_fail (GTK_IS_WIDGET (widget));
12999 g_return_if_fail (margin <= G_MAXINT16);
13001 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13003 if (aux_info->margin.right == margin)
13006 aux_info->margin.right = margin;
13007 gtk_widget_queue_resize (widget);
13008 g_object_notify (G_OBJECT (widget), "margin-right");
13012 * gtk_widget_get_margin_top:
13013 * @widget: a #GtkWidget
13015 * Gets the value of the #GtkWidget:margin-top property.
13017 * Returns: The top margin of @widget
13022 gtk_widget_get_margin_top (GtkWidget *widget)
13024 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13026 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13030 * gtk_widget_set_margin_top:
13031 * @widget: a #GtkWidget
13032 * @margin: the top margin
13034 * Sets the top margin of @widget.
13035 * See the #GtkWidget:margin-top property.
13040 gtk_widget_set_margin_top (GtkWidget *widget,
13043 GtkWidgetAuxInfo *aux_info;
13045 g_return_if_fail (GTK_IS_WIDGET (widget));
13046 g_return_if_fail (margin <= G_MAXINT16);
13048 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13050 if (aux_info->margin.top == margin)
13053 aux_info->margin.top = margin;
13054 gtk_widget_queue_resize (widget);
13055 g_object_notify (G_OBJECT (widget), "margin-top");
13059 * gtk_widget_get_margin_bottom:
13060 * @widget: a #GtkWidget
13062 * Gets the value of the #GtkWidget:margin-bottom property.
13064 * Returns: The bottom margin of @widget
13069 gtk_widget_get_margin_bottom (GtkWidget *widget)
13071 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13073 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13077 * gtk_widget_set_margin_bottom:
13078 * @widget: a #GtkWidget
13079 * @margin: the bottom margin
13081 * Sets the bottom margin of @widget.
13082 * See the #GtkWidget:margin-bottom property.
13087 gtk_widget_set_margin_bottom (GtkWidget *widget,
13090 GtkWidgetAuxInfo *aux_info;
13092 g_return_if_fail (GTK_IS_WIDGET (widget));
13093 g_return_if_fail (margin <= G_MAXINT16);
13095 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13097 if (aux_info->margin.bottom == margin)
13100 aux_info->margin.bottom = margin;
13101 gtk_widget_queue_resize (widget);
13102 g_object_notify (G_OBJECT (widget), "margin-bottom");
13106 * gtk_widget_get_clipboard:
13107 * @widget: a #GtkWidget
13108 * @selection: a #GdkAtom which identifies the clipboard
13109 * to use. %GDK_SELECTION_CLIPBOARD gives the
13110 * default clipboard. Another common value
13111 * is %GDK_SELECTION_PRIMARY, which gives
13112 * the primary X selection.
13114 * Returns the clipboard object for the given selection to
13115 * be used with @widget. @widget must have a #GdkDisplay
13116 * associated with it, so must be attached to a toplevel
13119 * Return value: (transfer none): the appropriate clipboard object. If no
13120 * clipboard already exists, a new one will
13121 * be created. Once a clipboard object has
13122 * been created, it is persistent for all time.
13127 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13129 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13130 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13132 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13137 * gtk_widget_list_mnemonic_labels:
13138 * @widget: a #GtkWidget
13140 * Returns a newly allocated list of the widgets, normally labels, for
13141 * which this widget is the target of a mnemonic (see for example,
13142 * gtk_label_set_mnemonic_widget()).
13144 * The widgets in the list are not individually referenced. If you
13145 * want to iterate through the list and perform actions involving
13146 * callbacks that might destroy the widgets, you
13147 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13148 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13149 * widgets afterwards.
13151 * Return value: (element-type GtkWidget) (transfer container): the list of
13152 * mnemonic labels; free this list
13153 * with g_list_free() when you are done with it.
13158 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13160 GList *list = NULL;
13163 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13165 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13166 list = g_list_prepend (list, l->data);
13172 * gtk_widget_add_mnemonic_label:
13173 * @widget: a #GtkWidget
13174 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13176 * Adds a widget to the list of mnemonic labels for
13177 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13178 * list of mnemonic labels for the widget is cleared when the
13179 * widget is destroyed, so the caller must make sure to update
13180 * its internal state at this point as well, by using a connection
13181 * to the #GtkWidget::destroy signal or a weak notifier.
13186 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13189 GSList *old_list, *new_list;
13191 g_return_if_fail (GTK_IS_WIDGET (widget));
13192 g_return_if_fail (GTK_IS_WIDGET (label));
13194 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13195 new_list = g_slist_prepend (old_list, label);
13197 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13198 new_list, (GDestroyNotify) g_slist_free);
13202 * gtk_widget_remove_mnemonic_label:
13203 * @widget: a #GtkWidget
13204 * @label: a #GtkWidget that was previously set as a mnemnic label for
13205 * @widget with gtk_widget_add_mnemonic_label().
13207 * Removes a widget from the list of mnemonic labels for
13208 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13209 * must have previously been added to the list with
13210 * gtk_widget_add_mnemonic_label().
13215 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13218 GSList *old_list, *new_list;
13220 g_return_if_fail (GTK_IS_WIDGET (widget));
13221 g_return_if_fail (GTK_IS_WIDGET (label));
13223 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13224 new_list = g_slist_remove (old_list, label);
13227 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13228 new_list, (GDestroyNotify) g_slist_free);
13232 * gtk_widget_get_no_show_all:
13233 * @widget: a #GtkWidget
13235 * Returns the current value of the #GtkWidget:no-show-all property,
13236 * which determines whether calls to gtk_widget_show_all()
13237 * will affect this widget.
13239 * Return value: the current value of the "no-show-all" property.
13244 gtk_widget_get_no_show_all (GtkWidget *widget)
13246 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13248 return widget->priv->no_show_all;
13252 * gtk_widget_set_no_show_all:
13253 * @widget: a #GtkWidget
13254 * @no_show_all: the new value for the "no-show-all" property
13256 * Sets the #GtkWidget:no-show-all property, which determines whether
13257 * calls to gtk_widget_show_all() will affect this widget.
13259 * This is mostly for use in constructing widget hierarchies with externally
13260 * controlled visibility, see #GtkUIManager.
13265 gtk_widget_set_no_show_all (GtkWidget *widget,
13266 gboolean no_show_all)
13268 g_return_if_fail (GTK_IS_WIDGET (widget));
13270 no_show_all = (no_show_all != FALSE);
13272 if (widget->priv->no_show_all != no_show_all)
13274 widget->priv->no_show_all = no_show_all;
13276 g_object_notify (G_OBJECT (widget), "no-show-all");
13282 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13283 gboolean has_tooltip,
13286 GtkWidgetPrivate *priv = widget->priv;
13287 gboolean priv_has_tooltip;
13289 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13290 quark_has_tooltip));
13292 if (priv_has_tooltip != has_tooltip || force)
13294 priv_has_tooltip = has_tooltip;
13296 if (priv_has_tooltip)
13298 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13299 gdk_window_set_events (priv->window,
13300 gdk_window_get_events (priv->window) |
13301 GDK_LEAVE_NOTIFY_MASK |
13302 GDK_POINTER_MOTION_MASK |
13303 GDK_POINTER_MOTION_HINT_MASK);
13305 if (gtk_widget_get_has_window (widget))
13306 gtk_widget_add_events (widget,
13307 GDK_LEAVE_NOTIFY_MASK |
13308 GDK_POINTER_MOTION_MASK |
13309 GDK_POINTER_MOTION_HINT_MASK);
13312 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13313 GUINT_TO_POINTER (priv_has_tooltip));
13318 * gtk_widget_set_tooltip_window:
13319 * @widget: a #GtkWidget
13320 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13322 * Replaces the default, usually yellow, window used for displaying
13323 * tooltips with @custom_window. GTK+ will take care of showing and
13324 * hiding @custom_window at the right moment, to behave likewise as
13325 * the default tooltip window. If @custom_window is %NULL, the default
13326 * tooltip window will be used.
13328 * If the custom window should have the default theming it needs to
13329 * have the name "gtk-tooltip", see gtk_widget_set_name().
13334 gtk_widget_set_tooltip_window (GtkWidget *widget,
13335 GtkWindow *custom_window)
13337 gboolean has_tooltip;
13338 gchar *tooltip_markup;
13340 g_return_if_fail (GTK_IS_WIDGET (widget));
13341 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13343 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13346 g_object_ref (custom_window);
13348 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13349 custom_window, g_object_unref);
13351 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13352 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13354 if (has_tooltip && gtk_widget_get_visible (widget))
13355 gtk_widget_queue_tooltip_query (widget);
13359 * gtk_widget_get_tooltip_window:
13360 * @widget: a #GtkWidget
13362 * Returns the #GtkWindow of the current tooltip. This can be the
13363 * GtkWindow created by default, or the custom tooltip window set
13364 * using gtk_widget_set_tooltip_window().
13366 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13371 gtk_widget_get_tooltip_window (GtkWidget *widget)
13373 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13375 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13379 * gtk_widget_trigger_tooltip_query:
13380 * @widget: a #GtkWidget
13382 * Triggers a tooltip query on the display where the toplevel of @widget
13383 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13389 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13391 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13394 static guint tooltip_query_id;
13395 static GSList *tooltip_query_displays;
13398 tooltip_query_idle (gpointer data)
13400 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13401 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13402 g_slist_free (tooltip_query_displays);
13404 tooltip_query_displays = NULL;
13405 tooltip_query_id = 0;
13411 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13413 GdkDisplay *display;
13415 display = gtk_widget_get_display (widget);
13417 if (!g_slist_find (tooltip_query_displays, display))
13418 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13420 if (tooltip_query_id == 0)
13421 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13425 * gtk_widget_set_tooltip_text:
13426 * @widget: a #GtkWidget
13427 * @text: (allow-none): the contents of the tooltip for @widget
13429 * Sets @text as the contents of the tooltip. This function will take
13430 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13431 * handler for the #GtkWidget::query-tooltip signal.
13433 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13438 gtk_widget_set_tooltip_text (GtkWidget *widget,
13441 g_return_if_fail (GTK_IS_WIDGET (widget));
13443 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13447 * gtk_widget_get_tooltip_text:
13448 * @widget: a #GtkWidget
13450 * Gets the contents of the tooltip for @widget.
13452 * Return value: the tooltip text, or %NULL. You should free the
13453 * returned string with g_free() when done.
13458 gtk_widget_get_tooltip_text (GtkWidget *widget)
13460 gchar *text = NULL;
13462 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13464 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13470 * gtk_widget_set_tooltip_markup:
13471 * @widget: a #GtkWidget
13472 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13474 * Sets @markup as the contents of the tooltip, which is marked up with
13475 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13477 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13478 * and of the default handler for the #GtkWidget::query-tooltip signal.
13480 * See also the #GtkWidget:tooltip-markup property and
13481 * gtk_tooltip_set_markup().
13486 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13487 const gchar *markup)
13489 g_return_if_fail (GTK_IS_WIDGET (widget));
13491 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13495 * gtk_widget_get_tooltip_markup:
13496 * @widget: a #GtkWidget
13498 * Gets the contents of the tooltip for @widget.
13500 * Return value: the tooltip text, or %NULL. You should free the
13501 * returned string with g_free() when done.
13506 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13508 gchar *text = NULL;
13510 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13512 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13518 * gtk_widget_set_has_tooltip:
13519 * @widget: a #GtkWidget
13520 * @has_tooltip: whether or not @widget has a tooltip.
13522 * Sets the has-tooltip property on @widget to @has_tooltip. See
13523 * #GtkWidget:has-tooltip for more information.
13528 gtk_widget_set_has_tooltip (GtkWidget *widget,
13529 gboolean has_tooltip)
13531 g_return_if_fail (GTK_IS_WIDGET (widget));
13533 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13537 * gtk_widget_get_has_tooltip:
13538 * @widget: a #GtkWidget
13540 * Returns the current value of the has-tooltip property. See
13541 * #GtkWidget:has-tooltip for more information.
13543 * Return value: current value of has-tooltip on @widget.
13548 gtk_widget_get_has_tooltip (GtkWidget *widget)
13550 gboolean has_tooltip = FALSE;
13552 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13554 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13556 return has_tooltip;
13560 * gtk_widget_get_allocation:
13561 * @widget: a #GtkWidget
13562 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13564 * Retrieves the widget's allocation.
13566 * Note, when implementing a #GtkContainer: a widget's allocation will
13567 * be its "adjusted" allocation, that is, the widget's parent
13568 * container typically calls gtk_widget_size_allocate() with an
13569 * allocation, and that allocation is then adjusted (to handle margin
13570 * and alignment for example) before assignment to the widget.
13571 * gtk_widget_get_allocation() returns the adjusted allocation that
13572 * was actually assigned to the widget. The adjusted allocation is
13573 * guaranteed to be completely contained within the
13574 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13575 * is guaranteed that its children stay inside the assigned bounds,
13576 * but not that they have exactly the bounds the container assigned.
13577 * There is no way to get the original allocation assigned by
13578 * gtk_widget_size_allocate(), since it isn't stored; if a container
13579 * implementation needs that information it will have to track it itself.
13584 gtk_widget_get_allocation (GtkWidget *widget,
13585 GtkAllocation *allocation)
13587 GtkWidgetPrivate *priv;
13589 g_return_if_fail (GTK_IS_WIDGET (widget));
13590 g_return_if_fail (allocation != NULL);
13592 priv = widget->priv;
13594 *allocation = priv->allocation;
13598 * gtk_widget_set_allocation:
13599 * @widget: a #GtkWidget
13600 * @allocation: a pointer to a #GtkAllocation to copy from
13602 * Sets the widget's allocation. This should not be used
13603 * directly, but from within a widget's size_allocate method.
13605 * The allocation set should be the "adjusted" or actual
13606 * allocation. If you're implementing a #GtkContainer, you want to use
13607 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13608 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13609 * allocation inside gtk_widget_size_allocate() to create an adjusted
13615 gtk_widget_set_allocation (GtkWidget *widget,
13616 const GtkAllocation *allocation)
13618 GtkWidgetPrivate *priv;
13620 g_return_if_fail (GTK_IS_WIDGET (widget));
13621 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13622 g_return_if_fail (allocation != NULL);
13624 priv = widget->priv;
13626 priv->allocation = *allocation;
13630 * gtk_widget_get_allocated_width:
13631 * @widget: the widget to query
13633 * Returns the width that has currently been allocated to @widget.
13634 * This function is intended to be used when implementing handlers
13635 * for the #GtkWidget::draw function.
13637 * Returns: the width of the @widget
13640 gtk_widget_get_allocated_width (GtkWidget *widget)
13642 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13644 return widget->priv->allocation.width;
13648 * gtk_widget_get_allocated_height:
13649 * @widget: the widget to query
13651 * Returns the height that has currently been allocated to @widget.
13652 * This function is intended to be used when implementing handlers
13653 * for the #GtkWidget::draw function.
13655 * Returns: the height of the @widget
13658 gtk_widget_get_allocated_height (GtkWidget *widget)
13660 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13662 return widget->priv->allocation.height;
13666 * gtk_widget_get_requisition:
13667 * @widget: a #GtkWidget
13668 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13670 * Retrieves the widget's requisition.
13672 * This function should only be used by widget implementations in
13673 * order to figure whether the widget's requisition has actually
13674 * changed after some internal state change (so that they can call
13675 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13677 * Normally, gtk_widget_size_request() should be used.
13681 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13682 * removed, If you need to cache sizes across requests and allocations,
13683 * add an explicit cache to the widget in question instead.
13686 gtk_widget_get_requisition (GtkWidget *widget,
13687 GtkRequisition *requisition)
13689 g_return_if_fail (GTK_IS_WIDGET (widget));
13690 g_return_if_fail (requisition != NULL);
13692 gtk_widget_get_preferred_size (widget, requisition, NULL);
13696 * gtk_widget_set_window:
13697 * @widget: a #GtkWidget
13698 * @window: (transfer full): a #GdkWindow
13700 * Sets a widget's window. This function should only be used in a
13701 * widget's #GtkWidget::realize implementation. The %window passed is
13702 * usually either new window created with gdk_window_new(), or the
13703 * window of its parent widget as returned by
13704 * gtk_widget_get_parent_window().
13706 * Widgets must indicate whether they will create their own #GdkWindow
13707 * by calling gtk_widget_set_has_window(). This is usually done in the
13708 * widget's init() function.
13710 * <note><para>This function does not add any reference to @window.</para></note>
13715 gtk_widget_set_window (GtkWidget *widget,
13718 GtkWidgetPrivate *priv;
13720 g_return_if_fail (GTK_IS_WIDGET (widget));
13721 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13723 priv = widget->priv;
13725 if (priv->window != window)
13727 priv->window = window;
13729 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
13730 gdk_window_set_opacity (window,
13731 priv->norender ? 0 : priv->alpha / 255.0);
13733 g_object_notify (G_OBJECT (widget), "window");
13738 * gtk_widget_register_window:
13739 * @widget: a #GtkWidget
13740 * @window: a #GdkWindow
13742 * Registers a #GdkWindow with the widget and sets it up so that
13743 * the widget recieves events for it. Call gtk_widget_unregister_window()
13744 * when destroying the window.
13746 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13747 * this up. This is now deprecated and you should use gtk_widget_register_window()
13748 * instead. Old code will keep working as is, although some new features like
13749 * transparency might not work perfectly.
13754 gtk_widget_register_window (GtkWidget *widget,
13757 GtkWidgetPrivate *priv;
13758 gpointer user_data;
13760 g_return_if_fail (GTK_IS_WIDGET (widget));
13761 g_return_if_fail (GDK_IS_WINDOW (window));
13763 gdk_window_get_user_data (window, &user_data);
13764 g_assert (user_data == NULL);
13766 priv = widget->priv;
13768 gdk_window_set_user_data (window, widget);
13769 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13771 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
13772 gdk_window_set_opacity (window,
13773 priv->norender_children ? 0.0 : 1.0);
13777 * gtk_widget_unregister_window:
13778 * @widget: a #GtkWidget
13779 * @window: a #GdkWindow
13781 * Unregisters a #GdkWindow from the widget that was previously set up with
13782 * gtk_widget_register_window(). You need to call this when the window is
13783 * no longer used by the widget, such as when you destroy it.
13788 gtk_widget_unregister_window (GtkWidget *widget,
13791 GtkWidgetPrivate *priv;
13792 gpointer user_data;
13794 g_return_if_fail (GTK_IS_WIDGET (widget));
13795 g_return_if_fail (GDK_IS_WINDOW (window));
13797 priv = widget->priv;
13799 gdk_window_get_user_data (window, &user_data);
13800 g_assert (user_data == widget);
13801 gdk_window_set_user_data (window, NULL);
13802 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13806 * gtk_widget_get_window:
13807 * @widget: a #GtkWidget
13809 * Returns the widget's window if it is realized, %NULL otherwise
13811 * Return value: (transfer none): @widget's window.
13816 gtk_widget_get_window (GtkWidget *widget)
13818 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13820 return widget->priv->window;
13824 * gtk_widget_get_support_multidevice:
13825 * @widget: a #GtkWidget
13827 * Returns %TRUE if @widget is multiple pointer aware. See
13828 * gtk_widget_set_support_multidevice() for more information.
13830 * Returns: %TRUE if @widget is multidevice aware.
13833 gtk_widget_get_support_multidevice (GtkWidget *widget)
13835 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13837 return widget->priv->multidevice;
13841 * gtk_widget_set_support_multidevice:
13842 * @widget: a #GtkWidget
13843 * @support_multidevice: %TRUE to support input from multiple devices.
13845 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13846 * @widget will start receiving multiple, per device enter/leave events. Note
13847 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13848 * gdk_window_set_support_multidevice() will have to be called manually on them.
13853 gtk_widget_set_support_multidevice (GtkWidget *widget,
13854 gboolean support_multidevice)
13856 GtkWidgetPrivate *priv;
13858 g_return_if_fail (GTK_IS_WIDGET (widget));
13860 priv = widget->priv;
13861 priv->multidevice = (support_multidevice == TRUE);
13863 if (gtk_widget_get_realized (widget))
13864 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13867 /* There are multiple alpha related sources, the user can specify alpha
13868 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
13869 * are multiplied together to form the total alpha.
13871 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
13872 * group we directly set the opacity of widget->window. This will cause gdk to properly
13873 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
13875 * However, if the widget is not windowed,
13876 * we do the opacity handling in the ::draw marshaller for the widget. A naive
13877 * implementation of this would break for windowed widgets or descendant widgets with
13878 * windows, as these would not be handled by the ::draw signal. To handle this we set
13879 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
13880 * to make the draw signal propagate to *all* child widgets/windows.
13882 * Note: We don't make all child windows fully transparent, we stop at the first one
13883 * in each branch when propagating down the hierarchy.
13887 /* This is called when priv->alpha changes, and should
13888 * update priv->norender and GdkWindow opacity for this widget and any children that
13889 * needs changing. It is also called whenver the parent changes, the parents
13890 * norender_children state changes, or the has_window state of the widget changes.
13893 gtk_widget_propagate_alpha (GtkWidget *widget)
13895 GtkWidgetPrivate *priv = widget->priv;
13897 gboolean norender, norender_children;
13900 parent = priv->parent;
13903 /* If the parent has norender_children, propagate that here */
13904 (parent != NULL && parent->priv->norender_children);
13906 /* Windowed widget children should norender if: */
13907 norender_children =
13908 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
13909 !gtk_widget_get_has_window (widget) &&
13910 ( /* norender is set, or */
13912 /* widget has an alpha */
13916 if (gtk_widget_get_has_window (widget))
13918 if (priv->window != NULL && !gdk_window_has_native (priv->window))
13919 gdk_window_set_opacity (priv->window,
13920 norender ? 0 : priv->alpha / 255.0);
13922 else /* !has_window */
13924 for (l = priv->registered_windows; l != NULL; l = l->next)
13926 GdkWindow *w = l->data;
13927 if (!gdk_window_has_native (w))
13928 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
13932 priv->norender = norender;
13933 if (priv->norender_children != norender_children)
13935 priv->norender_children = norender_children;
13937 if (GTK_IS_CONTAINER (widget))
13938 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
13941 if (gtk_widget_get_realized (widget))
13942 gtk_widget_queue_draw (widget);
13946 gtk_widget_update_alpha (GtkWidget *widget)
13948 GtkWidgetPrivate *priv;
13952 priv = widget->priv;
13954 alpha = priv->user_alpha;
13959 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
13960 GTK_CSS_PROPERTY_OPACITY),
13962 opacity = CLAMP (opacity, 0.0, 1.0);
13963 alpha = round (priv->user_alpha * opacity);
13966 if (alpha == priv->alpha)
13969 priv->alpha = alpha;
13971 gtk_widget_propagate_alpha (widget);
13976 * gtk_widget_set_opacity:
13977 * @widget: a #GtkWidget
13978 * @opacity: desired opacity, between 0 and 1
13980 * Request the @widget to be rendered partially transparent,
13981 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
13982 * are clamped to the [0,1] range.).
13983 * This works on both toplevel widget, and child widgets, although there
13984 * are some limitations:
13986 * For toplevel widgets this depends on the capabilities of the windowing
13987 * system. On X11 this has any effect only on X screens with a compositing manager
13988 * running. See gtk_widget_is_composited(). On Windows it should work
13989 * always, although setting a window's opacity after the window has been
13990 * shown causes it to flicker once on Windows.
13992 * For child widgets it doesn't work if any affected widget has a native window, or
13993 * disables double buffering.
13998 gtk_widget_set_opacity (GtkWidget *widget,
14001 GtkWidgetPrivate *priv;
14004 g_return_if_fail (GTK_IS_WIDGET (widget));
14006 priv = widget->priv;
14008 opacity = CLAMP (opacity, 0.0, 1.0);
14010 alpha = round (opacity * 255);
14011 if (alpha == priv->user_alpha)
14014 priv->user_alpha = alpha;
14016 gtk_widget_update_alpha (widget);
14020 * gtk_widget_get_opacity:
14021 * @widget: a #GtkWidget
14023 * Fetches the requested opacity for this widget. See
14024 * gtk_widget_set_opacity().
14026 * Return value: the requested opacity for this widget.
14031 gtk_widget_get_opacity (GtkWidget *widget)
14033 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14035 return widget->priv->alpha / 255.0;
14039 _gtk_widget_set_has_focus (GtkWidget *widget,
14040 gboolean has_focus)
14042 widget->priv->has_focus = has_focus;
14045 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14047 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14051 * gtk_widget_send_focus_change:
14052 * @widget: a #GtkWidget
14053 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14055 * Sends the focus change @event to @widget
14057 * This function is not meant to be used by applications. The only time it
14058 * should be used is when it is necessary for a #GtkWidget to assign focus
14059 * to a widget that is semantically owned by the first widget even though
14060 * it's not a direct child - for instance, a search entry in a floating
14061 * window similar to the quick search in #GtkTreeView.
14063 * An example of its usage is:
14066 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14068 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14069 * fevent->focus_change.in = TRUE;
14070 * fevent->focus_change.window = gtk_widget_get_window (widget);
14071 * if (fevent->focus_change.window != NULL)
14072 * g_object_ref (fevent->focus_change.window);
14074 * gtk_widget_send_focus_change (widget, fevent);
14076 * gdk_event_free (event);
14079 * Return value: the return value from the event signal emission: %TRUE
14080 * if the event was handled, and %FALSE otherwise
14085 gtk_widget_send_focus_change (GtkWidget *widget,
14090 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14091 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14093 g_object_ref (widget);
14095 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14097 res = gtk_widget_event (widget, event);
14099 g_object_notify (G_OBJECT (widget), "has-focus");
14101 g_object_unref (widget);
14107 * gtk_widget_in_destruction:
14108 * @widget: a #GtkWidget
14110 * Returns whether the widget is currently being destroyed.
14111 * This information can sometimes be used to avoid doing
14112 * unnecessary work.
14114 * Returns: %TRUE if @widget is being destroyed
14117 gtk_widget_in_destruction (GtkWidget *widget)
14119 return widget->priv->in_destruction;
14123 _gtk_widget_get_in_reparent (GtkWidget *widget)
14125 return widget->priv->in_reparent;
14129 _gtk_widget_set_in_reparent (GtkWidget *widget,
14130 gboolean in_reparent)
14132 widget->priv->in_reparent = in_reparent;
14136 _gtk_widget_get_anchored (GtkWidget *widget)
14138 return widget->priv->anchored;
14142 _gtk_widget_set_anchored (GtkWidget *widget,
14145 widget->priv->anchored = anchored;
14149 _gtk_widget_get_shadowed (GtkWidget *widget)
14151 return widget->priv->shadowed;
14155 _gtk_widget_set_shadowed (GtkWidget *widget,
14158 widget->priv->shadowed = shadowed;
14162 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14164 return widget->priv->alloc_needed;
14168 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14169 gboolean alloc_needed)
14171 widget->priv->alloc_needed = alloc_needed;
14175 _gtk_widget_add_sizegroup (GtkWidget *widget,
14180 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14181 groups = g_slist_prepend (groups, group);
14182 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14184 widget->priv->have_size_groups = TRUE;
14188 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14193 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14194 groups = g_slist_remove (groups, group);
14195 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14197 widget->priv->have_size_groups = groups != NULL;
14201 _gtk_widget_get_sizegroups (GtkWidget *widget)
14203 if (widget->priv->have_size_groups)
14204 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14210 _gtk_widget_add_attached_window (GtkWidget *widget,
14213 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14217 _gtk_widget_remove_attached_window (GtkWidget *widget,
14220 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14224 * gtk_widget_path_append_for_widget:
14225 * @path: a widget path
14226 * @widget: the widget to append to the widget path
14228 * Appends the data from @widget to the widget hierarchy represented
14229 * by @path. This function is a shortcut for adding information from
14230 * @widget to the given @path. This includes setting the name or
14231 * adding the style classes from @widget.
14233 * Returns: the position where the data was inserted
14238 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14243 g_return_val_if_fail (path != NULL, 0);
14244 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14246 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14248 if (widget->priv->name)
14249 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14251 if (widget->priv->context)
14253 GList *classes, *l;
14255 /* Also add any persistent classes in
14256 * the style context the widget path
14258 classes = gtk_style_context_list_classes (widget->priv->context);
14260 for (l = classes; l; l = l->next)
14261 gtk_widget_path_iter_add_class (path, pos, l->data);
14263 g_list_free (classes);
14270 _gtk_widget_create_path (GtkWidget *widget)
14274 parent = widget->priv->parent;
14277 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14280 /* Widget is either toplevel or unparented, treat both
14281 * as toplevels style wise, since there are situations
14282 * where style properties might be retrieved on that
14285 GtkWidget *attach_widget = NULL;
14286 GtkWidgetPath *result;
14288 if (GTK_IS_WINDOW (widget))
14289 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14291 if (attach_widget != NULL)
14292 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14294 result = gtk_widget_path_new ();
14296 gtk_widget_path_append_for_widget (result, widget);
14303 * gtk_widget_get_path:
14304 * @widget: a #GtkWidget
14306 * Returns the #GtkWidgetPath representing @widget, if the widget
14307 * is not connected to a toplevel widget, a partial path will be
14310 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14313 gtk_widget_get_path (GtkWidget *widget)
14315 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14317 if (!widget->priv->path)
14318 widget->priv->path = _gtk_widget_create_path (widget);
14320 return widget->priv->path;
14324 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14326 if (widget->priv->path)
14328 gtk_widget_path_free (widget->priv->path);
14329 widget->priv->path = NULL;
14332 if (gtk_widget_get_realized (widget))
14333 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14336 /* Compress all style updates so it
14337 * is only emitted once pre-realize.
14339 widget->priv->style_update_pending = TRUE;
14344 * gtk_widget_get_style_context:
14345 * @widget: a #GtkWidget
14347 * Returns the style context associated to @widget.
14349 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14350 * must not be freed.
14353 gtk_widget_get_style_context (GtkWidget *widget)
14355 GtkWidgetPrivate *priv;
14357 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14359 priv = widget->priv;
14361 if (G_UNLIKELY (priv->context == NULL))
14365 priv->context = gtk_style_context_new ();
14367 gtk_style_context_set_state (priv->context, priv->state_flags);
14369 screen = gtk_widget_get_screen (widget);
14371 gtk_style_context_set_screen (priv->context, screen);
14374 gtk_style_context_set_parent (priv->context,
14375 gtk_widget_get_style_context (priv->parent));
14377 _gtk_style_context_set_widget (priv->context, widget);
14380 return widget->priv->context;
14384 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14385 GtkCssChange change)
14387 GtkWidgetPrivate *priv;
14389 priv = widget->priv;
14391 if (priv->context == NULL)
14394 _gtk_style_context_queue_invalidate (priv->context, change);
14398 * gtk_widget_get_modifier_mask:
14399 * @widget: a #GtkWidget
14400 * @intent: the use case for the modifier mask
14402 * Returns the modifier mask the @widget's windowing system backend
14403 * uses for a particular purpose.
14405 * See gdk_keymap_get_modifier_mask().
14407 * Returns: the modifier mask used for @intent.
14412 gtk_widget_get_modifier_mask (GtkWidget *widget,
14413 GdkModifierIntent intent)
14415 GdkDisplay *display;
14417 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14419 display = gtk_widget_get_display (widget);
14421 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14426 _gtk_widget_get_style (GtkWidget *widget)
14428 return widget->priv->style;
14432 _gtk_widget_set_style (GtkWidget *widget,
14435 widget->priv->style = style;
14439 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14442 GActionMuxer *parent_muxer;
14444 if (widget->priv->muxer == NULL)
14447 if (GTK_IS_MENU (widget))
14448 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14450 parent = gtk_widget_get_parent (widget);
14452 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14454 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14458 _gtk_widget_get_action_muxer (GtkWidget *widget)
14460 if (widget->priv->muxer == NULL)
14462 widget->priv->muxer = g_action_muxer_new ();
14463 _gtk_widget_update_parent_muxer (widget);
14466 return widget->priv->muxer;
14470 * gtk_widget_insert_action_group:
14471 * @widget: a #GtkWidget
14472 * @name: the prefix for actions in @group
14473 * @group: a #GActionGroup
14475 * Inserts @group into @widget. Children of @widget that implement
14476 * #GtkActionable can then be associated with actions in @group by
14477 * setting their 'action-name' to
14478 * @prefix.<replaceable>action-name</replaceable>.
14483 gtk_widget_insert_action_group (GtkWidget *widget,
14485 GActionGroup *group)
14487 GActionMuxer *muxer;
14489 g_return_if_fail (GTK_IS_WIDGET (widget));
14490 g_return_if_fail (name != NULL);
14492 muxer = _gtk_widget_get_action_muxer (widget);
14495 g_action_muxer_insert (muxer, name, group);
14497 g_action_muxer_remove (muxer, name);