1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include <gobject/gvaluecollector.h>
33 #include <gobject/gobjectnotifyqueue.c>
34 #include <cairo-gobject.h>
36 #include "gtkcontainer.h"
37 #include "gtkaccelmapprivate.h"
38 #include "gtkclipboard.h"
39 #include "gtkcssstylepropertyprivate.h"
40 #include "gtkcssnumbervalueprivate.h"
41 #include "gtkiconfactory.h"
43 #include "gtkmarshalers.h"
44 #include "gtkselectionprivate.h"
45 #include "gtksettingsprivate.h"
46 #include "gtksizegroup-private.h"
47 #include "gtksizerequestcacheprivate.h"
48 #include "gtkwidget.h"
49 #include "gtkwidgetprivate.h"
50 #include "gtkwindowprivate.h"
51 #include "gtkcontainerprivate.h"
52 #include "gtkbindings.h"
53 #include "gtkprivate.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
60 #include "gtkstylecontextprivate.h"
61 #include "gtkcssprovider.h"
62 #include "gtkmodifierstyle.h"
63 #include "gtkversion.h"
66 #include "gtktypebuiltins.h"
67 #include "a11y/gtkwidgetaccessible.h"
71 * @Short_description: Base class for all widgets
74 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
75 * widget lifecycle, states and style.
77 * <refsect2 id="geometry-management">
78 * <title>Height-for-width Geometry Management</title>
80 * GTK+ uses a height-for-width (and width-for-height) geometry management
81 * system. Height-for-width means that a widget can change how much
82 * vertical space it needs, depending on the amount of horizontal space
83 * that it is given (and similar for width-for-height). The most common
84 * example is a label that reflows to fill up the available width, wraps
85 * to fewer lines, and therefore needs less height.
87 * Height-for-width geometry management is implemented in GTK+ by way
88 * of five virtual methods:
90 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
93 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
97 * There are some important things to keep in mind when implementing
98 * height-for-width and when using it in container implementations.
100 * The geometry management system will query a widget hierarchy in
101 * only one orientation at a time. When widgets are initially queried
102 * for their minimum sizes it is generally done in two initial passes
103 * in the #GtkSizeRequestMode chosen by the toplevel.
105 * For example, when queried in the normal
106 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
107 * First, the default minimum and natural width for each widget
108 * in the interface will be computed using gtk_widget_get_preferred_width().
109 * Because the preferred widths for each container depend on the preferred
110 * widths of their children, this information propagates up the hierarchy,
111 * and finally a minimum and natural width is determined for the entire
112 * toplevel. Next, the toplevel will use the minimum width to query for the
113 * minimum height contextual to that width using
114 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
115 * recursive operation. The minimum height for the minimum width is normally
116 * used to set the minimum size constraint on the toplevel
117 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
119 * After the toplevel window has initially requested its size in both
120 * dimensions it can go on to allocate itself a reasonable size (or a size
121 * previously specified with gtk_window_set_default_size()). During the
122 * recursive allocation process it's important to note that request cycles
123 * will be recursively executed while container widgets allocate their children.
124 * Each container widget, once allocated a size, will go on to first share the
125 * space in one orientation among its children and then request each child's
126 * height for its target allocated width or its width for allocated height,
127 * depending. In this way a #GtkWidget will typically be requested its size
128 * a number of times before actually being allocated a size. The size a
129 * widget is finally allocated can of course differ from the size it has
130 * requested. For this reason, #GtkWidget caches a small number of results
131 * to avoid re-querying for the same sizes in one allocation cycle.
133 * See <link linkend="container-geometry-management">GtkContainer's
134 * geometry management section</link>
135 * to learn more about how height-for-width allocations are performed
136 * by container widgets.
138 * If a widget does move content around to intelligently use up the
139 * allocated size then it must support the request in both
140 * #GtkSizeRequestModes even if the widget in question only
141 * trades sizes in a single orientation.
143 * For instance, a #GtkLabel that does height-for-width word wrapping
144 * will not expect to have #GtkWidgetClass.get_preferred_height() called
145 * because that call is specific to a width-for-height request. In this
146 * case the label must return the height required for its own minimum
147 * possible width. By following this rule any widget that handles
148 * height-for-width or width-for-height requests will always be allocated
149 * at least enough space to fit its own content.
151 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
152 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
154 * <programlisting><![CDATA[
156 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
158 * if (i_am_in_height_for_width_mode)
162 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
163 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
164 * min_height, nat_height);
168 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
169 * it will return the minimum and natural height for the rotated label here.
172 * ]]></programlisting>
174 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
175 * the minimum and natural width:
177 * <programlisting><![CDATA[
179 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
180 * gint *min_width, gint *nat_width)
182 * if (i_am_in_height_for_width_mode)
184 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
188 * ... again if a widget is sometimes operating in width-for-height mode
189 * (like a rotated GtkLabel) it can go ahead and do its real width for
190 * height calculation here.
193 * ]]></programlisting>
195 * Often a widget needs to get its own request during size request or
196 * allocation. For example, when computing height it may need to also
197 * compute width. Or when deciding how to use an allocation, the widget
198 * may need to know its natural size. In these cases, the widget should
199 * be careful to call its virtual methods directly, like this:
201 * <title>Widget calling its own size request method.</title>
203 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
208 * It will not work to use the wrapper functions, such as
209 * gtk_widget_get_preferred_width() inside your own size request
210 * implementation. These return a request adjusted by #GtkSizeGroup
211 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
212 * widget used the wrappers inside its virtual method implementations,
213 * then the adjustments (such as widget margins) would be applied
214 * twice. GTK+ therefore does not allow this and will warn if you try
217 * Of course if you are getting the size request for
218 * <emphasis>another</emphasis> widget, such as a child of a
219 * container, you <emphasis>must</emphasis> use the wrapper APIs.
220 * Otherwise, you would not properly consider widget margins,
221 * #GtkSizeGroup, and so forth.
224 * <refsect2 id="style-properties">
225 * <title>Style Properties</title>
227 * <structname>GtkWidget</structname> introduces <firstterm>style
228 * properties</firstterm> - these are basically object properties that are stored
229 * not on the object, but in the style object associated to the widget. Style
230 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
231 * This mechanism is used for configuring such things as the location of the
232 * scrollbar arrows through the theme, giving theme authors more control over the
233 * look of applications without the need to write a theme engine in C.
236 * Use gtk_widget_class_install_style_property() to install style properties for
237 * a widget class, gtk_widget_class_find_style_property() or
238 * gtk_widget_class_list_style_properties() to get information about existing
239 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
240 * gtk_widget_style_get_valist() to obtain the value of a style property.
243 * <refsect2 id="GtkWidget-BUILDER-UI">
244 * <title>GtkWidget as GtkBuildable</title>
246 * The GtkWidget implementation of the GtkBuildable interface supports a
247 * custom <accelerator> element, which has attributes named key,
248 * modifiers and signal and allows to specify accelerators.
251 * <title>A UI definition fragment specifying an accelerator</title>
252 * <programlisting><![CDATA[
253 * <object class="GtkButton">
254 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
256 * ]]></programlisting>
259 * In addition to accelerators, <structname>GtkWidget</structname> also support a
260 * custom <accessible> element, which supports actions and relations.
261 * Properties on the accessible implementation of an object can be set by accessing the
262 * internal child "accessible" of a <structname>GtkWidget</structname>.
265 * <title>A UI definition fragment specifying an accessible</title>
266 * <programlisting><![CDATA[
267 * <object class="GtkButton" id="label1"/>
268 * <property name="label">I am a Label for a Button</property>
270 * <object class="GtkButton" id="button1">
272 * <action action_name="click" translatable="yes">Click the button.</action>
273 * <relation target="label1" type="labelled-by"/>
275 * <child internal-child="accessible">
276 * <object class="AtkObject" id="a11y-button1">
277 * <property name="accessible-name">Clickable Button</property>
281 * ]]></programlisting>
284 * Finally, GtkWidget allows style information such as style classes to
285 * be associated with widgets, using the custom <style> element:
287 * <title>A UI definition fragment specifying an style class</title>
288 * <programlisting><![CDATA[
289 * <object class="GtkButton" id="button1">
291 * <class name="my-special-button-class"/>
292 * <class name="dark-button"/>
295 * ]]></programlisting>
301 /* Add flags here that should not be propagated to children. By default,
302 * all flags will be set on children (think prelight or active), but we
303 * might want to not do this for some.
305 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
306 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
308 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
310 #define GTK_STATE_FLAGS_BITS 9
312 struct _GtkWidgetPrivate
314 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
315 * (defined in "gtkenums.h").
317 guint state_flags : GTK_STATE_FLAGS_BITS;
321 guint in_destruction : 1;
324 guint composite_child : 1;
332 guint can_default : 1;
333 guint has_default : 1;
334 guint receives_default : 1;
337 guint style_update_pending : 1;
338 guint app_paintable : 1;
339 guint double_buffered : 1;
340 guint redraw_on_alloc : 1;
341 guint no_show_all : 1;
342 guint child_visible : 1;
343 guint multidevice : 1;
344 guint has_shape_mask : 1;
345 guint in_reparent : 1;
347 /* Queue-resize related flags */
348 guint alloc_needed : 1;
350 /* Expand-related flags */
351 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
352 guint computed_hexpand : 1; /* computed results (composite of child flags) */
353 guint computed_vexpand : 1;
354 guint hexpand : 1; /* application-forced expand */
356 guint hexpand_set : 1; /* whether to use application-forced */
357 guint vexpand_set : 1; /* instead of computing from children */
359 /* SizeGroup related flags */
360 guint have_size_groups : 1;
362 guint opacity_group : 1;
363 guint norender_children : 1;
364 guint norender : 1; /* Don't expose windows, instead recurse via draw */
369 /* The widget's name. If the widget does not have a name
370 * (the name is NULL), then its name (as returned by
371 * "gtk_widget_get_name") is its class's name.
372 * Among other things, the widget name is used to determine
373 * the style to use for a widget.
377 /* The list of attached windows to this widget.
378 * We keep a list in order to call reset_style to all of them,
380 GList *attached_windows;
382 /* The style for the widget. The style contains the
383 * colors the widget should be drawn in for each state
384 * along with graphics contexts used to draw with and
385 * the font to use for text.
388 GtkStyleContext *context;
390 /* Widget's path for styling */
393 /* The widget's allocated size */
394 GtkAllocation allocation;
396 /* The widget's requested sizes */
397 SizeRequestCache requests;
399 /* actions attached to this or any parent widget */
402 /* The widget's window or its parent window if it does
403 * not have a window. (Which will be indicated by the
404 * GTK_NO_WINDOW flag being set).
407 GList *registered_windows;
409 /* The widget's parent */
412 #ifdef G_ENABLE_DEBUG
413 /* Number of gtk_widget_push_verify_invariants () */
414 guint verifying_invariants_count;
415 #endif /* G_ENABLE_DEBUG */
418 struct _GtkWidgetClassPrivate
420 GType accessible_type;
421 AtkRole accessible_role;
450 BUTTON_RELEASE_EVENT,
464 PROPERTY_NOTIFY_EVENT,
465 SELECTION_CLEAR_EVENT,
466 SELECTION_REQUEST_EVENT,
467 SELECTION_NOTIFY_EVENT,
472 VISIBILITY_NOTIFY_EVENT,
486 ACCEL_CLOSURES_CHANGED,
511 PROP_RECEIVES_DEFAULT,
512 PROP_COMPOSITE_CHILD,
521 PROP_DOUBLE_BUFFERED,
536 typedef struct _GtkStateData GtkStateData;
541 guint flags_to_unset;
544 /* --- prototypes --- */
545 static void gtk_widget_base_class_init (gpointer g_class);
546 static void gtk_widget_class_init (GtkWidgetClass *klass);
547 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
548 static void gtk_widget_init (GtkWidget *widget);
549 static void gtk_widget_set_property (GObject *object,
553 static void gtk_widget_get_property (GObject *object,
557 static void gtk_widget_constructed (GObject *object);
558 static void gtk_widget_dispose (GObject *object);
559 static void gtk_widget_real_destroy (GtkWidget *object);
560 static void gtk_widget_finalize (GObject *object);
561 static void gtk_widget_real_show (GtkWidget *widget);
562 static void gtk_widget_real_hide (GtkWidget *widget);
563 static void gtk_widget_real_map (GtkWidget *widget);
564 static void gtk_widget_real_unmap (GtkWidget *widget);
565 static void gtk_widget_real_realize (GtkWidget *widget);
566 static void gtk_widget_real_unrealize (GtkWidget *widget);
567 static void gtk_widget_real_size_allocate (GtkWidget *widget,
568 GtkAllocation *allocation);
569 static void gtk_widget_real_style_set (GtkWidget *widget,
570 GtkStyle *previous_style);
571 static void gtk_widget_real_direction_changed(GtkWidget *widget,
572 GtkTextDirection previous_direction);
574 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
575 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
578 gboolean keyboard_tip,
579 GtkTooltip *tooltip);
580 static void gtk_widget_real_style_updated (GtkWidget *widget);
581 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
582 GtkWidgetHelpType help_type);
584 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
586 GParamSpec **pspecs);
587 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
589 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
591 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
592 GdkEventFocus *event);
593 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
594 GdkEventFocus *event);
595 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
596 GdkEventTouch *event);
597 static gboolean gtk_widget_real_focus (GtkWidget *widget,
598 GtkDirectionType direction);
599 static void gtk_widget_real_move_focus (GtkWidget *widget,
600 GtkDirectionType direction);
601 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
602 GtkDirectionType direction);
603 #ifdef G_ENABLE_DEBUG
604 static void gtk_widget_verify_invariants (GtkWidget *widget);
605 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
606 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
608 #define gtk_widget_verify_invariants(widget)
609 #define gtk_widget_push_verify_invariants(widget)
610 #define gtk_widget_pop_verify_invariants(widget)
612 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
613 static void gtk_widget_update_pango_context (GtkWidget *widget);
614 static void gtk_widget_propagate_state (GtkWidget *widget,
616 static void gtk_widget_update_alpha (GtkWidget *widget);
618 static gint gtk_widget_event_internal (GtkWidget *widget,
620 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
621 gboolean group_cycling);
622 static void gtk_widget_real_get_width (GtkWidget *widget,
625 static void gtk_widget_real_get_height (GtkWidget *widget,
628 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
630 gint *minimum_height,
631 gint *natural_height);
632 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
635 gint *natural_width);
636 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
637 GtkStateFlags old_state);
638 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
639 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
641 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
642 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
643 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
644 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
645 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
646 cairo_region_t *region);
647 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
648 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
651 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
652 gboolean has_tooltip,
654 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
655 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
657 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
658 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
660 const gchar *childname);
661 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
664 const GValue *value);
665 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
668 const gchar *tagname,
669 GMarkupParser *parser,
671 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
674 const gchar *tagname,
676 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
677 GtkBuilder *builder);
679 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
680 static void gtk_widget_real_get_width (GtkWidget *widget,
683 static void gtk_widget_real_get_height (GtkWidget *widget,
687 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
690 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
691 GtkOrientation orientation,
694 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
695 GtkOrientation orientation,
699 gint *allocated_size);
701 static void gtk_widget_set_usize_internal (GtkWidget *widget,
704 GtkQueueResizeFlags flags);
706 static void gtk_widget_add_events_internal (GtkWidget *widget,
709 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
713 static gboolean event_window_is_still_viewable (GdkEvent *event);
714 static void gtk_cairo_set_event (cairo_t *cr,
715 GdkEventExpose *event);
716 static void gtk_widget_propagate_alpha (GtkWidget *widget);
718 /* --- variables --- */
719 static gpointer gtk_widget_parent_class = NULL;
720 static guint widget_signals[LAST_SIGNAL] = { 0 };
721 static guint composite_child_stack = 0;
722 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
723 static GParamSpecPool *style_property_spec_pool = NULL;
725 static GQuark quark_property_parser = 0;
726 static GQuark quark_aux_info = 0;
727 static GQuark quark_accel_path = 0;
728 static GQuark quark_accel_closures = 0;
729 static GQuark quark_event_mask = 0;
730 static GQuark quark_device_event_mask = 0;
731 static GQuark quark_parent_window = 0;
732 static GQuark quark_pointer_window = 0;
733 static GQuark quark_shape_info = 0;
734 static GQuark quark_input_shape_info = 0;
735 static GQuark quark_pango_context = 0;
736 static GQuark quark_accessible_object = 0;
737 static GQuark quark_mnemonic_labels = 0;
738 static GQuark quark_tooltip_markup = 0;
739 static GQuark quark_has_tooltip = 0;
740 static GQuark quark_tooltip_window = 0;
741 static GQuark quark_visual = 0;
742 static GQuark quark_modifier_style = 0;
743 static GQuark quark_enabled_devices = 0;
744 static GQuark quark_size_groups = 0;
745 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
746 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
748 /* --- functions --- */
750 gtk_widget_get_type (void)
752 static GType widget_type = 0;
754 if (G_UNLIKELY (widget_type == 0))
756 const GTypeInfo widget_info =
758 sizeof (GtkWidgetClass),
759 gtk_widget_base_class_init,
760 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
761 (GClassInitFunc) gtk_widget_class_init,
762 NULL, /* class_finalize */
763 NULL, /* class_init */
766 (GInstanceInitFunc) gtk_widget_init,
767 NULL, /* value_table */
770 const GInterfaceInfo accessibility_info =
772 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
773 (GInterfaceFinalizeFunc) NULL,
774 NULL /* interface data */
777 const GInterfaceInfo buildable_info =
779 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
780 (GInterfaceFinalizeFunc) NULL,
781 NULL /* interface data */
784 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
785 &widget_info, G_TYPE_FLAG_ABSTRACT);
787 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
789 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
790 &accessibility_info) ;
791 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
799 gtk_widget_base_class_init (gpointer g_class)
801 GtkWidgetClass *klass = g_class;
803 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
807 child_property_notify_dispatcher (GObject *object,
811 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
814 /* We guard against the draw signal callbacks modifying the state of the
815 * cairo context by surounding it with save/restore.
816 * Maybe we should also cairo_new_path() just to be sure?
819 gtk_widget_draw_marshaller (GClosure *closure,
820 GValue *return_value,
821 guint n_param_values,
822 const GValue *param_values,
823 gpointer invocation_hint,
824 gpointer marshal_data)
826 GtkWidget *widget = g_value_get_object (¶m_values[0]);
827 GdkEventExpose *tmp_event;
829 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
832 tmp_event = _gtk_cairo_get_event (cr);
835 widget->priv->opacity_group ||
836 (widget->priv->alpha != 255 &&
837 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
841 cairo_push_group (cr);
842 gtk_cairo_set_event (cr, NULL);
845 _gtk_marshal_BOOLEAN__BOXED (closure,
855 cairo_pop_group_to_source (cr);
856 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
857 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
860 gtk_cairo_set_event (cr, tmp_event);
865 gtk_widget_draw_marshallerv (GClosure *closure,
866 GValue *return_value,
869 gpointer marshal_data,
873 GtkWidget *widget = GTK_WIDGET (instance);
874 GdkEventExpose *tmp_event;
879 G_VA_COPY (args_copy, args);
880 cr = va_arg (args_copy, gpointer);
883 tmp_event = _gtk_cairo_get_event (cr);
886 widget->priv->opacity_group ||
887 (widget->priv->alpha != 255 &&
888 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
892 cairo_push_group (cr);
893 gtk_cairo_set_event (cr, NULL);
896 _gtk_marshal_BOOLEAN__BOXEDv (closure,
907 cairo_pop_group_to_source (cr);
908 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
909 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
912 gtk_cairo_set_event (cr, tmp_event);
919 gtk_widget_class_init (GtkWidgetClass *klass)
921 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
922 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
923 GtkBindingSet *binding_set;
925 gtk_widget_parent_class = g_type_class_peek_parent (klass);
927 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
928 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
929 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
930 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
931 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
932 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
933 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
934 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
935 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
936 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
937 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
938 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
939 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
940 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
941 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
942 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
943 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
944 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
945 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
946 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
948 style_property_spec_pool = g_param_spec_pool_new (FALSE);
949 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
950 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
951 cpn_context.dispatcher = child_property_notify_dispatcher;
952 _gtk_widget_child_property_notify_context = &cpn_context;
954 gobject_class->constructed = gtk_widget_constructed;
955 gobject_class->dispose = gtk_widget_dispose;
956 gobject_class->finalize = gtk_widget_finalize;
957 gobject_class->set_property = gtk_widget_set_property;
958 gobject_class->get_property = gtk_widget_get_property;
960 klass->destroy = gtk_widget_real_destroy;
962 klass->activate_signal = 0;
963 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
964 klass->show = gtk_widget_real_show;
965 klass->show_all = gtk_widget_show;
966 klass->hide = gtk_widget_real_hide;
967 klass->map = gtk_widget_real_map;
968 klass->unmap = gtk_widget_real_unmap;
969 klass->realize = gtk_widget_real_realize;
970 klass->unrealize = gtk_widget_real_unrealize;
971 klass->size_allocate = gtk_widget_real_size_allocate;
972 klass->get_request_mode = gtk_widget_real_get_request_mode;
973 klass->get_preferred_width = gtk_widget_real_get_width;
974 klass->get_preferred_height = gtk_widget_real_get_height;
975 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
976 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
977 klass->state_changed = NULL;
978 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
979 klass->parent_set = NULL;
980 klass->hierarchy_changed = NULL;
981 klass->style_set = gtk_widget_real_style_set;
982 klass->direction_changed = gtk_widget_real_direction_changed;
983 klass->grab_notify = NULL;
984 klass->child_notify = NULL;
986 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
987 klass->grab_focus = gtk_widget_real_grab_focus;
988 klass->focus = gtk_widget_real_focus;
989 klass->move_focus = gtk_widget_real_move_focus;
990 klass->keynav_failed = gtk_widget_real_keynav_failed;
992 klass->button_press_event = NULL;
993 klass->button_release_event = NULL;
994 klass->motion_notify_event = NULL;
995 klass->touch_event = gtk_widget_real_touch_event;
996 klass->delete_event = NULL;
997 klass->destroy_event = NULL;
998 klass->key_press_event = gtk_widget_real_key_press_event;
999 klass->key_release_event = gtk_widget_real_key_release_event;
1000 klass->enter_notify_event = NULL;
1001 klass->leave_notify_event = NULL;
1002 klass->configure_event = NULL;
1003 klass->focus_in_event = gtk_widget_real_focus_in_event;
1004 klass->focus_out_event = gtk_widget_real_focus_out_event;
1005 klass->map_event = NULL;
1006 klass->unmap_event = NULL;
1007 klass->window_state_event = NULL;
1008 klass->property_notify_event = _gtk_selection_property_notify;
1009 klass->selection_clear_event = _gtk_selection_clear;
1010 klass->selection_request_event = _gtk_selection_request;
1011 klass->selection_notify_event = _gtk_selection_notify;
1012 klass->selection_received = NULL;
1013 klass->proximity_in_event = NULL;
1014 klass->proximity_out_event = NULL;
1015 klass->drag_begin = NULL;
1016 klass->drag_end = NULL;
1017 klass->drag_data_delete = NULL;
1018 klass->drag_leave = NULL;
1019 klass->drag_motion = NULL;
1020 klass->drag_drop = NULL;
1021 klass->drag_data_received = NULL;
1022 klass->screen_changed = NULL;
1023 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1024 klass->grab_broken_event = NULL;
1025 klass->query_tooltip = gtk_widget_real_query_tooltip;
1026 klass->style_updated = gtk_widget_real_style_updated;
1028 klass->show_help = gtk_widget_real_show_help;
1030 /* Accessibility support */
1031 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1032 klass->priv->accessible_role = ATK_ROLE_INVALID;
1033 klass->get_accessible = gtk_widget_real_get_accessible;
1035 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1036 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1038 g_object_class_install_property (gobject_class,
1040 g_param_spec_string ("name",
1042 P_("The name of the widget"),
1044 GTK_PARAM_READWRITE));
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_object ("parent",
1048 P_("Parent widget"),
1049 P_("The parent widget of this widget. Must be a Container widget"),
1051 GTK_PARAM_READWRITE));
1053 g_object_class_install_property (gobject_class,
1055 g_param_spec_int ("width-request",
1056 P_("Width request"),
1057 P_("Override for width request of the widget, or -1 if natural request should be used"),
1061 GTK_PARAM_READWRITE));
1062 g_object_class_install_property (gobject_class,
1063 PROP_HEIGHT_REQUEST,
1064 g_param_spec_int ("height-request",
1065 P_("Height request"),
1066 P_("Override for height request of the widget, or -1 if natural request should be used"),
1070 GTK_PARAM_READWRITE));
1071 g_object_class_install_property (gobject_class,
1073 g_param_spec_boolean ("visible",
1075 P_("Whether the widget is visible"),
1077 GTK_PARAM_READWRITE));
1078 g_object_class_install_property (gobject_class,
1080 g_param_spec_boolean ("sensitive",
1082 P_("Whether the widget responds to input"),
1084 GTK_PARAM_READWRITE));
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_boolean ("app-paintable",
1088 P_("Application paintable"),
1089 P_("Whether the application will paint directly on the widget"),
1091 GTK_PARAM_READWRITE));
1092 g_object_class_install_property (gobject_class,
1094 g_param_spec_boolean ("can-focus",
1096 P_("Whether the widget can accept the input focus"),
1098 GTK_PARAM_READWRITE));
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_boolean ("has-focus",
1103 P_("Whether the widget has the input focus"),
1105 GTK_PARAM_READWRITE));
1106 g_object_class_install_property (gobject_class,
1108 g_param_spec_boolean ("is-focus",
1110 P_("Whether the widget is the focus widget within the toplevel"),
1112 GTK_PARAM_READWRITE));
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_boolean ("can-default",
1117 P_("Whether the widget can be the default widget"),
1119 GTK_PARAM_READWRITE));
1120 g_object_class_install_property (gobject_class,
1122 g_param_spec_boolean ("has-default",
1124 P_("Whether the widget is the default widget"),
1126 GTK_PARAM_READWRITE));
1127 g_object_class_install_property (gobject_class,
1128 PROP_RECEIVES_DEFAULT,
1129 g_param_spec_boolean ("receives-default",
1130 P_("Receives default"),
1131 P_("If TRUE, the widget will receive the default action when it is focused"),
1133 GTK_PARAM_READWRITE));
1134 g_object_class_install_property (gobject_class,
1135 PROP_COMPOSITE_CHILD,
1136 g_param_spec_boolean ("composite-child",
1137 P_("Composite child"),
1138 P_("Whether the widget is part of a composite widget"),
1140 GTK_PARAM_READABLE));
1141 g_object_class_install_property (gobject_class,
1143 g_param_spec_object ("style",
1145 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1147 GTK_PARAM_READWRITE));
1148 g_object_class_install_property (gobject_class,
1150 g_param_spec_flags ("events",
1152 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1153 GDK_TYPE_EVENT_MASK,
1155 GTK_PARAM_READWRITE));
1156 g_object_class_install_property (gobject_class,
1158 g_param_spec_boolean ("no-show-all",
1160 P_("Whether gtk_widget_show_all() should not affect this widget"),
1162 GTK_PARAM_READWRITE));
1165 * GtkWidget:has-tooltip:
1167 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1168 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1169 * the widget will be queried using #GtkWidget::query-tooltip to determine
1170 * whether it will provide a tooltip or not.
1172 * Note that setting this property to %TRUE for the first time will change
1173 * the event masks of the GdkWindows of this widget to include leave-notify
1174 * and motion-notify events. This cannot and will not be undone when the
1175 * property is set to %FALSE again.
1179 g_object_class_install_property (gobject_class,
1181 g_param_spec_boolean ("has-tooltip",
1183 P_("Whether this widget has a tooltip"),
1185 GTK_PARAM_READWRITE));
1187 * GtkWidget:tooltip-text:
1189 * Sets the text of tooltip to be the given string.
1191 * Also see gtk_tooltip_set_text().
1193 * This is a convenience property which will take care of getting the
1194 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1195 * will automatically be set to %TRUE and there will be taken care of
1196 * #GtkWidget::query-tooltip in the default signal handler.
1200 g_object_class_install_property (gobject_class,
1202 g_param_spec_string ("tooltip-text",
1204 P_("The contents of the tooltip for this widget"),
1206 GTK_PARAM_READWRITE));
1208 * GtkWidget:tooltip-markup:
1210 * Sets the text of tooltip to be the given string, which is marked up
1211 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1212 * Also see gtk_tooltip_set_markup().
1214 * This is a convenience property which will take care of getting the
1215 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1216 * will automatically be set to %TRUE and there will be taken care of
1217 * #GtkWidget::query-tooltip in the default signal handler.
1221 g_object_class_install_property (gobject_class,
1222 PROP_TOOLTIP_MARKUP,
1223 g_param_spec_string ("tooltip-markup",
1224 P_("Tooltip markup"),
1225 P_("The contents of the tooltip for this widget"),
1227 GTK_PARAM_READWRITE));
1232 * The widget's window if it is realized, %NULL otherwise.
1236 g_object_class_install_property (gobject_class,
1238 g_param_spec_object ("window",
1240 P_("The widget's window if it is realized"),
1242 GTK_PARAM_READABLE));
1245 * GtkWidget:double-buffered:
1247 * Whether the widget is double buffered.
1251 g_object_class_install_property (gobject_class,
1252 PROP_DOUBLE_BUFFERED,
1253 g_param_spec_boolean ("double-buffered",
1254 P_("Double Buffered"),
1255 P_("Whether the widget is double buffered"),
1257 GTK_PARAM_READWRITE));
1262 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1266 g_object_class_install_property (gobject_class,
1268 g_param_spec_enum ("halign",
1269 P_("Horizontal Alignment"),
1270 P_("How to position in extra horizontal space"),
1273 GTK_PARAM_READWRITE));
1278 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1282 g_object_class_install_property (gobject_class,
1284 g_param_spec_enum ("valign",
1285 P_("Vertical Alignment"),
1286 P_("How to position in extra vertical space"),
1289 GTK_PARAM_READWRITE));
1292 * GtkWidget:margin-left:
1294 * Margin on left side of widget.
1296 * This property adds margin outside of the widget's normal size
1297 * request, the margin will be added in addition to the size from
1298 * gtk_widget_set_size_request() for example.
1302 g_object_class_install_property (gobject_class,
1304 g_param_spec_int ("margin-left",
1305 P_("Margin on Left"),
1306 P_("Pixels of extra space on the left side"),
1310 GTK_PARAM_READWRITE));
1313 * GtkWidget:margin-right:
1315 * Margin on right side of widget.
1317 * This property adds margin outside of the widget's normal size
1318 * request, the margin will be added in addition to the size from
1319 * gtk_widget_set_size_request() for example.
1323 g_object_class_install_property (gobject_class,
1325 g_param_spec_int ("margin-right",
1326 P_("Margin on Right"),
1327 P_("Pixels of extra space on the right side"),
1331 GTK_PARAM_READWRITE));
1334 * GtkWidget:margin-top:
1336 * Margin on top side of widget.
1338 * This property adds margin outside of the widget's normal size
1339 * request, the margin will be added in addition to the size from
1340 * gtk_widget_set_size_request() for example.
1344 g_object_class_install_property (gobject_class,
1346 g_param_spec_int ("margin-top",
1347 P_("Margin on Top"),
1348 P_("Pixels of extra space on the top side"),
1352 GTK_PARAM_READWRITE));
1355 * GtkWidget:margin-bottom:
1357 * Margin on bottom side of widget.
1359 * This property adds margin outside of the widget's normal size
1360 * request, the margin will be added in addition to the size from
1361 * gtk_widget_set_size_request() for example.
1365 g_object_class_install_property (gobject_class,
1367 g_param_spec_int ("margin-bottom",
1368 P_("Margin on Bottom"),
1369 P_("Pixels of extra space on the bottom side"),
1373 GTK_PARAM_READWRITE));
1378 * Sets all four sides' margin at once. If read, returns max
1379 * margin on any side.
1383 g_object_class_install_property (gobject_class,
1385 g_param_spec_int ("margin",
1387 P_("Pixels of extra space on all four sides"),
1391 GTK_PARAM_READWRITE));
1394 * GtkWidget::destroy:
1395 * @object: the object which received the signal
1397 * Signals that all holders of a reference to the widget should release
1398 * the reference that they hold. May result in finalization of the widget
1399 * if all references are released.
1401 widget_signals[DESTROY] =
1402 g_signal_new (I_("destroy"),
1403 G_TYPE_FROM_CLASS (gobject_class),
1404 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1405 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1407 _gtk_marshal_VOID__VOID,
1411 * GtkWidget:hexpand:
1413 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1417 g_object_class_install_property (gobject_class,
1419 g_param_spec_boolean ("hexpand",
1420 P_("Horizontal Expand"),
1421 P_("Whether widget wants more horizontal space"),
1423 GTK_PARAM_READWRITE));
1426 * GtkWidget:hexpand-set:
1428 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1432 g_object_class_install_property (gobject_class,
1434 g_param_spec_boolean ("hexpand-set",
1435 P_("Horizontal Expand Set"),
1436 P_("Whether to use the hexpand property"),
1438 GTK_PARAM_READWRITE));
1441 * GtkWidget:vexpand:
1443 * Whether to expand vertically. See gtk_widget_set_vexpand().
1447 g_object_class_install_property (gobject_class,
1449 g_param_spec_boolean ("vexpand",
1450 P_("Vertical Expand"),
1451 P_("Whether widget wants more vertical space"),
1453 GTK_PARAM_READWRITE));
1456 * GtkWidget:vexpand-set:
1458 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1462 g_object_class_install_property (gobject_class,
1464 g_param_spec_boolean ("vexpand-set",
1465 P_("Vertical Expand Set"),
1466 P_("Whether to use the vexpand property"),
1468 GTK_PARAM_READWRITE));
1473 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1477 g_object_class_install_property (gobject_class,
1479 g_param_spec_boolean ("expand",
1481 P_("Whether widget wants to expand in both directions"),
1483 GTK_PARAM_READWRITE));
1486 * GtkWidget:opacity:
1488 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1489 * more details about window opacity.
1491 * Before 3.8 this was only availible in GtkWindow
1495 g_object_class_install_property (gobject_class,
1497 g_param_spec_double ("opacity",
1498 P_("Opacity for Widget"),
1499 P_("The opacity of the widget, from 0 to 1"),
1503 GTK_PARAM_READWRITE));
1506 * @widget: the object which received the signal.
1508 widget_signals[SHOW] =
1509 g_signal_new (I_("show"),
1510 G_TYPE_FROM_CLASS (gobject_class),
1512 G_STRUCT_OFFSET (GtkWidgetClass, show),
1514 _gtk_marshal_VOID__VOID,
1519 * @widget: the object which received the signal.
1521 widget_signals[HIDE] =
1522 g_signal_new (I_("hide"),
1523 G_TYPE_FROM_CLASS (gobject_class),
1525 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1527 _gtk_marshal_VOID__VOID,
1532 * @widget: the object which received the signal.
1534 widget_signals[MAP] =
1535 g_signal_new (I_("map"),
1536 G_TYPE_FROM_CLASS (gobject_class),
1538 G_STRUCT_OFFSET (GtkWidgetClass, map),
1540 _gtk_marshal_VOID__VOID,
1545 * @widget: the object which received the signal.
1547 widget_signals[UNMAP] =
1548 g_signal_new (I_("unmap"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1551 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1553 _gtk_marshal_VOID__VOID,
1557 * GtkWidget::realize:
1558 * @widget: the object which received the signal.
1560 widget_signals[REALIZE] =
1561 g_signal_new (I_("realize"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1566 _gtk_marshal_VOID__VOID,
1570 * GtkWidget::unrealize:
1571 * @widget: the object which received the signal.
1573 widget_signals[UNREALIZE] =
1574 g_signal_new (I_("unrealize"),
1575 G_TYPE_FROM_CLASS (gobject_class),
1577 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1579 _gtk_marshal_VOID__VOID,
1583 * GtkWidget::size-allocate:
1584 * @widget: the object which received the signal.
1587 widget_signals[SIZE_ALLOCATE] =
1588 g_signal_new (I_("size-allocate"),
1589 G_TYPE_FROM_CLASS (gobject_class),
1591 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1593 _gtk_marshal_VOID__BOXED,
1595 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1598 * GtkWidget::state-changed:
1599 * @widget: the object which received the signal.
1600 * @state: the previous state
1602 * The ::state-changed signal is emitted when the widget state changes.
1603 * See gtk_widget_get_state().
1605 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1607 widget_signals[STATE_CHANGED] =
1608 g_signal_new (I_("state-changed"),
1609 G_TYPE_FROM_CLASS (gobject_class),
1611 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1613 _gtk_marshal_VOID__ENUM,
1615 GTK_TYPE_STATE_TYPE);
1618 * GtkWidget::state-flags-changed:
1619 * @widget: the object which received the signal.
1620 * @flags: The previous state flags.
1622 * The ::state-flags-changed signal is emitted when the widget state
1623 * changes, see gtk_widget_get_state_flags().
1627 widget_signals[STATE_FLAGS_CHANGED] =
1628 g_signal_new (I_("state-flags-changed"),
1629 G_TYPE_FROM_CLASS (gobject_class),
1631 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1633 _gtk_marshal_VOID__FLAGS,
1635 GTK_TYPE_STATE_FLAGS);
1638 * GtkWidget::parent-set:
1639 * @widget: the object on which the signal is emitted
1640 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1641 * just got its initial parent.
1643 * The ::parent-set signal is emitted when a new parent
1644 * has been set on a widget.
1646 widget_signals[PARENT_SET] =
1647 g_signal_new (I_("parent-set"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1650 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1652 _gtk_marshal_VOID__OBJECT,
1657 * GtkWidget::hierarchy-changed:
1658 * @widget: the object on which the signal is emitted
1659 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1660 * if the widget was previously unanchored
1662 * The ::hierarchy-changed signal is emitted when the
1663 * anchored state of a widget changes. A widget is
1664 * <firstterm>anchored</firstterm> when its toplevel
1665 * ancestor is a #GtkWindow. This signal is emitted when
1666 * a widget changes from un-anchored to anchored or vice-versa.
1668 widget_signals[HIERARCHY_CHANGED] =
1669 g_signal_new (I_("hierarchy-changed"),
1670 G_TYPE_FROM_CLASS (gobject_class),
1672 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1674 _gtk_marshal_VOID__OBJECT,
1679 * GtkWidget::style-set:
1680 * @widget: the object on which the signal is emitted
1681 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1682 * just got its initial style
1684 * The ::style-set signal is emitted when a new style has been set
1685 * on a widget. Note that style-modifying functions like
1686 * gtk_widget_modify_base() also cause this signal to be emitted.
1688 * Note that this signal is emitted for changes to the deprecated
1689 * #GtkStyle. To track changes to the #GtkStyleContext associated
1690 * with a widget, use the #GtkWidget::style-updated signal.
1692 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1694 widget_signals[STYLE_SET] =
1695 g_signal_new (I_("style-set"),
1696 G_TYPE_FROM_CLASS (gobject_class),
1698 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1700 _gtk_marshal_VOID__OBJECT,
1705 * GtkWidget::style-updated:
1706 * @widget: the object on which the signal is emitted
1708 * The ::style-updated signal is emitted when the #GtkStyleContext
1709 * of a widget is changed. Note that style-modifying functions like
1710 * gtk_widget_override_color() also cause this signal to be emitted.
1714 widget_signals[STYLE_UPDATED] =
1715 g_signal_new (I_("style-updated"),
1716 G_TYPE_FROM_CLASS (gobject_class),
1718 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1720 g_cclosure_marshal_VOID__VOID,
1724 * GtkWidget::direction-changed:
1725 * @widget: the object on which the signal is emitted
1726 * @previous_direction: the previous text direction of @widget
1728 * The ::direction-changed signal is emitted when the text direction
1729 * of a widget changes.
1731 widget_signals[DIRECTION_CHANGED] =
1732 g_signal_new (I_("direction-changed"),
1733 G_TYPE_FROM_CLASS (gobject_class),
1735 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1737 _gtk_marshal_VOID__ENUM,
1739 GTK_TYPE_TEXT_DIRECTION);
1742 * GtkWidget::grab-notify:
1743 * @widget: the object which received the signal
1744 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1745 * if it becomes unshadowed
1747 * The ::grab-notify signal is emitted when a widget becomes
1748 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1749 * another widget, or when it becomes unshadowed due to a grab
1752 * A widget is shadowed by a gtk_grab_add() when the topmost
1753 * grab widget in the grab stack of its window group is not
1756 widget_signals[GRAB_NOTIFY] =
1757 g_signal_new (I_("grab-notify"),
1758 G_TYPE_FROM_CLASS (gobject_class),
1760 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1762 _gtk_marshal_VOID__BOOLEAN,
1767 * GtkWidget::child-notify:
1768 * @widget: the object which received the signal
1769 * @child_property: the #GParamSpec of the changed child property
1771 * The ::child-notify signal is emitted for each
1772 * <link linkend="child-properties">child property</link> that has
1773 * changed on an object. The signal's detail holds the property name.
1775 widget_signals[CHILD_NOTIFY] =
1776 g_signal_new (I_("child-notify"),
1777 G_TYPE_FROM_CLASS (gobject_class),
1778 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1779 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1781 g_cclosure_marshal_VOID__PARAM,
1787 * @widget: the object which received the signal
1788 * @cr: the cairo context to draw to
1790 * This signal is emitted when a widget is supposed to render itself.
1791 * The @widget's top left corner must be painted at the origin of
1792 * the passed in context and be sized to the values returned by
1793 * gtk_widget_get_allocated_width() and
1794 * gtk_widget_get_allocated_height().
1796 * Signal handlers connected to this signal can modify the cairo
1797 * context passed as @cr in any way they like and don't need to
1798 * restore it. The signal emission takes care of calling cairo_save()
1799 * before and cairo_restore() after invoking the handler.
1801 * Returns: %TRUE to stop other handlers from being invoked for the event.
1802 % %FALSE to propagate the event further.
1806 widget_signals[DRAW] =
1807 g_signal_new (I_("draw"),
1808 G_TYPE_FROM_CLASS (gobject_class),
1810 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1811 _gtk_boolean_handled_accumulator, NULL,
1812 gtk_widget_draw_marshaller,
1814 CAIRO_GOBJECT_TYPE_CONTEXT);
1815 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1816 gtk_widget_draw_marshallerv);
1819 * GtkWidget::mnemonic-activate:
1820 * @widget: the object which received the signal.
1823 * Returns: %TRUE to stop other handlers from being invoked for the event.
1824 * %FALSE to propagate the event further.
1826 widget_signals[MNEMONIC_ACTIVATE] =
1827 g_signal_new (I_("mnemonic-activate"),
1828 G_TYPE_FROM_CLASS (gobject_class),
1830 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1831 _gtk_boolean_handled_accumulator, NULL,
1832 _gtk_marshal_BOOLEAN__BOOLEAN,
1837 * GtkWidget::grab-focus:
1838 * @widget: the object which received the signal.
1840 widget_signals[GRAB_FOCUS] =
1841 g_signal_new (I_("grab-focus"),
1842 G_TYPE_FROM_CLASS (gobject_class),
1843 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1844 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1846 _gtk_marshal_VOID__VOID,
1851 * @widget: the object which received the signal.
1854 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1856 widget_signals[FOCUS] =
1857 g_signal_new (I_("focus"),
1858 G_TYPE_FROM_CLASS (klass),
1860 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1861 _gtk_boolean_handled_accumulator, NULL,
1862 _gtk_marshal_BOOLEAN__ENUM,
1864 GTK_TYPE_DIRECTION_TYPE);
1867 * GtkWidget::move-focus:
1868 * @widget: the object which received the signal.
1871 widget_signals[MOVE_FOCUS] =
1872 g_signal_new (I_("move-focus"),
1873 G_TYPE_FROM_CLASS (klass),
1874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1875 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1877 _gtk_marshal_VOID__ENUM,
1880 GTK_TYPE_DIRECTION_TYPE);
1883 * GtkWidget::keynav-failed:
1884 * @widget: the object which received the signal
1885 * @direction: the direction of movement
1887 * Gets emitted if keyboard navigation fails.
1888 * See gtk_widget_keynav_failed() for details.
1890 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1891 * if the emitting widget should try to handle the keyboard
1892 * navigation attempt in its parent container(s).
1896 widget_signals[KEYNAV_FAILED] =
1897 g_signal_new (I_("keynav-failed"),
1898 G_TYPE_FROM_CLASS (klass),
1900 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1901 _gtk_boolean_handled_accumulator, NULL,
1902 _gtk_marshal_BOOLEAN__ENUM,
1904 GTK_TYPE_DIRECTION_TYPE);
1908 * @widget: the object which received the signal.
1909 * @event: the #GdkEvent which triggered this signal
1911 * The GTK+ main loop will emit three signals for each GDK event delivered
1912 * to a widget: one generic ::event signal, another, more specific,
1913 * signal that matches the type of event delivered (e.g.
1914 * #GtkWidget::key-press-event) and finally a generic
1915 * #GtkWidget::event-after signal.
1917 * Returns: %TRUE to stop other handlers from being invoked for the event
1918 * and to cancel the emission of the second specific ::event signal.
1919 * %FALSE to propagate the event further and to allow the emission of
1920 * the second signal. The ::event-after signal is emitted regardless of
1923 widget_signals[EVENT] =
1924 g_signal_new (I_("event"),
1925 G_TYPE_FROM_CLASS (klass),
1927 G_STRUCT_OFFSET (GtkWidgetClass, event),
1928 _gtk_boolean_handled_accumulator, NULL,
1929 _gtk_marshal_BOOLEAN__BOXED,
1931 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1932 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1933 _gtk_marshal_BOOLEAN__BOXEDv);
1936 * GtkWidget::event-after:
1937 * @widget: the object which received the signal.
1938 * @event: the #GdkEvent which triggered this signal
1940 * After the emission of the #GtkWidget::event signal and (optionally)
1941 * the second more specific signal, ::event-after will be emitted
1942 * regardless of the previous two signals handlers return values.
1945 widget_signals[EVENT_AFTER] =
1946 g_signal_new (I_("event-after"),
1947 G_TYPE_FROM_CLASS (klass),
1951 _gtk_marshal_VOID__BOXED,
1953 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1954 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1955 _gtk_marshal_BOOLEAN__BOXEDv);
1958 * GtkWidget::button-press-event:
1959 * @widget: the object which received the signal.
1960 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1963 * The ::button-press-event signal will be emitted when a button
1964 * (typically from a mouse) is pressed.
1966 * To receive this signal, the #GdkWindow associated to the
1967 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1969 * This signal will be sent to the grab widget if there is one.
1971 * Returns: %TRUE to stop other handlers from being invoked for the event.
1972 * %FALSE to propagate the event further.
1974 widget_signals[BUTTON_PRESS_EVENT] =
1975 g_signal_new (I_("button-press-event"),
1976 G_TYPE_FROM_CLASS (klass),
1978 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1979 _gtk_boolean_handled_accumulator, NULL,
1980 _gtk_marshal_BOOLEAN__BOXED,
1982 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1983 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1984 _gtk_marshal_BOOLEAN__BOXEDv);
1987 * GtkWidget::button-release-event:
1988 * @widget: the object which received the signal.
1989 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1992 * The ::button-release-event signal will be emitted when a button
1993 * (typically from a mouse) is released.
1995 * To receive this signal, the #GdkWindow associated to the
1996 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1998 * This signal will be sent to the grab widget if there is one.
2000 * Returns: %TRUE to stop other handlers from being invoked for the event.
2001 * %FALSE to propagate the event further.
2003 widget_signals[BUTTON_RELEASE_EVENT] =
2004 g_signal_new (I_("button-release-event"),
2005 G_TYPE_FROM_CLASS (klass),
2007 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2008 _gtk_boolean_handled_accumulator, NULL,
2009 _gtk_marshal_BOOLEAN__BOXED,
2011 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2012 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2013 _gtk_marshal_BOOLEAN__BOXEDv);
2015 widget_signals[TOUCH_EVENT] =
2016 g_signal_new (I_("touch-event"),
2017 G_TYPE_FROM_CLASS (klass),
2019 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2020 _gtk_boolean_handled_accumulator, NULL,
2021 _gtk_marshal_BOOLEAN__BOXED,
2023 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2024 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2025 _gtk_marshal_BOOLEAN__BOXEDv);
2028 * GtkWidget::scroll-event:
2029 * @widget: the object which received the signal.
2030 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2033 * The ::scroll-event signal is emitted when a button in the 4 to 7
2034 * range is pressed. Wheel mice are usually configured to generate
2035 * button press events for buttons 4 and 5 when the wheel is turned.
2037 * To receive this signal, the #GdkWindow associated to the widget needs
2038 * to enable the #GDK_SCROLL_MASK mask.
2040 * This signal will be sent to the grab widget if there is one.
2042 * Returns: %TRUE to stop other handlers from being invoked for the event.
2043 * %FALSE to propagate the event further.
2045 widget_signals[SCROLL_EVENT] =
2046 g_signal_new (I_("scroll-event"),
2047 G_TYPE_FROM_CLASS (klass),
2049 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2050 _gtk_boolean_handled_accumulator, NULL,
2051 _gtk_marshal_BOOLEAN__BOXED,
2053 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2054 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2055 _gtk_marshal_BOOLEAN__BOXEDv);
2058 * GtkWidget::motion-notify-event:
2059 * @widget: the object which received the signal.
2060 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2063 * The ::motion-notify-event signal is emitted when the pointer moves
2064 * over the widget's #GdkWindow.
2066 * To receive this signal, the #GdkWindow associated to the widget
2067 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2069 * This signal will be sent to the grab widget if there is one.
2071 * Returns: %TRUE to stop other handlers from being invoked for the event.
2072 * %FALSE to propagate the event further.
2074 widget_signals[MOTION_NOTIFY_EVENT] =
2075 g_signal_new (I_("motion-notify-event"),
2076 G_TYPE_FROM_CLASS (klass),
2078 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2079 _gtk_boolean_handled_accumulator, NULL,
2080 _gtk_marshal_BOOLEAN__BOXED,
2082 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2083 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2084 _gtk_marshal_BOOLEAN__BOXEDv);
2087 * GtkWidget::composited-changed:
2088 * @widget: the object on which the signal is emitted
2090 * The ::composited-changed signal is emitted when the composited
2091 * status of @widget<!-- -->s screen changes.
2092 * See gdk_screen_is_composited().
2094 widget_signals[COMPOSITED_CHANGED] =
2095 g_signal_new (I_("composited-changed"),
2096 G_TYPE_FROM_CLASS (klass),
2097 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2098 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2100 _gtk_marshal_VOID__VOID,
2104 * GtkWidget::delete-event:
2105 * @widget: the object which received the signal
2106 * @event: the event which triggered this signal
2108 * The ::delete-event signal is emitted if a user requests that
2109 * a toplevel window is closed. The default handler for this signal
2110 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2111 * this signal will cause the window to be hidden instead, so that
2112 * it can later be shown again without reconstructing it.
2114 * Returns: %TRUE to stop other handlers from being invoked for the event.
2115 * %FALSE to propagate the event further.
2117 widget_signals[DELETE_EVENT] =
2118 g_signal_new (I_("delete-event"),
2119 G_TYPE_FROM_CLASS (klass),
2121 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2122 _gtk_boolean_handled_accumulator, NULL,
2123 _gtk_marshal_BOOLEAN__BOXED,
2125 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2126 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2127 _gtk_marshal_BOOLEAN__BOXEDv);
2130 * GtkWidget::destroy-event:
2131 * @widget: the object which received the signal.
2132 * @event: the event which triggered this signal
2134 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2135 * You rarely get this signal, because most widgets disconnect themselves
2136 * from their window before they destroy it, so no widget owns the
2137 * window at destroy time.
2139 * To receive this signal, the #GdkWindow associated to the widget needs
2140 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2141 * automatically for all new windows.
2143 * Returns: %TRUE to stop other handlers from being invoked for the event.
2144 * %FALSE to propagate the event further.
2146 widget_signals[DESTROY_EVENT] =
2147 g_signal_new (I_("destroy-event"),
2148 G_TYPE_FROM_CLASS (klass),
2150 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2151 _gtk_boolean_handled_accumulator, NULL,
2152 _gtk_marshal_BOOLEAN__BOXED,
2154 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2155 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2156 _gtk_marshal_BOOLEAN__BOXEDv);
2159 * GtkWidget::key-press-event:
2160 * @widget: the object which received the signal
2161 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2163 * The ::key-press-event signal is emitted when a key is pressed. The signal
2164 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2166 * To receive this signal, the #GdkWindow associated to the widget needs
2167 * to enable the #GDK_KEY_PRESS_MASK mask.
2169 * This signal will be sent to the grab widget if there is one.
2171 * Returns: %TRUE to stop other handlers from being invoked for the event.
2172 * %FALSE to propagate the event further.
2174 widget_signals[KEY_PRESS_EVENT] =
2175 g_signal_new (I_("key-press-event"),
2176 G_TYPE_FROM_CLASS (klass),
2178 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2179 _gtk_boolean_handled_accumulator, NULL,
2180 _gtk_marshal_BOOLEAN__BOXED,
2182 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2183 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2184 _gtk_marshal_BOOLEAN__BOXEDv);
2187 * GtkWidget::key-release-event:
2188 * @widget: the object which received the signal
2189 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2191 * The ::key-release-event signal is emitted when a key is released.
2193 * To receive this signal, the #GdkWindow associated to the widget needs
2194 * to enable the #GDK_KEY_RELEASE_MASK mask.
2196 * This signal will be sent to the grab widget if there is one.
2198 * Returns: %TRUE to stop other handlers from being invoked for the event.
2199 * %FALSE to propagate the event further.
2201 widget_signals[KEY_RELEASE_EVENT] =
2202 g_signal_new (I_("key-release-event"),
2203 G_TYPE_FROM_CLASS (klass),
2205 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2206 _gtk_boolean_handled_accumulator, NULL,
2207 _gtk_marshal_BOOLEAN__BOXED,
2209 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2210 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2211 _gtk_marshal_BOOLEAN__BOXEDv);
2214 * GtkWidget::enter-notify-event:
2215 * @widget: the object which received the signal
2216 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2219 * The ::enter-notify-event will be emitted when the pointer enters
2220 * the @widget's window.
2222 * To receive this signal, the #GdkWindow associated to the widget needs
2223 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2225 * This signal will be sent to the grab widget if there is one.
2227 * Returns: %TRUE to stop other handlers from being invoked for the event.
2228 * %FALSE to propagate the event further.
2230 widget_signals[ENTER_NOTIFY_EVENT] =
2231 g_signal_new (I_("enter-notify-event"),
2232 G_TYPE_FROM_CLASS (klass),
2234 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2235 _gtk_boolean_handled_accumulator, NULL,
2236 _gtk_marshal_BOOLEAN__BOXED,
2238 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2239 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2240 _gtk_marshal_BOOLEAN__BOXEDv);
2243 * GtkWidget::leave-notify-event:
2244 * @widget: the object which received the signal
2245 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2248 * The ::leave-notify-event will be emitted when the pointer leaves
2249 * the @widget's window.
2251 * To receive this signal, the #GdkWindow associated to the widget needs
2252 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2254 * This signal will be sent to the grab widget if there is one.
2256 * Returns: %TRUE to stop other handlers from being invoked for the event.
2257 * %FALSE to propagate the event further.
2259 widget_signals[LEAVE_NOTIFY_EVENT] =
2260 g_signal_new (I_("leave-notify-event"),
2261 G_TYPE_FROM_CLASS (klass),
2263 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2264 _gtk_boolean_handled_accumulator, NULL,
2265 _gtk_marshal_BOOLEAN__BOXED,
2267 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2268 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2269 _gtk_marshal_BOOLEAN__BOXEDv);
2272 * GtkWidget::configure-event:
2273 * @widget: the object which received the signal
2274 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2277 * The ::configure-event signal will be emitted when the size, position or
2278 * stacking of the @widget's window has changed.
2280 * To receive this signal, the #GdkWindow associated to the widget needs
2281 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2282 * automatically for all new windows.
2284 * Returns: %TRUE to stop other handlers from being invoked for the event.
2285 * %FALSE to propagate the event further.
2287 widget_signals[CONFIGURE_EVENT] =
2288 g_signal_new (I_("configure-event"),
2289 G_TYPE_FROM_CLASS (klass),
2291 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2292 _gtk_boolean_handled_accumulator, NULL,
2293 _gtk_marshal_BOOLEAN__BOXED,
2295 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2296 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2297 _gtk_marshal_BOOLEAN__BOXEDv);
2300 * GtkWidget::focus-in-event:
2301 * @widget: the object which received the signal
2302 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2305 * The ::focus-in-event signal will be emitted when the keyboard focus
2306 * enters the @widget's window.
2308 * To receive this signal, the #GdkWindow associated to the widget needs
2309 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2311 * Returns: %TRUE to stop other handlers from being invoked for the event.
2312 * %FALSE to propagate the event further.
2314 widget_signals[FOCUS_IN_EVENT] =
2315 g_signal_new (I_("focus-in-event"),
2316 G_TYPE_FROM_CLASS (klass),
2318 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2319 _gtk_boolean_handled_accumulator, NULL,
2320 _gtk_marshal_BOOLEAN__BOXED,
2322 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2323 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2324 _gtk_marshal_BOOLEAN__BOXEDv);
2327 * GtkWidget::focus-out-event:
2328 * @widget: the object which received the signal
2329 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2332 * The ::focus-out-event signal will be emitted when the keyboard focus
2333 * leaves the @widget's window.
2335 * To receive this signal, the #GdkWindow associated to the widget needs
2336 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2338 * Returns: %TRUE to stop other handlers from being invoked for the event.
2339 * %FALSE to propagate the event further.
2341 widget_signals[FOCUS_OUT_EVENT] =
2342 g_signal_new (I_("focus-out-event"),
2343 G_TYPE_FROM_CLASS (klass),
2345 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2346 _gtk_boolean_handled_accumulator, NULL,
2347 _gtk_marshal_BOOLEAN__BOXED,
2349 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2350 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2351 _gtk_marshal_BOOLEAN__BOXEDv);
2354 * GtkWidget::map-event:
2355 * @widget: the object which received the signal
2356 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2358 * The ::map-event signal will be emitted when the @widget's window is
2359 * mapped. A window is mapped when it becomes visible on the screen.
2361 * To receive this signal, the #GdkWindow associated to the widget needs
2362 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2363 * automatically for all new windows.
2365 * Returns: %TRUE to stop other handlers from being invoked for the event.
2366 * %FALSE to propagate the event further.
2368 widget_signals[MAP_EVENT] =
2369 g_signal_new (I_("map-event"),
2370 G_TYPE_FROM_CLASS (klass),
2372 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2373 _gtk_boolean_handled_accumulator, NULL,
2374 _gtk_marshal_BOOLEAN__BOXED,
2376 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2377 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2378 _gtk_marshal_BOOLEAN__BOXEDv);
2381 * GtkWidget::unmap-event:
2382 * @widget: the object which received the signal
2383 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2385 * The ::unmap-event signal will be emitted when the @widget's window is
2386 * unmapped. A window is unmapped when it becomes invisible on the screen.
2388 * To receive this signal, the #GdkWindow associated to the widget needs
2389 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2390 * automatically for all new windows.
2392 * Returns: %TRUE to stop other handlers from being invoked for the event.
2393 * %FALSE to propagate the event further.
2395 widget_signals[UNMAP_EVENT] =
2396 g_signal_new (I_("unmap-event"),
2397 G_TYPE_FROM_CLASS (klass),
2399 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2400 _gtk_boolean_handled_accumulator, NULL,
2401 _gtk_marshal_BOOLEAN__BOXED,
2403 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2404 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2405 _gtk_marshal_BOOLEAN__BOXEDv);
2408 * GtkWidget::property-notify-event:
2409 * @widget: the object which received the signal
2410 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2413 * The ::property-notify-event signal will be emitted when a property on
2414 * the @widget's window has been changed or deleted.
2416 * To receive this signal, the #GdkWindow associated to the widget needs
2417 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2419 * Returns: %TRUE to stop other handlers from being invoked for the event.
2420 * %FALSE to propagate the event further.
2422 widget_signals[PROPERTY_NOTIFY_EVENT] =
2423 g_signal_new (I_("property-notify-event"),
2424 G_TYPE_FROM_CLASS (klass),
2426 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2427 _gtk_boolean_handled_accumulator, NULL,
2428 _gtk_marshal_BOOLEAN__BOXED,
2430 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2431 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2432 _gtk_marshal_BOOLEAN__BOXEDv);
2435 * GtkWidget::selection-clear-event:
2436 * @widget: the object which received the signal
2437 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2440 * The ::selection-clear-event signal will be emitted when the
2441 * the @widget's window has lost ownership of a selection.
2443 * Returns: %TRUE to stop other handlers from being invoked for the event.
2444 * %FALSE to propagate the event further.
2446 widget_signals[SELECTION_CLEAR_EVENT] =
2447 g_signal_new (I_("selection-clear-event"),
2448 G_TYPE_FROM_CLASS (klass),
2450 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2451 _gtk_boolean_handled_accumulator, NULL,
2452 _gtk_marshal_BOOLEAN__BOXED,
2454 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2455 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2456 _gtk_marshal_BOOLEAN__BOXEDv);
2459 * GtkWidget::selection-request-event:
2460 * @widget: the object which received the signal
2461 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2464 * The ::selection-request-event signal will be emitted when
2465 * another client requests ownership of the selection owned by
2466 * the @widget's window.
2468 * Returns: %TRUE to stop other handlers from being invoked for the event.
2469 * %FALSE to propagate the event further.
2471 widget_signals[SELECTION_REQUEST_EVENT] =
2472 g_signal_new (I_("selection-request-event"),
2473 G_TYPE_FROM_CLASS (klass),
2475 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2476 _gtk_boolean_handled_accumulator, NULL,
2477 _gtk_marshal_BOOLEAN__BOXED,
2479 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2480 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2481 _gtk_marshal_BOOLEAN__BOXEDv);
2484 * GtkWidget::selection-notify-event:
2485 * @widget: the object which received the signal.
2486 * @event: (type Gdk.EventSelection):
2488 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2490 widget_signals[SELECTION_NOTIFY_EVENT] =
2491 g_signal_new (I_("selection-notify-event"),
2492 G_TYPE_FROM_CLASS (klass),
2494 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2495 _gtk_boolean_handled_accumulator, NULL,
2496 _gtk_marshal_BOOLEAN__BOXED,
2498 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2499 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2500 _gtk_marshal_BOOLEAN__BOXEDv);
2503 * GtkWidget::selection-received:
2504 * @widget: the object which received the signal.
2508 widget_signals[SELECTION_RECEIVED] =
2509 g_signal_new (I_("selection-received"),
2510 G_TYPE_FROM_CLASS (klass),
2512 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2514 _gtk_marshal_VOID__BOXED_UINT,
2516 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2520 * GtkWidget::selection-get:
2521 * @widget: the object which received the signal.
2526 widget_signals[SELECTION_GET] =
2527 g_signal_new (I_("selection-get"),
2528 G_TYPE_FROM_CLASS (klass),
2530 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2532 _gtk_marshal_VOID__BOXED_UINT_UINT,
2534 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2539 * GtkWidget::proximity-in-event:
2540 * @widget: the object which received the signal
2541 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2544 * To receive this signal the #GdkWindow associated to the widget needs
2545 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2547 * This signal will be sent to the grab widget if there is one.
2549 * Returns: %TRUE to stop other handlers from being invoked for the event.
2550 * %FALSE to propagate the event further.
2552 widget_signals[PROXIMITY_IN_EVENT] =
2553 g_signal_new (I_("proximity-in-event"),
2554 G_TYPE_FROM_CLASS (klass),
2556 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2557 _gtk_boolean_handled_accumulator, NULL,
2558 _gtk_marshal_BOOLEAN__BOXED,
2560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2561 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2562 _gtk_marshal_BOOLEAN__BOXEDv);
2565 * GtkWidget::proximity-out-event:
2566 * @widget: the object which received the signal
2567 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2570 * To receive this signal the #GdkWindow associated to the widget needs
2571 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2573 * This signal will be sent to the grab widget if there is one.
2575 * Returns: %TRUE to stop other handlers from being invoked for the event.
2576 * %FALSE to propagate the event further.
2578 widget_signals[PROXIMITY_OUT_EVENT] =
2579 g_signal_new (I_("proximity-out-event"),
2580 G_TYPE_FROM_CLASS (klass),
2582 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2583 _gtk_boolean_handled_accumulator, NULL,
2584 _gtk_marshal_BOOLEAN__BOXED,
2586 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2587 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2588 _gtk_marshal_BOOLEAN__BOXEDv);
2591 * GtkWidget::drag-leave:
2592 * @widget: the object which received the signal.
2593 * @context: the drag context
2594 * @time: the timestamp of the motion event
2596 * The ::drag-leave signal is emitted on the drop site when the cursor
2597 * leaves the widget. A typical reason to connect to this signal is to
2598 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2599 * with gtk_drag_unhighlight()
2601 widget_signals[DRAG_LEAVE] =
2602 g_signal_new (I_("drag-leave"),
2603 G_TYPE_FROM_CLASS (klass),
2605 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2607 _gtk_marshal_VOID__OBJECT_UINT,
2609 GDK_TYPE_DRAG_CONTEXT,
2613 * GtkWidget::drag-begin:
2614 * @widget: the object which received the signal
2615 * @context: the drag context
2617 * The ::drag-begin signal is emitted on the drag source when a drag is
2618 * started. A typical reason to connect to this signal is to set up a
2619 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2621 * Note that some widgets set up a drag icon in the default handler of
2622 * this signal, so you may have to use g_signal_connect_after() to
2623 * override what the default handler did.
2625 widget_signals[DRAG_BEGIN] =
2626 g_signal_new (I_("drag-begin"),
2627 G_TYPE_FROM_CLASS (klass),
2629 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2631 _gtk_marshal_VOID__OBJECT,
2633 GDK_TYPE_DRAG_CONTEXT);
2636 * GtkWidget::drag-end:
2637 * @widget: the object which received the signal
2638 * @context: the drag context
2640 * The ::drag-end signal is emitted on the drag source when a drag is
2641 * finished. A typical reason to connect to this signal is to undo
2642 * things done in #GtkWidget::drag-begin.
2644 widget_signals[DRAG_END] =
2645 g_signal_new (I_("drag-end"),
2646 G_TYPE_FROM_CLASS (klass),
2648 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2650 _gtk_marshal_VOID__OBJECT,
2652 GDK_TYPE_DRAG_CONTEXT);
2655 * GtkWidget::drag-data-delete:
2656 * @widget: the object which received the signal
2657 * @context: the drag context
2659 * The ::drag-data-delete signal is emitted on the drag source when a drag
2660 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2661 * handler is responsible for deleting the data that has been dropped. What
2662 * "delete" means depends on the context of the drag operation.
2664 widget_signals[DRAG_DATA_DELETE] =
2665 g_signal_new (I_("drag-data-delete"),
2666 G_TYPE_FROM_CLASS (klass),
2668 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2670 _gtk_marshal_VOID__OBJECT,
2672 GDK_TYPE_DRAG_CONTEXT);
2675 * GtkWidget::drag-failed:
2676 * @widget: the object which received the signal
2677 * @context: the drag context
2678 * @result: the result of the drag operation
2680 * The ::drag-failed signal is emitted on the drag source when a drag has
2681 * failed. The signal handler may hook custom code to handle a failed DND
2682 * operation based on the type of error, it returns %TRUE is the failure has
2683 * been already handled (not showing the default "drag operation failed"
2684 * animation), otherwise it returns %FALSE.
2686 * Return value: %TRUE if the failed drag operation has been already handled.
2690 widget_signals[DRAG_FAILED] =
2691 g_signal_new (I_("drag-failed"),
2692 G_TYPE_FROM_CLASS (klass),
2694 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2695 _gtk_boolean_handled_accumulator, NULL,
2696 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2698 GDK_TYPE_DRAG_CONTEXT,
2699 GTK_TYPE_DRAG_RESULT);
2702 * GtkWidget::drag-motion:
2703 * @widget: the object which received the signal
2704 * @context: the drag context
2705 * @x: the x coordinate of the current cursor position
2706 * @y: the y coordinate of the current cursor position
2707 * @time: the timestamp of the motion event
2709 * The ::drag-motion signal is emitted on the drop site when the user
2710 * moves the cursor over the widget during a drag. The signal handler
2711 * must determine whether the cursor position is in a drop zone or not.
2712 * If it is not in a drop zone, it returns %FALSE and no further processing
2713 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2714 * handler is responsible for providing the necessary information for
2715 * displaying feedback to the user, by calling gdk_drag_status().
2717 * If the decision whether the drop will be accepted or rejected can't be
2718 * made based solely on the cursor position and the type of the data, the
2719 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2720 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2721 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2722 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2723 * when using the drag-motion signal that way.
2725 * Also note that there is no drag-enter signal. The drag receiver has to
2726 * keep track of whether he has received any drag-motion signals since the
2727 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2728 * an "enter" signal. Upon an "enter", the handler will typically highlight
2729 * the drop site with gtk_drag_highlight().
2732 * drag_motion (GtkWidget *widget,
2733 * GdkDragContext *context,
2740 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2742 * if (!private_data->drag_highlight)
2744 * private_data->drag_highlight = 1;
2745 * gtk_drag_highlight (widget);
2748 * target = gtk_drag_dest_find_target (widget, context, NULL);
2749 * if (target == GDK_NONE)
2750 * gdk_drag_status (context, 0, time);
2753 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2754 * gtk_drag_get_data (widget, context, target, time);
2761 * drag_data_received (GtkWidget *widget,
2762 * GdkDragContext *context,
2765 * GtkSelectionData *selection_data,
2769 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2771 * if (private_data->suggested_action)
2773 * private_data->suggested_action = 0;
2775 * /* We are getting this data due to a request in drag_motion,
2776 * * rather than due to a request in drag_drop, so we are just
2777 * * supposed to call gdk_drag_status(), not actually paste in
2780 * str = gtk_selection_data_get_text (selection_data);
2781 * if (!data_is_acceptable (str))
2782 * gdk_drag_status (context, 0, time);
2784 * gdk_drag_status (context, private_data->suggested_action, time);
2788 * /* accept the drop */
2793 * Returns: whether the cursor position is in a drop zone
2795 widget_signals[DRAG_MOTION] =
2796 g_signal_new (I_("drag-motion"),
2797 G_TYPE_FROM_CLASS (klass),
2799 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2800 _gtk_boolean_handled_accumulator, NULL,
2801 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2803 GDK_TYPE_DRAG_CONTEXT,
2809 * GtkWidget::drag-drop:
2810 * @widget: the object which received the signal
2811 * @context: the drag context
2812 * @x: the x coordinate of the current cursor position
2813 * @y: the y coordinate of the current cursor position
2814 * @time: the timestamp of the motion event
2816 * The ::drag-drop signal is emitted on the drop site when the user drops
2817 * the data onto the widget. The signal handler must determine whether
2818 * the cursor position is in a drop zone or not. If it is not in a drop
2819 * zone, it returns %FALSE and no further processing is necessary.
2820 * Otherwise, the handler returns %TRUE. In this case, the handler must
2821 * ensure that gtk_drag_finish() is called to let the source know that
2822 * the drop is done. The call to gtk_drag_finish() can be done either
2823 * directly or in a #GtkWidget::drag-data-received handler which gets
2824 * triggered by calling gtk_drag_get_data() to receive the data for one
2825 * or more of the supported targets.
2827 * Returns: whether the cursor position is in a drop zone
2829 widget_signals[DRAG_DROP] =
2830 g_signal_new (I_("drag-drop"),
2831 G_TYPE_FROM_CLASS (klass),
2833 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2834 _gtk_boolean_handled_accumulator, NULL,
2835 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2837 GDK_TYPE_DRAG_CONTEXT,
2843 * GtkWidget::drag-data-get:
2844 * @widget: the object which received the signal
2845 * @context: the drag context
2846 * @data: the #GtkSelectionData to be filled with the dragged data
2847 * @info: the info that has been registered with the target in the
2849 * @time: the timestamp at which the data was requested
2851 * The ::drag-data-get signal is emitted on the drag source when the drop
2852 * site requests the data which is dragged. It is the responsibility of
2853 * the signal handler to fill @data with the data in the format which
2854 * is indicated by @info. See gtk_selection_data_set() and
2855 * gtk_selection_data_set_text().
2857 widget_signals[DRAG_DATA_GET] =
2858 g_signal_new (I_("drag-data-get"),
2859 G_TYPE_FROM_CLASS (klass),
2861 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2863 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2865 GDK_TYPE_DRAG_CONTEXT,
2866 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2871 * GtkWidget::drag-data-received:
2872 * @widget: the object which received the signal
2873 * @context: the drag context
2874 * @x: where the drop happened
2875 * @y: where the drop happened
2876 * @data: the received data
2877 * @info: the info that has been registered with the target in the
2879 * @time: the timestamp at which the data was received
2881 * The ::drag-data-received signal is emitted on the drop site when the
2882 * dragged data has been received. If the data was received in order to
2883 * determine whether the drop will be accepted, the handler is expected
2884 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2885 * If the data was received in response to a #GtkWidget::drag-drop signal
2886 * (and this is the last target to be received), the handler for this
2887 * signal is expected to process the received data and then call
2888 * gtk_drag_finish(), setting the @success parameter depending on
2889 * whether the data was processed successfully.
2891 * The handler may inspect the selected action with
2892 * gdk_drag_context_get_selected_action() before calling
2893 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2894 * shown in the following example:
2897 * drag_data_received (GtkWidget *widget,
2898 * GdkDragContext *context,
2901 * GtkSelectionData *data,
2905 * if ((data->length >= 0) && (data->format == 8))
2907 * GdkDragAction action;
2909 * /* handle data here */
2911 * action = gdk_drag_context_get_selected_action (context);
2912 * if (action == GDK_ACTION_ASK)
2914 * GtkWidget *dialog;
2917 * dialog = gtk_message_dialog_new (NULL,
2918 * GTK_DIALOG_MODAL |
2919 * GTK_DIALOG_DESTROY_WITH_PARENT,
2921 * GTK_BUTTONS_YES_NO,
2922 * "Move the data ?\n");
2923 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2924 * gtk_widget_destroy (dialog);
2926 * if (response == GTK_RESPONSE_YES)
2927 * action = GDK_ACTION_MOVE;
2929 * action = GDK_ACTION_COPY;
2932 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2935 * gtk_drag_finish (context, FALSE, FALSE, time);
2939 widget_signals[DRAG_DATA_RECEIVED] =
2940 g_signal_new (I_("drag-data-received"),
2941 G_TYPE_FROM_CLASS (klass),
2943 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2945 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2947 GDK_TYPE_DRAG_CONTEXT,
2950 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2955 * GtkWidget::visibility-notify-event:
2956 * @widget: the object which received the signal
2957 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2958 * triggered this signal.
2960 * The ::visibility-notify-event will be emitted when the @widget's window
2961 * is obscured or unobscured.
2963 * To receive this signal the #GdkWindow associated to the widget needs
2964 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2966 * Returns: %TRUE to stop other handlers from being invoked for the event.
2967 * %FALSE to propagate the event further.
2969 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2970 g_signal_new (I_("visibility-notify-event"),
2971 G_TYPE_FROM_CLASS (klass),
2973 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2974 _gtk_boolean_handled_accumulator, NULL,
2975 _gtk_marshal_BOOLEAN__BOXED,
2977 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2980 * GtkWidget::window-state-event:
2981 * @widget: the object which received the signal
2982 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2983 * triggered this signal.
2985 * The ::window-state-event will be emitted when the state of the
2986 * toplevel window associated to the @widget changes.
2988 * To receive this signal the #GdkWindow associated to the widget
2989 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2990 * this mask automatically for all new windows.
2992 * Returns: %TRUE to stop other handlers from being invoked for the
2993 * event. %FALSE to propagate the event further.
2995 widget_signals[WINDOW_STATE_EVENT] =
2996 g_signal_new (I_("window-state-event"),
2997 G_TYPE_FROM_CLASS (klass),
2999 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
3000 _gtk_boolean_handled_accumulator, NULL,
3001 _gtk_marshal_BOOLEAN__BOXED,
3003 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3004 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3005 _gtk_marshal_BOOLEAN__BOXEDv);
3008 * GtkWidget::damage-event:
3009 * @widget: the object which received the signal
3010 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3012 * Emitted when a redirected window belonging to @widget gets drawn into.
3013 * The region/area members of the event shows what area of the redirected
3014 * drawable was drawn into.
3016 * Returns: %TRUE to stop other handlers from being invoked for the event.
3017 * %FALSE to propagate the event further.
3021 widget_signals[DAMAGE_EVENT] =
3022 g_signal_new (I_("damage-event"),
3023 G_TYPE_FROM_CLASS (klass),
3025 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3026 _gtk_boolean_handled_accumulator, NULL,
3027 _gtk_marshal_BOOLEAN__BOXED,
3029 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3030 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3031 _gtk_marshal_BOOLEAN__BOXEDv);
3034 * GtkWidget::grab-broken-event:
3035 * @widget: the object which received the signal
3036 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3038 * Emitted when a pointer or keyboard grab on a window belonging
3039 * to @widget gets broken.
3041 * On X11, this happens when the grab window becomes unviewable
3042 * (i.e. it or one of its ancestors is unmapped), or if the same
3043 * application grabs the pointer or keyboard again.
3045 * Returns: %TRUE to stop other handlers from being invoked for
3046 * the event. %FALSE to propagate the event further.
3050 widget_signals[GRAB_BROKEN_EVENT] =
3051 g_signal_new (I_("grab-broken-event"),
3052 G_TYPE_FROM_CLASS (klass),
3054 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3055 _gtk_boolean_handled_accumulator, NULL,
3056 _gtk_marshal_BOOLEAN__BOXED,
3058 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3059 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3060 _gtk_marshal_BOOLEAN__BOXEDv);
3063 * GtkWidget::query-tooltip:
3064 * @widget: the object which received the signal
3065 * @x: the x coordinate of the cursor position where the request has
3066 * been emitted, relative to @widget's left side
3067 * @y: the y coordinate of the cursor position where the request has
3068 * been emitted, relative to @widget's top
3069 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3070 * @tooltip: a #GtkTooltip
3072 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3073 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3074 * focus in keyboard mode.
3076 * Using the given coordinates, the signal handler should determine
3077 * whether a tooltip should be shown for @widget. If this is the case
3078 * %TRUE should be returned, %FALSE otherwise. Note that if
3079 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3080 * should not be used.
3082 * The signal handler is free to manipulate @tooltip with the therefore
3083 * destined function calls.
3085 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3089 widget_signals[QUERY_TOOLTIP] =
3090 g_signal_new (I_("query-tooltip"),
3091 G_TYPE_FROM_CLASS (klass),
3093 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3094 _gtk_boolean_handled_accumulator, NULL,
3095 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3103 * GtkWidget::popup-menu:
3104 * @widget: the object which received the signal
3106 * This signal gets emitted whenever a widget should pop up a context
3107 * menu. This usually happens through the standard key binding mechanism;
3108 * by pressing a certain key while a widget is focused, the user can cause
3109 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3110 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3111 * for an example of how to use this signal.
3113 * Returns: %TRUE if a menu was activated
3115 widget_signals[POPUP_MENU] =
3116 g_signal_new (I_("popup-menu"),
3117 G_TYPE_FROM_CLASS (klass),
3118 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3119 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3120 _gtk_boolean_handled_accumulator, NULL,
3121 _gtk_marshal_BOOLEAN__VOID,
3125 * GtkWidget::show-help:
3126 * @widget: the object which received the signal.
3129 * Returns: %TRUE to stop other handlers from being invoked for the event.
3130 * %FALSE to propagate the event further.
3132 widget_signals[SHOW_HELP] =
3133 g_signal_new (I_("show-help"),
3134 G_TYPE_FROM_CLASS (klass),
3135 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3136 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3137 _gtk_boolean_handled_accumulator, NULL,
3138 _gtk_marshal_BOOLEAN__ENUM,
3140 GTK_TYPE_WIDGET_HELP_TYPE);
3143 * GtkWidget::accel-closures-changed:
3144 * @widget: the object which received the signal.
3146 widget_signals[ACCEL_CLOSURES_CHANGED] =
3147 g_signal_new (I_("accel-closures-changed"),
3148 G_TYPE_FROM_CLASS (klass),
3152 _gtk_marshal_VOID__VOID,
3156 * GtkWidget::screen-changed:
3157 * @widget: the object on which the signal is emitted
3158 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3159 * widget was not associated with a screen before
3161 * The ::screen-changed signal gets emitted when the
3162 * screen of a widget has changed.
3164 widget_signals[SCREEN_CHANGED] =
3165 g_signal_new (I_("screen-changed"),
3166 G_TYPE_FROM_CLASS (klass),
3168 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3170 _gtk_marshal_VOID__OBJECT,
3175 * GtkWidget::can-activate-accel:
3176 * @widget: the object which received the signal
3177 * @signal_id: the ID of a signal installed on @widget
3179 * Determines whether an accelerator that activates the signal
3180 * identified by @signal_id can currently be activated.
3181 * This signal is present to allow applications and derived
3182 * widgets to override the default #GtkWidget handling
3183 * for determining whether an accelerator can be activated.
3185 * Returns: %TRUE if the signal can be activated.
3187 widget_signals[CAN_ACTIVATE_ACCEL] =
3188 g_signal_new (I_("can-activate-accel"),
3189 G_TYPE_FROM_CLASS (klass),
3191 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3192 _gtk_boolean_handled_accumulator, NULL,
3193 _gtk_marshal_BOOLEAN__UINT,
3194 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3196 binding_set = gtk_binding_set_by_class (klass);
3197 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3199 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3202 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3204 GTK_TYPE_WIDGET_HELP_TYPE,
3205 GTK_WIDGET_HELP_TOOLTIP);
3206 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3208 GTK_TYPE_WIDGET_HELP_TYPE,
3209 GTK_WIDGET_HELP_TOOLTIP);
3210 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3212 GTK_TYPE_WIDGET_HELP_TYPE,
3213 GTK_WIDGET_HELP_WHATS_THIS);
3214 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3216 GTK_TYPE_WIDGET_HELP_TYPE,
3217 GTK_WIDGET_HELP_WHATS_THIS);
3219 gtk_widget_class_install_style_property (klass,
3220 g_param_spec_boolean ("interior-focus",
3221 P_("Interior Focus"),
3222 P_("Whether to draw the focus indicator inside widgets"),
3224 GTK_PARAM_READABLE));
3226 gtk_widget_class_install_style_property (klass,
3227 g_param_spec_int ("focus-line-width",
3228 P_("Focus linewidth"),
3229 P_("Width, in pixels, of the focus indicator line"),
3231 GTK_PARAM_READABLE));
3233 gtk_widget_class_install_style_property (klass,
3234 g_param_spec_string ("focus-line-pattern",
3235 P_("Focus line dash pattern"),
3236 P_("Dash pattern used to draw the focus indicator"),
3238 GTK_PARAM_READABLE));
3239 gtk_widget_class_install_style_property (klass,
3240 g_param_spec_int ("focus-padding",
3241 P_("Focus padding"),
3242 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3244 GTK_PARAM_READABLE));
3245 gtk_widget_class_install_style_property (klass,
3246 g_param_spec_boxed ("cursor-color",
3248 P_("Color with which to draw insertion cursor"),
3250 GTK_PARAM_READABLE));
3251 gtk_widget_class_install_style_property (klass,
3252 g_param_spec_boxed ("secondary-cursor-color",
3253 P_("Secondary cursor color"),
3254 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3256 GTK_PARAM_READABLE));
3257 gtk_widget_class_install_style_property (klass,
3258 g_param_spec_float ("cursor-aspect-ratio",
3259 P_("Cursor line aspect ratio"),
3260 P_("Aspect ratio with which to draw insertion cursor"),
3262 GTK_PARAM_READABLE));
3264 gtk_widget_class_install_style_property (klass,
3265 g_param_spec_boolean ("window-dragging",
3266 P_("Window dragging"),
3267 P_("Whether windows can be dragged by clicking on empty areas"),
3269 GTK_PARAM_READABLE));
3272 * GtkWidget:link-color:
3274 * The "link-color" style property defines the color of unvisited links.
3278 gtk_widget_class_install_style_property (klass,
3279 g_param_spec_boxed ("link-color",
3280 P_("Unvisited Link Color"),
3281 P_("Color of unvisited links"),
3283 GTK_PARAM_READABLE));
3286 * GtkWidget:visited-link-color:
3288 * The "visited-link-color" style property defines the color of visited links.
3292 gtk_widget_class_install_style_property (klass,
3293 g_param_spec_boxed ("visited-link-color",
3294 P_("Visited Link Color"),
3295 P_("Color of visited links"),
3297 GTK_PARAM_READABLE));
3300 * GtkWidget:wide-separators:
3302 * The "wide-separators" style property defines whether separators have
3303 * configurable width and should be drawn using a box instead of a line.
3307 gtk_widget_class_install_style_property (klass,
3308 g_param_spec_boolean ("wide-separators",
3309 P_("Wide Separators"),
3310 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3312 GTK_PARAM_READABLE));
3315 * GtkWidget:separator-width:
3317 * The "separator-width" style property defines the width of separators.
3318 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3322 gtk_widget_class_install_style_property (klass,
3323 g_param_spec_int ("separator-width",
3324 P_("Separator Width"),
3325 P_("The width of separators if wide-separators is TRUE"),
3327 GTK_PARAM_READABLE));
3330 * GtkWidget:separator-height:
3332 * The "separator-height" style property defines the height of separators.
3333 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3337 gtk_widget_class_install_style_property (klass,
3338 g_param_spec_int ("separator-height",
3339 P_("Separator Height"),
3340 P_("The height of separators if \"wide-separators\" is TRUE"),
3342 GTK_PARAM_READABLE));
3345 * GtkWidget:scroll-arrow-hlength:
3347 * The "scroll-arrow-hlength" style property defines the length of
3348 * horizontal scroll arrows.
3352 gtk_widget_class_install_style_property (klass,
3353 g_param_spec_int ("scroll-arrow-hlength",
3354 P_("Horizontal Scroll Arrow Length"),
3355 P_("The length of horizontal scroll arrows"),
3357 GTK_PARAM_READABLE));
3360 * GtkWidget:scroll-arrow-vlength:
3362 * The "scroll-arrow-vlength" style property defines the length of
3363 * vertical scroll arrows.
3367 gtk_widget_class_install_style_property (klass,
3368 g_param_spec_int ("scroll-arrow-vlength",
3369 P_("Vertical Scroll Arrow Length"),
3370 P_("The length of vertical scroll arrows"),
3372 GTK_PARAM_READABLE));
3374 gtk_widget_class_install_style_property (klass,
3375 g_param_spec_int ("text-handle-width",
3376 P_("Width of text selection handles"),
3377 P_("Width of text selection handles"),
3379 GTK_PARAM_READABLE));
3380 gtk_widget_class_install_style_property (klass,
3381 g_param_spec_int ("text-handle-height",
3382 P_("Height of text selection handles"),
3383 P_("Height of text selection handles"),
3385 GTK_PARAM_READABLE));
3387 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3389 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3393 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3397 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3398 for (node = list; node; node = node->next)
3400 GParamSpec *pspec = node->data;
3402 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3403 g_param_spec_unref (pspec);
3409 gtk_widget_set_property (GObject *object,
3411 const GValue *value,
3414 GtkWidget *widget = GTK_WIDGET (object);
3419 gchar *tooltip_markup;
3420 const gchar *tooltip_text;
3421 GtkWindow *tooltip_window;
3424 gtk_widget_set_name (widget, g_value_get_string (value));
3427 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3429 case PROP_WIDTH_REQUEST:
3430 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3432 case PROP_HEIGHT_REQUEST:
3433 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3436 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3438 case PROP_SENSITIVE:
3439 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3441 case PROP_APP_PAINTABLE:
3442 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3444 case PROP_CAN_FOCUS:
3445 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3447 case PROP_HAS_FOCUS:
3448 if (g_value_get_boolean (value))
3449 gtk_widget_grab_focus (widget);
3452 if (g_value_get_boolean (value))
3453 gtk_widget_grab_focus (widget);
3455 case PROP_CAN_DEFAULT:
3456 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3458 case PROP_HAS_DEFAULT:
3459 if (g_value_get_boolean (value))
3460 gtk_widget_grab_default (widget);
3462 case PROP_RECEIVES_DEFAULT:
3463 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3466 gtk_widget_set_style (widget, g_value_get_object (value));
3469 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3470 gtk_widget_set_events (widget, g_value_get_flags (value));
3472 case PROP_NO_SHOW_ALL:
3473 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3475 case PROP_HAS_TOOLTIP:
3476 gtk_widget_real_set_has_tooltip (widget,
3477 g_value_get_boolean (value), FALSE);
3479 case PROP_TOOLTIP_MARKUP:
3480 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3481 tooltip_markup = g_value_dup_string (value);
3483 /* Treat an empty string as a NULL string,
3484 * because an empty string would be useless for a tooltip:
3486 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3488 g_free (tooltip_markup);
3489 tooltip_markup = NULL;
3492 g_object_set_qdata_full (object, quark_tooltip_markup,
3493 tooltip_markup, g_free);
3495 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3496 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3497 if (gtk_widget_get_visible (widget))
3498 gtk_widget_queue_tooltip_query (widget);
3500 case PROP_TOOLTIP_TEXT:
3501 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3503 tooltip_text = g_value_get_string (value);
3505 /* Treat an empty string as a NULL string,
3506 * because an empty string would be useless for a tooltip:
3508 if (tooltip_text && (strlen (tooltip_text) == 0))
3509 tooltip_text = NULL;
3511 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3513 g_object_set_qdata_full (object, quark_tooltip_markup,
3514 tooltip_markup, g_free);
3516 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3517 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3518 if (gtk_widget_get_visible (widget))
3519 gtk_widget_queue_tooltip_query (widget);
3521 case PROP_DOUBLE_BUFFERED:
3522 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3525 gtk_widget_set_halign (widget, g_value_get_enum (value));
3528 gtk_widget_set_valign (widget, g_value_get_enum (value));
3530 case PROP_MARGIN_LEFT:
3531 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3533 case PROP_MARGIN_RIGHT:
3534 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3536 case PROP_MARGIN_TOP:
3537 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3539 case PROP_MARGIN_BOTTOM:
3540 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3543 g_object_freeze_notify (G_OBJECT (widget));
3544 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3545 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3546 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3547 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3548 g_object_thaw_notify (G_OBJECT (widget));
3551 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3553 case PROP_HEXPAND_SET:
3554 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3557 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3559 case PROP_VEXPAND_SET:
3560 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3563 g_object_freeze_notify (G_OBJECT (widget));
3564 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3565 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3566 g_object_thaw_notify (G_OBJECT (widget));
3569 gtk_widget_set_opacity (widget, g_value_get_double (value));
3572 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3578 gtk_widget_get_property (GObject *object,
3583 GtkWidget *widget = GTK_WIDGET (object);
3584 GtkWidgetPrivate *priv = widget->priv;
3592 g_value_set_string (value, priv->name);
3594 g_value_set_static_string (value, "");
3597 g_value_set_object (value, priv->parent);
3599 case PROP_WIDTH_REQUEST:
3602 gtk_widget_get_size_request (widget, &w, NULL);
3603 g_value_set_int (value, w);
3606 case PROP_HEIGHT_REQUEST:
3609 gtk_widget_get_size_request (widget, NULL, &h);
3610 g_value_set_int (value, h);
3614 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3616 case PROP_SENSITIVE:
3617 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3619 case PROP_APP_PAINTABLE:
3620 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3622 case PROP_CAN_FOCUS:
3623 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3625 case PROP_HAS_FOCUS:
3626 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3629 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3631 case PROP_CAN_DEFAULT:
3632 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3634 case PROP_HAS_DEFAULT:
3635 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3637 case PROP_RECEIVES_DEFAULT:
3638 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3640 case PROP_COMPOSITE_CHILD:
3641 g_value_set_boolean (value, widget->priv->composite_child);
3644 g_value_set_object (value, gtk_widget_get_style (widget));
3647 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3648 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3650 case PROP_NO_SHOW_ALL:
3651 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3653 case PROP_HAS_TOOLTIP:
3654 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3656 case PROP_TOOLTIP_TEXT:
3658 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3661 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3662 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3664 g_value_take_string (value, text);
3667 case PROP_TOOLTIP_MARKUP:
3668 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3671 g_value_set_object (value, gtk_widget_get_window (widget));
3673 case PROP_DOUBLE_BUFFERED:
3674 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3677 g_value_set_enum (value, gtk_widget_get_halign (widget));
3680 g_value_set_enum (value, gtk_widget_get_valign (widget));
3682 case PROP_MARGIN_LEFT:
3683 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3685 case PROP_MARGIN_RIGHT:
3686 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3688 case PROP_MARGIN_TOP:
3689 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3691 case PROP_MARGIN_BOTTOM:
3692 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3696 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3697 if (aux_info == NULL)
3699 g_value_set_int (value, 0);
3703 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3704 aux_info->margin.right),
3705 MAX (aux_info->margin.top,
3706 aux_info->margin.bottom)));
3711 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3713 case PROP_HEXPAND_SET:
3714 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3717 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3719 case PROP_VEXPAND_SET:
3720 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3723 g_value_set_boolean (value,
3724 gtk_widget_get_hexpand (widget) &&
3725 gtk_widget_get_vexpand (widget));
3728 g_value_set_double (value, gtk_widget_get_opacity (widget));
3731 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3737 gtk_widget_init (GtkWidget *widget)
3739 GtkWidgetPrivate *priv;
3741 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3744 priv = widget->priv;
3746 priv->child_visible = TRUE;
3748 priv->allocation.x = -1;
3749 priv->allocation.y = -1;
3750 priv->allocation.width = 1;
3751 priv->allocation.height = 1;
3752 priv->user_alpha = 255;
3754 priv->window = NULL;
3755 priv->parent = NULL;
3757 priv->sensitive = TRUE;
3758 priv->composite_child = composite_child_stack != 0;
3759 priv->double_buffered = TRUE;
3760 priv->redraw_on_alloc = TRUE;
3761 priv->alloc_needed = TRUE;
3763 switch (gtk_widget_get_direction (widget))
3765 case GTK_TEXT_DIR_LTR:
3766 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3769 case GTK_TEXT_DIR_RTL:
3770 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3773 case GTK_TEXT_DIR_NONE:
3775 g_assert_not_reached ();
3780 /* this will be set to TRUE if the widget gets a child or if the
3781 * expand flag is set on the widget, but until one of those happen
3782 * we know the expand is already properly FALSE.
3784 * We really want to default FALSE here to avoid computing expand
3785 * all over the place while initially building a widget tree.
3787 priv->need_compute_expand = FALSE;
3789 _gtk_size_request_cache_init (&priv->requests);
3791 priv->style = gtk_widget_get_default_style ();
3792 g_object_ref (priv->style);
3797 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3799 GParamSpec **pspecs)
3801 GtkWidgetPrivate *priv = widget->priv;
3802 GtkWidget *container = priv->parent;
3805 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3806 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3810 * gtk_widget_freeze_child_notify:
3811 * @widget: a #GtkWidget
3813 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3814 * signals are queued until gtk_widget_thaw_child_notify() is called
3817 * This is the analogue of g_object_freeze_notify() for child properties.
3820 gtk_widget_freeze_child_notify (GtkWidget *widget)
3822 g_return_if_fail (GTK_IS_WIDGET (widget));
3824 if (!G_OBJECT (widget)->ref_count)
3827 g_object_ref (widget);
3828 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3829 g_object_unref (widget);
3833 * gtk_widget_child_notify:
3834 * @widget: a #GtkWidget
3835 * @child_property: the name of a child property installed on the
3836 * class of @widget<!-- -->'s parent
3838 * Emits a #GtkWidget::child-notify signal for the
3839 * <link linkend="child-properties">child property</link> @child_property
3842 * This is the analogue of g_object_notify() for child properties.
3844 * Also see gtk_container_child_notify().
3847 gtk_widget_child_notify (GtkWidget *widget,
3848 const gchar *child_property)
3850 if (widget->priv->parent == NULL)
3853 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3857 * gtk_widget_thaw_child_notify:
3858 * @widget: a #GtkWidget
3860 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3861 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3865 gtk_widget_thaw_child_notify (GtkWidget *widget)
3867 GObjectNotifyQueue *nqueue;
3869 g_return_if_fail (GTK_IS_WIDGET (widget));
3871 if (!G_OBJECT (widget)->ref_count)
3874 g_object_ref (widget);
3875 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3876 if (!nqueue || !nqueue->freeze_count)
3877 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3878 G_OBJECT_TYPE_NAME (widget), widget);
3880 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3881 g_object_unref (widget);
3887 * @type: type ID of the widget to create
3888 * @first_property_name: name of first property to set
3889 * @...: value of first property, followed by more properties,
3892 * This is a convenience function for creating a widget and setting
3893 * its properties in one go. For example you might write:
3894 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3895 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3896 * g_object_new(), but returns a widget so you don't have to
3897 * cast the object yourself.
3899 * Return value: a new #GtkWidget of type @widget_type
3902 gtk_widget_new (GType type,
3903 const gchar *first_property_name,
3909 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3911 va_start (var_args, first_property_name);
3912 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3919 gtk_widget_queue_draw_child (GtkWidget *widget)
3921 GtkWidgetPrivate *priv = widget->priv;
3924 parent = priv->parent;
3925 if (parent && gtk_widget_is_drawable (parent))
3926 gtk_widget_queue_draw_area (parent,
3929 priv->allocation.width,
3930 priv->allocation.height);
3934 * gtk_widget_unparent:
3935 * @widget: a #GtkWidget
3937 * This function is only for use in widget implementations.
3938 * Should be called by implementations of the remove method
3939 * on #GtkContainer, to dissociate a child from the container.
3942 gtk_widget_unparent (GtkWidget *widget)
3944 GtkWidgetPrivate *priv;
3945 GObjectNotifyQueue *nqueue;
3946 GtkWidget *toplevel;
3947 GtkWidget *old_parent;
3949 g_return_if_fail (GTK_IS_WIDGET (widget));
3951 priv = widget->priv;
3953 if (priv->parent == NULL)
3956 /* keep this function in sync with gtk_menu_detach() */
3958 gtk_widget_push_verify_invariants (widget);
3960 g_object_freeze_notify (G_OBJECT (widget));
3961 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3963 toplevel = gtk_widget_get_toplevel (widget);
3964 if (gtk_widget_is_toplevel (toplevel))
3965 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3967 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3968 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3970 gtk_widget_queue_draw_child (widget);
3972 /* Reset the width and height here, to force reallocation if we
3973 * get added back to a new parent. This won't work if our new
3974 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3975 * (would 0x0 be OK here?)
3977 priv->allocation.width = 1;
3978 priv->allocation.height = 1;
3980 if (gtk_widget_get_realized (widget))
3982 if (priv->in_reparent)
3983 gtk_widget_unmap (widget);
3985 gtk_widget_unrealize (widget);
3988 /* If we are unanchoring the child, we save around the toplevel
3989 * to emit hierarchy changed
3991 if (priv->parent->priv->anchored)
3992 g_object_ref (toplevel);
3996 /* Removing a widget from a container restores the child visible
3997 * flag to the default state, so it doesn't affect the child
3998 * in the next parent.
4000 priv->child_visible = TRUE;
4002 old_parent = priv->parent;
4003 priv->parent = NULL;
4005 /* parent may no longer expand if the removed
4006 * child was expand=TRUE and could therefore
4009 if (gtk_widget_get_visible (widget) &&
4010 (priv->need_compute_expand ||
4011 priv->computed_hexpand ||
4012 priv->computed_vexpand))
4014 gtk_widget_queue_compute_expand (old_parent);
4017 /* Unset BACKDROP since we are no longer inside a toplevel window */
4018 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4020 gtk_style_context_set_parent (priv->context, NULL);
4022 _gtk_widget_update_parent_muxer (widget);
4024 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4027 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4028 g_object_unref (toplevel);
4031 /* Now that the parent pointer is nullified and the hierarchy-changed
4032 * already passed, go ahead and unset the parent window, if we are unparenting
4033 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4034 * will fire again for the new subhierarchy.
4036 gtk_widget_set_parent_window (widget, NULL);
4038 g_object_notify (G_OBJECT (widget), "parent");
4039 g_object_thaw_notify (G_OBJECT (widget));
4041 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4042 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4044 gtk_widget_propagate_alpha (widget);
4046 gtk_widget_pop_verify_invariants (widget);
4047 g_object_unref (widget);
4051 * gtk_widget_destroy:
4052 * @widget: a #GtkWidget
4054 * Destroys a widget.
4057 * destroyed, it will break any references it holds to other objects.
4058 * If the widget is inside a container, the widget will be removed
4059 * from the container. If the widget is a toplevel (derived from
4060 * #GtkWindow), it will be removed from the list of toplevels, and the
4061 * reference GTK+ holds to it will be removed. Removing a
4062 * widget from its container or the list of toplevels results in the
4063 * widget being finalized, unless you've added additional references
4064 * to the widget with g_object_ref().
4066 * In most cases, only toplevel widgets (windows) require explicit
4067 * destruction, because when you destroy a toplevel its children will
4068 * be destroyed as well.
4071 gtk_widget_destroy (GtkWidget *widget)
4073 g_return_if_fail (GTK_IS_WIDGET (widget));
4075 if (!widget->priv->in_destruction)
4076 g_object_run_dispose (G_OBJECT (widget));
4080 * gtk_widget_destroyed:
4081 * @widget: a #GtkWidget
4082 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4084 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4085 * %NULL. It's intended to be used as a callback connected to the
4086 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4087 * as a signal handler, and pass the address of your widget variable
4088 * as user data. Then when the widget is destroyed, the variable will
4089 * be set to %NULL. Useful for example to avoid multiple copies
4090 * of the same dialog.
4093 gtk_widget_destroyed (GtkWidget *widget,
4094 GtkWidget **widget_pointer)
4096 /* Don't make any assumptions about the
4098 * Even check widget_pointer.
4101 *widget_pointer = NULL;
4106 * @widget: a #GtkWidget
4108 * Flags a widget to be displayed. Any widget that isn't shown will
4109 * not appear on the screen. If you want to show all the widgets in a
4110 * container, it's easier to call gtk_widget_show_all() on the
4111 * container, instead of individually showing the widgets.
4113 * Remember that you have to show the containers containing a widget,
4114 * in addition to the widget itself, before it will appear onscreen.
4116 * When a toplevel container is shown, it is immediately realized and
4117 * mapped; other shown widgets are realized and mapped when their
4118 * toplevel container is realized and mapped.
4121 gtk_widget_show (GtkWidget *widget)
4123 g_return_if_fail (GTK_IS_WIDGET (widget));
4125 if (!gtk_widget_get_visible (widget))
4127 g_object_ref (widget);
4128 gtk_widget_push_verify_invariants (widget);
4130 if (!gtk_widget_is_toplevel (widget))
4131 gtk_widget_queue_resize (widget);
4133 /* see comment in set_parent() for why this should and can be
4136 if (widget->priv->need_compute_expand ||
4137 widget->priv->computed_hexpand ||
4138 widget->priv->computed_vexpand)
4140 if (widget->priv->parent != NULL)
4141 gtk_widget_queue_compute_expand (widget->priv->parent);
4144 g_signal_emit (widget, widget_signals[SHOW], 0);
4145 g_object_notify (G_OBJECT (widget), "visible");
4147 gtk_widget_pop_verify_invariants (widget);
4148 g_object_unref (widget);
4153 gtk_widget_real_show (GtkWidget *widget)
4155 GtkWidgetPrivate *priv = widget->priv;
4157 if (!gtk_widget_get_visible (widget))
4159 priv->visible = TRUE;
4162 gtk_widget_get_mapped (priv->parent) &&
4163 gtk_widget_get_child_visible (widget) &&
4164 !gtk_widget_get_mapped (widget))
4165 gtk_widget_map (widget);
4170 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4173 g_signal_handlers_disconnect_by_func (widget,
4174 gtk_widget_show_map_callback,
4179 * gtk_widget_show_now:
4180 * @widget: a #GtkWidget
4182 * Shows a widget. If the widget is an unmapped toplevel widget
4183 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4184 * loop and wait for the window to actually be mapped. Be careful;
4185 * because the main loop is running, anything can happen during
4189 gtk_widget_show_now (GtkWidget *widget)
4193 g_return_if_fail (GTK_IS_WIDGET (widget));
4195 /* make sure we will get event */
4196 if (!gtk_widget_get_mapped (widget) &&
4197 gtk_widget_is_toplevel (widget))
4199 gtk_widget_show (widget);
4201 g_signal_connect (widget, "map-event",
4202 G_CALLBACK (gtk_widget_show_map_callback),
4206 gtk_main_iteration ();
4209 gtk_widget_show (widget);
4214 * @widget: a #GtkWidget
4216 * Reverses the effects of gtk_widget_show(), causing the widget to be
4217 * hidden (invisible to the user).
4220 gtk_widget_hide (GtkWidget *widget)
4222 g_return_if_fail (GTK_IS_WIDGET (widget));
4224 if (gtk_widget_get_visible (widget))
4226 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4228 g_object_ref (widget);
4229 gtk_widget_push_verify_invariants (widget);
4231 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4232 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4234 /* a parent may now be expand=FALSE since we're hidden. */
4235 if (widget->priv->need_compute_expand ||
4236 widget->priv->computed_hexpand ||
4237 widget->priv->computed_vexpand)
4239 gtk_widget_queue_compute_expand (widget);
4242 g_signal_emit (widget, widget_signals[HIDE], 0);
4243 if (!gtk_widget_is_toplevel (widget))
4244 gtk_widget_queue_resize (widget);
4245 g_object_notify (G_OBJECT (widget), "visible");
4247 gtk_widget_pop_verify_invariants (widget);
4248 g_object_unref (widget);
4253 gtk_widget_real_hide (GtkWidget *widget)
4255 if (gtk_widget_get_visible (widget))
4257 widget->priv->visible = FALSE;
4259 if (gtk_widget_get_mapped (widget))
4260 gtk_widget_unmap (widget);
4265 * gtk_widget_hide_on_delete:
4266 * @widget: a #GtkWidget
4268 * Utility function; intended to be connected to the #GtkWidget::delete-event
4269 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4270 * argument, then returns %TRUE. If connected to ::delete-event, the
4271 * result is that clicking the close button for a window (on the
4272 * window frame, top right corner usually) will hide but not destroy
4273 * the window. By default, GTK+ destroys windows when ::delete-event
4276 * Return value: %TRUE
4279 gtk_widget_hide_on_delete (GtkWidget *widget)
4281 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4283 gtk_widget_hide (widget);
4289 * gtk_widget_show_all:
4290 * @widget: a #GtkWidget
4292 * Recursively shows a widget, and any child widgets (if the widget is
4296 gtk_widget_show_all (GtkWidget *widget)
4298 GtkWidgetClass *class;
4300 g_return_if_fail (GTK_IS_WIDGET (widget));
4302 if (gtk_widget_get_no_show_all (widget))
4305 class = GTK_WIDGET_GET_CLASS (widget);
4307 if (class->show_all)
4308 class->show_all (widget);
4313 * @widget: a #GtkWidget
4315 * This function is only for use in widget implementations. Causes
4316 * a widget to be mapped if it isn't already.
4319 gtk_widget_map (GtkWidget *widget)
4321 GtkWidgetPrivate *priv;
4323 g_return_if_fail (GTK_IS_WIDGET (widget));
4324 g_return_if_fail (gtk_widget_get_visible (widget));
4325 g_return_if_fail (gtk_widget_get_child_visible (widget));
4327 priv = widget->priv;
4329 if (!gtk_widget_get_mapped (widget))
4331 gtk_widget_push_verify_invariants (widget);
4333 if (!gtk_widget_get_realized (widget))
4334 gtk_widget_realize (widget);
4336 g_signal_emit (widget, widget_signals[MAP], 0);
4338 if (!gtk_widget_get_has_window (widget))
4339 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4341 if (widget->priv->context)
4342 _gtk_style_context_update_animating (widget->priv->context);
4344 gtk_widget_pop_verify_invariants (widget);
4350 * @widget: a #GtkWidget
4352 * This function is only for use in widget implementations. Causes
4353 * a widget to be unmapped if it's currently mapped.
4356 gtk_widget_unmap (GtkWidget *widget)
4358 GtkWidgetPrivate *priv;
4360 g_return_if_fail (GTK_IS_WIDGET (widget));
4362 priv = widget->priv;
4364 if (gtk_widget_get_mapped (widget))
4366 gtk_widget_push_verify_invariants (widget);
4368 if (!gtk_widget_get_has_window (widget))
4369 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4370 _gtk_tooltip_hide (widget);
4372 if (widget->priv->context)
4373 _gtk_style_context_update_animating (widget->priv->context);
4375 g_signal_emit (widget, widget_signals[UNMAP], 0);
4377 gtk_widget_pop_verify_invariants (widget);
4379 /* Unset pointer/window info */
4380 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4385 _gtk_widget_enable_device_events (GtkWidget *widget)
4387 GHashTable *device_events;
4388 GHashTableIter iter;
4389 gpointer key, value;
4391 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4396 g_hash_table_iter_init (&iter, device_events);
4398 while (g_hash_table_iter_next (&iter, &key, &value))
4401 GdkEventMask event_mask;
4404 event_mask = GPOINTER_TO_UINT (value);
4405 gtk_widget_add_events_internal (widget, device, event_mask);
4410 get_widget_windows (GtkWidget *widget)
4412 GList *window_list, *last, *l, *children, *ret;
4414 if (gtk_widget_get_has_window (widget))
4415 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4417 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4419 last = g_list_last (window_list);
4422 for (l = window_list; l; l = l->next)
4424 GtkWidget *window_widget = NULL;
4426 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4428 if (widget != window_widget)
4431 ret = g_list_prepend (ret, l->data);
4432 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4436 last = g_list_concat (last, children);
4437 last = g_list_last (last);
4441 g_list_free (window_list);
4447 device_enable_foreach (GtkWidget *widget,
4450 GdkDevice *device = user_data;
4451 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4455 device_disable_foreach (GtkWidget *widget,
4458 GdkDevice *device = user_data;
4459 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4463 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4468 GList *window_list, *l;
4470 window_list = get_widget_windows (widget);
4472 for (l = window_list; l; l = l->next)
4474 GdkEventMask events = 0;
4480 events = gdk_window_get_events (window);
4482 gdk_window_set_device_events (window, device, events);
4485 if (recurse && GTK_IS_CONTAINER (widget))
4488 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4490 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4493 g_list_free (window_list);
4497 gtk_widget_update_devices_mask (GtkWidget *widget,
4500 GList *enabled_devices, *l;
4502 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4504 for (l = enabled_devices; l; l = l->next)
4505 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4509 * gtk_widget_realize:
4510 * @widget: a #GtkWidget
4512 * Creates the GDK (windowing system) resources associated with a
4513 * widget. For example, @widget->window will be created when a widget
4514 * is realized. Normally realization happens implicitly; if you show
4515 * a widget and all its parent containers, then the widget will be
4516 * realized and mapped automatically.
4518 * Realizing a widget requires all
4519 * the widget's parent widgets to be realized; calling
4520 * gtk_widget_realize() realizes the widget's parents in addition to
4521 * @widget itself. If a widget is not yet inside a toplevel window
4522 * when you realize it, bad things will happen.
4524 * This function is primarily used in widget implementations, and
4525 * isn't very useful otherwise. Many times when you think you might
4526 * need it, a better approach is to connect to a signal that will be
4527 * called after the widget is realized automatically, such as
4528 * #GtkWidget::draw. Or simply g_signal_connect () to the
4529 * #GtkWidget::realize signal.
4532 gtk_widget_realize (GtkWidget *widget)
4534 GtkWidgetPrivate *priv;
4535 cairo_region_t *region;
4537 g_return_if_fail (GTK_IS_WIDGET (widget));
4538 g_return_if_fail (widget->priv->anchored ||
4539 GTK_IS_INVISIBLE (widget));
4541 priv = widget->priv;
4543 if (!gtk_widget_get_realized (widget))
4545 gtk_widget_push_verify_invariants (widget);
4548 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4549 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4552 if (priv->parent == NULL &&
4553 !gtk_widget_is_toplevel (widget))
4554 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4555 "inside a toplevel window is not going to work very well. "
4556 "Widgets must be inside a toplevel container before realizing them.");
4558 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4559 gtk_widget_realize (priv->parent);
4561 gtk_widget_ensure_style (widget);
4563 if (priv->style_update_pending)
4564 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4566 g_signal_emit (widget, widget_signals[REALIZE], 0);
4568 gtk_widget_real_set_has_tooltip (widget,
4569 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4572 if (priv->has_shape_mask)
4574 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4575 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4578 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4580 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4582 if (priv->multidevice)
4583 gdk_window_set_support_multidevice (priv->window, TRUE);
4585 _gtk_widget_enable_device_events (widget);
4586 gtk_widget_update_devices_mask (widget, TRUE);
4588 gtk_widget_pop_verify_invariants (widget);
4593 * gtk_widget_unrealize:
4594 * @widget: a #GtkWidget
4596 * This function is only useful in widget implementations.
4597 * Causes a widget to be unrealized (frees all GDK resources
4598 * associated with the widget, such as @widget->window).
4601 gtk_widget_unrealize (GtkWidget *widget)
4603 g_return_if_fail (GTK_IS_WIDGET (widget));
4605 gtk_widget_push_verify_invariants (widget);
4607 if (widget->priv->has_shape_mask)
4608 gtk_widget_shape_combine_region (widget, NULL);
4610 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4611 gtk_widget_input_shape_combine_region (widget, NULL);
4613 if (gtk_widget_get_realized (widget))
4615 g_object_ref (widget);
4617 if (widget->priv->mapped)
4618 gtk_widget_unmap (widget);
4620 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4621 g_assert (!widget->priv->mapped);
4622 gtk_widget_set_realized (widget, FALSE);
4624 g_object_unref (widget);
4627 gtk_widget_pop_verify_invariants (widget);
4630 /*****************************************
4632 *****************************************/
4635 * gtk_widget_queue_draw_region:
4636 * @widget: a #GtkWidget
4637 * @region: region to draw
4639 * Invalidates the rectangular area of @widget defined by @region by
4640 * calling gdk_window_invalidate_region() on the widget's window and
4641 * all its child windows. Once the main loop becomes idle (after the
4642 * current batch of events has been processed, roughly), the window
4643 * will receive expose events for the union of all regions that have
4646 * Normally you would only use this function in widget
4647 * implementations. You might also use it to schedule a redraw of a
4648 * #GtkDrawingArea or some portion thereof.
4653 gtk_widget_queue_draw_region (GtkWidget *widget,
4654 const cairo_region_t *region)
4656 GtkWidgetPrivate *priv;
4659 g_return_if_fail (GTK_IS_WIDGET (widget));
4661 priv = widget->priv;
4663 if (!gtk_widget_get_realized (widget))
4666 /* Just return if the widget or one of its ancestors isn't mapped */
4667 for (w = widget; w != NULL; w = w->priv->parent)
4668 if (!gtk_widget_get_mapped (w))
4671 gdk_window_invalidate_region (priv->window, region, TRUE);
4675 * gtk_widget_queue_draw_area:
4676 * @widget: a #GtkWidget
4677 * @x: x coordinate of upper-left corner of rectangle to redraw
4678 * @y: y coordinate of upper-left corner of rectangle to redraw
4679 * @width: width of region to draw
4680 * @height: height of region to draw
4682 * Convenience function that calls gtk_widget_queue_draw_region() on
4683 * the region created from the given coordinates.
4685 * The region here is specified in widget coordinates.
4686 * Widget coordinates are a bit odd; for historical reasons, they are
4687 * defined as @widget->window coordinates for widgets that are not
4688 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4689 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4692 gtk_widget_queue_draw_area (GtkWidget *widget,
4699 cairo_region_t *region;
4701 g_return_if_fail (GTK_IS_WIDGET (widget));
4706 rect.height = height;
4708 region = cairo_region_create_rectangle (&rect);
4709 gtk_widget_queue_draw_region (widget, region);
4710 cairo_region_destroy (region);
4714 * gtk_widget_queue_draw:
4715 * @widget: a #GtkWidget
4717 * Equivalent to calling gtk_widget_queue_draw_area() for the
4718 * entire area of a widget.
4721 gtk_widget_queue_draw (GtkWidget *widget)
4725 g_return_if_fail (GTK_IS_WIDGET (widget));
4727 gtk_widget_get_allocation (widget, &rect);
4729 if (!gtk_widget_get_has_window (widget))
4730 gtk_widget_queue_draw_area (widget,
4731 rect.x, rect.y, rect.width, rect.height);
4733 gtk_widget_queue_draw_area (widget,
4734 0, 0, rect.width, rect.height);
4738 * gtk_widget_queue_resize:
4739 * @widget: a #GtkWidget
4741 * This function is only for use in widget implementations.
4742 * Flags a widget to have its size renegotiated; should
4743 * be called when a widget for some reason has a new size request.
4744 * For example, when you change the text in a #GtkLabel, #GtkLabel
4745 * queues a resize to ensure there's enough space for the new text.
4747 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4748 * from inside its implementation of the GtkWidgetClass::size_allocate
4749 * virtual method. Calls to gtk_widget_queue_resize() from inside
4750 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4753 gtk_widget_queue_resize (GtkWidget *widget)
4755 g_return_if_fail (GTK_IS_WIDGET (widget));
4757 if (gtk_widget_get_realized (widget))
4758 gtk_widget_queue_draw (widget);
4760 _gtk_size_group_queue_resize (widget, 0);
4764 * gtk_widget_queue_resize_no_redraw:
4765 * @widget: a #GtkWidget
4767 * This function works like gtk_widget_queue_resize(),
4768 * except that the widget is not invalidated.
4773 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4775 g_return_if_fail (GTK_IS_WIDGET (widget));
4777 _gtk_size_group_queue_resize (widget, 0);
4781 * gtk_widget_get_frame_clock:
4782 * @widget: a #GtkWidget
4784 * Obtains the frame clock for a widget. The frame clock is a global
4785 * "ticker" that can be used to drive animations and repaints. The
4786 * most common reason to get the frame clock is to call
4787 * gdk_frame_clock_get_frame_time(), in order to get a time to use for
4788 * animating. For example you might record the start of the animation
4789 * with an initial value from gdk_frame_clock_get_frame_time(), and
4790 * then update the animation by calling
4791 * gdk_frame_clock_get_frame_time() again during each repaint.
4793 * gdk_frame_clock_request_frame() will result in a new frame on the
4794 * clock, but won't necessarily repaint any widgets. To repaint a
4795 * widget, you have to use gtk_widget_queue_draw() which invalidates
4796 * the widget (thus scheduling it to receive a draw on the next
4797 * frame). gtk_widget_queue_draw() will also end up requesting a frame
4798 * on the appropriate frame clock.
4800 * A widget's frame clock will not change while the widget is
4801 * mapped. Reparenting a widget (which implies a temporary unmap) can
4802 * change the widget's frame clock.
4804 * Unrealized widgets do not have a frame clock.
4807 * Return value: a #GdkFrameClock (or #NULL if widget is unrealized)
4810 gtk_widget_get_frame_clock (GtkWidget *widget)
4812 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4814 if (widget->priv->realized)
4818 window = gtk_widget_get_window (widget);
4819 g_assert (window != NULL);
4820 return gdk_window_get_frame_clock (window);
4829 * gtk_widget_size_request:
4830 * @widget: a #GtkWidget
4831 * @requisition: (out): a #GtkRequisition to be filled in
4833 * This function is typically used when implementing a #GtkContainer
4834 * subclass. Obtains the preferred size of a widget. The container
4835 * uses this information to arrange its child widgets and decide what
4836 * size allocations to give them with gtk_widget_size_allocate().
4838 * You can also call this function from an application, with some
4839 * caveats. Most notably, getting a size request requires the widget
4840 * to be associated with a screen, because font information may be
4841 * needed. Multihead-aware applications should keep this in mind.
4843 * Also remember that the size request is not necessarily the size
4844 * a widget will actually be allocated.
4846 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4849 gtk_widget_size_request (GtkWidget *widget,
4850 GtkRequisition *requisition)
4852 g_return_if_fail (GTK_IS_WIDGET (widget));
4854 gtk_widget_get_preferred_size (widget, requisition, NULL);
4858 * gtk_widget_get_child_requisition:
4859 * @widget: a #GtkWidget
4860 * @requisition: (out): a #GtkRequisition to be filled in
4862 * This function is only for use in widget implementations. Obtains
4863 * @widget->requisition, unless someone has forced a particular
4864 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4865 * in which case it returns that geometry instead of the widget's
4868 * This function differs from gtk_widget_size_request() in that
4869 * it retrieves the last size request value from @widget->requisition,
4870 * while gtk_widget_size_request() actually calls the "size_request" method
4871 * on @widget to compute the size request and fill in @widget->requisition,
4872 * and only then returns @widget->requisition.
4874 * Because this function does not call the "size_request" method, it
4875 * can only be used when you know that @widget->requisition is
4876 * up-to-date, that is, gtk_widget_size_request() has been called
4877 * since the last time a resize was queued. In general, only container
4878 * implementations have this information; applications should use
4879 * gtk_widget_size_request().
4882 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4885 gtk_widget_get_child_requisition (GtkWidget *widget,
4886 GtkRequisition *requisition)
4888 gtk_widget_get_preferred_size (widget, requisition, NULL);
4892 invalidate_predicate (GdkWindow *window,
4897 gdk_window_get_user_data (window, &user_data);
4899 return (user_data == data);
4902 /* Invalidate @region in widget->window and all children
4903 * of widget->window owned by widget. @region is in the
4904 * same coordinates as widget->allocation and will be
4905 * modified by this call.
4908 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4909 cairo_region_t *region)
4911 GtkWidgetPrivate *priv = widget->priv;
4913 if (!gtk_widget_get_realized (widget))
4916 if (gtk_widget_get_has_window (widget) && priv->parent)
4920 gdk_window_get_position (priv->window, &x, &y);
4921 cairo_region_translate (region, -x, -y);
4924 gdk_window_invalidate_maybe_recurse (priv->window, region,
4925 invalidate_predicate, widget);
4929 * gtk_widget_size_allocate:
4930 * @widget: a #GtkWidget
4931 * @allocation: position and size to be allocated to @widget
4933 * This function is only used by #GtkContainer subclasses, to assign a size
4934 * and position to their child widgets.
4936 * In this function, the allocation may be adjusted. It will be forced
4937 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4938 * method on the child will be used to adjust the allocation. Standard
4939 * adjustments include removing the widget's margins, and applying the
4940 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4943 gtk_widget_size_allocate (GtkWidget *widget,
4944 GtkAllocation *allocation)
4946 GtkWidgetPrivate *priv;
4947 GdkRectangle real_allocation;
4948 GdkRectangle old_allocation;
4949 GdkRectangle adjusted_allocation;
4950 gboolean alloc_needed;
4951 gboolean size_changed;
4952 gboolean position_changed;
4953 gint natural_width, natural_height, dummy;
4954 gint min_width, min_height;
4956 priv = widget->priv;
4958 g_return_if_fail (GTK_IS_WIDGET (widget));
4960 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4963 gtk_widget_push_verify_invariants (widget);
4965 #ifdef G_ENABLE_DEBUG
4966 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4977 parent = gtk_widget_get_parent (parent);
4980 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4981 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4982 2 * depth, " ", name,
4983 allocation->width, allocation->height);
4985 #endif /* G_ENABLE_DEBUG */
4987 alloc_needed = priv->alloc_needed;
4988 /* Preserve request/allocate ordering */
4989 priv->alloc_needed = FALSE;
4991 old_allocation = priv->allocation;
4992 real_allocation = *allocation;
4994 adjusted_allocation = real_allocation;
4995 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4997 /* Go ahead and request the height for allocated width, note that the internals
4998 * of get_height_for_width will internally limit the for_size to natural size
4999 * when aligning implicitly.
5001 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
5002 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
5006 /* Go ahead and request the width for allocated height, note that the internals
5007 * of get_width_for_height will internally limit the for_size to natural size
5008 * when aligning implicitly.
5010 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
5011 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
5014 #ifdef G_ENABLE_DEBUG
5015 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5017 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
5018 !GTK_IS_SCROLLABLE (widget))
5019 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
5020 "Allocation is %dx%d, but minimum required size is %dx%d.",
5021 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
5022 G_OBJECT_TYPE_NAME (widget), widget,
5023 real_allocation.width, real_allocation.height,
5024 min_width, min_height);
5027 /* Now that we have the right natural height and width, go ahead and remove any margins from the
5028 * allocated sizes and possibly limit them to the natural sizes */
5029 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5030 GTK_ORIENTATION_HORIZONTAL,
5033 &adjusted_allocation.x,
5034 &adjusted_allocation.width);
5035 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5036 GTK_ORIENTATION_VERTICAL,
5039 &adjusted_allocation.y,
5040 &adjusted_allocation.height);
5042 if (adjusted_allocation.x < real_allocation.x ||
5043 adjusted_allocation.y < real_allocation.y ||
5044 (adjusted_allocation.x + adjusted_allocation.width) >
5045 (real_allocation.x + real_allocation.width) ||
5046 (adjusted_allocation.y + adjusted_allocation.height >
5047 real_allocation.y + real_allocation.height))
5049 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",
5050 G_OBJECT_TYPE_NAME (widget), widget,
5051 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5052 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5053 adjusted_allocation = real_allocation; /* veto it */
5057 real_allocation = adjusted_allocation;
5060 if (real_allocation.width < 0 || real_allocation.height < 0)
5062 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5063 real_allocation.width,
5064 real_allocation.height);
5067 real_allocation.width = MAX (real_allocation.width, 1);
5068 real_allocation.height = MAX (real_allocation.height, 1);
5070 size_changed = (old_allocation.width != real_allocation.width ||
5071 old_allocation.height != real_allocation.height);
5072 position_changed = (old_allocation.x != real_allocation.x ||
5073 old_allocation.y != real_allocation.y);
5075 if (!alloc_needed && !size_changed && !position_changed)
5078 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5080 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5081 priv->alloc_needed = FALSE;
5083 if (gtk_widget_get_mapped (widget))
5085 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5087 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5089 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5090 cairo_region_union_rectangle (invalidate, &old_allocation);
5092 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5093 cairo_region_destroy (invalidate);
5098 if (priv->redraw_on_alloc)
5100 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5102 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5103 cairo_region_union_rectangle (invalidate, &old_allocation);
5105 gtk_widget_invalidate_widget_windows (widget, invalidate);
5106 cairo_region_destroy (invalidate);
5111 if ((size_changed || position_changed) && priv->parent &&
5112 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5114 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5115 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5116 cairo_region_destroy (invalidate);
5120 gtk_widget_pop_verify_invariants (widget);
5124 * gtk_widget_common_ancestor:
5125 * @widget_a: a #GtkWidget
5126 * @widget_b: a #GtkWidget
5128 * Find the common ancestor of @widget_a and @widget_b that
5129 * is closest to the two widgets.
5131 * Return value: the closest common ancestor of @widget_a and
5132 * @widget_b or %NULL if @widget_a and @widget_b do not
5133 * share a common ancestor.
5136 gtk_widget_common_ancestor (GtkWidget *widget_a,
5137 GtkWidget *widget_b)
5139 GtkWidget *parent_a;
5140 GtkWidget *parent_b;
5144 parent_a = widget_a;
5145 while (parent_a->priv->parent)
5147 parent_a = parent_a->priv->parent;
5151 parent_b = widget_b;
5152 while (parent_b->priv->parent)
5154 parent_b = parent_b->priv->parent;
5158 if (parent_a != parent_b)
5161 while (depth_a > depth_b)
5163 widget_a = widget_a->priv->parent;
5167 while (depth_b > depth_a)
5169 widget_b = widget_b->priv->parent;
5173 while (widget_a != widget_b)
5175 widget_a = widget_a->priv->parent;
5176 widget_b = widget_b->priv->parent;
5183 * gtk_widget_translate_coordinates:
5184 * @src_widget: a #GtkWidget
5185 * @dest_widget: a #GtkWidget
5186 * @src_x: X position relative to @src_widget
5187 * @src_y: Y position relative to @src_widget
5188 * @dest_x: (out): location to store X position relative to @dest_widget
5189 * @dest_y: (out): location to store Y position relative to @dest_widget
5191 * Translate coordinates relative to @src_widget's allocation to coordinates
5192 * relative to @dest_widget's allocations. In order to perform this
5193 * operation, both widgets must be realized, and must share a common
5196 * Return value: %FALSE if either widget was not realized, or there
5197 * was no common ancestor. In this case, nothing is stored in
5198 * *@dest_x and *@dest_y. Otherwise %TRUE.
5201 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5202 GtkWidget *dest_widget,
5208 GtkWidgetPrivate *src_priv = src_widget->priv;
5209 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5210 GtkWidget *ancestor;
5212 GList *dest_list = NULL;
5214 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5215 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5217 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5218 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5221 /* Translate from allocation relative to window relative */
5222 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5225 gdk_window_get_position (src_priv->window, &wx, &wy);
5227 src_x -= wx - src_priv->allocation.x;
5228 src_y -= wy - src_priv->allocation.y;
5232 src_x += src_priv->allocation.x;
5233 src_y += src_priv->allocation.y;
5236 /* Translate to the common ancestor */
5237 window = src_priv->window;
5238 while (window != ancestor->priv->window)
5242 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5247 window = gdk_window_get_effective_parent (window);
5249 if (!window) /* Handle GtkHandleBox */
5254 window = dest_priv->window;
5255 while (window != ancestor->priv->window)
5257 dest_list = g_list_prepend (dest_list, window);
5259 window = gdk_window_get_effective_parent (window);
5261 if (!window) /* Handle GtkHandleBox */
5263 g_list_free (dest_list);
5272 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5277 dest_list = g_list_remove (dest_list, dest_list->data);
5280 /* Translate from window relative to allocation relative */
5281 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5284 gdk_window_get_position (dest_priv->window, &wx, &wy);
5286 src_x += wx - dest_priv->allocation.x;
5287 src_y += wy - dest_priv->allocation.y;
5291 src_x -= dest_priv->allocation.x;
5292 src_y -= dest_priv->allocation.y;
5304 gtk_widget_real_size_allocate (GtkWidget *widget,
5305 GtkAllocation *allocation)
5307 GtkWidgetPrivate *priv = widget->priv;
5309 priv->allocation = *allocation;
5311 if (gtk_widget_get_realized (widget) &&
5312 gtk_widget_get_has_window (widget))
5314 gdk_window_move_resize (priv->window,
5315 allocation->x, allocation->y,
5316 allocation->width, allocation->height);
5320 /* translate initial/final into start/end */
5322 effective_align (GtkAlign align,
5323 GtkTextDirection direction)
5327 case GTK_ALIGN_START:
5328 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5330 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5337 adjust_for_align (GtkAlign align,
5339 gint *allocated_pos,
5340 gint *allocated_size)
5344 case GTK_ALIGN_FILL:
5345 /* change nothing */
5347 case GTK_ALIGN_START:
5348 /* keep *allocated_pos where it is */
5349 *allocated_size = MIN (*allocated_size, *natural_size);
5352 if (*allocated_size > *natural_size)
5354 *allocated_pos += (*allocated_size - *natural_size);
5355 *allocated_size = *natural_size;
5358 case GTK_ALIGN_CENTER:
5359 if (*allocated_size > *natural_size)
5361 *allocated_pos += (*allocated_size - *natural_size) / 2;
5362 *allocated_size = MIN (*allocated_size, *natural_size);
5369 adjust_for_margin(gint start_margin,
5373 gint *allocated_pos,
5374 gint *allocated_size)
5376 *minimum_size -= (start_margin + end_margin);
5377 *natural_size -= (start_margin + end_margin);
5378 *allocated_pos += start_margin;
5379 *allocated_size -= (start_margin + end_margin);
5383 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5384 GtkOrientation orientation,
5387 gint *allocated_pos,
5388 gint *allocated_size)
5390 const GtkWidgetAuxInfo *aux_info;
5392 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5394 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5396 adjust_for_margin (aux_info->margin.left,
5397 aux_info->margin.right,
5398 minimum_size, natural_size,
5399 allocated_pos, allocated_size);
5400 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5401 natural_size, allocated_pos, allocated_size);
5405 adjust_for_margin (aux_info->margin.top,
5406 aux_info->margin.bottom,
5407 minimum_size, natural_size,
5408 allocated_pos, allocated_size);
5409 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5410 natural_size, allocated_pos, allocated_size);
5415 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5418 GtkWidgetPrivate *priv = widget->priv;
5420 /* widgets must be onscreen for accels to take effect */
5421 return gtk_widget_is_sensitive (widget) &&
5422 gtk_widget_is_drawable (widget) &&
5423 gdk_window_is_viewable (priv->window);
5427 * gtk_widget_can_activate_accel:
5428 * @widget: a #GtkWidget
5429 * @signal_id: the ID of a signal installed on @widget
5431 * Determines whether an accelerator that activates the signal
5432 * identified by @signal_id can currently be activated.
5433 * This is done by emitting the #GtkWidget::can-activate-accel
5434 * signal on @widget; if the signal isn't overridden by a
5435 * handler or in a derived widget, then the default check is
5436 * that the widget must be sensitive, and the widget and all
5437 * its ancestors mapped.
5439 * Return value: %TRUE if the accelerator can be activated.
5444 gtk_widget_can_activate_accel (GtkWidget *widget,
5447 gboolean can_activate = FALSE;
5448 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5449 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5450 return can_activate;
5459 closure_accel_activate (GClosure *closure,
5460 GValue *return_value,
5461 guint n_param_values,
5462 const GValue *param_values,
5463 gpointer invocation_hint,
5464 gpointer marshal_data)
5466 AccelClosure *aclosure = (AccelClosure*) closure;
5467 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5470 g_signal_emit (closure->data, aclosure->signal_id, 0);
5472 /* whether accelerator was handled */
5473 g_value_set_boolean (return_value, can_activate);
5477 closures_destroy (gpointer data)
5479 GSList *slist, *closures = data;
5481 for (slist = closures; slist; slist = slist->next)
5483 g_closure_invalidate (slist->data);
5484 g_closure_unref (slist->data);
5486 g_slist_free (closures);
5490 widget_new_accel_closure (GtkWidget *widget,
5493 AccelClosure *aclosure;
5494 GClosure *closure = NULL;
5495 GSList *slist, *closures;
5497 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5498 for (slist = closures; slist; slist = slist->next)
5499 if (!gtk_accel_group_from_accel_closure (slist->data))
5501 /* reuse this closure */
5502 closure = slist->data;
5507 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5508 closures = g_slist_prepend (closures, g_closure_ref (closure));
5509 g_closure_sink (closure);
5510 g_closure_set_marshal (closure, closure_accel_activate);
5512 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5514 aclosure = (AccelClosure*) closure;
5515 g_assert (closure->data == widget);
5516 g_assert (closure->marshal == closure_accel_activate);
5517 aclosure->signal_id = signal_id;
5523 * gtk_widget_add_accelerator:
5524 * @widget: widget to install an accelerator on
5525 * @accel_signal: widget signal to emit on accelerator activation
5526 * @accel_group: accel group for this widget, added to its toplevel
5527 * @accel_key: GDK keyval of the accelerator
5528 * @accel_mods: modifier key combination of the accelerator
5529 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5531 * Installs an accelerator for this @widget in @accel_group that causes
5532 * @accel_signal to be emitted if the accelerator is activated.
5533 * The @accel_group needs to be added to the widget's toplevel via
5534 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5535 * Accelerators added through this function are not user changeable during
5536 * runtime. If you want to support accelerators that can be changed by the
5537 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5538 * gtk_menu_item_set_accel_path() instead.
5541 gtk_widget_add_accelerator (GtkWidget *widget,
5542 const gchar *accel_signal,
5543 GtkAccelGroup *accel_group,
5545 GdkModifierType accel_mods,
5546 GtkAccelFlags accel_flags)
5551 g_return_if_fail (GTK_IS_WIDGET (widget));
5552 g_return_if_fail (accel_signal != NULL);
5553 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5555 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5556 if (!query.signal_id ||
5557 !(query.signal_flags & G_SIGNAL_ACTION) ||
5558 query.return_type != G_TYPE_NONE ||
5561 /* hmm, should be elaborate enough */
5562 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5563 G_OBJECT_TYPE_NAME (widget), accel_signal);
5567 closure = widget_new_accel_closure (widget, query.signal_id);
5569 g_object_ref (widget);
5571 /* install the accelerator. since we don't map this onto an accel_path,
5572 * the accelerator will automatically be locked.
5574 gtk_accel_group_connect (accel_group,
5577 accel_flags | GTK_ACCEL_LOCKED,
5580 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5582 g_object_unref (widget);
5586 * gtk_widget_remove_accelerator:
5587 * @widget: widget to install an accelerator on
5588 * @accel_group: accel group for this widget
5589 * @accel_key: GDK keyval of the accelerator
5590 * @accel_mods: modifier key combination of the accelerator
5592 * Removes an accelerator from @widget, previously installed with
5593 * gtk_widget_add_accelerator().
5595 * Returns: whether an accelerator was installed and could be removed
5598 gtk_widget_remove_accelerator (GtkWidget *widget,
5599 GtkAccelGroup *accel_group,
5601 GdkModifierType accel_mods)
5603 GtkAccelGroupEntry *ag_entry;
5604 GList *slist, *clist;
5607 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5608 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5610 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5611 clist = gtk_widget_list_accel_closures (widget);
5612 for (slist = clist; slist; slist = slist->next)
5616 for (i = 0; i < n; i++)
5617 if (slist->data == (gpointer) ag_entry[i].closure)
5619 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5621 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5623 g_list_free (clist);
5628 g_list_free (clist);
5630 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5631 accel_key, accel_mods, accel_group,
5632 G_OBJECT_TYPE_NAME (widget), widget);
5638 * gtk_widget_list_accel_closures:
5639 * @widget: widget to list accelerator closures for
5641 * Lists the closures used by @widget for accelerator group connections
5642 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5643 * The closures can be used to monitor accelerator changes on @widget,
5644 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5645 * #GtkAccelGroup of a closure which can be found out with
5646 * gtk_accel_group_from_accel_closure().
5648 * Return value: (transfer container) (element-type GClosure):
5649 * a newly allocated #GList of closures
5652 gtk_widget_list_accel_closures (GtkWidget *widget)
5655 GList *clist = NULL;
5657 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5659 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5660 if (gtk_accel_group_from_accel_closure (slist->data))
5661 clist = g_list_prepend (clist, slist->data);
5667 GtkAccelGroup *accel_group;
5672 destroy_accel_path (gpointer data)
5674 AccelPath *apath = data;
5676 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5678 /* closures_destroy takes care of unrefing the closure */
5679 g_object_unref (apath->accel_group);
5681 g_slice_free (AccelPath, apath);
5686 * gtk_widget_set_accel_path:
5687 * @widget: a #GtkWidget
5688 * @accel_path: (allow-none): path used to look up the accelerator
5689 * @accel_group: (allow-none): a #GtkAccelGroup.
5691 * Given an accelerator group, @accel_group, and an accelerator path,
5692 * @accel_path, sets up an accelerator in @accel_group so whenever the
5693 * key binding that is defined for @accel_path is pressed, @widget
5694 * will be activated. This removes any accelerators (for any
5695 * accelerator group) installed by previous calls to
5696 * gtk_widget_set_accel_path(). Associating accelerators with
5697 * paths allows them to be modified by the user and the modifications
5698 * to be saved for future use. (See gtk_accel_map_save().)
5700 * This function is a low level function that would most likely
5701 * be used by a menu creation system like #GtkUIManager. If you
5702 * use #GtkUIManager, setting up accelerator paths will be done
5705 * Even when you you aren't using #GtkUIManager, if you only want to
5706 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5707 * provides a somewhat more convenient interface.
5709 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5710 * pass a static string, you can save some memory by interning it first with
5711 * g_intern_static_string().
5714 gtk_widget_set_accel_path (GtkWidget *widget,
5715 const gchar *accel_path,
5716 GtkAccelGroup *accel_group)
5720 g_return_if_fail (GTK_IS_WIDGET (widget));
5721 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5725 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5726 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5728 gtk_accel_map_add_entry (accel_path, 0, 0);
5729 apath = g_slice_new (AccelPath);
5730 apath->accel_group = g_object_ref (accel_group);
5731 apath->path_quark = g_quark_from_string (accel_path);
5732 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5737 /* also removes possible old settings */
5738 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5741 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5743 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5747 _gtk_widget_get_accel_path (GtkWidget *widget,
5752 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5754 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5756 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5757 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5761 * gtk_widget_mnemonic_activate:
5762 * @widget: a #GtkWidget
5763 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5765 * Emits the #GtkWidget::mnemonic-activate signal.
5767 * The default handler for this signal activates the @widget if
5768 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5771 * Returns: %TRUE if the signal has been handled
5774 gtk_widget_mnemonic_activate (GtkWidget *widget,
5775 gboolean group_cycling)
5779 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5781 group_cycling = group_cycling != FALSE;
5782 if (!gtk_widget_is_sensitive (widget))
5785 g_signal_emit (widget,
5786 widget_signals[MNEMONIC_ACTIVATE],
5794 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5795 gboolean group_cycling)
5797 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5798 gtk_widget_activate (widget);
5799 else if (gtk_widget_get_can_focus (widget))
5800 gtk_widget_grab_focus (widget);
5803 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5804 G_OBJECT_TYPE_NAME (widget));
5805 gtk_widget_error_bell (widget);
5810 static const cairo_user_data_key_t event_key;
5813 _gtk_cairo_get_event (cairo_t *cr)
5815 g_return_val_if_fail (cr != NULL, NULL);
5817 return cairo_get_user_data (cr, &event_key);
5821 gtk_cairo_set_event (cairo_t *cr,
5822 GdkEventExpose *event)
5824 cairo_set_user_data (cr, &event_key, event, NULL);
5828 * gtk_cairo_should_draw_window:
5829 * @cr: a cairo context
5830 * @window: the window to check. @window may not be an input-only
5833 * This function is supposed to be called in #GtkWidget::draw
5834 * implementations for widgets that support multiple windows.
5835 * @cr must be untransformed from invoking of the draw function.
5836 * This function will return %TRUE if the contents of the given
5837 * @window are supposed to be drawn and %FALSE otherwise. Note
5838 * that when the drawing was not initiated by the windowing
5839 * system this function will return %TRUE for all windows, so
5840 * you need to draw the bottommost window first. Also, do not
5841 * use "else if" statements to check which window should be drawn.
5843 * Returns: %TRUE if @window should be drawn
5848 gtk_cairo_should_draw_window (cairo_t *cr,
5851 GdkEventExpose *event;
5853 g_return_val_if_fail (cr != NULL, FALSE);
5854 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5856 event = _gtk_cairo_get_event (cr);
5858 return event == NULL ||
5859 event->window == window;
5863 gtk_widget_get_clip_draw (GtkWidget *widget)
5865 /* labels are not clipped, because clipping them would cause
5866 * mnemonics to not appear on characters that go beyond the
5868 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5870 if (GTK_IS_LABEL (widget))
5876 /* code shared by gtk_container_propagate_draw() and
5880 _gtk_widget_draw_internal (GtkWidget *widget,
5882 gboolean clip_to_size)
5884 if (!gtk_widget_is_drawable (widget))
5887 clip_to_size &= gtk_widget_get_clip_draw (widget);
5891 cairo_rectangle (cr,
5893 widget->priv->allocation.width,
5894 widget->priv->allocation.height);
5898 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5902 g_signal_emit (widget, widget_signals[DRAW],
5906 if (cairo_status (cr) &&
5907 _gtk_cairo_get_event (cr))
5909 /* We check the event so we only warn about internal GTK calls.
5910 * Errors might come from PDF streams having write failures and
5911 * we don't want to spam stderr in that case.
5912 * We do want to catch errors from
5914 g_warning ("drawing failure for widget `%s': %s",
5915 G_OBJECT_TYPE_NAME (widget),
5916 cairo_status_to_string (cairo_status (cr)));
5923 * @widget: the widget to draw. It must be drawable (see
5924 * gtk_widget_is_drawable()) and a size must have been allocated.
5925 * @cr: a cairo context to draw to
5927 * Draws @widget to @cr. The top left corner of the widget will be
5928 * drawn to the currently set origin point of @cr.
5930 * You should pass a cairo context as @cr argument that is in an
5931 * original state. Otherwise the resulting drawing is undefined. For
5932 * example changing the operator using cairo_set_operator() or the
5933 * line width using cairo_set_line_width() might have unwanted side
5935 * You may however change the context's transform matrix - like with
5936 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5937 * region with cairo_clip() prior to calling this function. Also, it
5938 * is fine to modify the context with cairo_save() and
5939 * cairo_push_group() prior to calling this function.
5941 * <note><para>Special purpose widgets may contain special code for
5942 * rendering to the screen and might appear differently on screen
5943 * and when rendered using gtk_widget_draw().</para></note>
5948 gtk_widget_draw (GtkWidget *widget,
5951 GdkEventExpose *tmp_event;
5953 g_return_if_fail (GTK_IS_WIDGET (widget));
5954 g_return_if_fail (!widget->priv->alloc_needed);
5955 g_return_if_fail (cr != NULL);
5958 /* We have to reset the event here so that draw functions can call
5959 * gtk_widget_draw() on random other widgets and get the desired
5960 * effect: Drawing all contents, not just the current window.
5962 tmp_event = _gtk_cairo_get_event (cr);
5963 gtk_cairo_set_event (cr, NULL);
5965 _gtk_widget_draw_internal (widget, cr, TRUE);
5967 gtk_cairo_set_event (cr, tmp_event);
5972 gtk_widget_real_key_press_event (GtkWidget *widget,
5975 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5979 gtk_widget_real_key_release_event (GtkWidget *widget,
5982 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5986 gtk_widget_real_focus_in_event (GtkWidget *widget,
5987 GdkEventFocus *event)
5989 gtk_widget_queue_draw (widget);
5995 gtk_widget_real_focus_out_event (GtkWidget *widget,
5996 GdkEventFocus *event)
5998 gtk_widget_queue_draw (widget);
6004 gtk_widget_real_touch_event (GtkWidget *widget,
6005 GdkEventTouch *event)
6008 gboolean return_val;
6011 if (!event->emulating_pointer)
6014 if (event->type == GDK_TOUCH_BEGIN ||
6015 event->type == GDK_TOUCH_END)
6019 if (event->type == GDK_TOUCH_BEGIN)
6021 type = GDK_BUTTON_PRESS;
6022 signum = BUTTON_PRESS_EVENT;
6026 type = GDK_BUTTON_RELEASE;
6027 signum = BUTTON_RELEASE_EVENT;
6029 bevent = gdk_event_new (type);
6030 bevent->any.window = g_object_ref (event->window);
6031 bevent->any.send_event = FALSE;
6032 bevent->button.time = event->time;
6033 bevent->button.state = event->state;
6034 bevent->button.button = 1;
6035 bevent->button.x_root = event->x_root;
6036 bevent->button.y_root = event->y_root;
6037 bevent->button.x = event->x;
6038 bevent->button.y = event->y;
6039 bevent->button.device = event->device;
6040 bevent->button.axes = g_memdup (event->axes,
6041 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6042 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6044 else if (event->type == GDK_TOUCH_UPDATE)
6046 signum = MOTION_NOTIFY_EVENT;
6047 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6048 bevent->any.window = g_object_ref (event->window);
6049 bevent->any.send_event = FALSE;
6050 bevent->motion.time = event->time;
6051 bevent->motion.state = event->state;
6052 bevent->motion.x_root = event->x_root;
6053 bevent->motion.y_root = event->y_root;
6054 bevent->motion.x = event->x;
6055 bevent->motion.y = event->y;
6056 bevent->motion.device = event->device;
6057 bevent->motion.is_hint = FALSE;
6058 bevent->motion.axes = g_memdup (event->axes,
6059 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6060 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6065 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6067 gdk_event_free (bevent);
6073 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6074 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6078 * @widget: a #GtkWidget
6079 * @event: a #GdkEvent
6081 * Rarely-used function. This function is used to emit
6082 * the event signals on a widget (those signals should never
6083 * be emitted without using this function to do so).
6084 * If you want to synthesize an event though, don't use this function;
6085 * instead, use gtk_main_do_event() so the event will behave as if
6086 * it were in the event queue. Don't synthesize expose events; instead,
6087 * use gdk_window_invalidate_rect() to invalidate a region of the
6090 * Return value: return from the event signal emission (%TRUE if
6091 * the event was handled)
6094 gtk_widget_event (GtkWidget *widget,
6097 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6098 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6100 if (event->type == GDK_EXPOSE)
6102 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6103 "the same effect, call gdk_window_invalidate_rect/region(), "
6104 "followed by gdk_window_process_updates().");
6108 return gtk_widget_event_internal (widget, event);
6112 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6113 GtkCapturedEventHandler callback)
6115 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6119 _gtk_widget_captured_event (GtkWidget *widget,
6122 gboolean return_val = FALSE;
6123 GtkCapturedEventHandler handler;
6125 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6126 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6128 if (event->type == GDK_EXPOSE)
6130 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6131 "the same effect, call gdk_window_invalidate_rect/region(), "
6132 "followed by gdk_window_process_updates().");
6136 if (!event_window_is_still_viewable (event))
6139 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6143 g_object_ref (widget);
6145 return_val = handler (widget, event);
6146 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6148 /* The widget that was originally to receive the event
6149 * handles motion hints, but the capturing widget might
6150 * not, so ensure we get further motion events.
6153 event->type == GDK_MOTION_NOTIFY &&
6154 event->motion.is_hint &&
6155 (gdk_window_get_events (event->any.window) &
6156 GDK_POINTER_MOTION_HINT_MASK) != 0)
6157 gdk_event_request_motions (&event->motion);
6159 g_object_unref (widget);
6164 /* Returns TRUE if a translation should be done */
6166 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6171 GdkWindow *w, *widget_window;
6173 if (!gtk_widget_get_has_window (widget))
6175 *x = -widget->priv->allocation.x;
6176 *y = -widget->priv->allocation.y;
6184 widget_window = gtk_widget_get_window (widget);
6186 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6189 gdk_window_get_position (w, &wx, &wy);
6206 * gtk_cairo_transform_to_window:
6207 * @cr: the cairo context to transform
6208 * @widget: the widget the context is currently centered for
6209 * @window: the window to transform the context to
6211 * Transforms the given cairo context @cr that from @widget-relative
6212 * coordinates to @window-relative coordinates.
6213 * If the @widget's window is not an ancestor of @window, no
6214 * modification will be applied.
6216 * This is the inverse to the transformation GTK applies when
6217 * preparing an expose event to be emitted with the #GtkWidget::draw
6218 * signal. It is intended to help porting multiwindow widgets from
6219 * GTK+ 2 to the rendering architecture of GTK+ 3.
6224 gtk_cairo_transform_to_window (cairo_t *cr,
6230 g_return_if_fail (cr != NULL);
6231 g_return_if_fail (GTK_IS_WIDGET (widget));
6232 g_return_if_fail (GDK_IS_WINDOW (window));
6234 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6235 cairo_translate (cr, x, y);
6239 * gtk_widget_send_expose:
6240 * @widget: a #GtkWidget
6241 * @event: a expose #GdkEvent
6243 * Very rarely-used function. This function is used to emit
6244 * an expose event on a widget. This function is not normally used
6245 * directly. The only time it is used is when propagating an expose
6246 * event to a child %NO_WINDOW widget, and that is normally done
6247 * using gtk_container_propagate_draw().
6249 * If you want to force an area of a window to be redrawn,
6250 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6251 * To cause the redraw to be done immediately, follow that call
6252 * with a call to gdk_window_process_updates().
6254 * Return value: return from the event signal emission (%TRUE if
6255 * the event was handled)
6258 gtk_widget_send_expose (GtkWidget *widget,
6261 gboolean result = FALSE;
6266 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6267 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6268 g_return_val_if_fail (event != NULL, TRUE);
6269 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6271 cr = gdk_cairo_create (event->expose.window);
6272 gtk_cairo_set_event (cr, &event->expose);
6274 gdk_cairo_region (cr, event->expose.region);
6277 do_clip = _gtk_widget_get_translation_to_window (widget,
6278 event->expose.window,
6280 cairo_translate (cr, -x, -y);
6282 _gtk_widget_draw_internal (widget, cr, do_clip);
6284 /* unset here, so if someone keeps a reference to cr we
6285 * don't leak the window. */
6286 gtk_cairo_set_event (cr, NULL);
6293 event_window_is_still_viewable (GdkEvent *event)
6295 /* Check that we think the event's window is viewable before
6296 * delivering the event, to prevent suprises. We do this here
6297 * at the last moment, since the event may have been queued
6298 * up behind other events, held over a recursive main loop, etc.
6300 switch (event->type)
6303 case GDK_MOTION_NOTIFY:
6304 case GDK_BUTTON_PRESS:
6305 case GDK_2BUTTON_PRESS:
6306 case GDK_3BUTTON_PRESS:
6308 case GDK_ENTER_NOTIFY:
6309 case GDK_PROXIMITY_IN:
6311 return event->any.window && gdk_window_is_viewable (event->any.window);
6314 /* The following events are the second half of paired events;
6315 * we always deliver them to deal with widgets that clean up
6316 * on the second half.
6318 case GDK_BUTTON_RELEASE:
6319 case GDK_KEY_RELEASE:
6320 case GDK_LEAVE_NOTIFY:
6321 case GDK_PROXIMITY_OUT:
6325 /* Remaining events would make sense on an not-viewable window,
6326 * or don't have an associated window.
6333 gtk_widget_event_internal (GtkWidget *widget,
6336 gboolean return_val = FALSE;
6338 /* We check only once for is-still-visible; if someone
6339 * hides the window in on of the signals on the widget,
6340 * they are responsible for returning TRUE to terminate
6343 if (!event_window_is_still_viewable (event))
6346 g_object_ref (widget);
6348 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6349 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6354 switch (event->type)
6360 case GDK_BUTTON_PRESS:
6361 case GDK_2BUTTON_PRESS:
6362 case GDK_3BUTTON_PRESS:
6363 signal_num = BUTTON_PRESS_EVENT;
6365 case GDK_TOUCH_BEGIN:
6366 case GDK_TOUCH_UPDATE:
6368 case GDK_TOUCH_CANCEL:
6369 signal_num = TOUCH_EVENT;
6372 signal_num = SCROLL_EVENT;
6374 case GDK_BUTTON_RELEASE:
6375 signal_num = BUTTON_RELEASE_EVENT;
6377 case GDK_MOTION_NOTIFY:
6378 signal_num = MOTION_NOTIFY_EVENT;
6381 signal_num = DELETE_EVENT;
6384 signal_num = DESTROY_EVENT;
6385 _gtk_tooltip_hide (widget);
6388 signal_num = KEY_PRESS_EVENT;
6390 case GDK_KEY_RELEASE:
6391 signal_num = KEY_RELEASE_EVENT;
6393 case GDK_ENTER_NOTIFY:
6394 signal_num = ENTER_NOTIFY_EVENT;
6396 case GDK_LEAVE_NOTIFY:
6397 signal_num = LEAVE_NOTIFY_EVENT;
6399 case GDK_FOCUS_CHANGE:
6400 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6401 if (event->focus_change.in)
6402 _gtk_tooltip_focus_in (widget);
6404 _gtk_tooltip_focus_out (widget);
6407 signal_num = CONFIGURE_EVENT;
6410 signal_num = MAP_EVENT;
6413 signal_num = UNMAP_EVENT;
6415 case GDK_WINDOW_STATE:
6416 signal_num = WINDOW_STATE_EVENT;
6418 case GDK_PROPERTY_NOTIFY:
6419 signal_num = PROPERTY_NOTIFY_EVENT;
6421 case GDK_SELECTION_CLEAR:
6422 signal_num = SELECTION_CLEAR_EVENT;
6424 case GDK_SELECTION_REQUEST:
6425 signal_num = SELECTION_REQUEST_EVENT;
6427 case GDK_SELECTION_NOTIFY:
6428 signal_num = SELECTION_NOTIFY_EVENT;
6430 case GDK_PROXIMITY_IN:
6431 signal_num = PROXIMITY_IN_EVENT;
6433 case GDK_PROXIMITY_OUT:
6434 signal_num = PROXIMITY_OUT_EVENT;
6436 case GDK_VISIBILITY_NOTIFY:
6437 signal_num = VISIBILITY_NOTIFY_EVENT;
6439 case GDK_GRAB_BROKEN:
6440 signal_num = GRAB_BROKEN_EVENT;
6443 signal_num = DAMAGE_EVENT;
6446 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6450 if (signal_num != -1)
6451 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6453 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6454 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6458 g_object_unref (widget);
6464 * gtk_widget_activate:
6465 * @widget: a #GtkWidget that's activatable
6467 * For widgets that can be "activated" (buttons, menu items, etc.)
6468 * this function activates them. Activation is what happens when you
6469 * press Enter on a widget during key navigation. If @widget isn't
6470 * activatable, the function returns %FALSE.
6472 * Return value: %TRUE if the widget was activatable
6475 gtk_widget_activate (GtkWidget *widget)
6477 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6479 if (WIDGET_CLASS (widget)->activate_signal)
6481 /* FIXME: we should eventually check the signals signature here */
6482 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6491 gtk_widget_reparent_subwindows (GtkWidget *widget,
6492 GdkWindow *new_window)
6494 GtkWidgetPrivate *priv = widget->priv;
6496 if (!gtk_widget_get_has_window (widget))
6498 GList *children = gdk_window_get_children (priv->window);
6501 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6503 GdkWindow *window = tmp_list->data;
6506 gdk_window_get_user_data (window, &child);
6507 while (child && child != widget)
6508 child = ((GtkWidget*) child)->priv->parent;
6511 gdk_window_reparent (window, new_window, 0, 0);
6514 g_list_free (children);
6519 GList *tmp_list, *children;
6521 parent = gdk_window_get_parent (priv->window);
6524 gdk_window_reparent (priv->window, new_window, 0, 0);
6527 children = gdk_window_get_children (parent);
6529 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6531 GdkWindow *window = tmp_list->data;
6534 gdk_window_get_user_data (window, &child);
6536 if (child == widget)
6537 gdk_window_reparent (window, new_window, 0, 0);
6540 g_list_free (children);
6546 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6547 gpointer client_data)
6549 GtkWidgetPrivate *priv = widget->priv;
6551 g_assert (client_data != NULL);
6553 if (!gtk_widget_get_has_window (widget))
6556 g_object_unref (priv->window);
6557 priv->window = (GdkWindow*) client_data;
6559 g_object_ref (priv->window);
6561 if (GTK_IS_CONTAINER (widget))
6562 gtk_container_forall (GTK_CONTAINER (widget),
6563 gtk_widget_reparent_fixup_child,
6569 * gtk_widget_reparent:
6570 * @widget: a #GtkWidget
6571 * @new_parent: a #GtkContainer to move the widget into
6573 * Moves a widget from one #GtkContainer to another, handling reference
6574 * count issues to avoid destroying the widget.
6577 gtk_widget_reparent (GtkWidget *widget,
6578 GtkWidget *new_parent)
6580 GtkWidgetPrivate *priv;
6582 g_return_if_fail (GTK_IS_WIDGET (widget));
6583 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6584 priv = widget->priv;
6585 g_return_if_fail (priv->parent != NULL);
6587 if (priv->parent != new_parent)
6589 /* First try to see if we can get away without unrealizing
6590 * the widget as we reparent it. if so we set a flag so
6591 * that gtk_widget_unparent doesn't unrealize widget
6593 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6594 priv->in_reparent = TRUE;
6596 g_object_ref (widget);
6597 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6598 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6599 g_object_unref (widget);
6601 if (priv->in_reparent)
6603 priv->in_reparent = FALSE;
6605 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6606 gtk_widget_reparent_fixup_child (widget,
6607 gtk_widget_get_parent_window (widget));
6610 g_object_notify (G_OBJECT (widget), "parent");
6615 * gtk_widget_intersect:
6616 * @widget: a #GtkWidget
6617 * @area: a rectangle
6618 * @intersection: rectangle to store intersection of @widget and @area
6620 * Computes the intersection of a @widget's area and @area, storing
6621 * the intersection in @intersection, and returns %TRUE if there was
6622 * an intersection. @intersection may be %NULL if you're only
6623 * interested in whether there was an intersection.
6625 * Return value: %TRUE if there was an intersection
6628 gtk_widget_intersect (GtkWidget *widget,
6629 const GdkRectangle *area,
6630 GdkRectangle *intersection)
6632 GtkWidgetPrivate *priv;
6637 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6638 g_return_val_if_fail (area != NULL, FALSE);
6640 priv = widget->priv;
6643 dest = intersection;
6647 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6649 if (return_val && intersection && gtk_widget_get_has_window (widget))
6651 intersection->x -= priv->allocation.x;
6652 intersection->y -= priv->allocation.y;
6659 * gtk_widget_region_intersect:
6660 * @widget: a #GtkWidget
6661 * @region: a #cairo_region_t, in the same coordinate system as
6662 * @widget->allocation. That is, relative to @widget->window
6663 * for %NO_WINDOW widgets; relative to the parent window
6664 * of @widget->window for widgets with their own window.
6666 * Computes the intersection of a @widget's area and @region, returning
6667 * the intersection. The result may be empty, use cairo_region_is_empty() to
6670 * Returns: A newly allocated region holding the intersection of @widget
6671 * and @region. The coordinates of the return value are relative to
6672 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6673 * window of @widget->window for widgets with their own window.
6676 gtk_widget_region_intersect (GtkWidget *widget,
6677 const cairo_region_t *region)
6680 cairo_region_t *dest;
6682 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6683 g_return_val_if_fail (region != NULL, NULL);
6685 gtk_widget_get_allocation (widget, &rect);
6687 dest = cairo_region_create_rectangle (&rect);
6689 cairo_region_intersect (dest, region);
6695 * _gtk_widget_grab_notify:
6696 * @widget: a #GtkWidget
6697 * @was_grabbed: whether a grab is now in effect
6699 * Emits the #GtkWidget::grab-notify signal on @widget.
6704 _gtk_widget_grab_notify (GtkWidget *widget,
6705 gboolean was_grabbed)
6707 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6711 * gtk_widget_grab_focus:
6712 * @widget: a #GtkWidget
6714 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6715 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6716 * something like #GtkFrame won't work.
6718 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6719 * gtk_widget_set_can_focus() to modify that flag.
6721 * The widget also needs to be realized and mapped. This is indicated by the
6722 * related signals. Grabbing the focus immediately after creating the widget
6723 * will likely fail and cause critical warnings.
6726 gtk_widget_grab_focus (GtkWidget *widget)
6728 g_return_if_fail (GTK_IS_WIDGET (widget));
6730 if (!gtk_widget_is_sensitive (widget))
6733 g_object_ref (widget);
6734 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6735 g_object_notify (G_OBJECT (widget), "has-focus");
6736 g_object_unref (widget);
6740 reset_focus_recurse (GtkWidget *widget,
6743 if (GTK_IS_CONTAINER (widget))
6745 GtkContainer *container;
6747 container = GTK_CONTAINER (widget);
6748 gtk_container_set_focus_child (container, NULL);
6750 gtk_container_foreach (container,
6751 reset_focus_recurse,
6757 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6759 if (gtk_widget_get_can_focus (focus_widget))
6761 GtkWidget *toplevel;
6764 /* clear the current focus setting, break if the current widget
6765 * is the focus widget's parent, since containers above that will
6766 * be set by the next loop.
6768 toplevel = gtk_widget_get_toplevel (focus_widget);
6769 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6771 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6773 if (widget == focus_widget)
6775 /* We call _gtk_window_internal_set_focus() here so that the
6776 * toplevel window can request the focus if necessary.
6777 * This is needed when the toplevel is a GtkPlug
6779 if (!gtk_widget_has_focus (widget))
6780 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6787 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6789 if (widget != common_ancestor)
6791 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6793 widget = widget->priv->parent;
6794 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6799 else if (toplevel != focus_widget)
6801 /* gtk_widget_grab_focus() operates on a tree without window...
6802 * actually, this is very questionable behaviour.
6805 gtk_container_foreach (GTK_CONTAINER (toplevel),
6806 reset_focus_recurse,
6810 /* now propagate the new focus up the widget tree and finally
6811 * set it on the window
6813 widget = focus_widget;
6814 while (widget->priv->parent)
6816 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6817 widget = widget->priv->parent;
6819 if (GTK_IS_WINDOW (widget))
6820 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6825 gtk_widget_real_query_tooltip (GtkWidget *widget,
6828 gboolean keyboard_tip,
6829 GtkTooltip *tooltip)
6831 gchar *tooltip_markup;
6832 gboolean has_tooltip;
6834 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6835 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6837 if (has_tooltip && tooltip_markup)
6839 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6847 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6848 GtkStateFlags old_state)
6850 gtk_widget_update_pango_context (widget);
6854 gtk_widget_real_style_updated (GtkWidget *widget)
6856 GtkWidgetPrivate *priv = widget->priv;
6858 gtk_widget_update_pango_context (widget);
6859 gtk_widget_update_alpha (widget);
6861 if (priv->style != NULL &&
6862 priv->style != gtk_widget_get_default_style ())
6864 /* Trigger ::style-set for old
6865 * widgets not listening to this
6867 g_signal_emit (widget,
6868 widget_signals[STYLE_SET],
6870 widget->priv->style);
6873 if (widget->priv->context)
6875 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6877 if (gtk_widget_get_realized (widget) &&
6878 gtk_widget_get_has_window (widget) &&
6879 !gtk_widget_get_app_paintable (widget))
6880 gtk_style_context_set_background (widget->priv->context,
6881 widget->priv->window);
6883 if (widget->priv->anchored)
6885 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6886 gtk_widget_queue_resize (widget);
6888 gtk_widget_queue_draw (widget);
6893 if (widget->priv->anchored)
6894 gtk_widget_queue_resize (widget);
6899 gtk_widget_real_show_help (GtkWidget *widget,
6900 GtkWidgetHelpType help_type)
6902 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6904 _gtk_tooltip_toggle_keyboard_mode (widget);
6913 gtk_widget_real_focus (GtkWidget *widget,
6914 GtkDirectionType direction)
6916 if (!gtk_widget_get_can_focus (widget))
6919 if (!gtk_widget_is_focus (widget))
6921 gtk_widget_grab_focus (widget);
6929 gtk_widget_real_move_focus (GtkWidget *widget,
6930 GtkDirectionType direction)
6932 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6934 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6936 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6942 gtk_widget_real_keynav_failed (GtkWidget *widget,
6943 GtkDirectionType direction)
6945 gboolean cursor_only;
6949 case GTK_DIR_TAB_FORWARD:
6950 case GTK_DIR_TAB_BACKWARD:
6957 g_object_get (gtk_widget_get_settings (widget),
6958 "gtk-keynav-cursor-only", &cursor_only,
6965 gtk_widget_error_bell (widget);
6971 * gtk_widget_set_can_focus:
6972 * @widget: a #GtkWidget
6973 * @can_focus: whether or not @widget can own the input focus.
6975 * Specifies whether @widget can own the input focus. See
6976 * gtk_widget_grab_focus() for actually setting the input focus on a
6982 gtk_widget_set_can_focus (GtkWidget *widget,
6985 g_return_if_fail (GTK_IS_WIDGET (widget));
6987 if (widget->priv->can_focus != can_focus)
6989 widget->priv->can_focus = can_focus;
6991 gtk_widget_queue_resize (widget);
6992 g_object_notify (G_OBJECT (widget), "can-focus");
6997 * gtk_widget_get_can_focus:
6998 * @widget: a #GtkWidget
7000 * Determines whether @widget can own the input focus. See
7001 * gtk_widget_set_can_focus().
7003 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
7008 gtk_widget_get_can_focus (GtkWidget *widget)
7010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7012 return widget->priv->can_focus;
7016 * gtk_widget_has_focus:
7017 * @widget: a #GtkWidget
7019 * Determines if the widget has the global input focus. See
7020 * gtk_widget_is_focus() for the difference between having the global
7021 * input focus, and only having the focus within a toplevel.
7023 * Return value: %TRUE if the widget has the global input focus.
7028 gtk_widget_has_focus (GtkWidget *widget)
7030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7032 return widget->priv->has_focus;
7036 * gtk_widget_has_visible_focus:
7037 * @widget: a #GtkWidget
7039 * Determines if the widget should show a visible indication that
7040 * it has the global input focus. This is a convenience function for
7041 * use in ::draw handlers that takes into account whether focus
7042 * indication should currently be shown in the toplevel window of
7043 * @widget. See gtk_window_get_focus_visible() for more information
7044 * about focus indication.
7046 * To find out if the widget has the global input focus, use
7047 * gtk_widget_has_focus().
7049 * Return value: %TRUE if the widget should display a 'focus rectangle'
7054 gtk_widget_has_visible_focus (GtkWidget *widget)
7056 gboolean draw_focus;
7058 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7060 if (widget->priv->has_focus)
7062 GtkWidget *toplevel;
7064 toplevel = gtk_widget_get_toplevel (widget);
7066 if (GTK_IS_WINDOW (toplevel))
7067 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7078 * gtk_widget_is_focus:
7079 * @widget: a #GtkWidget
7081 * Determines if the widget is the focus widget within its
7082 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7083 * necessarily set; %HAS_FOCUS will only be set if the
7084 * toplevel widget additionally has the global input focus.)
7086 * Return value: %TRUE if the widget is the focus widget.
7089 gtk_widget_is_focus (GtkWidget *widget)
7091 GtkWidget *toplevel;
7093 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7095 toplevel = gtk_widget_get_toplevel (widget);
7097 if (GTK_IS_WINDOW (toplevel))
7098 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7104 * gtk_widget_set_can_default:
7105 * @widget: a #GtkWidget
7106 * @can_default: whether or not @widget can be a default widget.
7108 * Specifies whether @widget can be a default widget. See
7109 * gtk_widget_grab_default() for details about the meaning of
7115 gtk_widget_set_can_default (GtkWidget *widget,
7116 gboolean can_default)
7118 g_return_if_fail (GTK_IS_WIDGET (widget));
7120 if (widget->priv->can_default != can_default)
7122 widget->priv->can_default = can_default;
7124 gtk_widget_queue_resize (widget);
7125 g_object_notify (G_OBJECT (widget), "can-default");
7130 * gtk_widget_get_can_default:
7131 * @widget: a #GtkWidget
7133 * Determines whether @widget can be a default widget. See
7134 * gtk_widget_set_can_default().
7136 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7141 gtk_widget_get_can_default (GtkWidget *widget)
7143 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7145 return widget->priv->can_default;
7149 * gtk_widget_has_default:
7150 * @widget: a #GtkWidget
7152 * Determines whether @widget is the current default widget within its
7153 * toplevel. See gtk_widget_set_can_default().
7155 * Return value: %TRUE if @widget is the current default widget within
7156 * its toplevel, %FALSE otherwise
7161 gtk_widget_has_default (GtkWidget *widget)
7163 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7165 return widget->priv->has_default;
7169 _gtk_widget_set_has_default (GtkWidget *widget,
7170 gboolean has_default)
7172 GtkStyleContext *context;
7174 widget->priv->has_default = has_default;
7176 context = gtk_widget_get_style_context (widget);
7179 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7181 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7185 * gtk_widget_grab_default:
7186 * @widget: a #GtkWidget
7188 * Causes @widget to become the default widget. @widget must be able to be
7189 * a default widget; typically you would ensure this yourself
7190 * by calling gtk_widget_set_can_default() with a %TRUE value.
7191 * The default widget is activated when
7192 * the user presses Enter in a window. Default widgets must be
7193 * activatable, that is, gtk_widget_activate() should affect them. Note
7194 * that #GtkEntry widgets require the "activates-default" property
7195 * set to %TRUE before they activate the default widget when Enter
7196 * is pressed and the #GtkEntry is focused.
7199 gtk_widget_grab_default (GtkWidget *widget)
7203 g_return_if_fail (GTK_IS_WIDGET (widget));
7204 g_return_if_fail (gtk_widget_get_can_default (widget));
7206 window = gtk_widget_get_toplevel (widget);
7208 if (window && gtk_widget_is_toplevel (window))
7209 gtk_window_set_default (GTK_WINDOW (window), widget);
7211 g_warning (G_STRLOC ": widget not within a GtkWindow");
7215 * gtk_widget_set_receives_default:
7216 * @widget: a #GtkWidget
7217 * @receives_default: whether or not @widget can be a default widget.
7219 * Specifies whether @widget will be treated as the default widget
7220 * within its toplevel when it has the focus, even if another widget
7223 * See gtk_widget_grab_default() for details about the meaning of
7229 gtk_widget_set_receives_default (GtkWidget *widget,
7230 gboolean receives_default)
7232 g_return_if_fail (GTK_IS_WIDGET (widget));
7234 if (widget->priv->receives_default != receives_default)
7236 widget->priv->receives_default = receives_default;
7238 g_object_notify (G_OBJECT (widget), "receives-default");
7243 * gtk_widget_get_receives_default:
7244 * @widget: a #GtkWidget
7246 * Determines whether @widget is alyways treated as default widget
7247 * withing its toplevel when it has the focus, even if another widget
7250 * See gtk_widget_set_receives_default().
7252 * Return value: %TRUE if @widget acts as default widget when focussed,
7258 gtk_widget_get_receives_default (GtkWidget *widget)
7260 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7262 return widget->priv->receives_default;
7266 * gtk_widget_has_grab:
7267 * @widget: a #GtkWidget
7269 * Determines whether the widget is currently grabbing events, so it
7270 * is the only widget receiving input events (keyboard and mouse).
7272 * See also gtk_grab_add().
7274 * Return value: %TRUE if the widget is in the grab_widgets stack
7279 gtk_widget_has_grab (GtkWidget *widget)
7281 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7283 return widget->priv->has_grab;
7287 _gtk_widget_set_has_grab (GtkWidget *widget,
7290 widget->priv->has_grab = has_grab;
7294 * gtk_widget_device_is_shadowed:
7295 * @widget: a #GtkWidget
7296 * @device: a #GdkDevice
7298 * Returns %TRUE if @device has been shadowed by a GTK+
7299 * device grab on another widget, so it would stop sending
7300 * events to @widget. This may be used in the
7301 * #GtkWidget::grab-notify signal to check for specific
7302 * devices. See gtk_device_grab_add().
7304 * Returns: %TRUE if there is an ongoing grab on @device
7305 * by another #GtkWidget than @widget.
7310 gtk_widget_device_is_shadowed (GtkWidget *widget,
7313 GtkWindowGroup *group;
7314 GtkWidget *grab_widget, *toplevel;
7316 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7317 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7319 if (!gtk_widget_get_realized (widget))
7322 toplevel = gtk_widget_get_toplevel (widget);
7324 if (GTK_IS_WINDOW (toplevel))
7325 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7327 group = gtk_window_get_group (NULL);
7329 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7331 /* Widget not inside the hierarchy of grab_widget */
7333 widget != grab_widget &&
7334 !gtk_widget_is_ancestor (widget, grab_widget))
7337 grab_widget = gtk_window_group_get_current_grab (group);
7338 if (grab_widget && widget != grab_widget &&
7339 !gtk_widget_is_ancestor (widget, grab_widget))
7346 * gtk_widget_set_name:
7347 * @widget: a #GtkWidget
7348 * @name: name for the widget
7350 * Widgets can be named, which allows you to refer to them from a
7351 * CSS file. You can apply a style to widgets with a particular name
7352 * in the CSS file. See the documentation for the CSS syntax (on the
7353 * same page as the docs for #GtkStyleContext).
7355 * Note that the CSS syntax has certain special characters to delimit
7356 * and represent elements in a selector (period, #, >, *...),
7357 * so using these will make your widget impossible to match by name.
7358 * Any combination of alphanumeric symbols, dashes and underscores will
7362 gtk_widget_set_name (GtkWidget *widget,
7365 GtkWidgetPrivate *priv;
7368 g_return_if_fail (GTK_IS_WIDGET (widget));
7370 priv = widget->priv;
7372 new_name = g_strdup (name);
7373 g_free (priv->name);
7374 priv->name = new_name;
7376 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7378 g_object_notify (G_OBJECT (widget), "name");
7382 * gtk_widget_get_name:
7383 * @widget: a #GtkWidget
7385 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7386 * significance of widget names.
7388 * Return value: name of the widget. This string is owned by GTK+ and
7389 * should not be modified or freed
7392 gtk_widget_get_name (GtkWidget *widget)
7394 GtkWidgetPrivate *priv;
7396 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7398 priv = widget->priv;
7402 return G_OBJECT_TYPE_NAME (widget);
7406 gtk_widget_update_state_flags (GtkWidget *widget,
7407 GtkStateFlags flags_to_set,
7408 GtkStateFlags flags_to_unset)
7410 GtkWidgetPrivate *priv;
7412 priv = widget->priv;
7414 /* Handle insensitive first, since it is propagated
7415 * differently throughout the widget hierarchy.
7417 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7418 gtk_widget_set_sensitive (widget, TRUE);
7419 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7420 gtk_widget_set_sensitive (widget, FALSE);
7422 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7423 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7425 if (flags_to_set != 0 || flags_to_unset != 0)
7429 data.flags_to_set = flags_to_set;
7430 data.flags_to_unset = flags_to_unset;
7432 gtk_widget_propagate_state (widget, &data);
7437 * gtk_widget_set_state_flags:
7438 * @widget: a #GtkWidget
7439 * @flags: State flags to turn on
7440 * @clear: Whether to clear state before turning on @flags
7442 * This function is for use in widget implementations. Turns on flag
7443 * values in the current widget state (insensitive, prelighted, etc.).
7445 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7446 * will be propagated down to all non-internal children if @widget is a
7447 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7448 * down to all #GtkContainer children by different means than turning on the
7449 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7450 * gtk_widget_is_sensitive() will make use of these.
7455 gtk_widget_set_state_flags (GtkWidget *widget,
7456 GtkStateFlags flags,
7459 g_return_if_fail (GTK_IS_WIDGET (widget));
7461 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7462 (clear && widget->priv->state_flags == flags))
7466 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7468 gtk_widget_update_state_flags (widget, flags, 0);
7472 * gtk_widget_unset_state_flags:
7473 * @widget: a #GtkWidget
7474 * @flags: State flags to turn off
7476 * This function is for use in widget implementations. Turns off flag
7477 * values for the current widget state (insensitive, prelighted, etc.).
7478 * See gtk_widget_set_state_flags().
7483 gtk_widget_unset_state_flags (GtkWidget *widget,
7484 GtkStateFlags flags)
7486 g_return_if_fail (GTK_IS_WIDGET (widget));
7488 if ((widget->priv->state_flags & flags) == 0)
7491 gtk_widget_update_state_flags (widget, 0, flags);
7495 * gtk_widget_get_state_flags:
7496 * @widget: a #GtkWidget
7498 * Returns the widget state as a flag set. It is worth mentioning
7499 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7500 * returned, that is, also based on parent insensitivity, even if
7501 * @widget itself is sensitive.
7503 * Returns: The state flags for widget
7508 gtk_widget_get_state_flags (GtkWidget *widget)
7510 GtkStateFlags flags;
7512 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7514 flags = widget->priv->state_flags;
7516 if (gtk_widget_has_focus (widget))
7517 flags |= GTK_STATE_FLAG_FOCUSED;
7523 * gtk_widget_set_state:
7524 * @widget: a #GtkWidget
7525 * @state: new state for @widget
7527 * This function is for use in widget implementations. Sets the state
7528 * of a widget (insensitive, prelighted, etc.) Usually you should set
7529 * the state using wrapper functions such as gtk_widget_set_sensitive().
7531 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7534 gtk_widget_set_state (GtkWidget *widget,
7537 GtkStateFlags flags;
7539 if (state == gtk_widget_get_state (widget))
7544 case GTK_STATE_ACTIVE:
7545 flags = GTK_STATE_FLAG_ACTIVE;
7547 case GTK_STATE_PRELIGHT:
7548 flags = GTK_STATE_FLAG_PRELIGHT;
7550 case GTK_STATE_SELECTED:
7551 flags = GTK_STATE_FLAG_SELECTED;
7553 case GTK_STATE_INSENSITIVE:
7554 flags = GTK_STATE_FLAG_INSENSITIVE;
7556 case GTK_STATE_INCONSISTENT:
7557 flags = GTK_STATE_FLAG_INCONSISTENT;
7559 case GTK_STATE_FOCUSED:
7560 flags = GTK_STATE_FLAG_FOCUSED;
7562 case GTK_STATE_NORMAL:
7568 gtk_widget_update_state_flags (widget,
7570 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7571 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7575 * gtk_widget_get_state:
7576 * @widget: a #GtkWidget
7578 * Returns the widget's state. See gtk_widget_set_state().
7580 * Returns: the state of @widget.
7584 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7587 gtk_widget_get_state (GtkWidget *widget)
7589 GtkStateFlags flags;
7591 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7593 flags = gtk_widget_get_state_flags (widget);
7595 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7596 return GTK_STATE_INSENSITIVE;
7597 else if (flags & GTK_STATE_FLAG_ACTIVE)
7598 return GTK_STATE_ACTIVE;
7599 else if (flags & GTK_STATE_FLAG_SELECTED)
7600 return GTK_STATE_SELECTED;
7601 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7602 return GTK_STATE_PRELIGHT;
7604 return GTK_STATE_NORMAL;
7608 * gtk_widget_set_visible:
7609 * @widget: a #GtkWidget
7610 * @visible: whether the widget should be shown or not
7612 * Sets the visibility state of @widget. Note that setting this to
7613 * %TRUE doesn't mean the widget is actually viewable, see
7614 * gtk_widget_get_visible().
7616 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7617 * but is nicer to use when the visibility of the widget depends on
7623 gtk_widget_set_visible (GtkWidget *widget,
7626 g_return_if_fail (GTK_IS_WIDGET (widget));
7628 if (visible != gtk_widget_get_visible (widget))
7631 gtk_widget_show (widget);
7633 gtk_widget_hide (widget);
7638 _gtk_widget_set_visible_flag (GtkWidget *widget,
7641 GtkWidgetPrivate *priv = widget->priv;
7643 priv->visible = visible;
7647 priv->allocation.x = -1;
7648 priv->allocation.y = -1;
7649 priv->allocation.width = 1;
7650 priv->allocation.height = 1;
7655 * gtk_widget_get_visible:
7656 * @widget: a #GtkWidget
7658 * Determines whether the widget is visible. If you want to
7659 * take into account whether the widget's parent is also marked as
7660 * visible, use gtk_widget_is_visible() instead.
7662 * This function does not check if the widget is obscured in any way.
7664 * See gtk_widget_set_visible().
7666 * Return value: %TRUE if the widget is visible
7671 gtk_widget_get_visible (GtkWidget *widget)
7673 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7675 return widget->priv->visible;
7679 * gtk_widget_is_visible:
7680 * @widget: a #GtkWidget
7682 * Determines whether the widget and all its parents are marked as
7685 * This function does not check if the widget is obscured in any way.
7687 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7689 * Return value: %TRUE if the widget and all its parents are visible
7694 gtk_widget_is_visible (GtkWidget *widget)
7696 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7700 GtkWidgetPrivate *priv = widget->priv;
7705 widget = priv->parent;
7712 * gtk_widget_set_has_window:
7713 * @widget: a #GtkWidget
7714 * @has_window: whether or not @widget has a window.
7716 * Specifies whether @widget has a #GdkWindow of its own. Note that
7717 * all realized widgets have a non-%NULL "window" pointer
7718 * (gtk_widget_get_window() never returns a %NULL window when a widget
7719 * is realized), but for many of them it's actually the #GdkWindow of
7720 * one of its parent widgets. Widgets that do not create a %window for
7721 * themselves in #GtkWidget::realize must announce this by
7722 * calling this function with @has_window = %FALSE.
7724 * This function should only be called by widget implementations,
7725 * and they should call it in their init() function.
7730 gtk_widget_set_has_window (GtkWidget *widget,
7731 gboolean has_window)
7733 g_return_if_fail (GTK_IS_WIDGET (widget));
7735 widget->priv->no_window = !has_window;
7739 * gtk_widget_get_has_window:
7740 * @widget: a #GtkWidget
7742 * Determines whether @widget has a #GdkWindow of its own. See
7743 * gtk_widget_set_has_window().
7745 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7750 gtk_widget_get_has_window (GtkWidget *widget)
7752 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7754 return ! widget->priv->no_window;
7758 * gtk_widget_is_toplevel:
7759 * @widget: a #GtkWidget
7761 * Determines whether @widget is a toplevel widget.
7763 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7764 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7767 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7772 gtk_widget_is_toplevel (GtkWidget *widget)
7774 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7776 return widget->priv->toplevel;
7780 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7781 gboolean is_toplevel)
7783 widget->priv->toplevel = is_toplevel;
7787 * gtk_widget_is_drawable:
7788 * @widget: a #GtkWidget
7790 * Determines whether @widget can be drawn to. A widget can be drawn
7791 * to if it is mapped and visible.
7793 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7798 gtk_widget_is_drawable (GtkWidget *widget)
7800 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7802 return (gtk_widget_get_visible (widget) &&
7803 gtk_widget_get_mapped (widget));
7807 * gtk_widget_get_realized:
7808 * @widget: a #GtkWidget
7810 * Determines whether @widget is realized.
7812 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7817 gtk_widget_get_realized (GtkWidget *widget)
7819 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7821 return widget->priv->realized;
7825 * gtk_widget_set_realized:
7826 * @widget: a #GtkWidget
7827 * @realized: %TRUE to mark the widget as realized
7829 * Marks the widget as being realized.
7831 * This function should only ever be called in a derived widget's
7832 * "realize" or "unrealize" implementation.
7837 gtk_widget_set_realized (GtkWidget *widget,
7840 g_return_if_fail (GTK_IS_WIDGET (widget));
7842 widget->priv->realized = realized;
7846 * gtk_widget_get_mapped:
7847 * @widget: a #GtkWidget
7849 * Whether the widget is mapped.
7851 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7856 gtk_widget_get_mapped (GtkWidget *widget)
7858 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7860 return widget->priv->mapped;
7864 * gtk_widget_set_mapped:
7865 * @widget: a #GtkWidget
7866 * @mapped: %TRUE to mark the widget as mapped
7868 * Marks the widget as being realized.
7870 * This function should only ever be called in a derived widget's
7871 * "map" or "unmap" implementation.
7876 gtk_widget_set_mapped (GtkWidget *widget,
7879 g_return_if_fail (GTK_IS_WIDGET (widget));
7881 widget->priv->mapped = mapped;
7885 * gtk_widget_set_app_paintable:
7886 * @widget: a #GtkWidget
7887 * @app_paintable: %TRUE if the application will paint on the widget
7889 * Sets whether the application intends to draw on the widget in
7890 * an #GtkWidget::draw handler.
7892 * This is a hint to the widget and does not affect the behavior of
7893 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7894 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7895 * the effect is to suppress default themed drawing of the widget's
7896 * background. (Children of the widget will still be drawn.) The application
7897 * is then entirely responsible for drawing the widget background.
7899 * Note that the background is still drawn when the widget is mapped.
7902 gtk_widget_set_app_paintable (GtkWidget *widget,
7903 gboolean app_paintable)
7905 g_return_if_fail (GTK_IS_WIDGET (widget));
7907 app_paintable = (app_paintable != FALSE);
7909 if (widget->priv->app_paintable != app_paintable)
7911 widget->priv->app_paintable = app_paintable;
7913 if (gtk_widget_is_drawable (widget))
7914 gtk_widget_queue_draw (widget);
7916 g_object_notify (G_OBJECT (widget), "app-paintable");
7921 * gtk_widget_get_app_paintable:
7922 * @widget: a #GtkWidget
7924 * Determines whether the application intends to draw on the widget in
7925 * an #GtkWidget::draw handler.
7927 * See gtk_widget_set_app_paintable()
7929 * Return value: %TRUE if the widget is app paintable
7934 gtk_widget_get_app_paintable (GtkWidget *widget)
7936 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7938 return widget->priv->app_paintable;
7942 * gtk_widget_set_double_buffered:
7943 * @widget: a #GtkWidget
7944 * @double_buffered: %TRUE to double-buffer a widget
7946 * Widgets are double buffered by default; you can use this function
7947 * to turn off the buffering. "Double buffered" simply means that
7948 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7949 * automatically around expose events sent to the
7950 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7951 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7952 * buffer to the screen. The result is that users see the window
7953 * update in one smooth step, and don't see individual graphics
7954 * primitives being rendered.
7956 * In very simple terms, double buffered widgets don't flicker,
7957 * so you would only use this function to turn off double buffering
7958 * if you had special needs and really knew what you were doing.
7960 * Note: if you turn off double-buffering, you have to handle
7961 * expose events, since even the clearing to the background color or
7962 * pixmap will not happen automatically (as it is done in
7963 * gdk_window_begin_paint_region()).
7966 gtk_widget_set_double_buffered (GtkWidget *widget,
7967 gboolean double_buffered)
7969 g_return_if_fail (GTK_IS_WIDGET (widget));
7971 double_buffered = (double_buffered != FALSE);
7973 if (widget->priv->double_buffered != double_buffered)
7975 widget->priv->double_buffered = double_buffered;
7977 g_object_notify (G_OBJECT (widget), "double-buffered");
7982 * gtk_widget_get_double_buffered:
7983 * @widget: a #GtkWidget
7985 * Determines whether the widget is double buffered.
7987 * See gtk_widget_set_double_buffered()
7989 * Return value: %TRUE if the widget is double buffered
7994 gtk_widget_get_double_buffered (GtkWidget *widget)
7996 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7998 return widget->priv->double_buffered;
8002 * gtk_widget_set_redraw_on_allocate:
8003 * @widget: a #GtkWidget
8004 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
8005 * when it is allocated to a new size. Otherwise, only the
8006 * new portion of the widget will be redrawn.
8008 * Sets whether the entire widget is queued for drawing when its size
8009 * allocation changes. By default, this setting is %TRUE and
8010 * the entire widget is redrawn on every size change. If your widget
8011 * leaves the upper left unchanged when made bigger, turning this
8012 * setting off will improve performance.
8014 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
8015 * off all allocation on resizing: the widget will not even redraw if
8016 * its position changes; this is to allow containers that don't draw
8017 * anything to avoid excess invalidations. If you set this flag on a
8018 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
8019 * you are responsible for invalidating both the old and new allocation
8020 * of the widget when the widget is moved and responsible for invalidating
8021 * regions newly when the widget increases size.
8024 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
8025 gboolean redraw_on_allocate)
8027 g_return_if_fail (GTK_IS_WIDGET (widget));
8029 widget->priv->redraw_on_alloc = redraw_on_allocate;
8033 * gtk_widget_set_sensitive:
8034 * @widget: a #GtkWidget
8035 * @sensitive: %TRUE to make the widget sensitive
8037 * Sets the sensitivity of a widget. A widget is sensitive if the user
8038 * can interact with it. Insensitive widgets are "grayed out" and the
8039 * user can't interact with them. Insensitive widgets are known as
8040 * "inactive", "disabled", or "ghosted" in some other toolkits.
8043 gtk_widget_set_sensitive (GtkWidget *widget,
8046 GtkWidgetPrivate *priv;
8048 g_return_if_fail (GTK_IS_WIDGET (widget));
8050 priv = widget->priv;
8052 sensitive = (sensitive != FALSE);
8054 if (priv->sensitive == sensitive)
8057 priv->sensitive = sensitive;
8059 if (priv->parent == NULL
8060 || gtk_widget_is_sensitive (priv->parent))
8066 data.flags_to_set = 0;
8067 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8071 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8072 data.flags_to_unset = 0;
8075 gtk_widget_propagate_state (widget, &data);
8077 gtk_widget_queue_resize (widget);
8080 g_object_notify (G_OBJECT (widget), "sensitive");
8084 * gtk_widget_get_sensitive:
8085 * @widget: a #GtkWidget
8087 * Returns the widget's sensitivity (in the sense of returning
8088 * the value that has been set using gtk_widget_set_sensitive()).
8090 * The effective sensitivity of a widget is however determined by both its
8091 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8093 * Returns: %TRUE if the widget is sensitive
8098 gtk_widget_get_sensitive (GtkWidget *widget)
8100 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8102 return widget->priv->sensitive;
8106 * gtk_widget_is_sensitive:
8107 * @widget: a #GtkWidget
8109 * Returns the widget's effective sensitivity, which means
8110 * it is sensitive itself and also its parent widget is sensitive
8112 * Returns: %TRUE if the widget is effectively sensitive
8117 gtk_widget_is_sensitive (GtkWidget *widget)
8119 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8121 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8125 * gtk_widget_set_parent:
8126 * @widget: a #GtkWidget
8127 * @parent: parent container
8129 * This function is useful only when implementing subclasses of
8131 * Sets the container as the parent of @widget, and takes care of
8132 * some details such as updating the state and style of the child
8133 * to reflect its new location. The opposite function is
8134 * gtk_widget_unparent().
8137 gtk_widget_set_parent (GtkWidget *widget,
8140 GtkStateFlags parent_flags;
8141 GtkWidgetPrivate *priv;
8144 g_return_if_fail (GTK_IS_WIDGET (widget));
8145 g_return_if_fail (GTK_IS_WIDGET (parent));
8146 g_return_if_fail (widget != parent);
8148 priv = widget->priv;
8150 if (priv->parent != NULL)
8152 g_warning ("Can't set a parent on widget which has a parent\n");
8155 if (gtk_widget_is_toplevel (widget))
8157 g_warning ("Can't set a parent on a toplevel widget\n");
8161 /* keep this function in sync with gtk_menu_attach_to_widget()
8164 g_object_ref_sink (widget);
8166 gtk_widget_push_verify_invariants (widget);
8168 priv->parent = parent;
8170 parent_flags = gtk_widget_get_state_flags (parent);
8172 /* Merge both old state and current parent state,
8173 * making sure to only propagate the right states */
8174 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8175 data.flags_to_unset = 0;
8176 gtk_widget_propagate_state (widget, &data);
8179 gtk_style_context_set_parent (priv->context,
8180 gtk_widget_get_style_context (parent));
8182 _gtk_widget_update_parent_muxer (widget);
8184 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8185 if (priv->parent->priv->anchored)
8186 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8187 g_object_notify (G_OBJECT (widget), "parent");
8189 /* Enforce realized/mapped invariants
8191 if (gtk_widget_get_realized (priv->parent))
8192 gtk_widget_realize (widget);
8194 if (gtk_widget_get_visible (priv->parent) &&
8195 gtk_widget_get_visible (widget))
8197 if (gtk_widget_get_child_visible (widget) &&
8198 gtk_widget_get_mapped (priv->parent))
8199 gtk_widget_map (widget);
8201 gtk_widget_queue_resize (widget);
8204 /* child may cause parent's expand to change, if the child is
8205 * expanded. If child is not expanded, then it can't modify the
8206 * parent's expand. If the child becomes expanded later then it will
8207 * queue compute_expand then. This optimization plus defaulting
8208 * newly-constructed widgets to need_compute_expand=FALSE should
8209 * mean that initially building a widget tree doesn't have to keep
8210 * walking up setting need_compute_expand on parents over and over.
8212 * We can't change a parent to need to expand unless we're visible.
8214 if (gtk_widget_get_visible (widget) &&
8215 (priv->need_compute_expand ||
8216 priv->computed_hexpand ||
8217 priv->computed_vexpand))
8219 gtk_widget_queue_compute_expand (parent);
8222 gtk_widget_propagate_alpha (widget);
8224 gtk_widget_pop_verify_invariants (widget);
8228 * gtk_widget_get_parent:
8229 * @widget: a #GtkWidget
8231 * Returns the parent container of @widget.
8233 * Return value: (transfer none): the parent container of @widget, or %NULL
8236 gtk_widget_get_parent (GtkWidget *widget)
8238 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8240 return widget->priv->parent;
8244 modifier_style_changed (GtkModifierStyle *style,
8247 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8250 static GtkModifierStyle *
8251 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8253 GtkModifierStyle *style;
8255 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8257 if (G_UNLIKELY (!style))
8259 GtkStyleContext *context;
8261 style = _gtk_modifier_style_new ();
8262 g_object_set_qdata_full (G_OBJECT (widget),
8263 quark_modifier_style,
8265 (GDestroyNotify) g_object_unref);
8267 g_signal_connect (style, "changed",
8268 G_CALLBACK (modifier_style_changed), widget);
8270 context = gtk_widget_get_style_context (widget);
8272 gtk_style_context_add_provider (context,
8273 GTK_STYLE_PROVIDER (style),
8274 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8281 * gtk_widget_override_color:
8282 * @widget: a #GtkWidget
8283 * @state: the state for which to set the color
8284 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8285 * of previous calls to gtk_widget_override_color()
8287 * Sets the color to use for a widget.
8289 * All other style values are left untouched.
8292 * This API is mostly meant as a quick way for applications to
8293 * change a widget appearance. If you are developing a widgets
8294 * library and intend this change to be themeable, it is better
8295 * done by setting meaningful CSS classes and regions in your
8296 * widget/container implementation through gtk_style_context_add_class()
8297 * and gtk_style_context_add_region().
8299 * This way, your widget library can install a #GtkCssProvider
8300 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8301 * to provide a default styling for those widgets that need so, and
8302 * this theming may fully overridden by the user's theme.
8305 * Note that for complex widgets this may bring in undesired
8306 * results (such as uniform background color everywhere), in
8307 * these cases it is better to fully style such widgets through a
8308 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8315 gtk_widget_override_color (GtkWidget *widget,
8316 GtkStateFlags state,
8317 const GdkRGBA *color)
8319 GtkModifierStyle *style;
8321 g_return_if_fail (GTK_IS_WIDGET (widget));
8323 style = _gtk_widget_get_modifier_properties (widget);
8324 _gtk_modifier_style_set_color (style, state, color);
8328 * gtk_widget_override_background_color:
8329 * @widget: a #GtkWidget
8330 * @state: the state for which to set the background color
8331 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8332 * of previous calls to gtk_widget_override_background_color()
8334 * Sets the background color to use for a widget.
8336 * All other style values are left untouched.
8337 * See gtk_widget_override_color().
8342 gtk_widget_override_background_color (GtkWidget *widget,
8343 GtkStateFlags state,
8344 const GdkRGBA *color)
8346 GtkModifierStyle *style;
8348 g_return_if_fail (GTK_IS_WIDGET (widget));
8350 style = _gtk_widget_get_modifier_properties (widget);
8351 _gtk_modifier_style_set_background_color (style, state, color);
8355 * gtk_widget_override_font:
8356 * @widget: a #GtkWidget
8357 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8358 * the effect of previous calls to gtk_widget_override_font()
8360 * Sets the font to use for a widget. All other style values are
8361 * left untouched. See gtk_widget_override_color().
8366 gtk_widget_override_font (GtkWidget *widget,
8367 const PangoFontDescription *font_desc)
8369 GtkModifierStyle *style;
8371 g_return_if_fail (GTK_IS_WIDGET (widget));
8373 style = _gtk_widget_get_modifier_properties (widget);
8374 _gtk_modifier_style_set_font (style, font_desc);
8378 * gtk_widget_override_symbolic_color:
8379 * @widget: a #GtkWidget
8380 * @name: the name of the symbolic color to modify
8381 * @color: (allow-none): the color to assign (does not need
8382 * to be allocated), or %NULL to undo the effect of previous
8383 * calls to gtk_widget_override_symbolic_color()
8385 * Sets a symbolic color for a widget.
8387 * All other style values are left untouched.
8388 * See gtk_widget_override_color() for overriding the foreground
8389 * or background color.
8394 gtk_widget_override_symbolic_color (GtkWidget *widget,
8396 const GdkRGBA *color)
8398 GtkModifierStyle *style;
8400 g_return_if_fail (GTK_IS_WIDGET (widget));
8402 style = _gtk_widget_get_modifier_properties (widget);
8403 _gtk_modifier_style_map_color (style, name, color);
8407 * gtk_widget_override_cursor:
8408 * @widget: a #GtkWidget
8409 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8410 * allocated), or %NULL to undo the effect of previous calls to
8411 * of gtk_widget_override_cursor().
8412 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8413 * need to be allocated), or %NULL to undo the effect of previous
8414 * calls to of gtk_widget_override_cursor().
8416 * Sets the cursor color to use in a widget, overriding the
8417 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8418 * style properties. All other style values are left untouched.
8419 * See also gtk_widget_modify_style().
8421 * Note that the underlying properties have the #GdkColor type,
8422 * so the alpha value in @primary and @secondary will be ignored.
8427 gtk_widget_override_cursor (GtkWidget *widget,
8428 const GdkRGBA *cursor,
8429 const GdkRGBA *secondary_cursor)
8431 GtkModifierStyle *style;
8433 g_return_if_fail (GTK_IS_WIDGET (widget));
8435 style = _gtk_widget_get_modifier_properties (widget);
8436 _gtk_modifier_style_set_color_property (style,
8438 "cursor-color", cursor);
8439 _gtk_modifier_style_set_color_property (style,
8441 "secondary-cursor-color",
8446 gtk_widget_real_direction_changed (GtkWidget *widget,
8447 GtkTextDirection previous_direction)
8449 gtk_widget_queue_resize (widget);
8453 gtk_widget_real_style_set (GtkWidget *widget,
8454 GtkStyle *previous_style)
8459 GtkWidget *previous_toplevel;
8460 GdkScreen *previous_screen;
8461 GdkScreen *new_screen;
8462 } HierarchyChangedInfo;
8465 do_screen_change (GtkWidget *widget,
8466 GdkScreen *old_screen,
8467 GdkScreen *new_screen)
8469 if (old_screen != new_screen)
8471 GtkWidgetPrivate *priv = widget->priv;
8475 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8477 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8480 _gtk_tooltip_hide (widget);
8482 if (new_screen && priv->context)
8483 gtk_style_context_set_screen (priv->context, new_screen);
8485 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8490 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8491 gpointer client_data)
8493 GtkWidgetPrivate *priv = widget->priv;
8494 HierarchyChangedInfo *info = client_data;
8495 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8496 (priv->parent && priv->parent->priv->anchored);
8498 if (priv->anchored != new_anchored)
8500 g_object_ref (widget);
8502 priv->anchored = new_anchored;
8504 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8505 do_screen_change (widget, info->previous_screen, info->new_screen);
8507 if (GTK_IS_CONTAINER (widget))
8508 gtk_container_forall (GTK_CONTAINER (widget),
8509 gtk_widget_propagate_hierarchy_changed_recurse,
8512 g_object_unref (widget);
8517 * _gtk_widget_propagate_hierarchy_changed:
8518 * @widget: a #GtkWidget
8519 * @previous_toplevel: Previous toplevel
8521 * Propagates changes in the anchored state to a widget and all
8522 * children, unsetting or setting the %ANCHORED flag, and
8523 * emitting #GtkWidget::hierarchy-changed.
8526 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8527 GtkWidget *previous_toplevel)
8529 GtkWidgetPrivate *priv = widget->priv;
8530 HierarchyChangedInfo info;
8532 info.previous_toplevel = previous_toplevel;
8533 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8535 if (gtk_widget_is_toplevel (widget) ||
8536 (priv->parent && priv->parent->priv->anchored))
8537 info.new_screen = gtk_widget_get_screen (widget);
8539 info.new_screen = NULL;
8541 if (info.previous_screen)
8542 g_object_ref (info.previous_screen);
8543 if (previous_toplevel)
8544 g_object_ref (previous_toplevel);
8546 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8548 if (previous_toplevel)
8549 g_object_unref (previous_toplevel);
8550 if (info.previous_screen)
8551 g_object_unref (info.previous_screen);
8555 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8556 gpointer client_data)
8558 HierarchyChangedInfo *info = client_data;
8560 g_object_ref (widget);
8562 do_screen_change (widget, info->previous_screen, info->new_screen);
8564 if (GTK_IS_CONTAINER (widget))
8565 gtk_container_forall (GTK_CONTAINER (widget),
8566 gtk_widget_propagate_screen_changed_recurse,
8569 g_object_unref (widget);
8573 * gtk_widget_is_composited:
8574 * @widget: a #GtkWidget
8576 * Whether @widget can rely on having its alpha channel
8577 * drawn correctly. On X11 this function returns whether a
8578 * compositing manager is running for @widget's screen.
8580 * Please note that the semantics of this call will change
8581 * in the future if used on a widget that has a composited
8582 * window in its hierarchy (as set by gdk_window_set_composited()).
8584 * Return value: %TRUE if the widget can rely on its alpha
8585 * channel being drawn correctly.
8590 gtk_widget_is_composited (GtkWidget *widget)
8594 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8596 screen = gtk_widget_get_screen (widget);
8598 return gdk_screen_is_composited (screen);
8602 propagate_composited_changed (GtkWidget *widget,
8605 if (GTK_IS_CONTAINER (widget))
8607 gtk_container_forall (GTK_CONTAINER (widget),
8608 propagate_composited_changed,
8612 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8616 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8618 propagate_composited_changed (widget, NULL);
8622 * _gtk_widget_propagate_screen_changed:
8623 * @widget: a #GtkWidget
8624 * @previous_screen: Previous screen
8626 * Propagates changes in the screen for a widget to all
8627 * children, emitting #GtkWidget::screen-changed.
8630 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8631 GdkScreen *previous_screen)
8633 HierarchyChangedInfo info;
8635 info.previous_screen = previous_screen;
8636 info.new_screen = gtk_widget_get_screen (widget);
8638 if (previous_screen)
8639 g_object_ref (previous_screen);
8641 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8643 if (previous_screen)
8644 g_object_unref (previous_screen);
8648 reset_style_recurse (GtkWidget *widget, gpointer data)
8650 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8652 if (GTK_IS_CONTAINER (widget))
8653 gtk_container_forall (GTK_CONTAINER (widget),
8654 reset_style_recurse,
8659 * gtk_widget_reset_style:
8660 * @widget: a #GtkWidget
8662 * Updates the style context of @widget and all descendents
8663 * by updating its widget path. #GtkContainer<!-- -->s may want
8664 * to use this on a child when reordering it in a way that a different
8665 * style might apply to it. See also gtk_container_get_path_for_child().
8670 gtk_widget_reset_style (GtkWidget *widget)
8672 g_return_if_fail (GTK_IS_WIDGET (widget));
8674 reset_style_recurse (widget, NULL);
8676 g_list_foreach (widget->priv->attached_windows,
8677 (GFunc) reset_style_recurse, NULL);
8680 #ifdef G_ENABLE_DEBUG
8682 /* Verify invariants, see docs/widget_system.txt for notes on much of
8683 * this. Invariants may be temporarily broken while we're in the
8684 * process of updating state, of course, so you can only
8685 * verify_invariants() after a given operation is complete.
8686 * Use push/pop_verify_invariants to help with that.
8689 gtk_widget_verify_invariants (GtkWidget *widget)
8693 if (widget->priv->verifying_invariants_count > 0)
8696 parent = widget->priv->parent;
8698 if (widget->priv->mapped)
8700 /* Mapped implies ... */
8702 if (!widget->priv->realized)
8703 g_warning ("%s %p is mapped but not realized",
8704 G_OBJECT_TYPE_NAME (widget), widget);
8706 if (!widget->priv->visible)
8707 g_warning ("%s %p is mapped but not visible",
8708 G_OBJECT_TYPE_NAME (widget), widget);
8710 if (!widget->priv->toplevel)
8712 if (!widget->priv->child_visible)
8713 g_warning ("%s %p is mapped but not child_visible",
8714 G_OBJECT_TYPE_NAME (widget), widget);
8719 /* Not mapped implies... */
8722 /* This check makes sense for normal toplevels, but for
8723 * something like a toplevel that is embedded within a clutter
8724 * state, mapping may depend on external factors.
8726 if (widget->priv->toplevel)
8728 if (widget->priv->visible)
8729 g_warning ("%s %p toplevel is visible but not mapped",
8730 G_OBJECT_TYPE_NAME (widget), widget);
8735 /* Parent related checks aren't possible if parent has
8736 * verifying_invariants_count > 0 because parent needs to recurse
8737 * children first before the invariants will hold.
8739 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8742 parent->priv->realized)
8744 /* Parent realized implies... */
8747 /* This is in widget_system.txt but appears to fail
8748 * because there's no gtk_container_realize() that
8749 * realizes all children... instead we just lazily
8750 * wait for map to fix things up.
8752 if (!widget->priv->realized)
8753 g_warning ("%s %p is realized but child %s %p is not realized",
8754 G_OBJECT_TYPE_NAME (parent), parent,
8755 G_OBJECT_TYPE_NAME (widget), widget);
8758 else if (!widget->priv->toplevel)
8760 /* No parent or parent not realized on non-toplevel implies... */
8762 if (widget->priv->realized && !widget->priv->in_reparent)
8763 g_warning ("%s %p is not realized but child %s %p is realized",
8764 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8765 G_OBJECT_TYPE_NAME (widget), widget);
8769 parent->priv->mapped &&
8770 widget->priv->visible &&
8771 widget->priv->child_visible)
8773 /* Parent mapped and we are visible implies... */
8775 if (!widget->priv->mapped)
8776 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8777 G_OBJECT_TYPE_NAME (parent), parent,
8778 G_OBJECT_TYPE_NAME (widget), widget);
8780 else if (!widget->priv->toplevel)
8782 /* No parent or parent not mapped on non-toplevel implies... */
8784 if (widget->priv->mapped && !widget->priv->in_reparent)
8785 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8786 G_OBJECT_TYPE_NAME (widget), widget,
8787 widget->priv->visible,
8788 widget->priv->child_visible,
8789 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8790 parent ? parent->priv->mapped : FALSE);
8794 if (!widget->priv->realized)
8796 /* Not realized implies... */
8799 /* widget_system.txt says these hold, but they don't. */
8800 if (widget->priv->alloc_needed)
8801 g_warning ("%s %p alloc needed but not realized",
8802 G_OBJECT_TYPE_NAME (widget), widget);
8804 if (widget->priv->width_request_needed)
8805 g_warning ("%s %p width request needed but not realized",
8806 G_OBJECT_TYPE_NAME (widget), widget);
8808 if (widget->priv->height_request_needed)
8809 g_warning ("%s %p height request needed but not realized",
8810 G_OBJECT_TYPE_NAME (widget), widget);
8815 /* The point of this push/pop is that invariants may not hold while
8816 * we're busy making changes. So we only check at the outermost call
8817 * on the call stack, after we finish updating everything.
8820 gtk_widget_push_verify_invariants (GtkWidget *widget)
8822 widget->priv->verifying_invariants_count += 1;
8826 gtk_widget_verify_child_invariants (GtkWidget *widget,
8827 gpointer client_data)
8829 /* We don't recurse further; this is a one-level check. */
8830 gtk_widget_verify_invariants (widget);
8834 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8836 g_assert (widget->priv->verifying_invariants_count > 0);
8838 widget->priv->verifying_invariants_count -= 1;
8840 if (widget->priv->verifying_invariants_count == 0)
8842 gtk_widget_verify_invariants (widget);
8844 if (GTK_IS_CONTAINER (widget))
8846 /* Check one level of children, because our
8847 * push_verify_invariants() will have prevented some of the
8848 * checks. This does not recurse because if recursion is
8849 * needed, it will happen naturally as each child has a
8850 * push/pop on that child. For example if we're recursively
8851 * mapping children, we'll push/pop on each child as we map
8854 gtk_container_forall (GTK_CONTAINER (widget),
8855 gtk_widget_verify_child_invariants,
8860 #endif /* G_ENABLE_DEBUG */
8862 static PangoContext *
8863 gtk_widget_peek_pango_context (GtkWidget *widget)
8865 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8869 * gtk_widget_get_pango_context:
8870 * @widget: a #GtkWidget
8872 * Gets a #PangoContext with the appropriate font map, font description,
8873 * and base direction for this widget. Unlike the context returned
8874 * by gtk_widget_create_pango_context(), this context is owned by
8875 * the widget (it can be used until the screen for the widget changes
8876 * or the widget is removed from its toplevel), and will be updated to
8877 * match any changes to the widget's attributes. This can be tracked
8878 * by using the #GtkWidget::screen-changed signal on the widget.
8880 * Return value: (transfer none): the #PangoContext for the widget.
8883 gtk_widget_get_pango_context (GtkWidget *widget)
8885 PangoContext *context;
8887 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8889 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8892 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8893 g_object_set_qdata_full (G_OBJECT (widget),
8894 quark_pango_context,
8903 update_pango_context (GtkWidget *widget,
8904 PangoContext *context)
8906 PangoFontDescription *font_desc;
8907 GtkStyleContext *style_context;
8909 style_context = gtk_widget_get_style_context (widget);
8910 gtk_style_context_get (style_context,
8911 gtk_widget_get_state_flags (widget),
8915 pango_context_set_font_description (context, font_desc);
8916 pango_context_set_base_dir (context,
8917 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8918 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8920 pango_font_description_free (font_desc);
8924 gtk_widget_update_pango_context (GtkWidget *widget)
8926 PangoContext *context = gtk_widget_peek_pango_context (widget);
8932 update_pango_context (widget, context);
8934 screen = gtk_widget_get_screen_unchecked (widget);
8937 pango_cairo_context_set_resolution (context,
8938 gdk_screen_get_resolution (screen));
8939 pango_cairo_context_set_font_options (context,
8940 gdk_screen_get_font_options (screen));
8946 * gtk_widget_create_pango_context:
8947 * @widget: a #GtkWidget
8949 * Creates a new #PangoContext with the appropriate font map,
8950 * font description, and base direction for drawing text for
8951 * this widget. See also gtk_widget_get_pango_context().
8953 * Return value: (transfer full): the new #PangoContext
8956 gtk_widget_create_pango_context (GtkWidget *widget)
8959 PangoContext *context;
8961 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8963 screen = gtk_widget_get_screen_unchecked (widget);
8966 GTK_NOTE (MULTIHEAD,
8967 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8969 screen = gdk_screen_get_default ();
8972 context = gdk_pango_context_get_for_screen (screen);
8974 update_pango_context (widget, context);
8975 pango_context_set_language (context, gtk_get_default_language ());
8981 * gtk_widget_create_pango_layout:
8982 * @widget: a #GtkWidget
8983 * @text: text to set on the layout (can be %NULL)
8985 * Creates a new #PangoLayout with the appropriate font map,
8986 * font description, and base direction for drawing text for
8989 * If you keep a #PangoLayout created in this way around, you need
8990 * to re-create it when the widget #PangoContext is replaced.
8991 * This can be tracked by using the #GtkWidget::screen-changed signal
8994 * Return value: (transfer full): the new #PangoLayout
8997 gtk_widget_create_pango_layout (GtkWidget *widget,
9000 PangoLayout *layout;
9001 PangoContext *context;
9003 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9005 context = gtk_widget_get_pango_context (widget);
9006 layout = pango_layout_new (context);
9009 pango_layout_set_text (layout, text, -1);
9015 * gtk_widget_render_icon_pixbuf:
9016 * @widget: a #GtkWidget
9017 * @stock_id: a stock ID
9018 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9019 * render at the size of the source and don't scale (if there are
9020 * multiple source sizes, GTK+ picks one of the available sizes).
9022 * A convenience function that uses the theme engine and style
9023 * settings for @widget to look up @stock_id and render it to
9024 * a pixbuf. @stock_id should be a stock icon ID such as
9025 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9026 * such as #GTK_ICON_SIZE_MENU.
9028 * The pixels in the returned #GdkPixbuf are shared with the rest of
9029 * the application and should not be modified. The pixbuf should be freed
9030 * after use with g_object_unref().
9032 * Return value: (transfer full): a new pixbuf, or %NULL if the
9033 * stock ID wasn't known
9038 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9039 const gchar *stock_id,
9042 GtkStyleContext *context;
9043 GtkIconSet *icon_set;
9045 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9046 g_return_val_if_fail (stock_id != NULL, NULL);
9047 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9049 context = gtk_widget_get_style_context (widget);
9050 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9052 if (icon_set == NULL)
9055 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9059 * gtk_widget_set_parent_window:
9060 * @widget: a #GtkWidget.
9061 * @parent_window: the new parent window.
9063 * Sets a non default parent window for @widget.
9065 * For GtkWindow classes, setting a @parent_window effects whether
9066 * the window is a toplevel window or can be embedded into other
9070 * For GtkWindow classes, this needs to be called before the
9071 * window is realized.
9076 gtk_widget_set_parent_window (GtkWidget *widget,
9077 GdkWindow *parent_window)
9079 GdkWindow *old_parent_window;
9081 g_return_if_fail (GTK_IS_WIDGET (widget));
9083 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9084 quark_parent_window);
9086 if (parent_window != old_parent_window)
9090 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9092 if (old_parent_window)
9093 g_object_unref (old_parent_window);
9095 g_object_ref (parent_window);
9097 /* Unset toplevel flag when adding a parent window to a widget,
9098 * this is the primary entry point to allow toplevels to be
9101 #ifdef GDK_WINDOWING_X11
9102 is_plug = GTK_IS_PLUG (widget);
9106 if (GTK_IS_WINDOW (widget) && !is_plug)
9107 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9112 * gtk_widget_get_parent_window:
9113 * @widget: a #GtkWidget.
9115 * Gets @widget's parent window.
9117 * Returns: (transfer none): the parent window of @widget.
9120 gtk_widget_get_parent_window (GtkWidget *widget)
9122 GtkWidgetPrivate *priv;
9123 GdkWindow *parent_window;
9125 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9127 priv = widget->priv;
9129 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9131 return (parent_window != NULL) ? parent_window :
9132 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9137 * gtk_widget_set_child_visible:
9138 * @widget: a #GtkWidget
9139 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9141 * Sets whether @widget should be mapped along with its when its parent
9142 * is mapped and @widget has been shown with gtk_widget_show().
9144 * The child visibility can be set for widget before it is added to
9145 * a container with gtk_widget_set_parent(), to avoid mapping
9146 * children unnecessary before immediately unmapping them. However
9147 * it will be reset to its default state of %TRUE when the widget
9148 * is removed from a container.
9150 * Note that changing the child visibility of a widget does not
9151 * queue a resize on the widget. Most of the time, the size of
9152 * a widget is computed from all visible children, whether or
9153 * not they are mapped. If this is not the case, the container
9154 * can queue a resize itself.
9156 * This function is only useful for container implementations and
9157 * never should be called by an application.
9160 gtk_widget_set_child_visible (GtkWidget *widget,
9161 gboolean is_visible)
9163 GtkWidgetPrivate *priv;
9165 g_return_if_fail (GTK_IS_WIDGET (widget));
9166 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9168 priv = widget->priv;
9170 g_object_ref (widget);
9171 gtk_widget_verify_invariants (widget);
9174 priv->child_visible = TRUE;
9177 GtkWidget *toplevel;
9179 priv->child_visible = FALSE;
9181 toplevel = gtk_widget_get_toplevel (widget);
9182 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9183 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9186 if (priv->parent && gtk_widget_get_realized (priv->parent))
9188 if (gtk_widget_get_mapped (priv->parent) &&
9189 priv->child_visible &&
9190 gtk_widget_get_visible (widget))
9191 gtk_widget_map (widget);
9193 gtk_widget_unmap (widget);
9196 gtk_widget_verify_invariants (widget);
9197 g_object_unref (widget);
9201 * gtk_widget_get_child_visible:
9202 * @widget: a #GtkWidget
9204 * Gets the value set with gtk_widget_set_child_visible().
9205 * If you feel a need to use this function, your code probably
9206 * needs reorganization.
9208 * This function is only useful for container implementations and
9209 * never should be called by an application.
9211 * Return value: %TRUE if the widget is mapped with the parent.
9214 gtk_widget_get_child_visible (GtkWidget *widget)
9216 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9218 return widget->priv->child_visible;
9222 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9224 GtkWidget *toplevel;
9226 toplevel = gtk_widget_get_toplevel (widget);
9228 if (gtk_widget_is_toplevel (toplevel))
9230 if (GTK_IS_WINDOW (toplevel))
9231 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9232 else if (GTK_IS_INVISIBLE (toplevel))
9233 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9240 * gtk_widget_get_screen:
9241 * @widget: a #GtkWidget
9243 * Get the #GdkScreen from the toplevel window associated with
9244 * this widget. This function can only be called after the widget
9245 * has been added to a widget hierarchy with a #GtkWindow
9248 * In general, you should only create screen specific
9249 * resources when a widget has been realized, and you should
9250 * free those resources when the widget is unrealized.
9252 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9257 gtk_widget_get_screen (GtkWidget *widget)
9261 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9263 screen = gtk_widget_get_screen_unchecked (widget);
9270 g_warning (G_STRLOC ": Can't get associated screen"
9271 " for a widget unless it is inside a toplevel GtkWindow\n"
9272 " widget type is %s associated top level type is %s",
9273 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9274 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9276 return gdk_screen_get_default ();
9281 * gtk_widget_has_screen:
9282 * @widget: a #GtkWidget
9284 * Checks whether there is a #GdkScreen is associated with
9285 * this widget. All toplevel widgets have an associated
9286 * screen, and all widgets added into a hierarchy with a toplevel
9287 * window at the top.
9289 * Return value: %TRUE if there is a #GdkScreen associcated
9295 gtk_widget_has_screen (GtkWidget *widget)
9297 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9299 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9303 * gtk_widget_get_display:
9304 * @widget: a #GtkWidget
9306 * Get the #GdkDisplay for the toplevel window associated with
9307 * this widget. This function can only be called after the widget
9308 * has been added to a widget hierarchy with a #GtkWindow at the top.
9310 * In general, you should only create display specific
9311 * resources when a widget has been realized, and you should
9312 * free those resources when the widget is unrealized.
9314 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9319 gtk_widget_get_display (GtkWidget *widget)
9321 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9323 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9327 * gtk_widget_get_root_window:
9328 * @widget: a #GtkWidget
9330 * Get the root window where this widget is located. This function can
9331 * only be called after the widget has been added to a widget
9332 * hierarchy with #GtkWindow at the top.
9334 * The root window is useful for such purposes as creating a popup
9335 * #GdkWindow associated with the window. In general, you should only
9336 * create display specific resources when a widget has been realized,
9337 * and you should free those resources when the widget is unrealized.
9339 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9344 gtk_widget_get_root_window (GtkWidget *widget)
9346 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9348 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9352 * gtk_widget_child_focus:
9353 * @widget: a #GtkWidget
9354 * @direction: direction of focus movement
9356 * This function is used by custom widget implementations; if you're
9357 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9358 * to a particular widget, and gtk_container_set_focus_chain() to
9359 * change the focus tab order. So you may want to investigate those
9360 * functions instead.
9362 * gtk_widget_child_focus() is called by containers as the user moves
9363 * around the window using keyboard shortcuts. @direction indicates
9364 * what kind of motion is taking place (up, down, left, right, tab
9365 * forward, tab backward). gtk_widget_child_focus() emits the
9366 * #GtkWidget::focus signal; widgets override the default handler
9367 * for this signal in order to implement appropriate focus behavior.
9369 * The default ::focus handler for a widget should return %TRUE if
9370 * moving in @direction left the focus on a focusable location inside
9371 * that widget, and %FALSE if moving in @direction moved the focus
9372 * outside the widget. If returning %TRUE, widgets normally
9373 * call gtk_widget_grab_focus() to place the focus accordingly;
9374 * if returning %FALSE, they don't modify the current focus location.
9376 * Return value: %TRUE if focus ended up inside @widget
9379 gtk_widget_child_focus (GtkWidget *widget,
9380 GtkDirectionType direction)
9382 gboolean return_val;
9384 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9386 if (!gtk_widget_get_visible (widget) ||
9387 !gtk_widget_is_sensitive (widget))
9390 /* child widgets must set CAN_FOCUS, containers
9391 * don't have to though.
9393 if (!GTK_IS_CONTAINER (widget) &&
9394 !gtk_widget_get_can_focus (widget))
9397 g_signal_emit (widget,
9398 widget_signals[FOCUS],
9400 direction, &return_val);
9406 * gtk_widget_keynav_failed:
9407 * @widget: a #GtkWidget
9408 * @direction: direction of focus movement
9410 * This function should be called whenever keyboard navigation within
9411 * a single widget hits a boundary. The function emits the
9412 * #GtkWidget::keynav-failed signal on the widget and its return
9413 * value should be interpreted in a way similar to the return value of
9414 * gtk_widget_child_focus():
9416 * When %TRUE is returned, stay in the widget, the failed keyboard
9417 * navigation is Ok and/or there is nowhere we can/should move the
9420 * When %FALSE is returned, the caller should continue with keyboard
9421 * navigation outside the widget, e.g. by calling
9422 * gtk_widget_child_focus() on the widget's toplevel.
9424 * The default ::keynav-failed handler returns %TRUE for
9425 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9426 * values of #GtkDirectionType, it looks at the
9427 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9428 * if the setting is %TRUE. This way the entire user interface
9429 * becomes cursor-navigatable on input devices such as mobile phones
9430 * which only have cursor keys but no tab key.
9432 * Whenever the default handler returns %TRUE, it also calls
9433 * gtk_widget_error_bell() to notify the user of the failed keyboard
9436 * A use case for providing an own implementation of ::keynav-failed
9437 * (either by connecting to it or by overriding it) would be a row of
9438 * #GtkEntry widgets where the user should be able to navigate the
9439 * entire row with the cursor keys, as e.g. known from user interfaces
9440 * that require entering license keys.
9442 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9443 * if the emitting widget should try to handle the keyboard
9444 * navigation attempt in its parent container(s).
9449 gtk_widget_keynav_failed (GtkWidget *widget,
9450 GtkDirectionType direction)
9452 gboolean return_val;
9454 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9456 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9457 direction, &return_val);
9463 * gtk_widget_error_bell:
9464 * @widget: a #GtkWidget
9466 * Notifies the user about an input-related error on this widget.
9467 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9468 * gdk_window_beep(), otherwise it does nothing.
9470 * Note that the effect of gdk_window_beep() can be configured in many
9471 * ways, depending on the windowing backend and the desktop environment
9472 * or window manager that is used.
9477 gtk_widget_error_bell (GtkWidget *widget)
9479 GtkWidgetPrivate *priv;
9480 GtkSettings* settings;
9483 g_return_if_fail (GTK_IS_WIDGET (widget));
9485 priv = widget->priv;
9487 settings = gtk_widget_get_settings (widget);
9491 g_object_get (settings,
9492 "gtk-error-bell", &beep,
9495 if (beep && priv->window)
9496 gdk_window_beep (priv->window);
9500 gtk_widget_set_usize_internal (GtkWidget *widget,
9503 GtkQueueResizeFlags flags)
9505 GtkWidgetAuxInfo *aux_info;
9506 gboolean changed = FALSE;
9508 g_object_freeze_notify (G_OBJECT (widget));
9510 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9512 if (width > -2 && aux_info->width != width)
9514 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9515 g_object_notify (G_OBJECT (widget), "width-request");
9516 aux_info->width = width;
9519 if (height > -2 && aux_info->height != height)
9521 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9522 g_object_notify (G_OBJECT (widget), "height-request");
9523 aux_info->height = height;
9527 if (gtk_widget_get_visible (widget) && changed)
9529 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9530 gtk_widget_queue_resize (widget);
9532 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9535 g_object_thaw_notify (G_OBJECT (widget));
9539 * gtk_widget_set_size_request:
9540 * @widget: a #GtkWidget
9541 * @width: width @widget should request, or -1 to unset
9542 * @height: height @widget should request, or -1 to unset
9544 * Sets the minimum size of a widget; that is, the widget's size
9545 * request will be at least @width by @height. You can use this
9546 * function to force a widget to be larger than it normally would be.
9548 * In most cases, gtk_window_set_default_size() is a better choice for
9549 * toplevel windows than this function; setting the default size will
9550 * still allow users to shrink the window. Setting the size request
9551 * will force them to leave the window at least as large as the size
9552 * request. When dealing with window sizes,
9553 * gtk_window_set_geometry_hints() can be a useful function as well.
9555 * Note the inherent danger of setting any fixed size - themes,
9556 * translations into other languages, different fonts, and user action
9557 * can all change the appropriate size for a given widget. So, it's
9558 * basically impossible to hardcode a size that will always be
9561 * The size request of a widget is the smallest size a widget can
9562 * accept while still functioning well and drawing itself correctly.
9563 * However in some strange cases a widget may be allocated less than
9564 * its requested size, and in many cases a widget may be allocated more
9565 * space than it requested.
9567 * If the size request in a given direction is -1 (unset), then
9568 * the "natural" size request of the widget will be used instead.
9570 * The size request set here does not include any margin from the
9571 * #GtkWidget properties margin-left, margin-right, margin-top, and
9572 * margin-bottom, but it does include pretty much all other padding
9573 * or border properties set by any subclass of #GtkWidget.
9576 gtk_widget_set_size_request (GtkWidget *widget,
9580 g_return_if_fail (GTK_IS_WIDGET (widget));
9581 g_return_if_fail (width >= -1);
9582 g_return_if_fail (height >= -1);
9589 gtk_widget_set_usize_internal (widget, width, height, 0);
9594 * gtk_widget_get_size_request:
9595 * @widget: a #GtkWidget
9596 * @width: (out) (allow-none): return location for width, or %NULL
9597 * @height: (out) (allow-none): return location for height, or %NULL
9599 * Gets the size request that was explicitly set for the widget using
9600 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9601 * @height indicates that that dimension has not been set explicitly
9602 * and the natural requisition of the widget will be used intead. See
9603 * gtk_widget_set_size_request(). To get the size a widget will
9604 * actually request, call gtk_widget_get_preferred_size() instead of
9608 gtk_widget_get_size_request (GtkWidget *widget,
9612 const GtkWidgetAuxInfo *aux_info;
9614 g_return_if_fail (GTK_IS_WIDGET (widget));
9616 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9619 *width = aux_info->width;
9622 *height = aux_info->height;
9626 * _gtk_widget_override_size_request:
9627 * @widget: a #GtkWidget
9628 * @width: new forced minimum width
9629 * @height: new forced minimum height
9630 * @old_width: location to store previous forced minimum width
9631 * @old_height: location to store previous forced minumum height
9633 * Temporarily establishes a forced minimum size for a widget; this
9634 * is used by GtkWindow when calculating the size to add to the
9635 * window's geometry widget. Cached sizes for the widget and its
9636 * parents are invalidated, so that subsequent calls to the size
9637 * negotiation machinery produce the overriden result, but the
9638 * widget is not queued for relayout or redraw. The old size must
9639 * be restored with _gtk_widget_restore_size_request() or things
9643 _gtk_widget_override_size_request (GtkWidget *widget,
9649 gtk_widget_get_size_request (widget, old_width, old_height);
9650 gtk_widget_set_usize_internal (widget, width, height,
9651 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9655 * _gtk_widget_restore_size_request:
9656 * @widget: a #GtkWidget
9657 * @old_width: saved forced minimum size
9658 * @old_height: saved forced minimum size
9660 * Undoes the operation of_gtk_widget_override_size_request().
9663 _gtk_widget_restore_size_request (GtkWidget *widget,
9667 gtk_widget_set_usize_internal (widget, old_width, old_height,
9668 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9672 * gtk_widget_set_events:
9673 * @widget: a #GtkWidget
9674 * @events: event mask
9676 * Sets the event mask (see #GdkEventMask) for a widget. The event
9677 * mask determines which events a widget will receive. Keep in mind
9678 * that different widgets have different default event masks, and by
9679 * changing the event mask you may disrupt a widget's functionality,
9680 * so be careful. This function must be called while a widget is
9681 * unrealized. Consider gtk_widget_add_events() for widgets that are
9682 * already realized, or if you want to preserve the existing event
9683 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9684 * to get events on those widgets, place them inside a #GtkEventBox
9685 * and receive events on the event box.
9688 gtk_widget_set_events (GtkWidget *widget,
9691 g_return_if_fail (GTK_IS_WIDGET (widget));
9692 g_return_if_fail (!gtk_widget_get_realized (widget));
9694 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9695 GINT_TO_POINTER (events));
9696 g_object_notify (G_OBJECT (widget), "events");
9700 * gtk_widget_set_device_events:
9701 * @widget: a #GtkWidget
9702 * @device: a #GdkDevice
9703 * @events: event mask
9705 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9706 * mask determines which events a widget will receive from @device. Keep
9707 * in mind that different widgets have different default event masks, and by
9708 * changing the event mask you may disrupt a widget's functionality,
9709 * so be careful. This function must be called while a widget is
9710 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9711 * already realized, or if you want to preserve the existing event
9712 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9713 * to get events on those widgets, place them inside a #GtkEventBox
9714 * and receive events on the event box.
9719 gtk_widget_set_device_events (GtkWidget *widget,
9721 GdkEventMask events)
9723 GHashTable *device_events;
9725 g_return_if_fail (GTK_IS_WIDGET (widget));
9726 g_return_if_fail (GDK_IS_DEVICE (device));
9727 g_return_if_fail (!gtk_widget_get_realized (widget));
9729 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9731 if (G_UNLIKELY (!device_events))
9733 device_events = g_hash_table_new (NULL, NULL);
9734 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9735 (GDestroyNotify) g_hash_table_unref);
9738 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9742 * gtk_widget_set_device_enabled:
9743 * @widget: a #GtkWidget
9744 * @device: a #GdkDevice
9745 * @enabled: whether to enable the device
9747 * Enables or disables a #GdkDevice to interact with @widget
9748 * and all its children.
9750 * It does so by descending through the #GdkWindow hierarchy
9751 * and enabling the same mask that is has for core events
9752 * (i.e. the one that gdk_window_get_events() returns).
9757 gtk_widget_set_device_enabled (GtkWidget *widget,
9761 GList *enabled_devices;
9763 g_return_if_fail (GTK_IS_WIDGET (widget));
9764 g_return_if_fail (GDK_IS_DEVICE (device));
9766 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9767 enabled_devices = g_list_append (enabled_devices, device);
9769 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9770 enabled_devices, (GDestroyNotify) g_list_free);;
9772 if (gtk_widget_get_realized (widget))
9773 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9777 * gtk_widget_get_device_enabled:
9778 * @widget: a #GtkWidget
9779 * @device: a #GdkDevice
9781 * Returns whether @device can interact with @widget and its
9782 * children. See gtk_widget_set_device_enabled().
9784 * Return value: %TRUE is @device is enabled for @widget
9789 gtk_widget_get_device_enabled (GtkWidget *widget,
9792 GList *enabled_devices;
9794 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9795 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9797 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9799 return g_list_find (enabled_devices, device) != NULL;
9803 gtk_widget_add_events_internal_list (GtkWidget *widget,
9810 for (l = window_list; l != NULL; l = l->next)
9812 GdkWindow *window = l->data;
9815 gdk_window_get_user_data (window, &user_data);
9816 if (user_data == widget)
9821 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9823 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9825 children = gdk_window_get_children (window);
9826 gtk_widget_add_events_internal_list (widget, device, events, children);
9827 g_list_free (children);
9833 gtk_widget_add_events_internal (GtkWidget *widget,
9837 GtkWidgetPrivate *priv = widget->priv;
9840 if (!gtk_widget_get_has_window (widget))
9841 window_list = gdk_window_get_children (priv->window);
9843 window_list = g_list_prepend (NULL, priv->window);
9845 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9847 g_list_free (window_list);
9851 * gtk_widget_add_events:
9852 * @widget: a #GtkWidget
9853 * @events: an event mask, see #GdkEventMask
9855 * Adds the events in the bitfield @events to the event mask for
9856 * @widget. See gtk_widget_set_events() for details.
9859 gtk_widget_add_events (GtkWidget *widget,
9864 g_return_if_fail (GTK_IS_WIDGET (widget));
9866 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9867 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9868 GINT_TO_POINTER (old_events | events));
9870 if (gtk_widget_get_realized (widget))
9872 gtk_widget_add_events_internal (widget, NULL, events);
9873 gtk_widget_update_devices_mask (widget, FALSE);
9876 g_object_notify (G_OBJECT (widget), "events");
9880 * gtk_widget_add_device_events:
9881 * @widget: a #GtkWidget
9882 * @device: a #GdkDevice
9883 * @events: an event mask, see #GdkEventMask
9885 * Adds the device events in the bitfield @events to the event mask for
9886 * @widget. See gtk_widget_set_device_events() for details.
9891 gtk_widget_add_device_events (GtkWidget *widget,
9893 GdkEventMask events)
9895 GdkEventMask old_events;
9896 GHashTable *device_events;
9898 g_return_if_fail (GTK_IS_WIDGET (widget));
9899 g_return_if_fail (GDK_IS_DEVICE (device));
9901 old_events = gtk_widget_get_device_events (widget, device);
9903 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9905 if (G_UNLIKELY (!device_events))
9907 device_events = g_hash_table_new (NULL, NULL);
9908 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9909 (GDestroyNotify) g_hash_table_unref);
9912 g_hash_table_insert (device_events, device,
9913 GUINT_TO_POINTER (old_events | events));
9915 if (gtk_widget_get_realized (widget))
9916 gtk_widget_add_events_internal (widget, device, events);
9918 g_object_notify (G_OBJECT (widget), "events");
9922 * gtk_widget_get_toplevel:
9923 * @widget: a #GtkWidget
9925 * This function returns the topmost widget in the container hierarchy
9926 * @widget is a part of. If @widget has no parent widgets, it will be
9927 * returned as the topmost widget. No reference will be added to the
9928 * returned widget; it should not be unreferenced.
9930 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9931 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9933 * %NULL if @widget wasn't inside a toplevel window, and if the
9934 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9935 * inside the toplevel #GtkWindow. While the second case may
9936 * seem unlikely, it actually happens when a #GtkPlug is embedded
9937 * inside a #GtkSocket within the same application.
9939 * To reliably find the toplevel #GtkWindow, use
9940 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9941 * is set on the result.
9943 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9944 * if (gtk_widget_is_toplevel (toplevel))
9946 * /* Perform action on toplevel. */
9950 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9951 * if there's no ancestor.
9954 gtk_widget_get_toplevel (GtkWidget *widget)
9956 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9958 while (widget->priv->parent)
9959 widget = widget->priv->parent;
9965 * gtk_widget_get_ancestor:
9966 * @widget: a #GtkWidget
9967 * @widget_type: ancestor type
9969 * Gets the first ancestor of @widget with type @widget_type. For example,
9970 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9971 * the first #GtkBox that's an ancestor of @widget. No reference will be
9972 * added to the returned widget; it should not be unreferenced. See note
9973 * about checking for a toplevel #GtkWindow in the docs for
9974 * gtk_widget_get_toplevel().
9976 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9977 * considers @widget to be an ancestor of itself.
9979 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9982 gtk_widget_get_ancestor (GtkWidget *widget,
9985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9987 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9988 widget = widget->priv->parent;
9990 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9997 * gtk_widget_set_visual:
9998 * @widget: a #GtkWidget
9999 * @visual: visual to be used or %NULL to unset a previous one
10001 * Sets the visual that should be used for by widget and its children for
10002 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10003 * returned by gtk_widget_get_screen(), so handling the
10004 * #GtkWidget::screen-changed signal is necessary.
10006 * Setting a new @visual will not cause @widget to recreate its windows,
10007 * so you should call this function before @widget is realized.
10010 gtk_widget_set_visual (GtkWidget *widget,
10013 g_return_if_fail (GTK_IS_WIDGET (widget));
10014 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10017 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10020 g_object_set_qdata_full (G_OBJECT (widget),
10022 g_object_ref (visual),
10027 * gtk_widget_get_visual:
10028 * @widget: a #GtkWidget
10030 * Gets the visual that will be used to render @widget.
10032 * Return value: (transfer none): the visual for @widget
10035 gtk_widget_get_visual (GtkWidget *widget)
10041 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10043 if (gtk_widget_get_has_window (widget) &&
10044 widget->priv->window)
10045 return gdk_window_get_visual (widget->priv->window);
10047 screen = gtk_widget_get_screen (widget);
10049 for (w = widget; w != NULL; w = w->priv->parent)
10051 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10054 if (gdk_visual_get_screen (visual) == screen)
10057 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10058 gtk_widget_get_name (widget));
10062 return gdk_screen_get_system_visual (screen);
10066 * gtk_widget_get_settings:
10067 * @widget: a #GtkWidget
10069 * Gets the settings object holding the settings used for this widget.
10071 * Note that this function can only be called when the #GtkWidget
10072 * is attached to a toplevel, since the settings object is specific
10073 * to a particular #GdkScreen.
10075 * Return value: (transfer none): the relevant #GtkSettings object
10078 gtk_widget_get_settings (GtkWidget *widget)
10080 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10082 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10086 * gtk_widget_get_events:
10087 * @widget: a #GtkWidget
10089 * Returns the event mask for the widget (a bitfield containing flags
10090 * from the #GdkEventMask enumeration). These are the events that the widget
10093 * Return value: event mask for @widget
10096 gtk_widget_get_events (GtkWidget *widget)
10098 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10100 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10104 * gtk_widget_get_device_events:
10105 * @widget: a #GtkWidget
10106 * @device: a #GdkDevice
10108 * Returns the events mask for the widget corresponding to an specific device. These
10109 * are the events that the widget will receive when @device operates on it.
10111 * Returns: device event mask for @widget
10116 gtk_widget_get_device_events (GtkWidget *widget,
10119 GHashTable *device_events;
10121 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10122 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10124 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10126 if (!device_events)
10129 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10133 * gtk_widget_get_pointer:
10134 * @widget: a #GtkWidget
10135 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10136 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10138 * Obtains the location of the mouse pointer in widget coordinates.
10139 * Widget coordinates are a bit odd; for historical reasons, they are
10140 * defined as @widget->window coordinates for widgets that are not
10141 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10142 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10144 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10147 gtk_widget_get_pointer (GtkWidget *widget,
10151 GtkWidgetPrivate *priv;
10153 g_return_if_fail (GTK_IS_WIDGET (widget));
10155 priv = widget->priv;
10162 if (gtk_widget_get_realized (widget))
10164 gdk_window_get_device_position (priv->window,
10165 gdk_device_manager_get_client_pointer (
10166 gdk_display_get_device_manager (
10167 gtk_widget_get_display (widget))),
10170 if (!gtk_widget_get_has_window (widget))
10173 *x -= priv->allocation.x;
10175 *y -= priv->allocation.y;
10181 * gtk_widget_is_ancestor:
10182 * @widget: a #GtkWidget
10183 * @ancestor: another #GtkWidget
10185 * Determines whether @widget is somewhere inside @ancestor, possibly with
10186 * intermediate containers.
10188 * Return value: %TRUE if @ancestor contains @widget as a child,
10189 * grandchild, great grandchild, etc.
10192 gtk_widget_is_ancestor (GtkWidget *widget,
10193 GtkWidget *ancestor)
10195 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10196 g_return_val_if_fail (ancestor != NULL, FALSE);
10200 if (widget->priv->parent == ancestor)
10202 widget = widget->priv->parent;
10208 static GQuark quark_composite_name = 0;
10211 * gtk_widget_set_composite_name:
10212 * @widget: a #GtkWidget.
10213 * @name: the name to set
10215 * Sets a widgets composite name. The widget must be
10216 * a composite child of its parent; see gtk_widget_push_composite_child().
10219 gtk_widget_set_composite_name (GtkWidget *widget,
10222 g_return_if_fail (GTK_IS_WIDGET (widget));
10223 g_return_if_fail (widget->priv->composite_child);
10224 g_return_if_fail (name != NULL);
10226 if (!quark_composite_name)
10227 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10229 g_object_set_qdata_full (G_OBJECT (widget),
10230 quark_composite_name,
10236 * gtk_widget_get_composite_name:
10237 * @widget: a #GtkWidget
10239 * Obtains the composite name of a widget.
10241 * Returns: the composite name of @widget, or %NULL if @widget is not
10242 * a composite child. The string should be freed when it is no
10246 gtk_widget_get_composite_name (GtkWidget *widget)
10248 GtkWidgetPrivate *priv;
10250 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10252 priv = widget->priv;
10254 if (widget->priv->composite_child && priv->parent)
10255 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10262 * gtk_widget_push_composite_child:
10264 * Makes all newly-created widgets as composite children until
10265 * the corresponding gtk_widget_pop_composite_child() call.
10267 * A composite child is a child that's an implementation detail of the
10268 * container it's inside and should not be visible to people using the
10269 * container. Composite children aren't treated differently by GTK (but
10270 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10271 * builders might want to treat them in a different way.
10273 * Here is a simple example:
10275 * gtk_widget_push_composite_child ();
10276 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10277 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10278 * gtk_widget_pop_composite_child ();
10279 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10280 * GTK_WIDGET (scrolled_window));
10281 * g_object_ref (scrolled_window->hscrollbar);
10285 gtk_widget_push_composite_child (void)
10287 composite_child_stack++;
10291 * gtk_widget_pop_composite_child:
10293 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10296 gtk_widget_pop_composite_child (void)
10298 if (composite_child_stack)
10299 composite_child_stack--;
10303 gtk_widget_emit_direction_changed (GtkWidget *widget,
10304 GtkTextDirection old_dir)
10306 GtkTextDirection direction;
10307 GtkStateFlags state;
10309 gtk_widget_update_pango_context (widget);
10311 direction = gtk_widget_get_direction (widget);
10312 state = widget->priv->state_flags;
10313 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10317 case GTK_TEXT_DIR_LTR:
10318 state |= GTK_STATE_FLAG_DIR_LTR;
10321 case GTK_TEXT_DIR_RTL:
10322 state |= GTK_STATE_FLAG_DIR_RTL;
10325 case GTK_TEXT_DIR_NONE:
10327 g_assert_not_reached ();
10331 gtk_widget_set_state_flags (widget, state, TRUE);
10333 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10337 * gtk_widget_set_direction:
10338 * @widget: a #GtkWidget
10339 * @dir: the new direction
10341 * Sets the reading direction on a particular widget. This direction
10342 * controls the primary direction for widgets containing text,
10343 * and also the direction in which the children of a container are
10344 * packed. The ability to set the direction is present in order
10345 * so that correct localization into languages with right-to-left
10346 * reading directions can be done. Generally, applications will
10347 * let the default reading direction present, except for containers
10348 * where the containers are arranged in an order that is explicitely
10349 * visual rather than logical (such as buttons for text justification).
10351 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10352 * set by gtk_widget_set_default_direction() will be used.
10355 gtk_widget_set_direction (GtkWidget *widget,
10356 GtkTextDirection dir)
10358 GtkTextDirection old_dir;
10360 g_return_if_fail (GTK_IS_WIDGET (widget));
10361 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10363 old_dir = gtk_widget_get_direction (widget);
10365 widget->priv->direction = dir;
10367 if (old_dir != gtk_widget_get_direction (widget))
10368 gtk_widget_emit_direction_changed (widget, old_dir);
10372 * gtk_widget_get_direction:
10373 * @widget: a #GtkWidget
10375 * Gets the reading direction for a particular widget. See
10376 * gtk_widget_set_direction().
10378 * Return value: the reading direction for the widget.
10381 gtk_widget_get_direction (GtkWidget *widget)
10383 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10385 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10386 return gtk_default_direction;
10388 return widget->priv->direction;
10392 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10394 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10396 g_object_ref (widget);
10398 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10399 gtk_widget_emit_direction_changed (widget, old_dir);
10401 if (GTK_IS_CONTAINER (widget))
10402 gtk_container_forall (GTK_CONTAINER (widget),
10403 gtk_widget_set_default_direction_recurse,
10406 g_object_unref (widget);
10410 * gtk_widget_set_default_direction:
10411 * @dir: the new default direction. This cannot be
10412 * %GTK_TEXT_DIR_NONE.
10414 * Sets the default reading direction for widgets where the
10415 * direction has not been explicitly set by gtk_widget_set_direction().
10418 gtk_widget_set_default_direction (GtkTextDirection dir)
10420 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10422 if (dir != gtk_default_direction)
10424 GList *toplevels, *tmp_list;
10425 GtkTextDirection old_dir = gtk_default_direction;
10427 gtk_default_direction = dir;
10429 tmp_list = toplevels = gtk_window_list_toplevels ();
10430 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10434 gtk_widget_set_default_direction_recurse (tmp_list->data,
10435 GUINT_TO_POINTER (old_dir));
10436 g_object_unref (tmp_list->data);
10437 tmp_list = tmp_list->next;
10440 g_list_free (toplevels);
10445 * gtk_widget_get_default_direction:
10447 * Obtains the current default reading direction. See
10448 * gtk_widget_set_default_direction().
10450 * Return value: the current default direction.
10453 gtk_widget_get_default_direction (void)
10455 return gtk_default_direction;
10459 gtk_widget_constructed (GObject *object)
10461 GtkWidget *widget = GTK_WIDGET (object);
10462 GtkWidgetPrivate *priv = widget->priv;
10464 /* As strange as it may seem, this may happen on object construction.
10465 * init() implementations of parent types may eventually call this function,
10466 * each with its corresponding GType, which could leave a child
10467 * implementation with a wrong widget type in the widget path
10470 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10472 gtk_widget_path_free (priv->path);
10476 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10480 gtk_widget_dispose (GObject *object)
10482 GtkWidget *widget = GTK_WIDGET (object);
10483 GtkWidgetPrivate *priv = widget->priv;
10486 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10487 else if (gtk_widget_get_visible (widget))
10488 gtk_widget_hide (widget);
10490 priv->visible = FALSE;
10491 if (gtk_widget_get_realized (widget))
10492 gtk_widget_unrealize (widget);
10494 if (!priv->in_destruction)
10496 priv->in_destruction = TRUE;
10497 g_signal_emit (object, widget_signals[DESTROY], 0);
10498 priv->in_destruction = FALSE;
10501 g_clear_object (&priv->muxer);
10503 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10507 gtk_widget_real_destroy (GtkWidget *object)
10509 /* gtk_object_destroy() will already hold a refcount on object */
10510 GtkWidget *widget = GTK_WIDGET (object);
10511 GtkWidgetPrivate *priv = widget->priv;
10513 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10515 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10519 gtk_accessible_set_widget (accessible, NULL);
10520 g_object_unref (accessible);
10524 /* wipe accelerator closures (keep order) */
10525 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10526 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10528 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10529 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10531 gtk_grab_remove (widget);
10534 g_object_unref (priv->style);
10535 priv->style = gtk_widget_get_default_style ();
10536 g_object_ref (priv->style);
10540 gtk_widget_finalize (GObject *object)
10542 GtkWidget *widget = GTK_WIDGET (object);
10543 GtkWidgetPrivate *priv = widget->priv;
10544 GtkWidgetAuxInfo *aux_info;
10545 GtkAccessible *accessible;
10547 gtk_grab_remove (widget);
10549 g_object_unref (priv->style);
10550 priv->style = NULL;
10552 g_free (priv->name);
10554 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10556 gtk_widget_aux_info_destroy (aux_info);
10558 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10560 g_object_unref (accessible);
10563 gtk_widget_path_free (priv->path);
10567 _gtk_style_context_set_widget (priv->context, NULL);
10568 g_object_unref (priv->context);
10571 _gtk_size_request_cache_free (&priv->requests);
10573 if (g_object_is_floating (object))
10574 g_warning ("A floating object was finalized. This means that someone\n"
10575 "called g_object_unref() on an object that had only a floating\n"
10576 "reference; the initial floating reference is not owned by anyone\n"
10577 "and must be removed with g_object_ref_sink().");
10579 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10582 /*****************************************
10583 * gtk_widget_real_map:
10588 *****************************************/
10591 gtk_widget_real_map (GtkWidget *widget)
10593 GtkWidgetPrivate *priv = widget->priv;
10595 g_assert (gtk_widget_get_realized (widget));
10597 if (!gtk_widget_get_mapped (widget))
10599 gtk_widget_set_mapped (widget, TRUE);
10601 if (gtk_widget_get_has_window (widget))
10602 gdk_window_show (priv->window);
10606 /*****************************************
10607 * gtk_widget_real_unmap:
10612 *****************************************/
10615 gtk_widget_real_unmap (GtkWidget *widget)
10617 GtkWidgetPrivate *priv = widget->priv;
10619 if (gtk_widget_get_mapped (widget))
10621 gtk_widget_set_mapped (widget, FALSE);
10623 if (gtk_widget_get_has_window (widget))
10624 gdk_window_hide (priv->window);
10628 /*****************************************
10629 * gtk_widget_real_realize:
10634 *****************************************/
10637 gtk_widget_real_realize (GtkWidget *widget)
10639 GtkWidgetPrivate *priv = widget->priv;
10641 g_assert (!gtk_widget_get_has_window (widget));
10643 gtk_widget_set_realized (widget, TRUE);
10646 priv->window = gtk_widget_get_parent_window (widget);
10647 g_object_ref (priv->window);
10651 /*****************************************
10652 * gtk_widget_real_unrealize:
10657 *****************************************/
10660 gtk_widget_real_unrealize (GtkWidget *widget)
10662 GtkWidgetPrivate *priv = widget->priv;
10664 g_assert (!widget->priv->mapped);
10666 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10669 /* We must do unrealize child widget BEFORE container widget.
10670 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10671 * So, unrealizing container widget bofore its children causes the problem
10672 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10675 if (GTK_IS_CONTAINER (widget))
10676 gtk_container_forall (GTK_CONTAINER (widget),
10677 (GtkCallback) gtk_widget_unrealize,
10680 if (gtk_widget_get_has_window (widget))
10682 gtk_widget_unregister_window (widget, priv->window);
10683 gdk_window_destroy (priv->window);
10684 priv->window = NULL;
10688 g_object_unref (priv->window);
10689 priv->window = NULL;
10692 gtk_selection_remove_all (widget);
10694 gtk_widget_set_realized (widget, FALSE);
10698 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10699 GtkOrientation orientation,
10700 gint *minimum_size,
10701 gint *natural_size)
10703 const GtkWidgetAuxInfo *aux_info;
10705 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10707 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10708 aux_info->width > 0)
10710 *minimum_size = MAX (*minimum_size, aux_info->width);
10712 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10713 aux_info->height > 0)
10715 *minimum_size = MAX (*minimum_size, aux_info->height);
10718 /* Fix it if set_size_request made natural size smaller than min size.
10719 * This would also silently fix broken widgets, but we warn about them
10720 * in gtksizerequest.c when calling their size request vfuncs.
10722 *natural_size = MAX (*natural_size, *minimum_size);
10724 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10726 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10727 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10731 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10732 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10737 * _gtk_widget_peek_request_cache:
10739 * Returns the address of the widget's request cache (strictly for
10740 * internal use in gtksizerequest.c)
10742 * Return value: the address of @widget's size request cache.
10745 _gtk_widget_peek_request_cache (GtkWidget *widget)
10747 /* Don't bother slowing things down with the return_if_fail guards here */
10748 return &widget->priv->requests;
10752 * _gtk_widget_set_device_window:
10753 * @widget: a #GtkWidget
10754 * @device: a #GdkDevice
10755 * @window: the new device window
10757 * Sets pointer window for @widget and @device.
10758 * Does not ref @window.
10761 _gtk_widget_set_device_window (GtkWidget *widget,
10765 GHashTable *device_window;
10767 g_return_if_fail (GTK_IS_WIDGET (widget));
10768 g_return_if_fail (GDK_IS_DEVICE (device));
10769 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10771 if (!gtk_widget_get_mapped (widget))
10774 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10776 if (!device_window && window)
10778 device_window = g_hash_table_new (NULL, NULL);
10779 g_object_set_qdata_full (G_OBJECT (widget),
10780 quark_pointer_window,
10782 (GDestroyNotify) g_hash_table_destroy);
10786 g_hash_table_insert (device_window, device, window);
10787 else if (device_window)
10789 g_hash_table_remove (device_window, device);
10791 if (g_hash_table_size (device_window) == 0)
10792 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10797 * _gtk_widget_get_device_window:
10798 * @widget: a #GtkWidget
10799 * @device: a #GdkDevice
10801 * Return value: the device window set on @widget, or %NULL
10804 _gtk_widget_get_device_window (GtkWidget *widget,
10807 GHashTable *device_window;
10809 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10810 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10812 if (!gtk_widget_get_mapped (widget))
10815 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10817 if (!device_window)
10820 return g_hash_table_lookup (device_window, device);
10824 * _gtk_widget_list_devices:
10825 * @widget: a #GtkWidget
10827 * Returns the list of #GdkDevices that is currently on top
10828 * of any window belonging to @widget.
10829 * Free the list with g_list_free(), the elements are owned
10830 * by GTK+ and must not be freed.
10833 _gtk_widget_list_devices (GtkWidget *widget)
10835 GHashTableIter iter;
10836 GHashTable *device_window;
10837 GList *devices = NULL;
10838 gpointer key, value;
10840 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10842 if (!gtk_widget_get_mapped (widget))
10845 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10847 if (G_UNLIKELY (!device_window))
10850 g_hash_table_iter_init (&iter, device_window);
10852 while (g_hash_table_iter_next (&iter, &key, &value))
10853 devices = g_list_prepend (devices, key);
10859 synth_crossing (GtkWidget *widget,
10863 GdkCrossingMode mode,
10864 GdkNotifyType detail)
10868 event = gdk_event_new (type);
10870 event->crossing.window = g_object_ref (window);
10871 event->crossing.send_event = TRUE;
10872 event->crossing.subwindow = g_object_ref (window);
10873 event->crossing.time = GDK_CURRENT_TIME;
10874 event->crossing.x = event->crossing.y = 0;
10875 event->crossing.x_root = event->crossing.y_root = 0;
10876 event->crossing.mode = mode;
10877 event->crossing.detail = detail;
10878 event->crossing.focus = FALSE;
10879 event->crossing.state = 0;
10880 gdk_event_set_device (event, device);
10883 widget = gtk_get_event_widget (event);
10886 gtk_widget_event_internal (widget, event);
10888 gdk_event_free (event);
10892 * _gtk_widget_synthesize_crossing:
10893 * @from: the #GtkWidget the virtual pointer is leaving.
10894 * @to: the #GtkWidget the virtual pointer is moving to.
10895 * @mode: the #GdkCrossingMode to place on the synthesized events.
10897 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10899 * The real pointer window is the window that most recently received an enter notify
10900 * event. Windows that don't select for crossing events can't become the real
10901 * poiner window. The real pointer widget that owns the real pointer window. The
10902 * effective pointer window is the same as the real pointer window unless the real
10903 * pointer widget is either insensitive or there is a grab on a widget that is not
10904 * an ancestor of the real pointer widget (in which case the effective pointer
10905 * window should be the root window).
10907 * When the effective pointer window is the same as the real poiner window, we
10908 * receive crossing events from the windowing system. When the effective pointer
10909 * window changes to become different from the real pointer window we synthesize
10910 * crossing events, attempting to follow X protocol rules:
10912 * When the root window becomes the effective pointer window:
10913 * - leave notify on real pointer window, detail Ancestor
10914 * - leave notify on all of its ancestors, detail Virtual
10915 * - enter notify on root window, detail Inferior
10917 * When the root window ceases to be the effective pointer window:
10918 * - leave notify on root window, detail Inferior
10919 * - enter notify on all ancestors of real pointer window, detail Virtual
10920 * - enter notify on real pointer window, detail Ancestor
10923 _gtk_widget_synthesize_crossing (GtkWidget *from,
10926 GdkCrossingMode mode)
10928 GdkWindow *from_window = NULL, *to_window = NULL;
10930 g_return_if_fail (from != NULL || to != NULL);
10934 from_window = _gtk_widget_get_device_window (from, device);
10937 from_window = from->priv->window;
10942 to_window = _gtk_widget_get_device_window (to, device);
10945 to_window = to->priv->window;
10948 if (from_window == NULL && to_window == NULL)
10950 else if (from_window != NULL && to_window == NULL)
10952 GList *from_ancestors = NULL, *list;
10953 GdkWindow *from_ancestor = from_window;
10955 while (from_ancestor != NULL)
10957 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10958 if (from_ancestor == NULL)
10960 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10963 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10964 device, mode, GDK_NOTIFY_ANCESTOR);
10965 for (list = g_list_last (from_ancestors); list; list = list->prev)
10967 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10968 device, mode, GDK_NOTIFY_VIRTUAL);
10971 /* XXX: enter/inferior on root window? */
10973 g_list_free (from_ancestors);
10975 else if (from_window == NULL && to_window != NULL)
10977 GList *to_ancestors = NULL, *list;
10978 GdkWindow *to_ancestor = to_window;
10980 while (to_ancestor != NULL)
10982 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10983 if (to_ancestor == NULL)
10985 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10988 /* XXX: leave/inferior on root window? */
10990 for (list = to_ancestors; list; list = list->next)
10992 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10993 device, mode, GDK_NOTIFY_VIRTUAL);
10995 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10996 device, mode, GDK_NOTIFY_ANCESTOR);
10998 g_list_free (to_ancestors);
11000 else if (from_window == to_window)
11004 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11005 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11007 while (from_ancestor != NULL || to_ancestor != NULL)
11009 if (from_ancestor != NULL)
11011 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11012 if (from_ancestor == to_window)
11015 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11017 if (to_ancestor != NULL)
11019 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11020 if (to_ancestor == from_window)
11023 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11026 if (to_ancestor == from_window)
11028 if (mode != GDK_CROSSING_GTK_UNGRAB)
11029 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11030 device, mode, GDK_NOTIFY_INFERIOR);
11031 for (list = to_ancestors; list; list = list->next)
11032 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11033 device, mode, GDK_NOTIFY_VIRTUAL);
11034 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11035 device, mode, GDK_NOTIFY_ANCESTOR);
11037 else if (from_ancestor == to_window)
11039 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11040 device, mode, GDK_NOTIFY_ANCESTOR);
11041 for (list = g_list_last (from_ancestors); list; list = list->prev)
11043 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11044 device, mode, GDK_NOTIFY_VIRTUAL);
11046 if (mode != GDK_CROSSING_GTK_GRAB)
11047 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11048 device, mode, GDK_NOTIFY_INFERIOR);
11052 while (from_ancestors != NULL && to_ancestors != NULL
11053 && from_ancestors->data == to_ancestors->data)
11055 from_ancestors = g_list_delete_link (from_ancestors,
11057 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11060 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11061 device, mode, GDK_NOTIFY_NONLINEAR);
11063 for (list = g_list_last (from_ancestors); list; list = list->prev)
11065 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11066 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11068 for (list = to_ancestors; list; list = list->next)
11070 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11071 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11073 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11074 device, mode, GDK_NOTIFY_NONLINEAR);
11076 g_list_free (from_ancestors);
11077 g_list_free (to_ancestors);
11082 gtk_widget_propagate_state (GtkWidget *widget,
11083 GtkStateData *data)
11085 GtkWidgetPrivate *priv = widget->priv;
11086 GtkStateFlags new_flags, old_flags = priv->state_flags;
11087 GtkStateType old_state;
11089 old_state = gtk_widget_get_state (widget);
11091 priv->state_flags |= data->flags_to_set;
11092 priv->state_flags &= ~(data->flags_to_unset);
11094 /* make insensitivity unoverridable */
11095 if (!priv->sensitive)
11096 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11098 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11102 window = gtk_widget_get_toplevel (widget);
11104 if (window && gtk_widget_is_toplevel (window))
11105 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11108 new_flags = priv->state_flags;
11110 if (old_flags != new_flags)
11112 g_object_ref (widget);
11114 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11115 gtk_grab_remove (widget);
11117 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11119 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11120 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11122 if (!priv->shadowed &&
11123 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11125 GList *event_windows = NULL;
11126 GList *devices, *d;
11128 devices = _gtk_widget_list_devices (widget);
11130 for (d = devices; d; d = d->next)
11136 window = _gtk_widget_get_device_window (widget, device);
11138 /* Do not propagate more than once to the
11139 * same window if non-multidevice aware.
11141 if (!gdk_window_get_support_multidevice (window) &&
11142 g_list_find (event_windows, window))
11145 if (!gtk_widget_is_sensitive (widget))
11146 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11147 GDK_CROSSING_STATE_CHANGED);
11149 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11150 GDK_CROSSING_STATE_CHANGED);
11152 event_windows = g_list_prepend (event_windows, window);
11155 g_list_free (event_windows);
11156 g_list_free (devices);
11159 if (GTK_IS_CONTAINER (widget))
11161 GtkStateData child_data;
11163 /* Make sure to only propate the right states further */
11164 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11165 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11167 gtk_container_forall (GTK_CONTAINER (widget),
11168 (GtkCallback) gtk_widget_propagate_state,
11172 g_object_unref (widget);
11176 static const GtkWidgetAuxInfo default_aux_info = {
11184 * gtk_widget_get_aux_info:
11185 * @widget: a #GtkWidget
11186 * @create: if %TRUE, create the structure if it doesn't exist
11188 * Get the #GtkWidgetAuxInfo structure for the widget.
11190 * Return value: the #GtkAuxInfo structure for the widget, or
11191 * %NULL if @create is %FALSE and one doesn't already exist.
11193 static GtkWidgetAuxInfo *
11194 gtk_widget_get_aux_info (GtkWidget *widget,
11197 GtkWidgetAuxInfo *aux_info;
11199 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11200 if (!aux_info && create)
11202 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11204 *aux_info = default_aux_info;
11206 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11212 static const GtkWidgetAuxInfo*
11213 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11215 GtkWidgetAuxInfo *aux_info;
11217 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11218 if (aux_info == NULL)
11220 return &default_aux_info;
11228 /*****************************************
11229 * gtk_widget_aux_info_destroy:
11234 *****************************************/
11237 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11239 g_slice_free (GtkWidgetAuxInfo, aux_info);
11243 * gtk_widget_shape_combine_region:
11244 * @widget: a #GtkWidget
11245 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11247 * Sets a shape for this widget's GDK window. This allows for
11248 * transparent windows etc., see gdk_window_shape_combine_region()
11249 * for more information.
11254 gtk_widget_shape_combine_region (GtkWidget *widget,
11255 cairo_region_t *region)
11257 GtkWidgetPrivate *priv;
11259 g_return_if_fail (GTK_IS_WIDGET (widget));
11260 /* set_shape doesn't work on widgets without gdk window */
11261 g_return_if_fail (gtk_widget_get_has_window (widget));
11263 priv = widget->priv;
11265 if (region == NULL)
11267 priv->has_shape_mask = FALSE;
11270 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11272 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11276 priv->has_shape_mask = TRUE;
11278 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11279 cairo_region_copy (region),
11280 (GDestroyNotify) cairo_region_destroy);
11282 /* set shape if widget has a gdk window already.
11283 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11286 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11291 * gtk_widget_input_shape_combine_region:
11292 * @widget: a #GtkWidget
11293 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11295 * Sets an input shape for this widget's GDK window. This allows for
11296 * windows which react to mouse click in a nonrectangular region, see
11297 * gdk_window_input_shape_combine_region() for more information.
11302 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11303 cairo_region_t *region)
11305 GtkWidgetPrivate *priv;
11307 g_return_if_fail (GTK_IS_WIDGET (widget));
11308 /* set_shape doesn't work on widgets without gdk window */
11309 g_return_if_fail (gtk_widget_get_has_window (widget));
11311 priv = widget->priv;
11313 if (region == NULL)
11316 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11318 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11322 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11323 cairo_region_copy (region),
11324 (GDestroyNotify) cairo_region_destroy);
11326 /* set shape if widget has a gdk window already.
11327 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11330 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11335 /* style properties
11339 * gtk_widget_class_install_style_property_parser: (skip)
11340 * @klass: a #GtkWidgetClass
11341 * @pspec: the #GParamSpec for the style property
11342 * @parser: the parser for the style property
11344 * Installs a style property on a widget class.
11347 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11349 GtkRcPropertyParser parser)
11351 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11352 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11353 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11354 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11356 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11358 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11359 G_OBJECT_CLASS_NAME (klass),
11364 g_param_spec_ref_sink (pspec);
11365 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11366 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11370 * gtk_widget_class_install_style_property:
11371 * @klass: a #GtkWidgetClass
11372 * @pspec: the #GParamSpec for the property
11374 * Installs a style property on a widget class. The parser for the
11375 * style property is determined by the value type of @pspec.
11378 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11381 GtkRcPropertyParser parser;
11383 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11384 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11386 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11388 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11392 * gtk_widget_class_find_style_property:
11393 * @klass: a #GtkWidgetClass
11394 * @property_name: the name of the style property to find
11396 * Finds a style property of a widget class by name.
11398 * Returns: (transfer none): the #GParamSpec of the style property or
11399 * %NULL if @class has no style property with that name.
11404 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11405 const gchar *property_name)
11407 g_return_val_if_fail (property_name != NULL, NULL);
11409 return g_param_spec_pool_lookup (style_property_spec_pool,
11411 G_OBJECT_CLASS_TYPE (klass),
11416 * gtk_widget_class_list_style_properties:
11417 * @klass: a #GtkWidgetClass
11418 * @n_properties: location to return the number of style properties found
11420 * Returns all style properties of a widget class.
11422 * Returns: (array length=n_properties) (transfer container): a
11423 * newly allocated array of #GParamSpec*. The array must be
11424 * freed with g_free().
11429 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11430 guint *n_properties)
11432 GParamSpec **pspecs;
11435 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11436 G_OBJECT_CLASS_TYPE (klass),
11445 * gtk_widget_style_get_property:
11446 * @widget: a #GtkWidget
11447 * @property_name: the name of a style property
11448 * @value: location to return the property value
11450 * Gets the value of a style property of @widget.
11453 gtk_widget_style_get_property (GtkWidget *widget,
11454 const gchar *property_name,
11459 g_return_if_fail (GTK_IS_WIDGET (widget));
11460 g_return_if_fail (property_name != NULL);
11461 g_return_if_fail (G_IS_VALUE (value));
11463 g_object_ref (widget);
11464 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11466 G_OBJECT_TYPE (widget),
11469 g_warning ("%s: widget class `%s' has no property named `%s'",
11471 G_OBJECT_TYPE_NAME (widget),
11475 GtkStyleContext *context;
11476 const GValue *peek_value;
11477 GtkStateFlags state;
11479 context = gtk_widget_get_style_context (widget);
11480 state = gtk_widget_get_state_flags (widget);
11482 peek_value = _gtk_style_context_peek_style_property (context,
11483 G_OBJECT_TYPE (widget),
11486 /* auto-conversion of the caller's value type
11488 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11489 g_value_copy (peek_value, value);
11490 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11491 g_value_transform (peek_value, value);
11493 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11495 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11496 G_VALUE_TYPE_NAME (value));
11498 g_object_unref (widget);
11502 * gtk_widget_style_get_valist:
11503 * @widget: a #GtkWidget
11504 * @first_property_name: the name of the first property to get
11505 * @var_args: a <type>va_list</type> of pairs of property names and
11506 * locations to return the property values, starting with the location
11507 * for @first_property_name.
11509 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11513 gtk_widget_style_get_valist (GtkWidget *widget,
11514 const gchar *first_property_name,
11517 GtkStyleContext *context;
11518 GtkStateFlags state;
11521 g_return_if_fail (GTK_IS_WIDGET (widget));
11523 g_object_ref (widget);
11524 context = gtk_widget_get_style_context (widget);
11525 state = gtk_widget_get_state_flags (widget);
11527 name = first_property_name;
11530 const GValue *peek_value;
11534 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11536 G_OBJECT_TYPE (widget),
11540 g_warning ("%s: widget class `%s' has no property named `%s'",
11542 G_OBJECT_TYPE_NAME (widget),
11546 /* style pspecs are always readable so we can spare that check here */
11548 peek_value = _gtk_style_context_peek_style_property (context,
11549 G_OBJECT_TYPE (widget),
11552 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11555 g_warning ("%s: %s", G_STRLOC, error);
11560 name = va_arg (var_args, gchar*);
11563 g_object_unref (widget);
11567 * gtk_widget_style_get:
11568 * @widget: a #GtkWidget
11569 * @first_property_name: the name of the first property to get
11570 * @...: pairs of property names and locations to return the
11571 * property values, starting with the location for
11572 * @first_property_name, terminated by %NULL.
11574 * Gets the values of a multiple style properties of @widget.
11577 gtk_widget_style_get (GtkWidget *widget,
11578 const gchar *first_property_name,
11583 g_return_if_fail (GTK_IS_WIDGET (widget));
11585 va_start (var_args, first_property_name);
11586 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11591 * gtk_requisition_new:
11593 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11595 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11596 * be freed with gtk_requisition_free().
11601 gtk_requisition_new (void)
11603 return g_slice_new0 (GtkRequisition);
11607 * gtk_requisition_copy:
11608 * @requisition: a #GtkRequisition
11610 * Copies a #GtkRequisition.
11612 * Returns: a copy of @requisition
11615 gtk_requisition_copy (const GtkRequisition *requisition)
11617 return g_slice_dup (GtkRequisition, requisition);
11621 * gtk_requisition_free:
11622 * @requisition: a #GtkRequisition
11624 * Frees a #GtkRequisition.
11627 gtk_requisition_free (GtkRequisition *requisition)
11629 g_slice_free (GtkRequisition, requisition);
11632 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11633 gtk_requisition_copy,
11634 gtk_requisition_free)
11637 * gtk_widget_class_set_accessible_type:
11638 * @widget_class: class to set the accessible type for
11639 * @type: The object type that implements the accessible for @widget_class
11641 * Sets the type to be used for creating accessibles for widgets of
11642 * @widget_class. The given @type must be a subtype of the type used for
11643 * accessibles of the parent class.
11645 * This function should only be called from class init functions of widgets.
11650 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11653 GtkWidgetClassPrivate *priv;
11655 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11656 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11658 priv = widget_class->priv;
11660 priv->accessible_type = type;
11661 /* reset this - honoring the type's role is better. */
11662 priv->accessible_role = ATK_ROLE_INVALID;
11666 * gtk_widget_class_set_accessible_role:
11667 * @widget_class: class to set the accessible role for
11668 * @role: The role to use for accessibles created for @widget_class
11670 * Sets the default #AtkRole to be set on accessibles created for
11671 * widgets of @widget_class. Accessibles may decide to not honor this
11672 * setting if their role reporting is more refined. Calls to
11673 * gtk_widget_class_set_accessible_type() will reset this value.
11675 * In cases where you want more fine-grained control over the role of
11676 * accessibles created for @widget_class, you should provide your own
11677 * accessible type and use gtk_widget_class_set_accessible_type()
11680 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11681 * and the accessible's default role will be used instead.
11683 * This function should only be called from class init functions of widgets.
11688 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11691 GtkWidgetClassPrivate *priv;
11693 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11695 priv = widget_class->priv;
11697 priv->accessible_role = role;
11701 * _gtk_widget_peek_accessible:
11702 * @widget: a #GtkWidget
11704 * Gets the accessible for @widget, if it has been created yet.
11705 * Otherwise, this function returns %NULL. If the @widget's implementation
11706 * does not use the default way to create accessibles, %NULL will always be
11709 * Returns: the accessible for @widget or %NULL if none has been
11713 _gtk_widget_peek_accessible (GtkWidget *widget)
11715 return g_object_get_qdata (G_OBJECT (widget),
11716 quark_accessible_object);
11720 * gtk_widget_get_accessible:
11721 * @widget: a #GtkWidget
11723 * Returns the accessible object that describes the widget to an
11724 * assistive technology.
11726 * If accessibility support is not available, this #AtkObject
11727 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11728 * implementation is available for the widget instance in question,
11729 * it will inherit an #AtkObject implementation from the first ancestor
11730 * class for which such an implementation is defined.
11732 * The documentation of the
11733 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11734 * library contains more information about accessible objects and their uses.
11736 * Returns: (transfer none): the #AtkObject associated with @widget
11739 gtk_widget_get_accessible (GtkWidget *widget)
11741 GtkWidgetClass *klass;
11743 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11745 klass = GTK_WIDGET_GET_CLASS (widget);
11747 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11749 return klass->get_accessible (widget);
11753 gtk_widget_real_get_accessible (GtkWidget *widget)
11755 AtkObject* accessible;
11757 accessible = g_object_get_qdata (G_OBJECT (widget),
11758 quark_accessible_object);
11761 GtkWidgetClass *widget_class;
11762 GtkWidgetClassPrivate *priv;
11763 AtkObjectFactory *factory;
11764 AtkRegistry *default_registry;
11766 widget_class = GTK_WIDGET_GET_CLASS (widget);
11767 priv = widget_class->priv;
11769 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11771 default_registry = atk_get_default_registry ();
11772 factory = atk_registry_get_factory (default_registry,
11773 G_TYPE_FROM_INSTANCE (widget));
11775 atk_object_factory_create_accessible (factory,
11776 G_OBJECT (widget));
11778 if (priv->accessible_role != ATK_ROLE_INVALID)
11779 atk_object_set_role (accessible, priv->accessible_role);
11781 g_object_set_qdata (G_OBJECT (widget),
11782 quark_accessible_object,
11787 accessible = g_object_new (priv->accessible_type,
11790 if (priv->accessible_role != ATK_ROLE_INVALID)
11791 atk_object_set_role (accessible, priv->accessible_role);
11793 g_object_set_qdata (G_OBJECT (widget),
11794 quark_accessible_object,
11797 atk_object_initialize (accessible, widget);
11799 /* Set the role again, since we don't want a role set
11800 * in some parent initialize() function to override
11803 if (priv->accessible_role != ATK_ROLE_INVALID)
11804 atk_object_set_role (accessible, priv->accessible_role);
11811 * Initialize a AtkImplementorIface instance's virtual pointers as
11812 * appropriate to this implementor's class (GtkWidget).
11815 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11817 iface->ref_accessible = gtk_widget_ref_accessible;
11821 gtk_widget_ref_accessible (AtkImplementor *implementor)
11823 AtkObject *accessible;
11825 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11827 g_object_ref (accessible);
11832 * Expand flag management
11836 gtk_widget_update_computed_expand (GtkWidget *widget)
11838 GtkWidgetPrivate *priv;
11840 priv = widget->priv;
11842 if (priv->need_compute_expand)
11846 if (priv->hexpand_set)
11851 if (priv->vexpand_set)
11856 /* we don't need to use compute_expand if both expands are
11857 * forced by the app
11859 if (!(priv->hexpand_set && priv->vexpand_set))
11861 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11865 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11866 priv->hexpand_set ? &ignored : &h,
11867 priv->vexpand_set ? &ignored : &v);
11871 priv->need_compute_expand = FALSE;
11872 priv->computed_hexpand = h != FALSE;
11873 priv->computed_vexpand = v != FALSE;
11878 * gtk_widget_queue_compute_expand:
11879 * @widget: a #GtkWidget
11881 * Mark @widget as needing to recompute its expand flags. Call
11882 * this function when setting legacy expand child properties
11883 * on the child of a container.
11885 * See gtk_widget_compute_expand().
11888 gtk_widget_queue_compute_expand (GtkWidget *widget)
11891 gboolean changed_anything;
11893 if (widget->priv->need_compute_expand)
11896 changed_anything = FALSE;
11898 while (parent != NULL)
11900 if (!parent->priv->need_compute_expand)
11902 parent->priv->need_compute_expand = TRUE;
11903 changed_anything = TRUE;
11906 /* Note: if we had an invariant that "if a child needs to
11907 * compute expand, its parents also do" then we could stop going
11908 * up when we got to a parent that already needed to
11909 * compute. However, in general we compute expand lazily (as
11910 * soon as we see something in a subtree that is expand, we know
11911 * we're expanding) and so this invariant does not hold and we
11912 * have to always walk all the way up in case some ancestor
11913 * is not currently need_compute_expand.
11916 parent = parent->priv->parent;
11919 /* recomputing expand always requires
11920 * a relayout as well
11922 if (changed_anything)
11923 gtk_widget_queue_resize (widget);
11927 * gtk_widget_compute_expand:
11928 * @widget: the widget
11929 * @orientation: expand direction
11931 * Computes whether a container should give this widget extra space
11932 * when possible. Containers should check this, rather than
11933 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11935 * This function already checks whether the widget is visible, so
11936 * visibility does not need to be checked separately. Non-visible
11937 * widgets are not expanded.
11939 * The computed expand value uses either the expand setting explicitly
11940 * set on the widget itself, or, if none has been explicitly set,
11941 * the widget may expand if some of its children do.
11943 * Return value: whether widget tree rooted here should be expanded
11946 gtk_widget_compute_expand (GtkWidget *widget,
11947 GtkOrientation orientation)
11949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11951 /* We never make a widget expand if not even showing. */
11952 if (!gtk_widget_get_visible (widget))
11955 gtk_widget_update_computed_expand (widget);
11957 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11959 return widget->priv->computed_hexpand;
11963 return widget->priv->computed_vexpand;
11968 gtk_widget_set_expand (GtkWidget *widget,
11969 GtkOrientation orientation,
11972 const char *expand_prop;
11973 const char *expand_set_prop;
11975 GtkWidgetPrivate *priv;
11977 g_return_if_fail (GTK_IS_WIDGET (widget));
11979 priv = widget->priv;
11981 expand = expand != FALSE;
11983 was_both = priv->hexpand && priv->vexpand;
11985 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11987 if (priv->hexpand_set &&
11988 priv->hexpand == expand)
11991 priv->hexpand_set = TRUE;
11992 priv->hexpand = expand;
11994 expand_prop = "hexpand";
11995 expand_set_prop = "hexpand-set";
11999 if (priv->vexpand_set &&
12000 priv->vexpand == expand)
12003 priv->vexpand_set = TRUE;
12004 priv->vexpand = expand;
12006 expand_prop = "vexpand";
12007 expand_set_prop = "vexpand-set";
12010 gtk_widget_queue_compute_expand (widget);
12012 g_object_freeze_notify (G_OBJECT (widget));
12013 g_object_notify (G_OBJECT (widget), expand_prop);
12014 g_object_notify (G_OBJECT (widget), expand_set_prop);
12015 if (was_both != (priv->hexpand && priv->vexpand))
12016 g_object_notify (G_OBJECT (widget), "expand");
12017 g_object_thaw_notify (G_OBJECT (widget));
12021 gtk_widget_set_expand_set (GtkWidget *widget,
12022 GtkOrientation orientation,
12025 GtkWidgetPrivate *priv;
12028 priv = widget->priv;
12030 set = set != FALSE;
12032 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12034 if (set == priv->hexpand_set)
12037 priv->hexpand_set = set;
12038 prop = "hexpand-set";
12042 if (set == priv->vexpand_set)
12045 priv->vexpand_set = set;
12046 prop = "vexpand-set";
12049 gtk_widget_queue_compute_expand (widget);
12051 g_object_notify (G_OBJECT (widget), prop);
12055 * gtk_widget_get_hexpand:
12056 * @widget: the widget
12058 * Gets whether the widget would like any available extra horizontal
12059 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12060 * generally receive the extra space. For example, a list or
12061 * scrollable area or document in your window would often be set to
12064 * Containers should use gtk_widget_compute_expand() rather than
12065 * this function, to see whether a widget, or any of its children,
12066 * has the expand flag set. If any child of a widget wants to
12067 * expand, the parent may ask to expand also.
12069 * This function only looks at the widget's own hexpand flag, rather
12070 * than computing whether the entire widget tree rooted at this widget
12073 * Return value: whether hexpand flag is set
12076 gtk_widget_get_hexpand (GtkWidget *widget)
12078 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12080 return widget->priv->hexpand;
12084 * gtk_widget_set_hexpand:
12085 * @widget: the widget
12086 * @expand: whether to expand
12088 * Sets whether the widget would like any available extra horizontal
12089 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12090 * generally receive the extra space. For example, a list or
12091 * scrollable area or document in your window would often be set to
12094 * Call this function to set the expand flag if you would like your
12095 * widget to become larger horizontally when the window has extra
12098 * By default, widgets automatically expand if any of their children
12099 * want to expand. (To see if a widget will automatically expand given
12100 * its current children and state, call gtk_widget_compute_expand(). A
12101 * container can decide how the expandability of children affects the
12102 * expansion of the container by overriding the compute_expand virtual
12103 * method on #GtkWidget.).
12105 * Setting hexpand explicitly with this function will override the
12106 * automatic expand behavior.
12108 * This function forces the widget to expand or not to expand,
12109 * regardless of children. The override occurs because
12110 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12111 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12112 * value to be used, rather than looking at children and widget state.
12115 gtk_widget_set_hexpand (GtkWidget *widget,
12118 g_return_if_fail (GTK_IS_WIDGET (widget));
12120 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12124 * gtk_widget_get_hexpand_set:
12125 * @widget: the widget
12127 * Gets whether gtk_widget_set_hexpand() has been used to
12128 * explicitly set the expand flag on this widget.
12130 * If hexpand is set, then it overrides any computed
12131 * expand value based on child widgets. If hexpand is not
12132 * set, then the expand value depends on whether any
12133 * children of the widget would like to expand.
12135 * There are few reasons to use this function, but it's here
12136 * for completeness and consistency.
12138 * Return value: whether hexpand has been explicitly set
12141 gtk_widget_get_hexpand_set (GtkWidget *widget)
12143 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12145 return widget->priv->hexpand_set;
12149 * gtk_widget_set_hexpand_set:
12150 * @widget: the widget
12151 * @set: value for hexpand-set property
12153 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12156 * The hexpand-set property will be set automatically when you call
12157 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12158 * reason to use this function would be to unset an explicit expand
12161 * If hexpand is set, then it overrides any computed
12162 * expand value based on child widgets. If hexpand is not
12163 * set, then the expand value depends on whether any
12164 * children of the widget would like to expand.
12166 * There are few reasons to use this function, but it's here
12167 * for completeness and consistency.
12170 gtk_widget_set_hexpand_set (GtkWidget *widget,
12173 g_return_if_fail (GTK_IS_WIDGET (widget));
12175 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12180 * gtk_widget_get_vexpand:
12181 * @widget: the widget
12183 * Gets whether the widget would like any available extra vertical
12186 * See gtk_widget_get_hexpand() for more detail.
12188 * Return value: whether vexpand flag is set
12191 gtk_widget_get_vexpand (GtkWidget *widget)
12193 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12195 return widget->priv->vexpand;
12199 * gtk_widget_set_vexpand:
12200 * @widget: the widget
12201 * @expand: whether to expand
12203 * Sets whether the widget would like any available extra vertical
12206 * See gtk_widget_set_hexpand() for more detail.
12209 gtk_widget_set_vexpand (GtkWidget *widget,
12212 g_return_if_fail (GTK_IS_WIDGET (widget));
12214 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12218 * gtk_widget_get_vexpand_set:
12219 * @widget: the widget
12221 * Gets whether gtk_widget_set_vexpand() has been used to
12222 * explicitly set the expand flag on this widget.
12224 * See gtk_widget_get_hexpand_set() for more detail.
12226 * Return value: whether vexpand has been explicitly set
12229 gtk_widget_get_vexpand_set (GtkWidget *widget)
12231 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12233 return widget->priv->vexpand_set;
12237 * gtk_widget_set_vexpand_set:
12238 * @widget: the widget
12239 * @set: value for vexpand-set property
12241 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12244 * See gtk_widget_set_hexpand_set() for more detail.
12247 gtk_widget_set_vexpand_set (GtkWidget *widget,
12250 g_return_if_fail (GTK_IS_WIDGET (widget));
12252 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12256 * GtkBuildable implementation
12258 static GQuark quark_builder_has_default = 0;
12259 static GQuark quark_builder_has_focus = 0;
12260 static GQuark quark_builder_atk_relations = 0;
12261 static GQuark quark_builder_set_name = 0;
12264 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12266 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12267 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12268 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12269 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12271 iface->set_name = gtk_widget_buildable_set_name;
12272 iface->get_name = gtk_widget_buildable_get_name;
12273 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12274 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12275 iface->parser_finished = gtk_widget_buildable_parser_finished;
12276 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12277 iface->custom_finished = gtk_widget_buildable_custom_finished;
12281 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12284 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12285 g_strdup (name), g_free);
12288 static const gchar *
12289 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12291 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12295 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12296 GtkBuilder *builder,
12297 const gchar *childname)
12299 if (strcmp (childname, "accessible") == 0)
12300 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12306 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12307 GtkBuilder *builder,
12309 const GValue *value)
12311 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12312 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12313 GINT_TO_POINTER (TRUE));
12314 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12315 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12316 GINT_TO_POINTER (TRUE));
12318 g_object_set_property (G_OBJECT (buildable), name, value);
12323 gchar *action_name;
12324 GString *description;
12326 gboolean translatable;
12336 free_action (AtkActionData *data, gpointer user_data)
12338 g_free (data->action_name);
12339 g_string_free (data->description, TRUE);
12340 g_free (data->context);
12341 g_slice_free (AtkActionData, data);
12345 free_relation (AtkRelationData *data, gpointer user_data)
12347 g_free (data->target);
12348 g_free (data->type);
12349 g_slice_free (AtkRelationData, data);
12353 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12354 GtkBuilder *builder)
12356 GSList *atk_relations;
12358 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12359 gtk_widget_grab_default (GTK_WIDGET (buildable));
12360 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12361 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12363 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12364 quark_builder_atk_relations);
12367 AtkObject *accessible;
12368 AtkRelationSet *relation_set;
12371 AtkRelationType relation_type;
12372 AtkObject *target_accessible;
12374 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12375 relation_set = atk_object_ref_relation_set (accessible);
12377 for (l = atk_relations; l; l = l->next)
12379 AtkRelationData *relation = (AtkRelationData*)l->data;
12381 target = gtk_builder_get_object (builder, relation->target);
12384 g_warning ("Target object %s in <relation> does not exist",
12388 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12389 g_assert (target_accessible != NULL);
12391 relation_type = atk_relation_type_for_name (relation->type);
12392 if (relation_type == ATK_RELATION_NULL)
12394 g_warning ("<relation> type %s not found",
12398 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12399 target_accessible);
12401 g_object_unref (relation_set);
12403 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12404 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12413 } AccessibilitySubParserData;
12416 accessibility_start_element (GMarkupParseContext *context,
12417 const gchar *element_name,
12418 const gchar **names,
12419 const gchar **values,
12420 gpointer user_data,
12423 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12425 gint line_number, char_number;
12427 if (strcmp (element_name, "relation") == 0)
12429 gchar *target = NULL;
12430 gchar *type = NULL;
12431 AtkRelationData *relation;
12433 for (i = 0; names[i]; i++)
12435 if (strcmp (names[i], "target") == 0)
12436 target = g_strdup (values[i]);
12437 else if (strcmp (names[i], "type") == 0)
12438 type = g_strdup (values[i]);
12441 g_markup_parse_context_get_position (context,
12444 g_set_error (error,
12446 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12447 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12449 line_number, char_number, names[i], "relation");
12456 if (!target || !type)
12458 g_markup_parse_context_get_position (context,
12461 g_set_error (error,
12463 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12464 "%s:%d:%d <%s> requires attribute \"%s\"",
12466 line_number, char_number, "relation",
12467 type ? "target" : "type");
12473 relation = g_slice_new (AtkRelationData);
12474 relation->target = target;
12475 relation->type = type;
12477 data->relations = g_slist_prepend (data->relations, relation);
12479 else if (strcmp (element_name, "action") == 0)
12481 const gchar *action_name = NULL;
12482 const gchar *description = NULL;
12483 const gchar *msg_context = NULL;
12484 gboolean translatable = FALSE;
12485 AtkActionData *action;
12487 for (i = 0; names[i]; i++)
12489 if (strcmp (names[i], "action_name") == 0)
12490 action_name = values[i];
12491 else if (strcmp (names[i], "description") == 0)
12492 description = values[i];
12493 else if (strcmp (names[i], "translatable") == 0)
12495 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12498 else if (strcmp (names[i], "comments") == 0)
12500 /* do nothing, comments are for translators */
12502 else if (strcmp (names[i], "context") == 0)
12503 msg_context = values[i];
12506 g_markup_parse_context_get_position (context,
12509 g_set_error (error,
12511 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12512 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12514 line_number, char_number, names[i], "action");
12521 g_markup_parse_context_get_position (context,
12524 g_set_error (error,
12526 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12527 "%s:%d:%d <%s> requires attribute \"%s\"",
12529 line_number, char_number, "action",
12534 action = g_slice_new (AtkActionData);
12535 action->action_name = g_strdup (action_name);
12536 action->description = g_string_new (description);
12537 action->context = g_strdup (msg_context);
12538 action->translatable = translatable;
12540 data->actions = g_slist_prepend (data->actions, action);
12542 else if (strcmp (element_name, "accessibility") == 0)
12545 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12549 accessibility_text (GMarkupParseContext *context,
12552 gpointer user_data,
12555 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12557 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12559 AtkActionData *action = data->actions->data;
12561 g_string_append_len (action->description, text, text_len);
12565 static const GMarkupParser accessibility_parser =
12567 accessibility_start_element,
12569 accessibility_text,
12578 } AccelGroupParserData;
12581 accel_group_start_element (GMarkupParseContext *context,
12582 const gchar *element_name,
12583 const gchar **names,
12584 const gchar **values,
12585 gpointer user_data,
12590 guint modifiers = 0;
12591 gchar *signal = NULL;
12592 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12594 for (i = 0; names[i]; i++)
12596 if (strcmp (names[i], "key") == 0)
12597 key = gdk_keyval_from_name (values[i]);
12598 else if (strcmp (names[i], "modifiers") == 0)
12600 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12606 else if (strcmp (names[i], "signal") == 0)
12607 signal = g_strdup (values[i]);
12610 if (key == 0 || signal == NULL)
12612 g_warning ("<accelerator> requires key and signal attributes");
12615 parser_data->key = key;
12616 parser_data->modifiers = modifiers;
12617 parser_data->signal = signal;
12620 static const GMarkupParser accel_group_parser =
12622 accel_group_start_element,
12631 style_start_element (GMarkupParseContext *context,
12632 const gchar *element_name,
12633 const gchar **names,
12634 const gchar **values,
12635 gpointer user_data,
12638 StyleParserData *style_data = (StyleParserData *)user_data;
12641 if (strcmp (element_name, "class") == 0)
12643 if (g_markup_collect_attributes (element_name,
12647 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12648 G_MARKUP_COLLECT_INVALID))
12650 style_data->classes = g_slist_append (style_data->classes, class_name);
12653 else if (strcmp (element_name, "style") == 0)
12656 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12659 static const GMarkupParser style_parser =
12661 style_start_element,
12665 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12666 GtkBuilder *builder,
12668 const gchar *tagname,
12669 GMarkupParser *parser,
12672 g_assert (buildable);
12674 if (strcmp (tagname, "accelerator") == 0)
12676 AccelGroupParserData *parser_data;
12678 parser_data = g_slice_new0 (AccelGroupParserData);
12679 parser_data->object = g_object_ref (buildable);
12680 *parser = accel_group_parser;
12681 *data = parser_data;
12684 if (strcmp (tagname, "accessibility") == 0)
12686 AccessibilitySubParserData *parser_data;
12688 parser_data = g_slice_new0 (AccessibilitySubParserData);
12689 *parser = accessibility_parser;
12690 *data = parser_data;
12693 if (strcmp (tagname, "style") == 0)
12695 StyleParserData *parser_data;
12697 parser_data = g_slice_new0 (StyleParserData);
12698 *parser = style_parser;
12699 *data = parser_data;
12707 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12708 GtkWidget *toplevel,
12709 gpointer user_data)
12711 AccelGroupParserData *accel_data;
12712 GSList *accel_groups;
12713 GtkAccelGroup *accel_group;
12715 g_return_if_fail (GTK_IS_WIDGET (widget));
12716 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12717 g_return_if_fail (user_data != NULL);
12719 accel_data = (AccelGroupParserData*)user_data;
12720 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12721 if (g_slist_length (accel_groups) == 0)
12723 accel_group = gtk_accel_group_new ();
12724 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12728 g_assert (g_slist_length (accel_groups) == 1);
12729 accel_group = g_slist_nth_data (accel_groups, 0);
12732 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12733 accel_data->signal,
12736 accel_data->modifiers,
12737 GTK_ACCEL_VISIBLE);
12739 g_object_unref (accel_data->object);
12740 g_free (accel_data->signal);
12741 g_slice_free (AccelGroupParserData, accel_data);
12745 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12746 GtkBuilder *builder,
12748 const gchar *tagname,
12749 gpointer user_data)
12751 if (strcmp (tagname, "accelerator") == 0)
12753 AccelGroupParserData *accel_data;
12754 GtkWidget *toplevel;
12756 accel_data = (AccelGroupParserData*)user_data;
12757 g_assert (accel_data->object);
12759 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12761 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12763 else if (strcmp (tagname, "accessibility") == 0)
12765 AccessibilitySubParserData *a11y_data;
12767 a11y_data = (AccessibilitySubParserData*)user_data;
12769 if (a11y_data->actions)
12771 AtkObject *accessible;
12776 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12778 if (ATK_IS_ACTION (accessible))
12780 action = ATK_ACTION (accessible);
12781 n_actions = atk_action_get_n_actions (action);
12783 for (l = a11y_data->actions; l; l = l->next)
12785 AtkActionData *action_data = (AtkActionData*)l->data;
12787 for (i = 0; i < n_actions; i++)
12788 if (strcmp (atk_action_get_name (action, i),
12789 action_data->action_name) == 0)
12794 gchar *description;
12796 if (action_data->translatable && action_data->description->len)
12797 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12798 action_data->context,
12799 action_data->description->str);
12801 description = action_data->description->str;
12803 atk_action_set_description (action, i, description);
12808 g_warning ("accessibility action on a widget that does not implement AtkAction");
12810 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12813 if (a11y_data->relations)
12814 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12815 a11y_data->relations);
12817 g_slice_free (AccessibilitySubParserData, a11y_data);
12819 else if (strcmp (tagname, "style") == 0)
12821 StyleParserData *style_data = (StyleParserData *)user_data;
12822 GtkStyleContext *context;
12825 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12827 for (l = style_data->classes; l; l = l->next)
12828 gtk_style_context_add_class (context, (const gchar *)l->data);
12830 gtk_widget_reset_style (GTK_WIDGET (buildable));
12832 g_slist_free_full (style_data->classes, g_free);
12833 g_slice_free (StyleParserData, style_data);
12837 static GtkSizeRequestMode
12838 gtk_widget_real_get_request_mode (GtkWidget *widget)
12840 /* By default widgets dont trade size at all. */
12841 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12845 gtk_widget_real_get_width (GtkWidget *widget,
12846 gint *minimum_size,
12847 gint *natural_size)
12857 gtk_widget_real_get_height (GtkWidget *widget,
12858 gint *minimum_size,
12859 gint *natural_size)
12869 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12871 gint *minimum_height,
12872 gint *natural_height)
12874 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12878 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12880 gint *minimum_width,
12881 gint *natural_width)
12883 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12887 * gtk_widget_get_halign:
12888 * @widget: a #GtkWidget
12890 * Gets the value of the #GtkWidget:halign property.
12892 * Returns: the horizontal alignment of @widget
12895 gtk_widget_get_halign (GtkWidget *widget)
12897 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12898 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12902 * gtk_widget_set_halign:
12903 * @widget: a #GtkWidget
12904 * @align: the horizontal alignment
12906 * Sets the horizontal alignment of @widget.
12907 * See the #GtkWidget:halign property.
12910 gtk_widget_set_halign (GtkWidget *widget,
12913 GtkWidgetAuxInfo *aux_info;
12915 g_return_if_fail (GTK_IS_WIDGET (widget));
12917 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12919 if (aux_info->halign == align)
12922 aux_info->halign = align;
12923 gtk_widget_queue_resize (widget);
12924 g_object_notify (G_OBJECT (widget), "halign");
12928 * gtk_widget_get_valign:
12929 * @widget: a #GtkWidget
12931 * Gets the value of the #GtkWidget:valign property.
12933 * Returns: the vertical alignment of @widget
12936 gtk_widget_get_valign (GtkWidget *widget)
12938 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12939 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12943 * gtk_widget_set_valign:
12944 * @widget: a #GtkWidget
12945 * @align: the vertical alignment
12947 * Sets the vertical alignment of @widget.
12948 * See the #GtkWidget:valign property.
12951 gtk_widget_set_valign (GtkWidget *widget,
12954 GtkWidgetAuxInfo *aux_info;
12956 g_return_if_fail (GTK_IS_WIDGET (widget));
12958 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12960 if (aux_info->valign == align)
12963 aux_info->valign = align;
12964 gtk_widget_queue_resize (widget);
12965 g_object_notify (G_OBJECT (widget), "valign");
12969 * gtk_widget_get_margin_left:
12970 * @widget: a #GtkWidget
12972 * Gets the value of the #GtkWidget:margin-left property.
12974 * Returns: The left margin of @widget
12979 gtk_widget_get_margin_left (GtkWidget *widget)
12981 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12983 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12987 * gtk_widget_set_margin_left:
12988 * @widget: a #GtkWidget
12989 * @margin: the left margin
12991 * Sets the left margin of @widget.
12992 * See the #GtkWidget:margin-left property.
12997 gtk_widget_set_margin_left (GtkWidget *widget,
13000 GtkWidgetAuxInfo *aux_info;
13002 g_return_if_fail (GTK_IS_WIDGET (widget));
13003 g_return_if_fail (margin <= G_MAXINT16);
13005 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13007 if (aux_info->margin.left == margin)
13010 aux_info->margin.left = margin;
13011 gtk_widget_queue_resize (widget);
13012 g_object_notify (G_OBJECT (widget), "margin-left");
13016 * gtk_widget_get_margin_right:
13017 * @widget: a #GtkWidget
13019 * Gets the value of the #GtkWidget:margin-right property.
13021 * Returns: The right margin of @widget
13026 gtk_widget_get_margin_right (GtkWidget *widget)
13028 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13030 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13034 * gtk_widget_set_margin_right:
13035 * @widget: a #GtkWidget
13036 * @margin: the right margin
13038 * Sets the right margin of @widget.
13039 * See the #GtkWidget:margin-right property.
13044 gtk_widget_set_margin_right (GtkWidget *widget,
13047 GtkWidgetAuxInfo *aux_info;
13049 g_return_if_fail (GTK_IS_WIDGET (widget));
13050 g_return_if_fail (margin <= G_MAXINT16);
13052 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13054 if (aux_info->margin.right == margin)
13057 aux_info->margin.right = margin;
13058 gtk_widget_queue_resize (widget);
13059 g_object_notify (G_OBJECT (widget), "margin-right");
13063 * gtk_widget_get_margin_top:
13064 * @widget: a #GtkWidget
13066 * Gets the value of the #GtkWidget:margin-top property.
13068 * Returns: The top margin of @widget
13073 gtk_widget_get_margin_top (GtkWidget *widget)
13075 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13077 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13081 * gtk_widget_set_margin_top:
13082 * @widget: a #GtkWidget
13083 * @margin: the top margin
13085 * Sets the top margin of @widget.
13086 * See the #GtkWidget:margin-top property.
13091 gtk_widget_set_margin_top (GtkWidget *widget,
13094 GtkWidgetAuxInfo *aux_info;
13096 g_return_if_fail (GTK_IS_WIDGET (widget));
13097 g_return_if_fail (margin <= G_MAXINT16);
13099 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13101 if (aux_info->margin.top == margin)
13104 aux_info->margin.top = margin;
13105 gtk_widget_queue_resize (widget);
13106 g_object_notify (G_OBJECT (widget), "margin-top");
13110 * gtk_widget_get_margin_bottom:
13111 * @widget: a #GtkWidget
13113 * Gets the value of the #GtkWidget:margin-bottom property.
13115 * Returns: The bottom margin of @widget
13120 gtk_widget_get_margin_bottom (GtkWidget *widget)
13122 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13124 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13128 * gtk_widget_set_margin_bottom:
13129 * @widget: a #GtkWidget
13130 * @margin: the bottom margin
13132 * Sets the bottom margin of @widget.
13133 * See the #GtkWidget:margin-bottom property.
13138 gtk_widget_set_margin_bottom (GtkWidget *widget,
13141 GtkWidgetAuxInfo *aux_info;
13143 g_return_if_fail (GTK_IS_WIDGET (widget));
13144 g_return_if_fail (margin <= G_MAXINT16);
13146 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13148 if (aux_info->margin.bottom == margin)
13151 aux_info->margin.bottom = margin;
13152 gtk_widget_queue_resize (widget);
13153 g_object_notify (G_OBJECT (widget), "margin-bottom");
13157 * gtk_widget_get_clipboard:
13158 * @widget: a #GtkWidget
13159 * @selection: a #GdkAtom which identifies the clipboard
13160 * to use. %GDK_SELECTION_CLIPBOARD gives the
13161 * default clipboard. Another common value
13162 * is %GDK_SELECTION_PRIMARY, which gives
13163 * the primary X selection.
13165 * Returns the clipboard object for the given selection to
13166 * be used with @widget. @widget must have a #GdkDisplay
13167 * associated with it, so must be attached to a toplevel
13170 * Return value: (transfer none): the appropriate clipboard object. If no
13171 * clipboard already exists, a new one will
13172 * be created. Once a clipboard object has
13173 * been created, it is persistent for all time.
13178 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13180 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13181 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13183 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13188 * gtk_widget_list_mnemonic_labels:
13189 * @widget: a #GtkWidget
13191 * Returns a newly allocated list of the widgets, normally labels, for
13192 * which this widget is the target of a mnemonic (see for example,
13193 * gtk_label_set_mnemonic_widget()).
13195 * The widgets in the list are not individually referenced. If you
13196 * want to iterate through the list and perform actions involving
13197 * callbacks that might destroy the widgets, you
13198 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13199 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13200 * widgets afterwards.
13202 * Return value: (element-type GtkWidget) (transfer container): the list of
13203 * mnemonic labels; free this list
13204 * with g_list_free() when you are done with it.
13209 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13211 GList *list = NULL;
13214 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13216 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13217 list = g_list_prepend (list, l->data);
13223 * gtk_widget_add_mnemonic_label:
13224 * @widget: a #GtkWidget
13225 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13227 * Adds a widget to the list of mnemonic labels for
13228 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13229 * list of mnemonic labels for the widget is cleared when the
13230 * widget is destroyed, so the caller must make sure to update
13231 * its internal state at this point as well, by using a connection
13232 * to the #GtkWidget::destroy signal or a weak notifier.
13237 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13240 GSList *old_list, *new_list;
13242 g_return_if_fail (GTK_IS_WIDGET (widget));
13243 g_return_if_fail (GTK_IS_WIDGET (label));
13245 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13246 new_list = g_slist_prepend (old_list, label);
13248 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13249 new_list, (GDestroyNotify) g_slist_free);
13253 * gtk_widget_remove_mnemonic_label:
13254 * @widget: a #GtkWidget
13255 * @label: a #GtkWidget that was previously set as a mnemnic label for
13256 * @widget with gtk_widget_add_mnemonic_label().
13258 * Removes a widget from the list of mnemonic labels for
13259 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13260 * must have previously been added to the list with
13261 * gtk_widget_add_mnemonic_label().
13266 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13269 GSList *old_list, *new_list;
13271 g_return_if_fail (GTK_IS_WIDGET (widget));
13272 g_return_if_fail (GTK_IS_WIDGET (label));
13274 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13275 new_list = g_slist_remove (old_list, label);
13278 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13279 new_list, (GDestroyNotify) g_slist_free);
13283 * gtk_widget_get_no_show_all:
13284 * @widget: a #GtkWidget
13286 * Returns the current value of the #GtkWidget:no-show-all property,
13287 * which determines whether calls to gtk_widget_show_all()
13288 * will affect this widget.
13290 * Return value: the current value of the "no-show-all" property.
13295 gtk_widget_get_no_show_all (GtkWidget *widget)
13297 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13299 return widget->priv->no_show_all;
13303 * gtk_widget_set_no_show_all:
13304 * @widget: a #GtkWidget
13305 * @no_show_all: the new value for the "no-show-all" property
13307 * Sets the #GtkWidget:no-show-all property, which determines whether
13308 * calls to gtk_widget_show_all() will affect this widget.
13310 * This is mostly for use in constructing widget hierarchies with externally
13311 * controlled visibility, see #GtkUIManager.
13316 gtk_widget_set_no_show_all (GtkWidget *widget,
13317 gboolean no_show_all)
13319 g_return_if_fail (GTK_IS_WIDGET (widget));
13321 no_show_all = (no_show_all != FALSE);
13323 if (widget->priv->no_show_all != no_show_all)
13325 widget->priv->no_show_all = no_show_all;
13327 g_object_notify (G_OBJECT (widget), "no-show-all");
13333 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13334 gboolean has_tooltip,
13337 GtkWidgetPrivate *priv = widget->priv;
13338 gboolean priv_has_tooltip;
13340 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13341 quark_has_tooltip));
13343 if (priv_has_tooltip != has_tooltip || force)
13345 priv_has_tooltip = has_tooltip;
13347 if (priv_has_tooltip)
13349 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13350 gdk_window_set_events (priv->window,
13351 gdk_window_get_events (priv->window) |
13352 GDK_LEAVE_NOTIFY_MASK |
13353 GDK_POINTER_MOTION_MASK |
13354 GDK_POINTER_MOTION_HINT_MASK);
13356 if (gtk_widget_get_has_window (widget))
13357 gtk_widget_add_events (widget,
13358 GDK_LEAVE_NOTIFY_MASK |
13359 GDK_POINTER_MOTION_MASK |
13360 GDK_POINTER_MOTION_HINT_MASK);
13363 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13364 GUINT_TO_POINTER (priv_has_tooltip));
13369 * gtk_widget_set_tooltip_window:
13370 * @widget: a #GtkWidget
13371 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13373 * Replaces the default, usually yellow, window used for displaying
13374 * tooltips with @custom_window. GTK+ will take care of showing and
13375 * hiding @custom_window at the right moment, to behave likewise as
13376 * the default tooltip window. If @custom_window is %NULL, the default
13377 * tooltip window will be used.
13379 * If the custom window should have the default theming it needs to
13380 * have the name "gtk-tooltip", see gtk_widget_set_name().
13385 gtk_widget_set_tooltip_window (GtkWidget *widget,
13386 GtkWindow *custom_window)
13388 gboolean has_tooltip;
13389 gchar *tooltip_markup;
13391 g_return_if_fail (GTK_IS_WIDGET (widget));
13392 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13394 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13397 g_object_ref (custom_window);
13399 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13400 custom_window, g_object_unref);
13402 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13403 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13405 if (has_tooltip && gtk_widget_get_visible (widget))
13406 gtk_widget_queue_tooltip_query (widget);
13410 * gtk_widget_get_tooltip_window:
13411 * @widget: a #GtkWidget
13413 * Returns the #GtkWindow of the current tooltip. This can be the
13414 * GtkWindow created by default, or the custom tooltip window set
13415 * using gtk_widget_set_tooltip_window().
13417 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13422 gtk_widget_get_tooltip_window (GtkWidget *widget)
13424 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13426 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13430 * gtk_widget_trigger_tooltip_query:
13431 * @widget: a #GtkWidget
13433 * Triggers a tooltip query on the display where the toplevel of @widget
13434 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13440 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13442 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13445 static guint tooltip_query_id;
13446 static GSList *tooltip_query_displays;
13449 tooltip_query_idle (gpointer data)
13451 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13452 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13453 g_slist_free (tooltip_query_displays);
13455 tooltip_query_displays = NULL;
13456 tooltip_query_id = 0;
13462 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13464 GdkDisplay *display;
13466 display = gtk_widget_get_display (widget);
13468 if (!g_slist_find (tooltip_query_displays, display))
13469 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13471 if (tooltip_query_id == 0)
13472 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13476 * gtk_widget_set_tooltip_text:
13477 * @widget: a #GtkWidget
13478 * @text: (allow-none): the contents of the tooltip for @widget
13480 * Sets @text as the contents of the tooltip. This function will take
13481 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13482 * handler for the #GtkWidget::query-tooltip signal.
13484 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13489 gtk_widget_set_tooltip_text (GtkWidget *widget,
13492 g_return_if_fail (GTK_IS_WIDGET (widget));
13494 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13498 * gtk_widget_get_tooltip_text:
13499 * @widget: a #GtkWidget
13501 * Gets the contents of the tooltip for @widget.
13503 * Return value: the tooltip text, or %NULL. You should free the
13504 * returned string with g_free() when done.
13509 gtk_widget_get_tooltip_text (GtkWidget *widget)
13511 gchar *text = NULL;
13513 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13515 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13521 * gtk_widget_set_tooltip_markup:
13522 * @widget: a #GtkWidget
13523 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13525 * Sets @markup as the contents of the tooltip, which is marked up with
13526 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13528 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13529 * and of the default handler for the #GtkWidget::query-tooltip signal.
13531 * See also the #GtkWidget:tooltip-markup property and
13532 * gtk_tooltip_set_markup().
13537 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13538 const gchar *markup)
13540 g_return_if_fail (GTK_IS_WIDGET (widget));
13542 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13546 * gtk_widget_get_tooltip_markup:
13547 * @widget: a #GtkWidget
13549 * Gets the contents of the tooltip for @widget.
13551 * Return value: the tooltip text, or %NULL. You should free the
13552 * returned string with g_free() when done.
13557 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13559 gchar *text = NULL;
13561 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13563 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13569 * gtk_widget_set_has_tooltip:
13570 * @widget: a #GtkWidget
13571 * @has_tooltip: whether or not @widget has a tooltip.
13573 * Sets the has-tooltip property on @widget to @has_tooltip. See
13574 * #GtkWidget:has-tooltip for more information.
13579 gtk_widget_set_has_tooltip (GtkWidget *widget,
13580 gboolean has_tooltip)
13582 g_return_if_fail (GTK_IS_WIDGET (widget));
13584 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13588 * gtk_widget_get_has_tooltip:
13589 * @widget: a #GtkWidget
13591 * Returns the current value of the has-tooltip property. See
13592 * #GtkWidget:has-tooltip for more information.
13594 * Return value: current value of has-tooltip on @widget.
13599 gtk_widget_get_has_tooltip (GtkWidget *widget)
13601 gboolean has_tooltip = FALSE;
13603 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13605 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13607 return has_tooltip;
13611 * gtk_widget_get_allocation:
13612 * @widget: a #GtkWidget
13613 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13615 * Retrieves the widget's allocation.
13617 * Note, when implementing a #GtkContainer: a widget's allocation will
13618 * be its "adjusted" allocation, that is, the widget's parent
13619 * container typically calls gtk_widget_size_allocate() with an
13620 * allocation, and that allocation is then adjusted (to handle margin
13621 * and alignment for example) before assignment to the widget.
13622 * gtk_widget_get_allocation() returns the adjusted allocation that
13623 * was actually assigned to the widget. The adjusted allocation is
13624 * guaranteed to be completely contained within the
13625 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13626 * is guaranteed that its children stay inside the assigned bounds,
13627 * but not that they have exactly the bounds the container assigned.
13628 * There is no way to get the original allocation assigned by
13629 * gtk_widget_size_allocate(), since it isn't stored; if a container
13630 * implementation needs that information it will have to track it itself.
13635 gtk_widget_get_allocation (GtkWidget *widget,
13636 GtkAllocation *allocation)
13638 GtkWidgetPrivate *priv;
13640 g_return_if_fail (GTK_IS_WIDGET (widget));
13641 g_return_if_fail (allocation != NULL);
13643 priv = widget->priv;
13645 *allocation = priv->allocation;
13649 * gtk_widget_set_allocation:
13650 * @widget: a #GtkWidget
13651 * @allocation: a pointer to a #GtkAllocation to copy from
13653 * Sets the widget's allocation. This should not be used
13654 * directly, but from within a widget's size_allocate method.
13656 * The allocation set should be the "adjusted" or actual
13657 * allocation. If you're implementing a #GtkContainer, you want to use
13658 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13659 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13660 * allocation inside gtk_widget_size_allocate() to create an adjusted
13666 gtk_widget_set_allocation (GtkWidget *widget,
13667 const GtkAllocation *allocation)
13669 GtkWidgetPrivate *priv;
13671 g_return_if_fail (GTK_IS_WIDGET (widget));
13672 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13673 g_return_if_fail (allocation != NULL);
13675 priv = widget->priv;
13677 priv->allocation = *allocation;
13681 * gtk_widget_get_allocated_width:
13682 * @widget: the widget to query
13684 * Returns the width that has currently been allocated to @widget.
13685 * This function is intended to be used when implementing handlers
13686 * for the #GtkWidget::draw function.
13688 * Returns: the width of the @widget
13691 gtk_widget_get_allocated_width (GtkWidget *widget)
13693 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13695 return widget->priv->allocation.width;
13699 * gtk_widget_get_allocated_height:
13700 * @widget: the widget to query
13702 * Returns the height that has currently been allocated to @widget.
13703 * This function is intended to be used when implementing handlers
13704 * for the #GtkWidget::draw function.
13706 * Returns: the height of the @widget
13709 gtk_widget_get_allocated_height (GtkWidget *widget)
13711 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13713 return widget->priv->allocation.height;
13717 * gtk_widget_get_requisition:
13718 * @widget: a #GtkWidget
13719 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13721 * Retrieves the widget's requisition.
13723 * This function should only be used by widget implementations in
13724 * order to figure whether the widget's requisition has actually
13725 * changed after some internal state change (so that they can call
13726 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13728 * Normally, gtk_widget_size_request() should be used.
13732 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13733 * removed, If you need to cache sizes across requests and allocations,
13734 * add an explicit cache to the widget in question instead.
13737 gtk_widget_get_requisition (GtkWidget *widget,
13738 GtkRequisition *requisition)
13740 g_return_if_fail (GTK_IS_WIDGET (widget));
13741 g_return_if_fail (requisition != NULL);
13743 gtk_widget_get_preferred_size (widget, requisition, NULL);
13747 * gtk_widget_set_window:
13748 * @widget: a #GtkWidget
13749 * @window: (transfer full): a #GdkWindow
13751 * Sets a widget's window. This function should only be used in a
13752 * widget's #GtkWidget::realize implementation. The %window passed is
13753 * usually either new window created with gdk_window_new(), or the
13754 * window of its parent widget as returned by
13755 * gtk_widget_get_parent_window().
13757 * Widgets must indicate whether they will create their own #GdkWindow
13758 * by calling gtk_widget_set_has_window(). This is usually done in the
13759 * widget's init() function.
13761 * <note><para>This function does not add any reference to @window.</para></note>
13766 gtk_widget_set_window (GtkWidget *widget,
13769 GtkWidgetPrivate *priv;
13771 g_return_if_fail (GTK_IS_WIDGET (widget));
13772 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13774 priv = widget->priv;
13776 if (priv->window != window)
13778 priv->window = window;
13780 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
13781 gdk_window_set_opacity (window,
13782 priv->norender ? 0 : priv->alpha / 255.0);
13784 g_object_notify (G_OBJECT (widget), "window");
13789 * gtk_widget_register_window:
13790 * @widget: a #GtkWidget
13791 * @window: a #GdkWindow
13793 * Registers a #GdkWindow with the widget and sets it up so that
13794 * the widget recieves events for it. Call gtk_widget_unregister_window()
13795 * when destroying the window.
13797 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13798 * this up. This is now deprecated and you should use gtk_widget_register_window()
13799 * instead. Old code will keep working as is, although some new features like
13800 * transparency might not work perfectly.
13805 gtk_widget_register_window (GtkWidget *widget,
13808 GtkWidgetPrivate *priv;
13809 gpointer user_data;
13811 g_return_if_fail (GTK_IS_WIDGET (widget));
13812 g_return_if_fail (GDK_IS_WINDOW (window));
13814 gdk_window_get_user_data (window, &user_data);
13815 g_assert (user_data == NULL);
13817 priv = widget->priv;
13819 gdk_window_set_user_data (window, widget);
13820 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13822 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
13823 gdk_window_set_opacity (window,
13824 priv->norender_children ? 0.0 : 1.0);
13828 * gtk_widget_unregister_window:
13829 * @widget: a #GtkWidget
13830 * @window: a #GdkWindow
13832 * Unregisters a #GdkWindow from the widget that was previously set up with
13833 * gtk_widget_register_window(). You need to call this when the window is
13834 * no longer used by the widget, such as when you destroy it.
13839 gtk_widget_unregister_window (GtkWidget *widget,
13842 GtkWidgetPrivate *priv;
13843 gpointer user_data;
13845 g_return_if_fail (GTK_IS_WIDGET (widget));
13846 g_return_if_fail (GDK_IS_WINDOW (window));
13848 priv = widget->priv;
13850 gdk_window_get_user_data (window, &user_data);
13851 g_assert (user_data == widget);
13852 gdk_window_set_user_data (window, NULL);
13853 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13857 * gtk_widget_get_window:
13858 * @widget: a #GtkWidget
13860 * Returns the widget's window if it is realized, %NULL otherwise
13862 * Return value: (transfer none): @widget's window.
13867 gtk_widget_get_window (GtkWidget *widget)
13869 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13871 return widget->priv->window;
13875 * gtk_widget_get_support_multidevice:
13876 * @widget: a #GtkWidget
13878 * Returns %TRUE if @widget is multiple pointer aware. See
13879 * gtk_widget_set_support_multidevice() for more information.
13881 * Returns: %TRUE if @widget is multidevice aware.
13884 gtk_widget_get_support_multidevice (GtkWidget *widget)
13886 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13888 return widget->priv->multidevice;
13892 * gtk_widget_set_support_multidevice:
13893 * @widget: a #GtkWidget
13894 * @support_multidevice: %TRUE to support input from multiple devices.
13896 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13897 * @widget will start receiving multiple, per device enter/leave events. Note
13898 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13899 * gdk_window_set_support_multidevice() will have to be called manually on them.
13904 gtk_widget_set_support_multidevice (GtkWidget *widget,
13905 gboolean support_multidevice)
13907 GtkWidgetPrivate *priv;
13909 g_return_if_fail (GTK_IS_WIDGET (widget));
13911 priv = widget->priv;
13912 priv->multidevice = (support_multidevice == TRUE);
13914 if (gtk_widget_get_realized (widget))
13915 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13918 /* There are multiple alpha related sources. First of all the user can specify alpha
13919 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
13920 * are multiplied together to form the total alpha. Secondly, the user can specify
13921 * an opacity group for a widget, which means we must essentially handle it as having alpha.
13923 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
13924 * group we directly set the opacity of widget->window. This will cause gdk to properly
13925 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
13927 * However, if the widget is not windowed, or the user specified an opacity group for the
13928 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
13929 * implementation of this would break for windowed widgets or descendant widgets with
13930 * windows, as these would not be handled by the ::draw signal. To handle this we set
13931 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
13932 * to make the draw signal propagate to *all* child widgets/windows.
13934 * Note: We don't make all child windows fully transparent, we stop at the first one
13935 * in each branch when propagating down the hierarchy.
13939 /* This is called when priv->alpha or priv->opacity_group group changes, and should
13940 * update priv->norender and GdkWindow opacity for this widget and any children that
13941 * needs changing. It is also called whenver the parent changes, the parents
13942 * norender_children state changes, or the has_window state of the widget changes.
13945 gtk_widget_propagate_alpha (GtkWidget *widget)
13947 GtkWidgetPrivate *priv = widget->priv;
13949 gboolean norender, norender_children;
13952 parent = priv->parent;
13955 /* If this widget has an opacity group, never render it */
13956 priv->opacity_group ||
13957 /* If the parent has norender_children, propagate that here */
13958 (parent != NULL && parent->priv->norender_children);
13960 /* Windowed widget children should norender if: */
13961 norender_children =
13962 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
13963 !gtk_widget_get_has_window (widget) &&
13964 ( /* norender is set, or */
13966 /* widget has an alpha */
13970 if (gtk_widget_get_has_window (widget))
13972 if (priv->window != NULL && !gdk_window_has_native (priv->window))
13973 gdk_window_set_opacity (priv->window,
13974 norender ? 0 : priv->alpha / 255.0);
13976 else /* !has_window */
13978 for (l = priv->registered_windows; l != NULL; l = l->next)
13980 GdkWindow *w = l->data;
13981 if (!gdk_window_has_native (w))
13982 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
13986 priv->norender = norender;
13987 if (priv->norender_children != norender_children)
13989 priv->norender_children = norender_children;
13991 if (GTK_IS_CONTAINER (widget))
13992 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
13995 if (gtk_widget_get_realized (widget))
13996 gtk_widget_queue_draw (widget);
14000 gtk_widget_update_alpha (GtkWidget *widget)
14002 GtkWidgetPrivate *priv;
14006 priv = widget->priv;
14008 alpha = priv->user_alpha;
14013 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
14014 GTK_CSS_PROPERTY_OPACITY),
14016 opacity = CLAMP (opacity, 0.0, 1.0);
14017 alpha = round (priv->user_alpha * opacity);
14020 if (alpha == priv->alpha)
14023 priv->alpha = alpha;
14025 gtk_widget_propagate_alpha (widget);
14030 gtk_widget_set_has_opacity_group (GtkWidget *widget,
14031 gboolean has_opacity_group)
14033 GtkWidgetPrivate *priv;
14035 g_return_if_fail (GTK_IS_WIDGET (widget));
14037 priv = widget->priv;
14039 has_opacity_group = !!has_opacity_group;
14041 if (priv->opacity_group == has_opacity_group)
14044 priv->opacity_group = has_opacity_group;
14046 gtk_widget_propagate_alpha (widget);
14050 * gtk_widget_set_opacity:
14051 * @widget: a #GtkWidget
14052 * @opacity: desired opacity, between 0 and 1
14054 * Request the @widget to be rendered partially transparent,
14055 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14056 * are clamped to the [0,1] range.).
14057 * This works on both toplevel widget, and child widgets, although there
14058 * are some limitations:
14060 * For toplevel widgets this depends on the capabilities of the windowing
14061 * system. On X11 this has any effect only on X screens with a compositing manager
14062 * running. See gtk_widget_is_composited(). On Windows it should work
14063 * always, although setting a window's opacity after the window has been
14064 * shown causes it to flicker once on Windows.
14066 * For child widgets it doesn't work if any affected widget has a native window, or
14067 * disables double buffering.
14072 gtk_widget_set_opacity (GtkWidget *widget,
14075 GtkWidgetPrivate *priv;
14078 g_return_if_fail (GTK_IS_WIDGET (widget));
14080 priv = widget->priv;
14082 opacity = CLAMP (opacity, 0.0, 1.0);
14084 alpha = round (opacity * 255);
14086 /* As a kind of hack for internal use we treat an alpha very
14087 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14088 we want the opacity group behaviour wrt draw handling, but
14089 not actually an alpha value. See bug #687842 for discussions. */
14090 gtk_widget_set_has_opacity_group (widget,
14091 alpha == 255 && opacity != 1.0);
14093 if (alpha == priv->user_alpha)
14096 priv->user_alpha = alpha;
14098 gtk_widget_update_alpha (widget);
14103 * gtk_widget_get_opacity:
14104 * @widget: a #GtkWidget
14106 * Fetches the requested opacity for this widget. See
14107 * gtk_widget_set_opacity().
14109 * Return value: the requested opacity for this widget.
14114 gtk_widget_get_opacity (GtkWidget *widget)
14116 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14118 return widget->priv->alpha / 255.0;
14122 _gtk_widget_set_has_focus (GtkWidget *widget,
14123 gboolean has_focus)
14125 widget->priv->has_focus = has_focus;
14128 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14130 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14134 * gtk_widget_send_focus_change:
14135 * @widget: a #GtkWidget
14136 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14138 * Sends the focus change @event to @widget
14140 * This function is not meant to be used by applications. The only time it
14141 * should be used is when it is necessary for a #GtkWidget to assign focus
14142 * to a widget that is semantically owned by the first widget even though
14143 * it's not a direct child - for instance, a search entry in a floating
14144 * window similar to the quick search in #GtkTreeView.
14146 * An example of its usage is:
14149 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14151 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14152 * fevent->focus_change.in = TRUE;
14153 * fevent->focus_change.window = gtk_widget_get_window (widget);
14154 * if (fevent->focus_change.window != NULL)
14155 * g_object_ref (fevent->focus_change.window);
14157 * gtk_widget_send_focus_change (widget, fevent);
14159 * gdk_event_free (event);
14162 * Return value: the return value from the event signal emission: %TRUE
14163 * if the event was handled, and %FALSE otherwise
14168 gtk_widget_send_focus_change (GtkWidget *widget,
14173 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14174 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14176 g_object_ref (widget);
14178 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14180 res = gtk_widget_event (widget, event);
14182 g_object_notify (G_OBJECT (widget), "has-focus");
14184 g_object_unref (widget);
14190 * gtk_widget_in_destruction:
14191 * @widget: a #GtkWidget
14193 * Returns whether the widget is currently being destroyed.
14194 * This information can sometimes be used to avoid doing
14195 * unnecessary work.
14197 * Returns: %TRUE if @widget is being destroyed
14200 gtk_widget_in_destruction (GtkWidget *widget)
14202 return widget->priv->in_destruction;
14206 _gtk_widget_get_in_reparent (GtkWidget *widget)
14208 return widget->priv->in_reparent;
14212 _gtk_widget_set_in_reparent (GtkWidget *widget,
14213 gboolean in_reparent)
14215 widget->priv->in_reparent = in_reparent;
14219 _gtk_widget_get_anchored (GtkWidget *widget)
14221 return widget->priv->anchored;
14225 _gtk_widget_set_anchored (GtkWidget *widget,
14228 widget->priv->anchored = anchored;
14232 _gtk_widget_get_shadowed (GtkWidget *widget)
14234 return widget->priv->shadowed;
14238 _gtk_widget_set_shadowed (GtkWidget *widget,
14241 widget->priv->shadowed = shadowed;
14245 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14247 return widget->priv->alloc_needed;
14251 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14252 gboolean alloc_needed)
14254 widget->priv->alloc_needed = alloc_needed;
14258 _gtk_widget_add_sizegroup (GtkWidget *widget,
14263 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14264 groups = g_slist_prepend (groups, group);
14265 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14267 widget->priv->have_size_groups = TRUE;
14271 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14276 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14277 groups = g_slist_remove (groups, group);
14278 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14280 widget->priv->have_size_groups = groups != NULL;
14284 _gtk_widget_get_sizegroups (GtkWidget *widget)
14286 if (widget->priv->have_size_groups)
14287 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14293 _gtk_widget_add_attached_window (GtkWidget *widget,
14296 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14300 _gtk_widget_remove_attached_window (GtkWidget *widget,
14303 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14307 * gtk_widget_path_append_for_widget:
14308 * @path: a widget path
14309 * @widget: the widget to append to the widget path
14311 * Appends the data from @widget to the widget hierarchy represented
14312 * by @path. This function is a shortcut for adding information from
14313 * @widget to the given @path. This includes setting the name or
14314 * adding the style classes from @widget.
14316 * Returns: the position where the data was inserted
14321 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14326 g_return_val_if_fail (path != NULL, 0);
14327 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14329 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14331 if (widget->priv->name)
14332 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14334 if (widget->priv->context)
14336 GList *classes, *l;
14338 /* Also add any persistent classes in
14339 * the style context the widget path
14341 classes = gtk_style_context_list_classes (widget->priv->context);
14343 for (l = classes; l; l = l->next)
14344 gtk_widget_path_iter_add_class (path, pos, l->data);
14346 g_list_free (classes);
14353 _gtk_widget_create_path (GtkWidget *widget)
14357 parent = widget->priv->parent;
14360 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14363 /* Widget is either toplevel or unparented, treat both
14364 * as toplevels style wise, since there are situations
14365 * where style properties might be retrieved on that
14368 GtkWidget *attach_widget = NULL;
14369 GtkWidgetPath *result;
14371 if (GTK_IS_WINDOW (widget))
14372 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14374 if (attach_widget != NULL)
14375 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14377 result = gtk_widget_path_new ();
14379 gtk_widget_path_append_for_widget (result, widget);
14386 * gtk_widget_get_path:
14387 * @widget: a #GtkWidget
14389 * Returns the #GtkWidgetPath representing @widget, if the widget
14390 * is not connected to a toplevel widget, a partial path will be
14393 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14396 gtk_widget_get_path (GtkWidget *widget)
14398 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14400 if (!widget->priv->path)
14401 widget->priv->path = _gtk_widget_create_path (widget);
14403 return widget->priv->path;
14407 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14409 if (widget->priv->path)
14411 gtk_widget_path_free (widget->priv->path);
14412 widget->priv->path = NULL;
14415 if (gtk_widget_get_realized (widget))
14416 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14419 /* Compress all style updates so it
14420 * is only emitted once pre-realize.
14422 widget->priv->style_update_pending = TRUE;
14427 * gtk_widget_get_style_context:
14428 * @widget: a #GtkWidget
14430 * Returns the style context associated to @widget.
14432 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14433 * must not be freed.
14436 gtk_widget_get_style_context (GtkWidget *widget)
14438 GtkWidgetPrivate *priv;
14440 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14442 priv = widget->priv;
14444 if (G_UNLIKELY (priv->context == NULL))
14448 priv->context = gtk_style_context_new ();
14450 gtk_style_context_set_state (priv->context, priv->state_flags);
14452 screen = gtk_widget_get_screen (widget);
14454 gtk_style_context_set_screen (priv->context, screen);
14457 gtk_style_context_set_parent (priv->context,
14458 gtk_widget_get_style_context (priv->parent));
14460 _gtk_style_context_set_widget (priv->context, widget);
14463 return widget->priv->context;
14467 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14468 GtkCssChange change)
14470 GtkWidgetPrivate *priv;
14472 priv = widget->priv;
14474 if (priv->context == NULL)
14477 _gtk_style_context_queue_invalidate (priv->context, change);
14481 * gtk_widget_get_modifier_mask:
14482 * @widget: a #GtkWidget
14483 * @intent: the use case for the modifier mask
14485 * Returns the modifier mask the @widget's windowing system backend
14486 * uses for a particular purpose.
14488 * See gdk_keymap_get_modifier_mask().
14490 * Returns: the modifier mask used for @intent.
14495 gtk_widget_get_modifier_mask (GtkWidget *widget,
14496 GdkModifierIntent intent)
14498 GdkDisplay *display;
14500 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14502 display = gtk_widget_get_display (widget);
14504 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14509 _gtk_widget_get_style (GtkWidget *widget)
14511 return widget->priv->style;
14515 _gtk_widget_set_style (GtkWidget *widget,
14518 widget->priv->style = style;
14522 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14525 GActionMuxer *parent_muxer;
14527 if (widget->priv->muxer == NULL)
14530 if (GTK_IS_MENU (widget))
14531 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14533 parent = gtk_widget_get_parent (widget);
14535 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14537 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14541 _gtk_widget_get_action_muxer (GtkWidget *widget)
14543 if (widget->priv->muxer == NULL)
14545 widget->priv->muxer = g_action_muxer_new ();
14546 _gtk_widget_update_parent_muxer (widget);
14549 return widget->priv->muxer;
14553 * gtk_widget_insert_action_group:
14554 * @widget: a #GtkWidget
14555 * @name: the prefix for actions in @group
14556 * @group: a #GActionGroup
14558 * Inserts @group into @widget. Children of @widget that implement
14559 * #GtkActionable can then be associated with actions in @group by
14560 * setting their 'action-name' to
14561 * @prefix.<replaceable>action-name</replaceable>.
14566 gtk_widget_insert_action_group (GtkWidget *widget,
14568 GActionGroup *group)
14570 GActionMuxer *muxer;
14572 g_return_if_fail (GTK_IS_WIDGET (widget));
14573 g_return_if_fail (name != NULL);
14575 muxer = _gtk_widget_get_action_muxer (widget);
14578 g_action_muxer_insert (muxer, name, group);
14580 g_action_muxer_remove (muxer, name);