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 * The signal handler will get a @cr with a clip region already set to the
1809 * widget's dirty region, i.e. to the area that needs repainting. Complicated
1810 * widgets that want to avoid redrawing themselves completely can get the full
1811 * extents of the clip region with gdk_cairo_get_clip_rectangle(), or they can
1812 * get a finer-grained representation of the dirty region with
1813 * cairo_copy_clip_rectangle_list().
1815 * Returns: %TRUE to stop other handlers from being invoked for the event.
1816 % %FALSE to propagate the event further.
1820 widget_signals[DRAW] =
1821 g_signal_new (I_("draw"),
1822 G_TYPE_FROM_CLASS (gobject_class),
1824 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1825 _gtk_boolean_handled_accumulator, NULL,
1826 gtk_widget_draw_marshaller,
1828 CAIRO_GOBJECT_TYPE_CONTEXT);
1829 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1830 gtk_widget_draw_marshallerv);
1833 * GtkWidget::mnemonic-activate:
1834 * @widget: the object which received the signal.
1837 * Returns: %TRUE to stop other handlers from being invoked for the event.
1838 * %FALSE to propagate the event further.
1840 widget_signals[MNEMONIC_ACTIVATE] =
1841 g_signal_new (I_("mnemonic-activate"),
1842 G_TYPE_FROM_CLASS (gobject_class),
1844 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1845 _gtk_boolean_handled_accumulator, NULL,
1846 _gtk_marshal_BOOLEAN__BOOLEAN,
1851 * GtkWidget::grab-focus:
1852 * @widget: the object which received the signal.
1854 widget_signals[GRAB_FOCUS] =
1855 g_signal_new (I_("grab-focus"),
1856 G_TYPE_FROM_CLASS (gobject_class),
1857 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1858 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1860 _gtk_marshal_VOID__VOID,
1865 * @widget: the object which received the signal.
1868 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1870 widget_signals[FOCUS] =
1871 g_signal_new (I_("focus"),
1872 G_TYPE_FROM_CLASS (klass),
1874 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1875 _gtk_boolean_handled_accumulator, NULL,
1876 _gtk_marshal_BOOLEAN__ENUM,
1878 GTK_TYPE_DIRECTION_TYPE);
1881 * GtkWidget::move-focus:
1882 * @widget: the object which received the signal.
1885 widget_signals[MOVE_FOCUS] =
1886 g_signal_new (I_("move-focus"),
1887 G_TYPE_FROM_CLASS (klass),
1888 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1889 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1891 _gtk_marshal_VOID__ENUM,
1894 GTK_TYPE_DIRECTION_TYPE);
1897 * GtkWidget::keynav-failed:
1898 * @widget: the object which received the signal
1899 * @direction: the direction of movement
1901 * Gets emitted if keyboard navigation fails.
1902 * See gtk_widget_keynav_failed() for details.
1904 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1905 * if the emitting widget should try to handle the keyboard
1906 * navigation attempt in its parent container(s).
1910 widget_signals[KEYNAV_FAILED] =
1911 g_signal_new (I_("keynav-failed"),
1912 G_TYPE_FROM_CLASS (klass),
1914 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1915 _gtk_boolean_handled_accumulator, NULL,
1916 _gtk_marshal_BOOLEAN__ENUM,
1918 GTK_TYPE_DIRECTION_TYPE);
1922 * @widget: the object which received the signal.
1923 * @event: the #GdkEvent which triggered this signal
1925 * The GTK+ main loop will emit three signals for each GDK event delivered
1926 * to a widget: one generic ::event signal, another, more specific,
1927 * signal that matches the type of event delivered (e.g.
1928 * #GtkWidget::key-press-event) and finally a generic
1929 * #GtkWidget::event-after signal.
1931 * Returns: %TRUE to stop other handlers from being invoked for the event
1932 * and to cancel the emission of the second specific ::event signal.
1933 * %FALSE to propagate the event further and to allow the emission of
1934 * the second signal. The ::event-after signal is emitted regardless of
1937 widget_signals[EVENT] =
1938 g_signal_new (I_("event"),
1939 G_TYPE_FROM_CLASS (klass),
1941 G_STRUCT_OFFSET (GtkWidgetClass, event),
1942 _gtk_boolean_handled_accumulator, NULL,
1943 _gtk_marshal_BOOLEAN__BOXED,
1945 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1946 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1947 _gtk_marshal_BOOLEAN__BOXEDv);
1950 * GtkWidget::event-after:
1951 * @widget: the object which received the signal.
1952 * @event: the #GdkEvent which triggered this signal
1954 * After the emission of the #GtkWidget::event signal and (optionally)
1955 * the second more specific signal, ::event-after will be emitted
1956 * regardless of the previous two signals handlers return values.
1959 widget_signals[EVENT_AFTER] =
1960 g_signal_new (I_("event-after"),
1961 G_TYPE_FROM_CLASS (klass),
1965 _gtk_marshal_VOID__BOXED,
1967 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1968 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1969 _gtk_marshal_BOOLEAN__BOXEDv);
1972 * GtkWidget::button-press-event:
1973 * @widget: the object which received the signal.
1974 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1977 * The ::button-press-event signal will be emitted when a button
1978 * (typically from a mouse) is pressed.
1980 * To receive this signal, the #GdkWindow associated to the
1981 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1983 * This signal will be sent to the grab widget if there is one.
1985 * Returns: %TRUE to stop other handlers from being invoked for the event.
1986 * %FALSE to propagate the event further.
1988 widget_signals[BUTTON_PRESS_EVENT] =
1989 g_signal_new (I_("button-press-event"),
1990 G_TYPE_FROM_CLASS (klass),
1992 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1993 _gtk_boolean_handled_accumulator, NULL,
1994 _gtk_marshal_BOOLEAN__BOXED,
1996 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1997 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1998 _gtk_marshal_BOOLEAN__BOXEDv);
2001 * GtkWidget::button-release-event:
2002 * @widget: the object which received the signal.
2003 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
2006 * The ::button-release-event signal will be emitted when a button
2007 * (typically from a mouse) is released.
2009 * To receive this signal, the #GdkWindow associated to the
2010 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
2012 * This signal will be sent to the grab widget if there is one.
2014 * Returns: %TRUE to stop other handlers from being invoked for the event.
2015 * %FALSE to propagate the event further.
2017 widget_signals[BUTTON_RELEASE_EVENT] =
2018 g_signal_new (I_("button-release-event"),
2019 G_TYPE_FROM_CLASS (klass),
2021 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2022 _gtk_boolean_handled_accumulator, NULL,
2023 _gtk_marshal_BOOLEAN__BOXED,
2025 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2026 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2027 _gtk_marshal_BOOLEAN__BOXEDv);
2029 widget_signals[TOUCH_EVENT] =
2030 g_signal_new (I_("touch-event"),
2031 G_TYPE_FROM_CLASS (klass),
2033 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2034 _gtk_boolean_handled_accumulator, NULL,
2035 _gtk_marshal_BOOLEAN__BOXED,
2037 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2038 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2039 _gtk_marshal_BOOLEAN__BOXEDv);
2042 * GtkWidget::scroll-event:
2043 * @widget: the object which received the signal.
2044 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2047 * The ::scroll-event signal is emitted when a button in the 4 to 7
2048 * range is pressed. Wheel mice are usually configured to generate
2049 * button press events for buttons 4 and 5 when the wheel is turned.
2051 * To receive this signal, the #GdkWindow associated to the widget needs
2052 * to enable the #GDK_SCROLL_MASK mask.
2054 * This signal will be sent to the grab widget if there is one.
2056 * Returns: %TRUE to stop other handlers from being invoked for the event.
2057 * %FALSE to propagate the event further.
2059 widget_signals[SCROLL_EVENT] =
2060 g_signal_new (I_("scroll-event"),
2061 G_TYPE_FROM_CLASS (klass),
2063 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2064 _gtk_boolean_handled_accumulator, NULL,
2065 _gtk_marshal_BOOLEAN__BOXED,
2067 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2068 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2069 _gtk_marshal_BOOLEAN__BOXEDv);
2072 * GtkWidget::motion-notify-event:
2073 * @widget: the object which received the signal.
2074 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2077 * The ::motion-notify-event signal is emitted when the pointer moves
2078 * over the widget's #GdkWindow.
2080 * To receive this signal, the #GdkWindow associated to the widget
2081 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2083 * This signal will be sent to the grab widget if there is one.
2085 * Returns: %TRUE to stop other handlers from being invoked for the event.
2086 * %FALSE to propagate the event further.
2088 widget_signals[MOTION_NOTIFY_EVENT] =
2089 g_signal_new (I_("motion-notify-event"),
2090 G_TYPE_FROM_CLASS (klass),
2092 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2093 _gtk_boolean_handled_accumulator, NULL,
2094 _gtk_marshal_BOOLEAN__BOXED,
2096 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2097 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2098 _gtk_marshal_BOOLEAN__BOXEDv);
2101 * GtkWidget::composited-changed:
2102 * @widget: the object on which the signal is emitted
2104 * The ::composited-changed signal is emitted when the composited
2105 * status of @widget<!-- -->s screen changes.
2106 * See gdk_screen_is_composited().
2108 widget_signals[COMPOSITED_CHANGED] =
2109 g_signal_new (I_("composited-changed"),
2110 G_TYPE_FROM_CLASS (klass),
2111 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2112 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2114 _gtk_marshal_VOID__VOID,
2118 * GtkWidget::delete-event:
2119 * @widget: the object which received the signal
2120 * @event: the event which triggered this signal
2122 * The ::delete-event signal is emitted if a user requests that
2123 * a toplevel window is closed. The default handler for this signal
2124 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2125 * this signal will cause the window to be hidden instead, so that
2126 * it can later be shown again without reconstructing it.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[DELETE_EVENT] =
2132 g_signal_new (I_("delete-event"),
2133 G_TYPE_FROM_CLASS (klass),
2135 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2140 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2141 _gtk_marshal_BOOLEAN__BOXEDv);
2144 * GtkWidget::destroy-event:
2145 * @widget: the object which received the signal.
2146 * @event: the event which triggered this signal
2148 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2149 * You rarely get this signal, because most widgets disconnect themselves
2150 * from their window before they destroy it, so no widget owns the
2151 * window at destroy time.
2153 * To receive this signal, the #GdkWindow associated to the widget needs
2154 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2155 * automatically for all new windows.
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[DESTROY_EVENT] =
2161 g_signal_new (I_("destroy-event"),
2162 G_TYPE_FROM_CLASS (klass),
2164 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2169 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2170 _gtk_marshal_BOOLEAN__BOXEDv);
2173 * GtkWidget::key-press-event:
2174 * @widget: the object which received the signal
2175 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2177 * The ::key-press-event signal is emitted when a key is pressed. The signal
2178 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2180 * To receive this signal, the #GdkWindow associated to the widget needs
2181 * to enable the #GDK_KEY_PRESS_MASK mask.
2183 * This signal will be sent to the grab widget if there is one.
2185 * Returns: %TRUE to stop other handlers from being invoked for the event.
2186 * %FALSE to propagate the event further.
2188 widget_signals[KEY_PRESS_EVENT] =
2189 g_signal_new (I_("key-press-event"),
2190 G_TYPE_FROM_CLASS (klass),
2192 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2193 _gtk_boolean_handled_accumulator, NULL,
2194 _gtk_marshal_BOOLEAN__BOXED,
2196 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2197 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2198 _gtk_marshal_BOOLEAN__BOXEDv);
2201 * GtkWidget::key-release-event:
2202 * @widget: the object which received the signal
2203 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2205 * The ::key-release-event signal is emitted when a key is released.
2207 * To receive this signal, the #GdkWindow associated to the widget needs
2208 * to enable the #GDK_KEY_RELEASE_MASK mask.
2210 * This signal will be sent to the grab widget if there is one.
2212 * Returns: %TRUE to stop other handlers from being invoked for the event.
2213 * %FALSE to propagate the event further.
2215 widget_signals[KEY_RELEASE_EVENT] =
2216 g_signal_new (I_("key-release-event"),
2217 G_TYPE_FROM_CLASS (klass),
2219 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2220 _gtk_boolean_handled_accumulator, NULL,
2221 _gtk_marshal_BOOLEAN__BOXED,
2223 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2224 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2225 _gtk_marshal_BOOLEAN__BOXEDv);
2228 * GtkWidget::enter-notify-event:
2229 * @widget: the object which received the signal
2230 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2233 * The ::enter-notify-event will be emitted when the pointer enters
2234 * the @widget's window.
2236 * To receive this signal, the #GdkWindow associated to the widget needs
2237 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2239 * This signal will be sent to the grab widget if there is one.
2241 * Returns: %TRUE to stop other handlers from being invoked for the event.
2242 * %FALSE to propagate the event further.
2244 widget_signals[ENTER_NOTIFY_EVENT] =
2245 g_signal_new (I_("enter-notify-event"),
2246 G_TYPE_FROM_CLASS (klass),
2248 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2249 _gtk_boolean_handled_accumulator, NULL,
2250 _gtk_marshal_BOOLEAN__BOXED,
2252 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2253 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2254 _gtk_marshal_BOOLEAN__BOXEDv);
2257 * GtkWidget::leave-notify-event:
2258 * @widget: the object which received the signal
2259 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2262 * The ::leave-notify-event will be emitted when the pointer leaves
2263 * the @widget's window.
2265 * To receive this signal, the #GdkWindow associated to the widget needs
2266 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2268 * This signal will be sent to the grab widget if there is one.
2270 * Returns: %TRUE to stop other handlers from being invoked for the event.
2271 * %FALSE to propagate the event further.
2273 widget_signals[LEAVE_NOTIFY_EVENT] =
2274 g_signal_new (I_("leave-notify-event"),
2275 G_TYPE_FROM_CLASS (klass),
2277 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2278 _gtk_boolean_handled_accumulator, NULL,
2279 _gtk_marshal_BOOLEAN__BOXED,
2281 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2282 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2283 _gtk_marshal_BOOLEAN__BOXEDv);
2286 * GtkWidget::configure-event:
2287 * @widget: the object which received the signal
2288 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2291 * The ::configure-event signal will be emitted when the size, position or
2292 * stacking of the @widget's window has changed.
2294 * To receive this signal, the #GdkWindow associated to the widget needs
2295 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2296 * automatically for all new windows.
2298 * Returns: %TRUE to stop other handlers from being invoked for the event.
2299 * %FALSE to propagate the event further.
2301 widget_signals[CONFIGURE_EVENT] =
2302 g_signal_new (I_("configure-event"),
2303 G_TYPE_FROM_CLASS (klass),
2305 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2306 _gtk_boolean_handled_accumulator, NULL,
2307 _gtk_marshal_BOOLEAN__BOXED,
2309 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2310 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2311 _gtk_marshal_BOOLEAN__BOXEDv);
2314 * GtkWidget::focus-in-event:
2315 * @widget: the object which received the signal
2316 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2319 * The ::focus-in-event signal will be emitted when the keyboard focus
2320 * enters the @widget's window.
2322 * To receive this signal, the #GdkWindow associated to the widget needs
2323 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2325 * Returns: %TRUE to stop other handlers from being invoked for the event.
2326 * %FALSE to propagate the event further.
2328 widget_signals[FOCUS_IN_EVENT] =
2329 g_signal_new (I_("focus-in-event"),
2330 G_TYPE_FROM_CLASS (klass),
2332 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2333 _gtk_boolean_handled_accumulator, NULL,
2334 _gtk_marshal_BOOLEAN__BOXED,
2336 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2337 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2338 _gtk_marshal_BOOLEAN__BOXEDv);
2341 * GtkWidget::focus-out-event:
2342 * @widget: the object which received the signal
2343 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2346 * The ::focus-out-event signal will be emitted when the keyboard focus
2347 * leaves the @widget's window.
2349 * To receive this signal, the #GdkWindow associated to the widget needs
2350 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2352 * Returns: %TRUE to stop other handlers from being invoked for the event.
2353 * %FALSE to propagate the event further.
2355 widget_signals[FOCUS_OUT_EVENT] =
2356 g_signal_new (I_("focus-out-event"),
2357 G_TYPE_FROM_CLASS (klass),
2359 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2360 _gtk_boolean_handled_accumulator, NULL,
2361 _gtk_marshal_BOOLEAN__BOXED,
2363 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2364 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2365 _gtk_marshal_BOOLEAN__BOXEDv);
2368 * GtkWidget::map-event:
2369 * @widget: the object which received the signal
2370 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2372 * The ::map-event signal will be emitted when the @widget's window is
2373 * mapped. A window is mapped when it becomes visible on the screen.
2375 * To receive this signal, the #GdkWindow associated to the widget needs
2376 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2377 * automatically for all new windows.
2379 * Returns: %TRUE to stop other handlers from being invoked for the event.
2380 * %FALSE to propagate the event further.
2382 widget_signals[MAP_EVENT] =
2383 g_signal_new (I_("map-event"),
2384 G_TYPE_FROM_CLASS (klass),
2386 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2387 _gtk_boolean_handled_accumulator, NULL,
2388 _gtk_marshal_BOOLEAN__BOXED,
2390 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2391 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2392 _gtk_marshal_BOOLEAN__BOXEDv);
2395 * GtkWidget::unmap-event:
2396 * @widget: the object which received the signal
2397 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2399 * The ::unmap-event signal will be emitted when the @widget's window is
2400 * unmapped. A window is unmapped when it becomes invisible on the screen.
2402 * To receive this signal, the #GdkWindow associated to the widget needs
2403 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2404 * automatically for all new windows.
2406 * Returns: %TRUE to stop other handlers from being invoked for the event.
2407 * %FALSE to propagate the event further.
2409 widget_signals[UNMAP_EVENT] =
2410 g_signal_new (I_("unmap-event"),
2411 G_TYPE_FROM_CLASS (klass),
2413 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2414 _gtk_boolean_handled_accumulator, NULL,
2415 _gtk_marshal_BOOLEAN__BOXED,
2417 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2418 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2419 _gtk_marshal_BOOLEAN__BOXEDv);
2422 * GtkWidget::property-notify-event:
2423 * @widget: the object which received the signal
2424 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2427 * The ::property-notify-event signal will be emitted when a property on
2428 * the @widget's window has been changed or deleted.
2430 * To receive this signal, the #GdkWindow associated to the widget needs
2431 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2433 * Returns: %TRUE to stop other handlers from being invoked for the event.
2434 * %FALSE to propagate the event further.
2436 widget_signals[PROPERTY_NOTIFY_EVENT] =
2437 g_signal_new (I_("property-notify-event"),
2438 G_TYPE_FROM_CLASS (klass),
2440 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2441 _gtk_boolean_handled_accumulator, NULL,
2442 _gtk_marshal_BOOLEAN__BOXED,
2444 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2445 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2446 _gtk_marshal_BOOLEAN__BOXEDv);
2449 * GtkWidget::selection-clear-event:
2450 * @widget: the object which received the signal
2451 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2454 * The ::selection-clear-event signal will be emitted when the
2455 * the @widget's window has lost ownership of a selection.
2457 * Returns: %TRUE to stop other handlers from being invoked for the event.
2458 * %FALSE to propagate the event further.
2460 widget_signals[SELECTION_CLEAR_EVENT] =
2461 g_signal_new (I_("selection-clear-event"),
2462 G_TYPE_FROM_CLASS (klass),
2464 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2465 _gtk_boolean_handled_accumulator, NULL,
2466 _gtk_marshal_BOOLEAN__BOXED,
2468 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2469 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2470 _gtk_marshal_BOOLEAN__BOXEDv);
2473 * GtkWidget::selection-request-event:
2474 * @widget: the object which received the signal
2475 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2478 * The ::selection-request-event signal will be emitted when
2479 * another client requests ownership of the selection owned by
2480 * the @widget's window.
2482 * Returns: %TRUE to stop other handlers from being invoked for the event.
2483 * %FALSE to propagate the event further.
2485 widget_signals[SELECTION_REQUEST_EVENT] =
2486 g_signal_new (I_("selection-request-event"),
2487 G_TYPE_FROM_CLASS (klass),
2489 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2490 _gtk_boolean_handled_accumulator, NULL,
2491 _gtk_marshal_BOOLEAN__BOXED,
2493 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2494 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2495 _gtk_marshal_BOOLEAN__BOXEDv);
2498 * GtkWidget::selection-notify-event:
2499 * @widget: the object which received the signal.
2500 * @event: (type Gdk.EventSelection):
2502 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2504 widget_signals[SELECTION_NOTIFY_EVENT] =
2505 g_signal_new (I_("selection-notify-event"),
2506 G_TYPE_FROM_CLASS (klass),
2508 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2509 _gtk_boolean_handled_accumulator, NULL,
2510 _gtk_marshal_BOOLEAN__BOXED,
2512 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2513 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2514 _gtk_marshal_BOOLEAN__BOXEDv);
2517 * GtkWidget::selection-received:
2518 * @widget: the object which received the signal.
2522 widget_signals[SELECTION_RECEIVED] =
2523 g_signal_new (I_("selection-received"),
2524 G_TYPE_FROM_CLASS (klass),
2526 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2528 _gtk_marshal_VOID__BOXED_UINT,
2530 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2534 * GtkWidget::selection-get:
2535 * @widget: the object which received the signal.
2540 widget_signals[SELECTION_GET] =
2541 g_signal_new (I_("selection-get"),
2542 G_TYPE_FROM_CLASS (klass),
2544 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2546 _gtk_marshal_VOID__BOXED_UINT_UINT,
2548 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2553 * GtkWidget::proximity-in-event:
2554 * @widget: the object which received the signal
2555 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2558 * To receive this signal the #GdkWindow associated to the widget needs
2559 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2561 * This signal will be sent to the grab widget if there is one.
2563 * Returns: %TRUE to stop other handlers from being invoked for the event.
2564 * %FALSE to propagate the event further.
2566 widget_signals[PROXIMITY_IN_EVENT] =
2567 g_signal_new (I_("proximity-in-event"),
2568 G_TYPE_FROM_CLASS (klass),
2570 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2571 _gtk_boolean_handled_accumulator, NULL,
2572 _gtk_marshal_BOOLEAN__BOXED,
2574 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2575 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2576 _gtk_marshal_BOOLEAN__BOXEDv);
2579 * GtkWidget::proximity-out-event:
2580 * @widget: the object which received the signal
2581 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2584 * To receive this signal the #GdkWindow associated to the widget needs
2585 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2587 * This signal will be sent to the grab widget if there is one.
2589 * Returns: %TRUE to stop other handlers from being invoked for the event.
2590 * %FALSE to propagate the event further.
2592 widget_signals[PROXIMITY_OUT_EVENT] =
2593 g_signal_new (I_("proximity-out-event"),
2594 G_TYPE_FROM_CLASS (klass),
2596 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2597 _gtk_boolean_handled_accumulator, NULL,
2598 _gtk_marshal_BOOLEAN__BOXED,
2600 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2601 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2602 _gtk_marshal_BOOLEAN__BOXEDv);
2605 * GtkWidget::drag-leave:
2606 * @widget: the object which received the signal.
2607 * @context: the drag context
2608 * @time: the timestamp of the motion event
2610 * The ::drag-leave signal is emitted on the drop site when the cursor
2611 * leaves the widget. A typical reason to connect to this signal is to
2612 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2613 * with gtk_drag_unhighlight()
2615 widget_signals[DRAG_LEAVE] =
2616 g_signal_new (I_("drag-leave"),
2617 G_TYPE_FROM_CLASS (klass),
2619 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2621 _gtk_marshal_VOID__OBJECT_UINT,
2623 GDK_TYPE_DRAG_CONTEXT,
2627 * GtkWidget::drag-begin:
2628 * @widget: the object which received the signal
2629 * @context: the drag context
2631 * The ::drag-begin signal is emitted on the drag source when a drag is
2632 * started. A typical reason to connect to this signal is to set up a
2633 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2635 * Note that some widgets set up a drag icon in the default handler of
2636 * this signal, so you may have to use g_signal_connect_after() to
2637 * override what the default handler did.
2639 widget_signals[DRAG_BEGIN] =
2640 g_signal_new (I_("drag-begin"),
2641 G_TYPE_FROM_CLASS (klass),
2643 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2645 _gtk_marshal_VOID__OBJECT,
2647 GDK_TYPE_DRAG_CONTEXT);
2650 * GtkWidget::drag-end:
2651 * @widget: the object which received the signal
2652 * @context: the drag context
2654 * The ::drag-end signal is emitted on the drag source when a drag is
2655 * finished. A typical reason to connect to this signal is to undo
2656 * things done in #GtkWidget::drag-begin.
2658 widget_signals[DRAG_END] =
2659 g_signal_new (I_("drag-end"),
2660 G_TYPE_FROM_CLASS (klass),
2662 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2664 _gtk_marshal_VOID__OBJECT,
2666 GDK_TYPE_DRAG_CONTEXT);
2669 * GtkWidget::drag-data-delete:
2670 * @widget: the object which received the signal
2671 * @context: the drag context
2673 * The ::drag-data-delete signal is emitted on the drag source when a drag
2674 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2675 * handler is responsible for deleting the data that has been dropped. What
2676 * "delete" means depends on the context of the drag operation.
2678 widget_signals[DRAG_DATA_DELETE] =
2679 g_signal_new (I_("drag-data-delete"),
2680 G_TYPE_FROM_CLASS (klass),
2682 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2684 _gtk_marshal_VOID__OBJECT,
2686 GDK_TYPE_DRAG_CONTEXT);
2689 * GtkWidget::drag-failed:
2690 * @widget: the object which received the signal
2691 * @context: the drag context
2692 * @result: the result of the drag operation
2694 * The ::drag-failed signal is emitted on the drag source when a drag has
2695 * failed. The signal handler may hook custom code to handle a failed DND
2696 * operation based on the type of error, it returns %TRUE is the failure has
2697 * been already handled (not showing the default "drag operation failed"
2698 * animation), otherwise it returns %FALSE.
2700 * Return value: %TRUE if the failed drag operation has been already handled.
2704 widget_signals[DRAG_FAILED] =
2705 g_signal_new (I_("drag-failed"),
2706 G_TYPE_FROM_CLASS (klass),
2708 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2709 _gtk_boolean_handled_accumulator, NULL,
2710 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2712 GDK_TYPE_DRAG_CONTEXT,
2713 GTK_TYPE_DRAG_RESULT);
2716 * GtkWidget::drag-motion:
2717 * @widget: the object which received the signal
2718 * @context: the drag context
2719 * @x: the x coordinate of the current cursor position
2720 * @y: the y coordinate of the current cursor position
2721 * @time: the timestamp of the motion event
2723 * The ::drag-motion signal is emitted on the drop site when the user
2724 * moves the cursor over the widget during a drag. The signal handler
2725 * must determine whether the cursor position is in a drop zone or not.
2726 * If it is not in a drop zone, it returns %FALSE and no further processing
2727 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2728 * handler is responsible for providing the necessary information for
2729 * displaying feedback to the user, by calling gdk_drag_status().
2731 * If the decision whether the drop will be accepted or rejected can't be
2732 * made based solely on the cursor position and the type of the data, the
2733 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2734 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2735 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2736 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2737 * when using the drag-motion signal that way.
2739 * Also note that there is no drag-enter signal. The drag receiver has to
2740 * keep track of whether he has received any drag-motion signals since the
2741 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2742 * an "enter" signal. Upon an "enter", the handler will typically highlight
2743 * the drop site with gtk_drag_highlight().
2746 * drag_motion (GtkWidget *widget,
2747 * GdkDragContext *context,
2754 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2756 * if (!private_data->drag_highlight)
2758 * private_data->drag_highlight = 1;
2759 * gtk_drag_highlight (widget);
2762 * target = gtk_drag_dest_find_target (widget, context, NULL);
2763 * if (target == GDK_NONE)
2764 * gdk_drag_status (context, 0, time);
2767 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2768 * gtk_drag_get_data (widget, context, target, time);
2775 * drag_data_received (GtkWidget *widget,
2776 * GdkDragContext *context,
2779 * GtkSelectionData *selection_data,
2783 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2785 * if (private_data->suggested_action)
2787 * private_data->suggested_action = 0;
2789 * /* We are getting this data due to a request in drag_motion,
2790 * * rather than due to a request in drag_drop, so we are just
2791 * * supposed to call gdk_drag_status(), not actually paste in
2794 * str = gtk_selection_data_get_text (selection_data);
2795 * if (!data_is_acceptable (str))
2796 * gdk_drag_status (context, 0, time);
2798 * gdk_drag_status (context, private_data->suggested_action, time);
2802 * /* accept the drop */
2807 * Returns: whether the cursor position is in a drop zone
2809 widget_signals[DRAG_MOTION] =
2810 g_signal_new (I_("drag-motion"),
2811 G_TYPE_FROM_CLASS (klass),
2813 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2814 _gtk_boolean_handled_accumulator, NULL,
2815 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2817 GDK_TYPE_DRAG_CONTEXT,
2823 * GtkWidget::drag-drop:
2824 * @widget: the object which received the signal
2825 * @context: the drag context
2826 * @x: the x coordinate of the current cursor position
2827 * @y: the y coordinate of the current cursor position
2828 * @time: the timestamp of the motion event
2830 * The ::drag-drop signal is emitted on the drop site when the user drops
2831 * the data onto the widget. The signal handler must determine whether
2832 * the cursor position is in a drop zone or not. If it is not in a drop
2833 * zone, it returns %FALSE and no further processing is necessary.
2834 * Otherwise, the handler returns %TRUE. In this case, the handler must
2835 * ensure that gtk_drag_finish() is called to let the source know that
2836 * the drop is done. The call to gtk_drag_finish() can be done either
2837 * directly or in a #GtkWidget::drag-data-received handler which gets
2838 * triggered by calling gtk_drag_get_data() to receive the data for one
2839 * or more of the supported targets.
2841 * Returns: whether the cursor position is in a drop zone
2843 widget_signals[DRAG_DROP] =
2844 g_signal_new (I_("drag-drop"),
2845 G_TYPE_FROM_CLASS (klass),
2847 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2848 _gtk_boolean_handled_accumulator, NULL,
2849 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2851 GDK_TYPE_DRAG_CONTEXT,
2857 * GtkWidget::drag-data-get:
2858 * @widget: the object which received the signal
2859 * @context: the drag context
2860 * @data: the #GtkSelectionData to be filled with the dragged data
2861 * @info: the info that has been registered with the target in the
2863 * @time: the timestamp at which the data was requested
2865 * The ::drag-data-get signal is emitted on the drag source when the drop
2866 * site requests the data which is dragged. It is the responsibility of
2867 * the signal handler to fill @data with the data in the format which
2868 * is indicated by @info. See gtk_selection_data_set() and
2869 * gtk_selection_data_set_text().
2871 widget_signals[DRAG_DATA_GET] =
2872 g_signal_new (I_("drag-data-get"),
2873 G_TYPE_FROM_CLASS (klass),
2875 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2877 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2879 GDK_TYPE_DRAG_CONTEXT,
2880 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2885 * GtkWidget::drag-data-received:
2886 * @widget: the object which received the signal
2887 * @context: the drag context
2888 * @x: where the drop happened
2889 * @y: where the drop happened
2890 * @data: the received data
2891 * @info: the info that has been registered with the target in the
2893 * @time: the timestamp at which the data was received
2895 * The ::drag-data-received signal is emitted on the drop site when the
2896 * dragged data has been received. If the data was received in order to
2897 * determine whether the drop will be accepted, the handler is expected
2898 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2899 * If the data was received in response to a #GtkWidget::drag-drop signal
2900 * (and this is the last target to be received), the handler for this
2901 * signal is expected to process the received data and then call
2902 * gtk_drag_finish(), setting the @success parameter depending on
2903 * whether the data was processed successfully.
2905 * The handler may inspect the selected action with
2906 * gdk_drag_context_get_selected_action() before calling
2907 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2908 * shown in the following example:
2911 * drag_data_received (GtkWidget *widget,
2912 * GdkDragContext *context,
2915 * GtkSelectionData *data,
2919 * if ((data->length >= 0) && (data->format == 8))
2921 * GdkDragAction action;
2923 * /* handle data here */
2925 * action = gdk_drag_context_get_selected_action (context);
2926 * if (action == GDK_ACTION_ASK)
2928 * GtkWidget *dialog;
2931 * dialog = gtk_message_dialog_new (NULL,
2932 * GTK_DIALOG_MODAL |
2933 * GTK_DIALOG_DESTROY_WITH_PARENT,
2935 * GTK_BUTTONS_YES_NO,
2936 * "Move the data ?\n");
2937 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2938 * gtk_widget_destroy (dialog);
2940 * if (response == GTK_RESPONSE_YES)
2941 * action = GDK_ACTION_MOVE;
2943 * action = GDK_ACTION_COPY;
2946 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2949 * gtk_drag_finish (context, FALSE, FALSE, time);
2953 widget_signals[DRAG_DATA_RECEIVED] =
2954 g_signal_new (I_("drag-data-received"),
2955 G_TYPE_FROM_CLASS (klass),
2957 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2959 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2961 GDK_TYPE_DRAG_CONTEXT,
2964 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2969 * GtkWidget::visibility-notify-event:
2970 * @widget: the object which received the signal
2971 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2972 * triggered this signal.
2974 * The ::visibility-notify-event will be emitted when the @widget's window
2975 * is obscured or unobscured.
2977 * To receive this signal the #GdkWindow associated to the widget needs
2978 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2980 * Returns: %TRUE to stop other handlers from being invoked for the event.
2981 * %FALSE to propagate the event further.
2983 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2984 g_signal_new (I_("visibility-notify-event"),
2985 G_TYPE_FROM_CLASS (klass),
2987 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2988 _gtk_boolean_handled_accumulator, NULL,
2989 _gtk_marshal_BOOLEAN__BOXED,
2991 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2994 * GtkWidget::window-state-event:
2995 * @widget: the object which received the signal
2996 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2997 * triggered this signal.
2999 * The ::window-state-event will be emitted when the state of the
3000 * toplevel window associated to the @widget changes.
3002 * To receive this signal the #GdkWindow associated to the widget
3003 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
3004 * this mask automatically for all new windows.
3006 * Returns: %TRUE to stop other handlers from being invoked for the
3007 * event. %FALSE to propagate the event further.
3009 widget_signals[WINDOW_STATE_EVENT] =
3010 g_signal_new (I_("window-state-event"),
3011 G_TYPE_FROM_CLASS (klass),
3013 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
3014 _gtk_boolean_handled_accumulator, NULL,
3015 _gtk_marshal_BOOLEAN__BOXED,
3017 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3018 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3019 _gtk_marshal_BOOLEAN__BOXEDv);
3022 * GtkWidget::damage-event:
3023 * @widget: the object which received the signal
3024 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3026 * Emitted when a redirected window belonging to @widget gets drawn into.
3027 * The region/area members of the event shows what area of the redirected
3028 * drawable was drawn into.
3030 * Returns: %TRUE to stop other handlers from being invoked for the event.
3031 * %FALSE to propagate the event further.
3035 widget_signals[DAMAGE_EVENT] =
3036 g_signal_new (I_("damage-event"),
3037 G_TYPE_FROM_CLASS (klass),
3039 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3040 _gtk_boolean_handled_accumulator, NULL,
3041 _gtk_marshal_BOOLEAN__BOXED,
3043 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3044 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3045 _gtk_marshal_BOOLEAN__BOXEDv);
3048 * GtkWidget::grab-broken-event:
3049 * @widget: the object which received the signal
3050 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3052 * Emitted when a pointer or keyboard grab on a window belonging
3053 * to @widget gets broken.
3055 * On X11, this happens when the grab window becomes unviewable
3056 * (i.e. it or one of its ancestors is unmapped), or if the same
3057 * application grabs the pointer or keyboard again.
3059 * Returns: %TRUE to stop other handlers from being invoked for
3060 * the event. %FALSE to propagate the event further.
3064 widget_signals[GRAB_BROKEN_EVENT] =
3065 g_signal_new (I_("grab-broken-event"),
3066 G_TYPE_FROM_CLASS (klass),
3068 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3069 _gtk_boolean_handled_accumulator, NULL,
3070 _gtk_marshal_BOOLEAN__BOXED,
3072 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3073 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3074 _gtk_marshal_BOOLEAN__BOXEDv);
3077 * GtkWidget::query-tooltip:
3078 * @widget: the object which received the signal
3079 * @x: the x coordinate of the cursor position where the request has
3080 * been emitted, relative to @widget's left side
3081 * @y: the y coordinate of the cursor position where the request has
3082 * been emitted, relative to @widget's top
3083 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3084 * @tooltip: a #GtkTooltip
3086 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3087 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3088 * focus in keyboard mode.
3090 * Using the given coordinates, the signal handler should determine
3091 * whether a tooltip should be shown for @widget. If this is the case
3092 * %TRUE should be returned, %FALSE otherwise. Note that if
3093 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3094 * should not be used.
3096 * The signal handler is free to manipulate @tooltip with the therefore
3097 * destined function calls.
3099 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3103 widget_signals[QUERY_TOOLTIP] =
3104 g_signal_new (I_("query-tooltip"),
3105 G_TYPE_FROM_CLASS (klass),
3107 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3108 _gtk_boolean_handled_accumulator, NULL,
3109 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3117 * GtkWidget::popup-menu:
3118 * @widget: the object which received the signal
3120 * This signal gets emitted whenever a widget should pop up a context
3121 * menu. This usually happens through the standard key binding mechanism;
3122 * by pressing a certain key while a widget is focused, the user can cause
3123 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3124 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3125 * for an example of how to use this signal.
3127 * Returns: %TRUE if a menu was activated
3129 widget_signals[POPUP_MENU] =
3130 g_signal_new (I_("popup-menu"),
3131 G_TYPE_FROM_CLASS (klass),
3132 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3133 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3134 _gtk_boolean_handled_accumulator, NULL,
3135 _gtk_marshal_BOOLEAN__VOID,
3139 * GtkWidget::show-help:
3140 * @widget: the object which received the signal.
3143 * Returns: %TRUE to stop other handlers from being invoked for the event.
3144 * %FALSE to propagate the event further.
3146 widget_signals[SHOW_HELP] =
3147 g_signal_new (I_("show-help"),
3148 G_TYPE_FROM_CLASS (klass),
3149 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3150 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3151 _gtk_boolean_handled_accumulator, NULL,
3152 _gtk_marshal_BOOLEAN__ENUM,
3154 GTK_TYPE_WIDGET_HELP_TYPE);
3157 * GtkWidget::accel-closures-changed:
3158 * @widget: the object which received the signal.
3160 widget_signals[ACCEL_CLOSURES_CHANGED] =
3161 g_signal_new (I_("accel-closures-changed"),
3162 G_TYPE_FROM_CLASS (klass),
3166 _gtk_marshal_VOID__VOID,
3170 * GtkWidget::screen-changed:
3171 * @widget: the object on which the signal is emitted
3172 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3173 * widget was not associated with a screen before
3175 * The ::screen-changed signal gets emitted when the
3176 * screen of a widget has changed.
3178 widget_signals[SCREEN_CHANGED] =
3179 g_signal_new (I_("screen-changed"),
3180 G_TYPE_FROM_CLASS (klass),
3182 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3184 _gtk_marshal_VOID__OBJECT,
3189 * GtkWidget::can-activate-accel:
3190 * @widget: the object which received the signal
3191 * @signal_id: the ID of a signal installed on @widget
3193 * Determines whether an accelerator that activates the signal
3194 * identified by @signal_id can currently be activated.
3195 * This signal is present to allow applications and derived
3196 * widgets to override the default #GtkWidget handling
3197 * for determining whether an accelerator can be activated.
3199 * Returns: %TRUE if the signal can be activated.
3201 widget_signals[CAN_ACTIVATE_ACCEL] =
3202 g_signal_new (I_("can-activate-accel"),
3203 G_TYPE_FROM_CLASS (klass),
3205 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3206 _gtk_boolean_handled_accumulator, NULL,
3207 _gtk_marshal_BOOLEAN__UINT,
3208 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3210 binding_set = gtk_binding_set_by_class (klass);
3211 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3213 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3216 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3218 GTK_TYPE_WIDGET_HELP_TYPE,
3219 GTK_WIDGET_HELP_TOOLTIP);
3220 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3222 GTK_TYPE_WIDGET_HELP_TYPE,
3223 GTK_WIDGET_HELP_TOOLTIP);
3224 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3226 GTK_TYPE_WIDGET_HELP_TYPE,
3227 GTK_WIDGET_HELP_WHATS_THIS);
3228 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3230 GTK_TYPE_WIDGET_HELP_TYPE,
3231 GTK_WIDGET_HELP_WHATS_THIS);
3233 gtk_widget_class_install_style_property (klass,
3234 g_param_spec_boolean ("interior-focus",
3235 P_("Interior Focus"),
3236 P_("Whether to draw the focus indicator inside widgets"),
3238 GTK_PARAM_READABLE));
3240 gtk_widget_class_install_style_property (klass,
3241 g_param_spec_int ("focus-line-width",
3242 P_("Focus linewidth"),
3243 P_("Width, in pixels, of the focus indicator line"),
3245 GTK_PARAM_READABLE));
3247 gtk_widget_class_install_style_property (klass,
3248 g_param_spec_string ("focus-line-pattern",
3249 P_("Focus line dash pattern"),
3250 P_("Dash pattern used to draw the focus indicator"),
3252 GTK_PARAM_READABLE));
3253 gtk_widget_class_install_style_property (klass,
3254 g_param_spec_int ("focus-padding",
3255 P_("Focus padding"),
3256 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3258 GTK_PARAM_READABLE));
3259 gtk_widget_class_install_style_property (klass,
3260 g_param_spec_boxed ("cursor-color",
3262 P_("Color with which to draw insertion cursor"),
3264 GTK_PARAM_READABLE));
3265 gtk_widget_class_install_style_property (klass,
3266 g_param_spec_boxed ("secondary-cursor-color",
3267 P_("Secondary cursor color"),
3268 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3270 GTK_PARAM_READABLE));
3271 gtk_widget_class_install_style_property (klass,
3272 g_param_spec_float ("cursor-aspect-ratio",
3273 P_("Cursor line aspect ratio"),
3274 P_("Aspect ratio with which to draw insertion cursor"),
3276 GTK_PARAM_READABLE));
3278 gtk_widget_class_install_style_property (klass,
3279 g_param_spec_boolean ("window-dragging",
3280 P_("Window dragging"),
3281 P_("Whether windows can be dragged by clicking on empty areas"),
3283 GTK_PARAM_READABLE));
3286 * GtkWidget:link-color:
3288 * The "link-color" style property defines the color of unvisited links.
3292 gtk_widget_class_install_style_property (klass,
3293 g_param_spec_boxed ("link-color",
3294 P_("Unvisited Link Color"),
3295 P_("Color of unvisited links"),
3297 GTK_PARAM_READABLE));
3300 * GtkWidget:visited-link-color:
3302 * The "visited-link-color" style property defines the color of visited links.
3306 gtk_widget_class_install_style_property (klass,
3307 g_param_spec_boxed ("visited-link-color",
3308 P_("Visited Link Color"),
3309 P_("Color of visited links"),
3311 GTK_PARAM_READABLE));
3314 * GtkWidget:wide-separators:
3316 * The "wide-separators" style property defines whether separators have
3317 * configurable width and should be drawn using a box instead of a line.
3321 gtk_widget_class_install_style_property (klass,
3322 g_param_spec_boolean ("wide-separators",
3323 P_("Wide Separators"),
3324 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3326 GTK_PARAM_READABLE));
3329 * GtkWidget:separator-width:
3331 * The "separator-width" style property defines the width of separators.
3332 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3336 gtk_widget_class_install_style_property (klass,
3337 g_param_spec_int ("separator-width",
3338 P_("Separator Width"),
3339 P_("The width of separators if wide-separators is TRUE"),
3341 GTK_PARAM_READABLE));
3344 * GtkWidget:separator-height:
3346 * The "separator-height" style property defines the height of separators.
3347 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3351 gtk_widget_class_install_style_property (klass,
3352 g_param_spec_int ("separator-height",
3353 P_("Separator Height"),
3354 P_("The height of separators if \"wide-separators\" is TRUE"),
3356 GTK_PARAM_READABLE));
3359 * GtkWidget:scroll-arrow-hlength:
3361 * The "scroll-arrow-hlength" style property defines the length of
3362 * horizontal scroll arrows.
3366 gtk_widget_class_install_style_property (klass,
3367 g_param_spec_int ("scroll-arrow-hlength",
3368 P_("Horizontal Scroll Arrow Length"),
3369 P_("The length of horizontal scroll arrows"),
3371 GTK_PARAM_READABLE));
3374 * GtkWidget:scroll-arrow-vlength:
3376 * The "scroll-arrow-vlength" style property defines the length of
3377 * vertical scroll arrows.
3381 gtk_widget_class_install_style_property (klass,
3382 g_param_spec_int ("scroll-arrow-vlength",
3383 P_("Vertical Scroll Arrow Length"),
3384 P_("The length of vertical scroll arrows"),
3386 GTK_PARAM_READABLE));
3388 gtk_widget_class_install_style_property (klass,
3389 g_param_spec_int ("text-handle-width",
3390 P_("Width of text selection handles"),
3391 P_("Width of text selection handles"),
3393 GTK_PARAM_READABLE));
3394 gtk_widget_class_install_style_property (klass,
3395 g_param_spec_int ("text-handle-height",
3396 P_("Height of text selection handles"),
3397 P_("Height of text selection handles"),
3399 GTK_PARAM_READABLE));
3401 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3403 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3407 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3411 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3412 for (node = list; node; node = node->next)
3414 GParamSpec *pspec = node->data;
3416 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3417 g_param_spec_unref (pspec);
3423 gtk_widget_set_property (GObject *object,
3425 const GValue *value,
3428 GtkWidget *widget = GTK_WIDGET (object);
3433 gchar *tooltip_markup;
3434 const gchar *tooltip_text;
3435 GtkWindow *tooltip_window;
3438 gtk_widget_set_name (widget, g_value_get_string (value));
3441 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3443 case PROP_WIDTH_REQUEST:
3444 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3446 case PROP_HEIGHT_REQUEST:
3447 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3450 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3452 case PROP_SENSITIVE:
3453 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3455 case PROP_APP_PAINTABLE:
3456 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3458 case PROP_CAN_FOCUS:
3459 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3461 case PROP_HAS_FOCUS:
3462 if (g_value_get_boolean (value))
3463 gtk_widget_grab_focus (widget);
3466 if (g_value_get_boolean (value))
3467 gtk_widget_grab_focus (widget);
3469 case PROP_CAN_DEFAULT:
3470 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3472 case PROP_HAS_DEFAULT:
3473 if (g_value_get_boolean (value))
3474 gtk_widget_grab_default (widget);
3476 case PROP_RECEIVES_DEFAULT:
3477 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3480 gtk_widget_set_style (widget, g_value_get_object (value));
3483 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3484 gtk_widget_set_events (widget, g_value_get_flags (value));
3486 case PROP_NO_SHOW_ALL:
3487 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3489 case PROP_HAS_TOOLTIP:
3490 gtk_widget_real_set_has_tooltip (widget,
3491 g_value_get_boolean (value), FALSE);
3493 case PROP_TOOLTIP_MARKUP:
3494 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3495 tooltip_markup = g_value_dup_string (value);
3497 /* Treat an empty string as a NULL string,
3498 * because an empty string would be useless for a tooltip:
3500 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3502 g_free (tooltip_markup);
3503 tooltip_markup = NULL;
3506 g_object_set_qdata_full (object, quark_tooltip_markup,
3507 tooltip_markup, g_free);
3509 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3510 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3511 if (gtk_widget_get_visible (widget))
3512 gtk_widget_queue_tooltip_query (widget);
3514 case PROP_TOOLTIP_TEXT:
3515 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3517 tooltip_text = g_value_get_string (value);
3519 /* Treat an empty string as a NULL string,
3520 * because an empty string would be useless for a tooltip:
3522 if (tooltip_text && (strlen (tooltip_text) == 0))
3523 tooltip_text = NULL;
3525 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3527 g_object_set_qdata_full (object, quark_tooltip_markup,
3528 tooltip_markup, g_free);
3530 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3531 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3532 if (gtk_widget_get_visible (widget))
3533 gtk_widget_queue_tooltip_query (widget);
3535 case PROP_DOUBLE_BUFFERED:
3536 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3539 gtk_widget_set_halign (widget, g_value_get_enum (value));
3542 gtk_widget_set_valign (widget, g_value_get_enum (value));
3544 case PROP_MARGIN_LEFT:
3545 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3547 case PROP_MARGIN_RIGHT:
3548 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3550 case PROP_MARGIN_TOP:
3551 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3553 case PROP_MARGIN_BOTTOM:
3554 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3557 g_object_freeze_notify (G_OBJECT (widget));
3558 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3559 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3560 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3561 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3562 g_object_thaw_notify (G_OBJECT (widget));
3565 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3567 case PROP_HEXPAND_SET:
3568 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3571 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3573 case PROP_VEXPAND_SET:
3574 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3577 g_object_freeze_notify (G_OBJECT (widget));
3578 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3579 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3580 g_object_thaw_notify (G_OBJECT (widget));
3583 gtk_widget_set_opacity (widget, g_value_get_double (value));
3586 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3592 gtk_widget_get_property (GObject *object,
3597 GtkWidget *widget = GTK_WIDGET (object);
3598 GtkWidgetPrivate *priv = widget->priv;
3606 g_value_set_string (value, priv->name);
3608 g_value_set_static_string (value, "");
3611 g_value_set_object (value, priv->parent);
3613 case PROP_WIDTH_REQUEST:
3616 gtk_widget_get_size_request (widget, &w, NULL);
3617 g_value_set_int (value, w);
3620 case PROP_HEIGHT_REQUEST:
3623 gtk_widget_get_size_request (widget, NULL, &h);
3624 g_value_set_int (value, h);
3628 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3630 case PROP_SENSITIVE:
3631 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3633 case PROP_APP_PAINTABLE:
3634 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3636 case PROP_CAN_FOCUS:
3637 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3639 case PROP_HAS_FOCUS:
3640 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3643 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3645 case PROP_CAN_DEFAULT:
3646 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3648 case PROP_HAS_DEFAULT:
3649 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3651 case PROP_RECEIVES_DEFAULT:
3652 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3654 case PROP_COMPOSITE_CHILD:
3655 g_value_set_boolean (value, widget->priv->composite_child);
3658 g_value_set_object (value, gtk_widget_get_style (widget));
3661 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3662 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3664 case PROP_NO_SHOW_ALL:
3665 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3667 case PROP_HAS_TOOLTIP:
3668 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3670 case PROP_TOOLTIP_TEXT:
3672 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3675 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3676 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3678 g_value_take_string (value, text);
3681 case PROP_TOOLTIP_MARKUP:
3682 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3685 g_value_set_object (value, gtk_widget_get_window (widget));
3687 case PROP_DOUBLE_BUFFERED:
3688 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3691 g_value_set_enum (value, gtk_widget_get_halign (widget));
3694 g_value_set_enum (value, gtk_widget_get_valign (widget));
3696 case PROP_MARGIN_LEFT:
3697 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3699 case PROP_MARGIN_RIGHT:
3700 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3702 case PROP_MARGIN_TOP:
3703 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3705 case PROP_MARGIN_BOTTOM:
3706 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3710 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3711 if (aux_info == NULL)
3713 g_value_set_int (value, 0);
3717 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3718 aux_info->margin.right),
3719 MAX (aux_info->margin.top,
3720 aux_info->margin.bottom)));
3725 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3727 case PROP_HEXPAND_SET:
3728 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3731 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3733 case PROP_VEXPAND_SET:
3734 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3737 g_value_set_boolean (value,
3738 gtk_widget_get_hexpand (widget) &&
3739 gtk_widget_get_vexpand (widget));
3742 g_value_set_double (value, gtk_widget_get_opacity (widget));
3745 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3751 gtk_widget_init (GtkWidget *widget)
3753 GtkWidgetPrivate *priv;
3755 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3758 priv = widget->priv;
3760 priv->child_visible = TRUE;
3762 priv->allocation.x = -1;
3763 priv->allocation.y = -1;
3764 priv->allocation.width = 1;
3765 priv->allocation.height = 1;
3766 priv->user_alpha = 255;
3768 priv->window = NULL;
3769 priv->parent = NULL;
3771 priv->sensitive = TRUE;
3772 priv->composite_child = composite_child_stack != 0;
3773 priv->double_buffered = TRUE;
3774 priv->redraw_on_alloc = TRUE;
3775 priv->alloc_needed = TRUE;
3777 switch (gtk_widget_get_direction (widget))
3779 case GTK_TEXT_DIR_LTR:
3780 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3783 case GTK_TEXT_DIR_RTL:
3784 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3787 case GTK_TEXT_DIR_NONE:
3789 g_assert_not_reached ();
3794 /* this will be set to TRUE if the widget gets a child or if the
3795 * expand flag is set on the widget, but until one of those happen
3796 * we know the expand is already properly FALSE.
3798 * We really want to default FALSE here to avoid computing expand
3799 * all over the place while initially building a widget tree.
3801 priv->need_compute_expand = FALSE;
3803 _gtk_size_request_cache_init (&priv->requests);
3805 priv->style = gtk_widget_get_default_style ();
3806 g_object_ref (priv->style);
3811 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3813 GParamSpec **pspecs)
3815 GtkWidgetPrivate *priv = widget->priv;
3816 GtkWidget *container = priv->parent;
3819 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3820 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3824 * gtk_widget_freeze_child_notify:
3825 * @widget: a #GtkWidget
3827 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3828 * signals are queued until gtk_widget_thaw_child_notify() is called
3831 * This is the analogue of g_object_freeze_notify() for child properties.
3834 gtk_widget_freeze_child_notify (GtkWidget *widget)
3836 g_return_if_fail (GTK_IS_WIDGET (widget));
3838 if (!G_OBJECT (widget)->ref_count)
3841 g_object_ref (widget);
3842 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3843 g_object_unref (widget);
3847 * gtk_widget_child_notify:
3848 * @widget: a #GtkWidget
3849 * @child_property: the name of a child property installed on the
3850 * class of @widget<!-- -->'s parent
3852 * Emits a #GtkWidget::child-notify signal for the
3853 * <link linkend="child-properties">child property</link> @child_property
3856 * This is the analogue of g_object_notify() for child properties.
3858 * Also see gtk_container_child_notify().
3861 gtk_widget_child_notify (GtkWidget *widget,
3862 const gchar *child_property)
3864 if (widget->priv->parent == NULL)
3867 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3871 * gtk_widget_thaw_child_notify:
3872 * @widget: a #GtkWidget
3874 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3875 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3879 gtk_widget_thaw_child_notify (GtkWidget *widget)
3881 GObjectNotifyQueue *nqueue;
3883 g_return_if_fail (GTK_IS_WIDGET (widget));
3885 if (!G_OBJECT (widget)->ref_count)
3888 g_object_ref (widget);
3889 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3890 if (!nqueue || !nqueue->freeze_count)
3891 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3892 G_OBJECT_TYPE_NAME (widget), widget);
3894 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3895 g_object_unref (widget);
3901 * @type: type ID of the widget to create
3902 * @first_property_name: name of first property to set
3903 * @...: value of first property, followed by more properties,
3906 * This is a convenience function for creating a widget and setting
3907 * its properties in one go. For example you might write:
3908 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3909 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3910 * g_object_new(), but returns a widget so you don't have to
3911 * cast the object yourself.
3913 * Return value: a new #GtkWidget of type @widget_type
3916 gtk_widget_new (GType type,
3917 const gchar *first_property_name,
3923 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3925 va_start (var_args, first_property_name);
3926 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3933 gtk_widget_queue_draw_child (GtkWidget *widget)
3935 GtkWidgetPrivate *priv = widget->priv;
3938 parent = priv->parent;
3939 if (parent && gtk_widget_is_drawable (parent))
3940 gtk_widget_queue_draw_area (parent,
3943 priv->allocation.width,
3944 priv->allocation.height);
3948 * gtk_widget_unparent:
3949 * @widget: a #GtkWidget
3951 * This function is only for use in widget implementations.
3952 * Should be called by implementations of the remove method
3953 * on #GtkContainer, to dissociate a child from the container.
3956 gtk_widget_unparent (GtkWidget *widget)
3958 GtkWidgetPrivate *priv;
3959 GObjectNotifyQueue *nqueue;
3960 GtkWidget *toplevel;
3961 GtkWidget *old_parent;
3963 g_return_if_fail (GTK_IS_WIDGET (widget));
3965 priv = widget->priv;
3967 if (priv->parent == NULL)
3970 /* keep this function in sync with gtk_menu_detach() */
3972 gtk_widget_push_verify_invariants (widget);
3974 g_object_freeze_notify (G_OBJECT (widget));
3975 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3977 toplevel = gtk_widget_get_toplevel (widget);
3978 if (gtk_widget_is_toplevel (toplevel))
3979 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3981 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3982 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3984 gtk_widget_queue_draw_child (widget);
3986 /* Reset the width and height here, to force reallocation if we
3987 * get added back to a new parent. This won't work if our new
3988 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3989 * (would 0x0 be OK here?)
3991 priv->allocation.width = 1;
3992 priv->allocation.height = 1;
3994 if (gtk_widget_get_realized (widget))
3996 if (priv->in_reparent)
3997 gtk_widget_unmap (widget);
3999 gtk_widget_unrealize (widget);
4002 /* If we are unanchoring the child, we save around the toplevel
4003 * to emit hierarchy changed
4005 if (priv->parent->priv->anchored)
4006 g_object_ref (toplevel);
4010 /* Removing a widget from a container restores the child visible
4011 * flag to the default state, so it doesn't affect the child
4012 * in the next parent.
4014 priv->child_visible = TRUE;
4016 old_parent = priv->parent;
4017 priv->parent = NULL;
4019 /* parent may no longer expand if the removed
4020 * child was expand=TRUE and could therefore
4023 if (gtk_widget_get_visible (widget) &&
4024 (priv->need_compute_expand ||
4025 priv->computed_hexpand ||
4026 priv->computed_vexpand))
4028 gtk_widget_queue_compute_expand (old_parent);
4031 /* Unset BACKDROP since we are no longer inside a toplevel window */
4032 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4034 gtk_style_context_set_parent (priv->context, NULL);
4036 _gtk_widget_update_parent_muxer (widget);
4038 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4041 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4042 g_object_unref (toplevel);
4045 /* Now that the parent pointer is nullified and the hierarchy-changed
4046 * already passed, go ahead and unset the parent window, if we are unparenting
4047 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4048 * will fire again for the new subhierarchy.
4050 gtk_widget_set_parent_window (widget, NULL);
4052 g_object_notify (G_OBJECT (widget), "parent");
4053 g_object_thaw_notify (G_OBJECT (widget));
4055 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4056 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4058 gtk_widget_propagate_alpha (widget);
4060 gtk_widget_pop_verify_invariants (widget);
4061 g_object_unref (widget);
4065 * gtk_widget_destroy:
4066 * @widget: a #GtkWidget
4068 * Destroys a widget.
4071 * destroyed, it will break any references it holds to other objects.
4072 * If the widget is inside a container, the widget will be removed
4073 * from the container. If the widget is a toplevel (derived from
4074 * #GtkWindow), it will be removed from the list of toplevels, and the
4075 * reference GTK+ holds to it will be removed. Removing a
4076 * widget from its container or the list of toplevels results in the
4077 * widget being finalized, unless you've added additional references
4078 * to the widget with g_object_ref().
4080 * In most cases, only toplevel widgets (windows) require explicit
4081 * destruction, because when you destroy a toplevel its children will
4082 * be destroyed as well.
4085 gtk_widget_destroy (GtkWidget *widget)
4087 g_return_if_fail (GTK_IS_WIDGET (widget));
4089 if (!widget->priv->in_destruction)
4090 g_object_run_dispose (G_OBJECT (widget));
4094 * gtk_widget_destroyed:
4095 * @widget: a #GtkWidget
4096 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4098 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4099 * %NULL. It's intended to be used as a callback connected to the
4100 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4101 * as a signal handler, and pass the address of your widget variable
4102 * as user data. Then when the widget is destroyed, the variable will
4103 * be set to %NULL. Useful for example to avoid multiple copies
4104 * of the same dialog.
4107 gtk_widget_destroyed (GtkWidget *widget,
4108 GtkWidget **widget_pointer)
4110 /* Don't make any assumptions about the
4112 * Even check widget_pointer.
4115 *widget_pointer = NULL;
4120 * @widget: a #GtkWidget
4122 * Flags a widget to be displayed. Any widget that isn't shown will
4123 * not appear on the screen. If you want to show all the widgets in a
4124 * container, it's easier to call gtk_widget_show_all() on the
4125 * container, instead of individually showing the widgets.
4127 * Remember that you have to show the containers containing a widget,
4128 * in addition to the widget itself, before it will appear onscreen.
4130 * When a toplevel container is shown, it is immediately realized and
4131 * mapped; other shown widgets are realized and mapped when their
4132 * toplevel container is realized and mapped.
4135 gtk_widget_show (GtkWidget *widget)
4137 g_return_if_fail (GTK_IS_WIDGET (widget));
4139 if (!gtk_widget_get_visible (widget))
4141 g_object_ref (widget);
4142 gtk_widget_push_verify_invariants (widget);
4144 if (!gtk_widget_is_toplevel (widget))
4145 gtk_widget_queue_resize (widget);
4147 /* see comment in set_parent() for why this should and can be
4150 if (widget->priv->need_compute_expand ||
4151 widget->priv->computed_hexpand ||
4152 widget->priv->computed_vexpand)
4154 if (widget->priv->parent != NULL)
4155 gtk_widget_queue_compute_expand (widget->priv->parent);
4158 g_signal_emit (widget, widget_signals[SHOW], 0);
4159 g_object_notify (G_OBJECT (widget), "visible");
4161 gtk_widget_pop_verify_invariants (widget);
4162 g_object_unref (widget);
4167 gtk_widget_real_show (GtkWidget *widget)
4169 GtkWidgetPrivate *priv = widget->priv;
4171 if (!gtk_widget_get_visible (widget))
4173 priv->visible = TRUE;
4176 gtk_widget_get_mapped (priv->parent) &&
4177 gtk_widget_get_child_visible (widget) &&
4178 !gtk_widget_get_mapped (widget))
4179 gtk_widget_map (widget);
4184 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4187 g_signal_handlers_disconnect_by_func (widget,
4188 gtk_widget_show_map_callback,
4193 * gtk_widget_show_now:
4194 * @widget: a #GtkWidget
4196 * Shows a widget. If the widget is an unmapped toplevel widget
4197 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4198 * loop and wait for the window to actually be mapped. Be careful;
4199 * because the main loop is running, anything can happen during
4203 gtk_widget_show_now (GtkWidget *widget)
4207 g_return_if_fail (GTK_IS_WIDGET (widget));
4209 /* make sure we will get event */
4210 if (!gtk_widget_get_mapped (widget) &&
4211 gtk_widget_is_toplevel (widget))
4213 gtk_widget_show (widget);
4215 g_signal_connect (widget, "map-event",
4216 G_CALLBACK (gtk_widget_show_map_callback),
4220 gtk_main_iteration ();
4223 gtk_widget_show (widget);
4228 * @widget: a #GtkWidget
4230 * Reverses the effects of gtk_widget_show(), causing the widget to be
4231 * hidden (invisible to the user).
4234 gtk_widget_hide (GtkWidget *widget)
4236 g_return_if_fail (GTK_IS_WIDGET (widget));
4238 if (gtk_widget_get_visible (widget))
4240 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4242 g_object_ref (widget);
4243 gtk_widget_push_verify_invariants (widget);
4245 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4246 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4248 /* a parent may now be expand=FALSE since we're hidden. */
4249 if (widget->priv->need_compute_expand ||
4250 widget->priv->computed_hexpand ||
4251 widget->priv->computed_vexpand)
4253 gtk_widget_queue_compute_expand (widget);
4256 g_signal_emit (widget, widget_signals[HIDE], 0);
4257 if (!gtk_widget_is_toplevel (widget))
4258 gtk_widget_queue_resize (widget);
4259 g_object_notify (G_OBJECT (widget), "visible");
4261 gtk_widget_pop_verify_invariants (widget);
4262 g_object_unref (widget);
4267 gtk_widget_real_hide (GtkWidget *widget)
4269 if (gtk_widget_get_visible (widget))
4271 widget->priv->visible = FALSE;
4273 if (gtk_widget_get_mapped (widget))
4274 gtk_widget_unmap (widget);
4279 * gtk_widget_hide_on_delete:
4280 * @widget: a #GtkWidget
4282 * Utility function; intended to be connected to the #GtkWidget::delete-event
4283 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4284 * argument, then returns %TRUE. If connected to ::delete-event, the
4285 * result is that clicking the close button for a window (on the
4286 * window frame, top right corner usually) will hide but not destroy
4287 * the window. By default, GTK+ destroys windows when ::delete-event
4290 * Return value: %TRUE
4293 gtk_widget_hide_on_delete (GtkWidget *widget)
4295 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4297 gtk_widget_hide (widget);
4303 * gtk_widget_show_all:
4304 * @widget: a #GtkWidget
4306 * Recursively shows a widget, and any child widgets (if the widget is
4310 gtk_widget_show_all (GtkWidget *widget)
4312 GtkWidgetClass *class;
4314 g_return_if_fail (GTK_IS_WIDGET (widget));
4316 if (gtk_widget_get_no_show_all (widget))
4319 class = GTK_WIDGET_GET_CLASS (widget);
4321 if (class->show_all)
4322 class->show_all (widget);
4327 * @widget: a #GtkWidget
4329 * This function is only for use in widget implementations. Causes
4330 * a widget to be mapped if it isn't already.
4333 gtk_widget_map (GtkWidget *widget)
4335 GtkWidgetPrivate *priv;
4337 g_return_if_fail (GTK_IS_WIDGET (widget));
4338 g_return_if_fail (gtk_widget_get_visible (widget));
4339 g_return_if_fail (gtk_widget_get_child_visible (widget));
4341 priv = widget->priv;
4343 if (!gtk_widget_get_mapped (widget))
4345 gtk_widget_push_verify_invariants (widget);
4347 if (!gtk_widget_get_realized (widget))
4348 gtk_widget_realize (widget);
4350 g_signal_emit (widget, widget_signals[MAP], 0);
4352 if (!gtk_widget_get_has_window (widget))
4353 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4355 if (widget->priv->context)
4356 _gtk_style_context_update_animating (widget->priv->context);
4358 gtk_widget_pop_verify_invariants (widget);
4364 * @widget: a #GtkWidget
4366 * This function is only for use in widget implementations. Causes
4367 * a widget to be unmapped if it's currently mapped.
4370 gtk_widget_unmap (GtkWidget *widget)
4372 GtkWidgetPrivate *priv;
4374 g_return_if_fail (GTK_IS_WIDGET (widget));
4376 priv = widget->priv;
4378 if (gtk_widget_get_mapped (widget))
4380 gtk_widget_push_verify_invariants (widget);
4382 if (!gtk_widget_get_has_window (widget))
4383 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4384 _gtk_tooltip_hide (widget);
4386 if (widget->priv->context)
4387 _gtk_style_context_update_animating (widget->priv->context);
4389 g_signal_emit (widget, widget_signals[UNMAP], 0);
4391 gtk_widget_pop_verify_invariants (widget);
4393 /* Unset pointer/window info */
4394 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4399 _gtk_widget_enable_device_events (GtkWidget *widget)
4401 GHashTable *device_events;
4402 GHashTableIter iter;
4403 gpointer key, value;
4405 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4410 g_hash_table_iter_init (&iter, device_events);
4412 while (g_hash_table_iter_next (&iter, &key, &value))
4415 GdkEventMask event_mask;
4418 event_mask = GPOINTER_TO_UINT (value);
4419 gtk_widget_add_events_internal (widget, device, event_mask);
4424 get_widget_windows (GtkWidget *widget)
4426 GList *window_list, *last, *l, *children, *ret;
4428 if (gtk_widget_get_has_window (widget))
4429 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4431 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4433 last = g_list_last (window_list);
4436 for (l = window_list; l; l = l->next)
4438 GtkWidget *window_widget = NULL;
4440 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4442 if (widget != window_widget)
4445 ret = g_list_prepend (ret, l->data);
4446 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4450 last = g_list_concat (last, children);
4451 last = g_list_last (last);
4455 g_list_free (window_list);
4461 device_enable_foreach (GtkWidget *widget,
4464 GdkDevice *device = user_data;
4465 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4469 device_disable_foreach (GtkWidget *widget,
4472 GdkDevice *device = user_data;
4473 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4477 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4482 GList *window_list, *l;
4484 window_list = get_widget_windows (widget);
4486 for (l = window_list; l; l = l->next)
4488 GdkEventMask events = 0;
4494 events = gdk_window_get_events (window);
4496 gdk_window_set_device_events (window, device, events);
4499 if (recurse && GTK_IS_CONTAINER (widget))
4502 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4504 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4507 g_list_free (window_list);
4511 gtk_widget_update_devices_mask (GtkWidget *widget,
4514 GList *enabled_devices, *l;
4516 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4518 for (l = enabled_devices; l; l = l->next)
4519 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4522 typedef struct _GtkTickCallbackInfo GtkTickCallbackInfo;
4524 struct _GtkTickCallbackInfo
4529 GtkTickCallback callback;
4531 GDestroyNotify notify;
4533 guint destroyed : 1;
4537 ref_tick_callback_info (GtkTickCallbackInfo *info)
4543 unref_tick_callback_info (GtkWidget *widget,
4544 GtkTickCallbackInfo *info,
4547 GtkWidgetPrivate *priv = widget->priv;
4550 if (info->refcount == 0)
4552 priv->tick_callbacks = g_list_delete_link (priv->tick_callbacks, link);
4554 info->notify (info->user_data);
4555 g_slice_free (GtkTickCallbackInfo, info);
4558 if (priv->tick_callbacks == NULL && priv->realized)
4560 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4561 g_signal_handlers_disconnect_by_func (frame_clock,
4562 (gpointer) gtk_widget_on_frame_clock_update,
4564 gdk_frame_clock_end_updating (frame_clock);
4569 destroy_tick_callback_info (GtkWidget *widget,
4570 GtkTickCallbackInfo *info,
4573 if (!info->destroyed)
4575 info->destroyed = TRUE;
4576 unref_tick_callback_info (widget, info, link);
4581 gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
4584 GtkWidgetPrivate *priv = widget->priv;
4587 g_object_ref (widget);
4589 for (l = priv->tick_callbacks; l;)
4591 GtkTickCallbackInfo *info = l->data;
4594 ref_tick_callback_info (info);
4595 if (!info->destroyed)
4597 if (info->callback (widget,
4599 info->user_data) == G_SOURCE_REMOVE)
4601 destroy_tick_callback_info (widget, info, l);
4606 unref_tick_callback_info (widget, info, l);
4610 g_object_unref (widget);
4613 static guint tick_callback_id;
4616 * gtk_widget_add_tick_callback:
4617 * @widget: a #GtkWidget
4618 * @callback: function to call for updating animations
4619 * @user_data: data to pass to @callback
4620 * @notify: function to call to free @user_data when the callback is removed.
4622 * Queues a animation frame update and adds a callback to be called
4623 * before each frame. Until the tick callback is removed, it will be
4624 * called frequently (usually at the frame rate of the output device
4625 * or as quickly as the application an be repainted, whichever is
4626 * slower). For this reason, is most suitable for handling graphics
4627 * that change every frame or every few frames. The tick callback does
4628 * not automatically imply a relayout or repaint. If you want a
4629 * repaint or relayout, and aren't changing widget properties that
4630 * would trigger that (for example, changing the text of a #GtkLabel),
4631 * then you will have to call gtk_widget_queue_resize() or
4632 * gtk_widget_queue_draw_area() yourself.
4634 * gdk_frame_clock_get_frame_time() should generally be used for timing
4635 * continuous animations and
4636 * gdk_frame_timings_get_predicted_presentation_time() if you are
4637 * trying to display isolated frames particular times.
4639 * This is a more convenient alternative to connecting directly to the
4640 * ::update signal of GdkFrameClock, since you don't have to worry about
4641 * when a #GdkFrameClock is assigned to a widget.
4643 * Returns: an id for the connection of this callback. Remove the callback
4644 * by passing it to gtk_widget_remove_tick_callback()
4649 gtk_widget_add_tick_callback (GtkWidget *widget,
4650 GtkTickCallback callback,
4652 GDestroyNotify notify)
4654 GtkWidgetPrivate *priv;
4655 GtkTickCallbackInfo *info;
4657 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4659 priv = widget->priv;
4661 if (priv->tick_callbacks == NULL && priv->realized)
4663 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4664 g_signal_connect (frame_clock, "update",
4665 G_CALLBACK (gtk_widget_on_frame_clock_update),
4667 gdk_frame_clock_begin_updating (frame_clock);
4670 info = g_slice_new0 (GtkTickCallbackInfo);
4673 info->id = ++tick_callback_id;
4674 info->callback = callback;
4675 info->user_data = user_data;
4676 info->notify = notify;
4678 priv->tick_callbacks = g_list_prepend (priv->tick_callbacks,
4685 * gtk_widget_remove_tick_callback:
4686 * @widget: a #GtkWidget
4687 * @id: an id returned by gtk_widget_add_tick_callback()
4689 * Removes a tick callback previously registered with
4690 * gtk_widget_add_tick_callback().
4695 gtk_widget_remove_tick_callback (GtkWidget *widget,
4698 GtkWidgetPrivate *priv;
4701 g_return_if_fail (GTK_IS_WIDGET (widget));
4703 priv = widget->priv;
4705 for (l = priv->tick_callbacks; l; l = l->next)
4707 GtkTickCallbackInfo *info = l->data;
4709 destroy_tick_callback_info (widget, info, l);
4714 gtk_widget_connect_frame_clock (GtkWidget *widget,
4715 GdkFrameClock *frame_clock)
4717 GtkWidgetPrivate *priv = widget->priv;
4719 if (GTK_IS_CONTAINER (widget))
4720 _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
4722 if (priv->tick_callbacks != NULL)
4724 g_signal_connect (frame_clock, "update",
4725 G_CALLBACK (gtk_widget_on_frame_clock_update),
4727 gdk_frame_clock_begin_updating (frame_clock);
4731 gtk_style_context_set_frame_clock (priv->context, frame_clock);
4735 gtk_widget_disconnect_frame_clock (GtkWidget *widget,
4736 GdkFrameClock *frame_clock)
4738 GtkWidgetPrivate *priv = widget->priv;
4740 if (GTK_IS_CONTAINER (widget))
4741 _gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
4743 if (priv->tick_callbacks)
4745 g_signal_handlers_disconnect_by_func (frame_clock,
4746 (gpointer) gtk_widget_on_frame_clock_update,
4748 gdk_frame_clock_end_updating (frame_clock);
4752 gtk_style_context_set_frame_clock (priv->context, NULL);
4756 * gtk_widget_realize:
4757 * @widget: a #GtkWidget
4759 * Creates the GDK (windowing system) resources associated with a
4760 * widget. For example, @widget->window will be created when a widget
4761 * is realized. Normally realization happens implicitly; if you show
4762 * a widget and all its parent containers, then the widget will be
4763 * realized and mapped automatically.
4765 * Realizing a widget requires all
4766 * the widget's parent widgets to be realized; calling
4767 * gtk_widget_realize() realizes the widget's parents in addition to
4768 * @widget itself. If a widget is not yet inside a toplevel window
4769 * when you realize it, bad things will happen.
4771 * This function is primarily used in widget implementations, and
4772 * isn't very useful otherwise. Many times when you think you might
4773 * need it, a better approach is to connect to a signal that will be
4774 * called after the widget is realized automatically, such as
4775 * #GtkWidget::draw. Or simply g_signal_connect () to the
4776 * #GtkWidget::realize signal.
4779 gtk_widget_realize (GtkWidget *widget)
4781 GtkWidgetPrivate *priv;
4782 cairo_region_t *region;
4784 g_return_if_fail (GTK_IS_WIDGET (widget));
4785 g_return_if_fail (widget->priv->anchored ||
4786 GTK_IS_INVISIBLE (widget));
4788 priv = widget->priv;
4790 if (!gtk_widget_get_realized (widget))
4792 gtk_widget_push_verify_invariants (widget);
4795 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4796 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4799 if (priv->parent == NULL &&
4800 !gtk_widget_is_toplevel (widget))
4801 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4802 "inside a toplevel window is not going to work very well. "
4803 "Widgets must be inside a toplevel container before realizing them.");
4805 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4806 gtk_widget_realize (priv->parent);
4808 gtk_widget_ensure_style (widget);
4810 if (priv->style_update_pending)
4811 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4813 g_signal_emit (widget, widget_signals[REALIZE], 0);
4815 gtk_widget_real_set_has_tooltip (widget,
4816 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4819 if (priv->has_shape_mask)
4821 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4822 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4825 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4827 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4829 if (priv->multidevice)
4830 gdk_window_set_support_multidevice (priv->window, TRUE);
4832 _gtk_widget_enable_device_events (widget);
4833 gtk_widget_update_devices_mask (widget, TRUE);
4835 gtk_widget_connect_frame_clock (widget,
4836 gtk_widget_get_frame_clock (widget));
4838 gtk_widget_pop_verify_invariants (widget);
4843 * gtk_widget_unrealize:
4844 * @widget: a #GtkWidget
4846 * This function is only useful in widget implementations.
4847 * Causes a widget to be unrealized (frees all GDK resources
4848 * associated with the widget, such as @widget->window).
4851 gtk_widget_unrealize (GtkWidget *widget)
4853 g_return_if_fail (GTK_IS_WIDGET (widget));
4855 gtk_widget_push_verify_invariants (widget);
4857 if (widget->priv->has_shape_mask)
4858 gtk_widget_shape_combine_region (widget, NULL);
4860 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4861 gtk_widget_input_shape_combine_region (widget, NULL);
4863 if (gtk_widget_get_realized (widget))
4865 g_object_ref (widget);
4867 if (widget->priv->mapped)
4868 gtk_widget_unmap (widget);
4870 gtk_widget_disconnect_frame_clock (widget,
4871 gtk_widget_get_frame_clock (widget));
4873 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4874 g_assert (!widget->priv->mapped);
4875 gtk_widget_set_realized (widget, FALSE);
4877 g_object_unref (widget);
4880 gtk_widget_pop_verify_invariants (widget);
4883 /*****************************************
4885 *****************************************/
4888 * gtk_widget_queue_draw_region:
4889 * @widget: a #GtkWidget
4890 * @region: region to draw
4892 * Invalidates the rectangular area of @widget defined by @region by
4893 * calling gdk_window_invalidate_region() on the widget's window and
4894 * all its child windows. Once the main loop becomes idle (after the
4895 * current batch of events has been processed, roughly), the window
4896 * will receive expose events for the union of all regions that have
4899 * Normally you would only use this function in widget
4900 * implementations. You might also use it to schedule a redraw of a
4901 * #GtkDrawingArea or some portion thereof.
4906 gtk_widget_queue_draw_region (GtkWidget *widget,
4907 const cairo_region_t *region)
4909 GtkWidgetPrivate *priv;
4912 g_return_if_fail (GTK_IS_WIDGET (widget));
4914 priv = widget->priv;
4916 if (!gtk_widget_get_realized (widget))
4919 /* Just return if the widget or one of its ancestors isn't mapped */
4920 for (w = widget; w != NULL; w = w->priv->parent)
4921 if (!gtk_widget_get_mapped (w))
4924 gdk_window_invalidate_region (priv->window, region, TRUE);
4928 * gtk_widget_queue_draw_area:
4929 * @widget: a #GtkWidget
4930 * @x: x coordinate of upper-left corner of rectangle to redraw
4931 * @y: y coordinate of upper-left corner of rectangle to redraw
4932 * @width: width of region to draw
4933 * @height: height of region to draw
4935 * Convenience function that calls gtk_widget_queue_draw_region() on
4936 * the region created from the given coordinates.
4938 * The region here is specified in widget coordinates.
4939 * Widget coordinates are a bit odd; for historical reasons, they are
4940 * defined as @widget->window coordinates for widgets that are not
4941 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4942 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4945 gtk_widget_queue_draw_area (GtkWidget *widget,
4952 cairo_region_t *region;
4954 g_return_if_fail (GTK_IS_WIDGET (widget));
4959 rect.height = height;
4961 region = cairo_region_create_rectangle (&rect);
4962 gtk_widget_queue_draw_region (widget, region);
4963 cairo_region_destroy (region);
4967 * gtk_widget_queue_draw:
4968 * @widget: a #GtkWidget
4970 * Equivalent to calling gtk_widget_queue_draw_area() for the
4971 * entire area of a widget.
4974 gtk_widget_queue_draw (GtkWidget *widget)
4978 g_return_if_fail (GTK_IS_WIDGET (widget));
4980 gtk_widget_get_allocation (widget, &rect);
4982 if (!gtk_widget_get_has_window (widget))
4983 gtk_widget_queue_draw_area (widget,
4984 rect.x, rect.y, rect.width, rect.height);
4986 gtk_widget_queue_draw_area (widget,
4987 0, 0, rect.width, rect.height);
4991 * gtk_widget_queue_resize:
4992 * @widget: a #GtkWidget
4994 * This function is only for use in widget implementations.
4995 * Flags a widget to have its size renegotiated; should
4996 * be called when a widget for some reason has a new size request.
4997 * For example, when you change the text in a #GtkLabel, #GtkLabel
4998 * queues a resize to ensure there's enough space for the new text.
5000 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
5001 * from inside its implementation of the GtkWidgetClass::size_allocate
5002 * virtual method. Calls to gtk_widget_queue_resize() from inside
5003 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
5006 gtk_widget_queue_resize (GtkWidget *widget)
5008 g_return_if_fail (GTK_IS_WIDGET (widget));
5010 if (gtk_widget_get_realized (widget))
5011 gtk_widget_queue_draw (widget);
5013 _gtk_size_group_queue_resize (widget, 0);
5017 * gtk_widget_queue_resize_no_redraw:
5018 * @widget: a #GtkWidget
5020 * This function works like gtk_widget_queue_resize(),
5021 * except that the widget is not invalidated.
5026 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
5028 g_return_if_fail (GTK_IS_WIDGET (widget));
5030 _gtk_size_group_queue_resize (widget, 0);
5034 * gtk_widget_get_frame_clock:
5035 * @widget: a #GtkWidget
5037 * Obtains the frame clock for a widget. The frame clock is a global
5038 * "ticker" that can be used to drive animations and repaints. The
5039 * most common reason to get the frame clock is to call
5040 * gdk_frame_clock_get_frame_time(), in order to get a time to use for
5041 * animating. For example you might record the start of the animation
5042 * with an initial value from gdk_frame_clock_get_frame_time(), and
5043 * then update the animation by calling
5044 * gdk_frame_clock_get_frame_time() again during each repaint.
5046 * gdk_frame_clock_request_phase() will result in a new frame on the
5047 * clock, but won't necessarily repaint any widgets. To repaint a
5048 * widget, you have to use gtk_widget_queue_draw() which invalidates
5049 * the widget (thus scheduling it to receive a draw on the next
5050 * frame). gtk_widget_queue_draw() will also end up requesting a frame
5051 * on the appropriate frame clock.
5053 * A widget's frame clock will not change while the widget is
5054 * mapped. Reparenting a widget (which implies a temporary unmap) can
5055 * change the widget's frame clock.
5057 * Unrealized widgets do not have a frame clock.
5060 * Return value: (transfer none): a #GdkFrameClock (or #NULL if widget is unrealized)
5063 gtk_widget_get_frame_clock (GtkWidget *widget)
5065 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5067 if (widget->priv->realized)
5069 /* We use gtk_widget_get_toplevel() here to make it explicit that
5070 * the frame clock is a property of the toplevel that a widget
5071 * is anchored to; gdk_window_get_toplevel() will go up the
5072 * hierarchy anyways, but should squash any funny business with
5073 * reparenting windows and widgets.
5075 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5076 GdkWindow *window = gtk_widget_get_window (toplevel);
5077 g_assert (window != NULL);
5079 return gdk_window_get_frame_clock (window);
5088 * gtk_widget_size_request:
5089 * @widget: a #GtkWidget
5090 * @requisition: (out): a #GtkRequisition to be filled in
5092 * This function is typically used when implementing a #GtkContainer
5093 * subclass. Obtains the preferred size of a widget. The container
5094 * uses this information to arrange its child widgets and decide what
5095 * size allocations to give them with gtk_widget_size_allocate().
5097 * You can also call this function from an application, with some
5098 * caveats. Most notably, getting a size request requires the widget
5099 * to be associated with a screen, because font information may be
5100 * needed. Multihead-aware applications should keep this in mind.
5102 * Also remember that the size request is not necessarily the size
5103 * a widget will actually be allocated.
5105 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5108 gtk_widget_size_request (GtkWidget *widget,
5109 GtkRequisition *requisition)
5111 g_return_if_fail (GTK_IS_WIDGET (widget));
5113 gtk_widget_get_preferred_size (widget, requisition, NULL);
5117 * gtk_widget_get_child_requisition:
5118 * @widget: a #GtkWidget
5119 * @requisition: (out): a #GtkRequisition to be filled in
5121 * This function is only for use in widget implementations. Obtains
5122 * @widget->requisition, unless someone has forced a particular
5123 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
5124 * in which case it returns that geometry instead of the widget's
5127 * This function differs from gtk_widget_size_request() in that
5128 * it retrieves the last size request value from @widget->requisition,
5129 * while gtk_widget_size_request() actually calls the "size_request" method
5130 * on @widget to compute the size request and fill in @widget->requisition,
5131 * and only then returns @widget->requisition.
5133 * Because this function does not call the "size_request" method, it
5134 * can only be used when you know that @widget->requisition is
5135 * up-to-date, that is, gtk_widget_size_request() has been called
5136 * since the last time a resize was queued. In general, only container
5137 * implementations have this information; applications should use
5138 * gtk_widget_size_request().
5141 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5144 gtk_widget_get_child_requisition (GtkWidget *widget,
5145 GtkRequisition *requisition)
5147 gtk_widget_get_preferred_size (widget, requisition, NULL);
5151 invalidate_predicate (GdkWindow *window,
5156 gdk_window_get_user_data (window, &user_data);
5158 return (user_data == data);
5161 /* Invalidate @region in widget->window and all children
5162 * of widget->window owned by widget. @region is in the
5163 * same coordinates as widget->allocation and will be
5164 * modified by this call.
5167 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
5168 cairo_region_t *region)
5170 GtkWidgetPrivate *priv = widget->priv;
5172 if (!gtk_widget_get_realized (widget))
5175 if (gtk_widget_get_has_window (widget) && priv->parent)
5179 gdk_window_get_position (priv->window, &x, &y);
5180 cairo_region_translate (region, -x, -y);
5183 gdk_window_invalidate_maybe_recurse (priv->window, region,
5184 invalidate_predicate, widget);
5188 * gtk_widget_size_allocate:
5189 * @widget: a #GtkWidget
5190 * @allocation: position and size to be allocated to @widget
5192 * This function is only used by #GtkContainer subclasses, to assign a size
5193 * and position to their child widgets.
5195 * In this function, the allocation may be adjusted. It will be forced
5196 * to a 1x1 minimum size, and the adjust_size_allocation virtual
5197 * method on the child will be used to adjust the allocation. Standard
5198 * adjustments include removing the widget's margins, and applying the
5199 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
5202 gtk_widget_size_allocate (GtkWidget *widget,
5203 GtkAllocation *allocation)
5205 GtkWidgetPrivate *priv;
5206 GdkRectangle real_allocation;
5207 GdkRectangle old_allocation;
5208 GdkRectangle adjusted_allocation;
5209 gboolean alloc_needed;
5210 gboolean size_changed;
5211 gboolean position_changed;
5212 gint natural_width, natural_height, dummy;
5213 gint min_width, min_height;
5215 priv = widget->priv;
5217 g_return_if_fail (GTK_IS_WIDGET (widget));
5219 if (!priv->visible && !gtk_widget_is_toplevel (widget))
5222 gtk_widget_push_verify_invariants (widget);
5224 #ifdef G_ENABLE_DEBUG
5225 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5236 parent = gtk_widget_get_parent (parent);
5239 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
5240 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
5241 2 * depth, " ", name,
5242 allocation->width, allocation->height);
5244 #endif /* G_ENABLE_DEBUG */
5246 alloc_needed = priv->alloc_needed;
5247 /* Preserve request/allocate ordering */
5248 priv->alloc_needed = FALSE;
5250 old_allocation = priv->allocation;
5251 real_allocation = *allocation;
5253 adjusted_allocation = real_allocation;
5254 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
5256 /* Go ahead and request the height for allocated width, note that the internals
5257 * of get_height_for_width will internally limit the for_size to natural size
5258 * when aligning implicitly.
5260 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
5261 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
5265 /* Go ahead and request the width for allocated height, note that the internals
5266 * of get_width_for_height will internally limit the for_size to natural size
5267 * when aligning implicitly.
5269 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
5270 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
5273 #ifdef G_ENABLE_DEBUG
5274 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5276 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
5277 !GTK_IS_SCROLLABLE (widget))
5278 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
5279 "Allocation is %dx%d, but minimum required size is %dx%d.",
5280 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
5281 G_OBJECT_TYPE_NAME (widget), widget,
5282 real_allocation.width, real_allocation.height,
5283 min_width, min_height);
5286 /* Now that we have the right natural height and width, go ahead and remove any margins from the
5287 * allocated sizes and possibly limit them to the natural sizes */
5288 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5289 GTK_ORIENTATION_HORIZONTAL,
5292 &adjusted_allocation.x,
5293 &adjusted_allocation.width);
5294 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5295 GTK_ORIENTATION_VERTICAL,
5298 &adjusted_allocation.y,
5299 &adjusted_allocation.height);
5301 if (adjusted_allocation.x < real_allocation.x ||
5302 adjusted_allocation.y < real_allocation.y ||
5303 (adjusted_allocation.x + adjusted_allocation.width) >
5304 (real_allocation.x + real_allocation.width) ||
5305 (adjusted_allocation.y + adjusted_allocation.height >
5306 real_allocation.y + real_allocation.height))
5308 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",
5309 G_OBJECT_TYPE_NAME (widget), widget,
5310 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5311 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5312 adjusted_allocation = real_allocation; /* veto it */
5316 real_allocation = adjusted_allocation;
5319 if (real_allocation.width < 0 || real_allocation.height < 0)
5321 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5322 real_allocation.width,
5323 real_allocation.height);
5326 real_allocation.width = MAX (real_allocation.width, 1);
5327 real_allocation.height = MAX (real_allocation.height, 1);
5329 size_changed = (old_allocation.width != real_allocation.width ||
5330 old_allocation.height != real_allocation.height);
5331 position_changed = (old_allocation.x != real_allocation.x ||
5332 old_allocation.y != real_allocation.y);
5334 if (!alloc_needed && !size_changed && !position_changed)
5337 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5339 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5340 priv->alloc_needed = FALSE;
5342 if (gtk_widget_get_mapped (widget))
5344 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5346 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5348 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5349 cairo_region_union_rectangle (invalidate, &old_allocation);
5351 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5352 cairo_region_destroy (invalidate);
5357 if (priv->redraw_on_alloc)
5359 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5361 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5362 cairo_region_union_rectangle (invalidate, &old_allocation);
5364 gtk_widget_invalidate_widget_windows (widget, invalidate);
5365 cairo_region_destroy (invalidate);
5370 if ((size_changed || position_changed) && priv->parent &&
5371 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5373 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5374 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5375 cairo_region_destroy (invalidate);
5379 gtk_widget_pop_verify_invariants (widget);
5383 * gtk_widget_common_ancestor:
5384 * @widget_a: a #GtkWidget
5385 * @widget_b: a #GtkWidget
5387 * Find the common ancestor of @widget_a and @widget_b that
5388 * is closest to the two widgets.
5390 * Return value: the closest common ancestor of @widget_a and
5391 * @widget_b or %NULL if @widget_a and @widget_b do not
5392 * share a common ancestor.
5395 gtk_widget_common_ancestor (GtkWidget *widget_a,
5396 GtkWidget *widget_b)
5398 GtkWidget *parent_a;
5399 GtkWidget *parent_b;
5403 parent_a = widget_a;
5404 while (parent_a->priv->parent)
5406 parent_a = parent_a->priv->parent;
5410 parent_b = widget_b;
5411 while (parent_b->priv->parent)
5413 parent_b = parent_b->priv->parent;
5417 if (parent_a != parent_b)
5420 while (depth_a > depth_b)
5422 widget_a = widget_a->priv->parent;
5426 while (depth_b > depth_a)
5428 widget_b = widget_b->priv->parent;
5432 while (widget_a != widget_b)
5434 widget_a = widget_a->priv->parent;
5435 widget_b = widget_b->priv->parent;
5442 * gtk_widget_translate_coordinates:
5443 * @src_widget: a #GtkWidget
5444 * @dest_widget: a #GtkWidget
5445 * @src_x: X position relative to @src_widget
5446 * @src_y: Y position relative to @src_widget
5447 * @dest_x: (out): location to store X position relative to @dest_widget
5448 * @dest_y: (out): location to store Y position relative to @dest_widget
5450 * Translate coordinates relative to @src_widget's allocation to coordinates
5451 * relative to @dest_widget's allocations. In order to perform this
5452 * operation, both widgets must be realized, and must share a common
5455 * Return value: %FALSE if either widget was not realized, or there
5456 * was no common ancestor. In this case, nothing is stored in
5457 * *@dest_x and *@dest_y. Otherwise %TRUE.
5460 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5461 GtkWidget *dest_widget,
5467 GtkWidgetPrivate *src_priv = src_widget->priv;
5468 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5469 GtkWidget *ancestor;
5471 GList *dest_list = NULL;
5473 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5474 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5476 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5477 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5480 /* Translate from allocation relative to window relative */
5481 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5484 gdk_window_get_position (src_priv->window, &wx, &wy);
5486 src_x -= wx - src_priv->allocation.x;
5487 src_y -= wy - src_priv->allocation.y;
5491 src_x += src_priv->allocation.x;
5492 src_y += src_priv->allocation.y;
5495 /* Translate to the common ancestor */
5496 window = src_priv->window;
5497 while (window != ancestor->priv->window)
5501 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5506 window = gdk_window_get_effective_parent (window);
5508 if (!window) /* Handle GtkHandleBox */
5513 window = dest_priv->window;
5514 while (window != ancestor->priv->window)
5516 dest_list = g_list_prepend (dest_list, window);
5518 window = gdk_window_get_effective_parent (window);
5520 if (!window) /* Handle GtkHandleBox */
5522 g_list_free (dest_list);
5531 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5536 dest_list = g_list_remove (dest_list, dest_list->data);
5539 /* Translate from window relative to allocation relative */
5540 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5543 gdk_window_get_position (dest_priv->window, &wx, &wy);
5545 src_x += wx - dest_priv->allocation.x;
5546 src_y += wy - dest_priv->allocation.y;
5550 src_x -= dest_priv->allocation.x;
5551 src_y -= dest_priv->allocation.y;
5563 gtk_widget_real_size_allocate (GtkWidget *widget,
5564 GtkAllocation *allocation)
5566 GtkWidgetPrivate *priv = widget->priv;
5568 priv->allocation = *allocation;
5570 if (gtk_widget_get_realized (widget) &&
5571 gtk_widget_get_has_window (widget))
5573 gdk_window_move_resize (priv->window,
5574 allocation->x, allocation->y,
5575 allocation->width, allocation->height);
5579 /* translate initial/final into start/end */
5581 effective_align (GtkAlign align,
5582 GtkTextDirection direction)
5586 case GTK_ALIGN_START:
5587 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5589 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5596 adjust_for_align (GtkAlign align,
5598 gint *allocated_pos,
5599 gint *allocated_size)
5603 case GTK_ALIGN_FILL:
5604 /* change nothing */
5606 case GTK_ALIGN_START:
5607 /* keep *allocated_pos where it is */
5608 *allocated_size = MIN (*allocated_size, *natural_size);
5611 if (*allocated_size > *natural_size)
5613 *allocated_pos += (*allocated_size - *natural_size);
5614 *allocated_size = *natural_size;
5617 case GTK_ALIGN_CENTER:
5618 if (*allocated_size > *natural_size)
5620 *allocated_pos += (*allocated_size - *natural_size) / 2;
5621 *allocated_size = MIN (*allocated_size, *natural_size);
5628 adjust_for_margin(gint start_margin,
5632 gint *allocated_pos,
5633 gint *allocated_size)
5635 *minimum_size -= (start_margin + end_margin);
5636 *natural_size -= (start_margin + end_margin);
5637 *allocated_pos += start_margin;
5638 *allocated_size -= (start_margin + end_margin);
5642 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5643 GtkOrientation orientation,
5646 gint *allocated_pos,
5647 gint *allocated_size)
5649 const GtkWidgetAuxInfo *aux_info;
5651 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5653 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5655 adjust_for_margin (aux_info->margin.left,
5656 aux_info->margin.right,
5657 minimum_size, natural_size,
5658 allocated_pos, allocated_size);
5659 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5660 natural_size, allocated_pos, allocated_size);
5664 adjust_for_margin (aux_info->margin.top,
5665 aux_info->margin.bottom,
5666 minimum_size, natural_size,
5667 allocated_pos, allocated_size);
5668 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5669 natural_size, allocated_pos, allocated_size);
5674 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5677 GtkWidgetPrivate *priv = widget->priv;
5679 /* widgets must be onscreen for accels to take effect */
5680 return gtk_widget_is_sensitive (widget) &&
5681 gtk_widget_is_drawable (widget) &&
5682 gdk_window_is_viewable (priv->window);
5686 * gtk_widget_can_activate_accel:
5687 * @widget: a #GtkWidget
5688 * @signal_id: the ID of a signal installed on @widget
5690 * Determines whether an accelerator that activates the signal
5691 * identified by @signal_id can currently be activated.
5692 * This is done by emitting the #GtkWidget::can-activate-accel
5693 * signal on @widget; if the signal isn't overridden by a
5694 * handler or in a derived widget, then the default check is
5695 * that the widget must be sensitive, and the widget and all
5696 * its ancestors mapped.
5698 * Return value: %TRUE if the accelerator can be activated.
5703 gtk_widget_can_activate_accel (GtkWidget *widget,
5706 gboolean can_activate = FALSE;
5707 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5708 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5709 return can_activate;
5718 closure_accel_activate (GClosure *closure,
5719 GValue *return_value,
5720 guint n_param_values,
5721 const GValue *param_values,
5722 gpointer invocation_hint,
5723 gpointer marshal_data)
5725 AccelClosure *aclosure = (AccelClosure*) closure;
5726 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5729 g_signal_emit (closure->data, aclosure->signal_id, 0);
5731 /* whether accelerator was handled */
5732 g_value_set_boolean (return_value, can_activate);
5736 closures_destroy (gpointer data)
5738 GSList *slist, *closures = data;
5740 for (slist = closures; slist; slist = slist->next)
5742 g_closure_invalidate (slist->data);
5743 g_closure_unref (slist->data);
5745 g_slist_free (closures);
5749 widget_new_accel_closure (GtkWidget *widget,
5752 AccelClosure *aclosure;
5753 GClosure *closure = NULL;
5754 GSList *slist, *closures;
5756 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5757 for (slist = closures; slist; slist = slist->next)
5758 if (!gtk_accel_group_from_accel_closure (slist->data))
5760 /* reuse this closure */
5761 closure = slist->data;
5766 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5767 closures = g_slist_prepend (closures, g_closure_ref (closure));
5768 g_closure_sink (closure);
5769 g_closure_set_marshal (closure, closure_accel_activate);
5771 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5773 aclosure = (AccelClosure*) closure;
5774 g_assert (closure->data == widget);
5775 g_assert (closure->marshal == closure_accel_activate);
5776 aclosure->signal_id = signal_id;
5782 * gtk_widget_add_accelerator:
5783 * @widget: widget to install an accelerator on
5784 * @accel_signal: widget signal to emit on accelerator activation
5785 * @accel_group: accel group for this widget, added to its toplevel
5786 * @accel_key: GDK keyval of the accelerator
5787 * @accel_mods: modifier key combination of the accelerator
5788 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5790 * Installs an accelerator for this @widget in @accel_group that causes
5791 * @accel_signal to be emitted if the accelerator is activated.
5792 * The @accel_group needs to be added to the widget's toplevel via
5793 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5794 * Accelerators added through this function are not user changeable during
5795 * runtime. If you want to support accelerators that can be changed by the
5796 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5797 * gtk_menu_item_set_accel_path() instead.
5800 gtk_widget_add_accelerator (GtkWidget *widget,
5801 const gchar *accel_signal,
5802 GtkAccelGroup *accel_group,
5804 GdkModifierType accel_mods,
5805 GtkAccelFlags accel_flags)
5810 g_return_if_fail (GTK_IS_WIDGET (widget));
5811 g_return_if_fail (accel_signal != NULL);
5812 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5814 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5815 if (!query.signal_id ||
5816 !(query.signal_flags & G_SIGNAL_ACTION) ||
5817 query.return_type != G_TYPE_NONE ||
5820 /* hmm, should be elaborate enough */
5821 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5822 G_OBJECT_TYPE_NAME (widget), accel_signal);
5826 closure = widget_new_accel_closure (widget, query.signal_id);
5828 g_object_ref (widget);
5830 /* install the accelerator. since we don't map this onto an accel_path,
5831 * the accelerator will automatically be locked.
5833 gtk_accel_group_connect (accel_group,
5836 accel_flags | GTK_ACCEL_LOCKED,
5839 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5841 g_object_unref (widget);
5845 * gtk_widget_remove_accelerator:
5846 * @widget: widget to install an accelerator on
5847 * @accel_group: accel group for this widget
5848 * @accel_key: GDK keyval of the accelerator
5849 * @accel_mods: modifier key combination of the accelerator
5851 * Removes an accelerator from @widget, previously installed with
5852 * gtk_widget_add_accelerator().
5854 * Returns: whether an accelerator was installed and could be removed
5857 gtk_widget_remove_accelerator (GtkWidget *widget,
5858 GtkAccelGroup *accel_group,
5860 GdkModifierType accel_mods)
5862 GtkAccelGroupEntry *ag_entry;
5863 GList *slist, *clist;
5866 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5867 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5869 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5870 clist = gtk_widget_list_accel_closures (widget);
5871 for (slist = clist; slist; slist = slist->next)
5875 for (i = 0; i < n; i++)
5876 if (slist->data == (gpointer) ag_entry[i].closure)
5878 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5880 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5882 g_list_free (clist);
5887 g_list_free (clist);
5889 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5890 accel_key, accel_mods, accel_group,
5891 G_OBJECT_TYPE_NAME (widget), widget);
5897 * gtk_widget_list_accel_closures:
5898 * @widget: widget to list accelerator closures for
5900 * Lists the closures used by @widget for accelerator group connections
5901 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5902 * The closures can be used to monitor accelerator changes on @widget,
5903 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5904 * #GtkAccelGroup of a closure which can be found out with
5905 * gtk_accel_group_from_accel_closure().
5907 * Return value: (transfer container) (element-type GClosure):
5908 * a newly allocated #GList of closures
5911 gtk_widget_list_accel_closures (GtkWidget *widget)
5914 GList *clist = NULL;
5916 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5918 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5919 if (gtk_accel_group_from_accel_closure (slist->data))
5920 clist = g_list_prepend (clist, slist->data);
5926 GtkAccelGroup *accel_group;
5931 destroy_accel_path (gpointer data)
5933 AccelPath *apath = data;
5935 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5937 /* closures_destroy takes care of unrefing the closure */
5938 g_object_unref (apath->accel_group);
5940 g_slice_free (AccelPath, apath);
5945 * gtk_widget_set_accel_path:
5946 * @widget: a #GtkWidget
5947 * @accel_path: (allow-none): path used to look up the accelerator
5948 * @accel_group: (allow-none): a #GtkAccelGroup.
5950 * Given an accelerator group, @accel_group, and an accelerator path,
5951 * @accel_path, sets up an accelerator in @accel_group so whenever the
5952 * key binding that is defined for @accel_path is pressed, @widget
5953 * will be activated. This removes any accelerators (for any
5954 * accelerator group) installed by previous calls to
5955 * gtk_widget_set_accel_path(). Associating accelerators with
5956 * paths allows them to be modified by the user and the modifications
5957 * to be saved for future use. (See gtk_accel_map_save().)
5959 * This function is a low level function that would most likely
5960 * be used by a menu creation system like #GtkUIManager. If you
5961 * use #GtkUIManager, setting up accelerator paths will be done
5964 * Even when you you aren't using #GtkUIManager, if you only want to
5965 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5966 * provides a somewhat more convenient interface.
5968 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5969 * pass a static string, you can save some memory by interning it first with
5970 * g_intern_static_string().
5973 gtk_widget_set_accel_path (GtkWidget *widget,
5974 const gchar *accel_path,
5975 GtkAccelGroup *accel_group)
5979 g_return_if_fail (GTK_IS_WIDGET (widget));
5980 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5984 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5985 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5987 gtk_accel_map_add_entry (accel_path, 0, 0);
5988 apath = g_slice_new (AccelPath);
5989 apath->accel_group = g_object_ref (accel_group);
5990 apath->path_quark = g_quark_from_string (accel_path);
5991 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5996 /* also removes possible old settings */
5997 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
6000 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
6002 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
6006 _gtk_widget_get_accel_path (GtkWidget *widget,
6011 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6013 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
6015 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
6016 return apath ? g_quark_to_string (apath->path_quark) : NULL;
6020 * gtk_widget_mnemonic_activate:
6021 * @widget: a #GtkWidget
6022 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
6024 * Emits the #GtkWidget::mnemonic-activate signal.
6026 * The default handler for this signal activates the @widget if
6027 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
6030 * Returns: %TRUE if the signal has been handled
6033 gtk_widget_mnemonic_activate (GtkWidget *widget,
6034 gboolean group_cycling)
6038 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6040 group_cycling = group_cycling != FALSE;
6041 if (!gtk_widget_is_sensitive (widget))
6044 g_signal_emit (widget,
6045 widget_signals[MNEMONIC_ACTIVATE],
6053 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
6054 gboolean group_cycling)
6056 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
6057 gtk_widget_activate (widget);
6058 else if (gtk_widget_get_can_focus (widget))
6059 gtk_widget_grab_focus (widget);
6062 g_warning ("widget `%s' isn't suitable for mnemonic activation",
6063 G_OBJECT_TYPE_NAME (widget));
6064 gtk_widget_error_bell (widget);
6069 static const cairo_user_data_key_t event_key;
6072 _gtk_cairo_get_event (cairo_t *cr)
6074 g_return_val_if_fail (cr != NULL, NULL);
6076 return cairo_get_user_data (cr, &event_key);
6080 gtk_cairo_set_event (cairo_t *cr,
6081 GdkEventExpose *event)
6083 cairo_set_user_data (cr, &event_key, event, NULL);
6087 * gtk_cairo_should_draw_window:
6088 * @cr: a cairo context
6089 * @window: the window to check. @window may not be an input-only
6092 * This function is supposed to be called in #GtkWidget::draw
6093 * implementations for widgets that support multiple windows.
6094 * @cr must be untransformed from invoking of the draw function.
6095 * This function will return %TRUE if the contents of the given
6096 * @window are supposed to be drawn and %FALSE otherwise. Note
6097 * that when the drawing was not initiated by the windowing
6098 * system this function will return %TRUE for all windows, so
6099 * you need to draw the bottommost window first. Also, do not
6100 * use "else if" statements to check which window should be drawn.
6102 * Returns: %TRUE if @window should be drawn
6107 gtk_cairo_should_draw_window (cairo_t *cr,
6110 GdkEventExpose *event;
6112 g_return_val_if_fail (cr != NULL, FALSE);
6113 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
6115 event = _gtk_cairo_get_event (cr);
6117 return event == NULL ||
6118 event->window == window;
6122 gtk_widget_get_clip_draw (GtkWidget *widget)
6124 /* labels are not clipped, because clipping them would cause
6125 * mnemonics to not appear on characters that go beyond the
6127 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
6129 if (GTK_IS_LABEL (widget))
6135 /* code shared by gtk_container_propagate_draw() and
6139 _gtk_widget_draw_internal (GtkWidget *widget,
6141 gboolean clip_to_size)
6143 if (!gtk_widget_is_drawable (widget))
6146 clip_to_size &= gtk_widget_get_clip_draw (widget);
6150 cairo_rectangle (cr,
6152 widget->priv->allocation.width,
6153 widget->priv->allocation.height);
6157 if (gdk_cairo_get_clip_rectangle (cr, NULL))
6161 g_signal_emit (widget, widget_signals[DRAW],
6165 if (cairo_status (cr) &&
6166 _gtk_cairo_get_event (cr))
6168 /* We check the event so we only warn about internal GTK calls.
6169 * Errors might come from PDF streams having write failures and
6170 * we don't want to spam stderr in that case.
6171 * We do want to catch errors from
6173 g_warning ("drawing failure for widget `%s': %s",
6174 G_OBJECT_TYPE_NAME (widget),
6175 cairo_status_to_string (cairo_status (cr)));
6182 * @widget: the widget to draw. It must be drawable (see
6183 * gtk_widget_is_drawable()) and a size must have been allocated.
6184 * @cr: a cairo context to draw to
6186 * Draws @widget to @cr. The top left corner of the widget will be
6187 * drawn to the currently set origin point of @cr.
6189 * You should pass a cairo context as @cr argument that is in an
6190 * original state. Otherwise the resulting drawing is undefined. For
6191 * example changing the operator using cairo_set_operator() or the
6192 * line width using cairo_set_line_width() might have unwanted side
6194 * You may however change the context's transform matrix - like with
6195 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
6196 * region with cairo_clip() prior to calling this function. Also, it
6197 * is fine to modify the context with cairo_save() and
6198 * cairo_push_group() prior to calling this function.
6200 * <note><para>Special purpose widgets may contain special code for
6201 * rendering to the screen and might appear differently on screen
6202 * and when rendered using gtk_widget_draw().</para></note>
6207 gtk_widget_draw (GtkWidget *widget,
6210 GdkEventExpose *tmp_event;
6212 g_return_if_fail (GTK_IS_WIDGET (widget));
6213 g_return_if_fail (!widget->priv->alloc_needed);
6214 g_return_if_fail (cr != NULL);
6217 /* We have to reset the event here so that draw functions can call
6218 * gtk_widget_draw() on random other widgets and get the desired
6219 * effect: Drawing all contents, not just the current window.
6221 tmp_event = _gtk_cairo_get_event (cr);
6222 gtk_cairo_set_event (cr, NULL);
6224 _gtk_widget_draw_internal (widget, cr, TRUE);
6226 gtk_cairo_set_event (cr, tmp_event);
6231 gtk_widget_real_key_press_event (GtkWidget *widget,
6234 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6238 gtk_widget_real_key_release_event (GtkWidget *widget,
6241 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6245 gtk_widget_real_focus_in_event (GtkWidget *widget,
6246 GdkEventFocus *event)
6248 gtk_widget_queue_draw (widget);
6254 gtk_widget_real_focus_out_event (GtkWidget *widget,
6255 GdkEventFocus *event)
6257 gtk_widget_queue_draw (widget);
6263 gtk_widget_real_touch_event (GtkWidget *widget,
6264 GdkEventTouch *event)
6267 gboolean return_val;
6270 if (!event->emulating_pointer)
6273 if (event->type == GDK_TOUCH_BEGIN ||
6274 event->type == GDK_TOUCH_END)
6278 if (event->type == GDK_TOUCH_BEGIN)
6280 type = GDK_BUTTON_PRESS;
6281 signum = BUTTON_PRESS_EVENT;
6285 type = GDK_BUTTON_RELEASE;
6286 signum = BUTTON_RELEASE_EVENT;
6288 bevent = gdk_event_new (type);
6289 bevent->any.window = g_object_ref (event->window);
6290 bevent->any.send_event = FALSE;
6291 bevent->button.time = event->time;
6292 bevent->button.state = event->state;
6293 bevent->button.button = 1;
6294 bevent->button.x_root = event->x_root;
6295 bevent->button.y_root = event->y_root;
6296 bevent->button.x = event->x;
6297 bevent->button.y = event->y;
6298 bevent->button.device = event->device;
6299 bevent->button.axes = g_memdup (event->axes,
6300 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6301 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6303 else if (event->type == GDK_TOUCH_UPDATE)
6305 signum = MOTION_NOTIFY_EVENT;
6306 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6307 bevent->any.window = g_object_ref (event->window);
6308 bevent->any.send_event = FALSE;
6309 bevent->motion.time = event->time;
6310 bevent->motion.state = event->state;
6311 bevent->motion.x_root = event->x_root;
6312 bevent->motion.y_root = event->y_root;
6313 bevent->motion.x = event->x;
6314 bevent->motion.y = event->y;
6315 bevent->motion.device = event->device;
6316 bevent->motion.is_hint = FALSE;
6317 bevent->motion.axes = g_memdup (event->axes,
6318 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6319 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6324 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6326 gdk_event_free (bevent);
6332 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6333 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6337 * @widget: a #GtkWidget
6338 * @event: a #GdkEvent
6340 * Rarely-used function. This function is used to emit
6341 * the event signals on a widget (those signals should never
6342 * be emitted without using this function to do so).
6343 * If you want to synthesize an event though, don't use this function;
6344 * instead, use gtk_main_do_event() so the event will behave as if
6345 * it were in the event queue. Don't synthesize expose events; instead,
6346 * use gdk_window_invalidate_rect() to invalidate a region of the
6349 * Return value: return from the event signal emission (%TRUE if
6350 * the event was handled)
6353 gtk_widget_event (GtkWidget *widget,
6356 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6357 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6359 if (event->type == GDK_EXPOSE)
6361 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6362 "the same effect, call gdk_window_invalidate_rect/region(), "
6363 "followed by gdk_window_process_updates().");
6367 return gtk_widget_event_internal (widget, event);
6371 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6372 GtkCapturedEventHandler callback)
6374 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6378 _gtk_widget_captured_event (GtkWidget *widget,
6381 gboolean return_val = FALSE;
6382 GtkCapturedEventHandler handler;
6384 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6385 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6387 if (event->type == GDK_EXPOSE)
6389 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6390 "the same effect, call gdk_window_invalidate_rect/region(), "
6391 "followed by gdk_window_process_updates().");
6395 if (!event_window_is_still_viewable (event))
6398 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6402 g_object_ref (widget);
6404 return_val = handler (widget, event);
6405 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6407 /* The widget that was originally to receive the event
6408 * handles motion hints, but the capturing widget might
6409 * not, so ensure we get further motion events.
6412 event->type == GDK_MOTION_NOTIFY &&
6413 event->motion.is_hint &&
6414 (gdk_window_get_events (event->any.window) &
6415 GDK_POINTER_MOTION_HINT_MASK) != 0)
6416 gdk_event_request_motions (&event->motion);
6418 g_object_unref (widget);
6423 /* Returns TRUE if a translation should be done */
6425 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6430 GdkWindow *w, *widget_window;
6432 if (!gtk_widget_get_has_window (widget))
6434 *x = -widget->priv->allocation.x;
6435 *y = -widget->priv->allocation.y;
6443 widget_window = gtk_widget_get_window (widget);
6445 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6448 gdk_window_get_position (w, &wx, &wy);
6465 * gtk_cairo_transform_to_window:
6466 * @cr: the cairo context to transform
6467 * @widget: the widget the context is currently centered for
6468 * @window: the window to transform the context to
6470 * Transforms the given cairo context @cr that from @widget-relative
6471 * coordinates to @window-relative coordinates.
6472 * If the @widget's window is not an ancestor of @window, no
6473 * modification will be applied.
6475 * This is the inverse to the transformation GTK applies when
6476 * preparing an expose event to be emitted with the #GtkWidget::draw
6477 * signal. It is intended to help porting multiwindow widgets from
6478 * GTK+ 2 to the rendering architecture of GTK+ 3.
6483 gtk_cairo_transform_to_window (cairo_t *cr,
6489 g_return_if_fail (cr != NULL);
6490 g_return_if_fail (GTK_IS_WIDGET (widget));
6491 g_return_if_fail (GDK_IS_WINDOW (window));
6493 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6494 cairo_translate (cr, x, y);
6498 * gtk_widget_send_expose:
6499 * @widget: a #GtkWidget
6500 * @event: a expose #GdkEvent
6502 * Very rarely-used function. This function is used to emit
6503 * an expose event on a widget. This function is not normally used
6504 * directly. The only time it is used is when propagating an expose
6505 * event to a child %NO_WINDOW widget, and that is normally done
6506 * using gtk_container_propagate_draw().
6508 * If you want to force an area of a window to be redrawn,
6509 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6510 * To cause the redraw to be done immediately, follow that call
6511 * with a call to gdk_window_process_updates().
6513 * Return value: return from the event signal emission (%TRUE if
6514 * the event was handled)
6517 gtk_widget_send_expose (GtkWidget *widget,
6520 gboolean result = FALSE;
6525 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6526 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6527 g_return_val_if_fail (event != NULL, TRUE);
6528 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6530 cr = gdk_cairo_create (event->expose.window);
6531 gtk_cairo_set_event (cr, &event->expose);
6533 gdk_cairo_region (cr, event->expose.region);
6536 do_clip = _gtk_widget_get_translation_to_window (widget,
6537 event->expose.window,
6539 cairo_translate (cr, -x, -y);
6541 _gtk_widget_draw_internal (widget, cr, do_clip);
6543 /* unset here, so if someone keeps a reference to cr we
6544 * don't leak the window. */
6545 gtk_cairo_set_event (cr, NULL);
6552 event_window_is_still_viewable (GdkEvent *event)
6554 /* Check that we think the event's window is viewable before
6555 * delivering the event, to prevent suprises. We do this here
6556 * at the last moment, since the event may have been queued
6557 * up behind other events, held over a recursive main loop, etc.
6559 switch (event->type)
6562 case GDK_MOTION_NOTIFY:
6563 case GDK_BUTTON_PRESS:
6564 case GDK_2BUTTON_PRESS:
6565 case GDK_3BUTTON_PRESS:
6567 case GDK_ENTER_NOTIFY:
6568 case GDK_PROXIMITY_IN:
6570 return event->any.window && gdk_window_is_viewable (event->any.window);
6573 /* The following events are the second half of paired events;
6574 * we always deliver them to deal with widgets that clean up
6575 * on the second half.
6577 case GDK_BUTTON_RELEASE:
6578 case GDK_KEY_RELEASE:
6579 case GDK_LEAVE_NOTIFY:
6580 case GDK_PROXIMITY_OUT:
6584 /* Remaining events would make sense on an not-viewable window,
6585 * or don't have an associated window.
6592 gtk_widget_event_internal (GtkWidget *widget,
6595 gboolean return_val = FALSE;
6597 /* We check only once for is-still-visible; if someone
6598 * hides the window in on of the signals on the widget,
6599 * they are responsible for returning TRUE to terminate
6602 if (!event_window_is_still_viewable (event))
6605 g_object_ref (widget);
6607 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6608 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6613 switch (event->type)
6619 case GDK_BUTTON_PRESS:
6620 case GDK_2BUTTON_PRESS:
6621 case GDK_3BUTTON_PRESS:
6622 signal_num = BUTTON_PRESS_EVENT;
6624 case GDK_TOUCH_BEGIN:
6625 case GDK_TOUCH_UPDATE:
6627 case GDK_TOUCH_CANCEL:
6628 signal_num = TOUCH_EVENT;
6631 signal_num = SCROLL_EVENT;
6633 case GDK_BUTTON_RELEASE:
6634 signal_num = BUTTON_RELEASE_EVENT;
6636 case GDK_MOTION_NOTIFY:
6637 signal_num = MOTION_NOTIFY_EVENT;
6640 signal_num = DELETE_EVENT;
6643 signal_num = DESTROY_EVENT;
6644 _gtk_tooltip_hide (widget);
6647 signal_num = KEY_PRESS_EVENT;
6649 case GDK_KEY_RELEASE:
6650 signal_num = KEY_RELEASE_EVENT;
6652 case GDK_ENTER_NOTIFY:
6653 signal_num = ENTER_NOTIFY_EVENT;
6655 case GDK_LEAVE_NOTIFY:
6656 signal_num = LEAVE_NOTIFY_EVENT;
6658 case GDK_FOCUS_CHANGE:
6659 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6660 if (event->focus_change.in)
6661 _gtk_tooltip_focus_in (widget);
6663 _gtk_tooltip_focus_out (widget);
6666 signal_num = CONFIGURE_EVENT;
6669 signal_num = MAP_EVENT;
6672 signal_num = UNMAP_EVENT;
6674 case GDK_WINDOW_STATE:
6675 signal_num = WINDOW_STATE_EVENT;
6677 case GDK_PROPERTY_NOTIFY:
6678 signal_num = PROPERTY_NOTIFY_EVENT;
6680 case GDK_SELECTION_CLEAR:
6681 signal_num = SELECTION_CLEAR_EVENT;
6683 case GDK_SELECTION_REQUEST:
6684 signal_num = SELECTION_REQUEST_EVENT;
6686 case GDK_SELECTION_NOTIFY:
6687 signal_num = SELECTION_NOTIFY_EVENT;
6689 case GDK_PROXIMITY_IN:
6690 signal_num = PROXIMITY_IN_EVENT;
6692 case GDK_PROXIMITY_OUT:
6693 signal_num = PROXIMITY_OUT_EVENT;
6695 case GDK_VISIBILITY_NOTIFY:
6696 signal_num = VISIBILITY_NOTIFY_EVENT;
6698 case GDK_GRAB_BROKEN:
6699 signal_num = GRAB_BROKEN_EVENT;
6702 signal_num = DAMAGE_EVENT;
6705 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6709 if (signal_num != -1)
6710 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6712 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6713 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6717 g_object_unref (widget);
6723 * gtk_widget_activate:
6724 * @widget: a #GtkWidget that's activatable
6726 * For widgets that can be "activated" (buttons, menu items, etc.)
6727 * this function activates them. Activation is what happens when you
6728 * press Enter on a widget during key navigation. If @widget isn't
6729 * activatable, the function returns %FALSE.
6731 * Return value: %TRUE if the widget was activatable
6734 gtk_widget_activate (GtkWidget *widget)
6736 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6738 if (WIDGET_CLASS (widget)->activate_signal)
6740 /* FIXME: we should eventually check the signals signature here */
6741 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6750 gtk_widget_reparent_subwindows (GtkWidget *widget,
6751 GdkWindow *new_window)
6753 GtkWidgetPrivate *priv = widget->priv;
6755 if (!gtk_widget_get_has_window (widget))
6757 GList *children = gdk_window_get_children (priv->window);
6760 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6762 GdkWindow *window = tmp_list->data;
6765 gdk_window_get_user_data (window, &child);
6766 while (child && child != widget)
6767 child = ((GtkWidget*) child)->priv->parent;
6770 gdk_window_reparent (window, new_window, 0, 0);
6773 g_list_free (children);
6778 GList *tmp_list, *children;
6780 parent = gdk_window_get_parent (priv->window);
6783 gdk_window_reparent (priv->window, new_window, 0, 0);
6786 children = gdk_window_get_children (parent);
6788 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6790 GdkWindow *window = tmp_list->data;
6793 gdk_window_get_user_data (window, &child);
6795 if (child == widget)
6796 gdk_window_reparent (window, new_window, 0, 0);
6799 g_list_free (children);
6805 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6806 gpointer client_data)
6808 GtkWidgetPrivate *priv = widget->priv;
6810 g_assert (client_data != NULL);
6812 if (!gtk_widget_get_has_window (widget))
6815 g_object_unref (priv->window);
6816 priv->window = (GdkWindow*) client_data;
6818 g_object_ref (priv->window);
6820 if (GTK_IS_CONTAINER (widget))
6821 gtk_container_forall (GTK_CONTAINER (widget),
6822 gtk_widget_reparent_fixup_child,
6828 * gtk_widget_reparent:
6829 * @widget: a #GtkWidget
6830 * @new_parent: a #GtkContainer to move the widget into
6832 * Moves a widget from one #GtkContainer to another, handling reference
6833 * count issues to avoid destroying the widget.
6836 gtk_widget_reparent (GtkWidget *widget,
6837 GtkWidget *new_parent)
6839 GtkWidgetPrivate *priv;
6841 g_return_if_fail (GTK_IS_WIDGET (widget));
6842 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6843 priv = widget->priv;
6844 g_return_if_fail (priv->parent != NULL);
6846 if (priv->parent != new_parent)
6848 /* First try to see if we can get away without unrealizing
6849 * the widget as we reparent it. if so we set a flag so
6850 * that gtk_widget_unparent doesn't unrealize widget
6852 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6853 priv->in_reparent = TRUE;
6855 g_object_ref (widget);
6856 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6857 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6858 g_object_unref (widget);
6860 if (priv->in_reparent)
6862 priv->in_reparent = FALSE;
6864 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6865 gtk_widget_reparent_fixup_child (widget,
6866 gtk_widget_get_parent_window (widget));
6869 g_object_notify (G_OBJECT (widget), "parent");
6874 * gtk_widget_intersect:
6875 * @widget: a #GtkWidget
6876 * @area: a rectangle
6877 * @intersection: rectangle to store intersection of @widget and @area
6879 * Computes the intersection of a @widget's area and @area, storing
6880 * the intersection in @intersection, and returns %TRUE if there was
6881 * an intersection. @intersection may be %NULL if you're only
6882 * interested in whether there was an intersection.
6884 * Return value: %TRUE if there was an intersection
6887 gtk_widget_intersect (GtkWidget *widget,
6888 const GdkRectangle *area,
6889 GdkRectangle *intersection)
6891 GtkWidgetPrivate *priv;
6896 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6897 g_return_val_if_fail (area != NULL, FALSE);
6899 priv = widget->priv;
6902 dest = intersection;
6906 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6908 if (return_val && intersection && gtk_widget_get_has_window (widget))
6910 intersection->x -= priv->allocation.x;
6911 intersection->y -= priv->allocation.y;
6918 * gtk_widget_region_intersect:
6919 * @widget: a #GtkWidget
6920 * @region: a #cairo_region_t, in the same coordinate system as
6921 * @widget->allocation. That is, relative to @widget->window
6922 * for %NO_WINDOW widgets; relative to the parent window
6923 * of @widget->window for widgets with their own window.
6925 * Computes the intersection of a @widget's area and @region, returning
6926 * the intersection. The result may be empty, use cairo_region_is_empty() to
6929 * Returns: A newly allocated region holding the intersection of @widget
6930 * and @region. The coordinates of the return value are relative to
6931 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6932 * window of @widget->window for widgets with their own window.
6935 gtk_widget_region_intersect (GtkWidget *widget,
6936 const cairo_region_t *region)
6939 cairo_region_t *dest;
6941 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6942 g_return_val_if_fail (region != NULL, NULL);
6944 gtk_widget_get_allocation (widget, &rect);
6946 dest = cairo_region_create_rectangle (&rect);
6948 cairo_region_intersect (dest, region);
6954 * _gtk_widget_grab_notify:
6955 * @widget: a #GtkWidget
6956 * @was_grabbed: whether a grab is now in effect
6958 * Emits the #GtkWidget::grab-notify signal on @widget.
6963 _gtk_widget_grab_notify (GtkWidget *widget,
6964 gboolean was_grabbed)
6966 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6970 * gtk_widget_grab_focus:
6971 * @widget: a #GtkWidget
6973 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6974 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6975 * something like #GtkFrame won't work.
6977 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6978 * gtk_widget_set_can_focus() to modify that flag.
6980 * The widget also needs to be realized and mapped. This is indicated by the
6981 * related signals. Grabbing the focus immediately after creating the widget
6982 * will likely fail and cause critical warnings.
6985 gtk_widget_grab_focus (GtkWidget *widget)
6987 g_return_if_fail (GTK_IS_WIDGET (widget));
6989 if (!gtk_widget_is_sensitive (widget))
6992 g_object_ref (widget);
6993 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6994 g_object_notify (G_OBJECT (widget), "has-focus");
6995 g_object_unref (widget);
6999 reset_focus_recurse (GtkWidget *widget,
7002 if (GTK_IS_CONTAINER (widget))
7004 GtkContainer *container;
7006 container = GTK_CONTAINER (widget);
7007 gtk_container_set_focus_child (container, NULL);
7009 gtk_container_foreach (container,
7010 reset_focus_recurse,
7016 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
7018 if (gtk_widget_get_can_focus (focus_widget))
7020 GtkWidget *toplevel;
7023 /* clear the current focus setting, break if the current widget
7024 * is the focus widget's parent, since containers above that will
7025 * be set by the next loop.
7027 toplevel = gtk_widget_get_toplevel (focus_widget);
7028 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
7030 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
7032 if (widget == focus_widget)
7034 /* We call _gtk_window_internal_set_focus() here so that the
7035 * toplevel window can request the focus if necessary.
7036 * This is needed when the toplevel is a GtkPlug
7038 if (!gtk_widget_has_focus (widget))
7039 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
7046 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
7048 if (widget != common_ancestor)
7050 while (widget->priv->parent && widget->priv->parent != common_ancestor)
7052 widget = widget->priv->parent;
7053 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
7058 else if (toplevel != focus_widget)
7060 /* gtk_widget_grab_focus() operates on a tree without window...
7061 * actually, this is very questionable behaviour.
7064 gtk_container_foreach (GTK_CONTAINER (toplevel),
7065 reset_focus_recurse,
7069 /* now propagate the new focus up the widget tree and finally
7070 * set it on the window
7072 widget = focus_widget;
7073 while (widget->priv->parent)
7075 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
7076 widget = widget->priv->parent;
7078 if (GTK_IS_WINDOW (widget))
7079 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
7084 gtk_widget_real_query_tooltip (GtkWidget *widget,
7087 gboolean keyboard_tip,
7088 GtkTooltip *tooltip)
7090 gchar *tooltip_markup;
7091 gboolean has_tooltip;
7093 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
7094 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
7096 if (has_tooltip && tooltip_markup)
7098 gtk_tooltip_set_markup (tooltip, tooltip_markup);
7106 gtk_widget_real_state_flags_changed (GtkWidget *widget,
7107 GtkStateFlags old_state)
7109 gtk_widget_update_pango_context (widget);
7113 gtk_widget_real_style_updated (GtkWidget *widget)
7115 GtkWidgetPrivate *priv = widget->priv;
7117 gtk_widget_update_pango_context (widget);
7118 gtk_widget_update_alpha (widget);
7120 if (priv->style != NULL &&
7121 priv->style != gtk_widget_get_default_style ())
7123 /* Trigger ::style-set for old
7124 * widgets not listening to this
7126 g_signal_emit (widget,
7127 widget_signals[STYLE_SET],
7129 widget->priv->style);
7132 if (widget->priv->context)
7134 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
7136 if (gtk_widget_get_realized (widget) &&
7137 gtk_widget_get_has_window (widget) &&
7138 !gtk_widget_get_app_paintable (widget))
7139 gtk_style_context_set_background (widget->priv->context,
7140 widget->priv->window);
7142 if (widget->priv->anchored)
7144 if (changes && _gtk_css_style_property_changes_affect_size (changes))
7145 gtk_widget_queue_resize (widget);
7147 gtk_widget_queue_draw (widget);
7152 if (widget->priv->anchored)
7153 gtk_widget_queue_resize (widget);
7158 gtk_widget_real_show_help (GtkWidget *widget,
7159 GtkWidgetHelpType help_type)
7161 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
7163 _gtk_tooltip_toggle_keyboard_mode (widget);
7172 gtk_widget_real_focus (GtkWidget *widget,
7173 GtkDirectionType direction)
7175 if (!gtk_widget_get_can_focus (widget))
7178 if (!gtk_widget_is_focus (widget))
7180 gtk_widget_grab_focus (widget);
7188 gtk_widget_real_move_focus (GtkWidget *widget,
7189 GtkDirectionType direction)
7191 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7193 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
7195 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
7201 gtk_widget_real_keynav_failed (GtkWidget *widget,
7202 GtkDirectionType direction)
7204 gboolean cursor_only;
7208 case GTK_DIR_TAB_FORWARD:
7209 case GTK_DIR_TAB_BACKWARD:
7216 g_object_get (gtk_widget_get_settings (widget),
7217 "gtk-keynav-cursor-only", &cursor_only,
7224 gtk_widget_error_bell (widget);
7230 * gtk_widget_set_can_focus:
7231 * @widget: a #GtkWidget
7232 * @can_focus: whether or not @widget can own the input focus.
7234 * Specifies whether @widget can own the input focus. See
7235 * gtk_widget_grab_focus() for actually setting the input focus on a
7241 gtk_widget_set_can_focus (GtkWidget *widget,
7244 g_return_if_fail (GTK_IS_WIDGET (widget));
7246 if (widget->priv->can_focus != can_focus)
7248 widget->priv->can_focus = can_focus;
7250 gtk_widget_queue_resize (widget);
7251 g_object_notify (G_OBJECT (widget), "can-focus");
7256 * gtk_widget_get_can_focus:
7257 * @widget: a #GtkWidget
7259 * Determines whether @widget can own the input focus. See
7260 * gtk_widget_set_can_focus().
7262 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
7267 gtk_widget_get_can_focus (GtkWidget *widget)
7269 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7271 return widget->priv->can_focus;
7275 * gtk_widget_has_focus:
7276 * @widget: a #GtkWidget
7278 * Determines if the widget has the global input focus. See
7279 * gtk_widget_is_focus() for the difference between having the global
7280 * input focus, and only having the focus within a toplevel.
7282 * Return value: %TRUE if the widget has the global input focus.
7287 gtk_widget_has_focus (GtkWidget *widget)
7289 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7291 return widget->priv->has_focus;
7295 * gtk_widget_has_visible_focus:
7296 * @widget: a #GtkWidget
7298 * Determines if the widget should show a visible indication that
7299 * it has the global input focus. This is a convenience function for
7300 * use in ::draw handlers that takes into account whether focus
7301 * indication should currently be shown in the toplevel window of
7302 * @widget. See gtk_window_get_focus_visible() for more information
7303 * about focus indication.
7305 * To find out if the widget has the global input focus, use
7306 * gtk_widget_has_focus().
7308 * Return value: %TRUE if the widget should display a 'focus rectangle'
7313 gtk_widget_has_visible_focus (GtkWidget *widget)
7315 gboolean draw_focus;
7317 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7319 if (widget->priv->has_focus)
7321 GtkWidget *toplevel;
7323 toplevel = gtk_widget_get_toplevel (widget);
7325 if (GTK_IS_WINDOW (toplevel))
7326 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7337 * gtk_widget_is_focus:
7338 * @widget: a #GtkWidget
7340 * Determines if the widget is the focus widget within its
7341 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7342 * necessarily set; %HAS_FOCUS will only be set if the
7343 * toplevel widget additionally has the global input focus.)
7345 * Return value: %TRUE if the widget is the focus widget.
7348 gtk_widget_is_focus (GtkWidget *widget)
7350 GtkWidget *toplevel;
7352 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7354 toplevel = gtk_widget_get_toplevel (widget);
7356 if (GTK_IS_WINDOW (toplevel))
7357 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7363 * gtk_widget_set_can_default:
7364 * @widget: a #GtkWidget
7365 * @can_default: whether or not @widget can be a default widget.
7367 * Specifies whether @widget can be a default widget. See
7368 * gtk_widget_grab_default() for details about the meaning of
7374 gtk_widget_set_can_default (GtkWidget *widget,
7375 gboolean can_default)
7377 g_return_if_fail (GTK_IS_WIDGET (widget));
7379 if (widget->priv->can_default != can_default)
7381 widget->priv->can_default = can_default;
7383 gtk_widget_queue_resize (widget);
7384 g_object_notify (G_OBJECT (widget), "can-default");
7389 * gtk_widget_get_can_default:
7390 * @widget: a #GtkWidget
7392 * Determines whether @widget can be a default widget. See
7393 * gtk_widget_set_can_default().
7395 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7400 gtk_widget_get_can_default (GtkWidget *widget)
7402 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7404 return widget->priv->can_default;
7408 * gtk_widget_has_default:
7409 * @widget: a #GtkWidget
7411 * Determines whether @widget is the current default widget within its
7412 * toplevel. See gtk_widget_set_can_default().
7414 * Return value: %TRUE if @widget is the current default widget within
7415 * its toplevel, %FALSE otherwise
7420 gtk_widget_has_default (GtkWidget *widget)
7422 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7424 return widget->priv->has_default;
7428 _gtk_widget_set_has_default (GtkWidget *widget,
7429 gboolean has_default)
7431 GtkStyleContext *context;
7433 widget->priv->has_default = has_default;
7435 context = gtk_widget_get_style_context (widget);
7438 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7440 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7444 * gtk_widget_grab_default:
7445 * @widget: a #GtkWidget
7447 * Causes @widget to become the default widget. @widget must be able to be
7448 * a default widget; typically you would ensure this yourself
7449 * by calling gtk_widget_set_can_default() with a %TRUE value.
7450 * The default widget is activated when
7451 * the user presses Enter in a window. Default widgets must be
7452 * activatable, that is, gtk_widget_activate() should affect them. Note
7453 * that #GtkEntry widgets require the "activates-default" property
7454 * set to %TRUE before they activate the default widget when Enter
7455 * is pressed and the #GtkEntry is focused.
7458 gtk_widget_grab_default (GtkWidget *widget)
7462 g_return_if_fail (GTK_IS_WIDGET (widget));
7463 g_return_if_fail (gtk_widget_get_can_default (widget));
7465 window = gtk_widget_get_toplevel (widget);
7467 if (window && gtk_widget_is_toplevel (window))
7468 gtk_window_set_default (GTK_WINDOW (window), widget);
7470 g_warning (G_STRLOC ": widget not within a GtkWindow");
7474 * gtk_widget_set_receives_default:
7475 * @widget: a #GtkWidget
7476 * @receives_default: whether or not @widget can be a default widget.
7478 * Specifies whether @widget will be treated as the default widget
7479 * within its toplevel when it has the focus, even if another widget
7482 * See gtk_widget_grab_default() for details about the meaning of
7488 gtk_widget_set_receives_default (GtkWidget *widget,
7489 gboolean receives_default)
7491 g_return_if_fail (GTK_IS_WIDGET (widget));
7493 if (widget->priv->receives_default != receives_default)
7495 widget->priv->receives_default = receives_default;
7497 g_object_notify (G_OBJECT (widget), "receives-default");
7502 * gtk_widget_get_receives_default:
7503 * @widget: a #GtkWidget
7505 * Determines whether @widget is alyways treated as default widget
7506 * withing its toplevel when it has the focus, even if another widget
7509 * See gtk_widget_set_receives_default().
7511 * Return value: %TRUE if @widget acts as default widget when focussed,
7517 gtk_widget_get_receives_default (GtkWidget *widget)
7519 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7521 return widget->priv->receives_default;
7525 * gtk_widget_has_grab:
7526 * @widget: a #GtkWidget
7528 * Determines whether the widget is currently grabbing events, so it
7529 * is the only widget receiving input events (keyboard and mouse).
7531 * See also gtk_grab_add().
7533 * Return value: %TRUE if the widget is in the grab_widgets stack
7538 gtk_widget_has_grab (GtkWidget *widget)
7540 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7542 return widget->priv->has_grab;
7546 _gtk_widget_set_has_grab (GtkWidget *widget,
7549 widget->priv->has_grab = has_grab;
7553 * gtk_widget_device_is_shadowed:
7554 * @widget: a #GtkWidget
7555 * @device: a #GdkDevice
7557 * Returns %TRUE if @device has been shadowed by a GTK+
7558 * device grab on another widget, so it would stop sending
7559 * events to @widget. This may be used in the
7560 * #GtkWidget::grab-notify signal to check for specific
7561 * devices. See gtk_device_grab_add().
7563 * Returns: %TRUE if there is an ongoing grab on @device
7564 * by another #GtkWidget than @widget.
7569 gtk_widget_device_is_shadowed (GtkWidget *widget,
7572 GtkWindowGroup *group;
7573 GtkWidget *grab_widget, *toplevel;
7575 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7576 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7578 if (!gtk_widget_get_realized (widget))
7581 toplevel = gtk_widget_get_toplevel (widget);
7583 if (GTK_IS_WINDOW (toplevel))
7584 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7586 group = gtk_window_get_group (NULL);
7588 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7590 /* Widget not inside the hierarchy of grab_widget */
7592 widget != grab_widget &&
7593 !gtk_widget_is_ancestor (widget, grab_widget))
7596 grab_widget = gtk_window_group_get_current_grab (group);
7597 if (grab_widget && widget != grab_widget &&
7598 !gtk_widget_is_ancestor (widget, grab_widget))
7605 * gtk_widget_set_name:
7606 * @widget: a #GtkWidget
7607 * @name: name for the widget
7609 * Widgets can be named, which allows you to refer to them from a
7610 * CSS file. You can apply a style to widgets with a particular name
7611 * in the CSS file. See the documentation for the CSS syntax (on the
7612 * same page as the docs for #GtkStyleContext).
7614 * Note that the CSS syntax has certain special characters to delimit
7615 * and represent elements in a selector (period, #, >, *...),
7616 * so using these will make your widget impossible to match by name.
7617 * Any combination of alphanumeric symbols, dashes and underscores will
7621 gtk_widget_set_name (GtkWidget *widget,
7624 GtkWidgetPrivate *priv;
7627 g_return_if_fail (GTK_IS_WIDGET (widget));
7629 priv = widget->priv;
7631 new_name = g_strdup (name);
7632 g_free (priv->name);
7633 priv->name = new_name;
7635 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7637 g_object_notify (G_OBJECT (widget), "name");
7641 * gtk_widget_get_name:
7642 * @widget: a #GtkWidget
7644 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7645 * significance of widget names.
7647 * Return value: name of the widget. This string is owned by GTK+ and
7648 * should not be modified or freed
7651 gtk_widget_get_name (GtkWidget *widget)
7653 GtkWidgetPrivate *priv;
7655 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7657 priv = widget->priv;
7661 return G_OBJECT_TYPE_NAME (widget);
7665 gtk_widget_update_state_flags (GtkWidget *widget,
7666 GtkStateFlags flags_to_set,
7667 GtkStateFlags flags_to_unset)
7669 GtkWidgetPrivate *priv;
7671 priv = widget->priv;
7673 /* Handle insensitive first, since it is propagated
7674 * differently throughout the widget hierarchy.
7676 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7677 gtk_widget_set_sensitive (widget, TRUE);
7678 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7679 gtk_widget_set_sensitive (widget, FALSE);
7681 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7682 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7684 if (flags_to_set != 0 || flags_to_unset != 0)
7688 data.flags_to_set = flags_to_set;
7689 data.flags_to_unset = flags_to_unset;
7691 gtk_widget_propagate_state (widget, &data);
7696 * gtk_widget_set_state_flags:
7697 * @widget: a #GtkWidget
7698 * @flags: State flags to turn on
7699 * @clear: Whether to clear state before turning on @flags
7701 * This function is for use in widget implementations. Turns on flag
7702 * values in the current widget state (insensitive, prelighted, etc.).
7704 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7705 * will be propagated down to all non-internal children if @widget is a
7706 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7707 * down to all #GtkContainer children by different means than turning on the
7708 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7709 * gtk_widget_is_sensitive() will make use of these.
7714 gtk_widget_set_state_flags (GtkWidget *widget,
7715 GtkStateFlags flags,
7718 g_return_if_fail (GTK_IS_WIDGET (widget));
7720 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7721 (clear && widget->priv->state_flags == flags))
7725 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7727 gtk_widget_update_state_flags (widget, flags, 0);
7731 * gtk_widget_unset_state_flags:
7732 * @widget: a #GtkWidget
7733 * @flags: State flags to turn off
7735 * This function is for use in widget implementations. Turns off flag
7736 * values for the current widget state (insensitive, prelighted, etc.).
7737 * See gtk_widget_set_state_flags().
7742 gtk_widget_unset_state_flags (GtkWidget *widget,
7743 GtkStateFlags flags)
7745 g_return_if_fail (GTK_IS_WIDGET (widget));
7747 if ((widget->priv->state_flags & flags) == 0)
7750 gtk_widget_update_state_flags (widget, 0, flags);
7754 * gtk_widget_get_state_flags:
7755 * @widget: a #GtkWidget
7757 * Returns the widget state as a flag set. It is worth mentioning
7758 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7759 * returned, that is, also based on parent insensitivity, even if
7760 * @widget itself is sensitive.
7762 * Returns: The state flags for widget
7767 gtk_widget_get_state_flags (GtkWidget *widget)
7769 GtkStateFlags flags;
7771 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7773 flags = widget->priv->state_flags;
7775 if (gtk_widget_has_focus (widget))
7776 flags |= GTK_STATE_FLAG_FOCUSED;
7782 * gtk_widget_set_state:
7783 * @widget: a #GtkWidget
7784 * @state: new state for @widget
7786 * This function is for use in widget implementations. Sets the state
7787 * of a widget (insensitive, prelighted, etc.) Usually you should set
7788 * the state using wrapper functions such as gtk_widget_set_sensitive().
7790 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7793 gtk_widget_set_state (GtkWidget *widget,
7796 GtkStateFlags flags;
7798 if (state == gtk_widget_get_state (widget))
7803 case GTK_STATE_ACTIVE:
7804 flags = GTK_STATE_FLAG_ACTIVE;
7806 case GTK_STATE_PRELIGHT:
7807 flags = GTK_STATE_FLAG_PRELIGHT;
7809 case GTK_STATE_SELECTED:
7810 flags = GTK_STATE_FLAG_SELECTED;
7812 case GTK_STATE_INSENSITIVE:
7813 flags = GTK_STATE_FLAG_INSENSITIVE;
7815 case GTK_STATE_INCONSISTENT:
7816 flags = GTK_STATE_FLAG_INCONSISTENT;
7818 case GTK_STATE_FOCUSED:
7819 flags = GTK_STATE_FLAG_FOCUSED;
7821 case GTK_STATE_NORMAL:
7827 gtk_widget_update_state_flags (widget,
7829 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7830 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7834 * gtk_widget_get_state:
7835 * @widget: a #GtkWidget
7837 * Returns the widget's state. See gtk_widget_set_state().
7839 * Returns: the state of @widget.
7843 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7846 gtk_widget_get_state (GtkWidget *widget)
7848 GtkStateFlags flags;
7850 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7852 flags = gtk_widget_get_state_flags (widget);
7854 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7855 return GTK_STATE_INSENSITIVE;
7856 else if (flags & GTK_STATE_FLAG_ACTIVE)
7857 return GTK_STATE_ACTIVE;
7858 else if (flags & GTK_STATE_FLAG_SELECTED)
7859 return GTK_STATE_SELECTED;
7860 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7861 return GTK_STATE_PRELIGHT;
7863 return GTK_STATE_NORMAL;
7867 * gtk_widget_set_visible:
7868 * @widget: a #GtkWidget
7869 * @visible: whether the widget should be shown or not
7871 * Sets the visibility state of @widget. Note that setting this to
7872 * %TRUE doesn't mean the widget is actually viewable, see
7873 * gtk_widget_get_visible().
7875 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7876 * but is nicer to use when the visibility of the widget depends on
7882 gtk_widget_set_visible (GtkWidget *widget,
7885 g_return_if_fail (GTK_IS_WIDGET (widget));
7887 if (visible != gtk_widget_get_visible (widget))
7890 gtk_widget_show (widget);
7892 gtk_widget_hide (widget);
7897 _gtk_widget_set_visible_flag (GtkWidget *widget,
7900 GtkWidgetPrivate *priv = widget->priv;
7902 priv->visible = visible;
7906 priv->allocation.x = -1;
7907 priv->allocation.y = -1;
7908 priv->allocation.width = 1;
7909 priv->allocation.height = 1;
7914 * gtk_widget_get_visible:
7915 * @widget: a #GtkWidget
7917 * Determines whether the widget is visible. If you want to
7918 * take into account whether the widget's parent is also marked as
7919 * visible, use gtk_widget_is_visible() instead.
7921 * This function does not check if the widget is obscured in any way.
7923 * See gtk_widget_set_visible().
7925 * Return value: %TRUE if the widget is visible
7930 gtk_widget_get_visible (GtkWidget *widget)
7932 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7934 return widget->priv->visible;
7938 * gtk_widget_is_visible:
7939 * @widget: a #GtkWidget
7941 * Determines whether the widget and all its parents are marked as
7944 * This function does not check if the widget is obscured in any way.
7946 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7948 * Return value: %TRUE if the widget and all its parents are visible
7953 gtk_widget_is_visible (GtkWidget *widget)
7955 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7959 GtkWidgetPrivate *priv = widget->priv;
7964 widget = priv->parent;
7971 * gtk_widget_set_has_window:
7972 * @widget: a #GtkWidget
7973 * @has_window: whether or not @widget has a window.
7975 * Specifies whether @widget has a #GdkWindow of its own. Note that
7976 * all realized widgets have a non-%NULL "window" pointer
7977 * (gtk_widget_get_window() never returns a %NULL window when a widget
7978 * is realized), but for many of them it's actually the #GdkWindow of
7979 * one of its parent widgets. Widgets that do not create a %window for
7980 * themselves in #GtkWidget::realize must announce this by
7981 * calling this function with @has_window = %FALSE.
7983 * This function should only be called by widget implementations,
7984 * and they should call it in their init() function.
7989 gtk_widget_set_has_window (GtkWidget *widget,
7990 gboolean has_window)
7992 g_return_if_fail (GTK_IS_WIDGET (widget));
7994 widget->priv->no_window = !has_window;
7998 * gtk_widget_get_has_window:
7999 * @widget: a #GtkWidget
8001 * Determines whether @widget has a #GdkWindow of its own. See
8002 * gtk_widget_set_has_window().
8004 * Return value: %TRUE if @widget has a window, %FALSE otherwise
8009 gtk_widget_get_has_window (GtkWidget *widget)
8011 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8013 return ! widget->priv->no_window;
8017 * gtk_widget_is_toplevel:
8018 * @widget: a #GtkWidget
8020 * Determines whether @widget is a toplevel widget.
8022 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
8023 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
8026 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
8031 gtk_widget_is_toplevel (GtkWidget *widget)
8033 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8035 return widget->priv->toplevel;
8039 _gtk_widget_set_is_toplevel (GtkWidget *widget,
8040 gboolean is_toplevel)
8042 widget->priv->toplevel = is_toplevel;
8046 * gtk_widget_is_drawable:
8047 * @widget: a #GtkWidget
8049 * Determines whether @widget can be drawn to. A widget can be drawn
8050 * to if it is mapped and visible.
8052 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
8057 gtk_widget_is_drawable (GtkWidget *widget)
8059 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8061 return (gtk_widget_get_visible (widget) &&
8062 gtk_widget_get_mapped (widget));
8066 * gtk_widget_get_realized:
8067 * @widget: a #GtkWidget
8069 * Determines whether @widget is realized.
8071 * Return value: %TRUE if @widget is realized, %FALSE otherwise
8076 gtk_widget_get_realized (GtkWidget *widget)
8078 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8080 return widget->priv->realized;
8084 * gtk_widget_set_realized:
8085 * @widget: a #GtkWidget
8086 * @realized: %TRUE to mark the widget as realized
8088 * Marks the widget as being realized.
8090 * This function should only ever be called in a derived widget's
8091 * "realize" or "unrealize" implementation.
8096 gtk_widget_set_realized (GtkWidget *widget,
8099 g_return_if_fail (GTK_IS_WIDGET (widget));
8101 widget->priv->realized = realized;
8105 * gtk_widget_get_mapped:
8106 * @widget: a #GtkWidget
8108 * Whether the widget is mapped.
8110 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
8115 gtk_widget_get_mapped (GtkWidget *widget)
8117 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8119 return widget->priv->mapped;
8123 * gtk_widget_set_mapped:
8124 * @widget: a #GtkWidget
8125 * @mapped: %TRUE to mark the widget as mapped
8127 * Marks the widget as being realized.
8129 * This function should only ever be called in a derived widget's
8130 * "map" or "unmap" implementation.
8135 gtk_widget_set_mapped (GtkWidget *widget,
8138 g_return_if_fail (GTK_IS_WIDGET (widget));
8140 widget->priv->mapped = mapped;
8144 * gtk_widget_set_app_paintable:
8145 * @widget: a #GtkWidget
8146 * @app_paintable: %TRUE if the application will paint on the widget
8148 * Sets whether the application intends to draw on the widget in
8149 * an #GtkWidget::draw handler.
8151 * This is a hint to the widget and does not affect the behavior of
8152 * the GTK+ core; many widgets ignore this flag entirely. For widgets
8153 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
8154 * the effect is to suppress default themed drawing of the widget's
8155 * background. (Children of the widget will still be drawn.) The application
8156 * is then entirely responsible for drawing the widget background.
8158 * Note that the background is still drawn when the widget is mapped.
8161 gtk_widget_set_app_paintable (GtkWidget *widget,
8162 gboolean app_paintable)
8164 g_return_if_fail (GTK_IS_WIDGET (widget));
8166 app_paintable = (app_paintable != FALSE);
8168 if (widget->priv->app_paintable != app_paintable)
8170 widget->priv->app_paintable = app_paintable;
8172 if (gtk_widget_is_drawable (widget))
8173 gtk_widget_queue_draw (widget);
8175 g_object_notify (G_OBJECT (widget), "app-paintable");
8180 * gtk_widget_get_app_paintable:
8181 * @widget: a #GtkWidget
8183 * Determines whether the application intends to draw on the widget in
8184 * an #GtkWidget::draw handler.
8186 * See gtk_widget_set_app_paintable()
8188 * Return value: %TRUE if the widget is app paintable
8193 gtk_widget_get_app_paintable (GtkWidget *widget)
8195 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8197 return widget->priv->app_paintable;
8201 * gtk_widget_set_double_buffered:
8202 * @widget: a #GtkWidget
8203 * @double_buffered: %TRUE to double-buffer a widget
8205 * Widgets are double buffered by default; you can use this function
8206 * to turn off the buffering. "Double buffered" simply means that
8207 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
8208 * automatically around expose events sent to the
8209 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
8210 * window to an offscreen buffer, and gdk_window_end_paint() draws the
8211 * buffer to the screen. The result is that users see the window
8212 * update in one smooth step, and don't see individual graphics
8213 * primitives being rendered.
8215 * In very simple terms, double buffered widgets don't flicker,
8216 * so you would only use this function to turn off double buffering
8217 * if you had special needs and really knew what you were doing.
8219 * Note: if you turn off double-buffering, you have to handle
8220 * expose events, since even the clearing to the background color or
8221 * pixmap will not happen automatically (as it is done in
8222 * gdk_window_begin_paint_region()).
8225 gtk_widget_set_double_buffered (GtkWidget *widget,
8226 gboolean double_buffered)
8228 g_return_if_fail (GTK_IS_WIDGET (widget));
8230 double_buffered = (double_buffered != FALSE);
8232 if (widget->priv->double_buffered != double_buffered)
8234 widget->priv->double_buffered = double_buffered;
8236 g_object_notify (G_OBJECT (widget), "double-buffered");
8241 * gtk_widget_get_double_buffered:
8242 * @widget: a #GtkWidget
8244 * Determines whether the widget is double buffered.
8246 * See gtk_widget_set_double_buffered()
8248 * Return value: %TRUE if the widget is double buffered
8253 gtk_widget_get_double_buffered (GtkWidget *widget)
8255 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8257 return widget->priv->double_buffered;
8261 * gtk_widget_set_redraw_on_allocate:
8262 * @widget: a #GtkWidget
8263 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
8264 * when it is allocated to a new size. Otherwise, only the
8265 * new portion of the widget will be redrawn.
8267 * Sets whether the entire widget is queued for drawing when its size
8268 * allocation changes. By default, this setting is %TRUE and
8269 * the entire widget is redrawn on every size change. If your widget
8270 * leaves the upper left unchanged when made bigger, turning this
8271 * setting off will improve performance.
8273 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
8274 * off all allocation on resizing: the widget will not even redraw if
8275 * its position changes; this is to allow containers that don't draw
8276 * anything to avoid excess invalidations. If you set this flag on a
8277 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
8278 * you are responsible for invalidating both the old and new allocation
8279 * of the widget when the widget is moved and responsible for invalidating
8280 * regions newly when the widget increases size.
8283 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
8284 gboolean redraw_on_allocate)
8286 g_return_if_fail (GTK_IS_WIDGET (widget));
8288 widget->priv->redraw_on_alloc = redraw_on_allocate;
8292 * gtk_widget_set_sensitive:
8293 * @widget: a #GtkWidget
8294 * @sensitive: %TRUE to make the widget sensitive
8296 * Sets the sensitivity of a widget. A widget is sensitive if the user
8297 * can interact with it. Insensitive widgets are "grayed out" and the
8298 * user can't interact with them. Insensitive widgets are known as
8299 * "inactive", "disabled", or "ghosted" in some other toolkits.
8302 gtk_widget_set_sensitive (GtkWidget *widget,
8305 GtkWidgetPrivate *priv;
8307 g_return_if_fail (GTK_IS_WIDGET (widget));
8309 priv = widget->priv;
8311 sensitive = (sensitive != FALSE);
8313 if (priv->sensitive == sensitive)
8316 priv->sensitive = sensitive;
8318 if (priv->parent == NULL
8319 || gtk_widget_is_sensitive (priv->parent))
8325 data.flags_to_set = 0;
8326 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8330 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8331 data.flags_to_unset = 0;
8334 gtk_widget_propagate_state (widget, &data);
8336 gtk_widget_queue_resize (widget);
8339 g_object_notify (G_OBJECT (widget), "sensitive");
8343 * gtk_widget_get_sensitive:
8344 * @widget: a #GtkWidget
8346 * Returns the widget's sensitivity (in the sense of returning
8347 * the value that has been set using gtk_widget_set_sensitive()).
8349 * The effective sensitivity of a widget is however determined by both its
8350 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8352 * Returns: %TRUE if the widget is sensitive
8357 gtk_widget_get_sensitive (GtkWidget *widget)
8359 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8361 return widget->priv->sensitive;
8365 * gtk_widget_is_sensitive:
8366 * @widget: a #GtkWidget
8368 * Returns the widget's effective sensitivity, which means
8369 * it is sensitive itself and also its parent widget is sensitive
8371 * Returns: %TRUE if the widget is effectively sensitive
8376 gtk_widget_is_sensitive (GtkWidget *widget)
8378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8380 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8384 * gtk_widget_set_parent:
8385 * @widget: a #GtkWidget
8386 * @parent: parent container
8388 * This function is useful only when implementing subclasses of
8390 * Sets the container as the parent of @widget, and takes care of
8391 * some details such as updating the state and style of the child
8392 * to reflect its new location. The opposite function is
8393 * gtk_widget_unparent().
8396 gtk_widget_set_parent (GtkWidget *widget,
8399 GtkStateFlags parent_flags;
8400 GtkWidgetPrivate *priv;
8403 g_return_if_fail (GTK_IS_WIDGET (widget));
8404 g_return_if_fail (GTK_IS_WIDGET (parent));
8405 g_return_if_fail (widget != parent);
8407 priv = widget->priv;
8409 if (priv->parent != NULL)
8411 g_warning ("Can't set a parent on widget which has a parent\n");
8414 if (gtk_widget_is_toplevel (widget))
8416 g_warning ("Can't set a parent on a toplevel widget\n");
8420 /* keep this function in sync with gtk_menu_attach_to_widget()
8423 g_object_ref_sink (widget);
8425 gtk_widget_push_verify_invariants (widget);
8427 priv->parent = parent;
8429 parent_flags = gtk_widget_get_state_flags (parent);
8431 /* Merge both old state and current parent state,
8432 * making sure to only propagate the right states */
8433 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8434 data.flags_to_unset = 0;
8435 gtk_widget_propagate_state (widget, &data);
8438 gtk_style_context_set_parent (priv->context,
8439 gtk_widget_get_style_context (parent));
8441 _gtk_widget_update_parent_muxer (widget);
8443 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8444 if (priv->parent->priv->anchored)
8445 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8446 g_object_notify (G_OBJECT (widget), "parent");
8448 /* Enforce realized/mapped invariants
8450 if (gtk_widget_get_realized (priv->parent))
8451 gtk_widget_realize (widget);
8453 if (gtk_widget_get_visible (priv->parent) &&
8454 gtk_widget_get_visible (widget))
8456 if (gtk_widget_get_child_visible (widget) &&
8457 gtk_widget_get_mapped (priv->parent))
8458 gtk_widget_map (widget);
8460 gtk_widget_queue_resize (widget);
8463 /* child may cause parent's expand to change, if the child is
8464 * expanded. If child is not expanded, then it can't modify the
8465 * parent's expand. If the child becomes expanded later then it will
8466 * queue compute_expand then. This optimization plus defaulting
8467 * newly-constructed widgets to need_compute_expand=FALSE should
8468 * mean that initially building a widget tree doesn't have to keep
8469 * walking up setting need_compute_expand on parents over and over.
8471 * We can't change a parent to need to expand unless we're visible.
8473 if (gtk_widget_get_visible (widget) &&
8474 (priv->need_compute_expand ||
8475 priv->computed_hexpand ||
8476 priv->computed_vexpand))
8478 gtk_widget_queue_compute_expand (parent);
8481 gtk_widget_propagate_alpha (widget);
8483 gtk_widget_pop_verify_invariants (widget);
8487 * gtk_widget_get_parent:
8488 * @widget: a #GtkWidget
8490 * Returns the parent container of @widget.
8492 * Return value: (transfer none): the parent container of @widget, or %NULL
8495 gtk_widget_get_parent (GtkWidget *widget)
8497 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8499 return widget->priv->parent;
8503 modifier_style_changed (GtkModifierStyle *style,
8506 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8509 static GtkModifierStyle *
8510 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8512 GtkModifierStyle *style;
8514 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8516 if (G_UNLIKELY (!style))
8518 GtkStyleContext *context;
8520 style = _gtk_modifier_style_new ();
8521 g_object_set_qdata_full (G_OBJECT (widget),
8522 quark_modifier_style,
8524 (GDestroyNotify) g_object_unref);
8526 g_signal_connect (style, "changed",
8527 G_CALLBACK (modifier_style_changed), widget);
8529 context = gtk_widget_get_style_context (widget);
8531 gtk_style_context_add_provider (context,
8532 GTK_STYLE_PROVIDER (style),
8533 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8540 * gtk_widget_override_color:
8541 * @widget: a #GtkWidget
8542 * @state: the state for which to set the color
8543 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8544 * of previous calls to gtk_widget_override_color()
8546 * Sets the color to use for a widget.
8548 * All other style values are left untouched.
8551 * This API is mostly meant as a quick way for applications to
8552 * change a widget appearance. If you are developing a widgets
8553 * library and intend this change to be themeable, it is better
8554 * done by setting meaningful CSS classes and regions in your
8555 * widget/container implementation through gtk_style_context_add_class()
8556 * and gtk_style_context_add_region().
8558 * This way, your widget library can install a #GtkCssProvider
8559 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8560 * to provide a default styling for those widgets that need so, and
8561 * this theming may fully overridden by the user's theme.
8564 * Note that for complex widgets this may bring in undesired
8565 * results (such as uniform background color everywhere), in
8566 * these cases it is better to fully style such widgets through a
8567 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8574 gtk_widget_override_color (GtkWidget *widget,
8575 GtkStateFlags state,
8576 const GdkRGBA *color)
8578 GtkModifierStyle *style;
8580 g_return_if_fail (GTK_IS_WIDGET (widget));
8582 style = _gtk_widget_get_modifier_properties (widget);
8583 _gtk_modifier_style_set_color (style, state, color);
8587 * gtk_widget_override_background_color:
8588 * @widget: a #GtkWidget
8589 * @state: the state for which to set the background color
8590 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8591 * of previous calls to gtk_widget_override_background_color()
8593 * Sets the background color to use for a widget.
8595 * All other style values are left untouched.
8596 * See gtk_widget_override_color().
8601 gtk_widget_override_background_color (GtkWidget *widget,
8602 GtkStateFlags state,
8603 const GdkRGBA *color)
8605 GtkModifierStyle *style;
8607 g_return_if_fail (GTK_IS_WIDGET (widget));
8609 style = _gtk_widget_get_modifier_properties (widget);
8610 _gtk_modifier_style_set_background_color (style, state, color);
8614 * gtk_widget_override_font:
8615 * @widget: a #GtkWidget
8616 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8617 * the effect of previous calls to gtk_widget_override_font()
8619 * Sets the font to use for a widget. All other style values are
8620 * left untouched. See gtk_widget_override_color().
8625 gtk_widget_override_font (GtkWidget *widget,
8626 const PangoFontDescription *font_desc)
8628 GtkModifierStyle *style;
8630 g_return_if_fail (GTK_IS_WIDGET (widget));
8632 style = _gtk_widget_get_modifier_properties (widget);
8633 _gtk_modifier_style_set_font (style, font_desc);
8637 * gtk_widget_override_symbolic_color:
8638 * @widget: a #GtkWidget
8639 * @name: the name of the symbolic color to modify
8640 * @color: (allow-none): the color to assign (does not need
8641 * to be allocated), or %NULL to undo the effect of previous
8642 * calls to gtk_widget_override_symbolic_color()
8644 * Sets a symbolic color for a widget.
8646 * All other style values are left untouched.
8647 * See gtk_widget_override_color() for overriding the foreground
8648 * or background color.
8653 gtk_widget_override_symbolic_color (GtkWidget *widget,
8655 const GdkRGBA *color)
8657 GtkModifierStyle *style;
8659 g_return_if_fail (GTK_IS_WIDGET (widget));
8661 style = _gtk_widget_get_modifier_properties (widget);
8662 _gtk_modifier_style_map_color (style, name, color);
8666 * gtk_widget_override_cursor:
8667 * @widget: a #GtkWidget
8668 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8669 * allocated), or %NULL to undo the effect of previous calls to
8670 * of gtk_widget_override_cursor().
8671 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8672 * need to be allocated), or %NULL to undo the effect of previous
8673 * calls to of gtk_widget_override_cursor().
8675 * Sets the cursor color to use in a widget, overriding the
8676 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8677 * style properties. All other style values are left untouched.
8678 * See also gtk_widget_modify_style().
8680 * Note that the underlying properties have the #GdkColor type,
8681 * so the alpha value in @primary and @secondary will be ignored.
8686 gtk_widget_override_cursor (GtkWidget *widget,
8687 const GdkRGBA *cursor,
8688 const GdkRGBA *secondary_cursor)
8690 GtkModifierStyle *style;
8692 g_return_if_fail (GTK_IS_WIDGET (widget));
8694 style = _gtk_widget_get_modifier_properties (widget);
8695 _gtk_modifier_style_set_color_property (style,
8697 "cursor-color", cursor);
8698 _gtk_modifier_style_set_color_property (style,
8700 "secondary-cursor-color",
8705 gtk_widget_real_direction_changed (GtkWidget *widget,
8706 GtkTextDirection previous_direction)
8708 gtk_widget_queue_resize (widget);
8712 gtk_widget_real_style_set (GtkWidget *widget,
8713 GtkStyle *previous_style)
8718 GtkWidget *previous_toplevel;
8719 GdkScreen *previous_screen;
8720 GdkScreen *new_screen;
8721 } HierarchyChangedInfo;
8724 do_screen_change (GtkWidget *widget,
8725 GdkScreen *old_screen,
8726 GdkScreen *new_screen)
8728 if (old_screen != new_screen)
8730 GtkWidgetPrivate *priv = widget->priv;
8734 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8736 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8739 _gtk_tooltip_hide (widget);
8741 if (new_screen && priv->context)
8742 gtk_style_context_set_screen (priv->context, new_screen);
8744 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8749 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8750 gpointer client_data)
8752 GtkWidgetPrivate *priv = widget->priv;
8753 HierarchyChangedInfo *info = client_data;
8754 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8755 (priv->parent && priv->parent->priv->anchored);
8757 if (priv->anchored != new_anchored)
8759 g_object_ref (widget);
8761 priv->anchored = new_anchored;
8763 /* This can only happen with gtk_widget_reparent() */
8767 gtk_widget_connect_frame_clock (widget,
8768 gtk_widget_get_frame_clock (widget));
8770 gtk_widget_disconnect_frame_clock (widget,
8771 gtk_widget_get_frame_clock (info->previous_toplevel));
8774 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8775 do_screen_change (widget, info->previous_screen, info->new_screen);
8777 if (GTK_IS_CONTAINER (widget))
8778 gtk_container_forall (GTK_CONTAINER (widget),
8779 gtk_widget_propagate_hierarchy_changed_recurse,
8782 g_object_unref (widget);
8787 * _gtk_widget_propagate_hierarchy_changed:
8788 * @widget: a #GtkWidget
8789 * @previous_toplevel: Previous toplevel
8791 * Propagates changes in the anchored state to a widget and all
8792 * children, unsetting or setting the %ANCHORED flag, and
8793 * emitting #GtkWidget::hierarchy-changed.
8796 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8797 GtkWidget *previous_toplevel)
8799 GtkWidgetPrivate *priv = widget->priv;
8800 HierarchyChangedInfo info;
8802 info.previous_toplevel = previous_toplevel;
8803 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8805 if (gtk_widget_is_toplevel (widget) ||
8806 (priv->parent && priv->parent->priv->anchored))
8807 info.new_screen = gtk_widget_get_screen (widget);
8809 info.new_screen = NULL;
8811 if (info.previous_screen)
8812 g_object_ref (info.previous_screen);
8813 if (previous_toplevel)
8814 g_object_ref (previous_toplevel);
8816 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8818 if (previous_toplevel)
8819 g_object_unref (previous_toplevel);
8820 if (info.previous_screen)
8821 g_object_unref (info.previous_screen);
8825 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8826 gpointer client_data)
8828 HierarchyChangedInfo *info = client_data;
8830 g_object_ref (widget);
8832 do_screen_change (widget, info->previous_screen, info->new_screen);
8834 if (GTK_IS_CONTAINER (widget))
8835 gtk_container_forall (GTK_CONTAINER (widget),
8836 gtk_widget_propagate_screen_changed_recurse,
8839 g_object_unref (widget);
8843 * gtk_widget_is_composited:
8844 * @widget: a #GtkWidget
8846 * Whether @widget can rely on having its alpha channel
8847 * drawn correctly. On X11 this function returns whether a
8848 * compositing manager is running for @widget's screen.
8850 * Please note that the semantics of this call will change
8851 * in the future if used on a widget that has a composited
8852 * window in its hierarchy (as set by gdk_window_set_composited()).
8854 * Return value: %TRUE if the widget can rely on its alpha
8855 * channel being drawn correctly.
8860 gtk_widget_is_composited (GtkWidget *widget)
8864 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8866 screen = gtk_widget_get_screen (widget);
8868 return gdk_screen_is_composited (screen);
8872 propagate_composited_changed (GtkWidget *widget,
8875 if (GTK_IS_CONTAINER (widget))
8877 gtk_container_forall (GTK_CONTAINER (widget),
8878 propagate_composited_changed,
8882 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8886 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8888 propagate_composited_changed (widget, NULL);
8892 * _gtk_widget_propagate_screen_changed:
8893 * @widget: a #GtkWidget
8894 * @previous_screen: Previous screen
8896 * Propagates changes in the screen for a widget to all
8897 * children, emitting #GtkWidget::screen-changed.
8900 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8901 GdkScreen *previous_screen)
8903 HierarchyChangedInfo info;
8905 info.previous_screen = previous_screen;
8906 info.new_screen = gtk_widget_get_screen (widget);
8908 if (previous_screen)
8909 g_object_ref (previous_screen);
8911 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8913 if (previous_screen)
8914 g_object_unref (previous_screen);
8918 reset_style_recurse (GtkWidget *widget, gpointer data)
8920 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8922 if (GTK_IS_CONTAINER (widget))
8923 gtk_container_forall (GTK_CONTAINER (widget),
8924 reset_style_recurse,
8929 * gtk_widget_reset_style:
8930 * @widget: a #GtkWidget
8932 * Updates the style context of @widget and all descendents
8933 * by updating its widget path. #GtkContainer<!-- -->s may want
8934 * to use this on a child when reordering it in a way that a different
8935 * style might apply to it. See also gtk_container_get_path_for_child().
8940 gtk_widget_reset_style (GtkWidget *widget)
8942 g_return_if_fail (GTK_IS_WIDGET (widget));
8944 reset_style_recurse (widget, NULL);
8946 g_list_foreach (widget->priv->attached_windows,
8947 (GFunc) reset_style_recurse, NULL);
8950 #ifdef G_ENABLE_DEBUG
8952 /* Verify invariants, see docs/widget_system.txt for notes on much of
8953 * this. Invariants may be temporarily broken while we're in the
8954 * process of updating state, of course, so you can only
8955 * verify_invariants() after a given operation is complete.
8956 * Use push/pop_verify_invariants to help with that.
8959 gtk_widget_verify_invariants (GtkWidget *widget)
8963 if (widget->priv->verifying_invariants_count > 0)
8966 parent = widget->priv->parent;
8968 if (widget->priv->mapped)
8970 /* Mapped implies ... */
8972 if (!widget->priv->realized)
8973 g_warning ("%s %p is mapped but not realized",
8974 G_OBJECT_TYPE_NAME (widget), widget);
8976 if (!widget->priv->visible)
8977 g_warning ("%s %p is mapped but not visible",
8978 G_OBJECT_TYPE_NAME (widget), widget);
8980 if (!widget->priv->toplevel)
8982 if (!widget->priv->child_visible)
8983 g_warning ("%s %p is mapped but not child_visible",
8984 G_OBJECT_TYPE_NAME (widget), widget);
8989 /* Not mapped implies... */
8992 /* This check makes sense for normal toplevels, but for
8993 * something like a toplevel that is embedded within a clutter
8994 * state, mapping may depend on external factors.
8996 if (widget->priv->toplevel)
8998 if (widget->priv->visible)
8999 g_warning ("%s %p toplevel is visible but not mapped",
9000 G_OBJECT_TYPE_NAME (widget), widget);
9005 /* Parent related checks aren't possible if parent has
9006 * verifying_invariants_count > 0 because parent needs to recurse
9007 * children first before the invariants will hold.
9009 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
9012 parent->priv->realized)
9014 /* Parent realized implies... */
9017 /* This is in widget_system.txt but appears to fail
9018 * because there's no gtk_container_realize() that
9019 * realizes all children... instead we just lazily
9020 * wait for map to fix things up.
9022 if (!widget->priv->realized)
9023 g_warning ("%s %p is realized but child %s %p is not realized",
9024 G_OBJECT_TYPE_NAME (parent), parent,
9025 G_OBJECT_TYPE_NAME (widget), widget);
9028 else if (!widget->priv->toplevel)
9030 /* No parent or parent not realized on non-toplevel implies... */
9032 if (widget->priv->realized && !widget->priv->in_reparent)
9033 g_warning ("%s %p is not realized but child %s %p is realized",
9034 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9035 G_OBJECT_TYPE_NAME (widget), widget);
9039 parent->priv->mapped &&
9040 widget->priv->visible &&
9041 widget->priv->child_visible)
9043 /* Parent mapped and we are visible implies... */
9045 if (!widget->priv->mapped)
9046 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
9047 G_OBJECT_TYPE_NAME (parent), parent,
9048 G_OBJECT_TYPE_NAME (widget), widget);
9050 else if (!widget->priv->toplevel)
9052 /* No parent or parent not mapped on non-toplevel implies... */
9054 if (widget->priv->mapped && !widget->priv->in_reparent)
9055 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
9056 G_OBJECT_TYPE_NAME (widget), widget,
9057 widget->priv->visible,
9058 widget->priv->child_visible,
9059 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9060 parent ? parent->priv->mapped : FALSE);
9064 if (!widget->priv->realized)
9066 /* Not realized implies... */
9069 /* widget_system.txt says these hold, but they don't. */
9070 if (widget->priv->alloc_needed)
9071 g_warning ("%s %p alloc needed but not realized",
9072 G_OBJECT_TYPE_NAME (widget), widget);
9074 if (widget->priv->width_request_needed)
9075 g_warning ("%s %p width request needed but not realized",
9076 G_OBJECT_TYPE_NAME (widget), widget);
9078 if (widget->priv->height_request_needed)
9079 g_warning ("%s %p height request needed but not realized",
9080 G_OBJECT_TYPE_NAME (widget), widget);
9085 /* The point of this push/pop is that invariants may not hold while
9086 * we're busy making changes. So we only check at the outermost call
9087 * on the call stack, after we finish updating everything.
9090 gtk_widget_push_verify_invariants (GtkWidget *widget)
9092 widget->priv->verifying_invariants_count += 1;
9096 gtk_widget_verify_child_invariants (GtkWidget *widget,
9097 gpointer client_data)
9099 /* We don't recurse further; this is a one-level check. */
9100 gtk_widget_verify_invariants (widget);
9104 gtk_widget_pop_verify_invariants (GtkWidget *widget)
9106 g_assert (widget->priv->verifying_invariants_count > 0);
9108 widget->priv->verifying_invariants_count -= 1;
9110 if (widget->priv->verifying_invariants_count == 0)
9112 gtk_widget_verify_invariants (widget);
9114 if (GTK_IS_CONTAINER (widget))
9116 /* Check one level of children, because our
9117 * push_verify_invariants() will have prevented some of the
9118 * checks. This does not recurse because if recursion is
9119 * needed, it will happen naturally as each child has a
9120 * push/pop on that child. For example if we're recursively
9121 * mapping children, we'll push/pop on each child as we map
9124 gtk_container_forall (GTK_CONTAINER (widget),
9125 gtk_widget_verify_child_invariants,
9130 #endif /* G_ENABLE_DEBUG */
9132 static PangoContext *
9133 gtk_widget_peek_pango_context (GtkWidget *widget)
9135 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9139 * gtk_widget_get_pango_context:
9140 * @widget: a #GtkWidget
9142 * Gets a #PangoContext with the appropriate font map, font description,
9143 * and base direction for this widget. Unlike the context returned
9144 * by gtk_widget_create_pango_context(), this context is owned by
9145 * the widget (it can be used until the screen for the widget changes
9146 * or the widget is removed from its toplevel), and will be updated to
9147 * match any changes to the widget's attributes. This can be tracked
9148 * by using the #GtkWidget::screen-changed signal on the widget.
9150 * Return value: (transfer none): the #PangoContext for the widget.
9153 gtk_widget_get_pango_context (GtkWidget *widget)
9155 PangoContext *context;
9157 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9159 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9162 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9163 g_object_set_qdata_full (G_OBJECT (widget),
9164 quark_pango_context,
9173 update_pango_context (GtkWidget *widget,
9174 PangoContext *context)
9176 PangoFontDescription *font_desc;
9177 GtkStyleContext *style_context;
9179 style_context = gtk_widget_get_style_context (widget);
9180 gtk_style_context_get (style_context,
9181 gtk_widget_get_state_flags (widget),
9185 pango_context_set_font_description (context, font_desc);
9186 pango_context_set_base_dir (context,
9187 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9188 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9190 pango_font_description_free (font_desc);
9194 gtk_widget_update_pango_context (GtkWidget *widget)
9196 PangoContext *context = gtk_widget_peek_pango_context (widget);
9202 update_pango_context (widget, context);
9204 screen = gtk_widget_get_screen_unchecked (widget);
9207 pango_cairo_context_set_resolution (context,
9208 gdk_screen_get_resolution (screen));
9209 pango_cairo_context_set_font_options (context,
9210 gdk_screen_get_font_options (screen));
9216 * gtk_widget_create_pango_context:
9217 * @widget: a #GtkWidget
9219 * Creates a new #PangoContext with the appropriate font map,
9220 * font description, and base direction for drawing text for
9221 * this widget. See also gtk_widget_get_pango_context().
9223 * Return value: (transfer full): the new #PangoContext
9226 gtk_widget_create_pango_context (GtkWidget *widget)
9229 PangoContext *context;
9231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9233 screen = gtk_widget_get_screen_unchecked (widget);
9236 GTK_NOTE (MULTIHEAD,
9237 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9239 screen = gdk_screen_get_default ();
9242 context = gdk_pango_context_get_for_screen (screen);
9244 update_pango_context (widget, context);
9245 pango_context_set_language (context, gtk_get_default_language ());
9251 * gtk_widget_create_pango_layout:
9252 * @widget: a #GtkWidget
9253 * @text: text to set on the layout (can be %NULL)
9255 * Creates a new #PangoLayout with the appropriate font map,
9256 * font description, and base direction for drawing text for
9259 * If you keep a #PangoLayout created in this way around, you need
9260 * to re-create it when the widget #PangoContext is replaced.
9261 * This can be tracked by using the #GtkWidget::screen-changed signal
9264 * Return value: (transfer full): the new #PangoLayout
9267 gtk_widget_create_pango_layout (GtkWidget *widget,
9270 PangoLayout *layout;
9271 PangoContext *context;
9273 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9275 context = gtk_widget_get_pango_context (widget);
9276 layout = pango_layout_new (context);
9279 pango_layout_set_text (layout, text, -1);
9285 * gtk_widget_render_icon_pixbuf:
9286 * @widget: a #GtkWidget
9287 * @stock_id: a stock ID
9288 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9289 * render at the size of the source and don't scale (if there are
9290 * multiple source sizes, GTK+ picks one of the available sizes).
9292 * A convenience function that uses the theme engine and style
9293 * settings for @widget to look up @stock_id and render it to
9294 * a pixbuf. @stock_id should be a stock icon ID such as
9295 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9296 * such as #GTK_ICON_SIZE_MENU.
9298 * The pixels in the returned #GdkPixbuf are shared with the rest of
9299 * the application and should not be modified. The pixbuf should be freed
9300 * after use with g_object_unref().
9302 * Return value: (transfer full): a new pixbuf, or %NULL if the
9303 * stock ID wasn't known
9308 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9309 const gchar *stock_id,
9312 GtkStyleContext *context;
9313 GtkIconSet *icon_set;
9315 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9316 g_return_val_if_fail (stock_id != NULL, NULL);
9317 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9319 context = gtk_widget_get_style_context (widget);
9320 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9322 if (icon_set == NULL)
9325 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9329 * gtk_widget_set_parent_window:
9330 * @widget: a #GtkWidget.
9331 * @parent_window: the new parent window.
9333 * Sets a non default parent window for @widget.
9335 * For GtkWindow classes, setting a @parent_window effects whether
9336 * the window is a toplevel window or can be embedded into other
9340 * For GtkWindow classes, this needs to be called before the
9341 * window is realized.
9346 gtk_widget_set_parent_window (GtkWidget *widget,
9347 GdkWindow *parent_window)
9349 GdkWindow *old_parent_window;
9351 g_return_if_fail (GTK_IS_WIDGET (widget));
9353 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9354 quark_parent_window);
9356 if (parent_window != old_parent_window)
9360 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9362 if (old_parent_window)
9363 g_object_unref (old_parent_window);
9365 g_object_ref (parent_window);
9367 /* Unset toplevel flag when adding a parent window to a widget,
9368 * this is the primary entry point to allow toplevels to be
9371 #ifdef GDK_WINDOWING_X11
9372 is_plug = GTK_IS_PLUG (widget);
9376 if (GTK_IS_WINDOW (widget) && !is_plug)
9377 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9382 * gtk_widget_get_parent_window:
9383 * @widget: a #GtkWidget.
9385 * Gets @widget's parent window.
9387 * Returns: (transfer none): the parent window of @widget.
9390 gtk_widget_get_parent_window (GtkWidget *widget)
9392 GtkWidgetPrivate *priv;
9393 GdkWindow *parent_window;
9395 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9397 priv = widget->priv;
9399 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9401 return (parent_window != NULL) ? parent_window :
9402 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9407 * gtk_widget_set_child_visible:
9408 * @widget: a #GtkWidget
9409 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9411 * Sets whether @widget should be mapped along with its when its parent
9412 * is mapped and @widget has been shown with gtk_widget_show().
9414 * The child visibility can be set for widget before it is added to
9415 * a container with gtk_widget_set_parent(), to avoid mapping
9416 * children unnecessary before immediately unmapping them. However
9417 * it will be reset to its default state of %TRUE when the widget
9418 * is removed from a container.
9420 * Note that changing the child visibility of a widget does not
9421 * queue a resize on the widget. Most of the time, the size of
9422 * a widget is computed from all visible children, whether or
9423 * not they are mapped. If this is not the case, the container
9424 * can queue a resize itself.
9426 * This function is only useful for container implementations and
9427 * never should be called by an application.
9430 gtk_widget_set_child_visible (GtkWidget *widget,
9431 gboolean is_visible)
9433 GtkWidgetPrivate *priv;
9435 g_return_if_fail (GTK_IS_WIDGET (widget));
9436 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9438 priv = widget->priv;
9440 g_object_ref (widget);
9441 gtk_widget_verify_invariants (widget);
9444 priv->child_visible = TRUE;
9447 GtkWidget *toplevel;
9449 priv->child_visible = FALSE;
9451 toplevel = gtk_widget_get_toplevel (widget);
9452 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9453 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9456 if (priv->parent && gtk_widget_get_realized (priv->parent))
9458 if (gtk_widget_get_mapped (priv->parent) &&
9459 priv->child_visible &&
9460 gtk_widget_get_visible (widget))
9461 gtk_widget_map (widget);
9463 gtk_widget_unmap (widget);
9466 gtk_widget_verify_invariants (widget);
9467 g_object_unref (widget);
9471 * gtk_widget_get_child_visible:
9472 * @widget: a #GtkWidget
9474 * Gets the value set with gtk_widget_set_child_visible().
9475 * If you feel a need to use this function, your code probably
9476 * needs reorganization.
9478 * This function is only useful for container implementations and
9479 * never should be called by an application.
9481 * Return value: %TRUE if the widget is mapped with the parent.
9484 gtk_widget_get_child_visible (GtkWidget *widget)
9486 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9488 return widget->priv->child_visible;
9492 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9494 GtkWidget *toplevel;
9496 toplevel = gtk_widget_get_toplevel (widget);
9498 if (gtk_widget_is_toplevel (toplevel))
9500 if (GTK_IS_WINDOW (toplevel))
9501 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9502 else if (GTK_IS_INVISIBLE (toplevel))
9503 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9510 * gtk_widget_get_screen:
9511 * @widget: a #GtkWidget
9513 * Get the #GdkScreen from the toplevel window associated with
9514 * this widget. This function can only be called after the widget
9515 * has been added to a widget hierarchy with a #GtkWindow
9518 * In general, you should only create screen specific
9519 * resources when a widget has been realized, and you should
9520 * free those resources when the widget is unrealized.
9522 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9527 gtk_widget_get_screen (GtkWidget *widget)
9531 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9533 screen = gtk_widget_get_screen_unchecked (widget);
9540 g_warning (G_STRLOC ": Can't get associated screen"
9541 " for a widget unless it is inside a toplevel GtkWindow\n"
9542 " widget type is %s associated top level type is %s",
9543 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9544 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9546 return gdk_screen_get_default ();
9551 * gtk_widget_has_screen:
9552 * @widget: a #GtkWidget
9554 * Checks whether there is a #GdkScreen is associated with
9555 * this widget. All toplevel widgets have an associated
9556 * screen, and all widgets added into a hierarchy with a toplevel
9557 * window at the top.
9559 * Return value: %TRUE if there is a #GdkScreen associcated
9565 gtk_widget_has_screen (GtkWidget *widget)
9567 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9569 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9573 * gtk_widget_get_display:
9574 * @widget: a #GtkWidget
9576 * Get the #GdkDisplay for the toplevel window associated with
9577 * this widget. This function can only be called after the widget
9578 * has been added to a widget hierarchy with a #GtkWindow at the top.
9580 * In general, you should only create display specific
9581 * resources when a widget has been realized, and you should
9582 * free those resources when the widget is unrealized.
9584 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9589 gtk_widget_get_display (GtkWidget *widget)
9591 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9593 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9597 * gtk_widget_get_root_window:
9598 * @widget: a #GtkWidget
9600 * Get the root window where this widget is located. This function can
9601 * only be called after the widget has been added to a widget
9602 * hierarchy with #GtkWindow at the top.
9604 * The root window is useful for such purposes as creating a popup
9605 * #GdkWindow associated with the window. In general, you should only
9606 * create display specific resources when a widget has been realized,
9607 * and you should free those resources when the widget is unrealized.
9609 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9614 gtk_widget_get_root_window (GtkWidget *widget)
9616 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9618 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9622 * gtk_widget_child_focus:
9623 * @widget: a #GtkWidget
9624 * @direction: direction of focus movement
9626 * This function is used by custom widget implementations; if you're
9627 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9628 * to a particular widget, and gtk_container_set_focus_chain() to
9629 * change the focus tab order. So you may want to investigate those
9630 * functions instead.
9632 * gtk_widget_child_focus() is called by containers as the user moves
9633 * around the window using keyboard shortcuts. @direction indicates
9634 * what kind of motion is taking place (up, down, left, right, tab
9635 * forward, tab backward). gtk_widget_child_focus() emits the
9636 * #GtkWidget::focus signal; widgets override the default handler
9637 * for this signal in order to implement appropriate focus behavior.
9639 * The default ::focus handler for a widget should return %TRUE if
9640 * moving in @direction left the focus on a focusable location inside
9641 * that widget, and %FALSE if moving in @direction moved the focus
9642 * outside the widget. If returning %TRUE, widgets normally
9643 * call gtk_widget_grab_focus() to place the focus accordingly;
9644 * if returning %FALSE, they don't modify the current focus location.
9646 * Return value: %TRUE if focus ended up inside @widget
9649 gtk_widget_child_focus (GtkWidget *widget,
9650 GtkDirectionType direction)
9652 gboolean return_val;
9654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9656 if (!gtk_widget_get_visible (widget) ||
9657 !gtk_widget_is_sensitive (widget))
9660 /* child widgets must set CAN_FOCUS, containers
9661 * don't have to though.
9663 if (!GTK_IS_CONTAINER (widget) &&
9664 !gtk_widget_get_can_focus (widget))
9667 g_signal_emit (widget,
9668 widget_signals[FOCUS],
9670 direction, &return_val);
9676 * gtk_widget_keynav_failed:
9677 * @widget: a #GtkWidget
9678 * @direction: direction of focus movement
9680 * This function should be called whenever keyboard navigation within
9681 * a single widget hits a boundary. The function emits the
9682 * #GtkWidget::keynav-failed signal on the widget and its return
9683 * value should be interpreted in a way similar to the return value of
9684 * gtk_widget_child_focus():
9686 * When %TRUE is returned, stay in the widget, the failed keyboard
9687 * navigation is Ok and/or there is nowhere we can/should move the
9690 * When %FALSE is returned, the caller should continue with keyboard
9691 * navigation outside the widget, e.g. by calling
9692 * gtk_widget_child_focus() on the widget's toplevel.
9694 * The default ::keynav-failed handler returns %TRUE for
9695 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9696 * values of #GtkDirectionType, it looks at the
9697 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9698 * if the setting is %TRUE. This way the entire user interface
9699 * becomes cursor-navigatable on input devices such as mobile phones
9700 * which only have cursor keys but no tab key.
9702 * Whenever the default handler returns %TRUE, it also calls
9703 * gtk_widget_error_bell() to notify the user of the failed keyboard
9706 * A use case for providing an own implementation of ::keynav-failed
9707 * (either by connecting to it or by overriding it) would be a row of
9708 * #GtkEntry widgets where the user should be able to navigate the
9709 * entire row with the cursor keys, as e.g. known from user interfaces
9710 * that require entering license keys.
9712 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9713 * if the emitting widget should try to handle the keyboard
9714 * navigation attempt in its parent container(s).
9719 gtk_widget_keynav_failed (GtkWidget *widget,
9720 GtkDirectionType direction)
9722 gboolean return_val;
9724 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9726 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9727 direction, &return_val);
9733 * gtk_widget_error_bell:
9734 * @widget: a #GtkWidget
9736 * Notifies the user about an input-related error on this widget.
9737 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9738 * gdk_window_beep(), otherwise it does nothing.
9740 * Note that the effect of gdk_window_beep() can be configured in many
9741 * ways, depending on the windowing backend and the desktop environment
9742 * or window manager that is used.
9747 gtk_widget_error_bell (GtkWidget *widget)
9749 GtkWidgetPrivate *priv;
9750 GtkSettings* settings;
9753 g_return_if_fail (GTK_IS_WIDGET (widget));
9755 priv = widget->priv;
9757 settings = gtk_widget_get_settings (widget);
9761 g_object_get (settings,
9762 "gtk-error-bell", &beep,
9765 if (beep && priv->window)
9766 gdk_window_beep (priv->window);
9770 gtk_widget_set_usize_internal (GtkWidget *widget,
9773 GtkQueueResizeFlags flags)
9775 GtkWidgetAuxInfo *aux_info;
9776 gboolean changed = FALSE;
9778 g_object_freeze_notify (G_OBJECT (widget));
9780 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9782 if (width > -2 && aux_info->width != width)
9784 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9785 g_object_notify (G_OBJECT (widget), "width-request");
9786 aux_info->width = width;
9789 if (height > -2 && aux_info->height != height)
9791 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9792 g_object_notify (G_OBJECT (widget), "height-request");
9793 aux_info->height = height;
9797 if (gtk_widget_get_visible (widget) && changed)
9799 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9800 gtk_widget_queue_resize (widget);
9802 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9805 g_object_thaw_notify (G_OBJECT (widget));
9809 * gtk_widget_set_size_request:
9810 * @widget: a #GtkWidget
9811 * @width: width @widget should request, or -1 to unset
9812 * @height: height @widget should request, or -1 to unset
9814 * Sets the minimum size of a widget; that is, the widget's size
9815 * request will be at least @width by @height. You can use this
9816 * function to force a widget to be larger than it normally would be.
9818 * In most cases, gtk_window_set_default_size() is a better choice for
9819 * toplevel windows than this function; setting the default size will
9820 * still allow users to shrink the window. Setting the size request
9821 * will force them to leave the window at least as large as the size
9822 * request. When dealing with window sizes,
9823 * gtk_window_set_geometry_hints() can be a useful function as well.
9825 * Note the inherent danger of setting any fixed size - themes,
9826 * translations into other languages, different fonts, and user action
9827 * can all change the appropriate size for a given widget. So, it's
9828 * basically impossible to hardcode a size that will always be
9831 * The size request of a widget is the smallest size a widget can
9832 * accept while still functioning well and drawing itself correctly.
9833 * However in some strange cases a widget may be allocated less than
9834 * its requested size, and in many cases a widget may be allocated more
9835 * space than it requested.
9837 * If the size request in a given direction is -1 (unset), then
9838 * the "natural" size request of the widget will be used instead.
9840 * The size request set here does not include any margin from the
9841 * #GtkWidget properties margin-left, margin-right, margin-top, and
9842 * margin-bottom, but it does include pretty much all other padding
9843 * or border properties set by any subclass of #GtkWidget.
9846 gtk_widget_set_size_request (GtkWidget *widget,
9850 g_return_if_fail (GTK_IS_WIDGET (widget));
9851 g_return_if_fail (width >= -1);
9852 g_return_if_fail (height >= -1);
9859 gtk_widget_set_usize_internal (widget, width, height, 0);
9864 * gtk_widget_get_size_request:
9865 * @widget: a #GtkWidget
9866 * @width: (out) (allow-none): return location for width, or %NULL
9867 * @height: (out) (allow-none): return location for height, or %NULL
9869 * Gets the size request that was explicitly set for the widget using
9870 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9871 * @height indicates that that dimension has not been set explicitly
9872 * and the natural requisition of the widget will be used intead. See
9873 * gtk_widget_set_size_request(). To get the size a widget will
9874 * actually request, call gtk_widget_get_preferred_size() instead of
9878 gtk_widget_get_size_request (GtkWidget *widget,
9882 const GtkWidgetAuxInfo *aux_info;
9884 g_return_if_fail (GTK_IS_WIDGET (widget));
9886 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9889 *width = aux_info->width;
9892 *height = aux_info->height;
9896 * _gtk_widget_override_size_request:
9897 * @widget: a #GtkWidget
9898 * @width: new forced minimum width
9899 * @height: new forced minimum height
9900 * @old_width: location to store previous forced minimum width
9901 * @old_height: location to store previous forced minumum height
9903 * Temporarily establishes a forced minimum size for a widget; this
9904 * is used by GtkWindow when calculating the size to add to the
9905 * window's geometry widget. Cached sizes for the widget and its
9906 * parents are invalidated, so that subsequent calls to the size
9907 * negotiation machinery produce the overriden result, but the
9908 * widget is not queued for relayout or redraw. The old size must
9909 * be restored with _gtk_widget_restore_size_request() or things
9913 _gtk_widget_override_size_request (GtkWidget *widget,
9919 gtk_widget_get_size_request (widget, old_width, old_height);
9920 gtk_widget_set_usize_internal (widget, width, height,
9921 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9925 * _gtk_widget_restore_size_request:
9926 * @widget: a #GtkWidget
9927 * @old_width: saved forced minimum size
9928 * @old_height: saved forced minimum size
9930 * Undoes the operation of_gtk_widget_override_size_request().
9933 _gtk_widget_restore_size_request (GtkWidget *widget,
9937 gtk_widget_set_usize_internal (widget, old_width, old_height,
9938 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9942 * gtk_widget_set_events:
9943 * @widget: a #GtkWidget
9944 * @events: event mask
9946 * Sets the event mask (see #GdkEventMask) for a widget. The event
9947 * mask determines which events a widget will receive. Keep in mind
9948 * that different widgets have different default event masks, and by
9949 * changing the event mask you may disrupt a widget's functionality,
9950 * so be careful. This function must be called while a widget is
9951 * unrealized. Consider gtk_widget_add_events() for widgets that are
9952 * already realized, or if you want to preserve the existing event
9953 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9954 * to get events on those widgets, place them inside a #GtkEventBox
9955 * and receive events on the event box.
9958 gtk_widget_set_events (GtkWidget *widget,
9961 g_return_if_fail (GTK_IS_WIDGET (widget));
9962 g_return_if_fail (!gtk_widget_get_realized (widget));
9964 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9965 GINT_TO_POINTER (events));
9966 g_object_notify (G_OBJECT (widget), "events");
9970 * gtk_widget_set_device_events:
9971 * @widget: a #GtkWidget
9972 * @device: a #GdkDevice
9973 * @events: event mask
9975 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9976 * mask determines which events a widget will receive from @device. Keep
9977 * in mind that different widgets have different default event masks, and by
9978 * changing the event mask you may disrupt a widget's functionality,
9979 * so be careful. This function must be called while a widget is
9980 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9981 * already realized, or if you want to preserve the existing event
9982 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9983 * to get events on those widgets, place them inside a #GtkEventBox
9984 * and receive events on the event box.
9989 gtk_widget_set_device_events (GtkWidget *widget,
9991 GdkEventMask events)
9993 GHashTable *device_events;
9995 g_return_if_fail (GTK_IS_WIDGET (widget));
9996 g_return_if_fail (GDK_IS_DEVICE (device));
9997 g_return_if_fail (!gtk_widget_get_realized (widget));
9999 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10001 if (G_UNLIKELY (!device_events))
10003 device_events = g_hash_table_new (NULL, NULL);
10004 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10005 (GDestroyNotify) g_hash_table_unref);
10008 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
10012 * gtk_widget_set_device_enabled:
10013 * @widget: a #GtkWidget
10014 * @device: a #GdkDevice
10015 * @enabled: whether to enable the device
10017 * Enables or disables a #GdkDevice to interact with @widget
10018 * and all its children.
10020 * It does so by descending through the #GdkWindow hierarchy
10021 * and enabling the same mask that is has for core events
10022 * (i.e. the one that gdk_window_get_events() returns).
10027 gtk_widget_set_device_enabled (GtkWidget *widget,
10031 GList *enabled_devices;
10033 g_return_if_fail (GTK_IS_WIDGET (widget));
10034 g_return_if_fail (GDK_IS_DEVICE (device));
10036 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10037 enabled_devices = g_list_append (enabled_devices, device);
10039 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
10040 enabled_devices, (GDestroyNotify) g_list_free);;
10042 if (gtk_widget_get_realized (widget))
10043 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
10047 * gtk_widget_get_device_enabled:
10048 * @widget: a #GtkWidget
10049 * @device: a #GdkDevice
10051 * Returns whether @device can interact with @widget and its
10052 * children. See gtk_widget_set_device_enabled().
10054 * Return value: %TRUE is @device is enabled for @widget
10059 gtk_widget_get_device_enabled (GtkWidget *widget,
10062 GList *enabled_devices;
10064 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10065 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
10067 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10069 return g_list_find (enabled_devices, device) != NULL;
10073 gtk_widget_add_events_internal_list (GtkWidget *widget,
10076 GList *window_list)
10080 for (l = window_list; l != NULL; l = l->next)
10082 GdkWindow *window = l->data;
10083 gpointer user_data;
10085 gdk_window_get_user_data (window, &user_data);
10086 if (user_data == widget)
10091 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
10093 gdk_window_set_events (window, gdk_window_get_events (window) | events);
10095 children = gdk_window_get_children (window);
10096 gtk_widget_add_events_internal_list (widget, device, events, children);
10097 g_list_free (children);
10103 gtk_widget_add_events_internal (GtkWidget *widget,
10107 GtkWidgetPrivate *priv = widget->priv;
10108 GList *window_list;
10110 if (!gtk_widget_get_has_window (widget))
10111 window_list = gdk_window_get_children (priv->window);
10113 window_list = g_list_prepend (NULL, priv->window);
10115 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10117 g_list_free (window_list);
10121 * gtk_widget_add_events:
10122 * @widget: a #GtkWidget
10123 * @events: an event mask, see #GdkEventMask
10125 * Adds the events in the bitfield @events to the event mask for
10126 * @widget. See gtk_widget_set_events() for details.
10129 gtk_widget_add_events (GtkWidget *widget,
10134 g_return_if_fail (GTK_IS_WIDGET (widget));
10136 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10137 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10138 GINT_TO_POINTER (old_events | events));
10140 if (gtk_widget_get_realized (widget))
10142 gtk_widget_add_events_internal (widget, NULL, events);
10143 gtk_widget_update_devices_mask (widget, FALSE);
10146 g_object_notify (G_OBJECT (widget), "events");
10150 * gtk_widget_add_device_events:
10151 * @widget: a #GtkWidget
10152 * @device: a #GdkDevice
10153 * @events: an event mask, see #GdkEventMask
10155 * Adds the device events in the bitfield @events to the event mask for
10156 * @widget. See gtk_widget_set_device_events() for details.
10161 gtk_widget_add_device_events (GtkWidget *widget,
10163 GdkEventMask events)
10165 GdkEventMask old_events;
10166 GHashTable *device_events;
10168 g_return_if_fail (GTK_IS_WIDGET (widget));
10169 g_return_if_fail (GDK_IS_DEVICE (device));
10171 old_events = gtk_widget_get_device_events (widget, device);
10173 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10175 if (G_UNLIKELY (!device_events))
10177 device_events = g_hash_table_new (NULL, NULL);
10178 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10179 (GDestroyNotify) g_hash_table_unref);
10182 g_hash_table_insert (device_events, device,
10183 GUINT_TO_POINTER (old_events | events));
10185 if (gtk_widget_get_realized (widget))
10186 gtk_widget_add_events_internal (widget, device, events);
10188 g_object_notify (G_OBJECT (widget), "events");
10192 * gtk_widget_get_toplevel:
10193 * @widget: a #GtkWidget
10195 * This function returns the topmost widget in the container hierarchy
10196 * @widget is a part of. If @widget has no parent widgets, it will be
10197 * returned as the topmost widget. No reference will be added to the
10198 * returned widget; it should not be unreferenced.
10200 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10201 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10203 * %NULL if @widget wasn't inside a toplevel window, and if the
10204 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
10205 * inside the toplevel #GtkWindow. While the second case may
10206 * seem unlikely, it actually happens when a #GtkPlug is embedded
10207 * inside a #GtkSocket within the same application.
10209 * To reliably find the toplevel #GtkWindow, use
10210 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10211 * is set on the result.
10213 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10214 * if (gtk_widget_is_toplevel (toplevel))
10216 * /* Perform action on toplevel. */
10220 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10221 * if there's no ancestor.
10224 gtk_widget_get_toplevel (GtkWidget *widget)
10226 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10228 while (widget->priv->parent)
10229 widget = widget->priv->parent;
10235 * gtk_widget_get_ancestor:
10236 * @widget: a #GtkWidget
10237 * @widget_type: ancestor type
10239 * Gets the first ancestor of @widget with type @widget_type. For example,
10240 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10241 * the first #GtkBox that's an ancestor of @widget. No reference will be
10242 * added to the returned widget; it should not be unreferenced. See note
10243 * about checking for a toplevel #GtkWindow in the docs for
10244 * gtk_widget_get_toplevel().
10246 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10247 * considers @widget to be an ancestor of itself.
10249 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10252 gtk_widget_get_ancestor (GtkWidget *widget,
10255 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10257 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10258 widget = widget->priv->parent;
10260 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10267 * gtk_widget_set_visual:
10268 * @widget: a #GtkWidget
10269 * @visual: visual to be used or %NULL to unset a previous one
10271 * Sets the visual that should be used for by widget and its children for
10272 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10273 * returned by gtk_widget_get_screen(), so handling the
10274 * #GtkWidget::screen-changed signal is necessary.
10276 * Setting a new @visual will not cause @widget to recreate its windows,
10277 * so you should call this function before @widget is realized.
10280 gtk_widget_set_visual (GtkWidget *widget,
10283 g_return_if_fail (GTK_IS_WIDGET (widget));
10284 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10287 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10290 g_object_set_qdata_full (G_OBJECT (widget),
10292 g_object_ref (visual),
10297 * gtk_widget_get_visual:
10298 * @widget: a #GtkWidget
10300 * Gets the visual that will be used to render @widget.
10302 * Return value: (transfer none): the visual for @widget
10305 gtk_widget_get_visual (GtkWidget *widget)
10311 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10313 if (gtk_widget_get_has_window (widget) &&
10314 widget->priv->window)
10315 return gdk_window_get_visual (widget->priv->window);
10317 screen = gtk_widget_get_screen (widget);
10319 for (w = widget; w != NULL; w = w->priv->parent)
10321 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10324 if (gdk_visual_get_screen (visual) == screen)
10327 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10328 gtk_widget_get_name (widget));
10332 return gdk_screen_get_system_visual (screen);
10336 * gtk_widget_get_settings:
10337 * @widget: a #GtkWidget
10339 * Gets the settings object holding the settings used for this widget.
10341 * Note that this function can only be called when the #GtkWidget
10342 * is attached to a toplevel, since the settings object is specific
10343 * to a particular #GdkScreen.
10345 * Return value: (transfer none): the relevant #GtkSettings object
10348 gtk_widget_get_settings (GtkWidget *widget)
10350 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10352 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10356 * gtk_widget_get_events:
10357 * @widget: a #GtkWidget
10359 * Returns the event mask for the widget (a bitfield containing flags
10360 * from the #GdkEventMask enumeration). These are the events that the widget
10363 * Return value: event mask for @widget
10366 gtk_widget_get_events (GtkWidget *widget)
10368 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10370 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10374 * gtk_widget_get_device_events:
10375 * @widget: a #GtkWidget
10376 * @device: a #GdkDevice
10378 * Returns the events mask for the widget corresponding to an specific device. These
10379 * are the events that the widget will receive when @device operates on it.
10381 * Returns: device event mask for @widget
10386 gtk_widget_get_device_events (GtkWidget *widget,
10389 GHashTable *device_events;
10391 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10392 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10394 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10396 if (!device_events)
10399 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10403 * gtk_widget_get_pointer:
10404 * @widget: a #GtkWidget
10405 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10406 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10408 * Obtains the location of the mouse pointer in widget coordinates.
10409 * Widget coordinates are a bit odd; for historical reasons, they are
10410 * defined as @widget->window coordinates for widgets that are not
10411 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10412 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10414 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10417 gtk_widget_get_pointer (GtkWidget *widget,
10421 GtkWidgetPrivate *priv;
10423 g_return_if_fail (GTK_IS_WIDGET (widget));
10425 priv = widget->priv;
10432 if (gtk_widget_get_realized (widget))
10434 gdk_window_get_device_position (priv->window,
10435 gdk_device_manager_get_client_pointer (
10436 gdk_display_get_device_manager (
10437 gtk_widget_get_display (widget))),
10440 if (!gtk_widget_get_has_window (widget))
10443 *x -= priv->allocation.x;
10445 *y -= priv->allocation.y;
10451 * gtk_widget_is_ancestor:
10452 * @widget: a #GtkWidget
10453 * @ancestor: another #GtkWidget
10455 * Determines whether @widget is somewhere inside @ancestor, possibly with
10456 * intermediate containers.
10458 * Return value: %TRUE if @ancestor contains @widget as a child,
10459 * grandchild, great grandchild, etc.
10462 gtk_widget_is_ancestor (GtkWidget *widget,
10463 GtkWidget *ancestor)
10465 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10466 g_return_val_if_fail (ancestor != NULL, FALSE);
10470 if (widget->priv->parent == ancestor)
10472 widget = widget->priv->parent;
10478 static GQuark quark_composite_name = 0;
10481 * gtk_widget_set_composite_name:
10482 * @widget: a #GtkWidget.
10483 * @name: the name to set
10485 * Sets a widgets composite name. The widget must be
10486 * a composite child of its parent; see gtk_widget_push_composite_child().
10489 gtk_widget_set_composite_name (GtkWidget *widget,
10492 g_return_if_fail (GTK_IS_WIDGET (widget));
10493 g_return_if_fail (widget->priv->composite_child);
10494 g_return_if_fail (name != NULL);
10496 if (!quark_composite_name)
10497 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10499 g_object_set_qdata_full (G_OBJECT (widget),
10500 quark_composite_name,
10506 * gtk_widget_get_composite_name:
10507 * @widget: a #GtkWidget
10509 * Obtains the composite name of a widget.
10511 * Returns: the composite name of @widget, or %NULL if @widget is not
10512 * a composite child. The string should be freed when it is no
10516 gtk_widget_get_composite_name (GtkWidget *widget)
10518 GtkWidgetPrivate *priv;
10520 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10522 priv = widget->priv;
10524 if (widget->priv->composite_child && priv->parent)
10525 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10532 * gtk_widget_push_composite_child:
10534 * Makes all newly-created widgets as composite children until
10535 * the corresponding gtk_widget_pop_composite_child() call.
10537 * A composite child is a child that's an implementation detail of the
10538 * container it's inside and should not be visible to people using the
10539 * container. Composite children aren't treated differently by GTK (but
10540 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10541 * builders might want to treat them in a different way.
10543 * Here is a simple example:
10545 * gtk_widget_push_composite_child ();
10546 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10547 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10548 * gtk_widget_pop_composite_child ();
10549 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10550 * GTK_WIDGET (scrolled_window));
10551 * g_object_ref (scrolled_window->hscrollbar);
10555 gtk_widget_push_composite_child (void)
10557 composite_child_stack++;
10561 * gtk_widget_pop_composite_child:
10563 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10566 gtk_widget_pop_composite_child (void)
10568 if (composite_child_stack)
10569 composite_child_stack--;
10573 gtk_widget_emit_direction_changed (GtkWidget *widget,
10574 GtkTextDirection old_dir)
10576 GtkTextDirection direction;
10577 GtkStateFlags state;
10579 gtk_widget_update_pango_context (widget);
10581 direction = gtk_widget_get_direction (widget);
10582 state = widget->priv->state_flags;
10583 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10587 case GTK_TEXT_DIR_LTR:
10588 state |= GTK_STATE_FLAG_DIR_LTR;
10591 case GTK_TEXT_DIR_RTL:
10592 state |= GTK_STATE_FLAG_DIR_RTL;
10595 case GTK_TEXT_DIR_NONE:
10597 g_assert_not_reached ();
10601 gtk_widget_set_state_flags (widget, state, TRUE);
10603 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10607 * gtk_widget_set_direction:
10608 * @widget: a #GtkWidget
10609 * @dir: the new direction
10611 * Sets the reading direction on a particular widget. This direction
10612 * controls the primary direction for widgets containing text,
10613 * and also the direction in which the children of a container are
10614 * packed. The ability to set the direction is present in order
10615 * so that correct localization into languages with right-to-left
10616 * reading directions can be done. Generally, applications will
10617 * let the default reading direction present, except for containers
10618 * where the containers are arranged in an order that is explicitely
10619 * visual rather than logical (such as buttons for text justification).
10621 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10622 * set by gtk_widget_set_default_direction() will be used.
10625 gtk_widget_set_direction (GtkWidget *widget,
10626 GtkTextDirection dir)
10628 GtkTextDirection old_dir;
10630 g_return_if_fail (GTK_IS_WIDGET (widget));
10631 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10633 old_dir = gtk_widget_get_direction (widget);
10635 widget->priv->direction = dir;
10637 if (old_dir != gtk_widget_get_direction (widget))
10638 gtk_widget_emit_direction_changed (widget, old_dir);
10642 * gtk_widget_get_direction:
10643 * @widget: a #GtkWidget
10645 * Gets the reading direction for a particular widget. See
10646 * gtk_widget_set_direction().
10648 * Return value: the reading direction for the widget.
10651 gtk_widget_get_direction (GtkWidget *widget)
10653 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10655 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10656 return gtk_default_direction;
10658 return widget->priv->direction;
10662 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10664 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10666 g_object_ref (widget);
10668 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10669 gtk_widget_emit_direction_changed (widget, old_dir);
10671 if (GTK_IS_CONTAINER (widget))
10672 gtk_container_forall (GTK_CONTAINER (widget),
10673 gtk_widget_set_default_direction_recurse,
10676 g_object_unref (widget);
10680 * gtk_widget_set_default_direction:
10681 * @dir: the new default direction. This cannot be
10682 * %GTK_TEXT_DIR_NONE.
10684 * Sets the default reading direction for widgets where the
10685 * direction has not been explicitly set by gtk_widget_set_direction().
10688 gtk_widget_set_default_direction (GtkTextDirection dir)
10690 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10692 if (dir != gtk_default_direction)
10694 GList *toplevels, *tmp_list;
10695 GtkTextDirection old_dir = gtk_default_direction;
10697 gtk_default_direction = dir;
10699 tmp_list = toplevels = gtk_window_list_toplevels ();
10700 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10704 gtk_widget_set_default_direction_recurse (tmp_list->data,
10705 GUINT_TO_POINTER (old_dir));
10706 g_object_unref (tmp_list->data);
10707 tmp_list = tmp_list->next;
10710 g_list_free (toplevels);
10715 * gtk_widget_get_default_direction:
10717 * Obtains the current default reading direction. See
10718 * gtk_widget_set_default_direction().
10720 * Return value: the current default direction.
10723 gtk_widget_get_default_direction (void)
10725 return gtk_default_direction;
10729 gtk_widget_constructed (GObject *object)
10731 GtkWidget *widget = GTK_WIDGET (object);
10732 GtkWidgetPrivate *priv = widget->priv;
10734 /* As strange as it may seem, this may happen on object construction.
10735 * init() implementations of parent types may eventually call this function,
10736 * each with its corresponding GType, which could leave a child
10737 * implementation with a wrong widget type in the widget path
10740 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10742 gtk_widget_path_free (priv->path);
10746 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10750 gtk_widget_dispose (GObject *object)
10752 GtkWidget *widget = GTK_WIDGET (object);
10753 GtkWidgetPrivate *priv = widget->priv;
10756 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10757 else if (gtk_widget_get_visible (widget))
10758 gtk_widget_hide (widget);
10760 priv->visible = FALSE;
10761 if (gtk_widget_get_realized (widget))
10762 gtk_widget_unrealize (widget);
10764 if (!priv->in_destruction)
10766 priv->in_destruction = TRUE;
10767 g_signal_emit (object, widget_signals[DESTROY], 0);
10768 priv->in_destruction = FALSE;
10771 g_clear_object (&priv->muxer);
10773 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10777 gtk_widget_real_destroy (GtkWidget *object)
10779 /* gtk_object_destroy() will already hold a refcount on object */
10780 GtkWidget *widget = GTK_WIDGET (object);
10781 GtkWidgetPrivate *priv = widget->priv;
10784 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10786 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10790 gtk_accessible_set_widget (accessible, NULL);
10791 g_object_unref (accessible);
10795 /* wipe accelerator closures (keep order) */
10796 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10797 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10799 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10800 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10802 gtk_grab_remove (widget);
10804 for (l = priv->tick_callbacks; l;)
10806 GList *next = l->next;
10807 destroy_tick_callback_info (widget, l->data, l);
10812 g_object_unref (priv->style);
10813 priv->style = gtk_widget_get_default_style ();
10814 g_object_ref (priv->style);
10818 gtk_widget_finalize (GObject *object)
10820 GtkWidget *widget = GTK_WIDGET (object);
10821 GtkWidgetPrivate *priv = widget->priv;
10822 GtkWidgetAuxInfo *aux_info;
10823 GtkAccessible *accessible;
10825 gtk_grab_remove (widget);
10827 g_object_unref (priv->style);
10828 priv->style = NULL;
10830 g_free (priv->name);
10832 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10834 gtk_widget_aux_info_destroy (aux_info);
10836 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10838 g_object_unref (accessible);
10841 gtk_widget_path_free (priv->path);
10845 _gtk_style_context_set_widget (priv->context, NULL);
10846 g_object_unref (priv->context);
10849 _gtk_size_request_cache_free (&priv->requests);
10851 if (g_object_is_floating (object))
10852 g_warning ("A floating object was finalized. This means that someone\n"
10853 "called g_object_unref() on an object that had only a floating\n"
10854 "reference; the initial floating reference is not owned by anyone\n"
10855 "and must be removed with g_object_ref_sink().");
10857 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10860 /*****************************************
10861 * gtk_widget_real_map:
10866 *****************************************/
10869 gtk_widget_real_map (GtkWidget *widget)
10871 GtkWidgetPrivate *priv = widget->priv;
10873 g_assert (gtk_widget_get_realized (widget));
10875 if (!gtk_widget_get_mapped (widget))
10877 gtk_widget_set_mapped (widget, TRUE);
10879 if (gtk_widget_get_has_window (widget))
10880 gdk_window_show (priv->window);
10884 /*****************************************
10885 * gtk_widget_real_unmap:
10890 *****************************************/
10893 gtk_widget_real_unmap (GtkWidget *widget)
10895 GtkWidgetPrivate *priv = widget->priv;
10897 if (gtk_widget_get_mapped (widget))
10899 gtk_widget_set_mapped (widget, FALSE);
10901 if (gtk_widget_get_has_window (widget))
10902 gdk_window_hide (priv->window);
10906 /*****************************************
10907 * gtk_widget_real_realize:
10912 *****************************************/
10915 gtk_widget_real_realize (GtkWidget *widget)
10917 GtkWidgetPrivate *priv = widget->priv;
10919 g_assert (!gtk_widget_get_has_window (widget));
10921 gtk_widget_set_realized (widget, TRUE);
10924 priv->window = gtk_widget_get_parent_window (widget);
10925 g_object_ref (priv->window);
10929 /*****************************************
10930 * gtk_widget_real_unrealize:
10935 *****************************************/
10938 gtk_widget_real_unrealize (GtkWidget *widget)
10940 GtkWidgetPrivate *priv = widget->priv;
10942 g_assert (!widget->priv->mapped);
10944 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10947 /* We must do unrealize child widget BEFORE container widget.
10948 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10949 * So, unrealizing container widget bofore its children causes the problem
10950 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10953 if (GTK_IS_CONTAINER (widget))
10954 gtk_container_forall (GTK_CONTAINER (widget),
10955 (GtkCallback) gtk_widget_unrealize,
10958 if (gtk_widget_get_has_window (widget))
10960 gtk_widget_unregister_window (widget, priv->window);
10961 gdk_window_destroy (priv->window);
10962 priv->window = NULL;
10966 g_object_unref (priv->window);
10967 priv->window = NULL;
10970 gtk_selection_remove_all (widget);
10972 gtk_widget_set_realized (widget, FALSE);
10976 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10977 GtkOrientation orientation,
10978 gint *minimum_size,
10979 gint *natural_size)
10981 const GtkWidgetAuxInfo *aux_info;
10983 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10985 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10986 aux_info->width > 0)
10988 *minimum_size = MAX (*minimum_size, aux_info->width);
10990 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10991 aux_info->height > 0)
10993 *minimum_size = MAX (*minimum_size, aux_info->height);
10996 /* Fix it if set_size_request made natural size smaller than min size.
10997 * This would also silently fix broken widgets, but we warn about them
10998 * in gtksizerequest.c when calling their size request vfuncs.
11000 *natural_size = MAX (*natural_size, *minimum_size);
11002 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11004 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
11005 *natural_size += (aux_info->margin.left + aux_info->margin.right);
11009 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
11010 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
11015 * _gtk_widget_peek_request_cache:
11017 * Returns the address of the widget's request cache (strictly for
11018 * internal use in gtksizerequest.c)
11020 * Return value: the address of @widget's size request cache.
11023 _gtk_widget_peek_request_cache (GtkWidget *widget)
11025 /* Don't bother slowing things down with the return_if_fail guards here */
11026 return &widget->priv->requests;
11030 * _gtk_widget_set_device_window:
11031 * @widget: a #GtkWidget
11032 * @device: a #GdkDevice
11033 * @window: the new device window
11035 * Sets pointer window for @widget and @device.
11036 * Does not ref @window.
11039 _gtk_widget_set_device_window (GtkWidget *widget,
11043 GHashTable *device_window;
11045 g_return_if_fail (GTK_IS_WIDGET (widget));
11046 g_return_if_fail (GDK_IS_DEVICE (device));
11047 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11049 if (!gtk_widget_get_mapped (widget))
11052 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11054 if (!device_window && window)
11056 device_window = g_hash_table_new (NULL, NULL);
11057 g_object_set_qdata_full (G_OBJECT (widget),
11058 quark_pointer_window,
11060 (GDestroyNotify) g_hash_table_destroy);
11064 g_hash_table_insert (device_window, device, window);
11065 else if (device_window)
11067 g_hash_table_remove (device_window, device);
11069 if (g_hash_table_size (device_window) == 0)
11070 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
11075 * _gtk_widget_get_device_window:
11076 * @widget: a #GtkWidget
11077 * @device: a #GdkDevice
11079 * Return value: the device window set on @widget, or %NULL
11082 _gtk_widget_get_device_window (GtkWidget *widget,
11085 GHashTable *device_window;
11087 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11088 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
11090 if (!gtk_widget_get_mapped (widget))
11093 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11095 if (!device_window)
11098 return g_hash_table_lookup (device_window, device);
11102 * _gtk_widget_list_devices:
11103 * @widget: a #GtkWidget
11105 * Returns the list of #GdkDevices that is currently on top
11106 * of any window belonging to @widget.
11107 * Free the list with g_list_free(), the elements are owned
11108 * by GTK+ and must not be freed.
11111 _gtk_widget_list_devices (GtkWidget *widget)
11113 GHashTableIter iter;
11114 GHashTable *device_window;
11115 GList *devices = NULL;
11116 gpointer key, value;
11118 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11120 if (!gtk_widget_get_mapped (widget))
11123 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11125 if (G_UNLIKELY (!device_window))
11128 g_hash_table_iter_init (&iter, device_window);
11130 while (g_hash_table_iter_next (&iter, &key, &value))
11131 devices = g_list_prepend (devices, key);
11137 synth_crossing (GtkWidget *widget,
11141 GdkCrossingMode mode,
11142 GdkNotifyType detail)
11146 event = gdk_event_new (type);
11148 event->crossing.window = g_object_ref (window);
11149 event->crossing.send_event = TRUE;
11150 event->crossing.subwindow = g_object_ref (window);
11151 event->crossing.time = GDK_CURRENT_TIME;
11152 event->crossing.x = event->crossing.y = 0;
11153 event->crossing.x_root = event->crossing.y_root = 0;
11154 event->crossing.mode = mode;
11155 event->crossing.detail = detail;
11156 event->crossing.focus = FALSE;
11157 event->crossing.state = 0;
11158 gdk_event_set_device (event, device);
11161 widget = gtk_get_event_widget (event);
11164 gtk_widget_event_internal (widget, event);
11166 gdk_event_free (event);
11170 * _gtk_widget_synthesize_crossing:
11171 * @from: the #GtkWidget the virtual pointer is leaving.
11172 * @to: the #GtkWidget the virtual pointer is moving to.
11173 * @mode: the #GdkCrossingMode to place on the synthesized events.
11175 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11177 * The real pointer window is the window that most recently received an enter notify
11178 * event. Windows that don't select for crossing events can't become the real
11179 * poiner window. The real pointer widget that owns the real pointer window. The
11180 * effective pointer window is the same as the real pointer window unless the real
11181 * pointer widget is either insensitive or there is a grab on a widget that is not
11182 * an ancestor of the real pointer widget (in which case the effective pointer
11183 * window should be the root window).
11185 * When the effective pointer window is the same as the real poiner window, we
11186 * receive crossing events from the windowing system. When the effective pointer
11187 * window changes to become different from the real pointer window we synthesize
11188 * crossing events, attempting to follow X protocol rules:
11190 * When the root window becomes the effective pointer window:
11191 * - leave notify on real pointer window, detail Ancestor
11192 * - leave notify on all of its ancestors, detail Virtual
11193 * - enter notify on root window, detail Inferior
11195 * When the root window ceases to be the effective pointer window:
11196 * - leave notify on root window, detail Inferior
11197 * - enter notify on all ancestors of real pointer window, detail Virtual
11198 * - enter notify on real pointer window, detail Ancestor
11201 _gtk_widget_synthesize_crossing (GtkWidget *from,
11204 GdkCrossingMode mode)
11206 GdkWindow *from_window = NULL, *to_window = NULL;
11208 g_return_if_fail (from != NULL || to != NULL);
11212 from_window = _gtk_widget_get_device_window (from, device);
11215 from_window = from->priv->window;
11220 to_window = _gtk_widget_get_device_window (to, device);
11223 to_window = to->priv->window;
11226 if (from_window == NULL && to_window == NULL)
11228 else if (from_window != NULL && to_window == NULL)
11230 GList *from_ancestors = NULL, *list;
11231 GdkWindow *from_ancestor = from_window;
11233 while (from_ancestor != NULL)
11235 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11236 if (from_ancestor == NULL)
11238 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11241 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11242 device, mode, GDK_NOTIFY_ANCESTOR);
11243 for (list = g_list_last (from_ancestors); list; list = list->prev)
11245 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11246 device, mode, GDK_NOTIFY_VIRTUAL);
11249 /* XXX: enter/inferior on root window? */
11251 g_list_free (from_ancestors);
11253 else if (from_window == NULL && to_window != NULL)
11255 GList *to_ancestors = NULL, *list;
11256 GdkWindow *to_ancestor = to_window;
11258 while (to_ancestor != NULL)
11260 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11261 if (to_ancestor == NULL)
11263 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11266 /* XXX: leave/inferior on root window? */
11268 for (list = to_ancestors; list; list = list->next)
11270 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11271 device, mode, GDK_NOTIFY_VIRTUAL);
11273 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11274 device, mode, GDK_NOTIFY_ANCESTOR);
11276 g_list_free (to_ancestors);
11278 else if (from_window == to_window)
11282 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11283 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11285 while (from_ancestor != NULL || to_ancestor != NULL)
11287 if (from_ancestor != NULL)
11289 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11290 if (from_ancestor == to_window)
11293 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11295 if (to_ancestor != NULL)
11297 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11298 if (to_ancestor == from_window)
11301 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11304 if (to_ancestor == from_window)
11306 if (mode != GDK_CROSSING_GTK_UNGRAB)
11307 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11308 device, mode, GDK_NOTIFY_INFERIOR);
11309 for (list = to_ancestors; list; list = list->next)
11310 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11311 device, mode, GDK_NOTIFY_VIRTUAL);
11312 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11313 device, mode, GDK_NOTIFY_ANCESTOR);
11315 else if (from_ancestor == to_window)
11317 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11318 device, mode, GDK_NOTIFY_ANCESTOR);
11319 for (list = g_list_last (from_ancestors); list; list = list->prev)
11321 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11322 device, mode, GDK_NOTIFY_VIRTUAL);
11324 if (mode != GDK_CROSSING_GTK_GRAB)
11325 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11326 device, mode, GDK_NOTIFY_INFERIOR);
11330 while (from_ancestors != NULL && to_ancestors != NULL
11331 && from_ancestors->data == to_ancestors->data)
11333 from_ancestors = g_list_delete_link (from_ancestors,
11335 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11338 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11339 device, mode, GDK_NOTIFY_NONLINEAR);
11341 for (list = g_list_last (from_ancestors); list; list = list->prev)
11343 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11344 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11346 for (list = to_ancestors; list; list = list->next)
11348 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11349 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11351 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11352 device, mode, GDK_NOTIFY_NONLINEAR);
11354 g_list_free (from_ancestors);
11355 g_list_free (to_ancestors);
11360 gtk_widget_propagate_state (GtkWidget *widget,
11361 GtkStateData *data)
11363 GtkWidgetPrivate *priv = widget->priv;
11364 GtkStateFlags new_flags, old_flags = priv->state_flags;
11365 GtkStateType old_state;
11367 old_state = gtk_widget_get_state (widget);
11369 priv->state_flags |= data->flags_to_set;
11370 priv->state_flags &= ~(data->flags_to_unset);
11372 /* make insensitivity unoverridable */
11373 if (!priv->sensitive)
11374 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11376 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11380 window = gtk_widget_get_toplevel (widget);
11382 if (window && gtk_widget_is_toplevel (window))
11383 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11386 new_flags = priv->state_flags;
11388 if (old_flags != new_flags)
11390 g_object_ref (widget);
11392 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11393 gtk_grab_remove (widget);
11395 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11397 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11398 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11400 if (!priv->shadowed &&
11401 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11403 GList *event_windows = NULL;
11404 GList *devices, *d;
11406 devices = _gtk_widget_list_devices (widget);
11408 for (d = devices; d; d = d->next)
11414 window = _gtk_widget_get_device_window (widget, device);
11416 /* Do not propagate more than once to the
11417 * same window if non-multidevice aware.
11419 if (!gdk_window_get_support_multidevice (window) &&
11420 g_list_find (event_windows, window))
11423 if (!gtk_widget_is_sensitive (widget))
11424 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11425 GDK_CROSSING_STATE_CHANGED);
11427 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11428 GDK_CROSSING_STATE_CHANGED);
11430 event_windows = g_list_prepend (event_windows, window);
11433 g_list_free (event_windows);
11434 g_list_free (devices);
11437 if (GTK_IS_CONTAINER (widget))
11439 GtkStateData child_data;
11441 /* Make sure to only propate the right states further */
11442 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11443 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11445 gtk_container_forall (GTK_CONTAINER (widget),
11446 (GtkCallback) gtk_widget_propagate_state,
11450 g_object_unref (widget);
11454 static const GtkWidgetAuxInfo default_aux_info = {
11462 * gtk_widget_get_aux_info:
11463 * @widget: a #GtkWidget
11464 * @create: if %TRUE, create the structure if it doesn't exist
11466 * Get the #GtkWidgetAuxInfo structure for the widget.
11468 * Return value: the #GtkAuxInfo structure for the widget, or
11469 * %NULL if @create is %FALSE and one doesn't already exist.
11471 static GtkWidgetAuxInfo *
11472 gtk_widget_get_aux_info (GtkWidget *widget,
11475 GtkWidgetAuxInfo *aux_info;
11477 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11478 if (!aux_info && create)
11480 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11482 *aux_info = default_aux_info;
11484 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11490 static const GtkWidgetAuxInfo*
11491 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11493 GtkWidgetAuxInfo *aux_info;
11495 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11496 if (aux_info == NULL)
11498 return &default_aux_info;
11506 /*****************************************
11507 * gtk_widget_aux_info_destroy:
11512 *****************************************/
11515 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11517 g_slice_free (GtkWidgetAuxInfo, aux_info);
11521 * gtk_widget_shape_combine_region:
11522 * @widget: a #GtkWidget
11523 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11525 * Sets a shape for this widget's GDK window. This allows for
11526 * transparent windows etc., see gdk_window_shape_combine_region()
11527 * for more information.
11532 gtk_widget_shape_combine_region (GtkWidget *widget,
11533 cairo_region_t *region)
11535 GtkWidgetPrivate *priv;
11537 g_return_if_fail (GTK_IS_WIDGET (widget));
11538 /* set_shape doesn't work on widgets without gdk window */
11539 g_return_if_fail (gtk_widget_get_has_window (widget));
11541 priv = widget->priv;
11543 if (region == NULL)
11545 priv->has_shape_mask = FALSE;
11548 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11550 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11554 priv->has_shape_mask = TRUE;
11556 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11557 cairo_region_copy (region),
11558 (GDestroyNotify) cairo_region_destroy);
11560 /* set shape if widget has a gdk window already.
11561 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11564 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11569 * gtk_widget_input_shape_combine_region:
11570 * @widget: a #GtkWidget
11571 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11573 * Sets an input shape for this widget's GDK window. This allows for
11574 * windows which react to mouse click in a nonrectangular region, see
11575 * gdk_window_input_shape_combine_region() for more information.
11580 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11581 cairo_region_t *region)
11583 GtkWidgetPrivate *priv;
11585 g_return_if_fail (GTK_IS_WIDGET (widget));
11586 /* set_shape doesn't work on widgets without gdk window */
11587 g_return_if_fail (gtk_widget_get_has_window (widget));
11589 priv = widget->priv;
11591 if (region == NULL)
11594 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11596 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11600 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11601 cairo_region_copy (region),
11602 (GDestroyNotify) cairo_region_destroy);
11604 /* set shape if widget has a gdk window already.
11605 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11608 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11613 /* style properties
11617 * gtk_widget_class_install_style_property_parser: (skip)
11618 * @klass: a #GtkWidgetClass
11619 * @pspec: the #GParamSpec for the style property
11620 * @parser: the parser for the style property
11622 * Installs a style property on a widget class.
11625 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11627 GtkRcPropertyParser parser)
11629 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11630 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11631 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11632 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11634 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11636 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11637 G_OBJECT_CLASS_NAME (klass),
11642 g_param_spec_ref_sink (pspec);
11643 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11644 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11648 * gtk_widget_class_install_style_property:
11649 * @klass: a #GtkWidgetClass
11650 * @pspec: the #GParamSpec for the property
11652 * Installs a style property on a widget class. The parser for the
11653 * style property is determined by the value type of @pspec.
11656 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11659 GtkRcPropertyParser parser;
11661 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11662 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11664 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11666 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11670 * gtk_widget_class_find_style_property:
11671 * @klass: a #GtkWidgetClass
11672 * @property_name: the name of the style property to find
11674 * Finds a style property of a widget class by name.
11676 * Returns: (transfer none): the #GParamSpec of the style property or
11677 * %NULL if @class has no style property with that name.
11682 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11683 const gchar *property_name)
11685 g_return_val_if_fail (property_name != NULL, NULL);
11687 return g_param_spec_pool_lookup (style_property_spec_pool,
11689 G_OBJECT_CLASS_TYPE (klass),
11694 * gtk_widget_class_list_style_properties:
11695 * @klass: a #GtkWidgetClass
11696 * @n_properties: location to return the number of style properties found
11698 * Returns all style properties of a widget class.
11700 * Returns: (array length=n_properties) (transfer container): a
11701 * newly allocated array of #GParamSpec*. The array must be
11702 * freed with g_free().
11707 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11708 guint *n_properties)
11710 GParamSpec **pspecs;
11713 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11714 G_OBJECT_CLASS_TYPE (klass),
11723 * gtk_widget_style_get_property:
11724 * @widget: a #GtkWidget
11725 * @property_name: the name of a style property
11726 * @value: location to return the property value
11728 * Gets the value of a style property of @widget.
11731 gtk_widget_style_get_property (GtkWidget *widget,
11732 const gchar *property_name,
11737 g_return_if_fail (GTK_IS_WIDGET (widget));
11738 g_return_if_fail (property_name != NULL);
11739 g_return_if_fail (G_IS_VALUE (value));
11741 g_object_ref (widget);
11742 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11744 G_OBJECT_TYPE (widget),
11747 g_warning ("%s: widget class `%s' has no property named `%s'",
11749 G_OBJECT_TYPE_NAME (widget),
11753 GtkStyleContext *context;
11754 const GValue *peek_value;
11755 GtkStateFlags state;
11757 context = gtk_widget_get_style_context (widget);
11758 state = gtk_widget_get_state_flags (widget);
11760 peek_value = _gtk_style_context_peek_style_property (context,
11761 G_OBJECT_TYPE (widget),
11764 /* auto-conversion of the caller's value type
11766 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11767 g_value_copy (peek_value, value);
11768 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11769 g_value_transform (peek_value, value);
11771 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11773 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11774 G_VALUE_TYPE_NAME (value));
11776 g_object_unref (widget);
11780 * gtk_widget_style_get_valist:
11781 * @widget: a #GtkWidget
11782 * @first_property_name: the name of the first property to get
11783 * @var_args: a <type>va_list</type> of pairs of property names and
11784 * locations to return the property values, starting with the location
11785 * for @first_property_name.
11787 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11791 gtk_widget_style_get_valist (GtkWidget *widget,
11792 const gchar *first_property_name,
11795 GtkStyleContext *context;
11796 GtkStateFlags state;
11799 g_return_if_fail (GTK_IS_WIDGET (widget));
11801 g_object_ref (widget);
11802 context = gtk_widget_get_style_context (widget);
11803 state = gtk_widget_get_state_flags (widget);
11805 name = first_property_name;
11808 const GValue *peek_value;
11812 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11814 G_OBJECT_TYPE (widget),
11818 g_warning ("%s: widget class `%s' has no property named `%s'",
11820 G_OBJECT_TYPE_NAME (widget),
11824 /* style pspecs are always readable so we can spare that check here */
11826 peek_value = _gtk_style_context_peek_style_property (context,
11827 G_OBJECT_TYPE (widget),
11830 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11833 g_warning ("%s: %s", G_STRLOC, error);
11838 name = va_arg (var_args, gchar*);
11841 g_object_unref (widget);
11845 * gtk_widget_style_get:
11846 * @widget: a #GtkWidget
11847 * @first_property_name: the name of the first property to get
11848 * @...: pairs of property names and locations to return the
11849 * property values, starting with the location for
11850 * @first_property_name, terminated by %NULL.
11852 * Gets the values of a multiple style properties of @widget.
11855 gtk_widget_style_get (GtkWidget *widget,
11856 const gchar *first_property_name,
11861 g_return_if_fail (GTK_IS_WIDGET (widget));
11863 va_start (var_args, first_property_name);
11864 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11869 * gtk_requisition_new:
11871 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11873 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11874 * be freed with gtk_requisition_free().
11879 gtk_requisition_new (void)
11881 return g_slice_new0 (GtkRequisition);
11885 * gtk_requisition_copy:
11886 * @requisition: a #GtkRequisition
11888 * Copies a #GtkRequisition.
11890 * Returns: a copy of @requisition
11893 gtk_requisition_copy (const GtkRequisition *requisition)
11895 return g_slice_dup (GtkRequisition, requisition);
11899 * gtk_requisition_free:
11900 * @requisition: a #GtkRequisition
11902 * Frees a #GtkRequisition.
11905 gtk_requisition_free (GtkRequisition *requisition)
11907 g_slice_free (GtkRequisition, requisition);
11910 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11911 gtk_requisition_copy,
11912 gtk_requisition_free)
11915 * gtk_widget_class_set_accessible_type:
11916 * @widget_class: class to set the accessible type for
11917 * @type: The object type that implements the accessible for @widget_class
11919 * Sets the type to be used for creating accessibles for widgets of
11920 * @widget_class. The given @type must be a subtype of the type used for
11921 * accessibles of the parent class.
11923 * This function should only be called from class init functions of widgets.
11928 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11931 GtkWidgetClassPrivate *priv;
11933 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11934 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11936 priv = widget_class->priv;
11938 priv->accessible_type = type;
11939 /* reset this - honoring the type's role is better. */
11940 priv->accessible_role = ATK_ROLE_INVALID;
11944 * gtk_widget_class_set_accessible_role:
11945 * @widget_class: class to set the accessible role for
11946 * @role: The role to use for accessibles created for @widget_class
11948 * Sets the default #AtkRole to be set on accessibles created for
11949 * widgets of @widget_class. Accessibles may decide to not honor this
11950 * setting if their role reporting is more refined. Calls to
11951 * gtk_widget_class_set_accessible_type() will reset this value.
11953 * In cases where you want more fine-grained control over the role of
11954 * accessibles created for @widget_class, you should provide your own
11955 * accessible type and use gtk_widget_class_set_accessible_type()
11958 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11959 * and the accessible's default role will be used instead.
11961 * This function should only be called from class init functions of widgets.
11966 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11969 GtkWidgetClassPrivate *priv;
11971 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11973 priv = widget_class->priv;
11975 priv->accessible_role = role;
11979 * _gtk_widget_peek_accessible:
11980 * @widget: a #GtkWidget
11982 * Gets the accessible for @widget, if it has been created yet.
11983 * Otherwise, this function returns %NULL. If the @widget's implementation
11984 * does not use the default way to create accessibles, %NULL will always be
11987 * Returns: the accessible for @widget or %NULL if none has been
11991 _gtk_widget_peek_accessible (GtkWidget *widget)
11993 return g_object_get_qdata (G_OBJECT (widget),
11994 quark_accessible_object);
11998 * gtk_widget_get_accessible:
11999 * @widget: a #GtkWidget
12001 * Returns the accessible object that describes the widget to an
12002 * assistive technology.
12004 * If accessibility support is not available, this #AtkObject
12005 * instance may be a no-op. Likewise, if no class-specific #AtkObject
12006 * implementation is available for the widget instance in question,
12007 * it will inherit an #AtkObject implementation from the first ancestor
12008 * class for which such an implementation is defined.
12010 * The documentation of the
12011 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
12012 * library contains more information about accessible objects and their uses.
12014 * Returns: (transfer none): the #AtkObject associated with @widget
12017 gtk_widget_get_accessible (GtkWidget *widget)
12019 GtkWidgetClass *klass;
12021 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12023 klass = GTK_WIDGET_GET_CLASS (widget);
12025 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
12027 return klass->get_accessible (widget);
12031 gtk_widget_real_get_accessible (GtkWidget *widget)
12033 AtkObject* accessible;
12035 accessible = g_object_get_qdata (G_OBJECT (widget),
12036 quark_accessible_object);
12039 GtkWidgetClass *widget_class;
12040 GtkWidgetClassPrivate *priv;
12041 AtkObjectFactory *factory;
12042 AtkRegistry *default_registry;
12044 widget_class = GTK_WIDGET_GET_CLASS (widget);
12045 priv = widget_class->priv;
12047 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
12049 default_registry = atk_get_default_registry ();
12050 factory = atk_registry_get_factory (default_registry,
12051 G_TYPE_FROM_INSTANCE (widget));
12053 atk_object_factory_create_accessible (factory,
12054 G_OBJECT (widget));
12056 if (priv->accessible_role != ATK_ROLE_INVALID)
12057 atk_object_set_role (accessible, priv->accessible_role);
12059 g_object_set_qdata (G_OBJECT (widget),
12060 quark_accessible_object,
12065 accessible = g_object_new (priv->accessible_type,
12068 if (priv->accessible_role != ATK_ROLE_INVALID)
12069 atk_object_set_role (accessible, priv->accessible_role);
12071 g_object_set_qdata (G_OBJECT (widget),
12072 quark_accessible_object,
12075 atk_object_initialize (accessible, widget);
12077 /* Set the role again, since we don't want a role set
12078 * in some parent initialize() function to override
12081 if (priv->accessible_role != ATK_ROLE_INVALID)
12082 atk_object_set_role (accessible, priv->accessible_role);
12089 * Initialize a AtkImplementorIface instance's virtual pointers as
12090 * appropriate to this implementor's class (GtkWidget).
12093 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
12095 iface->ref_accessible = gtk_widget_ref_accessible;
12099 gtk_widget_ref_accessible (AtkImplementor *implementor)
12101 AtkObject *accessible;
12103 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
12105 g_object_ref (accessible);
12110 * Expand flag management
12114 gtk_widget_update_computed_expand (GtkWidget *widget)
12116 GtkWidgetPrivate *priv;
12118 priv = widget->priv;
12120 if (priv->need_compute_expand)
12124 if (priv->hexpand_set)
12129 if (priv->vexpand_set)
12134 /* we don't need to use compute_expand if both expands are
12135 * forced by the app
12137 if (!(priv->hexpand_set && priv->vexpand_set))
12139 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12143 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12144 priv->hexpand_set ? &ignored : &h,
12145 priv->vexpand_set ? &ignored : &v);
12149 priv->need_compute_expand = FALSE;
12150 priv->computed_hexpand = h != FALSE;
12151 priv->computed_vexpand = v != FALSE;
12156 * gtk_widget_queue_compute_expand:
12157 * @widget: a #GtkWidget
12159 * Mark @widget as needing to recompute its expand flags. Call
12160 * this function when setting legacy expand child properties
12161 * on the child of a container.
12163 * See gtk_widget_compute_expand().
12166 gtk_widget_queue_compute_expand (GtkWidget *widget)
12169 gboolean changed_anything;
12171 if (widget->priv->need_compute_expand)
12174 changed_anything = FALSE;
12176 while (parent != NULL)
12178 if (!parent->priv->need_compute_expand)
12180 parent->priv->need_compute_expand = TRUE;
12181 changed_anything = TRUE;
12184 /* Note: if we had an invariant that "if a child needs to
12185 * compute expand, its parents also do" then we could stop going
12186 * up when we got to a parent that already needed to
12187 * compute. However, in general we compute expand lazily (as
12188 * soon as we see something in a subtree that is expand, we know
12189 * we're expanding) and so this invariant does not hold and we
12190 * have to always walk all the way up in case some ancestor
12191 * is not currently need_compute_expand.
12194 parent = parent->priv->parent;
12197 /* recomputing expand always requires
12198 * a relayout as well
12200 if (changed_anything)
12201 gtk_widget_queue_resize (widget);
12205 * gtk_widget_compute_expand:
12206 * @widget: the widget
12207 * @orientation: expand direction
12209 * Computes whether a container should give this widget extra space
12210 * when possible. Containers should check this, rather than
12211 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12213 * This function already checks whether the widget is visible, so
12214 * visibility does not need to be checked separately. Non-visible
12215 * widgets are not expanded.
12217 * The computed expand value uses either the expand setting explicitly
12218 * set on the widget itself, or, if none has been explicitly set,
12219 * the widget may expand if some of its children do.
12221 * Return value: whether widget tree rooted here should be expanded
12224 gtk_widget_compute_expand (GtkWidget *widget,
12225 GtkOrientation orientation)
12227 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12229 /* We never make a widget expand if not even showing. */
12230 if (!gtk_widget_get_visible (widget))
12233 gtk_widget_update_computed_expand (widget);
12235 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12237 return widget->priv->computed_hexpand;
12241 return widget->priv->computed_vexpand;
12246 gtk_widget_set_expand (GtkWidget *widget,
12247 GtkOrientation orientation,
12250 const char *expand_prop;
12251 const char *expand_set_prop;
12253 GtkWidgetPrivate *priv;
12255 g_return_if_fail (GTK_IS_WIDGET (widget));
12257 priv = widget->priv;
12259 expand = expand != FALSE;
12261 was_both = priv->hexpand && priv->vexpand;
12263 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12265 if (priv->hexpand_set &&
12266 priv->hexpand == expand)
12269 priv->hexpand_set = TRUE;
12270 priv->hexpand = expand;
12272 expand_prop = "hexpand";
12273 expand_set_prop = "hexpand-set";
12277 if (priv->vexpand_set &&
12278 priv->vexpand == expand)
12281 priv->vexpand_set = TRUE;
12282 priv->vexpand = expand;
12284 expand_prop = "vexpand";
12285 expand_set_prop = "vexpand-set";
12288 gtk_widget_queue_compute_expand (widget);
12290 g_object_freeze_notify (G_OBJECT (widget));
12291 g_object_notify (G_OBJECT (widget), expand_prop);
12292 g_object_notify (G_OBJECT (widget), expand_set_prop);
12293 if (was_both != (priv->hexpand && priv->vexpand))
12294 g_object_notify (G_OBJECT (widget), "expand");
12295 g_object_thaw_notify (G_OBJECT (widget));
12299 gtk_widget_set_expand_set (GtkWidget *widget,
12300 GtkOrientation orientation,
12303 GtkWidgetPrivate *priv;
12306 priv = widget->priv;
12308 set = set != FALSE;
12310 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12312 if (set == priv->hexpand_set)
12315 priv->hexpand_set = set;
12316 prop = "hexpand-set";
12320 if (set == priv->vexpand_set)
12323 priv->vexpand_set = set;
12324 prop = "vexpand-set";
12327 gtk_widget_queue_compute_expand (widget);
12329 g_object_notify (G_OBJECT (widget), prop);
12333 * gtk_widget_get_hexpand:
12334 * @widget: the widget
12336 * Gets whether the widget would like any available extra horizontal
12337 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12338 * generally receive the extra space. For example, a list or
12339 * scrollable area or document in your window would often be set to
12342 * Containers should use gtk_widget_compute_expand() rather than
12343 * this function, to see whether a widget, or any of its children,
12344 * has the expand flag set. If any child of a widget wants to
12345 * expand, the parent may ask to expand also.
12347 * This function only looks at the widget's own hexpand flag, rather
12348 * than computing whether the entire widget tree rooted at this widget
12351 * Return value: whether hexpand flag is set
12354 gtk_widget_get_hexpand (GtkWidget *widget)
12356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12358 return widget->priv->hexpand;
12362 * gtk_widget_set_hexpand:
12363 * @widget: the widget
12364 * @expand: whether to expand
12366 * Sets whether the widget would like any available extra horizontal
12367 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12368 * generally receive the extra space. For example, a list or
12369 * scrollable area or document in your window would often be set to
12372 * Call this function to set the expand flag if you would like your
12373 * widget to become larger horizontally when the window has extra
12376 * By default, widgets automatically expand if any of their children
12377 * want to expand. (To see if a widget will automatically expand given
12378 * its current children and state, call gtk_widget_compute_expand(). A
12379 * container can decide how the expandability of children affects the
12380 * expansion of the container by overriding the compute_expand virtual
12381 * method on #GtkWidget.).
12383 * Setting hexpand explicitly with this function will override the
12384 * automatic expand behavior.
12386 * This function forces the widget to expand or not to expand,
12387 * regardless of children. The override occurs because
12388 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12389 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12390 * value to be used, rather than looking at children and widget state.
12393 gtk_widget_set_hexpand (GtkWidget *widget,
12396 g_return_if_fail (GTK_IS_WIDGET (widget));
12398 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12402 * gtk_widget_get_hexpand_set:
12403 * @widget: the widget
12405 * Gets whether gtk_widget_set_hexpand() has been used to
12406 * explicitly set the expand flag on this widget.
12408 * If hexpand is set, then it overrides any computed
12409 * expand value based on child widgets. If hexpand is not
12410 * set, then the expand value depends on whether any
12411 * children of the widget would like to expand.
12413 * There are few reasons to use this function, but it's here
12414 * for completeness and consistency.
12416 * Return value: whether hexpand has been explicitly set
12419 gtk_widget_get_hexpand_set (GtkWidget *widget)
12421 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12423 return widget->priv->hexpand_set;
12427 * gtk_widget_set_hexpand_set:
12428 * @widget: the widget
12429 * @set: value for hexpand-set property
12431 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12434 * The hexpand-set property will be set automatically when you call
12435 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12436 * reason to use this function would be to unset an explicit expand
12439 * If hexpand is set, then it overrides any computed
12440 * expand value based on child widgets. If hexpand is not
12441 * set, then the expand value depends on whether any
12442 * children of the widget would like to expand.
12444 * There are few reasons to use this function, but it's here
12445 * for completeness and consistency.
12448 gtk_widget_set_hexpand_set (GtkWidget *widget,
12451 g_return_if_fail (GTK_IS_WIDGET (widget));
12453 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12458 * gtk_widget_get_vexpand:
12459 * @widget: the widget
12461 * Gets whether the widget would like any available extra vertical
12464 * See gtk_widget_get_hexpand() for more detail.
12466 * Return value: whether vexpand flag is set
12469 gtk_widget_get_vexpand (GtkWidget *widget)
12471 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12473 return widget->priv->vexpand;
12477 * gtk_widget_set_vexpand:
12478 * @widget: the widget
12479 * @expand: whether to expand
12481 * Sets whether the widget would like any available extra vertical
12484 * See gtk_widget_set_hexpand() for more detail.
12487 gtk_widget_set_vexpand (GtkWidget *widget,
12490 g_return_if_fail (GTK_IS_WIDGET (widget));
12492 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12496 * gtk_widget_get_vexpand_set:
12497 * @widget: the widget
12499 * Gets whether gtk_widget_set_vexpand() has been used to
12500 * explicitly set the expand flag on this widget.
12502 * See gtk_widget_get_hexpand_set() for more detail.
12504 * Return value: whether vexpand has been explicitly set
12507 gtk_widget_get_vexpand_set (GtkWidget *widget)
12509 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12511 return widget->priv->vexpand_set;
12515 * gtk_widget_set_vexpand_set:
12516 * @widget: the widget
12517 * @set: value for vexpand-set property
12519 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12522 * See gtk_widget_set_hexpand_set() for more detail.
12525 gtk_widget_set_vexpand_set (GtkWidget *widget,
12528 g_return_if_fail (GTK_IS_WIDGET (widget));
12530 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12534 * GtkBuildable implementation
12536 static GQuark quark_builder_has_default = 0;
12537 static GQuark quark_builder_has_focus = 0;
12538 static GQuark quark_builder_atk_relations = 0;
12539 static GQuark quark_builder_set_name = 0;
12542 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12544 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12545 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12546 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12547 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12549 iface->set_name = gtk_widget_buildable_set_name;
12550 iface->get_name = gtk_widget_buildable_get_name;
12551 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12552 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12553 iface->parser_finished = gtk_widget_buildable_parser_finished;
12554 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12555 iface->custom_finished = gtk_widget_buildable_custom_finished;
12559 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12562 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12563 g_strdup (name), g_free);
12566 static const gchar *
12567 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12569 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12573 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12574 GtkBuilder *builder,
12575 const gchar *childname)
12577 if (strcmp (childname, "accessible") == 0)
12578 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12584 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12585 GtkBuilder *builder,
12587 const GValue *value)
12589 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12590 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12591 GINT_TO_POINTER (TRUE));
12592 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12593 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12594 GINT_TO_POINTER (TRUE));
12596 g_object_set_property (G_OBJECT (buildable), name, value);
12601 gchar *action_name;
12602 GString *description;
12604 gboolean translatable;
12614 free_action (AtkActionData *data, gpointer user_data)
12616 g_free (data->action_name);
12617 g_string_free (data->description, TRUE);
12618 g_free (data->context);
12619 g_slice_free (AtkActionData, data);
12623 free_relation (AtkRelationData *data, gpointer user_data)
12625 g_free (data->target);
12626 g_free (data->type);
12627 g_slice_free (AtkRelationData, data);
12631 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12632 GtkBuilder *builder)
12634 GSList *atk_relations;
12636 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12637 gtk_widget_grab_default (GTK_WIDGET (buildable));
12638 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12639 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12641 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12642 quark_builder_atk_relations);
12645 AtkObject *accessible;
12646 AtkRelationSet *relation_set;
12649 AtkRelationType relation_type;
12650 AtkObject *target_accessible;
12652 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12653 relation_set = atk_object_ref_relation_set (accessible);
12655 for (l = atk_relations; l; l = l->next)
12657 AtkRelationData *relation = (AtkRelationData*)l->data;
12659 target = gtk_builder_get_object (builder, relation->target);
12662 g_warning ("Target object %s in <relation> does not exist",
12666 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12667 g_assert (target_accessible != NULL);
12669 relation_type = atk_relation_type_for_name (relation->type);
12670 if (relation_type == ATK_RELATION_NULL)
12672 g_warning ("<relation> type %s not found",
12676 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12677 target_accessible);
12679 g_object_unref (relation_set);
12681 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12682 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12691 } AccessibilitySubParserData;
12694 accessibility_start_element (GMarkupParseContext *context,
12695 const gchar *element_name,
12696 const gchar **names,
12697 const gchar **values,
12698 gpointer user_data,
12701 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12703 gint line_number, char_number;
12705 if (strcmp (element_name, "relation") == 0)
12707 gchar *target = NULL;
12708 gchar *type = NULL;
12709 AtkRelationData *relation;
12711 for (i = 0; names[i]; i++)
12713 if (strcmp (names[i], "target") == 0)
12714 target = g_strdup (values[i]);
12715 else if (strcmp (names[i], "type") == 0)
12716 type = g_strdup (values[i]);
12719 g_markup_parse_context_get_position (context,
12722 g_set_error (error,
12724 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12725 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12727 line_number, char_number, names[i], "relation");
12734 if (!target || !type)
12736 g_markup_parse_context_get_position (context,
12739 g_set_error (error,
12741 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12742 "%s:%d:%d <%s> requires attribute \"%s\"",
12744 line_number, char_number, "relation",
12745 type ? "target" : "type");
12751 relation = g_slice_new (AtkRelationData);
12752 relation->target = target;
12753 relation->type = type;
12755 data->relations = g_slist_prepend (data->relations, relation);
12757 else if (strcmp (element_name, "action") == 0)
12759 const gchar *action_name = NULL;
12760 const gchar *description = NULL;
12761 const gchar *msg_context = NULL;
12762 gboolean translatable = FALSE;
12763 AtkActionData *action;
12765 for (i = 0; names[i]; i++)
12767 if (strcmp (names[i], "action_name") == 0)
12768 action_name = values[i];
12769 else if (strcmp (names[i], "description") == 0)
12770 description = values[i];
12771 else if (strcmp (names[i], "translatable") == 0)
12773 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12776 else if (strcmp (names[i], "comments") == 0)
12778 /* do nothing, comments are for translators */
12780 else if (strcmp (names[i], "context") == 0)
12781 msg_context = values[i];
12784 g_markup_parse_context_get_position (context,
12787 g_set_error (error,
12789 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12790 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12792 line_number, char_number, names[i], "action");
12799 g_markup_parse_context_get_position (context,
12802 g_set_error (error,
12804 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12805 "%s:%d:%d <%s> requires attribute \"%s\"",
12807 line_number, char_number, "action",
12812 action = g_slice_new (AtkActionData);
12813 action->action_name = g_strdup (action_name);
12814 action->description = g_string_new (description);
12815 action->context = g_strdup (msg_context);
12816 action->translatable = translatable;
12818 data->actions = g_slist_prepend (data->actions, action);
12820 else if (strcmp (element_name, "accessibility") == 0)
12823 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12827 accessibility_text (GMarkupParseContext *context,
12830 gpointer user_data,
12833 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12835 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12837 AtkActionData *action = data->actions->data;
12839 g_string_append_len (action->description, text, text_len);
12843 static const GMarkupParser accessibility_parser =
12845 accessibility_start_element,
12847 accessibility_text,
12856 } AccelGroupParserData;
12859 accel_group_start_element (GMarkupParseContext *context,
12860 const gchar *element_name,
12861 const gchar **names,
12862 const gchar **values,
12863 gpointer user_data,
12868 guint modifiers = 0;
12869 gchar *signal = NULL;
12870 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12872 for (i = 0; names[i]; i++)
12874 if (strcmp (names[i], "key") == 0)
12875 key = gdk_keyval_from_name (values[i]);
12876 else if (strcmp (names[i], "modifiers") == 0)
12878 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12884 else if (strcmp (names[i], "signal") == 0)
12885 signal = g_strdup (values[i]);
12888 if (key == 0 || signal == NULL)
12890 g_warning ("<accelerator> requires key and signal attributes");
12893 parser_data->key = key;
12894 parser_data->modifiers = modifiers;
12895 parser_data->signal = signal;
12898 static const GMarkupParser accel_group_parser =
12900 accel_group_start_element,
12909 style_start_element (GMarkupParseContext *context,
12910 const gchar *element_name,
12911 const gchar **names,
12912 const gchar **values,
12913 gpointer user_data,
12916 StyleParserData *style_data = (StyleParserData *)user_data;
12919 if (strcmp (element_name, "class") == 0)
12921 if (g_markup_collect_attributes (element_name,
12925 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12926 G_MARKUP_COLLECT_INVALID))
12928 style_data->classes = g_slist_append (style_data->classes, class_name);
12931 else if (strcmp (element_name, "style") == 0)
12934 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12937 static const GMarkupParser style_parser =
12939 style_start_element,
12943 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12944 GtkBuilder *builder,
12946 const gchar *tagname,
12947 GMarkupParser *parser,
12950 g_assert (buildable);
12952 if (strcmp (tagname, "accelerator") == 0)
12954 AccelGroupParserData *parser_data;
12956 parser_data = g_slice_new0 (AccelGroupParserData);
12957 parser_data->object = g_object_ref (buildable);
12958 *parser = accel_group_parser;
12959 *data = parser_data;
12962 if (strcmp (tagname, "accessibility") == 0)
12964 AccessibilitySubParserData *parser_data;
12966 parser_data = g_slice_new0 (AccessibilitySubParserData);
12967 *parser = accessibility_parser;
12968 *data = parser_data;
12971 if (strcmp (tagname, "style") == 0)
12973 StyleParserData *parser_data;
12975 parser_data = g_slice_new0 (StyleParserData);
12976 *parser = style_parser;
12977 *data = parser_data;
12985 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12986 GtkWidget *toplevel,
12987 gpointer user_data)
12989 AccelGroupParserData *accel_data;
12990 GSList *accel_groups;
12991 GtkAccelGroup *accel_group;
12993 g_return_if_fail (GTK_IS_WIDGET (widget));
12994 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12995 g_return_if_fail (user_data != NULL);
12997 accel_data = (AccelGroupParserData*)user_data;
12998 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12999 if (g_slist_length (accel_groups) == 0)
13001 accel_group = gtk_accel_group_new ();
13002 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
13006 g_assert (g_slist_length (accel_groups) == 1);
13007 accel_group = g_slist_nth_data (accel_groups, 0);
13010 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
13011 accel_data->signal,
13014 accel_data->modifiers,
13015 GTK_ACCEL_VISIBLE);
13017 g_object_unref (accel_data->object);
13018 g_free (accel_data->signal);
13019 g_slice_free (AccelGroupParserData, accel_data);
13023 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
13024 GtkBuilder *builder,
13026 const gchar *tagname,
13027 gpointer user_data)
13029 if (strcmp (tagname, "accelerator") == 0)
13031 AccelGroupParserData *accel_data;
13032 GtkWidget *toplevel;
13034 accel_data = (AccelGroupParserData*)user_data;
13035 g_assert (accel_data->object);
13037 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
13039 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
13041 else if (strcmp (tagname, "accessibility") == 0)
13043 AccessibilitySubParserData *a11y_data;
13045 a11y_data = (AccessibilitySubParserData*)user_data;
13047 if (a11y_data->actions)
13049 AtkObject *accessible;
13054 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
13056 if (ATK_IS_ACTION (accessible))
13058 action = ATK_ACTION (accessible);
13059 n_actions = atk_action_get_n_actions (action);
13061 for (l = a11y_data->actions; l; l = l->next)
13063 AtkActionData *action_data = (AtkActionData*)l->data;
13065 for (i = 0; i < n_actions; i++)
13066 if (strcmp (atk_action_get_name (action, i),
13067 action_data->action_name) == 0)
13072 gchar *description;
13074 if (action_data->translatable && action_data->description->len)
13075 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
13076 action_data->context,
13077 action_data->description->str);
13079 description = action_data->description->str;
13081 atk_action_set_description (action, i, description);
13086 g_warning ("accessibility action on a widget that does not implement AtkAction");
13088 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
13091 if (a11y_data->relations)
13092 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
13093 a11y_data->relations);
13095 g_slice_free (AccessibilitySubParserData, a11y_data);
13097 else if (strcmp (tagname, "style") == 0)
13099 StyleParserData *style_data = (StyleParserData *)user_data;
13100 GtkStyleContext *context;
13103 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
13105 for (l = style_data->classes; l; l = l->next)
13106 gtk_style_context_add_class (context, (const gchar *)l->data);
13108 gtk_widget_reset_style (GTK_WIDGET (buildable));
13110 g_slist_free_full (style_data->classes, g_free);
13111 g_slice_free (StyleParserData, style_data);
13115 static GtkSizeRequestMode
13116 gtk_widget_real_get_request_mode (GtkWidget *widget)
13118 /* By default widgets dont trade size at all. */
13119 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13123 gtk_widget_real_get_width (GtkWidget *widget,
13124 gint *minimum_size,
13125 gint *natural_size)
13135 gtk_widget_real_get_height (GtkWidget *widget,
13136 gint *minimum_size,
13137 gint *natural_size)
13147 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13149 gint *minimum_height,
13150 gint *natural_height)
13152 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13156 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13158 gint *minimum_width,
13159 gint *natural_width)
13161 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13165 * gtk_widget_get_halign:
13166 * @widget: a #GtkWidget
13168 * Gets the value of the #GtkWidget:halign property.
13170 * Returns: the horizontal alignment of @widget
13173 gtk_widget_get_halign (GtkWidget *widget)
13175 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13176 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13180 * gtk_widget_set_halign:
13181 * @widget: a #GtkWidget
13182 * @align: the horizontal alignment
13184 * Sets the horizontal alignment of @widget.
13185 * See the #GtkWidget:halign property.
13188 gtk_widget_set_halign (GtkWidget *widget,
13191 GtkWidgetAuxInfo *aux_info;
13193 g_return_if_fail (GTK_IS_WIDGET (widget));
13195 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13197 if (aux_info->halign == align)
13200 aux_info->halign = align;
13201 gtk_widget_queue_resize (widget);
13202 g_object_notify (G_OBJECT (widget), "halign");
13206 * gtk_widget_get_valign:
13207 * @widget: a #GtkWidget
13209 * Gets the value of the #GtkWidget:valign property.
13211 * Returns: the vertical alignment of @widget
13214 gtk_widget_get_valign (GtkWidget *widget)
13216 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13217 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13221 * gtk_widget_set_valign:
13222 * @widget: a #GtkWidget
13223 * @align: the vertical alignment
13225 * Sets the vertical alignment of @widget.
13226 * See the #GtkWidget:valign property.
13229 gtk_widget_set_valign (GtkWidget *widget,
13232 GtkWidgetAuxInfo *aux_info;
13234 g_return_if_fail (GTK_IS_WIDGET (widget));
13236 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13238 if (aux_info->valign == align)
13241 aux_info->valign = align;
13242 gtk_widget_queue_resize (widget);
13243 g_object_notify (G_OBJECT (widget), "valign");
13247 * gtk_widget_get_margin_left:
13248 * @widget: a #GtkWidget
13250 * Gets the value of the #GtkWidget:margin-left property.
13252 * Returns: The left margin of @widget
13257 gtk_widget_get_margin_left (GtkWidget *widget)
13259 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13261 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13265 * gtk_widget_set_margin_left:
13266 * @widget: a #GtkWidget
13267 * @margin: the left margin
13269 * Sets the left margin of @widget.
13270 * See the #GtkWidget:margin-left property.
13275 gtk_widget_set_margin_left (GtkWidget *widget,
13278 GtkWidgetAuxInfo *aux_info;
13280 g_return_if_fail (GTK_IS_WIDGET (widget));
13281 g_return_if_fail (margin <= G_MAXINT16);
13283 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13285 if (aux_info->margin.left == margin)
13288 aux_info->margin.left = margin;
13289 gtk_widget_queue_resize (widget);
13290 g_object_notify (G_OBJECT (widget), "margin-left");
13294 * gtk_widget_get_margin_right:
13295 * @widget: a #GtkWidget
13297 * Gets the value of the #GtkWidget:margin-right property.
13299 * Returns: The right margin of @widget
13304 gtk_widget_get_margin_right (GtkWidget *widget)
13306 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13308 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13312 * gtk_widget_set_margin_right:
13313 * @widget: a #GtkWidget
13314 * @margin: the right margin
13316 * Sets the right margin of @widget.
13317 * See the #GtkWidget:margin-right property.
13322 gtk_widget_set_margin_right (GtkWidget *widget,
13325 GtkWidgetAuxInfo *aux_info;
13327 g_return_if_fail (GTK_IS_WIDGET (widget));
13328 g_return_if_fail (margin <= G_MAXINT16);
13330 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13332 if (aux_info->margin.right == margin)
13335 aux_info->margin.right = margin;
13336 gtk_widget_queue_resize (widget);
13337 g_object_notify (G_OBJECT (widget), "margin-right");
13341 * gtk_widget_get_margin_top:
13342 * @widget: a #GtkWidget
13344 * Gets the value of the #GtkWidget:margin-top property.
13346 * Returns: The top margin of @widget
13351 gtk_widget_get_margin_top (GtkWidget *widget)
13353 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13355 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13359 * gtk_widget_set_margin_top:
13360 * @widget: a #GtkWidget
13361 * @margin: the top margin
13363 * Sets the top margin of @widget.
13364 * See the #GtkWidget:margin-top property.
13369 gtk_widget_set_margin_top (GtkWidget *widget,
13372 GtkWidgetAuxInfo *aux_info;
13374 g_return_if_fail (GTK_IS_WIDGET (widget));
13375 g_return_if_fail (margin <= G_MAXINT16);
13377 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13379 if (aux_info->margin.top == margin)
13382 aux_info->margin.top = margin;
13383 gtk_widget_queue_resize (widget);
13384 g_object_notify (G_OBJECT (widget), "margin-top");
13388 * gtk_widget_get_margin_bottom:
13389 * @widget: a #GtkWidget
13391 * Gets the value of the #GtkWidget:margin-bottom property.
13393 * Returns: The bottom margin of @widget
13398 gtk_widget_get_margin_bottom (GtkWidget *widget)
13400 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13402 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13406 * gtk_widget_set_margin_bottom:
13407 * @widget: a #GtkWidget
13408 * @margin: the bottom margin
13410 * Sets the bottom margin of @widget.
13411 * See the #GtkWidget:margin-bottom property.
13416 gtk_widget_set_margin_bottom (GtkWidget *widget,
13419 GtkWidgetAuxInfo *aux_info;
13421 g_return_if_fail (GTK_IS_WIDGET (widget));
13422 g_return_if_fail (margin <= G_MAXINT16);
13424 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13426 if (aux_info->margin.bottom == margin)
13429 aux_info->margin.bottom = margin;
13430 gtk_widget_queue_resize (widget);
13431 g_object_notify (G_OBJECT (widget), "margin-bottom");
13435 * gtk_widget_get_clipboard:
13436 * @widget: a #GtkWidget
13437 * @selection: a #GdkAtom which identifies the clipboard
13438 * to use. %GDK_SELECTION_CLIPBOARD gives the
13439 * default clipboard. Another common value
13440 * is %GDK_SELECTION_PRIMARY, which gives
13441 * the primary X selection.
13443 * Returns the clipboard object for the given selection to
13444 * be used with @widget. @widget must have a #GdkDisplay
13445 * associated with it, so must be attached to a toplevel
13448 * Return value: (transfer none): the appropriate clipboard object. If no
13449 * clipboard already exists, a new one will
13450 * be created. Once a clipboard object has
13451 * been created, it is persistent for all time.
13456 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13458 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13459 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13461 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13466 * gtk_widget_list_mnemonic_labels:
13467 * @widget: a #GtkWidget
13469 * Returns a newly allocated list of the widgets, normally labels, for
13470 * which this widget is the target of a mnemonic (see for example,
13471 * gtk_label_set_mnemonic_widget()).
13473 * The widgets in the list are not individually referenced. If you
13474 * want to iterate through the list and perform actions involving
13475 * callbacks that might destroy the widgets, you
13476 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13477 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13478 * widgets afterwards.
13480 * Return value: (element-type GtkWidget) (transfer container): the list of
13481 * mnemonic labels; free this list
13482 * with g_list_free() when you are done with it.
13487 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13489 GList *list = NULL;
13492 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13494 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13495 list = g_list_prepend (list, l->data);
13501 * gtk_widget_add_mnemonic_label:
13502 * @widget: a #GtkWidget
13503 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13505 * Adds a widget to the list of mnemonic labels for
13506 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13507 * list of mnemonic labels for the widget is cleared when the
13508 * widget is destroyed, so the caller must make sure to update
13509 * its internal state at this point as well, by using a connection
13510 * to the #GtkWidget::destroy signal or a weak notifier.
13515 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13518 GSList *old_list, *new_list;
13520 g_return_if_fail (GTK_IS_WIDGET (widget));
13521 g_return_if_fail (GTK_IS_WIDGET (label));
13523 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13524 new_list = g_slist_prepend (old_list, label);
13526 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13527 new_list, (GDestroyNotify) g_slist_free);
13531 * gtk_widget_remove_mnemonic_label:
13532 * @widget: a #GtkWidget
13533 * @label: a #GtkWidget that was previously set as a mnemnic label for
13534 * @widget with gtk_widget_add_mnemonic_label().
13536 * Removes a widget from the list of mnemonic labels for
13537 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13538 * must have previously been added to the list with
13539 * gtk_widget_add_mnemonic_label().
13544 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13547 GSList *old_list, *new_list;
13549 g_return_if_fail (GTK_IS_WIDGET (widget));
13550 g_return_if_fail (GTK_IS_WIDGET (label));
13552 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13553 new_list = g_slist_remove (old_list, label);
13556 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13557 new_list, (GDestroyNotify) g_slist_free);
13561 * gtk_widget_get_no_show_all:
13562 * @widget: a #GtkWidget
13564 * Returns the current value of the #GtkWidget:no-show-all property,
13565 * which determines whether calls to gtk_widget_show_all()
13566 * will affect this widget.
13568 * Return value: the current value of the "no-show-all" property.
13573 gtk_widget_get_no_show_all (GtkWidget *widget)
13575 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13577 return widget->priv->no_show_all;
13581 * gtk_widget_set_no_show_all:
13582 * @widget: a #GtkWidget
13583 * @no_show_all: the new value for the "no-show-all" property
13585 * Sets the #GtkWidget:no-show-all property, which determines whether
13586 * calls to gtk_widget_show_all() will affect this widget.
13588 * This is mostly for use in constructing widget hierarchies with externally
13589 * controlled visibility, see #GtkUIManager.
13594 gtk_widget_set_no_show_all (GtkWidget *widget,
13595 gboolean no_show_all)
13597 g_return_if_fail (GTK_IS_WIDGET (widget));
13599 no_show_all = (no_show_all != FALSE);
13601 if (widget->priv->no_show_all != no_show_all)
13603 widget->priv->no_show_all = no_show_all;
13605 g_object_notify (G_OBJECT (widget), "no-show-all");
13611 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13612 gboolean has_tooltip,
13615 GtkWidgetPrivate *priv = widget->priv;
13616 gboolean priv_has_tooltip;
13618 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13619 quark_has_tooltip));
13621 if (priv_has_tooltip != has_tooltip || force)
13623 priv_has_tooltip = has_tooltip;
13625 if (priv_has_tooltip)
13627 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13628 gdk_window_set_events (priv->window,
13629 gdk_window_get_events (priv->window) |
13630 GDK_LEAVE_NOTIFY_MASK |
13631 GDK_POINTER_MOTION_MASK |
13632 GDK_POINTER_MOTION_HINT_MASK);
13634 if (gtk_widget_get_has_window (widget))
13635 gtk_widget_add_events (widget,
13636 GDK_LEAVE_NOTIFY_MASK |
13637 GDK_POINTER_MOTION_MASK |
13638 GDK_POINTER_MOTION_HINT_MASK);
13641 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13642 GUINT_TO_POINTER (priv_has_tooltip));
13647 * gtk_widget_set_tooltip_window:
13648 * @widget: a #GtkWidget
13649 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13651 * Replaces the default, usually yellow, window used for displaying
13652 * tooltips with @custom_window. GTK+ will take care of showing and
13653 * hiding @custom_window at the right moment, to behave likewise as
13654 * the default tooltip window. If @custom_window is %NULL, the default
13655 * tooltip window will be used.
13657 * If the custom window should have the default theming it needs to
13658 * have the name "gtk-tooltip", see gtk_widget_set_name().
13663 gtk_widget_set_tooltip_window (GtkWidget *widget,
13664 GtkWindow *custom_window)
13666 gboolean has_tooltip;
13667 gchar *tooltip_markup;
13669 g_return_if_fail (GTK_IS_WIDGET (widget));
13670 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13672 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13675 g_object_ref (custom_window);
13677 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13678 custom_window, g_object_unref);
13680 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13681 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13683 if (has_tooltip && gtk_widget_get_visible (widget))
13684 gtk_widget_queue_tooltip_query (widget);
13688 * gtk_widget_get_tooltip_window:
13689 * @widget: a #GtkWidget
13691 * Returns the #GtkWindow of the current tooltip. This can be the
13692 * GtkWindow created by default, or the custom tooltip window set
13693 * using gtk_widget_set_tooltip_window().
13695 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13700 gtk_widget_get_tooltip_window (GtkWidget *widget)
13702 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13704 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13708 * gtk_widget_trigger_tooltip_query:
13709 * @widget: a #GtkWidget
13711 * Triggers a tooltip query on the display where the toplevel of @widget
13712 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13718 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13720 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13723 static guint tooltip_query_id;
13724 static GSList *tooltip_query_displays;
13727 tooltip_query_idle (gpointer data)
13729 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13730 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13731 g_slist_free (tooltip_query_displays);
13733 tooltip_query_displays = NULL;
13734 tooltip_query_id = 0;
13740 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13742 GdkDisplay *display;
13744 display = gtk_widget_get_display (widget);
13746 if (!g_slist_find (tooltip_query_displays, display))
13747 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13749 if (tooltip_query_id == 0)
13750 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13754 * gtk_widget_set_tooltip_text:
13755 * @widget: a #GtkWidget
13756 * @text: (allow-none): the contents of the tooltip for @widget
13758 * Sets @text as the contents of the tooltip. This function will take
13759 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13760 * handler for the #GtkWidget::query-tooltip signal.
13762 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13767 gtk_widget_set_tooltip_text (GtkWidget *widget,
13770 g_return_if_fail (GTK_IS_WIDGET (widget));
13772 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13776 * gtk_widget_get_tooltip_text:
13777 * @widget: a #GtkWidget
13779 * Gets the contents of the tooltip for @widget.
13781 * Return value: the tooltip text, or %NULL. You should free the
13782 * returned string with g_free() when done.
13787 gtk_widget_get_tooltip_text (GtkWidget *widget)
13789 gchar *text = NULL;
13791 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13793 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13799 * gtk_widget_set_tooltip_markup:
13800 * @widget: a #GtkWidget
13801 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13803 * Sets @markup as the contents of the tooltip, which is marked up with
13804 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13806 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13807 * and of the default handler for the #GtkWidget::query-tooltip signal.
13809 * See also the #GtkWidget:tooltip-markup property and
13810 * gtk_tooltip_set_markup().
13815 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13816 const gchar *markup)
13818 g_return_if_fail (GTK_IS_WIDGET (widget));
13820 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13824 * gtk_widget_get_tooltip_markup:
13825 * @widget: a #GtkWidget
13827 * Gets the contents of the tooltip for @widget.
13829 * Return value: the tooltip text, or %NULL. You should free the
13830 * returned string with g_free() when done.
13835 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13837 gchar *text = NULL;
13839 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13841 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13847 * gtk_widget_set_has_tooltip:
13848 * @widget: a #GtkWidget
13849 * @has_tooltip: whether or not @widget has a tooltip.
13851 * Sets the has-tooltip property on @widget to @has_tooltip. See
13852 * #GtkWidget:has-tooltip for more information.
13857 gtk_widget_set_has_tooltip (GtkWidget *widget,
13858 gboolean has_tooltip)
13860 g_return_if_fail (GTK_IS_WIDGET (widget));
13862 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13866 * gtk_widget_get_has_tooltip:
13867 * @widget: a #GtkWidget
13869 * Returns the current value of the has-tooltip property. See
13870 * #GtkWidget:has-tooltip for more information.
13872 * Return value: current value of has-tooltip on @widget.
13877 gtk_widget_get_has_tooltip (GtkWidget *widget)
13879 gboolean has_tooltip = FALSE;
13881 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13883 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13885 return has_tooltip;
13889 * gtk_widget_get_allocation:
13890 * @widget: a #GtkWidget
13891 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13893 * Retrieves the widget's allocation.
13895 * Note, when implementing a #GtkContainer: a widget's allocation will
13896 * be its "adjusted" allocation, that is, the widget's parent
13897 * container typically calls gtk_widget_size_allocate() with an
13898 * allocation, and that allocation is then adjusted (to handle margin
13899 * and alignment for example) before assignment to the widget.
13900 * gtk_widget_get_allocation() returns the adjusted allocation that
13901 * was actually assigned to the widget. The adjusted allocation is
13902 * guaranteed to be completely contained within the
13903 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13904 * is guaranteed that its children stay inside the assigned bounds,
13905 * but not that they have exactly the bounds the container assigned.
13906 * There is no way to get the original allocation assigned by
13907 * gtk_widget_size_allocate(), since it isn't stored; if a container
13908 * implementation needs that information it will have to track it itself.
13913 gtk_widget_get_allocation (GtkWidget *widget,
13914 GtkAllocation *allocation)
13916 GtkWidgetPrivate *priv;
13918 g_return_if_fail (GTK_IS_WIDGET (widget));
13919 g_return_if_fail (allocation != NULL);
13921 priv = widget->priv;
13923 *allocation = priv->allocation;
13927 * gtk_widget_set_allocation:
13928 * @widget: a #GtkWidget
13929 * @allocation: a pointer to a #GtkAllocation to copy from
13931 * Sets the widget's allocation. This should not be used
13932 * directly, but from within a widget's size_allocate method.
13934 * The allocation set should be the "adjusted" or actual
13935 * allocation. If you're implementing a #GtkContainer, you want to use
13936 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13937 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13938 * allocation inside gtk_widget_size_allocate() to create an adjusted
13944 gtk_widget_set_allocation (GtkWidget *widget,
13945 const GtkAllocation *allocation)
13947 GtkWidgetPrivate *priv;
13949 g_return_if_fail (GTK_IS_WIDGET (widget));
13950 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13951 g_return_if_fail (allocation != NULL);
13953 priv = widget->priv;
13955 priv->allocation = *allocation;
13959 * gtk_widget_get_allocated_width:
13960 * @widget: the widget to query
13962 * Returns the width that has currently been allocated to @widget.
13963 * This function is intended to be used when implementing handlers
13964 * for the #GtkWidget::draw function.
13966 * Returns: the width of the @widget
13969 gtk_widget_get_allocated_width (GtkWidget *widget)
13971 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13973 return widget->priv->allocation.width;
13977 * gtk_widget_get_allocated_height:
13978 * @widget: the widget to query
13980 * Returns the height that has currently been allocated to @widget.
13981 * This function is intended to be used when implementing handlers
13982 * for the #GtkWidget::draw function.
13984 * Returns: the height of the @widget
13987 gtk_widget_get_allocated_height (GtkWidget *widget)
13989 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13991 return widget->priv->allocation.height;
13995 * gtk_widget_get_requisition:
13996 * @widget: a #GtkWidget
13997 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13999 * Retrieves the widget's requisition.
14001 * This function should only be used by widget implementations in
14002 * order to figure whether the widget's requisition has actually
14003 * changed after some internal state change (so that they can call
14004 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
14006 * Normally, gtk_widget_size_request() should be used.
14010 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
14011 * removed, If you need to cache sizes across requests and allocations,
14012 * add an explicit cache to the widget in question instead.
14015 gtk_widget_get_requisition (GtkWidget *widget,
14016 GtkRequisition *requisition)
14018 g_return_if_fail (GTK_IS_WIDGET (widget));
14019 g_return_if_fail (requisition != NULL);
14021 gtk_widget_get_preferred_size (widget, requisition, NULL);
14025 * gtk_widget_set_window:
14026 * @widget: a #GtkWidget
14027 * @window: (transfer full): a #GdkWindow
14029 * Sets a widget's window. This function should only be used in a
14030 * widget's #GtkWidget::realize implementation. The %window passed is
14031 * usually either new window created with gdk_window_new(), or the
14032 * window of its parent widget as returned by
14033 * gtk_widget_get_parent_window().
14035 * Widgets must indicate whether they will create their own #GdkWindow
14036 * by calling gtk_widget_set_has_window(). This is usually done in the
14037 * widget's init() function.
14039 * <note><para>This function does not add any reference to @window.</para></note>
14044 gtk_widget_set_window (GtkWidget *widget,
14047 GtkWidgetPrivate *priv;
14049 g_return_if_fail (GTK_IS_WIDGET (widget));
14050 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
14052 priv = widget->priv;
14054 if (priv->window != window)
14056 priv->window = window;
14058 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
14059 gdk_window_set_opacity (window,
14060 priv->norender ? 0 : priv->alpha / 255.0);
14062 g_object_notify (G_OBJECT (widget), "window");
14067 * gtk_widget_register_window:
14068 * @widget: a #GtkWidget
14069 * @window: a #GdkWindow
14071 * Registers a #GdkWindow with the widget and sets it up so that
14072 * the widget recieves events for it. Call gtk_widget_unregister_window()
14073 * when destroying the window.
14075 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
14076 * this up. This is now deprecated and you should use gtk_widget_register_window()
14077 * instead. Old code will keep working as is, although some new features like
14078 * transparency might not work perfectly.
14083 gtk_widget_register_window (GtkWidget *widget,
14086 GtkWidgetPrivate *priv;
14087 gpointer user_data;
14089 g_return_if_fail (GTK_IS_WIDGET (widget));
14090 g_return_if_fail (GDK_IS_WINDOW (window));
14092 gdk_window_get_user_data (window, &user_data);
14093 g_assert (user_data == NULL);
14095 priv = widget->priv;
14097 gdk_window_set_user_data (window, widget);
14098 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
14100 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
14101 gdk_window_set_opacity (window,
14102 priv->norender_children ? 0.0 : 1.0);
14106 * gtk_widget_unregister_window:
14107 * @widget: a #GtkWidget
14108 * @window: a #GdkWindow
14110 * Unregisters a #GdkWindow from the widget that was previously set up with
14111 * gtk_widget_register_window(). You need to call this when the window is
14112 * no longer used by the widget, such as when you destroy it.
14117 gtk_widget_unregister_window (GtkWidget *widget,
14120 GtkWidgetPrivate *priv;
14121 gpointer user_data;
14123 g_return_if_fail (GTK_IS_WIDGET (widget));
14124 g_return_if_fail (GDK_IS_WINDOW (window));
14126 priv = widget->priv;
14128 gdk_window_get_user_data (window, &user_data);
14129 g_assert (user_data == widget);
14130 gdk_window_set_user_data (window, NULL);
14131 priv->registered_windows = g_list_remove (priv->registered_windows, window);
14135 * gtk_widget_get_window:
14136 * @widget: a #GtkWidget
14138 * Returns the widget's window if it is realized, %NULL otherwise
14140 * Return value: (transfer none): @widget's window.
14145 gtk_widget_get_window (GtkWidget *widget)
14147 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14149 return widget->priv->window;
14153 * gtk_widget_get_support_multidevice:
14154 * @widget: a #GtkWidget
14156 * Returns %TRUE if @widget is multiple pointer aware. See
14157 * gtk_widget_set_support_multidevice() for more information.
14159 * Returns: %TRUE if @widget is multidevice aware.
14162 gtk_widget_get_support_multidevice (GtkWidget *widget)
14164 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14166 return widget->priv->multidevice;
14170 * gtk_widget_set_support_multidevice:
14171 * @widget: a #GtkWidget
14172 * @support_multidevice: %TRUE to support input from multiple devices.
14174 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
14175 * @widget will start receiving multiple, per device enter/leave events. Note
14176 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
14177 * gdk_window_set_support_multidevice() will have to be called manually on them.
14182 gtk_widget_set_support_multidevice (GtkWidget *widget,
14183 gboolean support_multidevice)
14185 GtkWidgetPrivate *priv;
14187 g_return_if_fail (GTK_IS_WIDGET (widget));
14189 priv = widget->priv;
14190 priv->multidevice = (support_multidevice == TRUE);
14192 if (gtk_widget_get_realized (widget))
14193 gdk_window_set_support_multidevice (priv->window, support_multidevice);
14196 /* There are multiple alpha related sources. First of all the user can specify alpha
14197 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
14198 * are multiplied together to form the total alpha. Secondly, the user can specify
14199 * an opacity group for a widget, which means we must essentially handle it as having alpha.
14201 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
14202 * group we directly set the opacity of widget->window. This will cause gdk to properly
14203 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
14205 * However, if the widget is not windowed, or the user specified an opacity group for the
14206 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
14207 * implementation of this would break for windowed widgets or descendant widgets with
14208 * windows, as these would not be handled by the ::draw signal. To handle this we set
14209 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
14210 * to make the draw signal propagate to *all* child widgets/windows.
14212 * Note: We don't make all child windows fully transparent, we stop at the first one
14213 * in each branch when propagating down the hierarchy.
14217 /* This is called when priv->alpha or priv->opacity_group group changes, and should
14218 * update priv->norender and GdkWindow opacity for this widget and any children that
14219 * needs changing. It is also called whenver the parent changes, the parents
14220 * norender_children state changes, or the has_window state of the widget changes.
14223 gtk_widget_propagate_alpha (GtkWidget *widget)
14225 GtkWidgetPrivate *priv = widget->priv;
14227 gboolean norender, norender_children;
14230 parent = priv->parent;
14233 /* If this widget has an opacity group, never render it */
14234 priv->opacity_group ||
14235 /* If the parent has norender_children, propagate that here */
14236 (parent != NULL && parent->priv->norender_children);
14238 /* Windowed widget children should norender if: */
14239 norender_children =
14240 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
14241 !gtk_widget_get_has_window (widget) &&
14242 ( /* norender is set, or */
14244 /* widget has an alpha */
14248 if (gtk_widget_get_has_window (widget))
14250 if (priv->window != NULL && !gdk_window_has_native (priv->window))
14251 gdk_window_set_opacity (priv->window,
14252 norender ? 0 : priv->alpha / 255.0);
14254 else /* !has_window */
14256 for (l = priv->registered_windows; l != NULL; l = l->next)
14258 GdkWindow *w = l->data;
14259 if (!gdk_window_has_native (w))
14260 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
14264 priv->norender = norender;
14265 if (priv->norender_children != norender_children)
14267 priv->norender_children = norender_children;
14269 if (GTK_IS_CONTAINER (widget))
14270 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
14273 if (gtk_widget_get_realized (widget))
14274 gtk_widget_queue_draw (widget);
14278 gtk_widget_update_alpha (GtkWidget *widget)
14280 GtkWidgetPrivate *priv;
14284 priv = widget->priv;
14286 alpha = priv->user_alpha;
14291 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
14292 GTK_CSS_PROPERTY_OPACITY),
14294 opacity = CLAMP (opacity, 0.0, 1.0);
14295 alpha = round (priv->user_alpha * opacity);
14298 if (alpha == priv->alpha)
14301 priv->alpha = alpha;
14303 gtk_widget_propagate_alpha (widget);
14308 gtk_widget_set_has_opacity_group (GtkWidget *widget,
14309 gboolean has_opacity_group)
14311 GtkWidgetPrivate *priv;
14313 g_return_if_fail (GTK_IS_WIDGET (widget));
14315 priv = widget->priv;
14317 has_opacity_group = !!has_opacity_group;
14319 if (priv->opacity_group == has_opacity_group)
14322 priv->opacity_group = has_opacity_group;
14324 gtk_widget_propagate_alpha (widget);
14328 * gtk_widget_set_opacity:
14329 * @widget: a #GtkWidget
14330 * @opacity: desired opacity, between 0 and 1
14332 * Request the @widget to be rendered partially transparent,
14333 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14334 * are clamped to the [0,1] range.).
14335 * This works on both toplevel widget, and child widgets, although there
14336 * are some limitations:
14338 * For toplevel widgets this depends on the capabilities of the windowing
14339 * system. On X11 this has any effect only on X screens with a compositing manager
14340 * running. See gtk_widget_is_composited(). On Windows it should work
14341 * always, although setting a window's opacity after the window has been
14342 * shown causes it to flicker once on Windows.
14344 * For child widgets it doesn't work if any affected widget has a native window, or
14345 * disables double buffering.
14350 gtk_widget_set_opacity (GtkWidget *widget,
14353 GtkWidgetPrivate *priv;
14356 g_return_if_fail (GTK_IS_WIDGET (widget));
14358 priv = widget->priv;
14360 opacity = CLAMP (opacity, 0.0, 1.0);
14362 alpha = round (opacity * 255);
14364 /* As a kind of hack for internal use we treat an alpha very
14365 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14366 we want the opacity group behaviour wrt draw handling, but
14367 not actually an alpha value. See bug #687842 for discussions. */
14368 gtk_widget_set_has_opacity_group (widget,
14369 alpha == 255 && opacity != 1.0);
14371 if (alpha == priv->user_alpha)
14374 priv->user_alpha = alpha;
14376 gtk_widget_update_alpha (widget);
14381 * gtk_widget_get_opacity:
14382 * @widget: a #GtkWidget
14384 * Fetches the requested opacity for this widget. See
14385 * gtk_widget_set_opacity().
14387 * Return value: the requested opacity for this widget.
14392 gtk_widget_get_opacity (GtkWidget *widget)
14394 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14396 return widget->priv->alpha / 255.0;
14400 _gtk_widget_set_has_focus (GtkWidget *widget,
14401 gboolean has_focus)
14403 widget->priv->has_focus = has_focus;
14406 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14408 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14412 * gtk_widget_send_focus_change:
14413 * @widget: a #GtkWidget
14414 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14416 * Sends the focus change @event to @widget
14418 * This function is not meant to be used by applications. The only time it
14419 * should be used is when it is necessary for a #GtkWidget to assign focus
14420 * to a widget that is semantically owned by the first widget even though
14421 * it's not a direct child - for instance, a search entry in a floating
14422 * window similar to the quick search in #GtkTreeView.
14424 * An example of its usage is:
14427 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14429 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14430 * fevent->focus_change.in = TRUE;
14431 * fevent->focus_change.window = gtk_widget_get_window (widget);
14432 * if (fevent->focus_change.window != NULL)
14433 * g_object_ref (fevent->focus_change.window);
14435 * gtk_widget_send_focus_change (widget, fevent);
14437 * gdk_event_free (event);
14440 * Return value: the return value from the event signal emission: %TRUE
14441 * if the event was handled, and %FALSE otherwise
14446 gtk_widget_send_focus_change (GtkWidget *widget,
14451 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14452 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14454 g_object_ref (widget);
14456 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14458 res = gtk_widget_event (widget, event);
14460 g_object_notify (G_OBJECT (widget), "has-focus");
14462 g_object_unref (widget);
14468 * gtk_widget_in_destruction:
14469 * @widget: a #GtkWidget
14471 * Returns whether the widget is currently being destroyed.
14472 * This information can sometimes be used to avoid doing
14473 * unnecessary work.
14475 * Returns: %TRUE if @widget is being destroyed
14478 gtk_widget_in_destruction (GtkWidget *widget)
14480 return widget->priv->in_destruction;
14484 _gtk_widget_get_in_reparent (GtkWidget *widget)
14486 return widget->priv->in_reparent;
14490 _gtk_widget_set_in_reparent (GtkWidget *widget,
14491 gboolean in_reparent)
14493 widget->priv->in_reparent = in_reparent;
14497 _gtk_widget_get_anchored (GtkWidget *widget)
14499 return widget->priv->anchored;
14503 _gtk_widget_set_anchored (GtkWidget *widget,
14506 widget->priv->anchored = anchored;
14510 _gtk_widget_get_shadowed (GtkWidget *widget)
14512 return widget->priv->shadowed;
14516 _gtk_widget_set_shadowed (GtkWidget *widget,
14519 widget->priv->shadowed = shadowed;
14523 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14525 return widget->priv->alloc_needed;
14529 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14530 gboolean alloc_needed)
14532 widget->priv->alloc_needed = alloc_needed;
14536 _gtk_widget_add_sizegroup (GtkWidget *widget,
14541 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14542 groups = g_slist_prepend (groups, group);
14543 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14545 widget->priv->have_size_groups = TRUE;
14549 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14554 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14555 groups = g_slist_remove (groups, group);
14556 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14558 widget->priv->have_size_groups = groups != NULL;
14562 _gtk_widget_get_sizegroups (GtkWidget *widget)
14564 if (widget->priv->have_size_groups)
14565 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14571 _gtk_widget_add_attached_window (GtkWidget *widget,
14574 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14578 _gtk_widget_remove_attached_window (GtkWidget *widget,
14581 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14585 * gtk_widget_path_append_for_widget:
14586 * @path: a widget path
14587 * @widget: the widget to append to the widget path
14589 * Appends the data from @widget to the widget hierarchy represented
14590 * by @path. This function is a shortcut for adding information from
14591 * @widget to the given @path. This includes setting the name or
14592 * adding the style classes from @widget.
14594 * Returns: the position where the data was inserted
14599 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14604 g_return_val_if_fail (path != NULL, 0);
14605 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14607 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14609 if (widget->priv->name)
14610 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14612 if (widget->priv->context)
14614 GList *classes, *l;
14616 /* Also add any persistent classes in
14617 * the style context the widget path
14619 classes = gtk_style_context_list_classes (widget->priv->context);
14621 for (l = classes; l; l = l->next)
14622 gtk_widget_path_iter_add_class (path, pos, l->data);
14624 g_list_free (classes);
14631 _gtk_widget_create_path (GtkWidget *widget)
14635 parent = widget->priv->parent;
14638 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14641 /* Widget is either toplevel or unparented, treat both
14642 * as toplevels style wise, since there are situations
14643 * where style properties might be retrieved on that
14646 GtkWidget *attach_widget = NULL;
14647 GtkWidgetPath *result;
14649 if (GTK_IS_WINDOW (widget))
14650 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14652 if (attach_widget != NULL)
14653 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14655 result = gtk_widget_path_new ();
14657 gtk_widget_path_append_for_widget (result, widget);
14664 * gtk_widget_get_path:
14665 * @widget: a #GtkWidget
14667 * Returns the #GtkWidgetPath representing @widget, if the widget
14668 * is not connected to a toplevel widget, a partial path will be
14671 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14674 gtk_widget_get_path (GtkWidget *widget)
14676 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14678 if (!widget->priv->path)
14679 widget->priv->path = _gtk_widget_create_path (widget);
14681 return widget->priv->path;
14685 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14687 if (widget->priv->path)
14689 gtk_widget_path_free (widget->priv->path);
14690 widget->priv->path = NULL;
14693 if (gtk_widget_get_realized (widget))
14694 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14697 /* Compress all style updates so it
14698 * is only emitted once pre-realize.
14700 widget->priv->style_update_pending = TRUE;
14705 * gtk_widget_get_style_context:
14706 * @widget: a #GtkWidget
14708 * Returns the style context associated to @widget.
14710 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14711 * must not be freed.
14714 gtk_widget_get_style_context (GtkWidget *widget)
14716 GtkWidgetPrivate *priv;
14718 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14720 priv = widget->priv;
14722 if (G_UNLIKELY (priv->context == NULL))
14725 GdkFrameClock *frame_clock;
14727 priv->context = gtk_style_context_new ();
14729 gtk_style_context_set_state (priv->context, priv->state_flags);
14731 screen = gtk_widget_get_screen (widget);
14733 gtk_style_context_set_screen (priv->context, screen);
14735 frame_clock = gtk_widget_get_frame_clock (widget);
14737 gtk_style_context_set_frame_clock (priv->context, frame_clock);
14740 gtk_style_context_set_parent (priv->context,
14741 gtk_widget_get_style_context (priv->parent));
14743 _gtk_style_context_set_widget (priv->context, widget);
14746 return widget->priv->context;
14750 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14751 GtkCssChange change)
14753 GtkWidgetPrivate *priv;
14755 priv = widget->priv;
14757 if (priv->context == NULL)
14760 _gtk_style_context_queue_invalidate (priv->context, change);
14764 * gtk_widget_get_modifier_mask:
14765 * @widget: a #GtkWidget
14766 * @intent: the use case for the modifier mask
14768 * Returns the modifier mask the @widget's windowing system backend
14769 * uses for a particular purpose.
14771 * See gdk_keymap_get_modifier_mask().
14773 * Returns: the modifier mask used for @intent.
14778 gtk_widget_get_modifier_mask (GtkWidget *widget,
14779 GdkModifierIntent intent)
14781 GdkDisplay *display;
14783 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14785 display = gtk_widget_get_display (widget);
14787 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14792 _gtk_widget_get_style (GtkWidget *widget)
14794 return widget->priv->style;
14798 _gtk_widget_set_style (GtkWidget *widget,
14801 widget->priv->style = style;
14805 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14808 GActionMuxer *parent_muxer;
14810 if (widget->priv->muxer == NULL)
14813 if (GTK_IS_MENU (widget))
14814 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14816 parent = gtk_widget_get_parent (widget);
14818 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14820 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14824 _gtk_widget_get_action_muxer (GtkWidget *widget)
14826 if (widget->priv->muxer == NULL)
14828 widget->priv->muxer = g_action_muxer_new ();
14829 _gtk_widget_update_parent_muxer (widget);
14832 return widget->priv->muxer;
14836 * gtk_widget_insert_action_group:
14837 * @widget: a #GtkWidget
14838 * @name: the prefix for actions in @group
14839 * @group: a #GActionGroup
14841 * Inserts @group into @widget. Children of @widget that implement
14842 * #GtkActionable can then be associated with actions in @group by
14843 * setting their 'action-name' to
14844 * @prefix.<replaceable>action-name</replaceable>.
14849 gtk_widget_insert_action_group (GtkWidget *widget,
14851 GActionGroup *group)
14853 GActionMuxer *muxer;
14855 g_return_if_fail (GTK_IS_WIDGET (widget));
14856 g_return_if_fail (name != NULL);
14858 muxer = _gtk_widget_get_action_muxer (widget);
14861 g_action_muxer_insert (muxer, name, group);
14863 g_action_muxer_remove (muxer, name);