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 "gtkiconfactory.h"
42 #include "gtkmarshalers.h"
43 #include "gtkselectionprivate.h"
44 #include "gtksettingsprivate.h"
45 #include "gtksizegroup-private.h"
46 #include "gtksizerequestcacheprivate.h"
47 #include "gtkwidget.h"
48 #include "gtkwidgetprivate.h"
49 #include "gtkwindowprivate.h"
50 #include "gtkcontainerprivate.h"
51 #include "gtkbindings.h"
52 #include "gtkprivate.h"
53 #include "gtkaccessible.h"
54 #include "gtktooltip.h"
55 #include "gtkinvisible.h"
56 #include "gtkbuildable.h"
57 #include "gtkbuilderprivate.h"
58 #include "gtksizerequest.h"
59 #include "gtkstylecontextprivate.h"
60 #include "gtkcssprovider.h"
61 #include "gtkmodifierstyle.h"
62 #include "gtkversion.h"
65 #include "gtktypebuiltins.h"
66 #include "a11y/gtkwidgetaccessible.h"
70 * @Short_description: Base class for all widgets
73 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
74 * widget lifecycle, states and style.
76 * <refsect2 id="geometry-management">
77 * <title>Height-for-width Geometry Management</title>
79 * GTK+ uses a height-for-width (and width-for-height) geometry management
80 * system. Height-for-width means that a widget can change how much
81 * vertical space it needs, depending on the amount of horizontal space
82 * that it is given (and similar for width-for-height). The most common
83 * example is a label that reflows to fill up the available width, wraps
84 * to fewer lines, and therefore needs less height.
86 * Height-for-width geometry management is implemented in GTK+ by way
87 * of five virtual methods:
89 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
96 * There are some important things to keep in mind when implementing
97 * height-for-width and when using it in container implementations.
99 * The geometry management system will query a widget hierarchy in
100 * only one orientation at a time. When widgets are initially queried
101 * for their minimum sizes it is generally done in two initial passes
102 * in the #GtkSizeRequestMode chosen by the toplevel.
104 * For example, when queried in the normal
105 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
106 * First, the default minimum and natural width for each widget
107 * in the interface will be computed using gtk_widget_get_preferred_width().
108 * Because the preferred widths for each container depend on the preferred
109 * widths of their children, this information propagates up the hierarchy,
110 * and finally a minimum and natural width is determined for the entire
111 * toplevel. Next, the toplevel will use the minimum width to query for the
112 * minimum height contextual to that width using
113 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
114 * recursive operation. The minimum height for the minimum width is normally
115 * used to set the minimum size constraint on the toplevel
116 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
118 * After the toplevel window has initially requested its size in both
119 * dimensions it can go on to allocate itself a reasonable size (or a size
120 * previously specified with gtk_window_set_default_size()). During the
121 * recursive allocation process it's important to note that request cycles
122 * will be recursively executed while container widgets allocate their children.
123 * Each container widget, once allocated a size, will go on to first share the
124 * space in one orientation among its children and then request each child's
125 * height for its target allocated width or its width for allocated height,
126 * depending. In this way a #GtkWidget will typically be requested its size
127 * a number of times before actually being allocated a size. The size a
128 * widget is finally allocated can of course differ from the size it has
129 * requested. For this reason, #GtkWidget caches a small number of results
130 * to avoid re-querying for the same sizes in one allocation cycle.
132 * See <link linkend="container-geometry-management">GtkContainer's
133 * geometry management section</link>
134 * to learn more about how height-for-width allocations are performed
135 * by container widgets.
137 * If a widget does move content around to intelligently use up the
138 * allocated size then it must support the request in both
139 * #GtkSizeRequestModes even if the widget in question only
140 * trades sizes in a single orientation.
142 * For instance, a #GtkLabel that does height-for-width word wrapping
143 * will not expect to have #GtkWidgetClass.get_preferred_height() called
144 * because that call is specific to a width-for-height request. In this
145 * case the label must return the height required for its own minimum
146 * possible width. By following this rule any widget that handles
147 * height-for-width or width-for-height requests will always be allocated
148 * at least enough space to fit its own content.
150 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
151 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
153 * <programlisting><![CDATA[
155 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
157 * if (i_am_in_height_for_width_mode)
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
163 * min_height, nat_height);
167 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
168 * it will return the minimum and natural height for the rotated label here.
171 * ]]></programlisting>
173 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
174 * the minimum and natural width:
176 * <programlisting><![CDATA[
178 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
179 * gint *min_width, gint *nat_width)
181 * if (i_am_in_height_for_width_mode)
183 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
187 * ... again if a widget is sometimes operating in width-for-height mode
188 * (like a rotated GtkLabel) it can go ahead and do its real width for
189 * height calculation here.
192 * ]]></programlisting>
194 * Often a widget needs to get its own request during size request or
195 * allocation. For example, when computing height it may need to also
196 * compute width. Or when deciding how to use an allocation, the widget
197 * may need to know its natural size. In these cases, the widget should
198 * be careful to call its virtual methods directly, like this:
200 * <title>Widget calling its own size request method.</title>
202 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
207 * It will not work to use the wrapper functions, such as
208 * gtk_widget_get_preferred_width() inside your own size request
209 * implementation. These return a request adjusted by #GtkSizeGroup
210 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
211 * widget used the wrappers inside its virtual method implementations,
212 * then the adjustments (such as widget margins) would be applied
213 * twice. GTK+ therefore does not allow this and will warn if you try
216 * Of course if you are getting the size request for
217 * <emphasis>another</emphasis> widget, such as a child of a
218 * container, you <emphasis>must</emphasis> use the wrapper APIs.
219 * Otherwise, you would not properly consider widget margins,
220 * #GtkSizeGroup, and so forth.
223 * <refsect2 id="style-properties">
224 * <title>Style Properties</title>
226 * <structname>GtkWidget</structname> introduces <firstterm>style
227 * properties</firstterm> - these are basically object properties that are stored
228 * not on the object, but in the style object associated to the widget. Style
229 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
230 * This mechanism is used for configuring such things as the location of the
231 * scrollbar arrows through the theme, giving theme authors more control over the
232 * look of applications without the need to write a theme engine in C.
235 * Use gtk_widget_class_install_style_property() to install style properties for
236 * a widget class, gtk_widget_class_find_style_property() or
237 * gtk_widget_class_list_style_properties() to get information about existing
238 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
239 * gtk_widget_style_get_valist() to obtain the value of a style property.
242 * <refsect2 id="GtkWidget-BUILDER-UI">
243 * <title>GtkWidget as GtkBuildable</title>
245 * The GtkWidget implementation of the GtkBuildable interface supports a
246 * custom <accelerator> element, which has attributes named key,
247 * modifiers and signal and allows to specify accelerators.
250 * <title>A UI definition fragment specifying an accelerator</title>
251 * <programlisting><![CDATA[
252 * <object class="GtkButton">
253 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
255 * ]]></programlisting>
258 * In addition to accelerators, <structname>GtkWidget</structname> also support a
259 * custom <accessible> element, which supports actions and relations.
260 * Properties on the accessible implementation of an object can be set by accessing the
261 * internal child "accessible" of a <structname>GtkWidget</structname>.
264 * <title>A UI definition fragment specifying an accessible</title>
265 * <programlisting><![CDATA[
266 * <object class="GtkButton" id="label1"/>
267 * <property name="label">I am a Label for a Button</property>
269 * <object class="GtkButton" id="button1">
271 * <action action_name="click" translatable="yes">Click the button.</action>
272 * <relation target="label1" type="labelled-by"/>
274 * <child internal-child="accessible">
275 * <object class="AtkObject" id="a11y-button1">
276 * <property name="AtkObject::name">Clickable Button</property>
280 * ]]></programlisting>
283 * Finally, GtkWidget allows style information such as style classes to
284 * be associated with widgets, using the custom <style> element:
286 * <title>A UI definition fragment specifying an style class</title>
287 * <programlisting><![CDATA[
288 * <object class="GtkButton" id="button1">
290 * <class name="my-special-button-class"/>
291 * <class name="dark-button"/>
294 * ]]></programlisting>
300 /* Add flags here that should not be propagated to children. By default,
301 * all flags will be set on children (think prelight or active), but we
302 * might want to not do this for some.
304 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
305 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
307 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
309 #define GTK_STATE_FLAGS_BITS 9
311 struct _GtkWidgetPrivate
313 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
314 * (defined in "gtkenums.h").
316 guint state_flags : GTK_STATE_FLAGS_BITS;
320 guint in_destruction : 1;
323 guint composite_child : 1;
331 guint can_default : 1;
332 guint has_default : 1;
333 guint receives_default : 1;
336 guint style_update_pending : 1;
337 guint app_paintable : 1;
338 guint double_buffered : 1;
339 guint redraw_on_alloc : 1;
340 guint no_show_all : 1;
341 guint child_visible : 1;
342 guint multidevice : 1;
343 guint has_shape_mask : 1;
344 guint in_reparent : 1;
346 /* Queue-resize related flags */
347 guint alloc_needed : 1;
349 /* Expand-related flags */
350 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
351 guint computed_hexpand : 1; /* computed results (composite of child flags) */
352 guint computed_vexpand : 1;
353 guint hexpand : 1; /* application-forced expand */
355 guint hexpand_set : 1; /* whether to use application-forced */
356 guint vexpand_set : 1; /* instead of computing from children */
358 /* SizeGroup related flags */
359 guint have_size_groups : 1;
361 guint norender_children : 1;
362 guint norender : 1; /* Don't expose windows, instead recurse via draw */
366 /* The widget's name. If the widget does not have a name
367 * (the name is NULL), then its name (as returned by
368 * "gtk_widget_get_name") is its class's name.
369 * Among other things, the widget name is used to determine
370 * the style to use for a widget.
374 /* The list of attached windows to this widget.
375 * We keep a list in order to call reset_style to all of them,
377 GList *attached_windows;
379 /* The style for the widget. The style contains the
380 * colors the widget should be drawn in for each state
381 * along with graphics contexts used to draw with and
382 * the font to use for text.
385 GtkStyleContext *context;
387 /* Widget's path for styling */
390 /* The widget's allocated size */
391 GtkAllocation allocation;
393 /* The widget's requested sizes */
394 SizeRequestCache requests;
396 /* actions attached to this or any parent widget */
399 /* The widget's window or its parent window if it does
400 * not have a window. (Which will be indicated by the
401 * GTK_NO_WINDOW flag being set).
404 GList *registered_windows;
406 /* The widget's parent */
409 #ifdef G_ENABLE_DEBUG
410 /* Number of gtk_widget_push_verify_invariants () */
411 guint verifying_invariants_count;
412 #endif /* G_ENABLE_DEBUG */
415 struct _GtkWidgetClassPrivate
417 GType accessible_type;
418 AtkRole accessible_role;
447 BUTTON_RELEASE_EVENT,
461 PROPERTY_NOTIFY_EVENT,
462 SELECTION_CLEAR_EVENT,
463 SELECTION_REQUEST_EVENT,
464 SELECTION_NOTIFY_EVENT,
469 VISIBILITY_NOTIFY_EVENT,
483 ACCEL_CLOSURES_CHANGED,
508 PROP_RECEIVES_DEFAULT,
509 PROP_COMPOSITE_CHILD,
518 PROP_DOUBLE_BUFFERED,
533 typedef struct _GtkStateData GtkStateData;
538 guint flags_to_unset;
541 /* --- prototypes --- */
542 static void gtk_widget_base_class_init (gpointer g_class);
543 static void gtk_widget_class_init (GtkWidgetClass *klass);
544 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
545 static void gtk_widget_init (GtkWidget *widget);
546 static void gtk_widget_set_property (GObject *object,
550 static void gtk_widget_get_property (GObject *object,
554 static void gtk_widget_constructed (GObject *object);
555 static void gtk_widget_dispose (GObject *object);
556 static void gtk_widget_real_destroy (GtkWidget *object);
557 static void gtk_widget_finalize (GObject *object);
558 static void gtk_widget_real_show (GtkWidget *widget);
559 static void gtk_widget_real_hide (GtkWidget *widget);
560 static void gtk_widget_real_map (GtkWidget *widget);
561 static void gtk_widget_real_unmap (GtkWidget *widget);
562 static void gtk_widget_real_realize (GtkWidget *widget);
563 static void gtk_widget_real_unrealize (GtkWidget *widget);
564 static void gtk_widget_real_size_allocate (GtkWidget *widget,
565 GtkAllocation *allocation);
566 static void gtk_widget_real_style_set (GtkWidget *widget,
567 GtkStyle *previous_style);
568 static void gtk_widget_real_direction_changed(GtkWidget *widget,
569 GtkTextDirection previous_direction);
571 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
572 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
575 gboolean keyboard_tip,
576 GtkTooltip *tooltip);
577 static void gtk_widget_real_style_updated (GtkWidget *widget);
578 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
579 GtkWidgetHelpType help_type);
581 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
583 GParamSpec **pspecs);
584 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
586 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
588 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
589 GdkEventFocus *event);
590 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
591 GdkEventFocus *event);
592 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
593 GdkEventTouch *event);
594 static gboolean gtk_widget_real_focus (GtkWidget *widget,
595 GtkDirectionType direction);
596 static void gtk_widget_real_move_focus (GtkWidget *widget,
597 GtkDirectionType direction);
598 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
599 GtkDirectionType direction);
600 #ifdef G_ENABLE_DEBUG
601 static void gtk_widget_verify_invariants (GtkWidget *widget);
602 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
603 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
605 #define gtk_widget_verify_invariants(widget)
606 #define gtk_widget_push_verify_invariants(widget)
607 #define gtk_widget_pop_verify_invariants(widget)
609 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
610 static void gtk_widget_update_pango_context (GtkWidget *widget);
611 static void gtk_widget_propagate_state (GtkWidget *widget,
614 static gint gtk_widget_event_internal (GtkWidget *widget,
616 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
617 gboolean group_cycling);
618 static void gtk_widget_real_get_width (GtkWidget *widget,
621 static void gtk_widget_real_get_height (GtkWidget *widget,
624 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
626 gint *minimum_height,
627 gint *natural_height);
628 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
631 gint *natural_width);
632 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
633 GtkStateFlags old_state);
634 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
635 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
637 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
638 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
639 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
640 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
641 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
642 cairo_region_t *region);
643 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
644 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
647 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
648 gboolean has_tooltip,
650 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
651 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
653 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
654 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
656 const gchar *childname);
657 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
660 const GValue *value);
661 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
664 const gchar *tagname,
665 GMarkupParser *parser,
667 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
670 const gchar *tagname,
672 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
673 GtkBuilder *builder);
675 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
676 static void gtk_widget_real_get_width (GtkWidget *widget,
679 static void gtk_widget_real_get_height (GtkWidget *widget,
683 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
686 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
687 GtkOrientation orientation,
690 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
691 GtkOrientation orientation,
695 gint *allocated_size);
697 static void gtk_widget_set_usize_internal (GtkWidget *widget,
700 GtkQueueResizeFlags flags);
702 static void gtk_widget_add_events_internal (GtkWidget *widget,
705 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
709 static gboolean event_window_is_still_viewable (GdkEvent *event);
710 static void gtk_cairo_set_event (cairo_t *cr,
711 GdkEventExpose *event);
712 static void gtk_widget_update_norender (GtkWidget *widget);
714 /* --- variables --- */
715 static gpointer gtk_widget_parent_class = NULL;
716 static guint widget_signals[LAST_SIGNAL] = { 0 };
717 static guint composite_child_stack = 0;
718 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
719 static GParamSpecPool *style_property_spec_pool = NULL;
721 static GQuark quark_property_parser = 0;
722 static GQuark quark_aux_info = 0;
723 static GQuark quark_accel_path = 0;
724 static GQuark quark_accel_closures = 0;
725 static GQuark quark_event_mask = 0;
726 static GQuark quark_device_event_mask = 0;
727 static GQuark quark_parent_window = 0;
728 static GQuark quark_pointer_window = 0;
729 static GQuark quark_shape_info = 0;
730 static GQuark quark_input_shape_info = 0;
731 static GQuark quark_pango_context = 0;
732 static GQuark quark_accessible_object = 0;
733 static GQuark quark_mnemonic_labels = 0;
734 static GQuark quark_tooltip_markup = 0;
735 static GQuark quark_has_tooltip = 0;
736 static GQuark quark_tooltip_window = 0;
737 static GQuark quark_visual = 0;
738 static GQuark quark_modifier_style = 0;
739 static GQuark quark_enabled_devices = 0;
740 static GQuark quark_size_groups = 0;
741 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
742 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
744 /* --- functions --- */
746 gtk_widget_get_type (void)
748 static GType widget_type = 0;
750 if (G_UNLIKELY (widget_type == 0))
752 const GTypeInfo widget_info =
754 sizeof (GtkWidgetClass),
755 gtk_widget_base_class_init,
756 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
757 (GClassInitFunc) gtk_widget_class_init,
758 NULL, /* class_finalize */
759 NULL, /* class_init */
762 (GInstanceInitFunc) gtk_widget_init,
763 NULL, /* value_table */
766 const GInterfaceInfo accessibility_info =
768 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
769 (GInterfaceFinalizeFunc) NULL,
770 NULL /* interface data */
773 const GInterfaceInfo buildable_info =
775 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
776 (GInterfaceFinalizeFunc) NULL,
777 NULL /* interface data */
780 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
781 &widget_info, G_TYPE_FLAG_ABSTRACT);
783 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
785 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
786 &accessibility_info) ;
787 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
795 gtk_widget_base_class_init (gpointer g_class)
797 GtkWidgetClass *klass = g_class;
799 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
803 child_property_notify_dispatcher (GObject *object,
807 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
810 /* We guard against the draw signal callbacks modifying the state of the
811 * cairo context by surounding it with save/restore.
812 * Maybe we should also cairo_new_path() just to be sure?
815 gtk_widget_draw_marshaller (GClosure *closure,
816 GValue *return_value,
817 guint n_param_values,
818 const GValue *param_values,
819 gpointer invocation_hint,
820 gpointer marshal_data)
822 GtkWidget *widget = g_value_get_object (¶m_values[0]);
823 GdkEventExpose *tmp_event;
825 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
828 tmp_event = _gtk_cairo_get_event (cr);
831 widget->priv->alpha != 255 &&
832 (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
836 cairo_push_group (cr);
837 gtk_cairo_set_event (cr, NULL);
840 _gtk_marshal_BOOLEAN__BOXED (closure,
850 cairo_pop_group_to_source (cr);
851 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
852 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
855 gtk_cairo_set_event (cr, tmp_event);
860 gtk_widget_draw_marshallerv (GClosure *closure,
861 GValue *return_value,
864 gpointer marshal_data,
868 GtkWidget *widget = GTK_WIDGET (instance);
869 GdkEventExpose *tmp_event;
874 G_VA_COPY (args_copy, args);
875 cr = va_arg (args_copy, gpointer);
878 tmp_event = _gtk_cairo_get_event (cr);
881 widget->priv->alpha != 255 &&
882 (!gtk_widget_get_has_window (widget) || tmp_event == NULL);
886 cairo_push_group (cr);
887 gtk_cairo_set_event (cr, NULL);
890 _gtk_marshal_BOOLEAN__BOXEDv (closure,
901 cairo_pop_group_to_source (cr);
902 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
903 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
906 gtk_cairo_set_event (cr, tmp_event);
913 gtk_widget_class_init (GtkWidgetClass *klass)
915 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
916 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
917 GtkBindingSet *binding_set;
919 gtk_widget_parent_class = g_type_class_peek_parent (klass);
921 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
922 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
923 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
924 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
925 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
926 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
927 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
928 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
929 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
930 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
931 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
932 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
933 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
934 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
935 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
936 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
937 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
938 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
939 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
940 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
942 style_property_spec_pool = g_param_spec_pool_new (FALSE);
943 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
944 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
945 cpn_context.dispatcher = child_property_notify_dispatcher;
946 _gtk_widget_child_property_notify_context = &cpn_context;
948 gobject_class->constructed = gtk_widget_constructed;
949 gobject_class->dispose = gtk_widget_dispose;
950 gobject_class->finalize = gtk_widget_finalize;
951 gobject_class->set_property = gtk_widget_set_property;
952 gobject_class->get_property = gtk_widget_get_property;
954 klass->destroy = gtk_widget_real_destroy;
956 klass->activate_signal = 0;
957 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
958 klass->show = gtk_widget_real_show;
959 klass->show_all = gtk_widget_show;
960 klass->hide = gtk_widget_real_hide;
961 klass->map = gtk_widget_real_map;
962 klass->unmap = gtk_widget_real_unmap;
963 klass->realize = gtk_widget_real_realize;
964 klass->unrealize = gtk_widget_real_unrealize;
965 klass->size_allocate = gtk_widget_real_size_allocate;
966 klass->get_request_mode = gtk_widget_real_get_request_mode;
967 klass->get_preferred_width = gtk_widget_real_get_width;
968 klass->get_preferred_height = gtk_widget_real_get_height;
969 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
970 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
971 klass->state_changed = NULL;
972 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
973 klass->parent_set = NULL;
974 klass->hierarchy_changed = NULL;
975 klass->style_set = gtk_widget_real_style_set;
976 klass->direction_changed = gtk_widget_real_direction_changed;
977 klass->grab_notify = NULL;
978 klass->child_notify = NULL;
980 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
981 klass->grab_focus = gtk_widget_real_grab_focus;
982 klass->focus = gtk_widget_real_focus;
983 klass->move_focus = gtk_widget_real_move_focus;
984 klass->keynav_failed = gtk_widget_real_keynav_failed;
986 klass->button_press_event = NULL;
987 klass->button_release_event = NULL;
988 klass->motion_notify_event = NULL;
989 klass->touch_event = gtk_widget_real_touch_event;
990 klass->delete_event = NULL;
991 klass->destroy_event = NULL;
992 klass->key_press_event = gtk_widget_real_key_press_event;
993 klass->key_release_event = gtk_widget_real_key_release_event;
994 klass->enter_notify_event = NULL;
995 klass->leave_notify_event = NULL;
996 klass->configure_event = NULL;
997 klass->focus_in_event = gtk_widget_real_focus_in_event;
998 klass->focus_out_event = gtk_widget_real_focus_out_event;
999 klass->map_event = NULL;
1000 klass->unmap_event = NULL;
1001 klass->window_state_event = NULL;
1002 klass->property_notify_event = _gtk_selection_property_notify;
1003 klass->selection_clear_event = _gtk_selection_clear;
1004 klass->selection_request_event = _gtk_selection_request;
1005 klass->selection_notify_event = _gtk_selection_notify;
1006 klass->selection_received = NULL;
1007 klass->proximity_in_event = NULL;
1008 klass->proximity_out_event = NULL;
1009 klass->drag_begin = NULL;
1010 klass->drag_end = NULL;
1011 klass->drag_data_delete = NULL;
1012 klass->drag_leave = NULL;
1013 klass->drag_motion = NULL;
1014 klass->drag_drop = NULL;
1015 klass->drag_data_received = NULL;
1016 klass->screen_changed = NULL;
1017 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1018 klass->grab_broken_event = NULL;
1019 klass->query_tooltip = gtk_widget_real_query_tooltip;
1020 klass->style_updated = gtk_widget_real_style_updated;
1022 klass->show_help = gtk_widget_real_show_help;
1024 /* Accessibility support */
1025 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1026 klass->priv->accessible_role = ATK_ROLE_INVALID;
1027 klass->get_accessible = gtk_widget_real_get_accessible;
1029 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1030 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1032 g_object_class_install_property (gobject_class,
1034 g_param_spec_string ("name",
1036 P_("The name of the widget"),
1038 GTK_PARAM_READWRITE));
1039 g_object_class_install_property (gobject_class,
1041 g_param_spec_object ("parent",
1042 P_("Parent widget"),
1043 P_("The parent widget of this widget. Must be a Container widget"),
1045 GTK_PARAM_READWRITE));
1047 g_object_class_install_property (gobject_class,
1049 g_param_spec_int ("width-request",
1050 P_("Width request"),
1051 P_("Override for width request of the widget, or -1 if natural request should be used"),
1055 GTK_PARAM_READWRITE));
1056 g_object_class_install_property (gobject_class,
1057 PROP_HEIGHT_REQUEST,
1058 g_param_spec_int ("height-request",
1059 P_("Height request"),
1060 P_("Override for height request of the widget, or -1 if natural request should be used"),
1064 GTK_PARAM_READWRITE));
1065 g_object_class_install_property (gobject_class,
1067 g_param_spec_boolean ("visible",
1069 P_("Whether the widget is visible"),
1071 GTK_PARAM_READWRITE));
1072 g_object_class_install_property (gobject_class,
1074 g_param_spec_boolean ("sensitive",
1076 P_("Whether the widget responds to input"),
1078 GTK_PARAM_READWRITE));
1079 g_object_class_install_property (gobject_class,
1081 g_param_spec_boolean ("app-paintable",
1082 P_("Application paintable"),
1083 P_("Whether the application will paint directly on the widget"),
1085 GTK_PARAM_READWRITE));
1086 g_object_class_install_property (gobject_class,
1088 g_param_spec_boolean ("can-focus",
1090 P_("Whether the widget can accept the input focus"),
1092 GTK_PARAM_READWRITE));
1093 g_object_class_install_property (gobject_class,
1095 g_param_spec_boolean ("has-focus",
1097 P_("Whether the widget has the input focus"),
1099 GTK_PARAM_READWRITE));
1100 g_object_class_install_property (gobject_class,
1102 g_param_spec_boolean ("is-focus",
1104 P_("Whether the widget is the focus widget within the toplevel"),
1106 GTK_PARAM_READWRITE));
1107 g_object_class_install_property (gobject_class,
1109 g_param_spec_boolean ("can-default",
1111 P_("Whether the widget can be the default widget"),
1113 GTK_PARAM_READWRITE));
1114 g_object_class_install_property (gobject_class,
1116 g_param_spec_boolean ("has-default",
1118 P_("Whether the widget is the default widget"),
1120 GTK_PARAM_READWRITE));
1121 g_object_class_install_property (gobject_class,
1122 PROP_RECEIVES_DEFAULT,
1123 g_param_spec_boolean ("receives-default",
1124 P_("Receives default"),
1125 P_("If TRUE, the widget will receive the default action when it is focused"),
1127 GTK_PARAM_READWRITE));
1128 g_object_class_install_property (gobject_class,
1129 PROP_COMPOSITE_CHILD,
1130 g_param_spec_boolean ("composite-child",
1131 P_("Composite child"),
1132 P_("Whether the widget is part of a composite widget"),
1134 GTK_PARAM_READABLE));
1135 g_object_class_install_property (gobject_class,
1137 g_param_spec_object ("style",
1139 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1141 GTK_PARAM_READWRITE));
1142 g_object_class_install_property (gobject_class,
1144 g_param_spec_flags ("events",
1146 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1147 GDK_TYPE_EVENT_MASK,
1149 GTK_PARAM_READWRITE));
1150 g_object_class_install_property (gobject_class,
1152 g_param_spec_boolean ("no-show-all",
1154 P_("Whether gtk_widget_show_all() should not affect this widget"),
1156 GTK_PARAM_READWRITE));
1159 * GtkWidget:has-tooltip:
1161 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1162 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1163 * the widget will be queried using #GtkWidget::query-tooltip to determine
1164 * whether it will provide a tooltip or not.
1166 * Note that setting this property to %TRUE for the first time will change
1167 * the event masks of the GdkWindows of this widget to include leave-notify
1168 * and motion-notify events. This cannot and will not be undone when the
1169 * property is set to %FALSE again.
1173 g_object_class_install_property (gobject_class,
1175 g_param_spec_boolean ("has-tooltip",
1177 P_("Whether this widget has a tooltip"),
1179 GTK_PARAM_READWRITE));
1181 * GtkWidget:tooltip-text:
1183 * Sets the text of tooltip to be the given string.
1185 * Also see gtk_tooltip_set_text().
1187 * This is a convenience property which will take care of getting the
1188 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1189 * will automatically be set to %TRUE and there will be taken care of
1190 * #GtkWidget::query-tooltip in the default signal handler.
1194 g_object_class_install_property (gobject_class,
1196 g_param_spec_string ("tooltip-text",
1198 P_("The contents of the tooltip for this widget"),
1200 GTK_PARAM_READWRITE));
1202 * GtkWidget:tooltip-markup:
1204 * Sets the text of tooltip to be the given string, which is marked up
1205 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1206 * Also see gtk_tooltip_set_markup().
1208 * This is a convenience property which will take care of getting the
1209 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1210 * will automatically be set to %TRUE and there will be taken care of
1211 * #GtkWidget::query-tooltip in the default signal handler.
1215 g_object_class_install_property (gobject_class,
1216 PROP_TOOLTIP_MARKUP,
1217 g_param_spec_string ("tooltip-markup",
1218 P_("Tooltip markup"),
1219 P_("The contents of the tooltip for this widget"),
1221 GTK_PARAM_READWRITE));
1226 * The widget's window if it is realized, %NULL otherwise.
1230 g_object_class_install_property (gobject_class,
1232 g_param_spec_object ("window",
1234 P_("The widget's window if it is realized"),
1236 GTK_PARAM_READABLE));
1239 * GtkWidget:double-buffered:
1241 * Whether the widget is double buffered.
1245 g_object_class_install_property (gobject_class,
1246 PROP_DOUBLE_BUFFERED,
1247 g_param_spec_boolean ("double-buffered",
1248 P_("Double Buffered"),
1249 P_("Whether the widget is double buffered"),
1251 GTK_PARAM_READWRITE));
1256 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1260 g_object_class_install_property (gobject_class,
1262 g_param_spec_enum ("halign",
1263 P_("Horizontal Alignment"),
1264 P_("How to position in extra horizontal space"),
1267 GTK_PARAM_READWRITE));
1272 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1276 g_object_class_install_property (gobject_class,
1278 g_param_spec_enum ("valign",
1279 P_("Vertical Alignment"),
1280 P_("How to position in extra vertical space"),
1283 GTK_PARAM_READWRITE));
1286 * GtkWidget:margin-left:
1288 * Margin on left side of widget.
1290 * This property adds margin outside of the widget's normal size
1291 * request, the margin will be added in addition to the size from
1292 * gtk_widget_set_size_request() for example.
1296 g_object_class_install_property (gobject_class,
1298 g_param_spec_int ("margin-left",
1299 P_("Margin on Left"),
1300 P_("Pixels of extra space on the left side"),
1304 GTK_PARAM_READWRITE));
1307 * GtkWidget:margin-right:
1309 * Margin on right side of widget.
1311 * This property adds margin outside of the widget's normal size
1312 * request, the margin will be added in addition to the size from
1313 * gtk_widget_set_size_request() for example.
1317 g_object_class_install_property (gobject_class,
1319 g_param_spec_int ("margin-right",
1320 P_("Margin on Right"),
1321 P_("Pixels of extra space on the right side"),
1325 GTK_PARAM_READWRITE));
1328 * GtkWidget:margin-top:
1330 * Margin on top side of widget.
1332 * This property adds margin outside of the widget's normal size
1333 * request, the margin will be added in addition to the size from
1334 * gtk_widget_set_size_request() for example.
1338 g_object_class_install_property (gobject_class,
1340 g_param_spec_int ("margin-top",
1341 P_("Margin on Top"),
1342 P_("Pixels of extra space on the top side"),
1346 GTK_PARAM_READWRITE));
1349 * GtkWidget:margin-bottom:
1351 * Margin on bottom side of widget.
1353 * This property adds margin outside of the widget's normal size
1354 * request, the margin will be added in addition to the size from
1355 * gtk_widget_set_size_request() for example.
1359 g_object_class_install_property (gobject_class,
1361 g_param_spec_int ("margin-bottom",
1362 P_("Margin on Bottom"),
1363 P_("Pixels of extra space on the bottom side"),
1367 GTK_PARAM_READWRITE));
1372 * Sets all four sides' margin at once. If read, returns max
1373 * margin on any side.
1377 g_object_class_install_property (gobject_class,
1379 g_param_spec_int ("margin",
1381 P_("Pixels of extra space on all four sides"),
1385 GTK_PARAM_READWRITE));
1388 * GtkWidget::destroy:
1389 * @object: the object which received the signal
1391 * Signals that all holders of a reference to the widget should release
1392 * the reference that they hold. May result in finalization of the widget
1393 * if all references are released.
1395 widget_signals[DESTROY] =
1396 g_signal_new (I_("destroy"),
1397 G_TYPE_FROM_CLASS (gobject_class),
1398 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1399 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1401 _gtk_marshal_VOID__VOID,
1405 * GtkWidget:hexpand:
1407 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1411 g_object_class_install_property (gobject_class,
1413 g_param_spec_boolean ("hexpand",
1414 P_("Horizontal Expand"),
1415 P_("Whether widget wants more horizontal space"),
1417 GTK_PARAM_READWRITE));
1420 * GtkWidget:hexpand-set:
1422 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1426 g_object_class_install_property (gobject_class,
1428 g_param_spec_boolean ("hexpand-set",
1429 P_("Horizontal Expand Set"),
1430 P_("Whether to use the hexpand property"),
1432 GTK_PARAM_READWRITE));
1435 * GtkWidget:vexpand:
1437 * Whether to expand vertically. See gtk_widget_set_vexpand().
1441 g_object_class_install_property (gobject_class,
1443 g_param_spec_boolean ("vexpand",
1444 P_("Vertical Expand"),
1445 P_("Whether widget wants more vertical space"),
1447 GTK_PARAM_READWRITE));
1450 * GtkWidget:vexpand-set:
1452 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1456 g_object_class_install_property (gobject_class,
1458 g_param_spec_boolean ("vexpand-set",
1459 P_("Vertical Expand Set"),
1460 P_("Whether to use the vexpand property"),
1462 GTK_PARAM_READWRITE));
1467 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1471 g_object_class_install_property (gobject_class,
1473 g_param_spec_boolean ("expand",
1475 P_("Whether widget wants to expand in both directions"),
1477 GTK_PARAM_READWRITE));
1480 * GtkWidget:opacity:
1482 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1483 * more details about window opacity.
1485 * Before 3.8 this was only availible in GtkWindow
1489 g_object_class_install_property (gobject_class,
1491 g_param_spec_double ("opacity",
1492 P_("Opacity for Widget"),
1493 P_("The opacity of the widget, from 0 to 1"),
1497 GTK_PARAM_READWRITE));
1500 * @widget: the object which received the signal.
1502 widget_signals[SHOW] =
1503 g_signal_new (I_("show"),
1504 G_TYPE_FROM_CLASS (gobject_class),
1506 G_STRUCT_OFFSET (GtkWidgetClass, show),
1508 _gtk_marshal_VOID__VOID,
1513 * @widget: the object which received the signal.
1515 widget_signals[HIDE] =
1516 g_signal_new (I_("hide"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1519 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1521 _gtk_marshal_VOID__VOID,
1526 * @widget: the object which received the signal.
1528 widget_signals[MAP] =
1529 g_signal_new (I_("map"),
1530 G_TYPE_FROM_CLASS (gobject_class),
1532 G_STRUCT_OFFSET (GtkWidgetClass, map),
1534 _gtk_marshal_VOID__VOID,
1539 * @widget: the object which received the signal.
1541 widget_signals[UNMAP] =
1542 g_signal_new (I_("unmap"),
1543 G_TYPE_FROM_CLASS (gobject_class),
1545 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1547 _gtk_marshal_VOID__VOID,
1551 * GtkWidget::realize:
1552 * @widget: the object which received the signal.
1554 widget_signals[REALIZE] =
1555 g_signal_new (I_("realize"),
1556 G_TYPE_FROM_CLASS (gobject_class),
1558 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1560 _gtk_marshal_VOID__VOID,
1564 * GtkWidget::unrealize:
1565 * @widget: the object which received the signal.
1567 widget_signals[UNREALIZE] =
1568 g_signal_new (I_("unrealize"),
1569 G_TYPE_FROM_CLASS (gobject_class),
1571 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1573 _gtk_marshal_VOID__VOID,
1577 * GtkWidget::size-allocate:
1578 * @widget: the object which received the signal.
1581 widget_signals[SIZE_ALLOCATE] =
1582 g_signal_new (I_("size-allocate"),
1583 G_TYPE_FROM_CLASS (gobject_class),
1585 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1587 _gtk_marshal_VOID__BOXED,
1589 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1592 * GtkWidget::state-changed:
1593 * @widget: the object which received the signal.
1594 * @state: the previous state
1596 * The ::state-changed signal is emitted when the widget state changes.
1597 * See gtk_widget_get_state().
1599 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1601 widget_signals[STATE_CHANGED] =
1602 g_signal_new (I_("state-changed"),
1603 G_TYPE_FROM_CLASS (gobject_class),
1605 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1607 _gtk_marshal_VOID__ENUM,
1609 GTK_TYPE_STATE_TYPE);
1612 * GtkWidget::state-flags-changed:
1613 * @widget: the object which received the signal.
1614 * @flags: The previous state flags.
1616 * The ::state-flags-changed signal is emitted when the widget state
1617 * changes, see gtk_widget_get_state_flags().
1621 widget_signals[STATE_FLAGS_CHANGED] =
1622 g_signal_new (I_("state-flags-changed"),
1623 G_TYPE_FROM_CLASS (gobject_class),
1625 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1627 _gtk_marshal_VOID__FLAGS,
1629 GTK_TYPE_STATE_FLAGS);
1632 * GtkWidget::parent-set:
1633 * @widget: the object on which the signal is emitted
1634 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1635 * just got its initial parent.
1637 * The ::parent-set signal is emitted when a new parent
1638 * has been set on a widget.
1640 widget_signals[PARENT_SET] =
1641 g_signal_new (I_("parent-set"),
1642 G_TYPE_FROM_CLASS (gobject_class),
1644 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1646 _gtk_marshal_VOID__OBJECT,
1651 * GtkWidget::hierarchy-changed:
1652 * @widget: the object on which the signal is emitted
1653 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1654 * if the widget was previously unanchored
1656 * The ::hierarchy-changed signal is emitted when the
1657 * anchored state of a widget changes. A widget is
1658 * <firstterm>anchored</firstterm> when its toplevel
1659 * ancestor is a #GtkWindow. This signal is emitted when
1660 * a widget changes from un-anchored to anchored or vice-versa.
1662 widget_signals[HIERARCHY_CHANGED] =
1663 g_signal_new (I_("hierarchy-changed"),
1664 G_TYPE_FROM_CLASS (gobject_class),
1666 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1668 _gtk_marshal_VOID__OBJECT,
1673 * GtkWidget::style-set:
1674 * @widget: the object on which the signal is emitted
1675 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1676 * just got its initial style
1678 * The ::style-set signal is emitted when a new style has been set
1679 * on a widget. Note that style-modifying functions like
1680 * gtk_widget_modify_base() also cause this signal to be emitted.
1682 * Note that this signal is emitted for changes to the deprecated
1683 * #GtkStyle. To track changes to the #GtkStyleContext associated
1684 * with a widget, use the #GtkWidget::style-updated signal.
1686 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1688 widget_signals[STYLE_SET] =
1689 g_signal_new (I_("style-set"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1692 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1694 _gtk_marshal_VOID__OBJECT,
1699 * GtkWidget::style-updated:
1700 * @widget: the object on which the signal is emitted
1702 * The ::style-updated signal is emitted when the #GtkStyleContext
1703 * of a widget is changed. Note that style-modifying functions like
1704 * gtk_widget_override_color() also cause this signal to be emitted.
1708 widget_signals[STYLE_UPDATED] =
1709 g_signal_new (I_("style-updated"),
1710 G_TYPE_FROM_CLASS (gobject_class),
1712 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1714 g_cclosure_marshal_VOID__VOID,
1718 * GtkWidget::direction-changed:
1719 * @widget: the object on which the signal is emitted
1720 * @previous_direction: the previous text direction of @widget
1722 * The ::direction-changed signal is emitted when the text direction
1723 * of a widget changes.
1725 widget_signals[DIRECTION_CHANGED] =
1726 g_signal_new (I_("direction-changed"),
1727 G_TYPE_FROM_CLASS (gobject_class),
1729 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1731 _gtk_marshal_VOID__ENUM,
1733 GTK_TYPE_TEXT_DIRECTION);
1736 * GtkWidget::grab-notify:
1737 * @widget: the object which received the signal
1738 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1739 * if it becomes unshadowed
1741 * The ::grab-notify signal is emitted when a widget becomes
1742 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1743 * another widget, or when it becomes unshadowed due to a grab
1746 * A widget is shadowed by a gtk_grab_add() when the topmost
1747 * grab widget in the grab stack of its window group is not
1750 widget_signals[GRAB_NOTIFY] =
1751 g_signal_new (I_("grab-notify"),
1752 G_TYPE_FROM_CLASS (gobject_class),
1754 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1756 _gtk_marshal_VOID__BOOLEAN,
1761 * GtkWidget::child-notify:
1762 * @widget: the object which received the signal
1763 * @child_property: the #GParamSpec of the changed child property
1765 * The ::child-notify signal is emitted for each
1766 * <link linkend="child-properties">child property</link> that has
1767 * changed on an object. The signal's detail holds the property name.
1769 widget_signals[CHILD_NOTIFY] =
1770 g_signal_new (I_("child-notify"),
1771 G_TYPE_FROM_CLASS (gobject_class),
1772 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1773 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1775 g_cclosure_marshal_VOID__PARAM,
1781 * @widget: the object which received the signal
1782 * @cr: the cairo context to draw to
1784 * This signal is emitted when a widget is supposed to render itself.
1785 * The @widget's top left corner must be painted at the origin of
1786 * the passed in context and be sized to the values returned by
1787 * gtk_widget_get_allocated_width() and
1788 * gtk_widget_get_allocated_height().
1790 * Signal handlers connected to this signal can modify the cairo
1791 * context passed as @cr in any way they like and don't need to
1792 * restore it. The signal emission takes care of calling cairo_save()
1793 * before and cairo_restore() after invoking the handler.
1795 * Returns: %TRUE to stop other handlers from being invoked for the event.
1796 % %FALSE to propagate the event further.
1800 widget_signals[DRAW] =
1801 g_signal_new (I_("draw"),
1802 G_TYPE_FROM_CLASS (gobject_class),
1804 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1805 _gtk_boolean_handled_accumulator, NULL,
1806 gtk_widget_draw_marshaller,
1808 CAIRO_GOBJECT_TYPE_CONTEXT);
1809 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1810 gtk_widget_draw_marshallerv);
1813 * GtkWidget::mnemonic-activate:
1814 * @widget: the object which received the signal.
1817 * Returns: %TRUE to stop other handlers from being invoked for the event.
1818 * %FALSE to propagate the event further.
1820 widget_signals[MNEMONIC_ACTIVATE] =
1821 g_signal_new (I_("mnemonic-activate"),
1822 G_TYPE_FROM_CLASS (gobject_class),
1824 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1825 _gtk_boolean_handled_accumulator, NULL,
1826 _gtk_marshal_BOOLEAN__BOOLEAN,
1831 * GtkWidget::grab-focus:
1832 * @widget: the object which received the signal.
1834 widget_signals[GRAB_FOCUS] =
1835 g_signal_new (I_("grab-focus"),
1836 G_TYPE_FROM_CLASS (gobject_class),
1837 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1838 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1840 _gtk_marshal_VOID__VOID,
1845 * @widget: the object which received the signal.
1848 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1850 widget_signals[FOCUS] =
1851 g_signal_new (I_("focus"),
1852 G_TYPE_FROM_CLASS (klass),
1854 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1855 _gtk_boolean_handled_accumulator, NULL,
1856 _gtk_marshal_BOOLEAN__ENUM,
1858 GTK_TYPE_DIRECTION_TYPE);
1861 * GtkWidget::move-focus:
1862 * @widget: the object which received the signal.
1865 widget_signals[MOVE_FOCUS] =
1866 g_signal_new (I_("move-focus"),
1867 G_TYPE_FROM_CLASS (klass),
1868 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1869 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1871 _gtk_marshal_VOID__ENUM,
1874 GTK_TYPE_DIRECTION_TYPE);
1877 * GtkWidget::keynav-failed:
1878 * @widget: the object which received the signal
1879 * @direction: the direction of movement
1881 * Gets emitted if keyboard navigation fails.
1882 * See gtk_widget_keynav_failed() for details.
1884 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1885 * if the emitting widget should try to handle the keyboard
1886 * navigation attempt in its parent container(s).
1890 widget_signals[KEYNAV_FAILED] =
1891 g_signal_new (I_("keynav-failed"),
1892 G_TYPE_FROM_CLASS (klass),
1894 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1895 _gtk_boolean_handled_accumulator, NULL,
1896 _gtk_marshal_BOOLEAN__ENUM,
1898 GTK_TYPE_DIRECTION_TYPE);
1902 * @widget: the object which received the signal.
1903 * @event: the #GdkEvent which triggered this signal
1905 * The GTK+ main loop will emit three signals for each GDK event delivered
1906 * to a widget: one generic ::event signal, another, more specific,
1907 * signal that matches the type of event delivered (e.g.
1908 * #GtkWidget::key-press-event) and finally a generic
1909 * #GtkWidget::event-after signal.
1911 * Returns: %TRUE to stop other handlers from being invoked for the event
1912 * and to cancel the emission of the second specific ::event signal.
1913 * %FALSE to propagate the event further and to allow the emission of
1914 * the second signal. The ::event-after signal is emitted regardless of
1917 widget_signals[EVENT] =
1918 g_signal_new (I_("event"),
1919 G_TYPE_FROM_CLASS (klass),
1921 G_STRUCT_OFFSET (GtkWidgetClass, event),
1922 _gtk_boolean_handled_accumulator, NULL,
1923 _gtk_marshal_BOOLEAN__BOXED,
1925 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1926 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1927 _gtk_marshal_BOOLEAN__BOXEDv);
1930 * GtkWidget::event-after:
1931 * @widget: the object which received the signal.
1932 * @event: the #GdkEvent which triggered this signal
1934 * After the emission of the #GtkWidget::event signal and (optionally)
1935 * the second more specific signal, ::event-after will be emitted
1936 * regardless of the previous two signals handlers return values.
1939 widget_signals[EVENT_AFTER] =
1940 g_signal_new (I_("event-after"),
1941 G_TYPE_FROM_CLASS (klass),
1945 _gtk_marshal_VOID__BOXED,
1947 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1948 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1949 _gtk_marshal_BOOLEAN__BOXEDv);
1952 * GtkWidget::button-press-event:
1953 * @widget: the object which received the signal.
1954 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1957 * The ::button-press-event signal will be emitted when a button
1958 * (typically from a mouse) is pressed.
1960 * To receive this signal, the #GdkWindow associated to the
1961 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1963 * This signal will be sent to the grab widget if there is one.
1965 * Returns: %TRUE to stop other handlers from being invoked for the event.
1966 * %FALSE to propagate the event further.
1968 widget_signals[BUTTON_PRESS_EVENT] =
1969 g_signal_new (I_("button-press-event"),
1970 G_TYPE_FROM_CLASS (klass),
1972 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1973 _gtk_boolean_handled_accumulator, NULL,
1974 _gtk_marshal_BOOLEAN__BOXED,
1976 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1977 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1978 _gtk_marshal_BOOLEAN__BOXEDv);
1981 * GtkWidget::button-release-event:
1982 * @widget: the object which received the signal.
1983 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1986 * The ::button-release-event signal will be emitted when a button
1987 * (typically from a mouse) is released.
1989 * To receive this signal, the #GdkWindow associated to the
1990 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1992 * This signal will be sent to the grab widget if there is one.
1994 * Returns: %TRUE to stop other handlers from being invoked for the event.
1995 * %FALSE to propagate the event further.
1997 widget_signals[BUTTON_RELEASE_EVENT] =
1998 g_signal_new (I_("button-release-event"),
1999 G_TYPE_FROM_CLASS (klass),
2001 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2002 _gtk_boolean_handled_accumulator, NULL,
2003 _gtk_marshal_BOOLEAN__BOXED,
2005 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2006 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2007 _gtk_marshal_BOOLEAN__BOXEDv);
2009 widget_signals[TOUCH_EVENT] =
2010 g_signal_new (I_("touch-event"),
2011 G_TYPE_FROM_CLASS (klass),
2013 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2014 _gtk_boolean_handled_accumulator, NULL,
2015 _gtk_marshal_BOOLEAN__BOXED,
2017 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2018 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2019 _gtk_marshal_BOOLEAN__BOXEDv);
2022 * GtkWidget::scroll-event:
2023 * @widget: the object which received the signal.
2024 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2027 * The ::scroll-event signal is emitted when a button in the 4 to 7
2028 * range is pressed. Wheel mice are usually configured to generate
2029 * button press events for buttons 4 and 5 when the wheel is turned.
2031 * To receive this signal, the #GdkWindow associated to the widget needs
2032 * to enable the #GDK_SCROLL_MASK mask.
2034 * This signal will be sent to the grab widget if there is one.
2036 * Returns: %TRUE to stop other handlers from being invoked for the event.
2037 * %FALSE to propagate the event further.
2039 widget_signals[SCROLL_EVENT] =
2040 g_signal_new (I_("scroll-event"),
2041 G_TYPE_FROM_CLASS (klass),
2043 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2044 _gtk_boolean_handled_accumulator, NULL,
2045 _gtk_marshal_BOOLEAN__BOXED,
2047 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2048 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2049 _gtk_marshal_BOOLEAN__BOXEDv);
2052 * GtkWidget::motion-notify-event:
2053 * @widget: the object which received the signal.
2054 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2057 * The ::motion-notify-event signal is emitted when the pointer moves
2058 * over the widget's #GdkWindow.
2060 * To receive this signal, the #GdkWindow associated to the widget
2061 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2063 * This signal will be sent to the grab widget if there is one.
2065 * Returns: %TRUE to stop other handlers from being invoked for the event.
2066 * %FALSE to propagate the event further.
2068 widget_signals[MOTION_NOTIFY_EVENT] =
2069 g_signal_new (I_("motion-notify-event"),
2070 G_TYPE_FROM_CLASS (klass),
2072 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2073 _gtk_boolean_handled_accumulator, NULL,
2074 _gtk_marshal_BOOLEAN__BOXED,
2076 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2077 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2078 _gtk_marshal_BOOLEAN__BOXEDv);
2081 * GtkWidget::composited-changed:
2082 * @widget: the object on which the signal is emitted
2084 * The ::composited-changed signal is emitted when the composited
2085 * status of @widget<!-- -->s screen changes.
2086 * See gdk_screen_is_composited().
2088 widget_signals[COMPOSITED_CHANGED] =
2089 g_signal_new (I_("composited-changed"),
2090 G_TYPE_FROM_CLASS (klass),
2091 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2092 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2094 _gtk_marshal_VOID__VOID,
2098 * GtkWidget::delete-event:
2099 * @widget: the object which received the signal
2100 * @event: the event which triggered this signal
2102 * The ::delete-event signal is emitted if a user requests that
2103 * a toplevel window is closed. The default handler for this signal
2104 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2105 * this signal will cause the window to be hidden instead, so that
2106 * it can later be shown again without reconstructing it.
2108 * Returns: %TRUE to stop other handlers from being invoked for the event.
2109 * %FALSE to propagate the event further.
2111 widget_signals[DELETE_EVENT] =
2112 g_signal_new (I_("delete-event"),
2113 G_TYPE_FROM_CLASS (klass),
2115 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2116 _gtk_boolean_handled_accumulator, NULL,
2117 _gtk_marshal_BOOLEAN__BOXED,
2119 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2120 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2121 _gtk_marshal_BOOLEAN__BOXEDv);
2124 * GtkWidget::destroy-event:
2125 * @widget: the object which received the signal.
2126 * @event: the event which triggered this signal
2128 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2129 * You rarely get this signal, because most widgets disconnect themselves
2130 * from their window before they destroy it, so no widget owns the
2131 * window at destroy time.
2133 * To receive this signal, the #GdkWindow associated to the widget needs
2134 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2135 * automatically for all new windows.
2137 * Returns: %TRUE to stop other handlers from being invoked for the event.
2138 * %FALSE to propagate the event further.
2140 widget_signals[DESTROY_EVENT] =
2141 g_signal_new (I_("destroy-event"),
2142 G_TYPE_FROM_CLASS (klass),
2144 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2145 _gtk_boolean_handled_accumulator, NULL,
2146 _gtk_marshal_BOOLEAN__BOXED,
2148 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2149 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2150 _gtk_marshal_BOOLEAN__BOXEDv);
2153 * GtkWidget::key-press-event:
2154 * @widget: the object which received the signal
2155 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2157 * The ::key-press-event signal is emitted when a key is pressed. The signal
2158 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2160 * To receive this signal, the #GdkWindow associated to the widget needs
2161 * to enable the #GDK_KEY_PRESS_MASK mask.
2163 * This signal will be sent to the grab widget if there is one.
2165 * Returns: %TRUE to stop other handlers from being invoked for the event.
2166 * %FALSE to propagate the event further.
2168 widget_signals[KEY_PRESS_EVENT] =
2169 g_signal_new (I_("key-press-event"),
2170 G_TYPE_FROM_CLASS (klass),
2172 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2173 _gtk_boolean_handled_accumulator, NULL,
2174 _gtk_marshal_BOOLEAN__BOXED,
2176 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2177 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2178 _gtk_marshal_BOOLEAN__BOXEDv);
2181 * GtkWidget::key-release-event:
2182 * @widget: the object which received the signal
2183 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2185 * The ::key-release-event signal is emitted when a key is released.
2187 * To receive this signal, the #GdkWindow associated to the widget needs
2188 * to enable the #GDK_KEY_RELEASE_MASK mask.
2190 * This signal will be sent to the grab widget if there is one.
2192 * Returns: %TRUE to stop other handlers from being invoked for the event.
2193 * %FALSE to propagate the event further.
2195 widget_signals[KEY_RELEASE_EVENT] =
2196 g_signal_new (I_("key-release-event"),
2197 G_TYPE_FROM_CLASS (klass),
2199 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2200 _gtk_boolean_handled_accumulator, NULL,
2201 _gtk_marshal_BOOLEAN__BOXED,
2203 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2204 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2205 _gtk_marshal_BOOLEAN__BOXEDv);
2208 * GtkWidget::enter-notify-event:
2209 * @widget: the object which received the signal
2210 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2213 * The ::enter-notify-event will be emitted when the pointer enters
2214 * the @widget's window.
2216 * To receive this signal, the #GdkWindow associated to the widget needs
2217 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2219 * This signal will be sent to the grab widget if there is one.
2221 * Returns: %TRUE to stop other handlers from being invoked for the event.
2222 * %FALSE to propagate the event further.
2224 widget_signals[ENTER_NOTIFY_EVENT] =
2225 g_signal_new (I_("enter-notify-event"),
2226 G_TYPE_FROM_CLASS (klass),
2228 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2229 _gtk_boolean_handled_accumulator, NULL,
2230 _gtk_marshal_BOOLEAN__BOXED,
2232 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2233 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2234 _gtk_marshal_BOOLEAN__BOXEDv);
2237 * GtkWidget::leave-notify-event:
2238 * @widget: the object which received the signal
2239 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2242 * The ::leave-notify-event will be emitted when the pointer leaves
2243 * the @widget's window.
2245 * To receive this signal, the #GdkWindow associated to the widget needs
2246 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2248 * This signal will be sent to the grab widget if there is one.
2250 * Returns: %TRUE to stop other handlers from being invoked for the event.
2251 * %FALSE to propagate the event further.
2253 widget_signals[LEAVE_NOTIFY_EVENT] =
2254 g_signal_new (I_("leave-notify-event"),
2255 G_TYPE_FROM_CLASS (klass),
2257 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2258 _gtk_boolean_handled_accumulator, NULL,
2259 _gtk_marshal_BOOLEAN__BOXED,
2261 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2262 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2263 _gtk_marshal_BOOLEAN__BOXEDv);
2266 * GtkWidget::configure-event:
2267 * @widget: the object which received the signal
2268 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2271 * The ::configure-event signal will be emitted when the size, position or
2272 * stacking of the @widget's window has changed.
2274 * To receive this signal, the #GdkWindow associated to the widget needs
2275 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2276 * automatically for all new windows.
2278 * Returns: %TRUE to stop other handlers from being invoked for the event.
2279 * %FALSE to propagate the event further.
2281 widget_signals[CONFIGURE_EVENT] =
2282 g_signal_new (I_("configure-event"),
2283 G_TYPE_FROM_CLASS (klass),
2285 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2286 _gtk_boolean_handled_accumulator, NULL,
2287 _gtk_marshal_BOOLEAN__BOXED,
2289 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2290 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2291 _gtk_marshal_BOOLEAN__BOXEDv);
2294 * GtkWidget::focus-in-event:
2295 * @widget: the object which received the signal
2296 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2299 * The ::focus-in-event signal will be emitted when the keyboard focus
2300 * enters the @widget's window.
2302 * To receive this signal, the #GdkWindow associated to the widget needs
2303 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2305 * Returns: %TRUE to stop other handlers from being invoked for the event.
2306 * %FALSE to propagate the event further.
2308 widget_signals[FOCUS_IN_EVENT] =
2309 g_signal_new (I_("focus-in-event"),
2310 G_TYPE_FROM_CLASS (klass),
2312 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2313 _gtk_boolean_handled_accumulator, NULL,
2314 _gtk_marshal_BOOLEAN__BOXED,
2316 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2317 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2318 _gtk_marshal_BOOLEAN__BOXEDv);
2321 * GtkWidget::focus-out-event:
2322 * @widget: the object which received the signal
2323 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2326 * The ::focus-out-event signal will be emitted when the keyboard focus
2327 * leaves the @widget's window.
2329 * To receive this signal, the #GdkWindow associated to the widget needs
2330 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2332 * Returns: %TRUE to stop other handlers from being invoked for the event.
2333 * %FALSE to propagate the event further.
2335 widget_signals[FOCUS_OUT_EVENT] =
2336 g_signal_new (I_("focus-out-event"),
2337 G_TYPE_FROM_CLASS (klass),
2339 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2340 _gtk_boolean_handled_accumulator, NULL,
2341 _gtk_marshal_BOOLEAN__BOXED,
2343 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2344 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2345 _gtk_marshal_BOOLEAN__BOXEDv);
2348 * GtkWidget::map-event:
2349 * @widget: the object which received the signal
2350 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2352 * The ::map-event signal will be emitted when the @widget's window is
2353 * mapped. A window is mapped when it becomes visible on the screen.
2355 * To receive this signal, the #GdkWindow associated to the widget needs
2356 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2357 * automatically for all new windows.
2359 * Returns: %TRUE to stop other handlers from being invoked for the event.
2360 * %FALSE to propagate the event further.
2362 widget_signals[MAP_EVENT] =
2363 g_signal_new (I_("map-event"),
2364 G_TYPE_FROM_CLASS (klass),
2366 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2367 _gtk_boolean_handled_accumulator, NULL,
2368 _gtk_marshal_BOOLEAN__BOXED,
2370 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2371 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2372 _gtk_marshal_BOOLEAN__BOXEDv);
2375 * GtkWidget::unmap-event:
2376 * @widget: the object which received the signal
2377 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2379 * The ::unmap-event signal will be emitted when the @widget's window is
2380 * unmapped. A window is unmapped when it becomes invisible on the screen.
2382 * To receive this signal, the #GdkWindow associated to the widget needs
2383 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2384 * automatically for all new windows.
2386 * Returns: %TRUE to stop other handlers from being invoked for the event.
2387 * %FALSE to propagate the event further.
2389 widget_signals[UNMAP_EVENT] =
2390 g_signal_new (I_("unmap-event"),
2391 G_TYPE_FROM_CLASS (klass),
2393 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2394 _gtk_boolean_handled_accumulator, NULL,
2395 _gtk_marshal_BOOLEAN__BOXED,
2397 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2398 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2399 _gtk_marshal_BOOLEAN__BOXEDv);
2402 * GtkWidget::property-notify-event:
2403 * @widget: the object which received the signal
2404 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2407 * The ::property-notify-event signal will be emitted when a property on
2408 * the @widget's window has been changed or deleted.
2410 * To receive this signal, the #GdkWindow associated to the widget needs
2411 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2413 * Returns: %TRUE to stop other handlers from being invoked for the event.
2414 * %FALSE to propagate the event further.
2416 widget_signals[PROPERTY_NOTIFY_EVENT] =
2417 g_signal_new (I_("property-notify-event"),
2418 G_TYPE_FROM_CLASS (klass),
2420 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2421 _gtk_boolean_handled_accumulator, NULL,
2422 _gtk_marshal_BOOLEAN__BOXED,
2424 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2425 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2426 _gtk_marshal_BOOLEAN__BOXEDv);
2429 * GtkWidget::selection-clear-event:
2430 * @widget: the object which received the signal
2431 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2434 * The ::selection-clear-event signal will be emitted when the
2435 * the @widget's window has lost ownership of a selection.
2437 * Returns: %TRUE to stop other handlers from being invoked for the event.
2438 * %FALSE to propagate the event further.
2440 widget_signals[SELECTION_CLEAR_EVENT] =
2441 g_signal_new (I_("selection-clear-event"),
2442 G_TYPE_FROM_CLASS (klass),
2444 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2445 _gtk_boolean_handled_accumulator, NULL,
2446 _gtk_marshal_BOOLEAN__BOXED,
2448 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2449 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2450 _gtk_marshal_BOOLEAN__BOXEDv);
2453 * GtkWidget::selection-request-event:
2454 * @widget: the object which received the signal
2455 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2458 * The ::selection-request-event signal will be emitted when
2459 * another client requests ownership of the selection owned by
2460 * the @widget's window.
2462 * Returns: %TRUE to stop other handlers from being invoked for the event.
2463 * %FALSE to propagate the event further.
2465 widget_signals[SELECTION_REQUEST_EVENT] =
2466 g_signal_new (I_("selection-request-event"),
2467 G_TYPE_FROM_CLASS (klass),
2469 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2470 _gtk_boolean_handled_accumulator, NULL,
2471 _gtk_marshal_BOOLEAN__BOXED,
2473 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2474 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2475 _gtk_marshal_BOOLEAN__BOXEDv);
2478 * GtkWidget::selection-notify-event:
2479 * @widget: the object which received the signal.
2480 * @event: (type Gdk.EventSelection):
2482 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2484 widget_signals[SELECTION_NOTIFY_EVENT] =
2485 g_signal_new (I_("selection-notify-event"),
2486 G_TYPE_FROM_CLASS (klass),
2488 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2489 _gtk_boolean_handled_accumulator, NULL,
2490 _gtk_marshal_BOOLEAN__BOXED,
2492 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2493 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2494 _gtk_marshal_BOOLEAN__BOXEDv);
2497 * GtkWidget::selection-received:
2498 * @widget: the object which received the signal.
2502 widget_signals[SELECTION_RECEIVED] =
2503 g_signal_new (I_("selection-received"),
2504 G_TYPE_FROM_CLASS (klass),
2506 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2508 _gtk_marshal_VOID__BOXED_UINT,
2510 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2514 * GtkWidget::selection-get:
2515 * @widget: the object which received the signal.
2520 widget_signals[SELECTION_GET] =
2521 g_signal_new (I_("selection-get"),
2522 G_TYPE_FROM_CLASS (klass),
2524 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2526 _gtk_marshal_VOID__BOXED_UINT_UINT,
2528 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2533 * GtkWidget::proximity-in-event:
2534 * @widget: the object which received the signal
2535 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2538 * To receive this signal the #GdkWindow associated to the widget needs
2539 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2541 * This signal will be sent to the grab widget if there is one.
2543 * Returns: %TRUE to stop other handlers from being invoked for the event.
2544 * %FALSE to propagate the event further.
2546 widget_signals[PROXIMITY_IN_EVENT] =
2547 g_signal_new (I_("proximity-in-event"),
2548 G_TYPE_FROM_CLASS (klass),
2550 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2551 _gtk_boolean_handled_accumulator, NULL,
2552 _gtk_marshal_BOOLEAN__BOXED,
2554 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2555 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2556 _gtk_marshal_BOOLEAN__BOXEDv);
2559 * GtkWidget::proximity-out-event:
2560 * @widget: the object which received the signal
2561 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2564 * To receive this signal the #GdkWindow associated to the widget needs
2565 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2567 * This signal will be sent to the grab widget if there is one.
2569 * Returns: %TRUE to stop other handlers from being invoked for the event.
2570 * %FALSE to propagate the event further.
2572 widget_signals[PROXIMITY_OUT_EVENT] =
2573 g_signal_new (I_("proximity-out-event"),
2574 G_TYPE_FROM_CLASS (klass),
2576 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2577 _gtk_boolean_handled_accumulator, NULL,
2578 _gtk_marshal_BOOLEAN__BOXED,
2580 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2581 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2582 _gtk_marshal_BOOLEAN__BOXEDv);
2585 * GtkWidget::drag-leave:
2586 * @widget: the object which received the signal.
2587 * @context: the drag context
2588 * @time: the timestamp of the motion event
2590 * The ::drag-leave signal is emitted on the drop site when the cursor
2591 * leaves the widget. A typical reason to connect to this signal is to
2592 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2593 * with gtk_drag_unhighlight()
2595 widget_signals[DRAG_LEAVE] =
2596 g_signal_new (I_("drag-leave"),
2597 G_TYPE_FROM_CLASS (klass),
2599 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2601 _gtk_marshal_VOID__OBJECT_UINT,
2603 GDK_TYPE_DRAG_CONTEXT,
2607 * GtkWidget::drag-begin:
2608 * @widget: the object which received the signal
2609 * @context: the drag context
2611 * The ::drag-begin signal is emitted on the drag source when a drag is
2612 * started. A typical reason to connect to this signal is to set up a
2613 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2615 * Note that some widgets set up a drag icon in the default handler of
2616 * this signal, so you may have to use g_signal_connect_after() to
2617 * override what the default handler did.
2619 widget_signals[DRAG_BEGIN] =
2620 g_signal_new (I_("drag-begin"),
2621 G_TYPE_FROM_CLASS (klass),
2623 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2625 _gtk_marshal_VOID__OBJECT,
2627 GDK_TYPE_DRAG_CONTEXT);
2630 * GtkWidget::drag-end:
2631 * @widget: the object which received the signal
2632 * @context: the drag context
2634 * The ::drag-end signal is emitted on the drag source when a drag is
2635 * finished. A typical reason to connect to this signal is to undo
2636 * things done in #GtkWidget::drag-begin.
2638 widget_signals[DRAG_END] =
2639 g_signal_new (I_("drag-end"),
2640 G_TYPE_FROM_CLASS (klass),
2642 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2644 _gtk_marshal_VOID__OBJECT,
2646 GDK_TYPE_DRAG_CONTEXT);
2649 * GtkWidget::drag-data-delete:
2650 * @widget: the object which received the signal
2651 * @context: the drag context
2653 * The ::drag-data-delete signal is emitted on the drag source when a drag
2654 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2655 * handler is responsible for deleting the data that has been dropped. What
2656 * "delete" means depends on the context of the drag operation.
2658 widget_signals[DRAG_DATA_DELETE] =
2659 g_signal_new (I_("drag-data-delete"),
2660 G_TYPE_FROM_CLASS (klass),
2662 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2664 _gtk_marshal_VOID__OBJECT,
2666 GDK_TYPE_DRAG_CONTEXT);
2669 * GtkWidget::drag-failed:
2670 * @widget: the object which received the signal
2671 * @context: the drag context
2672 * @result: the result of the drag operation
2674 * The ::drag-failed signal is emitted on the drag source when a drag has
2675 * failed. The signal handler may hook custom code to handle a failed DND
2676 * operation based on the type of error, it returns %TRUE is the failure has
2677 * been already handled (not showing the default "drag operation failed"
2678 * animation), otherwise it returns %FALSE.
2680 * Return value: %TRUE if the failed drag operation has been already handled.
2684 widget_signals[DRAG_FAILED] =
2685 g_signal_new (I_("drag-failed"),
2686 G_TYPE_FROM_CLASS (klass),
2688 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2689 _gtk_boolean_handled_accumulator, NULL,
2690 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2692 GDK_TYPE_DRAG_CONTEXT,
2693 GTK_TYPE_DRAG_RESULT);
2696 * GtkWidget::drag-motion:
2697 * @widget: the object which received the signal
2698 * @context: the drag context
2699 * @x: the x coordinate of the current cursor position
2700 * @y: the y coordinate of the current cursor position
2701 * @time: the timestamp of the motion event
2703 * The ::drag-motion signal is emitted on the drop site when the user
2704 * moves the cursor over the widget during a drag. The signal handler
2705 * must determine whether the cursor position is in a drop zone or not.
2706 * If it is not in a drop zone, it returns %FALSE and no further processing
2707 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2708 * handler is responsible for providing the necessary information for
2709 * displaying feedback to the user, by calling gdk_drag_status().
2711 * If the decision whether the drop will be accepted or rejected can't be
2712 * made based solely on the cursor position and the type of the data, the
2713 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2714 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2715 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2716 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2717 * when using the drag-motion signal that way.
2719 * Also note that there is no drag-enter signal. The drag receiver has to
2720 * keep track of whether he has received any drag-motion signals since the
2721 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2722 * an "enter" signal. Upon an "enter", the handler will typically highlight
2723 * the drop site with gtk_drag_highlight().
2726 * drag_motion (GtkWidget *widget,
2727 * GdkDragContext *context,
2734 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2736 * if (!private_data->drag_highlight)
2738 * private_data->drag_highlight = 1;
2739 * gtk_drag_highlight (widget);
2742 * target = gtk_drag_dest_find_target (widget, context, NULL);
2743 * if (target == GDK_NONE)
2744 * gdk_drag_status (context, 0, time);
2747 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2748 * gtk_drag_get_data (widget, context, target, time);
2755 * drag_data_received (GtkWidget *widget,
2756 * GdkDragContext *context,
2759 * GtkSelectionData *selection_data,
2763 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2765 * if (private_data->suggested_action)
2767 * private_data->suggested_action = 0;
2769 * /* We are getting this data due to a request in drag_motion,
2770 * * rather than due to a request in drag_drop, so we are just
2771 * * supposed to call gdk_drag_status(), not actually paste in
2774 * str = gtk_selection_data_get_text (selection_data);
2775 * if (!data_is_acceptable (str))
2776 * gdk_drag_status (context, 0, time);
2778 * gdk_drag_status (context, private_data->suggested_action, time);
2782 * /* accept the drop */
2787 * Returns: whether the cursor position is in a drop zone
2789 widget_signals[DRAG_MOTION] =
2790 g_signal_new (I_("drag-motion"),
2791 G_TYPE_FROM_CLASS (klass),
2793 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2794 _gtk_boolean_handled_accumulator, NULL,
2795 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2797 GDK_TYPE_DRAG_CONTEXT,
2803 * GtkWidget::drag-drop:
2804 * @widget: the object which received the signal
2805 * @context: the drag context
2806 * @x: the x coordinate of the current cursor position
2807 * @y: the y coordinate of the current cursor position
2808 * @time: the timestamp of the motion event
2810 * The ::drag-drop signal is emitted on the drop site when the user drops
2811 * the data onto the widget. The signal handler must determine whether
2812 * the cursor position is in a drop zone or not. If it is not in a drop
2813 * zone, it returns %FALSE and no further processing is necessary.
2814 * Otherwise, the handler returns %TRUE. In this case, the handler must
2815 * ensure that gtk_drag_finish() is called to let the source know that
2816 * the drop is done. The call to gtk_drag_finish() can be done either
2817 * directly or in a #GtkWidget::drag-data-received handler which gets
2818 * triggered by calling gtk_drag_get_data() to receive the data for one
2819 * or more of the supported targets.
2821 * Returns: whether the cursor position is in a drop zone
2823 widget_signals[DRAG_DROP] =
2824 g_signal_new (I_("drag-drop"),
2825 G_TYPE_FROM_CLASS (klass),
2827 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2828 _gtk_boolean_handled_accumulator, NULL,
2829 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2831 GDK_TYPE_DRAG_CONTEXT,
2837 * GtkWidget::drag-data-get:
2838 * @widget: the object which received the signal
2839 * @context: the drag context
2840 * @data: the #GtkSelectionData to be filled with the dragged data
2841 * @info: the info that has been registered with the target in the
2843 * @time: the timestamp at which the data was requested
2845 * The ::drag-data-get signal is emitted on the drag source when the drop
2846 * site requests the data which is dragged. It is the responsibility of
2847 * the signal handler to fill @data with the data in the format which
2848 * is indicated by @info. See gtk_selection_data_set() and
2849 * gtk_selection_data_set_text().
2851 widget_signals[DRAG_DATA_GET] =
2852 g_signal_new (I_("drag-data-get"),
2853 G_TYPE_FROM_CLASS (klass),
2855 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2857 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2859 GDK_TYPE_DRAG_CONTEXT,
2860 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2865 * GtkWidget::drag-data-received:
2866 * @widget: the object which received the signal
2867 * @context: the drag context
2868 * @x: where the drop happened
2869 * @y: where the drop happened
2870 * @data: the received data
2871 * @info: the info that has been registered with the target in the
2873 * @time: the timestamp at which the data was received
2875 * The ::drag-data-received signal is emitted on the drop site when the
2876 * dragged data has been received. If the data was received in order to
2877 * determine whether the drop will be accepted, the handler is expected
2878 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2879 * If the data was received in response to a #GtkWidget::drag-drop signal
2880 * (and this is the last target to be received), the handler for this
2881 * signal is expected to process the received data and then call
2882 * gtk_drag_finish(), setting the @success parameter depending on
2883 * whether the data was processed successfully.
2885 * The handler may inspect the selected action with
2886 * gdk_drag_context_get_selected_action() before calling
2887 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2888 * shown in the following example:
2891 * drag_data_received (GtkWidget *widget,
2892 * GdkDragContext *context,
2895 * GtkSelectionData *data,
2899 * if ((data->length >= 0) && (data->format == 8))
2901 * GdkDragAction action;
2903 * /* handle data here */
2905 * action = gdk_drag_context_get_selected_action (context);
2906 * if (action == GDK_ACTION_ASK)
2908 * GtkWidget *dialog;
2911 * dialog = gtk_message_dialog_new (NULL,
2912 * GTK_DIALOG_MODAL |
2913 * GTK_DIALOG_DESTROY_WITH_PARENT,
2915 * GTK_BUTTONS_YES_NO,
2916 * "Move the data ?\n");
2917 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2918 * gtk_widget_destroy (dialog);
2920 * if (response == GTK_RESPONSE_YES)
2921 * action = GDK_ACTION_MOVE;
2923 * action = GDK_ACTION_COPY;
2926 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2929 * gtk_drag_finish (context, FALSE, FALSE, time);
2933 widget_signals[DRAG_DATA_RECEIVED] =
2934 g_signal_new (I_("drag-data-received"),
2935 G_TYPE_FROM_CLASS (klass),
2937 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2939 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2941 GDK_TYPE_DRAG_CONTEXT,
2944 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2949 * GtkWidget::visibility-notify-event:
2950 * @widget: the object which received the signal
2951 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2952 * triggered this signal.
2954 * The ::visibility-notify-event will be emitted when the @widget's window
2955 * is obscured or unobscured.
2957 * To receive this signal the #GdkWindow associated to the widget needs
2958 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2960 * Returns: %TRUE to stop other handlers from being invoked for the event.
2961 * %FALSE to propagate the event further.
2963 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2964 g_signal_new (I_("visibility-notify-event"),
2965 G_TYPE_FROM_CLASS (klass),
2967 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2968 _gtk_boolean_handled_accumulator, NULL,
2969 _gtk_marshal_BOOLEAN__BOXED,
2971 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2974 * GtkWidget::window-state-event:
2975 * @widget: the object which received the signal
2976 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2977 * triggered this signal.
2979 * The ::window-state-event will be emitted when the state of the
2980 * toplevel window associated to the @widget changes.
2982 * To receive this signal the #GdkWindow associated to the widget
2983 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2984 * this mask automatically for all new windows.
2986 * Returns: %TRUE to stop other handlers from being invoked for the
2987 * event. %FALSE to propagate the event further.
2989 widget_signals[WINDOW_STATE_EVENT] =
2990 g_signal_new (I_("window-state-event"),
2991 G_TYPE_FROM_CLASS (klass),
2993 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2994 _gtk_boolean_handled_accumulator, NULL,
2995 _gtk_marshal_BOOLEAN__BOXED,
2997 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2998 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
2999 _gtk_marshal_BOOLEAN__BOXEDv);
3002 * GtkWidget::damage-event:
3003 * @widget: the object which received the signal
3004 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3006 * Emitted when a redirected window belonging to @widget gets drawn into.
3007 * The region/area members of the event shows what area of the redirected
3008 * drawable was drawn into.
3010 * Returns: %TRUE to stop other handlers from being invoked for the event.
3011 * %FALSE to propagate the event further.
3015 widget_signals[DAMAGE_EVENT] =
3016 g_signal_new (I_("damage-event"),
3017 G_TYPE_FROM_CLASS (klass),
3019 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3020 _gtk_boolean_handled_accumulator, NULL,
3021 _gtk_marshal_BOOLEAN__BOXED,
3023 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3024 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3025 _gtk_marshal_BOOLEAN__BOXEDv);
3028 * GtkWidget::grab-broken-event:
3029 * @widget: the object which received the signal
3030 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3032 * Emitted when a pointer or keyboard grab on a window belonging
3033 * to @widget gets broken.
3035 * On X11, this happens when the grab window becomes unviewable
3036 * (i.e. it or one of its ancestors is unmapped), or if the same
3037 * application grabs the pointer or keyboard again.
3039 * Returns: %TRUE to stop other handlers from being invoked for
3040 * the event. %FALSE to propagate the event further.
3044 widget_signals[GRAB_BROKEN_EVENT] =
3045 g_signal_new (I_("grab-broken-event"),
3046 G_TYPE_FROM_CLASS (klass),
3048 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3049 _gtk_boolean_handled_accumulator, NULL,
3050 _gtk_marshal_BOOLEAN__BOXED,
3052 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3053 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3054 _gtk_marshal_BOOLEAN__BOXEDv);
3057 * GtkWidget::query-tooltip:
3058 * @widget: the object which received the signal
3059 * @x: the x coordinate of the cursor position where the request has
3060 * been emitted, relative to @widget's left side
3061 * @y: the y coordinate of the cursor position where the request has
3062 * been emitted, relative to @widget's top
3063 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3064 * @tooltip: a #GtkTooltip
3066 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3067 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3068 * focus in keyboard mode.
3070 * Using the given coordinates, the signal handler should determine
3071 * whether a tooltip should be shown for @widget. If this is the case
3072 * %TRUE should be returned, %FALSE otherwise. Note that if
3073 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3074 * should not be used.
3076 * The signal handler is free to manipulate @tooltip with the therefore
3077 * destined function calls.
3079 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3083 widget_signals[QUERY_TOOLTIP] =
3084 g_signal_new (I_("query-tooltip"),
3085 G_TYPE_FROM_CLASS (klass),
3087 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3088 _gtk_boolean_handled_accumulator, NULL,
3089 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3097 * GtkWidget::popup-menu:
3098 * @widget: the object which received the signal
3100 * This signal gets emitted whenever a widget should pop up a context
3101 * menu. This usually happens through the standard key binding mechanism;
3102 * by pressing a certain key while a widget is focused, the user can cause
3103 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3104 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3105 * for an example of how to use this signal.
3107 * Returns: %TRUE if a menu was activated
3109 widget_signals[POPUP_MENU] =
3110 g_signal_new (I_("popup-menu"),
3111 G_TYPE_FROM_CLASS (klass),
3112 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3113 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3114 _gtk_boolean_handled_accumulator, NULL,
3115 _gtk_marshal_BOOLEAN__VOID,
3119 * GtkWidget::show-help:
3120 * @widget: the object which received the signal.
3123 * Returns: %TRUE to stop other handlers from being invoked for the event.
3124 * %FALSE to propagate the event further.
3126 widget_signals[SHOW_HELP] =
3127 g_signal_new (I_("show-help"),
3128 G_TYPE_FROM_CLASS (klass),
3129 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3130 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3131 _gtk_boolean_handled_accumulator, NULL,
3132 _gtk_marshal_BOOLEAN__ENUM,
3134 GTK_TYPE_WIDGET_HELP_TYPE);
3137 * GtkWidget::accel-closures-changed:
3138 * @widget: the object which received the signal.
3140 widget_signals[ACCEL_CLOSURES_CHANGED] =
3141 g_signal_new (I_("accel-closures-changed"),
3142 G_TYPE_FROM_CLASS (klass),
3146 _gtk_marshal_VOID__VOID,
3150 * GtkWidget::screen-changed:
3151 * @widget: the object on which the signal is emitted
3152 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3153 * widget was not associated with a screen before
3155 * The ::screen-changed signal gets emitted when the
3156 * screen of a widget has changed.
3158 widget_signals[SCREEN_CHANGED] =
3159 g_signal_new (I_("screen-changed"),
3160 G_TYPE_FROM_CLASS (klass),
3162 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3164 _gtk_marshal_VOID__OBJECT,
3169 * GtkWidget::can-activate-accel:
3170 * @widget: the object which received the signal
3171 * @signal_id: the ID of a signal installed on @widget
3173 * Determines whether an accelerator that activates the signal
3174 * identified by @signal_id can currently be activated.
3175 * This signal is present to allow applications and derived
3176 * widgets to override the default #GtkWidget handling
3177 * for determining whether an accelerator can be activated.
3179 * Returns: %TRUE if the signal can be activated.
3181 widget_signals[CAN_ACTIVATE_ACCEL] =
3182 g_signal_new (I_("can-activate-accel"),
3183 G_TYPE_FROM_CLASS (klass),
3185 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3186 _gtk_boolean_handled_accumulator, NULL,
3187 _gtk_marshal_BOOLEAN__UINT,
3188 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3190 binding_set = gtk_binding_set_by_class (klass);
3191 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3193 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3196 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3198 GTK_TYPE_WIDGET_HELP_TYPE,
3199 GTK_WIDGET_HELP_TOOLTIP);
3200 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3202 GTK_TYPE_WIDGET_HELP_TYPE,
3203 GTK_WIDGET_HELP_TOOLTIP);
3204 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3206 GTK_TYPE_WIDGET_HELP_TYPE,
3207 GTK_WIDGET_HELP_WHATS_THIS);
3208 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3210 GTK_TYPE_WIDGET_HELP_TYPE,
3211 GTK_WIDGET_HELP_WHATS_THIS);
3213 gtk_widget_class_install_style_property (klass,
3214 g_param_spec_boolean ("interior-focus",
3215 P_("Interior Focus"),
3216 P_("Whether to draw the focus indicator inside widgets"),
3218 GTK_PARAM_READABLE));
3220 gtk_widget_class_install_style_property (klass,
3221 g_param_spec_int ("focus-line-width",
3222 P_("Focus linewidth"),
3223 P_("Width, in pixels, of the focus indicator line"),
3225 GTK_PARAM_READABLE));
3227 gtk_widget_class_install_style_property (klass,
3228 g_param_spec_string ("focus-line-pattern",
3229 P_("Focus line dash pattern"),
3230 P_("Dash pattern used to draw the focus indicator"),
3232 GTK_PARAM_READABLE));
3233 gtk_widget_class_install_style_property (klass,
3234 g_param_spec_int ("focus-padding",
3235 P_("Focus padding"),
3236 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3238 GTK_PARAM_READABLE));
3239 gtk_widget_class_install_style_property (klass,
3240 g_param_spec_boxed ("cursor-color",
3242 P_("Color with which to draw insertion cursor"),
3244 GTK_PARAM_READABLE));
3245 gtk_widget_class_install_style_property (klass,
3246 g_param_spec_boxed ("secondary-cursor-color",
3247 P_("Secondary cursor color"),
3248 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3250 GTK_PARAM_READABLE));
3251 gtk_widget_class_install_style_property (klass,
3252 g_param_spec_float ("cursor-aspect-ratio",
3253 P_("Cursor line aspect ratio"),
3254 P_("Aspect ratio with which to draw insertion cursor"),
3256 GTK_PARAM_READABLE));
3258 gtk_widget_class_install_style_property (klass,
3259 g_param_spec_boolean ("window-dragging",
3260 P_("Window dragging"),
3261 P_("Whether windows can be dragged by clicking on empty areas"),
3263 GTK_PARAM_READABLE));
3266 * GtkWidget:link-color:
3268 * The "link-color" style property defines the color of unvisited links.
3272 gtk_widget_class_install_style_property (klass,
3273 g_param_spec_boxed ("link-color",
3274 P_("Unvisited Link Color"),
3275 P_("Color of unvisited links"),
3277 GTK_PARAM_READABLE));
3280 * GtkWidget:visited-link-color:
3282 * The "visited-link-color" style property defines the color of visited links.
3286 gtk_widget_class_install_style_property (klass,
3287 g_param_spec_boxed ("visited-link-color",
3288 P_("Visited Link Color"),
3289 P_("Color of visited links"),
3291 GTK_PARAM_READABLE));
3294 * GtkWidget:wide-separators:
3296 * The "wide-separators" style property defines whether separators have
3297 * configurable width and should be drawn using a box instead of a line.
3301 gtk_widget_class_install_style_property (klass,
3302 g_param_spec_boolean ("wide-separators",
3303 P_("Wide Separators"),
3304 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3306 GTK_PARAM_READABLE));
3309 * GtkWidget:separator-width:
3311 * The "separator-width" style property defines the width of separators.
3312 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3316 gtk_widget_class_install_style_property (klass,
3317 g_param_spec_int ("separator-width",
3318 P_("Separator Width"),
3319 P_("The width of separators if wide-separators is TRUE"),
3321 GTK_PARAM_READABLE));
3324 * GtkWidget:separator-height:
3326 * The "separator-height" style property defines the height of separators.
3327 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3331 gtk_widget_class_install_style_property (klass,
3332 g_param_spec_int ("separator-height",
3333 P_("Separator Height"),
3334 P_("The height of separators if \"wide-separators\" is TRUE"),
3336 GTK_PARAM_READABLE));
3339 * GtkWidget:scroll-arrow-hlength:
3341 * The "scroll-arrow-hlength" style property defines the length of
3342 * horizontal scroll arrows.
3346 gtk_widget_class_install_style_property (klass,
3347 g_param_spec_int ("scroll-arrow-hlength",
3348 P_("Horizontal Scroll Arrow Length"),
3349 P_("The length of horizontal scroll arrows"),
3351 GTK_PARAM_READABLE));
3354 * GtkWidget:scroll-arrow-vlength:
3356 * The "scroll-arrow-vlength" style property defines the length of
3357 * vertical scroll arrows.
3361 gtk_widget_class_install_style_property (klass,
3362 g_param_spec_int ("scroll-arrow-vlength",
3363 P_("Vertical Scroll Arrow Length"),
3364 P_("The length of vertical scroll arrows"),
3366 GTK_PARAM_READABLE));
3368 gtk_widget_class_install_style_property (klass,
3369 g_param_spec_int ("text-handle-width",
3370 P_("Width of text selection handles"),
3371 P_("Width of text selection handles"),
3373 GTK_PARAM_READABLE));
3374 gtk_widget_class_install_style_property (klass,
3375 g_param_spec_int ("text-handle-height",
3376 P_("Height of text selection handles"),
3377 P_("Height of text selection handles"),
3379 GTK_PARAM_READABLE));
3381 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3383 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3387 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3391 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3392 for (node = list; node; node = node->next)
3394 GParamSpec *pspec = node->data;
3396 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3397 g_param_spec_unref (pspec);
3403 gtk_widget_set_property (GObject *object,
3405 const GValue *value,
3408 GtkWidget *widget = GTK_WIDGET (object);
3413 gchar *tooltip_markup;
3414 const gchar *tooltip_text;
3415 GtkWindow *tooltip_window;
3418 gtk_widget_set_name (widget, g_value_get_string (value));
3421 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3423 case PROP_WIDTH_REQUEST:
3424 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3426 case PROP_HEIGHT_REQUEST:
3427 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3430 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3432 case PROP_SENSITIVE:
3433 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3435 case PROP_APP_PAINTABLE:
3436 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3438 case PROP_CAN_FOCUS:
3439 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3441 case PROP_HAS_FOCUS:
3442 if (g_value_get_boolean (value))
3443 gtk_widget_grab_focus (widget);
3446 if (g_value_get_boolean (value))
3447 gtk_widget_grab_focus (widget);
3449 case PROP_CAN_DEFAULT:
3450 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3452 case PROP_HAS_DEFAULT:
3453 if (g_value_get_boolean (value))
3454 gtk_widget_grab_default (widget);
3456 case PROP_RECEIVES_DEFAULT:
3457 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3460 gtk_widget_set_style (widget, g_value_get_object (value));
3463 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3464 gtk_widget_set_events (widget, g_value_get_flags (value));
3466 case PROP_NO_SHOW_ALL:
3467 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3469 case PROP_HAS_TOOLTIP:
3470 gtk_widget_real_set_has_tooltip (widget,
3471 g_value_get_boolean (value), FALSE);
3473 case PROP_TOOLTIP_MARKUP:
3474 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3475 tooltip_markup = g_value_dup_string (value);
3477 /* Treat an empty string as a NULL string,
3478 * because an empty string would be useless for a tooltip:
3480 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3482 g_free (tooltip_markup);
3483 tooltip_markup = NULL;
3486 g_object_set_qdata_full (object, quark_tooltip_markup,
3487 tooltip_markup, g_free);
3489 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3490 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3491 if (gtk_widget_get_visible (widget))
3492 gtk_widget_queue_tooltip_query (widget);
3494 case PROP_TOOLTIP_TEXT:
3495 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3497 tooltip_text = g_value_get_string (value);
3499 /* Treat an empty string as a NULL string,
3500 * because an empty string would be useless for a tooltip:
3502 if (tooltip_text && (strlen (tooltip_text) == 0))
3503 tooltip_text = NULL;
3505 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3507 g_object_set_qdata_full (object, quark_tooltip_markup,
3508 tooltip_markup, g_free);
3510 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3511 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3512 if (gtk_widget_get_visible (widget))
3513 gtk_widget_queue_tooltip_query (widget);
3515 case PROP_DOUBLE_BUFFERED:
3516 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3519 gtk_widget_set_halign (widget, g_value_get_enum (value));
3522 gtk_widget_set_valign (widget, g_value_get_enum (value));
3524 case PROP_MARGIN_LEFT:
3525 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3527 case PROP_MARGIN_RIGHT:
3528 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3530 case PROP_MARGIN_TOP:
3531 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3533 case PROP_MARGIN_BOTTOM:
3534 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3537 g_object_freeze_notify (G_OBJECT (widget));
3538 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3539 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3540 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3541 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3542 g_object_thaw_notify (G_OBJECT (widget));
3545 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3547 case PROP_HEXPAND_SET:
3548 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3551 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3553 case PROP_VEXPAND_SET:
3554 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3557 g_object_freeze_notify (G_OBJECT (widget));
3558 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3559 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3560 g_object_thaw_notify (G_OBJECT (widget));
3563 gtk_widget_set_opacity (widget, g_value_get_double (value));
3566 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3572 gtk_widget_get_property (GObject *object,
3577 GtkWidget *widget = GTK_WIDGET (object);
3578 GtkWidgetPrivate *priv = widget->priv;
3586 g_value_set_string (value, priv->name);
3588 g_value_set_static_string (value, "");
3591 g_value_set_object (value, priv->parent);
3593 case PROP_WIDTH_REQUEST:
3596 gtk_widget_get_size_request (widget, &w, NULL);
3597 g_value_set_int (value, w);
3600 case PROP_HEIGHT_REQUEST:
3603 gtk_widget_get_size_request (widget, NULL, &h);
3604 g_value_set_int (value, h);
3608 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3610 case PROP_SENSITIVE:
3611 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3613 case PROP_APP_PAINTABLE:
3614 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3616 case PROP_CAN_FOCUS:
3617 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3619 case PROP_HAS_FOCUS:
3620 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3623 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3625 case PROP_CAN_DEFAULT:
3626 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3628 case PROP_HAS_DEFAULT:
3629 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3631 case PROP_RECEIVES_DEFAULT:
3632 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3634 case PROP_COMPOSITE_CHILD:
3635 g_value_set_boolean (value, widget->priv->composite_child);
3638 g_value_set_object (value, gtk_widget_get_style (widget));
3641 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3642 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3644 case PROP_NO_SHOW_ALL:
3645 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3647 case PROP_HAS_TOOLTIP:
3648 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3650 case PROP_TOOLTIP_TEXT:
3652 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3655 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3656 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3658 g_value_take_string (value, text);
3661 case PROP_TOOLTIP_MARKUP:
3662 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3665 g_value_set_object (value, gtk_widget_get_window (widget));
3667 case PROP_DOUBLE_BUFFERED:
3668 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3671 g_value_set_enum (value, gtk_widget_get_halign (widget));
3674 g_value_set_enum (value, gtk_widget_get_valign (widget));
3676 case PROP_MARGIN_LEFT:
3677 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3679 case PROP_MARGIN_RIGHT:
3680 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3682 case PROP_MARGIN_TOP:
3683 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3685 case PROP_MARGIN_BOTTOM:
3686 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3690 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3691 if (aux_info == NULL)
3693 g_value_set_int (value, 0);
3697 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3698 aux_info->margin.right),
3699 MAX (aux_info->margin.top,
3700 aux_info->margin.bottom)));
3705 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3707 case PROP_HEXPAND_SET:
3708 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3711 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3713 case PROP_VEXPAND_SET:
3714 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3717 g_value_set_boolean (value,
3718 gtk_widget_get_hexpand (widget) &&
3719 gtk_widget_get_vexpand (widget));
3722 g_value_set_double (value, gtk_widget_get_opacity (widget));
3725 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3731 gtk_widget_init (GtkWidget *widget)
3733 GtkWidgetPrivate *priv;
3735 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3738 priv = widget->priv;
3740 priv->child_visible = TRUE;
3742 priv->allocation.x = -1;
3743 priv->allocation.y = -1;
3744 priv->allocation.width = 1;
3745 priv->allocation.height = 1;
3747 priv->window = NULL;
3748 priv->parent = NULL;
3750 priv->sensitive = TRUE;
3751 priv->composite_child = composite_child_stack != 0;
3752 priv->double_buffered = TRUE;
3753 priv->redraw_on_alloc = TRUE;
3754 priv->alloc_needed = TRUE;
3756 switch (gtk_widget_get_direction (widget))
3758 case GTK_TEXT_DIR_LTR:
3759 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3762 case GTK_TEXT_DIR_RTL:
3763 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3766 case GTK_TEXT_DIR_NONE:
3768 g_assert_not_reached ();
3773 /* this will be set to TRUE if the widget gets a child or if the
3774 * expand flag is set on the widget, but until one of those happen
3775 * we know the expand is already properly FALSE.
3777 * We really want to default FALSE here to avoid computing expand
3778 * all over the place while initially building a widget tree.
3780 priv->need_compute_expand = FALSE;
3782 _gtk_size_request_cache_init (&priv->requests);
3784 priv->style = gtk_widget_get_default_style ();
3785 g_object_ref (priv->style);
3790 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3792 GParamSpec **pspecs)
3794 GtkWidgetPrivate *priv = widget->priv;
3795 GtkWidget *container = priv->parent;
3798 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3799 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3803 * gtk_widget_freeze_child_notify:
3804 * @widget: a #GtkWidget
3806 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3807 * signals are queued until gtk_widget_thaw_child_notify() is called
3810 * This is the analogue of g_object_freeze_notify() for child properties.
3813 gtk_widget_freeze_child_notify (GtkWidget *widget)
3815 g_return_if_fail (GTK_IS_WIDGET (widget));
3817 if (!G_OBJECT (widget)->ref_count)
3820 g_object_ref (widget);
3821 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3822 g_object_unref (widget);
3826 * gtk_widget_child_notify:
3827 * @widget: a #GtkWidget
3828 * @child_property: the name of a child property installed on the
3829 * class of @widget<!-- -->'s parent
3831 * Emits a #GtkWidget::child-notify signal for the
3832 * <link linkend="child-properties">child property</link> @child_property
3835 * This is the analogue of g_object_notify() for child properties.
3837 * Also see gtk_container_child_notify().
3840 gtk_widget_child_notify (GtkWidget *widget,
3841 const gchar *child_property)
3843 if (widget->priv->parent == NULL)
3846 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3850 * gtk_widget_thaw_child_notify:
3851 * @widget: a #GtkWidget
3853 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3854 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3858 gtk_widget_thaw_child_notify (GtkWidget *widget)
3860 GObjectNotifyQueue *nqueue;
3862 g_return_if_fail (GTK_IS_WIDGET (widget));
3864 if (!G_OBJECT (widget)->ref_count)
3867 g_object_ref (widget);
3868 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3869 if (!nqueue || !nqueue->freeze_count)
3870 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3871 G_OBJECT_TYPE_NAME (widget), widget);
3873 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3874 g_object_unref (widget);
3880 * @type: type ID of the widget to create
3881 * @first_property_name: name of first property to set
3882 * @...: value of first property, followed by more properties,
3885 * This is a convenience function for creating a widget and setting
3886 * its properties in one go. For example you might write:
3887 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3888 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3889 * g_object_new(), but returns a widget so you don't have to
3890 * cast the object yourself.
3892 * Return value: a new #GtkWidget of type @widget_type
3895 gtk_widget_new (GType type,
3896 const gchar *first_property_name,
3902 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3904 va_start (var_args, first_property_name);
3905 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3912 gtk_widget_queue_draw_child (GtkWidget *widget)
3914 GtkWidgetPrivate *priv = widget->priv;
3917 parent = priv->parent;
3918 if (parent && gtk_widget_is_drawable (parent))
3919 gtk_widget_queue_draw_area (parent,
3922 priv->allocation.width,
3923 priv->allocation.height);
3927 * gtk_widget_unparent:
3928 * @widget: a #GtkWidget
3930 * This function is only for use in widget implementations.
3931 * Should be called by implementations of the remove method
3932 * on #GtkContainer, to dissociate a child from the container.
3935 gtk_widget_unparent (GtkWidget *widget)
3937 GtkWidgetPrivate *priv;
3938 GObjectNotifyQueue *nqueue;
3939 GtkWidget *toplevel;
3940 GtkWidget *old_parent;
3942 g_return_if_fail (GTK_IS_WIDGET (widget));
3944 priv = widget->priv;
3946 if (priv->parent == NULL)
3949 /* keep this function in sync with gtk_menu_detach() */
3951 gtk_widget_push_verify_invariants (widget);
3953 g_object_freeze_notify (G_OBJECT (widget));
3954 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3956 toplevel = gtk_widget_get_toplevel (widget);
3957 if (gtk_widget_is_toplevel (toplevel))
3958 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3960 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3961 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3963 gtk_widget_queue_draw_child (widget);
3965 /* Reset the width and height here, to force reallocation if we
3966 * get added back to a new parent. This won't work if our new
3967 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3968 * (would 0x0 be OK here?)
3970 priv->allocation.width = 1;
3971 priv->allocation.height = 1;
3973 if (gtk_widget_get_realized (widget))
3975 if (priv->in_reparent)
3976 gtk_widget_unmap (widget);
3978 gtk_widget_unrealize (widget);
3981 /* If we are unanchoring the child, we save around the toplevel
3982 * to emit hierarchy changed
3984 if (priv->parent->priv->anchored)
3985 g_object_ref (toplevel);
3989 /* Removing a widget from a container restores the child visible
3990 * flag to the default state, so it doesn't affect the child
3991 * in the next parent.
3993 priv->child_visible = TRUE;
3995 old_parent = priv->parent;
3996 priv->parent = NULL;
3998 /* parent may no longer expand if the removed
3999 * child was expand=TRUE and could therefore
4002 if (gtk_widget_get_visible (widget) &&
4003 (priv->need_compute_expand ||
4004 priv->computed_hexpand ||
4005 priv->computed_vexpand))
4007 gtk_widget_queue_compute_expand (old_parent);
4010 /* Unset BACKDROP since we are no longer inside a toplevel window */
4011 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4013 gtk_style_context_set_parent (priv->context, NULL);
4015 _gtk_widget_update_parent_muxer (widget);
4017 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4020 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4021 g_object_unref (toplevel);
4024 /* Now that the parent pointer is nullified and the hierarchy-changed
4025 * already passed, go ahead and unset the parent window, if we are unparenting
4026 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4027 * will fire again for the new subhierarchy.
4029 gtk_widget_set_parent_window (widget, NULL);
4031 g_object_notify (G_OBJECT (widget), "parent");
4032 g_object_thaw_notify (G_OBJECT (widget));
4034 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4035 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4037 gtk_widget_update_norender (widget);
4039 gtk_widget_pop_verify_invariants (widget);
4040 g_object_unref (widget);
4044 * gtk_widget_destroy:
4045 * @widget: a #GtkWidget
4047 * Destroys a widget.
4050 * destroyed, it will break any references it holds to other objects.
4051 * If the widget is inside a container, the widget will be removed
4052 * from the container. If the widget is a toplevel (derived from
4053 * #GtkWindow), it will be removed from the list of toplevels, and the
4054 * reference GTK+ holds to it will be removed. Removing a
4055 * widget from its container or the list of toplevels results in the
4056 * widget being finalized, unless you've added additional references
4057 * to the widget with g_object_ref().
4059 * In most cases, only toplevel widgets (windows) require explicit
4060 * destruction, because when you destroy a toplevel its children will
4061 * be destroyed as well.
4064 gtk_widget_destroy (GtkWidget *widget)
4066 g_return_if_fail (GTK_IS_WIDGET (widget));
4068 if (!widget->priv->in_destruction)
4069 g_object_run_dispose (G_OBJECT (widget));
4073 * gtk_widget_destroyed:
4074 * @widget: a #GtkWidget
4075 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4077 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4078 * %NULL. It's intended to be used as a callback connected to the
4079 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4080 * as a signal handler, and pass the address of your widget variable
4081 * as user data. Then when the widget is destroyed, the variable will
4082 * be set to %NULL. Useful for example to avoid multiple copies
4083 * of the same dialog.
4086 gtk_widget_destroyed (GtkWidget *widget,
4087 GtkWidget **widget_pointer)
4089 /* Don't make any assumptions about the
4091 * Even check widget_pointer.
4094 *widget_pointer = NULL;
4099 * @widget: a #GtkWidget
4101 * Flags a widget to be displayed. Any widget that isn't shown will
4102 * not appear on the screen. If you want to show all the widgets in a
4103 * container, it's easier to call gtk_widget_show_all() on the
4104 * container, instead of individually showing the widgets.
4106 * Remember that you have to show the containers containing a widget,
4107 * in addition to the widget itself, before it will appear onscreen.
4109 * When a toplevel container is shown, it is immediately realized and
4110 * mapped; other shown widgets are realized and mapped when their
4111 * toplevel container is realized and mapped.
4114 gtk_widget_show (GtkWidget *widget)
4116 g_return_if_fail (GTK_IS_WIDGET (widget));
4118 if (!gtk_widget_get_visible (widget))
4120 g_object_ref (widget);
4121 gtk_widget_push_verify_invariants (widget);
4123 if (!gtk_widget_is_toplevel (widget))
4124 gtk_widget_queue_resize (widget);
4126 /* see comment in set_parent() for why this should and can be
4129 if (widget->priv->need_compute_expand ||
4130 widget->priv->computed_hexpand ||
4131 widget->priv->computed_vexpand)
4133 if (widget->priv->parent != NULL)
4134 gtk_widget_queue_compute_expand (widget->priv->parent);
4137 g_signal_emit (widget, widget_signals[SHOW], 0);
4138 g_object_notify (G_OBJECT (widget), "visible");
4140 gtk_widget_pop_verify_invariants (widget);
4141 g_object_unref (widget);
4146 gtk_widget_real_show (GtkWidget *widget)
4148 GtkWidgetPrivate *priv = widget->priv;
4150 if (!gtk_widget_get_visible (widget))
4152 priv->visible = TRUE;
4155 gtk_widget_get_mapped (priv->parent) &&
4156 gtk_widget_get_child_visible (widget) &&
4157 !gtk_widget_get_mapped (widget))
4158 gtk_widget_map (widget);
4163 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4166 g_signal_handlers_disconnect_by_func (widget,
4167 gtk_widget_show_map_callback,
4172 * gtk_widget_show_now:
4173 * @widget: a #GtkWidget
4175 * Shows a widget. If the widget is an unmapped toplevel widget
4176 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4177 * loop and wait for the window to actually be mapped. Be careful;
4178 * because the main loop is running, anything can happen during
4182 gtk_widget_show_now (GtkWidget *widget)
4186 g_return_if_fail (GTK_IS_WIDGET (widget));
4188 /* make sure we will get event */
4189 if (!gtk_widget_get_mapped (widget) &&
4190 gtk_widget_is_toplevel (widget))
4192 gtk_widget_show (widget);
4194 g_signal_connect (widget, "map-event",
4195 G_CALLBACK (gtk_widget_show_map_callback),
4199 gtk_main_iteration ();
4202 gtk_widget_show (widget);
4207 * @widget: a #GtkWidget
4209 * Reverses the effects of gtk_widget_show(), causing the widget to be
4210 * hidden (invisible to the user).
4213 gtk_widget_hide (GtkWidget *widget)
4215 g_return_if_fail (GTK_IS_WIDGET (widget));
4217 if (gtk_widget_get_visible (widget))
4219 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4221 g_object_ref (widget);
4222 gtk_widget_push_verify_invariants (widget);
4224 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4225 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4227 /* a parent may now be expand=FALSE since we're hidden. */
4228 if (widget->priv->need_compute_expand ||
4229 widget->priv->computed_hexpand ||
4230 widget->priv->computed_vexpand)
4232 gtk_widget_queue_compute_expand (widget);
4235 g_signal_emit (widget, widget_signals[HIDE], 0);
4236 if (!gtk_widget_is_toplevel (widget))
4237 gtk_widget_queue_resize (widget);
4238 g_object_notify (G_OBJECT (widget), "visible");
4240 gtk_widget_pop_verify_invariants (widget);
4241 g_object_unref (widget);
4246 gtk_widget_real_hide (GtkWidget *widget)
4248 if (gtk_widget_get_visible (widget))
4250 widget->priv->visible = FALSE;
4252 if (gtk_widget_get_mapped (widget))
4253 gtk_widget_unmap (widget);
4258 * gtk_widget_hide_on_delete:
4259 * @widget: a #GtkWidget
4261 * Utility function; intended to be connected to the #GtkWidget::delete-event
4262 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4263 * argument, then returns %TRUE. If connected to ::delete-event, the
4264 * result is that clicking the close button for a window (on the
4265 * window frame, top right corner usually) will hide but not destroy
4266 * the window. By default, GTK+ destroys windows when ::delete-event
4269 * Return value: %TRUE
4272 gtk_widget_hide_on_delete (GtkWidget *widget)
4274 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4276 gtk_widget_hide (widget);
4282 * gtk_widget_show_all:
4283 * @widget: a #GtkWidget
4285 * Recursively shows a widget, and any child widgets (if the widget is
4289 gtk_widget_show_all (GtkWidget *widget)
4291 GtkWidgetClass *class;
4293 g_return_if_fail (GTK_IS_WIDGET (widget));
4295 if (gtk_widget_get_no_show_all (widget))
4298 class = GTK_WIDGET_GET_CLASS (widget);
4300 if (class->show_all)
4301 class->show_all (widget);
4306 * @widget: a #GtkWidget
4308 * This function is only for use in widget implementations. Causes
4309 * a widget to be mapped if it isn't already.
4312 gtk_widget_map (GtkWidget *widget)
4314 GtkWidgetPrivate *priv;
4316 g_return_if_fail (GTK_IS_WIDGET (widget));
4317 g_return_if_fail (gtk_widget_get_visible (widget));
4318 g_return_if_fail (gtk_widget_get_child_visible (widget));
4320 priv = widget->priv;
4322 if (!gtk_widget_get_mapped (widget))
4324 gtk_widget_push_verify_invariants (widget);
4326 if (!gtk_widget_get_realized (widget))
4327 gtk_widget_realize (widget);
4329 g_signal_emit (widget, widget_signals[MAP], 0);
4331 if (!gtk_widget_get_has_window (widget))
4332 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4334 if (widget->priv->context)
4335 _gtk_style_context_update_animating (widget->priv->context);
4337 gtk_widget_pop_verify_invariants (widget);
4343 * @widget: a #GtkWidget
4345 * This function is only for use in widget implementations. Causes
4346 * a widget to be unmapped if it's currently mapped.
4349 gtk_widget_unmap (GtkWidget *widget)
4351 GtkWidgetPrivate *priv;
4353 g_return_if_fail (GTK_IS_WIDGET (widget));
4355 priv = widget->priv;
4357 if (gtk_widget_get_mapped (widget))
4359 gtk_widget_push_verify_invariants (widget);
4361 if (!gtk_widget_get_has_window (widget))
4362 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4363 _gtk_tooltip_hide (widget);
4365 if (widget->priv->context)
4366 _gtk_style_context_update_animating (widget->priv->context);
4368 g_signal_emit (widget, widget_signals[UNMAP], 0);
4370 gtk_widget_pop_verify_invariants (widget);
4372 /* Unset pointer/window info */
4373 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4378 _gtk_widget_enable_device_events (GtkWidget *widget)
4380 GHashTable *device_events;
4381 GHashTableIter iter;
4382 gpointer key, value;
4384 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4389 g_hash_table_iter_init (&iter, device_events);
4391 while (g_hash_table_iter_next (&iter, &key, &value))
4394 GdkEventMask event_mask;
4397 event_mask = GPOINTER_TO_UINT (value);
4398 gtk_widget_add_events_internal (widget, device, event_mask);
4403 get_widget_windows (GtkWidget *widget)
4405 GList *window_list, *last, *l, *children, *ret;
4407 if (gtk_widget_get_has_window (widget))
4408 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4410 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4412 last = g_list_last (window_list);
4415 for (l = window_list; l; l = l->next)
4417 GtkWidget *window_widget = NULL;
4419 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4421 if (widget != window_widget)
4424 ret = g_list_prepend (ret, l->data);
4425 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4429 last = g_list_concat (last, children);
4430 last = g_list_last (last);
4434 g_list_free (window_list);
4440 device_enable_foreach (GtkWidget *widget,
4443 GdkDevice *device = user_data;
4444 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4448 device_disable_foreach (GtkWidget *widget,
4451 GdkDevice *device = user_data;
4452 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4456 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4461 GList *window_list, *l;
4463 window_list = get_widget_windows (widget);
4465 for (l = window_list; l; l = l->next)
4467 GdkEventMask events = 0;
4473 events = gdk_window_get_events (window);
4475 gdk_window_set_device_events (window, device, events);
4478 if (recurse && GTK_IS_CONTAINER (widget))
4481 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4483 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4486 g_list_free (window_list);
4490 gtk_widget_update_devices_mask (GtkWidget *widget,
4493 GList *enabled_devices, *l;
4495 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4497 for (l = enabled_devices; l; l = l->next)
4498 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4502 * gtk_widget_realize:
4503 * @widget: a #GtkWidget
4505 * Creates the GDK (windowing system) resources associated with a
4506 * widget. For example, @widget->window will be created when a widget
4507 * is realized. Normally realization happens implicitly; if you show
4508 * a widget and all its parent containers, then the widget will be
4509 * realized and mapped automatically.
4511 * Realizing a widget requires all
4512 * the widget's parent widgets to be realized; calling
4513 * gtk_widget_realize() realizes the widget's parents in addition to
4514 * @widget itself. If a widget is not yet inside a toplevel window
4515 * when you realize it, bad things will happen.
4517 * This function is primarily used in widget implementations, and
4518 * isn't very useful otherwise. Many times when you think you might
4519 * need it, a better approach is to connect to a signal that will be
4520 * called after the widget is realized automatically, such as
4521 * #GtkWidget::draw. Or simply g_signal_connect () to the
4522 * #GtkWidget::realize signal.
4525 gtk_widget_realize (GtkWidget *widget)
4527 GtkWidgetPrivate *priv;
4528 cairo_region_t *region;
4530 g_return_if_fail (GTK_IS_WIDGET (widget));
4531 g_return_if_fail (widget->priv->anchored ||
4532 GTK_IS_INVISIBLE (widget));
4534 priv = widget->priv;
4536 if (!gtk_widget_get_realized (widget))
4538 gtk_widget_push_verify_invariants (widget);
4541 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4542 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4545 if (priv->parent == NULL &&
4546 !gtk_widget_is_toplevel (widget))
4547 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4548 "inside a toplevel window is not going to work very well. "
4549 "Widgets must be inside a toplevel container before realizing them.");
4551 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4552 gtk_widget_realize (priv->parent);
4554 gtk_widget_ensure_style (widget);
4556 if (priv->style_update_pending)
4557 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4559 g_signal_emit (widget, widget_signals[REALIZE], 0);
4561 gtk_widget_real_set_has_tooltip (widget,
4562 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4565 if (priv->has_shape_mask)
4567 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4568 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4571 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4573 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4575 if (priv->multidevice)
4576 gdk_window_set_support_multidevice (priv->window, TRUE);
4578 _gtk_widget_enable_device_events (widget);
4579 gtk_widget_update_devices_mask (widget, TRUE);
4581 gtk_widget_pop_verify_invariants (widget);
4586 * gtk_widget_unrealize:
4587 * @widget: a #GtkWidget
4589 * This function is only useful in widget implementations.
4590 * Causes a widget to be unrealized (frees all GDK resources
4591 * associated with the widget, such as @widget->window).
4594 gtk_widget_unrealize (GtkWidget *widget)
4596 g_return_if_fail (GTK_IS_WIDGET (widget));
4598 gtk_widget_push_verify_invariants (widget);
4600 if (widget->priv->has_shape_mask)
4601 gtk_widget_shape_combine_region (widget, NULL);
4603 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4604 gtk_widget_input_shape_combine_region (widget, NULL);
4606 if (gtk_widget_get_realized (widget))
4608 g_object_ref (widget);
4610 if (widget->priv->mapped)
4611 gtk_widget_unmap (widget);
4613 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4614 g_assert (!widget->priv->mapped);
4615 gtk_widget_set_realized (widget, FALSE);
4617 g_object_unref (widget);
4620 gtk_widget_pop_verify_invariants (widget);
4623 /*****************************************
4625 *****************************************/
4628 * gtk_widget_queue_draw_region:
4629 * @widget: a #GtkWidget
4630 * @region: region to draw
4632 * Invalidates the rectangular area of @widget defined by @region by
4633 * calling gdk_window_invalidate_region() on the widget's window and
4634 * all its child windows. Once the main loop becomes idle (after the
4635 * current batch of events has been processed, roughly), the window
4636 * will receive expose events for the union of all regions that have
4639 * Normally you would only use this function in widget
4640 * implementations. You might also use it to schedule a redraw of a
4641 * #GtkDrawingArea or some portion thereof.
4646 gtk_widget_queue_draw_region (GtkWidget *widget,
4647 const cairo_region_t *region)
4649 GtkWidgetPrivate *priv;
4652 g_return_if_fail (GTK_IS_WIDGET (widget));
4654 priv = widget->priv;
4656 if (!gtk_widget_get_realized (widget))
4659 /* Just return if the widget or one of its ancestors isn't mapped */
4660 for (w = widget; w != NULL; w = w->priv->parent)
4661 if (!gtk_widget_get_mapped (w))
4664 gdk_window_invalidate_region (priv->window, region, TRUE);
4668 * gtk_widget_queue_draw_area:
4669 * @widget: a #GtkWidget
4670 * @x: x coordinate of upper-left corner of rectangle to redraw
4671 * @y: y coordinate of upper-left corner of rectangle to redraw
4672 * @width: width of region to draw
4673 * @height: height of region to draw
4675 * Convenience function that calls gtk_widget_queue_draw_region() on
4676 * the region created from the given coordinates.
4678 * The region here is specified in widget coordinates.
4679 * Widget coordinates are a bit odd; for historical reasons, they are
4680 * defined as @widget->window coordinates for widgets that are not
4681 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4682 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4685 gtk_widget_queue_draw_area (GtkWidget *widget,
4692 cairo_region_t *region;
4694 g_return_if_fail (GTK_IS_WIDGET (widget));
4699 rect.height = height;
4701 region = cairo_region_create_rectangle (&rect);
4702 gtk_widget_queue_draw_region (widget, region);
4703 cairo_region_destroy (region);
4707 * gtk_widget_queue_draw:
4708 * @widget: a #GtkWidget
4710 * Equivalent to calling gtk_widget_queue_draw_area() for the
4711 * entire area of a widget.
4714 gtk_widget_queue_draw (GtkWidget *widget)
4718 g_return_if_fail (GTK_IS_WIDGET (widget));
4720 gtk_widget_get_allocation (widget, &rect);
4722 if (!gtk_widget_get_has_window (widget))
4723 gtk_widget_queue_draw_area (widget,
4724 rect.x, rect.y, rect.width, rect.height);
4726 gtk_widget_queue_draw_area (widget,
4727 0, 0, rect.width, rect.height);
4731 * gtk_widget_queue_resize:
4732 * @widget: a #GtkWidget
4734 * This function is only for use in widget implementations.
4735 * Flags a widget to have its size renegotiated; should
4736 * be called when a widget for some reason has a new size request.
4737 * For example, when you change the text in a #GtkLabel, #GtkLabel
4738 * queues a resize to ensure there's enough space for the new text.
4740 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4741 * from inside its implementation of the GtkWidgetClass::size_allocate
4742 * virtual method. Calls to gtk_widget_queue_resize() from inside
4743 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4746 gtk_widget_queue_resize (GtkWidget *widget)
4748 g_return_if_fail (GTK_IS_WIDGET (widget));
4750 if (gtk_widget_get_realized (widget))
4751 gtk_widget_queue_draw (widget);
4753 _gtk_size_group_queue_resize (widget, 0);
4757 * gtk_widget_queue_resize_no_redraw:
4758 * @widget: a #GtkWidget
4760 * This function works like gtk_widget_queue_resize(),
4761 * except that the widget is not invalidated.
4766 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4768 g_return_if_fail (GTK_IS_WIDGET (widget));
4770 _gtk_size_group_queue_resize (widget, 0);
4774 * gtk_widget_size_request:
4775 * @widget: a #GtkWidget
4776 * @requisition: (out): a #GtkRequisition to be filled in
4778 * This function is typically used when implementing a #GtkContainer
4779 * subclass. Obtains the preferred size of a widget. The container
4780 * uses this information to arrange its child widgets and decide what
4781 * size allocations to give them with gtk_widget_size_allocate().
4783 * You can also call this function from an application, with some
4784 * caveats. Most notably, getting a size request requires the widget
4785 * to be associated with a screen, because font information may be
4786 * needed. Multihead-aware applications should keep this in mind.
4788 * Also remember that the size request is not necessarily the size
4789 * a widget will actually be allocated.
4791 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4794 gtk_widget_size_request (GtkWidget *widget,
4795 GtkRequisition *requisition)
4797 g_return_if_fail (GTK_IS_WIDGET (widget));
4799 gtk_widget_get_preferred_size (widget, requisition, NULL);
4803 * gtk_widget_get_child_requisition:
4804 * @widget: a #GtkWidget
4805 * @requisition: (out): a #GtkRequisition to be filled in
4807 * This function is only for use in widget implementations. Obtains
4808 * @widget->requisition, unless someone has forced a particular
4809 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4810 * in which case it returns that geometry instead of the widget's
4813 * This function differs from gtk_widget_size_request() in that
4814 * it retrieves the last size request value from @widget->requisition,
4815 * while gtk_widget_size_request() actually calls the "size_request" method
4816 * on @widget to compute the size request and fill in @widget->requisition,
4817 * and only then returns @widget->requisition.
4819 * Because this function does not call the "size_request" method, it
4820 * can only be used when you know that @widget->requisition is
4821 * up-to-date, that is, gtk_widget_size_request() has been called
4822 * since the last time a resize was queued. In general, only container
4823 * implementations have this information; applications should use
4824 * gtk_widget_size_request().
4827 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4830 gtk_widget_get_child_requisition (GtkWidget *widget,
4831 GtkRequisition *requisition)
4833 gtk_widget_get_preferred_size (widget, requisition, NULL);
4837 invalidate_predicate (GdkWindow *window,
4842 gdk_window_get_user_data (window, &user_data);
4844 return (user_data == data);
4847 /* Invalidate @region in widget->window and all children
4848 * of widget->window owned by widget. @region is in the
4849 * same coordinates as widget->allocation and will be
4850 * modified by this call.
4853 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4854 cairo_region_t *region)
4856 GtkWidgetPrivate *priv = widget->priv;
4858 if (!gtk_widget_get_realized (widget))
4861 if (gtk_widget_get_has_window (widget) && priv->parent)
4865 gdk_window_get_position (priv->window, &x, &y);
4866 cairo_region_translate (region, -x, -y);
4869 gdk_window_invalidate_maybe_recurse (priv->window, region,
4870 invalidate_predicate, widget);
4874 * gtk_widget_size_allocate:
4875 * @widget: a #GtkWidget
4876 * @allocation: position and size to be allocated to @widget
4878 * This function is only used by #GtkContainer subclasses, to assign a size
4879 * and position to their child widgets.
4881 * In this function, the allocation may be adjusted. It will be forced
4882 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4883 * method on the child will be used to adjust the allocation. Standard
4884 * adjustments include removing the widget's margins, and applying the
4885 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4888 gtk_widget_size_allocate (GtkWidget *widget,
4889 GtkAllocation *allocation)
4891 GtkWidgetPrivate *priv;
4892 GdkRectangle real_allocation;
4893 GdkRectangle old_allocation;
4894 GdkRectangle adjusted_allocation;
4895 gboolean alloc_needed;
4896 gboolean size_changed;
4897 gboolean position_changed;
4898 gint natural_width, natural_height, dummy;
4899 gint min_width, min_height;
4901 priv = widget->priv;
4903 g_return_if_fail (GTK_IS_WIDGET (widget));
4905 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4908 gtk_widget_push_verify_invariants (widget);
4910 #ifdef G_ENABLE_DEBUG
4911 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4922 parent = gtk_widget_get_parent (parent);
4925 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4926 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4927 2 * depth, " ", name,
4928 allocation->width, allocation->height);
4930 #endif /* G_ENABLE_DEBUG */
4932 alloc_needed = priv->alloc_needed;
4933 /* Preserve request/allocate ordering */
4934 priv->alloc_needed = FALSE;
4936 old_allocation = priv->allocation;
4937 real_allocation = *allocation;
4939 adjusted_allocation = real_allocation;
4940 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4942 /* Go ahead and request the height for allocated width, note that the internals
4943 * of get_height_for_width will internally limit the for_size to natural size
4944 * when aligning implicitly.
4946 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4947 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4951 /* Go ahead and request the width for allocated height, note that the internals
4952 * of get_width_for_height will internally limit the for_size to natural size
4953 * when aligning implicitly.
4955 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4956 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4959 #ifdef G_ENABLE_DEBUG
4960 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4962 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4963 !GTK_IS_SCROLLABLE (widget))
4964 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4965 "Allocation is %dx%d, but minimum required size is %dx%d.",
4966 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4967 G_OBJECT_TYPE_NAME (widget), widget,
4968 real_allocation.width, real_allocation.height,
4969 min_width, min_height);
4972 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4973 * allocated sizes and possibly limit them to the natural sizes */
4974 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4975 GTK_ORIENTATION_HORIZONTAL,
4978 &adjusted_allocation.x,
4979 &adjusted_allocation.width);
4980 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4981 GTK_ORIENTATION_VERTICAL,
4984 &adjusted_allocation.y,
4985 &adjusted_allocation.height);
4987 if (adjusted_allocation.x < real_allocation.x ||
4988 adjusted_allocation.y < real_allocation.y ||
4989 (adjusted_allocation.x + adjusted_allocation.width) >
4990 (real_allocation.x + real_allocation.width) ||
4991 (adjusted_allocation.y + adjusted_allocation.height >
4992 real_allocation.y + real_allocation.height))
4994 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",
4995 G_OBJECT_TYPE_NAME (widget), widget,
4996 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4997 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4998 adjusted_allocation = real_allocation; /* veto it */
5002 real_allocation = adjusted_allocation;
5005 if (real_allocation.width < 0 || real_allocation.height < 0)
5007 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5008 real_allocation.width,
5009 real_allocation.height);
5012 real_allocation.width = MAX (real_allocation.width, 1);
5013 real_allocation.height = MAX (real_allocation.height, 1);
5015 size_changed = (old_allocation.width != real_allocation.width ||
5016 old_allocation.height != real_allocation.height);
5017 position_changed = (old_allocation.x != real_allocation.x ||
5018 old_allocation.y != real_allocation.y);
5020 if (!alloc_needed && !size_changed && !position_changed)
5023 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5025 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5026 priv->alloc_needed = FALSE;
5028 if (gtk_widget_get_mapped (widget))
5030 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5032 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5034 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5035 cairo_region_union_rectangle (invalidate, &old_allocation);
5037 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5038 cairo_region_destroy (invalidate);
5043 if (priv->redraw_on_alloc)
5045 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5047 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5048 cairo_region_union_rectangle (invalidate, &old_allocation);
5050 gtk_widget_invalidate_widget_windows (widget, invalidate);
5051 cairo_region_destroy (invalidate);
5056 if ((size_changed || position_changed) && priv->parent &&
5057 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5059 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5060 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5061 cairo_region_destroy (invalidate);
5065 gtk_widget_pop_verify_invariants (widget);
5069 * gtk_widget_common_ancestor:
5070 * @widget_a: a #GtkWidget
5071 * @widget_b: a #GtkWidget
5073 * Find the common ancestor of @widget_a and @widget_b that
5074 * is closest to the two widgets.
5076 * Return value: the closest common ancestor of @widget_a and
5077 * @widget_b or %NULL if @widget_a and @widget_b do not
5078 * share a common ancestor.
5081 gtk_widget_common_ancestor (GtkWidget *widget_a,
5082 GtkWidget *widget_b)
5084 GtkWidget *parent_a;
5085 GtkWidget *parent_b;
5089 parent_a = widget_a;
5090 while (parent_a->priv->parent)
5092 parent_a = parent_a->priv->parent;
5096 parent_b = widget_b;
5097 while (parent_b->priv->parent)
5099 parent_b = parent_b->priv->parent;
5103 if (parent_a != parent_b)
5106 while (depth_a > depth_b)
5108 widget_a = widget_a->priv->parent;
5112 while (depth_b > depth_a)
5114 widget_b = widget_b->priv->parent;
5118 while (widget_a != widget_b)
5120 widget_a = widget_a->priv->parent;
5121 widget_b = widget_b->priv->parent;
5128 * gtk_widget_translate_coordinates:
5129 * @src_widget: a #GtkWidget
5130 * @dest_widget: a #GtkWidget
5131 * @src_x: X position relative to @src_widget
5132 * @src_y: Y position relative to @src_widget
5133 * @dest_x: (out): location to store X position relative to @dest_widget
5134 * @dest_y: (out): location to store Y position relative to @dest_widget
5136 * Translate coordinates relative to @src_widget's allocation to coordinates
5137 * relative to @dest_widget's allocations. In order to perform this
5138 * operation, both widgets must be realized, and must share a common
5141 * Return value: %FALSE if either widget was not realized, or there
5142 * was no common ancestor. In this case, nothing is stored in
5143 * *@dest_x and *@dest_y. Otherwise %TRUE.
5146 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5147 GtkWidget *dest_widget,
5153 GtkWidgetPrivate *src_priv = src_widget->priv;
5154 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5155 GtkWidget *ancestor;
5157 GList *dest_list = NULL;
5159 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5160 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5162 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5163 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5166 /* Translate from allocation relative to window relative */
5167 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5170 gdk_window_get_position (src_priv->window, &wx, &wy);
5172 src_x -= wx - src_priv->allocation.x;
5173 src_y -= wy - src_priv->allocation.y;
5177 src_x += src_priv->allocation.x;
5178 src_y += src_priv->allocation.y;
5181 /* Translate to the common ancestor */
5182 window = src_priv->window;
5183 while (window != ancestor->priv->window)
5187 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5192 window = gdk_window_get_effective_parent (window);
5194 if (!window) /* Handle GtkHandleBox */
5199 window = dest_priv->window;
5200 while (window != ancestor->priv->window)
5202 dest_list = g_list_prepend (dest_list, window);
5204 window = gdk_window_get_effective_parent (window);
5206 if (!window) /* Handle GtkHandleBox */
5208 g_list_free (dest_list);
5217 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5222 dest_list = g_list_remove (dest_list, dest_list->data);
5225 /* Translate from window relative to allocation relative */
5226 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5229 gdk_window_get_position (dest_priv->window, &wx, &wy);
5231 src_x += wx - dest_priv->allocation.x;
5232 src_y += wy - dest_priv->allocation.y;
5236 src_x -= dest_priv->allocation.x;
5237 src_y -= dest_priv->allocation.y;
5249 gtk_widget_real_size_allocate (GtkWidget *widget,
5250 GtkAllocation *allocation)
5252 GtkWidgetPrivate *priv = widget->priv;
5254 priv->allocation = *allocation;
5256 if (gtk_widget_get_realized (widget) &&
5257 gtk_widget_get_has_window (widget))
5259 gdk_window_move_resize (priv->window,
5260 allocation->x, allocation->y,
5261 allocation->width, allocation->height);
5265 /* translate initial/final into start/end */
5267 effective_align (GtkAlign align,
5268 GtkTextDirection direction)
5272 case GTK_ALIGN_START:
5273 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5275 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5282 adjust_for_align (GtkAlign align,
5284 gint *allocated_pos,
5285 gint *allocated_size)
5289 case GTK_ALIGN_FILL:
5290 /* change nothing */
5292 case GTK_ALIGN_START:
5293 /* keep *allocated_pos where it is */
5294 *allocated_size = MIN (*allocated_size, *natural_size);
5297 if (*allocated_size > *natural_size)
5299 *allocated_pos += (*allocated_size - *natural_size);
5300 *allocated_size = *natural_size;
5303 case GTK_ALIGN_CENTER:
5304 if (*allocated_size > *natural_size)
5306 *allocated_pos += (*allocated_size - *natural_size) / 2;
5307 *allocated_size = MIN (*allocated_size, *natural_size);
5314 adjust_for_margin(gint start_margin,
5318 gint *allocated_pos,
5319 gint *allocated_size)
5321 *minimum_size -= (start_margin + end_margin);
5322 *natural_size -= (start_margin + end_margin);
5323 *allocated_pos += start_margin;
5324 *allocated_size -= (start_margin + end_margin);
5328 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5329 GtkOrientation orientation,
5332 gint *allocated_pos,
5333 gint *allocated_size)
5335 const GtkWidgetAuxInfo *aux_info;
5337 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5339 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5341 adjust_for_margin (aux_info->margin.left,
5342 aux_info->margin.right,
5343 minimum_size, natural_size,
5344 allocated_pos, allocated_size);
5345 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5346 natural_size, allocated_pos, allocated_size);
5350 adjust_for_margin (aux_info->margin.top,
5351 aux_info->margin.bottom,
5352 minimum_size, natural_size,
5353 allocated_pos, allocated_size);
5354 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5355 natural_size, allocated_pos, allocated_size);
5360 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5363 GtkWidgetPrivate *priv = widget->priv;
5365 /* widgets must be onscreen for accels to take effect */
5366 return gtk_widget_is_sensitive (widget) &&
5367 gtk_widget_is_drawable (widget) &&
5368 gdk_window_is_viewable (priv->window);
5372 * gtk_widget_can_activate_accel:
5373 * @widget: a #GtkWidget
5374 * @signal_id: the ID of a signal installed on @widget
5376 * Determines whether an accelerator that activates the signal
5377 * identified by @signal_id can currently be activated.
5378 * This is done by emitting the #GtkWidget::can-activate-accel
5379 * signal on @widget; if the signal isn't overridden by a
5380 * handler or in a derived widget, then the default check is
5381 * that the widget must be sensitive, and the widget and all
5382 * its ancestors mapped.
5384 * Return value: %TRUE if the accelerator can be activated.
5389 gtk_widget_can_activate_accel (GtkWidget *widget,
5392 gboolean can_activate = FALSE;
5393 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5394 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5395 return can_activate;
5404 closure_accel_activate (GClosure *closure,
5405 GValue *return_value,
5406 guint n_param_values,
5407 const GValue *param_values,
5408 gpointer invocation_hint,
5409 gpointer marshal_data)
5411 AccelClosure *aclosure = (AccelClosure*) closure;
5412 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5415 g_signal_emit (closure->data, aclosure->signal_id, 0);
5417 /* whether accelerator was handled */
5418 g_value_set_boolean (return_value, can_activate);
5422 closures_destroy (gpointer data)
5424 GSList *slist, *closures = data;
5426 for (slist = closures; slist; slist = slist->next)
5428 g_closure_invalidate (slist->data);
5429 g_closure_unref (slist->data);
5431 g_slist_free (closures);
5435 widget_new_accel_closure (GtkWidget *widget,
5438 AccelClosure *aclosure;
5439 GClosure *closure = NULL;
5440 GSList *slist, *closures;
5442 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5443 for (slist = closures; slist; slist = slist->next)
5444 if (!gtk_accel_group_from_accel_closure (slist->data))
5446 /* reuse this closure */
5447 closure = slist->data;
5452 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5453 closures = g_slist_prepend (closures, g_closure_ref (closure));
5454 g_closure_sink (closure);
5455 g_closure_set_marshal (closure, closure_accel_activate);
5457 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5459 aclosure = (AccelClosure*) closure;
5460 g_assert (closure->data == widget);
5461 g_assert (closure->marshal == closure_accel_activate);
5462 aclosure->signal_id = signal_id;
5468 * gtk_widget_add_accelerator:
5469 * @widget: widget to install an accelerator on
5470 * @accel_signal: widget signal to emit on accelerator activation
5471 * @accel_group: accel group for this widget, added to its toplevel
5472 * @accel_key: GDK keyval of the accelerator
5473 * @accel_mods: modifier key combination of the accelerator
5474 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5476 * Installs an accelerator for this @widget in @accel_group that causes
5477 * @accel_signal to be emitted if the accelerator is activated.
5478 * The @accel_group needs to be added to the widget's toplevel via
5479 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5480 * Accelerators added through this function are not user changeable during
5481 * runtime. If you want to support accelerators that can be changed by the
5482 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5483 * gtk_menu_item_set_accel_path() instead.
5486 gtk_widget_add_accelerator (GtkWidget *widget,
5487 const gchar *accel_signal,
5488 GtkAccelGroup *accel_group,
5490 GdkModifierType accel_mods,
5491 GtkAccelFlags accel_flags)
5496 g_return_if_fail (GTK_IS_WIDGET (widget));
5497 g_return_if_fail (accel_signal != NULL);
5498 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5500 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5501 if (!query.signal_id ||
5502 !(query.signal_flags & G_SIGNAL_ACTION) ||
5503 query.return_type != G_TYPE_NONE ||
5506 /* hmm, should be elaborate enough */
5507 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5508 G_OBJECT_TYPE_NAME (widget), accel_signal);
5512 closure = widget_new_accel_closure (widget, query.signal_id);
5514 g_object_ref (widget);
5516 /* install the accelerator. since we don't map this onto an accel_path,
5517 * the accelerator will automatically be locked.
5519 gtk_accel_group_connect (accel_group,
5522 accel_flags | GTK_ACCEL_LOCKED,
5525 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5527 g_object_unref (widget);
5531 * gtk_widget_remove_accelerator:
5532 * @widget: widget to install an accelerator on
5533 * @accel_group: accel group for this widget
5534 * @accel_key: GDK keyval of the accelerator
5535 * @accel_mods: modifier key combination of the accelerator
5537 * Removes an accelerator from @widget, previously installed with
5538 * gtk_widget_add_accelerator().
5540 * Returns: whether an accelerator was installed and could be removed
5543 gtk_widget_remove_accelerator (GtkWidget *widget,
5544 GtkAccelGroup *accel_group,
5546 GdkModifierType accel_mods)
5548 GtkAccelGroupEntry *ag_entry;
5549 GList *slist, *clist;
5552 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5553 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5555 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5556 clist = gtk_widget_list_accel_closures (widget);
5557 for (slist = clist; slist; slist = slist->next)
5561 for (i = 0; i < n; i++)
5562 if (slist->data == (gpointer) ag_entry[i].closure)
5564 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5566 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5568 g_list_free (clist);
5573 g_list_free (clist);
5575 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5576 accel_key, accel_mods, accel_group,
5577 G_OBJECT_TYPE_NAME (widget), widget);
5583 * gtk_widget_list_accel_closures:
5584 * @widget: widget to list accelerator closures for
5586 * Lists the closures used by @widget for accelerator group connections
5587 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5588 * The closures can be used to monitor accelerator changes on @widget,
5589 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5590 * #GtkAccelGroup of a closure which can be found out with
5591 * gtk_accel_group_from_accel_closure().
5593 * Return value: (transfer container) (element-type GClosure):
5594 * a newly allocated #GList of closures
5597 gtk_widget_list_accel_closures (GtkWidget *widget)
5600 GList *clist = NULL;
5602 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5604 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5605 if (gtk_accel_group_from_accel_closure (slist->data))
5606 clist = g_list_prepend (clist, slist->data);
5612 GtkAccelGroup *accel_group;
5617 destroy_accel_path (gpointer data)
5619 AccelPath *apath = data;
5621 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5623 /* closures_destroy takes care of unrefing the closure */
5624 g_object_unref (apath->accel_group);
5626 g_slice_free (AccelPath, apath);
5631 * gtk_widget_set_accel_path:
5632 * @widget: a #GtkWidget
5633 * @accel_path: (allow-none): path used to look up the accelerator
5634 * @accel_group: (allow-none): a #GtkAccelGroup.
5636 * Given an accelerator group, @accel_group, and an accelerator path,
5637 * @accel_path, sets up an accelerator in @accel_group so whenever the
5638 * key binding that is defined for @accel_path is pressed, @widget
5639 * will be activated. This removes any accelerators (for any
5640 * accelerator group) installed by previous calls to
5641 * gtk_widget_set_accel_path(). Associating accelerators with
5642 * paths allows them to be modified by the user and the modifications
5643 * to be saved for future use. (See gtk_accel_map_save().)
5645 * This function is a low level function that would most likely
5646 * be used by a menu creation system like #GtkUIManager. If you
5647 * use #GtkUIManager, setting up accelerator paths will be done
5650 * Even when you you aren't using #GtkUIManager, if you only want to
5651 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5652 * provides a somewhat more convenient interface.
5654 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5655 * pass a static string, you can save some memory by interning it first with
5656 * g_intern_static_string().
5659 gtk_widget_set_accel_path (GtkWidget *widget,
5660 const gchar *accel_path,
5661 GtkAccelGroup *accel_group)
5665 g_return_if_fail (GTK_IS_WIDGET (widget));
5666 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5670 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5671 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5673 gtk_accel_map_add_entry (accel_path, 0, 0);
5674 apath = g_slice_new (AccelPath);
5675 apath->accel_group = g_object_ref (accel_group);
5676 apath->path_quark = g_quark_from_string (accel_path);
5677 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5682 /* also removes possible old settings */
5683 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5686 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5688 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5692 _gtk_widget_get_accel_path (GtkWidget *widget,
5697 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5699 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5701 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5702 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5706 * gtk_widget_mnemonic_activate:
5707 * @widget: a #GtkWidget
5708 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5710 * Emits the #GtkWidget::mnemonic-activate signal.
5712 * The default handler for this signal activates the @widget if
5713 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5716 * Returns: %TRUE if the signal has been handled
5719 gtk_widget_mnemonic_activate (GtkWidget *widget,
5720 gboolean group_cycling)
5724 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5726 group_cycling = group_cycling != FALSE;
5727 if (!gtk_widget_is_sensitive (widget))
5730 g_signal_emit (widget,
5731 widget_signals[MNEMONIC_ACTIVATE],
5739 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5740 gboolean group_cycling)
5742 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5743 gtk_widget_activate (widget);
5744 else if (gtk_widget_get_can_focus (widget))
5745 gtk_widget_grab_focus (widget);
5748 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5749 G_OBJECT_TYPE_NAME (widget));
5750 gtk_widget_error_bell (widget);
5755 static const cairo_user_data_key_t event_key;
5758 _gtk_cairo_get_event (cairo_t *cr)
5760 g_return_val_if_fail (cr != NULL, NULL);
5762 return cairo_get_user_data (cr, &event_key);
5766 gtk_cairo_set_event (cairo_t *cr,
5767 GdkEventExpose *event)
5769 cairo_set_user_data (cr, &event_key, event, NULL);
5773 * gtk_cairo_should_draw_window:
5774 * @cr: a cairo context
5775 * @window: the window to check. @window may not be an input-only
5778 * This function is supposed to be called in #GtkWidget::draw
5779 * implementations for widgets that support multiple windows.
5780 * @cr must be untransformed from invoking of the draw function.
5781 * This function will return %TRUE if the contents of the given
5782 * @window are supposed to be drawn and %FALSE otherwise. Note
5783 * that when the drawing was not initiated by the windowing
5784 * system this function will return %TRUE for all windows, so
5785 * you need to draw the bottommost window first. Also, do not
5786 * use "else if" statements to check which window should be drawn.
5788 * Returns: %TRUE if @window should be drawn
5793 gtk_cairo_should_draw_window (cairo_t *cr,
5796 GdkEventExpose *event;
5798 g_return_val_if_fail (cr != NULL, FALSE);
5799 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5801 event = _gtk_cairo_get_event (cr);
5803 return event == NULL ||
5804 event->window == window;
5808 gtk_widget_get_clip_draw (GtkWidget *widget)
5810 /* labels are not clipped, because clipping them would cause
5811 * mnemonics to not appear on characters that go beyond the
5813 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5815 if (GTK_IS_LABEL (widget))
5821 /* code shared by gtk_container_propagate_draw() and
5825 _gtk_widget_draw_internal (GtkWidget *widget,
5827 gboolean clip_to_size)
5829 if (!gtk_widget_is_drawable (widget))
5832 clip_to_size &= gtk_widget_get_clip_draw (widget);
5836 cairo_rectangle (cr,
5838 widget->priv->allocation.width,
5839 widget->priv->allocation.height);
5843 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5847 g_signal_emit (widget, widget_signals[DRAW],
5851 if (cairo_status (cr) &&
5852 _gtk_cairo_get_event (cr))
5854 /* We check the event so we only warn about internal GTK calls.
5855 * Errors might come from PDF streams having write failures and
5856 * we don't want to spam stderr in that case.
5857 * We do want to catch errors from
5859 g_warning ("drawing failure for widget `%s': %s",
5860 G_OBJECT_TYPE_NAME (widget),
5861 cairo_status_to_string (cairo_status (cr)));
5868 * @widget: the widget to draw. It must be drawable (see
5869 * gtk_widget_is_drawable()) and a size must have been allocated.
5870 * @cr: a cairo context to draw to
5872 * Draws @widget to @cr. The top left corner of the widget will be
5873 * drawn to the currently set origin point of @cr.
5875 * You should pass a cairo context as @cr argument that is in an
5876 * original state. Otherwise the resulting drawing is undefined. For
5877 * example changing the operator using cairo_set_operator() or the
5878 * line width using cairo_set_line_width() might have unwanted side
5880 * You may however change the context's transform matrix - like with
5881 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5882 * region with cairo_clip() prior to calling this function. Also, it
5883 * is fine to modify the context with cairo_save() and
5884 * cairo_push_group() prior to calling this function.
5886 * <note><para>Special purpose widgets may contain special code for
5887 * rendering to the screen and might appear differently on screen
5888 * and when rendered using gtk_widget_draw().</para></note>
5893 gtk_widget_draw (GtkWidget *widget,
5896 GdkEventExpose *tmp_event;
5898 g_return_if_fail (GTK_IS_WIDGET (widget));
5899 g_return_if_fail (!widget->priv->alloc_needed);
5900 g_return_if_fail (cr != NULL);
5903 /* We have to reset the event here so that draw functions can call
5904 * gtk_widget_draw() on random other widgets and get the desired
5905 * effect: Drawing all contents, not just the current window.
5907 tmp_event = _gtk_cairo_get_event (cr);
5908 gtk_cairo_set_event (cr, NULL);
5910 _gtk_widget_draw_internal (widget, cr, TRUE);
5912 gtk_cairo_set_event (cr, tmp_event);
5917 gtk_widget_real_key_press_event (GtkWidget *widget,
5920 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5924 gtk_widget_real_key_release_event (GtkWidget *widget,
5927 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5931 gtk_widget_real_focus_in_event (GtkWidget *widget,
5932 GdkEventFocus *event)
5934 gtk_widget_queue_draw (widget);
5940 gtk_widget_real_focus_out_event (GtkWidget *widget,
5941 GdkEventFocus *event)
5943 gtk_widget_queue_draw (widget);
5949 gtk_widget_real_touch_event (GtkWidget *widget,
5950 GdkEventTouch *event)
5953 gboolean return_val;
5956 if (!event->emulating_pointer)
5959 if (event->type == GDK_TOUCH_BEGIN ||
5960 event->type == GDK_TOUCH_END)
5964 if (event->type == GDK_TOUCH_BEGIN)
5966 type = GDK_BUTTON_PRESS;
5967 signum = BUTTON_PRESS_EVENT;
5971 type = GDK_BUTTON_RELEASE;
5972 signum = BUTTON_RELEASE_EVENT;
5974 bevent = gdk_event_new (type);
5975 bevent->any.window = g_object_ref (event->window);
5976 bevent->any.send_event = FALSE;
5977 bevent->button.time = event->time;
5978 bevent->button.state = event->state;
5979 bevent->button.button = 1;
5980 bevent->button.x_root = event->x_root;
5981 bevent->button.y_root = event->y_root;
5982 bevent->button.x = event->x;
5983 bevent->button.y = event->y;
5984 bevent->button.device = event->device;
5985 bevent->button.axes = g_memdup (event->axes,
5986 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5987 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5989 else if (event->type == GDK_TOUCH_UPDATE)
5991 signum = MOTION_NOTIFY_EVENT;
5992 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
5993 bevent->any.window = g_object_ref (event->window);
5994 bevent->any.send_event = FALSE;
5995 bevent->motion.time = event->time;
5996 bevent->motion.state = event->state;
5997 bevent->motion.x_root = event->x_root;
5998 bevent->motion.y_root = event->y_root;
5999 bevent->motion.x = event->x;
6000 bevent->motion.y = event->y;
6001 bevent->motion.device = event->device;
6002 bevent->motion.is_hint = FALSE;
6003 bevent->motion.axes = g_memdup (event->axes,
6004 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6005 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6010 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6012 gdk_event_free (bevent);
6018 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6019 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6023 * @widget: a #GtkWidget
6024 * @event: a #GdkEvent
6026 * Rarely-used function. This function is used to emit
6027 * the event signals on a widget (those signals should never
6028 * be emitted without using this function to do so).
6029 * If you want to synthesize an event though, don't use this function;
6030 * instead, use gtk_main_do_event() so the event will behave as if
6031 * it were in the event queue. Don't synthesize expose events; instead,
6032 * use gdk_window_invalidate_rect() to invalidate a region of the
6035 * Return value: return from the event signal emission (%TRUE if
6036 * the event was handled)
6039 gtk_widget_event (GtkWidget *widget,
6042 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6043 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6045 if (event->type == GDK_EXPOSE)
6047 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6048 "the same effect, call gdk_window_invalidate_rect/region(), "
6049 "followed by gdk_window_process_updates().");
6053 return gtk_widget_event_internal (widget, event);
6057 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6058 GtkCapturedEventHandler callback)
6060 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6064 _gtk_widget_captured_event (GtkWidget *widget,
6067 gboolean return_val = FALSE;
6068 GtkCapturedEventHandler handler;
6070 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6071 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6073 if (event->type == GDK_EXPOSE)
6075 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6076 "the same effect, call gdk_window_invalidate_rect/region(), "
6077 "followed by gdk_window_process_updates().");
6081 if (!event_window_is_still_viewable (event))
6084 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6088 g_object_ref (widget);
6090 return_val = handler (widget, event);
6091 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6093 /* The widget that was originally to receive the event
6094 * handles motion hints, but the capturing widget might
6095 * not, so ensure we get further motion events.
6098 event->type == GDK_MOTION_NOTIFY &&
6099 event->motion.is_hint &&
6100 (gdk_window_get_events (event->any.window) &
6101 GDK_POINTER_MOTION_HINT_MASK) != 0)
6102 gdk_event_request_motions (&event->motion);
6104 g_object_unref (widget);
6109 /* Returns TRUE if a translation should be done */
6111 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6116 GdkWindow *w, *widget_window;
6118 if (!gtk_widget_get_has_window (widget))
6120 *x = -widget->priv->allocation.x;
6121 *y = -widget->priv->allocation.y;
6129 widget_window = gtk_widget_get_window (widget);
6131 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6134 gdk_window_get_position (w, &wx, &wy);
6151 * gtk_cairo_transform_to_window:
6152 * @cr: the cairo context to transform
6153 * @widget: the widget the context is currently centered for
6154 * @window: the window to transform the context to
6156 * Transforms the given cairo context @cr that from @widget-relative
6157 * coordinates to @window-relative coordinates.
6158 * If the @widget's window is not an ancestor of @window, no
6159 * modification will be applied.
6161 * This is the inverse to the transformation GTK applies when
6162 * preparing an expose event to be emitted with the #GtkWidget::draw
6163 * signal. It is intended to help porting multiwindow widgets from
6164 * GTK+ 2 to the rendering architecture of GTK+ 3.
6169 gtk_cairo_transform_to_window (cairo_t *cr,
6175 g_return_if_fail (cr != NULL);
6176 g_return_if_fail (GTK_IS_WIDGET (widget));
6177 g_return_if_fail (GDK_IS_WINDOW (window));
6179 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6180 cairo_translate (cr, x, y);
6184 * gtk_widget_send_expose:
6185 * @widget: a #GtkWidget
6186 * @event: a expose #GdkEvent
6188 * Very rarely-used function. This function is used to emit
6189 * an expose event on a widget. This function is not normally used
6190 * directly. The only time it is used is when propagating an expose
6191 * event to a child %NO_WINDOW widget, and that is normally done
6192 * using gtk_container_propagate_draw().
6194 * If you want to force an area of a window to be redrawn,
6195 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6196 * To cause the redraw to be done immediately, follow that call
6197 * with a call to gdk_window_process_updates().
6199 * Return value: return from the event signal emission (%TRUE if
6200 * the event was handled)
6203 gtk_widget_send_expose (GtkWidget *widget,
6206 gboolean result = FALSE;
6211 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6212 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6213 g_return_val_if_fail (event != NULL, TRUE);
6214 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6216 cr = gdk_cairo_create (event->expose.window);
6217 gtk_cairo_set_event (cr, &event->expose);
6219 gdk_cairo_region (cr, event->expose.region);
6222 do_clip = _gtk_widget_get_translation_to_window (widget,
6223 event->expose.window,
6225 cairo_translate (cr, -x, -y);
6227 _gtk_widget_draw_internal (widget, cr, do_clip);
6229 /* unset here, so if someone keeps a reference to cr we
6230 * don't leak the window. */
6231 gtk_cairo_set_event (cr, NULL);
6238 event_window_is_still_viewable (GdkEvent *event)
6240 /* Check that we think the event's window is viewable before
6241 * delivering the event, to prevent suprises. We do this here
6242 * at the last moment, since the event may have been queued
6243 * up behind other events, held over a recursive main loop, etc.
6245 switch (event->type)
6248 case GDK_MOTION_NOTIFY:
6249 case GDK_BUTTON_PRESS:
6250 case GDK_2BUTTON_PRESS:
6251 case GDK_3BUTTON_PRESS:
6253 case GDK_ENTER_NOTIFY:
6254 case GDK_PROXIMITY_IN:
6256 return event->any.window && gdk_window_is_viewable (event->any.window);
6259 /* The following events are the second half of paired events;
6260 * we always deliver them to deal with widgets that clean up
6261 * on the second half.
6263 case GDK_BUTTON_RELEASE:
6264 case GDK_KEY_RELEASE:
6265 case GDK_LEAVE_NOTIFY:
6266 case GDK_PROXIMITY_OUT:
6270 /* Remaining events would make sense on an not-viewable window,
6271 * or don't have an associated window.
6278 gtk_widget_event_internal (GtkWidget *widget,
6281 gboolean return_val = FALSE;
6283 /* We check only once for is-still-visible; if someone
6284 * hides the window in on of the signals on the widget,
6285 * they are responsible for returning TRUE to terminate
6288 if (!event_window_is_still_viewable (event))
6291 g_object_ref (widget);
6293 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6294 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6299 switch (event->type)
6305 case GDK_BUTTON_PRESS:
6306 case GDK_2BUTTON_PRESS:
6307 case GDK_3BUTTON_PRESS:
6308 signal_num = BUTTON_PRESS_EVENT;
6310 case GDK_TOUCH_BEGIN:
6311 case GDK_TOUCH_UPDATE:
6313 case GDK_TOUCH_CANCEL:
6314 signal_num = TOUCH_EVENT;
6317 signal_num = SCROLL_EVENT;
6319 case GDK_BUTTON_RELEASE:
6320 signal_num = BUTTON_RELEASE_EVENT;
6322 case GDK_MOTION_NOTIFY:
6323 signal_num = MOTION_NOTIFY_EVENT;
6326 signal_num = DELETE_EVENT;
6329 signal_num = DESTROY_EVENT;
6330 _gtk_tooltip_hide (widget);
6333 signal_num = KEY_PRESS_EVENT;
6335 case GDK_KEY_RELEASE:
6336 signal_num = KEY_RELEASE_EVENT;
6338 case GDK_ENTER_NOTIFY:
6339 signal_num = ENTER_NOTIFY_EVENT;
6341 case GDK_LEAVE_NOTIFY:
6342 signal_num = LEAVE_NOTIFY_EVENT;
6344 case GDK_FOCUS_CHANGE:
6345 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6346 if (event->focus_change.in)
6347 _gtk_tooltip_focus_in (widget);
6349 _gtk_tooltip_focus_out (widget);
6352 signal_num = CONFIGURE_EVENT;
6355 signal_num = MAP_EVENT;
6358 signal_num = UNMAP_EVENT;
6360 case GDK_WINDOW_STATE:
6361 signal_num = WINDOW_STATE_EVENT;
6363 case GDK_PROPERTY_NOTIFY:
6364 signal_num = PROPERTY_NOTIFY_EVENT;
6366 case GDK_SELECTION_CLEAR:
6367 signal_num = SELECTION_CLEAR_EVENT;
6369 case GDK_SELECTION_REQUEST:
6370 signal_num = SELECTION_REQUEST_EVENT;
6372 case GDK_SELECTION_NOTIFY:
6373 signal_num = SELECTION_NOTIFY_EVENT;
6375 case GDK_PROXIMITY_IN:
6376 signal_num = PROXIMITY_IN_EVENT;
6378 case GDK_PROXIMITY_OUT:
6379 signal_num = PROXIMITY_OUT_EVENT;
6381 case GDK_VISIBILITY_NOTIFY:
6382 signal_num = VISIBILITY_NOTIFY_EVENT;
6384 case GDK_GRAB_BROKEN:
6385 signal_num = GRAB_BROKEN_EVENT;
6388 signal_num = DAMAGE_EVENT;
6391 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6395 if (signal_num != -1)
6396 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6398 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6399 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6403 g_object_unref (widget);
6409 * gtk_widget_activate:
6410 * @widget: a #GtkWidget that's activatable
6412 * For widgets that can be "activated" (buttons, menu items, etc.)
6413 * this function activates them. Activation is what happens when you
6414 * press Enter on a widget during key navigation. If @widget isn't
6415 * activatable, the function returns %FALSE.
6417 * Return value: %TRUE if the widget was activatable
6420 gtk_widget_activate (GtkWidget *widget)
6422 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6424 if (WIDGET_CLASS (widget)->activate_signal)
6426 /* FIXME: we should eventually check the signals signature here */
6427 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6436 gtk_widget_reparent_subwindows (GtkWidget *widget,
6437 GdkWindow *new_window)
6439 GtkWidgetPrivate *priv = widget->priv;
6441 if (!gtk_widget_get_has_window (widget))
6443 GList *children = gdk_window_get_children (priv->window);
6446 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6448 GdkWindow *window = tmp_list->data;
6451 gdk_window_get_user_data (window, &child);
6452 while (child && child != widget)
6453 child = ((GtkWidget*) child)->priv->parent;
6456 gdk_window_reparent (window, new_window, 0, 0);
6459 g_list_free (children);
6464 GList *tmp_list, *children;
6466 parent = gdk_window_get_parent (priv->window);
6469 gdk_window_reparent (priv->window, new_window, 0, 0);
6472 children = gdk_window_get_children (parent);
6474 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6476 GdkWindow *window = tmp_list->data;
6479 gdk_window_get_user_data (window, &child);
6481 if (child == widget)
6482 gdk_window_reparent (window, new_window, 0, 0);
6485 g_list_free (children);
6491 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6492 gpointer client_data)
6494 GtkWidgetPrivate *priv = widget->priv;
6496 g_assert (client_data != NULL);
6498 if (!gtk_widget_get_has_window (widget))
6501 g_object_unref (priv->window);
6502 priv->window = (GdkWindow*) client_data;
6504 g_object_ref (priv->window);
6506 if (GTK_IS_CONTAINER (widget))
6507 gtk_container_forall (GTK_CONTAINER (widget),
6508 gtk_widget_reparent_fixup_child,
6514 * gtk_widget_reparent:
6515 * @widget: a #GtkWidget
6516 * @new_parent: a #GtkContainer to move the widget into
6518 * Moves a widget from one #GtkContainer to another, handling reference
6519 * count issues to avoid destroying the widget.
6522 gtk_widget_reparent (GtkWidget *widget,
6523 GtkWidget *new_parent)
6525 GtkWidgetPrivate *priv;
6527 g_return_if_fail (GTK_IS_WIDGET (widget));
6528 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6529 priv = widget->priv;
6530 g_return_if_fail (priv->parent != NULL);
6532 if (priv->parent != new_parent)
6534 /* First try to see if we can get away without unrealizing
6535 * the widget as we reparent it. if so we set a flag so
6536 * that gtk_widget_unparent doesn't unrealize widget
6538 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6539 priv->in_reparent = TRUE;
6541 g_object_ref (widget);
6542 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6543 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6544 g_object_unref (widget);
6546 if (priv->in_reparent)
6548 priv->in_reparent = FALSE;
6550 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6551 gtk_widget_reparent_fixup_child (widget,
6552 gtk_widget_get_parent_window (widget));
6555 g_object_notify (G_OBJECT (widget), "parent");
6560 * gtk_widget_intersect:
6561 * @widget: a #GtkWidget
6562 * @area: a rectangle
6563 * @intersection: rectangle to store intersection of @widget and @area
6565 * Computes the intersection of a @widget's area and @area, storing
6566 * the intersection in @intersection, and returns %TRUE if there was
6567 * an intersection. @intersection may be %NULL if you're only
6568 * interested in whether there was an intersection.
6570 * Return value: %TRUE if there was an intersection
6573 gtk_widget_intersect (GtkWidget *widget,
6574 const GdkRectangle *area,
6575 GdkRectangle *intersection)
6577 GtkWidgetPrivate *priv;
6582 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6583 g_return_val_if_fail (area != NULL, FALSE);
6585 priv = widget->priv;
6588 dest = intersection;
6592 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6594 if (return_val && intersection && gtk_widget_get_has_window (widget))
6596 intersection->x -= priv->allocation.x;
6597 intersection->y -= priv->allocation.y;
6604 * gtk_widget_region_intersect:
6605 * @widget: a #GtkWidget
6606 * @region: a #cairo_region_t, in the same coordinate system as
6607 * @widget->allocation. That is, relative to @widget->window
6608 * for %NO_WINDOW widgets; relative to the parent window
6609 * of @widget->window for widgets with their own window.
6611 * Computes the intersection of a @widget's area and @region, returning
6612 * the intersection. The result may be empty, use cairo_region_is_empty() to
6615 * Returns: A newly allocated region holding the intersection of @widget
6616 * and @region. The coordinates of the return value are relative to
6617 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6618 * window of @widget->window for widgets with their own window.
6621 gtk_widget_region_intersect (GtkWidget *widget,
6622 const cairo_region_t *region)
6625 cairo_region_t *dest;
6627 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6628 g_return_val_if_fail (region != NULL, NULL);
6630 gtk_widget_get_allocation (widget, &rect);
6632 dest = cairo_region_create_rectangle (&rect);
6634 cairo_region_intersect (dest, region);
6640 * _gtk_widget_grab_notify:
6641 * @widget: a #GtkWidget
6642 * @was_grabbed: whether a grab is now in effect
6644 * Emits the #GtkWidget::grab-notify signal on @widget.
6649 _gtk_widget_grab_notify (GtkWidget *widget,
6650 gboolean was_grabbed)
6652 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6656 * gtk_widget_grab_focus:
6657 * @widget: a #GtkWidget
6659 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6660 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6661 * something like #GtkFrame won't work.
6663 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6664 * gtk_widget_set_can_focus() to modify that flag.
6666 * The widget also needs to be realized and mapped. This is indicated by the
6667 * related signals. Grabbing the focus immediately after creating the widget
6668 * will likely fail and cause critical warnings.
6671 gtk_widget_grab_focus (GtkWidget *widget)
6673 g_return_if_fail (GTK_IS_WIDGET (widget));
6675 if (!gtk_widget_is_sensitive (widget))
6678 g_object_ref (widget);
6679 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6680 g_object_notify (G_OBJECT (widget), "has-focus");
6681 g_object_unref (widget);
6685 reset_focus_recurse (GtkWidget *widget,
6688 if (GTK_IS_CONTAINER (widget))
6690 GtkContainer *container;
6692 container = GTK_CONTAINER (widget);
6693 gtk_container_set_focus_child (container, NULL);
6695 gtk_container_foreach (container,
6696 reset_focus_recurse,
6702 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6704 if (gtk_widget_get_can_focus (focus_widget))
6706 GtkWidget *toplevel;
6709 /* clear the current focus setting, break if the current widget
6710 * is the focus widget's parent, since containers above that will
6711 * be set by the next loop.
6713 toplevel = gtk_widget_get_toplevel (focus_widget);
6714 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6716 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6718 if (widget == focus_widget)
6720 /* We call _gtk_window_internal_set_focus() here so that the
6721 * toplevel window can request the focus if necessary.
6722 * This is needed when the toplevel is a GtkPlug
6724 if (!gtk_widget_has_focus (widget))
6725 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6732 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6734 if (widget != common_ancestor)
6736 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6738 widget = widget->priv->parent;
6739 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6744 else if (toplevel != focus_widget)
6746 /* gtk_widget_grab_focus() operates on a tree without window...
6747 * actually, this is very questionable behaviour.
6750 gtk_container_foreach (GTK_CONTAINER (toplevel),
6751 reset_focus_recurse,
6755 /* now propagate the new focus up the widget tree and finally
6756 * set it on the window
6758 widget = focus_widget;
6759 while (widget->priv->parent)
6761 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6762 widget = widget->priv->parent;
6764 if (GTK_IS_WINDOW (widget))
6765 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6770 gtk_widget_real_query_tooltip (GtkWidget *widget,
6773 gboolean keyboard_tip,
6774 GtkTooltip *tooltip)
6776 gchar *tooltip_markup;
6777 gboolean has_tooltip;
6779 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6780 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6782 if (has_tooltip && tooltip_markup)
6784 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6792 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6793 GtkStateFlags old_state)
6795 gtk_widget_update_pango_context (widget);
6799 gtk_widget_real_style_updated (GtkWidget *widget)
6801 GtkWidgetPrivate *priv = widget->priv;
6803 gtk_widget_update_pango_context (widget);
6805 if (priv->style != NULL &&
6806 priv->style != gtk_widget_get_default_style ())
6808 /* Trigger ::style-set for old
6809 * widgets not listening to this
6811 g_signal_emit (widget,
6812 widget_signals[STYLE_SET],
6814 widget->priv->style);
6817 if (widget->priv->context)
6819 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6821 if (gtk_widget_get_realized (widget) &&
6822 gtk_widget_get_has_window (widget) &&
6823 !gtk_widget_get_app_paintable (widget))
6824 gtk_style_context_set_background (widget->priv->context,
6825 widget->priv->window);
6827 if (widget->priv->anchored)
6829 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6830 gtk_widget_queue_resize (widget);
6832 gtk_widget_queue_draw (widget);
6837 if (widget->priv->anchored)
6838 gtk_widget_queue_resize (widget);
6843 gtk_widget_real_show_help (GtkWidget *widget,
6844 GtkWidgetHelpType help_type)
6846 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6848 _gtk_tooltip_toggle_keyboard_mode (widget);
6857 gtk_widget_real_focus (GtkWidget *widget,
6858 GtkDirectionType direction)
6860 if (!gtk_widget_get_can_focus (widget))
6863 if (!gtk_widget_is_focus (widget))
6865 gtk_widget_grab_focus (widget);
6873 gtk_widget_real_move_focus (GtkWidget *widget,
6874 GtkDirectionType direction)
6876 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6878 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6880 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6886 gtk_widget_real_keynav_failed (GtkWidget *widget,
6887 GtkDirectionType direction)
6889 gboolean cursor_only;
6893 case GTK_DIR_TAB_FORWARD:
6894 case GTK_DIR_TAB_BACKWARD:
6901 g_object_get (gtk_widget_get_settings (widget),
6902 "gtk-keynav-cursor-only", &cursor_only,
6909 gtk_widget_error_bell (widget);
6915 * gtk_widget_set_can_focus:
6916 * @widget: a #GtkWidget
6917 * @can_focus: whether or not @widget can own the input focus.
6919 * Specifies whether @widget can own the input focus. See
6920 * gtk_widget_grab_focus() for actually setting the input focus on a
6926 gtk_widget_set_can_focus (GtkWidget *widget,
6929 g_return_if_fail (GTK_IS_WIDGET (widget));
6931 if (widget->priv->can_focus != can_focus)
6933 widget->priv->can_focus = can_focus;
6935 gtk_widget_queue_resize (widget);
6936 g_object_notify (G_OBJECT (widget), "can-focus");
6941 * gtk_widget_get_can_focus:
6942 * @widget: a #GtkWidget
6944 * Determines whether @widget can own the input focus. See
6945 * gtk_widget_set_can_focus().
6947 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6952 gtk_widget_get_can_focus (GtkWidget *widget)
6954 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6956 return widget->priv->can_focus;
6960 * gtk_widget_has_focus:
6961 * @widget: a #GtkWidget
6963 * Determines if the widget has the global input focus. See
6964 * gtk_widget_is_focus() for the difference between having the global
6965 * input focus, and only having the focus within a toplevel.
6967 * Return value: %TRUE if the widget has the global input focus.
6972 gtk_widget_has_focus (GtkWidget *widget)
6974 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6976 return widget->priv->has_focus;
6980 * gtk_widget_has_visible_focus:
6981 * @widget: a #GtkWidget
6983 * Determines if the widget should show a visible indication that
6984 * it has the global input focus. This is a convenience function for
6985 * use in ::draw handlers that takes into account whether focus
6986 * indication should currently be shown in the toplevel window of
6987 * @widget. See gtk_window_get_focus_visible() for more information
6988 * about focus indication.
6990 * To find out if the widget has the global input focus, use
6991 * gtk_widget_has_focus().
6993 * Return value: %TRUE if the widget should display a 'focus rectangle'
6998 gtk_widget_has_visible_focus (GtkWidget *widget)
7000 gboolean draw_focus;
7002 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7004 if (widget->priv->has_focus)
7006 GtkWidget *toplevel;
7008 toplevel = gtk_widget_get_toplevel (widget);
7010 if (GTK_IS_WINDOW (toplevel))
7011 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7022 * gtk_widget_is_focus:
7023 * @widget: a #GtkWidget
7025 * Determines if the widget is the focus widget within its
7026 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7027 * necessarily set; %HAS_FOCUS will only be set if the
7028 * toplevel widget additionally has the global input focus.)
7030 * Return value: %TRUE if the widget is the focus widget.
7033 gtk_widget_is_focus (GtkWidget *widget)
7035 GtkWidget *toplevel;
7037 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7039 toplevel = gtk_widget_get_toplevel (widget);
7041 if (GTK_IS_WINDOW (toplevel))
7042 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7048 * gtk_widget_set_can_default:
7049 * @widget: a #GtkWidget
7050 * @can_default: whether or not @widget can be a default widget.
7052 * Specifies whether @widget can be a default widget. See
7053 * gtk_widget_grab_default() for details about the meaning of
7059 gtk_widget_set_can_default (GtkWidget *widget,
7060 gboolean can_default)
7062 g_return_if_fail (GTK_IS_WIDGET (widget));
7064 if (widget->priv->can_default != can_default)
7066 widget->priv->can_default = can_default;
7068 gtk_widget_queue_resize (widget);
7069 g_object_notify (G_OBJECT (widget), "can-default");
7074 * gtk_widget_get_can_default:
7075 * @widget: a #GtkWidget
7077 * Determines whether @widget can be a default widget. See
7078 * gtk_widget_set_can_default().
7080 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7085 gtk_widget_get_can_default (GtkWidget *widget)
7087 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7089 return widget->priv->can_default;
7093 * gtk_widget_has_default:
7094 * @widget: a #GtkWidget
7096 * Determines whether @widget is the current default widget within its
7097 * toplevel. See gtk_widget_set_can_default().
7099 * Return value: %TRUE if @widget is the current default widget within
7100 * its toplevel, %FALSE otherwise
7105 gtk_widget_has_default (GtkWidget *widget)
7107 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7109 return widget->priv->has_default;
7113 _gtk_widget_set_has_default (GtkWidget *widget,
7114 gboolean has_default)
7116 GtkStyleContext *context;
7118 widget->priv->has_default = has_default;
7120 context = gtk_widget_get_style_context (widget);
7123 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7125 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7129 * gtk_widget_grab_default:
7130 * @widget: a #GtkWidget
7132 * Causes @widget to become the default widget. @widget must be able to be
7133 * a default widget; typically you would ensure this yourself
7134 * by calling gtk_widget_set_can_default() with a %TRUE value.
7135 * The default widget is activated when
7136 * the user presses Enter in a window. Default widgets must be
7137 * activatable, that is, gtk_widget_activate() should affect them. Note
7138 * that #GtkEntry widgets require the "activates-default" property
7139 * set to %TRUE before they activate the default widget when Enter
7140 * is pressed and the #GtkEntry is focused.
7143 gtk_widget_grab_default (GtkWidget *widget)
7147 g_return_if_fail (GTK_IS_WIDGET (widget));
7148 g_return_if_fail (gtk_widget_get_can_default (widget));
7150 window = gtk_widget_get_toplevel (widget);
7152 if (window && gtk_widget_is_toplevel (window))
7153 gtk_window_set_default (GTK_WINDOW (window), widget);
7155 g_warning (G_STRLOC ": widget not within a GtkWindow");
7159 * gtk_widget_set_receives_default:
7160 * @widget: a #GtkWidget
7161 * @receives_default: whether or not @widget can be a default widget.
7163 * Specifies whether @widget will be treated as the default widget
7164 * within its toplevel when it has the focus, even if another widget
7167 * See gtk_widget_grab_default() for details about the meaning of
7173 gtk_widget_set_receives_default (GtkWidget *widget,
7174 gboolean receives_default)
7176 g_return_if_fail (GTK_IS_WIDGET (widget));
7178 if (widget->priv->receives_default != receives_default)
7180 widget->priv->receives_default = receives_default;
7182 g_object_notify (G_OBJECT (widget), "receives-default");
7187 * gtk_widget_get_receives_default:
7188 * @widget: a #GtkWidget
7190 * Determines whether @widget is alyways treated as default widget
7191 * withing its toplevel when it has the focus, even if another widget
7194 * See gtk_widget_set_receives_default().
7196 * Return value: %TRUE if @widget acts as default widget when focussed,
7202 gtk_widget_get_receives_default (GtkWidget *widget)
7204 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7206 return widget->priv->receives_default;
7210 * gtk_widget_has_grab:
7211 * @widget: a #GtkWidget
7213 * Determines whether the widget is currently grabbing events, so it
7214 * is the only widget receiving input events (keyboard and mouse).
7216 * See also gtk_grab_add().
7218 * Return value: %TRUE if the widget is in the grab_widgets stack
7223 gtk_widget_has_grab (GtkWidget *widget)
7225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7227 return widget->priv->has_grab;
7231 _gtk_widget_set_has_grab (GtkWidget *widget,
7234 widget->priv->has_grab = has_grab;
7238 * gtk_widget_device_is_shadowed:
7239 * @widget: a #GtkWidget
7240 * @device: a #GdkDevice
7242 * Returns %TRUE if @device has been shadowed by a GTK+
7243 * device grab on another widget, so it would stop sending
7244 * events to @widget. This may be used in the
7245 * #GtkWidget::grab-notify signal to check for specific
7246 * devices. See gtk_device_grab_add().
7248 * Returns: %TRUE if there is an ongoing grab on @device
7249 * by another #GtkWidget than @widget.
7254 gtk_widget_device_is_shadowed (GtkWidget *widget,
7257 GtkWindowGroup *group;
7258 GtkWidget *grab_widget, *toplevel;
7260 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7261 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7263 if (!gtk_widget_get_realized (widget))
7266 toplevel = gtk_widget_get_toplevel (widget);
7268 if (GTK_IS_WINDOW (toplevel))
7269 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7271 group = gtk_window_get_group (NULL);
7273 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7275 /* Widget not inside the hierarchy of grab_widget */
7277 widget != grab_widget &&
7278 !gtk_widget_is_ancestor (widget, grab_widget))
7281 grab_widget = gtk_window_group_get_current_grab (group);
7282 if (grab_widget && widget != grab_widget &&
7283 !gtk_widget_is_ancestor (widget, grab_widget))
7290 * gtk_widget_set_name:
7291 * @widget: a #GtkWidget
7292 * @name: name for the widget
7294 * Widgets can be named, which allows you to refer to them from a
7295 * CSS file. You can apply a style to widgets with a particular name
7296 * in the CSS file. See the documentation for the CSS syntax (on the
7297 * same page as the docs for #GtkStyleContext).
7299 * Note that the CSS syntax has certain special characters to delimit
7300 * and represent elements in a selector (period, #, >, *...),
7301 * so using these will make your widget impossible to match by name.
7302 * Any combination of alphanumeric symbols, dashes and underscores will
7306 gtk_widget_set_name (GtkWidget *widget,
7309 GtkWidgetPrivate *priv;
7312 g_return_if_fail (GTK_IS_WIDGET (widget));
7314 priv = widget->priv;
7316 new_name = g_strdup (name);
7317 g_free (priv->name);
7318 priv->name = new_name;
7320 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7322 g_object_notify (G_OBJECT (widget), "name");
7326 * gtk_widget_get_name:
7327 * @widget: a #GtkWidget
7329 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7330 * significance of widget names.
7332 * Return value: name of the widget. This string is owned by GTK+ and
7333 * should not be modified or freed
7336 gtk_widget_get_name (GtkWidget *widget)
7338 GtkWidgetPrivate *priv;
7340 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7342 priv = widget->priv;
7346 return G_OBJECT_TYPE_NAME (widget);
7350 gtk_widget_update_state_flags (GtkWidget *widget,
7351 GtkStateFlags flags_to_set,
7352 GtkStateFlags flags_to_unset)
7354 GtkWidgetPrivate *priv;
7356 priv = widget->priv;
7358 /* Handle insensitive first, since it is propagated
7359 * differently throughout the widget hierarchy.
7361 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7362 gtk_widget_set_sensitive (widget, TRUE);
7363 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7364 gtk_widget_set_sensitive (widget, FALSE);
7366 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7367 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7369 if (flags_to_set != 0 || flags_to_unset != 0)
7373 data.flags_to_set = flags_to_set;
7374 data.flags_to_unset = flags_to_unset;
7376 gtk_widget_propagate_state (widget, &data);
7381 * gtk_widget_set_state_flags:
7382 * @widget: a #GtkWidget
7383 * @flags: State flags to turn on
7384 * @clear: Whether to clear state before turning on @flags
7386 * This function is for use in widget implementations. Turns on flag
7387 * values in the current widget state (insensitive, prelighted, etc.).
7389 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7390 * will be propagated down to all non-internal children if @widget is a
7391 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7392 * down to all #GtkContainer children by different means than turning on the
7393 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7394 * gtk_widget_is_sensitive() will make use of these.
7399 gtk_widget_set_state_flags (GtkWidget *widget,
7400 GtkStateFlags flags,
7403 g_return_if_fail (GTK_IS_WIDGET (widget));
7405 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7406 (clear && widget->priv->state_flags == flags))
7410 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7412 gtk_widget_update_state_flags (widget, flags, 0);
7416 * gtk_widget_unset_state_flags:
7417 * @widget: a #GtkWidget
7418 * @flags: State flags to turn off
7420 * This function is for use in widget implementations. Turns off flag
7421 * values for the current widget state (insensitive, prelighted, etc.).
7422 * See gtk_widget_set_state_flags().
7427 gtk_widget_unset_state_flags (GtkWidget *widget,
7428 GtkStateFlags flags)
7430 g_return_if_fail (GTK_IS_WIDGET (widget));
7432 if ((widget->priv->state_flags & flags) == 0)
7435 gtk_widget_update_state_flags (widget, 0, flags);
7439 * gtk_widget_get_state_flags:
7440 * @widget: a #GtkWidget
7442 * Returns the widget state as a flag set. It is worth mentioning
7443 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7444 * returned, that is, also based on parent insensitivity, even if
7445 * @widget itself is sensitive.
7447 * Returns: The state flags for widget
7452 gtk_widget_get_state_flags (GtkWidget *widget)
7454 GtkStateFlags flags;
7456 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7458 flags = widget->priv->state_flags;
7460 if (gtk_widget_has_focus (widget))
7461 flags |= GTK_STATE_FLAG_FOCUSED;
7467 * gtk_widget_set_state:
7468 * @widget: a #GtkWidget
7469 * @state: new state for @widget
7471 * This function is for use in widget implementations. Sets the state
7472 * of a widget (insensitive, prelighted, etc.) Usually you should set
7473 * the state using wrapper functions such as gtk_widget_set_sensitive().
7475 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7478 gtk_widget_set_state (GtkWidget *widget,
7481 GtkStateFlags flags;
7483 if (state == gtk_widget_get_state (widget))
7488 case GTK_STATE_ACTIVE:
7489 flags = GTK_STATE_FLAG_ACTIVE;
7491 case GTK_STATE_PRELIGHT:
7492 flags = GTK_STATE_FLAG_PRELIGHT;
7494 case GTK_STATE_SELECTED:
7495 flags = GTK_STATE_FLAG_SELECTED;
7497 case GTK_STATE_INSENSITIVE:
7498 flags = GTK_STATE_FLAG_INSENSITIVE;
7500 case GTK_STATE_INCONSISTENT:
7501 flags = GTK_STATE_FLAG_INCONSISTENT;
7503 case GTK_STATE_FOCUSED:
7504 flags = GTK_STATE_FLAG_FOCUSED;
7506 case GTK_STATE_NORMAL:
7512 gtk_widget_update_state_flags (widget,
7514 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7515 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7519 * gtk_widget_get_state:
7520 * @widget: a #GtkWidget
7522 * Returns the widget's state. See gtk_widget_set_state().
7524 * Returns: the state of @widget.
7528 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7531 gtk_widget_get_state (GtkWidget *widget)
7533 GtkStateFlags flags;
7535 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7537 flags = gtk_widget_get_state_flags (widget);
7539 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7540 return GTK_STATE_INSENSITIVE;
7541 else if (flags & GTK_STATE_FLAG_ACTIVE)
7542 return GTK_STATE_ACTIVE;
7543 else if (flags & GTK_STATE_FLAG_SELECTED)
7544 return GTK_STATE_SELECTED;
7545 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7546 return GTK_STATE_PRELIGHT;
7548 return GTK_STATE_NORMAL;
7552 * gtk_widget_set_visible:
7553 * @widget: a #GtkWidget
7554 * @visible: whether the widget should be shown or not
7556 * Sets the visibility state of @widget. Note that setting this to
7557 * %TRUE doesn't mean the widget is actually viewable, see
7558 * gtk_widget_get_visible().
7560 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7561 * but is nicer to use when the visibility of the widget depends on
7567 gtk_widget_set_visible (GtkWidget *widget,
7570 g_return_if_fail (GTK_IS_WIDGET (widget));
7572 if (visible != gtk_widget_get_visible (widget))
7575 gtk_widget_show (widget);
7577 gtk_widget_hide (widget);
7582 _gtk_widget_set_visible_flag (GtkWidget *widget,
7585 GtkWidgetPrivate *priv = widget->priv;
7587 priv->visible = visible;
7591 priv->allocation.x = -1;
7592 priv->allocation.y = -1;
7593 priv->allocation.width = 1;
7594 priv->allocation.height = 1;
7599 * gtk_widget_get_visible:
7600 * @widget: a #GtkWidget
7602 * Determines whether the widget is visible. If you want to
7603 * take into account whether the widget's parent is also marked as
7604 * visible, use gtk_widget_is_visible() instead.
7606 * This function does not check if the widget is obscured in any way.
7608 * See gtk_widget_set_visible().
7610 * Return value: %TRUE if the widget is visible
7615 gtk_widget_get_visible (GtkWidget *widget)
7617 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7619 return widget->priv->visible;
7623 * gtk_widget_is_visible:
7624 * @widget: a #GtkWidget
7626 * Determines whether the widget and all its parents are marked as
7629 * This function does not check if the widget is obscured in any way.
7631 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7633 * Return value: %TRUE if the widget and all its parents are visible
7638 gtk_widget_is_visible (GtkWidget *widget)
7640 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7644 GtkWidgetPrivate *priv = widget->priv;
7649 widget = priv->parent;
7656 * gtk_widget_set_has_window:
7657 * @widget: a #GtkWidget
7658 * @has_window: whether or not @widget has a window.
7660 * Specifies whether @widget has a #GdkWindow of its own. Note that
7661 * all realized widgets have a non-%NULL "window" pointer
7662 * (gtk_widget_get_window() never returns a %NULL window when a widget
7663 * is realized), but for many of them it's actually the #GdkWindow of
7664 * one of its parent widgets. Widgets that do not create a %window for
7665 * themselves in #GtkWidget::realize must announce this by
7666 * calling this function with @has_window = %FALSE.
7668 * This function should only be called by widget implementations,
7669 * and they should call it in their init() function.
7674 gtk_widget_set_has_window (GtkWidget *widget,
7675 gboolean has_window)
7677 g_return_if_fail (GTK_IS_WIDGET (widget));
7679 widget->priv->no_window = !has_window;
7683 * gtk_widget_get_has_window:
7684 * @widget: a #GtkWidget
7686 * Determines whether @widget has a #GdkWindow of its own. See
7687 * gtk_widget_set_has_window().
7689 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7694 gtk_widget_get_has_window (GtkWidget *widget)
7696 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7698 return ! widget->priv->no_window;
7702 * gtk_widget_is_toplevel:
7703 * @widget: a #GtkWidget
7705 * Determines whether @widget is a toplevel widget.
7707 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7708 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7711 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7716 gtk_widget_is_toplevel (GtkWidget *widget)
7718 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7720 return widget->priv->toplevel;
7724 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7725 gboolean is_toplevel)
7727 widget->priv->toplevel = is_toplevel;
7731 * gtk_widget_is_drawable:
7732 * @widget: a #GtkWidget
7734 * Determines whether @widget can be drawn to. A widget can be drawn
7735 * to if it is mapped and visible.
7737 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7742 gtk_widget_is_drawable (GtkWidget *widget)
7744 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7746 return (gtk_widget_get_visible (widget) &&
7747 gtk_widget_get_mapped (widget));
7751 * gtk_widget_get_realized:
7752 * @widget: a #GtkWidget
7754 * Determines whether @widget is realized.
7756 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7761 gtk_widget_get_realized (GtkWidget *widget)
7763 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7765 return widget->priv->realized;
7769 * gtk_widget_set_realized:
7770 * @widget: a #GtkWidget
7771 * @realized: %TRUE to mark the widget as realized
7773 * Marks the widget as being realized.
7775 * This function should only ever be called in a derived widget's
7776 * "realize" or "unrealize" implementation.
7781 gtk_widget_set_realized (GtkWidget *widget,
7784 g_return_if_fail (GTK_IS_WIDGET (widget));
7786 widget->priv->realized = realized;
7790 * gtk_widget_get_mapped:
7791 * @widget: a #GtkWidget
7793 * Whether the widget is mapped.
7795 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7800 gtk_widget_get_mapped (GtkWidget *widget)
7802 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7804 return widget->priv->mapped;
7808 * gtk_widget_set_mapped:
7809 * @widget: a #GtkWidget
7810 * @mapped: %TRUE to mark the widget as mapped
7812 * Marks the widget as being realized.
7814 * This function should only ever be called in a derived widget's
7815 * "map" or "unmap" implementation.
7820 gtk_widget_set_mapped (GtkWidget *widget,
7823 g_return_if_fail (GTK_IS_WIDGET (widget));
7825 widget->priv->mapped = mapped;
7829 * gtk_widget_set_app_paintable:
7830 * @widget: a #GtkWidget
7831 * @app_paintable: %TRUE if the application will paint on the widget
7833 * Sets whether the application intends to draw on the widget in
7834 * an #GtkWidget::draw handler.
7836 * This is a hint to the widget and does not affect the behavior of
7837 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7838 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7839 * the effect is to suppress default themed drawing of the widget's
7840 * background. (Children of the widget will still be drawn.) The application
7841 * is then entirely responsible for drawing the widget background.
7843 * Note that the background is still drawn when the widget is mapped.
7846 gtk_widget_set_app_paintable (GtkWidget *widget,
7847 gboolean app_paintable)
7849 g_return_if_fail (GTK_IS_WIDGET (widget));
7851 app_paintable = (app_paintable != FALSE);
7853 if (widget->priv->app_paintable != app_paintable)
7855 widget->priv->app_paintable = app_paintable;
7857 if (gtk_widget_is_drawable (widget))
7858 gtk_widget_queue_draw (widget);
7860 g_object_notify (G_OBJECT (widget), "app-paintable");
7865 * gtk_widget_get_app_paintable:
7866 * @widget: a #GtkWidget
7868 * Determines whether the application intends to draw on the widget in
7869 * an #GtkWidget::draw handler.
7871 * See gtk_widget_set_app_paintable()
7873 * Return value: %TRUE if the widget is app paintable
7878 gtk_widget_get_app_paintable (GtkWidget *widget)
7880 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7882 return widget->priv->app_paintable;
7886 * gtk_widget_set_double_buffered:
7887 * @widget: a #GtkWidget
7888 * @double_buffered: %TRUE to double-buffer a widget
7890 * Widgets are double buffered by default; you can use this function
7891 * to turn off the buffering. "Double buffered" simply means that
7892 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7893 * automatically around expose events sent to the
7894 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7895 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7896 * buffer to the screen. The result is that users see the window
7897 * update in one smooth step, and don't see individual graphics
7898 * primitives being rendered.
7900 * In very simple terms, double buffered widgets don't flicker,
7901 * so you would only use this function to turn off double buffering
7902 * if you had special needs and really knew what you were doing.
7904 * Note: if you turn off double-buffering, you have to handle
7905 * expose events, since even the clearing to the background color or
7906 * pixmap will not happen automatically (as it is done in
7907 * gdk_window_begin_paint_region()).
7910 gtk_widget_set_double_buffered (GtkWidget *widget,
7911 gboolean double_buffered)
7913 g_return_if_fail (GTK_IS_WIDGET (widget));
7915 double_buffered = (double_buffered != FALSE);
7917 if (widget->priv->double_buffered != double_buffered)
7919 widget->priv->double_buffered = double_buffered;
7921 g_object_notify (G_OBJECT (widget), "double-buffered");
7926 * gtk_widget_get_double_buffered:
7927 * @widget: a #GtkWidget
7929 * Determines whether the widget is double buffered.
7931 * See gtk_widget_set_double_buffered()
7933 * Return value: %TRUE if the widget is double buffered
7938 gtk_widget_get_double_buffered (GtkWidget *widget)
7940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7942 return widget->priv->double_buffered;
7946 * gtk_widget_set_redraw_on_allocate:
7947 * @widget: a #GtkWidget
7948 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7949 * when it is allocated to a new size. Otherwise, only the
7950 * new portion of the widget will be redrawn.
7952 * Sets whether the entire widget is queued for drawing when its size
7953 * allocation changes. By default, this setting is %TRUE and
7954 * the entire widget is redrawn on every size change. If your widget
7955 * leaves the upper left unchanged when made bigger, turning this
7956 * setting off will improve performance.
7958 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7959 * off all allocation on resizing: the widget will not even redraw if
7960 * its position changes; this is to allow containers that don't draw
7961 * anything to avoid excess invalidations. If you set this flag on a
7962 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7963 * you are responsible for invalidating both the old and new allocation
7964 * of the widget when the widget is moved and responsible for invalidating
7965 * regions newly when the widget increases size.
7968 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7969 gboolean redraw_on_allocate)
7971 g_return_if_fail (GTK_IS_WIDGET (widget));
7973 widget->priv->redraw_on_alloc = redraw_on_allocate;
7977 * gtk_widget_set_sensitive:
7978 * @widget: a #GtkWidget
7979 * @sensitive: %TRUE to make the widget sensitive
7981 * Sets the sensitivity of a widget. A widget is sensitive if the user
7982 * can interact with it. Insensitive widgets are "grayed out" and the
7983 * user can't interact with them. Insensitive widgets are known as
7984 * "inactive", "disabled", or "ghosted" in some other toolkits.
7987 gtk_widget_set_sensitive (GtkWidget *widget,
7990 GtkWidgetPrivate *priv;
7992 g_return_if_fail (GTK_IS_WIDGET (widget));
7994 priv = widget->priv;
7996 sensitive = (sensitive != FALSE);
7998 if (priv->sensitive == sensitive)
8001 priv->sensitive = sensitive;
8003 if (priv->parent == NULL
8004 || gtk_widget_is_sensitive (priv->parent))
8010 data.flags_to_set = 0;
8011 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8015 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8016 data.flags_to_unset = 0;
8019 gtk_widget_propagate_state (widget, &data);
8021 gtk_widget_queue_resize (widget);
8024 g_object_notify (G_OBJECT (widget), "sensitive");
8028 * gtk_widget_get_sensitive:
8029 * @widget: a #GtkWidget
8031 * Returns the widget's sensitivity (in the sense of returning
8032 * the value that has been set using gtk_widget_set_sensitive()).
8034 * The effective sensitivity of a widget is however determined by both its
8035 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8037 * Returns: %TRUE if the widget is sensitive
8042 gtk_widget_get_sensitive (GtkWidget *widget)
8044 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8046 return widget->priv->sensitive;
8050 * gtk_widget_is_sensitive:
8051 * @widget: a #GtkWidget
8053 * Returns the widget's effective sensitivity, which means
8054 * it is sensitive itself and also its parent widget is sensitive
8056 * Returns: %TRUE if the widget is effectively sensitive
8061 gtk_widget_is_sensitive (GtkWidget *widget)
8063 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8065 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8069 * gtk_widget_set_parent:
8070 * @widget: a #GtkWidget
8071 * @parent: parent container
8073 * This function is useful only when implementing subclasses of
8075 * Sets the container as the parent of @widget, and takes care of
8076 * some details such as updating the state and style of the child
8077 * to reflect its new location. The opposite function is
8078 * gtk_widget_unparent().
8081 gtk_widget_set_parent (GtkWidget *widget,
8084 GtkStateFlags parent_flags;
8085 GtkWidgetPrivate *priv;
8088 g_return_if_fail (GTK_IS_WIDGET (widget));
8089 g_return_if_fail (GTK_IS_WIDGET (parent));
8090 g_return_if_fail (widget != parent);
8092 priv = widget->priv;
8094 if (priv->parent != NULL)
8096 g_warning ("Can't set a parent on widget which has a parent\n");
8099 if (gtk_widget_is_toplevel (widget))
8101 g_warning ("Can't set a parent on a toplevel widget\n");
8105 /* keep this function in sync with gtk_menu_attach_to_widget()
8108 g_object_ref_sink (widget);
8110 gtk_widget_push_verify_invariants (widget);
8112 priv->parent = parent;
8114 parent_flags = gtk_widget_get_state_flags (parent);
8116 /* Merge both old state and current parent state,
8117 * making sure to only propagate the right states */
8118 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8119 data.flags_to_unset = 0;
8120 gtk_widget_propagate_state (widget, &data);
8123 gtk_style_context_set_parent (priv->context,
8124 gtk_widget_get_style_context (parent));
8126 _gtk_widget_update_parent_muxer (widget);
8128 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8129 if (priv->parent->priv->anchored)
8130 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8131 g_object_notify (G_OBJECT (widget), "parent");
8133 /* Enforce realized/mapped invariants
8135 if (gtk_widget_get_realized (priv->parent))
8136 gtk_widget_realize (widget);
8138 if (gtk_widget_get_visible (priv->parent) &&
8139 gtk_widget_get_visible (widget))
8141 if (gtk_widget_get_child_visible (widget) &&
8142 gtk_widget_get_mapped (priv->parent))
8143 gtk_widget_map (widget);
8145 gtk_widget_queue_resize (widget);
8148 /* child may cause parent's expand to change, if the child is
8149 * expanded. If child is not expanded, then it can't modify the
8150 * parent's expand. If the child becomes expanded later then it will
8151 * queue compute_expand then. This optimization plus defaulting
8152 * newly-constructed widgets to need_compute_expand=FALSE should
8153 * mean that initially building a widget tree doesn't have to keep
8154 * walking up setting need_compute_expand on parents over and over.
8156 * We can't change a parent to need to expand unless we're visible.
8158 if (gtk_widget_get_visible (widget) &&
8159 (priv->need_compute_expand ||
8160 priv->computed_hexpand ||
8161 priv->computed_vexpand))
8163 gtk_widget_queue_compute_expand (parent);
8166 gtk_widget_update_norender (widget);
8168 gtk_widget_pop_verify_invariants (widget);
8172 * gtk_widget_get_parent:
8173 * @widget: a #GtkWidget
8175 * Returns the parent container of @widget.
8177 * Return value: (transfer none): the parent container of @widget, or %NULL
8180 gtk_widget_get_parent (GtkWidget *widget)
8182 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8184 return widget->priv->parent;
8188 modifier_style_changed (GtkModifierStyle *style,
8191 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8194 static GtkModifierStyle *
8195 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8197 GtkModifierStyle *style;
8199 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8201 if (G_UNLIKELY (!style))
8203 GtkStyleContext *context;
8205 style = _gtk_modifier_style_new ();
8206 g_object_set_qdata_full (G_OBJECT (widget),
8207 quark_modifier_style,
8209 (GDestroyNotify) g_object_unref);
8211 g_signal_connect (style, "changed",
8212 G_CALLBACK (modifier_style_changed), widget);
8214 context = gtk_widget_get_style_context (widget);
8216 gtk_style_context_add_provider (context,
8217 GTK_STYLE_PROVIDER (style),
8218 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8225 * gtk_widget_override_color:
8226 * @widget: a #GtkWidget
8227 * @state: the state for which to set the color
8228 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8229 * of previous calls to gtk_widget_override_color()
8231 * Sets the color to use for a widget.
8233 * All other style values are left untouched.
8236 * This API is mostly meant as a quick way for applications to
8237 * change a widget appearance. If you are developing a widgets
8238 * library and intend this change to be themeable, it is better
8239 * done by setting meaningful CSS classes and regions in your
8240 * widget/container implementation through gtk_style_context_add_class()
8241 * and gtk_style_context_add_region().
8243 * This way, your widget library can install a #GtkCssProvider
8244 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8245 * to provide a default styling for those widgets that need so, and
8246 * this theming may fully overridden by the user's theme.
8249 * Note that for complex widgets this may bring in undesired
8250 * results (such as uniform background color everywhere), in
8251 * these cases it is better to fully style such widgets through a
8252 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8259 gtk_widget_override_color (GtkWidget *widget,
8260 GtkStateFlags state,
8261 const GdkRGBA *color)
8263 GtkModifierStyle *style;
8265 g_return_if_fail (GTK_IS_WIDGET (widget));
8267 style = _gtk_widget_get_modifier_properties (widget);
8268 _gtk_modifier_style_set_color (style, state, color);
8272 * gtk_widget_override_background_color:
8273 * @widget: a #GtkWidget
8274 * @state: the state for which to set the background color
8275 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8276 * of previous calls to gtk_widget_override_background_color()
8278 * Sets the background color to use for a widget.
8280 * All other style values are left untouched.
8281 * See gtk_widget_override_color().
8286 gtk_widget_override_background_color (GtkWidget *widget,
8287 GtkStateFlags state,
8288 const GdkRGBA *color)
8290 GtkModifierStyle *style;
8292 g_return_if_fail (GTK_IS_WIDGET (widget));
8294 style = _gtk_widget_get_modifier_properties (widget);
8295 _gtk_modifier_style_set_background_color (style, state, color);
8299 * gtk_widget_override_font:
8300 * @widget: a #GtkWidget
8301 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8302 * the effect of previous calls to gtk_widget_override_font()
8304 * Sets the font to use for a widget. All other style values are
8305 * left untouched. See gtk_widget_override_color().
8310 gtk_widget_override_font (GtkWidget *widget,
8311 const PangoFontDescription *font_desc)
8313 GtkModifierStyle *style;
8315 g_return_if_fail (GTK_IS_WIDGET (widget));
8317 style = _gtk_widget_get_modifier_properties (widget);
8318 _gtk_modifier_style_set_font (style, font_desc);
8322 * gtk_widget_override_symbolic_color:
8323 * @widget: a #GtkWidget
8324 * @name: the name of the symbolic color to modify
8325 * @color: (allow-none): the color to assign (does not need
8326 * to be allocated), or %NULL to undo the effect of previous
8327 * calls to gtk_widget_override_symbolic_color()
8329 * Sets a symbolic color for a widget.
8331 * All other style values are left untouched.
8332 * See gtk_widget_override_color() for overriding the foreground
8333 * or background color.
8338 gtk_widget_override_symbolic_color (GtkWidget *widget,
8340 const GdkRGBA *color)
8342 GtkModifierStyle *style;
8344 g_return_if_fail (GTK_IS_WIDGET (widget));
8346 style = _gtk_widget_get_modifier_properties (widget);
8347 _gtk_modifier_style_map_color (style, name, color);
8351 * gtk_widget_override_cursor:
8352 * @widget: a #GtkWidget
8353 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8354 * allocated), or %NULL to undo the effect of previous calls to
8355 * of gtk_widget_override_cursor().
8356 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8357 * need to be allocated), or %NULL to undo the effect of previous
8358 * calls to of gtk_widget_override_cursor().
8360 * Sets the cursor color to use in a widget, overriding the
8361 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8362 * style properties. All other style values are left untouched.
8363 * See also gtk_widget_modify_style().
8365 * Note that the underlying properties have the #GdkColor type,
8366 * so the alpha value in @primary and @secondary will be ignored.
8371 gtk_widget_override_cursor (GtkWidget *widget,
8372 const GdkRGBA *cursor,
8373 const GdkRGBA *secondary_cursor)
8375 GtkModifierStyle *style;
8377 g_return_if_fail (GTK_IS_WIDGET (widget));
8379 style = _gtk_widget_get_modifier_properties (widget);
8380 _gtk_modifier_style_set_color_property (style,
8382 "cursor-color", cursor);
8383 _gtk_modifier_style_set_color_property (style,
8385 "secondary-cursor-color",
8390 gtk_widget_real_direction_changed (GtkWidget *widget,
8391 GtkTextDirection previous_direction)
8393 gtk_widget_queue_resize (widget);
8397 gtk_widget_real_style_set (GtkWidget *widget,
8398 GtkStyle *previous_style)
8403 GtkWidget *previous_toplevel;
8404 GdkScreen *previous_screen;
8405 GdkScreen *new_screen;
8406 } HierarchyChangedInfo;
8409 do_screen_change (GtkWidget *widget,
8410 GdkScreen *old_screen,
8411 GdkScreen *new_screen)
8413 if (old_screen != new_screen)
8415 GtkWidgetPrivate *priv = widget->priv;
8419 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8421 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8424 _gtk_tooltip_hide (widget);
8426 if (new_screen && priv->context)
8427 gtk_style_context_set_screen (priv->context, new_screen);
8429 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8434 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8435 gpointer client_data)
8437 GtkWidgetPrivate *priv = widget->priv;
8438 HierarchyChangedInfo *info = client_data;
8439 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8440 (priv->parent && priv->parent->priv->anchored);
8442 if (priv->anchored != new_anchored)
8444 g_object_ref (widget);
8446 priv->anchored = new_anchored;
8448 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8449 do_screen_change (widget, info->previous_screen, info->new_screen);
8451 if (GTK_IS_CONTAINER (widget))
8452 gtk_container_forall (GTK_CONTAINER (widget),
8453 gtk_widget_propagate_hierarchy_changed_recurse,
8456 g_object_unref (widget);
8461 * _gtk_widget_propagate_hierarchy_changed:
8462 * @widget: a #GtkWidget
8463 * @previous_toplevel: Previous toplevel
8465 * Propagates changes in the anchored state to a widget and all
8466 * children, unsetting or setting the %ANCHORED flag, and
8467 * emitting #GtkWidget::hierarchy-changed.
8470 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8471 GtkWidget *previous_toplevel)
8473 GtkWidgetPrivate *priv = widget->priv;
8474 HierarchyChangedInfo info;
8476 info.previous_toplevel = previous_toplevel;
8477 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8479 if (gtk_widget_is_toplevel (widget) ||
8480 (priv->parent && priv->parent->priv->anchored))
8481 info.new_screen = gtk_widget_get_screen (widget);
8483 info.new_screen = NULL;
8485 if (info.previous_screen)
8486 g_object_ref (info.previous_screen);
8487 if (previous_toplevel)
8488 g_object_ref (previous_toplevel);
8490 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8492 if (previous_toplevel)
8493 g_object_unref (previous_toplevel);
8494 if (info.previous_screen)
8495 g_object_unref (info.previous_screen);
8499 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8500 gpointer client_data)
8502 HierarchyChangedInfo *info = client_data;
8504 g_object_ref (widget);
8506 do_screen_change (widget, info->previous_screen, info->new_screen);
8508 if (GTK_IS_CONTAINER (widget))
8509 gtk_container_forall (GTK_CONTAINER (widget),
8510 gtk_widget_propagate_screen_changed_recurse,
8513 g_object_unref (widget);
8517 * gtk_widget_is_composited:
8518 * @widget: a #GtkWidget
8520 * Whether @widget can rely on having its alpha channel
8521 * drawn correctly. On X11 this function returns whether a
8522 * compositing manager is running for @widget's screen.
8524 * Please note that the semantics of this call will change
8525 * in the future if used on a widget that has a composited
8526 * window in its hierarchy (as set by gdk_window_set_composited()).
8528 * Return value: %TRUE if the widget can rely on its alpha
8529 * channel being drawn correctly.
8534 gtk_widget_is_composited (GtkWidget *widget)
8538 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8540 screen = gtk_widget_get_screen (widget);
8542 return gdk_screen_is_composited (screen);
8546 propagate_composited_changed (GtkWidget *widget,
8549 if (GTK_IS_CONTAINER (widget))
8551 gtk_container_forall (GTK_CONTAINER (widget),
8552 propagate_composited_changed,
8556 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8560 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8562 propagate_composited_changed (widget, NULL);
8566 * _gtk_widget_propagate_screen_changed:
8567 * @widget: a #GtkWidget
8568 * @previous_screen: Previous screen
8570 * Propagates changes in the screen for a widget to all
8571 * children, emitting #GtkWidget::screen-changed.
8574 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8575 GdkScreen *previous_screen)
8577 HierarchyChangedInfo info;
8579 info.previous_screen = previous_screen;
8580 info.new_screen = gtk_widget_get_screen (widget);
8582 if (previous_screen)
8583 g_object_ref (previous_screen);
8585 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8587 if (previous_screen)
8588 g_object_unref (previous_screen);
8592 reset_style_recurse (GtkWidget *widget, gpointer data)
8594 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8596 if (GTK_IS_CONTAINER (widget))
8597 gtk_container_forall (GTK_CONTAINER (widget),
8598 reset_style_recurse,
8603 * gtk_widget_reset_style:
8604 * @widget: a #GtkWidget
8606 * Updates the style context of @widget and all descendents
8607 * by updating its widget path. #GtkContainer<!-- -->s may want
8608 * to use this on a child when reordering it in a way that a different
8609 * style might apply to it. See also gtk_container_get_path_for_child().
8614 gtk_widget_reset_style (GtkWidget *widget)
8616 g_return_if_fail (GTK_IS_WIDGET (widget));
8618 reset_style_recurse (widget, NULL);
8620 g_list_foreach (widget->priv->attached_windows,
8621 (GFunc) reset_style_recurse, NULL);
8624 #ifdef G_ENABLE_DEBUG
8626 /* Verify invariants, see docs/widget_system.txt for notes on much of
8627 * this. Invariants may be temporarily broken while we're in the
8628 * process of updating state, of course, so you can only
8629 * verify_invariants() after a given operation is complete.
8630 * Use push/pop_verify_invariants to help with that.
8633 gtk_widget_verify_invariants (GtkWidget *widget)
8637 if (widget->priv->verifying_invariants_count > 0)
8640 parent = widget->priv->parent;
8642 if (widget->priv->mapped)
8644 /* Mapped implies ... */
8646 if (!widget->priv->realized)
8647 g_warning ("%s %p is mapped but not realized",
8648 G_OBJECT_TYPE_NAME (widget), widget);
8650 if (!widget->priv->visible)
8651 g_warning ("%s %p is mapped but not visible",
8652 G_OBJECT_TYPE_NAME (widget), widget);
8654 if (!widget->priv->toplevel)
8656 if (!widget->priv->child_visible)
8657 g_warning ("%s %p is mapped but not child_visible",
8658 G_OBJECT_TYPE_NAME (widget), widget);
8663 /* Not mapped implies... */
8666 /* This check makes sense for normal toplevels, but for
8667 * something like a toplevel that is embedded within a clutter
8668 * state, mapping may depend on external factors.
8670 if (widget->priv->toplevel)
8672 if (widget->priv->visible)
8673 g_warning ("%s %p toplevel is visible but not mapped",
8674 G_OBJECT_TYPE_NAME (widget), widget);
8679 /* Parent related checks aren't possible if parent has
8680 * verifying_invariants_count > 0 because parent needs to recurse
8681 * children first before the invariants will hold.
8683 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8686 parent->priv->realized)
8688 /* Parent realized implies... */
8691 /* This is in widget_system.txt but appears to fail
8692 * because there's no gtk_container_realize() that
8693 * realizes all children... instead we just lazily
8694 * wait for map to fix things up.
8696 if (!widget->priv->realized)
8697 g_warning ("%s %p is realized but child %s %p is not realized",
8698 G_OBJECT_TYPE_NAME (parent), parent,
8699 G_OBJECT_TYPE_NAME (widget), widget);
8702 else if (!widget->priv->toplevel)
8704 /* No parent or parent not realized on non-toplevel implies... */
8706 if (widget->priv->realized && !widget->priv->in_reparent)
8707 g_warning ("%s %p is not realized but child %s %p is realized",
8708 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8709 G_OBJECT_TYPE_NAME (widget), widget);
8713 parent->priv->mapped &&
8714 widget->priv->visible &&
8715 widget->priv->child_visible)
8717 /* Parent mapped and we are visible implies... */
8719 if (!widget->priv->mapped)
8720 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8721 G_OBJECT_TYPE_NAME (parent), parent,
8722 G_OBJECT_TYPE_NAME (widget), widget);
8724 else if (!widget->priv->toplevel)
8726 /* No parent or parent not mapped on non-toplevel implies... */
8728 if (widget->priv->mapped && !widget->priv->in_reparent)
8729 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8730 G_OBJECT_TYPE_NAME (widget), widget,
8731 widget->priv->visible,
8732 widget->priv->child_visible,
8733 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8734 parent ? parent->priv->mapped : FALSE);
8738 if (!widget->priv->realized)
8740 /* Not realized implies... */
8743 /* widget_system.txt says these hold, but they don't. */
8744 if (widget->priv->alloc_needed)
8745 g_warning ("%s %p alloc needed but not realized",
8746 G_OBJECT_TYPE_NAME (widget), widget);
8748 if (widget->priv->width_request_needed)
8749 g_warning ("%s %p width request needed but not realized",
8750 G_OBJECT_TYPE_NAME (widget), widget);
8752 if (widget->priv->height_request_needed)
8753 g_warning ("%s %p height request needed but not realized",
8754 G_OBJECT_TYPE_NAME (widget), widget);
8759 /* The point of this push/pop is that invariants may not hold while
8760 * we're busy making changes. So we only check at the outermost call
8761 * on the call stack, after we finish updating everything.
8764 gtk_widget_push_verify_invariants (GtkWidget *widget)
8766 widget->priv->verifying_invariants_count += 1;
8770 gtk_widget_verify_child_invariants (GtkWidget *widget,
8771 gpointer client_data)
8773 /* We don't recurse further; this is a one-level check. */
8774 gtk_widget_verify_invariants (widget);
8778 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8780 g_assert (widget->priv->verifying_invariants_count > 0);
8782 widget->priv->verifying_invariants_count -= 1;
8784 if (widget->priv->verifying_invariants_count == 0)
8786 gtk_widget_verify_invariants (widget);
8788 if (GTK_IS_CONTAINER (widget))
8790 /* Check one level of children, because our
8791 * push_verify_invariants() will have prevented some of the
8792 * checks. This does not recurse because if recursion is
8793 * needed, it will happen naturally as each child has a
8794 * push/pop on that child. For example if we're recursively
8795 * mapping children, we'll push/pop on each child as we map
8798 gtk_container_forall (GTK_CONTAINER (widget),
8799 gtk_widget_verify_child_invariants,
8804 #endif /* G_ENABLE_DEBUG */
8806 static PangoContext *
8807 gtk_widget_peek_pango_context (GtkWidget *widget)
8809 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8813 * gtk_widget_get_pango_context:
8814 * @widget: a #GtkWidget
8816 * Gets a #PangoContext with the appropriate font map, font description,
8817 * and base direction for this widget. Unlike the context returned
8818 * by gtk_widget_create_pango_context(), this context is owned by
8819 * the widget (it can be used until the screen for the widget changes
8820 * or the widget is removed from its toplevel), and will be updated to
8821 * match any changes to the widget's attributes. This can be tracked
8822 * by using the #GtkWidget::screen-changed signal on the widget.
8824 * Return value: (transfer none): the #PangoContext for the widget.
8827 gtk_widget_get_pango_context (GtkWidget *widget)
8829 PangoContext *context;
8831 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8833 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8836 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8837 g_object_set_qdata_full (G_OBJECT (widget),
8838 quark_pango_context,
8847 update_pango_context (GtkWidget *widget,
8848 PangoContext *context)
8850 PangoFontDescription *font_desc;
8851 GtkStyleContext *style_context;
8853 style_context = gtk_widget_get_style_context (widget);
8854 gtk_style_context_get (style_context,
8855 gtk_widget_get_state_flags (widget),
8859 pango_context_set_font_description (context, font_desc);
8860 pango_context_set_base_dir (context,
8861 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8862 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8864 pango_font_description_free (font_desc);
8868 gtk_widget_update_pango_context (GtkWidget *widget)
8870 PangoContext *context = gtk_widget_peek_pango_context (widget);
8876 update_pango_context (widget, context);
8878 screen = gtk_widget_get_screen_unchecked (widget);
8881 pango_cairo_context_set_resolution (context,
8882 gdk_screen_get_resolution (screen));
8883 pango_cairo_context_set_font_options (context,
8884 gdk_screen_get_font_options (screen));
8890 * gtk_widget_create_pango_context:
8891 * @widget: a #GtkWidget
8893 * Creates a new #PangoContext with the appropriate font map,
8894 * font description, and base direction for drawing text for
8895 * this widget. See also gtk_widget_get_pango_context().
8897 * Return value: (transfer full): the new #PangoContext
8900 gtk_widget_create_pango_context (GtkWidget *widget)
8903 PangoContext *context;
8905 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8907 screen = gtk_widget_get_screen_unchecked (widget);
8910 GTK_NOTE (MULTIHEAD,
8911 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8913 screen = gdk_screen_get_default ();
8916 context = gdk_pango_context_get_for_screen (screen);
8918 update_pango_context (widget, context);
8919 pango_context_set_language (context, gtk_get_default_language ());
8925 * gtk_widget_create_pango_layout:
8926 * @widget: a #GtkWidget
8927 * @text: text to set on the layout (can be %NULL)
8929 * Creates a new #PangoLayout with the appropriate font map,
8930 * font description, and base direction for drawing text for
8933 * If you keep a #PangoLayout created in this way around, you need
8934 * to re-create it when the widget #PangoContext is replaced.
8935 * This can be tracked by using the #GtkWidget::screen-changed signal
8938 * Return value: (transfer full): the new #PangoLayout
8941 gtk_widget_create_pango_layout (GtkWidget *widget,
8944 PangoLayout *layout;
8945 PangoContext *context;
8947 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8949 context = gtk_widget_get_pango_context (widget);
8950 layout = pango_layout_new (context);
8953 pango_layout_set_text (layout, text, -1);
8959 * gtk_widget_render_icon_pixbuf:
8960 * @widget: a #GtkWidget
8961 * @stock_id: a stock ID
8962 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8963 * render at the size of the source and don't scale (if there are
8964 * multiple source sizes, GTK+ picks one of the available sizes).
8966 * A convenience function that uses the theme engine and style
8967 * settings for @widget to look up @stock_id and render it to
8968 * a pixbuf. @stock_id should be a stock icon ID such as
8969 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8970 * such as #GTK_ICON_SIZE_MENU.
8972 * The pixels in the returned #GdkPixbuf are shared with the rest of
8973 * the application and should not be modified. The pixbuf should be freed
8974 * after use with g_object_unref().
8976 * Return value: (transfer full): a new pixbuf, or %NULL if the
8977 * stock ID wasn't known
8982 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8983 const gchar *stock_id,
8986 GtkStyleContext *context;
8987 GtkIconSet *icon_set;
8989 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8990 g_return_val_if_fail (stock_id != NULL, NULL);
8991 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8993 context = gtk_widget_get_style_context (widget);
8994 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
8996 if (icon_set == NULL)
8999 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9003 * gtk_widget_set_parent_window:
9004 * @widget: a #GtkWidget.
9005 * @parent_window: the new parent window.
9007 * Sets a non default parent window for @widget.
9009 * For GtkWindow classes, setting a @parent_window effects whether
9010 * the window is a toplevel window or can be embedded into other
9014 * For GtkWindow classes, this needs to be called before the
9015 * window is realized.
9020 gtk_widget_set_parent_window (GtkWidget *widget,
9021 GdkWindow *parent_window)
9023 GdkWindow *old_parent_window;
9025 g_return_if_fail (GTK_IS_WIDGET (widget));
9027 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9028 quark_parent_window);
9030 if (parent_window != old_parent_window)
9034 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9036 if (old_parent_window)
9037 g_object_unref (old_parent_window);
9039 g_object_ref (parent_window);
9041 /* Unset toplevel flag when adding a parent window to a widget,
9042 * this is the primary entry point to allow toplevels to be
9045 #ifdef GDK_WINDOWING_X11
9046 is_plug = GTK_IS_PLUG (widget);
9050 if (GTK_IS_WINDOW (widget) && !is_plug)
9051 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9056 * gtk_widget_get_parent_window:
9057 * @widget: a #GtkWidget.
9059 * Gets @widget's parent window.
9061 * Returns: (transfer none): the parent window of @widget.
9064 gtk_widget_get_parent_window (GtkWidget *widget)
9066 GtkWidgetPrivate *priv;
9067 GdkWindow *parent_window;
9069 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9071 priv = widget->priv;
9073 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9075 return (parent_window != NULL) ? parent_window :
9076 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9081 * gtk_widget_set_child_visible:
9082 * @widget: a #GtkWidget
9083 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9085 * Sets whether @widget should be mapped along with its when its parent
9086 * is mapped and @widget has been shown with gtk_widget_show().
9088 * The child visibility can be set for widget before it is added to
9089 * a container with gtk_widget_set_parent(), to avoid mapping
9090 * children unnecessary before immediately unmapping them. However
9091 * it will be reset to its default state of %TRUE when the widget
9092 * is removed from a container.
9094 * Note that changing the child visibility of a widget does not
9095 * queue a resize on the widget. Most of the time, the size of
9096 * a widget is computed from all visible children, whether or
9097 * not they are mapped. If this is not the case, the container
9098 * can queue a resize itself.
9100 * This function is only useful for container implementations and
9101 * never should be called by an application.
9104 gtk_widget_set_child_visible (GtkWidget *widget,
9105 gboolean is_visible)
9107 GtkWidgetPrivate *priv;
9109 g_return_if_fail (GTK_IS_WIDGET (widget));
9110 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9112 priv = widget->priv;
9114 g_object_ref (widget);
9115 gtk_widget_verify_invariants (widget);
9118 priv->child_visible = TRUE;
9121 GtkWidget *toplevel;
9123 priv->child_visible = FALSE;
9125 toplevel = gtk_widget_get_toplevel (widget);
9126 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9127 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9130 if (priv->parent && gtk_widget_get_realized (priv->parent))
9132 if (gtk_widget_get_mapped (priv->parent) &&
9133 priv->child_visible &&
9134 gtk_widget_get_visible (widget))
9135 gtk_widget_map (widget);
9137 gtk_widget_unmap (widget);
9140 gtk_widget_verify_invariants (widget);
9141 g_object_unref (widget);
9145 * gtk_widget_get_child_visible:
9146 * @widget: a #GtkWidget
9148 * Gets the value set with gtk_widget_set_child_visible().
9149 * If you feel a need to use this function, your code probably
9150 * needs reorganization.
9152 * This function is only useful for container implementations and
9153 * never should be called by an application.
9155 * Return value: %TRUE if the widget is mapped with the parent.
9158 gtk_widget_get_child_visible (GtkWidget *widget)
9160 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9162 return widget->priv->child_visible;
9166 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9168 GtkWidget *toplevel;
9170 toplevel = gtk_widget_get_toplevel (widget);
9172 if (gtk_widget_is_toplevel (toplevel))
9174 if (GTK_IS_WINDOW (toplevel))
9175 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9176 else if (GTK_IS_INVISIBLE (toplevel))
9177 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9184 * gtk_widget_get_screen:
9185 * @widget: a #GtkWidget
9187 * Get the #GdkScreen from the toplevel window associated with
9188 * this widget. This function can only be called after the widget
9189 * has been added to a widget hierarchy with a #GtkWindow
9192 * In general, you should only create screen specific
9193 * resources when a widget has been realized, and you should
9194 * free those resources when the widget is unrealized.
9196 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9201 gtk_widget_get_screen (GtkWidget *widget)
9205 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9207 screen = gtk_widget_get_screen_unchecked (widget);
9214 g_warning (G_STRLOC ": Can't get associated screen"
9215 " for a widget unless it is inside a toplevel GtkWindow\n"
9216 " widget type is %s associated top level type is %s",
9217 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9218 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9220 return gdk_screen_get_default ();
9225 * gtk_widget_has_screen:
9226 * @widget: a #GtkWidget
9228 * Checks whether there is a #GdkScreen is associated with
9229 * this widget. All toplevel widgets have an associated
9230 * screen, and all widgets added into a hierarchy with a toplevel
9231 * window at the top.
9233 * Return value: %TRUE if there is a #GdkScreen associcated
9239 gtk_widget_has_screen (GtkWidget *widget)
9241 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9243 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9247 * gtk_widget_get_display:
9248 * @widget: a #GtkWidget
9250 * Get the #GdkDisplay for the toplevel window associated with
9251 * this widget. This function can only be called after the widget
9252 * has been added to a widget hierarchy with a #GtkWindow at the top.
9254 * In general, you should only create display specific
9255 * resources when a widget has been realized, and you should
9256 * free those resources when the widget is unrealized.
9258 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9263 gtk_widget_get_display (GtkWidget *widget)
9265 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9267 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9271 * gtk_widget_get_root_window:
9272 * @widget: a #GtkWidget
9274 * Get the root window where this widget is located. This function can
9275 * only be called after the widget has been added to a widget
9276 * hierarchy with #GtkWindow at the top.
9278 * The root window is useful for such purposes as creating a popup
9279 * #GdkWindow associated with the window. In general, you should only
9280 * create display specific resources when a widget has been realized,
9281 * and you should free those resources when the widget is unrealized.
9283 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9288 gtk_widget_get_root_window (GtkWidget *widget)
9290 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9292 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9296 * gtk_widget_child_focus:
9297 * @widget: a #GtkWidget
9298 * @direction: direction of focus movement
9300 * This function is used by custom widget implementations; if you're
9301 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9302 * to a particular widget, and gtk_container_set_focus_chain() to
9303 * change the focus tab order. So you may want to investigate those
9304 * functions instead.
9306 * gtk_widget_child_focus() is called by containers as the user moves
9307 * around the window using keyboard shortcuts. @direction indicates
9308 * what kind of motion is taking place (up, down, left, right, tab
9309 * forward, tab backward). gtk_widget_child_focus() emits the
9310 * #GtkWidget::focus signal; widgets override the default handler
9311 * for this signal in order to implement appropriate focus behavior.
9313 * The default ::focus handler for a widget should return %TRUE if
9314 * moving in @direction left the focus on a focusable location inside
9315 * that widget, and %FALSE if moving in @direction moved the focus
9316 * outside the widget. If returning %TRUE, widgets normally
9317 * call gtk_widget_grab_focus() to place the focus accordingly;
9318 * if returning %FALSE, they don't modify the current focus location.
9320 * Return value: %TRUE if focus ended up inside @widget
9323 gtk_widget_child_focus (GtkWidget *widget,
9324 GtkDirectionType direction)
9326 gboolean return_val;
9328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9330 if (!gtk_widget_get_visible (widget) ||
9331 !gtk_widget_is_sensitive (widget))
9334 /* child widgets must set CAN_FOCUS, containers
9335 * don't have to though.
9337 if (!GTK_IS_CONTAINER (widget) &&
9338 !gtk_widget_get_can_focus (widget))
9341 g_signal_emit (widget,
9342 widget_signals[FOCUS],
9344 direction, &return_val);
9350 * gtk_widget_keynav_failed:
9351 * @widget: a #GtkWidget
9352 * @direction: direction of focus movement
9354 * This function should be called whenever keyboard navigation within
9355 * a single widget hits a boundary. The function emits the
9356 * #GtkWidget::keynav-failed signal on the widget and its return
9357 * value should be interpreted in a way similar to the return value of
9358 * gtk_widget_child_focus():
9360 * When %TRUE is returned, stay in the widget, the failed keyboard
9361 * navigation is Ok and/or there is nowhere we can/should move the
9364 * When %FALSE is returned, the caller should continue with keyboard
9365 * navigation outside the widget, e.g. by calling
9366 * gtk_widget_child_focus() on the widget's toplevel.
9368 * The default ::keynav-failed handler returns %TRUE for
9369 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9370 * values of #GtkDirectionType, it looks at the
9371 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9372 * if the setting is %TRUE. This way the entire user interface
9373 * becomes cursor-navigatable on input devices such as mobile phones
9374 * which only have cursor keys but no tab key.
9376 * Whenever the default handler returns %TRUE, it also calls
9377 * gtk_widget_error_bell() to notify the user of the failed keyboard
9380 * A use case for providing an own implementation of ::keynav-failed
9381 * (either by connecting to it or by overriding it) would be a row of
9382 * #GtkEntry widgets where the user should be able to navigate the
9383 * entire row with the cursor keys, as e.g. known from user interfaces
9384 * that require entering license keys.
9386 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9387 * if the emitting widget should try to handle the keyboard
9388 * navigation attempt in its parent container(s).
9393 gtk_widget_keynav_failed (GtkWidget *widget,
9394 GtkDirectionType direction)
9396 gboolean return_val;
9398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9400 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9401 direction, &return_val);
9407 * gtk_widget_error_bell:
9408 * @widget: a #GtkWidget
9410 * Notifies the user about an input-related error on this widget.
9411 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9412 * gdk_window_beep(), otherwise it does nothing.
9414 * Note that the effect of gdk_window_beep() can be configured in many
9415 * ways, depending on the windowing backend and the desktop environment
9416 * or window manager that is used.
9421 gtk_widget_error_bell (GtkWidget *widget)
9423 GtkWidgetPrivate *priv;
9424 GtkSettings* settings;
9427 g_return_if_fail (GTK_IS_WIDGET (widget));
9429 priv = widget->priv;
9431 settings = gtk_widget_get_settings (widget);
9435 g_object_get (settings,
9436 "gtk-error-bell", &beep,
9439 if (beep && priv->window)
9440 gdk_window_beep (priv->window);
9444 gtk_widget_set_usize_internal (GtkWidget *widget,
9447 GtkQueueResizeFlags flags)
9449 GtkWidgetAuxInfo *aux_info;
9450 gboolean changed = FALSE;
9452 g_object_freeze_notify (G_OBJECT (widget));
9454 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9456 if (width > -2 && aux_info->width != width)
9458 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9459 g_object_notify (G_OBJECT (widget), "width-request");
9460 aux_info->width = width;
9463 if (height > -2 && aux_info->height != height)
9465 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9466 g_object_notify (G_OBJECT (widget), "height-request");
9467 aux_info->height = height;
9471 if (gtk_widget_get_visible (widget) && changed)
9473 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9474 gtk_widget_queue_resize (widget);
9476 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9479 g_object_thaw_notify (G_OBJECT (widget));
9483 * gtk_widget_set_size_request:
9484 * @widget: a #GtkWidget
9485 * @width: width @widget should request, or -1 to unset
9486 * @height: height @widget should request, or -1 to unset
9488 * Sets the minimum size of a widget; that is, the widget's size
9489 * request will be at least @width by @height. You can use this
9490 * function to force a widget to be larger than it normally would be.
9492 * In most cases, gtk_window_set_default_size() is a better choice for
9493 * toplevel windows than this function; setting the default size will
9494 * still allow users to shrink the window. Setting the size request
9495 * will force them to leave the window at least as large as the size
9496 * request. When dealing with window sizes,
9497 * gtk_window_set_geometry_hints() can be a useful function as well.
9499 * Note the inherent danger of setting any fixed size - themes,
9500 * translations into other languages, different fonts, and user action
9501 * can all change the appropriate size for a given widget. So, it's
9502 * basically impossible to hardcode a size that will always be
9505 * The size request of a widget is the smallest size a widget can
9506 * accept while still functioning well and drawing itself correctly.
9507 * However in some strange cases a widget may be allocated less than
9508 * its requested size, and in many cases a widget may be allocated more
9509 * space than it requested.
9511 * If the size request in a given direction is -1 (unset), then
9512 * the "natural" size request of the widget will be used instead.
9514 * The size request set here does not include any margin from the
9515 * #GtkWidget properties margin-left, margin-right, margin-top, and
9516 * margin-bottom, but it does include pretty much all other padding
9517 * or border properties set by any subclass of #GtkWidget.
9520 gtk_widget_set_size_request (GtkWidget *widget,
9524 g_return_if_fail (GTK_IS_WIDGET (widget));
9525 g_return_if_fail (width >= -1);
9526 g_return_if_fail (height >= -1);
9533 gtk_widget_set_usize_internal (widget, width, height, 0);
9538 * gtk_widget_get_size_request:
9539 * @widget: a #GtkWidget
9540 * @width: (out) (allow-none): return location for width, or %NULL
9541 * @height: (out) (allow-none): return location for height, or %NULL
9543 * Gets the size request that was explicitly set for the widget using
9544 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9545 * @height indicates that that dimension has not been set explicitly
9546 * and the natural requisition of the widget will be used intead. See
9547 * gtk_widget_set_size_request(). To get the size a widget will
9548 * actually request, call gtk_widget_get_preferred_size() instead of
9552 gtk_widget_get_size_request (GtkWidget *widget,
9556 const GtkWidgetAuxInfo *aux_info;
9558 g_return_if_fail (GTK_IS_WIDGET (widget));
9560 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9563 *width = aux_info->width;
9566 *height = aux_info->height;
9570 * _gtk_widget_override_size_request:
9571 * @widget: a #GtkWidget
9572 * @width: new forced minimum width
9573 * @height: new forced minimum height
9574 * @old_width: location to store previous forced minimum width
9575 * @old_height: location to store previous forced minumum height
9577 * Temporarily establishes a forced minimum size for a widget; this
9578 * is used by GtkWindow when calculating the size to add to the
9579 * window's geometry widget. Cached sizes for the widget and its
9580 * parents are invalidated, so that subsequent calls to the size
9581 * negotiation machinery produce the overriden result, but the
9582 * widget is not queued for relayout or redraw. The old size must
9583 * be restored with _gtk_widget_restore_size_request() or things
9587 _gtk_widget_override_size_request (GtkWidget *widget,
9593 gtk_widget_get_size_request (widget, old_width, old_height);
9594 gtk_widget_set_usize_internal (widget, width, height,
9595 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9599 * _gtk_widget_restore_size_request:
9600 * @widget: a #GtkWidget
9601 * @old_width: saved forced minimum size
9602 * @old_height: saved forced minimum size
9604 * Undoes the operation of_gtk_widget_override_size_request().
9607 _gtk_widget_restore_size_request (GtkWidget *widget,
9611 gtk_widget_set_usize_internal (widget, old_width, old_height,
9612 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9616 * gtk_widget_set_events:
9617 * @widget: a #GtkWidget
9618 * @events: event mask
9620 * Sets the event mask (see #GdkEventMask) for a widget. The event
9621 * mask determines which events a widget will receive. Keep in mind
9622 * that different widgets have different default event masks, and by
9623 * changing the event mask you may disrupt a widget's functionality,
9624 * so be careful. This function must be called while a widget is
9625 * unrealized. Consider gtk_widget_add_events() for widgets that are
9626 * already realized, or if you want to preserve the existing event
9627 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9628 * to get events on those widgets, place them inside a #GtkEventBox
9629 * and receive events on the event box.
9632 gtk_widget_set_events (GtkWidget *widget,
9635 g_return_if_fail (GTK_IS_WIDGET (widget));
9636 g_return_if_fail (!gtk_widget_get_realized (widget));
9638 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9639 GINT_TO_POINTER (events));
9640 g_object_notify (G_OBJECT (widget), "events");
9644 * gtk_widget_set_device_events:
9645 * @widget: a #GtkWidget
9646 * @device: a #GdkDevice
9647 * @events: event mask
9649 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9650 * mask determines which events a widget will receive from @device. Keep
9651 * in mind that different widgets have different default event masks, and by
9652 * changing the event mask you may disrupt a widget's functionality,
9653 * so be careful. This function must be called while a widget is
9654 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9655 * already realized, or if you want to preserve the existing event
9656 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9657 * to get events on those widgets, place them inside a #GtkEventBox
9658 * and receive events on the event box.
9663 gtk_widget_set_device_events (GtkWidget *widget,
9665 GdkEventMask events)
9667 GHashTable *device_events;
9669 g_return_if_fail (GTK_IS_WIDGET (widget));
9670 g_return_if_fail (GDK_IS_DEVICE (device));
9671 g_return_if_fail (!gtk_widget_get_realized (widget));
9673 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9675 if (G_UNLIKELY (!device_events))
9677 device_events = g_hash_table_new (NULL, NULL);
9678 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9679 (GDestroyNotify) g_hash_table_unref);
9682 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9686 * gtk_widget_set_device_enabled:
9687 * @widget: a #GtkWidget
9688 * @device: a #GdkDevice
9689 * @enabled: whether to enable the device
9691 * Enables or disables a #GdkDevice to interact with @widget
9692 * and all its children.
9694 * It does so by descending through the #GdkWindow hierarchy
9695 * and enabling the same mask that is has for core events
9696 * (i.e. the one that gdk_window_get_events() returns).
9701 gtk_widget_set_device_enabled (GtkWidget *widget,
9705 GList *enabled_devices;
9707 g_return_if_fail (GTK_IS_WIDGET (widget));
9708 g_return_if_fail (GDK_IS_DEVICE (device));
9710 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9711 enabled_devices = g_list_append (enabled_devices, device);
9713 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9714 enabled_devices, (GDestroyNotify) g_list_free);;
9716 if (gtk_widget_get_realized (widget))
9717 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9721 * gtk_widget_get_device_enabled:
9722 * @widget: a #GtkWidget
9723 * @device: a #GdkDevice
9725 * Returns whether @device can interact with @widget and its
9726 * children. See gtk_widget_set_device_enabled().
9728 * Return value: %TRUE is @device is enabled for @widget
9733 gtk_widget_get_device_enabled (GtkWidget *widget,
9736 GList *enabled_devices;
9738 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9739 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9741 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9743 return g_list_find (enabled_devices, device) != NULL;
9747 gtk_widget_add_events_internal_list (GtkWidget *widget,
9754 for (l = window_list; l != NULL; l = l->next)
9756 GdkWindow *window = l->data;
9759 gdk_window_get_user_data (window, &user_data);
9760 if (user_data == widget)
9765 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9767 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9769 children = gdk_window_get_children (window);
9770 gtk_widget_add_events_internal_list (widget, device, events, children);
9771 g_list_free (children);
9777 gtk_widget_add_events_internal (GtkWidget *widget,
9781 GtkWidgetPrivate *priv = widget->priv;
9784 if (!gtk_widget_get_has_window (widget))
9785 window_list = gdk_window_get_children (priv->window);
9787 window_list = g_list_prepend (NULL, priv->window);
9789 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9791 g_list_free (window_list);
9795 * gtk_widget_add_events:
9796 * @widget: a #GtkWidget
9797 * @events: an event mask, see #GdkEventMask
9799 * Adds the events in the bitfield @events to the event mask for
9800 * @widget. See gtk_widget_set_events() for details.
9803 gtk_widget_add_events (GtkWidget *widget,
9808 g_return_if_fail (GTK_IS_WIDGET (widget));
9810 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9811 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9812 GINT_TO_POINTER (old_events | events));
9814 if (gtk_widget_get_realized (widget))
9816 gtk_widget_add_events_internal (widget, NULL, events);
9817 gtk_widget_update_devices_mask (widget, FALSE);
9820 g_object_notify (G_OBJECT (widget), "events");
9824 * gtk_widget_add_device_events:
9825 * @widget: a #GtkWidget
9826 * @device: a #GdkDevice
9827 * @events: an event mask, see #GdkEventMask
9829 * Adds the device events in the bitfield @events to the event mask for
9830 * @widget. See gtk_widget_set_device_events() for details.
9835 gtk_widget_add_device_events (GtkWidget *widget,
9837 GdkEventMask events)
9839 GdkEventMask old_events;
9840 GHashTable *device_events;
9842 g_return_if_fail (GTK_IS_WIDGET (widget));
9843 g_return_if_fail (GDK_IS_DEVICE (device));
9845 old_events = gtk_widget_get_device_events (widget, device);
9847 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9849 if (G_UNLIKELY (!device_events))
9851 device_events = g_hash_table_new (NULL, NULL);
9852 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9853 (GDestroyNotify) g_hash_table_unref);
9856 g_hash_table_insert (device_events, device,
9857 GUINT_TO_POINTER (old_events | events));
9859 if (gtk_widget_get_realized (widget))
9860 gtk_widget_add_events_internal (widget, device, events);
9862 g_object_notify (G_OBJECT (widget), "events");
9866 * gtk_widget_get_toplevel:
9867 * @widget: a #GtkWidget
9869 * This function returns the topmost widget in the container hierarchy
9870 * @widget is a part of. If @widget has no parent widgets, it will be
9871 * returned as the topmost widget. No reference will be added to the
9872 * returned widget; it should not be unreferenced.
9874 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9875 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9877 * %NULL if @widget wasn't inside a toplevel window, and if the
9878 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9879 * inside the toplevel #GtkWindow. While the second case may
9880 * seem unlikely, it actually happens when a #GtkPlug is embedded
9881 * inside a #GtkSocket within the same application.
9883 * To reliably find the toplevel #GtkWindow, use
9884 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9885 * is set on the result.
9887 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9888 * if (gtk_widget_is_toplevel (toplevel))
9890 * /* Perform action on toplevel. */
9894 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9895 * if there's no ancestor.
9898 gtk_widget_get_toplevel (GtkWidget *widget)
9900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9902 while (widget->priv->parent)
9903 widget = widget->priv->parent;
9909 * gtk_widget_get_ancestor:
9910 * @widget: a #GtkWidget
9911 * @widget_type: ancestor type
9913 * Gets the first ancestor of @widget with type @widget_type. For example,
9914 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9915 * the first #GtkBox that's an ancestor of @widget. No reference will be
9916 * added to the returned widget; it should not be unreferenced. See note
9917 * about checking for a toplevel #GtkWindow in the docs for
9918 * gtk_widget_get_toplevel().
9920 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9921 * considers @widget to be an ancestor of itself.
9923 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9926 gtk_widget_get_ancestor (GtkWidget *widget,
9929 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9931 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9932 widget = widget->priv->parent;
9934 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9941 * gtk_widget_set_visual:
9942 * @widget: a #GtkWidget
9943 * @visual: visual to be used or %NULL to unset a previous one
9945 * Sets the visual that should be used for by widget and its children for
9946 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9947 * returned by gtk_widget_get_screen(), so handling the
9948 * #GtkWidget::screen-changed signal is necessary.
9950 * Setting a new @visual will not cause @widget to recreate its windows,
9951 * so you should call this function before @widget is realized.
9954 gtk_widget_set_visual (GtkWidget *widget,
9957 g_return_if_fail (GTK_IS_WIDGET (widget));
9958 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9961 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9964 g_object_set_qdata_full (G_OBJECT (widget),
9966 g_object_ref (visual),
9971 * gtk_widget_get_visual:
9972 * @widget: a #GtkWidget
9974 * Gets the visual that will be used to render @widget.
9976 * Return value: (transfer none): the visual for @widget
9979 gtk_widget_get_visual (GtkWidget *widget)
9985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9987 if (gtk_widget_get_has_window (widget) &&
9988 widget->priv->window)
9989 return gdk_window_get_visual (widget->priv->window);
9991 screen = gtk_widget_get_screen (widget);
9993 for (w = widget; w != NULL; w = w->priv->parent)
9995 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9998 if (gdk_visual_get_screen (visual) == screen)
10001 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10002 gtk_widget_get_name (widget));
10006 return gdk_screen_get_system_visual (screen);
10010 * gtk_widget_get_settings:
10011 * @widget: a #GtkWidget
10013 * Gets the settings object holding the settings used for this widget.
10015 * Note that this function can only be called when the #GtkWidget
10016 * is attached to a toplevel, since the settings object is specific
10017 * to a particular #GdkScreen.
10019 * Return value: (transfer none): the relevant #GtkSettings object
10022 gtk_widget_get_settings (GtkWidget *widget)
10024 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10026 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10030 * gtk_widget_get_events:
10031 * @widget: a #GtkWidget
10033 * Returns the event mask for the widget (a bitfield containing flags
10034 * from the #GdkEventMask enumeration). These are the events that the widget
10037 * Return value: event mask for @widget
10040 gtk_widget_get_events (GtkWidget *widget)
10042 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10044 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10048 * gtk_widget_get_device_events:
10049 * @widget: a #GtkWidget
10050 * @device: a #GdkDevice
10052 * Returns the events mask for the widget corresponding to an specific device. These
10053 * are the events that the widget will receive when @device operates on it.
10055 * Returns: device event mask for @widget
10060 gtk_widget_get_device_events (GtkWidget *widget,
10063 GHashTable *device_events;
10065 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10066 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10068 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10070 if (!device_events)
10073 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10077 * gtk_widget_get_pointer:
10078 * @widget: a #GtkWidget
10079 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10080 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10082 * Obtains the location of the mouse pointer in widget coordinates.
10083 * Widget coordinates are a bit odd; for historical reasons, they are
10084 * defined as @widget->window coordinates for widgets that are not
10085 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10086 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10088 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10091 gtk_widget_get_pointer (GtkWidget *widget,
10095 GtkWidgetPrivate *priv;
10097 g_return_if_fail (GTK_IS_WIDGET (widget));
10099 priv = widget->priv;
10106 if (gtk_widget_get_realized (widget))
10108 gdk_window_get_device_position (priv->window,
10109 gdk_device_manager_get_client_pointer (
10110 gdk_display_get_device_manager (
10111 gtk_widget_get_display (widget))),
10114 if (!gtk_widget_get_has_window (widget))
10117 *x -= priv->allocation.x;
10119 *y -= priv->allocation.y;
10125 * gtk_widget_is_ancestor:
10126 * @widget: a #GtkWidget
10127 * @ancestor: another #GtkWidget
10129 * Determines whether @widget is somewhere inside @ancestor, possibly with
10130 * intermediate containers.
10132 * Return value: %TRUE if @ancestor contains @widget as a child,
10133 * grandchild, great grandchild, etc.
10136 gtk_widget_is_ancestor (GtkWidget *widget,
10137 GtkWidget *ancestor)
10139 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10140 g_return_val_if_fail (ancestor != NULL, FALSE);
10144 if (widget->priv->parent == ancestor)
10146 widget = widget->priv->parent;
10152 static GQuark quark_composite_name = 0;
10155 * gtk_widget_set_composite_name:
10156 * @widget: a #GtkWidget.
10157 * @name: the name to set
10159 * Sets a widgets composite name. The widget must be
10160 * a composite child of its parent; see gtk_widget_push_composite_child().
10163 gtk_widget_set_composite_name (GtkWidget *widget,
10166 g_return_if_fail (GTK_IS_WIDGET (widget));
10167 g_return_if_fail (widget->priv->composite_child);
10168 g_return_if_fail (name != NULL);
10170 if (!quark_composite_name)
10171 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10173 g_object_set_qdata_full (G_OBJECT (widget),
10174 quark_composite_name,
10180 * gtk_widget_get_composite_name:
10181 * @widget: a #GtkWidget
10183 * Obtains the composite name of a widget.
10185 * Returns: the composite name of @widget, or %NULL if @widget is not
10186 * a composite child. The string should be freed when it is no
10190 gtk_widget_get_composite_name (GtkWidget *widget)
10192 GtkWidgetPrivate *priv;
10194 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10196 priv = widget->priv;
10198 if (widget->priv->composite_child && priv->parent)
10199 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10206 * gtk_widget_push_composite_child:
10208 * Makes all newly-created widgets as composite children until
10209 * the corresponding gtk_widget_pop_composite_child() call.
10211 * A composite child is a child that's an implementation detail of the
10212 * container it's inside and should not be visible to people using the
10213 * container. Composite children aren't treated differently by GTK (but
10214 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10215 * builders might want to treat them in a different way.
10217 * Here is a simple example:
10219 * gtk_widget_push_composite_child ();
10220 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10221 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10222 * gtk_widget_pop_composite_child ();
10223 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10224 * GTK_WIDGET (scrolled_window));
10225 * g_object_ref (scrolled_window->hscrollbar);
10229 gtk_widget_push_composite_child (void)
10231 composite_child_stack++;
10235 * gtk_widget_pop_composite_child:
10237 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10240 gtk_widget_pop_composite_child (void)
10242 if (composite_child_stack)
10243 composite_child_stack--;
10247 gtk_widget_emit_direction_changed (GtkWidget *widget,
10248 GtkTextDirection old_dir)
10250 GtkTextDirection direction;
10251 GtkStateFlags state;
10253 gtk_widget_update_pango_context (widget);
10255 direction = gtk_widget_get_direction (widget);
10256 state = widget->priv->state_flags;
10257 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10261 case GTK_TEXT_DIR_LTR:
10262 state |= GTK_STATE_FLAG_DIR_LTR;
10265 case GTK_TEXT_DIR_RTL:
10266 state |= GTK_STATE_FLAG_DIR_RTL;
10269 case GTK_TEXT_DIR_NONE:
10271 g_assert_not_reached ();
10275 gtk_widget_set_state_flags (widget, state, TRUE);
10277 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10281 * gtk_widget_set_direction:
10282 * @widget: a #GtkWidget
10283 * @dir: the new direction
10285 * Sets the reading direction on a particular widget. This direction
10286 * controls the primary direction for widgets containing text,
10287 * and also the direction in which the children of a container are
10288 * packed. The ability to set the direction is present in order
10289 * so that correct localization into languages with right-to-left
10290 * reading directions can be done. Generally, applications will
10291 * let the default reading direction present, except for containers
10292 * where the containers are arranged in an order that is explicitely
10293 * visual rather than logical (such as buttons for text justification).
10295 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10296 * set by gtk_widget_set_default_direction() will be used.
10299 gtk_widget_set_direction (GtkWidget *widget,
10300 GtkTextDirection dir)
10302 GtkTextDirection old_dir;
10304 g_return_if_fail (GTK_IS_WIDGET (widget));
10305 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10307 old_dir = gtk_widget_get_direction (widget);
10309 widget->priv->direction = dir;
10311 if (old_dir != gtk_widget_get_direction (widget))
10312 gtk_widget_emit_direction_changed (widget, old_dir);
10316 * gtk_widget_get_direction:
10317 * @widget: a #GtkWidget
10319 * Gets the reading direction for a particular widget. See
10320 * gtk_widget_set_direction().
10322 * Return value: the reading direction for the widget.
10325 gtk_widget_get_direction (GtkWidget *widget)
10327 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10329 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10330 return gtk_default_direction;
10332 return widget->priv->direction;
10336 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10338 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10340 g_object_ref (widget);
10342 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10343 gtk_widget_emit_direction_changed (widget, old_dir);
10345 if (GTK_IS_CONTAINER (widget))
10346 gtk_container_forall (GTK_CONTAINER (widget),
10347 gtk_widget_set_default_direction_recurse,
10350 g_object_unref (widget);
10354 * gtk_widget_set_default_direction:
10355 * @dir: the new default direction. This cannot be
10356 * %GTK_TEXT_DIR_NONE.
10358 * Sets the default reading direction for widgets where the
10359 * direction has not been explicitly set by gtk_widget_set_direction().
10362 gtk_widget_set_default_direction (GtkTextDirection dir)
10364 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10366 if (dir != gtk_default_direction)
10368 GList *toplevels, *tmp_list;
10369 GtkTextDirection old_dir = gtk_default_direction;
10371 gtk_default_direction = dir;
10373 tmp_list = toplevels = gtk_window_list_toplevels ();
10374 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10378 gtk_widget_set_default_direction_recurse (tmp_list->data,
10379 GUINT_TO_POINTER (old_dir));
10380 g_object_unref (tmp_list->data);
10381 tmp_list = tmp_list->next;
10384 g_list_free (toplevels);
10389 * gtk_widget_get_default_direction:
10391 * Obtains the current default reading direction. See
10392 * gtk_widget_set_default_direction().
10394 * Return value: the current default direction.
10397 gtk_widget_get_default_direction (void)
10399 return gtk_default_direction;
10403 gtk_widget_constructed (GObject *object)
10405 GtkWidget *widget = GTK_WIDGET (object);
10406 GtkWidgetPrivate *priv = widget->priv;
10408 /* As strange as it may seem, this may happen on object construction.
10409 * init() implementations of parent types may eventually call this function,
10410 * each with its corresponding GType, which could leave a child
10411 * implementation with a wrong widget type in the widget path
10414 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10416 gtk_widget_path_free (priv->path);
10420 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10424 gtk_widget_dispose (GObject *object)
10426 GtkWidget *widget = GTK_WIDGET (object);
10427 GtkWidgetPrivate *priv = widget->priv;
10430 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10431 else if (gtk_widget_get_visible (widget))
10432 gtk_widget_hide (widget);
10434 priv->visible = FALSE;
10435 if (gtk_widget_get_realized (widget))
10436 gtk_widget_unrealize (widget);
10438 if (!priv->in_destruction)
10440 priv->in_destruction = TRUE;
10441 g_signal_emit (object, widget_signals[DESTROY], 0);
10442 priv->in_destruction = FALSE;
10445 g_clear_object (&priv->muxer);
10447 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10451 gtk_widget_real_destroy (GtkWidget *object)
10453 /* gtk_object_destroy() will already hold a refcount on object */
10454 GtkWidget *widget = GTK_WIDGET (object);
10455 GtkWidgetPrivate *priv = widget->priv;
10457 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10459 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10463 gtk_accessible_set_widget (accessible, NULL);
10464 g_object_unref (accessible);
10468 /* wipe accelerator closures (keep order) */
10469 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10470 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10472 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10473 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10475 gtk_grab_remove (widget);
10478 g_object_unref (priv->style);
10479 priv->style = gtk_widget_get_default_style ();
10480 g_object_ref (priv->style);
10484 gtk_widget_finalize (GObject *object)
10486 GtkWidget *widget = GTK_WIDGET (object);
10487 GtkWidgetPrivate *priv = widget->priv;
10488 GtkWidgetAuxInfo *aux_info;
10489 GtkAccessible *accessible;
10491 gtk_grab_remove (widget);
10493 g_object_unref (priv->style);
10494 priv->style = NULL;
10496 g_free (priv->name);
10498 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10500 gtk_widget_aux_info_destroy (aux_info);
10502 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10504 g_object_unref (accessible);
10507 gtk_widget_path_free (priv->path);
10511 _gtk_style_context_set_widget (priv->context, NULL);
10512 g_object_unref (priv->context);
10515 _gtk_size_request_cache_free (&priv->requests);
10517 if (g_object_is_floating (object))
10518 g_warning ("A floating object was finalized. This means that someone\n"
10519 "called g_object_unref() on an object that had only a floating\n"
10520 "reference; the initial floating reference is not owned by anyone\n"
10521 "and must be removed with g_object_ref_sink().");
10523 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10526 /*****************************************
10527 * gtk_widget_real_map:
10532 *****************************************/
10535 gtk_widget_real_map (GtkWidget *widget)
10537 GtkWidgetPrivate *priv = widget->priv;
10539 g_assert (gtk_widget_get_realized (widget));
10541 if (!gtk_widget_get_mapped (widget))
10543 gtk_widget_set_mapped (widget, TRUE);
10545 if (gtk_widget_get_has_window (widget))
10546 gdk_window_show (priv->window);
10550 /*****************************************
10551 * gtk_widget_real_unmap:
10556 *****************************************/
10559 gtk_widget_real_unmap (GtkWidget *widget)
10561 GtkWidgetPrivate *priv = widget->priv;
10563 if (gtk_widget_get_mapped (widget))
10565 gtk_widget_set_mapped (widget, FALSE);
10567 if (gtk_widget_get_has_window (widget))
10568 gdk_window_hide (priv->window);
10572 /*****************************************
10573 * gtk_widget_real_realize:
10578 *****************************************/
10581 gtk_widget_real_realize (GtkWidget *widget)
10583 GtkWidgetPrivate *priv = widget->priv;
10585 g_assert (!gtk_widget_get_has_window (widget));
10587 gtk_widget_set_realized (widget, TRUE);
10590 priv->window = gtk_widget_get_parent_window (widget);
10591 g_object_ref (priv->window);
10595 /*****************************************
10596 * gtk_widget_real_unrealize:
10601 *****************************************/
10604 gtk_widget_real_unrealize (GtkWidget *widget)
10606 GtkWidgetPrivate *priv = widget->priv;
10608 g_assert (!widget->priv->mapped);
10610 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10613 /* We must do unrealize child widget BEFORE container widget.
10614 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10615 * So, unrealizing container widget bofore its children causes the problem
10616 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10619 if (GTK_IS_CONTAINER (widget))
10620 gtk_container_forall (GTK_CONTAINER (widget),
10621 (GtkCallback) gtk_widget_unrealize,
10624 if (gtk_widget_get_has_window (widget))
10626 gtk_widget_unregister_window (widget, priv->window);
10627 gdk_window_destroy (priv->window);
10628 priv->window = NULL;
10632 g_object_unref (priv->window);
10633 priv->window = NULL;
10636 gtk_selection_remove_all (widget);
10638 gtk_widget_set_realized (widget, FALSE);
10642 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10643 GtkOrientation orientation,
10644 gint *minimum_size,
10645 gint *natural_size)
10647 const GtkWidgetAuxInfo *aux_info;
10649 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10651 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10652 aux_info->width > 0)
10654 *minimum_size = MAX (*minimum_size, aux_info->width);
10656 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10657 aux_info->height > 0)
10659 *minimum_size = MAX (*minimum_size, aux_info->height);
10662 /* Fix it if set_size_request made natural size smaller than min size.
10663 * This would also silently fix broken widgets, but we warn about them
10664 * in gtksizerequest.c when calling their size request vfuncs.
10666 *natural_size = MAX (*natural_size, *minimum_size);
10668 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10670 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10671 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10675 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10676 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10681 * _gtk_widget_peek_request_cache:
10683 * Returns the address of the widget's request cache (strictly for
10684 * internal use in gtksizerequest.c)
10686 * Return value: the address of @widget's size request cache.
10689 _gtk_widget_peek_request_cache (GtkWidget *widget)
10691 /* Don't bother slowing things down with the return_if_fail guards here */
10692 return &widget->priv->requests;
10696 * _gtk_widget_set_device_window:
10697 * @widget: a #GtkWidget
10698 * @device: a #GdkDevice
10699 * @window: the new device window
10701 * Sets pointer window for @widget and @device.
10702 * Does not ref @window.
10705 _gtk_widget_set_device_window (GtkWidget *widget,
10709 GHashTable *device_window;
10711 g_return_if_fail (GTK_IS_WIDGET (widget));
10712 g_return_if_fail (GDK_IS_DEVICE (device));
10713 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10715 if (!gtk_widget_get_mapped (widget))
10718 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10720 if (!device_window && window)
10722 device_window = g_hash_table_new (NULL, NULL);
10723 g_object_set_qdata_full (G_OBJECT (widget),
10724 quark_pointer_window,
10726 (GDestroyNotify) g_hash_table_destroy);
10730 g_hash_table_insert (device_window, device, window);
10731 else if (device_window)
10733 g_hash_table_remove (device_window, device);
10735 if (g_hash_table_size (device_window) == 0)
10736 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10741 * _gtk_widget_get_device_window:
10742 * @widget: a #GtkWidget
10743 * @device: a #GdkDevice
10745 * Return value: the device window set on @widget, or %NULL
10748 _gtk_widget_get_device_window (GtkWidget *widget,
10751 GHashTable *device_window;
10753 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10754 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10756 if (!gtk_widget_get_mapped (widget))
10759 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10761 if (!device_window)
10764 return g_hash_table_lookup (device_window, device);
10768 * _gtk_widget_list_devices:
10769 * @widget: a #GtkWidget
10771 * Returns the list of #GdkDevices that is currently on top
10772 * of any window belonging to @widget.
10773 * Free the list with g_list_free(), the elements are owned
10774 * by GTK+ and must not be freed.
10777 _gtk_widget_list_devices (GtkWidget *widget)
10779 GHashTableIter iter;
10780 GHashTable *device_window;
10781 GList *devices = NULL;
10782 gpointer key, value;
10784 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10786 if (!gtk_widget_get_mapped (widget))
10789 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10791 if (G_UNLIKELY (!device_window))
10794 g_hash_table_iter_init (&iter, device_window);
10796 while (g_hash_table_iter_next (&iter, &key, &value))
10797 devices = g_list_prepend (devices, key);
10803 synth_crossing (GtkWidget *widget,
10807 GdkCrossingMode mode,
10808 GdkNotifyType detail)
10812 event = gdk_event_new (type);
10814 event->crossing.window = g_object_ref (window);
10815 event->crossing.send_event = TRUE;
10816 event->crossing.subwindow = g_object_ref (window);
10817 event->crossing.time = GDK_CURRENT_TIME;
10818 event->crossing.x = event->crossing.y = 0;
10819 event->crossing.x_root = event->crossing.y_root = 0;
10820 event->crossing.mode = mode;
10821 event->crossing.detail = detail;
10822 event->crossing.focus = FALSE;
10823 event->crossing.state = 0;
10824 gdk_event_set_device (event, device);
10827 widget = gtk_get_event_widget (event);
10830 gtk_widget_event_internal (widget, event);
10832 gdk_event_free (event);
10836 * _gtk_widget_synthesize_crossing:
10837 * @from: the #GtkWidget the virtual pointer is leaving.
10838 * @to: the #GtkWidget the virtual pointer is moving to.
10839 * @mode: the #GdkCrossingMode to place on the synthesized events.
10841 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10843 * The real pointer window is the window that most recently received an enter notify
10844 * event. Windows that don't select for crossing events can't become the real
10845 * poiner window. The real pointer widget that owns the real pointer window. The
10846 * effective pointer window is the same as the real pointer window unless the real
10847 * pointer widget is either insensitive or there is a grab on a widget that is not
10848 * an ancestor of the real pointer widget (in which case the effective pointer
10849 * window should be the root window).
10851 * When the effective pointer window is the same as the real poiner window, we
10852 * receive crossing events from the windowing system. When the effective pointer
10853 * window changes to become different from the real pointer window we synthesize
10854 * crossing events, attempting to follow X protocol rules:
10856 * When the root window becomes the effective pointer window:
10857 * - leave notify on real pointer window, detail Ancestor
10858 * - leave notify on all of its ancestors, detail Virtual
10859 * - enter notify on root window, detail Inferior
10861 * When the root window ceases to be the effective pointer window:
10862 * - leave notify on root window, detail Inferior
10863 * - enter notify on all ancestors of real pointer window, detail Virtual
10864 * - enter notify on real pointer window, detail Ancestor
10867 _gtk_widget_synthesize_crossing (GtkWidget *from,
10870 GdkCrossingMode mode)
10872 GdkWindow *from_window = NULL, *to_window = NULL;
10874 g_return_if_fail (from != NULL || to != NULL);
10878 from_window = _gtk_widget_get_device_window (from, device);
10881 from_window = from->priv->window;
10886 to_window = _gtk_widget_get_device_window (to, device);
10889 to_window = to->priv->window;
10892 if (from_window == NULL && to_window == NULL)
10894 else if (from_window != NULL && to_window == NULL)
10896 GList *from_ancestors = NULL, *list;
10897 GdkWindow *from_ancestor = from_window;
10899 while (from_ancestor != NULL)
10901 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10902 if (from_ancestor == NULL)
10904 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10907 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10908 device, mode, GDK_NOTIFY_ANCESTOR);
10909 for (list = g_list_last (from_ancestors); list; list = list->prev)
10911 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10912 device, mode, GDK_NOTIFY_VIRTUAL);
10915 /* XXX: enter/inferior on root window? */
10917 g_list_free (from_ancestors);
10919 else if (from_window == NULL && to_window != NULL)
10921 GList *to_ancestors = NULL, *list;
10922 GdkWindow *to_ancestor = to_window;
10924 while (to_ancestor != NULL)
10926 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10927 if (to_ancestor == NULL)
10929 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10932 /* XXX: leave/inferior on root window? */
10934 for (list = to_ancestors; list; list = list->next)
10936 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10937 device, mode, GDK_NOTIFY_VIRTUAL);
10939 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10940 device, mode, GDK_NOTIFY_ANCESTOR);
10942 g_list_free (to_ancestors);
10944 else if (from_window == to_window)
10948 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10949 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10951 while (from_ancestor != NULL || to_ancestor != NULL)
10953 if (from_ancestor != NULL)
10955 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10956 if (from_ancestor == to_window)
10959 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10961 if (to_ancestor != NULL)
10963 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10964 if (to_ancestor == from_window)
10967 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10970 if (to_ancestor == from_window)
10972 if (mode != GDK_CROSSING_GTK_UNGRAB)
10973 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10974 device, mode, GDK_NOTIFY_INFERIOR);
10975 for (list = to_ancestors; list; list = list->next)
10976 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10977 device, mode, GDK_NOTIFY_VIRTUAL);
10978 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10979 device, mode, GDK_NOTIFY_ANCESTOR);
10981 else if (from_ancestor == to_window)
10983 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10984 device, mode, GDK_NOTIFY_ANCESTOR);
10985 for (list = g_list_last (from_ancestors); list; list = list->prev)
10987 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10988 device, mode, GDK_NOTIFY_VIRTUAL);
10990 if (mode != GDK_CROSSING_GTK_GRAB)
10991 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10992 device, mode, GDK_NOTIFY_INFERIOR);
10996 while (from_ancestors != NULL && to_ancestors != NULL
10997 && from_ancestors->data == to_ancestors->data)
10999 from_ancestors = g_list_delete_link (from_ancestors,
11001 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11004 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11005 device, mode, GDK_NOTIFY_NONLINEAR);
11007 for (list = g_list_last (from_ancestors); list; list = list->prev)
11009 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11010 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11012 for (list = to_ancestors; list; list = list->next)
11014 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11015 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11017 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11018 device, mode, GDK_NOTIFY_NONLINEAR);
11020 g_list_free (from_ancestors);
11021 g_list_free (to_ancestors);
11026 gtk_widget_propagate_state (GtkWidget *widget,
11027 GtkStateData *data)
11029 GtkWidgetPrivate *priv = widget->priv;
11030 GtkStateFlags new_flags, old_flags = priv->state_flags;
11031 GtkStateType old_state;
11033 old_state = gtk_widget_get_state (widget);
11035 priv->state_flags |= data->flags_to_set;
11036 priv->state_flags &= ~(data->flags_to_unset);
11038 /* make insensitivity unoverridable */
11039 if (!priv->sensitive)
11040 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11042 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11046 window = gtk_widget_get_toplevel (widget);
11048 if (window && gtk_widget_is_toplevel (window))
11049 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11052 new_flags = priv->state_flags;
11054 if (old_flags != new_flags)
11056 g_object_ref (widget);
11058 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11059 gtk_grab_remove (widget);
11061 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11063 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11064 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11066 if (!priv->shadowed &&
11067 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11069 GList *event_windows = NULL;
11070 GList *devices, *d;
11072 devices = _gtk_widget_list_devices (widget);
11074 for (d = devices; d; d = d->next)
11080 window = _gtk_widget_get_device_window (widget, device);
11082 /* Do not propagate more than once to the
11083 * same window if non-multidevice aware.
11085 if (!gdk_window_get_support_multidevice (window) &&
11086 g_list_find (event_windows, window))
11089 if (!gtk_widget_is_sensitive (widget))
11090 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11091 GDK_CROSSING_STATE_CHANGED);
11093 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11094 GDK_CROSSING_STATE_CHANGED);
11096 event_windows = g_list_prepend (event_windows, window);
11099 g_list_free (event_windows);
11100 g_list_free (devices);
11103 if (GTK_IS_CONTAINER (widget))
11105 GtkStateData child_data;
11107 /* Make sure to only propate the right states further */
11108 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11109 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11111 gtk_container_forall (GTK_CONTAINER (widget),
11112 (GtkCallback) gtk_widget_propagate_state,
11116 g_object_unref (widget);
11120 static const GtkWidgetAuxInfo default_aux_info = {
11128 * gtk_widget_get_aux_info:
11129 * @widget: a #GtkWidget
11130 * @create: if %TRUE, create the structure if it doesn't exist
11132 * Get the #GtkWidgetAuxInfo structure for the widget.
11134 * Return value: the #GtkAuxInfo structure for the widget, or
11135 * %NULL if @create is %FALSE and one doesn't already exist.
11137 static GtkWidgetAuxInfo *
11138 gtk_widget_get_aux_info (GtkWidget *widget,
11141 GtkWidgetAuxInfo *aux_info;
11143 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11144 if (!aux_info && create)
11146 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11148 *aux_info = default_aux_info;
11150 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11156 static const GtkWidgetAuxInfo*
11157 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11159 GtkWidgetAuxInfo *aux_info;
11161 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11162 if (aux_info == NULL)
11164 return &default_aux_info;
11172 /*****************************************
11173 * gtk_widget_aux_info_destroy:
11178 *****************************************/
11181 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11183 g_slice_free (GtkWidgetAuxInfo, aux_info);
11187 * gtk_widget_shape_combine_region:
11188 * @widget: a #GtkWidget
11189 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11191 * Sets a shape for this widget's GDK window. This allows for
11192 * transparent windows etc., see gdk_window_shape_combine_region()
11193 * for more information.
11198 gtk_widget_shape_combine_region (GtkWidget *widget,
11199 cairo_region_t *region)
11201 GtkWidgetPrivate *priv;
11203 g_return_if_fail (GTK_IS_WIDGET (widget));
11204 /* set_shape doesn't work on widgets without gdk window */
11205 g_return_if_fail (gtk_widget_get_has_window (widget));
11207 priv = widget->priv;
11209 if (region == NULL)
11211 priv->has_shape_mask = FALSE;
11214 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11216 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11220 priv->has_shape_mask = TRUE;
11222 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11223 cairo_region_copy (region),
11224 (GDestroyNotify) cairo_region_destroy);
11226 /* set shape if widget has a gdk window already.
11227 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11230 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11235 * gtk_widget_input_shape_combine_region:
11236 * @widget: a #GtkWidget
11237 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11239 * Sets an input shape for this widget's GDK window. This allows for
11240 * windows which react to mouse click in a nonrectangular region, see
11241 * gdk_window_input_shape_combine_region() for more information.
11246 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11247 cairo_region_t *region)
11249 GtkWidgetPrivate *priv;
11251 g_return_if_fail (GTK_IS_WIDGET (widget));
11252 /* set_shape doesn't work on widgets without gdk window */
11253 g_return_if_fail (gtk_widget_get_has_window (widget));
11255 priv = widget->priv;
11257 if (region == NULL)
11260 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11262 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11266 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11267 cairo_region_copy (region),
11268 (GDestroyNotify) cairo_region_destroy);
11270 /* set shape if widget has a gdk window already.
11271 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11274 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11279 /* style properties
11283 * gtk_widget_class_install_style_property_parser: (skip)
11284 * @klass: a #GtkWidgetClass
11285 * @pspec: the #GParamSpec for the style property
11286 * @parser: the parser for the style property
11288 * Installs a style property on a widget class.
11291 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11293 GtkRcPropertyParser parser)
11295 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11296 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11297 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11298 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11300 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11302 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11303 G_OBJECT_CLASS_NAME (klass),
11308 g_param_spec_ref_sink (pspec);
11309 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11310 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11314 * gtk_widget_class_install_style_property:
11315 * @klass: a #GtkWidgetClass
11316 * @pspec: the #GParamSpec for the property
11318 * Installs a style property on a widget class. The parser for the
11319 * style property is determined by the value type of @pspec.
11322 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11325 GtkRcPropertyParser parser;
11327 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11328 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11330 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11332 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11336 * gtk_widget_class_find_style_property:
11337 * @klass: a #GtkWidgetClass
11338 * @property_name: the name of the style property to find
11340 * Finds a style property of a widget class by name.
11342 * Returns: (transfer none): the #GParamSpec of the style property or
11343 * %NULL if @class has no style property with that name.
11348 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11349 const gchar *property_name)
11351 g_return_val_if_fail (property_name != NULL, NULL);
11353 return g_param_spec_pool_lookup (style_property_spec_pool,
11355 G_OBJECT_CLASS_TYPE (klass),
11360 * gtk_widget_class_list_style_properties:
11361 * @klass: a #GtkWidgetClass
11362 * @n_properties: location to return the number of style properties found
11364 * Returns all style properties of a widget class.
11366 * Returns: (array length=n_properties) (transfer container): a
11367 * newly allocated array of #GParamSpec*. The array must be
11368 * freed with g_free().
11373 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11374 guint *n_properties)
11376 GParamSpec **pspecs;
11379 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11380 G_OBJECT_CLASS_TYPE (klass),
11389 * gtk_widget_style_get_property:
11390 * @widget: a #GtkWidget
11391 * @property_name: the name of a style property
11392 * @value: location to return the property value
11394 * Gets the value of a style property of @widget.
11397 gtk_widget_style_get_property (GtkWidget *widget,
11398 const gchar *property_name,
11403 g_return_if_fail (GTK_IS_WIDGET (widget));
11404 g_return_if_fail (property_name != NULL);
11405 g_return_if_fail (G_IS_VALUE (value));
11407 g_object_ref (widget);
11408 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11410 G_OBJECT_TYPE (widget),
11413 g_warning ("%s: widget class `%s' has no property named `%s'",
11415 G_OBJECT_TYPE_NAME (widget),
11419 GtkStyleContext *context;
11420 const GValue *peek_value;
11421 GtkStateFlags state;
11423 context = gtk_widget_get_style_context (widget);
11424 state = gtk_widget_get_state_flags (widget);
11426 peek_value = _gtk_style_context_peek_style_property (context,
11427 G_OBJECT_TYPE (widget),
11430 /* auto-conversion of the caller's value type
11432 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11433 g_value_copy (peek_value, value);
11434 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11435 g_value_transform (peek_value, value);
11437 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11439 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11440 G_VALUE_TYPE_NAME (value));
11442 g_object_unref (widget);
11446 * gtk_widget_style_get_valist:
11447 * @widget: a #GtkWidget
11448 * @first_property_name: the name of the first property to get
11449 * @var_args: a <type>va_list</type> of pairs of property names and
11450 * locations to return the property values, starting with the location
11451 * for @first_property_name.
11453 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11457 gtk_widget_style_get_valist (GtkWidget *widget,
11458 const gchar *first_property_name,
11461 GtkStyleContext *context;
11462 GtkStateFlags state;
11465 g_return_if_fail (GTK_IS_WIDGET (widget));
11467 g_object_ref (widget);
11468 context = gtk_widget_get_style_context (widget);
11469 state = gtk_widget_get_state_flags (widget);
11471 name = first_property_name;
11474 const GValue *peek_value;
11478 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11480 G_OBJECT_TYPE (widget),
11484 g_warning ("%s: widget class `%s' has no property named `%s'",
11486 G_OBJECT_TYPE_NAME (widget),
11490 /* style pspecs are always readable so we can spare that check here */
11492 peek_value = _gtk_style_context_peek_style_property (context,
11493 G_OBJECT_TYPE (widget),
11496 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11499 g_warning ("%s: %s", G_STRLOC, error);
11504 name = va_arg (var_args, gchar*);
11507 g_object_unref (widget);
11511 * gtk_widget_style_get:
11512 * @widget: a #GtkWidget
11513 * @first_property_name: the name of the first property to get
11514 * @...: pairs of property names and locations to return the
11515 * property values, starting with the location for
11516 * @first_property_name, terminated by %NULL.
11518 * Gets the values of a multiple style properties of @widget.
11521 gtk_widget_style_get (GtkWidget *widget,
11522 const gchar *first_property_name,
11527 g_return_if_fail (GTK_IS_WIDGET (widget));
11529 va_start (var_args, first_property_name);
11530 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11535 * gtk_requisition_new:
11537 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11539 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11540 * be freed with gtk_requisition_free().
11545 gtk_requisition_new (void)
11547 return g_slice_new0 (GtkRequisition);
11551 * gtk_requisition_copy:
11552 * @requisition: a #GtkRequisition
11554 * Copies a #GtkRequisition.
11556 * Returns: a copy of @requisition
11559 gtk_requisition_copy (const GtkRequisition *requisition)
11561 return g_slice_dup (GtkRequisition, requisition);
11565 * gtk_requisition_free:
11566 * @requisition: a #GtkRequisition
11568 * Frees a #GtkRequisition.
11571 gtk_requisition_free (GtkRequisition *requisition)
11573 g_slice_free (GtkRequisition, requisition);
11576 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11577 gtk_requisition_copy,
11578 gtk_requisition_free)
11581 * gtk_widget_class_set_accessible_type:
11582 * @widget_class: class to set the accessible type for
11583 * @type: The object type that implements the accessible for @widget_class
11585 * Sets the type to be used for creating accessibles for widgets of
11586 * @widget_class. The given @type must be a subtype of the type used for
11587 * accessibles of the parent class.
11589 * This function should only be called from class init functions of widgets.
11594 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11597 GtkWidgetClassPrivate *priv;
11599 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11600 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11602 priv = widget_class->priv;
11604 priv->accessible_type = type;
11605 /* reset this - honoring the type's role is better. */
11606 priv->accessible_role = ATK_ROLE_INVALID;
11610 * gtk_widget_class_set_accessible_role:
11611 * @widget_class: class to set the accessible role for
11612 * @role: The role to use for accessibles created for @widget_class
11614 * Sets the default #AtkRole to be set on accessibles created for
11615 * widgets of @widget_class. Accessibles may decide to not honor this
11616 * setting if their role reporting is more refined. Calls to
11617 * gtk_widget_class_set_accessible_type() will reset this value.
11619 * In cases where you want more fine-grained control over the role of
11620 * accessibles created for @widget_class, you should provide your own
11621 * accessible type and use gtk_widget_class_set_accessible_type()
11624 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11625 * and the accessible's default role will be used instead.
11627 * This function should only be called from class init functions of widgets.
11632 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11635 GtkWidgetClassPrivate *priv;
11637 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11639 priv = widget_class->priv;
11641 priv->accessible_role = role;
11645 * _gtk_widget_peek_accessible:
11646 * @widget: a #GtkWidget
11648 * Gets the accessible for @widget, if it has been created yet.
11649 * Otherwise, this function returns %NULL. If the @widget's implementation
11650 * does not use the default way to create accessibles, %NULL will always be
11653 * Returns: the accessible for @widget or %NULL if none has been
11657 _gtk_widget_peek_accessible (GtkWidget *widget)
11659 return g_object_get_qdata (G_OBJECT (widget),
11660 quark_accessible_object);
11664 * gtk_widget_get_accessible:
11665 * @widget: a #GtkWidget
11667 * Returns the accessible object that describes the widget to an
11668 * assistive technology.
11670 * If accessibility support is not available, this #AtkObject
11671 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11672 * implementation is available for the widget instance in question,
11673 * it will inherit an #AtkObject implementation from the first ancestor
11674 * class for which such an implementation is defined.
11676 * The documentation of the
11677 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11678 * library contains more information about accessible objects and their uses.
11680 * Returns: (transfer none): the #AtkObject associated with @widget
11683 gtk_widget_get_accessible (GtkWidget *widget)
11685 GtkWidgetClass *klass;
11687 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11689 klass = GTK_WIDGET_GET_CLASS (widget);
11691 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11693 return klass->get_accessible (widget);
11697 gtk_widget_real_get_accessible (GtkWidget *widget)
11699 AtkObject* accessible;
11701 accessible = g_object_get_qdata (G_OBJECT (widget),
11702 quark_accessible_object);
11705 GtkWidgetClass *widget_class;
11706 GtkWidgetClassPrivate *priv;
11707 AtkObjectFactory *factory;
11708 AtkRegistry *default_registry;
11710 widget_class = GTK_WIDGET_GET_CLASS (widget);
11711 priv = widget_class->priv;
11713 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11715 default_registry = atk_get_default_registry ();
11716 factory = atk_registry_get_factory (default_registry,
11717 G_TYPE_FROM_INSTANCE (widget));
11719 atk_object_factory_create_accessible (factory,
11720 G_OBJECT (widget));
11722 if (priv->accessible_role != ATK_ROLE_INVALID)
11723 atk_object_set_role (accessible, priv->accessible_role);
11725 g_object_set_qdata (G_OBJECT (widget),
11726 quark_accessible_object,
11731 accessible = g_object_new (priv->accessible_type,
11734 if (priv->accessible_role != ATK_ROLE_INVALID)
11735 atk_object_set_role (accessible, priv->accessible_role);
11737 g_object_set_qdata (G_OBJECT (widget),
11738 quark_accessible_object,
11741 atk_object_initialize (accessible, widget);
11743 /* Set the role again, since we don't want a role set
11744 * in some parent initialize() function to override
11747 if (priv->accessible_role != ATK_ROLE_INVALID)
11748 atk_object_set_role (accessible, priv->accessible_role);
11755 * Initialize a AtkImplementorIface instance's virtual pointers as
11756 * appropriate to this implementor's class (GtkWidget).
11759 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11761 iface->ref_accessible = gtk_widget_ref_accessible;
11765 gtk_widget_ref_accessible (AtkImplementor *implementor)
11767 AtkObject *accessible;
11769 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11771 g_object_ref (accessible);
11776 * Expand flag management
11780 gtk_widget_update_computed_expand (GtkWidget *widget)
11782 GtkWidgetPrivate *priv;
11784 priv = widget->priv;
11786 if (priv->need_compute_expand)
11790 if (priv->hexpand_set)
11795 if (priv->vexpand_set)
11800 /* we don't need to use compute_expand if both expands are
11801 * forced by the app
11803 if (!(priv->hexpand_set && priv->vexpand_set))
11805 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11809 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11810 priv->hexpand_set ? &ignored : &h,
11811 priv->vexpand_set ? &ignored : &v);
11815 priv->need_compute_expand = FALSE;
11816 priv->computed_hexpand = h != FALSE;
11817 priv->computed_vexpand = v != FALSE;
11822 * gtk_widget_queue_compute_expand:
11823 * @widget: a #GtkWidget
11825 * Mark @widget as needing to recompute its expand flags. Call
11826 * this function when setting legacy expand child properties
11827 * on the child of a container.
11829 * See gtk_widget_compute_expand().
11832 gtk_widget_queue_compute_expand (GtkWidget *widget)
11835 gboolean changed_anything;
11837 if (widget->priv->need_compute_expand)
11840 changed_anything = FALSE;
11842 while (parent != NULL)
11844 if (!parent->priv->need_compute_expand)
11846 parent->priv->need_compute_expand = TRUE;
11847 changed_anything = TRUE;
11850 /* Note: if we had an invariant that "if a child needs to
11851 * compute expand, its parents also do" then we could stop going
11852 * up when we got to a parent that already needed to
11853 * compute. However, in general we compute expand lazily (as
11854 * soon as we see something in a subtree that is expand, we know
11855 * we're expanding) and so this invariant does not hold and we
11856 * have to always walk all the way up in case some ancestor
11857 * is not currently need_compute_expand.
11860 parent = parent->priv->parent;
11863 /* recomputing expand always requires
11864 * a relayout as well
11866 if (changed_anything)
11867 gtk_widget_queue_resize (widget);
11871 * gtk_widget_compute_expand:
11872 * @widget: the widget
11873 * @orientation: expand direction
11875 * Computes whether a container should give this widget extra space
11876 * when possible. Containers should check this, rather than
11877 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11879 * This function already checks whether the widget is visible, so
11880 * visibility does not need to be checked separately. Non-visible
11881 * widgets are not expanded.
11883 * The computed expand value uses either the expand setting explicitly
11884 * set on the widget itself, or, if none has been explicitly set,
11885 * the widget may expand if some of its children do.
11887 * Return value: whether widget tree rooted here should be expanded
11890 gtk_widget_compute_expand (GtkWidget *widget,
11891 GtkOrientation orientation)
11893 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11895 /* We never make a widget expand if not even showing. */
11896 if (!gtk_widget_get_visible (widget))
11899 gtk_widget_update_computed_expand (widget);
11901 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11903 return widget->priv->computed_hexpand;
11907 return widget->priv->computed_vexpand;
11912 gtk_widget_set_expand (GtkWidget *widget,
11913 GtkOrientation orientation,
11916 const char *expand_prop;
11917 const char *expand_set_prop;
11919 GtkWidgetPrivate *priv;
11921 g_return_if_fail (GTK_IS_WIDGET (widget));
11923 priv = widget->priv;
11925 expand = expand != FALSE;
11927 was_both = priv->hexpand && priv->vexpand;
11929 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11931 if (priv->hexpand_set &&
11932 priv->hexpand == expand)
11935 priv->hexpand_set = TRUE;
11936 priv->hexpand = expand;
11938 expand_prop = "hexpand";
11939 expand_set_prop = "hexpand-set";
11943 if (priv->vexpand_set &&
11944 priv->vexpand == expand)
11947 priv->vexpand_set = TRUE;
11948 priv->vexpand = expand;
11950 expand_prop = "vexpand";
11951 expand_set_prop = "vexpand-set";
11954 gtk_widget_queue_compute_expand (widget);
11956 g_object_freeze_notify (G_OBJECT (widget));
11957 g_object_notify (G_OBJECT (widget), expand_prop);
11958 g_object_notify (G_OBJECT (widget), expand_set_prop);
11959 if (was_both != (priv->hexpand && priv->vexpand))
11960 g_object_notify (G_OBJECT (widget), "expand");
11961 g_object_thaw_notify (G_OBJECT (widget));
11965 gtk_widget_set_expand_set (GtkWidget *widget,
11966 GtkOrientation orientation,
11969 GtkWidgetPrivate *priv;
11972 priv = widget->priv;
11974 set = set != FALSE;
11976 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11978 if (set == priv->hexpand_set)
11981 priv->hexpand_set = set;
11982 prop = "hexpand-set";
11986 if (set == priv->vexpand_set)
11989 priv->vexpand_set = set;
11990 prop = "vexpand-set";
11993 gtk_widget_queue_compute_expand (widget);
11995 g_object_notify (G_OBJECT (widget), prop);
11999 * gtk_widget_get_hexpand:
12000 * @widget: the widget
12002 * Gets whether the widget would like any available extra horizontal
12003 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12004 * generally receive the extra space. For example, a list or
12005 * scrollable area or document in your window would often be set to
12008 * Containers should use gtk_widget_compute_expand() rather than
12009 * this function, to see whether a widget, or any of its children,
12010 * has the expand flag set. If any child of a widget wants to
12011 * expand, the parent may ask to expand also.
12013 * This function only looks at the widget's own hexpand flag, rather
12014 * than computing whether the entire widget tree rooted at this widget
12017 * Return value: whether hexpand flag is set
12020 gtk_widget_get_hexpand (GtkWidget *widget)
12022 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12024 return widget->priv->hexpand;
12028 * gtk_widget_set_hexpand:
12029 * @widget: the widget
12030 * @expand: whether to expand
12032 * Sets whether the widget would like any available extra horizontal
12033 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12034 * generally receive the extra space. For example, a list or
12035 * scrollable area or document in your window would often be set to
12038 * Call this function to set the expand flag if you would like your
12039 * widget to become larger horizontally when the window has extra
12042 * By default, widgets automatically expand if any of their children
12043 * want to expand. (To see if a widget will automatically expand given
12044 * its current children and state, call gtk_widget_compute_expand(). A
12045 * container can decide how the expandability of children affects the
12046 * expansion of the container by overriding the compute_expand virtual
12047 * method on #GtkWidget.).
12049 * Setting hexpand explicitly with this function will override the
12050 * automatic expand behavior.
12052 * This function forces the widget to expand or not to expand,
12053 * regardless of children. The override occurs because
12054 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12055 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12056 * value to be used, rather than looking at children and widget state.
12059 gtk_widget_set_hexpand (GtkWidget *widget,
12062 g_return_if_fail (GTK_IS_WIDGET (widget));
12064 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12068 * gtk_widget_get_hexpand_set:
12069 * @widget: the widget
12071 * Gets whether gtk_widget_set_hexpand() has been used to
12072 * explicitly set the expand flag on this widget.
12074 * If hexpand is set, then it overrides any computed
12075 * expand value based on child widgets. If hexpand is not
12076 * set, then the expand value depends on whether any
12077 * children of the widget would like to expand.
12079 * There are few reasons to use this function, but it's here
12080 * for completeness and consistency.
12082 * Return value: whether hexpand has been explicitly set
12085 gtk_widget_get_hexpand_set (GtkWidget *widget)
12087 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12089 return widget->priv->hexpand_set;
12093 * gtk_widget_set_hexpand_set:
12094 * @widget: the widget
12095 * @set: value for hexpand-set property
12097 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12100 * The hexpand-set property will be set automatically when you call
12101 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12102 * reason to use this function would be to unset an explicit expand
12105 * If hexpand is set, then it overrides any computed
12106 * expand value based on child widgets. If hexpand is not
12107 * set, then the expand value depends on whether any
12108 * children of the widget would like to expand.
12110 * There are few reasons to use this function, but it's here
12111 * for completeness and consistency.
12114 gtk_widget_set_hexpand_set (GtkWidget *widget,
12117 g_return_if_fail (GTK_IS_WIDGET (widget));
12119 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12124 * gtk_widget_get_vexpand:
12125 * @widget: the widget
12127 * Gets whether the widget would like any available extra vertical
12130 * See gtk_widget_get_hexpand() for more detail.
12132 * Return value: whether vexpand flag is set
12135 gtk_widget_get_vexpand (GtkWidget *widget)
12137 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12139 return widget->priv->vexpand;
12143 * gtk_widget_set_vexpand:
12144 * @widget: the widget
12145 * @expand: whether to expand
12147 * Sets whether the widget would like any available extra vertical
12150 * See gtk_widget_set_hexpand() for more detail.
12153 gtk_widget_set_vexpand (GtkWidget *widget,
12156 g_return_if_fail (GTK_IS_WIDGET (widget));
12158 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12162 * gtk_widget_get_vexpand_set:
12163 * @widget: the widget
12165 * Gets whether gtk_widget_set_vexpand() has been used to
12166 * explicitly set the expand flag on this widget.
12168 * See gtk_widget_get_hexpand_set() for more detail.
12170 * Return value: whether vexpand has been explicitly set
12173 gtk_widget_get_vexpand_set (GtkWidget *widget)
12175 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12177 return widget->priv->vexpand_set;
12181 * gtk_widget_set_vexpand_set:
12182 * @widget: the widget
12183 * @set: value for vexpand-set property
12185 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12188 * See gtk_widget_set_hexpand_set() for more detail.
12191 gtk_widget_set_vexpand_set (GtkWidget *widget,
12194 g_return_if_fail (GTK_IS_WIDGET (widget));
12196 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12200 * GtkBuildable implementation
12202 static GQuark quark_builder_has_default = 0;
12203 static GQuark quark_builder_has_focus = 0;
12204 static GQuark quark_builder_atk_relations = 0;
12205 static GQuark quark_builder_set_name = 0;
12208 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12210 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12211 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12212 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12213 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12215 iface->set_name = gtk_widget_buildable_set_name;
12216 iface->get_name = gtk_widget_buildable_get_name;
12217 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12218 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12219 iface->parser_finished = gtk_widget_buildable_parser_finished;
12220 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12221 iface->custom_finished = gtk_widget_buildable_custom_finished;
12225 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12228 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12229 g_strdup (name), g_free);
12232 static const gchar *
12233 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12235 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12239 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12240 GtkBuilder *builder,
12241 const gchar *childname)
12243 if (strcmp (childname, "accessible") == 0)
12244 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12250 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12251 GtkBuilder *builder,
12253 const GValue *value)
12255 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12256 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12257 GINT_TO_POINTER (TRUE));
12258 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12259 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12260 GINT_TO_POINTER (TRUE));
12262 g_object_set_property (G_OBJECT (buildable), name, value);
12267 gchar *action_name;
12268 GString *description;
12270 gboolean translatable;
12280 free_action (AtkActionData *data, gpointer user_data)
12282 g_free (data->action_name);
12283 g_string_free (data->description, TRUE);
12284 g_free (data->context);
12285 g_slice_free (AtkActionData, data);
12289 free_relation (AtkRelationData *data, gpointer user_data)
12291 g_free (data->target);
12292 g_free (data->type);
12293 g_slice_free (AtkRelationData, data);
12297 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12298 GtkBuilder *builder)
12300 GSList *atk_relations;
12302 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12303 gtk_widget_grab_default (GTK_WIDGET (buildable));
12304 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12305 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12307 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12308 quark_builder_atk_relations);
12311 AtkObject *accessible;
12312 AtkRelationSet *relation_set;
12315 AtkRelationType relation_type;
12316 AtkObject *target_accessible;
12318 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12319 relation_set = atk_object_ref_relation_set (accessible);
12321 for (l = atk_relations; l; l = l->next)
12323 AtkRelationData *relation = (AtkRelationData*)l->data;
12325 target = gtk_builder_get_object (builder, relation->target);
12328 g_warning ("Target object %s in <relation> does not exist",
12332 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12333 g_assert (target_accessible != NULL);
12335 relation_type = atk_relation_type_for_name (relation->type);
12336 if (relation_type == ATK_RELATION_NULL)
12338 g_warning ("<relation> type %s not found",
12342 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12343 target_accessible);
12345 g_object_unref (relation_set);
12347 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12348 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12357 } AccessibilitySubParserData;
12360 accessibility_start_element (GMarkupParseContext *context,
12361 const gchar *element_name,
12362 const gchar **names,
12363 const gchar **values,
12364 gpointer user_data,
12367 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12369 gint line_number, char_number;
12371 if (strcmp (element_name, "relation") == 0)
12373 gchar *target = NULL;
12374 gchar *type = NULL;
12375 AtkRelationData *relation;
12377 for (i = 0; names[i]; i++)
12379 if (strcmp (names[i], "target") == 0)
12380 target = g_strdup (values[i]);
12381 else if (strcmp (names[i], "type") == 0)
12382 type = g_strdup (values[i]);
12385 g_markup_parse_context_get_position (context,
12388 g_set_error (error,
12390 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12391 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12393 line_number, char_number, names[i], "relation");
12400 if (!target || !type)
12402 g_markup_parse_context_get_position (context,
12405 g_set_error (error,
12407 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12408 "%s:%d:%d <%s> requires attribute \"%s\"",
12410 line_number, char_number, "relation",
12411 type ? "target" : "type");
12417 relation = g_slice_new (AtkRelationData);
12418 relation->target = target;
12419 relation->type = type;
12421 data->relations = g_slist_prepend (data->relations, relation);
12423 else if (strcmp (element_name, "action") == 0)
12425 const gchar *action_name = NULL;
12426 const gchar *description = NULL;
12427 const gchar *msg_context = NULL;
12428 gboolean translatable = FALSE;
12429 AtkActionData *action;
12431 for (i = 0; names[i]; i++)
12433 if (strcmp (names[i], "action_name") == 0)
12434 action_name = values[i];
12435 else if (strcmp (names[i], "description") == 0)
12436 description = values[i];
12437 else if (strcmp (names[i], "translatable") == 0)
12439 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12442 else if (strcmp (names[i], "comments") == 0)
12444 /* do nothing, comments are for translators */
12446 else if (strcmp (names[i], "context") == 0)
12447 msg_context = values[i];
12450 g_markup_parse_context_get_position (context,
12453 g_set_error (error,
12455 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12456 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12458 line_number, char_number, names[i], "action");
12465 g_markup_parse_context_get_position (context,
12468 g_set_error (error,
12470 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12471 "%s:%d:%d <%s> requires attribute \"%s\"",
12473 line_number, char_number, "action",
12478 action = g_slice_new (AtkActionData);
12479 action->action_name = g_strdup (action_name);
12480 action->description = g_string_new (description);
12481 action->context = g_strdup (msg_context);
12482 action->translatable = translatable;
12484 data->actions = g_slist_prepend (data->actions, action);
12486 else if (strcmp (element_name, "accessibility") == 0)
12489 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12493 accessibility_text (GMarkupParseContext *context,
12496 gpointer user_data,
12499 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12501 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12503 AtkActionData *action = data->actions->data;
12505 g_string_append_len (action->description, text, text_len);
12509 static const GMarkupParser accessibility_parser =
12511 accessibility_start_element,
12513 accessibility_text,
12522 } AccelGroupParserData;
12525 accel_group_start_element (GMarkupParseContext *context,
12526 const gchar *element_name,
12527 const gchar **names,
12528 const gchar **values,
12529 gpointer user_data,
12534 guint modifiers = 0;
12535 gchar *signal = NULL;
12536 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12538 for (i = 0; names[i]; i++)
12540 if (strcmp (names[i], "key") == 0)
12541 key = gdk_keyval_from_name (values[i]);
12542 else if (strcmp (names[i], "modifiers") == 0)
12544 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12550 else if (strcmp (names[i], "signal") == 0)
12551 signal = g_strdup (values[i]);
12554 if (key == 0 || signal == NULL)
12556 g_warning ("<accelerator> requires key and signal attributes");
12559 parser_data->key = key;
12560 parser_data->modifiers = modifiers;
12561 parser_data->signal = signal;
12564 static const GMarkupParser accel_group_parser =
12566 accel_group_start_element,
12575 style_start_element (GMarkupParseContext *context,
12576 const gchar *element_name,
12577 const gchar **names,
12578 const gchar **values,
12579 gpointer user_data,
12582 StyleParserData *style_data = (StyleParserData *)user_data;
12585 if (strcmp (element_name, "class") == 0)
12587 if (g_markup_collect_attributes (element_name,
12591 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12592 G_MARKUP_COLLECT_INVALID))
12594 style_data->classes = g_slist_append (style_data->classes, class_name);
12597 else if (strcmp (element_name, "style") == 0)
12600 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12603 static const GMarkupParser style_parser =
12605 style_start_element,
12609 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12610 GtkBuilder *builder,
12612 const gchar *tagname,
12613 GMarkupParser *parser,
12616 g_assert (buildable);
12618 if (strcmp (tagname, "accelerator") == 0)
12620 AccelGroupParserData *parser_data;
12622 parser_data = g_slice_new0 (AccelGroupParserData);
12623 parser_data->object = g_object_ref (buildable);
12624 *parser = accel_group_parser;
12625 *data = parser_data;
12628 if (strcmp (tagname, "accessibility") == 0)
12630 AccessibilitySubParserData *parser_data;
12632 parser_data = g_slice_new0 (AccessibilitySubParserData);
12633 *parser = accessibility_parser;
12634 *data = parser_data;
12637 if (strcmp (tagname, "style") == 0)
12639 StyleParserData *parser_data;
12641 parser_data = g_slice_new0 (StyleParserData);
12642 *parser = style_parser;
12643 *data = parser_data;
12651 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12652 GtkWidget *toplevel,
12653 gpointer user_data)
12655 AccelGroupParserData *accel_data;
12656 GSList *accel_groups;
12657 GtkAccelGroup *accel_group;
12659 g_return_if_fail (GTK_IS_WIDGET (widget));
12660 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12661 g_return_if_fail (user_data != NULL);
12663 accel_data = (AccelGroupParserData*)user_data;
12664 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12665 if (g_slist_length (accel_groups) == 0)
12667 accel_group = gtk_accel_group_new ();
12668 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12672 g_assert (g_slist_length (accel_groups) == 1);
12673 accel_group = g_slist_nth_data (accel_groups, 0);
12676 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12677 accel_data->signal,
12680 accel_data->modifiers,
12681 GTK_ACCEL_VISIBLE);
12683 g_object_unref (accel_data->object);
12684 g_free (accel_data->signal);
12685 g_slice_free (AccelGroupParserData, accel_data);
12689 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12690 GtkBuilder *builder,
12692 const gchar *tagname,
12693 gpointer user_data)
12695 if (strcmp (tagname, "accelerator") == 0)
12697 AccelGroupParserData *accel_data;
12698 GtkWidget *toplevel;
12700 accel_data = (AccelGroupParserData*)user_data;
12701 g_assert (accel_data->object);
12703 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12705 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12707 else if (strcmp (tagname, "accessibility") == 0)
12709 AccessibilitySubParserData *a11y_data;
12711 a11y_data = (AccessibilitySubParserData*)user_data;
12713 if (a11y_data->actions)
12715 AtkObject *accessible;
12720 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12722 if (ATK_IS_ACTION (accessible))
12724 action = ATK_ACTION (accessible);
12725 n_actions = atk_action_get_n_actions (action);
12727 for (l = a11y_data->actions; l; l = l->next)
12729 AtkActionData *action_data = (AtkActionData*)l->data;
12731 for (i = 0; i < n_actions; i++)
12732 if (strcmp (atk_action_get_name (action, i),
12733 action_data->action_name) == 0)
12738 gchar *description;
12740 if (action_data->translatable && action_data->description->len)
12741 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12742 action_data->context,
12743 action_data->description->str);
12745 description = action_data->description->str;
12747 atk_action_set_description (action, i, description);
12752 g_warning ("accessibility action on a widget that does not implement AtkAction");
12754 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12757 if (a11y_data->relations)
12758 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12759 a11y_data->relations);
12761 g_slice_free (AccessibilitySubParserData, a11y_data);
12763 else if (strcmp (tagname, "style") == 0)
12765 StyleParserData *style_data = (StyleParserData *)user_data;
12766 GtkStyleContext *context;
12769 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12771 for (l = style_data->classes; l; l = l->next)
12772 gtk_style_context_add_class (context, (const gchar *)l->data);
12774 gtk_widget_reset_style (GTK_WIDGET (buildable));
12776 g_slist_free_full (style_data->classes, g_free);
12777 g_slice_free (StyleParserData, style_data);
12781 static GtkSizeRequestMode
12782 gtk_widget_real_get_request_mode (GtkWidget *widget)
12784 /* By default widgets dont trade size at all. */
12785 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12789 gtk_widget_real_get_width (GtkWidget *widget,
12790 gint *minimum_size,
12791 gint *natural_size)
12801 gtk_widget_real_get_height (GtkWidget *widget,
12802 gint *minimum_size,
12803 gint *natural_size)
12813 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12815 gint *minimum_height,
12816 gint *natural_height)
12818 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12822 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12824 gint *minimum_width,
12825 gint *natural_width)
12827 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12831 * gtk_widget_get_halign:
12832 * @widget: a #GtkWidget
12834 * Gets the value of the #GtkWidget:halign property.
12836 * Returns: the horizontal alignment of @widget
12839 gtk_widget_get_halign (GtkWidget *widget)
12841 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12842 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12846 * gtk_widget_set_halign:
12847 * @widget: a #GtkWidget
12848 * @align: the horizontal alignment
12850 * Sets the horizontal alignment of @widget.
12851 * See the #GtkWidget:halign property.
12854 gtk_widget_set_halign (GtkWidget *widget,
12857 GtkWidgetAuxInfo *aux_info;
12859 g_return_if_fail (GTK_IS_WIDGET (widget));
12861 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12863 if (aux_info->halign == align)
12866 aux_info->halign = align;
12867 gtk_widget_queue_resize (widget);
12868 g_object_notify (G_OBJECT (widget), "halign");
12872 * gtk_widget_get_valign:
12873 * @widget: a #GtkWidget
12875 * Gets the value of the #GtkWidget:valign property.
12877 * Returns: the vertical alignment of @widget
12880 gtk_widget_get_valign (GtkWidget *widget)
12882 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12883 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12887 * gtk_widget_set_valign:
12888 * @widget: a #GtkWidget
12889 * @align: the vertical alignment
12891 * Sets the vertical alignment of @widget.
12892 * See the #GtkWidget:valign property.
12895 gtk_widget_set_valign (GtkWidget *widget,
12898 GtkWidgetAuxInfo *aux_info;
12900 g_return_if_fail (GTK_IS_WIDGET (widget));
12902 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12904 if (aux_info->valign == align)
12907 aux_info->valign = align;
12908 gtk_widget_queue_resize (widget);
12909 g_object_notify (G_OBJECT (widget), "valign");
12913 * gtk_widget_get_margin_left:
12914 * @widget: a #GtkWidget
12916 * Gets the value of the #GtkWidget:margin-left property.
12918 * Returns: The left margin of @widget
12923 gtk_widget_get_margin_left (GtkWidget *widget)
12925 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12927 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12931 * gtk_widget_set_margin_left:
12932 * @widget: a #GtkWidget
12933 * @margin: the left margin
12935 * Sets the left margin of @widget.
12936 * See the #GtkWidget:margin-left property.
12941 gtk_widget_set_margin_left (GtkWidget *widget,
12944 GtkWidgetAuxInfo *aux_info;
12946 g_return_if_fail (GTK_IS_WIDGET (widget));
12947 g_return_if_fail (margin <= G_MAXINT16);
12949 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12951 if (aux_info->margin.left == margin)
12954 aux_info->margin.left = margin;
12955 gtk_widget_queue_resize (widget);
12956 g_object_notify (G_OBJECT (widget), "margin-left");
12960 * gtk_widget_get_margin_right:
12961 * @widget: a #GtkWidget
12963 * Gets the value of the #GtkWidget:margin-right property.
12965 * Returns: The right margin of @widget
12970 gtk_widget_get_margin_right (GtkWidget *widget)
12972 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12974 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12978 * gtk_widget_set_margin_right:
12979 * @widget: a #GtkWidget
12980 * @margin: the right margin
12982 * Sets the right margin of @widget.
12983 * See the #GtkWidget:margin-right property.
12988 gtk_widget_set_margin_right (GtkWidget *widget,
12991 GtkWidgetAuxInfo *aux_info;
12993 g_return_if_fail (GTK_IS_WIDGET (widget));
12994 g_return_if_fail (margin <= G_MAXINT16);
12996 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12998 if (aux_info->margin.right == margin)
13001 aux_info->margin.right = margin;
13002 gtk_widget_queue_resize (widget);
13003 g_object_notify (G_OBJECT (widget), "margin-right");
13007 * gtk_widget_get_margin_top:
13008 * @widget: a #GtkWidget
13010 * Gets the value of the #GtkWidget:margin-top property.
13012 * Returns: The top margin of @widget
13017 gtk_widget_get_margin_top (GtkWidget *widget)
13019 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13021 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13025 * gtk_widget_set_margin_top:
13026 * @widget: a #GtkWidget
13027 * @margin: the top margin
13029 * Sets the top margin of @widget.
13030 * See the #GtkWidget:margin-top property.
13035 gtk_widget_set_margin_top (GtkWidget *widget,
13038 GtkWidgetAuxInfo *aux_info;
13040 g_return_if_fail (GTK_IS_WIDGET (widget));
13041 g_return_if_fail (margin <= G_MAXINT16);
13043 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13045 if (aux_info->margin.top == margin)
13048 aux_info->margin.top = margin;
13049 gtk_widget_queue_resize (widget);
13050 g_object_notify (G_OBJECT (widget), "margin-top");
13054 * gtk_widget_get_margin_bottom:
13055 * @widget: a #GtkWidget
13057 * Gets the value of the #GtkWidget:margin-bottom property.
13059 * Returns: The bottom margin of @widget
13064 gtk_widget_get_margin_bottom (GtkWidget *widget)
13066 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13068 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13072 * gtk_widget_set_margin_bottom:
13073 * @widget: a #GtkWidget
13074 * @margin: the bottom margin
13076 * Sets the bottom margin of @widget.
13077 * See the #GtkWidget:margin-bottom property.
13082 gtk_widget_set_margin_bottom (GtkWidget *widget,
13085 GtkWidgetAuxInfo *aux_info;
13087 g_return_if_fail (GTK_IS_WIDGET (widget));
13088 g_return_if_fail (margin <= G_MAXINT16);
13090 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13092 if (aux_info->margin.bottom == margin)
13095 aux_info->margin.bottom = margin;
13096 gtk_widget_queue_resize (widget);
13097 g_object_notify (G_OBJECT (widget), "margin-bottom");
13101 * gtk_widget_get_clipboard:
13102 * @widget: a #GtkWidget
13103 * @selection: a #GdkAtom which identifies the clipboard
13104 * to use. %GDK_SELECTION_CLIPBOARD gives the
13105 * default clipboard. Another common value
13106 * is %GDK_SELECTION_PRIMARY, which gives
13107 * the primary X selection.
13109 * Returns the clipboard object for the given selection to
13110 * be used with @widget. @widget must have a #GdkDisplay
13111 * associated with it, so must be attached to a toplevel
13114 * Return value: (transfer none): the appropriate clipboard object. If no
13115 * clipboard already exists, a new one will
13116 * be created. Once a clipboard object has
13117 * been created, it is persistent for all time.
13122 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13124 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13125 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13127 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13132 * gtk_widget_list_mnemonic_labels:
13133 * @widget: a #GtkWidget
13135 * Returns a newly allocated list of the widgets, normally labels, for
13136 * which this widget is the target of a mnemonic (see for example,
13137 * gtk_label_set_mnemonic_widget()).
13139 * The widgets in the list are not individually referenced. If you
13140 * want to iterate through the list and perform actions involving
13141 * callbacks that might destroy the widgets, you
13142 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13143 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13144 * widgets afterwards.
13146 * Return value: (element-type GtkWidget) (transfer container): the list of
13147 * mnemonic labels; free this list
13148 * with g_list_free() when you are done with it.
13153 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13155 GList *list = NULL;
13158 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13160 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13161 list = g_list_prepend (list, l->data);
13167 * gtk_widget_add_mnemonic_label:
13168 * @widget: a #GtkWidget
13169 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13171 * Adds a widget to the list of mnemonic labels for
13172 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13173 * list of mnemonic labels for the widget is cleared when the
13174 * widget is destroyed, so the caller must make sure to update
13175 * its internal state at this point as well, by using a connection
13176 * to the #GtkWidget::destroy signal or a weak notifier.
13181 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13184 GSList *old_list, *new_list;
13186 g_return_if_fail (GTK_IS_WIDGET (widget));
13187 g_return_if_fail (GTK_IS_WIDGET (label));
13189 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13190 new_list = g_slist_prepend (old_list, label);
13192 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13193 new_list, (GDestroyNotify) g_slist_free);
13197 * gtk_widget_remove_mnemonic_label:
13198 * @widget: a #GtkWidget
13199 * @label: a #GtkWidget that was previously set as a mnemnic label for
13200 * @widget with gtk_widget_add_mnemonic_label().
13202 * Removes a widget from the list of mnemonic labels for
13203 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13204 * must have previously been added to the list with
13205 * gtk_widget_add_mnemonic_label().
13210 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13213 GSList *old_list, *new_list;
13215 g_return_if_fail (GTK_IS_WIDGET (widget));
13216 g_return_if_fail (GTK_IS_WIDGET (label));
13218 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13219 new_list = g_slist_remove (old_list, label);
13222 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13223 new_list, (GDestroyNotify) g_slist_free);
13227 * gtk_widget_get_no_show_all:
13228 * @widget: a #GtkWidget
13230 * Returns the current value of the #GtkWidget:no-show-all property,
13231 * which determines whether calls to gtk_widget_show_all()
13232 * will affect this widget.
13234 * Return value: the current value of the "no-show-all" property.
13239 gtk_widget_get_no_show_all (GtkWidget *widget)
13241 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13243 return widget->priv->no_show_all;
13247 * gtk_widget_set_no_show_all:
13248 * @widget: a #GtkWidget
13249 * @no_show_all: the new value for the "no-show-all" property
13251 * Sets the #GtkWidget:no-show-all property, which determines whether
13252 * calls to gtk_widget_show_all() will affect this widget.
13254 * This is mostly for use in constructing widget hierarchies with externally
13255 * controlled visibility, see #GtkUIManager.
13260 gtk_widget_set_no_show_all (GtkWidget *widget,
13261 gboolean no_show_all)
13263 g_return_if_fail (GTK_IS_WIDGET (widget));
13265 no_show_all = (no_show_all != FALSE);
13267 if (widget->priv->no_show_all != no_show_all)
13269 widget->priv->no_show_all = no_show_all;
13271 g_object_notify (G_OBJECT (widget), "no-show-all");
13277 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13278 gboolean has_tooltip,
13281 GtkWidgetPrivate *priv = widget->priv;
13282 gboolean priv_has_tooltip;
13284 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13285 quark_has_tooltip));
13287 if (priv_has_tooltip != has_tooltip || force)
13289 priv_has_tooltip = has_tooltip;
13291 if (priv_has_tooltip)
13293 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13294 gdk_window_set_events (priv->window,
13295 gdk_window_get_events (priv->window) |
13296 GDK_LEAVE_NOTIFY_MASK |
13297 GDK_POINTER_MOTION_MASK |
13298 GDK_POINTER_MOTION_HINT_MASK);
13300 if (gtk_widget_get_has_window (widget))
13301 gtk_widget_add_events (widget,
13302 GDK_LEAVE_NOTIFY_MASK |
13303 GDK_POINTER_MOTION_MASK |
13304 GDK_POINTER_MOTION_HINT_MASK);
13307 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13308 GUINT_TO_POINTER (priv_has_tooltip));
13313 * gtk_widget_set_tooltip_window:
13314 * @widget: a #GtkWidget
13315 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13317 * Replaces the default, usually yellow, window used for displaying
13318 * tooltips with @custom_window. GTK+ will take care of showing and
13319 * hiding @custom_window at the right moment, to behave likewise as
13320 * the default tooltip window. If @custom_window is %NULL, the default
13321 * tooltip window will be used.
13323 * If the custom window should have the default theming it needs to
13324 * have the name "gtk-tooltip", see gtk_widget_set_name().
13329 gtk_widget_set_tooltip_window (GtkWidget *widget,
13330 GtkWindow *custom_window)
13332 gboolean has_tooltip;
13333 gchar *tooltip_markup;
13335 g_return_if_fail (GTK_IS_WIDGET (widget));
13336 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13338 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13341 g_object_ref (custom_window);
13343 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13344 custom_window, g_object_unref);
13346 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13347 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13349 if (has_tooltip && gtk_widget_get_visible (widget))
13350 gtk_widget_queue_tooltip_query (widget);
13354 * gtk_widget_get_tooltip_window:
13355 * @widget: a #GtkWidget
13357 * Returns the #GtkWindow of the current tooltip. This can be the
13358 * GtkWindow created by default, or the custom tooltip window set
13359 * using gtk_widget_set_tooltip_window().
13361 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13366 gtk_widget_get_tooltip_window (GtkWidget *widget)
13368 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13370 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13374 * gtk_widget_trigger_tooltip_query:
13375 * @widget: a #GtkWidget
13377 * Triggers a tooltip query on the display where the toplevel of @widget
13378 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13384 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13386 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13389 static guint tooltip_query_id;
13390 static GSList *tooltip_query_displays;
13393 tooltip_query_idle (gpointer data)
13395 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13396 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13397 g_slist_free (tooltip_query_displays);
13399 tooltip_query_displays = NULL;
13400 tooltip_query_id = 0;
13406 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13408 GdkDisplay *display;
13410 display = gtk_widget_get_display (widget);
13412 if (!g_slist_find (tooltip_query_displays, display))
13413 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13415 if (tooltip_query_id == 0)
13416 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13420 * gtk_widget_set_tooltip_text:
13421 * @widget: a #GtkWidget
13422 * @text: (allow-none): the contents of the tooltip for @widget
13424 * Sets @text as the contents of the tooltip. This function will take
13425 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13426 * handler for the #GtkWidget::query-tooltip signal.
13428 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13433 gtk_widget_set_tooltip_text (GtkWidget *widget,
13436 g_return_if_fail (GTK_IS_WIDGET (widget));
13438 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13442 * gtk_widget_get_tooltip_text:
13443 * @widget: a #GtkWidget
13445 * Gets the contents of the tooltip for @widget.
13447 * Return value: the tooltip text, or %NULL. You should free the
13448 * returned string with g_free() when done.
13453 gtk_widget_get_tooltip_text (GtkWidget *widget)
13455 gchar *text = NULL;
13457 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13459 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13465 * gtk_widget_set_tooltip_markup:
13466 * @widget: a #GtkWidget
13467 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13469 * Sets @markup as the contents of the tooltip, which is marked up with
13470 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13472 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13473 * and of the default handler for the #GtkWidget::query-tooltip signal.
13475 * See also the #GtkWidget:tooltip-markup property and
13476 * gtk_tooltip_set_markup().
13481 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13482 const gchar *markup)
13484 g_return_if_fail (GTK_IS_WIDGET (widget));
13486 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13490 * gtk_widget_get_tooltip_markup:
13491 * @widget: a #GtkWidget
13493 * Gets the contents of the tooltip for @widget.
13495 * Return value: the tooltip text, or %NULL. You should free the
13496 * returned string with g_free() when done.
13501 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13503 gchar *text = NULL;
13505 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13507 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13513 * gtk_widget_set_has_tooltip:
13514 * @widget: a #GtkWidget
13515 * @has_tooltip: whether or not @widget has a tooltip.
13517 * Sets the has-tooltip property on @widget to @has_tooltip. See
13518 * #GtkWidget:has-tooltip for more information.
13523 gtk_widget_set_has_tooltip (GtkWidget *widget,
13524 gboolean has_tooltip)
13526 g_return_if_fail (GTK_IS_WIDGET (widget));
13528 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13532 * gtk_widget_get_has_tooltip:
13533 * @widget: a #GtkWidget
13535 * Returns the current value of the has-tooltip property. See
13536 * #GtkWidget:has-tooltip for more information.
13538 * Return value: current value of has-tooltip on @widget.
13543 gtk_widget_get_has_tooltip (GtkWidget *widget)
13545 gboolean has_tooltip = FALSE;
13547 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13549 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13551 return has_tooltip;
13555 * gtk_widget_get_allocation:
13556 * @widget: a #GtkWidget
13557 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13559 * Retrieves the widget's allocation.
13561 * Note, when implementing a #GtkContainer: a widget's allocation will
13562 * be its "adjusted" allocation, that is, the widget's parent
13563 * container typically calls gtk_widget_size_allocate() with an
13564 * allocation, and that allocation is then adjusted (to handle margin
13565 * and alignment for example) before assignment to the widget.
13566 * gtk_widget_get_allocation() returns the adjusted allocation that
13567 * was actually assigned to the widget. The adjusted allocation is
13568 * guaranteed to be completely contained within the
13569 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13570 * is guaranteed that its children stay inside the assigned bounds,
13571 * but not that they have exactly the bounds the container assigned.
13572 * There is no way to get the original allocation assigned by
13573 * gtk_widget_size_allocate(), since it isn't stored; if a container
13574 * implementation needs that information it will have to track it itself.
13579 gtk_widget_get_allocation (GtkWidget *widget,
13580 GtkAllocation *allocation)
13582 GtkWidgetPrivate *priv;
13584 g_return_if_fail (GTK_IS_WIDGET (widget));
13585 g_return_if_fail (allocation != NULL);
13587 priv = widget->priv;
13589 *allocation = priv->allocation;
13593 * gtk_widget_set_allocation:
13594 * @widget: a #GtkWidget
13595 * @allocation: a pointer to a #GtkAllocation to copy from
13597 * Sets the widget's allocation. This should not be used
13598 * directly, but from within a widget's size_allocate method.
13600 * The allocation set should be the "adjusted" or actual
13601 * allocation. If you're implementing a #GtkContainer, you want to use
13602 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13603 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13604 * allocation inside gtk_widget_size_allocate() to create an adjusted
13610 gtk_widget_set_allocation (GtkWidget *widget,
13611 const GtkAllocation *allocation)
13613 GtkWidgetPrivate *priv;
13615 g_return_if_fail (GTK_IS_WIDGET (widget));
13616 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13617 g_return_if_fail (allocation != NULL);
13619 priv = widget->priv;
13621 priv->allocation = *allocation;
13625 * gtk_widget_get_allocated_width:
13626 * @widget: the widget to query
13628 * Returns the width that has currently been allocated to @widget.
13629 * This function is intended to be used when implementing handlers
13630 * for the #GtkWidget::draw function.
13632 * Returns: the width of the @widget
13635 gtk_widget_get_allocated_width (GtkWidget *widget)
13637 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13639 return widget->priv->allocation.width;
13643 * gtk_widget_get_allocated_height:
13644 * @widget: the widget to query
13646 * Returns the height that has currently been allocated to @widget.
13647 * This function is intended to be used when implementing handlers
13648 * for the #GtkWidget::draw function.
13650 * Returns: the height of the @widget
13653 gtk_widget_get_allocated_height (GtkWidget *widget)
13655 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13657 return widget->priv->allocation.height;
13661 * gtk_widget_get_requisition:
13662 * @widget: a #GtkWidget
13663 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13665 * Retrieves the widget's requisition.
13667 * This function should only be used by widget implementations in
13668 * order to figure whether the widget's requisition has actually
13669 * changed after some internal state change (so that they can call
13670 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13672 * Normally, gtk_widget_size_request() should be used.
13676 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13677 * removed, If you need to cache sizes across requests and allocations,
13678 * add an explicit cache to the widget in question instead.
13681 gtk_widget_get_requisition (GtkWidget *widget,
13682 GtkRequisition *requisition)
13684 g_return_if_fail (GTK_IS_WIDGET (widget));
13685 g_return_if_fail (requisition != NULL);
13687 gtk_widget_get_preferred_size (widget, requisition, NULL);
13691 * gtk_widget_set_window:
13692 * @widget: a #GtkWidget
13693 * @window: (transfer full): a #GdkWindow
13695 * Sets a widget's window. This function should only be used in a
13696 * widget's #GtkWidget::realize implementation. The %window passed is
13697 * usually either new window created with gdk_window_new(), or the
13698 * window of its parent widget as returned by
13699 * gtk_widget_get_parent_window().
13701 * Widgets must indicate whether they will create their own #GdkWindow
13702 * by calling gtk_widget_set_has_window(). This is usually done in the
13703 * widget's init() function.
13705 * <note><para>This function does not add any reference to @window.</para></note>
13710 gtk_widget_set_window (GtkWidget *widget,
13713 GtkWidgetPrivate *priv;
13715 g_return_if_fail (GTK_IS_WIDGET (widget));
13716 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13718 priv = widget->priv;
13720 if (priv->window != window)
13722 priv->window = window;
13724 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
13725 gdk_window_set_opacity (window,
13726 priv->norender ? 0 : priv->alpha / 255.0);
13728 g_object_notify (G_OBJECT (widget), "window");
13733 * gtk_widget_register_window:
13734 * @widget: a #GtkWidget
13735 * @window: a #GdkWindow
13737 * Registers a #GdkWindow with the widget and sets it up so that
13738 * the widget recieves events for it. Call gtk_widget_unregister_window()
13739 * when destroying the window.
13741 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13742 * this up. This is now deprecated and you should use gtk_widget_register_window()
13743 * instead. Old code will keep working as is, although some new features like
13744 * transparency might not work perfectly.
13749 gtk_widget_register_window (GtkWidget *widget,
13752 GtkWidgetPrivate *priv;
13753 gpointer user_data;
13755 g_return_if_fail (GTK_IS_WIDGET (widget));
13756 g_return_if_fail (GDK_IS_WINDOW (window));
13758 gdk_window_get_user_data (window, &user_data);
13759 g_assert (user_data == NULL);
13761 priv = widget->priv;
13763 gdk_window_set_user_data (window, widget);
13764 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13766 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
13767 gdk_window_set_opacity (window,
13768 (priv->norender || priv->norender_children) ? 0.0 : 1.0);
13772 * gtk_widget_unregister_window:
13773 * @widget: a #GtkWidget
13774 * @window: a #GdkWindow
13776 * Unregisters a #GdkWindow from the widget that was previously set up with
13777 * gtk_widget_register_window(). You need to call this when the window is
13778 * no longer used by the widget, such as when you destroy it.
13783 gtk_widget_unregister_window (GtkWidget *widget,
13786 GtkWidgetPrivate *priv;
13787 gpointer user_data;
13789 g_return_if_fail (GTK_IS_WIDGET (widget));
13790 g_return_if_fail (GDK_IS_WINDOW (window));
13792 priv = widget->priv;
13794 gdk_window_get_user_data (window, &user_data);
13795 g_assert (user_data == widget);
13796 gdk_window_set_user_data (window, NULL);
13797 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13801 * gtk_widget_get_window:
13802 * @widget: a #GtkWidget
13804 * Returns the widget's window if it is realized, %NULL otherwise
13806 * Return value: (transfer none): @widget's window.
13811 gtk_widget_get_window (GtkWidget *widget)
13813 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13815 return widget->priv->window;
13819 * gtk_widget_get_support_multidevice:
13820 * @widget: a #GtkWidget
13822 * Returns %TRUE if @widget is multiple pointer aware. See
13823 * gtk_widget_set_support_multidevice() for more information.
13825 * Returns: %TRUE if @widget is multidevice aware.
13828 gtk_widget_get_support_multidevice (GtkWidget *widget)
13830 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13832 return widget->priv->multidevice;
13836 * gtk_widget_set_support_multidevice:
13837 * @widget: a #GtkWidget
13838 * @support_multidevice: %TRUE to support input from multiple devices.
13840 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13841 * @widget will start receiving multiple, per device enter/leave events. Note
13842 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13843 * gdk_window_set_support_multidevice() will have to be called manually on them.
13848 gtk_widget_set_support_multidevice (GtkWidget *widget,
13849 gboolean support_multidevice)
13851 GtkWidgetPrivate *priv;
13853 g_return_if_fail (GTK_IS_WIDGET (widget));
13855 priv = widget->priv;
13856 priv->multidevice = (support_multidevice == TRUE);
13858 if (gtk_widget_get_realized (widget))
13859 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13862 static void apply_norender (GtkWidget *widget, gboolean norender);
13865 apply_norender_cb (GtkWidget *widget, gpointer norender)
13867 apply_norender (widget, GPOINTER_TO_INT (norender));
13871 propagate_norender_non_window (GtkWidget *widget, gboolean norender)
13875 g_assert (!gtk_widget_get_has_window (widget));
13877 for (l = widget->priv->registered_windows; l != NULL; l = l->next)
13878 gdk_window_set_opacity (l->data,
13879 norender ? 0 : widget->priv->alpha / 255.0);
13881 if (GTK_IS_CONTAINER (widget))
13882 gtk_container_forall (GTK_CONTAINER (widget), apply_norender_cb,
13883 GINT_TO_POINTER (norender));
13887 apply_norender (GtkWidget *widget, gboolean norender)
13889 if (widget->priv->norender == norender)
13892 widget->priv->norender = norender;
13894 if (gtk_widget_get_has_window (widget))
13896 if (widget->priv->window != NULL)
13897 gdk_window_set_opacity (widget->priv->window,
13898 norender ? 0 : widget->priv->alpha / 255.0);
13901 propagate_norender_non_window (widget, norender | widget->priv->norender_children);
13904 /* This is called when the norender_children state of a non-window widget changes,
13905 * its parent changes, or its has_window state changes. It means we need
13906 * to update the norender of all the windows owned by the widget and those
13907 * of child widgets, up to and including the first windowed widgets in the hierarchy.
13910 gtk_widget_update_norender (GtkWidget *widget)
13915 parent = widget->priv->parent;
13919 (parent->priv->norender_children ||
13920 (parent->priv->norender && !gtk_widget_get_has_window (parent)));
13922 apply_norender (widget, norender);
13924 /* The above may not have propagated to children if norender_children changed but
13925 not norender, so we need to enforce propagation. */
13926 if (!gtk_widget_get_has_window (widget))
13927 propagate_norender_non_window (widget, norender | widget->priv->norender_children);
13931 * gtk_widget_set_opacity:
13932 * @widget: a #GtkWidget
13933 * @opacity: desired opacity, between 0 and 1
13935 * Request the @widget to be rendered partially transparent,
13936 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
13937 * are clamped to the [0,1] range.).
13938 * This works on both toplevel widget, and child widgets, although there
13939 * are some limitations:
13941 * For toplevel widgets this depends on the capabilities of the windowing
13942 * system. On X11 this has any effect only on X screens with a compositing manager
13943 * running. See gtk_widget_is_composited(). On Windows it should work
13944 * always, although setting a window's opacity after the window has been
13945 * shown causes it to flicker once on Windows.
13947 * For child widgets it doesn't work if any affected widget has a native window, or
13948 * disables double buffering.
13953 gtk_widget_set_opacity (GtkWidget *widget,
13956 GtkWidgetPrivate *priv;
13959 g_return_if_fail (GTK_IS_WIDGET (widget));
13961 priv = widget->priv;
13965 else if (opacity > 1.0)
13968 alpha = round (opacity * 255);
13969 if (alpha == priv->alpha)
13972 priv->alpha = alpha;
13974 if (gtk_widget_get_has_window (widget))
13976 if (priv->window != NULL)
13977 gdk_window_set_opacity (priv->window,
13978 priv->norender ? 0 : opacity);
13982 /* For non windowed widgets we can't use gdk_window_set_opacity() directly, as there is
13983 no GdkWindow at the right place in the hierarchy. For no-window widget this is not a problem,
13984 as we just push an opacity group in the draw marshaller.
13986 However, that only works for non-window descendant widgets. If any descendant has a
13987 window that window will not normally be rendered in the draw signal, so the opacity
13988 group will not work for it.
13990 To fix this we set all such windows to a zero opacity, meaning they don't get drawn
13991 by gdk, and instead we set a NULL _gtk_cairo_get_event during expose so that the draw
13992 handler recurses into windowed widgets.
13994 We do this by setting "norender_children", which means that any windows in this widget
13995 or its ancestors (stopping at the first such windows at each branch in the hierarchy)
13996 are set to zero opacity. This is then propagated into all necessary children as norender,
13997 which controls whether a window should be exposed or not.
13999 priv->norender_children = priv->alpha != 255;
14000 gtk_widget_update_norender (widget);
14003 if (gtk_widget_get_realized (widget))
14004 gtk_widget_queue_draw (widget);
14008 * gtk_widget_get_opacity:
14009 * @widget: a #GtkWidget
14011 * Fetches the requested opacity for this widget. See
14012 * gtk_widget_set_opacity().
14014 * Return value: the requested opacity for this widget.
14019 gtk_widget_get_opacity (GtkWidget *widget)
14021 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14023 return widget->priv->alpha / 255.0;
14027 _gtk_widget_set_has_focus (GtkWidget *widget,
14028 gboolean has_focus)
14030 widget->priv->has_focus = has_focus;
14033 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14035 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14039 * gtk_widget_send_focus_change:
14040 * @widget: a #GtkWidget
14041 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14043 * Sends the focus change @event to @widget
14045 * This function is not meant to be used by applications. The only time it
14046 * should be used is when it is necessary for a #GtkWidget to assign focus
14047 * to a widget that is semantically owned by the first widget even though
14048 * it's not a direct child - for instance, a search entry in a floating
14049 * window similar to the quick search in #GtkTreeView.
14051 * An example of its usage is:
14054 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14056 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14057 * fevent->focus_change.in = TRUE;
14058 * fevent->focus_change.window = gtk_widget_get_window (widget);
14059 * if (fevent->focus_change.window != NULL)
14060 * g_object_ref (fevent->focus_change.window);
14062 * gtk_widget_send_focus_change (widget, fevent);
14064 * gdk_event_free (event);
14067 * Return value: the return value from the event signal emission: %TRUE
14068 * if the event was handled, and %FALSE otherwise
14073 gtk_widget_send_focus_change (GtkWidget *widget,
14078 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14079 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14081 g_object_ref (widget);
14083 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14085 res = gtk_widget_event (widget, event);
14087 g_object_notify (G_OBJECT (widget), "has-focus");
14089 g_object_unref (widget);
14095 * gtk_widget_in_destruction:
14096 * @widget: a #GtkWidget
14098 * Returns whether the widget is currently being destroyed.
14099 * This information can sometimes be used to avoid doing
14100 * unnecessary work.
14102 * Returns: %TRUE if @widget is being destroyed
14105 gtk_widget_in_destruction (GtkWidget *widget)
14107 return widget->priv->in_destruction;
14111 _gtk_widget_get_in_reparent (GtkWidget *widget)
14113 return widget->priv->in_reparent;
14117 _gtk_widget_set_in_reparent (GtkWidget *widget,
14118 gboolean in_reparent)
14120 widget->priv->in_reparent = in_reparent;
14124 _gtk_widget_get_anchored (GtkWidget *widget)
14126 return widget->priv->anchored;
14130 _gtk_widget_set_anchored (GtkWidget *widget,
14133 widget->priv->anchored = anchored;
14137 _gtk_widget_get_shadowed (GtkWidget *widget)
14139 return widget->priv->shadowed;
14143 _gtk_widget_set_shadowed (GtkWidget *widget,
14146 widget->priv->shadowed = shadowed;
14150 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14152 return widget->priv->alloc_needed;
14156 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14157 gboolean alloc_needed)
14159 widget->priv->alloc_needed = alloc_needed;
14163 _gtk_widget_add_sizegroup (GtkWidget *widget,
14168 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14169 groups = g_slist_prepend (groups, group);
14170 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14172 widget->priv->have_size_groups = TRUE;
14176 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14181 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14182 groups = g_slist_remove (groups, group);
14183 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14185 widget->priv->have_size_groups = groups != NULL;
14189 _gtk_widget_get_sizegroups (GtkWidget *widget)
14191 if (widget->priv->have_size_groups)
14192 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14198 _gtk_widget_add_attached_window (GtkWidget *widget,
14201 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14205 _gtk_widget_remove_attached_window (GtkWidget *widget,
14208 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14212 * gtk_widget_path_append_for_widget:
14213 * @path: a widget path
14214 * @widget: the widget to append to the widget path
14216 * Appends the data from @widget to the widget hierarchy represented
14217 * by @path. This function is a shortcut for adding information from
14218 * @widget to the given @path. This includes setting the name or
14219 * adding the style classes from @widget.
14221 * Returns: the position where the data was inserted
14226 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14231 g_return_val_if_fail (path != NULL, 0);
14232 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14234 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14236 if (widget->priv->name)
14237 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14239 if (widget->priv->context)
14241 GList *classes, *l;
14243 /* Also add any persistent classes in
14244 * the style context the widget path
14246 classes = gtk_style_context_list_classes (widget->priv->context);
14248 for (l = classes; l; l = l->next)
14249 gtk_widget_path_iter_add_class (path, pos, l->data);
14251 g_list_free (classes);
14258 _gtk_widget_create_path (GtkWidget *widget)
14262 parent = widget->priv->parent;
14265 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14268 /* Widget is either toplevel or unparented, treat both
14269 * as toplevels style wise, since there are situations
14270 * where style properties might be retrieved on that
14273 GtkWidget *attach_widget = NULL;
14274 GtkWidgetPath *result;
14276 if (GTK_IS_WINDOW (widget))
14277 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14279 if (attach_widget != NULL)
14280 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14282 result = gtk_widget_path_new ();
14284 gtk_widget_path_append_for_widget (result, widget);
14291 * gtk_widget_get_path:
14292 * @widget: a #GtkWidget
14294 * Returns the #GtkWidgetPath representing @widget, if the widget
14295 * is not connected to a toplevel widget, a partial path will be
14298 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14301 gtk_widget_get_path (GtkWidget *widget)
14303 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14305 if (!widget->priv->path)
14306 widget->priv->path = _gtk_widget_create_path (widget);
14308 return widget->priv->path;
14312 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14314 if (widget->priv->path)
14316 gtk_widget_path_free (widget->priv->path);
14317 widget->priv->path = NULL;
14320 if (gtk_widget_get_realized (widget))
14321 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14324 /* Compress all style updates so it
14325 * is only emitted once pre-realize.
14327 widget->priv->style_update_pending = TRUE;
14332 * gtk_widget_get_style_context:
14333 * @widget: a #GtkWidget
14335 * Returns the style context associated to @widget.
14337 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14338 * must not be freed.
14341 gtk_widget_get_style_context (GtkWidget *widget)
14343 GtkWidgetPrivate *priv;
14345 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14347 priv = widget->priv;
14349 if (G_UNLIKELY (priv->context == NULL))
14353 priv->context = gtk_style_context_new ();
14355 gtk_style_context_set_state (priv->context, priv->state_flags);
14357 screen = gtk_widget_get_screen (widget);
14359 gtk_style_context_set_screen (priv->context, screen);
14362 gtk_style_context_set_parent (priv->context,
14363 gtk_widget_get_style_context (priv->parent));
14365 _gtk_style_context_set_widget (priv->context, widget);
14368 return widget->priv->context;
14372 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14373 GtkCssChange change)
14375 GtkWidgetPrivate *priv;
14377 priv = widget->priv;
14379 if (priv->context == NULL)
14382 _gtk_style_context_queue_invalidate (priv->context, change);
14386 * gtk_widget_get_modifier_mask:
14387 * @widget: a #GtkWidget
14388 * @intent: the use case for the modifier mask
14390 * Returns the modifier mask the @widget's windowing system backend
14391 * uses for a particular purpose.
14393 * See gdk_keymap_get_modifier_mask().
14395 * Returns: the modifier mask used for @intent.
14400 gtk_widget_get_modifier_mask (GtkWidget *widget,
14401 GdkModifierIntent intent)
14403 GdkDisplay *display;
14405 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14407 display = gtk_widget_get_display (widget);
14409 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14414 _gtk_widget_get_style (GtkWidget *widget)
14416 return widget->priv->style;
14420 _gtk_widget_set_style (GtkWidget *widget,
14423 widget->priv->style = style;
14427 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14430 GActionMuxer *parent_muxer;
14432 if (widget->priv->muxer == NULL)
14435 if (GTK_IS_MENU (widget))
14436 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14438 parent = gtk_widget_get_parent (widget);
14440 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14442 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14446 _gtk_widget_get_action_muxer (GtkWidget *widget)
14448 if (widget->priv->muxer == NULL)
14450 widget->priv->muxer = g_action_muxer_new ();
14451 _gtk_widget_update_parent_muxer (widget);
14454 return widget->priv->muxer;
14458 * gtk_widget_insert_action_group:
14459 * @widget: a #GtkWidget
14460 * @name: the prefix for actions in @group
14461 * @group: a #GActionGroup
14463 * Inserts @group into @widget. Children of @widget that implement
14464 * #GtkActionable can then be associated with actions in @group by
14465 * setting their 'action-name' to
14466 * @prefix.<replaceable>action-name</replaceable>.
14471 gtk_widget_insert_action_group (GtkWidget *widget,
14473 GActionGroup *group)
14475 GActionMuxer *muxer;
14477 g_return_if_fail (GTK_IS_WIDGET (widget));
14478 g_return_if_fail (name != NULL);
14480 muxer = _gtk_widget_get_action_muxer (widget);
14483 g_action_muxer_insert (muxer, name, group);
14485 g_action_muxer_remove (muxer, name);