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 /* Animations and other things to update on clock ticks */
413 GList *tick_callbacks;
415 #ifdef G_ENABLE_DEBUG
416 /* Number of gtk_widget_push_verify_invariants () */
417 guint verifying_invariants_count;
418 #endif /* G_ENABLE_DEBUG */
421 struct _GtkWidgetClassPrivate
423 GType accessible_type;
424 AtkRole accessible_role;
453 BUTTON_RELEASE_EVENT,
467 PROPERTY_NOTIFY_EVENT,
468 SELECTION_CLEAR_EVENT,
469 SELECTION_REQUEST_EVENT,
470 SELECTION_NOTIFY_EVENT,
475 VISIBILITY_NOTIFY_EVENT,
489 ACCEL_CLOSURES_CHANGED,
514 PROP_RECEIVES_DEFAULT,
515 PROP_COMPOSITE_CHILD,
524 PROP_DOUBLE_BUFFERED,
539 typedef struct _GtkStateData GtkStateData;
544 guint flags_to_unset;
547 /* --- prototypes --- */
548 static void gtk_widget_base_class_init (gpointer g_class);
549 static void gtk_widget_class_init (GtkWidgetClass *klass);
550 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
551 static void gtk_widget_init (GtkWidget *widget);
552 static void gtk_widget_set_property (GObject *object,
556 static void gtk_widget_get_property (GObject *object,
560 static void gtk_widget_constructed (GObject *object);
561 static void gtk_widget_dispose (GObject *object);
562 static void gtk_widget_real_destroy (GtkWidget *object);
563 static void gtk_widget_finalize (GObject *object);
564 static void gtk_widget_real_show (GtkWidget *widget);
565 static void gtk_widget_real_hide (GtkWidget *widget);
566 static void gtk_widget_real_map (GtkWidget *widget);
567 static void gtk_widget_real_unmap (GtkWidget *widget);
568 static void gtk_widget_real_realize (GtkWidget *widget);
569 static void gtk_widget_real_unrealize (GtkWidget *widget);
570 static void gtk_widget_real_size_allocate (GtkWidget *widget,
571 GtkAllocation *allocation);
572 static void gtk_widget_real_style_set (GtkWidget *widget,
573 GtkStyle *previous_style);
574 static void gtk_widget_real_direction_changed(GtkWidget *widget,
575 GtkTextDirection previous_direction);
577 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
578 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
581 gboolean keyboard_tip,
582 GtkTooltip *tooltip);
583 static void gtk_widget_real_style_updated (GtkWidget *widget);
584 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
585 GtkWidgetHelpType help_type);
587 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
589 GParamSpec **pspecs);
590 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
592 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
594 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
595 GdkEventFocus *event);
596 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
597 GdkEventFocus *event);
598 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
599 GdkEventTouch *event);
600 static gboolean gtk_widget_real_focus (GtkWidget *widget,
601 GtkDirectionType direction);
602 static void gtk_widget_real_move_focus (GtkWidget *widget,
603 GtkDirectionType direction);
604 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
605 GtkDirectionType direction);
606 #ifdef G_ENABLE_DEBUG
607 static void gtk_widget_verify_invariants (GtkWidget *widget);
608 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
609 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
611 #define gtk_widget_verify_invariants(widget)
612 #define gtk_widget_push_verify_invariants(widget)
613 #define gtk_widget_pop_verify_invariants(widget)
615 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
616 static void gtk_widget_update_pango_context (GtkWidget *widget);
617 static void gtk_widget_propagate_state (GtkWidget *widget,
619 static void gtk_widget_update_alpha (GtkWidget *widget);
621 static gint gtk_widget_event_internal (GtkWidget *widget,
623 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
624 gboolean group_cycling);
625 static void gtk_widget_real_get_width (GtkWidget *widget,
628 static void gtk_widget_real_get_height (GtkWidget *widget,
631 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
633 gint *minimum_height,
634 gint *natural_height);
635 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
638 gint *natural_width);
639 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
640 GtkStateFlags old_state);
641 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
642 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
644 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
645 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
646 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
647 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
648 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
649 cairo_region_t *region);
650 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
651 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
654 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
655 gboolean has_tooltip,
657 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
658 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
660 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
661 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
663 const gchar *childname);
664 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
667 const GValue *value);
668 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
671 const gchar *tagname,
672 GMarkupParser *parser,
674 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
677 const gchar *tagname,
679 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
680 GtkBuilder *builder);
682 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
683 static void gtk_widget_real_get_width (GtkWidget *widget,
686 static void gtk_widget_real_get_height (GtkWidget *widget,
690 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
693 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
694 GtkOrientation orientation,
697 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
698 GtkOrientation orientation,
702 gint *allocated_size);
704 static void gtk_widget_set_usize_internal (GtkWidget *widget,
707 GtkQueueResizeFlags flags);
709 static void gtk_widget_add_events_internal (GtkWidget *widget,
712 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
717 static void gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
720 static gboolean event_window_is_still_viewable (GdkEvent *event);
721 static void gtk_cairo_set_event (cairo_t *cr,
722 GdkEventExpose *event);
723 static void gtk_widget_propagate_alpha (GtkWidget *widget);
725 /* --- variables --- */
726 static gpointer gtk_widget_parent_class = NULL;
727 static guint widget_signals[LAST_SIGNAL] = { 0 };
728 static guint composite_child_stack = 0;
729 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
730 static GParamSpecPool *style_property_spec_pool = NULL;
732 static GQuark quark_property_parser = 0;
733 static GQuark quark_aux_info = 0;
734 static GQuark quark_accel_path = 0;
735 static GQuark quark_accel_closures = 0;
736 static GQuark quark_event_mask = 0;
737 static GQuark quark_device_event_mask = 0;
738 static GQuark quark_parent_window = 0;
739 static GQuark quark_pointer_window = 0;
740 static GQuark quark_shape_info = 0;
741 static GQuark quark_input_shape_info = 0;
742 static GQuark quark_pango_context = 0;
743 static GQuark quark_accessible_object = 0;
744 static GQuark quark_mnemonic_labels = 0;
745 static GQuark quark_tooltip_markup = 0;
746 static GQuark quark_has_tooltip = 0;
747 static GQuark quark_tooltip_window = 0;
748 static GQuark quark_visual = 0;
749 static GQuark quark_modifier_style = 0;
750 static GQuark quark_enabled_devices = 0;
751 static GQuark quark_size_groups = 0;
752 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
753 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
755 /* --- functions --- */
757 gtk_widget_get_type (void)
759 static GType widget_type = 0;
761 if (G_UNLIKELY (widget_type == 0))
763 const GTypeInfo widget_info =
765 sizeof (GtkWidgetClass),
766 gtk_widget_base_class_init,
767 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
768 (GClassInitFunc) gtk_widget_class_init,
769 NULL, /* class_finalize */
770 NULL, /* class_init */
773 (GInstanceInitFunc) gtk_widget_init,
774 NULL, /* value_table */
777 const GInterfaceInfo accessibility_info =
779 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
780 (GInterfaceFinalizeFunc) NULL,
781 NULL /* interface data */
784 const GInterfaceInfo buildable_info =
786 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
787 (GInterfaceFinalizeFunc) NULL,
788 NULL /* interface data */
791 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
792 &widget_info, G_TYPE_FLAG_ABSTRACT);
794 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
796 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
797 &accessibility_info) ;
798 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
806 gtk_widget_base_class_init (gpointer g_class)
808 GtkWidgetClass *klass = g_class;
810 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
814 child_property_notify_dispatcher (GObject *object,
818 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
821 /* We guard against the draw signal callbacks modifying the state of the
822 * cairo context by surounding it with save/restore.
823 * Maybe we should also cairo_new_path() just to be sure?
826 gtk_widget_draw_marshaller (GClosure *closure,
827 GValue *return_value,
828 guint n_param_values,
829 const GValue *param_values,
830 gpointer invocation_hint,
831 gpointer marshal_data)
833 GtkWidget *widget = g_value_get_object (¶m_values[0]);
834 GdkEventExpose *tmp_event;
836 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
839 tmp_event = _gtk_cairo_get_event (cr);
842 widget->priv->opacity_group ||
843 (widget->priv->alpha != 255 &&
844 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
848 cairo_push_group (cr);
849 gtk_cairo_set_event (cr, NULL);
852 _gtk_marshal_BOOLEAN__BOXED (closure,
862 cairo_pop_group_to_source (cr);
863 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
864 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
867 gtk_cairo_set_event (cr, tmp_event);
872 gtk_widget_draw_marshallerv (GClosure *closure,
873 GValue *return_value,
876 gpointer marshal_data,
880 GtkWidget *widget = GTK_WIDGET (instance);
881 GdkEventExpose *tmp_event;
886 G_VA_COPY (args_copy, args);
887 cr = va_arg (args_copy, gpointer);
890 tmp_event = _gtk_cairo_get_event (cr);
893 widget->priv->opacity_group ||
894 (widget->priv->alpha != 255 &&
895 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
899 cairo_push_group (cr);
900 gtk_cairo_set_event (cr, NULL);
903 _gtk_marshal_BOOLEAN__BOXEDv (closure,
914 cairo_pop_group_to_source (cr);
915 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
916 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
919 gtk_cairo_set_event (cr, tmp_event);
926 gtk_widget_class_init (GtkWidgetClass *klass)
928 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
929 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
930 GtkBindingSet *binding_set;
932 gtk_widget_parent_class = g_type_class_peek_parent (klass);
934 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
935 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
936 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
937 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
938 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
939 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
940 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
941 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
942 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
943 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
944 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
945 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
946 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
947 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
948 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
949 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
950 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
951 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
952 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
953 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
955 style_property_spec_pool = g_param_spec_pool_new (FALSE);
956 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
957 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
958 cpn_context.dispatcher = child_property_notify_dispatcher;
959 _gtk_widget_child_property_notify_context = &cpn_context;
961 gobject_class->constructed = gtk_widget_constructed;
962 gobject_class->dispose = gtk_widget_dispose;
963 gobject_class->finalize = gtk_widget_finalize;
964 gobject_class->set_property = gtk_widget_set_property;
965 gobject_class->get_property = gtk_widget_get_property;
967 klass->destroy = gtk_widget_real_destroy;
969 klass->activate_signal = 0;
970 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
971 klass->show = gtk_widget_real_show;
972 klass->show_all = gtk_widget_show;
973 klass->hide = gtk_widget_real_hide;
974 klass->map = gtk_widget_real_map;
975 klass->unmap = gtk_widget_real_unmap;
976 klass->realize = gtk_widget_real_realize;
977 klass->unrealize = gtk_widget_real_unrealize;
978 klass->size_allocate = gtk_widget_real_size_allocate;
979 klass->get_request_mode = gtk_widget_real_get_request_mode;
980 klass->get_preferred_width = gtk_widget_real_get_width;
981 klass->get_preferred_height = gtk_widget_real_get_height;
982 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
983 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
984 klass->state_changed = NULL;
985 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
986 klass->parent_set = NULL;
987 klass->hierarchy_changed = NULL;
988 klass->style_set = gtk_widget_real_style_set;
989 klass->direction_changed = gtk_widget_real_direction_changed;
990 klass->grab_notify = NULL;
991 klass->child_notify = NULL;
993 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
994 klass->grab_focus = gtk_widget_real_grab_focus;
995 klass->focus = gtk_widget_real_focus;
996 klass->move_focus = gtk_widget_real_move_focus;
997 klass->keynav_failed = gtk_widget_real_keynav_failed;
999 klass->button_press_event = NULL;
1000 klass->button_release_event = NULL;
1001 klass->motion_notify_event = NULL;
1002 klass->touch_event = gtk_widget_real_touch_event;
1003 klass->delete_event = NULL;
1004 klass->destroy_event = NULL;
1005 klass->key_press_event = gtk_widget_real_key_press_event;
1006 klass->key_release_event = gtk_widget_real_key_release_event;
1007 klass->enter_notify_event = NULL;
1008 klass->leave_notify_event = NULL;
1009 klass->configure_event = NULL;
1010 klass->focus_in_event = gtk_widget_real_focus_in_event;
1011 klass->focus_out_event = gtk_widget_real_focus_out_event;
1012 klass->map_event = NULL;
1013 klass->unmap_event = NULL;
1014 klass->window_state_event = NULL;
1015 klass->property_notify_event = _gtk_selection_property_notify;
1016 klass->selection_clear_event = _gtk_selection_clear;
1017 klass->selection_request_event = _gtk_selection_request;
1018 klass->selection_notify_event = _gtk_selection_notify;
1019 klass->selection_received = NULL;
1020 klass->proximity_in_event = NULL;
1021 klass->proximity_out_event = NULL;
1022 klass->drag_begin = NULL;
1023 klass->drag_end = NULL;
1024 klass->drag_data_delete = NULL;
1025 klass->drag_leave = NULL;
1026 klass->drag_motion = NULL;
1027 klass->drag_drop = NULL;
1028 klass->drag_data_received = NULL;
1029 klass->screen_changed = NULL;
1030 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1031 klass->grab_broken_event = NULL;
1032 klass->query_tooltip = gtk_widget_real_query_tooltip;
1033 klass->style_updated = gtk_widget_real_style_updated;
1035 klass->show_help = gtk_widget_real_show_help;
1037 /* Accessibility support */
1038 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1039 klass->priv->accessible_role = ATK_ROLE_INVALID;
1040 klass->get_accessible = gtk_widget_real_get_accessible;
1042 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1043 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1045 g_object_class_install_property (gobject_class,
1047 g_param_spec_string ("name",
1049 P_("The name of the widget"),
1051 GTK_PARAM_READWRITE));
1052 g_object_class_install_property (gobject_class,
1054 g_param_spec_object ("parent",
1055 P_("Parent widget"),
1056 P_("The parent widget of this widget. Must be a Container widget"),
1058 GTK_PARAM_READWRITE));
1060 g_object_class_install_property (gobject_class,
1062 g_param_spec_int ("width-request",
1063 P_("Width request"),
1064 P_("Override for width request of the widget, or -1 if natural request should be used"),
1068 GTK_PARAM_READWRITE));
1069 g_object_class_install_property (gobject_class,
1070 PROP_HEIGHT_REQUEST,
1071 g_param_spec_int ("height-request",
1072 P_("Height request"),
1073 P_("Override for height request of the widget, or -1 if natural request should be used"),
1077 GTK_PARAM_READWRITE));
1078 g_object_class_install_property (gobject_class,
1080 g_param_spec_boolean ("visible",
1082 P_("Whether the widget is visible"),
1084 GTK_PARAM_READWRITE));
1085 g_object_class_install_property (gobject_class,
1087 g_param_spec_boolean ("sensitive",
1089 P_("Whether the widget responds to input"),
1091 GTK_PARAM_READWRITE));
1092 g_object_class_install_property (gobject_class,
1094 g_param_spec_boolean ("app-paintable",
1095 P_("Application paintable"),
1096 P_("Whether the application will paint directly on the widget"),
1098 GTK_PARAM_READWRITE));
1099 g_object_class_install_property (gobject_class,
1101 g_param_spec_boolean ("can-focus",
1103 P_("Whether the widget can accept the input focus"),
1105 GTK_PARAM_READWRITE));
1106 g_object_class_install_property (gobject_class,
1108 g_param_spec_boolean ("has-focus",
1110 P_("Whether the widget has the input focus"),
1112 GTK_PARAM_READWRITE));
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_boolean ("is-focus",
1117 P_("Whether the widget is the focus widget within the toplevel"),
1119 GTK_PARAM_READWRITE));
1120 g_object_class_install_property (gobject_class,
1122 g_param_spec_boolean ("can-default",
1124 P_("Whether the widget can be the default widget"),
1126 GTK_PARAM_READWRITE));
1127 g_object_class_install_property (gobject_class,
1129 g_param_spec_boolean ("has-default",
1131 P_("Whether the widget is the default widget"),
1133 GTK_PARAM_READWRITE));
1134 g_object_class_install_property (gobject_class,
1135 PROP_RECEIVES_DEFAULT,
1136 g_param_spec_boolean ("receives-default",
1137 P_("Receives default"),
1138 P_("If TRUE, the widget will receive the default action when it is focused"),
1140 GTK_PARAM_READWRITE));
1141 g_object_class_install_property (gobject_class,
1142 PROP_COMPOSITE_CHILD,
1143 g_param_spec_boolean ("composite-child",
1144 P_("Composite child"),
1145 P_("Whether the widget is part of a composite widget"),
1147 GTK_PARAM_READABLE));
1148 g_object_class_install_property (gobject_class,
1150 g_param_spec_object ("style",
1152 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1154 GTK_PARAM_READWRITE));
1155 g_object_class_install_property (gobject_class,
1157 g_param_spec_flags ("events",
1159 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1160 GDK_TYPE_EVENT_MASK,
1162 GTK_PARAM_READWRITE));
1163 g_object_class_install_property (gobject_class,
1165 g_param_spec_boolean ("no-show-all",
1167 P_("Whether gtk_widget_show_all() should not affect this widget"),
1169 GTK_PARAM_READWRITE));
1172 * GtkWidget:has-tooltip:
1174 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1175 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1176 * the widget will be queried using #GtkWidget::query-tooltip to determine
1177 * whether it will provide a tooltip or not.
1179 * Note that setting this property to %TRUE for the first time will change
1180 * the event masks of the GdkWindows of this widget to include leave-notify
1181 * and motion-notify events. This cannot and will not be undone when the
1182 * property is set to %FALSE again.
1186 g_object_class_install_property (gobject_class,
1188 g_param_spec_boolean ("has-tooltip",
1190 P_("Whether this widget has a tooltip"),
1192 GTK_PARAM_READWRITE));
1194 * GtkWidget:tooltip-text:
1196 * Sets the text of tooltip to be the given string.
1198 * Also see gtk_tooltip_set_text().
1200 * This is a convenience property which will take care of getting the
1201 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1202 * will automatically be set to %TRUE and there will be taken care of
1203 * #GtkWidget::query-tooltip in the default signal handler.
1207 g_object_class_install_property (gobject_class,
1209 g_param_spec_string ("tooltip-text",
1211 P_("The contents of the tooltip for this widget"),
1213 GTK_PARAM_READWRITE));
1215 * GtkWidget:tooltip-markup:
1217 * Sets the text of tooltip to be the given string, which is marked up
1218 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1219 * Also see gtk_tooltip_set_markup().
1221 * This is a convenience property which will take care of getting the
1222 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1223 * will automatically be set to %TRUE and there will be taken care of
1224 * #GtkWidget::query-tooltip in the default signal handler.
1228 g_object_class_install_property (gobject_class,
1229 PROP_TOOLTIP_MARKUP,
1230 g_param_spec_string ("tooltip-markup",
1231 P_("Tooltip markup"),
1232 P_("The contents of the tooltip for this widget"),
1234 GTK_PARAM_READWRITE));
1239 * The widget's window if it is realized, %NULL otherwise.
1243 g_object_class_install_property (gobject_class,
1245 g_param_spec_object ("window",
1247 P_("The widget's window if it is realized"),
1249 GTK_PARAM_READABLE));
1252 * GtkWidget:double-buffered:
1254 * Whether the widget is double buffered.
1258 g_object_class_install_property (gobject_class,
1259 PROP_DOUBLE_BUFFERED,
1260 g_param_spec_boolean ("double-buffered",
1261 P_("Double Buffered"),
1262 P_("Whether the widget is double buffered"),
1264 GTK_PARAM_READWRITE));
1269 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1273 g_object_class_install_property (gobject_class,
1275 g_param_spec_enum ("halign",
1276 P_("Horizontal Alignment"),
1277 P_("How to position in extra horizontal space"),
1280 GTK_PARAM_READWRITE));
1285 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1289 g_object_class_install_property (gobject_class,
1291 g_param_spec_enum ("valign",
1292 P_("Vertical Alignment"),
1293 P_("How to position in extra vertical space"),
1296 GTK_PARAM_READWRITE));
1299 * GtkWidget:margin-left:
1301 * Margin on left side of widget.
1303 * This property adds margin outside of the widget's normal size
1304 * request, the margin will be added in addition to the size from
1305 * gtk_widget_set_size_request() for example.
1309 g_object_class_install_property (gobject_class,
1311 g_param_spec_int ("margin-left",
1312 P_("Margin on Left"),
1313 P_("Pixels of extra space on the left side"),
1317 GTK_PARAM_READWRITE));
1320 * GtkWidget:margin-right:
1322 * Margin on right side of widget.
1324 * This property adds margin outside of the widget's normal size
1325 * request, the margin will be added in addition to the size from
1326 * gtk_widget_set_size_request() for example.
1330 g_object_class_install_property (gobject_class,
1332 g_param_spec_int ("margin-right",
1333 P_("Margin on Right"),
1334 P_("Pixels of extra space on the right side"),
1338 GTK_PARAM_READWRITE));
1341 * GtkWidget:margin-top:
1343 * Margin on top side of widget.
1345 * This property adds margin outside of the widget's normal size
1346 * request, the margin will be added in addition to the size from
1347 * gtk_widget_set_size_request() for example.
1351 g_object_class_install_property (gobject_class,
1353 g_param_spec_int ("margin-top",
1354 P_("Margin on Top"),
1355 P_("Pixels of extra space on the top side"),
1359 GTK_PARAM_READWRITE));
1362 * GtkWidget:margin-bottom:
1364 * Margin on bottom side of widget.
1366 * This property adds margin outside of the widget's normal size
1367 * request, the margin will be added in addition to the size from
1368 * gtk_widget_set_size_request() for example.
1372 g_object_class_install_property (gobject_class,
1374 g_param_spec_int ("margin-bottom",
1375 P_("Margin on Bottom"),
1376 P_("Pixels of extra space on the bottom side"),
1380 GTK_PARAM_READWRITE));
1385 * Sets all four sides' margin at once. If read, returns max
1386 * margin on any side.
1390 g_object_class_install_property (gobject_class,
1392 g_param_spec_int ("margin",
1394 P_("Pixels of extra space on all four sides"),
1398 GTK_PARAM_READWRITE));
1401 * GtkWidget::destroy:
1402 * @object: the object which received the signal
1404 * Signals that all holders of a reference to the widget should release
1405 * the reference that they hold. May result in finalization of the widget
1406 * if all references are released.
1408 widget_signals[DESTROY] =
1409 g_signal_new (I_("destroy"),
1410 G_TYPE_FROM_CLASS (gobject_class),
1411 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1412 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1414 _gtk_marshal_VOID__VOID,
1418 * GtkWidget:hexpand:
1420 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1424 g_object_class_install_property (gobject_class,
1426 g_param_spec_boolean ("hexpand",
1427 P_("Horizontal Expand"),
1428 P_("Whether widget wants more horizontal space"),
1430 GTK_PARAM_READWRITE));
1433 * GtkWidget:hexpand-set:
1435 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1439 g_object_class_install_property (gobject_class,
1441 g_param_spec_boolean ("hexpand-set",
1442 P_("Horizontal Expand Set"),
1443 P_("Whether to use the hexpand property"),
1445 GTK_PARAM_READWRITE));
1448 * GtkWidget:vexpand:
1450 * Whether to expand vertically. See gtk_widget_set_vexpand().
1454 g_object_class_install_property (gobject_class,
1456 g_param_spec_boolean ("vexpand",
1457 P_("Vertical Expand"),
1458 P_("Whether widget wants more vertical space"),
1460 GTK_PARAM_READWRITE));
1463 * GtkWidget:vexpand-set:
1465 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1469 g_object_class_install_property (gobject_class,
1471 g_param_spec_boolean ("vexpand-set",
1472 P_("Vertical Expand Set"),
1473 P_("Whether to use the vexpand property"),
1475 GTK_PARAM_READWRITE));
1480 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1484 g_object_class_install_property (gobject_class,
1486 g_param_spec_boolean ("expand",
1488 P_("Whether widget wants to expand in both directions"),
1490 GTK_PARAM_READWRITE));
1493 * GtkWidget:opacity:
1495 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1496 * more details about window opacity.
1498 * Before 3.8 this was only availible in GtkWindow
1502 g_object_class_install_property (gobject_class,
1504 g_param_spec_double ("opacity",
1505 P_("Opacity for Widget"),
1506 P_("The opacity of the widget, from 0 to 1"),
1510 GTK_PARAM_READWRITE));
1513 * @widget: the object which received the signal.
1515 widget_signals[SHOW] =
1516 g_signal_new (I_("show"),
1517 G_TYPE_FROM_CLASS (gobject_class),
1519 G_STRUCT_OFFSET (GtkWidgetClass, show),
1521 _gtk_marshal_VOID__VOID,
1526 * @widget: the object which received the signal.
1528 widget_signals[HIDE] =
1529 g_signal_new (I_("hide"),
1530 G_TYPE_FROM_CLASS (gobject_class),
1532 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1534 _gtk_marshal_VOID__VOID,
1539 * @widget: the object which received the signal.
1541 widget_signals[MAP] =
1542 g_signal_new (I_("map"),
1543 G_TYPE_FROM_CLASS (gobject_class),
1545 G_STRUCT_OFFSET (GtkWidgetClass, map),
1547 _gtk_marshal_VOID__VOID,
1552 * @widget: the object which received the signal.
1554 widget_signals[UNMAP] =
1555 g_signal_new (I_("unmap"),
1556 G_TYPE_FROM_CLASS (gobject_class),
1558 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1560 _gtk_marshal_VOID__VOID,
1564 * GtkWidget::realize:
1565 * @widget: the object which received the signal.
1567 widget_signals[REALIZE] =
1568 g_signal_new (I_("realize"),
1569 G_TYPE_FROM_CLASS (gobject_class),
1571 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1573 _gtk_marshal_VOID__VOID,
1577 * GtkWidget::unrealize:
1578 * @widget: the object which received the signal.
1580 widget_signals[UNREALIZE] =
1581 g_signal_new (I_("unrealize"),
1582 G_TYPE_FROM_CLASS (gobject_class),
1584 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1586 _gtk_marshal_VOID__VOID,
1590 * GtkWidget::size-allocate:
1591 * @widget: the object which received the signal.
1594 widget_signals[SIZE_ALLOCATE] =
1595 g_signal_new (I_("size-allocate"),
1596 G_TYPE_FROM_CLASS (gobject_class),
1598 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1600 _gtk_marshal_VOID__BOXED,
1602 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1605 * GtkWidget::state-changed:
1606 * @widget: the object which received the signal.
1607 * @state: the previous state
1609 * The ::state-changed signal is emitted when the widget state changes.
1610 * See gtk_widget_get_state().
1612 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1614 widget_signals[STATE_CHANGED] =
1615 g_signal_new (I_("state-changed"),
1616 G_TYPE_FROM_CLASS (gobject_class),
1618 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1620 _gtk_marshal_VOID__ENUM,
1622 GTK_TYPE_STATE_TYPE);
1625 * GtkWidget::state-flags-changed:
1626 * @widget: the object which received the signal.
1627 * @flags: The previous state flags.
1629 * The ::state-flags-changed signal is emitted when the widget state
1630 * changes, see gtk_widget_get_state_flags().
1634 widget_signals[STATE_FLAGS_CHANGED] =
1635 g_signal_new (I_("state-flags-changed"),
1636 G_TYPE_FROM_CLASS (gobject_class),
1638 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1640 _gtk_marshal_VOID__FLAGS,
1642 GTK_TYPE_STATE_FLAGS);
1645 * GtkWidget::parent-set:
1646 * @widget: the object on which the signal is emitted
1647 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1648 * just got its initial parent.
1650 * The ::parent-set signal is emitted when a new parent
1651 * has been set on a widget.
1653 widget_signals[PARENT_SET] =
1654 g_signal_new (I_("parent-set"),
1655 G_TYPE_FROM_CLASS (gobject_class),
1657 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1659 _gtk_marshal_VOID__OBJECT,
1664 * GtkWidget::hierarchy-changed:
1665 * @widget: the object on which the signal is emitted
1666 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1667 * if the widget was previously unanchored
1669 * The ::hierarchy-changed signal is emitted when the
1670 * anchored state of a widget changes. A widget is
1671 * <firstterm>anchored</firstterm> when its toplevel
1672 * ancestor is a #GtkWindow. This signal is emitted when
1673 * a widget changes from un-anchored to anchored or vice-versa.
1675 widget_signals[HIERARCHY_CHANGED] =
1676 g_signal_new (I_("hierarchy-changed"),
1677 G_TYPE_FROM_CLASS (gobject_class),
1679 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1681 _gtk_marshal_VOID__OBJECT,
1686 * GtkWidget::style-set:
1687 * @widget: the object on which the signal is emitted
1688 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1689 * just got its initial style
1691 * The ::style-set signal is emitted when a new style has been set
1692 * on a widget. Note that style-modifying functions like
1693 * gtk_widget_modify_base() also cause this signal to be emitted.
1695 * Note that this signal is emitted for changes to the deprecated
1696 * #GtkStyle. To track changes to the #GtkStyleContext associated
1697 * with a widget, use the #GtkWidget::style-updated signal.
1699 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1701 widget_signals[STYLE_SET] =
1702 g_signal_new (I_("style-set"),
1703 G_TYPE_FROM_CLASS (gobject_class),
1705 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1707 _gtk_marshal_VOID__OBJECT,
1712 * GtkWidget::style-updated:
1713 * @widget: the object on which the signal is emitted
1715 * The ::style-updated signal is emitted when the #GtkStyleContext
1716 * of a widget is changed. Note that style-modifying functions like
1717 * gtk_widget_override_color() also cause this signal to be emitted.
1721 widget_signals[STYLE_UPDATED] =
1722 g_signal_new (I_("style-updated"),
1723 G_TYPE_FROM_CLASS (gobject_class),
1725 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1727 g_cclosure_marshal_VOID__VOID,
1731 * GtkWidget::direction-changed:
1732 * @widget: the object on which the signal is emitted
1733 * @previous_direction: the previous text direction of @widget
1735 * The ::direction-changed signal is emitted when the text direction
1736 * of a widget changes.
1738 widget_signals[DIRECTION_CHANGED] =
1739 g_signal_new (I_("direction-changed"),
1740 G_TYPE_FROM_CLASS (gobject_class),
1742 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1744 _gtk_marshal_VOID__ENUM,
1746 GTK_TYPE_TEXT_DIRECTION);
1749 * GtkWidget::grab-notify:
1750 * @widget: the object which received the signal
1751 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1752 * if it becomes unshadowed
1754 * The ::grab-notify signal is emitted when a widget becomes
1755 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1756 * another widget, or when it becomes unshadowed due to a grab
1759 * A widget is shadowed by a gtk_grab_add() when the topmost
1760 * grab widget in the grab stack of its window group is not
1763 widget_signals[GRAB_NOTIFY] =
1764 g_signal_new (I_("grab-notify"),
1765 G_TYPE_FROM_CLASS (gobject_class),
1767 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1769 _gtk_marshal_VOID__BOOLEAN,
1774 * GtkWidget::child-notify:
1775 * @widget: the object which received the signal
1776 * @child_property: the #GParamSpec of the changed child property
1778 * The ::child-notify signal is emitted for each
1779 * <link linkend="child-properties">child property</link> that has
1780 * changed on an object. The signal's detail holds the property name.
1782 widget_signals[CHILD_NOTIFY] =
1783 g_signal_new (I_("child-notify"),
1784 G_TYPE_FROM_CLASS (gobject_class),
1785 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1786 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1788 g_cclosure_marshal_VOID__PARAM,
1794 * @widget: the object which received the signal
1795 * @cr: the cairo context to draw to
1797 * This signal is emitted when a widget is supposed to render itself.
1798 * The @widget's top left corner must be painted at the origin of
1799 * the passed in context and be sized to the values returned by
1800 * gtk_widget_get_allocated_width() and
1801 * gtk_widget_get_allocated_height().
1803 * Signal handlers connected to this signal can modify the cairo
1804 * context passed as @cr in any way they like and don't need to
1805 * restore it. The signal emission takes care of calling cairo_save()
1806 * before and cairo_restore() after invoking the handler.
1808 * Returns: %TRUE to stop other handlers from being invoked for the event.
1809 % %FALSE to propagate the event further.
1813 widget_signals[DRAW] =
1814 g_signal_new (I_("draw"),
1815 G_TYPE_FROM_CLASS (gobject_class),
1817 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1818 _gtk_boolean_handled_accumulator, NULL,
1819 gtk_widget_draw_marshaller,
1821 CAIRO_GOBJECT_TYPE_CONTEXT);
1822 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1823 gtk_widget_draw_marshallerv);
1826 * GtkWidget::mnemonic-activate:
1827 * @widget: the object which received the signal.
1830 * Returns: %TRUE to stop other handlers from being invoked for the event.
1831 * %FALSE to propagate the event further.
1833 widget_signals[MNEMONIC_ACTIVATE] =
1834 g_signal_new (I_("mnemonic-activate"),
1835 G_TYPE_FROM_CLASS (gobject_class),
1837 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1838 _gtk_boolean_handled_accumulator, NULL,
1839 _gtk_marshal_BOOLEAN__BOOLEAN,
1844 * GtkWidget::grab-focus:
1845 * @widget: the object which received the signal.
1847 widget_signals[GRAB_FOCUS] =
1848 g_signal_new (I_("grab-focus"),
1849 G_TYPE_FROM_CLASS (gobject_class),
1850 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1851 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1853 _gtk_marshal_VOID__VOID,
1858 * @widget: the object which received the signal.
1861 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1863 widget_signals[FOCUS] =
1864 g_signal_new (I_("focus"),
1865 G_TYPE_FROM_CLASS (klass),
1867 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1868 _gtk_boolean_handled_accumulator, NULL,
1869 _gtk_marshal_BOOLEAN__ENUM,
1871 GTK_TYPE_DIRECTION_TYPE);
1874 * GtkWidget::move-focus:
1875 * @widget: the object which received the signal.
1878 widget_signals[MOVE_FOCUS] =
1879 g_signal_new (I_("move-focus"),
1880 G_TYPE_FROM_CLASS (klass),
1881 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1882 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1884 _gtk_marshal_VOID__ENUM,
1887 GTK_TYPE_DIRECTION_TYPE);
1890 * GtkWidget::keynav-failed:
1891 * @widget: the object which received the signal
1892 * @direction: the direction of movement
1894 * Gets emitted if keyboard navigation fails.
1895 * See gtk_widget_keynav_failed() for details.
1897 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1898 * if the emitting widget should try to handle the keyboard
1899 * navigation attempt in its parent container(s).
1903 widget_signals[KEYNAV_FAILED] =
1904 g_signal_new (I_("keynav-failed"),
1905 G_TYPE_FROM_CLASS (klass),
1907 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1908 _gtk_boolean_handled_accumulator, NULL,
1909 _gtk_marshal_BOOLEAN__ENUM,
1911 GTK_TYPE_DIRECTION_TYPE);
1915 * @widget: the object which received the signal.
1916 * @event: the #GdkEvent which triggered this signal
1918 * The GTK+ main loop will emit three signals for each GDK event delivered
1919 * to a widget: one generic ::event signal, another, more specific,
1920 * signal that matches the type of event delivered (e.g.
1921 * #GtkWidget::key-press-event) and finally a generic
1922 * #GtkWidget::event-after signal.
1924 * Returns: %TRUE to stop other handlers from being invoked for the event
1925 * and to cancel the emission of the second specific ::event signal.
1926 * %FALSE to propagate the event further and to allow the emission of
1927 * the second signal. The ::event-after signal is emitted regardless of
1930 widget_signals[EVENT] =
1931 g_signal_new (I_("event"),
1932 G_TYPE_FROM_CLASS (klass),
1934 G_STRUCT_OFFSET (GtkWidgetClass, event),
1935 _gtk_boolean_handled_accumulator, NULL,
1936 _gtk_marshal_BOOLEAN__BOXED,
1938 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1939 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1940 _gtk_marshal_BOOLEAN__BOXEDv);
1943 * GtkWidget::event-after:
1944 * @widget: the object which received the signal.
1945 * @event: the #GdkEvent which triggered this signal
1947 * After the emission of the #GtkWidget::event signal and (optionally)
1948 * the second more specific signal, ::event-after will be emitted
1949 * regardless of the previous two signals handlers return values.
1952 widget_signals[EVENT_AFTER] =
1953 g_signal_new (I_("event-after"),
1954 G_TYPE_FROM_CLASS (klass),
1958 _gtk_marshal_VOID__BOXED,
1960 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1961 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1962 _gtk_marshal_BOOLEAN__BOXEDv);
1965 * GtkWidget::button-press-event:
1966 * @widget: the object which received the signal.
1967 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1970 * The ::button-press-event signal will be emitted when a button
1971 * (typically from a mouse) is pressed.
1973 * To receive this signal, the #GdkWindow associated to the
1974 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1976 * This signal will be sent to the grab widget if there is one.
1978 * Returns: %TRUE to stop other handlers from being invoked for the event.
1979 * %FALSE to propagate the event further.
1981 widget_signals[BUTTON_PRESS_EVENT] =
1982 g_signal_new (I_("button-press-event"),
1983 G_TYPE_FROM_CLASS (klass),
1985 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1986 _gtk_boolean_handled_accumulator, NULL,
1987 _gtk_marshal_BOOLEAN__BOXED,
1989 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1990 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1991 _gtk_marshal_BOOLEAN__BOXEDv);
1994 * GtkWidget::button-release-event:
1995 * @widget: the object which received the signal.
1996 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1999 * The ::button-release-event signal will be emitted when a button
2000 * (typically from a mouse) is released.
2002 * To receive this signal, the #GdkWindow associated to the
2003 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
2005 * This signal will be sent to the grab widget if there is one.
2007 * Returns: %TRUE to stop other handlers from being invoked for the event.
2008 * %FALSE to propagate the event further.
2010 widget_signals[BUTTON_RELEASE_EVENT] =
2011 g_signal_new (I_("button-release-event"),
2012 G_TYPE_FROM_CLASS (klass),
2014 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2015 _gtk_boolean_handled_accumulator, NULL,
2016 _gtk_marshal_BOOLEAN__BOXED,
2018 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2019 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2020 _gtk_marshal_BOOLEAN__BOXEDv);
2022 widget_signals[TOUCH_EVENT] =
2023 g_signal_new (I_("touch-event"),
2024 G_TYPE_FROM_CLASS (klass),
2026 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2027 _gtk_boolean_handled_accumulator, NULL,
2028 _gtk_marshal_BOOLEAN__BOXED,
2030 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2031 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2032 _gtk_marshal_BOOLEAN__BOXEDv);
2035 * GtkWidget::scroll-event:
2036 * @widget: the object which received the signal.
2037 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2040 * The ::scroll-event signal is emitted when a button in the 4 to 7
2041 * range is pressed. Wheel mice are usually configured to generate
2042 * button press events for buttons 4 and 5 when the wheel is turned.
2044 * To receive this signal, the #GdkWindow associated to the widget needs
2045 * to enable the #GDK_SCROLL_MASK mask.
2047 * This signal will be sent to the grab widget if there is one.
2049 * Returns: %TRUE to stop other handlers from being invoked for the event.
2050 * %FALSE to propagate the event further.
2052 widget_signals[SCROLL_EVENT] =
2053 g_signal_new (I_("scroll-event"),
2054 G_TYPE_FROM_CLASS (klass),
2056 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2057 _gtk_boolean_handled_accumulator, NULL,
2058 _gtk_marshal_BOOLEAN__BOXED,
2060 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2061 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2062 _gtk_marshal_BOOLEAN__BOXEDv);
2065 * GtkWidget::motion-notify-event:
2066 * @widget: the object which received the signal.
2067 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2070 * The ::motion-notify-event signal is emitted when the pointer moves
2071 * over the widget's #GdkWindow.
2073 * To receive this signal, the #GdkWindow associated to the widget
2074 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2076 * This signal will be sent to the grab widget if there is one.
2078 * Returns: %TRUE to stop other handlers from being invoked for the event.
2079 * %FALSE to propagate the event further.
2081 widget_signals[MOTION_NOTIFY_EVENT] =
2082 g_signal_new (I_("motion-notify-event"),
2083 G_TYPE_FROM_CLASS (klass),
2085 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2086 _gtk_boolean_handled_accumulator, NULL,
2087 _gtk_marshal_BOOLEAN__BOXED,
2089 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2090 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2091 _gtk_marshal_BOOLEAN__BOXEDv);
2094 * GtkWidget::composited-changed:
2095 * @widget: the object on which the signal is emitted
2097 * The ::composited-changed signal is emitted when the composited
2098 * status of @widget<!-- -->s screen changes.
2099 * See gdk_screen_is_composited().
2101 widget_signals[COMPOSITED_CHANGED] =
2102 g_signal_new (I_("composited-changed"),
2103 G_TYPE_FROM_CLASS (klass),
2104 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2105 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2107 _gtk_marshal_VOID__VOID,
2111 * GtkWidget::delete-event:
2112 * @widget: the object which received the signal
2113 * @event: the event which triggered this signal
2115 * The ::delete-event signal is emitted if a user requests that
2116 * a toplevel window is closed. The default handler for this signal
2117 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2118 * this signal will cause the window to be hidden instead, so that
2119 * it can later be shown again without reconstructing it.
2121 * Returns: %TRUE to stop other handlers from being invoked for the event.
2122 * %FALSE to propagate the event further.
2124 widget_signals[DELETE_EVENT] =
2125 g_signal_new (I_("delete-event"),
2126 G_TYPE_FROM_CLASS (klass),
2128 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2129 _gtk_boolean_handled_accumulator, NULL,
2130 _gtk_marshal_BOOLEAN__BOXED,
2132 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2133 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2134 _gtk_marshal_BOOLEAN__BOXEDv);
2137 * GtkWidget::destroy-event:
2138 * @widget: the object which received the signal.
2139 * @event: the event which triggered this signal
2141 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2142 * You rarely get this signal, because most widgets disconnect themselves
2143 * from their window before they destroy it, so no widget owns the
2144 * window at destroy time.
2146 * To receive this signal, the #GdkWindow associated to the widget needs
2147 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2148 * automatically for all new windows.
2150 * Returns: %TRUE to stop other handlers from being invoked for the event.
2151 * %FALSE to propagate the event further.
2153 widget_signals[DESTROY_EVENT] =
2154 g_signal_new (I_("destroy-event"),
2155 G_TYPE_FROM_CLASS (klass),
2157 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2158 _gtk_boolean_handled_accumulator, NULL,
2159 _gtk_marshal_BOOLEAN__BOXED,
2161 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2162 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2163 _gtk_marshal_BOOLEAN__BOXEDv);
2166 * GtkWidget::key-press-event:
2167 * @widget: the object which received the signal
2168 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2170 * The ::key-press-event signal is emitted when a key is pressed. The signal
2171 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2173 * To receive this signal, the #GdkWindow associated to the widget needs
2174 * to enable the #GDK_KEY_PRESS_MASK mask.
2176 * This signal will be sent to the grab widget if there is one.
2178 * Returns: %TRUE to stop other handlers from being invoked for the event.
2179 * %FALSE to propagate the event further.
2181 widget_signals[KEY_PRESS_EVENT] =
2182 g_signal_new (I_("key-press-event"),
2183 G_TYPE_FROM_CLASS (klass),
2185 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2186 _gtk_boolean_handled_accumulator, NULL,
2187 _gtk_marshal_BOOLEAN__BOXED,
2189 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2190 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2191 _gtk_marshal_BOOLEAN__BOXEDv);
2194 * GtkWidget::key-release-event:
2195 * @widget: the object which received the signal
2196 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2198 * The ::key-release-event signal is emitted when a key is released.
2200 * To receive this signal, the #GdkWindow associated to the widget needs
2201 * to enable the #GDK_KEY_RELEASE_MASK mask.
2203 * This signal will be sent to the grab widget if there is one.
2205 * Returns: %TRUE to stop other handlers from being invoked for the event.
2206 * %FALSE to propagate the event further.
2208 widget_signals[KEY_RELEASE_EVENT] =
2209 g_signal_new (I_("key-release-event"),
2210 G_TYPE_FROM_CLASS (klass),
2212 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2213 _gtk_boolean_handled_accumulator, NULL,
2214 _gtk_marshal_BOOLEAN__BOXED,
2216 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2217 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2218 _gtk_marshal_BOOLEAN__BOXEDv);
2221 * GtkWidget::enter-notify-event:
2222 * @widget: the object which received the signal
2223 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2226 * The ::enter-notify-event will be emitted when the pointer enters
2227 * the @widget's window.
2229 * To receive this signal, the #GdkWindow associated to the widget needs
2230 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2232 * This signal will be sent to the grab widget if there is one.
2234 * Returns: %TRUE to stop other handlers from being invoked for the event.
2235 * %FALSE to propagate the event further.
2237 widget_signals[ENTER_NOTIFY_EVENT] =
2238 g_signal_new (I_("enter-notify-event"),
2239 G_TYPE_FROM_CLASS (klass),
2241 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2242 _gtk_boolean_handled_accumulator, NULL,
2243 _gtk_marshal_BOOLEAN__BOXED,
2245 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2246 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2247 _gtk_marshal_BOOLEAN__BOXEDv);
2250 * GtkWidget::leave-notify-event:
2251 * @widget: the object which received the signal
2252 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2255 * The ::leave-notify-event will be emitted when the pointer leaves
2256 * the @widget's window.
2258 * To receive this signal, the #GdkWindow associated to the widget needs
2259 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2261 * This signal will be sent to the grab widget if there is one.
2263 * Returns: %TRUE to stop other handlers from being invoked for the event.
2264 * %FALSE to propagate the event further.
2266 widget_signals[LEAVE_NOTIFY_EVENT] =
2267 g_signal_new (I_("leave-notify-event"),
2268 G_TYPE_FROM_CLASS (klass),
2270 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2271 _gtk_boolean_handled_accumulator, NULL,
2272 _gtk_marshal_BOOLEAN__BOXED,
2274 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2275 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2276 _gtk_marshal_BOOLEAN__BOXEDv);
2279 * GtkWidget::configure-event:
2280 * @widget: the object which received the signal
2281 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2284 * The ::configure-event signal will be emitted when the size, position or
2285 * stacking of the @widget's window has changed.
2287 * To receive this signal, the #GdkWindow associated to the widget needs
2288 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2289 * automatically for all new windows.
2291 * Returns: %TRUE to stop other handlers from being invoked for the event.
2292 * %FALSE to propagate the event further.
2294 widget_signals[CONFIGURE_EVENT] =
2295 g_signal_new (I_("configure-event"),
2296 G_TYPE_FROM_CLASS (klass),
2298 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2299 _gtk_boolean_handled_accumulator, NULL,
2300 _gtk_marshal_BOOLEAN__BOXED,
2302 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2303 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2304 _gtk_marshal_BOOLEAN__BOXEDv);
2307 * GtkWidget::focus-in-event:
2308 * @widget: the object which received the signal
2309 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2312 * The ::focus-in-event signal will be emitted when the keyboard focus
2313 * enters the @widget's window.
2315 * To receive this signal, the #GdkWindow associated to the widget needs
2316 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2318 * Returns: %TRUE to stop other handlers from being invoked for the event.
2319 * %FALSE to propagate the event further.
2321 widget_signals[FOCUS_IN_EVENT] =
2322 g_signal_new (I_("focus-in-event"),
2323 G_TYPE_FROM_CLASS (klass),
2325 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2326 _gtk_boolean_handled_accumulator, NULL,
2327 _gtk_marshal_BOOLEAN__BOXED,
2329 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2330 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2331 _gtk_marshal_BOOLEAN__BOXEDv);
2334 * GtkWidget::focus-out-event:
2335 * @widget: the object which received the signal
2336 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2339 * The ::focus-out-event signal will be emitted when the keyboard focus
2340 * leaves the @widget's window.
2342 * To receive this signal, the #GdkWindow associated to the widget needs
2343 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2345 * Returns: %TRUE to stop other handlers from being invoked for the event.
2346 * %FALSE to propagate the event further.
2348 widget_signals[FOCUS_OUT_EVENT] =
2349 g_signal_new (I_("focus-out-event"),
2350 G_TYPE_FROM_CLASS (klass),
2352 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2353 _gtk_boolean_handled_accumulator, NULL,
2354 _gtk_marshal_BOOLEAN__BOXED,
2356 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2357 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2358 _gtk_marshal_BOOLEAN__BOXEDv);
2361 * GtkWidget::map-event:
2362 * @widget: the object which received the signal
2363 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2365 * The ::map-event signal will be emitted when the @widget's window is
2366 * mapped. A window is mapped when it becomes visible on the screen.
2368 * To receive this signal, the #GdkWindow associated to the widget needs
2369 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2370 * automatically for all new windows.
2372 * Returns: %TRUE to stop other handlers from being invoked for the event.
2373 * %FALSE to propagate the event further.
2375 widget_signals[MAP_EVENT] =
2376 g_signal_new (I_("map-event"),
2377 G_TYPE_FROM_CLASS (klass),
2379 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2380 _gtk_boolean_handled_accumulator, NULL,
2381 _gtk_marshal_BOOLEAN__BOXED,
2383 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2384 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2385 _gtk_marshal_BOOLEAN__BOXEDv);
2388 * GtkWidget::unmap-event:
2389 * @widget: the object which received the signal
2390 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2392 * The ::unmap-event signal will be emitted when the @widget's window is
2393 * unmapped. A window is unmapped when it becomes invisible on the screen.
2395 * To receive this signal, the #GdkWindow associated to the widget needs
2396 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2397 * automatically for all new windows.
2399 * Returns: %TRUE to stop other handlers from being invoked for the event.
2400 * %FALSE to propagate the event further.
2402 widget_signals[UNMAP_EVENT] =
2403 g_signal_new (I_("unmap-event"),
2404 G_TYPE_FROM_CLASS (klass),
2406 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2407 _gtk_boolean_handled_accumulator, NULL,
2408 _gtk_marshal_BOOLEAN__BOXED,
2410 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2411 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2412 _gtk_marshal_BOOLEAN__BOXEDv);
2415 * GtkWidget::property-notify-event:
2416 * @widget: the object which received the signal
2417 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2420 * The ::property-notify-event signal will be emitted when a property on
2421 * the @widget's window has been changed or deleted.
2423 * To receive this signal, the #GdkWindow associated to the widget needs
2424 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2426 * Returns: %TRUE to stop other handlers from being invoked for the event.
2427 * %FALSE to propagate the event further.
2429 widget_signals[PROPERTY_NOTIFY_EVENT] =
2430 g_signal_new (I_("property-notify-event"),
2431 G_TYPE_FROM_CLASS (klass),
2433 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2434 _gtk_boolean_handled_accumulator, NULL,
2435 _gtk_marshal_BOOLEAN__BOXED,
2437 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2438 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2439 _gtk_marshal_BOOLEAN__BOXEDv);
2442 * GtkWidget::selection-clear-event:
2443 * @widget: the object which received the signal
2444 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2447 * The ::selection-clear-event signal will be emitted when the
2448 * the @widget's window has lost ownership of a selection.
2450 * Returns: %TRUE to stop other handlers from being invoked for the event.
2451 * %FALSE to propagate the event further.
2453 widget_signals[SELECTION_CLEAR_EVENT] =
2454 g_signal_new (I_("selection-clear-event"),
2455 G_TYPE_FROM_CLASS (klass),
2457 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2458 _gtk_boolean_handled_accumulator, NULL,
2459 _gtk_marshal_BOOLEAN__BOXED,
2461 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2462 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2463 _gtk_marshal_BOOLEAN__BOXEDv);
2466 * GtkWidget::selection-request-event:
2467 * @widget: the object which received the signal
2468 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2471 * The ::selection-request-event signal will be emitted when
2472 * another client requests ownership of the selection owned by
2473 * the @widget's window.
2475 * Returns: %TRUE to stop other handlers from being invoked for the event.
2476 * %FALSE to propagate the event further.
2478 widget_signals[SELECTION_REQUEST_EVENT] =
2479 g_signal_new (I_("selection-request-event"),
2480 G_TYPE_FROM_CLASS (klass),
2482 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2483 _gtk_boolean_handled_accumulator, NULL,
2484 _gtk_marshal_BOOLEAN__BOXED,
2486 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2487 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2488 _gtk_marshal_BOOLEAN__BOXEDv);
2491 * GtkWidget::selection-notify-event:
2492 * @widget: the object which received the signal.
2493 * @event: (type Gdk.EventSelection):
2495 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2497 widget_signals[SELECTION_NOTIFY_EVENT] =
2498 g_signal_new (I_("selection-notify-event"),
2499 G_TYPE_FROM_CLASS (klass),
2501 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2502 _gtk_boolean_handled_accumulator, NULL,
2503 _gtk_marshal_BOOLEAN__BOXED,
2505 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2506 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2507 _gtk_marshal_BOOLEAN__BOXEDv);
2510 * GtkWidget::selection-received:
2511 * @widget: the object which received the signal.
2515 widget_signals[SELECTION_RECEIVED] =
2516 g_signal_new (I_("selection-received"),
2517 G_TYPE_FROM_CLASS (klass),
2519 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2521 _gtk_marshal_VOID__BOXED_UINT,
2523 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2527 * GtkWidget::selection-get:
2528 * @widget: the object which received the signal.
2533 widget_signals[SELECTION_GET] =
2534 g_signal_new (I_("selection-get"),
2535 G_TYPE_FROM_CLASS (klass),
2537 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2539 _gtk_marshal_VOID__BOXED_UINT_UINT,
2541 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2546 * GtkWidget::proximity-in-event:
2547 * @widget: the object which received the signal
2548 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2551 * To receive this signal the #GdkWindow associated to the widget needs
2552 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2554 * This signal will be sent to the grab widget if there is one.
2556 * Returns: %TRUE to stop other handlers from being invoked for the event.
2557 * %FALSE to propagate the event further.
2559 widget_signals[PROXIMITY_IN_EVENT] =
2560 g_signal_new (I_("proximity-in-event"),
2561 G_TYPE_FROM_CLASS (klass),
2563 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2564 _gtk_boolean_handled_accumulator, NULL,
2565 _gtk_marshal_BOOLEAN__BOXED,
2567 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2568 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2569 _gtk_marshal_BOOLEAN__BOXEDv);
2572 * GtkWidget::proximity-out-event:
2573 * @widget: the object which received the signal
2574 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2577 * To receive this signal the #GdkWindow associated to the widget needs
2578 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2580 * This signal will be sent to the grab widget if there is one.
2582 * Returns: %TRUE to stop other handlers from being invoked for the event.
2583 * %FALSE to propagate the event further.
2585 widget_signals[PROXIMITY_OUT_EVENT] =
2586 g_signal_new (I_("proximity-out-event"),
2587 G_TYPE_FROM_CLASS (klass),
2589 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2590 _gtk_boolean_handled_accumulator, NULL,
2591 _gtk_marshal_BOOLEAN__BOXED,
2593 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2594 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2595 _gtk_marshal_BOOLEAN__BOXEDv);
2598 * GtkWidget::drag-leave:
2599 * @widget: the object which received the signal.
2600 * @context: the drag context
2601 * @time: the timestamp of the motion event
2603 * The ::drag-leave signal is emitted on the drop site when the cursor
2604 * leaves the widget. A typical reason to connect to this signal is to
2605 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2606 * with gtk_drag_unhighlight()
2608 widget_signals[DRAG_LEAVE] =
2609 g_signal_new (I_("drag-leave"),
2610 G_TYPE_FROM_CLASS (klass),
2612 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2614 _gtk_marshal_VOID__OBJECT_UINT,
2616 GDK_TYPE_DRAG_CONTEXT,
2620 * GtkWidget::drag-begin:
2621 * @widget: the object which received the signal
2622 * @context: the drag context
2624 * The ::drag-begin signal is emitted on the drag source when a drag is
2625 * started. A typical reason to connect to this signal is to set up a
2626 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2628 * Note that some widgets set up a drag icon in the default handler of
2629 * this signal, so you may have to use g_signal_connect_after() to
2630 * override what the default handler did.
2632 widget_signals[DRAG_BEGIN] =
2633 g_signal_new (I_("drag-begin"),
2634 G_TYPE_FROM_CLASS (klass),
2636 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2638 _gtk_marshal_VOID__OBJECT,
2640 GDK_TYPE_DRAG_CONTEXT);
2643 * GtkWidget::drag-end:
2644 * @widget: the object which received the signal
2645 * @context: the drag context
2647 * The ::drag-end signal is emitted on the drag source when a drag is
2648 * finished. A typical reason to connect to this signal is to undo
2649 * things done in #GtkWidget::drag-begin.
2651 widget_signals[DRAG_END] =
2652 g_signal_new (I_("drag-end"),
2653 G_TYPE_FROM_CLASS (klass),
2655 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2657 _gtk_marshal_VOID__OBJECT,
2659 GDK_TYPE_DRAG_CONTEXT);
2662 * GtkWidget::drag-data-delete:
2663 * @widget: the object which received the signal
2664 * @context: the drag context
2666 * The ::drag-data-delete signal is emitted on the drag source when a drag
2667 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2668 * handler is responsible for deleting the data that has been dropped. What
2669 * "delete" means depends on the context of the drag operation.
2671 widget_signals[DRAG_DATA_DELETE] =
2672 g_signal_new (I_("drag-data-delete"),
2673 G_TYPE_FROM_CLASS (klass),
2675 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2677 _gtk_marshal_VOID__OBJECT,
2679 GDK_TYPE_DRAG_CONTEXT);
2682 * GtkWidget::drag-failed:
2683 * @widget: the object which received the signal
2684 * @context: the drag context
2685 * @result: the result of the drag operation
2687 * The ::drag-failed signal is emitted on the drag source when a drag has
2688 * failed. The signal handler may hook custom code to handle a failed DND
2689 * operation based on the type of error, it returns %TRUE is the failure has
2690 * been already handled (not showing the default "drag operation failed"
2691 * animation), otherwise it returns %FALSE.
2693 * Return value: %TRUE if the failed drag operation has been already handled.
2697 widget_signals[DRAG_FAILED] =
2698 g_signal_new (I_("drag-failed"),
2699 G_TYPE_FROM_CLASS (klass),
2701 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2702 _gtk_boolean_handled_accumulator, NULL,
2703 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2705 GDK_TYPE_DRAG_CONTEXT,
2706 GTK_TYPE_DRAG_RESULT);
2709 * GtkWidget::drag-motion:
2710 * @widget: the object which received the signal
2711 * @context: the drag context
2712 * @x: the x coordinate of the current cursor position
2713 * @y: the y coordinate of the current cursor position
2714 * @time: the timestamp of the motion event
2716 * The ::drag-motion signal is emitted on the drop site when the user
2717 * moves the cursor over the widget during a drag. The signal handler
2718 * must determine whether the cursor position is in a drop zone or not.
2719 * If it is not in a drop zone, it returns %FALSE and no further processing
2720 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2721 * handler is responsible for providing the necessary information for
2722 * displaying feedback to the user, by calling gdk_drag_status().
2724 * If the decision whether the drop will be accepted or rejected can't be
2725 * made based solely on the cursor position and the type of the data, the
2726 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2727 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2728 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2729 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2730 * when using the drag-motion signal that way.
2732 * Also note that there is no drag-enter signal. The drag receiver has to
2733 * keep track of whether he has received any drag-motion signals since the
2734 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2735 * an "enter" signal. Upon an "enter", the handler will typically highlight
2736 * the drop site with gtk_drag_highlight().
2739 * drag_motion (GtkWidget *widget,
2740 * GdkDragContext *context,
2747 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2749 * if (!private_data->drag_highlight)
2751 * private_data->drag_highlight = 1;
2752 * gtk_drag_highlight (widget);
2755 * target = gtk_drag_dest_find_target (widget, context, NULL);
2756 * if (target == GDK_NONE)
2757 * gdk_drag_status (context, 0, time);
2760 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2761 * gtk_drag_get_data (widget, context, target, time);
2768 * drag_data_received (GtkWidget *widget,
2769 * GdkDragContext *context,
2772 * GtkSelectionData *selection_data,
2776 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2778 * if (private_data->suggested_action)
2780 * private_data->suggested_action = 0;
2782 * /* We are getting this data due to a request in drag_motion,
2783 * * rather than due to a request in drag_drop, so we are just
2784 * * supposed to call gdk_drag_status(), not actually paste in
2787 * str = gtk_selection_data_get_text (selection_data);
2788 * if (!data_is_acceptable (str))
2789 * gdk_drag_status (context, 0, time);
2791 * gdk_drag_status (context, private_data->suggested_action, time);
2795 * /* accept the drop */
2800 * Returns: whether the cursor position is in a drop zone
2802 widget_signals[DRAG_MOTION] =
2803 g_signal_new (I_("drag-motion"),
2804 G_TYPE_FROM_CLASS (klass),
2806 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2807 _gtk_boolean_handled_accumulator, NULL,
2808 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2810 GDK_TYPE_DRAG_CONTEXT,
2816 * GtkWidget::drag-drop:
2817 * @widget: the object which received the signal
2818 * @context: the drag context
2819 * @x: the x coordinate of the current cursor position
2820 * @y: the y coordinate of the current cursor position
2821 * @time: the timestamp of the motion event
2823 * The ::drag-drop signal is emitted on the drop site when the user drops
2824 * the data onto the widget. The signal handler must determine whether
2825 * the cursor position is in a drop zone or not. If it is not in a drop
2826 * zone, it returns %FALSE and no further processing is necessary.
2827 * Otherwise, the handler returns %TRUE. In this case, the handler must
2828 * ensure that gtk_drag_finish() is called to let the source know that
2829 * the drop is done. The call to gtk_drag_finish() can be done either
2830 * directly or in a #GtkWidget::drag-data-received handler which gets
2831 * triggered by calling gtk_drag_get_data() to receive the data for one
2832 * or more of the supported targets.
2834 * Returns: whether the cursor position is in a drop zone
2836 widget_signals[DRAG_DROP] =
2837 g_signal_new (I_("drag-drop"),
2838 G_TYPE_FROM_CLASS (klass),
2840 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2841 _gtk_boolean_handled_accumulator, NULL,
2842 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2844 GDK_TYPE_DRAG_CONTEXT,
2850 * GtkWidget::drag-data-get:
2851 * @widget: the object which received the signal
2852 * @context: the drag context
2853 * @data: the #GtkSelectionData to be filled with the dragged data
2854 * @info: the info that has been registered with the target in the
2856 * @time: the timestamp at which the data was requested
2858 * The ::drag-data-get signal is emitted on the drag source when the drop
2859 * site requests the data which is dragged. It is the responsibility of
2860 * the signal handler to fill @data with the data in the format which
2861 * is indicated by @info. See gtk_selection_data_set() and
2862 * gtk_selection_data_set_text().
2864 widget_signals[DRAG_DATA_GET] =
2865 g_signal_new (I_("drag-data-get"),
2866 G_TYPE_FROM_CLASS (klass),
2868 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2870 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2872 GDK_TYPE_DRAG_CONTEXT,
2873 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2878 * GtkWidget::drag-data-received:
2879 * @widget: the object which received the signal
2880 * @context: the drag context
2881 * @x: where the drop happened
2882 * @y: where the drop happened
2883 * @data: the received data
2884 * @info: the info that has been registered with the target in the
2886 * @time: the timestamp at which the data was received
2888 * The ::drag-data-received signal is emitted on the drop site when the
2889 * dragged data has been received. If the data was received in order to
2890 * determine whether the drop will be accepted, the handler is expected
2891 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2892 * If the data was received in response to a #GtkWidget::drag-drop signal
2893 * (and this is the last target to be received), the handler for this
2894 * signal is expected to process the received data and then call
2895 * gtk_drag_finish(), setting the @success parameter depending on
2896 * whether the data was processed successfully.
2898 * The handler may inspect the selected action with
2899 * gdk_drag_context_get_selected_action() before calling
2900 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2901 * shown in the following example:
2904 * drag_data_received (GtkWidget *widget,
2905 * GdkDragContext *context,
2908 * GtkSelectionData *data,
2912 * if ((data->length >= 0) && (data->format == 8))
2914 * GdkDragAction action;
2916 * /* handle data here */
2918 * action = gdk_drag_context_get_selected_action (context);
2919 * if (action == GDK_ACTION_ASK)
2921 * GtkWidget *dialog;
2924 * dialog = gtk_message_dialog_new (NULL,
2925 * GTK_DIALOG_MODAL |
2926 * GTK_DIALOG_DESTROY_WITH_PARENT,
2928 * GTK_BUTTONS_YES_NO,
2929 * "Move the data ?\n");
2930 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2931 * gtk_widget_destroy (dialog);
2933 * if (response == GTK_RESPONSE_YES)
2934 * action = GDK_ACTION_MOVE;
2936 * action = GDK_ACTION_COPY;
2939 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2942 * gtk_drag_finish (context, FALSE, FALSE, time);
2946 widget_signals[DRAG_DATA_RECEIVED] =
2947 g_signal_new (I_("drag-data-received"),
2948 G_TYPE_FROM_CLASS (klass),
2950 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2952 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2954 GDK_TYPE_DRAG_CONTEXT,
2957 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2962 * GtkWidget::visibility-notify-event:
2963 * @widget: the object which received the signal
2964 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2965 * triggered this signal.
2967 * The ::visibility-notify-event will be emitted when the @widget's window
2968 * is obscured or unobscured.
2970 * To receive this signal the #GdkWindow associated to the widget needs
2971 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2973 * Returns: %TRUE to stop other handlers from being invoked for the event.
2974 * %FALSE to propagate the event further.
2976 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2977 g_signal_new (I_("visibility-notify-event"),
2978 G_TYPE_FROM_CLASS (klass),
2980 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2981 _gtk_boolean_handled_accumulator, NULL,
2982 _gtk_marshal_BOOLEAN__BOXED,
2984 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2987 * GtkWidget::window-state-event:
2988 * @widget: the object which received the signal
2989 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2990 * triggered this signal.
2992 * The ::window-state-event will be emitted when the state of the
2993 * toplevel window associated to the @widget changes.
2995 * To receive this signal the #GdkWindow associated to the widget
2996 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2997 * this mask automatically for all new windows.
2999 * Returns: %TRUE to stop other handlers from being invoked for the
3000 * event. %FALSE to propagate the event further.
3002 widget_signals[WINDOW_STATE_EVENT] =
3003 g_signal_new (I_("window-state-event"),
3004 G_TYPE_FROM_CLASS (klass),
3006 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
3007 _gtk_boolean_handled_accumulator, NULL,
3008 _gtk_marshal_BOOLEAN__BOXED,
3010 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3011 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3012 _gtk_marshal_BOOLEAN__BOXEDv);
3015 * GtkWidget::damage-event:
3016 * @widget: the object which received the signal
3017 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3019 * Emitted when a redirected window belonging to @widget gets drawn into.
3020 * The region/area members of the event shows what area of the redirected
3021 * drawable was drawn into.
3023 * Returns: %TRUE to stop other handlers from being invoked for the event.
3024 * %FALSE to propagate the event further.
3028 widget_signals[DAMAGE_EVENT] =
3029 g_signal_new (I_("damage-event"),
3030 G_TYPE_FROM_CLASS (klass),
3032 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3033 _gtk_boolean_handled_accumulator, NULL,
3034 _gtk_marshal_BOOLEAN__BOXED,
3036 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3037 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3038 _gtk_marshal_BOOLEAN__BOXEDv);
3041 * GtkWidget::grab-broken-event:
3042 * @widget: the object which received the signal
3043 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3045 * Emitted when a pointer or keyboard grab on a window belonging
3046 * to @widget gets broken.
3048 * On X11, this happens when the grab window becomes unviewable
3049 * (i.e. it or one of its ancestors is unmapped), or if the same
3050 * application grabs the pointer or keyboard again.
3052 * Returns: %TRUE to stop other handlers from being invoked for
3053 * the event. %FALSE to propagate the event further.
3057 widget_signals[GRAB_BROKEN_EVENT] =
3058 g_signal_new (I_("grab-broken-event"),
3059 G_TYPE_FROM_CLASS (klass),
3061 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3062 _gtk_boolean_handled_accumulator, NULL,
3063 _gtk_marshal_BOOLEAN__BOXED,
3065 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3066 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3067 _gtk_marshal_BOOLEAN__BOXEDv);
3070 * GtkWidget::query-tooltip:
3071 * @widget: the object which received the signal
3072 * @x: the x coordinate of the cursor position where the request has
3073 * been emitted, relative to @widget's left side
3074 * @y: the y coordinate of the cursor position where the request has
3075 * been emitted, relative to @widget's top
3076 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3077 * @tooltip: a #GtkTooltip
3079 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3080 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3081 * focus in keyboard mode.
3083 * Using the given coordinates, the signal handler should determine
3084 * whether a tooltip should be shown for @widget. If this is the case
3085 * %TRUE should be returned, %FALSE otherwise. Note that if
3086 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3087 * should not be used.
3089 * The signal handler is free to manipulate @tooltip with the therefore
3090 * destined function calls.
3092 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3096 widget_signals[QUERY_TOOLTIP] =
3097 g_signal_new (I_("query-tooltip"),
3098 G_TYPE_FROM_CLASS (klass),
3100 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3101 _gtk_boolean_handled_accumulator, NULL,
3102 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3110 * GtkWidget::popup-menu:
3111 * @widget: the object which received the signal
3113 * This signal gets emitted whenever a widget should pop up a context
3114 * menu. This usually happens through the standard key binding mechanism;
3115 * by pressing a certain key while a widget is focused, the user can cause
3116 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3117 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3118 * for an example of how to use this signal.
3120 * Returns: %TRUE if a menu was activated
3122 widget_signals[POPUP_MENU] =
3123 g_signal_new (I_("popup-menu"),
3124 G_TYPE_FROM_CLASS (klass),
3125 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3126 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3127 _gtk_boolean_handled_accumulator, NULL,
3128 _gtk_marshal_BOOLEAN__VOID,
3132 * GtkWidget::show-help:
3133 * @widget: the object which received the signal.
3136 * Returns: %TRUE to stop other handlers from being invoked for the event.
3137 * %FALSE to propagate the event further.
3139 widget_signals[SHOW_HELP] =
3140 g_signal_new (I_("show-help"),
3141 G_TYPE_FROM_CLASS (klass),
3142 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3143 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3144 _gtk_boolean_handled_accumulator, NULL,
3145 _gtk_marshal_BOOLEAN__ENUM,
3147 GTK_TYPE_WIDGET_HELP_TYPE);
3150 * GtkWidget::accel-closures-changed:
3151 * @widget: the object which received the signal.
3153 widget_signals[ACCEL_CLOSURES_CHANGED] =
3154 g_signal_new (I_("accel-closures-changed"),
3155 G_TYPE_FROM_CLASS (klass),
3159 _gtk_marshal_VOID__VOID,
3163 * GtkWidget::screen-changed:
3164 * @widget: the object on which the signal is emitted
3165 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3166 * widget was not associated with a screen before
3168 * The ::screen-changed signal gets emitted when the
3169 * screen of a widget has changed.
3171 widget_signals[SCREEN_CHANGED] =
3172 g_signal_new (I_("screen-changed"),
3173 G_TYPE_FROM_CLASS (klass),
3175 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3177 _gtk_marshal_VOID__OBJECT,
3182 * GtkWidget::can-activate-accel:
3183 * @widget: the object which received the signal
3184 * @signal_id: the ID of a signal installed on @widget
3186 * Determines whether an accelerator that activates the signal
3187 * identified by @signal_id can currently be activated.
3188 * This signal is present to allow applications and derived
3189 * widgets to override the default #GtkWidget handling
3190 * for determining whether an accelerator can be activated.
3192 * Returns: %TRUE if the signal can be activated.
3194 widget_signals[CAN_ACTIVATE_ACCEL] =
3195 g_signal_new (I_("can-activate-accel"),
3196 G_TYPE_FROM_CLASS (klass),
3198 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3199 _gtk_boolean_handled_accumulator, NULL,
3200 _gtk_marshal_BOOLEAN__UINT,
3201 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3203 binding_set = gtk_binding_set_by_class (klass);
3204 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3206 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3209 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3211 GTK_TYPE_WIDGET_HELP_TYPE,
3212 GTK_WIDGET_HELP_TOOLTIP);
3213 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3215 GTK_TYPE_WIDGET_HELP_TYPE,
3216 GTK_WIDGET_HELP_TOOLTIP);
3217 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3219 GTK_TYPE_WIDGET_HELP_TYPE,
3220 GTK_WIDGET_HELP_WHATS_THIS);
3221 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3223 GTK_TYPE_WIDGET_HELP_TYPE,
3224 GTK_WIDGET_HELP_WHATS_THIS);
3226 gtk_widget_class_install_style_property (klass,
3227 g_param_spec_boolean ("interior-focus",
3228 P_("Interior Focus"),
3229 P_("Whether to draw the focus indicator inside widgets"),
3231 GTK_PARAM_READABLE));
3233 gtk_widget_class_install_style_property (klass,
3234 g_param_spec_int ("focus-line-width",
3235 P_("Focus linewidth"),
3236 P_("Width, in pixels, of the focus indicator line"),
3238 GTK_PARAM_READABLE));
3240 gtk_widget_class_install_style_property (klass,
3241 g_param_spec_string ("focus-line-pattern",
3242 P_("Focus line dash pattern"),
3243 P_("Dash pattern used to draw the focus indicator"),
3245 GTK_PARAM_READABLE));
3246 gtk_widget_class_install_style_property (klass,
3247 g_param_spec_int ("focus-padding",
3248 P_("Focus padding"),
3249 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3251 GTK_PARAM_READABLE));
3252 gtk_widget_class_install_style_property (klass,
3253 g_param_spec_boxed ("cursor-color",
3255 P_("Color with which to draw insertion cursor"),
3257 GTK_PARAM_READABLE));
3258 gtk_widget_class_install_style_property (klass,
3259 g_param_spec_boxed ("secondary-cursor-color",
3260 P_("Secondary cursor color"),
3261 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3263 GTK_PARAM_READABLE));
3264 gtk_widget_class_install_style_property (klass,
3265 g_param_spec_float ("cursor-aspect-ratio",
3266 P_("Cursor line aspect ratio"),
3267 P_("Aspect ratio with which to draw insertion cursor"),
3269 GTK_PARAM_READABLE));
3271 gtk_widget_class_install_style_property (klass,
3272 g_param_spec_boolean ("window-dragging",
3273 P_("Window dragging"),
3274 P_("Whether windows can be dragged by clicking on empty areas"),
3276 GTK_PARAM_READABLE));
3279 * GtkWidget:link-color:
3281 * The "link-color" style property defines the color of unvisited links.
3285 gtk_widget_class_install_style_property (klass,
3286 g_param_spec_boxed ("link-color",
3287 P_("Unvisited Link Color"),
3288 P_("Color of unvisited links"),
3290 GTK_PARAM_READABLE));
3293 * GtkWidget:visited-link-color:
3295 * The "visited-link-color" style property defines the color of visited links.
3299 gtk_widget_class_install_style_property (klass,
3300 g_param_spec_boxed ("visited-link-color",
3301 P_("Visited Link Color"),
3302 P_("Color of visited links"),
3304 GTK_PARAM_READABLE));
3307 * GtkWidget:wide-separators:
3309 * The "wide-separators" style property defines whether separators have
3310 * configurable width and should be drawn using a box instead of a line.
3314 gtk_widget_class_install_style_property (klass,
3315 g_param_spec_boolean ("wide-separators",
3316 P_("Wide Separators"),
3317 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3319 GTK_PARAM_READABLE));
3322 * GtkWidget:separator-width:
3324 * The "separator-width" style property defines the width of separators.
3325 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3329 gtk_widget_class_install_style_property (klass,
3330 g_param_spec_int ("separator-width",
3331 P_("Separator Width"),
3332 P_("The width of separators if wide-separators is TRUE"),
3334 GTK_PARAM_READABLE));
3337 * GtkWidget:separator-height:
3339 * The "separator-height" style property defines the height of separators.
3340 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3344 gtk_widget_class_install_style_property (klass,
3345 g_param_spec_int ("separator-height",
3346 P_("Separator Height"),
3347 P_("The height of separators if \"wide-separators\" is TRUE"),
3349 GTK_PARAM_READABLE));
3352 * GtkWidget:scroll-arrow-hlength:
3354 * The "scroll-arrow-hlength" style property defines the length of
3355 * horizontal scroll arrows.
3359 gtk_widget_class_install_style_property (klass,
3360 g_param_spec_int ("scroll-arrow-hlength",
3361 P_("Horizontal Scroll Arrow Length"),
3362 P_("The length of horizontal scroll arrows"),
3364 GTK_PARAM_READABLE));
3367 * GtkWidget:scroll-arrow-vlength:
3369 * The "scroll-arrow-vlength" style property defines the length of
3370 * vertical scroll arrows.
3374 gtk_widget_class_install_style_property (klass,
3375 g_param_spec_int ("scroll-arrow-vlength",
3376 P_("Vertical Scroll Arrow Length"),
3377 P_("The length of vertical scroll arrows"),
3379 GTK_PARAM_READABLE));
3381 gtk_widget_class_install_style_property (klass,
3382 g_param_spec_int ("text-handle-width",
3383 P_("Width of text selection handles"),
3384 P_("Width of text selection handles"),
3386 GTK_PARAM_READABLE));
3387 gtk_widget_class_install_style_property (klass,
3388 g_param_spec_int ("text-handle-height",
3389 P_("Height of text selection handles"),
3390 P_("Height of text selection handles"),
3392 GTK_PARAM_READABLE));
3394 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3396 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3400 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3404 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3405 for (node = list; node; node = node->next)
3407 GParamSpec *pspec = node->data;
3409 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3410 g_param_spec_unref (pspec);
3416 gtk_widget_set_property (GObject *object,
3418 const GValue *value,
3421 GtkWidget *widget = GTK_WIDGET (object);
3426 gchar *tooltip_markup;
3427 const gchar *tooltip_text;
3428 GtkWindow *tooltip_window;
3431 gtk_widget_set_name (widget, g_value_get_string (value));
3434 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3436 case PROP_WIDTH_REQUEST:
3437 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3439 case PROP_HEIGHT_REQUEST:
3440 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3443 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3445 case PROP_SENSITIVE:
3446 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3448 case PROP_APP_PAINTABLE:
3449 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3451 case PROP_CAN_FOCUS:
3452 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3454 case PROP_HAS_FOCUS:
3455 if (g_value_get_boolean (value))
3456 gtk_widget_grab_focus (widget);
3459 if (g_value_get_boolean (value))
3460 gtk_widget_grab_focus (widget);
3462 case PROP_CAN_DEFAULT:
3463 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3465 case PROP_HAS_DEFAULT:
3466 if (g_value_get_boolean (value))
3467 gtk_widget_grab_default (widget);
3469 case PROP_RECEIVES_DEFAULT:
3470 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3473 gtk_widget_set_style (widget, g_value_get_object (value));
3476 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3477 gtk_widget_set_events (widget, g_value_get_flags (value));
3479 case PROP_NO_SHOW_ALL:
3480 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3482 case PROP_HAS_TOOLTIP:
3483 gtk_widget_real_set_has_tooltip (widget,
3484 g_value_get_boolean (value), FALSE);
3486 case PROP_TOOLTIP_MARKUP:
3487 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3488 tooltip_markup = g_value_dup_string (value);
3490 /* Treat an empty string as a NULL string,
3491 * because an empty string would be useless for a tooltip:
3493 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3495 g_free (tooltip_markup);
3496 tooltip_markup = NULL;
3499 g_object_set_qdata_full (object, quark_tooltip_markup,
3500 tooltip_markup, g_free);
3502 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3503 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3504 if (gtk_widget_get_visible (widget))
3505 gtk_widget_queue_tooltip_query (widget);
3507 case PROP_TOOLTIP_TEXT:
3508 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3510 tooltip_text = g_value_get_string (value);
3512 /* Treat an empty string as a NULL string,
3513 * because an empty string would be useless for a tooltip:
3515 if (tooltip_text && (strlen (tooltip_text) == 0))
3516 tooltip_text = NULL;
3518 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3520 g_object_set_qdata_full (object, quark_tooltip_markup,
3521 tooltip_markup, g_free);
3523 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3524 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3525 if (gtk_widget_get_visible (widget))
3526 gtk_widget_queue_tooltip_query (widget);
3528 case PROP_DOUBLE_BUFFERED:
3529 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3532 gtk_widget_set_halign (widget, g_value_get_enum (value));
3535 gtk_widget_set_valign (widget, g_value_get_enum (value));
3537 case PROP_MARGIN_LEFT:
3538 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3540 case PROP_MARGIN_RIGHT:
3541 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3543 case PROP_MARGIN_TOP:
3544 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3546 case PROP_MARGIN_BOTTOM:
3547 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3550 g_object_freeze_notify (G_OBJECT (widget));
3551 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3552 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3553 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3554 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3555 g_object_thaw_notify (G_OBJECT (widget));
3558 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3560 case PROP_HEXPAND_SET:
3561 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3564 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3566 case PROP_VEXPAND_SET:
3567 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3570 g_object_freeze_notify (G_OBJECT (widget));
3571 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3572 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3573 g_object_thaw_notify (G_OBJECT (widget));
3576 gtk_widget_set_opacity (widget, g_value_get_double (value));
3579 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3585 gtk_widget_get_property (GObject *object,
3590 GtkWidget *widget = GTK_WIDGET (object);
3591 GtkWidgetPrivate *priv = widget->priv;
3599 g_value_set_string (value, priv->name);
3601 g_value_set_static_string (value, "");
3604 g_value_set_object (value, priv->parent);
3606 case PROP_WIDTH_REQUEST:
3609 gtk_widget_get_size_request (widget, &w, NULL);
3610 g_value_set_int (value, w);
3613 case PROP_HEIGHT_REQUEST:
3616 gtk_widget_get_size_request (widget, NULL, &h);
3617 g_value_set_int (value, h);
3621 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3623 case PROP_SENSITIVE:
3624 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3626 case PROP_APP_PAINTABLE:
3627 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3629 case PROP_CAN_FOCUS:
3630 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3632 case PROP_HAS_FOCUS:
3633 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3636 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3638 case PROP_CAN_DEFAULT:
3639 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3641 case PROP_HAS_DEFAULT:
3642 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3644 case PROP_RECEIVES_DEFAULT:
3645 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3647 case PROP_COMPOSITE_CHILD:
3648 g_value_set_boolean (value, widget->priv->composite_child);
3651 g_value_set_object (value, gtk_widget_get_style (widget));
3654 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3655 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3657 case PROP_NO_SHOW_ALL:
3658 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3660 case PROP_HAS_TOOLTIP:
3661 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3663 case PROP_TOOLTIP_TEXT:
3665 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3668 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3669 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3671 g_value_take_string (value, text);
3674 case PROP_TOOLTIP_MARKUP:
3675 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3678 g_value_set_object (value, gtk_widget_get_window (widget));
3680 case PROP_DOUBLE_BUFFERED:
3681 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3684 g_value_set_enum (value, gtk_widget_get_halign (widget));
3687 g_value_set_enum (value, gtk_widget_get_valign (widget));
3689 case PROP_MARGIN_LEFT:
3690 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3692 case PROP_MARGIN_RIGHT:
3693 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3695 case PROP_MARGIN_TOP:
3696 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3698 case PROP_MARGIN_BOTTOM:
3699 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3703 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3704 if (aux_info == NULL)
3706 g_value_set_int (value, 0);
3710 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3711 aux_info->margin.right),
3712 MAX (aux_info->margin.top,
3713 aux_info->margin.bottom)));
3718 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3720 case PROP_HEXPAND_SET:
3721 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3724 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3726 case PROP_VEXPAND_SET:
3727 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3730 g_value_set_boolean (value,
3731 gtk_widget_get_hexpand (widget) &&
3732 gtk_widget_get_vexpand (widget));
3735 g_value_set_double (value, gtk_widget_get_opacity (widget));
3738 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3744 gtk_widget_init (GtkWidget *widget)
3746 GtkWidgetPrivate *priv;
3748 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3751 priv = widget->priv;
3753 priv->child_visible = TRUE;
3755 priv->allocation.x = -1;
3756 priv->allocation.y = -1;
3757 priv->allocation.width = 1;
3758 priv->allocation.height = 1;
3759 priv->user_alpha = 255;
3761 priv->window = NULL;
3762 priv->parent = NULL;
3764 priv->sensitive = TRUE;
3765 priv->composite_child = composite_child_stack != 0;
3766 priv->double_buffered = TRUE;
3767 priv->redraw_on_alloc = TRUE;
3768 priv->alloc_needed = TRUE;
3770 switch (gtk_widget_get_direction (widget))
3772 case GTK_TEXT_DIR_LTR:
3773 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3776 case GTK_TEXT_DIR_RTL:
3777 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3780 case GTK_TEXT_DIR_NONE:
3782 g_assert_not_reached ();
3787 /* this will be set to TRUE if the widget gets a child or if the
3788 * expand flag is set on the widget, but until one of those happen
3789 * we know the expand is already properly FALSE.
3791 * We really want to default FALSE here to avoid computing expand
3792 * all over the place while initially building a widget tree.
3794 priv->need_compute_expand = FALSE;
3796 _gtk_size_request_cache_init (&priv->requests);
3798 priv->style = gtk_widget_get_default_style ();
3799 g_object_ref (priv->style);
3804 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3806 GParamSpec **pspecs)
3808 GtkWidgetPrivate *priv = widget->priv;
3809 GtkWidget *container = priv->parent;
3812 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3813 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3817 * gtk_widget_freeze_child_notify:
3818 * @widget: a #GtkWidget
3820 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3821 * signals are queued until gtk_widget_thaw_child_notify() is called
3824 * This is the analogue of g_object_freeze_notify() for child properties.
3827 gtk_widget_freeze_child_notify (GtkWidget *widget)
3829 g_return_if_fail (GTK_IS_WIDGET (widget));
3831 if (!G_OBJECT (widget)->ref_count)
3834 g_object_ref (widget);
3835 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3836 g_object_unref (widget);
3840 * gtk_widget_child_notify:
3841 * @widget: a #GtkWidget
3842 * @child_property: the name of a child property installed on the
3843 * class of @widget<!-- -->'s parent
3845 * Emits a #GtkWidget::child-notify signal for the
3846 * <link linkend="child-properties">child property</link> @child_property
3849 * This is the analogue of g_object_notify() for child properties.
3851 * Also see gtk_container_child_notify().
3854 gtk_widget_child_notify (GtkWidget *widget,
3855 const gchar *child_property)
3857 if (widget->priv->parent == NULL)
3860 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3864 * gtk_widget_thaw_child_notify:
3865 * @widget: a #GtkWidget
3867 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3868 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3872 gtk_widget_thaw_child_notify (GtkWidget *widget)
3874 GObjectNotifyQueue *nqueue;
3876 g_return_if_fail (GTK_IS_WIDGET (widget));
3878 if (!G_OBJECT (widget)->ref_count)
3881 g_object_ref (widget);
3882 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3883 if (!nqueue || !nqueue->freeze_count)
3884 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3885 G_OBJECT_TYPE_NAME (widget), widget);
3887 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3888 g_object_unref (widget);
3894 * @type: type ID of the widget to create
3895 * @first_property_name: name of first property to set
3896 * @...: value of first property, followed by more properties,
3899 * This is a convenience function for creating a widget and setting
3900 * its properties in one go. For example you might write:
3901 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3902 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3903 * g_object_new(), but returns a widget so you don't have to
3904 * cast the object yourself.
3906 * Return value: a new #GtkWidget of type @widget_type
3909 gtk_widget_new (GType type,
3910 const gchar *first_property_name,
3916 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3918 va_start (var_args, first_property_name);
3919 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3926 gtk_widget_queue_draw_child (GtkWidget *widget)
3928 GtkWidgetPrivate *priv = widget->priv;
3931 parent = priv->parent;
3932 if (parent && gtk_widget_is_drawable (parent))
3933 gtk_widget_queue_draw_area (parent,
3936 priv->allocation.width,
3937 priv->allocation.height);
3941 * gtk_widget_unparent:
3942 * @widget: a #GtkWidget
3944 * This function is only for use in widget implementations.
3945 * Should be called by implementations of the remove method
3946 * on #GtkContainer, to dissociate a child from the container.
3949 gtk_widget_unparent (GtkWidget *widget)
3951 GtkWidgetPrivate *priv;
3952 GObjectNotifyQueue *nqueue;
3953 GtkWidget *toplevel;
3954 GtkWidget *old_parent;
3956 g_return_if_fail (GTK_IS_WIDGET (widget));
3958 priv = widget->priv;
3960 if (priv->parent == NULL)
3963 /* keep this function in sync with gtk_menu_detach() */
3965 gtk_widget_push_verify_invariants (widget);
3967 g_object_freeze_notify (G_OBJECT (widget));
3968 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3970 toplevel = gtk_widget_get_toplevel (widget);
3971 if (gtk_widget_is_toplevel (toplevel))
3972 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3974 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3975 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3977 gtk_widget_queue_draw_child (widget);
3979 /* Reset the width and height here, to force reallocation if we
3980 * get added back to a new parent. This won't work if our new
3981 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3982 * (would 0x0 be OK here?)
3984 priv->allocation.width = 1;
3985 priv->allocation.height = 1;
3987 if (gtk_widget_get_realized (widget))
3989 if (priv->in_reparent)
3990 gtk_widget_unmap (widget);
3992 gtk_widget_unrealize (widget);
3995 /* If we are unanchoring the child, we save around the toplevel
3996 * to emit hierarchy changed
3998 if (priv->parent->priv->anchored)
3999 g_object_ref (toplevel);
4003 /* Removing a widget from a container restores the child visible
4004 * flag to the default state, so it doesn't affect the child
4005 * in the next parent.
4007 priv->child_visible = TRUE;
4009 old_parent = priv->parent;
4010 priv->parent = NULL;
4012 /* parent may no longer expand if the removed
4013 * child was expand=TRUE and could therefore
4016 if (gtk_widget_get_visible (widget) &&
4017 (priv->need_compute_expand ||
4018 priv->computed_hexpand ||
4019 priv->computed_vexpand))
4021 gtk_widget_queue_compute_expand (old_parent);
4024 /* Unset BACKDROP since we are no longer inside a toplevel window */
4025 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4027 gtk_style_context_set_parent (priv->context, NULL);
4029 _gtk_widget_update_parent_muxer (widget);
4031 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4034 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4035 g_object_unref (toplevel);
4038 /* Now that the parent pointer is nullified and the hierarchy-changed
4039 * already passed, go ahead and unset the parent window, if we are unparenting
4040 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4041 * will fire again for the new subhierarchy.
4043 gtk_widget_set_parent_window (widget, NULL);
4045 g_object_notify (G_OBJECT (widget), "parent");
4046 g_object_thaw_notify (G_OBJECT (widget));
4048 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4049 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4051 gtk_widget_propagate_alpha (widget);
4053 gtk_widget_pop_verify_invariants (widget);
4054 g_object_unref (widget);
4058 * gtk_widget_destroy:
4059 * @widget: a #GtkWidget
4061 * Destroys a widget.
4064 * destroyed, it will break any references it holds to other objects.
4065 * If the widget is inside a container, the widget will be removed
4066 * from the container. If the widget is a toplevel (derived from
4067 * #GtkWindow), it will be removed from the list of toplevels, and the
4068 * reference GTK+ holds to it will be removed. Removing a
4069 * widget from its container or the list of toplevels results in the
4070 * widget being finalized, unless you've added additional references
4071 * to the widget with g_object_ref().
4073 * In most cases, only toplevel widgets (windows) require explicit
4074 * destruction, because when you destroy a toplevel its children will
4075 * be destroyed as well.
4078 gtk_widget_destroy (GtkWidget *widget)
4080 g_return_if_fail (GTK_IS_WIDGET (widget));
4082 if (!widget->priv->in_destruction)
4083 g_object_run_dispose (G_OBJECT (widget));
4087 * gtk_widget_destroyed:
4088 * @widget: a #GtkWidget
4089 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4091 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4092 * %NULL. It's intended to be used as a callback connected to the
4093 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4094 * as a signal handler, and pass the address of your widget variable
4095 * as user data. Then when the widget is destroyed, the variable will
4096 * be set to %NULL. Useful for example to avoid multiple copies
4097 * of the same dialog.
4100 gtk_widget_destroyed (GtkWidget *widget,
4101 GtkWidget **widget_pointer)
4103 /* Don't make any assumptions about the
4105 * Even check widget_pointer.
4108 *widget_pointer = NULL;
4113 * @widget: a #GtkWidget
4115 * Flags a widget to be displayed. Any widget that isn't shown will
4116 * not appear on the screen. If you want to show all the widgets in a
4117 * container, it's easier to call gtk_widget_show_all() on the
4118 * container, instead of individually showing the widgets.
4120 * Remember that you have to show the containers containing a widget,
4121 * in addition to the widget itself, before it will appear onscreen.
4123 * When a toplevel container is shown, it is immediately realized and
4124 * mapped; other shown widgets are realized and mapped when their
4125 * toplevel container is realized and mapped.
4128 gtk_widget_show (GtkWidget *widget)
4130 g_return_if_fail (GTK_IS_WIDGET (widget));
4132 if (!gtk_widget_get_visible (widget))
4134 g_object_ref (widget);
4135 gtk_widget_push_verify_invariants (widget);
4137 if (!gtk_widget_is_toplevel (widget))
4138 gtk_widget_queue_resize (widget);
4140 /* see comment in set_parent() for why this should and can be
4143 if (widget->priv->need_compute_expand ||
4144 widget->priv->computed_hexpand ||
4145 widget->priv->computed_vexpand)
4147 if (widget->priv->parent != NULL)
4148 gtk_widget_queue_compute_expand (widget->priv->parent);
4151 g_signal_emit (widget, widget_signals[SHOW], 0);
4152 g_object_notify (G_OBJECT (widget), "visible");
4154 gtk_widget_pop_verify_invariants (widget);
4155 g_object_unref (widget);
4160 gtk_widget_real_show (GtkWidget *widget)
4162 GtkWidgetPrivate *priv = widget->priv;
4164 if (!gtk_widget_get_visible (widget))
4166 priv->visible = TRUE;
4169 gtk_widget_get_mapped (priv->parent) &&
4170 gtk_widget_get_child_visible (widget) &&
4171 !gtk_widget_get_mapped (widget))
4172 gtk_widget_map (widget);
4177 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4180 g_signal_handlers_disconnect_by_func (widget,
4181 gtk_widget_show_map_callback,
4186 * gtk_widget_show_now:
4187 * @widget: a #GtkWidget
4189 * Shows a widget. If the widget is an unmapped toplevel widget
4190 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4191 * loop and wait for the window to actually be mapped. Be careful;
4192 * because the main loop is running, anything can happen during
4196 gtk_widget_show_now (GtkWidget *widget)
4200 g_return_if_fail (GTK_IS_WIDGET (widget));
4202 /* make sure we will get event */
4203 if (!gtk_widget_get_mapped (widget) &&
4204 gtk_widget_is_toplevel (widget))
4206 gtk_widget_show (widget);
4208 g_signal_connect (widget, "map-event",
4209 G_CALLBACK (gtk_widget_show_map_callback),
4213 gtk_main_iteration ();
4216 gtk_widget_show (widget);
4221 * @widget: a #GtkWidget
4223 * Reverses the effects of gtk_widget_show(), causing the widget to be
4224 * hidden (invisible to the user).
4227 gtk_widget_hide (GtkWidget *widget)
4229 g_return_if_fail (GTK_IS_WIDGET (widget));
4231 if (gtk_widget_get_visible (widget))
4233 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4235 g_object_ref (widget);
4236 gtk_widget_push_verify_invariants (widget);
4238 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4239 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4241 /* a parent may now be expand=FALSE since we're hidden. */
4242 if (widget->priv->need_compute_expand ||
4243 widget->priv->computed_hexpand ||
4244 widget->priv->computed_vexpand)
4246 gtk_widget_queue_compute_expand (widget);
4249 g_signal_emit (widget, widget_signals[HIDE], 0);
4250 if (!gtk_widget_is_toplevel (widget))
4251 gtk_widget_queue_resize (widget);
4252 g_object_notify (G_OBJECT (widget), "visible");
4254 gtk_widget_pop_verify_invariants (widget);
4255 g_object_unref (widget);
4260 gtk_widget_real_hide (GtkWidget *widget)
4262 if (gtk_widget_get_visible (widget))
4264 widget->priv->visible = FALSE;
4266 if (gtk_widget_get_mapped (widget))
4267 gtk_widget_unmap (widget);
4272 * gtk_widget_hide_on_delete:
4273 * @widget: a #GtkWidget
4275 * Utility function; intended to be connected to the #GtkWidget::delete-event
4276 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4277 * argument, then returns %TRUE. If connected to ::delete-event, the
4278 * result is that clicking the close button for a window (on the
4279 * window frame, top right corner usually) will hide but not destroy
4280 * the window. By default, GTK+ destroys windows when ::delete-event
4283 * Return value: %TRUE
4286 gtk_widget_hide_on_delete (GtkWidget *widget)
4288 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4290 gtk_widget_hide (widget);
4296 * gtk_widget_show_all:
4297 * @widget: a #GtkWidget
4299 * Recursively shows a widget, and any child widgets (if the widget is
4303 gtk_widget_show_all (GtkWidget *widget)
4305 GtkWidgetClass *class;
4307 g_return_if_fail (GTK_IS_WIDGET (widget));
4309 if (gtk_widget_get_no_show_all (widget))
4312 class = GTK_WIDGET_GET_CLASS (widget);
4314 if (class->show_all)
4315 class->show_all (widget);
4320 * @widget: a #GtkWidget
4322 * This function is only for use in widget implementations. Causes
4323 * a widget to be mapped if it isn't already.
4326 gtk_widget_map (GtkWidget *widget)
4328 GtkWidgetPrivate *priv;
4330 g_return_if_fail (GTK_IS_WIDGET (widget));
4331 g_return_if_fail (gtk_widget_get_visible (widget));
4332 g_return_if_fail (gtk_widget_get_child_visible (widget));
4334 priv = widget->priv;
4336 if (!gtk_widget_get_mapped (widget))
4338 gtk_widget_push_verify_invariants (widget);
4340 if (!gtk_widget_get_realized (widget))
4341 gtk_widget_realize (widget);
4343 g_signal_emit (widget, widget_signals[MAP], 0);
4345 if (!gtk_widget_get_has_window (widget))
4346 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4348 if (widget->priv->context)
4349 _gtk_style_context_update_animating (widget->priv->context);
4351 gtk_widget_pop_verify_invariants (widget);
4357 * @widget: a #GtkWidget
4359 * This function is only for use in widget implementations. Causes
4360 * a widget to be unmapped if it's currently mapped.
4363 gtk_widget_unmap (GtkWidget *widget)
4365 GtkWidgetPrivate *priv;
4367 g_return_if_fail (GTK_IS_WIDGET (widget));
4369 priv = widget->priv;
4371 if (gtk_widget_get_mapped (widget))
4373 gtk_widget_push_verify_invariants (widget);
4375 if (!gtk_widget_get_has_window (widget))
4376 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4377 _gtk_tooltip_hide (widget);
4379 if (widget->priv->context)
4380 _gtk_style_context_update_animating (widget->priv->context);
4382 g_signal_emit (widget, widget_signals[UNMAP], 0);
4384 gtk_widget_pop_verify_invariants (widget);
4386 /* Unset pointer/window info */
4387 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4392 _gtk_widget_enable_device_events (GtkWidget *widget)
4394 GHashTable *device_events;
4395 GHashTableIter iter;
4396 gpointer key, value;
4398 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4403 g_hash_table_iter_init (&iter, device_events);
4405 while (g_hash_table_iter_next (&iter, &key, &value))
4408 GdkEventMask event_mask;
4411 event_mask = GPOINTER_TO_UINT (value);
4412 gtk_widget_add_events_internal (widget, device, event_mask);
4417 get_widget_windows (GtkWidget *widget)
4419 GList *window_list, *last, *l, *children, *ret;
4421 if (gtk_widget_get_has_window (widget))
4422 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4424 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4426 last = g_list_last (window_list);
4429 for (l = window_list; l; l = l->next)
4431 GtkWidget *window_widget = NULL;
4433 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4435 if (widget != window_widget)
4438 ret = g_list_prepend (ret, l->data);
4439 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4443 last = g_list_concat (last, children);
4444 last = g_list_last (last);
4448 g_list_free (window_list);
4454 device_enable_foreach (GtkWidget *widget,
4457 GdkDevice *device = user_data;
4458 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4462 device_disable_foreach (GtkWidget *widget,
4465 GdkDevice *device = user_data;
4466 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4470 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4475 GList *window_list, *l;
4477 window_list = get_widget_windows (widget);
4479 for (l = window_list; l; l = l->next)
4481 GdkEventMask events = 0;
4487 events = gdk_window_get_events (window);
4489 gdk_window_set_device_events (window, device, events);
4492 if (recurse && GTK_IS_CONTAINER (widget))
4495 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4497 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4500 g_list_free (window_list);
4504 gtk_widget_update_devices_mask (GtkWidget *widget,
4507 GList *enabled_devices, *l;
4509 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4511 for (l = enabled_devices; l; l = l->next)
4512 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4515 typedef struct _GtkTickCallbackInfo GtkTickCallbackInfo;
4517 struct _GtkTickCallbackInfo
4522 GtkTickCallback callback;
4524 GDestroyNotify notify;
4526 guint destroyed : 1;
4530 ref_tick_callback_info (GtkTickCallbackInfo *info)
4536 unref_tick_callback_info (GtkWidget *widget,
4537 GtkTickCallbackInfo *info,
4540 GtkWidgetPrivate *priv = widget->priv;
4543 if (info->refcount == 0)
4545 priv->tick_callbacks = g_list_delete_link (priv->tick_callbacks, link);
4547 info->notify (info->user_data);
4548 g_slice_free (GtkTickCallbackInfo, info);
4551 if (priv->tick_callbacks == NULL && priv->realized)
4553 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4554 g_signal_handlers_disconnect_by_func (frame_clock,
4555 (gpointer) gtk_widget_on_frame_clock_update,
4561 destroy_tick_callback_info (GtkWidget *widget,
4562 GtkTickCallbackInfo *info,
4565 if (!info->destroyed)
4567 info->destroyed = TRUE;
4568 unref_tick_callback_info (widget, info, link);
4573 gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
4576 GtkWidgetPrivate *priv = widget->priv;
4579 for (l = priv->tick_callbacks; l;)
4581 GtkTickCallbackInfo *info = l->data;
4584 ref_tick_callback_info (info);
4585 if (!info->destroyed)
4587 if (info->callback (widget,
4589 info->user_data) == G_SOURCE_REMOVE)
4591 destroy_tick_callback_info (widget, info, l);
4596 unref_tick_callback_info (widget, info, l);
4600 if (priv->tick_callbacks != NULL)
4601 gdk_frame_clock_request_phase (frame_clock,
4602 GDK_FRAME_CLOCK_PHASE_UPDATE);
4605 static guint tick_callback_id;
4608 * gtk_widget_add_tick_callback:
4609 * @widget: a #GtkWidget
4610 * @callback: function to call for updating animations
4611 * @user_data: data to pass to @callback
4612 * @notify: function to call to free @user_data when the callback is removed.
4614 * Queues a animation frame update and adds a callback to be called
4615 * before each frame. Until the tick callback is removed, it will be
4616 * called frequently (usually at the frame rate of the output device
4617 * or as quickly as the application an be repainted, whichever is
4618 * slower). For this reason, is most suitable for handling graphics
4619 * that change every frame or every few frames. The tick callback does
4620 * not automatically imply a relayout or repaint. If you want a
4621 * repaint or relayout, and aren't changing widget properties that
4622 * would trigger that (for example, changing the text of a #GtkLabel),
4623 * then you will have to call gtk_widget_queue_resize() or
4624 * gtk_widget_queue_draw_area() yourself.
4626 * gdk_frame_clock_get_frame_time() should generally be used for timing
4627 * continuous animations and
4628 * gdk_frame_timings_get_predicted_presentation_time() if you are
4629 * trying to display isolated frames particular times.
4631 * This is a more convenient alternative to connecting directly to the
4632 * ::update signal of GdkFrameClock, since you don't have to worry about
4633 * when a #GdkFrameClock is assigned to a widget.
4636 gtk_widget_add_tick_callback (GtkWidget *widget,
4637 GtkTickCallback callback,
4639 GDestroyNotify notify)
4641 GtkWidgetPrivate *priv;
4642 GtkTickCallbackInfo *info;
4644 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4646 priv = widget->priv;
4648 if (priv->tick_callbacks == NULL && priv->realized)
4650 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4651 g_signal_connect (frame_clock, "update",
4652 G_CALLBACK (gtk_widget_on_frame_clock_update),
4654 gdk_frame_clock_request_phase (frame_clock,
4655 GDK_FRAME_CLOCK_PHASE_UPDATE);
4658 info = g_slice_new0 (GtkTickCallbackInfo);
4661 info->id = ++tick_callback_id;
4662 info->callback = callback;
4663 info->user_data = user_data;
4664 info->notify = notify;
4666 priv->tick_callbacks = g_list_prepend (priv->tick_callbacks,
4673 gtk_widget_remove_tick_callback (GtkWidget *widget,
4676 GtkWidgetPrivate *priv;
4679 g_return_if_fail (GTK_IS_WIDGET (widget));
4681 priv = widget->priv;
4683 for (l = priv->tick_callbacks; l; l = l->next)
4685 GtkTickCallbackInfo *info = l->data;
4687 destroy_tick_callback_info (widget, info, l);
4692 gtk_widget_connect_frame_clock (GtkWidget *widget,
4693 GdkFrameClock *frame_clock)
4695 GtkWidgetPrivate *priv = widget->priv;
4697 if (GTK_IS_CONTAINER (widget))
4698 _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
4700 if (priv->tick_callbacks != NULL)
4702 g_signal_connect (frame_clock, "update",
4703 G_CALLBACK (gtk_widget_on_frame_clock_update),
4705 gdk_frame_clock_request_phase (frame_clock,
4706 GDK_FRAME_CLOCK_PHASE_UPDATE);
4710 gtk_style_context_set_frame_clock (priv->context, frame_clock);
4714 gtk_widget_disconnect_frame_clock (GtkWidget *widget,
4715 GdkFrameClock *frame_clock)
4717 GtkWidgetPrivate *priv = widget->priv;
4719 if (GTK_IS_CONTAINER (widget))
4720 _gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
4722 if (priv->tick_callbacks)
4723 g_signal_handlers_disconnect_by_func (frame_clock,
4724 (gpointer) gtk_widget_on_frame_clock_update,
4728 gtk_style_context_set_frame_clock (priv->context, NULL);
4732 * gtk_widget_realize:
4733 * @widget: a #GtkWidget
4735 * Creates the GDK (windowing system) resources associated with a
4736 * widget. For example, @widget->window will be created when a widget
4737 * is realized. Normally realization happens implicitly; if you show
4738 * a widget and all its parent containers, then the widget will be
4739 * realized and mapped automatically.
4741 * Realizing a widget requires all
4742 * the widget's parent widgets to be realized; calling
4743 * gtk_widget_realize() realizes the widget's parents in addition to
4744 * @widget itself. If a widget is not yet inside a toplevel window
4745 * when you realize it, bad things will happen.
4747 * This function is primarily used in widget implementations, and
4748 * isn't very useful otherwise. Many times when you think you might
4749 * need it, a better approach is to connect to a signal that will be
4750 * called after the widget is realized automatically, such as
4751 * #GtkWidget::draw. Or simply g_signal_connect () to the
4752 * #GtkWidget::realize signal.
4755 gtk_widget_realize (GtkWidget *widget)
4757 GtkWidgetPrivate *priv;
4758 cairo_region_t *region;
4760 g_return_if_fail (GTK_IS_WIDGET (widget));
4761 g_return_if_fail (widget->priv->anchored ||
4762 GTK_IS_INVISIBLE (widget));
4764 priv = widget->priv;
4766 if (!gtk_widget_get_realized (widget))
4768 gtk_widget_push_verify_invariants (widget);
4771 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4772 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4775 if (priv->parent == NULL &&
4776 !gtk_widget_is_toplevel (widget))
4777 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4778 "inside a toplevel window is not going to work very well. "
4779 "Widgets must be inside a toplevel container before realizing them.");
4781 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4782 gtk_widget_realize (priv->parent);
4784 gtk_widget_ensure_style (widget);
4786 if (priv->style_update_pending)
4787 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4789 g_signal_emit (widget, widget_signals[REALIZE], 0);
4791 gtk_widget_real_set_has_tooltip (widget,
4792 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4795 if (priv->has_shape_mask)
4797 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4798 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4801 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4803 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4805 if (priv->multidevice)
4806 gdk_window_set_support_multidevice (priv->window, TRUE);
4808 _gtk_widget_enable_device_events (widget);
4809 gtk_widget_update_devices_mask (widget, TRUE);
4811 gtk_widget_connect_frame_clock (widget,
4812 gtk_widget_get_frame_clock (widget));
4814 gtk_widget_pop_verify_invariants (widget);
4819 * gtk_widget_unrealize:
4820 * @widget: a #GtkWidget
4822 * This function is only useful in widget implementations.
4823 * Causes a widget to be unrealized (frees all GDK resources
4824 * associated with the widget, such as @widget->window).
4827 gtk_widget_unrealize (GtkWidget *widget)
4829 g_return_if_fail (GTK_IS_WIDGET (widget));
4831 gtk_widget_push_verify_invariants (widget);
4833 if (widget->priv->has_shape_mask)
4834 gtk_widget_shape_combine_region (widget, NULL);
4836 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4837 gtk_widget_input_shape_combine_region (widget, NULL);
4839 if (gtk_widget_get_realized (widget))
4841 g_object_ref (widget);
4843 if (widget->priv->mapped)
4844 gtk_widget_unmap (widget);
4846 gtk_widget_disconnect_frame_clock (widget,
4847 gtk_widget_get_frame_clock (widget));
4849 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4850 g_assert (!widget->priv->mapped);
4851 gtk_widget_set_realized (widget, FALSE);
4853 g_object_unref (widget);
4856 gtk_widget_pop_verify_invariants (widget);
4859 /*****************************************
4861 *****************************************/
4864 * gtk_widget_queue_draw_region:
4865 * @widget: a #GtkWidget
4866 * @region: region to draw
4868 * Invalidates the rectangular area of @widget defined by @region by
4869 * calling gdk_window_invalidate_region() on the widget's window and
4870 * all its child windows. Once the main loop becomes idle (after the
4871 * current batch of events has been processed, roughly), the window
4872 * will receive expose events for the union of all regions that have
4875 * Normally you would only use this function in widget
4876 * implementations. You might also use it to schedule a redraw of a
4877 * #GtkDrawingArea or some portion thereof.
4882 gtk_widget_queue_draw_region (GtkWidget *widget,
4883 const cairo_region_t *region)
4885 GtkWidgetPrivate *priv;
4888 g_return_if_fail (GTK_IS_WIDGET (widget));
4890 priv = widget->priv;
4892 if (!gtk_widget_get_realized (widget))
4895 /* Just return if the widget or one of its ancestors isn't mapped */
4896 for (w = widget; w != NULL; w = w->priv->parent)
4897 if (!gtk_widget_get_mapped (w))
4900 gdk_window_invalidate_region (priv->window, region, TRUE);
4904 * gtk_widget_queue_draw_area:
4905 * @widget: a #GtkWidget
4906 * @x: x coordinate of upper-left corner of rectangle to redraw
4907 * @y: y coordinate of upper-left corner of rectangle to redraw
4908 * @width: width of region to draw
4909 * @height: height of region to draw
4911 * Convenience function that calls gtk_widget_queue_draw_region() on
4912 * the region created from the given coordinates.
4914 * The region here is specified in widget coordinates.
4915 * Widget coordinates are a bit odd; for historical reasons, they are
4916 * defined as @widget->window coordinates for widgets that are not
4917 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4918 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4921 gtk_widget_queue_draw_area (GtkWidget *widget,
4928 cairo_region_t *region;
4930 g_return_if_fail (GTK_IS_WIDGET (widget));
4935 rect.height = height;
4937 region = cairo_region_create_rectangle (&rect);
4938 gtk_widget_queue_draw_region (widget, region);
4939 cairo_region_destroy (region);
4943 * gtk_widget_queue_draw:
4944 * @widget: a #GtkWidget
4946 * Equivalent to calling gtk_widget_queue_draw_area() for the
4947 * entire area of a widget.
4950 gtk_widget_queue_draw (GtkWidget *widget)
4954 g_return_if_fail (GTK_IS_WIDGET (widget));
4956 gtk_widget_get_allocation (widget, &rect);
4958 if (!gtk_widget_get_has_window (widget))
4959 gtk_widget_queue_draw_area (widget,
4960 rect.x, rect.y, rect.width, rect.height);
4962 gtk_widget_queue_draw_area (widget,
4963 0, 0, rect.width, rect.height);
4967 * gtk_widget_queue_resize:
4968 * @widget: a #GtkWidget
4970 * This function is only for use in widget implementations.
4971 * Flags a widget to have its size renegotiated; should
4972 * be called when a widget for some reason has a new size request.
4973 * For example, when you change the text in a #GtkLabel, #GtkLabel
4974 * queues a resize to ensure there's enough space for the new text.
4976 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4977 * from inside its implementation of the GtkWidgetClass::size_allocate
4978 * virtual method. Calls to gtk_widget_queue_resize() from inside
4979 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4982 gtk_widget_queue_resize (GtkWidget *widget)
4984 g_return_if_fail (GTK_IS_WIDGET (widget));
4986 if (gtk_widget_get_realized (widget))
4987 gtk_widget_queue_draw (widget);
4989 _gtk_size_group_queue_resize (widget, 0);
4993 * gtk_widget_queue_resize_no_redraw:
4994 * @widget: a #GtkWidget
4996 * This function works like gtk_widget_queue_resize(),
4997 * except that the widget is not invalidated.
5002 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
5004 g_return_if_fail (GTK_IS_WIDGET (widget));
5006 _gtk_size_group_queue_resize (widget, 0);
5010 * gtk_widget_get_frame_clock:
5011 * @widget: a #GtkWidget
5013 * Obtains the frame clock for a widget. The frame clock is a global
5014 * "ticker" that can be used to drive animations and repaints. The
5015 * most common reason to get the frame clock is to call
5016 * gdk_frame_clock_get_frame_time(), in order to get a time to use for
5017 * animating. For example you might record the start of the animation
5018 * with an initial value from gdk_frame_clock_get_frame_time(), and
5019 * then update the animation by calling
5020 * gdk_frame_clock_get_frame_time() again during each repaint.
5022 * gdk_frame_clock_request_phase() will result in a new frame on the
5023 * clock, but won't necessarily repaint any widgets. To repaint a
5024 * widget, you have to use gtk_widget_queue_draw() which invalidates
5025 * the widget (thus scheduling it to receive a draw on the next
5026 * frame). gtk_widget_queue_draw() will also end up requesting a frame
5027 * on the appropriate frame clock.
5029 * A widget's frame clock will not change while the widget is
5030 * mapped. Reparenting a widget (which implies a temporary unmap) can
5031 * change the widget's frame clock.
5033 * Unrealized widgets do not have a frame clock.
5036 * Return value: (transfer none): a #GdkFrameClock (or #NULL if widget is unrealized)
5039 gtk_widget_get_frame_clock (GtkWidget *widget)
5041 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5043 if (widget->priv->realized)
5045 /* We use gtk_widget_get_toplevel() here to make it explicit that
5046 * the frame clock is a property of the toplevel that a widget
5047 * is anchored to; gdk_window_get_toplevel() will go up the
5048 * hierarchy anyways, but should squash any funny business with
5049 * reparenting windows and widgets.
5051 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5052 GdkWindow *window = gtk_widget_get_window (toplevel);
5053 g_assert (window != NULL);
5055 return gdk_window_get_frame_clock (window);
5064 * gtk_widget_size_request:
5065 * @widget: a #GtkWidget
5066 * @requisition: (out): a #GtkRequisition to be filled in
5068 * This function is typically used when implementing a #GtkContainer
5069 * subclass. Obtains the preferred size of a widget. The container
5070 * uses this information to arrange its child widgets and decide what
5071 * size allocations to give them with gtk_widget_size_allocate().
5073 * You can also call this function from an application, with some
5074 * caveats. Most notably, getting a size request requires the widget
5075 * to be associated with a screen, because font information may be
5076 * needed. Multihead-aware applications should keep this in mind.
5078 * Also remember that the size request is not necessarily the size
5079 * a widget will actually be allocated.
5081 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5084 gtk_widget_size_request (GtkWidget *widget,
5085 GtkRequisition *requisition)
5087 g_return_if_fail (GTK_IS_WIDGET (widget));
5089 gtk_widget_get_preferred_size (widget, requisition, NULL);
5093 * gtk_widget_get_child_requisition:
5094 * @widget: a #GtkWidget
5095 * @requisition: (out): a #GtkRequisition to be filled in
5097 * This function is only for use in widget implementations. Obtains
5098 * @widget->requisition, unless someone has forced a particular
5099 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
5100 * in which case it returns that geometry instead of the widget's
5103 * This function differs from gtk_widget_size_request() in that
5104 * it retrieves the last size request value from @widget->requisition,
5105 * while gtk_widget_size_request() actually calls the "size_request" method
5106 * on @widget to compute the size request and fill in @widget->requisition,
5107 * and only then returns @widget->requisition.
5109 * Because this function does not call the "size_request" method, it
5110 * can only be used when you know that @widget->requisition is
5111 * up-to-date, that is, gtk_widget_size_request() has been called
5112 * since the last time a resize was queued. In general, only container
5113 * implementations have this information; applications should use
5114 * gtk_widget_size_request().
5117 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5120 gtk_widget_get_child_requisition (GtkWidget *widget,
5121 GtkRequisition *requisition)
5123 gtk_widget_get_preferred_size (widget, requisition, NULL);
5127 invalidate_predicate (GdkWindow *window,
5132 gdk_window_get_user_data (window, &user_data);
5134 return (user_data == data);
5137 /* Invalidate @region in widget->window and all children
5138 * of widget->window owned by widget. @region is in the
5139 * same coordinates as widget->allocation and will be
5140 * modified by this call.
5143 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
5144 cairo_region_t *region)
5146 GtkWidgetPrivate *priv = widget->priv;
5148 if (!gtk_widget_get_realized (widget))
5151 if (gtk_widget_get_has_window (widget) && priv->parent)
5155 gdk_window_get_position (priv->window, &x, &y);
5156 cairo_region_translate (region, -x, -y);
5159 gdk_window_invalidate_maybe_recurse (priv->window, region,
5160 invalidate_predicate, widget);
5164 * gtk_widget_size_allocate:
5165 * @widget: a #GtkWidget
5166 * @allocation: position and size to be allocated to @widget
5168 * This function is only used by #GtkContainer subclasses, to assign a size
5169 * and position to their child widgets.
5171 * In this function, the allocation may be adjusted. It will be forced
5172 * to a 1x1 minimum size, and the adjust_size_allocation virtual
5173 * method on the child will be used to adjust the allocation. Standard
5174 * adjustments include removing the widget's margins, and applying the
5175 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
5178 gtk_widget_size_allocate (GtkWidget *widget,
5179 GtkAllocation *allocation)
5181 GtkWidgetPrivate *priv;
5182 GdkRectangle real_allocation;
5183 GdkRectangle old_allocation;
5184 GdkRectangle adjusted_allocation;
5185 gboolean alloc_needed;
5186 gboolean size_changed;
5187 gboolean position_changed;
5188 gint natural_width, natural_height, dummy;
5189 gint min_width, min_height;
5191 priv = widget->priv;
5193 g_return_if_fail (GTK_IS_WIDGET (widget));
5195 if (!priv->visible && !gtk_widget_is_toplevel (widget))
5198 gtk_widget_push_verify_invariants (widget);
5200 #ifdef G_ENABLE_DEBUG
5201 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5212 parent = gtk_widget_get_parent (parent);
5215 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
5216 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
5217 2 * depth, " ", name,
5218 allocation->width, allocation->height);
5220 #endif /* G_ENABLE_DEBUG */
5222 alloc_needed = priv->alloc_needed;
5223 /* Preserve request/allocate ordering */
5224 priv->alloc_needed = FALSE;
5226 old_allocation = priv->allocation;
5227 real_allocation = *allocation;
5229 adjusted_allocation = real_allocation;
5230 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
5232 /* Go ahead and request the height for allocated width, note that the internals
5233 * of get_height_for_width will internally limit the for_size to natural size
5234 * when aligning implicitly.
5236 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
5237 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
5241 /* Go ahead and request the width for allocated height, note that the internals
5242 * of get_width_for_height will internally limit the for_size to natural size
5243 * when aligning implicitly.
5245 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
5246 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
5249 #ifdef G_ENABLE_DEBUG
5250 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5252 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
5253 !GTK_IS_SCROLLABLE (widget))
5254 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
5255 "Allocation is %dx%d, but minimum required size is %dx%d.",
5256 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
5257 G_OBJECT_TYPE_NAME (widget), widget,
5258 real_allocation.width, real_allocation.height,
5259 min_width, min_height);
5262 /* Now that we have the right natural height and width, go ahead and remove any margins from the
5263 * allocated sizes and possibly limit them to the natural sizes */
5264 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5265 GTK_ORIENTATION_HORIZONTAL,
5268 &adjusted_allocation.x,
5269 &adjusted_allocation.width);
5270 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5271 GTK_ORIENTATION_VERTICAL,
5274 &adjusted_allocation.y,
5275 &adjusted_allocation.height);
5277 if (adjusted_allocation.x < real_allocation.x ||
5278 adjusted_allocation.y < real_allocation.y ||
5279 (adjusted_allocation.x + adjusted_allocation.width) >
5280 (real_allocation.x + real_allocation.width) ||
5281 (adjusted_allocation.y + adjusted_allocation.height >
5282 real_allocation.y + real_allocation.height))
5284 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",
5285 G_OBJECT_TYPE_NAME (widget), widget,
5286 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5287 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5288 adjusted_allocation = real_allocation; /* veto it */
5292 real_allocation = adjusted_allocation;
5295 if (real_allocation.width < 0 || real_allocation.height < 0)
5297 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5298 real_allocation.width,
5299 real_allocation.height);
5302 real_allocation.width = MAX (real_allocation.width, 1);
5303 real_allocation.height = MAX (real_allocation.height, 1);
5305 size_changed = (old_allocation.width != real_allocation.width ||
5306 old_allocation.height != real_allocation.height);
5307 position_changed = (old_allocation.x != real_allocation.x ||
5308 old_allocation.y != real_allocation.y);
5310 if (!alloc_needed && !size_changed && !position_changed)
5313 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5315 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5316 priv->alloc_needed = FALSE;
5318 if (gtk_widget_get_mapped (widget))
5320 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5322 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5324 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5325 cairo_region_union_rectangle (invalidate, &old_allocation);
5327 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5328 cairo_region_destroy (invalidate);
5333 if (priv->redraw_on_alloc)
5335 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5337 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5338 cairo_region_union_rectangle (invalidate, &old_allocation);
5340 gtk_widget_invalidate_widget_windows (widget, invalidate);
5341 cairo_region_destroy (invalidate);
5346 if ((size_changed || position_changed) && priv->parent &&
5347 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5349 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5350 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5351 cairo_region_destroy (invalidate);
5355 gtk_widget_pop_verify_invariants (widget);
5359 * gtk_widget_common_ancestor:
5360 * @widget_a: a #GtkWidget
5361 * @widget_b: a #GtkWidget
5363 * Find the common ancestor of @widget_a and @widget_b that
5364 * is closest to the two widgets.
5366 * Return value: the closest common ancestor of @widget_a and
5367 * @widget_b or %NULL if @widget_a and @widget_b do not
5368 * share a common ancestor.
5371 gtk_widget_common_ancestor (GtkWidget *widget_a,
5372 GtkWidget *widget_b)
5374 GtkWidget *parent_a;
5375 GtkWidget *parent_b;
5379 parent_a = widget_a;
5380 while (parent_a->priv->parent)
5382 parent_a = parent_a->priv->parent;
5386 parent_b = widget_b;
5387 while (parent_b->priv->parent)
5389 parent_b = parent_b->priv->parent;
5393 if (parent_a != parent_b)
5396 while (depth_a > depth_b)
5398 widget_a = widget_a->priv->parent;
5402 while (depth_b > depth_a)
5404 widget_b = widget_b->priv->parent;
5408 while (widget_a != widget_b)
5410 widget_a = widget_a->priv->parent;
5411 widget_b = widget_b->priv->parent;
5418 * gtk_widget_translate_coordinates:
5419 * @src_widget: a #GtkWidget
5420 * @dest_widget: a #GtkWidget
5421 * @src_x: X position relative to @src_widget
5422 * @src_y: Y position relative to @src_widget
5423 * @dest_x: (out): location to store X position relative to @dest_widget
5424 * @dest_y: (out): location to store Y position relative to @dest_widget
5426 * Translate coordinates relative to @src_widget's allocation to coordinates
5427 * relative to @dest_widget's allocations. In order to perform this
5428 * operation, both widgets must be realized, and must share a common
5431 * Return value: %FALSE if either widget was not realized, or there
5432 * was no common ancestor. In this case, nothing is stored in
5433 * *@dest_x and *@dest_y. Otherwise %TRUE.
5436 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5437 GtkWidget *dest_widget,
5443 GtkWidgetPrivate *src_priv = src_widget->priv;
5444 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5445 GtkWidget *ancestor;
5447 GList *dest_list = NULL;
5449 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5450 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5452 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5453 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5456 /* Translate from allocation relative to window relative */
5457 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5460 gdk_window_get_position (src_priv->window, &wx, &wy);
5462 src_x -= wx - src_priv->allocation.x;
5463 src_y -= wy - src_priv->allocation.y;
5467 src_x += src_priv->allocation.x;
5468 src_y += src_priv->allocation.y;
5471 /* Translate to the common ancestor */
5472 window = src_priv->window;
5473 while (window != ancestor->priv->window)
5477 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5482 window = gdk_window_get_effective_parent (window);
5484 if (!window) /* Handle GtkHandleBox */
5489 window = dest_priv->window;
5490 while (window != ancestor->priv->window)
5492 dest_list = g_list_prepend (dest_list, window);
5494 window = gdk_window_get_effective_parent (window);
5496 if (!window) /* Handle GtkHandleBox */
5498 g_list_free (dest_list);
5507 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5512 dest_list = g_list_remove (dest_list, dest_list->data);
5515 /* Translate from window relative to allocation relative */
5516 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5519 gdk_window_get_position (dest_priv->window, &wx, &wy);
5521 src_x += wx - dest_priv->allocation.x;
5522 src_y += wy - dest_priv->allocation.y;
5526 src_x -= dest_priv->allocation.x;
5527 src_y -= dest_priv->allocation.y;
5539 gtk_widget_real_size_allocate (GtkWidget *widget,
5540 GtkAllocation *allocation)
5542 GtkWidgetPrivate *priv = widget->priv;
5544 priv->allocation = *allocation;
5546 if (gtk_widget_get_realized (widget) &&
5547 gtk_widget_get_has_window (widget))
5549 gdk_window_move_resize (priv->window,
5550 allocation->x, allocation->y,
5551 allocation->width, allocation->height);
5555 /* translate initial/final into start/end */
5557 effective_align (GtkAlign align,
5558 GtkTextDirection direction)
5562 case GTK_ALIGN_START:
5563 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5565 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5572 adjust_for_align (GtkAlign align,
5574 gint *allocated_pos,
5575 gint *allocated_size)
5579 case GTK_ALIGN_FILL:
5580 /* change nothing */
5582 case GTK_ALIGN_START:
5583 /* keep *allocated_pos where it is */
5584 *allocated_size = MIN (*allocated_size, *natural_size);
5587 if (*allocated_size > *natural_size)
5589 *allocated_pos += (*allocated_size - *natural_size);
5590 *allocated_size = *natural_size;
5593 case GTK_ALIGN_CENTER:
5594 if (*allocated_size > *natural_size)
5596 *allocated_pos += (*allocated_size - *natural_size) / 2;
5597 *allocated_size = MIN (*allocated_size, *natural_size);
5604 adjust_for_margin(gint start_margin,
5608 gint *allocated_pos,
5609 gint *allocated_size)
5611 *minimum_size -= (start_margin + end_margin);
5612 *natural_size -= (start_margin + end_margin);
5613 *allocated_pos += start_margin;
5614 *allocated_size -= (start_margin + end_margin);
5618 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5619 GtkOrientation orientation,
5622 gint *allocated_pos,
5623 gint *allocated_size)
5625 const GtkWidgetAuxInfo *aux_info;
5627 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5629 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5631 adjust_for_margin (aux_info->margin.left,
5632 aux_info->margin.right,
5633 minimum_size, natural_size,
5634 allocated_pos, allocated_size);
5635 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5636 natural_size, allocated_pos, allocated_size);
5640 adjust_for_margin (aux_info->margin.top,
5641 aux_info->margin.bottom,
5642 minimum_size, natural_size,
5643 allocated_pos, allocated_size);
5644 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5645 natural_size, allocated_pos, allocated_size);
5650 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5653 GtkWidgetPrivate *priv = widget->priv;
5655 /* widgets must be onscreen for accels to take effect */
5656 return gtk_widget_is_sensitive (widget) &&
5657 gtk_widget_is_drawable (widget) &&
5658 gdk_window_is_viewable (priv->window);
5662 * gtk_widget_can_activate_accel:
5663 * @widget: a #GtkWidget
5664 * @signal_id: the ID of a signal installed on @widget
5666 * Determines whether an accelerator that activates the signal
5667 * identified by @signal_id can currently be activated.
5668 * This is done by emitting the #GtkWidget::can-activate-accel
5669 * signal on @widget; if the signal isn't overridden by a
5670 * handler or in a derived widget, then the default check is
5671 * that the widget must be sensitive, and the widget and all
5672 * its ancestors mapped.
5674 * Return value: %TRUE if the accelerator can be activated.
5679 gtk_widget_can_activate_accel (GtkWidget *widget,
5682 gboolean can_activate = FALSE;
5683 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5684 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5685 return can_activate;
5694 closure_accel_activate (GClosure *closure,
5695 GValue *return_value,
5696 guint n_param_values,
5697 const GValue *param_values,
5698 gpointer invocation_hint,
5699 gpointer marshal_data)
5701 AccelClosure *aclosure = (AccelClosure*) closure;
5702 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5705 g_signal_emit (closure->data, aclosure->signal_id, 0);
5707 /* whether accelerator was handled */
5708 g_value_set_boolean (return_value, can_activate);
5712 closures_destroy (gpointer data)
5714 GSList *slist, *closures = data;
5716 for (slist = closures; slist; slist = slist->next)
5718 g_closure_invalidate (slist->data);
5719 g_closure_unref (slist->data);
5721 g_slist_free (closures);
5725 widget_new_accel_closure (GtkWidget *widget,
5728 AccelClosure *aclosure;
5729 GClosure *closure = NULL;
5730 GSList *slist, *closures;
5732 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5733 for (slist = closures; slist; slist = slist->next)
5734 if (!gtk_accel_group_from_accel_closure (slist->data))
5736 /* reuse this closure */
5737 closure = slist->data;
5742 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5743 closures = g_slist_prepend (closures, g_closure_ref (closure));
5744 g_closure_sink (closure);
5745 g_closure_set_marshal (closure, closure_accel_activate);
5747 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5749 aclosure = (AccelClosure*) closure;
5750 g_assert (closure->data == widget);
5751 g_assert (closure->marshal == closure_accel_activate);
5752 aclosure->signal_id = signal_id;
5758 * gtk_widget_add_accelerator:
5759 * @widget: widget to install an accelerator on
5760 * @accel_signal: widget signal to emit on accelerator activation
5761 * @accel_group: accel group for this widget, added to its toplevel
5762 * @accel_key: GDK keyval of the accelerator
5763 * @accel_mods: modifier key combination of the accelerator
5764 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5766 * Installs an accelerator for this @widget in @accel_group that causes
5767 * @accel_signal to be emitted if the accelerator is activated.
5768 * The @accel_group needs to be added to the widget's toplevel via
5769 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5770 * Accelerators added through this function are not user changeable during
5771 * runtime. If you want to support accelerators that can be changed by the
5772 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5773 * gtk_menu_item_set_accel_path() instead.
5776 gtk_widget_add_accelerator (GtkWidget *widget,
5777 const gchar *accel_signal,
5778 GtkAccelGroup *accel_group,
5780 GdkModifierType accel_mods,
5781 GtkAccelFlags accel_flags)
5786 g_return_if_fail (GTK_IS_WIDGET (widget));
5787 g_return_if_fail (accel_signal != NULL);
5788 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5790 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5791 if (!query.signal_id ||
5792 !(query.signal_flags & G_SIGNAL_ACTION) ||
5793 query.return_type != G_TYPE_NONE ||
5796 /* hmm, should be elaborate enough */
5797 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5798 G_OBJECT_TYPE_NAME (widget), accel_signal);
5802 closure = widget_new_accel_closure (widget, query.signal_id);
5804 g_object_ref (widget);
5806 /* install the accelerator. since we don't map this onto an accel_path,
5807 * the accelerator will automatically be locked.
5809 gtk_accel_group_connect (accel_group,
5812 accel_flags | GTK_ACCEL_LOCKED,
5815 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5817 g_object_unref (widget);
5821 * gtk_widget_remove_accelerator:
5822 * @widget: widget to install an accelerator on
5823 * @accel_group: accel group for this widget
5824 * @accel_key: GDK keyval of the accelerator
5825 * @accel_mods: modifier key combination of the accelerator
5827 * Removes an accelerator from @widget, previously installed with
5828 * gtk_widget_add_accelerator().
5830 * Returns: whether an accelerator was installed and could be removed
5833 gtk_widget_remove_accelerator (GtkWidget *widget,
5834 GtkAccelGroup *accel_group,
5836 GdkModifierType accel_mods)
5838 GtkAccelGroupEntry *ag_entry;
5839 GList *slist, *clist;
5842 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5843 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5845 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5846 clist = gtk_widget_list_accel_closures (widget);
5847 for (slist = clist; slist; slist = slist->next)
5851 for (i = 0; i < n; i++)
5852 if (slist->data == (gpointer) ag_entry[i].closure)
5854 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5856 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5858 g_list_free (clist);
5863 g_list_free (clist);
5865 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5866 accel_key, accel_mods, accel_group,
5867 G_OBJECT_TYPE_NAME (widget), widget);
5873 * gtk_widget_list_accel_closures:
5874 * @widget: widget to list accelerator closures for
5876 * Lists the closures used by @widget for accelerator group connections
5877 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5878 * The closures can be used to monitor accelerator changes on @widget,
5879 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5880 * #GtkAccelGroup of a closure which can be found out with
5881 * gtk_accel_group_from_accel_closure().
5883 * Return value: (transfer container) (element-type GClosure):
5884 * a newly allocated #GList of closures
5887 gtk_widget_list_accel_closures (GtkWidget *widget)
5890 GList *clist = NULL;
5892 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5894 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5895 if (gtk_accel_group_from_accel_closure (slist->data))
5896 clist = g_list_prepend (clist, slist->data);
5902 GtkAccelGroup *accel_group;
5907 destroy_accel_path (gpointer data)
5909 AccelPath *apath = data;
5911 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5913 /* closures_destroy takes care of unrefing the closure */
5914 g_object_unref (apath->accel_group);
5916 g_slice_free (AccelPath, apath);
5921 * gtk_widget_set_accel_path:
5922 * @widget: a #GtkWidget
5923 * @accel_path: (allow-none): path used to look up the accelerator
5924 * @accel_group: (allow-none): a #GtkAccelGroup.
5926 * Given an accelerator group, @accel_group, and an accelerator path,
5927 * @accel_path, sets up an accelerator in @accel_group so whenever the
5928 * key binding that is defined for @accel_path is pressed, @widget
5929 * will be activated. This removes any accelerators (for any
5930 * accelerator group) installed by previous calls to
5931 * gtk_widget_set_accel_path(). Associating accelerators with
5932 * paths allows them to be modified by the user and the modifications
5933 * to be saved for future use. (See gtk_accel_map_save().)
5935 * This function is a low level function that would most likely
5936 * be used by a menu creation system like #GtkUIManager. If you
5937 * use #GtkUIManager, setting up accelerator paths will be done
5940 * Even when you you aren't using #GtkUIManager, if you only want to
5941 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5942 * provides a somewhat more convenient interface.
5944 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5945 * pass a static string, you can save some memory by interning it first with
5946 * g_intern_static_string().
5949 gtk_widget_set_accel_path (GtkWidget *widget,
5950 const gchar *accel_path,
5951 GtkAccelGroup *accel_group)
5955 g_return_if_fail (GTK_IS_WIDGET (widget));
5956 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5960 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5961 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5963 gtk_accel_map_add_entry (accel_path, 0, 0);
5964 apath = g_slice_new (AccelPath);
5965 apath->accel_group = g_object_ref (accel_group);
5966 apath->path_quark = g_quark_from_string (accel_path);
5967 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5972 /* also removes possible old settings */
5973 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5976 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5978 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5982 _gtk_widget_get_accel_path (GtkWidget *widget,
5987 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5989 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5991 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5992 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5996 * gtk_widget_mnemonic_activate:
5997 * @widget: a #GtkWidget
5998 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
6000 * Emits the #GtkWidget::mnemonic-activate signal.
6002 * The default handler for this signal activates the @widget if
6003 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
6006 * Returns: %TRUE if the signal has been handled
6009 gtk_widget_mnemonic_activate (GtkWidget *widget,
6010 gboolean group_cycling)
6014 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6016 group_cycling = group_cycling != FALSE;
6017 if (!gtk_widget_is_sensitive (widget))
6020 g_signal_emit (widget,
6021 widget_signals[MNEMONIC_ACTIVATE],
6029 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
6030 gboolean group_cycling)
6032 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
6033 gtk_widget_activate (widget);
6034 else if (gtk_widget_get_can_focus (widget))
6035 gtk_widget_grab_focus (widget);
6038 g_warning ("widget `%s' isn't suitable for mnemonic activation",
6039 G_OBJECT_TYPE_NAME (widget));
6040 gtk_widget_error_bell (widget);
6045 static const cairo_user_data_key_t event_key;
6048 _gtk_cairo_get_event (cairo_t *cr)
6050 g_return_val_if_fail (cr != NULL, NULL);
6052 return cairo_get_user_data (cr, &event_key);
6056 gtk_cairo_set_event (cairo_t *cr,
6057 GdkEventExpose *event)
6059 cairo_set_user_data (cr, &event_key, event, NULL);
6063 * gtk_cairo_should_draw_window:
6064 * @cr: a cairo context
6065 * @window: the window to check. @window may not be an input-only
6068 * This function is supposed to be called in #GtkWidget::draw
6069 * implementations for widgets that support multiple windows.
6070 * @cr must be untransformed from invoking of the draw function.
6071 * This function will return %TRUE if the contents of the given
6072 * @window are supposed to be drawn and %FALSE otherwise. Note
6073 * that when the drawing was not initiated by the windowing
6074 * system this function will return %TRUE for all windows, so
6075 * you need to draw the bottommost window first. Also, do not
6076 * use "else if" statements to check which window should be drawn.
6078 * Returns: %TRUE if @window should be drawn
6083 gtk_cairo_should_draw_window (cairo_t *cr,
6086 GdkEventExpose *event;
6088 g_return_val_if_fail (cr != NULL, FALSE);
6089 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
6091 event = _gtk_cairo_get_event (cr);
6093 return event == NULL ||
6094 event->window == window;
6098 gtk_widget_get_clip_draw (GtkWidget *widget)
6100 /* labels are not clipped, because clipping them would cause
6101 * mnemonics to not appear on characters that go beyond the
6103 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
6105 if (GTK_IS_LABEL (widget))
6111 /* code shared by gtk_container_propagate_draw() and
6115 _gtk_widget_draw_internal (GtkWidget *widget,
6117 gboolean clip_to_size)
6119 if (!gtk_widget_is_drawable (widget))
6122 clip_to_size &= gtk_widget_get_clip_draw (widget);
6126 cairo_rectangle (cr,
6128 widget->priv->allocation.width,
6129 widget->priv->allocation.height);
6133 if (gdk_cairo_get_clip_rectangle (cr, NULL))
6137 g_signal_emit (widget, widget_signals[DRAW],
6141 if (cairo_status (cr) &&
6142 _gtk_cairo_get_event (cr))
6144 /* We check the event so we only warn about internal GTK calls.
6145 * Errors might come from PDF streams having write failures and
6146 * we don't want to spam stderr in that case.
6147 * We do want to catch errors from
6149 g_warning ("drawing failure for widget `%s': %s",
6150 G_OBJECT_TYPE_NAME (widget),
6151 cairo_status_to_string (cairo_status (cr)));
6158 * @widget: the widget to draw. It must be drawable (see
6159 * gtk_widget_is_drawable()) and a size must have been allocated.
6160 * @cr: a cairo context to draw to
6162 * Draws @widget to @cr. The top left corner of the widget will be
6163 * drawn to the currently set origin point of @cr.
6165 * You should pass a cairo context as @cr argument that is in an
6166 * original state. Otherwise the resulting drawing is undefined. For
6167 * example changing the operator using cairo_set_operator() or the
6168 * line width using cairo_set_line_width() might have unwanted side
6170 * You may however change the context's transform matrix - like with
6171 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
6172 * region with cairo_clip() prior to calling this function. Also, it
6173 * is fine to modify the context with cairo_save() and
6174 * cairo_push_group() prior to calling this function.
6176 * <note><para>Special purpose widgets may contain special code for
6177 * rendering to the screen and might appear differently on screen
6178 * and when rendered using gtk_widget_draw().</para></note>
6183 gtk_widget_draw (GtkWidget *widget,
6186 GdkEventExpose *tmp_event;
6188 g_return_if_fail (GTK_IS_WIDGET (widget));
6189 g_return_if_fail (!widget->priv->alloc_needed);
6190 g_return_if_fail (cr != NULL);
6193 /* We have to reset the event here so that draw functions can call
6194 * gtk_widget_draw() on random other widgets and get the desired
6195 * effect: Drawing all contents, not just the current window.
6197 tmp_event = _gtk_cairo_get_event (cr);
6198 gtk_cairo_set_event (cr, NULL);
6200 _gtk_widget_draw_internal (widget, cr, TRUE);
6202 gtk_cairo_set_event (cr, tmp_event);
6207 gtk_widget_real_key_press_event (GtkWidget *widget,
6210 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6214 gtk_widget_real_key_release_event (GtkWidget *widget,
6217 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6221 gtk_widget_real_focus_in_event (GtkWidget *widget,
6222 GdkEventFocus *event)
6224 gtk_widget_queue_draw (widget);
6230 gtk_widget_real_focus_out_event (GtkWidget *widget,
6231 GdkEventFocus *event)
6233 gtk_widget_queue_draw (widget);
6239 gtk_widget_real_touch_event (GtkWidget *widget,
6240 GdkEventTouch *event)
6243 gboolean return_val;
6246 if (!event->emulating_pointer)
6249 if (event->type == GDK_TOUCH_BEGIN ||
6250 event->type == GDK_TOUCH_END)
6254 if (event->type == GDK_TOUCH_BEGIN)
6256 type = GDK_BUTTON_PRESS;
6257 signum = BUTTON_PRESS_EVENT;
6261 type = GDK_BUTTON_RELEASE;
6262 signum = BUTTON_RELEASE_EVENT;
6264 bevent = gdk_event_new (type);
6265 bevent->any.window = g_object_ref (event->window);
6266 bevent->any.send_event = FALSE;
6267 bevent->button.time = event->time;
6268 bevent->button.state = event->state;
6269 bevent->button.button = 1;
6270 bevent->button.x_root = event->x_root;
6271 bevent->button.y_root = event->y_root;
6272 bevent->button.x = event->x;
6273 bevent->button.y = event->y;
6274 bevent->button.device = event->device;
6275 bevent->button.axes = g_memdup (event->axes,
6276 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6277 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6279 else if (event->type == GDK_TOUCH_UPDATE)
6281 signum = MOTION_NOTIFY_EVENT;
6282 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6283 bevent->any.window = g_object_ref (event->window);
6284 bevent->any.send_event = FALSE;
6285 bevent->motion.time = event->time;
6286 bevent->motion.state = event->state;
6287 bevent->motion.x_root = event->x_root;
6288 bevent->motion.y_root = event->y_root;
6289 bevent->motion.x = event->x;
6290 bevent->motion.y = event->y;
6291 bevent->motion.device = event->device;
6292 bevent->motion.is_hint = FALSE;
6293 bevent->motion.axes = g_memdup (event->axes,
6294 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6295 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6300 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6302 gdk_event_free (bevent);
6308 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6309 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6313 * @widget: a #GtkWidget
6314 * @event: a #GdkEvent
6316 * Rarely-used function. This function is used to emit
6317 * the event signals on a widget (those signals should never
6318 * be emitted without using this function to do so).
6319 * If you want to synthesize an event though, don't use this function;
6320 * instead, use gtk_main_do_event() so the event will behave as if
6321 * it were in the event queue. Don't synthesize expose events; instead,
6322 * use gdk_window_invalidate_rect() to invalidate a region of the
6325 * Return value: return from the event signal emission (%TRUE if
6326 * the event was handled)
6329 gtk_widget_event (GtkWidget *widget,
6332 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6333 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6335 if (event->type == GDK_EXPOSE)
6337 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6338 "the same effect, call gdk_window_invalidate_rect/region(), "
6339 "followed by gdk_window_process_updates().");
6343 return gtk_widget_event_internal (widget, event);
6347 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6348 GtkCapturedEventHandler callback)
6350 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6354 _gtk_widget_captured_event (GtkWidget *widget,
6357 gboolean return_val = FALSE;
6358 GtkCapturedEventHandler handler;
6360 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6361 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6363 if (event->type == GDK_EXPOSE)
6365 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6366 "the same effect, call gdk_window_invalidate_rect/region(), "
6367 "followed by gdk_window_process_updates().");
6371 if (!event_window_is_still_viewable (event))
6374 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6378 g_object_ref (widget);
6380 return_val = handler (widget, event);
6381 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6383 /* The widget that was originally to receive the event
6384 * handles motion hints, but the capturing widget might
6385 * not, so ensure we get further motion events.
6388 event->type == GDK_MOTION_NOTIFY &&
6389 event->motion.is_hint &&
6390 (gdk_window_get_events (event->any.window) &
6391 GDK_POINTER_MOTION_HINT_MASK) != 0)
6392 gdk_event_request_motions (&event->motion);
6394 g_object_unref (widget);
6399 /* Returns TRUE if a translation should be done */
6401 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6406 GdkWindow *w, *widget_window;
6408 if (!gtk_widget_get_has_window (widget))
6410 *x = -widget->priv->allocation.x;
6411 *y = -widget->priv->allocation.y;
6419 widget_window = gtk_widget_get_window (widget);
6421 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6424 gdk_window_get_position (w, &wx, &wy);
6441 * gtk_cairo_transform_to_window:
6442 * @cr: the cairo context to transform
6443 * @widget: the widget the context is currently centered for
6444 * @window: the window to transform the context to
6446 * Transforms the given cairo context @cr that from @widget-relative
6447 * coordinates to @window-relative coordinates.
6448 * If the @widget's window is not an ancestor of @window, no
6449 * modification will be applied.
6451 * This is the inverse to the transformation GTK applies when
6452 * preparing an expose event to be emitted with the #GtkWidget::draw
6453 * signal. It is intended to help porting multiwindow widgets from
6454 * GTK+ 2 to the rendering architecture of GTK+ 3.
6459 gtk_cairo_transform_to_window (cairo_t *cr,
6465 g_return_if_fail (cr != NULL);
6466 g_return_if_fail (GTK_IS_WIDGET (widget));
6467 g_return_if_fail (GDK_IS_WINDOW (window));
6469 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6470 cairo_translate (cr, x, y);
6474 * gtk_widget_send_expose:
6475 * @widget: a #GtkWidget
6476 * @event: a expose #GdkEvent
6478 * Very rarely-used function. This function is used to emit
6479 * an expose event on a widget. This function is not normally used
6480 * directly. The only time it is used is when propagating an expose
6481 * event to a child %NO_WINDOW widget, and that is normally done
6482 * using gtk_container_propagate_draw().
6484 * If you want to force an area of a window to be redrawn,
6485 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6486 * To cause the redraw to be done immediately, follow that call
6487 * with a call to gdk_window_process_updates().
6489 * Return value: return from the event signal emission (%TRUE if
6490 * the event was handled)
6493 gtk_widget_send_expose (GtkWidget *widget,
6496 gboolean result = FALSE;
6501 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6502 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6503 g_return_val_if_fail (event != NULL, TRUE);
6504 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6506 cr = gdk_cairo_create (event->expose.window);
6507 gtk_cairo_set_event (cr, &event->expose);
6509 gdk_cairo_region (cr, event->expose.region);
6512 do_clip = _gtk_widget_get_translation_to_window (widget,
6513 event->expose.window,
6515 cairo_translate (cr, -x, -y);
6517 _gtk_widget_draw_internal (widget, cr, do_clip);
6519 /* unset here, so if someone keeps a reference to cr we
6520 * don't leak the window. */
6521 gtk_cairo_set_event (cr, NULL);
6528 event_window_is_still_viewable (GdkEvent *event)
6530 /* Check that we think the event's window is viewable before
6531 * delivering the event, to prevent suprises. We do this here
6532 * at the last moment, since the event may have been queued
6533 * up behind other events, held over a recursive main loop, etc.
6535 switch (event->type)
6538 case GDK_MOTION_NOTIFY:
6539 case GDK_BUTTON_PRESS:
6540 case GDK_2BUTTON_PRESS:
6541 case GDK_3BUTTON_PRESS:
6543 case GDK_ENTER_NOTIFY:
6544 case GDK_PROXIMITY_IN:
6546 return event->any.window && gdk_window_is_viewable (event->any.window);
6549 /* The following events are the second half of paired events;
6550 * we always deliver them to deal with widgets that clean up
6551 * on the second half.
6553 case GDK_BUTTON_RELEASE:
6554 case GDK_KEY_RELEASE:
6555 case GDK_LEAVE_NOTIFY:
6556 case GDK_PROXIMITY_OUT:
6560 /* Remaining events would make sense on an not-viewable window,
6561 * or don't have an associated window.
6568 gtk_widget_event_internal (GtkWidget *widget,
6571 gboolean return_val = FALSE;
6573 /* We check only once for is-still-visible; if someone
6574 * hides the window in on of the signals on the widget,
6575 * they are responsible for returning TRUE to terminate
6578 if (!event_window_is_still_viewable (event))
6581 g_object_ref (widget);
6583 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6584 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6589 switch (event->type)
6595 case GDK_BUTTON_PRESS:
6596 case GDK_2BUTTON_PRESS:
6597 case GDK_3BUTTON_PRESS:
6598 signal_num = BUTTON_PRESS_EVENT;
6600 case GDK_TOUCH_BEGIN:
6601 case GDK_TOUCH_UPDATE:
6603 case GDK_TOUCH_CANCEL:
6604 signal_num = TOUCH_EVENT;
6607 signal_num = SCROLL_EVENT;
6609 case GDK_BUTTON_RELEASE:
6610 signal_num = BUTTON_RELEASE_EVENT;
6612 case GDK_MOTION_NOTIFY:
6613 signal_num = MOTION_NOTIFY_EVENT;
6616 signal_num = DELETE_EVENT;
6619 signal_num = DESTROY_EVENT;
6620 _gtk_tooltip_hide (widget);
6623 signal_num = KEY_PRESS_EVENT;
6625 case GDK_KEY_RELEASE:
6626 signal_num = KEY_RELEASE_EVENT;
6628 case GDK_ENTER_NOTIFY:
6629 signal_num = ENTER_NOTIFY_EVENT;
6631 case GDK_LEAVE_NOTIFY:
6632 signal_num = LEAVE_NOTIFY_EVENT;
6634 case GDK_FOCUS_CHANGE:
6635 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6636 if (event->focus_change.in)
6637 _gtk_tooltip_focus_in (widget);
6639 _gtk_tooltip_focus_out (widget);
6642 signal_num = CONFIGURE_EVENT;
6645 signal_num = MAP_EVENT;
6648 signal_num = UNMAP_EVENT;
6650 case GDK_WINDOW_STATE:
6651 signal_num = WINDOW_STATE_EVENT;
6653 case GDK_PROPERTY_NOTIFY:
6654 signal_num = PROPERTY_NOTIFY_EVENT;
6656 case GDK_SELECTION_CLEAR:
6657 signal_num = SELECTION_CLEAR_EVENT;
6659 case GDK_SELECTION_REQUEST:
6660 signal_num = SELECTION_REQUEST_EVENT;
6662 case GDK_SELECTION_NOTIFY:
6663 signal_num = SELECTION_NOTIFY_EVENT;
6665 case GDK_PROXIMITY_IN:
6666 signal_num = PROXIMITY_IN_EVENT;
6668 case GDK_PROXIMITY_OUT:
6669 signal_num = PROXIMITY_OUT_EVENT;
6671 case GDK_VISIBILITY_NOTIFY:
6672 signal_num = VISIBILITY_NOTIFY_EVENT;
6674 case GDK_GRAB_BROKEN:
6675 signal_num = GRAB_BROKEN_EVENT;
6678 signal_num = DAMAGE_EVENT;
6681 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6685 if (signal_num != -1)
6686 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6688 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6689 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6693 g_object_unref (widget);
6699 * gtk_widget_activate:
6700 * @widget: a #GtkWidget that's activatable
6702 * For widgets that can be "activated" (buttons, menu items, etc.)
6703 * this function activates them. Activation is what happens when you
6704 * press Enter on a widget during key navigation. If @widget isn't
6705 * activatable, the function returns %FALSE.
6707 * Return value: %TRUE if the widget was activatable
6710 gtk_widget_activate (GtkWidget *widget)
6712 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6714 if (WIDGET_CLASS (widget)->activate_signal)
6716 /* FIXME: we should eventually check the signals signature here */
6717 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6726 gtk_widget_reparent_subwindows (GtkWidget *widget,
6727 GdkWindow *new_window)
6729 GtkWidgetPrivate *priv = widget->priv;
6731 if (!gtk_widget_get_has_window (widget))
6733 GList *children = gdk_window_get_children (priv->window);
6736 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6738 GdkWindow *window = tmp_list->data;
6741 gdk_window_get_user_data (window, &child);
6742 while (child && child != widget)
6743 child = ((GtkWidget*) child)->priv->parent;
6746 gdk_window_reparent (window, new_window, 0, 0);
6749 g_list_free (children);
6754 GList *tmp_list, *children;
6756 parent = gdk_window_get_parent (priv->window);
6759 gdk_window_reparent (priv->window, new_window, 0, 0);
6762 children = gdk_window_get_children (parent);
6764 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6766 GdkWindow *window = tmp_list->data;
6769 gdk_window_get_user_data (window, &child);
6771 if (child == widget)
6772 gdk_window_reparent (window, new_window, 0, 0);
6775 g_list_free (children);
6781 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6782 gpointer client_data)
6784 GtkWidgetPrivate *priv = widget->priv;
6786 g_assert (client_data != NULL);
6788 if (!gtk_widget_get_has_window (widget))
6791 g_object_unref (priv->window);
6792 priv->window = (GdkWindow*) client_data;
6794 g_object_ref (priv->window);
6796 if (GTK_IS_CONTAINER (widget))
6797 gtk_container_forall (GTK_CONTAINER (widget),
6798 gtk_widget_reparent_fixup_child,
6804 * gtk_widget_reparent:
6805 * @widget: a #GtkWidget
6806 * @new_parent: a #GtkContainer to move the widget into
6808 * Moves a widget from one #GtkContainer to another, handling reference
6809 * count issues to avoid destroying the widget.
6812 gtk_widget_reparent (GtkWidget *widget,
6813 GtkWidget *new_parent)
6815 GtkWidgetPrivate *priv;
6817 g_return_if_fail (GTK_IS_WIDGET (widget));
6818 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6819 priv = widget->priv;
6820 g_return_if_fail (priv->parent != NULL);
6822 if (priv->parent != new_parent)
6824 /* First try to see if we can get away without unrealizing
6825 * the widget as we reparent it. if so we set a flag so
6826 * that gtk_widget_unparent doesn't unrealize widget
6828 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6829 priv->in_reparent = TRUE;
6831 g_object_ref (widget);
6832 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6833 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6834 g_object_unref (widget);
6836 if (priv->in_reparent)
6838 priv->in_reparent = FALSE;
6840 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6841 gtk_widget_reparent_fixup_child (widget,
6842 gtk_widget_get_parent_window (widget));
6845 g_object_notify (G_OBJECT (widget), "parent");
6850 * gtk_widget_intersect:
6851 * @widget: a #GtkWidget
6852 * @area: a rectangle
6853 * @intersection: rectangle to store intersection of @widget and @area
6855 * Computes the intersection of a @widget's area and @area, storing
6856 * the intersection in @intersection, and returns %TRUE if there was
6857 * an intersection. @intersection may be %NULL if you're only
6858 * interested in whether there was an intersection.
6860 * Return value: %TRUE if there was an intersection
6863 gtk_widget_intersect (GtkWidget *widget,
6864 const GdkRectangle *area,
6865 GdkRectangle *intersection)
6867 GtkWidgetPrivate *priv;
6872 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6873 g_return_val_if_fail (area != NULL, FALSE);
6875 priv = widget->priv;
6878 dest = intersection;
6882 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6884 if (return_val && intersection && gtk_widget_get_has_window (widget))
6886 intersection->x -= priv->allocation.x;
6887 intersection->y -= priv->allocation.y;
6894 * gtk_widget_region_intersect:
6895 * @widget: a #GtkWidget
6896 * @region: a #cairo_region_t, in the same coordinate system as
6897 * @widget->allocation. That is, relative to @widget->window
6898 * for %NO_WINDOW widgets; relative to the parent window
6899 * of @widget->window for widgets with their own window.
6901 * Computes the intersection of a @widget's area and @region, returning
6902 * the intersection. The result may be empty, use cairo_region_is_empty() to
6905 * Returns: A newly allocated region holding the intersection of @widget
6906 * and @region. The coordinates of the return value are relative to
6907 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6908 * window of @widget->window for widgets with their own window.
6911 gtk_widget_region_intersect (GtkWidget *widget,
6912 const cairo_region_t *region)
6915 cairo_region_t *dest;
6917 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6918 g_return_val_if_fail (region != NULL, NULL);
6920 gtk_widget_get_allocation (widget, &rect);
6922 dest = cairo_region_create_rectangle (&rect);
6924 cairo_region_intersect (dest, region);
6930 * _gtk_widget_grab_notify:
6931 * @widget: a #GtkWidget
6932 * @was_grabbed: whether a grab is now in effect
6934 * Emits the #GtkWidget::grab-notify signal on @widget.
6939 _gtk_widget_grab_notify (GtkWidget *widget,
6940 gboolean was_grabbed)
6942 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6946 * gtk_widget_grab_focus:
6947 * @widget: a #GtkWidget
6949 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6950 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6951 * something like #GtkFrame won't work.
6953 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6954 * gtk_widget_set_can_focus() to modify that flag.
6956 * The widget also needs to be realized and mapped. This is indicated by the
6957 * related signals. Grabbing the focus immediately after creating the widget
6958 * will likely fail and cause critical warnings.
6961 gtk_widget_grab_focus (GtkWidget *widget)
6963 g_return_if_fail (GTK_IS_WIDGET (widget));
6965 if (!gtk_widget_is_sensitive (widget))
6968 g_object_ref (widget);
6969 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6970 g_object_notify (G_OBJECT (widget), "has-focus");
6971 g_object_unref (widget);
6975 reset_focus_recurse (GtkWidget *widget,
6978 if (GTK_IS_CONTAINER (widget))
6980 GtkContainer *container;
6982 container = GTK_CONTAINER (widget);
6983 gtk_container_set_focus_child (container, NULL);
6985 gtk_container_foreach (container,
6986 reset_focus_recurse,
6992 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6994 if (gtk_widget_get_can_focus (focus_widget))
6996 GtkWidget *toplevel;
6999 /* clear the current focus setting, break if the current widget
7000 * is the focus widget's parent, since containers above that will
7001 * be set by the next loop.
7003 toplevel = gtk_widget_get_toplevel (focus_widget);
7004 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
7006 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
7008 if (widget == focus_widget)
7010 /* We call _gtk_window_internal_set_focus() here so that the
7011 * toplevel window can request the focus if necessary.
7012 * This is needed when the toplevel is a GtkPlug
7014 if (!gtk_widget_has_focus (widget))
7015 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
7022 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
7024 if (widget != common_ancestor)
7026 while (widget->priv->parent && widget->priv->parent != common_ancestor)
7028 widget = widget->priv->parent;
7029 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
7034 else if (toplevel != focus_widget)
7036 /* gtk_widget_grab_focus() operates on a tree without window...
7037 * actually, this is very questionable behaviour.
7040 gtk_container_foreach (GTK_CONTAINER (toplevel),
7041 reset_focus_recurse,
7045 /* now propagate the new focus up the widget tree and finally
7046 * set it on the window
7048 widget = focus_widget;
7049 while (widget->priv->parent)
7051 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
7052 widget = widget->priv->parent;
7054 if (GTK_IS_WINDOW (widget))
7055 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
7060 gtk_widget_real_query_tooltip (GtkWidget *widget,
7063 gboolean keyboard_tip,
7064 GtkTooltip *tooltip)
7066 gchar *tooltip_markup;
7067 gboolean has_tooltip;
7069 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
7070 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
7072 if (has_tooltip && tooltip_markup)
7074 gtk_tooltip_set_markup (tooltip, tooltip_markup);
7082 gtk_widget_real_state_flags_changed (GtkWidget *widget,
7083 GtkStateFlags old_state)
7085 gtk_widget_update_pango_context (widget);
7089 gtk_widget_real_style_updated (GtkWidget *widget)
7091 GtkWidgetPrivate *priv = widget->priv;
7093 gtk_widget_update_pango_context (widget);
7094 gtk_widget_update_alpha (widget);
7096 if (priv->style != NULL &&
7097 priv->style != gtk_widget_get_default_style ())
7099 /* Trigger ::style-set for old
7100 * widgets not listening to this
7102 g_signal_emit (widget,
7103 widget_signals[STYLE_SET],
7105 widget->priv->style);
7108 if (widget->priv->context)
7110 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
7112 if (gtk_widget_get_realized (widget) &&
7113 gtk_widget_get_has_window (widget) &&
7114 !gtk_widget_get_app_paintable (widget))
7115 gtk_style_context_set_background (widget->priv->context,
7116 widget->priv->window);
7118 if (widget->priv->anchored)
7120 if (changes && _gtk_css_style_property_changes_affect_size (changes))
7121 gtk_widget_queue_resize (widget);
7123 gtk_widget_queue_draw (widget);
7128 if (widget->priv->anchored)
7129 gtk_widget_queue_resize (widget);
7134 gtk_widget_real_show_help (GtkWidget *widget,
7135 GtkWidgetHelpType help_type)
7137 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
7139 _gtk_tooltip_toggle_keyboard_mode (widget);
7148 gtk_widget_real_focus (GtkWidget *widget,
7149 GtkDirectionType direction)
7151 if (!gtk_widget_get_can_focus (widget))
7154 if (!gtk_widget_is_focus (widget))
7156 gtk_widget_grab_focus (widget);
7164 gtk_widget_real_move_focus (GtkWidget *widget,
7165 GtkDirectionType direction)
7167 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7169 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
7171 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
7177 gtk_widget_real_keynav_failed (GtkWidget *widget,
7178 GtkDirectionType direction)
7180 gboolean cursor_only;
7184 case GTK_DIR_TAB_FORWARD:
7185 case GTK_DIR_TAB_BACKWARD:
7192 g_object_get (gtk_widget_get_settings (widget),
7193 "gtk-keynav-cursor-only", &cursor_only,
7200 gtk_widget_error_bell (widget);
7206 * gtk_widget_set_can_focus:
7207 * @widget: a #GtkWidget
7208 * @can_focus: whether or not @widget can own the input focus.
7210 * Specifies whether @widget can own the input focus. See
7211 * gtk_widget_grab_focus() for actually setting the input focus on a
7217 gtk_widget_set_can_focus (GtkWidget *widget,
7220 g_return_if_fail (GTK_IS_WIDGET (widget));
7222 if (widget->priv->can_focus != can_focus)
7224 widget->priv->can_focus = can_focus;
7226 gtk_widget_queue_resize (widget);
7227 g_object_notify (G_OBJECT (widget), "can-focus");
7232 * gtk_widget_get_can_focus:
7233 * @widget: a #GtkWidget
7235 * Determines whether @widget can own the input focus. See
7236 * gtk_widget_set_can_focus().
7238 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
7243 gtk_widget_get_can_focus (GtkWidget *widget)
7245 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7247 return widget->priv->can_focus;
7251 * gtk_widget_has_focus:
7252 * @widget: a #GtkWidget
7254 * Determines if the widget has the global input focus. See
7255 * gtk_widget_is_focus() for the difference between having the global
7256 * input focus, and only having the focus within a toplevel.
7258 * Return value: %TRUE if the widget has the global input focus.
7263 gtk_widget_has_focus (GtkWidget *widget)
7265 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7267 return widget->priv->has_focus;
7271 * gtk_widget_has_visible_focus:
7272 * @widget: a #GtkWidget
7274 * Determines if the widget should show a visible indication that
7275 * it has the global input focus. This is a convenience function for
7276 * use in ::draw handlers that takes into account whether focus
7277 * indication should currently be shown in the toplevel window of
7278 * @widget. See gtk_window_get_focus_visible() for more information
7279 * about focus indication.
7281 * To find out if the widget has the global input focus, use
7282 * gtk_widget_has_focus().
7284 * Return value: %TRUE if the widget should display a 'focus rectangle'
7289 gtk_widget_has_visible_focus (GtkWidget *widget)
7291 gboolean draw_focus;
7293 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7295 if (widget->priv->has_focus)
7297 GtkWidget *toplevel;
7299 toplevel = gtk_widget_get_toplevel (widget);
7301 if (GTK_IS_WINDOW (toplevel))
7302 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7313 * gtk_widget_is_focus:
7314 * @widget: a #GtkWidget
7316 * Determines if the widget is the focus widget within its
7317 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7318 * necessarily set; %HAS_FOCUS will only be set if the
7319 * toplevel widget additionally has the global input focus.)
7321 * Return value: %TRUE if the widget is the focus widget.
7324 gtk_widget_is_focus (GtkWidget *widget)
7326 GtkWidget *toplevel;
7328 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7330 toplevel = gtk_widget_get_toplevel (widget);
7332 if (GTK_IS_WINDOW (toplevel))
7333 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7339 * gtk_widget_set_can_default:
7340 * @widget: a #GtkWidget
7341 * @can_default: whether or not @widget can be a default widget.
7343 * Specifies whether @widget can be a default widget. See
7344 * gtk_widget_grab_default() for details about the meaning of
7350 gtk_widget_set_can_default (GtkWidget *widget,
7351 gboolean can_default)
7353 g_return_if_fail (GTK_IS_WIDGET (widget));
7355 if (widget->priv->can_default != can_default)
7357 widget->priv->can_default = can_default;
7359 gtk_widget_queue_resize (widget);
7360 g_object_notify (G_OBJECT (widget), "can-default");
7365 * gtk_widget_get_can_default:
7366 * @widget: a #GtkWidget
7368 * Determines whether @widget can be a default widget. See
7369 * gtk_widget_set_can_default().
7371 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7376 gtk_widget_get_can_default (GtkWidget *widget)
7378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7380 return widget->priv->can_default;
7384 * gtk_widget_has_default:
7385 * @widget: a #GtkWidget
7387 * Determines whether @widget is the current default widget within its
7388 * toplevel. See gtk_widget_set_can_default().
7390 * Return value: %TRUE if @widget is the current default widget within
7391 * its toplevel, %FALSE otherwise
7396 gtk_widget_has_default (GtkWidget *widget)
7398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7400 return widget->priv->has_default;
7404 _gtk_widget_set_has_default (GtkWidget *widget,
7405 gboolean has_default)
7407 GtkStyleContext *context;
7409 widget->priv->has_default = has_default;
7411 context = gtk_widget_get_style_context (widget);
7414 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7416 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7420 * gtk_widget_grab_default:
7421 * @widget: a #GtkWidget
7423 * Causes @widget to become the default widget. @widget must be able to be
7424 * a default widget; typically you would ensure this yourself
7425 * by calling gtk_widget_set_can_default() with a %TRUE value.
7426 * The default widget is activated when
7427 * the user presses Enter in a window. Default widgets must be
7428 * activatable, that is, gtk_widget_activate() should affect them. Note
7429 * that #GtkEntry widgets require the "activates-default" property
7430 * set to %TRUE before they activate the default widget when Enter
7431 * is pressed and the #GtkEntry is focused.
7434 gtk_widget_grab_default (GtkWidget *widget)
7438 g_return_if_fail (GTK_IS_WIDGET (widget));
7439 g_return_if_fail (gtk_widget_get_can_default (widget));
7441 window = gtk_widget_get_toplevel (widget);
7443 if (window && gtk_widget_is_toplevel (window))
7444 gtk_window_set_default (GTK_WINDOW (window), widget);
7446 g_warning (G_STRLOC ": widget not within a GtkWindow");
7450 * gtk_widget_set_receives_default:
7451 * @widget: a #GtkWidget
7452 * @receives_default: whether or not @widget can be a default widget.
7454 * Specifies whether @widget will be treated as the default widget
7455 * within its toplevel when it has the focus, even if another widget
7458 * See gtk_widget_grab_default() for details about the meaning of
7464 gtk_widget_set_receives_default (GtkWidget *widget,
7465 gboolean receives_default)
7467 g_return_if_fail (GTK_IS_WIDGET (widget));
7469 if (widget->priv->receives_default != receives_default)
7471 widget->priv->receives_default = receives_default;
7473 g_object_notify (G_OBJECT (widget), "receives-default");
7478 * gtk_widget_get_receives_default:
7479 * @widget: a #GtkWidget
7481 * Determines whether @widget is alyways treated as default widget
7482 * withing its toplevel when it has the focus, even if another widget
7485 * See gtk_widget_set_receives_default().
7487 * Return value: %TRUE if @widget acts as default widget when focussed,
7493 gtk_widget_get_receives_default (GtkWidget *widget)
7495 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7497 return widget->priv->receives_default;
7501 * gtk_widget_has_grab:
7502 * @widget: a #GtkWidget
7504 * Determines whether the widget is currently grabbing events, so it
7505 * is the only widget receiving input events (keyboard and mouse).
7507 * See also gtk_grab_add().
7509 * Return value: %TRUE if the widget is in the grab_widgets stack
7514 gtk_widget_has_grab (GtkWidget *widget)
7516 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7518 return widget->priv->has_grab;
7522 _gtk_widget_set_has_grab (GtkWidget *widget,
7525 widget->priv->has_grab = has_grab;
7529 * gtk_widget_device_is_shadowed:
7530 * @widget: a #GtkWidget
7531 * @device: a #GdkDevice
7533 * Returns %TRUE if @device has been shadowed by a GTK+
7534 * device grab on another widget, so it would stop sending
7535 * events to @widget. This may be used in the
7536 * #GtkWidget::grab-notify signal to check for specific
7537 * devices. See gtk_device_grab_add().
7539 * Returns: %TRUE if there is an ongoing grab on @device
7540 * by another #GtkWidget than @widget.
7545 gtk_widget_device_is_shadowed (GtkWidget *widget,
7548 GtkWindowGroup *group;
7549 GtkWidget *grab_widget, *toplevel;
7551 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7552 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7554 if (!gtk_widget_get_realized (widget))
7557 toplevel = gtk_widget_get_toplevel (widget);
7559 if (GTK_IS_WINDOW (toplevel))
7560 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7562 group = gtk_window_get_group (NULL);
7564 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7566 /* Widget not inside the hierarchy of grab_widget */
7568 widget != grab_widget &&
7569 !gtk_widget_is_ancestor (widget, grab_widget))
7572 grab_widget = gtk_window_group_get_current_grab (group);
7573 if (grab_widget && widget != grab_widget &&
7574 !gtk_widget_is_ancestor (widget, grab_widget))
7581 * gtk_widget_set_name:
7582 * @widget: a #GtkWidget
7583 * @name: name for the widget
7585 * Widgets can be named, which allows you to refer to them from a
7586 * CSS file. You can apply a style to widgets with a particular name
7587 * in the CSS file. See the documentation for the CSS syntax (on the
7588 * same page as the docs for #GtkStyleContext).
7590 * Note that the CSS syntax has certain special characters to delimit
7591 * and represent elements in a selector (period, #, >, *...),
7592 * so using these will make your widget impossible to match by name.
7593 * Any combination of alphanumeric symbols, dashes and underscores will
7597 gtk_widget_set_name (GtkWidget *widget,
7600 GtkWidgetPrivate *priv;
7603 g_return_if_fail (GTK_IS_WIDGET (widget));
7605 priv = widget->priv;
7607 new_name = g_strdup (name);
7608 g_free (priv->name);
7609 priv->name = new_name;
7611 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7613 g_object_notify (G_OBJECT (widget), "name");
7617 * gtk_widget_get_name:
7618 * @widget: a #GtkWidget
7620 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7621 * significance of widget names.
7623 * Return value: name of the widget. This string is owned by GTK+ and
7624 * should not be modified or freed
7627 gtk_widget_get_name (GtkWidget *widget)
7629 GtkWidgetPrivate *priv;
7631 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7633 priv = widget->priv;
7637 return G_OBJECT_TYPE_NAME (widget);
7641 gtk_widget_update_state_flags (GtkWidget *widget,
7642 GtkStateFlags flags_to_set,
7643 GtkStateFlags flags_to_unset)
7645 GtkWidgetPrivate *priv;
7647 priv = widget->priv;
7649 /* Handle insensitive first, since it is propagated
7650 * differently throughout the widget hierarchy.
7652 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7653 gtk_widget_set_sensitive (widget, TRUE);
7654 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7655 gtk_widget_set_sensitive (widget, FALSE);
7657 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7658 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7660 if (flags_to_set != 0 || flags_to_unset != 0)
7664 data.flags_to_set = flags_to_set;
7665 data.flags_to_unset = flags_to_unset;
7667 gtk_widget_propagate_state (widget, &data);
7672 * gtk_widget_set_state_flags:
7673 * @widget: a #GtkWidget
7674 * @flags: State flags to turn on
7675 * @clear: Whether to clear state before turning on @flags
7677 * This function is for use in widget implementations. Turns on flag
7678 * values in the current widget state (insensitive, prelighted, etc.).
7680 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7681 * will be propagated down to all non-internal children if @widget is a
7682 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7683 * down to all #GtkContainer children by different means than turning on the
7684 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7685 * gtk_widget_is_sensitive() will make use of these.
7690 gtk_widget_set_state_flags (GtkWidget *widget,
7691 GtkStateFlags flags,
7694 g_return_if_fail (GTK_IS_WIDGET (widget));
7696 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7697 (clear && widget->priv->state_flags == flags))
7701 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7703 gtk_widget_update_state_flags (widget, flags, 0);
7707 * gtk_widget_unset_state_flags:
7708 * @widget: a #GtkWidget
7709 * @flags: State flags to turn off
7711 * This function is for use in widget implementations. Turns off flag
7712 * values for the current widget state (insensitive, prelighted, etc.).
7713 * See gtk_widget_set_state_flags().
7718 gtk_widget_unset_state_flags (GtkWidget *widget,
7719 GtkStateFlags flags)
7721 g_return_if_fail (GTK_IS_WIDGET (widget));
7723 if ((widget->priv->state_flags & flags) == 0)
7726 gtk_widget_update_state_flags (widget, 0, flags);
7730 * gtk_widget_get_state_flags:
7731 * @widget: a #GtkWidget
7733 * Returns the widget state as a flag set. It is worth mentioning
7734 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7735 * returned, that is, also based on parent insensitivity, even if
7736 * @widget itself is sensitive.
7738 * Returns: The state flags for widget
7743 gtk_widget_get_state_flags (GtkWidget *widget)
7745 GtkStateFlags flags;
7747 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7749 flags = widget->priv->state_flags;
7751 if (gtk_widget_has_focus (widget))
7752 flags |= GTK_STATE_FLAG_FOCUSED;
7758 * gtk_widget_set_state:
7759 * @widget: a #GtkWidget
7760 * @state: new state for @widget
7762 * This function is for use in widget implementations. Sets the state
7763 * of a widget (insensitive, prelighted, etc.) Usually you should set
7764 * the state using wrapper functions such as gtk_widget_set_sensitive().
7766 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7769 gtk_widget_set_state (GtkWidget *widget,
7772 GtkStateFlags flags;
7774 if (state == gtk_widget_get_state (widget))
7779 case GTK_STATE_ACTIVE:
7780 flags = GTK_STATE_FLAG_ACTIVE;
7782 case GTK_STATE_PRELIGHT:
7783 flags = GTK_STATE_FLAG_PRELIGHT;
7785 case GTK_STATE_SELECTED:
7786 flags = GTK_STATE_FLAG_SELECTED;
7788 case GTK_STATE_INSENSITIVE:
7789 flags = GTK_STATE_FLAG_INSENSITIVE;
7791 case GTK_STATE_INCONSISTENT:
7792 flags = GTK_STATE_FLAG_INCONSISTENT;
7794 case GTK_STATE_FOCUSED:
7795 flags = GTK_STATE_FLAG_FOCUSED;
7797 case GTK_STATE_NORMAL:
7803 gtk_widget_update_state_flags (widget,
7805 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7806 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7810 * gtk_widget_get_state:
7811 * @widget: a #GtkWidget
7813 * Returns the widget's state. See gtk_widget_set_state().
7815 * Returns: the state of @widget.
7819 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7822 gtk_widget_get_state (GtkWidget *widget)
7824 GtkStateFlags flags;
7826 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7828 flags = gtk_widget_get_state_flags (widget);
7830 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7831 return GTK_STATE_INSENSITIVE;
7832 else if (flags & GTK_STATE_FLAG_ACTIVE)
7833 return GTK_STATE_ACTIVE;
7834 else if (flags & GTK_STATE_FLAG_SELECTED)
7835 return GTK_STATE_SELECTED;
7836 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7837 return GTK_STATE_PRELIGHT;
7839 return GTK_STATE_NORMAL;
7843 * gtk_widget_set_visible:
7844 * @widget: a #GtkWidget
7845 * @visible: whether the widget should be shown or not
7847 * Sets the visibility state of @widget. Note that setting this to
7848 * %TRUE doesn't mean the widget is actually viewable, see
7849 * gtk_widget_get_visible().
7851 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7852 * but is nicer to use when the visibility of the widget depends on
7858 gtk_widget_set_visible (GtkWidget *widget,
7861 g_return_if_fail (GTK_IS_WIDGET (widget));
7863 if (visible != gtk_widget_get_visible (widget))
7866 gtk_widget_show (widget);
7868 gtk_widget_hide (widget);
7873 _gtk_widget_set_visible_flag (GtkWidget *widget,
7876 GtkWidgetPrivate *priv = widget->priv;
7878 priv->visible = visible;
7882 priv->allocation.x = -1;
7883 priv->allocation.y = -1;
7884 priv->allocation.width = 1;
7885 priv->allocation.height = 1;
7890 * gtk_widget_get_visible:
7891 * @widget: a #GtkWidget
7893 * Determines whether the widget is visible. If you want to
7894 * take into account whether the widget's parent is also marked as
7895 * visible, use gtk_widget_is_visible() instead.
7897 * This function does not check if the widget is obscured in any way.
7899 * See gtk_widget_set_visible().
7901 * Return value: %TRUE if the widget is visible
7906 gtk_widget_get_visible (GtkWidget *widget)
7908 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7910 return widget->priv->visible;
7914 * gtk_widget_is_visible:
7915 * @widget: a #GtkWidget
7917 * Determines whether the widget and all its parents are marked as
7920 * This function does not check if the widget is obscured in any way.
7922 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7924 * Return value: %TRUE if the widget and all its parents are visible
7929 gtk_widget_is_visible (GtkWidget *widget)
7931 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7935 GtkWidgetPrivate *priv = widget->priv;
7940 widget = priv->parent;
7947 * gtk_widget_set_has_window:
7948 * @widget: a #GtkWidget
7949 * @has_window: whether or not @widget has a window.
7951 * Specifies whether @widget has a #GdkWindow of its own. Note that
7952 * all realized widgets have a non-%NULL "window" pointer
7953 * (gtk_widget_get_window() never returns a %NULL window when a widget
7954 * is realized), but for many of them it's actually the #GdkWindow of
7955 * one of its parent widgets. Widgets that do not create a %window for
7956 * themselves in #GtkWidget::realize must announce this by
7957 * calling this function with @has_window = %FALSE.
7959 * This function should only be called by widget implementations,
7960 * and they should call it in their init() function.
7965 gtk_widget_set_has_window (GtkWidget *widget,
7966 gboolean has_window)
7968 g_return_if_fail (GTK_IS_WIDGET (widget));
7970 widget->priv->no_window = !has_window;
7974 * gtk_widget_get_has_window:
7975 * @widget: a #GtkWidget
7977 * Determines whether @widget has a #GdkWindow of its own. See
7978 * gtk_widget_set_has_window().
7980 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7985 gtk_widget_get_has_window (GtkWidget *widget)
7987 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7989 return ! widget->priv->no_window;
7993 * gtk_widget_is_toplevel:
7994 * @widget: a #GtkWidget
7996 * Determines whether @widget is a toplevel widget.
7998 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7999 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
8002 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
8007 gtk_widget_is_toplevel (GtkWidget *widget)
8009 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8011 return widget->priv->toplevel;
8015 _gtk_widget_set_is_toplevel (GtkWidget *widget,
8016 gboolean is_toplevel)
8018 widget->priv->toplevel = is_toplevel;
8022 * gtk_widget_is_drawable:
8023 * @widget: a #GtkWidget
8025 * Determines whether @widget can be drawn to. A widget can be drawn
8026 * to if it is mapped and visible.
8028 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
8033 gtk_widget_is_drawable (GtkWidget *widget)
8035 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8037 return (gtk_widget_get_visible (widget) &&
8038 gtk_widget_get_mapped (widget));
8042 * gtk_widget_get_realized:
8043 * @widget: a #GtkWidget
8045 * Determines whether @widget is realized.
8047 * Return value: %TRUE if @widget is realized, %FALSE otherwise
8052 gtk_widget_get_realized (GtkWidget *widget)
8054 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8056 return widget->priv->realized;
8060 * gtk_widget_set_realized:
8061 * @widget: a #GtkWidget
8062 * @realized: %TRUE to mark the widget as realized
8064 * Marks the widget as being realized.
8066 * This function should only ever be called in a derived widget's
8067 * "realize" or "unrealize" implementation.
8072 gtk_widget_set_realized (GtkWidget *widget,
8075 g_return_if_fail (GTK_IS_WIDGET (widget));
8077 widget->priv->realized = realized;
8081 * gtk_widget_get_mapped:
8082 * @widget: a #GtkWidget
8084 * Whether the widget is mapped.
8086 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
8091 gtk_widget_get_mapped (GtkWidget *widget)
8093 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8095 return widget->priv->mapped;
8099 * gtk_widget_set_mapped:
8100 * @widget: a #GtkWidget
8101 * @mapped: %TRUE to mark the widget as mapped
8103 * Marks the widget as being realized.
8105 * This function should only ever be called in a derived widget's
8106 * "map" or "unmap" implementation.
8111 gtk_widget_set_mapped (GtkWidget *widget,
8114 g_return_if_fail (GTK_IS_WIDGET (widget));
8116 widget->priv->mapped = mapped;
8120 * gtk_widget_set_app_paintable:
8121 * @widget: a #GtkWidget
8122 * @app_paintable: %TRUE if the application will paint on the widget
8124 * Sets whether the application intends to draw on the widget in
8125 * an #GtkWidget::draw handler.
8127 * This is a hint to the widget and does not affect the behavior of
8128 * the GTK+ core; many widgets ignore this flag entirely. For widgets
8129 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
8130 * the effect is to suppress default themed drawing of the widget's
8131 * background. (Children of the widget will still be drawn.) The application
8132 * is then entirely responsible for drawing the widget background.
8134 * Note that the background is still drawn when the widget is mapped.
8137 gtk_widget_set_app_paintable (GtkWidget *widget,
8138 gboolean app_paintable)
8140 g_return_if_fail (GTK_IS_WIDGET (widget));
8142 app_paintable = (app_paintable != FALSE);
8144 if (widget->priv->app_paintable != app_paintable)
8146 widget->priv->app_paintable = app_paintable;
8148 if (gtk_widget_is_drawable (widget))
8149 gtk_widget_queue_draw (widget);
8151 g_object_notify (G_OBJECT (widget), "app-paintable");
8156 * gtk_widget_get_app_paintable:
8157 * @widget: a #GtkWidget
8159 * Determines whether the application intends to draw on the widget in
8160 * an #GtkWidget::draw handler.
8162 * See gtk_widget_set_app_paintable()
8164 * Return value: %TRUE if the widget is app paintable
8169 gtk_widget_get_app_paintable (GtkWidget *widget)
8171 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8173 return widget->priv->app_paintable;
8177 * gtk_widget_set_double_buffered:
8178 * @widget: a #GtkWidget
8179 * @double_buffered: %TRUE to double-buffer a widget
8181 * Widgets are double buffered by default; you can use this function
8182 * to turn off the buffering. "Double buffered" simply means that
8183 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
8184 * automatically around expose events sent to the
8185 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
8186 * window to an offscreen buffer, and gdk_window_end_paint() draws the
8187 * buffer to the screen. The result is that users see the window
8188 * update in one smooth step, and don't see individual graphics
8189 * primitives being rendered.
8191 * In very simple terms, double buffered widgets don't flicker,
8192 * so you would only use this function to turn off double buffering
8193 * if you had special needs and really knew what you were doing.
8195 * Note: if you turn off double-buffering, you have to handle
8196 * expose events, since even the clearing to the background color or
8197 * pixmap will not happen automatically (as it is done in
8198 * gdk_window_begin_paint_region()).
8201 gtk_widget_set_double_buffered (GtkWidget *widget,
8202 gboolean double_buffered)
8204 g_return_if_fail (GTK_IS_WIDGET (widget));
8206 double_buffered = (double_buffered != FALSE);
8208 if (widget->priv->double_buffered != double_buffered)
8210 widget->priv->double_buffered = double_buffered;
8212 g_object_notify (G_OBJECT (widget), "double-buffered");
8217 * gtk_widget_get_double_buffered:
8218 * @widget: a #GtkWidget
8220 * Determines whether the widget is double buffered.
8222 * See gtk_widget_set_double_buffered()
8224 * Return value: %TRUE if the widget is double buffered
8229 gtk_widget_get_double_buffered (GtkWidget *widget)
8231 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8233 return widget->priv->double_buffered;
8237 * gtk_widget_set_redraw_on_allocate:
8238 * @widget: a #GtkWidget
8239 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
8240 * when it is allocated to a new size. Otherwise, only the
8241 * new portion of the widget will be redrawn.
8243 * Sets whether the entire widget is queued for drawing when its size
8244 * allocation changes. By default, this setting is %TRUE and
8245 * the entire widget is redrawn on every size change. If your widget
8246 * leaves the upper left unchanged when made bigger, turning this
8247 * setting off will improve performance.
8249 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
8250 * off all allocation on resizing: the widget will not even redraw if
8251 * its position changes; this is to allow containers that don't draw
8252 * anything to avoid excess invalidations. If you set this flag on a
8253 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
8254 * you are responsible for invalidating both the old and new allocation
8255 * of the widget when the widget is moved and responsible for invalidating
8256 * regions newly when the widget increases size.
8259 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
8260 gboolean redraw_on_allocate)
8262 g_return_if_fail (GTK_IS_WIDGET (widget));
8264 widget->priv->redraw_on_alloc = redraw_on_allocate;
8268 * gtk_widget_set_sensitive:
8269 * @widget: a #GtkWidget
8270 * @sensitive: %TRUE to make the widget sensitive
8272 * Sets the sensitivity of a widget. A widget is sensitive if the user
8273 * can interact with it. Insensitive widgets are "grayed out" and the
8274 * user can't interact with them. Insensitive widgets are known as
8275 * "inactive", "disabled", or "ghosted" in some other toolkits.
8278 gtk_widget_set_sensitive (GtkWidget *widget,
8281 GtkWidgetPrivate *priv;
8283 g_return_if_fail (GTK_IS_WIDGET (widget));
8285 priv = widget->priv;
8287 sensitive = (sensitive != FALSE);
8289 if (priv->sensitive == sensitive)
8292 priv->sensitive = sensitive;
8294 if (priv->parent == NULL
8295 || gtk_widget_is_sensitive (priv->parent))
8301 data.flags_to_set = 0;
8302 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8306 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8307 data.flags_to_unset = 0;
8310 gtk_widget_propagate_state (widget, &data);
8312 gtk_widget_queue_resize (widget);
8315 g_object_notify (G_OBJECT (widget), "sensitive");
8319 * gtk_widget_get_sensitive:
8320 * @widget: a #GtkWidget
8322 * Returns the widget's sensitivity (in the sense of returning
8323 * the value that has been set using gtk_widget_set_sensitive()).
8325 * The effective sensitivity of a widget is however determined by both its
8326 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8328 * Returns: %TRUE if the widget is sensitive
8333 gtk_widget_get_sensitive (GtkWidget *widget)
8335 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8337 return widget->priv->sensitive;
8341 * gtk_widget_is_sensitive:
8342 * @widget: a #GtkWidget
8344 * Returns the widget's effective sensitivity, which means
8345 * it is sensitive itself and also its parent widget is sensitive
8347 * Returns: %TRUE if the widget is effectively sensitive
8352 gtk_widget_is_sensitive (GtkWidget *widget)
8354 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8356 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8360 * gtk_widget_set_parent:
8361 * @widget: a #GtkWidget
8362 * @parent: parent container
8364 * This function is useful only when implementing subclasses of
8366 * Sets the container as the parent of @widget, and takes care of
8367 * some details such as updating the state and style of the child
8368 * to reflect its new location. The opposite function is
8369 * gtk_widget_unparent().
8372 gtk_widget_set_parent (GtkWidget *widget,
8375 GtkStateFlags parent_flags;
8376 GtkWidgetPrivate *priv;
8379 g_return_if_fail (GTK_IS_WIDGET (widget));
8380 g_return_if_fail (GTK_IS_WIDGET (parent));
8381 g_return_if_fail (widget != parent);
8383 priv = widget->priv;
8385 if (priv->parent != NULL)
8387 g_warning ("Can't set a parent on widget which has a parent\n");
8390 if (gtk_widget_is_toplevel (widget))
8392 g_warning ("Can't set a parent on a toplevel widget\n");
8396 /* keep this function in sync with gtk_menu_attach_to_widget()
8399 g_object_ref_sink (widget);
8401 gtk_widget_push_verify_invariants (widget);
8403 priv->parent = parent;
8405 parent_flags = gtk_widget_get_state_flags (parent);
8407 /* Merge both old state and current parent state,
8408 * making sure to only propagate the right states */
8409 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8410 data.flags_to_unset = 0;
8411 gtk_widget_propagate_state (widget, &data);
8414 gtk_style_context_set_parent (priv->context,
8415 gtk_widget_get_style_context (parent));
8417 _gtk_widget_update_parent_muxer (widget);
8419 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8420 if (priv->parent->priv->anchored)
8421 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8422 g_object_notify (G_OBJECT (widget), "parent");
8424 /* Enforce realized/mapped invariants
8426 if (gtk_widget_get_realized (priv->parent))
8427 gtk_widget_realize (widget);
8429 if (gtk_widget_get_visible (priv->parent) &&
8430 gtk_widget_get_visible (widget))
8432 if (gtk_widget_get_child_visible (widget) &&
8433 gtk_widget_get_mapped (priv->parent))
8434 gtk_widget_map (widget);
8436 gtk_widget_queue_resize (widget);
8439 /* child may cause parent's expand to change, if the child is
8440 * expanded. If child is not expanded, then it can't modify the
8441 * parent's expand. If the child becomes expanded later then it will
8442 * queue compute_expand then. This optimization plus defaulting
8443 * newly-constructed widgets to need_compute_expand=FALSE should
8444 * mean that initially building a widget tree doesn't have to keep
8445 * walking up setting need_compute_expand on parents over and over.
8447 * We can't change a parent to need to expand unless we're visible.
8449 if (gtk_widget_get_visible (widget) &&
8450 (priv->need_compute_expand ||
8451 priv->computed_hexpand ||
8452 priv->computed_vexpand))
8454 gtk_widget_queue_compute_expand (parent);
8457 gtk_widget_propagate_alpha (widget);
8459 gtk_widget_pop_verify_invariants (widget);
8463 * gtk_widget_get_parent:
8464 * @widget: a #GtkWidget
8466 * Returns the parent container of @widget.
8468 * Return value: (transfer none): the parent container of @widget, or %NULL
8471 gtk_widget_get_parent (GtkWidget *widget)
8473 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8475 return widget->priv->parent;
8479 modifier_style_changed (GtkModifierStyle *style,
8482 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8485 static GtkModifierStyle *
8486 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8488 GtkModifierStyle *style;
8490 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8492 if (G_UNLIKELY (!style))
8494 GtkStyleContext *context;
8496 style = _gtk_modifier_style_new ();
8497 g_object_set_qdata_full (G_OBJECT (widget),
8498 quark_modifier_style,
8500 (GDestroyNotify) g_object_unref);
8502 g_signal_connect (style, "changed",
8503 G_CALLBACK (modifier_style_changed), widget);
8505 context = gtk_widget_get_style_context (widget);
8507 gtk_style_context_add_provider (context,
8508 GTK_STYLE_PROVIDER (style),
8509 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8516 * gtk_widget_override_color:
8517 * @widget: a #GtkWidget
8518 * @state: the state for which to set the color
8519 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8520 * of previous calls to gtk_widget_override_color()
8522 * Sets the color to use for a widget.
8524 * All other style values are left untouched.
8527 * This API is mostly meant as a quick way for applications to
8528 * change a widget appearance. If you are developing a widgets
8529 * library and intend this change to be themeable, it is better
8530 * done by setting meaningful CSS classes and regions in your
8531 * widget/container implementation through gtk_style_context_add_class()
8532 * and gtk_style_context_add_region().
8534 * This way, your widget library can install a #GtkCssProvider
8535 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8536 * to provide a default styling for those widgets that need so, and
8537 * this theming may fully overridden by the user's theme.
8540 * Note that for complex widgets this may bring in undesired
8541 * results (such as uniform background color everywhere), in
8542 * these cases it is better to fully style such widgets through a
8543 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8550 gtk_widget_override_color (GtkWidget *widget,
8551 GtkStateFlags state,
8552 const GdkRGBA *color)
8554 GtkModifierStyle *style;
8556 g_return_if_fail (GTK_IS_WIDGET (widget));
8558 style = _gtk_widget_get_modifier_properties (widget);
8559 _gtk_modifier_style_set_color (style, state, color);
8563 * gtk_widget_override_background_color:
8564 * @widget: a #GtkWidget
8565 * @state: the state for which to set the background color
8566 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8567 * of previous calls to gtk_widget_override_background_color()
8569 * Sets the background color to use for a widget.
8571 * All other style values are left untouched.
8572 * See gtk_widget_override_color().
8577 gtk_widget_override_background_color (GtkWidget *widget,
8578 GtkStateFlags state,
8579 const GdkRGBA *color)
8581 GtkModifierStyle *style;
8583 g_return_if_fail (GTK_IS_WIDGET (widget));
8585 style = _gtk_widget_get_modifier_properties (widget);
8586 _gtk_modifier_style_set_background_color (style, state, color);
8590 * gtk_widget_override_font:
8591 * @widget: a #GtkWidget
8592 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8593 * the effect of previous calls to gtk_widget_override_font()
8595 * Sets the font to use for a widget. All other style values are
8596 * left untouched. See gtk_widget_override_color().
8601 gtk_widget_override_font (GtkWidget *widget,
8602 const PangoFontDescription *font_desc)
8604 GtkModifierStyle *style;
8606 g_return_if_fail (GTK_IS_WIDGET (widget));
8608 style = _gtk_widget_get_modifier_properties (widget);
8609 _gtk_modifier_style_set_font (style, font_desc);
8613 * gtk_widget_override_symbolic_color:
8614 * @widget: a #GtkWidget
8615 * @name: the name of the symbolic color to modify
8616 * @color: (allow-none): the color to assign (does not need
8617 * to be allocated), or %NULL to undo the effect of previous
8618 * calls to gtk_widget_override_symbolic_color()
8620 * Sets a symbolic color for a widget.
8622 * All other style values are left untouched.
8623 * See gtk_widget_override_color() for overriding the foreground
8624 * or background color.
8629 gtk_widget_override_symbolic_color (GtkWidget *widget,
8631 const GdkRGBA *color)
8633 GtkModifierStyle *style;
8635 g_return_if_fail (GTK_IS_WIDGET (widget));
8637 style = _gtk_widget_get_modifier_properties (widget);
8638 _gtk_modifier_style_map_color (style, name, color);
8642 * gtk_widget_override_cursor:
8643 * @widget: a #GtkWidget
8644 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8645 * allocated), or %NULL to undo the effect of previous calls to
8646 * of gtk_widget_override_cursor().
8647 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8648 * need to be allocated), or %NULL to undo the effect of previous
8649 * calls to of gtk_widget_override_cursor().
8651 * Sets the cursor color to use in a widget, overriding the
8652 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8653 * style properties. All other style values are left untouched.
8654 * See also gtk_widget_modify_style().
8656 * Note that the underlying properties have the #GdkColor type,
8657 * so the alpha value in @primary and @secondary will be ignored.
8662 gtk_widget_override_cursor (GtkWidget *widget,
8663 const GdkRGBA *cursor,
8664 const GdkRGBA *secondary_cursor)
8666 GtkModifierStyle *style;
8668 g_return_if_fail (GTK_IS_WIDGET (widget));
8670 style = _gtk_widget_get_modifier_properties (widget);
8671 _gtk_modifier_style_set_color_property (style,
8673 "cursor-color", cursor);
8674 _gtk_modifier_style_set_color_property (style,
8676 "secondary-cursor-color",
8681 gtk_widget_real_direction_changed (GtkWidget *widget,
8682 GtkTextDirection previous_direction)
8684 gtk_widget_queue_resize (widget);
8688 gtk_widget_real_style_set (GtkWidget *widget,
8689 GtkStyle *previous_style)
8694 GtkWidget *previous_toplevel;
8695 GdkScreen *previous_screen;
8696 GdkScreen *new_screen;
8697 } HierarchyChangedInfo;
8700 do_screen_change (GtkWidget *widget,
8701 GdkScreen *old_screen,
8702 GdkScreen *new_screen)
8704 if (old_screen != new_screen)
8706 GtkWidgetPrivate *priv = widget->priv;
8710 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8712 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8715 _gtk_tooltip_hide (widget);
8717 if (new_screen && priv->context)
8718 gtk_style_context_set_screen (priv->context, new_screen);
8720 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8725 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8726 gpointer client_data)
8728 GtkWidgetPrivate *priv = widget->priv;
8729 HierarchyChangedInfo *info = client_data;
8730 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8731 (priv->parent && priv->parent->priv->anchored);
8733 if (priv->anchored != new_anchored)
8735 g_object_ref (widget);
8737 priv->anchored = new_anchored;
8739 /* This can only happen with gtk_widget_reparent() */
8743 gtk_widget_connect_frame_clock (widget,
8744 gtk_widget_get_frame_clock (widget));
8746 gtk_widget_disconnect_frame_clock (widget,
8747 gtk_widget_get_frame_clock (info->previous_toplevel));
8750 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8751 do_screen_change (widget, info->previous_screen, info->new_screen);
8753 if (GTK_IS_CONTAINER (widget))
8754 gtk_container_forall (GTK_CONTAINER (widget),
8755 gtk_widget_propagate_hierarchy_changed_recurse,
8758 g_object_unref (widget);
8763 * _gtk_widget_propagate_hierarchy_changed:
8764 * @widget: a #GtkWidget
8765 * @previous_toplevel: Previous toplevel
8767 * Propagates changes in the anchored state to a widget and all
8768 * children, unsetting or setting the %ANCHORED flag, and
8769 * emitting #GtkWidget::hierarchy-changed.
8772 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8773 GtkWidget *previous_toplevel)
8775 GtkWidgetPrivate *priv = widget->priv;
8776 HierarchyChangedInfo info;
8778 info.previous_toplevel = previous_toplevel;
8779 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8781 if (gtk_widget_is_toplevel (widget) ||
8782 (priv->parent && priv->parent->priv->anchored))
8783 info.new_screen = gtk_widget_get_screen (widget);
8785 info.new_screen = NULL;
8787 if (info.previous_screen)
8788 g_object_ref (info.previous_screen);
8789 if (previous_toplevel)
8790 g_object_ref (previous_toplevel);
8792 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8794 if (previous_toplevel)
8795 g_object_unref (previous_toplevel);
8796 if (info.previous_screen)
8797 g_object_unref (info.previous_screen);
8801 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8802 gpointer client_data)
8804 HierarchyChangedInfo *info = client_data;
8806 g_object_ref (widget);
8808 do_screen_change (widget, info->previous_screen, info->new_screen);
8810 if (GTK_IS_CONTAINER (widget))
8811 gtk_container_forall (GTK_CONTAINER (widget),
8812 gtk_widget_propagate_screen_changed_recurse,
8815 g_object_unref (widget);
8819 * gtk_widget_is_composited:
8820 * @widget: a #GtkWidget
8822 * Whether @widget can rely on having its alpha channel
8823 * drawn correctly. On X11 this function returns whether a
8824 * compositing manager is running for @widget's screen.
8826 * Please note that the semantics of this call will change
8827 * in the future if used on a widget that has a composited
8828 * window in its hierarchy (as set by gdk_window_set_composited()).
8830 * Return value: %TRUE if the widget can rely on its alpha
8831 * channel being drawn correctly.
8836 gtk_widget_is_composited (GtkWidget *widget)
8840 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8842 screen = gtk_widget_get_screen (widget);
8844 return gdk_screen_is_composited (screen);
8848 propagate_composited_changed (GtkWidget *widget,
8851 if (GTK_IS_CONTAINER (widget))
8853 gtk_container_forall (GTK_CONTAINER (widget),
8854 propagate_composited_changed,
8858 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8862 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8864 propagate_composited_changed (widget, NULL);
8868 * _gtk_widget_propagate_screen_changed:
8869 * @widget: a #GtkWidget
8870 * @previous_screen: Previous screen
8872 * Propagates changes in the screen for a widget to all
8873 * children, emitting #GtkWidget::screen-changed.
8876 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8877 GdkScreen *previous_screen)
8879 HierarchyChangedInfo info;
8881 info.previous_screen = previous_screen;
8882 info.new_screen = gtk_widget_get_screen (widget);
8884 if (previous_screen)
8885 g_object_ref (previous_screen);
8887 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8889 if (previous_screen)
8890 g_object_unref (previous_screen);
8894 reset_style_recurse (GtkWidget *widget, gpointer data)
8896 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8898 if (GTK_IS_CONTAINER (widget))
8899 gtk_container_forall (GTK_CONTAINER (widget),
8900 reset_style_recurse,
8905 * gtk_widget_reset_style:
8906 * @widget: a #GtkWidget
8908 * Updates the style context of @widget and all descendents
8909 * by updating its widget path. #GtkContainer<!-- -->s may want
8910 * to use this on a child when reordering it in a way that a different
8911 * style might apply to it. See also gtk_container_get_path_for_child().
8916 gtk_widget_reset_style (GtkWidget *widget)
8918 g_return_if_fail (GTK_IS_WIDGET (widget));
8920 reset_style_recurse (widget, NULL);
8922 g_list_foreach (widget->priv->attached_windows,
8923 (GFunc) reset_style_recurse, NULL);
8926 #ifdef G_ENABLE_DEBUG
8928 /* Verify invariants, see docs/widget_system.txt for notes on much of
8929 * this. Invariants may be temporarily broken while we're in the
8930 * process of updating state, of course, so you can only
8931 * verify_invariants() after a given operation is complete.
8932 * Use push/pop_verify_invariants to help with that.
8935 gtk_widget_verify_invariants (GtkWidget *widget)
8939 if (widget->priv->verifying_invariants_count > 0)
8942 parent = widget->priv->parent;
8944 if (widget->priv->mapped)
8946 /* Mapped implies ... */
8948 if (!widget->priv->realized)
8949 g_warning ("%s %p is mapped but not realized",
8950 G_OBJECT_TYPE_NAME (widget), widget);
8952 if (!widget->priv->visible)
8953 g_warning ("%s %p is mapped but not visible",
8954 G_OBJECT_TYPE_NAME (widget), widget);
8956 if (!widget->priv->toplevel)
8958 if (!widget->priv->child_visible)
8959 g_warning ("%s %p is mapped but not child_visible",
8960 G_OBJECT_TYPE_NAME (widget), widget);
8965 /* Not mapped implies... */
8968 /* This check makes sense for normal toplevels, but for
8969 * something like a toplevel that is embedded within a clutter
8970 * state, mapping may depend on external factors.
8972 if (widget->priv->toplevel)
8974 if (widget->priv->visible)
8975 g_warning ("%s %p toplevel is visible but not mapped",
8976 G_OBJECT_TYPE_NAME (widget), widget);
8981 /* Parent related checks aren't possible if parent has
8982 * verifying_invariants_count > 0 because parent needs to recurse
8983 * children first before the invariants will hold.
8985 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8988 parent->priv->realized)
8990 /* Parent realized implies... */
8993 /* This is in widget_system.txt but appears to fail
8994 * because there's no gtk_container_realize() that
8995 * realizes all children... instead we just lazily
8996 * wait for map to fix things up.
8998 if (!widget->priv->realized)
8999 g_warning ("%s %p is realized but child %s %p is not realized",
9000 G_OBJECT_TYPE_NAME (parent), parent,
9001 G_OBJECT_TYPE_NAME (widget), widget);
9004 else if (!widget->priv->toplevel)
9006 /* No parent or parent not realized on non-toplevel implies... */
9008 if (widget->priv->realized && !widget->priv->in_reparent)
9009 g_warning ("%s %p is not realized but child %s %p is realized",
9010 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9011 G_OBJECT_TYPE_NAME (widget), widget);
9015 parent->priv->mapped &&
9016 widget->priv->visible &&
9017 widget->priv->child_visible)
9019 /* Parent mapped and we are visible implies... */
9021 if (!widget->priv->mapped)
9022 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
9023 G_OBJECT_TYPE_NAME (parent), parent,
9024 G_OBJECT_TYPE_NAME (widget), widget);
9026 else if (!widget->priv->toplevel)
9028 /* No parent or parent not mapped on non-toplevel implies... */
9030 if (widget->priv->mapped && !widget->priv->in_reparent)
9031 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
9032 G_OBJECT_TYPE_NAME (widget), widget,
9033 widget->priv->visible,
9034 widget->priv->child_visible,
9035 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9036 parent ? parent->priv->mapped : FALSE);
9040 if (!widget->priv->realized)
9042 /* Not realized implies... */
9045 /* widget_system.txt says these hold, but they don't. */
9046 if (widget->priv->alloc_needed)
9047 g_warning ("%s %p alloc needed but not realized",
9048 G_OBJECT_TYPE_NAME (widget), widget);
9050 if (widget->priv->width_request_needed)
9051 g_warning ("%s %p width request needed but not realized",
9052 G_OBJECT_TYPE_NAME (widget), widget);
9054 if (widget->priv->height_request_needed)
9055 g_warning ("%s %p height request needed but not realized",
9056 G_OBJECT_TYPE_NAME (widget), widget);
9061 /* The point of this push/pop is that invariants may not hold while
9062 * we're busy making changes. So we only check at the outermost call
9063 * on the call stack, after we finish updating everything.
9066 gtk_widget_push_verify_invariants (GtkWidget *widget)
9068 widget->priv->verifying_invariants_count += 1;
9072 gtk_widget_verify_child_invariants (GtkWidget *widget,
9073 gpointer client_data)
9075 /* We don't recurse further; this is a one-level check. */
9076 gtk_widget_verify_invariants (widget);
9080 gtk_widget_pop_verify_invariants (GtkWidget *widget)
9082 g_assert (widget->priv->verifying_invariants_count > 0);
9084 widget->priv->verifying_invariants_count -= 1;
9086 if (widget->priv->verifying_invariants_count == 0)
9088 gtk_widget_verify_invariants (widget);
9090 if (GTK_IS_CONTAINER (widget))
9092 /* Check one level of children, because our
9093 * push_verify_invariants() will have prevented some of the
9094 * checks. This does not recurse because if recursion is
9095 * needed, it will happen naturally as each child has a
9096 * push/pop on that child. For example if we're recursively
9097 * mapping children, we'll push/pop on each child as we map
9100 gtk_container_forall (GTK_CONTAINER (widget),
9101 gtk_widget_verify_child_invariants,
9106 #endif /* G_ENABLE_DEBUG */
9108 static PangoContext *
9109 gtk_widget_peek_pango_context (GtkWidget *widget)
9111 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9115 * gtk_widget_get_pango_context:
9116 * @widget: a #GtkWidget
9118 * Gets a #PangoContext with the appropriate font map, font description,
9119 * and base direction for this widget. Unlike the context returned
9120 * by gtk_widget_create_pango_context(), this context is owned by
9121 * the widget (it can be used until the screen for the widget changes
9122 * or the widget is removed from its toplevel), and will be updated to
9123 * match any changes to the widget's attributes. This can be tracked
9124 * by using the #GtkWidget::screen-changed signal on the widget.
9126 * Return value: (transfer none): the #PangoContext for the widget.
9129 gtk_widget_get_pango_context (GtkWidget *widget)
9131 PangoContext *context;
9133 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9135 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9138 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9139 g_object_set_qdata_full (G_OBJECT (widget),
9140 quark_pango_context,
9149 update_pango_context (GtkWidget *widget,
9150 PangoContext *context)
9152 PangoFontDescription *font_desc;
9153 GtkStyleContext *style_context;
9155 style_context = gtk_widget_get_style_context (widget);
9156 gtk_style_context_get (style_context,
9157 gtk_widget_get_state_flags (widget),
9161 pango_context_set_font_description (context, font_desc);
9162 pango_context_set_base_dir (context,
9163 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9164 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9166 pango_font_description_free (font_desc);
9170 gtk_widget_update_pango_context (GtkWidget *widget)
9172 PangoContext *context = gtk_widget_peek_pango_context (widget);
9178 update_pango_context (widget, context);
9180 screen = gtk_widget_get_screen_unchecked (widget);
9183 pango_cairo_context_set_resolution (context,
9184 gdk_screen_get_resolution (screen));
9185 pango_cairo_context_set_font_options (context,
9186 gdk_screen_get_font_options (screen));
9192 * gtk_widget_create_pango_context:
9193 * @widget: a #GtkWidget
9195 * Creates a new #PangoContext with the appropriate font map,
9196 * font description, and base direction for drawing text for
9197 * this widget. See also gtk_widget_get_pango_context().
9199 * Return value: (transfer full): the new #PangoContext
9202 gtk_widget_create_pango_context (GtkWidget *widget)
9205 PangoContext *context;
9207 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9209 screen = gtk_widget_get_screen_unchecked (widget);
9212 GTK_NOTE (MULTIHEAD,
9213 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9215 screen = gdk_screen_get_default ();
9218 context = gdk_pango_context_get_for_screen (screen);
9220 update_pango_context (widget, context);
9221 pango_context_set_language (context, gtk_get_default_language ());
9227 * gtk_widget_create_pango_layout:
9228 * @widget: a #GtkWidget
9229 * @text: text to set on the layout (can be %NULL)
9231 * Creates a new #PangoLayout with the appropriate font map,
9232 * font description, and base direction for drawing text for
9235 * If you keep a #PangoLayout created in this way around, you need
9236 * to re-create it when the widget #PangoContext is replaced.
9237 * This can be tracked by using the #GtkWidget::screen-changed signal
9240 * Return value: (transfer full): the new #PangoLayout
9243 gtk_widget_create_pango_layout (GtkWidget *widget,
9246 PangoLayout *layout;
9247 PangoContext *context;
9249 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9251 context = gtk_widget_get_pango_context (widget);
9252 layout = pango_layout_new (context);
9255 pango_layout_set_text (layout, text, -1);
9261 * gtk_widget_render_icon_pixbuf:
9262 * @widget: a #GtkWidget
9263 * @stock_id: a stock ID
9264 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9265 * render at the size of the source and don't scale (if there are
9266 * multiple source sizes, GTK+ picks one of the available sizes).
9268 * A convenience function that uses the theme engine and style
9269 * settings for @widget to look up @stock_id and render it to
9270 * a pixbuf. @stock_id should be a stock icon ID such as
9271 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9272 * such as #GTK_ICON_SIZE_MENU.
9274 * The pixels in the returned #GdkPixbuf are shared with the rest of
9275 * the application and should not be modified. The pixbuf should be freed
9276 * after use with g_object_unref().
9278 * Return value: (transfer full): a new pixbuf, or %NULL if the
9279 * stock ID wasn't known
9284 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9285 const gchar *stock_id,
9288 GtkStyleContext *context;
9289 GtkIconSet *icon_set;
9291 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9292 g_return_val_if_fail (stock_id != NULL, NULL);
9293 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9295 context = gtk_widget_get_style_context (widget);
9296 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9298 if (icon_set == NULL)
9301 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9305 * gtk_widget_set_parent_window:
9306 * @widget: a #GtkWidget.
9307 * @parent_window: the new parent window.
9309 * Sets a non default parent window for @widget.
9311 * For GtkWindow classes, setting a @parent_window effects whether
9312 * the window is a toplevel window or can be embedded into other
9316 * For GtkWindow classes, this needs to be called before the
9317 * window is realized.
9322 gtk_widget_set_parent_window (GtkWidget *widget,
9323 GdkWindow *parent_window)
9325 GdkWindow *old_parent_window;
9327 g_return_if_fail (GTK_IS_WIDGET (widget));
9329 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9330 quark_parent_window);
9332 if (parent_window != old_parent_window)
9336 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9338 if (old_parent_window)
9339 g_object_unref (old_parent_window);
9341 g_object_ref (parent_window);
9343 /* Unset toplevel flag when adding a parent window to a widget,
9344 * this is the primary entry point to allow toplevels to be
9347 #ifdef GDK_WINDOWING_X11
9348 is_plug = GTK_IS_PLUG (widget);
9352 if (GTK_IS_WINDOW (widget) && !is_plug)
9353 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9358 * gtk_widget_get_parent_window:
9359 * @widget: a #GtkWidget.
9361 * Gets @widget's parent window.
9363 * Returns: (transfer none): the parent window of @widget.
9366 gtk_widget_get_parent_window (GtkWidget *widget)
9368 GtkWidgetPrivate *priv;
9369 GdkWindow *parent_window;
9371 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9373 priv = widget->priv;
9375 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9377 return (parent_window != NULL) ? parent_window :
9378 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9383 * gtk_widget_set_child_visible:
9384 * @widget: a #GtkWidget
9385 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9387 * Sets whether @widget should be mapped along with its when its parent
9388 * is mapped and @widget has been shown with gtk_widget_show().
9390 * The child visibility can be set for widget before it is added to
9391 * a container with gtk_widget_set_parent(), to avoid mapping
9392 * children unnecessary before immediately unmapping them. However
9393 * it will be reset to its default state of %TRUE when the widget
9394 * is removed from a container.
9396 * Note that changing the child visibility of a widget does not
9397 * queue a resize on the widget. Most of the time, the size of
9398 * a widget is computed from all visible children, whether or
9399 * not they are mapped. If this is not the case, the container
9400 * can queue a resize itself.
9402 * This function is only useful for container implementations and
9403 * never should be called by an application.
9406 gtk_widget_set_child_visible (GtkWidget *widget,
9407 gboolean is_visible)
9409 GtkWidgetPrivate *priv;
9411 g_return_if_fail (GTK_IS_WIDGET (widget));
9412 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9414 priv = widget->priv;
9416 g_object_ref (widget);
9417 gtk_widget_verify_invariants (widget);
9420 priv->child_visible = TRUE;
9423 GtkWidget *toplevel;
9425 priv->child_visible = FALSE;
9427 toplevel = gtk_widget_get_toplevel (widget);
9428 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9429 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9432 if (priv->parent && gtk_widget_get_realized (priv->parent))
9434 if (gtk_widget_get_mapped (priv->parent) &&
9435 priv->child_visible &&
9436 gtk_widget_get_visible (widget))
9437 gtk_widget_map (widget);
9439 gtk_widget_unmap (widget);
9442 gtk_widget_verify_invariants (widget);
9443 g_object_unref (widget);
9447 * gtk_widget_get_child_visible:
9448 * @widget: a #GtkWidget
9450 * Gets the value set with gtk_widget_set_child_visible().
9451 * If you feel a need to use this function, your code probably
9452 * needs reorganization.
9454 * This function is only useful for container implementations and
9455 * never should be called by an application.
9457 * Return value: %TRUE if the widget is mapped with the parent.
9460 gtk_widget_get_child_visible (GtkWidget *widget)
9462 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9464 return widget->priv->child_visible;
9468 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9470 GtkWidget *toplevel;
9472 toplevel = gtk_widget_get_toplevel (widget);
9474 if (gtk_widget_is_toplevel (toplevel))
9476 if (GTK_IS_WINDOW (toplevel))
9477 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9478 else if (GTK_IS_INVISIBLE (toplevel))
9479 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9486 * gtk_widget_get_screen:
9487 * @widget: a #GtkWidget
9489 * Get the #GdkScreen from the toplevel window associated with
9490 * this widget. This function can only be called after the widget
9491 * has been added to a widget hierarchy with a #GtkWindow
9494 * In general, you should only create screen specific
9495 * resources when a widget has been realized, and you should
9496 * free those resources when the widget is unrealized.
9498 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9503 gtk_widget_get_screen (GtkWidget *widget)
9507 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9509 screen = gtk_widget_get_screen_unchecked (widget);
9516 g_warning (G_STRLOC ": Can't get associated screen"
9517 " for a widget unless it is inside a toplevel GtkWindow\n"
9518 " widget type is %s associated top level type is %s",
9519 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9520 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9522 return gdk_screen_get_default ();
9527 * gtk_widget_has_screen:
9528 * @widget: a #GtkWidget
9530 * Checks whether there is a #GdkScreen is associated with
9531 * this widget. All toplevel widgets have an associated
9532 * screen, and all widgets added into a hierarchy with a toplevel
9533 * window at the top.
9535 * Return value: %TRUE if there is a #GdkScreen associcated
9541 gtk_widget_has_screen (GtkWidget *widget)
9543 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9545 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9549 * gtk_widget_get_display:
9550 * @widget: a #GtkWidget
9552 * Get the #GdkDisplay for the toplevel window associated with
9553 * this widget. This function can only be called after the widget
9554 * has been added to a widget hierarchy with a #GtkWindow at the top.
9556 * In general, you should only create display specific
9557 * resources when a widget has been realized, and you should
9558 * free those resources when the widget is unrealized.
9560 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9565 gtk_widget_get_display (GtkWidget *widget)
9567 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9569 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9573 * gtk_widget_get_root_window:
9574 * @widget: a #GtkWidget
9576 * Get the root window where this widget is located. This function can
9577 * only be called after the widget has been added to a widget
9578 * hierarchy with #GtkWindow at the top.
9580 * The root window is useful for such purposes as creating a popup
9581 * #GdkWindow associated with the window. In general, you should only
9582 * create display specific resources when a widget has been realized,
9583 * and you should free those resources when the widget is unrealized.
9585 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9590 gtk_widget_get_root_window (GtkWidget *widget)
9592 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9594 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9598 * gtk_widget_child_focus:
9599 * @widget: a #GtkWidget
9600 * @direction: direction of focus movement
9602 * This function is used by custom widget implementations; if you're
9603 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9604 * to a particular widget, and gtk_container_set_focus_chain() to
9605 * change the focus tab order. So you may want to investigate those
9606 * functions instead.
9608 * gtk_widget_child_focus() is called by containers as the user moves
9609 * around the window using keyboard shortcuts. @direction indicates
9610 * what kind of motion is taking place (up, down, left, right, tab
9611 * forward, tab backward). gtk_widget_child_focus() emits the
9612 * #GtkWidget::focus signal; widgets override the default handler
9613 * for this signal in order to implement appropriate focus behavior.
9615 * The default ::focus handler for a widget should return %TRUE if
9616 * moving in @direction left the focus on a focusable location inside
9617 * that widget, and %FALSE if moving in @direction moved the focus
9618 * outside the widget. If returning %TRUE, widgets normally
9619 * call gtk_widget_grab_focus() to place the focus accordingly;
9620 * if returning %FALSE, they don't modify the current focus location.
9622 * Return value: %TRUE if focus ended up inside @widget
9625 gtk_widget_child_focus (GtkWidget *widget,
9626 GtkDirectionType direction)
9628 gboolean return_val;
9630 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9632 if (!gtk_widget_get_visible (widget) ||
9633 !gtk_widget_is_sensitive (widget))
9636 /* child widgets must set CAN_FOCUS, containers
9637 * don't have to though.
9639 if (!GTK_IS_CONTAINER (widget) &&
9640 !gtk_widget_get_can_focus (widget))
9643 g_signal_emit (widget,
9644 widget_signals[FOCUS],
9646 direction, &return_val);
9652 * gtk_widget_keynav_failed:
9653 * @widget: a #GtkWidget
9654 * @direction: direction of focus movement
9656 * This function should be called whenever keyboard navigation within
9657 * a single widget hits a boundary. The function emits the
9658 * #GtkWidget::keynav-failed signal on the widget and its return
9659 * value should be interpreted in a way similar to the return value of
9660 * gtk_widget_child_focus():
9662 * When %TRUE is returned, stay in the widget, the failed keyboard
9663 * navigation is Ok and/or there is nowhere we can/should move the
9666 * When %FALSE is returned, the caller should continue with keyboard
9667 * navigation outside the widget, e.g. by calling
9668 * gtk_widget_child_focus() on the widget's toplevel.
9670 * The default ::keynav-failed handler returns %TRUE for
9671 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9672 * values of #GtkDirectionType, it looks at the
9673 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9674 * if the setting is %TRUE. This way the entire user interface
9675 * becomes cursor-navigatable on input devices such as mobile phones
9676 * which only have cursor keys but no tab key.
9678 * Whenever the default handler returns %TRUE, it also calls
9679 * gtk_widget_error_bell() to notify the user of the failed keyboard
9682 * A use case for providing an own implementation of ::keynav-failed
9683 * (either by connecting to it or by overriding it) would be a row of
9684 * #GtkEntry widgets where the user should be able to navigate the
9685 * entire row with the cursor keys, as e.g. known from user interfaces
9686 * that require entering license keys.
9688 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9689 * if the emitting widget should try to handle the keyboard
9690 * navigation attempt in its parent container(s).
9695 gtk_widget_keynav_failed (GtkWidget *widget,
9696 GtkDirectionType direction)
9698 gboolean return_val;
9700 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9702 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9703 direction, &return_val);
9709 * gtk_widget_error_bell:
9710 * @widget: a #GtkWidget
9712 * Notifies the user about an input-related error on this widget.
9713 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9714 * gdk_window_beep(), otherwise it does nothing.
9716 * Note that the effect of gdk_window_beep() can be configured in many
9717 * ways, depending on the windowing backend and the desktop environment
9718 * or window manager that is used.
9723 gtk_widget_error_bell (GtkWidget *widget)
9725 GtkWidgetPrivate *priv;
9726 GtkSettings* settings;
9729 g_return_if_fail (GTK_IS_WIDGET (widget));
9731 priv = widget->priv;
9733 settings = gtk_widget_get_settings (widget);
9737 g_object_get (settings,
9738 "gtk-error-bell", &beep,
9741 if (beep && priv->window)
9742 gdk_window_beep (priv->window);
9746 gtk_widget_set_usize_internal (GtkWidget *widget,
9749 GtkQueueResizeFlags flags)
9751 GtkWidgetAuxInfo *aux_info;
9752 gboolean changed = FALSE;
9754 g_object_freeze_notify (G_OBJECT (widget));
9756 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9758 if (width > -2 && aux_info->width != width)
9760 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9761 g_object_notify (G_OBJECT (widget), "width-request");
9762 aux_info->width = width;
9765 if (height > -2 && aux_info->height != height)
9767 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9768 g_object_notify (G_OBJECT (widget), "height-request");
9769 aux_info->height = height;
9773 if (gtk_widget_get_visible (widget) && changed)
9775 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9776 gtk_widget_queue_resize (widget);
9778 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9781 g_object_thaw_notify (G_OBJECT (widget));
9785 * gtk_widget_set_size_request:
9786 * @widget: a #GtkWidget
9787 * @width: width @widget should request, or -1 to unset
9788 * @height: height @widget should request, or -1 to unset
9790 * Sets the minimum size of a widget; that is, the widget's size
9791 * request will be at least @width by @height. You can use this
9792 * function to force a widget to be larger than it normally would be.
9794 * In most cases, gtk_window_set_default_size() is a better choice for
9795 * toplevel windows than this function; setting the default size will
9796 * still allow users to shrink the window. Setting the size request
9797 * will force them to leave the window at least as large as the size
9798 * request. When dealing with window sizes,
9799 * gtk_window_set_geometry_hints() can be a useful function as well.
9801 * Note the inherent danger of setting any fixed size - themes,
9802 * translations into other languages, different fonts, and user action
9803 * can all change the appropriate size for a given widget. So, it's
9804 * basically impossible to hardcode a size that will always be
9807 * The size request of a widget is the smallest size a widget can
9808 * accept while still functioning well and drawing itself correctly.
9809 * However in some strange cases a widget may be allocated less than
9810 * its requested size, and in many cases a widget may be allocated more
9811 * space than it requested.
9813 * If the size request in a given direction is -1 (unset), then
9814 * the "natural" size request of the widget will be used instead.
9816 * The size request set here does not include any margin from the
9817 * #GtkWidget properties margin-left, margin-right, margin-top, and
9818 * margin-bottom, but it does include pretty much all other padding
9819 * or border properties set by any subclass of #GtkWidget.
9822 gtk_widget_set_size_request (GtkWidget *widget,
9826 g_return_if_fail (GTK_IS_WIDGET (widget));
9827 g_return_if_fail (width >= -1);
9828 g_return_if_fail (height >= -1);
9835 gtk_widget_set_usize_internal (widget, width, height, 0);
9840 * gtk_widget_get_size_request:
9841 * @widget: a #GtkWidget
9842 * @width: (out) (allow-none): return location for width, or %NULL
9843 * @height: (out) (allow-none): return location for height, or %NULL
9845 * Gets the size request that was explicitly set for the widget using
9846 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9847 * @height indicates that that dimension has not been set explicitly
9848 * and the natural requisition of the widget will be used intead. See
9849 * gtk_widget_set_size_request(). To get the size a widget will
9850 * actually request, call gtk_widget_get_preferred_size() instead of
9854 gtk_widget_get_size_request (GtkWidget *widget,
9858 const GtkWidgetAuxInfo *aux_info;
9860 g_return_if_fail (GTK_IS_WIDGET (widget));
9862 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9865 *width = aux_info->width;
9868 *height = aux_info->height;
9872 * _gtk_widget_override_size_request:
9873 * @widget: a #GtkWidget
9874 * @width: new forced minimum width
9875 * @height: new forced minimum height
9876 * @old_width: location to store previous forced minimum width
9877 * @old_height: location to store previous forced minumum height
9879 * Temporarily establishes a forced minimum size for a widget; this
9880 * is used by GtkWindow when calculating the size to add to the
9881 * window's geometry widget. Cached sizes for the widget and its
9882 * parents are invalidated, so that subsequent calls to the size
9883 * negotiation machinery produce the overriden result, but the
9884 * widget is not queued for relayout or redraw. The old size must
9885 * be restored with _gtk_widget_restore_size_request() or things
9889 _gtk_widget_override_size_request (GtkWidget *widget,
9895 gtk_widget_get_size_request (widget, old_width, old_height);
9896 gtk_widget_set_usize_internal (widget, width, height,
9897 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9901 * _gtk_widget_restore_size_request:
9902 * @widget: a #GtkWidget
9903 * @old_width: saved forced minimum size
9904 * @old_height: saved forced minimum size
9906 * Undoes the operation of_gtk_widget_override_size_request().
9909 _gtk_widget_restore_size_request (GtkWidget *widget,
9913 gtk_widget_set_usize_internal (widget, old_width, old_height,
9914 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9918 * gtk_widget_set_events:
9919 * @widget: a #GtkWidget
9920 * @events: event mask
9922 * Sets the event mask (see #GdkEventMask) for a widget. The event
9923 * mask determines which events a widget will receive. Keep in mind
9924 * that different widgets have different default event masks, and by
9925 * changing the event mask you may disrupt a widget's functionality,
9926 * so be careful. This function must be called while a widget is
9927 * unrealized. Consider gtk_widget_add_events() for widgets that are
9928 * already realized, or if you want to preserve the existing event
9929 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9930 * to get events on those widgets, place them inside a #GtkEventBox
9931 * and receive events on the event box.
9934 gtk_widget_set_events (GtkWidget *widget,
9937 g_return_if_fail (GTK_IS_WIDGET (widget));
9938 g_return_if_fail (!gtk_widget_get_realized (widget));
9940 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9941 GINT_TO_POINTER (events));
9942 g_object_notify (G_OBJECT (widget), "events");
9946 * gtk_widget_set_device_events:
9947 * @widget: a #GtkWidget
9948 * @device: a #GdkDevice
9949 * @events: event mask
9951 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9952 * mask determines which events a widget will receive from @device. Keep
9953 * in mind that different widgets have different default event masks, and by
9954 * changing the event mask you may disrupt a widget's functionality,
9955 * so be careful. This function must be called while a widget is
9956 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9957 * already realized, or if you want to preserve the existing event
9958 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9959 * to get events on those widgets, place them inside a #GtkEventBox
9960 * and receive events on the event box.
9965 gtk_widget_set_device_events (GtkWidget *widget,
9967 GdkEventMask events)
9969 GHashTable *device_events;
9971 g_return_if_fail (GTK_IS_WIDGET (widget));
9972 g_return_if_fail (GDK_IS_DEVICE (device));
9973 g_return_if_fail (!gtk_widget_get_realized (widget));
9975 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9977 if (G_UNLIKELY (!device_events))
9979 device_events = g_hash_table_new (NULL, NULL);
9980 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9981 (GDestroyNotify) g_hash_table_unref);
9984 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9988 * gtk_widget_set_device_enabled:
9989 * @widget: a #GtkWidget
9990 * @device: a #GdkDevice
9991 * @enabled: whether to enable the device
9993 * Enables or disables a #GdkDevice to interact with @widget
9994 * and all its children.
9996 * It does so by descending through the #GdkWindow hierarchy
9997 * and enabling the same mask that is has for core events
9998 * (i.e. the one that gdk_window_get_events() returns).
10003 gtk_widget_set_device_enabled (GtkWidget *widget,
10007 GList *enabled_devices;
10009 g_return_if_fail (GTK_IS_WIDGET (widget));
10010 g_return_if_fail (GDK_IS_DEVICE (device));
10012 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10013 enabled_devices = g_list_append (enabled_devices, device);
10015 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
10016 enabled_devices, (GDestroyNotify) g_list_free);;
10018 if (gtk_widget_get_realized (widget))
10019 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
10023 * gtk_widget_get_device_enabled:
10024 * @widget: a #GtkWidget
10025 * @device: a #GdkDevice
10027 * Returns whether @device can interact with @widget and its
10028 * children. See gtk_widget_set_device_enabled().
10030 * Return value: %TRUE is @device is enabled for @widget
10035 gtk_widget_get_device_enabled (GtkWidget *widget,
10038 GList *enabled_devices;
10040 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10041 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
10043 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10045 return g_list_find (enabled_devices, device) != NULL;
10049 gtk_widget_add_events_internal_list (GtkWidget *widget,
10052 GList *window_list)
10056 for (l = window_list; l != NULL; l = l->next)
10058 GdkWindow *window = l->data;
10059 gpointer user_data;
10061 gdk_window_get_user_data (window, &user_data);
10062 if (user_data == widget)
10067 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
10069 gdk_window_set_events (window, gdk_window_get_events (window) | events);
10071 children = gdk_window_get_children (window);
10072 gtk_widget_add_events_internal_list (widget, device, events, children);
10073 g_list_free (children);
10079 gtk_widget_add_events_internal (GtkWidget *widget,
10083 GtkWidgetPrivate *priv = widget->priv;
10084 GList *window_list;
10086 if (!gtk_widget_get_has_window (widget))
10087 window_list = gdk_window_get_children (priv->window);
10089 window_list = g_list_prepend (NULL, priv->window);
10091 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10093 g_list_free (window_list);
10097 * gtk_widget_add_events:
10098 * @widget: a #GtkWidget
10099 * @events: an event mask, see #GdkEventMask
10101 * Adds the events in the bitfield @events to the event mask for
10102 * @widget. See gtk_widget_set_events() for details.
10105 gtk_widget_add_events (GtkWidget *widget,
10110 g_return_if_fail (GTK_IS_WIDGET (widget));
10112 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10113 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10114 GINT_TO_POINTER (old_events | events));
10116 if (gtk_widget_get_realized (widget))
10118 gtk_widget_add_events_internal (widget, NULL, events);
10119 gtk_widget_update_devices_mask (widget, FALSE);
10122 g_object_notify (G_OBJECT (widget), "events");
10126 * gtk_widget_add_device_events:
10127 * @widget: a #GtkWidget
10128 * @device: a #GdkDevice
10129 * @events: an event mask, see #GdkEventMask
10131 * Adds the device events in the bitfield @events to the event mask for
10132 * @widget. See gtk_widget_set_device_events() for details.
10137 gtk_widget_add_device_events (GtkWidget *widget,
10139 GdkEventMask events)
10141 GdkEventMask old_events;
10142 GHashTable *device_events;
10144 g_return_if_fail (GTK_IS_WIDGET (widget));
10145 g_return_if_fail (GDK_IS_DEVICE (device));
10147 old_events = gtk_widget_get_device_events (widget, device);
10149 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10151 if (G_UNLIKELY (!device_events))
10153 device_events = g_hash_table_new (NULL, NULL);
10154 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10155 (GDestroyNotify) g_hash_table_unref);
10158 g_hash_table_insert (device_events, device,
10159 GUINT_TO_POINTER (old_events | events));
10161 if (gtk_widget_get_realized (widget))
10162 gtk_widget_add_events_internal (widget, device, events);
10164 g_object_notify (G_OBJECT (widget), "events");
10168 * gtk_widget_get_toplevel:
10169 * @widget: a #GtkWidget
10171 * This function returns the topmost widget in the container hierarchy
10172 * @widget is a part of. If @widget has no parent widgets, it will be
10173 * returned as the topmost widget. No reference will be added to the
10174 * returned widget; it should not be unreferenced.
10176 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10177 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10179 * %NULL if @widget wasn't inside a toplevel window, and if the
10180 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
10181 * inside the toplevel #GtkWindow. While the second case may
10182 * seem unlikely, it actually happens when a #GtkPlug is embedded
10183 * inside a #GtkSocket within the same application.
10185 * To reliably find the toplevel #GtkWindow, use
10186 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10187 * is set on the result.
10189 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10190 * if (gtk_widget_is_toplevel (toplevel))
10192 * /* Perform action on toplevel. */
10196 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10197 * if there's no ancestor.
10200 gtk_widget_get_toplevel (GtkWidget *widget)
10202 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10204 while (widget->priv->parent)
10205 widget = widget->priv->parent;
10211 * gtk_widget_get_ancestor:
10212 * @widget: a #GtkWidget
10213 * @widget_type: ancestor type
10215 * Gets the first ancestor of @widget with type @widget_type. For example,
10216 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10217 * the first #GtkBox that's an ancestor of @widget. No reference will be
10218 * added to the returned widget; it should not be unreferenced. See note
10219 * about checking for a toplevel #GtkWindow in the docs for
10220 * gtk_widget_get_toplevel().
10222 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10223 * considers @widget to be an ancestor of itself.
10225 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10228 gtk_widget_get_ancestor (GtkWidget *widget,
10231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10233 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10234 widget = widget->priv->parent;
10236 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10243 * gtk_widget_set_visual:
10244 * @widget: a #GtkWidget
10245 * @visual: visual to be used or %NULL to unset a previous one
10247 * Sets the visual that should be used for by widget and its children for
10248 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10249 * returned by gtk_widget_get_screen(), so handling the
10250 * #GtkWidget::screen-changed signal is necessary.
10252 * Setting a new @visual will not cause @widget to recreate its windows,
10253 * so you should call this function before @widget is realized.
10256 gtk_widget_set_visual (GtkWidget *widget,
10259 g_return_if_fail (GTK_IS_WIDGET (widget));
10260 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10263 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10266 g_object_set_qdata_full (G_OBJECT (widget),
10268 g_object_ref (visual),
10273 * gtk_widget_get_visual:
10274 * @widget: a #GtkWidget
10276 * Gets the visual that will be used to render @widget.
10278 * Return value: (transfer none): the visual for @widget
10281 gtk_widget_get_visual (GtkWidget *widget)
10287 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10289 if (gtk_widget_get_has_window (widget) &&
10290 widget->priv->window)
10291 return gdk_window_get_visual (widget->priv->window);
10293 screen = gtk_widget_get_screen (widget);
10295 for (w = widget; w != NULL; w = w->priv->parent)
10297 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10300 if (gdk_visual_get_screen (visual) == screen)
10303 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10304 gtk_widget_get_name (widget));
10308 return gdk_screen_get_system_visual (screen);
10312 * gtk_widget_get_settings:
10313 * @widget: a #GtkWidget
10315 * Gets the settings object holding the settings used for this widget.
10317 * Note that this function can only be called when the #GtkWidget
10318 * is attached to a toplevel, since the settings object is specific
10319 * to a particular #GdkScreen.
10321 * Return value: (transfer none): the relevant #GtkSettings object
10324 gtk_widget_get_settings (GtkWidget *widget)
10326 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10328 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10332 * gtk_widget_get_events:
10333 * @widget: a #GtkWidget
10335 * Returns the event mask for the widget (a bitfield containing flags
10336 * from the #GdkEventMask enumeration). These are the events that the widget
10339 * Return value: event mask for @widget
10342 gtk_widget_get_events (GtkWidget *widget)
10344 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10346 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10350 * gtk_widget_get_device_events:
10351 * @widget: a #GtkWidget
10352 * @device: a #GdkDevice
10354 * Returns the events mask for the widget corresponding to an specific device. These
10355 * are the events that the widget will receive when @device operates on it.
10357 * Returns: device event mask for @widget
10362 gtk_widget_get_device_events (GtkWidget *widget,
10365 GHashTable *device_events;
10367 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10368 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10370 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10372 if (!device_events)
10375 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10379 * gtk_widget_get_pointer:
10380 * @widget: a #GtkWidget
10381 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10382 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10384 * Obtains the location of the mouse pointer in widget coordinates.
10385 * Widget coordinates are a bit odd; for historical reasons, they are
10386 * defined as @widget->window coordinates for widgets that are not
10387 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10388 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10390 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10393 gtk_widget_get_pointer (GtkWidget *widget,
10397 GtkWidgetPrivate *priv;
10399 g_return_if_fail (GTK_IS_WIDGET (widget));
10401 priv = widget->priv;
10408 if (gtk_widget_get_realized (widget))
10410 gdk_window_get_device_position (priv->window,
10411 gdk_device_manager_get_client_pointer (
10412 gdk_display_get_device_manager (
10413 gtk_widget_get_display (widget))),
10416 if (!gtk_widget_get_has_window (widget))
10419 *x -= priv->allocation.x;
10421 *y -= priv->allocation.y;
10427 * gtk_widget_is_ancestor:
10428 * @widget: a #GtkWidget
10429 * @ancestor: another #GtkWidget
10431 * Determines whether @widget is somewhere inside @ancestor, possibly with
10432 * intermediate containers.
10434 * Return value: %TRUE if @ancestor contains @widget as a child,
10435 * grandchild, great grandchild, etc.
10438 gtk_widget_is_ancestor (GtkWidget *widget,
10439 GtkWidget *ancestor)
10441 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10442 g_return_val_if_fail (ancestor != NULL, FALSE);
10446 if (widget->priv->parent == ancestor)
10448 widget = widget->priv->parent;
10454 static GQuark quark_composite_name = 0;
10457 * gtk_widget_set_composite_name:
10458 * @widget: a #GtkWidget.
10459 * @name: the name to set
10461 * Sets a widgets composite name. The widget must be
10462 * a composite child of its parent; see gtk_widget_push_composite_child().
10465 gtk_widget_set_composite_name (GtkWidget *widget,
10468 g_return_if_fail (GTK_IS_WIDGET (widget));
10469 g_return_if_fail (widget->priv->composite_child);
10470 g_return_if_fail (name != NULL);
10472 if (!quark_composite_name)
10473 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10475 g_object_set_qdata_full (G_OBJECT (widget),
10476 quark_composite_name,
10482 * gtk_widget_get_composite_name:
10483 * @widget: a #GtkWidget
10485 * Obtains the composite name of a widget.
10487 * Returns: the composite name of @widget, or %NULL if @widget is not
10488 * a composite child. The string should be freed when it is no
10492 gtk_widget_get_composite_name (GtkWidget *widget)
10494 GtkWidgetPrivate *priv;
10496 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10498 priv = widget->priv;
10500 if (widget->priv->composite_child && priv->parent)
10501 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10508 * gtk_widget_push_composite_child:
10510 * Makes all newly-created widgets as composite children until
10511 * the corresponding gtk_widget_pop_composite_child() call.
10513 * A composite child is a child that's an implementation detail of the
10514 * container it's inside and should not be visible to people using the
10515 * container. Composite children aren't treated differently by GTK (but
10516 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10517 * builders might want to treat them in a different way.
10519 * Here is a simple example:
10521 * gtk_widget_push_composite_child ();
10522 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10523 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10524 * gtk_widget_pop_composite_child ();
10525 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10526 * GTK_WIDGET (scrolled_window));
10527 * g_object_ref (scrolled_window->hscrollbar);
10531 gtk_widget_push_composite_child (void)
10533 composite_child_stack++;
10537 * gtk_widget_pop_composite_child:
10539 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10542 gtk_widget_pop_composite_child (void)
10544 if (composite_child_stack)
10545 composite_child_stack--;
10549 gtk_widget_emit_direction_changed (GtkWidget *widget,
10550 GtkTextDirection old_dir)
10552 GtkTextDirection direction;
10553 GtkStateFlags state;
10555 gtk_widget_update_pango_context (widget);
10557 direction = gtk_widget_get_direction (widget);
10558 state = widget->priv->state_flags;
10559 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10563 case GTK_TEXT_DIR_LTR:
10564 state |= GTK_STATE_FLAG_DIR_LTR;
10567 case GTK_TEXT_DIR_RTL:
10568 state |= GTK_STATE_FLAG_DIR_RTL;
10571 case GTK_TEXT_DIR_NONE:
10573 g_assert_not_reached ();
10577 gtk_widget_set_state_flags (widget, state, TRUE);
10579 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10583 * gtk_widget_set_direction:
10584 * @widget: a #GtkWidget
10585 * @dir: the new direction
10587 * Sets the reading direction on a particular widget. This direction
10588 * controls the primary direction for widgets containing text,
10589 * and also the direction in which the children of a container are
10590 * packed. The ability to set the direction is present in order
10591 * so that correct localization into languages with right-to-left
10592 * reading directions can be done. Generally, applications will
10593 * let the default reading direction present, except for containers
10594 * where the containers are arranged in an order that is explicitely
10595 * visual rather than logical (such as buttons for text justification).
10597 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10598 * set by gtk_widget_set_default_direction() will be used.
10601 gtk_widget_set_direction (GtkWidget *widget,
10602 GtkTextDirection dir)
10604 GtkTextDirection old_dir;
10606 g_return_if_fail (GTK_IS_WIDGET (widget));
10607 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10609 old_dir = gtk_widget_get_direction (widget);
10611 widget->priv->direction = dir;
10613 if (old_dir != gtk_widget_get_direction (widget))
10614 gtk_widget_emit_direction_changed (widget, old_dir);
10618 * gtk_widget_get_direction:
10619 * @widget: a #GtkWidget
10621 * Gets the reading direction for a particular widget. See
10622 * gtk_widget_set_direction().
10624 * Return value: the reading direction for the widget.
10627 gtk_widget_get_direction (GtkWidget *widget)
10629 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10631 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10632 return gtk_default_direction;
10634 return widget->priv->direction;
10638 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10640 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10642 g_object_ref (widget);
10644 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10645 gtk_widget_emit_direction_changed (widget, old_dir);
10647 if (GTK_IS_CONTAINER (widget))
10648 gtk_container_forall (GTK_CONTAINER (widget),
10649 gtk_widget_set_default_direction_recurse,
10652 g_object_unref (widget);
10656 * gtk_widget_set_default_direction:
10657 * @dir: the new default direction. This cannot be
10658 * %GTK_TEXT_DIR_NONE.
10660 * Sets the default reading direction for widgets where the
10661 * direction has not been explicitly set by gtk_widget_set_direction().
10664 gtk_widget_set_default_direction (GtkTextDirection dir)
10666 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10668 if (dir != gtk_default_direction)
10670 GList *toplevels, *tmp_list;
10671 GtkTextDirection old_dir = gtk_default_direction;
10673 gtk_default_direction = dir;
10675 tmp_list = toplevels = gtk_window_list_toplevels ();
10676 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10680 gtk_widget_set_default_direction_recurse (tmp_list->data,
10681 GUINT_TO_POINTER (old_dir));
10682 g_object_unref (tmp_list->data);
10683 tmp_list = tmp_list->next;
10686 g_list_free (toplevels);
10691 * gtk_widget_get_default_direction:
10693 * Obtains the current default reading direction. See
10694 * gtk_widget_set_default_direction().
10696 * Return value: the current default direction.
10699 gtk_widget_get_default_direction (void)
10701 return gtk_default_direction;
10705 gtk_widget_constructed (GObject *object)
10707 GtkWidget *widget = GTK_WIDGET (object);
10708 GtkWidgetPrivate *priv = widget->priv;
10710 /* As strange as it may seem, this may happen on object construction.
10711 * init() implementations of parent types may eventually call this function,
10712 * each with its corresponding GType, which could leave a child
10713 * implementation with a wrong widget type in the widget path
10716 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10718 gtk_widget_path_free (priv->path);
10722 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10726 gtk_widget_dispose (GObject *object)
10728 GtkWidget *widget = GTK_WIDGET (object);
10729 GtkWidgetPrivate *priv = widget->priv;
10732 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10733 else if (gtk_widget_get_visible (widget))
10734 gtk_widget_hide (widget);
10736 priv->visible = FALSE;
10737 if (gtk_widget_get_realized (widget))
10738 gtk_widget_unrealize (widget);
10740 if (!priv->in_destruction)
10742 priv->in_destruction = TRUE;
10743 g_signal_emit (object, widget_signals[DESTROY], 0);
10744 priv->in_destruction = FALSE;
10747 g_clear_object (&priv->muxer);
10749 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10753 gtk_widget_real_destroy (GtkWidget *object)
10755 /* gtk_object_destroy() will already hold a refcount on object */
10756 GtkWidget *widget = GTK_WIDGET (object);
10757 GtkWidgetPrivate *priv = widget->priv;
10760 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10762 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10766 gtk_accessible_set_widget (accessible, NULL);
10767 g_object_unref (accessible);
10771 /* wipe accelerator closures (keep order) */
10772 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10773 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10775 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10776 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10778 gtk_grab_remove (widget);
10780 for (l = priv->tick_callbacks; l;)
10782 GList *next = l->next;
10783 destroy_tick_callback_info (widget, l->data, l);
10788 g_object_unref (priv->style);
10789 priv->style = gtk_widget_get_default_style ();
10790 g_object_ref (priv->style);
10794 gtk_widget_finalize (GObject *object)
10796 GtkWidget *widget = GTK_WIDGET (object);
10797 GtkWidgetPrivate *priv = widget->priv;
10798 GtkWidgetAuxInfo *aux_info;
10799 GtkAccessible *accessible;
10801 gtk_grab_remove (widget);
10803 g_object_unref (priv->style);
10804 priv->style = NULL;
10806 g_free (priv->name);
10808 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10810 gtk_widget_aux_info_destroy (aux_info);
10812 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10814 g_object_unref (accessible);
10817 gtk_widget_path_free (priv->path);
10821 _gtk_style_context_set_widget (priv->context, NULL);
10822 g_object_unref (priv->context);
10825 _gtk_size_request_cache_free (&priv->requests);
10827 if (g_object_is_floating (object))
10828 g_warning ("A floating object was finalized. This means that someone\n"
10829 "called g_object_unref() on an object that had only a floating\n"
10830 "reference; the initial floating reference is not owned by anyone\n"
10831 "and must be removed with g_object_ref_sink().");
10833 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10836 /*****************************************
10837 * gtk_widget_real_map:
10842 *****************************************/
10845 gtk_widget_real_map (GtkWidget *widget)
10847 GtkWidgetPrivate *priv = widget->priv;
10849 g_assert (gtk_widget_get_realized (widget));
10851 if (!gtk_widget_get_mapped (widget))
10853 gtk_widget_set_mapped (widget, TRUE);
10855 if (gtk_widget_get_has_window (widget))
10856 gdk_window_show (priv->window);
10860 /*****************************************
10861 * gtk_widget_real_unmap:
10866 *****************************************/
10869 gtk_widget_real_unmap (GtkWidget *widget)
10871 GtkWidgetPrivate *priv = widget->priv;
10873 if (gtk_widget_get_mapped (widget))
10875 gtk_widget_set_mapped (widget, FALSE);
10877 if (gtk_widget_get_has_window (widget))
10878 gdk_window_hide (priv->window);
10882 /*****************************************
10883 * gtk_widget_real_realize:
10888 *****************************************/
10891 gtk_widget_real_realize (GtkWidget *widget)
10893 GtkWidgetPrivate *priv = widget->priv;
10895 g_assert (!gtk_widget_get_has_window (widget));
10897 gtk_widget_set_realized (widget, TRUE);
10900 priv->window = gtk_widget_get_parent_window (widget);
10901 g_object_ref (priv->window);
10905 /*****************************************
10906 * gtk_widget_real_unrealize:
10911 *****************************************/
10914 gtk_widget_real_unrealize (GtkWidget *widget)
10916 GtkWidgetPrivate *priv = widget->priv;
10918 g_assert (!widget->priv->mapped);
10920 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10923 /* We must do unrealize child widget BEFORE container widget.
10924 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10925 * So, unrealizing container widget bofore its children causes the problem
10926 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10929 if (GTK_IS_CONTAINER (widget))
10930 gtk_container_forall (GTK_CONTAINER (widget),
10931 (GtkCallback) gtk_widget_unrealize,
10934 if (gtk_widget_get_has_window (widget))
10936 gtk_widget_unregister_window (widget, priv->window);
10937 gdk_window_destroy (priv->window);
10938 priv->window = NULL;
10942 g_object_unref (priv->window);
10943 priv->window = NULL;
10946 gtk_selection_remove_all (widget);
10948 gtk_widget_set_realized (widget, FALSE);
10952 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10953 GtkOrientation orientation,
10954 gint *minimum_size,
10955 gint *natural_size)
10957 const GtkWidgetAuxInfo *aux_info;
10959 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10961 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10962 aux_info->width > 0)
10964 *minimum_size = MAX (*minimum_size, aux_info->width);
10966 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10967 aux_info->height > 0)
10969 *minimum_size = MAX (*minimum_size, aux_info->height);
10972 /* Fix it if set_size_request made natural size smaller than min size.
10973 * This would also silently fix broken widgets, but we warn about them
10974 * in gtksizerequest.c when calling their size request vfuncs.
10976 *natural_size = MAX (*natural_size, *minimum_size);
10978 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10980 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10981 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10985 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10986 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10991 * _gtk_widget_peek_request_cache:
10993 * Returns the address of the widget's request cache (strictly for
10994 * internal use in gtksizerequest.c)
10996 * Return value: the address of @widget's size request cache.
10999 _gtk_widget_peek_request_cache (GtkWidget *widget)
11001 /* Don't bother slowing things down with the return_if_fail guards here */
11002 return &widget->priv->requests;
11006 * _gtk_widget_set_device_window:
11007 * @widget: a #GtkWidget
11008 * @device: a #GdkDevice
11009 * @window: the new device window
11011 * Sets pointer window for @widget and @device.
11012 * Does not ref @window.
11015 _gtk_widget_set_device_window (GtkWidget *widget,
11019 GHashTable *device_window;
11021 g_return_if_fail (GTK_IS_WIDGET (widget));
11022 g_return_if_fail (GDK_IS_DEVICE (device));
11023 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11025 if (!gtk_widget_get_mapped (widget))
11028 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11030 if (!device_window && window)
11032 device_window = g_hash_table_new (NULL, NULL);
11033 g_object_set_qdata_full (G_OBJECT (widget),
11034 quark_pointer_window,
11036 (GDestroyNotify) g_hash_table_destroy);
11040 g_hash_table_insert (device_window, device, window);
11041 else if (device_window)
11043 g_hash_table_remove (device_window, device);
11045 if (g_hash_table_size (device_window) == 0)
11046 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
11051 * _gtk_widget_get_device_window:
11052 * @widget: a #GtkWidget
11053 * @device: a #GdkDevice
11055 * Return value: the device window set on @widget, or %NULL
11058 _gtk_widget_get_device_window (GtkWidget *widget,
11061 GHashTable *device_window;
11063 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11064 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
11066 if (!gtk_widget_get_mapped (widget))
11069 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11071 if (!device_window)
11074 return g_hash_table_lookup (device_window, device);
11078 * _gtk_widget_list_devices:
11079 * @widget: a #GtkWidget
11081 * Returns the list of #GdkDevices that is currently on top
11082 * of any window belonging to @widget.
11083 * Free the list with g_list_free(), the elements are owned
11084 * by GTK+ and must not be freed.
11087 _gtk_widget_list_devices (GtkWidget *widget)
11089 GHashTableIter iter;
11090 GHashTable *device_window;
11091 GList *devices = NULL;
11092 gpointer key, value;
11094 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11096 if (!gtk_widget_get_mapped (widget))
11099 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11101 if (G_UNLIKELY (!device_window))
11104 g_hash_table_iter_init (&iter, device_window);
11106 while (g_hash_table_iter_next (&iter, &key, &value))
11107 devices = g_list_prepend (devices, key);
11113 synth_crossing (GtkWidget *widget,
11117 GdkCrossingMode mode,
11118 GdkNotifyType detail)
11122 event = gdk_event_new (type);
11124 event->crossing.window = g_object_ref (window);
11125 event->crossing.send_event = TRUE;
11126 event->crossing.subwindow = g_object_ref (window);
11127 event->crossing.time = GDK_CURRENT_TIME;
11128 event->crossing.x = event->crossing.y = 0;
11129 event->crossing.x_root = event->crossing.y_root = 0;
11130 event->crossing.mode = mode;
11131 event->crossing.detail = detail;
11132 event->crossing.focus = FALSE;
11133 event->crossing.state = 0;
11134 gdk_event_set_device (event, device);
11137 widget = gtk_get_event_widget (event);
11140 gtk_widget_event_internal (widget, event);
11142 gdk_event_free (event);
11146 * _gtk_widget_synthesize_crossing:
11147 * @from: the #GtkWidget the virtual pointer is leaving.
11148 * @to: the #GtkWidget the virtual pointer is moving to.
11149 * @mode: the #GdkCrossingMode to place on the synthesized events.
11151 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11153 * The real pointer window is the window that most recently received an enter notify
11154 * event. Windows that don't select for crossing events can't become the real
11155 * poiner window. The real pointer widget that owns the real pointer window. The
11156 * effective pointer window is the same as the real pointer window unless the real
11157 * pointer widget is either insensitive or there is a grab on a widget that is not
11158 * an ancestor of the real pointer widget (in which case the effective pointer
11159 * window should be the root window).
11161 * When the effective pointer window is the same as the real poiner window, we
11162 * receive crossing events from the windowing system. When the effective pointer
11163 * window changes to become different from the real pointer window we synthesize
11164 * crossing events, attempting to follow X protocol rules:
11166 * When the root window becomes the effective pointer window:
11167 * - leave notify on real pointer window, detail Ancestor
11168 * - leave notify on all of its ancestors, detail Virtual
11169 * - enter notify on root window, detail Inferior
11171 * When the root window ceases to be the effective pointer window:
11172 * - leave notify on root window, detail Inferior
11173 * - enter notify on all ancestors of real pointer window, detail Virtual
11174 * - enter notify on real pointer window, detail Ancestor
11177 _gtk_widget_synthesize_crossing (GtkWidget *from,
11180 GdkCrossingMode mode)
11182 GdkWindow *from_window = NULL, *to_window = NULL;
11184 g_return_if_fail (from != NULL || to != NULL);
11188 from_window = _gtk_widget_get_device_window (from, device);
11191 from_window = from->priv->window;
11196 to_window = _gtk_widget_get_device_window (to, device);
11199 to_window = to->priv->window;
11202 if (from_window == NULL && to_window == NULL)
11204 else if (from_window != NULL && to_window == NULL)
11206 GList *from_ancestors = NULL, *list;
11207 GdkWindow *from_ancestor = from_window;
11209 while (from_ancestor != NULL)
11211 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11212 if (from_ancestor == NULL)
11214 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11217 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11218 device, mode, GDK_NOTIFY_ANCESTOR);
11219 for (list = g_list_last (from_ancestors); list; list = list->prev)
11221 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11222 device, mode, GDK_NOTIFY_VIRTUAL);
11225 /* XXX: enter/inferior on root window? */
11227 g_list_free (from_ancestors);
11229 else if (from_window == NULL && to_window != NULL)
11231 GList *to_ancestors = NULL, *list;
11232 GdkWindow *to_ancestor = to_window;
11234 while (to_ancestor != NULL)
11236 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11237 if (to_ancestor == NULL)
11239 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11242 /* XXX: leave/inferior on root window? */
11244 for (list = to_ancestors; list; list = list->next)
11246 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11247 device, mode, GDK_NOTIFY_VIRTUAL);
11249 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11250 device, mode, GDK_NOTIFY_ANCESTOR);
11252 g_list_free (to_ancestors);
11254 else if (from_window == to_window)
11258 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11259 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11261 while (from_ancestor != NULL || to_ancestor != NULL)
11263 if (from_ancestor != NULL)
11265 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11266 if (from_ancestor == to_window)
11269 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11271 if (to_ancestor != NULL)
11273 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11274 if (to_ancestor == from_window)
11277 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11280 if (to_ancestor == from_window)
11282 if (mode != GDK_CROSSING_GTK_UNGRAB)
11283 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11284 device, mode, GDK_NOTIFY_INFERIOR);
11285 for (list = to_ancestors; list; list = list->next)
11286 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11287 device, mode, GDK_NOTIFY_VIRTUAL);
11288 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11289 device, mode, GDK_NOTIFY_ANCESTOR);
11291 else if (from_ancestor == to_window)
11293 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11294 device, mode, GDK_NOTIFY_ANCESTOR);
11295 for (list = g_list_last (from_ancestors); list; list = list->prev)
11297 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11298 device, mode, GDK_NOTIFY_VIRTUAL);
11300 if (mode != GDK_CROSSING_GTK_GRAB)
11301 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11302 device, mode, GDK_NOTIFY_INFERIOR);
11306 while (from_ancestors != NULL && to_ancestors != NULL
11307 && from_ancestors->data == to_ancestors->data)
11309 from_ancestors = g_list_delete_link (from_ancestors,
11311 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11314 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11315 device, mode, GDK_NOTIFY_NONLINEAR);
11317 for (list = g_list_last (from_ancestors); list; list = list->prev)
11319 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11320 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11322 for (list = to_ancestors; list; list = list->next)
11324 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11325 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11327 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11328 device, mode, GDK_NOTIFY_NONLINEAR);
11330 g_list_free (from_ancestors);
11331 g_list_free (to_ancestors);
11336 gtk_widget_propagate_state (GtkWidget *widget,
11337 GtkStateData *data)
11339 GtkWidgetPrivate *priv = widget->priv;
11340 GtkStateFlags new_flags, old_flags = priv->state_flags;
11341 GtkStateType old_state;
11343 old_state = gtk_widget_get_state (widget);
11345 priv->state_flags |= data->flags_to_set;
11346 priv->state_flags &= ~(data->flags_to_unset);
11348 /* make insensitivity unoverridable */
11349 if (!priv->sensitive)
11350 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11352 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11356 window = gtk_widget_get_toplevel (widget);
11358 if (window && gtk_widget_is_toplevel (window))
11359 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11362 new_flags = priv->state_flags;
11364 if (old_flags != new_flags)
11366 g_object_ref (widget);
11368 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11369 gtk_grab_remove (widget);
11371 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11373 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11374 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11376 if (!priv->shadowed &&
11377 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11379 GList *event_windows = NULL;
11380 GList *devices, *d;
11382 devices = _gtk_widget_list_devices (widget);
11384 for (d = devices; d; d = d->next)
11390 window = _gtk_widget_get_device_window (widget, device);
11392 /* Do not propagate more than once to the
11393 * same window if non-multidevice aware.
11395 if (!gdk_window_get_support_multidevice (window) &&
11396 g_list_find (event_windows, window))
11399 if (!gtk_widget_is_sensitive (widget))
11400 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11401 GDK_CROSSING_STATE_CHANGED);
11403 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11404 GDK_CROSSING_STATE_CHANGED);
11406 event_windows = g_list_prepend (event_windows, window);
11409 g_list_free (event_windows);
11410 g_list_free (devices);
11413 if (GTK_IS_CONTAINER (widget))
11415 GtkStateData child_data;
11417 /* Make sure to only propate the right states further */
11418 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11419 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11421 gtk_container_forall (GTK_CONTAINER (widget),
11422 (GtkCallback) gtk_widget_propagate_state,
11426 g_object_unref (widget);
11430 static const GtkWidgetAuxInfo default_aux_info = {
11438 * gtk_widget_get_aux_info:
11439 * @widget: a #GtkWidget
11440 * @create: if %TRUE, create the structure if it doesn't exist
11442 * Get the #GtkWidgetAuxInfo structure for the widget.
11444 * Return value: the #GtkAuxInfo structure for the widget, or
11445 * %NULL if @create is %FALSE and one doesn't already exist.
11447 static GtkWidgetAuxInfo *
11448 gtk_widget_get_aux_info (GtkWidget *widget,
11451 GtkWidgetAuxInfo *aux_info;
11453 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11454 if (!aux_info && create)
11456 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11458 *aux_info = default_aux_info;
11460 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11466 static const GtkWidgetAuxInfo*
11467 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11469 GtkWidgetAuxInfo *aux_info;
11471 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11472 if (aux_info == NULL)
11474 return &default_aux_info;
11482 /*****************************************
11483 * gtk_widget_aux_info_destroy:
11488 *****************************************/
11491 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11493 g_slice_free (GtkWidgetAuxInfo, aux_info);
11497 * gtk_widget_shape_combine_region:
11498 * @widget: a #GtkWidget
11499 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11501 * Sets a shape for this widget's GDK window. This allows for
11502 * transparent windows etc., see gdk_window_shape_combine_region()
11503 * for more information.
11508 gtk_widget_shape_combine_region (GtkWidget *widget,
11509 cairo_region_t *region)
11511 GtkWidgetPrivate *priv;
11513 g_return_if_fail (GTK_IS_WIDGET (widget));
11514 /* set_shape doesn't work on widgets without gdk window */
11515 g_return_if_fail (gtk_widget_get_has_window (widget));
11517 priv = widget->priv;
11519 if (region == NULL)
11521 priv->has_shape_mask = FALSE;
11524 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11526 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11530 priv->has_shape_mask = TRUE;
11532 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11533 cairo_region_copy (region),
11534 (GDestroyNotify) cairo_region_destroy);
11536 /* set shape if widget has a gdk window already.
11537 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11540 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11545 * gtk_widget_input_shape_combine_region:
11546 * @widget: a #GtkWidget
11547 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11549 * Sets an input shape for this widget's GDK window. This allows for
11550 * windows which react to mouse click in a nonrectangular region, see
11551 * gdk_window_input_shape_combine_region() for more information.
11556 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11557 cairo_region_t *region)
11559 GtkWidgetPrivate *priv;
11561 g_return_if_fail (GTK_IS_WIDGET (widget));
11562 /* set_shape doesn't work on widgets without gdk window */
11563 g_return_if_fail (gtk_widget_get_has_window (widget));
11565 priv = widget->priv;
11567 if (region == NULL)
11570 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11572 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11576 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11577 cairo_region_copy (region),
11578 (GDestroyNotify) cairo_region_destroy);
11580 /* set shape if widget has a gdk window already.
11581 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11584 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11589 /* style properties
11593 * gtk_widget_class_install_style_property_parser: (skip)
11594 * @klass: a #GtkWidgetClass
11595 * @pspec: the #GParamSpec for the style property
11596 * @parser: the parser for the style property
11598 * Installs a style property on a widget class.
11601 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11603 GtkRcPropertyParser parser)
11605 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11606 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11607 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11608 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11610 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11612 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11613 G_OBJECT_CLASS_NAME (klass),
11618 g_param_spec_ref_sink (pspec);
11619 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11620 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11624 * gtk_widget_class_install_style_property:
11625 * @klass: a #GtkWidgetClass
11626 * @pspec: the #GParamSpec for the property
11628 * Installs a style property on a widget class. The parser for the
11629 * style property is determined by the value type of @pspec.
11632 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11635 GtkRcPropertyParser parser;
11637 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11638 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11640 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11642 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11646 * gtk_widget_class_find_style_property:
11647 * @klass: a #GtkWidgetClass
11648 * @property_name: the name of the style property to find
11650 * Finds a style property of a widget class by name.
11652 * Returns: (transfer none): the #GParamSpec of the style property or
11653 * %NULL if @class has no style property with that name.
11658 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11659 const gchar *property_name)
11661 g_return_val_if_fail (property_name != NULL, NULL);
11663 return g_param_spec_pool_lookup (style_property_spec_pool,
11665 G_OBJECT_CLASS_TYPE (klass),
11670 * gtk_widget_class_list_style_properties:
11671 * @klass: a #GtkWidgetClass
11672 * @n_properties: location to return the number of style properties found
11674 * Returns all style properties of a widget class.
11676 * Returns: (array length=n_properties) (transfer container): a
11677 * newly allocated array of #GParamSpec*. The array must be
11678 * freed with g_free().
11683 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11684 guint *n_properties)
11686 GParamSpec **pspecs;
11689 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11690 G_OBJECT_CLASS_TYPE (klass),
11699 * gtk_widget_style_get_property:
11700 * @widget: a #GtkWidget
11701 * @property_name: the name of a style property
11702 * @value: location to return the property value
11704 * Gets the value of a style property of @widget.
11707 gtk_widget_style_get_property (GtkWidget *widget,
11708 const gchar *property_name,
11713 g_return_if_fail (GTK_IS_WIDGET (widget));
11714 g_return_if_fail (property_name != NULL);
11715 g_return_if_fail (G_IS_VALUE (value));
11717 g_object_ref (widget);
11718 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11720 G_OBJECT_TYPE (widget),
11723 g_warning ("%s: widget class `%s' has no property named `%s'",
11725 G_OBJECT_TYPE_NAME (widget),
11729 GtkStyleContext *context;
11730 const GValue *peek_value;
11731 GtkStateFlags state;
11733 context = gtk_widget_get_style_context (widget);
11734 state = gtk_widget_get_state_flags (widget);
11736 peek_value = _gtk_style_context_peek_style_property (context,
11737 G_OBJECT_TYPE (widget),
11740 /* auto-conversion of the caller's value type
11742 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11743 g_value_copy (peek_value, value);
11744 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11745 g_value_transform (peek_value, value);
11747 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11749 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11750 G_VALUE_TYPE_NAME (value));
11752 g_object_unref (widget);
11756 * gtk_widget_style_get_valist:
11757 * @widget: a #GtkWidget
11758 * @first_property_name: the name of the first property to get
11759 * @var_args: a <type>va_list</type> of pairs of property names and
11760 * locations to return the property values, starting with the location
11761 * for @first_property_name.
11763 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11767 gtk_widget_style_get_valist (GtkWidget *widget,
11768 const gchar *first_property_name,
11771 GtkStyleContext *context;
11772 GtkStateFlags state;
11775 g_return_if_fail (GTK_IS_WIDGET (widget));
11777 g_object_ref (widget);
11778 context = gtk_widget_get_style_context (widget);
11779 state = gtk_widget_get_state_flags (widget);
11781 name = first_property_name;
11784 const GValue *peek_value;
11788 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11790 G_OBJECT_TYPE (widget),
11794 g_warning ("%s: widget class `%s' has no property named `%s'",
11796 G_OBJECT_TYPE_NAME (widget),
11800 /* style pspecs are always readable so we can spare that check here */
11802 peek_value = _gtk_style_context_peek_style_property (context,
11803 G_OBJECT_TYPE (widget),
11806 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11809 g_warning ("%s: %s", G_STRLOC, error);
11814 name = va_arg (var_args, gchar*);
11817 g_object_unref (widget);
11821 * gtk_widget_style_get:
11822 * @widget: a #GtkWidget
11823 * @first_property_name: the name of the first property to get
11824 * @...: pairs of property names and locations to return the
11825 * property values, starting with the location for
11826 * @first_property_name, terminated by %NULL.
11828 * Gets the values of a multiple style properties of @widget.
11831 gtk_widget_style_get (GtkWidget *widget,
11832 const gchar *first_property_name,
11837 g_return_if_fail (GTK_IS_WIDGET (widget));
11839 va_start (var_args, first_property_name);
11840 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11845 * gtk_requisition_new:
11847 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11849 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11850 * be freed with gtk_requisition_free().
11855 gtk_requisition_new (void)
11857 return g_slice_new0 (GtkRequisition);
11861 * gtk_requisition_copy:
11862 * @requisition: a #GtkRequisition
11864 * Copies a #GtkRequisition.
11866 * Returns: a copy of @requisition
11869 gtk_requisition_copy (const GtkRequisition *requisition)
11871 return g_slice_dup (GtkRequisition, requisition);
11875 * gtk_requisition_free:
11876 * @requisition: a #GtkRequisition
11878 * Frees a #GtkRequisition.
11881 gtk_requisition_free (GtkRequisition *requisition)
11883 g_slice_free (GtkRequisition, requisition);
11886 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11887 gtk_requisition_copy,
11888 gtk_requisition_free)
11891 * gtk_widget_class_set_accessible_type:
11892 * @widget_class: class to set the accessible type for
11893 * @type: The object type that implements the accessible for @widget_class
11895 * Sets the type to be used for creating accessibles for widgets of
11896 * @widget_class. The given @type must be a subtype of the type used for
11897 * accessibles of the parent class.
11899 * This function should only be called from class init functions of widgets.
11904 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11907 GtkWidgetClassPrivate *priv;
11909 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11910 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11912 priv = widget_class->priv;
11914 priv->accessible_type = type;
11915 /* reset this - honoring the type's role is better. */
11916 priv->accessible_role = ATK_ROLE_INVALID;
11920 * gtk_widget_class_set_accessible_role:
11921 * @widget_class: class to set the accessible role for
11922 * @role: The role to use for accessibles created for @widget_class
11924 * Sets the default #AtkRole to be set on accessibles created for
11925 * widgets of @widget_class. Accessibles may decide to not honor this
11926 * setting if their role reporting is more refined. Calls to
11927 * gtk_widget_class_set_accessible_type() will reset this value.
11929 * In cases where you want more fine-grained control over the role of
11930 * accessibles created for @widget_class, you should provide your own
11931 * accessible type and use gtk_widget_class_set_accessible_type()
11934 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11935 * and the accessible's default role will be used instead.
11937 * This function should only be called from class init functions of widgets.
11942 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11945 GtkWidgetClassPrivate *priv;
11947 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11949 priv = widget_class->priv;
11951 priv->accessible_role = role;
11955 * _gtk_widget_peek_accessible:
11956 * @widget: a #GtkWidget
11958 * Gets the accessible for @widget, if it has been created yet.
11959 * Otherwise, this function returns %NULL. If the @widget's implementation
11960 * does not use the default way to create accessibles, %NULL will always be
11963 * Returns: the accessible for @widget or %NULL if none has been
11967 _gtk_widget_peek_accessible (GtkWidget *widget)
11969 return g_object_get_qdata (G_OBJECT (widget),
11970 quark_accessible_object);
11974 * gtk_widget_get_accessible:
11975 * @widget: a #GtkWidget
11977 * Returns the accessible object that describes the widget to an
11978 * assistive technology.
11980 * If accessibility support is not available, this #AtkObject
11981 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11982 * implementation is available for the widget instance in question,
11983 * it will inherit an #AtkObject implementation from the first ancestor
11984 * class for which such an implementation is defined.
11986 * The documentation of the
11987 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11988 * library contains more information about accessible objects and their uses.
11990 * Returns: (transfer none): the #AtkObject associated with @widget
11993 gtk_widget_get_accessible (GtkWidget *widget)
11995 GtkWidgetClass *klass;
11997 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11999 klass = GTK_WIDGET_GET_CLASS (widget);
12001 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
12003 return klass->get_accessible (widget);
12007 gtk_widget_real_get_accessible (GtkWidget *widget)
12009 AtkObject* accessible;
12011 accessible = g_object_get_qdata (G_OBJECT (widget),
12012 quark_accessible_object);
12015 GtkWidgetClass *widget_class;
12016 GtkWidgetClassPrivate *priv;
12017 AtkObjectFactory *factory;
12018 AtkRegistry *default_registry;
12020 widget_class = GTK_WIDGET_GET_CLASS (widget);
12021 priv = widget_class->priv;
12023 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
12025 default_registry = atk_get_default_registry ();
12026 factory = atk_registry_get_factory (default_registry,
12027 G_TYPE_FROM_INSTANCE (widget));
12029 atk_object_factory_create_accessible (factory,
12030 G_OBJECT (widget));
12032 if (priv->accessible_role != ATK_ROLE_INVALID)
12033 atk_object_set_role (accessible, priv->accessible_role);
12035 g_object_set_qdata (G_OBJECT (widget),
12036 quark_accessible_object,
12041 accessible = g_object_new (priv->accessible_type,
12044 if (priv->accessible_role != ATK_ROLE_INVALID)
12045 atk_object_set_role (accessible, priv->accessible_role);
12047 g_object_set_qdata (G_OBJECT (widget),
12048 quark_accessible_object,
12051 atk_object_initialize (accessible, widget);
12053 /* Set the role again, since we don't want a role set
12054 * in some parent initialize() function to override
12057 if (priv->accessible_role != ATK_ROLE_INVALID)
12058 atk_object_set_role (accessible, priv->accessible_role);
12065 * Initialize a AtkImplementorIface instance's virtual pointers as
12066 * appropriate to this implementor's class (GtkWidget).
12069 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
12071 iface->ref_accessible = gtk_widget_ref_accessible;
12075 gtk_widget_ref_accessible (AtkImplementor *implementor)
12077 AtkObject *accessible;
12079 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
12081 g_object_ref (accessible);
12086 * Expand flag management
12090 gtk_widget_update_computed_expand (GtkWidget *widget)
12092 GtkWidgetPrivate *priv;
12094 priv = widget->priv;
12096 if (priv->need_compute_expand)
12100 if (priv->hexpand_set)
12105 if (priv->vexpand_set)
12110 /* we don't need to use compute_expand if both expands are
12111 * forced by the app
12113 if (!(priv->hexpand_set && priv->vexpand_set))
12115 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12119 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12120 priv->hexpand_set ? &ignored : &h,
12121 priv->vexpand_set ? &ignored : &v);
12125 priv->need_compute_expand = FALSE;
12126 priv->computed_hexpand = h != FALSE;
12127 priv->computed_vexpand = v != FALSE;
12132 * gtk_widget_queue_compute_expand:
12133 * @widget: a #GtkWidget
12135 * Mark @widget as needing to recompute its expand flags. Call
12136 * this function when setting legacy expand child properties
12137 * on the child of a container.
12139 * See gtk_widget_compute_expand().
12142 gtk_widget_queue_compute_expand (GtkWidget *widget)
12145 gboolean changed_anything;
12147 if (widget->priv->need_compute_expand)
12150 changed_anything = FALSE;
12152 while (parent != NULL)
12154 if (!parent->priv->need_compute_expand)
12156 parent->priv->need_compute_expand = TRUE;
12157 changed_anything = TRUE;
12160 /* Note: if we had an invariant that "if a child needs to
12161 * compute expand, its parents also do" then we could stop going
12162 * up when we got to a parent that already needed to
12163 * compute. However, in general we compute expand lazily (as
12164 * soon as we see something in a subtree that is expand, we know
12165 * we're expanding) and so this invariant does not hold and we
12166 * have to always walk all the way up in case some ancestor
12167 * is not currently need_compute_expand.
12170 parent = parent->priv->parent;
12173 /* recomputing expand always requires
12174 * a relayout as well
12176 if (changed_anything)
12177 gtk_widget_queue_resize (widget);
12181 * gtk_widget_compute_expand:
12182 * @widget: the widget
12183 * @orientation: expand direction
12185 * Computes whether a container should give this widget extra space
12186 * when possible. Containers should check this, rather than
12187 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12189 * This function already checks whether the widget is visible, so
12190 * visibility does not need to be checked separately. Non-visible
12191 * widgets are not expanded.
12193 * The computed expand value uses either the expand setting explicitly
12194 * set on the widget itself, or, if none has been explicitly set,
12195 * the widget may expand if some of its children do.
12197 * Return value: whether widget tree rooted here should be expanded
12200 gtk_widget_compute_expand (GtkWidget *widget,
12201 GtkOrientation orientation)
12203 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12205 /* We never make a widget expand if not even showing. */
12206 if (!gtk_widget_get_visible (widget))
12209 gtk_widget_update_computed_expand (widget);
12211 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12213 return widget->priv->computed_hexpand;
12217 return widget->priv->computed_vexpand;
12222 gtk_widget_set_expand (GtkWidget *widget,
12223 GtkOrientation orientation,
12226 const char *expand_prop;
12227 const char *expand_set_prop;
12229 GtkWidgetPrivate *priv;
12231 g_return_if_fail (GTK_IS_WIDGET (widget));
12233 priv = widget->priv;
12235 expand = expand != FALSE;
12237 was_both = priv->hexpand && priv->vexpand;
12239 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12241 if (priv->hexpand_set &&
12242 priv->hexpand == expand)
12245 priv->hexpand_set = TRUE;
12246 priv->hexpand = expand;
12248 expand_prop = "hexpand";
12249 expand_set_prop = "hexpand-set";
12253 if (priv->vexpand_set &&
12254 priv->vexpand == expand)
12257 priv->vexpand_set = TRUE;
12258 priv->vexpand = expand;
12260 expand_prop = "vexpand";
12261 expand_set_prop = "vexpand-set";
12264 gtk_widget_queue_compute_expand (widget);
12266 g_object_freeze_notify (G_OBJECT (widget));
12267 g_object_notify (G_OBJECT (widget), expand_prop);
12268 g_object_notify (G_OBJECT (widget), expand_set_prop);
12269 if (was_both != (priv->hexpand && priv->vexpand))
12270 g_object_notify (G_OBJECT (widget), "expand");
12271 g_object_thaw_notify (G_OBJECT (widget));
12275 gtk_widget_set_expand_set (GtkWidget *widget,
12276 GtkOrientation orientation,
12279 GtkWidgetPrivate *priv;
12282 priv = widget->priv;
12284 set = set != FALSE;
12286 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12288 if (set == priv->hexpand_set)
12291 priv->hexpand_set = set;
12292 prop = "hexpand-set";
12296 if (set == priv->vexpand_set)
12299 priv->vexpand_set = set;
12300 prop = "vexpand-set";
12303 gtk_widget_queue_compute_expand (widget);
12305 g_object_notify (G_OBJECT (widget), prop);
12309 * gtk_widget_get_hexpand:
12310 * @widget: the widget
12312 * Gets whether the widget would like any available extra horizontal
12313 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12314 * generally receive the extra space. For example, a list or
12315 * scrollable area or document in your window would often be set to
12318 * Containers should use gtk_widget_compute_expand() rather than
12319 * this function, to see whether a widget, or any of its children,
12320 * has the expand flag set. If any child of a widget wants to
12321 * expand, the parent may ask to expand also.
12323 * This function only looks at the widget's own hexpand flag, rather
12324 * than computing whether the entire widget tree rooted at this widget
12327 * Return value: whether hexpand flag is set
12330 gtk_widget_get_hexpand (GtkWidget *widget)
12332 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12334 return widget->priv->hexpand;
12338 * gtk_widget_set_hexpand:
12339 * @widget: the widget
12340 * @expand: whether to expand
12342 * Sets whether the widget would like any available extra horizontal
12343 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12344 * generally receive the extra space. For example, a list or
12345 * scrollable area or document in your window would often be set to
12348 * Call this function to set the expand flag if you would like your
12349 * widget to become larger horizontally when the window has extra
12352 * By default, widgets automatically expand if any of their children
12353 * want to expand. (To see if a widget will automatically expand given
12354 * its current children and state, call gtk_widget_compute_expand(). A
12355 * container can decide how the expandability of children affects the
12356 * expansion of the container by overriding the compute_expand virtual
12357 * method on #GtkWidget.).
12359 * Setting hexpand explicitly with this function will override the
12360 * automatic expand behavior.
12362 * This function forces the widget to expand or not to expand,
12363 * regardless of children. The override occurs because
12364 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12365 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12366 * value to be used, rather than looking at children and widget state.
12369 gtk_widget_set_hexpand (GtkWidget *widget,
12372 g_return_if_fail (GTK_IS_WIDGET (widget));
12374 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12378 * gtk_widget_get_hexpand_set:
12379 * @widget: the widget
12381 * Gets whether gtk_widget_set_hexpand() has been used to
12382 * explicitly set the expand flag on this widget.
12384 * If hexpand is set, then it overrides any computed
12385 * expand value based on child widgets. If hexpand is not
12386 * set, then the expand value depends on whether any
12387 * children of the widget would like to expand.
12389 * There are few reasons to use this function, but it's here
12390 * for completeness and consistency.
12392 * Return value: whether hexpand has been explicitly set
12395 gtk_widget_get_hexpand_set (GtkWidget *widget)
12397 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12399 return widget->priv->hexpand_set;
12403 * gtk_widget_set_hexpand_set:
12404 * @widget: the widget
12405 * @set: value for hexpand-set property
12407 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12410 * The hexpand-set property will be set automatically when you call
12411 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12412 * reason to use this function would be to unset an explicit expand
12415 * If hexpand is set, then it overrides any computed
12416 * expand value based on child widgets. If hexpand is not
12417 * set, then the expand value depends on whether any
12418 * children of the widget would like to expand.
12420 * There are few reasons to use this function, but it's here
12421 * for completeness and consistency.
12424 gtk_widget_set_hexpand_set (GtkWidget *widget,
12427 g_return_if_fail (GTK_IS_WIDGET (widget));
12429 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12434 * gtk_widget_get_vexpand:
12435 * @widget: the widget
12437 * Gets whether the widget would like any available extra vertical
12440 * See gtk_widget_get_hexpand() for more detail.
12442 * Return value: whether vexpand flag is set
12445 gtk_widget_get_vexpand (GtkWidget *widget)
12447 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12449 return widget->priv->vexpand;
12453 * gtk_widget_set_vexpand:
12454 * @widget: the widget
12455 * @expand: whether to expand
12457 * Sets whether the widget would like any available extra vertical
12460 * See gtk_widget_set_hexpand() for more detail.
12463 gtk_widget_set_vexpand (GtkWidget *widget,
12466 g_return_if_fail (GTK_IS_WIDGET (widget));
12468 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12472 * gtk_widget_get_vexpand_set:
12473 * @widget: the widget
12475 * Gets whether gtk_widget_set_vexpand() has been used to
12476 * explicitly set the expand flag on this widget.
12478 * See gtk_widget_get_hexpand_set() for more detail.
12480 * Return value: whether vexpand has been explicitly set
12483 gtk_widget_get_vexpand_set (GtkWidget *widget)
12485 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12487 return widget->priv->vexpand_set;
12491 * gtk_widget_set_vexpand_set:
12492 * @widget: the widget
12493 * @set: value for vexpand-set property
12495 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12498 * See gtk_widget_set_hexpand_set() for more detail.
12501 gtk_widget_set_vexpand_set (GtkWidget *widget,
12504 g_return_if_fail (GTK_IS_WIDGET (widget));
12506 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12510 * GtkBuildable implementation
12512 static GQuark quark_builder_has_default = 0;
12513 static GQuark quark_builder_has_focus = 0;
12514 static GQuark quark_builder_atk_relations = 0;
12515 static GQuark quark_builder_set_name = 0;
12518 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12520 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12521 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12522 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12523 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12525 iface->set_name = gtk_widget_buildable_set_name;
12526 iface->get_name = gtk_widget_buildable_get_name;
12527 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12528 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12529 iface->parser_finished = gtk_widget_buildable_parser_finished;
12530 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12531 iface->custom_finished = gtk_widget_buildable_custom_finished;
12535 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12538 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12539 g_strdup (name), g_free);
12542 static const gchar *
12543 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12545 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12549 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12550 GtkBuilder *builder,
12551 const gchar *childname)
12553 if (strcmp (childname, "accessible") == 0)
12554 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12560 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12561 GtkBuilder *builder,
12563 const GValue *value)
12565 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12566 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12567 GINT_TO_POINTER (TRUE));
12568 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12569 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12570 GINT_TO_POINTER (TRUE));
12572 g_object_set_property (G_OBJECT (buildable), name, value);
12577 gchar *action_name;
12578 GString *description;
12580 gboolean translatable;
12590 free_action (AtkActionData *data, gpointer user_data)
12592 g_free (data->action_name);
12593 g_string_free (data->description, TRUE);
12594 g_free (data->context);
12595 g_slice_free (AtkActionData, data);
12599 free_relation (AtkRelationData *data, gpointer user_data)
12601 g_free (data->target);
12602 g_free (data->type);
12603 g_slice_free (AtkRelationData, data);
12607 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12608 GtkBuilder *builder)
12610 GSList *atk_relations;
12612 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12613 gtk_widget_grab_default (GTK_WIDGET (buildable));
12614 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12615 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12617 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12618 quark_builder_atk_relations);
12621 AtkObject *accessible;
12622 AtkRelationSet *relation_set;
12625 AtkRelationType relation_type;
12626 AtkObject *target_accessible;
12628 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12629 relation_set = atk_object_ref_relation_set (accessible);
12631 for (l = atk_relations; l; l = l->next)
12633 AtkRelationData *relation = (AtkRelationData*)l->data;
12635 target = gtk_builder_get_object (builder, relation->target);
12638 g_warning ("Target object %s in <relation> does not exist",
12642 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12643 g_assert (target_accessible != NULL);
12645 relation_type = atk_relation_type_for_name (relation->type);
12646 if (relation_type == ATK_RELATION_NULL)
12648 g_warning ("<relation> type %s not found",
12652 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12653 target_accessible);
12655 g_object_unref (relation_set);
12657 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12658 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12667 } AccessibilitySubParserData;
12670 accessibility_start_element (GMarkupParseContext *context,
12671 const gchar *element_name,
12672 const gchar **names,
12673 const gchar **values,
12674 gpointer user_data,
12677 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12679 gint line_number, char_number;
12681 if (strcmp (element_name, "relation") == 0)
12683 gchar *target = NULL;
12684 gchar *type = NULL;
12685 AtkRelationData *relation;
12687 for (i = 0; names[i]; i++)
12689 if (strcmp (names[i], "target") == 0)
12690 target = g_strdup (values[i]);
12691 else if (strcmp (names[i], "type") == 0)
12692 type = g_strdup (values[i]);
12695 g_markup_parse_context_get_position (context,
12698 g_set_error (error,
12700 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12701 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12703 line_number, char_number, names[i], "relation");
12710 if (!target || !type)
12712 g_markup_parse_context_get_position (context,
12715 g_set_error (error,
12717 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12718 "%s:%d:%d <%s> requires attribute \"%s\"",
12720 line_number, char_number, "relation",
12721 type ? "target" : "type");
12727 relation = g_slice_new (AtkRelationData);
12728 relation->target = target;
12729 relation->type = type;
12731 data->relations = g_slist_prepend (data->relations, relation);
12733 else if (strcmp (element_name, "action") == 0)
12735 const gchar *action_name = NULL;
12736 const gchar *description = NULL;
12737 const gchar *msg_context = NULL;
12738 gboolean translatable = FALSE;
12739 AtkActionData *action;
12741 for (i = 0; names[i]; i++)
12743 if (strcmp (names[i], "action_name") == 0)
12744 action_name = values[i];
12745 else if (strcmp (names[i], "description") == 0)
12746 description = values[i];
12747 else if (strcmp (names[i], "translatable") == 0)
12749 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12752 else if (strcmp (names[i], "comments") == 0)
12754 /* do nothing, comments are for translators */
12756 else if (strcmp (names[i], "context") == 0)
12757 msg_context = values[i];
12760 g_markup_parse_context_get_position (context,
12763 g_set_error (error,
12765 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12766 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12768 line_number, char_number, names[i], "action");
12775 g_markup_parse_context_get_position (context,
12778 g_set_error (error,
12780 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12781 "%s:%d:%d <%s> requires attribute \"%s\"",
12783 line_number, char_number, "action",
12788 action = g_slice_new (AtkActionData);
12789 action->action_name = g_strdup (action_name);
12790 action->description = g_string_new (description);
12791 action->context = g_strdup (msg_context);
12792 action->translatable = translatable;
12794 data->actions = g_slist_prepend (data->actions, action);
12796 else if (strcmp (element_name, "accessibility") == 0)
12799 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12803 accessibility_text (GMarkupParseContext *context,
12806 gpointer user_data,
12809 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12811 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12813 AtkActionData *action = data->actions->data;
12815 g_string_append_len (action->description, text, text_len);
12819 static const GMarkupParser accessibility_parser =
12821 accessibility_start_element,
12823 accessibility_text,
12832 } AccelGroupParserData;
12835 accel_group_start_element (GMarkupParseContext *context,
12836 const gchar *element_name,
12837 const gchar **names,
12838 const gchar **values,
12839 gpointer user_data,
12844 guint modifiers = 0;
12845 gchar *signal = NULL;
12846 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12848 for (i = 0; names[i]; i++)
12850 if (strcmp (names[i], "key") == 0)
12851 key = gdk_keyval_from_name (values[i]);
12852 else if (strcmp (names[i], "modifiers") == 0)
12854 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12860 else if (strcmp (names[i], "signal") == 0)
12861 signal = g_strdup (values[i]);
12864 if (key == 0 || signal == NULL)
12866 g_warning ("<accelerator> requires key and signal attributes");
12869 parser_data->key = key;
12870 parser_data->modifiers = modifiers;
12871 parser_data->signal = signal;
12874 static const GMarkupParser accel_group_parser =
12876 accel_group_start_element,
12885 style_start_element (GMarkupParseContext *context,
12886 const gchar *element_name,
12887 const gchar **names,
12888 const gchar **values,
12889 gpointer user_data,
12892 StyleParserData *style_data = (StyleParserData *)user_data;
12895 if (strcmp (element_name, "class") == 0)
12897 if (g_markup_collect_attributes (element_name,
12901 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12902 G_MARKUP_COLLECT_INVALID))
12904 style_data->classes = g_slist_append (style_data->classes, class_name);
12907 else if (strcmp (element_name, "style") == 0)
12910 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12913 static const GMarkupParser style_parser =
12915 style_start_element,
12919 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12920 GtkBuilder *builder,
12922 const gchar *tagname,
12923 GMarkupParser *parser,
12926 g_assert (buildable);
12928 if (strcmp (tagname, "accelerator") == 0)
12930 AccelGroupParserData *parser_data;
12932 parser_data = g_slice_new0 (AccelGroupParserData);
12933 parser_data->object = g_object_ref (buildable);
12934 *parser = accel_group_parser;
12935 *data = parser_data;
12938 if (strcmp (tagname, "accessibility") == 0)
12940 AccessibilitySubParserData *parser_data;
12942 parser_data = g_slice_new0 (AccessibilitySubParserData);
12943 *parser = accessibility_parser;
12944 *data = parser_data;
12947 if (strcmp (tagname, "style") == 0)
12949 StyleParserData *parser_data;
12951 parser_data = g_slice_new0 (StyleParserData);
12952 *parser = style_parser;
12953 *data = parser_data;
12961 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12962 GtkWidget *toplevel,
12963 gpointer user_data)
12965 AccelGroupParserData *accel_data;
12966 GSList *accel_groups;
12967 GtkAccelGroup *accel_group;
12969 g_return_if_fail (GTK_IS_WIDGET (widget));
12970 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12971 g_return_if_fail (user_data != NULL);
12973 accel_data = (AccelGroupParserData*)user_data;
12974 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12975 if (g_slist_length (accel_groups) == 0)
12977 accel_group = gtk_accel_group_new ();
12978 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12982 g_assert (g_slist_length (accel_groups) == 1);
12983 accel_group = g_slist_nth_data (accel_groups, 0);
12986 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12987 accel_data->signal,
12990 accel_data->modifiers,
12991 GTK_ACCEL_VISIBLE);
12993 g_object_unref (accel_data->object);
12994 g_free (accel_data->signal);
12995 g_slice_free (AccelGroupParserData, accel_data);
12999 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
13000 GtkBuilder *builder,
13002 const gchar *tagname,
13003 gpointer user_data)
13005 if (strcmp (tagname, "accelerator") == 0)
13007 AccelGroupParserData *accel_data;
13008 GtkWidget *toplevel;
13010 accel_data = (AccelGroupParserData*)user_data;
13011 g_assert (accel_data->object);
13013 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
13015 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
13017 else if (strcmp (tagname, "accessibility") == 0)
13019 AccessibilitySubParserData *a11y_data;
13021 a11y_data = (AccessibilitySubParserData*)user_data;
13023 if (a11y_data->actions)
13025 AtkObject *accessible;
13030 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
13032 if (ATK_IS_ACTION (accessible))
13034 action = ATK_ACTION (accessible);
13035 n_actions = atk_action_get_n_actions (action);
13037 for (l = a11y_data->actions; l; l = l->next)
13039 AtkActionData *action_data = (AtkActionData*)l->data;
13041 for (i = 0; i < n_actions; i++)
13042 if (strcmp (atk_action_get_name (action, i),
13043 action_data->action_name) == 0)
13048 gchar *description;
13050 if (action_data->translatable && action_data->description->len)
13051 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
13052 action_data->context,
13053 action_data->description->str);
13055 description = action_data->description->str;
13057 atk_action_set_description (action, i, description);
13062 g_warning ("accessibility action on a widget that does not implement AtkAction");
13064 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
13067 if (a11y_data->relations)
13068 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
13069 a11y_data->relations);
13071 g_slice_free (AccessibilitySubParserData, a11y_data);
13073 else if (strcmp (tagname, "style") == 0)
13075 StyleParserData *style_data = (StyleParserData *)user_data;
13076 GtkStyleContext *context;
13079 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
13081 for (l = style_data->classes; l; l = l->next)
13082 gtk_style_context_add_class (context, (const gchar *)l->data);
13084 gtk_widget_reset_style (GTK_WIDGET (buildable));
13086 g_slist_free_full (style_data->classes, g_free);
13087 g_slice_free (StyleParserData, style_data);
13091 static GtkSizeRequestMode
13092 gtk_widget_real_get_request_mode (GtkWidget *widget)
13094 /* By default widgets dont trade size at all. */
13095 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13099 gtk_widget_real_get_width (GtkWidget *widget,
13100 gint *minimum_size,
13101 gint *natural_size)
13111 gtk_widget_real_get_height (GtkWidget *widget,
13112 gint *minimum_size,
13113 gint *natural_size)
13123 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13125 gint *minimum_height,
13126 gint *natural_height)
13128 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13132 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13134 gint *minimum_width,
13135 gint *natural_width)
13137 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13141 * gtk_widget_get_halign:
13142 * @widget: a #GtkWidget
13144 * Gets the value of the #GtkWidget:halign property.
13146 * Returns: the horizontal alignment of @widget
13149 gtk_widget_get_halign (GtkWidget *widget)
13151 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13152 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13156 * gtk_widget_set_halign:
13157 * @widget: a #GtkWidget
13158 * @align: the horizontal alignment
13160 * Sets the horizontal alignment of @widget.
13161 * See the #GtkWidget:halign property.
13164 gtk_widget_set_halign (GtkWidget *widget,
13167 GtkWidgetAuxInfo *aux_info;
13169 g_return_if_fail (GTK_IS_WIDGET (widget));
13171 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13173 if (aux_info->halign == align)
13176 aux_info->halign = align;
13177 gtk_widget_queue_resize (widget);
13178 g_object_notify (G_OBJECT (widget), "halign");
13182 * gtk_widget_get_valign:
13183 * @widget: a #GtkWidget
13185 * Gets the value of the #GtkWidget:valign property.
13187 * Returns: the vertical alignment of @widget
13190 gtk_widget_get_valign (GtkWidget *widget)
13192 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13193 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13197 * gtk_widget_set_valign:
13198 * @widget: a #GtkWidget
13199 * @align: the vertical alignment
13201 * Sets the vertical alignment of @widget.
13202 * See the #GtkWidget:valign property.
13205 gtk_widget_set_valign (GtkWidget *widget,
13208 GtkWidgetAuxInfo *aux_info;
13210 g_return_if_fail (GTK_IS_WIDGET (widget));
13212 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13214 if (aux_info->valign == align)
13217 aux_info->valign = align;
13218 gtk_widget_queue_resize (widget);
13219 g_object_notify (G_OBJECT (widget), "valign");
13223 * gtk_widget_get_margin_left:
13224 * @widget: a #GtkWidget
13226 * Gets the value of the #GtkWidget:margin-left property.
13228 * Returns: The left margin of @widget
13233 gtk_widget_get_margin_left (GtkWidget *widget)
13235 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13237 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13241 * gtk_widget_set_margin_left:
13242 * @widget: a #GtkWidget
13243 * @margin: the left margin
13245 * Sets the left margin of @widget.
13246 * See the #GtkWidget:margin-left property.
13251 gtk_widget_set_margin_left (GtkWidget *widget,
13254 GtkWidgetAuxInfo *aux_info;
13256 g_return_if_fail (GTK_IS_WIDGET (widget));
13257 g_return_if_fail (margin <= G_MAXINT16);
13259 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13261 if (aux_info->margin.left == margin)
13264 aux_info->margin.left = margin;
13265 gtk_widget_queue_resize (widget);
13266 g_object_notify (G_OBJECT (widget), "margin-left");
13270 * gtk_widget_get_margin_right:
13271 * @widget: a #GtkWidget
13273 * Gets the value of the #GtkWidget:margin-right property.
13275 * Returns: The right margin of @widget
13280 gtk_widget_get_margin_right (GtkWidget *widget)
13282 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13284 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13288 * gtk_widget_set_margin_right:
13289 * @widget: a #GtkWidget
13290 * @margin: the right margin
13292 * Sets the right margin of @widget.
13293 * See the #GtkWidget:margin-right property.
13298 gtk_widget_set_margin_right (GtkWidget *widget,
13301 GtkWidgetAuxInfo *aux_info;
13303 g_return_if_fail (GTK_IS_WIDGET (widget));
13304 g_return_if_fail (margin <= G_MAXINT16);
13306 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13308 if (aux_info->margin.right == margin)
13311 aux_info->margin.right = margin;
13312 gtk_widget_queue_resize (widget);
13313 g_object_notify (G_OBJECT (widget), "margin-right");
13317 * gtk_widget_get_margin_top:
13318 * @widget: a #GtkWidget
13320 * Gets the value of the #GtkWidget:margin-top property.
13322 * Returns: The top margin of @widget
13327 gtk_widget_get_margin_top (GtkWidget *widget)
13329 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13331 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13335 * gtk_widget_set_margin_top:
13336 * @widget: a #GtkWidget
13337 * @margin: the top margin
13339 * Sets the top margin of @widget.
13340 * See the #GtkWidget:margin-top property.
13345 gtk_widget_set_margin_top (GtkWidget *widget,
13348 GtkWidgetAuxInfo *aux_info;
13350 g_return_if_fail (GTK_IS_WIDGET (widget));
13351 g_return_if_fail (margin <= G_MAXINT16);
13353 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13355 if (aux_info->margin.top == margin)
13358 aux_info->margin.top = margin;
13359 gtk_widget_queue_resize (widget);
13360 g_object_notify (G_OBJECT (widget), "margin-top");
13364 * gtk_widget_get_margin_bottom:
13365 * @widget: a #GtkWidget
13367 * Gets the value of the #GtkWidget:margin-bottom property.
13369 * Returns: The bottom margin of @widget
13374 gtk_widget_get_margin_bottom (GtkWidget *widget)
13376 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13378 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13382 * gtk_widget_set_margin_bottom:
13383 * @widget: a #GtkWidget
13384 * @margin: the bottom margin
13386 * Sets the bottom margin of @widget.
13387 * See the #GtkWidget:margin-bottom property.
13392 gtk_widget_set_margin_bottom (GtkWidget *widget,
13395 GtkWidgetAuxInfo *aux_info;
13397 g_return_if_fail (GTK_IS_WIDGET (widget));
13398 g_return_if_fail (margin <= G_MAXINT16);
13400 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13402 if (aux_info->margin.bottom == margin)
13405 aux_info->margin.bottom = margin;
13406 gtk_widget_queue_resize (widget);
13407 g_object_notify (G_OBJECT (widget), "margin-bottom");
13411 * gtk_widget_get_clipboard:
13412 * @widget: a #GtkWidget
13413 * @selection: a #GdkAtom which identifies the clipboard
13414 * to use. %GDK_SELECTION_CLIPBOARD gives the
13415 * default clipboard. Another common value
13416 * is %GDK_SELECTION_PRIMARY, which gives
13417 * the primary X selection.
13419 * Returns the clipboard object for the given selection to
13420 * be used with @widget. @widget must have a #GdkDisplay
13421 * associated with it, so must be attached to a toplevel
13424 * Return value: (transfer none): the appropriate clipboard object. If no
13425 * clipboard already exists, a new one will
13426 * be created. Once a clipboard object has
13427 * been created, it is persistent for all time.
13432 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13434 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13435 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13437 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13442 * gtk_widget_list_mnemonic_labels:
13443 * @widget: a #GtkWidget
13445 * Returns a newly allocated list of the widgets, normally labels, for
13446 * which this widget is the target of a mnemonic (see for example,
13447 * gtk_label_set_mnemonic_widget()).
13449 * The widgets in the list are not individually referenced. If you
13450 * want to iterate through the list and perform actions involving
13451 * callbacks that might destroy the widgets, you
13452 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13453 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13454 * widgets afterwards.
13456 * Return value: (element-type GtkWidget) (transfer container): the list of
13457 * mnemonic labels; free this list
13458 * with g_list_free() when you are done with it.
13463 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13465 GList *list = NULL;
13468 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13470 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13471 list = g_list_prepend (list, l->data);
13477 * gtk_widget_add_mnemonic_label:
13478 * @widget: a #GtkWidget
13479 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13481 * Adds a widget to the list of mnemonic labels for
13482 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13483 * list of mnemonic labels for the widget is cleared when the
13484 * widget is destroyed, so the caller must make sure to update
13485 * its internal state at this point as well, by using a connection
13486 * to the #GtkWidget::destroy signal or a weak notifier.
13491 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13494 GSList *old_list, *new_list;
13496 g_return_if_fail (GTK_IS_WIDGET (widget));
13497 g_return_if_fail (GTK_IS_WIDGET (label));
13499 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13500 new_list = g_slist_prepend (old_list, label);
13502 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13503 new_list, (GDestroyNotify) g_slist_free);
13507 * gtk_widget_remove_mnemonic_label:
13508 * @widget: a #GtkWidget
13509 * @label: a #GtkWidget that was previously set as a mnemnic label for
13510 * @widget with gtk_widget_add_mnemonic_label().
13512 * Removes a widget from the list of mnemonic labels for
13513 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13514 * must have previously been added to the list with
13515 * gtk_widget_add_mnemonic_label().
13520 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13523 GSList *old_list, *new_list;
13525 g_return_if_fail (GTK_IS_WIDGET (widget));
13526 g_return_if_fail (GTK_IS_WIDGET (label));
13528 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13529 new_list = g_slist_remove (old_list, label);
13532 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13533 new_list, (GDestroyNotify) g_slist_free);
13537 * gtk_widget_get_no_show_all:
13538 * @widget: a #GtkWidget
13540 * Returns the current value of the #GtkWidget:no-show-all property,
13541 * which determines whether calls to gtk_widget_show_all()
13542 * will affect this widget.
13544 * Return value: the current value of the "no-show-all" property.
13549 gtk_widget_get_no_show_all (GtkWidget *widget)
13551 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13553 return widget->priv->no_show_all;
13557 * gtk_widget_set_no_show_all:
13558 * @widget: a #GtkWidget
13559 * @no_show_all: the new value for the "no-show-all" property
13561 * Sets the #GtkWidget:no-show-all property, which determines whether
13562 * calls to gtk_widget_show_all() will affect this widget.
13564 * This is mostly for use in constructing widget hierarchies with externally
13565 * controlled visibility, see #GtkUIManager.
13570 gtk_widget_set_no_show_all (GtkWidget *widget,
13571 gboolean no_show_all)
13573 g_return_if_fail (GTK_IS_WIDGET (widget));
13575 no_show_all = (no_show_all != FALSE);
13577 if (widget->priv->no_show_all != no_show_all)
13579 widget->priv->no_show_all = no_show_all;
13581 g_object_notify (G_OBJECT (widget), "no-show-all");
13587 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13588 gboolean has_tooltip,
13591 GtkWidgetPrivate *priv = widget->priv;
13592 gboolean priv_has_tooltip;
13594 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13595 quark_has_tooltip));
13597 if (priv_has_tooltip != has_tooltip || force)
13599 priv_has_tooltip = has_tooltip;
13601 if (priv_has_tooltip)
13603 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13604 gdk_window_set_events (priv->window,
13605 gdk_window_get_events (priv->window) |
13606 GDK_LEAVE_NOTIFY_MASK |
13607 GDK_POINTER_MOTION_MASK |
13608 GDK_POINTER_MOTION_HINT_MASK);
13610 if (gtk_widget_get_has_window (widget))
13611 gtk_widget_add_events (widget,
13612 GDK_LEAVE_NOTIFY_MASK |
13613 GDK_POINTER_MOTION_MASK |
13614 GDK_POINTER_MOTION_HINT_MASK);
13617 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13618 GUINT_TO_POINTER (priv_has_tooltip));
13623 * gtk_widget_set_tooltip_window:
13624 * @widget: a #GtkWidget
13625 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13627 * Replaces the default, usually yellow, window used for displaying
13628 * tooltips with @custom_window. GTK+ will take care of showing and
13629 * hiding @custom_window at the right moment, to behave likewise as
13630 * the default tooltip window. If @custom_window is %NULL, the default
13631 * tooltip window will be used.
13633 * If the custom window should have the default theming it needs to
13634 * have the name "gtk-tooltip", see gtk_widget_set_name().
13639 gtk_widget_set_tooltip_window (GtkWidget *widget,
13640 GtkWindow *custom_window)
13642 gboolean has_tooltip;
13643 gchar *tooltip_markup;
13645 g_return_if_fail (GTK_IS_WIDGET (widget));
13646 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13648 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13651 g_object_ref (custom_window);
13653 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13654 custom_window, g_object_unref);
13656 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13657 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13659 if (has_tooltip && gtk_widget_get_visible (widget))
13660 gtk_widget_queue_tooltip_query (widget);
13664 * gtk_widget_get_tooltip_window:
13665 * @widget: a #GtkWidget
13667 * Returns the #GtkWindow of the current tooltip. This can be the
13668 * GtkWindow created by default, or the custom tooltip window set
13669 * using gtk_widget_set_tooltip_window().
13671 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13676 gtk_widget_get_tooltip_window (GtkWidget *widget)
13678 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13680 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13684 * gtk_widget_trigger_tooltip_query:
13685 * @widget: a #GtkWidget
13687 * Triggers a tooltip query on the display where the toplevel of @widget
13688 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13694 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13696 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13699 static guint tooltip_query_id;
13700 static GSList *tooltip_query_displays;
13703 tooltip_query_idle (gpointer data)
13705 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13706 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13707 g_slist_free (tooltip_query_displays);
13709 tooltip_query_displays = NULL;
13710 tooltip_query_id = 0;
13716 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13718 GdkDisplay *display;
13720 display = gtk_widget_get_display (widget);
13722 if (!g_slist_find (tooltip_query_displays, display))
13723 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13725 if (tooltip_query_id == 0)
13726 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13730 * gtk_widget_set_tooltip_text:
13731 * @widget: a #GtkWidget
13732 * @text: (allow-none): the contents of the tooltip for @widget
13734 * Sets @text as the contents of the tooltip. This function will take
13735 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13736 * handler for the #GtkWidget::query-tooltip signal.
13738 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13743 gtk_widget_set_tooltip_text (GtkWidget *widget,
13746 g_return_if_fail (GTK_IS_WIDGET (widget));
13748 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13752 * gtk_widget_get_tooltip_text:
13753 * @widget: a #GtkWidget
13755 * Gets the contents of the tooltip for @widget.
13757 * Return value: the tooltip text, or %NULL. You should free the
13758 * returned string with g_free() when done.
13763 gtk_widget_get_tooltip_text (GtkWidget *widget)
13765 gchar *text = NULL;
13767 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13769 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13775 * gtk_widget_set_tooltip_markup:
13776 * @widget: a #GtkWidget
13777 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13779 * Sets @markup as the contents of the tooltip, which is marked up with
13780 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13782 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13783 * and of the default handler for the #GtkWidget::query-tooltip signal.
13785 * See also the #GtkWidget:tooltip-markup property and
13786 * gtk_tooltip_set_markup().
13791 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13792 const gchar *markup)
13794 g_return_if_fail (GTK_IS_WIDGET (widget));
13796 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13800 * gtk_widget_get_tooltip_markup:
13801 * @widget: a #GtkWidget
13803 * Gets the contents of the tooltip for @widget.
13805 * Return value: the tooltip text, or %NULL. You should free the
13806 * returned string with g_free() when done.
13811 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13813 gchar *text = NULL;
13815 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13817 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13823 * gtk_widget_set_has_tooltip:
13824 * @widget: a #GtkWidget
13825 * @has_tooltip: whether or not @widget has a tooltip.
13827 * Sets the has-tooltip property on @widget to @has_tooltip. See
13828 * #GtkWidget:has-tooltip for more information.
13833 gtk_widget_set_has_tooltip (GtkWidget *widget,
13834 gboolean has_tooltip)
13836 g_return_if_fail (GTK_IS_WIDGET (widget));
13838 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13842 * gtk_widget_get_has_tooltip:
13843 * @widget: a #GtkWidget
13845 * Returns the current value of the has-tooltip property. See
13846 * #GtkWidget:has-tooltip for more information.
13848 * Return value: current value of has-tooltip on @widget.
13853 gtk_widget_get_has_tooltip (GtkWidget *widget)
13855 gboolean has_tooltip = FALSE;
13857 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13859 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13861 return has_tooltip;
13865 * gtk_widget_get_allocation:
13866 * @widget: a #GtkWidget
13867 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13869 * Retrieves the widget's allocation.
13871 * Note, when implementing a #GtkContainer: a widget's allocation will
13872 * be its "adjusted" allocation, that is, the widget's parent
13873 * container typically calls gtk_widget_size_allocate() with an
13874 * allocation, and that allocation is then adjusted (to handle margin
13875 * and alignment for example) before assignment to the widget.
13876 * gtk_widget_get_allocation() returns the adjusted allocation that
13877 * was actually assigned to the widget. The adjusted allocation is
13878 * guaranteed to be completely contained within the
13879 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13880 * is guaranteed that its children stay inside the assigned bounds,
13881 * but not that they have exactly the bounds the container assigned.
13882 * There is no way to get the original allocation assigned by
13883 * gtk_widget_size_allocate(), since it isn't stored; if a container
13884 * implementation needs that information it will have to track it itself.
13889 gtk_widget_get_allocation (GtkWidget *widget,
13890 GtkAllocation *allocation)
13892 GtkWidgetPrivate *priv;
13894 g_return_if_fail (GTK_IS_WIDGET (widget));
13895 g_return_if_fail (allocation != NULL);
13897 priv = widget->priv;
13899 *allocation = priv->allocation;
13903 * gtk_widget_set_allocation:
13904 * @widget: a #GtkWidget
13905 * @allocation: a pointer to a #GtkAllocation to copy from
13907 * Sets the widget's allocation. This should not be used
13908 * directly, but from within a widget's size_allocate method.
13910 * The allocation set should be the "adjusted" or actual
13911 * allocation. If you're implementing a #GtkContainer, you want to use
13912 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13913 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13914 * allocation inside gtk_widget_size_allocate() to create an adjusted
13920 gtk_widget_set_allocation (GtkWidget *widget,
13921 const GtkAllocation *allocation)
13923 GtkWidgetPrivate *priv;
13925 g_return_if_fail (GTK_IS_WIDGET (widget));
13926 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13927 g_return_if_fail (allocation != NULL);
13929 priv = widget->priv;
13931 priv->allocation = *allocation;
13935 * gtk_widget_get_allocated_width:
13936 * @widget: the widget to query
13938 * Returns the width that has currently been allocated to @widget.
13939 * This function is intended to be used when implementing handlers
13940 * for the #GtkWidget::draw function.
13942 * Returns: the width of the @widget
13945 gtk_widget_get_allocated_width (GtkWidget *widget)
13947 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13949 return widget->priv->allocation.width;
13953 * gtk_widget_get_allocated_height:
13954 * @widget: the widget to query
13956 * Returns the height that has currently been allocated to @widget.
13957 * This function is intended to be used when implementing handlers
13958 * for the #GtkWidget::draw function.
13960 * Returns: the height of the @widget
13963 gtk_widget_get_allocated_height (GtkWidget *widget)
13965 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13967 return widget->priv->allocation.height;
13971 * gtk_widget_get_requisition:
13972 * @widget: a #GtkWidget
13973 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13975 * Retrieves the widget's requisition.
13977 * This function should only be used by widget implementations in
13978 * order to figure whether the widget's requisition has actually
13979 * changed after some internal state change (so that they can call
13980 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13982 * Normally, gtk_widget_size_request() should be used.
13986 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13987 * removed, If you need to cache sizes across requests and allocations,
13988 * add an explicit cache to the widget in question instead.
13991 gtk_widget_get_requisition (GtkWidget *widget,
13992 GtkRequisition *requisition)
13994 g_return_if_fail (GTK_IS_WIDGET (widget));
13995 g_return_if_fail (requisition != NULL);
13997 gtk_widget_get_preferred_size (widget, requisition, NULL);
14001 * gtk_widget_set_window:
14002 * @widget: a #GtkWidget
14003 * @window: (transfer full): a #GdkWindow
14005 * Sets a widget's window. This function should only be used in a
14006 * widget's #GtkWidget::realize implementation. The %window passed is
14007 * usually either new window created with gdk_window_new(), or the
14008 * window of its parent widget as returned by
14009 * gtk_widget_get_parent_window().
14011 * Widgets must indicate whether they will create their own #GdkWindow
14012 * by calling gtk_widget_set_has_window(). This is usually done in the
14013 * widget's init() function.
14015 * <note><para>This function does not add any reference to @window.</para></note>
14020 gtk_widget_set_window (GtkWidget *widget,
14023 GtkWidgetPrivate *priv;
14025 g_return_if_fail (GTK_IS_WIDGET (widget));
14026 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
14028 priv = widget->priv;
14030 if (priv->window != window)
14032 priv->window = window;
14034 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
14035 gdk_window_set_opacity (window,
14036 priv->norender ? 0 : priv->alpha / 255.0);
14038 g_object_notify (G_OBJECT (widget), "window");
14043 * gtk_widget_register_window:
14044 * @widget: a #GtkWidget
14045 * @window: a #GdkWindow
14047 * Registers a #GdkWindow with the widget and sets it up so that
14048 * the widget recieves events for it. Call gtk_widget_unregister_window()
14049 * when destroying the window.
14051 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
14052 * this up. This is now deprecated and you should use gtk_widget_register_window()
14053 * instead. Old code will keep working as is, although some new features like
14054 * transparency might not work perfectly.
14059 gtk_widget_register_window (GtkWidget *widget,
14062 GtkWidgetPrivate *priv;
14063 gpointer user_data;
14065 g_return_if_fail (GTK_IS_WIDGET (widget));
14066 g_return_if_fail (GDK_IS_WINDOW (window));
14068 gdk_window_get_user_data (window, &user_data);
14069 g_assert (user_data == NULL);
14071 priv = widget->priv;
14073 gdk_window_set_user_data (window, widget);
14074 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
14076 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
14077 gdk_window_set_opacity (window,
14078 priv->norender_children ? 0.0 : 1.0);
14082 * gtk_widget_unregister_window:
14083 * @widget: a #GtkWidget
14084 * @window: a #GdkWindow
14086 * Unregisters a #GdkWindow from the widget that was previously set up with
14087 * gtk_widget_register_window(). You need to call this when the window is
14088 * no longer used by the widget, such as when you destroy it.
14093 gtk_widget_unregister_window (GtkWidget *widget,
14096 GtkWidgetPrivate *priv;
14097 gpointer user_data;
14099 g_return_if_fail (GTK_IS_WIDGET (widget));
14100 g_return_if_fail (GDK_IS_WINDOW (window));
14102 priv = widget->priv;
14104 gdk_window_get_user_data (window, &user_data);
14105 g_assert (user_data == widget);
14106 gdk_window_set_user_data (window, NULL);
14107 priv->registered_windows = g_list_remove (priv->registered_windows, window);
14111 * gtk_widget_get_window:
14112 * @widget: a #GtkWidget
14114 * Returns the widget's window if it is realized, %NULL otherwise
14116 * Return value: (transfer none): @widget's window.
14121 gtk_widget_get_window (GtkWidget *widget)
14123 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14125 return widget->priv->window;
14129 * gtk_widget_get_support_multidevice:
14130 * @widget: a #GtkWidget
14132 * Returns %TRUE if @widget is multiple pointer aware. See
14133 * gtk_widget_set_support_multidevice() for more information.
14135 * Returns: %TRUE if @widget is multidevice aware.
14138 gtk_widget_get_support_multidevice (GtkWidget *widget)
14140 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14142 return widget->priv->multidevice;
14146 * gtk_widget_set_support_multidevice:
14147 * @widget: a #GtkWidget
14148 * @support_multidevice: %TRUE to support input from multiple devices.
14150 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
14151 * @widget will start receiving multiple, per device enter/leave events. Note
14152 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
14153 * gdk_window_set_support_multidevice() will have to be called manually on them.
14158 gtk_widget_set_support_multidevice (GtkWidget *widget,
14159 gboolean support_multidevice)
14161 GtkWidgetPrivate *priv;
14163 g_return_if_fail (GTK_IS_WIDGET (widget));
14165 priv = widget->priv;
14166 priv->multidevice = (support_multidevice == TRUE);
14168 if (gtk_widget_get_realized (widget))
14169 gdk_window_set_support_multidevice (priv->window, support_multidevice);
14172 /* There are multiple alpha related sources. First of all the user can specify alpha
14173 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
14174 * are multiplied together to form the total alpha. Secondly, the user can specify
14175 * an opacity group for a widget, which means we must essentially handle it as having alpha.
14177 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
14178 * group we directly set the opacity of widget->window. This will cause gdk to properly
14179 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
14181 * However, if the widget is not windowed, or the user specified an opacity group for the
14182 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
14183 * implementation of this would break for windowed widgets or descendant widgets with
14184 * windows, as these would not be handled by the ::draw signal. To handle this we set
14185 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
14186 * to make the draw signal propagate to *all* child widgets/windows.
14188 * Note: We don't make all child windows fully transparent, we stop at the first one
14189 * in each branch when propagating down the hierarchy.
14193 /* This is called when priv->alpha or priv->opacity_group group changes, and should
14194 * update priv->norender and GdkWindow opacity for this widget and any children that
14195 * needs changing. It is also called whenver the parent changes, the parents
14196 * norender_children state changes, or the has_window state of the widget changes.
14199 gtk_widget_propagate_alpha (GtkWidget *widget)
14201 GtkWidgetPrivate *priv = widget->priv;
14203 gboolean norender, norender_children;
14206 parent = priv->parent;
14209 /* If this widget has an opacity group, never render it */
14210 priv->opacity_group ||
14211 /* If the parent has norender_children, propagate that here */
14212 (parent != NULL && parent->priv->norender_children);
14214 /* Windowed widget children should norender if: */
14215 norender_children =
14216 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
14217 !gtk_widget_get_has_window (widget) &&
14218 ( /* norender is set, or */
14220 /* widget has an alpha */
14224 if (gtk_widget_get_has_window (widget))
14226 if (priv->window != NULL && !gdk_window_has_native (priv->window))
14227 gdk_window_set_opacity (priv->window,
14228 norender ? 0 : priv->alpha / 255.0);
14230 else /* !has_window */
14232 for (l = priv->registered_windows; l != NULL; l = l->next)
14234 GdkWindow *w = l->data;
14235 if (!gdk_window_has_native (w))
14236 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
14240 priv->norender = norender;
14241 if (priv->norender_children != norender_children)
14243 priv->norender_children = norender_children;
14245 if (GTK_IS_CONTAINER (widget))
14246 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
14249 if (gtk_widget_get_realized (widget))
14250 gtk_widget_queue_draw (widget);
14254 gtk_widget_update_alpha (GtkWidget *widget)
14256 GtkWidgetPrivate *priv;
14260 priv = widget->priv;
14262 alpha = priv->user_alpha;
14267 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
14268 GTK_CSS_PROPERTY_OPACITY),
14270 opacity = CLAMP (opacity, 0.0, 1.0);
14271 alpha = round (priv->user_alpha * opacity);
14274 if (alpha == priv->alpha)
14277 priv->alpha = alpha;
14279 gtk_widget_propagate_alpha (widget);
14284 gtk_widget_set_has_opacity_group (GtkWidget *widget,
14285 gboolean has_opacity_group)
14287 GtkWidgetPrivate *priv;
14289 g_return_if_fail (GTK_IS_WIDGET (widget));
14291 priv = widget->priv;
14293 has_opacity_group = !!has_opacity_group;
14295 if (priv->opacity_group == has_opacity_group)
14298 priv->opacity_group = has_opacity_group;
14300 gtk_widget_propagate_alpha (widget);
14304 * gtk_widget_set_opacity:
14305 * @widget: a #GtkWidget
14306 * @opacity: desired opacity, between 0 and 1
14308 * Request the @widget to be rendered partially transparent,
14309 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14310 * are clamped to the [0,1] range.).
14311 * This works on both toplevel widget, and child widgets, although there
14312 * are some limitations:
14314 * For toplevel widgets this depends on the capabilities of the windowing
14315 * system. On X11 this has any effect only on X screens with a compositing manager
14316 * running. See gtk_widget_is_composited(). On Windows it should work
14317 * always, although setting a window's opacity after the window has been
14318 * shown causes it to flicker once on Windows.
14320 * For child widgets it doesn't work if any affected widget has a native window, or
14321 * disables double buffering.
14326 gtk_widget_set_opacity (GtkWidget *widget,
14329 GtkWidgetPrivate *priv;
14332 g_return_if_fail (GTK_IS_WIDGET (widget));
14334 priv = widget->priv;
14336 opacity = CLAMP (opacity, 0.0, 1.0);
14338 alpha = round (opacity * 255);
14340 /* As a kind of hack for internal use we treat an alpha very
14341 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14342 we want the opacity group behaviour wrt draw handling, but
14343 not actually an alpha value. See bug #687842 for discussions. */
14344 gtk_widget_set_has_opacity_group (widget,
14345 alpha == 255 && opacity != 1.0);
14347 if (alpha == priv->user_alpha)
14350 priv->user_alpha = alpha;
14352 gtk_widget_update_alpha (widget);
14357 * gtk_widget_get_opacity:
14358 * @widget: a #GtkWidget
14360 * Fetches the requested opacity for this widget. See
14361 * gtk_widget_set_opacity().
14363 * Return value: the requested opacity for this widget.
14368 gtk_widget_get_opacity (GtkWidget *widget)
14370 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14372 return widget->priv->alpha / 255.0;
14376 _gtk_widget_set_has_focus (GtkWidget *widget,
14377 gboolean has_focus)
14379 widget->priv->has_focus = has_focus;
14382 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14384 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14388 * gtk_widget_send_focus_change:
14389 * @widget: a #GtkWidget
14390 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14392 * Sends the focus change @event to @widget
14394 * This function is not meant to be used by applications. The only time it
14395 * should be used is when it is necessary for a #GtkWidget to assign focus
14396 * to a widget that is semantically owned by the first widget even though
14397 * it's not a direct child - for instance, a search entry in a floating
14398 * window similar to the quick search in #GtkTreeView.
14400 * An example of its usage is:
14403 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14405 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14406 * fevent->focus_change.in = TRUE;
14407 * fevent->focus_change.window = gtk_widget_get_window (widget);
14408 * if (fevent->focus_change.window != NULL)
14409 * g_object_ref (fevent->focus_change.window);
14411 * gtk_widget_send_focus_change (widget, fevent);
14413 * gdk_event_free (event);
14416 * Return value: the return value from the event signal emission: %TRUE
14417 * if the event was handled, and %FALSE otherwise
14422 gtk_widget_send_focus_change (GtkWidget *widget,
14427 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14428 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14430 g_object_ref (widget);
14432 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14434 res = gtk_widget_event (widget, event);
14436 g_object_notify (G_OBJECT (widget), "has-focus");
14438 g_object_unref (widget);
14444 * gtk_widget_in_destruction:
14445 * @widget: a #GtkWidget
14447 * Returns whether the widget is currently being destroyed.
14448 * This information can sometimes be used to avoid doing
14449 * unnecessary work.
14451 * Returns: %TRUE if @widget is being destroyed
14454 gtk_widget_in_destruction (GtkWidget *widget)
14456 return widget->priv->in_destruction;
14460 _gtk_widget_get_in_reparent (GtkWidget *widget)
14462 return widget->priv->in_reparent;
14466 _gtk_widget_set_in_reparent (GtkWidget *widget,
14467 gboolean in_reparent)
14469 widget->priv->in_reparent = in_reparent;
14473 _gtk_widget_get_anchored (GtkWidget *widget)
14475 return widget->priv->anchored;
14479 _gtk_widget_set_anchored (GtkWidget *widget,
14482 widget->priv->anchored = anchored;
14486 _gtk_widget_get_shadowed (GtkWidget *widget)
14488 return widget->priv->shadowed;
14492 _gtk_widget_set_shadowed (GtkWidget *widget,
14495 widget->priv->shadowed = shadowed;
14499 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14501 return widget->priv->alloc_needed;
14505 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14506 gboolean alloc_needed)
14508 widget->priv->alloc_needed = alloc_needed;
14512 _gtk_widget_add_sizegroup (GtkWidget *widget,
14517 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14518 groups = g_slist_prepend (groups, group);
14519 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14521 widget->priv->have_size_groups = TRUE;
14525 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14530 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14531 groups = g_slist_remove (groups, group);
14532 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14534 widget->priv->have_size_groups = groups != NULL;
14538 _gtk_widget_get_sizegroups (GtkWidget *widget)
14540 if (widget->priv->have_size_groups)
14541 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14547 _gtk_widget_add_attached_window (GtkWidget *widget,
14550 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14554 _gtk_widget_remove_attached_window (GtkWidget *widget,
14557 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14561 * gtk_widget_path_append_for_widget:
14562 * @path: a widget path
14563 * @widget: the widget to append to the widget path
14565 * Appends the data from @widget to the widget hierarchy represented
14566 * by @path. This function is a shortcut for adding information from
14567 * @widget to the given @path. This includes setting the name or
14568 * adding the style classes from @widget.
14570 * Returns: the position where the data was inserted
14575 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14580 g_return_val_if_fail (path != NULL, 0);
14581 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14583 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14585 if (widget->priv->name)
14586 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14588 if (widget->priv->context)
14590 GList *classes, *l;
14592 /* Also add any persistent classes in
14593 * the style context the widget path
14595 classes = gtk_style_context_list_classes (widget->priv->context);
14597 for (l = classes; l; l = l->next)
14598 gtk_widget_path_iter_add_class (path, pos, l->data);
14600 g_list_free (classes);
14607 _gtk_widget_create_path (GtkWidget *widget)
14611 parent = widget->priv->parent;
14614 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14617 /* Widget is either toplevel or unparented, treat both
14618 * as toplevels style wise, since there are situations
14619 * where style properties might be retrieved on that
14622 GtkWidget *attach_widget = NULL;
14623 GtkWidgetPath *result;
14625 if (GTK_IS_WINDOW (widget))
14626 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14628 if (attach_widget != NULL)
14629 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14631 result = gtk_widget_path_new ();
14633 gtk_widget_path_append_for_widget (result, widget);
14640 * gtk_widget_get_path:
14641 * @widget: a #GtkWidget
14643 * Returns the #GtkWidgetPath representing @widget, if the widget
14644 * is not connected to a toplevel widget, a partial path will be
14647 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14650 gtk_widget_get_path (GtkWidget *widget)
14652 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14654 if (!widget->priv->path)
14655 widget->priv->path = _gtk_widget_create_path (widget);
14657 return widget->priv->path;
14661 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14663 if (widget->priv->path)
14665 gtk_widget_path_free (widget->priv->path);
14666 widget->priv->path = NULL;
14669 if (gtk_widget_get_realized (widget))
14670 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14673 /* Compress all style updates so it
14674 * is only emitted once pre-realize.
14676 widget->priv->style_update_pending = TRUE;
14681 * gtk_widget_get_style_context:
14682 * @widget: a #GtkWidget
14684 * Returns the style context associated to @widget.
14686 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14687 * must not be freed.
14690 gtk_widget_get_style_context (GtkWidget *widget)
14692 GtkWidgetPrivate *priv;
14694 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14696 priv = widget->priv;
14698 if (G_UNLIKELY (priv->context == NULL))
14701 GdkFrameClock *frame_clock;
14703 priv->context = gtk_style_context_new ();
14705 gtk_style_context_set_state (priv->context, priv->state_flags);
14707 screen = gtk_widget_get_screen (widget);
14709 gtk_style_context_set_screen (priv->context, screen);
14711 frame_clock = gtk_widget_get_frame_clock (widget);
14713 gtk_style_context_set_frame_clock (priv->context, frame_clock);
14716 gtk_style_context_set_parent (priv->context,
14717 gtk_widget_get_style_context (priv->parent));
14719 _gtk_style_context_set_widget (priv->context, widget);
14722 return widget->priv->context;
14726 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14727 GtkCssChange change)
14729 GtkWidgetPrivate *priv;
14731 priv = widget->priv;
14733 if (priv->context == NULL)
14736 _gtk_style_context_queue_invalidate (priv->context, change);
14740 * gtk_widget_get_modifier_mask:
14741 * @widget: a #GtkWidget
14742 * @intent: the use case for the modifier mask
14744 * Returns the modifier mask the @widget's windowing system backend
14745 * uses for a particular purpose.
14747 * See gdk_keymap_get_modifier_mask().
14749 * Returns: the modifier mask used for @intent.
14754 gtk_widget_get_modifier_mask (GtkWidget *widget,
14755 GdkModifierIntent intent)
14757 GdkDisplay *display;
14759 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14761 display = gtk_widget_get_display (widget);
14763 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14768 _gtk_widget_get_style (GtkWidget *widget)
14770 return widget->priv->style;
14774 _gtk_widget_set_style (GtkWidget *widget,
14777 widget->priv->style = style;
14781 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14784 GActionMuxer *parent_muxer;
14786 if (widget->priv->muxer == NULL)
14789 if (GTK_IS_MENU (widget))
14790 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14792 parent = gtk_widget_get_parent (widget);
14794 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14796 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14800 _gtk_widget_get_action_muxer (GtkWidget *widget)
14802 if (widget->priv->muxer == NULL)
14804 widget->priv->muxer = g_action_muxer_new ();
14805 _gtk_widget_update_parent_muxer (widget);
14808 return widget->priv->muxer;
14812 * gtk_widget_insert_action_group:
14813 * @widget: a #GtkWidget
14814 * @name: the prefix for actions in @group
14815 * @group: a #GActionGroup
14817 * Inserts @group into @widget. Children of @widget that implement
14818 * #GtkActionable can then be associated with actions in @group by
14819 * setting their 'action-name' to
14820 * @prefix.<replaceable>action-name</replaceable>.
14825 gtk_widget_insert_action_group (GtkWidget *widget,
14827 GActionGroup *group)
14829 GActionMuxer *muxer;
14831 g_return_if_fail (GTK_IS_WIDGET (widget));
14832 g_return_if_fail (name != NULL);
14834 muxer = _gtk_widget_get_action_muxer (widget);
14837 g_action_muxer_insert (muxer, name, group);
14839 g_action_muxer_remove (muxer, name);