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_size_request:
4782 * @widget: a #GtkWidget
4783 * @requisition: (out): a #GtkRequisition to be filled in
4785 * This function is typically used when implementing a #GtkContainer
4786 * subclass. Obtains the preferred size of a widget. The container
4787 * uses this information to arrange its child widgets and decide what
4788 * size allocations to give them with gtk_widget_size_allocate().
4790 * You can also call this function from an application, with some
4791 * caveats. Most notably, getting a size request requires the widget
4792 * to be associated with a screen, because font information may be
4793 * needed. Multihead-aware applications should keep this in mind.
4795 * Also remember that the size request is not necessarily the size
4796 * a widget will actually be allocated.
4798 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4801 gtk_widget_size_request (GtkWidget *widget,
4802 GtkRequisition *requisition)
4804 g_return_if_fail (GTK_IS_WIDGET (widget));
4806 gtk_widget_get_preferred_size (widget, requisition, NULL);
4810 * gtk_widget_get_child_requisition:
4811 * @widget: a #GtkWidget
4812 * @requisition: (out): a #GtkRequisition to be filled in
4814 * This function is only for use in widget implementations. Obtains
4815 * @widget->requisition, unless someone has forced a particular
4816 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4817 * in which case it returns that geometry instead of the widget's
4820 * This function differs from gtk_widget_size_request() in that
4821 * it retrieves the last size request value from @widget->requisition,
4822 * while gtk_widget_size_request() actually calls the "size_request" method
4823 * on @widget to compute the size request and fill in @widget->requisition,
4824 * and only then returns @widget->requisition.
4826 * Because this function does not call the "size_request" method, it
4827 * can only be used when you know that @widget->requisition is
4828 * up-to-date, that is, gtk_widget_size_request() has been called
4829 * since the last time a resize was queued. In general, only container
4830 * implementations have this information; applications should use
4831 * gtk_widget_size_request().
4834 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4837 gtk_widget_get_child_requisition (GtkWidget *widget,
4838 GtkRequisition *requisition)
4840 gtk_widget_get_preferred_size (widget, requisition, NULL);
4844 invalidate_predicate (GdkWindow *window,
4849 gdk_window_get_user_data (window, &user_data);
4851 return (user_data == data);
4854 /* Invalidate @region in widget->window and all children
4855 * of widget->window owned by widget. @region is in the
4856 * same coordinates as widget->allocation and will be
4857 * modified by this call.
4860 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4861 cairo_region_t *region)
4863 GtkWidgetPrivate *priv = widget->priv;
4865 if (!gtk_widget_get_realized (widget))
4868 if (gtk_widget_get_has_window (widget) && priv->parent)
4872 gdk_window_get_position (priv->window, &x, &y);
4873 cairo_region_translate (region, -x, -y);
4876 gdk_window_invalidate_maybe_recurse (priv->window, region,
4877 invalidate_predicate, widget);
4881 * gtk_widget_size_allocate:
4882 * @widget: a #GtkWidget
4883 * @allocation: position and size to be allocated to @widget
4885 * This function is only used by #GtkContainer subclasses, to assign a size
4886 * and position to their child widgets.
4888 * In this function, the allocation may be adjusted. It will be forced
4889 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4890 * method on the child will be used to adjust the allocation. Standard
4891 * adjustments include removing the widget's margins, and applying the
4892 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4895 gtk_widget_size_allocate (GtkWidget *widget,
4896 GtkAllocation *allocation)
4898 GtkWidgetPrivate *priv;
4899 GdkRectangle real_allocation;
4900 GdkRectangle old_allocation;
4901 GdkRectangle adjusted_allocation;
4902 gboolean alloc_needed;
4903 gboolean size_changed;
4904 gboolean position_changed;
4905 gint natural_width, natural_height, dummy;
4906 gint min_width, min_height;
4908 priv = widget->priv;
4910 g_return_if_fail (GTK_IS_WIDGET (widget));
4912 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4915 gtk_widget_push_verify_invariants (widget);
4917 #ifdef G_ENABLE_DEBUG
4918 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4929 parent = gtk_widget_get_parent (parent);
4932 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4933 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4934 2 * depth, " ", name,
4935 allocation->width, allocation->height);
4937 #endif /* G_ENABLE_DEBUG */
4939 alloc_needed = priv->alloc_needed;
4940 /* Preserve request/allocate ordering */
4941 priv->alloc_needed = FALSE;
4943 old_allocation = priv->allocation;
4944 real_allocation = *allocation;
4946 adjusted_allocation = real_allocation;
4947 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4949 /* Go ahead and request the height for allocated width, note that the internals
4950 * of get_height_for_width will internally limit the for_size to natural size
4951 * when aligning implicitly.
4953 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4954 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
4958 /* Go ahead and request the width for allocated height, note that the internals
4959 * of get_width_for_height will internally limit the for_size to natural size
4960 * when aligning implicitly.
4962 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4963 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
4966 #ifdef G_ENABLE_DEBUG
4967 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4969 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
4970 !GTK_IS_SCROLLABLE (widget))
4971 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
4972 "Allocation is %dx%d, but minimum required size is %dx%d.",
4973 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
4974 G_OBJECT_TYPE_NAME (widget), widget,
4975 real_allocation.width, real_allocation.height,
4976 min_width, min_height);
4979 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4980 * allocated sizes and possibly limit them to the natural sizes */
4981 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4982 GTK_ORIENTATION_HORIZONTAL,
4985 &adjusted_allocation.x,
4986 &adjusted_allocation.width);
4987 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4988 GTK_ORIENTATION_VERTICAL,
4991 &adjusted_allocation.y,
4992 &adjusted_allocation.height);
4994 if (adjusted_allocation.x < real_allocation.x ||
4995 adjusted_allocation.y < real_allocation.y ||
4996 (adjusted_allocation.x + adjusted_allocation.width) >
4997 (real_allocation.x + real_allocation.width) ||
4998 (adjusted_allocation.y + adjusted_allocation.height >
4999 real_allocation.y + real_allocation.height))
5001 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",
5002 G_OBJECT_TYPE_NAME (widget), widget,
5003 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5004 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5005 adjusted_allocation = real_allocation; /* veto it */
5009 real_allocation = adjusted_allocation;
5012 if (real_allocation.width < 0 || real_allocation.height < 0)
5014 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5015 real_allocation.width,
5016 real_allocation.height);
5019 real_allocation.width = MAX (real_allocation.width, 1);
5020 real_allocation.height = MAX (real_allocation.height, 1);
5022 size_changed = (old_allocation.width != real_allocation.width ||
5023 old_allocation.height != real_allocation.height);
5024 position_changed = (old_allocation.x != real_allocation.x ||
5025 old_allocation.y != real_allocation.y);
5027 if (!alloc_needed && !size_changed && !position_changed)
5030 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5032 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5033 priv->alloc_needed = FALSE;
5035 if (gtk_widget_get_mapped (widget))
5037 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5039 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5041 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5042 cairo_region_union_rectangle (invalidate, &old_allocation);
5044 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5045 cairo_region_destroy (invalidate);
5050 if (priv->redraw_on_alloc)
5052 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5054 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5055 cairo_region_union_rectangle (invalidate, &old_allocation);
5057 gtk_widget_invalidate_widget_windows (widget, invalidate);
5058 cairo_region_destroy (invalidate);
5063 if ((size_changed || position_changed) && priv->parent &&
5064 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5066 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5067 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5068 cairo_region_destroy (invalidate);
5072 gtk_widget_pop_verify_invariants (widget);
5076 * gtk_widget_common_ancestor:
5077 * @widget_a: a #GtkWidget
5078 * @widget_b: a #GtkWidget
5080 * Find the common ancestor of @widget_a and @widget_b that
5081 * is closest to the two widgets.
5083 * Return value: the closest common ancestor of @widget_a and
5084 * @widget_b or %NULL if @widget_a and @widget_b do not
5085 * share a common ancestor.
5088 gtk_widget_common_ancestor (GtkWidget *widget_a,
5089 GtkWidget *widget_b)
5091 GtkWidget *parent_a;
5092 GtkWidget *parent_b;
5096 parent_a = widget_a;
5097 while (parent_a->priv->parent)
5099 parent_a = parent_a->priv->parent;
5103 parent_b = widget_b;
5104 while (parent_b->priv->parent)
5106 parent_b = parent_b->priv->parent;
5110 if (parent_a != parent_b)
5113 while (depth_a > depth_b)
5115 widget_a = widget_a->priv->parent;
5119 while (depth_b > depth_a)
5121 widget_b = widget_b->priv->parent;
5125 while (widget_a != widget_b)
5127 widget_a = widget_a->priv->parent;
5128 widget_b = widget_b->priv->parent;
5135 * gtk_widget_translate_coordinates:
5136 * @src_widget: a #GtkWidget
5137 * @dest_widget: a #GtkWidget
5138 * @src_x: X position relative to @src_widget
5139 * @src_y: Y position relative to @src_widget
5140 * @dest_x: (out): location to store X position relative to @dest_widget
5141 * @dest_y: (out): location to store Y position relative to @dest_widget
5143 * Translate coordinates relative to @src_widget's allocation to coordinates
5144 * relative to @dest_widget's allocations. In order to perform this
5145 * operation, both widgets must be realized, and must share a common
5148 * Return value: %FALSE if either widget was not realized, or there
5149 * was no common ancestor. In this case, nothing is stored in
5150 * *@dest_x and *@dest_y. Otherwise %TRUE.
5153 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5154 GtkWidget *dest_widget,
5160 GtkWidgetPrivate *src_priv = src_widget->priv;
5161 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5162 GtkWidget *ancestor;
5164 GList *dest_list = NULL;
5166 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5167 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5169 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5170 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5173 /* Translate from allocation relative to window relative */
5174 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5177 gdk_window_get_position (src_priv->window, &wx, &wy);
5179 src_x -= wx - src_priv->allocation.x;
5180 src_y -= wy - src_priv->allocation.y;
5184 src_x += src_priv->allocation.x;
5185 src_y += src_priv->allocation.y;
5188 /* Translate to the common ancestor */
5189 window = src_priv->window;
5190 while (window != ancestor->priv->window)
5194 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5199 window = gdk_window_get_effective_parent (window);
5201 if (!window) /* Handle GtkHandleBox */
5206 window = dest_priv->window;
5207 while (window != ancestor->priv->window)
5209 dest_list = g_list_prepend (dest_list, window);
5211 window = gdk_window_get_effective_parent (window);
5213 if (!window) /* Handle GtkHandleBox */
5215 g_list_free (dest_list);
5224 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5229 dest_list = g_list_remove (dest_list, dest_list->data);
5232 /* Translate from window relative to allocation relative */
5233 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5236 gdk_window_get_position (dest_priv->window, &wx, &wy);
5238 src_x += wx - dest_priv->allocation.x;
5239 src_y += wy - dest_priv->allocation.y;
5243 src_x -= dest_priv->allocation.x;
5244 src_y -= dest_priv->allocation.y;
5256 gtk_widget_real_size_allocate (GtkWidget *widget,
5257 GtkAllocation *allocation)
5259 GtkWidgetPrivate *priv = widget->priv;
5261 priv->allocation = *allocation;
5263 if (gtk_widget_get_realized (widget) &&
5264 gtk_widget_get_has_window (widget))
5266 gdk_window_move_resize (priv->window,
5267 allocation->x, allocation->y,
5268 allocation->width, allocation->height);
5272 /* translate initial/final into start/end */
5274 effective_align (GtkAlign align,
5275 GtkTextDirection direction)
5279 case GTK_ALIGN_START:
5280 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5282 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5289 adjust_for_align (GtkAlign align,
5291 gint *allocated_pos,
5292 gint *allocated_size)
5296 case GTK_ALIGN_FILL:
5297 /* change nothing */
5299 case GTK_ALIGN_START:
5300 /* keep *allocated_pos where it is */
5301 *allocated_size = MIN (*allocated_size, *natural_size);
5304 if (*allocated_size > *natural_size)
5306 *allocated_pos += (*allocated_size - *natural_size);
5307 *allocated_size = *natural_size;
5310 case GTK_ALIGN_CENTER:
5311 if (*allocated_size > *natural_size)
5313 *allocated_pos += (*allocated_size - *natural_size) / 2;
5314 *allocated_size = MIN (*allocated_size, *natural_size);
5321 adjust_for_margin(gint start_margin,
5325 gint *allocated_pos,
5326 gint *allocated_size)
5328 *minimum_size -= (start_margin + end_margin);
5329 *natural_size -= (start_margin + end_margin);
5330 *allocated_pos += start_margin;
5331 *allocated_size -= (start_margin + end_margin);
5335 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5336 GtkOrientation orientation,
5339 gint *allocated_pos,
5340 gint *allocated_size)
5342 const GtkWidgetAuxInfo *aux_info;
5344 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5346 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5348 adjust_for_margin (aux_info->margin.left,
5349 aux_info->margin.right,
5350 minimum_size, natural_size,
5351 allocated_pos, allocated_size);
5352 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5353 natural_size, allocated_pos, allocated_size);
5357 adjust_for_margin (aux_info->margin.top,
5358 aux_info->margin.bottom,
5359 minimum_size, natural_size,
5360 allocated_pos, allocated_size);
5361 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5362 natural_size, allocated_pos, allocated_size);
5367 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5370 GtkWidgetPrivate *priv = widget->priv;
5372 /* widgets must be onscreen for accels to take effect */
5373 return gtk_widget_is_sensitive (widget) &&
5374 gtk_widget_is_drawable (widget) &&
5375 gdk_window_is_viewable (priv->window);
5379 * gtk_widget_can_activate_accel:
5380 * @widget: a #GtkWidget
5381 * @signal_id: the ID of a signal installed on @widget
5383 * Determines whether an accelerator that activates the signal
5384 * identified by @signal_id can currently be activated.
5385 * This is done by emitting the #GtkWidget::can-activate-accel
5386 * signal on @widget; if the signal isn't overridden by a
5387 * handler or in a derived widget, then the default check is
5388 * that the widget must be sensitive, and the widget and all
5389 * its ancestors mapped.
5391 * Return value: %TRUE if the accelerator can be activated.
5396 gtk_widget_can_activate_accel (GtkWidget *widget,
5399 gboolean can_activate = FALSE;
5400 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5401 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5402 return can_activate;
5411 closure_accel_activate (GClosure *closure,
5412 GValue *return_value,
5413 guint n_param_values,
5414 const GValue *param_values,
5415 gpointer invocation_hint,
5416 gpointer marshal_data)
5418 AccelClosure *aclosure = (AccelClosure*) closure;
5419 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5422 g_signal_emit (closure->data, aclosure->signal_id, 0);
5424 /* whether accelerator was handled */
5425 g_value_set_boolean (return_value, can_activate);
5429 closures_destroy (gpointer data)
5431 GSList *slist, *closures = data;
5433 for (slist = closures; slist; slist = slist->next)
5435 g_closure_invalidate (slist->data);
5436 g_closure_unref (slist->data);
5438 g_slist_free (closures);
5442 widget_new_accel_closure (GtkWidget *widget,
5445 AccelClosure *aclosure;
5446 GClosure *closure = NULL;
5447 GSList *slist, *closures;
5449 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5450 for (slist = closures; slist; slist = slist->next)
5451 if (!gtk_accel_group_from_accel_closure (slist->data))
5453 /* reuse this closure */
5454 closure = slist->data;
5459 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5460 closures = g_slist_prepend (closures, g_closure_ref (closure));
5461 g_closure_sink (closure);
5462 g_closure_set_marshal (closure, closure_accel_activate);
5464 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5466 aclosure = (AccelClosure*) closure;
5467 g_assert (closure->data == widget);
5468 g_assert (closure->marshal == closure_accel_activate);
5469 aclosure->signal_id = signal_id;
5475 * gtk_widget_add_accelerator:
5476 * @widget: widget to install an accelerator on
5477 * @accel_signal: widget signal to emit on accelerator activation
5478 * @accel_group: accel group for this widget, added to its toplevel
5479 * @accel_key: GDK keyval of the accelerator
5480 * @accel_mods: modifier key combination of the accelerator
5481 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5483 * Installs an accelerator for this @widget in @accel_group that causes
5484 * @accel_signal to be emitted if the accelerator is activated.
5485 * The @accel_group needs to be added to the widget's toplevel via
5486 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5487 * Accelerators added through this function are not user changeable during
5488 * runtime. If you want to support accelerators that can be changed by the
5489 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5490 * gtk_menu_item_set_accel_path() instead.
5493 gtk_widget_add_accelerator (GtkWidget *widget,
5494 const gchar *accel_signal,
5495 GtkAccelGroup *accel_group,
5497 GdkModifierType accel_mods,
5498 GtkAccelFlags accel_flags)
5503 g_return_if_fail (GTK_IS_WIDGET (widget));
5504 g_return_if_fail (accel_signal != NULL);
5505 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5507 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5508 if (!query.signal_id ||
5509 !(query.signal_flags & G_SIGNAL_ACTION) ||
5510 query.return_type != G_TYPE_NONE ||
5513 /* hmm, should be elaborate enough */
5514 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5515 G_OBJECT_TYPE_NAME (widget), accel_signal);
5519 closure = widget_new_accel_closure (widget, query.signal_id);
5521 g_object_ref (widget);
5523 /* install the accelerator. since we don't map this onto an accel_path,
5524 * the accelerator will automatically be locked.
5526 gtk_accel_group_connect (accel_group,
5529 accel_flags | GTK_ACCEL_LOCKED,
5532 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5534 g_object_unref (widget);
5538 * gtk_widget_remove_accelerator:
5539 * @widget: widget to install an accelerator on
5540 * @accel_group: accel group for this widget
5541 * @accel_key: GDK keyval of the accelerator
5542 * @accel_mods: modifier key combination of the accelerator
5544 * Removes an accelerator from @widget, previously installed with
5545 * gtk_widget_add_accelerator().
5547 * Returns: whether an accelerator was installed and could be removed
5550 gtk_widget_remove_accelerator (GtkWidget *widget,
5551 GtkAccelGroup *accel_group,
5553 GdkModifierType accel_mods)
5555 GtkAccelGroupEntry *ag_entry;
5556 GList *slist, *clist;
5559 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5560 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5562 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5563 clist = gtk_widget_list_accel_closures (widget);
5564 for (slist = clist; slist; slist = slist->next)
5568 for (i = 0; i < n; i++)
5569 if (slist->data == (gpointer) ag_entry[i].closure)
5571 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5573 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5575 g_list_free (clist);
5580 g_list_free (clist);
5582 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5583 accel_key, accel_mods, accel_group,
5584 G_OBJECT_TYPE_NAME (widget), widget);
5590 * gtk_widget_list_accel_closures:
5591 * @widget: widget to list accelerator closures for
5593 * Lists the closures used by @widget for accelerator group connections
5594 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5595 * The closures can be used to monitor accelerator changes on @widget,
5596 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5597 * #GtkAccelGroup of a closure which can be found out with
5598 * gtk_accel_group_from_accel_closure().
5600 * Return value: (transfer container) (element-type GClosure):
5601 * a newly allocated #GList of closures
5604 gtk_widget_list_accel_closures (GtkWidget *widget)
5607 GList *clist = NULL;
5609 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5611 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5612 if (gtk_accel_group_from_accel_closure (slist->data))
5613 clist = g_list_prepend (clist, slist->data);
5619 GtkAccelGroup *accel_group;
5624 destroy_accel_path (gpointer data)
5626 AccelPath *apath = data;
5628 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5630 /* closures_destroy takes care of unrefing the closure */
5631 g_object_unref (apath->accel_group);
5633 g_slice_free (AccelPath, apath);
5638 * gtk_widget_set_accel_path:
5639 * @widget: a #GtkWidget
5640 * @accel_path: (allow-none): path used to look up the accelerator
5641 * @accel_group: (allow-none): a #GtkAccelGroup.
5643 * Given an accelerator group, @accel_group, and an accelerator path,
5644 * @accel_path, sets up an accelerator in @accel_group so whenever the
5645 * key binding that is defined for @accel_path is pressed, @widget
5646 * will be activated. This removes any accelerators (for any
5647 * accelerator group) installed by previous calls to
5648 * gtk_widget_set_accel_path(). Associating accelerators with
5649 * paths allows them to be modified by the user and the modifications
5650 * to be saved for future use. (See gtk_accel_map_save().)
5652 * This function is a low level function that would most likely
5653 * be used by a menu creation system like #GtkUIManager. If you
5654 * use #GtkUIManager, setting up accelerator paths will be done
5657 * Even when you you aren't using #GtkUIManager, if you only want to
5658 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5659 * provides a somewhat more convenient interface.
5661 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5662 * pass a static string, you can save some memory by interning it first with
5663 * g_intern_static_string().
5666 gtk_widget_set_accel_path (GtkWidget *widget,
5667 const gchar *accel_path,
5668 GtkAccelGroup *accel_group)
5672 g_return_if_fail (GTK_IS_WIDGET (widget));
5673 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5677 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5678 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5680 gtk_accel_map_add_entry (accel_path, 0, 0);
5681 apath = g_slice_new (AccelPath);
5682 apath->accel_group = g_object_ref (accel_group);
5683 apath->path_quark = g_quark_from_string (accel_path);
5684 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5689 /* also removes possible old settings */
5690 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5693 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5695 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5699 _gtk_widget_get_accel_path (GtkWidget *widget,
5704 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5706 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5708 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5709 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5713 * gtk_widget_mnemonic_activate:
5714 * @widget: a #GtkWidget
5715 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5717 * Emits the #GtkWidget::mnemonic-activate signal.
5719 * The default handler for this signal activates the @widget if
5720 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5723 * Returns: %TRUE if the signal has been handled
5726 gtk_widget_mnemonic_activate (GtkWidget *widget,
5727 gboolean group_cycling)
5731 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5733 group_cycling = group_cycling != FALSE;
5734 if (!gtk_widget_is_sensitive (widget))
5737 g_signal_emit (widget,
5738 widget_signals[MNEMONIC_ACTIVATE],
5746 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5747 gboolean group_cycling)
5749 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5750 gtk_widget_activate (widget);
5751 else if (gtk_widget_get_can_focus (widget))
5752 gtk_widget_grab_focus (widget);
5755 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5756 G_OBJECT_TYPE_NAME (widget));
5757 gtk_widget_error_bell (widget);
5762 static const cairo_user_data_key_t event_key;
5765 _gtk_cairo_get_event (cairo_t *cr)
5767 g_return_val_if_fail (cr != NULL, NULL);
5769 return cairo_get_user_data (cr, &event_key);
5773 gtk_cairo_set_event (cairo_t *cr,
5774 GdkEventExpose *event)
5776 cairo_set_user_data (cr, &event_key, event, NULL);
5780 * gtk_cairo_should_draw_window:
5781 * @cr: a cairo context
5782 * @window: the window to check. @window may not be an input-only
5785 * This function is supposed to be called in #GtkWidget::draw
5786 * implementations for widgets that support multiple windows.
5787 * @cr must be untransformed from invoking of the draw function.
5788 * This function will return %TRUE if the contents of the given
5789 * @window are supposed to be drawn and %FALSE otherwise. Note
5790 * that when the drawing was not initiated by the windowing
5791 * system this function will return %TRUE for all windows, so
5792 * you need to draw the bottommost window first. Also, do not
5793 * use "else if" statements to check which window should be drawn.
5795 * Returns: %TRUE if @window should be drawn
5800 gtk_cairo_should_draw_window (cairo_t *cr,
5803 GdkEventExpose *event;
5805 g_return_val_if_fail (cr != NULL, FALSE);
5806 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5808 event = _gtk_cairo_get_event (cr);
5810 return event == NULL ||
5811 event->window == window;
5815 gtk_widget_get_clip_draw (GtkWidget *widget)
5817 /* labels are not clipped, because clipping them would cause
5818 * mnemonics to not appear on characters that go beyond the
5820 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5822 if (GTK_IS_LABEL (widget))
5828 /* code shared by gtk_container_propagate_draw() and
5832 _gtk_widget_draw_internal (GtkWidget *widget,
5834 gboolean clip_to_size)
5836 if (!gtk_widget_is_drawable (widget))
5839 clip_to_size &= gtk_widget_get_clip_draw (widget);
5843 cairo_rectangle (cr,
5845 widget->priv->allocation.width,
5846 widget->priv->allocation.height);
5850 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5854 g_signal_emit (widget, widget_signals[DRAW],
5858 if (cairo_status (cr) &&
5859 _gtk_cairo_get_event (cr))
5861 /* We check the event so we only warn about internal GTK calls.
5862 * Errors might come from PDF streams having write failures and
5863 * we don't want to spam stderr in that case.
5864 * We do want to catch errors from
5866 g_warning ("drawing failure for widget `%s': %s",
5867 G_OBJECT_TYPE_NAME (widget),
5868 cairo_status_to_string (cairo_status (cr)));
5875 * @widget: the widget to draw. It must be drawable (see
5876 * gtk_widget_is_drawable()) and a size must have been allocated.
5877 * @cr: a cairo context to draw to
5879 * Draws @widget to @cr. The top left corner of the widget will be
5880 * drawn to the currently set origin point of @cr.
5882 * You should pass a cairo context as @cr argument that is in an
5883 * original state. Otherwise the resulting drawing is undefined. For
5884 * example changing the operator using cairo_set_operator() or the
5885 * line width using cairo_set_line_width() might have unwanted side
5887 * You may however change the context's transform matrix - like with
5888 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5889 * region with cairo_clip() prior to calling this function. Also, it
5890 * is fine to modify the context with cairo_save() and
5891 * cairo_push_group() prior to calling this function.
5893 * <note><para>Special purpose widgets may contain special code for
5894 * rendering to the screen and might appear differently on screen
5895 * and when rendered using gtk_widget_draw().</para></note>
5900 gtk_widget_draw (GtkWidget *widget,
5903 GdkEventExpose *tmp_event;
5905 g_return_if_fail (GTK_IS_WIDGET (widget));
5906 g_return_if_fail (!widget->priv->alloc_needed);
5907 g_return_if_fail (cr != NULL);
5910 /* We have to reset the event here so that draw functions can call
5911 * gtk_widget_draw() on random other widgets and get the desired
5912 * effect: Drawing all contents, not just the current window.
5914 tmp_event = _gtk_cairo_get_event (cr);
5915 gtk_cairo_set_event (cr, NULL);
5917 _gtk_widget_draw_internal (widget, cr, TRUE);
5919 gtk_cairo_set_event (cr, tmp_event);
5924 gtk_widget_real_key_press_event (GtkWidget *widget,
5927 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5931 gtk_widget_real_key_release_event (GtkWidget *widget,
5934 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5938 gtk_widget_real_focus_in_event (GtkWidget *widget,
5939 GdkEventFocus *event)
5941 gtk_widget_queue_draw (widget);
5947 gtk_widget_real_focus_out_event (GtkWidget *widget,
5948 GdkEventFocus *event)
5950 gtk_widget_queue_draw (widget);
5956 gtk_widget_real_touch_event (GtkWidget *widget,
5957 GdkEventTouch *event)
5960 gboolean return_val;
5963 if (!event->emulating_pointer)
5966 if (event->type == GDK_TOUCH_BEGIN ||
5967 event->type == GDK_TOUCH_END)
5971 if (event->type == GDK_TOUCH_BEGIN)
5973 type = GDK_BUTTON_PRESS;
5974 signum = BUTTON_PRESS_EVENT;
5978 type = GDK_BUTTON_RELEASE;
5979 signum = BUTTON_RELEASE_EVENT;
5981 bevent = gdk_event_new (type);
5982 bevent->any.window = g_object_ref (event->window);
5983 bevent->any.send_event = FALSE;
5984 bevent->button.time = event->time;
5985 bevent->button.state = event->state;
5986 bevent->button.button = 1;
5987 bevent->button.x_root = event->x_root;
5988 bevent->button.y_root = event->y_root;
5989 bevent->button.x = event->x;
5990 bevent->button.y = event->y;
5991 bevent->button.device = event->device;
5992 bevent->button.axes = g_memdup (event->axes,
5993 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
5994 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
5996 else if (event->type == GDK_TOUCH_UPDATE)
5998 signum = MOTION_NOTIFY_EVENT;
5999 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6000 bevent->any.window = g_object_ref (event->window);
6001 bevent->any.send_event = FALSE;
6002 bevent->motion.time = event->time;
6003 bevent->motion.state = event->state;
6004 bevent->motion.x_root = event->x_root;
6005 bevent->motion.y_root = event->y_root;
6006 bevent->motion.x = event->x;
6007 bevent->motion.y = event->y;
6008 bevent->motion.device = event->device;
6009 bevent->motion.is_hint = FALSE;
6010 bevent->motion.axes = g_memdup (event->axes,
6011 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6012 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6017 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6019 gdk_event_free (bevent);
6025 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6026 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6030 * @widget: a #GtkWidget
6031 * @event: a #GdkEvent
6033 * Rarely-used function. This function is used to emit
6034 * the event signals on a widget (those signals should never
6035 * be emitted without using this function to do so).
6036 * If you want to synthesize an event though, don't use this function;
6037 * instead, use gtk_main_do_event() so the event will behave as if
6038 * it were in the event queue. Don't synthesize expose events; instead,
6039 * use gdk_window_invalidate_rect() to invalidate a region of the
6042 * Return value: return from the event signal emission (%TRUE if
6043 * the event was handled)
6046 gtk_widget_event (GtkWidget *widget,
6049 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6050 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6052 if (event->type == GDK_EXPOSE)
6054 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6055 "the same effect, call gdk_window_invalidate_rect/region(), "
6056 "followed by gdk_window_process_updates().");
6060 return gtk_widget_event_internal (widget, event);
6064 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6065 GtkCapturedEventHandler callback)
6067 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6071 _gtk_widget_captured_event (GtkWidget *widget,
6074 gboolean return_val = FALSE;
6075 GtkCapturedEventHandler handler;
6077 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6078 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6080 if (event->type == GDK_EXPOSE)
6082 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6083 "the same effect, call gdk_window_invalidate_rect/region(), "
6084 "followed by gdk_window_process_updates().");
6088 if (!event_window_is_still_viewable (event))
6091 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6095 g_object_ref (widget);
6097 return_val = handler (widget, event);
6098 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6100 /* The widget that was originally to receive the event
6101 * handles motion hints, but the capturing widget might
6102 * not, so ensure we get further motion events.
6105 event->type == GDK_MOTION_NOTIFY &&
6106 event->motion.is_hint &&
6107 (gdk_window_get_events (event->any.window) &
6108 GDK_POINTER_MOTION_HINT_MASK) != 0)
6109 gdk_event_request_motions (&event->motion);
6111 g_object_unref (widget);
6116 /* Returns TRUE if a translation should be done */
6118 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6123 GdkWindow *w, *widget_window;
6125 if (!gtk_widget_get_has_window (widget))
6127 *x = -widget->priv->allocation.x;
6128 *y = -widget->priv->allocation.y;
6136 widget_window = gtk_widget_get_window (widget);
6138 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6141 gdk_window_get_position (w, &wx, &wy);
6158 * gtk_cairo_transform_to_window:
6159 * @cr: the cairo context to transform
6160 * @widget: the widget the context is currently centered for
6161 * @window: the window to transform the context to
6163 * Transforms the given cairo context @cr that from @widget-relative
6164 * coordinates to @window-relative coordinates.
6165 * If the @widget's window is not an ancestor of @window, no
6166 * modification will be applied.
6168 * This is the inverse to the transformation GTK applies when
6169 * preparing an expose event to be emitted with the #GtkWidget::draw
6170 * signal. It is intended to help porting multiwindow widgets from
6171 * GTK+ 2 to the rendering architecture of GTK+ 3.
6176 gtk_cairo_transform_to_window (cairo_t *cr,
6182 g_return_if_fail (cr != NULL);
6183 g_return_if_fail (GTK_IS_WIDGET (widget));
6184 g_return_if_fail (GDK_IS_WINDOW (window));
6186 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6187 cairo_translate (cr, x, y);
6191 * gtk_widget_send_expose:
6192 * @widget: a #GtkWidget
6193 * @event: a expose #GdkEvent
6195 * Very rarely-used function. This function is used to emit
6196 * an expose event on a widget. This function is not normally used
6197 * directly. The only time it is used is when propagating an expose
6198 * event to a child %NO_WINDOW widget, and that is normally done
6199 * using gtk_container_propagate_draw().
6201 * If you want to force an area of a window to be redrawn,
6202 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6203 * To cause the redraw to be done immediately, follow that call
6204 * with a call to gdk_window_process_updates().
6206 * Return value: return from the event signal emission (%TRUE if
6207 * the event was handled)
6210 gtk_widget_send_expose (GtkWidget *widget,
6213 gboolean result = FALSE;
6218 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6219 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6220 g_return_val_if_fail (event != NULL, TRUE);
6221 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6223 cr = gdk_cairo_create (event->expose.window);
6224 gtk_cairo_set_event (cr, &event->expose);
6226 gdk_cairo_region (cr, event->expose.region);
6229 do_clip = _gtk_widget_get_translation_to_window (widget,
6230 event->expose.window,
6232 cairo_translate (cr, -x, -y);
6234 _gtk_widget_draw_internal (widget, cr, do_clip);
6236 /* unset here, so if someone keeps a reference to cr we
6237 * don't leak the window. */
6238 gtk_cairo_set_event (cr, NULL);
6245 event_window_is_still_viewable (GdkEvent *event)
6247 /* Check that we think the event's window is viewable before
6248 * delivering the event, to prevent suprises. We do this here
6249 * at the last moment, since the event may have been queued
6250 * up behind other events, held over a recursive main loop, etc.
6252 switch (event->type)
6255 case GDK_MOTION_NOTIFY:
6256 case GDK_BUTTON_PRESS:
6257 case GDK_2BUTTON_PRESS:
6258 case GDK_3BUTTON_PRESS:
6260 case GDK_ENTER_NOTIFY:
6261 case GDK_PROXIMITY_IN:
6263 return event->any.window && gdk_window_is_viewable (event->any.window);
6266 /* The following events are the second half of paired events;
6267 * we always deliver them to deal with widgets that clean up
6268 * on the second half.
6270 case GDK_BUTTON_RELEASE:
6271 case GDK_KEY_RELEASE:
6272 case GDK_LEAVE_NOTIFY:
6273 case GDK_PROXIMITY_OUT:
6277 /* Remaining events would make sense on an not-viewable window,
6278 * or don't have an associated window.
6285 gtk_widget_event_internal (GtkWidget *widget,
6288 gboolean return_val = FALSE;
6290 /* We check only once for is-still-visible; if someone
6291 * hides the window in on of the signals on the widget,
6292 * they are responsible for returning TRUE to terminate
6295 if (!event_window_is_still_viewable (event))
6298 g_object_ref (widget);
6300 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6301 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6306 switch (event->type)
6312 case GDK_BUTTON_PRESS:
6313 case GDK_2BUTTON_PRESS:
6314 case GDK_3BUTTON_PRESS:
6315 signal_num = BUTTON_PRESS_EVENT;
6317 case GDK_TOUCH_BEGIN:
6318 case GDK_TOUCH_UPDATE:
6320 case GDK_TOUCH_CANCEL:
6321 signal_num = TOUCH_EVENT;
6324 signal_num = SCROLL_EVENT;
6326 case GDK_BUTTON_RELEASE:
6327 signal_num = BUTTON_RELEASE_EVENT;
6329 case GDK_MOTION_NOTIFY:
6330 signal_num = MOTION_NOTIFY_EVENT;
6333 signal_num = DELETE_EVENT;
6336 signal_num = DESTROY_EVENT;
6337 _gtk_tooltip_hide (widget);
6340 signal_num = KEY_PRESS_EVENT;
6342 case GDK_KEY_RELEASE:
6343 signal_num = KEY_RELEASE_EVENT;
6345 case GDK_ENTER_NOTIFY:
6346 signal_num = ENTER_NOTIFY_EVENT;
6348 case GDK_LEAVE_NOTIFY:
6349 signal_num = LEAVE_NOTIFY_EVENT;
6351 case GDK_FOCUS_CHANGE:
6352 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6353 if (event->focus_change.in)
6354 _gtk_tooltip_focus_in (widget);
6356 _gtk_tooltip_focus_out (widget);
6359 signal_num = CONFIGURE_EVENT;
6362 signal_num = MAP_EVENT;
6365 signal_num = UNMAP_EVENT;
6367 case GDK_WINDOW_STATE:
6368 signal_num = WINDOW_STATE_EVENT;
6370 case GDK_PROPERTY_NOTIFY:
6371 signal_num = PROPERTY_NOTIFY_EVENT;
6373 case GDK_SELECTION_CLEAR:
6374 signal_num = SELECTION_CLEAR_EVENT;
6376 case GDK_SELECTION_REQUEST:
6377 signal_num = SELECTION_REQUEST_EVENT;
6379 case GDK_SELECTION_NOTIFY:
6380 signal_num = SELECTION_NOTIFY_EVENT;
6382 case GDK_PROXIMITY_IN:
6383 signal_num = PROXIMITY_IN_EVENT;
6385 case GDK_PROXIMITY_OUT:
6386 signal_num = PROXIMITY_OUT_EVENT;
6388 case GDK_VISIBILITY_NOTIFY:
6389 signal_num = VISIBILITY_NOTIFY_EVENT;
6391 case GDK_GRAB_BROKEN:
6392 signal_num = GRAB_BROKEN_EVENT;
6395 signal_num = DAMAGE_EVENT;
6398 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6402 if (signal_num != -1)
6403 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6405 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6406 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6410 g_object_unref (widget);
6416 * gtk_widget_activate:
6417 * @widget: a #GtkWidget that's activatable
6419 * For widgets that can be "activated" (buttons, menu items, etc.)
6420 * this function activates them. Activation is what happens when you
6421 * press Enter on a widget during key navigation. If @widget isn't
6422 * activatable, the function returns %FALSE.
6424 * Return value: %TRUE if the widget was activatable
6427 gtk_widget_activate (GtkWidget *widget)
6429 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6431 if (WIDGET_CLASS (widget)->activate_signal)
6433 /* FIXME: we should eventually check the signals signature here */
6434 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6443 gtk_widget_reparent_subwindows (GtkWidget *widget,
6444 GdkWindow *new_window)
6446 GtkWidgetPrivate *priv = widget->priv;
6448 if (!gtk_widget_get_has_window (widget))
6450 GList *children = gdk_window_get_children (priv->window);
6453 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6455 GdkWindow *window = tmp_list->data;
6458 gdk_window_get_user_data (window, &child);
6459 while (child && child != widget)
6460 child = ((GtkWidget*) child)->priv->parent;
6463 gdk_window_reparent (window, new_window, 0, 0);
6466 g_list_free (children);
6471 GList *tmp_list, *children;
6473 parent = gdk_window_get_parent (priv->window);
6476 gdk_window_reparent (priv->window, new_window, 0, 0);
6479 children = gdk_window_get_children (parent);
6481 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6483 GdkWindow *window = tmp_list->data;
6486 gdk_window_get_user_data (window, &child);
6488 if (child == widget)
6489 gdk_window_reparent (window, new_window, 0, 0);
6492 g_list_free (children);
6498 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6499 gpointer client_data)
6501 GtkWidgetPrivate *priv = widget->priv;
6503 g_assert (client_data != NULL);
6505 if (!gtk_widget_get_has_window (widget))
6508 g_object_unref (priv->window);
6509 priv->window = (GdkWindow*) client_data;
6511 g_object_ref (priv->window);
6513 if (GTK_IS_CONTAINER (widget))
6514 gtk_container_forall (GTK_CONTAINER (widget),
6515 gtk_widget_reparent_fixup_child,
6521 * gtk_widget_reparent:
6522 * @widget: a #GtkWidget
6523 * @new_parent: a #GtkContainer to move the widget into
6525 * Moves a widget from one #GtkContainer to another, handling reference
6526 * count issues to avoid destroying the widget.
6529 gtk_widget_reparent (GtkWidget *widget,
6530 GtkWidget *new_parent)
6532 GtkWidgetPrivate *priv;
6534 g_return_if_fail (GTK_IS_WIDGET (widget));
6535 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6536 priv = widget->priv;
6537 g_return_if_fail (priv->parent != NULL);
6539 if (priv->parent != new_parent)
6541 /* First try to see if we can get away without unrealizing
6542 * the widget as we reparent it. if so we set a flag so
6543 * that gtk_widget_unparent doesn't unrealize widget
6545 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6546 priv->in_reparent = TRUE;
6548 g_object_ref (widget);
6549 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6550 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6551 g_object_unref (widget);
6553 if (priv->in_reparent)
6555 priv->in_reparent = FALSE;
6557 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6558 gtk_widget_reparent_fixup_child (widget,
6559 gtk_widget_get_parent_window (widget));
6562 g_object_notify (G_OBJECT (widget), "parent");
6567 * gtk_widget_intersect:
6568 * @widget: a #GtkWidget
6569 * @area: a rectangle
6570 * @intersection: rectangle to store intersection of @widget and @area
6572 * Computes the intersection of a @widget's area and @area, storing
6573 * the intersection in @intersection, and returns %TRUE if there was
6574 * an intersection. @intersection may be %NULL if you're only
6575 * interested in whether there was an intersection.
6577 * Return value: %TRUE if there was an intersection
6580 gtk_widget_intersect (GtkWidget *widget,
6581 const GdkRectangle *area,
6582 GdkRectangle *intersection)
6584 GtkWidgetPrivate *priv;
6589 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6590 g_return_val_if_fail (area != NULL, FALSE);
6592 priv = widget->priv;
6595 dest = intersection;
6599 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6601 if (return_val && intersection && gtk_widget_get_has_window (widget))
6603 intersection->x -= priv->allocation.x;
6604 intersection->y -= priv->allocation.y;
6611 * gtk_widget_region_intersect:
6612 * @widget: a #GtkWidget
6613 * @region: a #cairo_region_t, in the same coordinate system as
6614 * @widget->allocation. That is, relative to @widget->window
6615 * for %NO_WINDOW widgets; relative to the parent window
6616 * of @widget->window for widgets with their own window.
6618 * Computes the intersection of a @widget's area and @region, returning
6619 * the intersection. The result may be empty, use cairo_region_is_empty() to
6622 * Returns: A newly allocated region holding the intersection of @widget
6623 * and @region. The coordinates of the return value are relative to
6624 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6625 * window of @widget->window for widgets with their own window.
6628 gtk_widget_region_intersect (GtkWidget *widget,
6629 const cairo_region_t *region)
6632 cairo_region_t *dest;
6634 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6635 g_return_val_if_fail (region != NULL, NULL);
6637 gtk_widget_get_allocation (widget, &rect);
6639 dest = cairo_region_create_rectangle (&rect);
6641 cairo_region_intersect (dest, region);
6647 * _gtk_widget_grab_notify:
6648 * @widget: a #GtkWidget
6649 * @was_grabbed: whether a grab is now in effect
6651 * Emits the #GtkWidget::grab-notify signal on @widget.
6656 _gtk_widget_grab_notify (GtkWidget *widget,
6657 gboolean was_grabbed)
6659 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6663 * gtk_widget_grab_focus:
6664 * @widget: a #GtkWidget
6666 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6667 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6668 * something like #GtkFrame won't work.
6670 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6671 * gtk_widget_set_can_focus() to modify that flag.
6673 * The widget also needs to be realized and mapped. This is indicated by the
6674 * related signals. Grabbing the focus immediately after creating the widget
6675 * will likely fail and cause critical warnings.
6678 gtk_widget_grab_focus (GtkWidget *widget)
6680 g_return_if_fail (GTK_IS_WIDGET (widget));
6682 if (!gtk_widget_is_sensitive (widget))
6685 g_object_ref (widget);
6686 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6687 g_object_notify (G_OBJECT (widget), "has-focus");
6688 g_object_unref (widget);
6692 reset_focus_recurse (GtkWidget *widget,
6695 if (GTK_IS_CONTAINER (widget))
6697 GtkContainer *container;
6699 container = GTK_CONTAINER (widget);
6700 gtk_container_set_focus_child (container, NULL);
6702 gtk_container_foreach (container,
6703 reset_focus_recurse,
6709 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6711 if (gtk_widget_get_can_focus (focus_widget))
6713 GtkWidget *toplevel;
6716 /* clear the current focus setting, break if the current widget
6717 * is the focus widget's parent, since containers above that will
6718 * be set by the next loop.
6720 toplevel = gtk_widget_get_toplevel (focus_widget);
6721 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6723 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6725 if (widget == focus_widget)
6727 /* We call _gtk_window_internal_set_focus() here so that the
6728 * toplevel window can request the focus if necessary.
6729 * This is needed when the toplevel is a GtkPlug
6731 if (!gtk_widget_has_focus (widget))
6732 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6739 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6741 if (widget != common_ancestor)
6743 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6745 widget = widget->priv->parent;
6746 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6751 else if (toplevel != focus_widget)
6753 /* gtk_widget_grab_focus() operates on a tree without window...
6754 * actually, this is very questionable behaviour.
6757 gtk_container_foreach (GTK_CONTAINER (toplevel),
6758 reset_focus_recurse,
6762 /* now propagate the new focus up the widget tree and finally
6763 * set it on the window
6765 widget = focus_widget;
6766 while (widget->priv->parent)
6768 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6769 widget = widget->priv->parent;
6771 if (GTK_IS_WINDOW (widget))
6772 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6777 gtk_widget_real_query_tooltip (GtkWidget *widget,
6780 gboolean keyboard_tip,
6781 GtkTooltip *tooltip)
6783 gchar *tooltip_markup;
6784 gboolean has_tooltip;
6786 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6787 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6789 if (has_tooltip && tooltip_markup)
6791 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6799 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6800 GtkStateFlags old_state)
6802 gtk_widget_update_pango_context (widget);
6806 gtk_widget_real_style_updated (GtkWidget *widget)
6808 GtkWidgetPrivate *priv = widget->priv;
6810 gtk_widget_update_pango_context (widget);
6811 gtk_widget_update_alpha (widget);
6813 if (priv->style != NULL &&
6814 priv->style != gtk_widget_get_default_style ())
6816 /* Trigger ::style-set for old
6817 * widgets not listening to this
6819 g_signal_emit (widget,
6820 widget_signals[STYLE_SET],
6822 widget->priv->style);
6825 if (widget->priv->context)
6827 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6829 if (gtk_widget_get_realized (widget) &&
6830 gtk_widget_get_has_window (widget) &&
6831 !gtk_widget_get_app_paintable (widget))
6832 gtk_style_context_set_background (widget->priv->context,
6833 widget->priv->window);
6835 if (widget->priv->anchored)
6837 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6838 gtk_widget_queue_resize (widget);
6840 gtk_widget_queue_draw (widget);
6845 if (widget->priv->anchored)
6846 gtk_widget_queue_resize (widget);
6851 gtk_widget_real_show_help (GtkWidget *widget,
6852 GtkWidgetHelpType help_type)
6854 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6856 _gtk_tooltip_toggle_keyboard_mode (widget);
6865 gtk_widget_real_focus (GtkWidget *widget,
6866 GtkDirectionType direction)
6868 if (!gtk_widget_get_can_focus (widget))
6871 if (!gtk_widget_is_focus (widget))
6873 gtk_widget_grab_focus (widget);
6881 gtk_widget_real_move_focus (GtkWidget *widget,
6882 GtkDirectionType direction)
6884 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6886 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6888 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6894 gtk_widget_real_keynav_failed (GtkWidget *widget,
6895 GtkDirectionType direction)
6897 gboolean cursor_only;
6901 case GTK_DIR_TAB_FORWARD:
6902 case GTK_DIR_TAB_BACKWARD:
6909 g_object_get (gtk_widget_get_settings (widget),
6910 "gtk-keynav-cursor-only", &cursor_only,
6917 gtk_widget_error_bell (widget);
6923 * gtk_widget_set_can_focus:
6924 * @widget: a #GtkWidget
6925 * @can_focus: whether or not @widget can own the input focus.
6927 * Specifies whether @widget can own the input focus. See
6928 * gtk_widget_grab_focus() for actually setting the input focus on a
6934 gtk_widget_set_can_focus (GtkWidget *widget,
6937 g_return_if_fail (GTK_IS_WIDGET (widget));
6939 if (widget->priv->can_focus != can_focus)
6941 widget->priv->can_focus = can_focus;
6943 gtk_widget_queue_resize (widget);
6944 g_object_notify (G_OBJECT (widget), "can-focus");
6949 * gtk_widget_get_can_focus:
6950 * @widget: a #GtkWidget
6952 * Determines whether @widget can own the input focus. See
6953 * gtk_widget_set_can_focus().
6955 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6960 gtk_widget_get_can_focus (GtkWidget *widget)
6962 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6964 return widget->priv->can_focus;
6968 * gtk_widget_has_focus:
6969 * @widget: a #GtkWidget
6971 * Determines if the widget has the global input focus. See
6972 * gtk_widget_is_focus() for the difference between having the global
6973 * input focus, and only having the focus within a toplevel.
6975 * Return value: %TRUE if the widget has the global input focus.
6980 gtk_widget_has_focus (GtkWidget *widget)
6982 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6984 return widget->priv->has_focus;
6988 * gtk_widget_has_visible_focus:
6989 * @widget: a #GtkWidget
6991 * Determines if the widget should show a visible indication that
6992 * it has the global input focus. This is a convenience function for
6993 * use in ::draw handlers that takes into account whether focus
6994 * indication should currently be shown in the toplevel window of
6995 * @widget. See gtk_window_get_focus_visible() for more information
6996 * about focus indication.
6998 * To find out if the widget has the global input focus, use
6999 * gtk_widget_has_focus().
7001 * Return value: %TRUE if the widget should display a 'focus rectangle'
7006 gtk_widget_has_visible_focus (GtkWidget *widget)
7008 gboolean draw_focus;
7010 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7012 if (widget->priv->has_focus)
7014 GtkWidget *toplevel;
7016 toplevel = gtk_widget_get_toplevel (widget);
7018 if (GTK_IS_WINDOW (toplevel))
7019 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7030 * gtk_widget_is_focus:
7031 * @widget: a #GtkWidget
7033 * Determines if the widget is the focus widget within its
7034 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7035 * necessarily set; %HAS_FOCUS will only be set if the
7036 * toplevel widget additionally has the global input focus.)
7038 * Return value: %TRUE if the widget is the focus widget.
7041 gtk_widget_is_focus (GtkWidget *widget)
7043 GtkWidget *toplevel;
7045 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7047 toplevel = gtk_widget_get_toplevel (widget);
7049 if (GTK_IS_WINDOW (toplevel))
7050 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7056 * gtk_widget_set_can_default:
7057 * @widget: a #GtkWidget
7058 * @can_default: whether or not @widget can be a default widget.
7060 * Specifies whether @widget can be a default widget. See
7061 * gtk_widget_grab_default() for details about the meaning of
7067 gtk_widget_set_can_default (GtkWidget *widget,
7068 gboolean can_default)
7070 g_return_if_fail (GTK_IS_WIDGET (widget));
7072 if (widget->priv->can_default != can_default)
7074 widget->priv->can_default = can_default;
7076 gtk_widget_queue_resize (widget);
7077 g_object_notify (G_OBJECT (widget), "can-default");
7082 * gtk_widget_get_can_default:
7083 * @widget: a #GtkWidget
7085 * Determines whether @widget can be a default widget. See
7086 * gtk_widget_set_can_default().
7088 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7093 gtk_widget_get_can_default (GtkWidget *widget)
7095 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7097 return widget->priv->can_default;
7101 * gtk_widget_has_default:
7102 * @widget: a #GtkWidget
7104 * Determines whether @widget is the current default widget within its
7105 * toplevel. See gtk_widget_set_can_default().
7107 * Return value: %TRUE if @widget is the current default widget within
7108 * its toplevel, %FALSE otherwise
7113 gtk_widget_has_default (GtkWidget *widget)
7115 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7117 return widget->priv->has_default;
7121 _gtk_widget_set_has_default (GtkWidget *widget,
7122 gboolean has_default)
7124 GtkStyleContext *context;
7126 widget->priv->has_default = has_default;
7128 context = gtk_widget_get_style_context (widget);
7131 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7133 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7137 * gtk_widget_grab_default:
7138 * @widget: a #GtkWidget
7140 * Causes @widget to become the default widget. @widget must be able to be
7141 * a default widget; typically you would ensure this yourself
7142 * by calling gtk_widget_set_can_default() with a %TRUE value.
7143 * The default widget is activated when
7144 * the user presses Enter in a window. Default widgets must be
7145 * activatable, that is, gtk_widget_activate() should affect them. Note
7146 * that #GtkEntry widgets require the "activates-default" property
7147 * set to %TRUE before they activate the default widget when Enter
7148 * is pressed and the #GtkEntry is focused.
7151 gtk_widget_grab_default (GtkWidget *widget)
7155 g_return_if_fail (GTK_IS_WIDGET (widget));
7156 g_return_if_fail (gtk_widget_get_can_default (widget));
7158 window = gtk_widget_get_toplevel (widget);
7160 if (window && gtk_widget_is_toplevel (window))
7161 gtk_window_set_default (GTK_WINDOW (window), widget);
7163 g_warning (G_STRLOC ": widget not within a GtkWindow");
7167 * gtk_widget_set_receives_default:
7168 * @widget: a #GtkWidget
7169 * @receives_default: whether or not @widget can be a default widget.
7171 * Specifies whether @widget will be treated as the default widget
7172 * within its toplevel when it has the focus, even if another widget
7175 * See gtk_widget_grab_default() for details about the meaning of
7181 gtk_widget_set_receives_default (GtkWidget *widget,
7182 gboolean receives_default)
7184 g_return_if_fail (GTK_IS_WIDGET (widget));
7186 if (widget->priv->receives_default != receives_default)
7188 widget->priv->receives_default = receives_default;
7190 g_object_notify (G_OBJECT (widget), "receives-default");
7195 * gtk_widget_get_receives_default:
7196 * @widget: a #GtkWidget
7198 * Determines whether @widget is alyways treated as default widget
7199 * withing its toplevel when it has the focus, even if another widget
7202 * See gtk_widget_set_receives_default().
7204 * Return value: %TRUE if @widget acts as default widget when focussed,
7210 gtk_widget_get_receives_default (GtkWidget *widget)
7212 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7214 return widget->priv->receives_default;
7218 * gtk_widget_has_grab:
7219 * @widget: a #GtkWidget
7221 * Determines whether the widget is currently grabbing events, so it
7222 * is the only widget receiving input events (keyboard and mouse).
7224 * See also gtk_grab_add().
7226 * Return value: %TRUE if the widget is in the grab_widgets stack
7231 gtk_widget_has_grab (GtkWidget *widget)
7233 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7235 return widget->priv->has_grab;
7239 _gtk_widget_set_has_grab (GtkWidget *widget,
7242 widget->priv->has_grab = has_grab;
7246 * gtk_widget_device_is_shadowed:
7247 * @widget: a #GtkWidget
7248 * @device: a #GdkDevice
7250 * Returns %TRUE if @device has been shadowed by a GTK+
7251 * device grab on another widget, so it would stop sending
7252 * events to @widget. This may be used in the
7253 * #GtkWidget::grab-notify signal to check for specific
7254 * devices. See gtk_device_grab_add().
7256 * Returns: %TRUE if there is an ongoing grab on @device
7257 * by another #GtkWidget than @widget.
7262 gtk_widget_device_is_shadowed (GtkWidget *widget,
7265 GtkWindowGroup *group;
7266 GtkWidget *grab_widget, *toplevel;
7268 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7269 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7271 if (!gtk_widget_get_realized (widget))
7274 toplevel = gtk_widget_get_toplevel (widget);
7276 if (GTK_IS_WINDOW (toplevel))
7277 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7279 group = gtk_window_get_group (NULL);
7281 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7283 /* Widget not inside the hierarchy of grab_widget */
7285 widget != grab_widget &&
7286 !gtk_widget_is_ancestor (widget, grab_widget))
7289 grab_widget = gtk_window_group_get_current_grab (group);
7290 if (grab_widget && widget != grab_widget &&
7291 !gtk_widget_is_ancestor (widget, grab_widget))
7298 * gtk_widget_set_name:
7299 * @widget: a #GtkWidget
7300 * @name: name for the widget
7302 * Widgets can be named, which allows you to refer to them from a
7303 * CSS file. You can apply a style to widgets with a particular name
7304 * in the CSS file. See the documentation for the CSS syntax (on the
7305 * same page as the docs for #GtkStyleContext).
7307 * Note that the CSS syntax has certain special characters to delimit
7308 * and represent elements in a selector (period, #, >, *...),
7309 * so using these will make your widget impossible to match by name.
7310 * Any combination of alphanumeric symbols, dashes and underscores will
7314 gtk_widget_set_name (GtkWidget *widget,
7317 GtkWidgetPrivate *priv;
7320 g_return_if_fail (GTK_IS_WIDGET (widget));
7322 priv = widget->priv;
7324 new_name = g_strdup (name);
7325 g_free (priv->name);
7326 priv->name = new_name;
7328 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7330 g_object_notify (G_OBJECT (widget), "name");
7334 * gtk_widget_get_name:
7335 * @widget: a #GtkWidget
7337 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7338 * significance of widget names.
7340 * Return value: name of the widget. This string is owned by GTK+ and
7341 * should not be modified or freed
7344 gtk_widget_get_name (GtkWidget *widget)
7346 GtkWidgetPrivate *priv;
7348 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7350 priv = widget->priv;
7354 return G_OBJECT_TYPE_NAME (widget);
7358 gtk_widget_update_state_flags (GtkWidget *widget,
7359 GtkStateFlags flags_to_set,
7360 GtkStateFlags flags_to_unset)
7362 GtkWidgetPrivate *priv;
7364 priv = widget->priv;
7366 /* Handle insensitive first, since it is propagated
7367 * differently throughout the widget hierarchy.
7369 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7370 gtk_widget_set_sensitive (widget, TRUE);
7371 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7372 gtk_widget_set_sensitive (widget, FALSE);
7374 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7375 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7377 if (flags_to_set != 0 || flags_to_unset != 0)
7381 data.flags_to_set = flags_to_set;
7382 data.flags_to_unset = flags_to_unset;
7384 gtk_widget_propagate_state (widget, &data);
7389 * gtk_widget_set_state_flags:
7390 * @widget: a #GtkWidget
7391 * @flags: State flags to turn on
7392 * @clear: Whether to clear state before turning on @flags
7394 * This function is for use in widget implementations. Turns on flag
7395 * values in the current widget state (insensitive, prelighted, etc.).
7397 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7398 * will be propagated down to all non-internal children if @widget is a
7399 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7400 * down to all #GtkContainer children by different means than turning on the
7401 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7402 * gtk_widget_is_sensitive() will make use of these.
7407 gtk_widget_set_state_flags (GtkWidget *widget,
7408 GtkStateFlags flags,
7411 g_return_if_fail (GTK_IS_WIDGET (widget));
7413 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7414 (clear && widget->priv->state_flags == flags))
7418 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7420 gtk_widget_update_state_flags (widget, flags, 0);
7424 * gtk_widget_unset_state_flags:
7425 * @widget: a #GtkWidget
7426 * @flags: State flags to turn off
7428 * This function is for use in widget implementations. Turns off flag
7429 * values for the current widget state (insensitive, prelighted, etc.).
7430 * See gtk_widget_set_state_flags().
7435 gtk_widget_unset_state_flags (GtkWidget *widget,
7436 GtkStateFlags flags)
7438 g_return_if_fail (GTK_IS_WIDGET (widget));
7440 if ((widget->priv->state_flags & flags) == 0)
7443 gtk_widget_update_state_flags (widget, 0, flags);
7447 * gtk_widget_get_state_flags:
7448 * @widget: a #GtkWidget
7450 * Returns the widget state as a flag set. It is worth mentioning
7451 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7452 * returned, that is, also based on parent insensitivity, even if
7453 * @widget itself is sensitive.
7455 * Returns: The state flags for widget
7460 gtk_widget_get_state_flags (GtkWidget *widget)
7462 GtkStateFlags flags;
7464 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7466 flags = widget->priv->state_flags;
7468 if (gtk_widget_has_focus (widget))
7469 flags |= GTK_STATE_FLAG_FOCUSED;
7475 * gtk_widget_set_state:
7476 * @widget: a #GtkWidget
7477 * @state: new state for @widget
7479 * This function is for use in widget implementations. Sets the state
7480 * of a widget (insensitive, prelighted, etc.) Usually you should set
7481 * the state using wrapper functions such as gtk_widget_set_sensitive().
7483 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7486 gtk_widget_set_state (GtkWidget *widget,
7489 GtkStateFlags flags;
7491 if (state == gtk_widget_get_state (widget))
7496 case GTK_STATE_ACTIVE:
7497 flags = GTK_STATE_FLAG_ACTIVE;
7499 case GTK_STATE_PRELIGHT:
7500 flags = GTK_STATE_FLAG_PRELIGHT;
7502 case GTK_STATE_SELECTED:
7503 flags = GTK_STATE_FLAG_SELECTED;
7505 case GTK_STATE_INSENSITIVE:
7506 flags = GTK_STATE_FLAG_INSENSITIVE;
7508 case GTK_STATE_INCONSISTENT:
7509 flags = GTK_STATE_FLAG_INCONSISTENT;
7511 case GTK_STATE_FOCUSED:
7512 flags = GTK_STATE_FLAG_FOCUSED;
7514 case GTK_STATE_NORMAL:
7520 gtk_widget_update_state_flags (widget,
7522 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7523 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7527 * gtk_widget_get_state:
7528 * @widget: a #GtkWidget
7530 * Returns the widget's state. See gtk_widget_set_state().
7532 * Returns: the state of @widget.
7536 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7539 gtk_widget_get_state (GtkWidget *widget)
7541 GtkStateFlags flags;
7543 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7545 flags = gtk_widget_get_state_flags (widget);
7547 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7548 return GTK_STATE_INSENSITIVE;
7549 else if (flags & GTK_STATE_FLAG_ACTIVE)
7550 return GTK_STATE_ACTIVE;
7551 else if (flags & GTK_STATE_FLAG_SELECTED)
7552 return GTK_STATE_SELECTED;
7553 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7554 return GTK_STATE_PRELIGHT;
7556 return GTK_STATE_NORMAL;
7560 * gtk_widget_set_visible:
7561 * @widget: a #GtkWidget
7562 * @visible: whether the widget should be shown or not
7564 * Sets the visibility state of @widget. Note that setting this to
7565 * %TRUE doesn't mean the widget is actually viewable, see
7566 * gtk_widget_get_visible().
7568 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7569 * but is nicer to use when the visibility of the widget depends on
7575 gtk_widget_set_visible (GtkWidget *widget,
7578 g_return_if_fail (GTK_IS_WIDGET (widget));
7580 if (visible != gtk_widget_get_visible (widget))
7583 gtk_widget_show (widget);
7585 gtk_widget_hide (widget);
7590 _gtk_widget_set_visible_flag (GtkWidget *widget,
7593 GtkWidgetPrivate *priv = widget->priv;
7595 priv->visible = visible;
7599 priv->allocation.x = -1;
7600 priv->allocation.y = -1;
7601 priv->allocation.width = 1;
7602 priv->allocation.height = 1;
7607 * gtk_widget_get_visible:
7608 * @widget: a #GtkWidget
7610 * Determines whether the widget is visible. If you want to
7611 * take into account whether the widget's parent is also marked as
7612 * visible, use gtk_widget_is_visible() instead.
7614 * This function does not check if the widget is obscured in any way.
7616 * See gtk_widget_set_visible().
7618 * Return value: %TRUE if the widget is visible
7623 gtk_widget_get_visible (GtkWidget *widget)
7625 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7627 return widget->priv->visible;
7631 * gtk_widget_is_visible:
7632 * @widget: a #GtkWidget
7634 * Determines whether the widget and all its parents are marked as
7637 * This function does not check if the widget is obscured in any way.
7639 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7641 * Return value: %TRUE if the widget and all its parents are visible
7646 gtk_widget_is_visible (GtkWidget *widget)
7648 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7652 GtkWidgetPrivate *priv = widget->priv;
7657 widget = priv->parent;
7664 * gtk_widget_set_has_window:
7665 * @widget: a #GtkWidget
7666 * @has_window: whether or not @widget has a window.
7668 * Specifies whether @widget has a #GdkWindow of its own. Note that
7669 * all realized widgets have a non-%NULL "window" pointer
7670 * (gtk_widget_get_window() never returns a %NULL window when a widget
7671 * is realized), but for many of them it's actually the #GdkWindow of
7672 * one of its parent widgets. Widgets that do not create a %window for
7673 * themselves in #GtkWidget::realize must announce this by
7674 * calling this function with @has_window = %FALSE.
7676 * This function should only be called by widget implementations,
7677 * and they should call it in their init() function.
7682 gtk_widget_set_has_window (GtkWidget *widget,
7683 gboolean has_window)
7685 g_return_if_fail (GTK_IS_WIDGET (widget));
7687 widget->priv->no_window = !has_window;
7691 * gtk_widget_get_has_window:
7692 * @widget: a #GtkWidget
7694 * Determines whether @widget has a #GdkWindow of its own. See
7695 * gtk_widget_set_has_window().
7697 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7702 gtk_widget_get_has_window (GtkWidget *widget)
7704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7706 return ! widget->priv->no_window;
7710 * gtk_widget_is_toplevel:
7711 * @widget: a #GtkWidget
7713 * Determines whether @widget is a toplevel widget.
7715 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7716 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7719 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7724 gtk_widget_is_toplevel (GtkWidget *widget)
7726 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7728 return widget->priv->toplevel;
7732 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7733 gboolean is_toplevel)
7735 widget->priv->toplevel = is_toplevel;
7739 * gtk_widget_is_drawable:
7740 * @widget: a #GtkWidget
7742 * Determines whether @widget can be drawn to. A widget can be drawn
7743 * to if it is mapped and visible.
7745 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7750 gtk_widget_is_drawable (GtkWidget *widget)
7752 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7754 return (gtk_widget_get_visible (widget) &&
7755 gtk_widget_get_mapped (widget));
7759 * gtk_widget_get_realized:
7760 * @widget: a #GtkWidget
7762 * Determines whether @widget is realized.
7764 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7769 gtk_widget_get_realized (GtkWidget *widget)
7771 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7773 return widget->priv->realized;
7777 * gtk_widget_set_realized:
7778 * @widget: a #GtkWidget
7779 * @realized: %TRUE to mark the widget as realized
7781 * Marks the widget as being realized.
7783 * This function should only ever be called in a derived widget's
7784 * "realize" or "unrealize" implementation.
7789 gtk_widget_set_realized (GtkWidget *widget,
7792 g_return_if_fail (GTK_IS_WIDGET (widget));
7794 widget->priv->realized = realized;
7798 * gtk_widget_get_mapped:
7799 * @widget: a #GtkWidget
7801 * Whether the widget is mapped.
7803 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7808 gtk_widget_get_mapped (GtkWidget *widget)
7810 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7812 return widget->priv->mapped;
7816 * gtk_widget_set_mapped:
7817 * @widget: a #GtkWidget
7818 * @mapped: %TRUE to mark the widget as mapped
7820 * Marks the widget as being realized.
7822 * This function should only ever be called in a derived widget's
7823 * "map" or "unmap" implementation.
7828 gtk_widget_set_mapped (GtkWidget *widget,
7831 g_return_if_fail (GTK_IS_WIDGET (widget));
7833 widget->priv->mapped = mapped;
7837 * gtk_widget_set_app_paintable:
7838 * @widget: a #GtkWidget
7839 * @app_paintable: %TRUE if the application will paint on the widget
7841 * Sets whether the application intends to draw on the widget in
7842 * an #GtkWidget::draw handler.
7844 * This is a hint to the widget and does not affect the behavior of
7845 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7846 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7847 * the effect is to suppress default themed drawing of the widget's
7848 * background. (Children of the widget will still be drawn.) The application
7849 * is then entirely responsible for drawing the widget background.
7851 * Note that the background is still drawn when the widget is mapped.
7854 gtk_widget_set_app_paintable (GtkWidget *widget,
7855 gboolean app_paintable)
7857 g_return_if_fail (GTK_IS_WIDGET (widget));
7859 app_paintable = (app_paintable != FALSE);
7861 if (widget->priv->app_paintable != app_paintable)
7863 widget->priv->app_paintable = app_paintable;
7865 if (gtk_widget_is_drawable (widget))
7866 gtk_widget_queue_draw (widget);
7868 g_object_notify (G_OBJECT (widget), "app-paintable");
7873 * gtk_widget_get_app_paintable:
7874 * @widget: a #GtkWidget
7876 * Determines whether the application intends to draw on the widget in
7877 * an #GtkWidget::draw handler.
7879 * See gtk_widget_set_app_paintable()
7881 * Return value: %TRUE if the widget is app paintable
7886 gtk_widget_get_app_paintable (GtkWidget *widget)
7888 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7890 return widget->priv->app_paintable;
7894 * gtk_widget_set_double_buffered:
7895 * @widget: a #GtkWidget
7896 * @double_buffered: %TRUE to double-buffer a widget
7898 * Widgets are double buffered by default; you can use this function
7899 * to turn off the buffering. "Double buffered" simply means that
7900 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7901 * automatically around expose events sent to the
7902 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7903 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7904 * buffer to the screen. The result is that users see the window
7905 * update in one smooth step, and don't see individual graphics
7906 * primitives being rendered.
7908 * In very simple terms, double buffered widgets don't flicker,
7909 * so you would only use this function to turn off double buffering
7910 * if you had special needs and really knew what you were doing.
7912 * Note: if you turn off double-buffering, you have to handle
7913 * expose events, since even the clearing to the background color or
7914 * pixmap will not happen automatically (as it is done in
7915 * gdk_window_begin_paint_region()).
7918 gtk_widget_set_double_buffered (GtkWidget *widget,
7919 gboolean double_buffered)
7921 g_return_if_fail (GTK_IS_WIDGET (widget));
7923 double_buffered = (double_buffered != FALSE);
7925 if (widget->priv->double_buffered != double_buffered)
7927 widget->priv->double_buffered = double_buffered;
7929 g_object_notify (G_OBJECT (widget), "double-buffered");
7934 * gtk_widget_get_double_buffered:
7935 * @widget: a #GtkWidget
7937 * Determines whether the widget is double buffered.
7939 * See gtk_widget_set_double_buffered()
7941 * Return value: %TRUE if the widget is double buffered
7946 gtk_widget_get_double_buffered (GtkWidget *widget)
7948 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7950 return widget->priv->double_buffered;
7954 * gtk_widget_set_redraw_on_allocate:
7955 * @widget: a #GtkWidget
7956 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7957 * when it is allocated to a new size. Otherwise, only the
7958 * new portion of the widget will be redrawn.
7960 * Sets whether the entire widget is queued for drawing when its size
7961 * allocation changes. By default, this setting is %TRUE and
7962 * the entire widget is redrawn on every size change. If your widget
7963 * leaves the upper left unchanged when made bigger, turning this
7964 * setting off will improve performance.
7966 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7967 * off all allocation on resizing: the widget will not even redraw if
7968 * its position changes; this is to allow containers that don't draw
7969 * anything to avoid excess invalidations. If you set this flag on a
7970 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7971 * you are responsible for invalidating both the old and new allocation
7972 * of the widget when the widget is moved and responsible for invalidating
7973 * regions newly when the widget increases size.
7976 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7977 gboolean redraw_on_allocate)
7979 g_return_if_fail (GTK_IS_WIDGET (widget));
7981 widget->priv->redraw_on_alloc = redraw_on_allocate;
7985 * gtk_widget_set_sensitive:
7986 * @widget: a #GtkWidget
7987 * @sensitive: %TRUE to make the widget sensitive
7989 * Sets the sensitivity of a widget. A widget is sensitive if the user
7990 * can interact with it. Insensitive widgets are "grayed out" and the
7991 * user can't interact with them. Insensitive widgets are known as
7992 * "inactive", "disabled", or "ghosted" in some other toolkits.
7995 gtk_widget_set_sensitive (GtkWidget *widget,
7998 GtkWidgetPrivate *priv;
8000 g_return_if_fail (GTK_IS_WIDGET (widget));
8002 priv = widget->priv;
8004 sensitive = (sensitive != FALSE);
8006 if (priv->sensitive == sensitive)
8009 priv->sensitive = sensitive;
8011 if (priv->parent == NULL
8012 || gtk_widget_is_sensitive (priv->parent))
8018 data.flags_to_set = 0;
8019 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8023 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8024 data.flags_to_unset = 0;
8027 gtk_widget_propagate_state (widget, &data);
8029 gtk_widget_queue_resize (widget);
8032 g_object_notify (G_OBJECT (widget), "sensitive");
8036 * gtk_widget_get_sensitive:
8037 * @widget: a #GtkWidget
8039 * Returns the widget's sensitivity (in the sense of returning
8040 * the value that has been set using gtk_widget_set_sensitive()).
8042 * The effective sensitivity of a widget is however determined by both its
8043 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8045 * Returns: %TRUE if the widget is sensitive
8050 gtk_widget_get_sensitive (GtkWidget *widget)
8052 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8054 return widget->priv->sensitive;
8058 * gtk_widget_is_sensitive:
8059 * @widget: a #GtkWidget
8061 * Returns the widget's effective sensitivity, which means
8062 * it is sensitive itself and also its parent widget is sensitive
8064 * Returns: %TRUE if the widget is effectively sensitive
8069 gtk_widget_is_sensitive (GtkWidget *widget)
8071 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8073 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8077 * gtk_widget_set_parent:
8078 * @widget: a #GtkWidget
8079 * @parent: parent container
8081 * This function is useful only when implementing subclasses of
8083 * Sets the container as the parent of @widget, and takes care of
8084 * some details such as updating the state and style of the child
8085 * to reflect its new location. The opposite function is
8086 * gtk_widget_unparent().
8089 gtk_widget_set_parent (GtkWidget *widget,
8092 GtkStateFlags parent_flags;
8093 GtkWidgetPrivate *priv;
8096 g_return_if_fail (GTK_IS_WIDGET (widget));
8097 g_return_if_fail (GTK_IS_WIDGET (parent));
8098 g_return_if_fail (widget != parent);
8100 priv = widget->priv;
8102 if (priv->parent != NULL)
8104 g_warning ("Can't set a parent on widget which has a parent\n");
8107 if (gtk_widget_is_toplevel (widget))
8109 g_warning ("Can't set a parent on a toplevel widget\n");
8113 /* keep this function in sync with gtk_menu_attach_to_widget()
8116 g_object_ref_sink (widget);
8118 gtk_widget_push_verify_invariants (widget);
8120 priv->parent = parent;
8122 parent_flags = gtk_widget_get_state_flags (parent);
8124 /* Merge both old state and current parent state,
8125 * making sure to only propagate the right states */
8126 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8127 data.flags_to_unset = 0;
8128 gtk_widget_propagate_state (widget, &data);
8131 gtk_style_context_set_parent (priv->context,
8132 gtk_widget_get_style_context (parent));
8134 _gtk_widget_update_parent_muxer (widget);
8136 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8137 if (priv->parent->priv->anchored)
8138 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8139 g_object_notify (G_OBJECT (widget), "parent");
8141 /* Enforce realized/mapped invariants
8143 if (gtk_widget_get_realized (priv->parent))
8144 gtk_widget_realize (widget);
8146 if (gtk_widget_get_visible (priv->parent) &&
8147 gtk_widget_get_visible (widget))
8149 if (gtk_widget_get_child_visible (widget) &&
8150 gtk_widget_get_mapped (priv->parent))
8151 gtk_widget_map (widget);
8153 gtk_widget_queue_resize (widget);
8156 /* child may cause parent's expand to change, if the child is
8157 * expanded. If child is not expanded, then it can't modify the
8158 * parent's expand. If the child becomes expanded later then it will
8159 * queue compute_expand then. This optimization plus defaulting
8160 * newly-constructed widgets to need_compute_expand=FALSE should
8161 * mean that initially building a widget tree doesn't have to keep
8162 * walking up setting need_compute_expand on parents over and over.
8164 * We can't change a parent to need to expand unless we're visible.
8166 if (gtk_widget_get_visible (widget) &&
8167 (priv->need_compute_expand ||
8168 priv->computed_hexpand ||
8169 priv->computed_vexpand))
8171 gtk_widget_queue_compute_expand (parent);
8174 gtk_widget_propagate_alpha (widget);
8176 gtk_widget_pop_verify_invariants (widget);
8180 * gtk_widget_get_parent:
8181 * @widget: a #GtkWidget
8183 * Returns the parent container of @widget.
8185 * Return value: (transfer none): the parent container of @widget, or %NULL
8188 gtk_widget_get_parent (GtkWidget *widget)
8190 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8192 return widget->priv->parent;
8196 modifier_style_changed (GtkModifierStyle *style,
8199 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8202 static GtkModifierStyle *
8203 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8205 GtkModifierStyle *style;
8207 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8209 if (G_UNLIKELY (!style))
8211 GtkStyleContext *context;
8213 style = _gtk_modifier_style_new ();
8214 g_object_set_qdata_full (G_OBJECT (widget),
8215 quark_modifier_style,
8217 (GDestroyNotify) g_object_unref);
8219 g_signal_connect (style, "changed",
8220 G_CALLBACK (modifier_style_changed), widget);
8222 context = gtk_widget_get_style_context (widget);
8224 gtk_style_context_add_provider (context,
8225 GTK_STYLE_PROVIDER (style),
8226 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8233 * gtk_widget_override_color:
8234 * @widget: a #GtkWidget
8235 * @state: the state for which to set the color
8236 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8237 * of previous calls to gtk_widget_override_color()
8239 * Sets the color to use for a widget.
8241 * All other style values are left untouched.
8244 * This API is mostly meant as a quick way for applications to
8245 * change a widget appearance. If you are developing a widgets
8246 * library and intend this change to be themeable, it is better
8247 * done by setting meaningful CSS classes and regions in your
8248 * widget/container implementation through gtk_style_context_add_class()
8249 * and gtk_style_context_add_region().
8251 * This way, your widget library can install a #GtkCssProvider
8252 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8253 * to provide a default styling for those widgets that need so, and
8254 * this theming may fully overridden by the user's theme.
8257 * Note that for complex widgets this may bring in undesired
8258 * results (such as uniform background color everywhere), in
8259 * these cases it is better to fully style such widgets through a
8260 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8267 gtk_widget_override_color (GtkWidget *widget,
8268 GtkStateFlags state,
8269 const GdkRGBA *color)
8271 GtkModifierStyle *style;
8273 g_return_if_fail (GTK_IS_WIDGET (widget));
8275 style = _gtk_widget_get_modifier_properties (widget);
8276 _gtk_modifier_style_set_color (style, state, color);
8280 * gtk_widget_override_background_color:
8281 * @widget: a #GtkWidget
8282 * @state: the state for which to set the background color
8283 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8284 * of previous calls to gtk_widget_override_background_color()
8286 * Sets the background color to use for a widget.
8288 * All other style values are left untouched.
8289 * See gtk_widget_override_color().
8294 gtk_widget_override_background_color (GtkWidget *widget,
8295 GtkStateFlags state,
8296 const GdkRGBA *color)
8298 GtkModifierStyle *style;
8300 g_return_if_fail (GTK_IS_WIDGET (widget));
8302 style = _gtk_widget_get_modifier_properties (widget);
8303 _gtk_modifier_style_set_background_color (style, state, color);
8307 * gtk_widget_override_font:
8308 * @widget: a #GtkWidget
8309 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8310 * the effect of previous calls to gtk_widget_override_font()
8312 * Sets the font to use for a widget. All other style values are
8313 * left untouched. See gtk_widget_override_color().
8318 gtk_widget_override_font (GtkWidget *widget,
8319 const PangoFontDescription *font_desc)
8321 GtkModifierStyle *style;
8323 g_return_if_fail (GTK_IS_WIDGET (widget));
8325 style = _gtk_widget_get_modifier_properties (widget);
8326 _gtk_modifier_style_set_font (style, font_desc);
8330 * gtk_widget_override_symbolic_color:
8331 * @widget: a #GtkWidget
8332 * @name: the name of the symbolic color to modify
8333 * @color: (allow-none): the color to assign (does not need
8334 * to be allocated), or %NULL to undo the effect of previous
8335 * calls to gtk_widget_override_symbolic_color()
8337 * Sets a symbolic color for a widget.
8339 * All other style values are left untouched.
8340 * See gtk_widget_override_color() for overriding the foreground
8341 * or background color.
8346 gtk_widget_override_symbolic_color (GtkWidget *widget,
8348 const GdkRGBA *color)
8350 GtkModifierStyle *style;
8352 g_return_if_fail (GTK_IS_WIDGET (widget));
8354 style = _gtk_widget_get_modifier_properties (widget);
8355 _gtk_modifier_style_map_color (style, name, color);
8359 * gtk_widget_override_cursor:
8360 * @widget: a #GtkWidget
8361 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8362 * allocated), or %NULL to undo the effect of previous calls to
8363 * of gtk_widget_override_cursor().
8364 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8365 * need to be allocated), or %NULL to undo the effect of previous
8366 * calls to of gtk_widget_override_cursor().
8368 * Sets the cursor color to use in a widget, overriding the
8369 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8370 * style properties. All other style values are left untouched.
8371 * See also gtk_widget_modify_style().
8373 * Note that the underlying properties have the #GdkColor type,
8374 * so the alpha value in @primary and @secondary will be ignored.
8379 gtk_widget_override_cursor (GtkWidget *widget,
8380 const GdkRGBA *cursor,
8381 const GdkRGBA *secondary_cursor)
8383 GtkModifierStyle *style;
8385 g_return_if_fail (GTK_IS_WIDGET (widget));
8387 style = _gtk_widget_get_modifier_properties (widget);
8388 _gtk_modifier_style_set_color_property (style,
8390 "cursor-color", cursor);
8391 _gtk_modifier_style_set_color_property (style,
8393 "secondary-cursor-color",
8398 gtk_widget_real_direction_changed (GtkWidget *widget,
8399 GtkTextDirection previous_direction)
8401 gtk_widget_queue_resize (widget);
8405 gtk_widget_real_style_set (GtkWidget *widget,
8406 GtkStyle *previous_style)
8411 GtkWidget *previous_toplevel;
8412 GdkScreen *previous_screen;
8413 GdkScreen *new_screen;
8414 } HierarchyChangedInfo;
8417 do_screen_change (GtkWidget *widget,
8418 GdkScreen *old_screen,
8419 GdkScreen *new_screen)
8421 if (old_screen != new_screen)
8423 GtkWidgetPrivate *priv = widget->priv;
8427 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8429 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8432 _gtk_tooltip_hide (widget);
8434 if (new_screen && priv->context)
8435 gtk_style_context_set_screen (priv->context, new_screen);
8437 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8442 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8443 gpointer client_data)
8445 GtkWidgetPrivate *priv = widget->priv;
8446 HierarchyChangedInfo *info = client_data;
8447 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8448 (priv->parent && priv->parent->priv->anchored);
8450 if (priv->anchored != new_anchored)
8452 g_object_ref (widget);
8454 priv->anchored = new_anchored;
8456 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8457 do_screen_change (widget, info->previous_screen, info->new_screen);
8459 if (GTK_IS_CONTAINER (widget))
8460 gtk_container_forall (GTK_CONTAINER (widget),
8461 gtk_widget_propagate_hierarchy_changed_recurse,
8464 g_object_unref (widget);
8469 * _gtk_widget_propagate_hierarchy_changed:
8470 * @widget: a #GtkWidget
8471 * @previous_toplevel: Previous toplevel
8473 * Propagates changes in the anchored state to a widget and all
8474 * children, unsetting or setting the %ANCHORED flag, and
8475 * emitting #GtkWidget::hierarchy-changed.
8478 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8479 GtkWidget *previous_toplevel)
8481 GtkWidgetPrivate *priv = widget->priv;
8482 HierarchyChangedInfo info;
8484 info.previous_toplevel = previous_toplevel;
8485 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8487 if (gtk_widget_is_toplevel (widget) ||
8488 (priv->parent && priv->parent->priv->anchored))
8489 info.new_screen = gtk_widget_get_screen (widget);
8491 info.new_screen = NULL;
8493 if (info.previous_screen)
8494 g_object_ref (info.previous_screen);
8495 if (previous_toplevel)
8496 g_object_ref (previous_toplevel);
8498 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8500 if (previous_toplevel)
8501 g_object_unref (previous_toplevel);
8502 if (info.previous_screen)
8503 g_object_unref (info.previous_screen);
8507 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8508 gpointer client_data)
8510 HierarchyChangedInfo *info = client_data;
8512 g_object_ref (widget);
8514 do_screen_change (widget, info->previous_screen, info->new_screen);
8516 if (GTK_IS_CONTAINER (widget))
8517 gtk_container_forall (GTK_CONTAINER (widget),
8518 gtk_widget_propagate_screen_changed_recurse,
8521 g_object_unref (widget);
8525 * gtk_widget_is_composited:
8526 * @widget: a #GtkWidget
8528 * Whether @widget can rely on having its alpha channel
8529 * drawn correctly. On X11 this function returns whether a
8530 * compositing manager is running for @widget's screen.
8532 * Please note that the semantics of this call will change
8533 * in the future if used on a widget that has a composited
8534 * window in its hierarchy (as set by gdk_window_set_composited()).
8536 * Return value: %TRUE if the widget can rely on its alpha
8537 * channel being drawn correctly.
8542 gtk_widget_is_composited (GtkWidget *widget)
8546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8548 screen = gtk_widget_get_screen (widget);
8550 return gdk_screen_is_composited (screen);
8554 propagate_composited_changed (GtkWidget *widget,
8557 if (GTK_IS_CONTAINER (widget))
8559 gtk_container_forall (GTK_CONTAINER (widget),
8560 propagate_composited_changed,
8564 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8568 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8570 propagate_composited_changed (widget, NULL);
8574 * _gtk_widget_propagate_screen_changed:
8575 * @widget: a #GtkWidget
8576 * @previous_screen: Previous screen
8578 * Propagates changes in the screen for a widget to all
8579 * children, emitting #GtkWidget::screen-changed.
8582 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8583 GdkScreen *previous_screen)
8585 HierarchyChangedInfo info;
8587 info.previous_screen = previous_screen;
8588 info.new_screen = gtk_widget_get_screen (widget);
8590 if (previous_screen)
8591 g_object_ref (previous_screen);
8593 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8595 if (previous_screen)
8596 g_object_unref (previous_screen);
8600 reset_style_recurse (GtkWidget *widget, gpointer data)
8602 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8604 if (GTK_IS_CONTAINER (widget))
8605 gtk_container_forall (GTK_CONTAINER (widget),
8606 reset_style_recurse,
8611 * gtk_widget_reset_style:
8612 * @widget: a #GtkWidget
8614 * Updates the style context of @widget and all descendents
8615 * by updating its widget path. #GtkContainer<!-- -->s may want
8616 * to use this on a child when reordering it in a way that a different
8617 * style might apply to it. See also gtk_container_get_path_for_child().
8622 gtk_widget_reset_style (GtkWidget *widget)
8624 g_return_if_fail (GTK_IS_WIDGET (widget));
8626 reset_style_recurse (widget, NULL);
8628 g_list_foreach (widget->priv->attached_windows,
8629 (GFunc) reset_style_recurse, NULL);
8632 #ifdef G_ENABLE_DEBUG
8634 /* Verify invariants, see docs/widget_system.txt for notes on much of
8635 * this. Invariants may be temporarily broken while we're in the
8636 * process of updating state, of course, so you can only
8637 * verify_invariants() after a given operation is complete.
8638 * Use push/pop_verify_invariants to help with that.
8641 gtk_widget_verify_invariants (GtkWidget *widget)
8645 if (widget->priv->verifying_invariants_count > 0)
8648 parent = widget->priv->parent;
8650 if (widget->priv->mapped)
8652 /* Mapped implies ... */
8654 if (!widget->priv->realized)
8655 g_warning ("%s %p is mapped but not realized",
8656 G_OBJECT_TYPE_NAME (widget), widget);
8658 if (!widget->priv->visible)
8659 g_warning ("%s %p is mapped but not visible",
8660 G_OBJECT_TYPE_NAME (widget), widget);
8662 if (!widget->priv->toplevel)
8664 if (!widget->priv->child_visible)
8665 g_warning ("%s %p is mapped but not child_visible",
8666 G_OBJECT_TYPE_NAME (widget), widget);
8671 /* Not mapped implies... */
8674 /* This check makes sense for normal toplevels, but for
8675 * something like a toplevel that is embedded within a clutter
8676 * state, mapping may depend on external factors.
8678 if (widget->priv->toplevel)
8680 if (widget->priv->visible)
8681 g_warning ("%s %p toplevel is visible but not mapped",
8682 G_OBJECT_TYPE_NAME (widget), widget);
8687 /* Parent related checks aren't possible if parent has
8688 * verifying_invariants_count > 0 because parent needs to recurse
8689 * children first before the invariants will hold.
8691 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8694 parent->priv->realized)
8696 /* Parent realized implies... */
8699 /* This is in widget_system.txt but appears to fail
8700 * because there's no gtk_container_realize() that
8701 * realizes all children... instead we just lazily
8702 * wait for map to fix things up.
8704 if (!widget->priv->realized)
8705 g_warning ("%s %p is realized but child %s %p is not realized",
8706 G_OBJECT_TYPE_NAME (parent), parent,
8707 G_OBJECT_TYPE_NAME (widget), widget);
8710 else if (!widget->priv->toplevel)
8712 /* No parent or parent not realized on non-toplevel implies... */
8714 if (widget->priv->realized && !widget->priv->in_reparent)
8715 g_warning ("%s %p is not realized but child %s %p is realized",
8716 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8717 G_OBJECT_TYPE_NAME (widget), widget);
8721 parent->priv->mapped &&
8722 widget->priv->visible &&
8723 widget->priv->child_visible)
8725 /* Parent mapped and we are visible implies... */
8727 if (!widget->priv->mapped)
8728 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8729 G_OBJECT_TYPE_NAME (parent), parent,
8730 G_OBJECT_TYPE_NAME (widget), widget);
8732 else if (!widget->priv->toplevel)
8734 /* No parent or parent not mapped on non-toplevel implies... */
8736 if (widget->priv->mapped && !widget->priv->in_reparent)
8737 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8738 G_OBJECT_TYPE_NAME (widget), widget,
8739 widget->priv->visible,
8740 widget->priv->child_visible,
8741 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8742 parent ? parent->priv->mapped : FALSE);
8746 if (!widget->priv->realized)
8748 /* Not realized implies... */
8751 /* widget_system.txt says these hold, but they don't. */
8752 if (widget->priv->alloc_needed)
8753 g_warning ("%s %p alloc needed but not realized",
8754 G_OBJECT_TYPE_NAME (widget), widget);
8756 if (widget->priv->width_request_needed)
8757 g_warning ("%s %p width request needed but not realized",
8758 G_OBJECT_TYPE_NAME (widget), widget);
8760 if (widget->priv->height_request_needed)
8761 g_warning ("%s %p height request needed but not realized",
8762 G_OBJECT_TYPE_NAME (widget), widget);
8767 /* The point of this push/pop is that invariants may not hold while
8768 * we're busy making changes. So we only check at the outermost call
8769 * on the call stack, after we finish updating everything.
8772 gtk_widget_push_verify_invariants (GtkWidget *widget)
8774 widget->priv->verifying_invariants_count += 1;
8778 gtk_widget_verify_child_invariants (GtkWidget *widget,
8779 gpointer client_data)
8781 /* We don't recurse further; this is a one-level check. */
8782 gtk_widget_verify_invariants (widget);
8786 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8788 g_assert (widget->priv->verifying_invariants_count > 0);
8790 widget->priv->verifying_invariants_count -= 1;
8792 if (widget->priv->verifying_invariants_count == 0)
8794 gtk_widget_verify_invariants (widget);
8796 if (GTK_IS_CONTAINER (widget))
8798 /* Check one level of children, because our
8799 * push_verify_invariants() will have prevented some of the
8800 * checks. This does not recurse because if recursion is
8801 * needed, it will happen naturally as each child has a
8802 * push/pop on that child. For example if we're recursively
8803 * mapping children, we'll push/pop on each child as we map
8806 gtk_container_forall (GTK_CONTAINER (widget),
8807 gtk_widget_verify_child_invariants,
8812 #endif /* G_ENABLE_DEBUG */
8814 static PangoContext *
8815 gtk_widget_peek_pango_context (GtkWidget *widget)
8817 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8821 * gtk_widget_get_pango_context:
8822 * @widget: a #GtkWidget
8824 * Gets a #PangoContext with the appropriate font map, font description,
8825 * and base direction for this widget. Unlike the context returned
8826 * by gtk_widget_create_pango_context(), this context is owned by
8827 * the widget (it can be used until the screen for the widget changes
8828 * or the widget is removed from its toplevel), and will be updated to
8829 * match any changes to the widget's attributes. This can be tracked
8830 * by using the #GtkWidget::screen-changed signal on the widget.
8832 * Return value: (transfer none): the #PangoContext for the widget.
8835 gtk_widget_get_pango_context (GtkWidget *widget)
8837 PangoContext *context;
8839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8841 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8844 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8845 g_object_set_qdata_full (G_OBJECT (widget),
8846 quark_pango_context,
8855 update_pango_context (GtkWidget *widget,
8856 PangoContext *context)
8858 PangoFontDescription *font_desc;
8859 GtkStyleContext *style_context;
8861 style_context = gtk_widget_get_style_context (widget);
8862 gtk_style_context_get (style_context,
8863 gtk_widget_get_state_flags (widget),
8867 pango_context_set_font_description (context, font_desc);
8868 pango_context_set_base_dir (context,
8869 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8870 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8872 pango_font_description_free (font_desc);
8876 gtk_widget_update_pango_context (GtkWidget *widget)
8878 PangoContext *context = gtk_widget_peek_pango_context (widget);
8884 update_pango_context (widget, context);
8886 screen = gtk_widget_get_screen_unchecked (widget);
8889 pango_cairo_context_set_resolution (context,
8890 gdk_screen_get_resolution (screen));
8891 pango_cairo_context_set_font_options (context,
8892 gdk_screen_get_font_options (screen));
8898 * gtk_widget_create_pango_context:
8899 * @widget: a #GtkWidget
8901 * Creates a new #PangoContext with the appropriate font map,
8902 * font description, and base direction for drawing text for
8903 * this widget. See also gtk_widget_get_pango_context().
8905 * Return value: (transfer full): the new #PangoContext
8908 gtk_widget_create_pango_context (GtkWidget *widget)
8911 PangoContext *context;
8913 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8915 screen = gtk_widget_get_screen_unchecked (widget);
8918 GTK_NOTE (MULTIHEAD,
8919 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8921 screen = gdk_screen_get_default ();
8924 context = gdk_pango_context_get_for_screen (screen);
8926 update_pango_context (widget, context);
8927 pango_context_set_language (context, gtk_get_default_language ());
8933 * gtk_widget_create_pango_layout:
8934 * @widget: a #GtkWidget
8935 * @text: text to set on the layout (can be %NULL)
8937 * Creates a new #PangoLayout with the appropriate font map,
8938 * font description, and base direction for drawing text for
8941 * If you keep a #PangoLayout created in this way around, you need
8942 * to re-create it when the widget #PangoContext is replaced.
8943 * This can be tracked by using the #GtkWidget::screen-changed signal
8946 * Return value: (transfer full): the new #PangoLayout
8949 gtk_widget_create_pango_layout (GtkWidget *widget,
8952 PangoLayout *layout;
8953 PangoContext *context;
8955 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8957 context = gtk_widget_get_pango_context (widget);
8958 layout = pango_layout_new (context);
8961 pango_layout_set_text (layout, text, -1);
8967 * gtk_widget_render_icon_pixbuf:
8968 * @widget: a #GtkWidget
8969 * @stock_id: a stock ID
8970 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8971 * render at the size of the source and don't scale (if there are
8972 * multiple source sizes, GTK+ picks one of the available sizes).
8974 * A convenience function that uses the theme engine and style
8975 * settings for @widget to look up @stock_id and render it to
8976 * a pixbuf. @stock_id should be a stock icon ID such as
8977 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8978 * such as #GTK_ICON_SIZE_MENU.
8980 * The pixels in the returned #GdkPixbuf are shared with the rest of
8981 * the application and should not be modified. The pixbuf should be freed
8982 * after use with g_object_unref().
8984 * Return value: (transfer full): a new pixbuf, or %NULL if the
8985 * stock ID wasn't known
8990 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
8991 const gchar *stock_id,
8994 GtkStyleContext *context;
8995 GtkIconSet *icon_set;
8997 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8998 g_return_val_if_fail (stock_id != NULL, NULL);
8999 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9001 context = gtk_widget_get_style_context (widget);
9002 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9004 if (icon_set == NULL)
9007 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9011 * gtk_widget_set_parent_window:
9012 * @widget: a #GtkWidget.
9013 * @parent_window: the new parent window.
9015 * Sets a non default parent window for @widget.
9017 * For GtkWindow classes, setting a @parent_window effects whether
9018 * the window is a toplevel window or can be embedded into other
9022 * For GtkWindow classes, this needs to be called before the
9023 * window is realized.
9028 gtk_widget_set_parent_window (GtkWidget *widget,
9029 GdkWindow *parent_window)
9031 GdkWindow *old_parent_window;
9033 g_return_if_fail (GTK_IS_WIDGET (widget));
9035 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9036 quark_parent_window);
9038 if (parent_window != old_parent_window)
9042 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9044 if (old_parent_window)
9045 g_object_unref (old_parent_window);
9047 g_object_ref (parent_window);
9049 /* Unset toplevel flag when adding a parent window to a widget,
9050 * this is the primary entry point to allow toplevels to be
9053 #ifdef GDK_WINDOWING_X11
9054 is_plug = GTK_IS_PLUG (widget);
9058 if (GTK_IS_WINDOW (widget) && !is_plug)
9059 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9064 * gtk_widget_get_parent_window:
9065 * @widget: a #GtkWidget.
9067 * Gets @widget's parent window.
9069 * Returns: (transfer none): the parent window of @widget.
9072 gtk_widget_get_parent_window (GtkWidget *widget)
9074 GtkWidgetPrivate *priv;
9075 GdkWindow *parent_window;
9077 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9079 priv = widget->priv;
9081 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9083 return (parent_window != NULL) ? parent_window :
9084 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9089 * gtk_widget_set_child_visible:
9090 * @widget: a #GtkWidget
9091 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9093 * Sets whether @widget should be mapped along with its when its parent
9094 * is mapped and @widget has been shown with gtk_widget_show().
9096 * The child visibility can be set for widget before it is added to
9097 * a container with gtk_widget_set_parent(), to avoid mapping
9098 * children unnecessary before immediately unmapping them. However
9099 * it will be reset to its default state of %TRUE when the widget
9100 * is removed from a container.
9102 * Note that changing the child visibility of a widget does not
9103 * queue a resize on the widget. Most of the time, the size of
9104 * a widget is computed from all visible children, whether or
9105 * not they are mapped. If this is not the case, the container
9106 * can queue a resize itself.
9108 * This function is only useful for container implementations and
9109 * never should be called by an application.
9112 gtk_widget_set_child_visible (GtkWidget *widget,
9113 gboolean is_visible)
9115 GtkWidgetPrivate *priv;
9117 g_return_if_fail (GTK_IS_WIDGET (widget));
9118 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9120 priv = widget->priv;
9122 g_object_ref (widget);
9123 gtk_widget_verify_invariants (widget);
9126 priv->child_visible = TRUE;
9129 GtkWidget *toplevel;
9131 priv->child_visible = FALSE;
9133 toplevel = gtk_widget_get_toplevel (widget);
9134 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9135 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9138 if (priv->parent && gtk_widget_get_realized (priv->parent))
9140 if (gtk_widget_get_mapped (priv->parent) &&
9141 priv->child_visible &&
9142 gtk_widget_get_visible (widget))
9143 gtk_widget_map (widget);
9145 gtk_widget_unmap (widget);
9148 gtk_widget_verify_invariants (widget);
9149 g_object_unref (widget);
9153 * gtk_widget_get_child_visible:
9154 * @widget: a #GtkWidget
9156 * Gets the value set with gtk_widget_set_child_visible().
9157 * If you feel a need to use this function, your code probably
9158 * needs reorganization.
9160 * This function is only useful for container implementations and
9161 * never should be called by an application.
9163 * Return value: %TRUE if the widget is mapped with the parent.
9166 gtk_widget_get_child_visible (GtkWidget *widget)
9168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9170 return widget->priv->child_visible;
9174 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9176 GtkWidget *toplevel;
9178 toplevel = gtk_widget_get_toplevel (widget);
9180 if (gtk_widget_is_toplevel (toplevel))
9182 if (GTK_IS_WINDOW (toplevel))
9183 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9184 else if (GTK_IS_INVISIBLE (toplevel))
9185 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9192 * gtk_widget_get_screen:
9193 * @widget: a #GtkWidget
9195 * Get the #GdkScreen from the toplevel window associated with
9196 * this widget. This function can only be called after the widget
9197 * has been added to a widget hierarchy with a #GtkWindow
9200 * In general, you should only create screen specific
9201 * resources when a widget has been realized, and you should
9202 * free those resources when the widget is unrealized.
9204 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9209 gtk_widget_get_screen (GtkWidget *widget)
9213 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9215 screen = gtk_widget_get_screen_unchecked (widget);
9222 g_warning (G_STRLOC ": Can't get associated screen"
9223 " for a widget unless it is inside a toplevel GtkWindow\n"
9224 " widget type is %s associated top level type is %s",
9225 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9226 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9228 return gdk_screen_get_default ();
9233 * gtk_widget_has_screen:
9234 * @widget: a #GtkWidget
9236 * Checks whether there is a #GdkScreen is associated with
9237 * this widget. All toplevel widgets have an associated
9238 * screen, and all widgets added into a hierarchy with a toplevel
9239 * window at the top.
9241 * Return value: %TRUE if there is a #GdkScreen associcated
9247 gtk_widget_has_screen (GtkWidget *widget)
9249 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9251 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9255 * gtk_widget_get_display:
9256 * @widget: a #GtkWidget
9258 * Get the #GdkDisplay for the toplevel window associated with
9259 * this widget. This function can only be called after the widget
9260 * has been added to a widget hierarchy with a #GtkWindow at the top.
9262 * In general, you should only create display specific
9263 * resources when a widget has been realized, and you should
9264 * free those resources when the widget is unrealized.
9266 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9271 gtk_widget_get_display (GtkWidget *widget)
9273 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9275 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9279 * gtk_widget_get_root_window:
9280 * @widget: a #GtkWidget
9282 * Get the root window where this widget is located. This function can
9283 * only be called after the widget has been added to a widget
9284 * hierarchy with #GtkWindow at the top.
9286 * The root window is useful for such purposes as creating a popup
9287 * #GdkWindow associated with the window. In general, you should only
9288 * create display specific resources when a widget has been realized,
9289 * and you should free those resources when the widget is unrealized.
9291 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9296 gtk_widget_get_root_window (GtkWidget *widget)
9298 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9300 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9304 * gtk_widget_child_focus:
9305 * @widget: a #GtkWidget
9306 * @direction: direction of focus movement
9308 * This function is used by custom widget implementations; if you're
9309 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9310 * to a particular widget, and gtk_container_set_focus_chain() to
9311 * change the focus tab order. So you may want to investigate those
9312 * functions instead.
9314 * gtk_widget_child_focus() is called by containers as the user moves
9315 * around the window using keyboard shortcuts. @direction indicates
9316 * what kind of motion is taking place (up, down, left, right, tab
9317 * forward, tab backward). gtk_widget_child_focus() emits the
9318 * #GtkWidget::focus signal; widgets override the default handler
9319 * for this signal in order to implement appropriate focus behavior.
9321 * The default ::focus handler for a widget should return %TRUE if
9322 * moving in @direction left the focus on a focusable location inside
9323 * that widget, and %FALSE if moving in @direction moved the focus
9324 * outside the widget. If returning %TRUE, widgets normally
9325 * call gtk_widget_grab_focus() to place the focus accordingly;
9326 * if returning %FALSE, they don't modify the current focus location.
9328 * Return value: %TRUE if focus ended up inside @widget
9331 gtk_widget_child_focus (GtkWidget *widget,
9332 GtkDirectionType direction)
9334 gboolean return_val;
9336 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9338 if (!gtk_widget_get_visible (widget) ||
9339 !gtk_widget_is_sensitive (widget))
9342 /* child widgets must set CAN_FOCUS, containers
9343 * don't have to though.
9345 if (!GTK_IS_CONTAINER (widget) &&
9346 !gtk_widget_get_can_focus (widget))
9349 g_signal_emit (widget,
9350 widget_signals[FOCUS],
9352 direction, &return_val);
9358 * gtk_widget_keynav_failed:
9359 * @widget: a #GtkWidget
9360 * @direction: direction of focus movement
9362 * This function should be called whenever keyboard navigation within
9363 * a single widget hits a boundary. The function emits the
9364 * #GtkWidget::keynav-failed signal on the widget and its return
9365 * value should be interpreted in a way similar to the return value of
9366 * gtk_widget_child_focus():
9368 * When %TRUE is returned, stay in the widget, the failed keyboard
9369 * navigation is Ok and/or there is nowhere we can/should move the
9372 * When %FALSE is returned, the caller should continue with keyboard
9373 * navigation outside the widget, e.g. by calling
9374 * gtk_widget_child_focus() on the widget's toplevel.
9376 * The default ::keynav-failed handler returns %TRUE for
9377 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9378 * values of #GtkDirectionType, it looks at the
9379 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9380 * if the setting is %TRUE. This way the entire user interface
9381 * becomes cursor-navigatable on input devices such as mobile phones
9382 * which only have cursor keys but no tab key.
9384 * Whenever the default handler returns %TRUE, it also calls
9385 * gtk_widget_error_bell() to notify the user of the failed keyboard
9388 * A use case for providing an own implementation of ::keynav-failed
9389 * (either by connecting to it or by overriding it) would be a row of
9390 * #GtkEntry widgets where the user should be able to navigate the
9391 * entire row with the cursor keys, as e.g. known from user interfaces
9392 * that require entering license keys.
9394 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9395 * if the emitting widget should try to handle the keyboard
9396 * navigation attempt in its parent container(s).
9401 gtk_widget_keynav_failed (GtkWidget *widget,
9402 GtkDirectionType direction)
9404 gboolean return_val;
9406 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9408 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9409 direction, &return_val);
9415 * gtk_widget_error_bell:
9416 * @widget: a #GtkWidget
9418 * Notifies the user about an input-related error on this widget.
9419 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9420 * gdk_window_beep(), otherwise it does nothing.
9422 * Note that the effect of gdk_window_beep() can be configured in many
9423 * ways, depending on the windowing backend and the desktop environment
9424 * or window manager that is used.
9429 gtk_widget_error_bell (GtkWidget *widget)
9431 GtkWidgetPrivate *priv;
9432 GtkSettings* settings;
9435 g_return_if_fail (GTK_IS_WIDGET (widget));
9437 priv = widget->priv;
9439 settings = gtk_widget_get_settings (widget);
9443 g_object_get (settings,
9444 "gtk-error-bell", &beep,
9447 if (beep && priv->window)
9448 gdk_window_beep (priv->window);
9452 gtk_widget_set_usize_internal (GtkWidget *widget,
9455 GtkQueueResizeFlags flags)
9457 GtkWidgetAuxInfo *aux_info;
9458 gboolean changed = FALSE;
9460 g_object_freeze_notify (G_OBJECT (widget));
9462 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9464 if (width > -2 && aux_info->width != width)
9466 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9467 g_object_notify (G_OBJECT (widget), "width-request");
9468 aux_info->width = width;
9471 if (height > -2 && aux_info->height != height)
9473 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9474 g_object_notify (G_OBJECT (widget), "height-request");
9475 aux_info->height = height;
9479 if (gtk_widget_get_visible (widget) && changed)
9481 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9482 gtk_widget_queue_resize (widget);
9484 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9487 g_object_thaw_notify (G_OBJECT (widget));
9491 * gtk_widget_set_size_request:
9492 * @widget: a #GtkWidget
9493 * @width: width @widget should request, or -1 to unset
9494 * @height: height @widget should request, or -1 to unset
9496 * Sets the minimum size of a widget; that is, the widget's size
9497 * request will be at least @width by @height. You can use this
9498 * function to force a widget to be larger than it normally would be.
9500 * In most cases, gtk_window_set_default_size() is a better choice for
9501 * toplevel windows than this function; setting the default size will
9502 * still allow users to shrink the window. Setting the size request
9503 * will force them to leave the window at least as large as the size
9504 * request. When dealing with window sizes,
9505 * gtk_window_set_geometry_hints() can be a useful function as well.
9507 * Note the inherent danger of setting any fixed size - themes,
9508 * translations into other languages, different fonts, and user action
9509 * can all change the appropriate size for a given widget. So, it's
9510 * basically impossible to hardcode a size that will always be
9513 * The size request of a widget is the smallest size a widget can
9514 * accept while still functioning well and drawing itself correctly.
9515 * However in some strange cases a widget may be allocated less than
9516 * its requested size, and in many cases a widget may be allocated more
9517 * space than it requested.
9519 * If the size request in a given direction is -1 (unset), then
9520 * the "natural" size request of the widget will be used instead.
9522 * The size request set here does not include any margin from the
9523 * #GtkWidget properties margin-left, margin-right, margin-top, and
9524 * margin-bottom, but it does include pretty much all other padding
9525 * or border properties set by any subclass of #GtkWidget.
9528 gtk_widget_set_size_request (GtkWidget *widget,
9532 g_return_if_fail (GTK_IS_WIDGET (widget));
9533 g_return_if_fail (width >= -1);
9534 g_return_if_fail (height >= -1);
9541 gtk_widget_set_usize_internal (widget, width, height, 0);
9546 * gtk_widget_get_size_request:
9547 * @widget: a #GtkWidget
9548 * @width: (out) (allow-none): return location for width, or %NULL
9549 * @height: (out) (allow-none): return location for height, or %NULL
9551 * Gets the size request that was explicitly set for the widget using
9552 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9553 * @height indicates that that dimension has not been set explicitly
9554 * and the natural requisition of the widget will be used intead. See
9555 * gtk_widget_set_size_request(). To get the size a widget will
9556 * actually request, call gtk_widget_get_preferred_size() instead of
9560 gtk_widget_get_size_request (GtkWidget *widget,
9564 const GtkWidgetAuxInfo *aux_info;
9566 g_return_if_fail (GTK_IS_WIDGET (widget));
9568 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9571 *width = aux_info->width;
9574 *height = aux_info->height;
9578 * _gtk_widget_override_size_request:
9579 * @widget: a #GtkWidget
9580 * @width: new forced minimum width
9581 * @height: new forced minimum height
9582 * @old_width: location to store previous forced minimum width
9583 * @old_height: location to store previous forced minumum height
9585 * Temporarily establishes a forced minimum size for a widget; this
9586 * is used by GtkWindow when calculating the size to add to the
9587 * window's geometry widget. Cached sizes for the widget and its
9588 * parents are invalidated, so that subsequent calls to the size
9589 * negotiation machinery produce the overriden result, but the
9590 * widget is not queued for relayout or redraw. The old size must
9591 * be restored with _gtk_widget_restore_size_request() or things
9595 _gtk_widget_override_size_request (GtkWidget *widget,
9601 gtk_widget_get_size_request (widget, old_width, old_height);
9602 gtk_widget_set_usize_internal (widget, width, height,
9603 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9607 * _gtk_widget_restore_size_request:
9608 * @widget: a #GtkWidget
9609 * @old_width: saved forced minimum size
9610 * @old_height: saved forced minimum size
9612 * Undoes the operation of_gtk_widget_override_size_request().
9615 _gtk_widget_restore_size_request (GtkWidget *widget,
9619 gtk_widget_set_usize_internal (widget, old_width, old_height,
9620 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9624 * gtk_widget_set_events:
9625 * @widget: a #GtkWidget
9626 * @events: event mask
9628 * Sets the event mask (see #GdkEventMask) for a widget. The event
9629 * mask determines which events a widget will receive. Keep in mind
9630 * that different widgets have different default event masks, and by
9631 * changing the event mask you may disrupt a widget's functionality,
9632 * so be careful. This function must be called while a widget is
9633 * unrealized. Consider gtk_widget_add_events() for widgets that are
9634 * already realized, or if you want to preserve the existing event
9635 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9636 * to get events on those widgets, place them inside a #GtkEventBox
9637 * and receive events on the event box.
9640 gtk_widget_set_events (GtkWidget *widget,
9643 g_return_if_fail (GTK_IS_WIDGET (widget));
9644 g_return_if_fail (!gtk_widget_get_realized (widget));
9646 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9647 GINT_TO_POINTER (events));
9648 g_object_notify (G_OBJECT (widget), "events");
9652 * gtk_widget_set_device_events:
9653 * @widget: a #GtkWidget
9654 * @device: a #GdkDevice
9655 * @events: event mask
9657 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9658 * mask determines which events a widget will receive from @device. Keep
9659 * in mind that different widgets have different default event masks, and by
9660 * changing the event mask you may disrupt a widget's functionality,
9661 * so be careful. This function must be called while a widget is
9662 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9663 * already realized, or if you want to preserve the existing event
9664 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9665 * to get events on those widgets, place them inside a #GtkEventBox
9666 * and receive events on the event box.
9671 gtk_widget_set_device_events (GtkWidget *widget,
9673 GdkEventMask events)
9675 GHashTable *device_events;
9677 g_return_if_fail (GTK_IS_WIDGET (widget));
9678 g_return_if_fail (GDK_IS_DEVICE (device));
9679 g_return_if_fail (!gtk_widget_get_realized (widget));
9681 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9683 if (G_UNLIKELY (!device_events))
9685 device_events = g_hash_table_new (NULL, NULL);
9686 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9687 (GDestroyNotify) g_hash_table_unref);
9690 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9694 * gtk_widget_set_device_enabled:
9695 * @widget: a #GtkWidget
9696 * @device: a #GdkDevice
9697 * @enabled: whether to enable the device
9699 * Enables or disables a #GdkDevice to interact with @widget
9700 * and all its children.
9702 * It does so by descending through the #GdkWindow hierarchy
9703 * and enabling the same mask that is has for core events
9704 * (i.e. the one that gdk_window_get_events() returns).
9709 gtk_widget_set_device_enabled (GtkWidget *widget,
9713 GList *enabled_devices;
9715 g_return_if_fail (GTK_IS_WIDGET (widget));
9716 g_return_if_fail (GDK_IS_DEVICE (device));
9718 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9719 enabled_devices = g_list_append (enabled_devices, device);
9721 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9722 enabled_devices, (GDestroyNotify) g_list_free);;
9724 if (gtk_widget_get_realized (widget))
9725 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9729 * gtk_widget_get_device_enabled:
9730 * @widget: a #GtkWidget
9731 * @device: a #GdkDevice
9733 * Returns whether @device can interact with @widget and its
9734 * children. See gtk_widget_set_device_enabled().
9736 * Return value: %TRUE is @device is enabled for @widget
9741 gtk_widget_get_device_enabled (GtkWidget *widget,
9744 GList *enabled_devices;
9746 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9747 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9749 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9751 return g_list_find (enabled_devices, device) != NULL;
9755 gtk_widget_add_events_internal_list (GtkWidget *widget,
9762 for (l = window_list; l != NULL; l = l->next)
9764 GdkWindow *window = l->data;
9767 gdk_window_get_user_data (window, &user_data);
9768 if (user_data == widget)
9773 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9775 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9777 children = gdk_window_get_children (window);
9778 gtk_widget_add_events_internal_list (widget, device, events, children);
9779 g_list_free (children);
9785 gtk_widget_add_events_internal (GtkWidget *widget,
9789 GtkWidgetPrivate *priv = widget->priv;
9792 if (!gtk_widget_get_has_window (widget))
9793 window_list = gdk_window_get_children (priv->window);
9795 window_list = g_list_prepend (NULL, priv->window);
9797 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9799 g_list_free (window_list);
9803 * gtk_widget_add_events:
9804 * @widget: a #GtkWidget
9805 * @events: an event mask, see #GdkEventMask
9807 * Adds the events in the bitfield @events to the event mask for
9808 * @widget. See gtk_widget_set_events() for details.
9811 gtk_widget_add_events (GtkWidget *widget,
9816 g_return_if_fail (GTK_IS_WIDGET (widget));
9818 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9819 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9820 GINT_TO_POINTER (old_events | events));
9822 if (gtk_widget_get_realized (widget))
9824 gtk_widget_add_events_internal (widget, NULL, events);
9825 gtk_widget_update_devices_mask (widget, FALSE);
9828 g_object_notify (G_OBJECT (widget), "events");
9832 * gtk_widget_add_device_events:
9833 * @widget: a #GtkWidget
9834 * @device: a #GdkDevice
9835 * @events: an event mask, see #GdkEventMask
9837 * Adds the device events in the bitfield @events to the event mask for
9838 * @widget. See gtk_widget_set_device_events() for details.
9843 gtk_widget_add_device_events (GtkWidget *widget,
9845 GdkEventMask events)
9847 GdkEventMask old_events;
9848 GHashTable *device_events;
9850 g_return_if_fail (GTK_IS_WIDGET (widget));
9851 g_return_if_fail (GDK_IS_DEVICE (device));
9853 old_events = gtk_widget_get_device_events (widget, device);
9855 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9857 if (G_UNLIKELY (!device_events))
9859 device_events = g_hash_table_new (NULL, NULL);
9860 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9861 (GDestroyNotify) g_hash_table_unref);
9864 g_hash_table_insert (device_events, device,
9865 GUINT_TO_POINTER (old_events | events));
9867 if (gtk_widget_get_realized (widget))
9868 gtk_widget_add_events_internal (widget, device, events);
9870 g_object_notify (G_OBJECT (widget), "events");
9874 * gtk_widget_get_toplevel:
9875 * @widget: a #GtkWidget
9877 * This function returns the topmost widget in the container hierarchy
9878 * @widget is a part of. If @widget has no parent widgets, it will be
9879 * returned as the topmost widget. No reference will be added to the
9880 * returned widget; it should not be unreferenced.
9882 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9883 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9885 * %NULL if @widget wasn't inside a toplevel window, and if the
9886 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9887 * inside the toplevel #GtkWindow. While the second case may
9888 * seem unlikely, it actually happens when a #GtkPlug is embedded
9889 * inside a #GtkSocket within the same application.
9891 * To reliably find the toplevel #GtkWindow, use
9892 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9893 * is set on the result.
9895 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9896 * if (gtk_widget_is_toplevel (toplevel))
9898 * /* Perform action on toplevel. */
9902 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9903 * if there's no ancestor.
9906 gtk_widget_get_toplevel (GtkWidget *widget)
9908 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9910 while (widget->priv->parent)
9911 widget = widget->priv->parent;
9917 * gtk_widget_get_ancestor:
9918 * @widget: a #GtkWidget
9919 * @widget_type: ancestor type
9921 * Gets the first ancestor of @widget with type @widget_type. For example,
9922 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9923 * the first #GtkBox that's an ancestor of @widget. No reference will be
9924 * added to the returned widget; it should not be unreferenced. See note
9925 * about checking for a toplevel #GtkWindow in the docs for
9926 * gtk_widget_get_toplevel().
9928 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9929 * considers @widget to be an ancestor of itself.
9931 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9934 gtk_widget_get_ancestor (GtkWidget *widget,
9937 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9939 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9940 widget = widget->priv->parent;
9942 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9949 * gtk_widget_set_visual:
9950 * @widget: a #GtkWidget
9951 * @visual: visual to be used or %NULL to unset a previous one
9953 * Sets the visual that should be used for by widget and its children for
9954 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9955 * returned by gtk_widget_get_screen(), so handling the
9956 * #GtkWidget::screen-changed signal is necessary.
9958 * Setting a new @visual will not cause @widget to recreate its windows,
9959 * so you should call this function before @widget is realized.
9962 gtk_widget_set_visual (GtkWidget *widget,
9965 g_return_if_fail (GTK_IS_WIDGET (widget));
9966 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9969 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9972 g_object_set_qdata_full (G_OBJECT (widget),
9974 g_object_ref (visual),
9979 * gtk_widget_get_visual:
9980 * @widget: a #GtkWidget
9982 * Gets the visual that will be used to render @widget.
9984 * Return value: (transfer none): the visual for @widget
9987 gtk_widget_get_visual (GtkWidget *widget)
9993 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9995 if (gtk_widget_get_has_window (widget) &&
9996 widget->priv->window)
9997 return gdk_window_get_visual (widget->priv->window);
9999 screen = gtk_widget_get_screen (widget);
10001 for (w = widget; w != NULL; w = w->priv->parent)
10003 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10006 if (gdk_visual_get_screen (visual) == screen)
10009 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10010 gtk_widget_get_name (widget));
10014 return gdk_screen_get_system_visual (screen);
10018 * gtk_widget_get_settings:
10019 * @widget: a #GtkWidget
10021 * Gets the settings object holding the settings used for this widget.
10023 * Note that this function can only be called when the #GtkWidget
10024 * is attached to a toplevel, since the settings object is specific
10025 * to a particular #GdkScreen.
10027 * Return value: (transfer none): the relevant #GtkSettings object
10030 gtk_widget_get_settings (GtkWidget *widget)
10032 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10034 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10038 * gtk_widget_get_events:
10039 * @widget: a #GtkWidget
10041 * Returns the event mask for the widget (a bitfield containing flags
10042 * from the #GdkEventMask enumeration). These are the events that the widget
10045 * Return value: event mask for @widget
10048 gtk_widget_get_events (GtkWidget *widget)
10050 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10052 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10056 * gtk_widget_get_device_events:
10057 * @widget: a #GtkWidget
10058 * @device: a #GdkDevice
10060 * Returns the events mask for the widget corresponding to an specific device. These
10061 * are the events that the widget will receive when @device operates on it.
10063 * Returns: device event mask for @widget
10068 gtk_widget_get_device_events (GtkWidget *widget,
10071 GHashTable *device_events;
10073 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10074 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10076 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10078 if (!device_events)
10081 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10085 * gtk_widget_get_pointer:
10086 * @widget: a #GtkWidget
10087 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10088 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10090 * Obtains the location of the mouse pointer in widget coordinates.
10091 * Widget coordinates are a bit odd; for historical reasons, they are
10092 * defined as @widget->window coordinates for widgets that are not
10093 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10094 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10096 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10099 gtk_widget_get_pointer (GtkWidget *widget,
10103 GtkWidgetPrivate *priv;
10105 g_return_if_fail (GTK_IS_WIDGET (widget));
10107 priv = widget->priv;
10114 if (gtk_widget_get_realized (widget))
10116 gdk_window_get_device_position (priv->window,
10117 gdk_device_manager_get_client_pointer (
10118 gdk_display_get_device_manager (
10119 gtk_widget_get_display (widget))),
10122 if (!gtk_widget_get_has_window (widget))
10125 *x -= priv->allocation.x;
10127 *y -= priv->allocation.y;
10133 * gtk_widget_is_ancestor:
10134 * @widget: a #GtkWidget
10135 * @ancestor: another #GtkWidget
10137 * Determines whether @widget is somewhere inside @ancestor, possibly with
10138 * intermediate containers.
10140 * Return value: %TRUE if @ancestor contains @widget as a child,
10141 * grandchild, great grandchild, etc.
10144 gtk_widget_is_ancestor (GtkWidget *widget,
10145 GtkWidget *ancestor)
10147 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10148 g_return_val_if_fail (ancestor != NULL, FALSE);
10152 if (widget->priv->parent == ancestor)
10154 widget = widget->priv->parent;
10160 static GQuark quark_composite_name = 0;
10163 * gtk_widget_set_composite_name:
10164 * @widget: a #GtkWidget.
10165 * @name: the name to set
10167 * Sets a widgets composite name. The widget must be
10168 * a composite child of its parent; see gtk_widget_push_composite_child().
10171 gtk_widget_set_composite_name (GtkWidget *widget,
10174 g_return_if_fail (GTK_IS_WIDGET (widget));
10175 g_return_if_fail (widget->priv->composite_child);
10176 g_return_if_fail (name != NULL);
10178 if (!quark_composite_name)
10179 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10181 g_object_set_qdata_full (G_OBJECT (widget),
10182 quark_composite_name,
10188 * gtk_widget_get_composite_name:
10189 * @widget: a #GtkWidget
10191 * Obtains the composite name of a widget.
10193 * Returns: the composite name of @widget, or %NULL if @widget is not
10194 * a composite child. The string should be freed when it is no
10198 gtk_widget_get_composite_name (GtkWidget *widget)
10200 GtkWidgetPrivate *priv;
10202 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10204 priv = widget->priv;
10206 if (widget->priv->composite_child && priv->parent)
10207 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10214 * gtk_widget_push_composite_child:
10216 * Makes all newly-created widgets as composite children until
10217 * the corresponding gtk_widget_pop_composite_child() call.
10219 * A composite child is a child that's an implementation detail of the
10220 * container it's inside and should not be visible to people using the
10221 * container. Composite children aren't treated differently by GTK (but
10222 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10223 * builders might want to treat them in a different way.
10225 * Here is a simple example:
10227 * gtk_widget_push_composite_child ();
10228 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10229 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10230 * gtk_widget_pop_composite_child ();
10231 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10232 * GTK_WIDGET (scrolled_window));
10233 * g_object_ref (scrolled_window->hscrollbar);
10237 gtk_widget_push_composite_child (void)
10239 composite_child_stack++;
10243 * gtk_widget_pop_composite_child:
10245 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10248 gtk_widget_pop_composite_child (void)
10250 if (composite_child_stack)
10251 composite_child_stack--;
10255 gtk_widget_emit_direction_changed (GtkWidget *widget,
10256 GtkTextDirection old_dir)
10258 GtkTextDirection direction;
10259 GtkStateFlags state;
10261 gtk_widget_update_pango_context (widget);
10263 direction = gtk_widget_get_direction (widget);
10264 state = widget->priv->state_flags;
10265 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10269 case GTK_TEXT_DIR_LTR:
10270 state |= GTK_STATE_FLAG_DIR_LTR;
10273 case GTK_TEXT_DIR_RTL:
10274 state |= GTK_STATE_FLAG_DIR_RTL;
10277 case GTK_TEXT_DIR_NONE:
10279 g_assert_not_reached ();
10283 gtk_widget_set_state_flags (widget, state, TRUE);
10285 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10289 * gtk_widget_set_direction:
10290 * @widget: a #GtkWidget
10291 * @dir: the new direction
10293 * Sets the reading direction on a particular widget. This direction
10294 * controls the primary direction for widgets containing text,
10295 * and also the direction in which the children of a container are
10296 * packed. The ability to set the direction is present in order
10297 * so that correct localization into languages with right-to-left
10298 * reading directions can be done. Generally, applications will
10299 * let the default reading direction present, except for containers
10300 * where the containers are arranged in an order that is explicitely
10301 * visual rather than logical (such as buttons for text justification).
10303 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10304 * set by gtk_widget_set_default_direction() will be used.
10307 gtk_widget_set_direction (GtkWidget *widget,
10308 GtkTextDirection dir)
10310 GtkTextDirection old_dir;
10312 g_return_if_fail (GTK_IS_WIDGET (widget));
10313 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10315 old_dir = gtk_widget_get_direction (widget);
10317 widget->priv->direction = dir;
10319 if (old_dir != gtk_widget_get_direction (widget))
10320 gtk_widget_emit_direction_changed (widget, old_dir);
10324 * gtk_widget_get_direction:
10325 * @widget: a #GtkWidget
10327 * Gets the reading direction for a particular widget. See
10328 * gtk_widget_set_direction().
10330 * Return value: the reading direction for the widget.
10333 gtk_widget_get_direction (GtkWidget *widget)
10335 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10337 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10338 return gtk_default_direction;
10340 return widget->priv->direction;
10344 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10346 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10348 g_object_ref (widget);
10350 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10351 gtk_widget_emit_direction_changed (widget, old_dir);
10353 if (GTK_IS_CONTAINER (widget))
10354 gtk_container_forall (GTK_CONTAINER (widget),
10355 gtk_widget_set_default_direction_recurse,
10358 g_object_unref (widget);
10362 * gtk_widget_set_default_direction:
10363 * @dir: the new default direction. This cannot be
10364 * %GTK_TEXT_DIR_NONE.
10366 * Sets the default reading direction for widgets where the
10367 * direction has not been explicitly set by gtk_widget_set_direction().
10370 gtk_widget_set_default_direction (GtkTextDirection dir)
10372 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10374 if (dir != gtk_default_direction)
10376 GList *toplevels, *tmp_list;
10377 GtkTextDirection old_dir = gtk_default_direction;
10379 gtk_default_direction = dir;
10381 tmp_list = toplevels = gtk_window_list_toplevels ();
10382 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10386 gtk_widget_set_default_direction_recurse (tmp_list->data,
10387 GUINT_TO_POINTER (old_dir));
10388 g_object_unref (tmp_list->data);
10389 tmp_list = tmp_list->next;
10392 g_list_free (toplevels);
10397 * gtk_widget_get_default_direction:
10399 * Obtains the current default reading direction. See
10400 * gtk_widget_set_default_direction().
10402 * Return value: the current default direction.
10405 gtk_widget_get_default_direction (void)
10407 return gtk_default_direction;
10411 gtk_widget_constructed (GObject *object)
10413 GtkWidget *widget = GTK_WIDGET (object);
10414 GtkWidgetPrivate *priv = widget->priv;
10416 /* As strange as it may seem, this may happen on object construction.
10417 * init() implementations of parent types may eventually call this function,
10418 * each with its corresponding GType, which could leave a child
10419 * implementation with a wrong widget type in the widget path
10422 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10424 gtk_widget_path_free (priv->path);
10428 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10432 gtk_widget_dispose (GObject *object)
10434 GtkWidget *widget = GTK_WIDGET (object);
10435 GtkWidgetPrivate *priv = widget->priv;
10438 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10439 else if (gtk_widget_get_visible (widget))
10440 gtk_widget_hide (widget);
10442 priv->visible = FALSE;
10443 if (gtk_widget_get_realized (widget))
10444 gtk_widget_unrealize (widget);
10446 if (!priv->in_destruction)
10448 priv->in_destruction = TRUE;
10449 g_signal_emit (object, widget_signals[DESTROY], 0);
10450 priv->in_destruction = FALSE;
10453 g_clear_object (&priv->muxer);
10455 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10459 gtk_widget_real_destroy (GtkWidget *object)
10461 /* gtk_object_destroy() will already hold a refcount on object */
10462 GtkWidget *widget = GTK_WIDGET (object);
10463 GtkWidgetPrivate *priv = widget->priv;
10465 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10467 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10471 gtk_accessible_set_widget (accessible, NULL);
10472 g_object_unref (accessible);
10476 /* wipe accelerator closures (keep order) */
10477 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10478 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10480 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10481 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10483 gtk_grab_remove (widget);
10486 g_object_unref (priv->style);
10487 priv->style = gtk_widget_get_default_style ();
10488 g_object_ref (priv->style);
10492 gtk_widget_finalize (GObject *object)
10494 GtkWidget *widget = GTK_WIDGET (object);
10495 GtkWidgetPrivate *priv = widget->priv;
10496 GtkWidgetAuxInfo *aux_info;
10497 GtkAccessible *accessible;
10499 gtk_grab_remove (widget);
10501 g_object_unref (priv->style);
10502 priv->style = NULL;
10504 g_free (priv->name);
10506 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10508 gtk_widget_aux_info_destroy (aux_info);
10510 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10512 g_object_unref (accessible);
10515 gtk_widget_path_free (priv->path);
10519 _gtk_style_context_set_widget (priv->context, NULL);
10520 g_object_unref (priv->context);
10523 _gtk_size_request_cache_free (&priv->requests);
10525 if (g_object_is_floating (object))
10526 g_warning ("A floating object was finalized. This means that someone\n"
10527 "called g_object_unref() on an object that had only a floating\n"
10528 "reference; the initial floating reference is not owned by anyone\n"
10529 "and must be removed with g_object_ref_sink().");
10531 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10534 /*****************************************
10535 * gtk_widget_real_map:
10540 *****************************************/
10543 gtk_widget_real_map (GtkWidget *widget)
10545 GtkWidgetPrivate *priv = widget->priv;
10547 g_assert (gtk_widget_get_realized (widget));
10549 if (!gtk_widget_get_mapped (widget))
10551 gtk_widget_set_mapped (widget, TRUE);
10553 if (gtk_widget_get_has_window (widget))
10554 gdk_window_show (priv->window);
10558 /*****************************************
10559 * gtk_widget_real_unmap:
10564 *****************************************/
10567 gtk_widget_real_unmap (GtkWidget *widget)
10569 GtkWidgetPrivate *priv = widget->priv;
10571 if (gtk_widget_get_mapped (widget))
10573 gtk_widget_set_mapped (widget, FALSE);
10575 if (gtk_widget_get_has_window (widget))
10576 gdk_window_hide (priv->window);
10580 /*****************************************
10581 * gtk_widget_real_realize:
10586 *****************************************/
10589 gtk_widget_real_realize (GtkWidget *widget)
10591 GtkWidgetPrivate *priv = widget->priv;
10593 g_assert (!gtk_widget_get_has_window (widget));
10595 gtk_widget_set_realized (widget, TRUE);
10598 priv->window = gtk_widget_get_parent_window (widget);
10599 g_object_ref (priv->window);
10603 /*****************************************
10604 * gtk_widget_real_unrealize:
10609 *****************************************/
10612 gtk_widget_real_unrealize (GtkWidget *widget)
10614 GtkWidgetPrivate *priv = widget->priv;
10616 g_assert (!widget->priv->mapped);
10618 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10621 /* We must do unrealize child widget BEFORE container widget.
10622 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10623 * So, unrealizing container widget bofore its children causes the problem
10624 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10627 if (GTK_IS_CONTAINER (widget))
10628 gtk_container_forall (GTK_CONTAINER (widget),
10629 (GtkCallback) gtk_widget_unrealize,
10632 if (gtk_widget_get_has_window (widget))
10634 gtk_widget_unregister_window (widget, priv->window);
10635 gdk_window_destroy (priv->window);
10636 priv->window = NULL;
10640 g_object_unref (priv->window);
10641 priv->window = NULL;
10644 gtk_selection_remove_all (widget);
10646 gtk_widget_set_realized (widget, FALSE);
10650 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10651 GtkOrientation orientation,
10652 gint *minimum_size,
10653 gint *natural_size)
10655 const GtkWidgetAuxInfo *aux_info;
10657 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10659 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10660 aux_info->width > 0)
10662 *minimum_size = MAX (*minimum_size, aux_info->width);
10664 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10665 aux_info->height > 0)
10667 *minimum_size = MAX (*minimum_size, aux_info->height);
10670 /* Fix it if set_size_request made natural size smaller than min size.
10671 * This would also silently fix broken widgets, but we warn about them
10672 * in gtksizerequest.c when calling their size request vfuncs.
10674 *natural_size = MAX (*natural_size, *minimum_size);
10676 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10678 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10679 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10683 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10684 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10689 * _gtk_widget_peek_request_cache:
10691 * Returns the address of the widget's request cache (strictly for
10692 * internal use in gtksizerequest.c)
10694 * Return value: the address of @widget's size request cache.
10697 _gtk_widget_peek_request_cache (GtkWidget *widget)
10699 /* Don't bother slowing things down with the return_if_fail guards here */
10700 return &widget->priv->requests;
10704 * _gtk_widget_set_device_window:
10705 * @widget: a #GtkWidget
10706 * @device: a #GdkDevice
10707 * @window: the new device window
10709 * Sets pointer window for @widget and @device.
10710 * Does not ref @window.
10713 _gtk_widget_set_device_window (GtkWidget *widget,
10717 GHashTable *device_window;
10719 g_return_if_fail (GTK_IS_WIDGET (widget));
10720 g_return_if_fail (GDK_IS_DEVICE (device));
10721 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10723 if (!gtk_widget_get_mapped (widget))
10726 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10728 if (!device_window && window)
10730 device_window = g_hash_table_new (NULL, NULL);
10731 g_object_set_qdata_full (G_OBJECT (widget),
10732 quark_pointer_window,
10734 (GDestroyNotify) g_hash_table_destroy);
10738 g_hash_table_insert (device_window, device, window);
10739 else if (device_window)
10741 g_hash_table_remove (device_window, device);
10743 if (g_hash_table_size (device_window) == 0)
10744 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10749 * _gtk_widget_get_device_window:
10750 * @widget: a #GtkWidget
10751 * @device: a #GdkDevice
10753 * Return value: the device window set on @widget, or %NULL
10756 _gtk_widget_get_device_window (GtkWidget *widget,
10759 GHashTable *device_window;
10761 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10762 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10764 if (!gtk_widget_get_mapped (widget))
10767 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10769 if (!device_window)
10772 return g_hash_table_lookup (device_window, device);
10776 * _gtk_widget_list_devices:
10777 * @widget: a #GtkWidget
10779 * Returns the list of #GdkDevices that is currently on top
10780 * of any window belonging to @widget.
10781 * Free the list with g_list_free(), the elements are owned
10782 * by GTK+ and must not be freed.
10785 _gtk_widget_list_devices (GtkWidget *widget)
10787 GHashTableIter iter;
10788 GHashTable *device_window;
10789 GList *devices = NULL;
10790 gpointer key, value;
10792 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10794 if (!gtk_widget_get_mapped (widget))
10797 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10799 if (G_UNLIKELY (!device_window))
10802 g_hash_table_iter_init (&iter, device_window);
10804 while (g_hash_table_iter_next (&iter, &key, &value))
10805 devices = g_list_prepend (devices, key);
10811 synth_crossing (GtkWidget *widget,
10815 GdkCrossingMode mode,
10816 GdkNotifyType detail)
10820 event = gdk_event_new (type);
10822 event->crossing.window = g_object_ref (window);
10823 event->crossing.send_event = TRUE;
10824 event->crossing.subwindow = g_object_ref (window);
10825 event->crossing.time = GDK_CURRENT_TIME;
10826 event->crossing.x = event->crossing.y = 0;
10827 event->crossing.x_root = event->crossing.y_root = 0;
10828 event->crossing.mode = mode;
10829 event->crossing.detail = detail;
10830 event->crossing.focus = FALSE;
10831 event->crossing.state = 0;
10832 gdk_event_set_device (event, device);
10835 widget = gtk_get_event_widget (event);
10838 gtk_widget_event_internal (widget, event);
10840 gdk_event_free (event);
10844 * _gtk_widget_synthesize_crossing:
10845 * @from: the #GtkWidget the virtual pointer is leaving.
10846 * @to: the #GtkWidget the virtual pointer is moving to.
10847 * @mode: the #GdkCrossingMode to place on the synthesized events.
10849 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10851 * The real pointer window is the window that most recently received an enter notify
10852 * event. Windows that don't select for crossing events can't become the real
10853 * poiner window. The real pointer widget that owns the real pointer window. The
10854 * effective pointer window is the same as the real pointer window unless the real
10855 * pointer widget is either insensitive or there is a grab on a widget that is not
10856 * an ancestor of the real pointer widget (in which case the effective pointer
10857 * window should be the root window).
10859 * When the effective pointer window is the same as the real poiner window, we
10860 * receive crossing events from the windowing system. When the effective pointer
10861 * window changes to become different from the real pointer window we synthesize
10862 * crossing events, attempting to follow X protocol rules:
10864 * When the root window becomes the effective pointer window:
10865 * - leave notify on real pointer window, detail Ancestor
10866 * - leave notify on all of its ancestors, detail Virtual
10867 * - enter notify on root window, detail Inferior
10869 * When the root window ceases to be the effective pointer window:
10870 * - leave notify on root window, detail Inferior
10871 * - enter notify on all ancestors of real pointer window, detail Virtual
10872 * - enter notify on real pointer window, detail Ancestor
10875 _gtk_widget_synthesize_crossing (GtkWidget *from,
10878 GdkCrossingMode mode)
10880 GdkWindow *from_window = NULL, *to_window = NULL;
10882 g_return_if_fail (from != NULL || to != NULL);
10886 from_window = _gtk_widget_get_device_window (from, device);
10889 from_window = from->priv->window;
10894 to_window = _gtk_widget_get_device_window (to, device);
10897 to_window = to->priv->window;
10900 if (from_window == NULL && to_window == NULL)
10902 else if (from_window != NULL && to_window == NULL)
10904 GList *from_ancestors = NULL, *list;
10905 GdkWindow *from_ancestor = from_window;
10907 while (from_ancestor != NULL)
10909 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10910 if (from_ancestor == NULL)
10912 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10915 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10916 device, mode, GDK_NOTIFY_ANCESTOR);
10917 for (list = g_list_last (from_ancestors); list; list = list->prev)
10919 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10920 device, mode, GDK_NOTIFY_VIRTUAL);
10923 /* XXX: enter/inferior on root window? */
10925 g_list_free (from_ancestors);
10927 else if (from_window == NULL && to_window != NULL)
10929 GList *to_ancestors = NULL, *list;
10930 GdkWindow *to_ancestor = to_window;
10932 while (to_ancestor != NULL)
10934 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10935 if (to_ancestor == NULL)
10937 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10940 /* XXX: leave/inferior on root window? */
10942 for (list = to_ancestors; list; list = list->next)
10944 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10945 device, mode, GDK_NOTIFY_VIRTUAL);
10947 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10948 device, mode, GDK_NOTIFY_ANCESTOR);
10950 g_list_free (to_ancestors);
10952 else if (from_window == to_window)
10956 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10957 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10959 while (from_ancestor != NULL || to_ancestor != NULL)
10961 if (from_ancestor != NULL)
10963 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10964 if (from_ancestor == to_window)
10967 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10969 if (to_ancestor != NULL)
10971 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10972 if (to_ancestor == from_window)
10975 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10978 if (to_ancestor == from_window)
10980 if (mode != GDK_CROSSING_GTK_UNGRAB)
10981 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10982 device, mode, GDK_NOTIFY_INFERIOR);
10983 for (list = to_ancestors; list; list = list->next)
10984 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10985 device, mode, GDK_NOTIFY_VIRTUAL);
10986 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10987 device, mode, GDK_NOTIFY_ANCESTOR);
10989 else if (from_ancestor == to_window)
10991 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10992 device, mode, GDK_NOTIFY_ANCESTOR);
10993 for (list = g_list_last (from_ancestors); list; list = list->prev)
10995 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10996 device, mode, GDK_NOTIFY_VIRTUAL);
10998 if (mode != GDK_CROSSING_GTK_GRAB)
10999 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11000 device, mode, GDK_NOTIFY_INFERIOR);
11004 while (from_ancestors != NULL && to_ancestors != NULL
11005 && from_ancestors->data == to_ancestors->data)
11007 from_ancestors = g_list_delete_link (from_ancestors,
11009 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11012 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11013 device, mode, GDK_NOTIFY_NONLINEAR);
11015 for (list = g_list_last (from_ancestors); list; list = list->prev)
11017 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11018 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11020 for (list = to_ancestors; list; list = list->next)
11022 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11023 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11025 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11026 device, mode, GDK_NOTIFY_NONLINEAR);
11028 g_list_free (from_ancestors);
11029 g_list_free (to_ancestors);
11034 gtk_widget_propagate_state (GtkWidget *widget,
11035 GtkStateData *data)
11037 GtkWidgetPrivate *priv = widget->priv;
11038 GtkStateFlags new_flags, old_flags = priv->state_flags;
11039 GtkStateType old_state;
11041 old_state = gtk_widget_get_state (widget);
11043 priv->state_flags |= data->flags_to_set;
11044 priv->state_flags &= ~(data->flags_to_unset);
11046 /* make insensitivity unoverridable */
11047 if (!priv->sensitive)
11048 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11050 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11054 window = gtk_widget_get_toplevel (widget);
11056 if (window && gtk_widget_is_toplevel (window))
11057 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11060 new_flags = priv->state_flags;
11062 if (old_flags != new_flags)
11064 g_object_ref (widget);
11066 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11067 gtk_grab_remove (widget);
11069 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11071 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11072 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11074 if (!priv->shadowed &&
11075 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11077 GList *event_windows = NULL;
11078 GList *devices, *d;
11080 devices = _gtk_widget_list_devices (widget);
11082 for (d = devices; d; d = d->next)
11088 window = _gtk_widget_get_device_window (widget, device);
11090 /* Do not propagate more than once to the
11091 * same window if non-multidevice aware.
11093 if (!gdk_window_get_support_multidevice (window) &&
11094 g_list_find (event_windows, window))
11097 if (!gtk_widget_is_sensitive (widget))
11098 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11099 GDK_CROSSING_STATE_CHANGED);
11101 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11102 GDK_CROSSING_STATE_CHANGED);
11104 event_windows = g_list_prepend (event_windows, window);
11107 g_list_free (event_windows);
11108 g_list_free (devices);
11111 if (GTK_IS_CONTAINER (widget))
11113 GtkStateData child_data;
11115 /* Make sure to only propate the right states further */
11116 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11117 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11119 gtk_container_forall (GTK_CONTAINER (widget),
11120 (GtkCallback) gtk_widget_propagate_state,
11124 g_object_unref (widget);
11128 static const GtkWidgetAuxInfo default_aux_info = {
11136 * gtk_widget_get_aux_info:
11137 * @widget: a #GtkWidget
11138 * @create: if %TRUE, create the structure if it doesn't exist
11140 * Get the #GtkWidgetAuxInfo structure for the widget.
11142 * Return value: the #GtkAuxInfo structure for the widget, or
11143 * %NULL if @create is %FALSE and one doesn't already exist.
11145 static GtkWidgetAuxInfo *
11146 gtk_widget_get_aux_info (GtkWidget *widget,
11149 GtkWidgetAuxInfo *aux_info;
11151 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11152 if (!aux_info && create)
11154 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11156 *aux_info = default_aux_info;
11158 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11164 static const GtkWidgetAuxInfo*
11165 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11167 GtkWidgetAuxInfo *aux_info;
11169 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11170 if (aux_info == NULL)
11172 return &default_aux_info;
11180 /*****************************************
11181 * gtk_widget_aux_info_destroy:
11186 *****************************************/
11189 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11191 g_slice_free (GtkWidgetAuxInfo, aux_info);
11195 * gtk_widget_shape_combine_region:
11196 * @widget: a #GtkWidget
11197 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11199 * Sets a shape for this widget's GDK window. This allows for
11200 * transparent windows etc., see gdk_window_shape_combine_region()
11201 * for more information.
11206 gtk_widget_shape_combine_region (GtkWidget *widget,
11207 cairo_region_t *region)
11209 GtkWidgetPrivate *priv;
11211 g_return_if_fail (GTK_IS_WIDGET (widget));
11212 /* set_shape doesn't work on widgets without gdk window */
11213 g_return_if_fail (gtk_widget_get_has_window (widget));
11215 priv = widget->priv;
11217 if (region == NULL)
11219 priv->has_shape_mask = FALSE;
11222 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11224 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11228 priv->has_shape_mask = TRUE;
11230 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11231 cairo_region_copy (region),
11232 (GDestroyNotify) cairo_region_destroy);
11234 /* set shape if widget has a gdk window already.
11235 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11238 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11243 * gtk_widget_input_shape_combine_region:
11244 * @widget: a #GtkWidget
11245 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11247 * Sets an input shape for this widget's GDK window. This allows for
11248 * windows which react to mouse click in a nonrectangular region, see
11249 * gdk_window_input_shape_combine_region() for more information.
11254 gtk_widget_input_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)
11268 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11270 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11274 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11275 cairo_region_copy (region),
11276 (GDestroyNotify) cairo_region_destroy);
11278 /* set shape if widget has a gdk window already.
11279 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11282 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11287 /* style properties
11291 * gtk_widget_class_install_style_property_parser: (skip)
11292 * @klass: a #GtkWidgetClass
11293 * @pspec: the #GParamSpec for the style property
11294 * @parser: the parser for the style property
11296 * Installs a style property on a widget class.
11299 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11301 GtkRcPropertyParser parser)
11303 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11304 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11305 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11306 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11308 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11310 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11311 G_OBJECT_CLASS_NAME (klass),
11316 g_param_spec_ref_sink (pspec);
11317 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11318 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11322 * gtk_widget_class_install_style_property:
11323 * @klass: a #GtkWidgetClass
11324 * @pspec: the #GParamSpec for the property
11326 * Installs a style property on a widget class. The parser for the
11327 * style property is determined by the value type of @pspec.
11330 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11333 GtkRcPropertyParser parser;
11335 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11336 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11338 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11340 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11344 * gtk_widget_class_find_style_property:
11345 * @klass: a #GtkWidgetClass
11346 * @property_name: the name of the style property to find
11348 * Finds a style property of a widget class by name.
11350 * Returns: (transfer none): the #GParamSpec of the style property or
11351 * %NULL if @class has no style property with that name.
11356 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11357 const gchar *property_name)
11359 g_return_val_if_fail (property_name != NULL, NULL);
11361 return g_param_spec_pool_lookup (style_property_spec_pool,
11363 G_OBJECT_CLASS_TYPE (klass),
11368 * gtk_widget_class_list_style_properties:
11369 * @klass: a #GtkWidgetClass
11370 * @n_properties: location to return the number of style properties found
11372 * Returns all style properties of a widget class.
11374 * Returns: (array length=n_properties) (transfer container): a
11375 * newly allocated array of #GParamSpec*. The array must be
11376 * freed with g_free().
11381 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11382 guint *n_properties)
11384 GParamSpec **pspecs;
11387 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11388 G_OBJECT_CLASS_TYPE (klass),
11397 * gtk_widget_style_get_property:
11398 * @widget: a #GtkWidget
11399 * @property_name: the name of a style property
11400 * @value: location to return the property value
11402 * Gets the value of a style property of @widget.
11405 gtk_widget_style_get_property (GtkWidget *widget,
11406 const gchar *property_name,
11411 g_return_if_fail (GTK_IS_WIDGET (widget));
11412 g_return_if_fail (property_name != NULL);
11413 g_return_if_fail (G_IS_VALUE (value));
11415 g_object_ref (widget);
11416 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11418 G_OBJECT_TYPE (widget),
11421 g_warning ("%s: widget class `%s' has no property named `%s'",
11423 G_OBJECT_TYPE_NAME (widget),
11427 GtkStyleContext *context;
11428 const GValue *peek_value;
11429 GtkStateFlags state;
11431 context = gtk_widget_get_style_context (widget);
11432 state = gtk_widget_get_state_flags (widget);
11434 peek_value = _gtk_style_context_peek_style_property (context,
11435 G_OBJECT_TYPE (widget),
11438 /* auto-conversion of the caller's value type
11440 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11441 g_value_copy (peek_value, value);
11442 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11443 g_value_transform (peek_value, value);
11445 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11447 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11448 G_VALUE_TYPE_NAME (value));
11450 g_object_unref (widget);
11454 * gtk_widget_style_get_valist:
11455 * @widget: a #GtkWidget
11456 * @first_property_name: the name of the first property to get
11457 * @var_args: a <type>va_list</type> of pairs of property names and
11458 * locations to return the property values, starting with the location
11459 * for @first_property_name.
11461 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11465 gtk_widget_style_get_valist (GtkWidget *widget,
11466 const gchar *first_property_name,
11469 GtkStyleContext *context;
11470 GtkStateFlags state;
11473 g_return_if_fail (GTK_IS_WIDGET (widget));
11475 g_object_ref (widget);
11476 context = gtk_widget_get_style_context (widget);
11477 state = gtk_widget_get_state_flags (widget);
11479 name = first_property_name;
11482 const GValue *peek_value;
11486 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11488 G_OBJECT_TYPE (widget),
11492 g_warning ("%s: widget class `%s' has no property named `%s'",
11494 G_OBJECT_TYPE_NAME (widget),
11498 /* style pspecs are always readable so we can spare that check here */
11500 peek_value = _gtk_style_context_peek_style_property (context,
11501 G_OBJECT_TYPE (widget),
11504 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11507 g_warning ("%s: %s", G_STRLOC, error);
11512 name = va_arg (var_args, gchar*);
11515 g_object_unref (widget);
11519 * gtk_widget_style_get:
11520 * @widget: a #GtkWidget
11521 * @first_property_name: the name of the first property to get
11522 * @...: pairs of property names and locations to return the
11523 * property values, starting with the location for
11524 * @first_property_name, terminated by %NULL.
11526 * Gets the values of a multiple style properties of @widget.
11529 gtk_widget_style_get (GtkWidget *widget,
11530 const gchar *first_property_name,
11535 g_return_if_fail (GTK_IS_WIDGET (widget));
11537 va_start (var_args, first_property_name);
11538 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11543 * gtk_requisition_new:
11545 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11547 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11548 * be freed with gtk_requisition_free().
11553 gtk_requisition_new (void)
11555 return g_slice_new0 (GtkRequisition);
11559 * gtk_requisition_copy:
11560 * @requisition: a #GtkRequisition
11562 * Copies a #GtkRequisition.
11564 * Returns: a copy of @requisition
11567 gtk_requisition_copy (const GtkRequisition *requisition)
11569 return g_slice_dup (GtkRequisition, requisition);
11573 * gtk_requisition_free:
11574 * @requisition: a #GtkRequisition
11576 * Frees a #GtkRequisition.
11579 gtk_requisition_free (GtkRequisition *requisition)
11581 g_slice_free (GtkRequisition, requisition);
11584 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11585 gtk_requisition_copy,
11586 gtk_requisition_free)
11589 * gtk_widget_class_set_accessible_type:
11590 * @widget_class: class to set the accessible type for
11591 * @type: The object type that implements the accessible for @widget_class
11593 * Sets the type to be used for creating accessibles for widgets of
11594 * @widget_class. The given @type must be a subtype of the type used for
11595 * accessibles of the parent class.
11597 * This function should only be called from class init functions of widgets.
11602 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11605 GtkWidgetClassPrivate *priv;
11607 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11608 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11610 priv = widget_class->priv;
11612 priv->accessible_type = type;
11613 /* reset this - honoring the type's role is better. */
11614 priv->accessible_role = ATK_ROLE_INVALID;
11618 * gtk_widget_class_set_accessible_role:
11619 * @widget_class: class to set the accessible role for
11620 * @role: The role to use for accessibles created for @widget_class
11622 * Sets the default #AtkRole to be set on accessibles created for
11623 * widgets of @widget_class. Accessibles may decide to not honor this
11624 * setting if their role reporting is more refined. Calls to
11625 * gtk_widget_class_set_accessible_type() will reset this value.
11627 * In cases where you want more fine-grained control over the role of
11628 * accessibles created for @widget_class, you should provide your own
11629 * accessible type and use gtk_widget_class_set_accessible_type()
11632 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11633 * and the accessible's default role will be used instead.
11635 * This function should only be called from class init functions of widgets.
11640 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11643 GtkWidgetClassPrivate *priv;
11645 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11647 priv = widget_class->priv;
11649 priv->accessible_role = role;
11653 * _gtk_widget_peek_accessible:
11654 * @widget: a #GtkWidget
11656 * Gets the accessible for @widget, if it has been created yet.
11657 * Otherwise, this function returns %NULL. If the @widget's implementation
11658 * does not use the default way to create accessibles, %NULL will always be
11661 * Returns: the accessible for @widget or %NULL if none has been
11665 _gtk_widget_peek_accessible (GtkWidget *widget)
11667 return g_object_get_qdata (G_OBJECT (widget),
11668 quark_accessible_object);
11672 * gtk_widget_get_accessible:
11673 * @widget: a #GtkWidget
11675 * Returns the accessible object that describes the widget to an
11676 * assistive technology.
11678 * If accessibility support is not available, this #AtkObject
11679 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11680 * implementation is available for the widget instance in question,
11681 * it will inherit an #AtkObject implementation from the first ancestor
11682 * class for which such an implementation is defined.
11684 * The documentation of the
11685 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11686 * library contains more information about accessible objects and their uses.
11688 * Returns: (transfer none): the #AtkObject associated with @widget
11691 gtk_widget_get_accessible (GtkWidget *widget)
11693 GtkWidgetClass *klass;
11695 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11697 klass = GTK_WIDGET_GET_CLASS (widget);
11699 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11701 return klass->get_accessible (widget);
11705 gtk_widget_real_get_accessible (GtkWidget *widget)
11707 AtkObject* accessible;
11709 accessible = g_object_get_qdata (G_OBJECT (widget),
11710 quark_accessible_object);
11713 GtkWidgetClass *widget_class;
11714 GtkWidgetClassPrivate *priv;
11715 AtkObjectFactory *factory;
11716 AtkRegistry *default_registry;
11718 widget_class = GTK_WIDGET_GET_CLASS (widget);
11719 priv = widget_class->priv;
11721 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11723 default_registry = atk_get_default_registry ();
11724 factory = atk_registry_get_factory (default_registry,
11725 G_TYPE_FROM_INSTANCE (widget));
11727 atk_object_factory_create_accessible (factory,
11728 G_OBJECT (widget));
11730 if (priv->accessible_role != ATK_ROLE_INVALID)
11731 atk_object_set_role (accessible, priv->accessible_role);
11733 g_object_set_qdata (G_OBJECT (widget),
11734 quark_accessible_object,
11739 accessible = g_object_new (priv->accessible_type,
11742 if (priv->accessible_role != ATK_ROLE_INVALID)
11743 atk_object_set_role (accessible, priv->accessible_role);
11745 g_object_set_qdata (G_OBJECT (widget),
11746 quark_accessible_object,
11749 atk_object_initialize (accessible, widget);
11751 /* Set the role again, since we don't want a role set
11752 * in some parent initialize() function to override
11755 if (priv->accessible_role != ATK_ROLE_INVALID)
11756 atk_object_set_role (accessible, priv->accessible_role);
11763 * Initialize a AtkImplementorIface instance's virtual pointers as
11764 * appropriate to this implementor's class (GtkWidget).
11767 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11769 iface->ref_accessible = gtk_widget_ref_accessible;
11773 gtk_widget_ref_accessible (AtkImplementor *implementor)
11775 AtkObject *accessible;
11777 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11779 g_object_ref (accessible);
11784 * Expand flag management
11788 gtk_widget_update_computed_expand (GtkWidget *widget)
11790 GtkWidgetPrivate *priv;
11792 priv = widget->priv;
11794 if (priv->need_compute_expand)
11798 if (priv->hexpand_set)
11803 if (priv->vexpand_set)
11808 /* we don't need to use compute_expand if both expands are
11809 * forced by the app
11811 if (!(priv->hexpand_set && priv->vexpand_set))
11813 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11817 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11818 priv->hexpand_set ? &ignored : &h,
11819 priv->vexpand_set ? &ignored : &v);
11823 priv->need_compute_expand = FALSE;
11824 priv->computed_hexpand = h != FALSE;
11825 priv->computed_vexpand = v != FALSE;
11830 * gtk_widget_queue_compute_expand:
11831 * @widget: a #GtkWidget
11833 * Mark @widget as needing to recompute its expand flags. Call
11834 * this function when setting legacy expand child properties
11835 * on the child of a container.
11837 * See gtk_widget_compute_expand().
11840 gtk_widget_queue_compute_expand (GtkWidget *widget)
11843 gboolean changed_anything;
11845 if (widget->priv->need_compute_expand)
11848 changed_anything = FALSE;
11850 while (parent != NULL)
11852 if (!parent->priv->need_compute_expand)
11854 parent->priv->need_compute_expand = TRUE;
11855 changed_anything = TRUE;
11858 /* Note: if we had an invariant that "if a child needs to
11859 * compute expand, its parents also do" then we could stop going
11860 * up when we got to a parent that already needed to
11861 * compute. However, in general we compute expand lazily (as
11862 * soon as we see something in a subtree that is expand, we know
11863 * we're expanding) and so this invariant does not hold and we
11864 * have to always walk all the way up in case some ancestor
11865 * is not currently need_compute_expand.
11868 parent = parent->priv->parent;
11871 /* recomputing expand always requires
11872 * a relayout as well
11874 if (changed_anything)
11875 gtk_widget_queue_resize (widget);
11879 * gtk_widget_compute_expand:
11880 * @widget: the widget
11881 * @orientation: expand direction
11883 * Computes whether a container should give this widget extra space
11884 * when possible. Containers should check this, rather than
11885 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11887 * This function already checks whether the widget is visible, so
11888 * visibility does not need to be checked separately. Non-visible
11889 * widgets are not expanded.
11891 * The computed expand value uses either the expand setting explicitly
11892 * set on the widget itself, or, if none has been explicitly set,
11893 * the widget may expand if some of its children do.
11895 * Return value: whether widget tree rooted here should be expanded
11898 gtk_widget_compute_expand (GtkWidget *widget,
11899 GtkOrientation orientation)
11901 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11903 /* We never make a widget expand if not even showing. */
11904 if (!gtk_widget_get_visible (widget))
11907 gtk_widget_update_computed_expand (widget);
11909 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11911 return widget->priv->computed_hexpand;
11915 return widget->priv->computed_vexpand;
11920 gtk_widget_set_expand (GtkWidget *widget,
11921 GtkOrientation orientation,
11924 const char *expand_prop;
11925 const char *expand_set_prop;
11927 GtkWidgetPrivate *priv;
11929 g_return_if_fail (GTK_IS_WIDGET (widget));
11931 priv = widget->priv;
11933 expand = expand != FALSE;
11935 was_both = priv->hexpand && priv->vexpand;
11937 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11939 if (priv->hexpand_set &&
11940 priv->hexpand == expand)
11943 priv->hexpand_set = TRUE;
11944 priv->hexpand = expand;
11946 expand_prop = "hexpand";
11947 expand_set_prop = "hexpand-set";
11951 if (priv->vexpand_set &&
11952 priv->vexpand == expand)
11955 priv->vexpand_set = TRUE;
11956 priv->vexpand = expand;
11958 expand_prop = "vexpand";
11959 expand_set_prop = "vexpand-set";
11962 gtk_widget_queue_compute_expand (widget);
11964 g_object_freeze_notify (G_OBJECT (widget));
11965 g_object_notify (G_OBJECT (widget), expand_prop);
11966 g_object_notify (G_OBJECT (widget), expand_set_prop);
11967 if (was_both != (priv->hexpand && priv->vexpand))
11968 g_object_notify (G_OBJECT (widget), "expand");
11969 g_object_thaw_notify (G_OBJECT (widget));
11973 gtk_widget_set_expand_set (GtkWidget *widget,
11974 GtkOrientation orientation,
11977 GtkWidgetPrivate *priv;
11980 priv = widget->priv;
11982 set = set != FALSE;
11984 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11986 if (set == priv->hexpand_set)
11989 priv->hexpand_set = set;
11990 prop = "hexpand-set";
11994 if (set == priv->vexpand_set)
11997 priv->vexpand_set = set;
11998 prop = "vexpand-set";
12001 gtk_widget_queue_compute_expand (widget);
12003 g_object_notify (G_OBJECT (widget), prop);
12007 * gtk_widget_get_hexpand:
12008 * @widget: the widget
12010 * Gets whether the widget would like any available extra horizontal
12011 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12012 * generally receive the extra space. For example, a list or
12013 * scrollable area or document in your window would often be set to
12016 * Containers should use gtk_widget_compute_expand() rather than
12017 * this function, to see whether a widget, or any of its children,
12018 * has the expand flag set. If any child of a widget wants to
12019 * expand, the parent may ask to expand also.
12021 * This function only looks at the widget's own hexpand flag, rather
12022 * than computing whether the entire widget tree rooted at this widget
12025 * Return value: whether hexpand flag is set
12028 gtk_widget_get_hexpand (GtkWidget *widget)
12030 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12032 return widget->priv->hexpand;
12036 * gtk_widget_set_hexpand:
12037 * @widget: the widget
12038 * @expand: whether to expand
12040 * Sets whether the widget would like any available extra horizontal
12041 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12042 * generally receive the extra space. For example, a list or
12043 * scrollable area or document in your window would often be set to
12046 * Call this function to set the expand flag if you would like your
12047 * widget to become larger horizontally when the window has extra
12050 * By default, widgets automatically expand if any of their children
12051 * want to expand. (To see if a widget will automatically expand given
12052 * its current children and state, call gtk_widget_compute_expand(). A
12053 * container can decide how the expandability of children affects the
12054 * expansion of the container by overriding the compute_expand virtual
12055 * method on #GtkWidget.).
12057 * Setting hexpand explicitly with this function will override the
12058 * automatic expand behavior.
12060 * This function forces the widget to expand or not to expand,
12061 * regardless of children. The override occurs because
12062 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12063 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12064 * value to be used, rather than looking at children and widget state.
12067 gtk_widget_set_hexpand (GtkWidget *widget,
12070 g_return_if_fail (GTK_IS_WIDGET (widget));
12072 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12076 * gtk_widget_get_hexpand_set:
12077 * @widget: the widget
12079 * Gets whether gtk_widget_set_hexpand() has been used to
12080 * explicitly set the expand flag on this widget.
12082 * If hexpand is set, then it overrides any computed
12083 * expand value based on child widgets. If hexpand is not
12084 * set, then the expand value depends on whether any
12085 * children of the widget would like to expand.
12087 * There are few reasons to use this function, but it's here
12088 * for completeness and consistency.
12090 * Return value: whether hexpand has been explicitly set
12093 gtk_widget_get_hexpand_set (GtkWidget *widget)
12095 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12097 return widget->priv->hexpand_set;
12101 * gtk_widget_set_hexpand_set:
12102 * @widget: the widget
12103 * @set: value for hexpand-set property
12105 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12108 * The hexpand-set property will be set automatically when you call
12109 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12110 * reason to use this function would be to unset an explicit expand
12113 * If hexpand is set, then it overrides any computed
12114 * expand value based on child widgets. If hexpand is not
12115 * set, then the expand value depends on whether any
12116 * children of the widget would like to expand.
12118 * There are few reasons to use this function, but it's here
12119 * for completeness and consistency.
12122 gtk_widget_set_hexpand_set (GtkWidget *widget,
12125 g_return_if_fail (GTK_IS_WIDGET (widget));
12127 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12132 * gtk_widget_get_vexpand:
12133 * @widget: the widget
12135 * Gets whether the widget would like any available extra vertical
12138 * See gtk_widget_get_hexpand() for more detail.
12140 * Return value: whether vexpand flag is set
12143 gtk_widget_get_vexpand (GtkWidget *widget)
12145 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12147 return widget->priv->vexpand;
12151 * gtk_widget_set_vexpand:
12152 * @widget: the widget
12153 * @expand: whether to expand
12155 * Sets whether the widget would like any available extra vertical
12158 * See gtk_widget_set_hexpand() for more detail.
12161 gtk_widget_set_vexpand (GtkWidget *widget,
12164 g_return_if_fail (GTK_IS_WIDGET (widget));
12166 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12170 * gtk_widget_get_vexpand_set:
12171 * @widget: the widget
12173 * Gets whether gtk_widget_set_vexpand() has been used to
12174 * explicitly set the expand flag on this widget.
12176 * See gtk_widget_get_hexpand_set() for more detail.
12178 * Return value: whether vexpand has been explicitly set
12181 gtk_widget_get_vexpand_set (GtkWidget *widget)
12183 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12185 return widget->priv->vexpand_set;
12189 * gtk_widget_set_vexpand_set:
12190 * @widget: the widget
12191 * @set: value for vexpand-set property
12193 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12196 * See gtk_widget_set_hexpand_set() for more detail.
12199 gtk_widget_set_vexpand_set (GtkWidget *widget,
12202 g_return_if_fail (GTK_IS_WIDGET (widget));
12204 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12208 * GtkBuildable implementation
12210 static GQuark quark_builder_has_default = 0;
12211 static GQuark quark_builder_has_focus = 0;
12212 static GQuark quark_builder_atk_relations = 0;
12213 static GQuark quark_builder_set_name = 0;
12216 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12218 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12219 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12220 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12221 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12223 iface->set_name = gtk_widget_buildable_set_name;
12224 iface->get_name = gtk_widget_buildable_get_name;
12225 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12226 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12227 iface->parser_finished = gtk_widget_buildable_parser_finished;
12228 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12229 iface->custom_finished = gtk_widget_buildable_custom_finished;
12233 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12236 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12237 g_strdup (name), g_free);
12240 static const gchar *
12241 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12243 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12247 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12248 GtkBuilder *builder,
12249 const gchar *childname)
12251 if (strcmp (childname, "accessible") == 0)
12252 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12258 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12259 GtkBuilder *builder,
12261 const GValue *value)
12263 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12264 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12265 GINT_TO_POINTER (TRUE));
12266 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12267 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12268 GINT_TO_POINTER (TRUE));
12270 g_object_set_property (G_OBJECT (buildable), name, value);
12275 gchar *action_name;
12276 GString *description;
12278 gboolean translatable;
12288 free_action (AtkActionData *data, gpointer user_data)
12290 g_free (data->action_name);
12291 g_string_free (data->description, TRUE);
12292 g_free (data->context);
12293 g_slice_free (AtkActionData, data);
12297 free_relation (AtkRelationData *data, gpointer user_data)
12299 g_free (data->target);
12300 g_free (data->type);
12301 g_slice_free (AtkRelationData, data);
12305 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12306 GtkBuilder *builder)
12308 GSList *atk_relations;
12310 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12311 gtk_widget_grab_default (GTK_WIDGET (buildable));
12312 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12313 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12315 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12316 quark_builder_atk_relations);
12319 AtkObject *accessible;
12320 AtkRelationSet *relation_set;
12323 AtkRelationType relation_type;
12324 AtkObject *target_accessible;
12326 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12327 relation_set = atk_object_ref_relation_set (accessible);
12329 for (l = atk_relations; l; l = l->next)
12331 AtkRelationData *relation = (AtkRelationData*)l->data;
12333 target = gtk_builder_get_object (builder, relation->target);
12336 g_warning ("Target object %s in <relation> does not exist",
12340 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12341 g_assert (target_accessible != NULL);
12343 relation_type = atk_relation_type_for_name (relation->type);
12344 if (relation_type == ATK_RELATION_NULL)
12346 g_warning ("<relation> type %s not found",
12350 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12351 target_accessible);
12353 g_object_unref (relation_set);
12355 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12356 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12365 } AccessibilitySubParserData;
12368 accessibility_start_element (GMarkupParseContext *context,
12369 const gchar *element_name,
12370 const gchar **names,
12371 const gchar **values,
12372 gpointer user_data,
12375 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12377 gint line_number, char_number;
12379 if (strcmp (element_name, "relation") == 0)
12381 gchar *target = NULL;
12382 gchar *type = NULL;
12383 AtkRelationData *relation;
12385 for (i = 0; names[i]; i++)
12387 if (strcmp (names[i], "target") == 0)
12388 target = g_strdup (values[i]);
12389 else if (strcmp (names[i], "type") == 0)
12390 type = g_strdup (values[i]);
12393 g_markup_parse_context_get_position (context,
12396 g_set_error (error,
12398 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12399 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12401 line_number, char_number, names[i], "relation");
12408 if (!target || !type)
12410 g_markup_parse_context_get_position (context,
12413 g_set_error (error,
12415 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12416 "%s:%d:%d <%s> requires attribute \"%s\"",
12418 line_number, char_number, "relation",
12419 type ? "target" : "type");
12425 relation = g_slice_new (AtkRelationData);
12426 relation->target = target;
12427 relation->type = type;
12429 data->relations = g_slist_prepend (data->relations, relation);
12431 else if (strcmp (element_name, "action") == 0)
12433 const gchar *action_name = NULL;
12434 const gchar *description = NULL;
12435 const gchar *msg_context = NULL;
12436 gboolean translatable = FALSE;
12437 AtkActionData *action;
12439 for (i = 0; names[i]; i++)
12441 if (strcmp (names[i], "action_name") == 0)
12442 action_name = values[i];
12443 else if (strcmp (names[i], "description") == 0)
12444 description = values[i];
12445 else if (strcmp (names[i], "translatable") == 0)
12447 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12450 else if (strcmp (names[i], "comments") == 0)
12452 /* do nothing, comments are for translators */
12454 else if (strcmp (names[i], "context") == 0)
12455 msg_context = values[i];
12458 g_markup_parse_context_get_position (context,
12461 g_set_error (error,
12463 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12464 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12466 line_number, char_number, names[i], "action");
12473 g_markup_parse_context_get_position (context,
12476 g_set_error (error,
12478 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12479 "%s:%d:%d <%s> requires attribute \"%s\"",
12481 line_number, char_number, "action",
12486 action = g_slice_new (AtkActionData);
12487 action->action_name = g_strdup (action_name);
12488 action->description = g_string_new (description);
12489 action->context = g_strdup (msg_context);
12490 action->translatable = translatable;
12492 data->actions = g_slist_prepend (data->actions, action);
12494 else if (strcmp (element_name, "accessibility") == 0)
12497 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12501 accessibility_text (GMarkupParseContext *context,
12504 gpointer user_data,
12507 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12509 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12511 AtkActionData *action = data->actions->data;
12513 g_string_append_len (action->description, text, text_len);
12517 static const GMarkupParser accessibility_parser =
12519 accessibility_start_element,
12521 accessibility_text,
12530 } AccelGroupParserData;
12533 accel_group_start_element (GMarkupParseContext *context,
12534 const gchar *element_name,
12535 const gchar **names,
12536 const gchar **values,
12537 gpointer user_data,
12542 guint modifiers = 0;
12543 gchar *signal = NULL;
12544 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12546 for (i = 0; names[i]; i++)
12548 if (strcmp (names[i], "key") == 0)
12549 key = gdk_keyval_from_name (values[i]);
12550 else if (strcmp (names[i], "modifiers") == 0)
12552 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12558 else if (strcmp (names[i], "signal") == 0)
12559 signal = g_strdup (values[i]);
12562 if (key == 0 || signal == NULL)
12564 g_warning ("<accelerator> requires key and signal attributes");
12567 parser_data->key = key;
12568 parser_data->modifiers = modifiers;
12569 parser_data->signal = signal;
12572 static const GMarkupParser accel_group_parser =
12574 accel_group_start_element,
12583 style_start_element (GMarkupParseContext *context,
12584 const gchar *element_name,
12585 const gchar **names,
12586 const gchar **values,
12587 gpointer user_data,
12590 StyleParserData *style_data = (StyleParserData *)user_data;
12593 if (strcmp (element_name, "class") == 0)
12595 if (g_markup_collect_attributes (element_name,
12599 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12600 G_MARKUP_COLLECT_INVALID))
12602 style_data->classes = g_slist_append (style_data->classes, class_name);
12605 else if (strcmp (element_name, "style") == 0)
12608 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12611 static const GMarkupParser style_parser =
12613 style_start_element,
12617 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12618 GtkBuilder *builder,
12620 const gchar *tagname,
12621 GMarkupParser *parser,
12624 g_assert (buildable);
12626 if (strcmp (tagname, "accelerator") == 0)
12628 AccelGroupParserData *parser_data;
12630 parser_data = g_slice_new0 (AccelGroupParserData);
12631 parser_data->object = g_object_ref (buildable);
12632 *parser = accel_group_parser;
12633 *data = parser_data;
12636 if (strcmp (tagname, "accessibility") == 0)
12638 AccessibilitySubParserData *parser_data;
12640 parser_data = g_slice_new0 (AccessibilitySubParserData);
12641 *parser = accessibility_parser;
12642 *data = parser_data;
12645 if (strcmp (tagname, "style") == 0)
12647 StyleParserData *parser_data;
12649 parser_data = g_slice_new0 (StyleParserData);
12650 *parser = style_parser;
12651 *data = parser_data;
12659 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12660 GtkWidget *toplevel,
12661 gpointer user_data)
12663 AccelGroupParserData *accel_data;
12664 GSList *accel_groups;
12665 GtkAccelGroup *accel_group;
12667 g_return_if_fail (GTK_IS_WIDGET (widget));
12668 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12669 g_return_if_fail (user_data != NULL);
12671 accel_data = (AccelGroupParserData*)user_data;
12672 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12673 if (g_slist_length (accel_groups) == 0)
12675 accel_group = gtk_accel_group_new ();
12676 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12680 g_assert (g_slist_length (accel_groups) == 1);
12681 accel_group = g_slist_nth_data (accel_groups, 0);
12684 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12685 accel_data->signal,
12688 accel_data->modifiers,
12689 GTK_ACCEL_VISIBLE);
12691 g_object_unref (accel_data->object);
12692 g_free (accel_data->signal);
12693 g_slice_free (AccelGroupParserData, accel_data);
12697 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12698 GtkBuilder *builder,
12700 const gchar *tagname,
12701 gpointer user_data)
12703 if (strcmp (tagname, "accelerator") == 0)
12705 AccelGroupParserData *accel_data;
12706 GtkWidget *toplevel;
12708 accel_data = (AccelGroupParserData*)user_data;
12709 g_assert (accel_data->object);
12711 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12713 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12715 else if (strcmp (tagname, "accessibility") == 0)
12717 AccessibilitySubParserData *a11y_data;
12719 a11y_data = (AccessibilitySubParserData*)user_data;
12721 if (a11y_data->actions)
12723 AtkObject *accessible;
12728 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12730 if (ATK_IS_ACTION (accessible))
12732 action = ATK_ACTION (accessible);
12733 n_actions = atk_action_get_n_actions (action);
12735 for (l = a11y_data->actions; l; l = l->next)
12737 AtkActionData *action_data = (AtkActionData*)l->data;
12739 for (i = 0; i < n_actions; i++)
12740 if (strcmp (atk_action_get_name (action, i),
12741 action_data->action_name) == 0)
12746 gchar *description;
12748 if (action_data->translatable && action_data->description->len)
12749 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12750 action_data->context,
12751 action_data->description->str);
12753 description = action_data->description->str;
12755 atk_action_set_description (action, i, description);
12760 g_warning ("accessibility action on a widget that does not implement AtkAction");
12762 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12765 if (a11y_data->relations)
12766 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12767 a11y_data->relations);
12769 g_slice_free (AccessibilitySubParserData, a11y_data);
12771 else if (strcmp (tagname, "style") == 0)
12773 StyleParserData *style_data = (StyleParserData *)user_data;
12774 GtkStyleContext *context;
12777 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12779 for (l = style_data->classes; l; l = l->next)
12780 gtk_style_context_add_class (context, (const gchar *)l->data);
12782 gtk_widget_reset_style (GTK_WIDGET (buildable));
12784 g_slist_free_full (style_data->classes, g_free);
12785 g_slice_free (StyleParserData, style_data);
12789 static GtkSizeRequestMode
12790 gtk_widget_real_get_request_mode (GtkWidget *widget)
12792 /* By default widgets dont trade size at all. */
12793 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12797 gtk_widget_real_get_width (GtkWidget *widget,
12798 gint *minimum_size,
12799 gint *natural_size)
12809 gtk_widget_real_get_height (GtkWidget *widget,
12810 gint *minimum_size,
12811 gint *natural_size)
12821 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12823 gint *minimum_height,
12824 gint *natural_height)
12826 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12830 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12832 gint *minimum_width,
12833 gint *natural_width)
12835 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12839 * gtk_widget_get_halign:
12840 * @widget: a #GtkWidget
12842 * Gets the value of the #GtkWidget:halign property.
12844 * Returns: the horizontal alignment of @widget
12847 gtk_widget_get_halign (GtkWidget *widget)
12849 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12850 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12854 * gtk_widget_set_halign:
12855 * @widget: a #GtkWidget
12856 * @align: the horizontal alignment
12858 * Sets the horizontal alignment of @widget.
12859 * See the #GtkWidget:halign property.
12862 gtk_widget_set_halign (GtkWidget *widget,
12865 GtkWidgetAuxInfo *aux_info;
12867 g_return_if_fail (GTK_IS_WIDGET (widget));
12869 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12871 if (aux_info->halign == align)
12874 aux_info->halign = align;
12875 gtk_widget_queue_resize (widget);
12876 g_object_notify (G_OBJECT (widget), "halign");
12880 * gtk_widget_get_valign:
12881 * @widget: a #GtkWidget
12883 * Gets the value of the #GtkWidget:valign property.
12885 * Returns: the vertical alignment of @widget
12888 gtk_widget_get_valign (GtkWidget *widget)
12890 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12891 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12895 * gtk_widget_set_valign:
12896 * @widget: a #GtkWidget
12897 * @align: the vertical alignment
12899 * Sets the vertical alignment of @widget.
12900 * See the #GtkWidget:valign property.
12903 gtk_widget_set_valign (GtkWidget *widget,
12906 GtkWidgetAuxInfo *aux_info;
12908 g_return_if_fail (GTK_IS_WIDGET (widget));
12910 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12912 if (aux_info->valign == align)
12915 aux_info->valign = align;
12916 gtk_widget_queue_resize (widget);
12917 g_object_notify (G_OBJECT (widget), "valign");
12921 * gtk_widget_get_margin_left:
12922 * @widget: a #GtkWidget
12924 * Gets the value of the #GtkWidget:margin-left property.
12926 * Returns: The left margin of @widget
12931 gtk_widget_get_margin_left (GtkWidget *widget)
12933 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12935 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12939 * gtk_widget_set_margin_left:
12940 * @widget: a #GtkWidget
12941 * @margin: the left margin
12943 * Sets the left margin of @widget.
12944 * See the #GtkWidget:margin-left property.
12949 gtk_widget_set_margin_left (GtkWidget *widget,
12952 GtkWidgetAuxInfo *aux_info;
12954 g_return_if_fail (GTK_IS_WIDGET (widget));
12955 g_return_if_fail (margin <= G_MAXINT16);
12957 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12959 if (aux_info->margin.left == margin)
12962 aux_info->margin.left = margin;
12963 gtk_widget_queue_resize (widget);
12964 g_object_notify (G_OBJECT (widget), "margin-left");
12968 * gtk_widget_get_margin_right:
12969 * @widget: a #GtkWidget
12971 * Gets the value of the #GtkWidget:margin-right property.
12973 * Returns: The right margin of @widget
12978 gtk_widget_get_margin_right (GtkWidget *widget)
12980 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12982 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12986 * gtk_widget_set_margin_right:
12987 * @widget: a #GtkWidget
12988 * @margin: the right margin
12990 * Sets the right margin of @widget.
12991 * See the #GtkWidget:margin-right property.
12996 gtk_widget_set_margin_right (GtkWidget *widget,
12999 GtkWidgetAuxInfo *aux_info;
13001 g_return_if_fail (GTK_IS_WIDGET (widget));
13002 g_return_if_fail (margin <= G_MAXINT16);
13004 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13006 if (aux_info->margin.right == margin)
13009 aux_info->margin.right = margin;
13010 gtk_widget_queue_resize (widget);
13011 g_object_notify (G_OBJECT (widget), "margin-right");
13015 * gtk_widget_get_margin_top:
13016 * @widget: a #GtkWidget
13018 * Gets the value of the #GtkWidget:margin-top property.
13020 * Returns: The top margin of @widget
13025 gtk_widget_get_margin_top (GtkWidget *widget)
13027 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13029 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13033 * gtk_widget_set_margin_top:
13034 * @widget: a #GtkWidget
13035 * @margin: the top margin
13037 * Sets the top margin of @widget.
13038 * See the #GtkWidget:margin-top property.
13043 gtk_widget_set_margin_top (GtkWidget *widget,
13046 GtkWidgetAuxInfo *aux_info;
13048 g_return_if_fail (GTK_IS_WIDGET (widget));
13049 g_return_if_fail (margin <= G_MAXINT16);
13051 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13053 if (aux_info->margin.top == margin)
13056 aux_info->margin.top = margin;
13057 gtk_widget_queue_resize (widget);
13058 g_object_notify (G_OBJECT (widget), "margin-top");
13062 * gtk_widget_get_margin_bottom:
13063 * @widget: a #GtkWidget
13065 * Gets the value of the #GtkWidget:margin-bottom property.
13067 * Returns: The bottom margin of @widget
13072 gtk_widget_get_margin_bottom (GtkWidget *widget)
13074 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13076 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13080 * gtk_widget_set_margin_bottom:
13081 * @widget: a #GtkWidget
13082 * @margin: the bottom margin
13084 * Sets the bottom margin of @widget.
13085 * See the #GtkWidget:margin-bottom property.
13090 gtk_widget_set_margin_bottom (GtkWidget *widget,
13093 GtkWidgetAuxInfo *aux_info;
13095 g_return_if_fail (GTK_IS_WIDGET (widget));
13096 g_return_if_fail (margin <= G_MAXINT16);
13098 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13100 if (aux_info->margin.bottom == margin)
13103 aux_info->margin.bottom = margin;
13104 gtk_widget_queue_resize (widget);
13105 g_object_notify (G_OBJECT (widget), "margin-bottom");
13109 * gtk_widget_get_clipboard:
13110 * @widget: a #GtkWidget
13111 * @selection: a #GdkAtom which identifies the clipboard
13112 * to use. %GDK_SELECTION_CLIPBOARD gives the
13113 * default clipboard. Another common value
13114 * is %GDK_SELECTION_PRIMARY, which gives
13115 * the primary X selection.
13117 * Returns the clipboard object for the given selection to
13118 * be used with @widget. @widget must have a #GdkDisplay
13119 * associated with it, so must be attached to a toplevel
13122 * Return value: (transfer none): the appropriate clipboard object. If no
13123 * clipboard already exists, a new one will
13124 * be created. Once a clipboard object has
13125 * been created, it is persistent for all time.
13130 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13132 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13133 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13135 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13140 * gtk_widget_list_mnemonic_labels:
13141 * @widget: a #GtkWidget
13143 * Returns a newly allocated list of the widgets, normally labels, for
13144 * which this widget is the target of a mnemonic (see for example,
13145 * gtk_label_set_mnemonic_widget()).
13147 * The widgets in the list are not individually referenced. If you
13148 * want to iterate through the list and perform actions involving
13149 * callbacks that might destroy the widgets, you
13150 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13151 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13152 * widgets afterwards.
13154 * Return value: (element-type GtkWidget) (transfer container): the list of
13155 * mnemonic labels; free this list
13156 * with g_list_free() when you are done with it.
13161 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13163 GList *list = NULL;
13166 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13168 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13169 list = g_list_prepend (list, l->data);
13175 * gtk_widget_add_mnemonic_label:
13176 * @widget: a #GtkWidget
13177 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13179 * Adds a widget to the list of mnemonic labels for
13180 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13181 * list of mnemonic labels for the widget is cleared when the
13182 * widget is destroyed, so the caller must make sure to update
13183 * its internal state at this point as well, by using a connection
13184 * to the #GtkWidget::destroy signal or a weak notifier.
13189 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13192 GSList *old_list, *new_list;
13194 g_return_if_fail (GTK_IS_WIDGET (widget));
13195 g_return_if_fail (GTK_IS_WIDGET (label));
13197 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13198 new_list = g_slist_prepend (old_list, label);
13200 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13201 new_list, (GDestroyNotify) g_slist_free);
13205 * gtk_widget_remove_mnemonic_label:
13206 * @widget: a #GtkWidget
13207 * @label: a #GtkWidget that was previously set as a mnemnic label for
13208 * @widget with gtk_widget_add_mnemonic_label().
13210 * Removes a widget from the list of mnemonic labels for
13211 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13212 * must have previously been added to the list with
13213 * gtk_widget_add_mnemonic_label().
13218 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13221 GSList *old_list, *new_list;
13223 g_return_if_fail (GTK_IS_WIDGET (widget));
13224 g_return_if_fail (GTK_IS_WIDGET (label));
13226 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13227 new_list = g_slist_remove (old_list, label);
13230 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13231 new_list, (GDestroyNotify) g_slist_free);
13235 * gtk_widget_get_no_show_all:
13236 * @widget: a #GtkWidget
13238 * Returns the current value of the #GtkWidget:no-show-all property,
13239 * which determines whether calls to gtk_widget_show_all()
13240 * will affect this widget.
13242 * Return value: the current value of the "no-show-all" property.
13247 gtk_widget_get_no_show_all (GtkWidget *widget)
13249 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13251 return widget->priv->no_show_all;
13255 * gtk_widget_set_no_show_all:
13256 * @widget: a #GtkWidget
13257 * @no_show_all: the new value for the "no-show-all" property
13259 * Sets the #GtkWidget:no-show-all property, which determines whether
13260 * calls to gtk_widget_show_all() will affect this widget.
13262 * This is mostly for use in constructing widget hierarchies with externally
13263 * controlled visibility, see #GtkUIManager.
13268 gtk_widget_set_no_show_all (GtkWidget *widget,
13269 gboolean no_show_all)
13271 g_return_if_fail (GTK_IS_WIDGET (widget));
13273 no_show_all = (no_show_all != FALSE);
13275 if (widget->priv->no_show_all != no_show_all)
13277 widget->priv->no_show_all = no_show_all;
13279 g_object_notify (G_OBJECT (widget), "no-show-all");
13285 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13286 gboolean has_tooltip,
13289 GtkWidgetPrivate *priv = widget->priv;
13290 gboolean priv_has_tooltip;
13292 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13293 quark_has_tooltip));
13295 if (priv_has_tooltip != has_tooltip || force)
13297 priv_has_tooltip = has_tooltip;
13299 if (priv_has_tooltip)
13301 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13302 gdk_window_set_events (priv->window,
13303 gdk_window_get_events (priv->window) |
13304 GDK_LEAVE_NOTIFY_MASK |
13305 GDK_POINTER_MOTION_MASK |
13306 GDK_POINTER_MOTION_HINT_MASK);
13308 if (gtk_widget_get_has_window (widget))
13309 gtk_widget_add_events (widget,
13310 GDK_LEAVE_NOTIFY_MASK |
13311 GDK_POINTER_MOTION_MASK |
13312 GDK_POINTER_MOTION_HINT_MASK);
13315 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13316 GUINT_TO_POINTER (priv_has_tooltip));
13321 * gtk_widget_set_tooltip_window:
13322 * @widget: a #GtkWidget
13323 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13325 * Replaces the default, usually yellow, window used for displaying
13326 * tooltips with @custom_window. GTK+ will take care of showing and
13327 * hiding @custom_window at the right moment, to behave likewise as
13328 * the default tooltip window. If @custom_window is %NULL, the default
13329 * tooltip window will be used.
13331 * If the custom window should have the default theming it needs to
13332 * have the name "gtk-tooltip", see gtk_widget_set_name().
13337 gtk_widget_set_tooltip_window (GtkWidget *widget,
13338 GtkWindow *custom_window)
13340 gboolean has_tooltip;
13341 gchar *tooltip_markup;
13343 g_return_if_fail (GTK_IS_WIDGET (widget));
13344 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13346 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13349 g_object_ref (custom_window);
13351 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13352 custom_window, g_object_unref);
13354 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13355 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13357 if (has_tooltip && gtk_widget_get_visible (widget))
13358 gtk_widget_queue_tooltip_query (widget);
13362 * gtk_widget_get_tooltip_window:
13363 * @widget: a #GtkWidget
13365 * Returns the #GtkWindow of the current tooltip. This can be the
13366 * GtkWindow created by default, or the custom tooltip window set
13367 * using gtk_widget_set_tooltip_window().
13369 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13374 gtk_widget_get_tooltip_window (GtkWidget *widget)
13376 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13378 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13382 * gtk_widget_trigger_tooltip_query:
13383 * @widget: a #GtkWidget
13385 * Triggers a tooltip query on the display where the toplevel of @widget
13386 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13392 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13394 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13397 static guint tooltip_query_id;
13398 static GSList *tooltip_query_displays;
13401 tooltip_query_idle (gpointer data)
13403 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13404 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13405 g_slist_free (tooltip_query_displays);
13407 tooltip_query_displays = NULL;
13408 tooltip_query_id = 0;
13414 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13416 GdkDisplay *display;
13418 display = gtk_widget_get_display (widget);
13420 if (!g_slist_find (tooltip_query_displays, display))
13421 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13423 if (tooltip_query_id == 0)
13424 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13428 * gtk_widget_set_tooltip_text:
13429 * @widget: a #GtkWidget
13430 * @text: (allow-none): the contents of the tooltip for @widget
13432 * Sets @text as the contents of the tooltip. This function will take
13433 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13434 * handler for the #GtkWidget::query-tooltip signal.
13436 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13441 gtk_widget_set_tooltip_text (GtkWidget *widget,
13444 g_return_if_fail (GTK_IS_WIDGET (widget));
13446 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13450 * gtk_widget_get_tooltip_text:
13451 * @widget: a #GtkWidget
13453 * Gets the contents of the tooltip for @widget.
13455 * Return value: the tooltip text, or %NULL. You should free the
13456 * returned string with g_free() when done.
13461 gtk_widget_get_tooltip_text (GtkWidget *widget)
13463 gchar *text = NULL;
13465 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13467 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13473 * gtk_widget_set_tooltip_markup:
13474 * @widget: a #GtkWidget
13475 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13477 * Sets @markup as the contents of the tooltip, which is marked up with
13478 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13480 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13481 * and of the default handler for the #GtkWidget::query-tooltip signal.
13483 * See also the #GtkWidget:tooltip-markup property and
13484 * gtk_tooltip_set_markup().
13489 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13490 const gchar *markup)
13492 g_return_if_fail (GTK_IS_WIDGET (widget));
13494 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13498 * gtk_widget_get_tooltip_markup:
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_markup (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-markup", &text, NULL);
13521 * gtk_widget_set_has_tooltip:
13522 * @widget: a #GtkWidget
13523 * @has_tooltip: whether or not @widget has a tooltip.
13525 * Sets the has-tooltip property on @widget to @has_tooltip. See
13526 * #GtkWidget:has-tooltip for more information.
13531 gtk_widget_set_has_tooltip (GtkWidget *widget,
13532 gboolean has_tooltip)
13534 g_return_if_fail (GTK_IS_WIDGET (widget));
13536 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13540 * gtk_widget_get_has_tooltip:
13541 * @widget: a #GtkWidget
13543 * Returns the current value of the has-tooltip property. See
13544 * #GtkWidget:has-tooltip for more information.
13546 * Return value: current value of has-tooltip on @widget.
13551 gtk_widget_get_has_tooltip (GtkWidget *widget)
13553 gboolean has_tooltip = FALSE;
13555 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13557 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13559 return has_tooltip;
13563 * gtk_widget_get_allocation:
13564 * @widget: a #GtkWidget
13565 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13567 * Retrieves the widget's allocation.
13569 * Note, when implementing a #GtkContainer: a widget's allocation will
13570 * be its "adjusted" allocation, that is, the widget's parent
13571 * container typically calls gtk_widget_size_allocate() with an
13572 * allocation, and that allocation is then adjusted (to handle margin
13573 * and alignment for example) before assignment to the widget.
13574 * gtk_widget_get_allocation() returns the adjusted allocation that
13575 * was actually assigned to the widget. The adjusted allocation is
13576 * guaranteed to be completely contained within the
13577 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13578 * is guaranteed that its children stay inside the assigned bounds,
13579 * but not that they have exactly the bounds the container assigned.
13580 * There is no way to get the original allocation assigned by
13581 * gtk_widget_size_allocate(), since it isn't stored; if a container
13582 * implementation needs that information it will have to track it itself.
13587 gtk_widget_get_allocation (GtkWidget *widget,
13588 GtkAllocation *allocation)
13590 GtkWidgetPrivate *priv;
13592 g_return_if_fail (GTK_IS_WIDGET (widget));
13593 g_return_if_fail (allocation != NULL);
13595 priv = widget->priv;
13597 *allocation = priv->allocation;
13601 * gtk_widget_set_allocation:
13602 * @widget: a #GtkWidget
13603 * @allocation: a pointer to a #GtkAllocation to copy from
13605 * Sets the widget's allocation. This should not be used
13606 * directly, but from within a widget's size_allocate method.
13608 * The allocation set should be the "adjusted" or actual
13609 * allocation. If you're implementing a #GtkContainer, you want to use
13610 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13611 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13612 * allocation inside gtk_widget_size_allocate() to create an adjusted
13618 gtk_widget_set_allocation (GtkWidget *widget,
13619 const GtkAllocation *allocation)
13621 GtkWidgetPrivate *priv;
13623 g_return_if_fail (GTK_IS_WIDGET (widget));
13624 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13625 g_return_if_fail (allocation != NULL);
13627 priv = widget->priv;
13629 priv->allocation = *allocation;
13633 * gtk_widget_get_allocated_width:
13634 * @widget: the widget to query
13636 * Returns the width that has currently been allocated to @widget.
13637 * This function is intended to be used when implementing handlers
13638 * for the #GtkWidget::draw function.
13640 * Returns: the width of the @widget
13643 gtk_widget_get_allocated_width (GtkWidget *widget)
13645 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13647 return widget->priv->allocation.width;
13651 * gtk_widget_get_allocated_height:
13652 * @widget: the widget to query
13654 * Returns the height that has currently been allocated to @widget.
13655 * This function is intended to be used when implementing handlers
13656 * for the #GtkWidget::draw function.
13658 * Returns: the height of the @widget
13661 gtk_widget_get_allocated_height (GtkWidget *widget)
13663 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13665 return widget->priv->allocation.height;
13669 * gtk_widget_get_requisition:
13670 * @widget: a #GtkWidget
13671 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13673 * Retrieves the widget's requisition.
13675 * This function should only be used by widget implementations in
13676 * order to figure whether the widget's requisition has actually
13677 * changed after some internal state change (so that they can call
13678 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13680 * Normally, gtk_widget_size_request() should be used.
13684 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13685 * removed, If you need to cache sizes across requests and allocations,
13686 * add an explicit cache to the widget in question instead.
13689 gtk_widget_get_requisition (GtkWidget *widget,
13690 GtkRequisition *requisition)
13692 g_return_if_fail (GTK_IS_WIDGET (widget));
13693 g_return_if_fail (requisition != NULL);
13695 gtk_widget_get_preferred_size (widget, requisition, NULL);
13699 * gtk_widget_set_window:
13700 * @widget: a #GtkWidget
13701 * @window: (transfer full): a #GdkWindow
13703 * Sets a widget's window. This function should only be used in a
13704 * widget's #GtkWidget::realize implementation. The %window passed is
13705 * usually either new window created with gdk_window_new(), or the
13706 * window of its parent widget as returned by
13707 * gtk_widget_get_parent_window().
13709 * Widgets must indicate whether they will create their own #GdkWindow
13710 * by calling gtk_widget_set_has_window(). This is usually done in the
13711 * widget's init() function.
13713 * <note><para>This function does not add any reference to @window.</para></note>
13718 gtk_widget_set_window (GtkWidget *widget,
13721 GtkWidgetPrivate *priv;
13723 g_return_if_fail (GTK_IS_WIDGET (widget));
13724 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13726 priv = widget->priv;
13728 if (priv->window != window)
13730 priv->window = window;
13732 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
13733 gdk_window_set_opacity (window,
13734 priv->norender ? 0 : priv->alpha / 255.0);
13736 g_object_notify (G_OBJECT (widget), "window");
13741 * gtk_widget_register_window:
13742 * @widget: a #GtkWidget
13743 * @window: a #GdkWindow
13745 * Registers a #GdkWindow with the widget and sets it up so that
13746 * the widget recieves events for it. Call gtk_widget_unregister_window()
13747 * when destroying the window.
13749 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13750 * this up. This is now deprecated and you should use gtk_widget_register_window()
13751 * instead. Old code will keep working as is, although some new features like
13752 * transparency might not work perfectly.
13757 gtk_widget_register_window (GtkWidget *widget,
13760 GtkWidgetPrivate *priv;
13761 gpointer user_data;
13763 g_return_if_fail (GTK_IS_WIDGET (widget));
13764 g_return_if_fail (GDK_IS_WINDOW (window));
13766 gdk_window_get_user_data (window, &user_data);
13767 g_assert (user_data == NULL);
13769 priv = widget->priv;
13771 gdk_window_set_user_data (window, widget);
13772 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13774 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
13775 gdk_window_set_opacity (window,
13776 priv->norender_children ? 0.0 : 1.0);
13780 * gtk_widget_unregister_window:
13781 * @widget: a #GtkWidget
13782 * @window: a #GdkWindow
13784 * Unregisters a #GdkWindow from the widget that was previously set up with
13785 * gtk_widget_register_window(). You need to call this when the window is
13786 * no longer used by the widget, such as when you destroy it.
13791 gtk_widget_unregister_window (GtkWidget *widget,
13794 GtkWidgetPrivate *priv;
13795 gpointer user_data;
13797 g_return_if_fail (GTK_IS_WIDGET (widget));
13798 g_return_if_fail (GDK_IS_WINDOW (window));
13800 priv = widget->priv;
13802 gdk_window_get_user_data (window, &user_data);
13803 g_assert (user_data == widget);
13804 gdk_window_set_user_data (window, NULL);
13805 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13809 * gtk_widget_get_window:
13810 * @widget: a #GtkWidget
13812 * Returns the widget's window if it is realized, %NULL otherwise
13814 * Return value: (transfer none): @widget's window.
13819 gtk_widget_get_window (GtkWidget *widget)
13821 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13823 return widget->priv->window;
13827 * gtk_widget_get_support_multidevice:
13828 * @widget: a #GtkWidget
13830 * Returns %TRUE if @widget is multiple pointer aware. See
13831 * gtk_widget_set_support_multidevice() for more information.
13833 * Returns: %TRUE if @widget is multidevice aware.
13836 gtk_widget_get_support_multidevice (GtkWidget *widget)
13838 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13840 return widget->priv->multidevice;
13844 * gtk_widget_set_support_multidevice:
13845 * @widget: a #GtkWidget
13846 * @support_multidevice: %TRUE to support input from multiple devices.
13848 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13849 * @widget will start receiving multiple, per device enter/leave events. Note
13850 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13851 * gdk_window_set_support_multidevice() will have to be called manually on them.
13856 gtk_widget_set_support_multidevice (GtkWidget *widget,
13857 gboolean support_multidevice)
13859 GtkWidgetPrivate *priv;
13861 g_return_if_fail (GTK_IS_WIDGET (widget));
13863 priv = widget->priv;
13864 priv->multidevice = (support_multidevice == TRUE);
13866 if (gtk_widget_get_realized (widget))
13867 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13870 /* There are multiple alpha related sources. First of all the user can specify alpha
13871 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
13872 * are multiplied together to form the total alpha. Secondly, the user can specify
13873 * an opacity group for a widget, which means we must essentially handle it as having alpha.
13875 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
13876 * group we directly set the opacity of widget->window. This will cause gdk to properly
13877 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
13879 * However, if the widget is not windowed, or the user specified an opacity group for the
13880 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
13881 * implementation of this would break for windowed widgets or descendant widgets with
13882 * windows, as these would not be handled by the ::draw signal. To handle this we set
13883 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
13884 * to make the draw signal propagate to *all* child widgets/windows.
13886 * Note: We don't make all child windows fully transparent, we stop at the first one
13887 * in each branch when propagating down the hierarchy.
13891 /* This is called when priv->alpha or priv->opacity_group group changes, and should
13892 * update priv->norender and GdkWindow opacity for this widget and any children that
13893 * needs changing. It is also called whenver the parent changes, the parents
13894 * norender_children state changes, or the has_window state of the widget changes.
13897 gtk_widget_propagate_alpha (GtkWidget *widget)
13899 GtkWidgetPrivate *priv = widget->priv;
13901 gboolean norender, norender_children;
13904 parent = priv->parent;
13907 /* If this widget has an opacity group, never render it */
13908 priv->opacity_group ||
13909 /* If the parent has norender_children, propagate that here */
13910 (parent != NULL && parent->priv->norender_children);
13912 /* Windowed widget children should norender if: */
13913 norender_children =
13914 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
13915 !gtk_widget_get_has_window (widget) &&
13916 ( /* norender is set, or */
13918 /* widget has an alpha */
13922 if (gtk_widget_get_has_window (widget))
13924 if (priv->window != NULL && !gdk_window_has_native (priv->window))
13925 gdk_window_set_opacity (priv->window,
13926 norender ? 0 : priv->alpha / 255.0);
13928 else /* !has_window */
13930 for (l = priv->registered_windows; l != NULL; l = l->next)
13932 GdkWindow *w = l->data;
13933 if (!gdk_window_has_native (w))
13934 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
13938 priv->norender = norender;
13939 if (priv->norender_children != norender_children)
13941 priv->norender_children = norender_children;
13943 if (GTK_IS_CONTAINER (widget))
13944 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
13947 if (gtk_widget_get_realized (widget))
13948 gtk_widget_queue_draw (widget);
13952 gtk_widget_update_alpha (GtkWidget *widget)
13954 GtkWidgetPrivate *priv;
13958 priv = widget->priv;
13960 alpha = priv->user_alpha;
13965 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
13966 GTK_CSS_PROPERTY_OPACITY),
13968 opacity = CLAMP (opacity, 0.0, 1.0);
13969 alpha = round (priv->user_alpha * opacity);
13972 if (alpha == priv->alpha)
13975 priv->alpha = alpha;
13977 gtk_widget_propagate_alpha (widget);
13982 gtk_widget_set_has_opacity_group (GtkWidget *widget,
13983 gboolean has_opacity_group)
13985 GtkWidgetPrivate *priv;
13987 g_return_if_fail (GTK_IS_WIDGET (widget));
13989 priv = widget->priv;
13991 has_opacity_group = !!has_opacity_group;
13993 if (priv->opacity_group == has_opacity_group)
13996 priv->opacity_group = has_opacity_group;
13998 gtk_widget_propagate_alpha (widget);
14002 * gtk_widget_set_opacity:
14003 * @widget: a #GtkWidget
14004 * @opacity: desired opacity, between 0 and 1
14006 * Request the @widget to be rendered partially transparent,
14007 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14008 * are clamped to the [0,1] range.).
14009 * This works on both toplevel widget, and child widgets, although there
14010 * are some limitations:
14012 * For toplevel widgets this depends on the capabilities of the windowing
14013 * system. On X11 this has any effect only on X screens with a compositing manager
14014 * running. See gtk_widget_is_composited(). On Windows it should work
14015 * always, although setting a window's opacity after the window has been
14016 * shown causes it to flicker once on Windows.
14018 * For child widgets it doesn't work if any affected widget has a native window, or
14019 * disables double buffering.
14024 gtk_widget_set_opacity (GtkWidget *widget,
14027 GtkWidgetPrivate *priv;
14030 g_return_if_fail (GTK_IS_WIDGET (widget));
14032 priv = widget->priv;
14034 opacity = CLAMP (opacity, 0.0, 1.0);
14036 alpha = round (opacity * 255);
14038 /* As a kind of hack for internal use we treat an alpha very
14039 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14040 we want the opacity group behaviour wrt draw handling, but
14041 not actually an alpha value. See bug #687842 for discussions. */
14042 gtk_widget_set_has_opacity_group (widget,
14043 alpha == 255 && opacity != 1.0);
14045 if (alpha == priv->user_alpha)
14048 priv->user_alpha = alpha;
14050 gtk_widget_update_alpha (widget);
14055 * gtk_widget_get_opacity:
14056 * @widget: a #GtkWidget
14058 * Fetches the requested opacity for this widget. See
14059 * gtk_widget_set_opacity().
14061 * Return value: the requested opacity for this widget.
14066 gtk_widget_get_opacity (GtkWidget *widget)
14068 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14070 return widget->priv->alpha / 255.0;
14074 _gtk_widget_set_has_focus (GtkWidget *widget,
14075 gboolean has_focus)
14077 widget->priv->has_focus = has_focus;
14080 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14082 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14086 * gtk_widget_send_focus_change:
14087 * @widget: a #GtkWidget
14088 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14090 * Sends the focus change @event to @widget
14092 * This function is not meant to be used by applications. The only time it
14093 * should be used is when it is necessary for a #GtkWidget to assign focus
14094 * to a widget that is semantically owned by the first widget even though
14095 * it's not a direct child - for instance, a search entry in a floating
14096 * window similar to the quick search in #GtkTreeView.
14098 * An example of its usage is:
14101 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14103 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14104 * fevent->focus_change.in = TRUE;
14105 * fevent->focus_change.window = gtk_widget_get_window (widget);
14106 * if (fevent->focus_change.window != NULL)
14107 * g_object_ref (fevent->focus_change.window);
14109 * gtk_widget_send_focus_change (widget, fevent);
14111 * gdk_event_free (event);
14114 * Return value: the return value from the event signal emission: %TRUE
14115 * if the event was handled, and %FALSE otherwise
14120 gtk_widget_send_focus_change (GtkWidget *widget,
14125 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14126 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14128 g_object_ref (widget);
14130 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14132 res = gtk_widget_event (widget, event);
14134 g_object_notify (G_OBJECT (widget), "has-focus");
14136 g_object_unref (widget);
14142 * gtk_widget_in_destruction:
14143 * @widget: a #GtkWidget
14145 * Returns whether the widget is currently being destroyed.
14146 * This information can sometimes be used to avoid doing
14147 * unnecessary work.
14149 * Returns: %TRUE if @widget is being destroyed
14152 gtk_widget_in_destruction (GtkWidget *widget)
14154 return widget->priv->in_destruction;
14158 _gtk_widget_get_in_reparent (GtkWidget *widget)
14160 return widget->priv->in_reparent;
14164 _gtk_widget_set_in_reparent (GtkWidget *widget,
14165 gboolean in_reparent)
14167 widget->priv->in_reparent = in_reparent;
14171 _gtk_widget_get_anchored (GtkWidget *widget)
14173 return widget->priv->anchored;
14177 _gtk_widget_set_anchored (GtkWidget *widget,
14180 widget->priv->anchored = anchored;
14184 _gtk_widget_get_shadowed (GtkWidget *widget)
14186 return widget->priv->shadowed;
14190 _gtk_widget_set_shadowed (GtkWidget *widget,
14193 widget->priv->shadowed = shadowed;
14197 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14199 return widget->priv->alloc_needed;
14203 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14204 gboolean alloc_needed)
14206 widget->priv->alloc_needed = alloc_needed;
14210 _gtk_widget_add_sizegroup (GtkWidget *widget,
14215 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14216 groups = g_slist_prepend (groups, group);
14217 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14219 widget->priv->have_size_groups = TRUE;
14223 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14228 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14229 groups = g_slist_remove (groups, group);
14230 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14232 widget->priv->have_size_groups = groups != NULL;
14236 _gtk_widget_get_sizegroups (GtkWidget *widget)
14238 if (widget->priv->have_size_groups)
14239 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14245 _gtk_widget_add_attached_window (GtkWidget *widget,
14248 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14252 _gtk_widget_remove_attached_window (GtkWidget *widget,
14255 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14259 * gtk_widget_path_append_for_widget:
14260 * @path: a widget path
14261 * @widget: the widget to append to the widget path
14263 * Appends the data from @widget to the widget hierarchy represented
14264 * by @path. This function is a shortcut for adding information from
14265 * @widget to the given @path. This includes setting the name or
14266 * adding the style classes from @widget.
14268 * Returns: the position where the data was inserted
14273 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14278 g_return_val_if_fail (path != NULL, 0);
14279 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14281 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14283 if (widget->priv->name)
14284 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14286 if (widget->priv->context)
14288 GList *classes, *l;
14290 /* Also add any persistent classes in
14291 * the style context the widget path
14293 classes = gtk_style_context_list_classes (widget->priv->context);
14295 for (l = classes; l; l = l->next)
14296 gtk_widget_path_iter_add_class (path, pos, l->data);
14298 g_list_free (classes);
14305 _gtk_widget_create_path (GtkWidget *widget)
14309 parent = widget->priv->parent;
14312 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14315 /* Widget is either toplevel or unparented, treat both
14316 * as toplevels style wise, since there are situations
14317 * where style properties might be retrieved on that
14320 GtkWidget *attach_widget = NULL;
14321 GtkWidgetPath *result;
14323 if (GTK_IS_WINDOW (widget))
14324 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14326 if (attach_widget != NULL)
14327 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14329 result = gtk_widget_path_new ();
14331 gtk_widget_path_append_for_widget (result, widget);
14338 * gtk_widget_get_path:
14339 * @widget: a #GtkWidget
14341 * Returns the #GtkWidgetPath representing @widget, if the widget
14342 * is not connected to a toplevel widget, a partial path will be
14345 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14348 gtk_widget_get_path (GtkWidget *widget)
14350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14352 if (!widget->priv->path)
14353 widget->priv->path = _gtk_widget_create_path (widget);
14355 return widget->priv->path;
14359 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14361 if (widget->priv->path)
14363 gtk_widget_path_free (widget->priv->path);
14364 widget->priv->path = NULL;
14367 if (gtk_widget_get_realized (widget))
14368 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14371 /* Compress all style updates so it
14372 * is only emitted once pre-realize.
14374 widget->priv->style_update_pending = TRUE;
14379 * gtk_widget_get_style_context:
14380 * @widget: a #GtkWidget
14382 * Returns the style context associated to @widget.
14384 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14385 * must not be freed.
14388 gtk_widget_get_style_context (GtkWidget *widget)
14390 GtkWidgetPrivate *priv;
14392 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14394 priv = widget->priv;
14396 if (G_UNLIKELY (priv->context == NULL))
14400 priv->context = gtk_style_context_new ();
14402 gtk_style_context_set_state (priv->context, priv->state_flags);
14404 screen = gtk_widget_get_screen (widget);
14406 gtk_style_context_set_screen (priv->context, screen);
14409 gtk_style_context_set_parent (priv->context,
14410 gtk_widget_get_style_context (priv->parent));
14412 _gtk_style_context_set_widget (priv->context, widget);
14415 return widget->priv->context;
14419 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14420 GtkCssChange change)
14422 GtkWidgetPrivate *priv;
14424 priv = widget->priv;
14426 if (priv->context == NULL)
14429 _gtk_style_context_queue_invalidate (priv->context, change);
14433 * gtk_widget_get_modifier_mask:
14434 * @widget: a #GtkWidget
14435 * @intent: the use case for the modifier mask
14437 * Returns the modifier mask the @widget's windowing system backend
14438 * uses for a particular purpose.
14440 * See gdk_keymap_get_modifier_mask().
14442 * Returns: the modifier mask used for @intent.
14447 gtk_widget_get_modifier_mask (GtkWidget *widget,
14448 GdkModifierIntent intent)
14450 GdkDisplay *display;
14452 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14454 display = gtk_widget_get_display (widget);
14456 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14461 _gtk_widget_get_style (GtkWidget *widget)
14463 return widget->priv->style;
14467 _gtk_widget_set_style (GtkWidget *widget,
14470 widget->priv->style = style;
14474 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14477 GActionMuxer *parent_muxer;
14479 if (widget->priv->muxer == NULL)
14482 if (GTK_IS_MENU (widget))
14483 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14485 parent = gtk_widget_get_parent (widget);
14487 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14489 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14493 _gtk_widget_get_action_muxer (GtkWidget *widget)
14495 if (widget->priv->muxer == NULL)
14497 widget->priv->muxer = g_action_muxer_new ();
14498 _gtk_widget_update_parent_muxer (widget);
14501 return widget->priv->muxer;
14505 * gtk_widget_insert_action_group:
14506 * @widget: a #GtkWidget
14507 * @name: the prefix for actions in @group
14508 * @group: a #GActionGroup
14510 * Inserts @group into @widget. Children of @widget that implement
14511 * #GtkActionable can then be associated with actions in @group by
14512 * setting their 'action-name' to
14513 * @prefix.<replaceable>action-name</replaceable>.
14518 gtk_widget_insert_action_group (GtkWidget *widget,
14520 GActionGroup *group)
14522 GActionMuxer *muxer;
14524 g_return_if_fail (GTK_IS_WIDGET (widget));
14525 g_return_if_fail (name != NULL);
14527 muxer = _gtk_widget_get_action_muxer (widget);
14530 g_action_muxer_insert (muxer, name, group);
14532 g_action_muxer_remove (muxer, name);