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 *frame_clock_targets;
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,
716 static gboolean event_window_is_still_viewable (GdkEvent *event);
717 static void gtk_cairo_set_event (cairo_t *cr,
718 GdkEventExpose *event);
719 static void gtk_widget_propagate_alpha (GtkWidget *widget);
721 /* --- variables --- */
722 static gpointer gtk_widget_parent_class = NULL;
723 static guint widget_signals[LAST_SIGNAL] = { 0 };
724 static guint composite_child_stack = 0;
725 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
726 static GParamSpecPool *style_property_spec_pool = NULL;
728 static GQuark quark_property_parser = 0;
729 static GQuark quark_aux_info = 0;
730 static GQuark quark_accel_path = 0;
731 static GQuark quark_accel_closures = 0;
732 static GQuark quark_event_mask = 0;
733 static GQuark quark_device_event_mask = 0;
734 static GQuark quark_parent_window = 0;
735 static GQuark quark_pointer_window = 0;
736 static GQuark quark_shape_info = 0;
737 static GQuark quark_input_shape_info = 0;
738 static GQuark quark_pango_context = 0;
739 static GQuark quark_accessible_object = 0;
740 static GQuark quark_mnemonic_labels = 0;
741 static GQuark quark_tooltip_markup = 0;
742 static GQuark quark_has_tooltip = 0;
743 static GQuark quark_tooltip_window = 0;
744 static GQuark quark_visual = 0;
745 static GQuark quark_modifier_style = 0;
746 static GQuark quark_enabled_devices = 0;
747 static GQuark quark_size_groups = 0;
748 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
749 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
751 /* --- functions --- */
753 gtk_widget_get_type (void)
755 static GType widget_type = 0;
757 if (G_UNLIKELY (widget_type == 0))
759 const GTypeInfo widget_info =
761 sizeof (GtkWidgetClass),
762 gtk_widget_base_class_init,
763 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
764 (GClassInitFunc) gtk_widget_class_init,
765 NULL, /* class_finalize */
766 NULL, /* class_init */
769 (GInstanceInitFunc) gtk_widget_init,
770 NULL, /* value_table */
773 const GInterfaceInfo accessibility_info =
775 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
776 (GInterfaceFinalizeFunc) NULL,
777 NULL /* interface data */
780 const GInterfaceInfo buildable_info =
782 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
783 (GInterfaceFinalizeFunc) NULL,
784 NULL /* interface data */
787 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
788 &widget_info, G_TYPE_FLAG_ABSTRACT);
790 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
792 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
793 &accessibility_info) ;
794 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
802 gtk_widget_base_class_init (gpointer g_class)
804 GtkWidgetClass *klass = g_class;
806 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
810 child_property_notify_dispatcher (GObject *object,
814 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
817 /* We guard against the draw signal callbacks modifying the state of the
818 * cairo context by surounding it with save/restore.
819 * Maybe we should also cairo_new_path() just to be sure?
822 gtk_widget_draw_marshaller (GClosure *closure,
823 GValue *return_value,
824 guint n_param_values,
825 const GValue *param_values,
826 gpointer invocation_hint,
827 gpointer marshal_data)
829 GtkWidget *widget = g_value_get_object (¶m_values[0]);
830 GdkEventExpose *tmp_event;
832 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
835 tmp_event = _gtk_cairo_get_event (cr);
838 widget->priv->opacity_group ||
839 (widget->priv->alpha != 255 &&
840 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
844 cairo_push_group (cr);
845 gtk_cairo_set_event (cr, NULL);
848 _gtk_marshal_BOOLEAN__BOXED (closure,
858 cairo_pop_group_to_source (cr);
859 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
860 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
863 gtk_cairo_set_event (cr, tmp_event);
868 gtk_widget_draw_marshallerv (GClosure *closure,
869 GValue *return_value,
872 gpointer marshal_data,
876 GtkWidget *widget = GTK_WIDGET (instance);
877 GdkEventExpose *tmp_event;
882 G_VA_COPY (args_copy, args);
883 cr = va_arg (args_copy, gpointer);
886 tmp_event = _gtk_cairo_get_event (cr);
889 widget->priv->opacity_group ||
890 (widget->priv->alpha != 255 &&
891 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
895 cairo_push_group (cr);
896 gtk_cairo_set_event (cr, NULL);
899 _gtk_marshal_BOOLEAN__BOXEDv (closure,
910 cairo_pop_group_to_source (cr);
911 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
912 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
915 gtk_cairo_set_event (cr, tmp_event);
922 gtk_widget_class_init (GtkWidgetClass *klass)
924 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
925 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
926 GtkBindingSet *binding_set;
928 gtk_widget_parent_class = g_type_class_peek_parent (klass);
930 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
931 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
932 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
933 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
934 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
935 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
936 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
937 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
938 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
939 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
940 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
941 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
942 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
943 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
944 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
945 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
946 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
947 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
948 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
949 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
951 style_property_spec_pool = g_param_spec_pool_new (FALSE);
952 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
953 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
954 cpn_context.dispatcher = child_property_notify_dispatcher;
955 _gtk_widget_child_property_notify_context = &cpn_context;
957 gobject_class->constructed = gtk_widget_constructed;
958 gobject_class->dispose = gtk_widget_dispose;
959 gobject_class->finalize = gtk_widget_finalize;
960 gobject_class->set_property = gtk_widget_set_property;
961 gobject_class->get_property = gtk_widget_get_property;
963 klass->destroy = gtk_widget_real_destroy;
965 klass->activate_signal = 0;
966 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
967 klass->show = gtk_widget_real_show;
968 klass->show_all = gtk_widget_show;
969 klass->hide = gtk_widget_real_hide;
970 klass->map = gtk_widget_real_map;
971 klass->unmap = gtk_widget_real_unmap;
972 klass->realize = gtk_widget_real_realize;
973 klass->unrealize = gtk_widget_real_unrealize;
974 klass->size_allocate = gtk_widget_real_size_allocate;
975 klass->get_request_mode = gtk_widget_real_get_request_mode;
976 klass->get_preferred_width = gtk_widget_real_get_width;
977 klass->get_preferred_height = gtk_widget_real_get_height;
978 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
979 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
980 klass->state_changed = NULL;
981 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
982 klass->parent_set = NULL;
983 klass->hierarchy_changed = NULL;
984 klass->style_set = gtk_widget_real_style_set;
985 klass->direction_changed = gtk_widget_real_direction_changed;
986 klass->grab_notify = NULL;
987 klass->child_notify = NULL;
989 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
990 klass->grab_focus = gtk_widget_real_grab_focus;
991 klass->focus = gtk_widget_real_focus;
992 klass->move_focus = gtk_widget_real_move_focus;
993 klass->keynav_failed = gtk_widget_real_keynav_failed;
995 klass->button_press_event = NULL;
996 klass->button_release_event = NULL;
997 klass->motion_notify_event = NULL;
998 klass->touch_event = gtk_widget_real_touch_event;
999 klass->delete_event = NULL;
1000 klass->destroy_event = NULL;
1001 klass->key_press_event = gtk_widget_real_key_press_event;
1002 klass->key_release_event = gtk_widget_real_key_release_event;
1003 klass->enter_notify_event = NULL;
1004 klass->leave_notify_event = NULL;
1005 klass->configure_event = NULL;
1006 klass->focus_in_event = gtk_widget_real_focus_in_event;
1007 klass->focus_out_event = gtk_widget_real_focus_out_event;
1008 klass->map_event = NULL;
1009 klass->unmap_event = NULL;
1010 klass->window_state_event = NULL;
1011 klass->property_notify_event = _gtk_selection_property_notify;
1012 klass->selection_clear_event = _gtk_selection_clear;
1013 klass->selection_request_event = _gtk_selection_request;
1014 klass->selection_notify_event = _gtk_selection_notify;
1015 klass->selection_received = NULL;
1016 klass->proximity_in_event = NULL;
1017 klass->proximity_out_event = NULL;
1018 klass->drag_begin = NULL;
1019 klass->drag_end = NULL;
1020 klass->drag_data_delete = NULL;
1021 klass->drag_leave = NULL;
1022 klass->drag_motion = NULL;
1023 klass->drag_drop = NULL;
1024 klass->drag_data_received = NULL;
1025 klass->screen_changed = NULL;
1026 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1027 klass->grab_broken_event = NULL;
1028 klass->query_tooltip = gtk_widget_real_query_tooltip;
1029 klass->style_updated = gtk_widget_real_style_updated;
1031 klass->show_help = gtk_widget_real_show_help;
1033 /* Accessibility support */
1034 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1035 klass->priv->accessible_role = ATK_ROLE_INVALID;
1036 klass->get_accessible = gtk_widget_real_get_accessible;
1038 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1039 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1041 g_object_class_install_property (gobject_class,
1043 g_param_spec_string ("name",
1045 P_("The name of the widget"),
1047 GTK_PARAM_READWRITE));
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_object ("parent",
1051 P_("Parent widget"),
1052 P_("The parent widget of this widget. Must be a Container widget"),
1054 GTK_PARAM_READWRITE));
1056 g_object_class_install_property (gobject_class,
1058 g_param_spec_int ("width-request",
1059 P_("Width request"),
1060 P_("Override for width request of the widget, or -1 if natural request should be used"),
1064 GTK_PARAM_READWRITE));
1065 g_object_class_install_property (gobject_class,
1066 PROP_HEIGHT_REQUEST,
1067 g_param_spec_int ("height-request",
1068 P_("Height request"),
1069 P_("Override for height request of the widget, or -1 if natural request should be used"),
1073 GTK_PARAM_READWRITE));
1074 g_object_class_install_property (gobject_class,
1076 g_param_spec_boolean ("visible",
1078 P_("Whether the widget is visible"),
1080 GTK_PARAM_READWRITE));
1081 g_object_class_install_property (gobject_class,
1083 g_param_spec_boolean ("sensitive",
1085 P_("Whether the widget responds to input"),
1087 GTK_PARAM_READWRITE));
1088 g_object_class_install_property (gobject_class,
1090 g_param_spec_boolean ("app-paintable",
1091 P_("Application paintable"),
1092 P_("Whether the application will paint directly on the widget"),
1094 GTK_PARAM_READWRITE));
1095 g_object_class_install_property (gobject_class,
1097 g_param_spec_boolean ("can-focus",
1099 P_("Whether the widget can accept the input focus"),
1101 GTK_PARAM_READWRITE));
1102 g_object_class_install_property (gobject_class,
1104 g_param_spec_boolean ("has-focus",
1106 P_("Whether the widget has the input focus"),
1108 GTK_PARAM_READWRITE));
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_boolean ("is-focus",
1113 P_("Whether the widget is the focus widget within the toplevel"),
1115 GTK_PARAM_READWRITE));
1116 g_object_class_install_property (gobject_class,
1118 g_param_spec_boolean ("can-default",
1120 P_("Whether the widget can be the default widget"),
1122 GTK_PARAM_READWRITE));
1123 g_object_class_install_property (gobject_class,
1125 g_param_spec_boolean ("has-default",
1127 P_("Whether the widget is the default widget"),
1129 GTK_PARAM_READWRITE));
1130 g_object_class_install_property (gobject_class,
1131 PROP_RECEIVES_DEFAULT,
1132 g_param_spec_boolean ("receives-default",
1133 P_("Receives default"),
1134 P_("If TRUE, the widget will receive the default action when it is focused"),
1136 GTK_PARAM_READWRITE));
1137 g_object_class_install_property (gobject_class,
1138 PROP_COMPOSITE_CHILD,
1139 g_param_spec_boolean ("composite-child",
1140 P_("Composite child"),
1141 P_("Whether the widget is part of a composite widget"),
1143 GTK_PARAM_READABLE));
1144 g_object_class_install_property (gobject_class,
1146 g_param_spec_object ("style",
1148 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1150 GTK_PARAM_READWRITE));
1151 g_object_class_install_property (gobject_class,
1153 g_param_spec_flags ("events",
1155 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1156 GDK_TYPE_EVENT_MASK,
1158 GTK_PARAM_READWRITE));
1159 g_object_class_install_property (gobject_class,
1161 g_param_spec_boolean ("no-show-all",
1163 P_("Whether gtk_widget_show_all() should not affect this widget"),
1165 GTK_PARAM_READWRITE));
1168 * GtkWidget:has-tooltip:
1170 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1171 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1172 * the widget will be queried using #GtkWidget::query-tooltip to determine
1173 * whether it will provide a tooltip or not.
1175 * Note that setting this property to %TRUE for the first time will change
1176 * the event masks of the GdkWindows of this widget to include leave-notify
1177 * and motion-notify events. This cannot and will not be undone when the
1178 * property is set to %FALSE again.
1182 g_object_class_install_property (gobject_class,
1184 g_param_spec_boolean ("has-tooltip",
1186 P_("Whether this widget has a tooltip"),
1188 GTK_PARAM_READWRITE));
1190 * GtkWidget:tooltip-text:
1192 * Sets the text of tooltip to be the given string.
1194 * Also see gtk_tooltip_set_text().
1196 * This is a convenience property which will take care of getting the
1197 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1198 * will automatically be set to %TRUE and there will be taken care of
1199 * #GtkWidget::query-tooltip in the default signal handler.
1203 g_object_class_install_property (gobject_class,
1205 g_param_spec_string ("tooltip-text",
1207 P_("The contents of the tooltip for this widget"),
1209 GTK_PARAM_READWRITE));
1211 * GtkWidget:tooltip-markup:
1213 * Sets the text of tooltip to be the given string, which is marked up
1214 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1215 * Also see gtk_tooltip_set_markup().
1217 * This is a convenience property which will take care of getting the
1218 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1219 * will automatically be set to %TRUE and there will be taken care of
1220 * #GtkWidget::query-tooltip in the default signal handler.
1224 g_object_class_install_property (gobject_class,
1225 PROP_TOOLTIP_MARKUP,
1226 g_param_spec_string ("tooltip-markup",
1227 P_("Tooltip markup"),
1228 P_("The contents of the tooltip for this widget"),
1230 GTK_PARAM_READWRITE));
1235 * The widget's window if it is realized, %NULL otherwise.
1239 g_object_class_install_property (gobject_class,
1241 g_param_spec_object ("window",
1243 P_("The widget's window if it is realized"),
1245 GTK_PARAM_READABLE));
1248 * GtkWidget:double-buffered:
1250 * Whether the widget is double buffered.
1254 g_object_class_install_property (gobject_class,
1255 PROP_DOUBLE_BUFFERED,
1256 g_param_spec_boolean ("double-buffered",
1257 P_("Double Buffered"),
1258 P_("Whether the widget is double buffered"),
1260 GTK_PARAM_READWRITE));
1265 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1269 g_object_class_install_property (gobject_class,
1271 g_param_spec_enum ("halign",
1272 P_("Horizontal Alignment"),
1273 P_("How to position in extra horizontal space"),
1276 GTK_PARAM_READWRITE));
1281 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1285 g_object_class_install_property (gobject_class,
1287 g_param_spec_enum ("valign",
1288 P_("Vertical Alignment"),
1289 P_("How to position in extra vertical space"),
1292 GTK_PARAM_READWRITE));
1295 * GtkWidget:margin-left:
1297 * Margin on left side of widget.
1299 * This property adds margin outside of the widget's normal size
1300 * request, the margin will be added in addition to the size from
1301 * gtk_widget_set_size_request() for example.
1305 g_object_class_install_property (gobject_class,
1307 g_param_spec_int ("margin-left",
1308 P_("Margin on Left"),
1309 P_("Pixels of extra space on the left side"),
1313 GTK_PARAM_READWRITE));
1316 * GtkWidget:margin-right:
1318 * Margin on right side of widget.
1320 * This property adds margin outside of the widget's normal size
1321 * request, the margin will be added in addition to the size from
1322 * gtk_widget_set_size_request() for example.
1326 g_object_class_install_property (gobject_class,
1328 g_param_spec_int ("margin-right",
1329 P_("Margin on Right"),
1330 P_("Pixels of extra space on the right side"),
1334 GTK_PARAM_READWRITE));
1337 * GtkWidget:margin-top:
1339 * Margin on top side of widget.
1341 * This property adds margin outside of the widget's normal size
1342 * request, the margin will be added in addition to the size from
1343 * gtk_widget_set_size_request() for example.
1347 g_object_class_install_property (gobject_class,
1349 g_param_spec_int ("margin-top",
1350 P_("Margin on Top"),
1351 P_("Pixels of extra space on the top side"),
1355 GTK_PARAM_READWRITE));
1358 * GtkWidget:margin-bottom:
1360 * Margin on bottom side of widget.
1362 * This property adds margin outside of the widget's normal size
1363 * request, the margin will be added in addition to the size from
1364 * gtk_widget_set_size_request() for example.
1368 g_object_class_install_property (gobject_class,
1370 g_param_spec_int ("margin-bottom",
1371 P_("Margin on Bottom"),
1372 P_("Pixels of extra space on the bottom side"),
1376 GTK_PARAM_READWRITE));
1381 * Sets all four sides' margin at once. If read, returns max
1382 * margin on any side.
1386 g_object_class_install_property (gobject_class,
1388 g_param_spec_int ("margin",
1390 P_("Pixels of extra space on all four sides"),
1394 GTK_PARAM_READWRITE));
1397 * GtkWidget::destroy:
1398 * @object: the object which received the signal
1400 * Signals that all holders of a reference to the widget should release
1401 * the reference that they hold. May result in finalization of the widget
1402 * if all references are released.
1404 widget_signals[DESTROY] =
1405 g_signal_new (I_("destroy"),
1406 G_TYPE_FROM_CLASS (gobject_class),
1407 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1408 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1410 _gtk_marshal_VOID__VOID,
1414 * GtkWidget:hexpand:
1416 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1420 g_object_class_install_property (gobject_class,
1422 g_param_spec_boolean ("hexpand",
1423 P_("Horizontal Expand"),
1424 P_("Whether widget wants more horizontal space"),
1426 GTK_PARAM_READWRITE));
1429 * GtkWidget:hexpand-set:
1431 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1435 g_object_class_install_property (gobject_class,
1437 g_param_spec_boolean ("hexpand-set",
1438 P_("Horizontal Expand Set"),
1439 P_("Whether to use the hexpand property"),
1441 GTK_PARAM_READWRITE));
1444 * GtkWidget:vexpand:
1446 * Whether to expand vertically. See gtk_widget_set_vexpand().
1450 g_object_class_install_property (gobject_class,
1452 g_param_spec_boolean ("vexpand",
1453 P_("Vertical Expand"),
1454 P_("Whether widget wants more vertical space"),
1456 GTK_PARAM_READWRITE));
1459 * GtkWidget:vexpand-set:
1461 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1465 g_object_class_install_property (gobject_class,
1467 g_param_spec_boolean ("vexpand-set",
1468 P_("Vertical Expand Set"),
1469 P_("Whether to use the vexpand property"),
1471 GTK_PARAM_READWRITE));
1476 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1480 g_object_class_install_property (gobject_class,
1482 g_param_spec_boolean ("expand",
1484 P_("Whether widget wants to expand in both directions"),
1486 GTK_PARAM_READWRITE));
1489 * GtkWidget:opacity:
1491 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1492 * more details about window opacity.
1494 * Before 3.8 this was only availible in GtkWindow
1498 g_object_class_install_property (gobject_class,
1500 g_param_spec_double ("opacity",
1501 P_("Opacity for Widget"),
1502 P_("The opacity of the widget, from 0 to 1"),
1506 GTK_PARAM_READWRITE));
1509 * @widget: the object which received the signal.
1511 widget_signals[SHOW] =
1512 g_signal_new (I_("show"),
1513 G_TYPE_FROM_CLASS (gobject_class),
1515 G_STRUCT_OFFSET (GtkWidgetClass, show),
1517 _gtk_marshal_VOID__VOID,
1522 * @widget: the object which received the signal.
1524 widget_signals[HIDE] =
1525 g_signal_new (I_("hide"),
1526 G_TYPE_FROM_CLASS (gobject_class),
1528 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1530 _gtk_marshal_VOID__VOID,
1535 * @widget: the object which received the signal.
1537 widget_signals[MAP] =
1538 g_signal_new (I_("map"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1541 G_STRUCT_OFFSET (GtkWidgetClass, map),
1543 _gtk_marshal_VOID__VOID,
1548 * @widget: the object which received the signal.
1550 widget_signals[UNMAP] =
1551 g_signal_new (I_("unmap"),
1552 G_TYPE_FROM_CLASS (gobject_class),
1554 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1556 _gtk_marshal_VOID__VOID,
1560 * GtkWidget::realize:
1561 * @widget: the object which received the signal.
1563 widget_signals[REALIZE] =
1564 g_signal_new (I_("realize"),
1565 G_TYPE_FROM_CLASS (gobject_class),
1567 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1569 _gtk_marshal_VOID__VOID,
1573 * GtkWidget::unrealize:
1574 * @widget: the object which received the signal.
1576 widget_signals[UNREALIZE] =
1577 g_signal_new (I_("unrealize"),
1578 G_TYPE_FROM_CLASS (gobject_class),
1580 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1582 _gtk_marshal_VOID__VOID,
1586 * GtkWidget::size-allocate:
1587 * @widget: the object which received the signal.
1590 widget_signals[SIZE_ALLOCATE] =
1591 g_signal_new (I_("size-allocate"),
1592 G_TYPE_FROM_CLASS (gobject_class),
1594 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1596 _gtk_marshal_VOID__BOXED,
1598 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1601 * GtkWidget::state-changed:
1602 * @widget: the object which received the signal.
1603 * @state: the previous state
1605 * The ::state-changed signal is emitted when the widget state changes.
1606 * See gtk_widget_get_state().
1608 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1610 widget_signals[STATE_CHANGED] =
1611 g_signal_new (I_("state-changed"),
1612 G_TYPE_FROM_CLASS (gobject_class),
1614 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1616 _gtk_marshal_VOID__ENUM,
1618 GTK_TYPE_STATE_TYPE);
1621 * GtkWidget::state-flags-changed:
1622 * @widget: the object which received the signal.
1623 * @flags: The previous state flags.
1625 * The ::state-flags-changed signal is emitted when the widget state
1626 * changes, see gtk_widget_get_state_flags().
1630 widget_signals[STATE_FLAGS_CHANGED] =
1631 g_signal_new (I_("state-flags-changed"),
1632 G_TYPE_FROM_CLASS (gobject_class),
1634 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1636 _gtk_marshal_VOID__FLAGS,
1638 GTK_TYPE_STATE_FLAGS);
1641 * GtkWidget::parent-set:
1642 * @widget: the object on which the signal is emitted
1643 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1644 * just got its initial parent.
1646 * The ::parent-set signal is emitted when a new parent
1647 * has been set on a widget.
1649 widget_signals[PARENT_SET] =
1650 g_signal_new (I_("parent-set"),
1651 G_TYPE_FROM_CLASS (gobject_class),
1653 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1655 _gtk_marshal_VOID__OBJECT,
1660 * GtkWidget::hierarchy-changed:
1661 * @widget: the object on which the signal is emitted
1662 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1663 * if the widget was previously unanchored
1665 * The ::hierarchy-changed signal is emitted when the
1666 * anchored state of a widget changes. A widget is
1667 * <firstterm>anchored</firstterm> when its toplevel
1668 * ancestor is a #GtkWindow. This signal is emitted when
1669 * a widget changes from un-anchored to anchored or vice-versa.
1671 widget_signals[HIERARCHY_CHANGED] =
1672 g_signal_new (I_("hierarchy-changed"),
1673 G_TYPE_FROM_CLASS (gobject_class),
1675 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1677 _gtk_marshal_VOID__OBJECT,
1682 * GtkWidget::style-set:
1683 * @widget: the object on which the signal is emitted
1684 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1685 * just got its initial style
1687 * The ::style-set signal is emitted when a new style has been set
1688 * on a widget. Note that style-modifying functions like
1689 * gtk_widget_modify_base() also cause this signal to be emitted.
1691 * Note that this signal is emitted for changes to the deprecated
1692 * #GtkStyle. To track changes to the #GtkStyleContext associated
1693 * with a widget, use the #GtkWidget::style-updated signal.
1695 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1697 widget_signals[STYLE_SET] =
1698 g_signal_new (I_("style-set"),
1699 G_TYPE_FROM_CLASS (gobject_class),
1701 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1703 _gtk_marshal_VOID__OBJECT,
1708 * GtkWidget::style-updated:
1709 * @widget: the object on which the signal is emitted
1711 * The ::style-updated signal is emitted when the #GtkStyleContext
1712 * of a widget is changed. Note that style-modifying functions like
1713 * gtk_widget_override_color() also cause this signal to be emitted.
1717 widget_signals[STYLE_UPDATED] =
1718 g_signal_new (I_("style-updated"),
1719 G_TYPE_FROM_CLASS (gobject_class),
1721 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1723 g_cclosure_marshal_VOID__VOID,
1727 * GtkWidget::direction-changed:
1728 * @widget: the object on which the signal is emitted
1729 * @previous_direction: the previous text direction of @widget
1731 * The ::direction-changed signal is emitted when the text direction
1732 * of a widget changes.
1734 widget_signals[DIRECTION_CHANGED] =
1735 g_signal_new (I_("direction-changed"),
1736 G_TYPE_FROM_CLASS (gobject_class),
1738 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1740 _gtk_marshal_VOID__ENUM,
1742 GTK_TYPE_TEXT_DIRECTION);
1745 * GtkWidget::grab-notify:
1746 * @widget: the object which received the signal
1747 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1748 * if it becomes unshadowed
1750 * The ::grab-notify signal is emitted when a widget becomes
1751 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1752 * another widget, or when it becomes unshadowed due to a grab
1755 * A widget is shadowed by a gtk_grab_add() when the topmost
1756 * grab widget in the grab stack of its window group is not
1759 widget_signals[GRAB_NOTIFY] =
1760 g_signal_new (I_("grab-notify"),
1761 G_TYPE_FROM_CLASS (gobject_class),
1763 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1765 _gtk_marshal_VOID__BOOLEAN,
1770 * GtkWidget::child-notify:
1771 * @widget: the object which received the signal
1772 * @child_property: the #GParamSpec of the changed child property
1774 * The ::child-notify signal is emitted for each
1775 * <link linkend="child-properties">child property</link> that has
1776 * changed on an object. The signal's detail holds the property name.
1778 widget_signals[CHILD_NOTIFY] =
1779 g_signal_new (I_("child-notify"),
1780 G_TYPE_FROM_CLASS (gobject_class),
1781 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1782 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1784 g_cclosure_marshal_VOID__PARAM,
1790 * @widget: the object which received the signal
1791 * @cr: the cairo context to draw to
1793 * This signal is emitted when a widget is supposed to render itself.
1794 * The @widget's top left corner must be painted at the origin of
1795 * the passed in context and be sized to the values returned by
1796 * gtk_widget_get_allocated_width() and
1797 * gtk_widget_get_allocated_height().
1799 * Signal handlers connected to this signal can modify the cairo
1800 * context passed as @cr in any way they like and don't need to
1801 * restore it. The signal emission takes care of calling cairo_save()
1802 * before and cairo_restore() after invoking the handler.
1804 * Returns: %TRUE to stop other handlers from being invoked for the event.
1805 % %FALSE to propagate the event further.
1809 widget_signals[DRAW] =
1810 g_signal_new (I_("draw"),
1811 G_TYPE_FROM_CLASS (gobject_class),
1813 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1814 _gtk_boolean_handled_accumulator, NULL,
1815 gtk_widget_draw_marshaller,
1817 CAIRO_GOBJECT_TYPE_CONTEXT);
1818 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1819 gtk_widget_draw_marshallerv);
1822 * GtkWidget::mnemonic-activate:
1823 * @widget: the object which received the signal.
1826 * Returns: %TRUE to stop other handlers from being invoked for the event.
1827 * %FALSE to propagate the event further.
1829 widget_signals[MNEMONIC_ACTIVATE] =
1830 g_signal_new (I_("mnemonic-activate"),
1831 G_TYPE_FROM_CLASS (gobject_class),
1833 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1834 _gtk_boolean_handled_accumulator, NULL,
1835 _gtk_marshal_BOOLEAN__BOOLEAN,
1840 * GtkWidget::grab-focus:
1841 * @widget: the object which received the signal.
1843 widget_signals[GRAB_FOCUS] =
1844 g_signal_new (I_("grab-focus"),
1845 G_TYPE_FROM_CLASS (gobject_class),
1846 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1847 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1849 _gtk_marshal_VOID__VOID,
1854 * @widget: the object which received the signal.
1857 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1859 widget_signals[FOCUS] =
1860 g_signal_new (I_("focus"),
1861 G_TYPE_FROM_CLASS (klass),
1863 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1864 _gtk_boolean_handled_accumulator, NULL,
1865 _gtk_marshal_BOOLEAN__ENUM,
1867 GTK_TYPE_DIRECTION_TYPE);
1870 * GtkWidget::move-focus:
1871 * @widget: the object which received the signal.
1874 widget_signals[MOVE_FOCUS] =
1875 g_signal_new (I_("move-focus"),
1876 G_TYPE_FROM_CLASS (klass),
1877 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1878 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1880 _gtk_marshal_VOID__ENUM,
1883 GTK_TYPE_DIRECTION_TYPE);
1886 * GtkWidget::keynav-failed:
1887 * @widget: the object which received the signal
1888 * @direction: the direction of movement
1890 * Gets emitted if keyboard navigation fails.
1891 * See gtk_widget_keynav_failed() for details.
1893 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1894 * if the emitting widget should try to handle the keyboard
1895 * navigation attempt in its parent container(s).
1899 widget_signals[KEYNAV_FAILED] =
1900 g_signal_new (I_("keynav-failed"),
1901 G_TYPE_FROM_CLASS (klass),
1903 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1904 _gtk_boolean_handled_accumulator, NULL,
1905 _gtk_marshal_BOOLEAN__ENUM,
1907 GTK_TYPE_DIRECTION_TYPE);
1911 * @widget: the object which received the signal.
1912 * @event: the #GdkEvent which triggered this signal
1914 * The GTK+ main loop will emit three signals for each GDK event delivered
1915 * to a widget: one generic ::event signal, another, more specific,
1916 * signal that matches the type of event delivered (e.g.
1917 * #GtkWidget::key-press-event) and finally a generic
1918 * #GtkWidget::event-after signal.
1920 * Returns: %TRUE to stop other handlers from being invoked for the event
1921 * and to cancel the emission of the second specific ::event signal.
1922 * %FALSE to propagate the event further and to allow the emission of
1923 * the second signal. The ::event-after signal is emitted regardless of
1926 widget_signals[EVENT] =
1927 g_signal_new (I_("event"),
1928 G_TYPE_FROM_CLASS (klass),
1930 G_STRUCT_OFFSET (GtkWidgetClass, event),
1931 _gtk_boolean_handled_accumulator, NULL,
1932 _gtk_marshal_BOOLEAN__BOXED,
1934 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1935 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1936 _gtk_marshal_BOOLEAN__BOXEDv);
1939 * GtkWidget::event-after:
1940 * @widget: the object which received the signal.
1941 * @event: the #GdkEvent which triggered this signal
1943 * After the emission of the #GtkWidget::event signal and (optionally)
1944 * the second more specific signal, ::event-after will be emitted
1945 * regardless of the previous two signals handlers return values.
1948 widget_signals[EVENT_AFTER] =
1949 g_signal_new (I_("event-after"),
1950 G_TYPE_FROM_CLASS (klass),
1954 _gtk_marshal_VOID__BOXED,
1956 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1957 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1958 _gtk_marshal_BOOLEAN__BOXEDv);
1961 * GtkWidget::button-press-event:
1962 * @widget: the object which received the signal.
1963 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1966 * The ::button-press-event signal will be emitted when a button
1967 * (typically from a mouse) is pressed.
1969 * To receive this signal, the #GdkWindow associated to the
1970 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1972 * This signal will be sent to the grab widget if there is one.
1974 * Returns: %TRUE to stop other handlers from being invoked for the event.
1975 * %FALSE to propagate the event further.
1977 widget_signals[BUTTON_PRESS_EVENT] =
1978 g_signal_new (I_("button-press-event"),
1979 G_TYPE_FROM_CLASS (klass),
1981 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1982 _gtk_boolean_handled_accumulator, NULL,
1983 _gtk_marshal_BOOLEAN__BOXED,
1985 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1986 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
1987 _gtk_marshal_BOOLEAN__BOXEDv);
1990 * GtkWidget::button-release-event:
1991 * @widget: the object which received the signal.
1992 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1995 * The ::button-release-event signal will be emitted when a button
1996 * (typically from a mouse) is released.
1998 * To receive this signal, the #GdkWindow associated to the
1999 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
2001 * This signal will be sent to the grab widget if there is one.
2003 * Returns: %TRUE to stop other handlers from being invoked for the event.
2004 * %FALSE to propagate the event further.
2006 widget_signals[BUTTON_RELEASE_EVENT] =
2007 g_signal_new (I_("button-release-event"),
2008 G_TYPE_FROM_CLASS (klass),
2010 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2011 _gtk_boolean_handled_accumulator, NULL,
2012 _gtk_marshal_BOOLEAN__BOXED,
2014 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2015 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2016 _gtk_marshal_BOOLEAN__BOXEDv);
2018 widget_signals[TOUCH_EVENT] =
2019 g_signal_new (I_("touch-event"),
2020 G_TYPE_FROM_CLASS (klass),
2022 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2023 _gtk_boolean_handled_accumulator, NULL,
2024 _gtk_marshal_BOOLEAN__BOXED,
2026 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2027 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2028 _gtk_marshal_BOOLEAN__BOXEDv);
2031 * GtkWidget::scroll-event:
2032 * @widget: the object which received the signal.
2033 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2036 * The ::scroll-event signal is emitted when a button in the 4 to 7
2037 * range is pressed. Wheel mice are usually configured to generate
2038 * button press events for buttons 4 and 5 when the wheel is turned.
2040 * To receive this signal, the #GdkWindow associated to the widget needs
2041 * to enable the #GDK_SCROLL_MASK mask.
2043 * This signal will be sent to the grab widget if there is one.
2045 * Returns: %TRUE to stop other handlers from being invoked for the event.
2046 * %FALSE to propagate the event further.
2048 widget_signals[SCROLL_EVENT] =
2049 g_signal_new (I_("scroll-event"),
2050 G_TYPE_FROM_CLASS (klass),
2052 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2053 _gtk_boolean_handled_accumulator, NULL,
2054 _gtk_marshal_BOOLEAN__BOXED,
2056 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2057 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2058 _gtk_marshal_BOOLEAN__BOXEDv);
2061 * GtkWidget::motion-notify-event:
2062 * @widget: the object which received the signal.
2063 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2066 * The ::motion-notify-event signal is emitted when the pointer moves
2067 * over the widget's #GdkWindow.
2069 * To receive this signal, the #GdkWindow associated to the widget
2070 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2072 * This signal will be sent to the grab widget if there is one.
2074 * Returns: %TRUE to stop other handlers from being invoked for the event.
2075 * %FALSE to propagate the event further.
2077 widget_signals[MOTION_NOTIFY_EVENT] =
2078 g_signal_new (I_("motion-notify-event"),
2079 G_TYPE_FROM_CLASS (klass),
2081 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2082 _gtk_boolean_handled_accumulator, NULL,
2083 _gtk_marshal_BOOLEAN__BOXED,
2085 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2086 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2087 _gtk_marshal_BOOLEAN__BOXEDv);
2090 * GtkWidget::composited-changed:
2091 * @widget: the object on which the signal is emitted
2093 * The ::composited-changed signal is emitted when the composited
2094 * status of @widget<!-- -->s screen changes.
2095 * See gdk_screen_is_composited().
2097 widget_signals[COMPOSITED_CHANGED] =
2098 g_signal_new (I_("composited-changed"),
2099 G_TYPE_FROM_CLASS (klass),
2100 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2101 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2103 _gtk_marshal_VOID__VOID,
2107 * GtkWidget::delete-event:
2108 * @widget: the object which received the signal
2109 * @event: the event which triggered this signal
2111 * The ::delete-event signal is emitted if a user requests that
2112 * a toplevel window is closed. The default handler for this signal
2113 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2114 * this signal will cause the window to be hidden instead, so that
2115 * it can later be shown again without reconstructing it.
2117 * Returns: %TRUE to stop other handlers from being invoked for the event.
2118 * %FALSE to propagate the event further.
2120 widget_signals[DELETE_EVENT] =
2121 g_signal_new (I_("delete-event"),
2122 G_TYPE_FROM_CLASS (klass),
2124 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2125 _gtk_boolean_handled_accumulator, NULL,
2126 _gtk_marshal_BOOLEAN__BOXED,
2128 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2129 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2130 _gtk_marshal_BOOLEAN__BOXEDv);
2133 * GtkWidget::destroy-event:
2134 * @widget: the object which received the signal.
2135 * @event: the event which triggered this signal
2137 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2138 * You rarely get this signal, because most widgets disconnect themselves
2139 * from their window before they destroy it, so no widget owns the
2140 * window at destroy time.
2142 * To receive this signal, the #GdkWindow associated to the widget needs
2143 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2144 * automatically for all new windows.
2146 * Returns: %TRUE to stop other handlers from being invoked for the event.
2147 * %FALSE to propagate the event further.
2149 widget_signals[DESTROY_EVENT] =
2150 g_signal_new (I_("destroy-event"),
2151 G_TYPE_FROM_CLASS (klass),
2153 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2154 _gtk_boolean_handled_accumulator, NULL,
2155 _gtk_marshal_BOOLEAN__BOXED,
2157 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2158 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2159 _gtk_marshal_BOOLEAN__BOXEDv);
2162 * GtkWidget::key-press-event:
2163 * @widget: the object which received the signal
2164 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2166 * The ::key-press-event signal is emitted when a key is pressed. The signal
2167 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2169 * To receive this signal, the #GdkWindow associated to the widget needs
2170 * to enable the #GDK_KEY_PRESS_MASK mask.
2172 * This signal will be sent to the grab widget if there is one.
2174 * Returns: %TRUE to stop other handlers from being invoked for the event.
2175 * %FALSE to propagate the event further.
2177 widget_signals[KEY_PRESS_EVENT] =
2178 g_signal_new (I_("key-press-event"),
2179 G_TYPE_FROM_CLASS (klass),
2181 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2182 _gtk_boolean_handled_accumulator, NULL,
2183 _gtk_marshal_BOOLEAN__BOXED,
2185 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2186 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2187 _gtk_marshal_BOOLEAN__BOXEDv);
2190 * GtkWidget::key-release-event:
2191 * @widget: the object which received the signal
2192 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2194 * The ::key-release-event signal is emitted when a key is released.
2196 * To receive this signal, the #GdkWindow associated to the widget needs
2197 * to enable the #GDK_KEY_RELEASE_MASK mask.
2199 * This signal will be sent to the grab widget if there is one.
2201 * Returns: %TRUE to stop other handlers from being invoked for the event.
2202 * %FALSE to propagate the event further.
2204 widget_signals[KEY_RELEASE_EVENT] =
2205 g_signal_new (I_("key-release-event"),
2206 G_TYPE_FROM_CLASS (klass),
2208 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2209 _gtk_boolean_handled_accumulator, NULL,
2210 _gtk_marshal_BOOLEAN__BOXED,
2212 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2213 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2214 _gtk_marshal_BOOLEAN__BOXEDv);
2217 * GtkWidget::enter-notify-event:
2218 * @widget: the object which received the signal
2219 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2222 * The ::enter-notify-event will be emitted when the pointer enters
2223 * the @widget's window.
2225 * To receive this signal, the #GdkWindow associated to the widget needs
2226 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2228 * This signal will be sent to the grab widget if there is one.
2230 * Returns: %TRUE to stop other handlers from being invoked for the event.
2231 * %FALSE to propagate the event further.
2233 widget_signals[ENTER_NOTIFY_EVENT] =
2234 g_signal_new (I_("enter-notify-event"),
2235 G_TYPE_FROM_CLASS (klass),
2237 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2238 _gtk_boolean_handled_accumulator, NULL,
2239 _gtk_marshal_BOOLEAN__BOXED,
2241 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2242 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2243 _gtk_marshal_BOOLEAN__BOXEDv);
2246 * GtkWidget::leave-notify-event:
2247 * @widget: the object which received the signal
2248 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2251 * The ::leave-notify-event will be emitted when the pointer leaves
2252 * the @widget's window.
2254 * To receive this signal, the #GdkWindow associated to the widget needs
2255 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2257 * This signal will be sent to the grab widget if there is one.
2259 * Returns: %TRUE to stop other handlers from being invoked for the event.
2260 * %FALSE to propagate the event further.
2262 widget_signals[LEAVE_NOTIFY_EVENT] =
2263 g_signal_new (I_("leave-notify-event"),
2264 G_TYPE_FROM_CLASS (klass),
2266 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2267 _gtk_boolean_handled_accumulator, NULL,
2268 _gtk_marshal_BOOLEAN__BOXED,
2270 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2271 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2272 _gtk_marshal_BOOLEAN__BOXEDv);
2275 * GtkWidget::configure-event:
2276 * @widget: the object which received the signal
2277 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2280 * The ::configure-event signal will be emitted when the size, position or
2281 * stacking of the @widget's window has changed.
2283 * To receive this signal, the #GdkWindow associated to the widget needs
2284 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2285 * automatically for all new windows.
2287 * Returns: %TRUE to stop other handlers from being invoked for the event.
2288 * %FALSE to propagate the event further.
2290 widget_signals[CONFIGURE_EVENT] =
2291 g_signal_new (I_("configure-event"),
2292 G_TYPE_FROM_CLASS (klass),
2294 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2295 _gtk_boolean_handled_accumulator, NULL,
2296 _gtk_marshal_BOOLEAN__BOXED,
2298 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2299 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2300 _gtk_marshal_BOOLEAN__BOXEDv);
2303 * GtkWidget::focus-in-event:
2304 * @widget: the object which received the signal
2305 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2308 * The ::focus-in-event signal will be emitted when the keyboard focus
2309 * enters the @widget's window.
2311 * To receive this signal, the #GdkWindow associated to the widget needs
2312 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2314 * Returns: %TRUE to stop other handlers from being invoked for the event.
2315 * %FALSE to propagate the event further.
2317 widget_signals[FOCUS_IN_EVENT] =
2318 g_signal_new (I_("focus-in-event"),
2319 G_TYPE_FROM_CLASS (klass),
2321 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2322 _gtk_boolean_handled_accumulator, NULL,
2323 _gtk_marshal_BOOLEAN__BOXED,
2325 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2326 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2327 _gtk_marshal_BOOLEAN__BOXEDv);
2330 * GtkWidget::focus-out-event:
2331 * @widget: the object which received the signal
2332 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2335 * The ::focus-out-event signal will be emitted when the keyboard focus
2336 * leaves the @widget's window.
2338 * To receive this signal, the #GdkWindow associated to the widget needs
2339 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2341 * Returns: %TRUE to stop other handlers from being invoked for the event.
2342 * %FALSE to propagate the event further.
2344 widget_signals[FOCUS_OUT_EVENT] =
2345 g_signal_new (I_("focus-out-event"),
2346 G_TYPE_FROM_CLASS (klass),
2348 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2349 _gtk_boolean_handled_accumulator, NULL,
2350 _gtk_marshal_BOOLEAN__BOXED,
2352 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2353 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2354 _gtk_marshal_BOOLEAN__BOXEDv);
2357 * GtkWidget::map-event:
2358 * @widget: the object which received the signal
2359 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2361 * The ::map-event signal will be emitted when the @widget's window is
2362 * mapped. A window is mapped when it becomes visible on the screen.
2364 * To receive this signal, the #GdkWindow associated to the widget needs
2365 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2366 * automatically for all new windows.
2368 * Returns: %TRUE to stop other handlers from being invoked for the event.
2369 * %FALSE to propagate the event further.
2371 widget_signals[MAP_EVENT] =
2372 g_signal_new (I_("map-event"),
2373 G_TYPE_FROM_CLASS (klass),
2375 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2376 _gtk_boolean_handled_accumulator, NULL,
2377 _gtk_marshal_BOOLEAN__BOXED,
2379 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2380 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2381 _gtk_marshal_BOOLEAN__BOXEDv);
2384 * GtkWidget::unmap-event:
2385 * @widget: the object which received the signal
2386 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2388 * The ::unmap-event signal will be emitted when the @widget's window is
2389 * unmapped. A window is unmapped when it becomes invisible on the screen.
2391 * To receive this signal, the #GdkWindow associated to the widget needs
2392 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2393 * automatically for all new windows.
2395 * Returns: %TRUE to stop other handlers from being invoked for the event.
2396 * %FALSE to propagate the event further.
2398 widget_signals[UNMAP_EVENT] =
2399 g_signal_new (I_("unmap-event"),
2400 G_TYPE_FROM_CLASS (klass),
2402 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2403 _gtk_boolean_handled_accumulator, NULL,
2404 _gtk_marshal_BOOLEAN__BOXED,
2406 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2407 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2408 _gtk_marshal_BOOLEAN__BOXEDv);
2411 * GtkWidget::property-notify-event:
2412 * @widget: the object which received the signal
2413 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2416 * The ::property-notify-event signal will be emitted when a property on
2417 * the @widget's window has been changed or deleted.
2419 * To receive this signal, the #GdkWindow associated to the widget needs
2420 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2422 * Returns: %TRUE to stop other handlers from being invoked for the event.
2423 * %FALSE to propagate the event further.
2425 widget_signals[PROPERTY_NOTIFY_EVENT] =
2426 g_signal_new (I_("property-notify-event"),
2427 G_TYPE_FROM_CLASS (klass),
2429 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2430 _gtk_boolean_handled_accumulator, NULL,
2431 _gtk_marshal_BOOLEAN__BOXED,
2433 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2434 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2435 _gtk_marshal_BOOLEAN__BOXEDv);
2438 * GtkWidget::selection-clear-event:
2439 * @widget: the object which received the signal
2440 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2443 * The ::selection-clear-event signal will be emitted when the
2444 * the @widget's window has lost ownership of a selection.
2446 * Returns: %TRUE to stop other handlers from being invoked for the event.
2447 * %FALSE to propagate the event further.
2449 widget_signals[SELECTION_CLEAR_EVENT] =
2450 g_signal_new (I_("selection-clear-event"),
2451 G_TYPE_FROM_CLASS (klass),
2453 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2454 _gtk_boolean_handled_accumulator, NULL,
2455 _gtk_marshal_BOOLEAN__BOXED,
2457 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2458 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2459 _gtk_marshal_BOOLEAN__BOXEDv);
2462 * GtkWidget::selection-request-event:
2463 * @widget: the object which received the signal
2464 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2467 * The ::selection-request-event signal will be emitted when
2468 * another client requests ownership of the selection owned by
2469 * the @widget's window.
2471 * Returns: %TRUE to stop other handlers from being invoked for the event.
2472 * %FALSE to propagate the event further.
2474 widget_signals[SELECTION_REQUEST_EVENT] =
2475 g_signal_new (I_("selection-request-event"),
2476 G_TYPE_FROM_CLASS (klass),
2478 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2479 _gtk_boolean_handled_accumulator, NULL,
2480 _gtk_marshal_BOOLEAN__BOXED,
2482 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2483 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2484 _gtk_marshal_BOOLEAN__BOXEDv);
2487 * GtkWidget::selection-notify-event:
2488 * @widget: the object which received the signal.
2489 * @event: (type Gdk.EventSelection):
2491 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2493 widget_signals[SELECTION_NOTIFY_EVENT] =
2494 g_signal_new (I_("selection-notify-event"),
2495 G_TYPE_FROM_CLASS (klass),
2497 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2498 _gtk_boolean_handled_accumulator, NULL,
2499 _gtk_marshal_BOOLEAN__BOXED,
2501 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2502 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2503 _gtk_marshal_BOOLEAN__BOXEDv);
2506 * GtkWidget::selection-received:
2507 * @widget: the object which received the signal.
2511 widget_signals[SELECTION_RECEIVED] =
2512 g_signal_new (I_("selection-received"),
2513 G_TYPE_FROM_CLASS (klass),
2515 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2517 _gtk_marshal_VOID__BOXED_UINT,
2519 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2523 * GtkWidget::selection-get:
2524 * @widget: the object which received the signal.
2529 widget_signals[SELECTION_GET] =
2530 g_signal_new (I_("selection-get"),
2531 G_TYPE_FROM_CLASS (klass),
2533 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2535 _gtk_marshal_VOID__BOXED_UINT_UINT,
2537 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2542 * GtkWidget::proximity-in-event:
2543 * @widget: the object which received the signal
2544 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2547 * To receive this signal the #GdkWindow associated to the widget needs
2548 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2550 * This signal will be sent to the grab widget if there is one.
2552 * Returns: %TRUE to stop other handlers from being invoked for the event.
2553 * %FALSE to propagate the event further.
2555 widget_signals[PROXIMITY_IN_EVENT] =
2556 g_signal_new (I_("proximity-in-event"),
2557 G_TYPE_FROM_CLASS (klass),
2559 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2560 _gtk_boolean_handled_accumulator, NULL,
2561 _gtk_marshal_BOOLEAN__BOXED,
2563 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2564 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2565 _gtk_marshal_BOOLEAN__BOXEDv);
2568 * GtkWidget::proximity-out-event:
2569 * @widget: the object which received the signal
2570 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2573 * To receive this signal the #GdkWindow associated to the widget needs
2574 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2576 * This signal will be sent to the grab widget if there is one.
2578 * Returns: %TRUE to stop other handlers from being invoked for the event.
2579 * %FALSE to propagate the event further.
2581 widget_signals[PROXIMITY_OUT_EVENT] =
2582 g_signal_new (I_("proximity-out-event"),
2583 G_TYPE_FROM_CLASS (klass),
2585 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2586 _gtk_boolean_handled_accumulator, NULL,
2587 _gtk_marshal_BOOLEAN__BOXED,
2589 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2590 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2591 _gtk_marshal_BOOLEAN__BOXEDv);
2594 * GtkWidget::drag-leave:
2595 * @widget: the object which received the signal.
2596 * @context: the drag context
2597 * @time: the timestamp of the motion event
2599 * The ::drag-leave signal is emitted on the drop site when the cursor
2600 * leaves the widget. A typical reason to connect to this signal is to
2601 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2602 * with gtk_drag_unhighlight()
2604 widget_signals[DRAG_LEAVE] =
2605 g_signal_new (I_("drag-leave"),
2606 G_TYPE_FROM_CLASS (klass),
2608 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2610 _gtk_marshal_VOID__OBJECT_UINT,
2612 GDK_TYPE_DRAG_CONTEXT,
2616 * GtkWidget::drag-begin:
2617 * @widget: the object which received the signal
2618 * @context: the drag context
2620 * The ::drag-begin signal is emitted on the drag source when a drag is
2621 * started. A typical reason to connect to this signal is to set up a
2622 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2624 * Note that some widgets set up a drag icon in the default handler of
2625 * this signal, so you may have to use g_signal_connect_after() to
2626 * override what the default handler did.
2628 widget_signals[DRAG_BEGIN] =
2629 g_signal_new (I_("drag-begin"),
2630 G_TYPE_FROM_CLASS (klass),
2632 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2634 _gtk_marshal_VOID__OBJECT,
2636 GDK_TYPE_DRAG_CONTEXT);
2639 * GtkWidget::drag-end:
2640 * @widget: the object which received the signal
2641 * @context: the drag context
2643 * The ::drag-end signal is emitted on the drag source when a drag is
2644 * finished. A typical reason to connect to this signal is to undo
2645 * things done in #GtkWidget::drag-begin.
2647 widget_signals[DRAG_END] =
2648 g_signal_new (I_("drag-end"),
2649 G_TYPE_FROM_CLASS (klass),
2651 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2653 _gtk_marshal_VOID__OBJECT,
2655 GDK_TYPE_DRAG_CONTEXT);
2658 * GtkWidget::drag-data-delete:
2659 * @widget: the object which received the signal
2660 * @context: the drag context
2662 * The ::drag-data-delete signal is emitted on the drag source when a drag
2663 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2664 * handler is responsible for deleting the data that has been dropped. What
2665 * "delete" means depends on the context of the drag operation.
2667 widget_signals[DRAG_DATA_DELETE] =
2668 g_signal_new (I_("drag-data-delete"),
2669 G_TYPE_FROM_CLASS (klass),
2671 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2673 _gtk_marshal_VOID__OBJECT,
2675 GDK_TYPE_DRAG_CONTEXT);
2678 * GtkWidget::drag-failed:
2679 * @widget: the object which received the signal
2680 * @context: the drag context
2681 * @result: the result of the drag operation
2683 * The ::drag-failed signal is emitted on the drag source when a drag has
2684 * failed. The signal handler may hook custom code to handle a failed DND
2685 * operation based on the type of error, it returns %TRUE is the failure has
2686 * been already handled (not showing the default "drag operation failed"
2687 * animation), otherwise it returns %FALSE.
2689 * Return value: %TRUE if the failed drag operation has been already handled.
2693 widget_signals[DRAG_FAILED] =
2694 g_signal_new (I_("drag-failed"),
2695 G_TYPE_FROM_CLASS (klass),
2697 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2698 _gtk_boolean_handled_accumulator, NULL,
2699 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2701 GDK_TYPE_DRAG_CONTEXT,
2702 GTK_TYPE_DRAG_RESULT);
2705 * GtkWidget::drag-motion:
2706 * @widget: the object which received the signal
2707 * @context: the drag context
2708 * @x: the x coordinate of the current cursor position
2709 * @y: the y coordinate of the current cursor position
2710 * @time: the timestamp of the motion event
2712 * The ::drag-motion signal is emitted on the drop site when the user
2713 * moves the cursor over the widget during a drag. The signal handler
2714 * must determine whether the cursor position is in a drop zone or not.
2715 * If it is not in a drop zone, it returns %FALSE and no further processing
2716 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2717 * handler is responsible for providing the necessary information for
2718 * displaying feedback to the user, by calling gdk_drag_status().
2720 * If the decision whether the drop will be accepted or rejected can't be
2721 * made based solely on the cursor position and the type of the data, the
2722 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2723 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2724 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2725 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2726 * when using the drag-motion signal that way.
2728 * Also note that there is no drag-enter signal. The drag receiver has to
2729 * keep track of whether he has received any drag-motion signals since the
2730 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2731 * an "enter" signal. Upon an "enter", the handler will typically highlight
2732 * the drop site with gtk_drag_highlight().
2735 * drag_motion (GtkWidget *widget,
2736 * GdkDragContext *context,
2743 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2745 * if (!private_data->drag_highlight)
2747 * private_data->drag_highlight = 1;
2748 * gtk_drag_highlight (widget);
2751 * target = gtk_drag_dest_find_target (widget, context, NULL);
2752 * if (target == GDK_NONE)
2753 * gdk_drag_status (context, 0, time);
2756 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2757 * gtk_drag_get_data (widget, context, target, time);
2764 * drag_data_received (GtkWidget *widget,
2765 * GdkDragContext *context,
2768 * GtkSelectionData *selection_data,
2772 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2774 * if (private_data->suggested_action)
2776 * private_data->suggested_action = 0;
2778 * /* We are getting this data due to a request in drag_motion,
2779 * * rather than due to a request in drag_drop, so we are just
2780 * * supposed to call gdk_drag_status(), not actually paste in
2783 * str = gtk_selection_data_get_text (selection_data);
2784 * if (!data_is_acceptable (str))
2785 * gdk_drag_status (context, 0, time);
2787 * gdk_drag_status (context, private_data->suggested_action, time);
2791 * /* accept the drop */
2796 * Returns: whether the cursor position is in a drop zone
2798 widget_signals[DRAG_MOTION] =
2799 g_signal_new (I_("drag-motion"),
2800 G_TYPE_FROM_CLASS (klass),
2802 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2803 _gtk_boolean_handled_accumulator, NULL,
2804 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2806 GDK_TYPE_DRAG_CONTEXT,
2812 * GtkWidget::drag-drop:
2813 * @widget: the object which received the signal
2814 * @context: the drag context
2815 * @x: the x coordinate of the current cursor position
2816 * @y: the y coordinate of the current cursor position
2817 * @time: the timestamp of the motion event
2819 * The ::drag-drop signal is emitted on the drop site when the user drops
2820 * the data onto the widget. The signal handler must determine whether
2821 * the cursor position is in a drop zone or not. If it is not in a drop
2822 * zone, it returns %FALSE and no further processing is necessary.
2823 * Otherwise, the handler returns %TRUE. In this case, the handler must
2824 * ensure that gtk_drag_finish() is called to let the source know that
2825 * the drop is done. The call to gtk_drag_finish() can be done either
2826 * directly or in a #GtkWidget::drag-data-received handler which gets
2827 * triggered by calling gtk_drag_get_data() to receive the data for one
2828 * or more of the supported targets.
2830 * Returns: whether the cursor position is in a drop zone
2832 widget_signals[DRAG_DROP] =
2833 g_signal_new (I_("drag-drop"),
2834 G_TYPE_FROM_CLASS (klass),
2836 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2837 _gtk_boolean_handled_accumulator, NULL,
2838 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2840 GDK_TYPE_DRAG_CONTEXT,
2846 * GtkWidget::drag-data-get:
2847 * @widget: the object which received the signal
2848 * @context: the drag context
2849 * @data: the #GtkSelectionData to be filled with the dragged data
2850 * @info: the info that has been registered with the target in the
2852 * @time: the timestamp at which the data was requested
2854 * The ::drag-data-get signal is emitted on the drag source when the drop
2855 * site requests the data which is dragged. It is the responsibility of
2856 * the signal handler to fill @data with the data in the format which
2857 * is indicated by @info. See gtk_selection_data_set() and
2858 * gtk_selection_data_set_text().
2860 widget_signals[DRAG_DATA_GET] =
2861 g_signal_new (I_("drag-data-get"),
2862 G_TYPE_FROM_CLASS (klass),
2864 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2866 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2868 GDK_TYPE_DRAG_CONTEXT,
2869 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2874 * GtkWidget::drag-data-received:
2875 * @widget: the object which received the signal
2876 * @context: the drag context
2877 * @x: where the drop happened
2878 * @y: where the drop happened
2879 * @data: the received data
2880 * @info: the info that has been registered with the target in the
2882 * @time: the timestamp at which the data was received
2884 * The ::drag-data-received signal is emitted on the drop site when the
2885 * dragged data has been received. If the data was received in order to
2886 * determine whether the drop will be accepted, the handler is expected
2887 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2888 * If the data was received in response to a #GtkWidget::drag-drop signal
2889 * (and this is the last target to be received), the handler for this
2890 * signal is expected to process the received data and then call
2891 * gtk_drag_finish(), setting the @success parameter depending on
2892 * whether the data was processed successfully.
2894 * The handler may inspect the selected action with
2895 * gdk_drag_context_get_selected_action() before calling
2896 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2897 * shown in the following example:
2900 * drag_data_received (GtkWidget *widget,
2901 * GdkDragContext *context,
2904 * GtkSelectionData *data,
2908 * if ((data->length >= 0) && (data->format == 8))
2910 * GdkDragAction action;
2912 * /* handle data here */
2914 * action = gdk_drag_context_get_selected_action (context);
2915 * if (action == GDK_ACTION_ASK)
2917 * GtkWidget *dialog;
2920 * dialog = gtk_message_dialog_new (NULL,
2921 * GTK_DIALOG_MODAL |
2922 * GTK_DIALOG_DESTROY_WITH_PARENT,
2924 * GTK_BUTTONS_YES_NO,
2925 * "Move the data ?\n");
2926 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2927 * gtk_widget_destroy (dialog);
2929 * if (response == GTK_RESPONSE_YES)
2930 * action = GDK_ACTION_MOVE;
2932 * action = GDK_ACTION_COPY;
2935 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2938 * gtk_drag_finish (context, FALSE, FALSE, time);
2942 widget_signals[DRAG_DATA_RECEIVED] =
2943 g_signal_new (I_("drag-data-received"),
2944 G_TYPE_FROM_CLASS (klass),
2946 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2948 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2950 GDK_TYPE_DRAG_CONTEXT,
2953 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2958 * GtkWidget::visibility-notify-event:
2959 * @widget: the object which received the signal
2960 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2961 * triggered this signal.
2963 * The ::visibility-notify-event will be emitted when the @widget's window
2964 * is obscured or unobscured.
2966 * To receive this signal the #GdkWindow associated to the widget needs
2967 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2969 * Returns: %TRUE to stop other handlers from being invoked for the event.
2970 * %FALSE to propagate the event further.
2972 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2973 g_signal_new (I_("visibility-notify-event"),
2974 G_TYPE_FROM_CLASS (klass),
2976 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2977 _gtk_boolean_handled_accumulator, NULL,
2978 _gtk_marshal_BOOLEAN__BOXED,
2980 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2983 * GtkWidget::window-state-event:
2984 * @widget: the object which received the signal
2985 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2986 * triggered this signal.
2988 * The ::window-state-event will be emitted when the state of the
2989 * toplevel window associated to the @widget changes.
2991 * To receive this signal the #GdkWindow associated to the widget
2992 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2993 * this mask automatically for all new windows.
2995 * Returns: %TRUE to stop other handlers from being invoked for the
2996 * event. %FALSE to propagate the event further.
2998 widget_signals[WINDOW_STATE_EVENT] =
2999 g_signal_new (I_("window-state-event"),
3000 G_TYPE_FROM_CLASS (klass),
3002 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
3003 _gtk_boolean_handled_accumulator, NULL,
3004 _gtk_marshal_BOOLEAN__BOXED,
3006 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3007 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3008 _gtk_marshal_BOOLEAN__BOXEDv);
3011 * GtkWidget::damage-event:
3012 * @widget: the object which received the signal
3013 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3015 * Emitted when a redirected window belonging to @widget gets drawn into.
3016 * The region/area members of the event shows what area of the redirected
3017 * drawable was drawn into.
3019 * Returns: %TRUE to stop other handlers from being invoked for the event.
3020 * %FALSE to propagate the event further.
3024 widget_signals[DAMAGE_EVENT] =
3025 g_signal_new (I_("damage-event"),
3026 G_TYPE_FROM_CLASS (klass),
3028 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3029 _gtk_boolean_handled_accumulator, NULL,
3030 _gtk_marshal_BOOLEAN__BOXED,
3032 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3033 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3034 _gtk_marshal_BOOLEAN__BOXEDv);
3037 * GtkWidget::grab-broken-event:
3038 * @widget: the object which received the signal
3039 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3041 * Emitted when a pointer or keyboard grab on a window belonging
3042 * to @widget gets broken.
3044 * On X11, this happens when the grab window becomes unviewable
3045 * (i.e. it or one of its ancestors is unmapped), or if the same
3046 * application grabs the pointer or keyboard again.
3048 * Returns: %TRUE to stop other handlers from being invoked for
3049 * the event. %FALSE to propagate the event further.
3053 widget_signals[GRAB_BROKEN_EVENT] =
3054 g_signal_new (I_("grab-broken-event"),
3055 G_TYPE_FROM_CLASS (klass),
3057 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3058 _gtk_boolean_handled_accumulator, NULL,
3059 _gtk_marshal_BOOLEAN__BOXED,
3061 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3062 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3063 _gtk_marshal_BOOLEAN__BOXEDv);
3066 * GtkWidget::query-tooltip:
3067 * @widget: the object which received the signal
3068 * @x: the x coordinate of the cursor position where the request has
3069 * been emitted, relative to @widget's left side
3070 * @y: the y coordinate of the cursor position where the request has
3071 * been emitted, relative to @widget's top
3072 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3073 * @tooltip: a #GtkTooltip
3075 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3076 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3077 * focus in keyboard mode.
3079 * Using the given coordinates, the signal handler should determine
3080 * whether a tooltip should be shown for @widget. If this is the case
3081 * %TRUE should be returned, %FALSE otherwise. Note that if
3082 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3083 * should not be used.
3085 * The signal handler is free to manipulate @tooltip with the therefore
3086 * destined function calls.
3088 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3092 widget_signals[QUERY_TOOLTIP] =
3093 g_signal_new (I_("query-tooltip"),
3094 G_TYPE_FROM_CLASS (klass),
3096 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3097 _gtk_boolean_handled_accumulator, NULL,
3098 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3106 * GtkWidget::popup-menu:
3107 * @widget: the object which received the signal
3109 * This signal gets emitted whenever a widget should pop up a context
3110 * menu. This usually happens through the standard key binding mechanism;
3111 * by pressing a certain key while a widget is focused, the user can cause
3112 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3113 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3114 * for an example of how to use this signal.
3116 * Returns: %TRUE if a menu was activated
3118 widget_signals[POPUP_MENU] =
3119 g_signal_new (I_("popup-menu"),
3120 G_TYPE_FROM_CLASS (klass),
3121 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3122 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3123 _gtk_boolean_handled_accumulator, NULL,
3124 _gtk_marshal_BOOLEAN__VOID,
3128 * GtkWidget::show-help:
3129 * @widget: the object which received the signal.
3132 * Returns: %TRUE to stop other handlers from being invoked for the event.
3133 * %FALSE to propagate the event further.
3135 widget_signals[SHOW_HELP] =
3136 g_signal_new (I_("show-help"),
3137 G_TYPE_FROM_CLASS (klass),
3138 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3139 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3140 _gtk_boolean_handled_accumulator, NULL,
3141 _gtk_marshal_BOOLEAN__ENUM,
3143 GTK_TYPE_WIDGET_HELP_TYPE);
3146 * GtkWidget::accel-closures-changed:
3147 * @widget: the object which received the signal.
3149 widget_signals[ACCEL_CLOSURES_CHANGED] =
3150 g_signal_new (I_("accel-closures-changed"),
3151 G_TYPE_FROM_CLASS (klass),
3155 _gtk_marshal_VOID__VOID,
3159 * GtkWidget::screen-changed:
3160 * @widget: the object on which the signal is emitted
3161 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3162 * widget was not associated with a screen before
3164 * The ::screen-changed signal gets emitted when the
3165 * screen of a widget has changed.
3167 widget_signals[SCREEN_CHANGED] =
3168 g_signal_new (I_("screen-changed"),
3169 G_TYPE_FROM_CLASS (klass),
3171 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3173 _gtk_marshal_VOID__OBJECT,
3178 * GtkWidget::can-activate-accel:
3179 * @widget: the object which received the signal
3180 * @signal_id: the ID of a signal installed on @widget
3182 * Determines whether an accelerator that activates the signal
3183 * identified by @signal_id can currently be activated.
3184 * This signal is present to allow applications and derived
3185 * widgets to override the default #GtkWidget handling
3186 * for determining whether an accelerator can be activated.
3188 * Returns: %TRUE if the signal can be activated.
3190 widget_signals[CAN_ACTIVATE_ACCEL] =
3191 g_signal_new (I_("can-activate-accel"),
3192 G_TYPE_FROM_CLASS (klass),
3194 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3195 _gtk_boolean_handled_accumulator, NULL,
3196 _gtk_marshal_BOOLEAN__UINT,
3197 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3199 binding_set = gtk_binding_set_by_class (klass);
3200 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3202 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3205 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3207 GTK_TYPE_WIDGET_HELP_TYPE,
3208 GTK_WIDGET_HELP_TOOLTIP);
3209 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3211 GTK_TYPE_WIDGET_HELP_TYPE,
3212 GTK_WIDGET_HELP_TOOLTIP);
3213 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3215 GTK_TYPE_WIDGET_HELP_TYPE,
3216 GTK_WIDGET_HELP_WHATS_THIS);
3217 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3219 GTK_TYPE_WIDGET_HELP_TYPE,
3220 GTK_WIDGET_HELP_WHATS_THIS);
3222 gtk_widget_class_install_style_property (klass,
3223 g_param_spec_boolean ("interior-focus",
3224 P_("Interior Focus"),
3225 P_("Whether to draw the focus indicator inside widgets"),
3227 GTK_PARAM_READABLE));
3229 gtk_widget_class_install_style_property (klass,
3230 g_param_spec_int ("focus-line-width",
3231 P_("Focus linewidth"),
3232 P_("Width, in pixels, of the focus indicator line"),
3234 GTK_PARAM_READABLE));
3236 gtk_widget_class_install_style_property (klass,
3237 g_param_spec_string ("focus-line-pattern",
3238 P_("Focus line dash pattern"),
3239 P_("Dash pattern used to draw the focus indicator"),
3241 GTK_PARAM_READABLE));
3242 gtk_widget_class_install_style_property (klass,
3243 g_param_spec_int ("focus-padding",
3244 P_("Focus padding"),
3245 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3247 GTK_PARAM_READABLE));
3248 gtk_widget_class_install_style_property (klass,
3249 g_param_spec_boxed ("cursor-color",
3251 P_("Color with which to draw insertion cursor"),
3253 GTK_PARAM_READABLE));
3254 gtk_widget_class_install_style_property (klass,
3255 g_param_spec_boxed ("secondary-cursor-color",
3256 P_("Secondary cursor color"),
3257 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3259 GTK_PARAM_READABLE));
3260 gtk_widget_class_install_style_property (klass,
3261 g_param_spec_float ("cursor-aspect-ratio",
3262 P_("Cursor line aspect ratio"),
3263 P_("Aspect ratio with which to draw insertion cursor"),
3265 GTK_PARAM_READABLE));
3267 gtk_widget_class_install_style_property (klass,
3268 g_param_spec_boolean ("window-dragging",
3269 P_("Window dragging"),
3270 P_("Whether windows can be dragged by clicking on empty areas"),
3272 GTK_PARAM_READABLE));
3275 * GtkWidget:link-color:
3277 * The "link-color" style property defines the color of unvisited links.
3281 gtk_widget_class_install_style_property (klass,
3282 g_param_spec_boxed ("link-color",
3283 P_("Unvisited Link Color"),
3284 P_("Color of unvisited links"),
3286 GTK_PARAM_READABLE));
3289 * GtkWidget:visited-link-color:
3291 * The "visited-link-color" style property defines the color of visited links.
3295 gtk_widget_class_install_style_property (klass,
3296 g_param_spec_boxed ("visited-link-color",
3297 P_("Visited Link Color"),
3298 P_("Color of visited links"),
3300 GTK_PARAM_READABLE));
3303 * GtkWidget:wide-separators:
3305 * The "wide-separators" style property defines whether separators have
3306 * configurable width and should be drawn using a box instead of a line.
3310 gtk_widget_class_install_style_property (klass,
3311 g_param_spec_boolean ("wide-separators",
3312 P_("Wide Separators"),
3313 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3315 GTK_PARAM_READABLE));
3318 * GtkWidget:separator-width:
3320 * The "separator-width" style property defines the width of separators.
3321 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3325 gtk_widget_class_install_style_property (klass,
3326 g_param_spec_int ("separator-width",
3327 P_("Separator Width"),
3328 P_("The width of separators if wide-separators is TRUE"),
3330 GTK_PARAM_READABLE));
3333 * GtkWidget:separator-height:
3335 * The "separator-height" style property defines the height of separators.
3336 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3340 gtk_widget_class_install_style_property (klass,
3341 g_param_spec_int ("separator-height",
3342 P_("Separator Height"),
3343 P_("The height of separators if \"wide-separators\" is TRUE"),
3345 GTK_PARAM_READABLE));
3348 * GtkWidget:scroll-arrow-hlength:
3350 * The "scroll-arrow-hlength" style property defines the length of
3351 * horizontal scroll arrows.
3355 gtk_widget_class_install_style_property (klass,
3356 g_param_spec_int ("scroll-arrow-hlength",
3357 P_("Horizontal Scroll Arrow Length"),
3358 P_("The length of horizontal scroll arrows"),
3360 GTK_PARAM_READABLE));
3363 * GtkWidget:scroll-arrow-vlength:
3365 * The "scroll-arrow-vlength" style property defines the length of
3366 * vertical scroll arrows.
3370 gtk_widget_class_install_style_property (klass,
3371 g_param_spec_int ("scroll-arrow-vlength",
3372 P_("Vertical Scroll Arrow Length"),
3373 P_("The length of vertical scroll arrows"),
3375 GTK_PARAM_READABLE));
3377 gtk_widget_class_install_style_property (klass,
3378 g_param_spec_int ("text-handle-width",
3379 P_("Width of text selection handles"),
3380 P_("Width of text selection handles"),
3382 GTK_PARAM_READABLE));
3383 gtk_widget_class_install_style_property (klass,
3384 g_param_spec_int ("text-handle-height",
3385 P_("Height of text selection handles"),
3386 P_("Height of text selection handles"),
3388 GTK_PARAM_READABLE));
3390 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3392 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3396 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3400 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3401 for (node = list; node; node = node->next)
3403 GParamSpec *pspec = node->data;
3405 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3406 g_param_spec_unref (pspec);
3412 gtk_widget_set_property (GObject *object,
3414 const GValue *value,
3417 GtkWidget *widget = GTK_WIDGET (object);
3422 gchar *tooltip_markup;
3423 const gchar *tooltip_text;
3424 GtkWindow *tooltip_window;
3427 gtk_widget_set_name (widget, g_value_get_string (value));
3430 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3432 case PROP_WIDTH_REQUEST:
3433 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3435 case PROP_HEIGHT_REQUEST:
3436 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3439 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3441 case PROP_SENSITIVE:
3442 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3444 case PROP_APP_PAINTABLE:
3445 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3447 case PROP_CAN_FOCUS:
3448 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3450 case PROP_HAS_FOCUS:
3451 if (g_value_get_boolean (value))
3452 gtk_widget_grab_focus (widget);
3455 if (g_value_get_boolean (value))
3456 gtk_widget_grab_focus (widget);
3458 case PROP_CAN_DEFAULT:
3459 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3461 case PROP_HAS_DEFAULT:
3462 if (g_value_get_boolean (value))
3463 gtk_widget_grab_default (widget);
3465 case PROP_RECEIVES_DEFAULT:
3466 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3469 gtk_widget_set_style (widget, g_value_get_object (value));
3472 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3473 gtk_widget_set_events (widget, g_value_get_flags (value));
3475 case PROP_NO_SHOW_ALL:
3476 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3478 case PROP_HAS_TOOLTIP:
3479 gtk_widget_real_set_has_tooltip (widget,
3480 g_value_get_boolean (value), FALSE);
3482 case PROP_TOOLTIP_MARKUP:
3483 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3484 tooltip_markup = g_value_dup_string (value);
3486 /* Treat an empty string as a NULL string,
3487 * because an empty string would be useless for a tooltip:
3489 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3491 g_free (tooltip_markup);
3492 tooltip_markup = NULL;
3495 g_object_set_qdata_full (object, quark_tooltip_markup,
3496 tooltip_markup, g_free);
3498 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3499 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3500 if (gtk_widget_get_visible (widget))
3501 gtk_widget_queue_tooltip_query (widget);
3503 case PROP_TOOLTIP_TEXT:
3504 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3506 tooltip_text = g_value_get_string (value);
3508 /* Treat an empty string as a NULL string,
3509 * because an empty string would be useless for a tooltip:
3511 if (tooltip_text && (strlen (tooltip_text) == 0))
3512 tooltip_text = NULL;
3514 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3516 g_object_set_qdata_full (object, quark_tooltip_markup,
3517 tooltip_markup, g_free);
3519 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3520 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3521 if (gtk_widget_get_visible (widget))
3522 gtk_widget_queue_tooltip_query (widget);
3524 case PROP_DOUBLE_BUFFERED:
3525 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3528 gtk_widget_set_halign (widget, g_value_get_enum (value));
3531 gtk_widget_set_valign (widget, g_value_get_enum (value));
3533 case PROP_MARGIN_LEFT:
3534 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3536 case PROP_MARGIN_RIGHT:
3537 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3539 case PROP_MARGIN_TOP:
3540 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3542 case PROP_MARGIN_BOTTOM:
3543 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3546 g_object_freeze_notify (G_OBJECT (widget));
3547 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3548 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3549 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3550 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3551 g_object_thaw_notify (G_OBJECT (widget));
3554 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3556 case PROP_HEXPAND_SET:
3557 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3560 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3562 case PROP_VEXPAND_SET:
3563 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3566 g_object_freeze_notify (G_OBJECT (widget));
3567 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3568 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3569 g_object_thaw_notify (G_OBJECT (widget));
3572 gtk_widget_set_opacity (widget, g_value_get_double (value));
3575 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3581 gtk_widget_get_property (GObject *object,
3586 GtkWidget *widget = GTK_WIDGET (object);
3587 GtkWidgetPrivate *priv = widget->priv;
3595 g_value_set_string (value, priv->name);
3597 g_value_set_static_string (value, "");
3600 g_value_set_object (value, priv->parent);
3602 case PROP_WIDTH_REQUEST:
3605 gtk_widget_get_size_request (widget, &w, NULL);
3606 g_value_set_int (value, w);
3609 case PROP_HEIGHT_REQUEST:
3612 gtk_widget_get_size_request (widget, NULL, &h);
3613 g_value_set_int (value, h);
3617 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3619 case PROP_SENSITIVE:
3620 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3622 case PROP_APP_PAINTABLE:
3623 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3625 case PROP_CAN_FOCUS:
3626 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3628 case PROP_HAS_FOCUS:
3629 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3632 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3634 case PROP_CAN_DEFAULT:
3635 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3637 case PROP_HAS_DEFAULT:
3638 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3640 case PROP_RECEIVES_DEFAULT:
3641 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3643 case PROP_COMPOSITE_CHILD:
3644 g_value_set_boolean (value, widget->priv->composite_child);
3647 g_value_set_object (value, gtk_widget_get_style (widget));
3650 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3651 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3653 case PROP_NO_SHOW_ALL:
3654 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3656 case PROP_HAS_TOOLTIP:
3657 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3659 case PROP_TOOLTIP_TEXT:
3661 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3664 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3665 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3667 g_value_take_string (value, text);
3670 case PROP_TOOLTIP_MARKUP:
3671 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3674 g_value_set_object (value, gtk_widget_get_window (widget));
3676 case PROP_DOUBLE_BUFFERED:
3677 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3680 g_value_set_enum (value, gtk_widget_get_halign (widget));
3683 g_value_set_enum (value, gtk_widget_get_valign (widget));
3685 case PROP_MARGIN_LEFT:
3686 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3688 case PROP_MARGIN_RIGHT:
3689 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3691 case PROP_MARGIN_TOP:
3692 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3694 case PROP_MARGIN_BOTTOM:
3695 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3699 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3700 if (aux_info == NULL)
3702 g_value_set_int (value, 0);
3706 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3707 aux_info->margin.right),
3708 MAX (aux_info->margin.top,
3709 aux_info->margin.bottom)));
3714 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3716 case PROP_HEXPAND_SET:
3717 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3720 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3722 case PROP_VEXPAND_SET:
3723 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3726 g_value_set_boolean (value,
3727 gtk_widget_get_hexpand (widget) &&
3728 gtk_widget_get_vexpand (widget));
3731 g_value_set_double (value, gtk_widget_get_opacity (widget));
3734 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3740 gtk_widget_init (GtkWidget *widget)
3742 GtkWidgetPrivate *priv;
3744 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3747 priv = widget->priv;
3749 priv->child_visible = TRUE;
3751 priv->allocation.x = -1;
3752 priv->allocation.y = -1;
3753 priv->allocation.width = 1;
3754 priv->allocation.height = 1;
3755 priv->user_alpha = 255;
3757 priv->window = NULL;
3758 priv->parent = NULL;
3760 priv->sensitive = TRUE;
3761 priv->composite_child = composite_child_stack != 0;
3762 priv->double_buffered = TRUE;
3763 priv->redraw_on_alloc = TRUE;
3764 priv->alloc_needed = TRUE;
3766 switch (gtk_widget_get_direction (widget))
3768 case GTK_TEXT_DIR_LTR:
3769 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3772 case GTK_TEXT_DIR_RTL:
3773 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3776 case GTK_TEXT_DIR_NONE:
3778 g_assert_not_reached ();
3783 /* this will be set to TRUE if the widget gets a child or if the
3784 * expand flag is set on the widget, but until one of those happen
3785 * we know the expand is already properly FALSE.
3787 * We really want to default FALSE here to avoid computing expand
3788 * all over the place while initially building a widget tree.
3790 priv->need_compute_expand = FALSE;
3792 _gtk_size_request_cache_init (&priv->requests);
3794 priv->style = gtk_widget_get_default_style ();
3795 g_object_ref (priv->style);
3800 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3802 GParamSpec **pspecs)
3804 GtkWidgetPrivate *priv = widget->priv;
3805 GtkWidget *container = priv->parent;
3808 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3809 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3813 * gtk_widget_freeze_child_notify:
3814 * @widget: a #GtkWidget
3816 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3817 * signals are queued until gtk_widget_thaw_child_notify() is called
3820 * This is the analogue of g_object_freeze_notify() for child properties.
3823 gtk_widget_freeze_child_notify (GtkWidget *widget)
3825 g_return_if_fail (GTK_IS_WIDGET (widget));
3827 if (!G_OBJECT (widget)->ref_count)
3830 g_object_ref (widget);
3831 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3832 g_object_unref (widget);
3836 * gtk_widget_child_notify:
3837 * @widget: a #GtkWidget
3838 * @child_property: the name of a child property installed on the
3839 * class of @widget<!-- -->'s parent
3841 * Emits a #GtkWidget::child-notify signal for the
3842 * <link linkend="child-properties">child property</link> @child_property
3845 * This is the analogue of g_object_notify() for child properties.
3847 * Also see gtk_container_child_notify().
3850 gtk_widget_child_notify (GtkWidget *widget,
3851 const gchar *child_property)
3853 if (widget->priv->parent == NULL)
3856 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3860 * gtk_widget_thaw_child_notify:
3861 * @widget: a #GtkWidget
3863 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3864 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3868 gtk_widget_thaw_child_notify (GtkWidget *widget)
3870 GObjectNotifyQueue *nqueue;
3872 g_return_if_fail (GTK_IS_WIDGET (widget));
3874 if (!G_OBJECT (widget)->ref_count)
3877 g_object_ref (widget);
3878 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3879 if (!nqueue || !nqueue->freeze_count)
3880 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3881 G_OBJECT_TYPE_NAME (widget), widget);
3883 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3884 g_object_unref (widget);
3890 * @type: type ID of the widget to create
3891 * @first_property_name: name of first property to set
3892 * @...: value of first property, followed by more properties,
3895 * This is a convenience function for creating a widget and setting
3896 * its properties in one go. For example you might write:
3897 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3898 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3899 * g_object_new(), but returns a widget so you don't have to
3900 * cast the object yourself.
3902 * Return value: a new #GtkWidget of type @widget_type
3905 gtk_widget_new (GType type,
3906 const gchar *first_property_name,
3912 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3914 va_start (var_args, first_property_name);
3915 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3922 gtk_widget_queue_draw_child (GtkWidget *widget)
3924 GtkWidgetPrivate *priv = widget->priv;
3927 parent = priv->parent;
3928 if (parent && gtk_widget_is_drawable (parent))
3929 gtk_widget_queue_draw_area (parent,
3932 priv->allocation.width,
3933 priv->allocation.height);
3937 * gtk_widget_unparent:
3938 * @widget: a #GtkWidget
3940 * This function is only for use in widget implementations.
3941 * Should be called by implementations of the remove method
3942 * on #GtkContainer, to dissociate a child from the container.
3945 gtk_widget_unparent (GtkWidget *widget)
3947 GtkWidgetPrivate *priv;
3948 GObjectNotifyQueue *nqueue;
3949 GtkWidget *toplevel;
3950 GtkWidget *old_parent;
3952 g_return_if_fail (GTK_IS_WIDGET (widget));
3954 priv = widget->priv;
3956 if (priv->parent == NULL)
3959 /* keep this function in sync with gtk_menu_detach() */
3961 gtk_widget_push_verify_invariants (widget);
3963 g_object_freeze_notify (G_OBJECT (widget));
3964 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3966 toplevel = gtk_widget_get_toplevel (widget);
3967 if (gtk_widget_is_toplevel (toplevel))
3968 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3970 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3971 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3973 gtk_widget_queue_draw_child (widget);
3975 /* Reset the width and height here, to force reallocation if we
3976 * get added back to a new parent. This won't work if our new
3977 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3978 * (would 0x0 be OK here?)
3980 priv->allocation.width = 1;
3981 priv->allocation.height = 1;
3983 if (gtk_widget_get_realized (widget))
3985 if (priv->in_reparent)
3986 gtk_widget_unmap (widget);
3988 gtk_widget_unrealize (widget);
3991 /* If we are unanchoring the child, we save around the toplevel
3992 * to emit hierarchy changed
3994 if (priv->parent->priv->anchored)
3995 g_object_ref (toplevel);
3999 /* Removing a widget from a container restores the child visible
4000 * flag to the default state, so it doesn't affect the child
4001 * in the next parent.
4003 priv->child_visible = TRUE;
4005 old_parent = priv->parent;
4006 priv->parent = NULL;
4008 /* parent may no longer expand if the removed
4009 * child was expand=TRUE and could therefore
4012 if (gtk_widget_get_visible (widget) &&
4013 (priv->need_compute_expand ||
4014 priv->computed_hexpand ||
4015 priv->computed_vexpand))
4017 gtk_widget_queue_compute_expand (old_parent);
4020 /* Unset BACKDROP since we are no longer inside a toplevel window */
4021 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4023 gtk_style_context_set_parent (priv->context, NULL);
4025 _gtk_widget_update_parent_muxer (widget);
4027 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4030 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4031 g_object_unref (toplevel);
4034 /* Now that the parent pointer is nullified and the hierarchy-changed
4035 * already passed, go ahead and unset the parent window, if we are unparenting
4036 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4037 * will fire again for the new subhierarchy.
4039 gtk_widget_set_parent_window (widget, NULL);
4041 g_object_notify (G_OBJECT (widget), "parent");
4042 g_object_thaw_notify (G_OBJECT (widget));
4044 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4045 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4047 gtk_widget_propagate_alpha (widget);
4049 gtk_widget_pop_verify_invariants (widget);
4050 g_object_unref (widget);
4054 * gtk_widget_destroy:
4055 * @widget: a #GtkWidget
4057 * Destroys a widget.
4060 * destroyed, it will break any references it holds to other objects.
4061 * If the widget is inside a container, the widget will be removed
4062 * from the container. If the widget is a toplevel (derived from
4063 * #GtkWindow), it will be removed from the list of toplevels, and the
4064 * reference GTK+ holds to it will be removed. Removing a
4065 * widget from its container or the list of toplevels results in the
4066 * widget being finalized, unless you've added additional references
4067 * to the widget with g_object_ref().
4069 * In most cases, only toplevel widgets (windows) require explicit
4070 * destruction, because when you destroy a toplevel its children will
4071 * be destroyed as well.
4074 gtk_widget_destroy (GtkWidget *widget)
4076 g_return_if_fail (GTK_IS_WIDGET (widget));
4078 if (!widget->priv->in_destruction)
4079 g_object_run_dispose (G_OBJECT (widget));
4083 * gtk_widget_destroyed:
4084 * @widget: a #GtkWidget
4085 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4087 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4088 * %NULL. It's intended to be used as a callback connected to the
4089 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4090 * as a signal handler, and pass the address of your widget variable
4091 * as user data. Then when the widget is destroyed, the variable will
4092 * be set to %NULL. Useful for example to avoid multiple copies
4093 * of the same dialog.
4096 gtk_widget_destroyed (GtkWidget *widget,
4097 GtkWidget **widget_pointer)
4099 /* Don't make any assumptions about the
4101 * Even check widget_pointer.
4104 *widget_pointer = NULL;
4109 * @widget: a #GtkWidget
4111 * Flags a widget to be displayed. Any widget that isn't shown will
4112 * not appear on the screen. If you want to show all the widgets in a
4113 * container, it's easier to call gtk_widget_show_all() on the
4114 * container, instead of individually showing the widgets.
4116 * Remember that you have to show the containers containing a widget,
4117 * in addition to the widget itself, before it will appear onscreen.
4119 * When a toplevel container is shown, it is immediately realized and
4120 * mapped; other shown widgets are realized and mapped when their
4121 * toplevel container is realized and mapped.
4124 gtk_widget_show (GtkWidget *widget)
4126 g_return_if_fail (GTK_IS_WIDGET (widget));
4128 if (!gtk_widget_get_visible (widget))
4130 g_object_ref (widget);
4131 gtk_widget_push_verify_invariants (widget);
4133 if (!gtk_widget_is_toplevel (widget))
4134 gtk_widget_queue_resize (widget);
4136 /* see comment in set_parent() for why this should and can be
4139 if (widget->priv->need_compute_expand ||
4140 widget->priv->computed_hexpand ||
4141 widget->priv->computed_vexpand)
4143 if (widget->priv->parent != NULL)
4144 gtk_widget_queue_compute_expand (widget->priv->parent);
4147 g_signal_emit (widget, widget_signals[SHOW], 0);
4148 g_object_notify (G_OBJECT (widget), "visible");
4150 gtk_widget_pop_verify_invariants (widget);
4151 g_object_unref (widget);
4156 gtk_widget_real_show (GtkWidget *widget)
4158 GtkWidgetPrivate *priv = widget->priv;
4160 if (!gtk_widget_get_visible (widget))
4162 priv->visible = TRUE;
4165 gtk_widget_get_mapped (priv->parent) &&
4166 gtk_widget_get_child_visible (widget) &&
4167 !gtk_widget_get_mapped (widget))
4168 gtk_widget_map (widget);
4173 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4176 g_signal_handlers_disconnect_by_func (widget,
4177 gtk_widget_show_map_callback,
4182 * gtk_widget_show_now:
4183 * @widget: a #GtkWidget
4185 * Shows a widget. If the widget is an unmapped toplevel widget
4186 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4187 * loop and wait for the window to actually be mapped. Be careful;
4188 * because the main loop is running, anything can happen during
4192 gtk_widget_show_now (GtkWidget *widget)
4196 g_return_if_fail (GTK_IS_WIDGET (widget));
4198 /* make sure we will get event */
4199 if (!gtk_widget_get_mapped (widget) &&
4200 gtk_widget_is_toplevel (widget))
4202 gtk_widget_show (widget);
4204 g_signal_connect (widget, "map-event",
4205 G_CALLBACK (gtk_widget_show_map_callback),
4209 gtk_main_iteration ();
4212 gtk_widget_show (widget);
4217 * @widget: a #GtkWidget
4219 * Reverses the effects of gtk_widget_show(), causing the widget to be
4220 * hidden (invisible to the user).
4223 gtk_widget_hide (GtkWidget *widget)
4225 g_return_if_fail (GTK_IS_WIDGET (widget));
4227 if (gtk_widget_get_visible (widget))
4229 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4231 g_object_ref (widget);
4232 gtk_widget_push_verify_invariants (widget);
4234 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4235 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4237 /* a parent may now be expand=FALSE since we're hidden. */
4238 if (widget->priv->need_compute_expand ||
4239 widget->priv->computed_hexpand ||
4240 widget->priv->computed_vexpand)
4242 gtk_widget_queue_compute_expand (widget);
4245 g_signal_emit (widget, widget_signals[HIDE], 0);
4246 if (!gtk_widget_is_toplevel (widget))
4247 gtk_widget_queue_resize (widget);
4248 g_object_notify (G_OBJECT (widget), "visible");
4250 gtk_widget_pop_verify_invariants (widget);
4251 g_object_unref (widget);
4256 gtk_widget_real_hide (GtkWidget *widget)
4258 if (gtk_widget_get_visible (widget))
4260 widget->priv->visible = FALSE;
4262 if (gtk_widget_get_mapped (widget))
4263 gtk_widget_unmap (widget);
4268 * gtk_widget_hide_on_delete:
4269 * @widget: a #GtkWidget
4271 * Utility function; intended to be connected to the #GtkWidget::delete-event
4272 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4273 * argument, then returns %TRUE. If connected to ::delete-event, the
4274 * result is that clicking the close button for a window (on the
4275 * window frame, top right corner usually) will hide but not destroy
4276 * the window. By default, GTK+ destroys windows when ::delete-event
4279 * Return value: %TRUE
4282 gtk_widget_hide_on_delete (GtkWidget *widget)
4284 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4286 gtk_widget_hide (widget);
4292 * gtk_widget_show_all:
4293 * @widget: a #GtkWidget
4295 * Recursively shows a widget, and any child widgets (if the widget is
4299 gtk_widget_show_all (GtkWidget *widget)
4301 GtkWidgetClass *class;
4303 g_return_if_fail (GTK_IS_WIDGET (widget));
4305 if (gtk_widget_get_no_show_all (widget))
4308 class = GTK_WIDGET_GET_CLASS (widget);
4310 if (class->show_all)
4311 class->show_all (widget);
4316 * @widget: a #GtkWidget
4318 * This function is only for use in widget implementations. Causes
4319 * a widget to be mapped if it isn't already.
4322 gtk_widget_map (GtkWidget *widget)
4324 GtkWidgetPrivate *priv;
4326 g_return_if_fail (GTK_IS_WIDGET (widget));
4327 g_return_if_fail (gtk_widget_get_visible (widget));
4328 g_return_if_fail (gtk_widget_get_child_visible (widget));
4330 priv = widget->priv;
4332 if (!gtk_widget_get_mapped (widget))
4334 gtk_widget_push_verify_invariants (widget);
4336 if (!gtk_widget_get_realized (widget))
4337 gtk_widget_realize (widget);
4339 g_signal_emit (widget, widget_signals[MAP], 0);
4341 if (!gtk_widget_get_has_window (widget))
4342 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4344 if (widget->priv->context)
4345 _gtk_style_context_update_animating (widget->priv->context);
4347 gtk_widget_pop_verify_invariants (widget);
4353 * @widget: a #GtkWidget
4355 * This function is only for use in widget implementations. Causes
4356 * a widget to be unmapped if it's currently mapped.
4359 gtk_widget_unmap (GtkWidget *widget)
4361 GtkWidgetPrivate *priv;
4363 g_return_if_fail (GTK_IS_WIDGET (widget));
4365 priv = widget->priv;
4367 if (gtk_widget_get_mapped (widget))
4369 gtk_widget_push_verify_invariants (widget);
4371 if (!gtk_widget_get_has_window (widget))
4372 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4373 _gtk_tooltip_hide (widget);
4375 if (widget->priv->context)
4376 _gtk_style_context_update_animating (widget->priv->context);
4378 g_signal_emit (widget, widget_signals[UNMAP], 0);
4380 gtk_widget_pop_verify_invariants (widget);
4382 /* Unset pointer/window info */
4383 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4388 _gtk_widget_enable_device_events (GtkWidget *widget)
4390 GHashTable *device_events;
4391 GHashTableIter iter;
4392 gpointer key, value;
4394 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4399 g_hash_table_iter_init (&iter, device_events);
4401 while (g_hash_table_iter_next (&iter, &key, &value))
4404 GdkEventMask event_mask;
4407 event_mask = GPOINTER_TO_UINT (value);
4408 gtk_widget_add_events_internal (widget, device, event_mask);
4413 get_widget_windows (GtkWidget *widget)
4415 GList *window_list, *last, *l, *children, *ret;
4417 if (gtk_widget_get_has_window (widget))
4418 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4420 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4422 last = g_list_last (window_list);
4425 for (l = window_list; l; l = l->next)
4427 GtkWidget *window_widget = NULL;
4429 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4431 if (widget != window_widget)
4434 ret = g_list_prepend (ret, l->data);
4435 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4439 last = g_list_concat (last, children);
4440 last = g_list_last (last);
4444 g_list_free (window_list);
4450 device_enable_foreach (GtkWidget *widget,
4453 GdkDevice *device = user_data;
4454 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4458 device_disable_foreach (GtkWidget *widget,
4461 GdkDevice *device = user_data;
4462 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4466 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4471 GList *window_list, *l;
4473 window_list = get_widget_windows (widget);
4475 for (l = window_list; l; l = l->next)
4477 GdkEventMask events = 0;
4483 events = gdk_window_get_events (window);
4485 gdk_window_set_device_events (window, device, events);
4488 if (recurse && GTK_IS_CONTAINER (widget))
4491 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4493 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4496 g_list_free (window_list);
4500 gtk_widget_update_devices_mask (GtkWidget *widget,
4503 GList *enabled_devices, *l;
4505 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4507 for (l = enabled_devices; l; l = l->next)
4508 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4512 * gtk_widget_realize:
4513 * @widget: a #GtkWidget
4515 * Creates the GDK (windowing system) resources associated with a
4516 * widget. For example, @widget->window will be created when a widget
4517 * is realized. Normally realization happens implicitly; if you show
4518 * a widget and all its parent containers, then the widget will be
4519 * realized and mapped automatically.
4521 * Realizing a widget requires all
4522 * the widget's parent widgets to be realized; calling
4523 * gtk_widget_realize() realizes the widget's parents in addition to
4524 * @widget itself. If a widget is not yet inside a toplevel window
4525 * when you realize it, bad things will happen.
4527 * This function is primarily used in widget implementations, and
4528 * isn't very useful otherwise. Many times when you think you might
4529 * need it, a better approach is to connect to a signal that will be
4530 * called after the widget is realized automatically, such as
4531 * #GtkWidget::draw. Or simply g_signal_connect () to the
4532 * #GtkWidget::realize signal.
4535 gtk_widget_realize (GtkWidget *widget)
4537 GtkWidgetPrivate *priv;
4538 cairo_region_t *region;
4541 g_return_if_fail (GTK_IS_WIDGET (widget));
4542 g_return_if_fail (widget->priv->anchored ||
4543 GTK_IS_INVISIBLE (widget));
4545 priv = widget->priv;
4547 if (!gtk_widget_get_realized (widget))
4549 gtk_widget_push_verify_invariants (widget);
4552 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4553 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4556 if (priv->parent == NULL &&
4557 !gtk_widget_is_toplevel (widget))
4558 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4559 "inside a toplevel window is not going to work very well. "
4560 "Widgets must be inside a toplevel container before realizing them.");
4562 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4563 gtk_widget_realize (priv->parent);
4565 gtk_widget_ensure_style (widget);
4567 if (priv->style_update_pending)
4568 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4570 g_signal_emit (widget, widget_signals[REALIZE], 0);
4572 gtk_widget_real_set_has_tooltip (widget,
4573 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4576 if (priv->has_shape_mask)
4578 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4579 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4582 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4584 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4586 if (priv->multidevice)
4587 gdk_window_set_support_multidevice (priv->window, TRUE);
4589 _gtk_widget_enable_device_events (widget);
4590 gtk_widget_update_devices_mask (widget, TRUE);
4592 if (GTK_IS_CONTAINER (widget))
4593 _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
4595 for (tmp_list = priv->frame_clock_targets; tmp_list; tmp_list = tmp_list->next)
4597 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4598 gdk_frame_clock_target_set_clock (tmp_list->data, frame_clock);
4601 gtk_widget_pop_verify_invariants (widget);
4606 * gtk_widget_unrealize:
4607 * @widget: a #GtkWidget
4609 * This function is only useful in widget implementations.
4610 * Causes a widget to be unrealized (frees all GDK resources
4611 * associated with the widget, such as @widget->window).
4614 gtk_widget_unrealize (GtkWidget *widget)
4616 g_return_if_fail (GTK_IS_WIDGET (widget));
4618 gtk_widget_push_verify_invariants (widget);
4620 if (widget->priv->has_shape_mask)
4621 gtk_widget_shape_combine_region (widget, NULL);
4623 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4624 gtk_widget_input_shape_combine_region (widget, NULL);
4626 if (gtk_widget_get_realized (widget))
4628 g_object_ref (widget);
4630 if (widget->priv->mapped)
4631 gtk_widget_unmap (widget);
4633 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4634 g_assert (!widget->priv->mapped);
4635 gtk_widget_set_realized (widget, FALSE);
4637 g_object_unref (widget);
4640 gtk_widget_pop_verify_invariants (widget);
4643 /*****************************************
4645 *****************************************/
4648 * gtk_widget_queue_draw_region:
4649 * @widget: a #GtkWidget
4650 * @region: region to draw
4652 * Invalidates the rectangular area of @widget defined by @region by
4653 * calling gdk_window_invalidate_region() on the widget's window and
4654 * all its child windows. Once the main loop becomes idle (after the
4655 * current batch of events has been processed, roughly), the window
4656 * will receive expose events for the union of all regions that have
4659 * Normally you would only use this function in widget
4660 * implementations. You might also use it to schedule a redraw of a
4661 * #GtkDrawingArea or some portion thereof.
4666 gtk_widget_queue_draw_region (GtkWidget *widget,
4667 const cairo_region_t *region)
4669 GtkWidgetPrivate *priv;
4672 g_return_if_fail (GTK_IS_WIDGET (widget));
4674 priv = widget->priv;
4676 if (!gtk_widget_get_realized (widget))
4679 /* Just return if the widget or one of its ancestors isn't mapped */
4680 for (w = widget; w != NULL; w = w->priv->parent)
4681 if (!gtk_widget_get_mapped (w))
4684 gdk_window_invalidate_region (priv->window, region, TRUE);
4688 * gtk_widget_queue_draw_area:
4689 * @widget: a #GtkWidget
4690 * @x: x coordinate of upper-left corner of rectangle to redraw
4691 * @y: y coordinate of upper-left corner of rectangle to redraw
4692 * @width: width of region to draw
4693 * @height: height of region to draw
4695 * Convenience function that calls gtk_widget_queue_draw_region() on
4696 * the region created from the given coordinates.
4698 * The region here is specified in widget coordinates.
4699 * Widget coordinates are a bit odd; for historical reasons, they are
4700 * defined as @widget->window coordinates for widgets that are not
4701 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4702 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4705 gtk_widget_queue_draw_area (GtkWidget *widget,
4712 cairo_region_t *region;
4714 g_return_if_fail (GTK_IS_WIDGET (widget));
4719 rect.height = height;
4721 region = cairo_region_create_rectangle (&rect);
4722 gtk_widget_queue_draw_region (widget, region);
4723 cairo_region_destroy (region);
4727 * gtk_widget_queue_draw:
4728 * @widget: a #GtkWidget
4730 * Equivalent to calling gtk_widget_queue_draw_area() for the
4731 * entire area of a widget.
4734 gtk_widget_queue_draw (GtkWidget *widget)
4738 g_return_if_fail (GTK_IS_WIDGET (widget));
4740 gtk_widget_get_allocation (widget, &rect);
4742 if (!gtk_widget_get_has_window (widget))
4743 gtk_widget_queue_draw_area (widget,
4744 rect.x, rect.y, rect.width, rect.height);
4746 gtk_widget_queue_draw_area (widget,
4747 0, 0, rect.width, rect.height);
4751 * gtk_widget_queue_resize:
4752 * @widget: a #GtkWidget
4754 * This function is only for use in widget implementations.
4755 * Flags a widget to have its size renegotiated; should
4756 * be called when a widget for some reason has a new size request.
4757 * For example, when you change the text in a #GtkLabel, #GtkLabel
4758 * queues a resize to ensure there's enough space for the new text.
4760 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4761 * from inside its implementation of the GtkWidgetClass::size_allocate
4762 * virtual method. Calls to gtk_widget_queue_resize() from inside
4763 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4766 gtk_widget_queue_resize (GtkWidget *widget)
4768 g_return_if_fail (GTK_IS_WIDGET (widget));
4770 if (gtk_widget_get_realized (widget))
4771 gtk_widget_queue_draw (widget);
4773 _gtk_size_group_queue_resize (widget, 0);
4777 * gtk_widget_queue_resize_no_redraw:
4778 * @widget: a #GtkWidget
4780 * This function works like gtk_widget_queue_resize(),
4781 * except that the widget is not invalidated.
4786 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4788 g_return_if_fail (GTK_IS_WIDGET (widget));
4790 _gtk_size_group_queue_resize (widget, 0);
4794 * gtk_widget_get_frame_clock:
4795 * @widget: a #GtkWidget
4797 * Obtains the frame clock for a widget. The frame clock is a global
4798 * "ticker" that can be used to drive animations and repaints. The
4799 * most common reason to get the frame clock is to call
4800 * gdk_frame_clock_get_frame_time(), in order to get a time to use for
4801 * animating. For example you might record the start of the animation
4802 * with an initial value from gdk_frame_clock_get_frame_time(), and
4803 * then update the animation by calling
4804 * gdk_frame_clock_get_frame_time() again during each repaint.
4806 * gdk_frame_clock_request_phase() will result in a new frame on the
4807 * clock, but won't necessarily repaint any widgets. To repaint a
4808 * widget, you have to use gtk_widget_queue_draw() which invalidates
4809 * the widget (thus scheduling it to receive a draw on the next
4810 * frame). gtk_widget_queue_draw() will also end up requesting a frame
4811 * on the appropriate frame clock.
4813 * A widget's frame clock will not change while the widget is
4814 * mapped. Reparenting a widget (which implies a temporary unmap) can
4815 * change the widget's frame clock.
4817 * Unrealized widgets do not have a frame clock.
4820 * Return value: a #GdkFrameClock (or #NULL if widget is unrealized)
4823 gtk_widget_get_frame_clock (GtkWidget *widget)
4825 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4827 if (widget->priv->realized)
4831 window = gtk_widget_get_window (widget);
4832 g_assert (window != NULL);
4833 return gdk_window_get_frame_clock (window);
4842 * gtk_widget_size_request:
4843 * @widget: a #GtkWidget
4844 * @requisition: (out): a #GtkRequisition to be filled in
4846 * This function is typically used when implementing a #GtkContainer
4847 * subclass. Obtains the preferred size of a widget. The container
4848 * uses this information to arrange its child widgets and decide what
4849 * size allocations to give them with gtk_widget_size_allocate().
4851 * You can also call this function from an application, with some
4852 * caveats. Most notably, getting a size request requires the widget
4853 * to be associated with a screen, because font information may be
4854 * needed. Multihead-aware applications should keep this in mind.
4856 * Also remember that the size request is not necessarily the size
4857 * a widget will actually be allocated.
4859 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4862 gtk_widget_size_request (GtkWidget *widget,
4863 GtkRequisition *requisition)
4865 g_return_if_fail (GTK_IS_WIDGET (widget));
4867 gtk_widget_get_preferred_size (widget, requisition, NULL);
4871 * gtk_widget_get_child_requisition:
4872 * @widget: a #GtkWidget
4873 * @requisition: (out): a #GtkRequisition to be filled in
4875 * This function is only for use in widget implementations. Obtains
4876 * @widget->requisition, unless someone has forced a particular
4877 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4878 * in which case it returns that geometry instead of the widget's
4881 * This function differs from gtk_widget_size_request() in that
4882 * it retrieves the last size request value from @widget->requisition,
4883 * while gtk_widget_size_request() actually calls the "size_request" method
4884 * on @widget to compute the size request and fill in @widget->requisition,
4885 * and only then returns @widget->requisition.
4887 * Because this function does not call the "size_request" method, it
4888 * can only be used when you know that @widget->requisition is
4889 * up-to-date, that is, gtk_widget_size_request() has been called
4890 * since the last time a resize was queued. In general, only container
4891 * implementations have this information; applications should use
4892 * gtk_widget_size_request().
4895 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4898 gtk_widget_get_child_requisition (GtkWidget *widget,
4899 GtkRequisition *requisition)
4901 gtk_widget_get_preferred_size (widget, requisition, NULL);
4905 invalidate_predicate (GdkWindow *window,
4910 gdk_window_get_user_data (window, &user_data);
4912 return (user_data == data);
4915 /* Invalidate @region in widget->window and all children
4916 * of widget->window owned by widget. @region is in the
4917 * same coordinates as widget->allocation and will be
4918 * modified by this call.
4921 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4922 cairo_region_t *region)
4924 GtkWidgetPrivate *priv = widget->priv;
4926 if (!gtk_widget_get_realized (widget))
4929 if (gtk_widget_get_has_window (widget) && priv->parent)
4933 gdk_window_get_position (priv->window, &x, &y);
4934 cairo_region_translate (region, -x, -y);
4937 gdk_window_invalidate_maybe_recurse (priv->window, region,
4938 invalidate_predicate, widget);
4942 * gtk_widget_size_allocate:
4943 * @widget: a #GtkWidget
4944 * @allocation: position and size to be allocated to @widget
4946 * This function is only used by #GtkContainer subclasses, to assign a size
4947 * and position to their child widgets.
4949 * In this function, the allocation may be adjusted. It will be forced
4950 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4951 * method on the child will be used to adjust the allocation. Standard
4952 * adjustments include removing the widget's margins, and applying the
4953 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4956 gtk_widget_size_allocate (GtkWidget *widget,
4957 GtkAllocation *allocation)
4959 GtkWidgetPrivate *priv;
4960 GdkRectangle real_allocation;
4961 GdkRectangle old_allocation;
4962 GdkRectangle adjusted_allocation;
4963 gboolean alloc_needed;
4964 gboolean size_changed;
4965 gboolean position_changed;
4966 gint natural_width, natural_height, dummy;
4967 gint min_width, min_height;
4969 priv = widget->priv;
4971 g_return_if_fail (GTK_IS_WIDGET (widget));
4973 if (!priv->visible && !gtk_widget_is_toplevel (widget))
4976 gtk_widget_push_verify_invariants (widget);
4978 #ifdef G_ENABLE_DEBUG
4979 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4990 parent = gtk_widget_get_parent (parent);
4993 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4994 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4995 2 * depth, " ", name,
4996 allocation->width, allocation->height);
4998 #endif /* G_ENABLE_DEBUG */
5000 alloc_needed = priv->alloc_needed;
5001 /* Preserve request/allocate ordering */
5002 priv->alloc_needed = FALSE;
5004 old_allocation = priv->allocation;
5005 real_allocation = *allocation;
5007 adjusted_allocation = real_allocation;
5008 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
5010 /* Go ahead and request the height for allocated width, note that the internals
5011 * of get_height_for_width will internally limit the for_size to natural size
5012 * when aligning implicitly.
5014 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
5015 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
5019 /* Go ahead and request the width for allocated height, note that the internals
5020 * of get_width_for_height will internally limit the for_size to natural size
5021 * when aligning implicitly.
5023 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
5024 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
5027 #ifdef G_ENABLE_DEBUG
5028 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5030 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
5031 !GTK_IS_SCROLLABLE (widget))
5032 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
5033 "Allocation is %dx%d, but minimum required size is %dx%d.",
5034 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
5035 G_OBJECT_TYPE_NAME (widget), widget,
5036 real_allocation.width, real_allocation.height,
5037 min_width, min_height);
5040 /* Now that we have the right natural height and width, go ahead and remove any margins from the
5041 * allocated sizes and possibly limit them to the natural sizes */
5042 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5043 GTK_ORIENTATION_HORIZONTAL,
5046 &adjusted_allocation.x,
5047 &adjusted_allocation.width);
5048 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5049 GTK_ORIENTATION_VERTICAL,
5052 &adjusted_allocation.y,
5053 &adjusted_allocation.height);
5055 if (adjusted_allocation.x < real_allocation.x ||
5056 adjusted_allocation.y < real_allocation.y ||
5057 (adjusted_allocation.x + adjusted_allocation.width) >
5058 (real_allocation.x + real_allocation.width) ||
5059 (adjusted_allocation.y + adjusted_allocation.height >
5060 real_allocation.y + real_allocation.height))
5062 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",
5063 G_OBJECT_TYPE_NAME (widget), widget,
5064 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5065 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5066 adjusted_allocation = real_allocation; /* veto it */
5070 real_allocation = adjusted_allocation;
5073 if (real_allocation.width < 0 || real_allocation.height < 0)
5075 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5076 real_allocation.width,
5077 real_allocation.height);
5080 real_allocation.width = MAX (real_allocation.width, 1);
5081 real_allocation.height = MAX (real_allocation.height, 1);
5083 size_changed = (old_allocation.width != real_allocation.width ||
5084 old_allocation.height != real_allocation.height);
5085 position_changed = (old_allocation.x != real_allocation.x ||
5086 old_allocation.y != real_allocation.y);
5088 if (!alloc_needed && !size_changed && !position_changed)
5091 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5093 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5094 priv->alloc_needed = FALSE;
5096 if (gtk_widget_get_mapped (widget))
5098 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5100 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5102 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5103 cairo_region_union_rectangle (invalidate, &old_allocation);
5105 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5106 cairo_region_destroy (invalidate);
5111 if (priv->redraw_on_alloc)
5113 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5115 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5116 cairo_region_union_rectangle (invalidate, &old_allocation);
5118 gtk_widget_invalidate_widget_windows (widget, invalidate);
5119 cairo_region_destroy (invalidate);
5124 if ((size_changed || position_changed) && priv->parent &&
5125 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5127 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5128 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5129 cairo_region_destroy (invalidate);
5133 gtk_widget_pop_verify_invariants (widget);
5137 * gtk_widget_common_ancestor:
5138 * @widget_a: a #GtkWidget
5139 * @widget_b: a #GtkWidget
5141 * Find the common ancestor of @widget_a and @widget_b that
5142 * is closest to the two widgets.
5144 * Return value: the closest common ancestor of @widget_a and
5145 * @widget_b or %NULL if @widget_a and @widget_b do not
5146 * share a common ancestor.
5149 gtk_widget_common_ancestor (GtkWidget *widget_a,
5150 GtkWidget *widget_b)
5152 GtkWidget *parent_a;
5153 GtkWidget *parent_b;
5157 parent_a = widget_a;
5158 while (parent_a->priv->parent)
5160 parent_a = parent_a->priv->parent;
5164 parent_b = widget_b;
5165 while (parent_b->priv->parent)
5167 parent_b = parent_b->priv->parent;
5171 if (parent_a != parent_b)
5174 while (depth_a > depth_b)
5176 widget_a = widget_a->priv->parent;
5180 while (depth_b > depth_a)
5182 widget_b = widget_b->priv->parent;
5186 while (widget_a != widget_b)
5188 widget_a = widget_a->priv->parent;
5189 widget_b = widget_b->priv->parent;
5196 * gtk_widget_translate_coordinates:
5197 * @src_widget: a #GtkWidget
5198 * @dest_widget: a #GtkWidget
5199 * @src_x: X position relative to @src_widget
5200 * @src_y: Y position relative to @src_widget
5201 * @dest_x: (out): location to store X position relative to @dest_widget
5202 * @dest_y: (out): location to store Y position relative to @dest_widget
5204 * Translate coordinates relative to @src_widget's allocation to coordinates
5205 * relative to @dest_widget's allocations. In order to perform this
5206 * operation, both widgets must be realized, and must share a common
5209 * Return value: %FALSE if either widget was not realized, or there
5210 * was no common ancestor. In this case, nothing is stored in
5211 * *@dest_x and *@dest_y. Otherwise %TRUE.
5214 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5215 GtkWidget *dest_widget,
5221 GtkWidgetPrivate *src_priv = src_widget->priv;
5222 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5223 GtkWidget *ancestor;
5225 GList *dest_list = NULL;
5227 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5228 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5230 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5231 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5234 /* Translate from allocation relative to window relative */
5235 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5238 gdk_window_get_position (src_priv->window, &wx, &wy);
5240 src_x -= wx - src_priv->allocation.x;
5241 src_y -= wy - src_priv->allocation.y;
5245 src_x += src_priv->allocation.x;
5246 src_y += src_priv->allocation.y;
5249 /* Translate to the common ancestor */
5250 window = src_priv->window;
5251 while (window != ancestor->priv->window)
5255 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5260 window = gdk_window_get_effective_parent (window);
5262 if (!window) /* Handle GtkHandleBox */
5267 window = dest_priv->window;
5268 while (window != ancestor->priv->window)
5270 dest_list = g_list_prepend (dest_list, window);
5272 window = gdk_window_get_effective_parent (window);
5274 if (!window) /* Handle GtkHandleBox */
5276 g_list_free (dest_list);
5285 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5290 dest_list = g_list_remove (dest_list, dest_list->data);
5293 /* Translate from window relative to allocation relative */
5294 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5297 gdk_window_get_position (dest_priv->window, &wx, &wy);
5299 src_x += wx - dest_priv->allocation.x;
5300 src_y += wy - dest_priv->allocation.y;
5304 src_x -= dest_priv->allocation.x;
5305 src_y -= dest_priv->allocation.y;
5317 gtk_widget_real_size_allocate (GtkWidget *widget,
5318 GtkAllocation *allocation)
5320 GtkWidgetPrivate *priv = widget->priv;
5322 priv->allocation = *allocation;
5324 if (gtk_widget_get_realized (widget) &&
5325 gtk_widget_get_has_window (widget))
5327 gdk_window_move_resize (priv->window,
5328 allocation->x, allocation->y,
5329 allocation->width, allocation->height);
5333 /* translate initial/final into start/end */
5335 effective_align (GtkAlign align,
5336 GtkTextDirection direction)
5340 case GTK_ALIGN_START:
5341 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5343 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5350 adjust_for_align (GtkAlign align,
5352 gint *allocated_pos,
5353 gint *allocated_size)
5357 case GTK_ALIGN_FILL:
5358 /* change nothing */
5360 case GTK_ALIGN_START:
5361 /* keep *allocated_pos where it is */
5362 *allocated_size = MIN (*allocated_size, *natural_size);
5365 if (*allocated_size > *natural_size)
5367 *allocated_pos += (*allocated_size - *natural_size);
5368 *allocated_size = *natural_size;
5371 case GTK_ALIGN_CENTER:
5372 if (*allocated_size > *natural_size)
5374 *allocated_pos += (*allocated_size - *natural_size) / 2;
5375 *allocated_size = MIN (*allocated_size, *natural_size);
5382 adjust_for_margin(gint start_margin,
5386 gint *allocated_pos,
5387 gint *allocated_size)
5389 *minimum_size -= (start_margin + end_margin);
5390 *natural_size -= (start_margin + end_margin);
5391 *allocated_pos += start_margin;
5392 *allocated_size -= (start_margin + end_margin);
5396 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5397 GtkOrientation orientation,
5400 gint *allocated_pos,
5401 gint *allocated_size)
5403 const GtkWidgetAuxInfo *aux_info;
5405 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5407 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5409 adjust_for_margin (aux_info->margin.left,
5410 aux_info->margin.right,
5411 minimum_size, natural_size,
5412 allocated_pos, allocated_size);
5413 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5414 natural_size, allocated_pos, allocated_size);
5418 adjust_for_margin (aux_info->margin.top,
5419 aux_info->margin.bottom,
5420 minimum_size, natural_size,
5421 allocated_pos, allocated_size);
5422 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5423 natural_size, allocated_pos, allocated_size);
5428 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5431 GtkWidgetPrivate *priv = widget->priv;
5433 /* widgets must be onscreen for accels to take effect */
5434 return gtk_widget_is_sensitive (widget) &&
5435 gtk_widget_is_drawable (widget) &&
5436 gdk_window_is_viewable (priv->window);
5440 * gtk_widget_can_activate_accel:
5441 * @widget: a #GtkWidget
5442 * @signal_id: the ID of a signal installed on @widget
5444 * Determines whether an accelerator that activates the signal
5445 * identified by @signal_id can currently be activated.
5446 * This is done by emitting the #GtkWidget::can-activate-accel
5447 * signal on @widget; if the signal isn't overridden by a
5448 * handler or in a derived widget, then the default check is
5449 * that the widget must be sensitive, and the widget and all
5450 * its ancestors mapped.
5452 * Return value: %TRUE if the accelerator can be activated.
5457 gtk_widget_can_activate_accel (GtkWidget *widget,
5460 gboolean can_activate = FALSE;
5461 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5462 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5463 return can_activate;
5472 closure_accel_activate (GClosure *closure,
5473 GValue *return_value,
5474 guint n_param_values,
5475 const GValue *param_values,
5476 gpointer invocation_hint,
5477 gpointer marshal_data)
5479 AccelClosure *aclosure = (AccelClosure*) closure;
5480 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5483 g_signal_emit (closure->data, aclosure->signal_id, 0);
5485 /* whether accelerator was handled */
5486 g_value_set_boolean (return_value, can_activate);
5490 closures_destroy (gpointer data)
5492 GSList *slist, *closures = data;
5494 for (slist = closures; slist; slist = slist->next)
5496 g_closure_invalidate (slist->data);
5497 g_closure_unref (slist->data);
5499 g_slist_free (closures);
5503 widget_new_accel_closure (GtkWidget *widget,
5506 AccelClosure *aclosure;
5507 GClosure *closure = NULL;
5508 GSList *slist, *closures;
5510 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5511 for (slist = closures; slist; slist = slist->next)
5512 if (!gtk_accel_group_from_accel_closure (slist->data))
5514 /* reuse this closure */
5515 closure = slist->data;
5520 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5521 closures = g_slist_prepend (closures, g_closure_ref (closure));
5522 g_closure_sink (closure);
5523 g_closure_set_marshal (closure, closure_accel_activate);
5525 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5527 aclosure = (AccelClosure*) closure;
5528 g_assert (closure->data == widget);
5529 g_assert (closure->marshal == closure_accel_activate);
5530 aclosure->signal_id = signal_id;
5536 * gtk_widget_add_accelerator:
5537 * @widget: widget to install an accelerator on
5538 * @accel_signal: widget signal to emit on accelerator activation
5539 * @accel_group: accel group for this widget, added to its toplevel
5540 * @accel_key: GDK keyval of the accelerator
5541 * @accel_mods: modifier key combination of the accelerator
5542 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5544 * Installs an accelerator for this @widget in @accel_group that causes
5545 * @accel_signal to be emitted if the accelerator is activated.
5546 * The @accel_group needs to be added to the widget's toplevel via
5547 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5548 * Accelerators added through this function are not user changeable during
5549 * runtime. If you want to support accelerators that can be changed by the
5550 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5551 * gtk_menu_item_set_accel_path() instead.
5554 gtk_widget_add_accelerator (GtkWidget *widget,
5555 const gchar *accel_signal,
5556 GtkAccelGroup *accel_group,
5558 GdkModifierType accel_mods,
5559 GtkAccelFlags accel_flags)
5564 g_return_if_fail (GTK_IS_WIDGET (widget));
5565 g_return_if_fail (accel_signal != NULL);
5566 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5568 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5569 if (!query.signal_id ||
5570 !(query.signal_flags & G_SIGNAL_ACTION) ||
5571 query.return_type != G_TYPE_NONE ||
5574 /* hmm, should be elaborate enough */
5575 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5576 G_OBJECT_TYPE_NAME (widget), accel_signal);
5580 closure = widget_new_accel_closure (widget, query.signal_id);
5582 g_object_ref (widget);
5584 /* install the accelerator. since we don't map this onto an accel_path,
5585 * the accelerator will automatically be locked.
5587 gtk_accel_group_connect (accel_group,
5590 accel_flags | GTK_ACCEL_LOCKED,
5593 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5595 g_object_unref (widget);
5599 * gtk_widget_remove_accelerator:
5600 * @widget: widget to install an accelerator on
5601 * @accel_group: accel group for this widget
5602 * @accel_key: GDK keyval of the accelerator
5603 * @accel_mods: modifier key combination of the accelerator
5605 * Removes an accelerator from @widget, previously installed with
5606 * gtk_widget_add_accelerator().
5608 * Returns: whether an accelerator was installed and could be removed
5611 gtk_widget_remove_accelerator (GtkWidget *widget,
5612 GtkAccelGroup *accel_group,
5614 GdkModifierType accel_mods)
5616 GtkAccelGroupEntry *ag_entry;
5617 GList *slist, *clist;
5620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5621 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5623 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5624 clist = gtk_widget_list_accel_closures (widget);
5625 for (slist = clist; slist; slist = slist->next)
5629 for (i = 0; i < n; i++)
5630 if (slist->data == (gpointer) ag_entry[i].closure)
5632 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5634 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5636 g_list_free (clist);
5641 g_list_free (clist);
5643 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5644 accel_key, accel_mods, accel_group,
5645 G_OBJECT_TYPE_NAME (widget), widget);
5651 * gtk_widget_list_accel_closures:
5652 * @widget: widget to list accelerator closures for
5654 * Lists the closures used by @widget for accelerator group connections
5655 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5656 * The closures can be used to monitor accelerator changes on @widget,
5657 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5658 * #GtkAccelGroup of a closure which can be found out with
5659 * gtk_accel_group_from_accel_closure().
5661 * Return value: (transfer container) (element-type GClosure):
5662 * a newly allocated #GList of closures
5665 gtk_widget_list_accel_closures (GtkWidget *widget)
5668 GList *clist = NULL;
5670 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5672 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5673 if (gtk_accel_group_from_accel_closure (slist->data))
5674 clist = g_list_prepend (clist, slist->data);
5680 GtkAccelGroup *accel_group;
5685 destroy_accel_path (gpointer data)
5687 AccelPath *apath = data;
5689 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5691 /* closures_destroy takes care of unrefing the closure */
5692 g_object_unref (apath->accel_group);
5694 g_slice_free (AccelPath, apath);
5699 * gtk_widget_set_accel_path:
5700 * @widget: a #GtkWidget
5701 * @accel_path: (allow-none): path used to look up the accelerator
5702 * @accel_group: (allow-none): a #GtkAccelGroup.
5704 * Given an accelerator group, @accel_group, and an accelerator path,
5705 * @accel_path, sets up an accelerator in @accel_group so whenever the
5706 * key binding that is defined for @accel_path is pressed, @widget
5707 * will be activated. This removes any accelerators (for any
5708 * accelerator group) installed by previous calls to
5709 * gtk_widget_set_accel_path(). Associating accelerators with
5710 * paths allows them to be modified by the user and the modifications
5711 * to be saved for future use. (See gtk_accel_map_save().)
5713 * This function is a low level function that would most likely
5714 * be used by a menu creation system like #GtkUIManager. If you
5715 * use #GtkUIManager, setting up accelerator paths will be done
5718 * Even when you you aren't using #GtkUIManager, if you only want to
5719 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5720 * provides a somewhat more convenient interface.
5722 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5723 * pass a static string, you can save some memory by interning it first with
5724 * g_intern_static_string().
5727 gtk_widget_set_accel_path (GtkWidget *widget,
5728 const gchar *accel_path,
5729 GtkAccelGroup *accel_group)
5733 g_return_if_fail (GTK_IS_WIDGET (widget));
5734 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5738 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5739 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5741 gtk_accel_map_add_entry (accel_path, 0, 0);
5742 apath = g_slice_new (AccelPath);
5743 apath->accel_group = g_object_ref (accel_group);
5744 apath->path_quark = g_quark_from_string (accel_path);
5745 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5750 /* also removes possible old settings */
5751 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5754 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5756 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5760 _gtk_widget_get_accel_path (GtkWidget *widget,
5765 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5767 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5769 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5770 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5774 * gtk_widget_mnemonic_activate:
5775 * @widget: a #GtkWidget
5776 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5778 * Emits the #GtkWidget::mnemonic-activate signal.
5780 * The default handler for this signal activates the @widget if
5781 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5784 * Returns: %TRUE if the signal has been handled
5787 gtk_widget_mnemonic_activate (GtkWidget *widget,
5788 gboolean group_cycling)
5792 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5794 group_cycling = group_cycling != FALSE;
5795 if (!gtk_widget_is_sensitive (widget))
5798 g_signal_emit (widget,
5799 widget_signals[MNEMONIC_ACTIVATE],
5807 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5808 gboolean group_cycling)
5810 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5811 gtk_widget_activate (widget);
5812 else if (gtk_widget_get_can_focus (widget))
5813 gtk_widget_grab_focus (widget);
5816 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5817 G_OBJECT_TYPE_NAME (widget));
5818 gtk_widget_error_bell (widget);
5823 static const cairo_user_data_key_t event_key;
5826 _gtk_cairo_get_event (cairo_t *cr)
5828 g_return_val_if_fail (cr != NULL, NULL);
5830 return cairo_get_user_data (cr, &event_key);
5834 gtk_cairo_set_event (cairo_t *cr,
5835 GdkEventExpose *event)
5837 cairo_set_user_data (cr, &event_key, event, NULL);
5841 * gtk_cairo_should_draw_window:
5842 * @cr: a cairo context
5843 * @window: the window to check. @window may not be an input-only
5846 * This function is supposed to be called in #GtkWidget::draw
5847 * implementations for widgets that support multiple windows.
5848 * @cr must be untransformed from invoking of the draw function.
5849 * This function will return %TRUE if the contents of the given
5850 * @window are supposed to be drawn and %FALSE otherwise. Note
5851 * that when the drawing was not initiated by the windowing
5852 * system this function will return %TRUE for all windows, so
5853 * you need to draw the bottommost window first. Also, do not
5854 * use "else if" statements to check which window should be drawn.
5856 * Returns: %TRUE if @window should be drawn
5861 gtk_cairo_should_draw_window (cairo_t *cr,
5864 GdkEventExpose *event;
5866 g_return_val_if_fail (cr != NULL, FALSE);
5867 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5869 event = _gtk_cairo_get_event (cr);
5871 return event == NULL ||
5872 event->window == window;
5876 gtk_widget_get_clip_draw (GtkWidget *widget)
5878 /* labels are not clipped, because clipping them would cause
5879 * mnemonics to not appear on characters that go beyond the
5881 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
5883 if (GTK_IS_LABEL (widget))
5889 /* code shared by gtk_container_propagate_draw() and
5893 _gtk_widget_draw_internal (GtkWidget *widget,
5895 gboolean clip_to_size)
5897 if (!gtk_widget_is_drawable (widget))
5900 clip_to_size &= gtk_widget_get_clip_draw (widget);
5904 cairo_rectangle (cr,
5906 widget->priv->allocation.width,
5907 widget->priv->allocation.height);
5911 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5915 g_signal_emit (widget, widget_signals[DRAW],
5919 if (cairo_status (cr) &&
5920 _gtk_cairo_get_event (cr))
5922 /* We check the event so we only warn about internal GTK calls.
5923 * Errors might come from PDF streams having write failures and
5924 * we don't want to spam stderr in that case.
5925 * We do want to catch errors from
5927 g_warning ("drawing failure for widget `%s': %s",
5928 G_OBJECT_TYPE_NAME (widget),
5929 cairo_status_to_string (cairo_status (cr)));
5936 * @widget: the widget to draw. It must be drawable (see
5937 * gtk_widget_is_drawable()) and a size must have been allocated.
5938 * @cr: a cairo context to draw to
5940 * Draws @widget to @cr. The top left corner of the widget will be
5941 * drawn to the currently set origin point of @cr.
5943 * You should pass a cairo context as @cr argument that is in an
5944 * original state. Otherwise the resulting drawing is undefined. For
5945 * example changing the operator using cairo_set_operator() or the
5946 * line width using cairo_set_line_width() might have unwanted side
5948 * You may however change the context's transform matrix - like with
5949 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5950 * region with cairo_clip() prior to calling this function. Also, it
5951 * is fine to modify the context with cairo_save() and
5952 * cairo_push_group() prior to calling this function.
5954 * <note><para>Special purpose widgets may contain special code for
5955 * rendering to the screen and might appear differently on screen
5956 * and when rendered using gtk_widget_draw().</para></note>
5961 gtk_widget_draw (GtkWidget *widget,
5964 GdkEventExpose *tmp_event;
5966 g_return_if_fail (GTK_IS_WIDGET (widget));
5967 g_return_if_fail (!widget->priv->alloc_needed);
5968 g_return_if_fail (cr != NULL);
5971 /* We have to reset the event here so that draw functions can call
5972 * gtk_widget_draw() on random other widgets and get the desired
5973 * effect: Drawing all contents, not just the current window.
5975 tmp_event = _gtk_cairo_get_event (cr);
5976 gtk_cairo_set_event (cr, NULL);
5978 _gtk_widget_draw_internal (widget, cr, TRUE);
5980 gtk_cairo_set_event (cr, tmp_event);
5985 gtk_widget_real_key_press_event (GtkWidget *widget,
5988 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5992 gtk_widget_real_key_release_event (GtkWidget *widget,
5995 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5999 gtk_widget_real_focus_in_event (GtkWidget *widget,
6000 GdkEventFocus *event)
6002 gtk_widget_queue_draw (widget);
6008 gtk_widget_real_focus_out_event (GtkWidget *widget,
6009 GdkEventFocus *event)
6011 gtk_widget_queue_draw (widget);
6017 gtk_widget_real_touch_event (GtkWidget *widget,
6018 GdkEventTouch *event)
6021 gboolean return_val;
6024 if (!event->emulating_pointer)
6027 if (event->type == GDK_TOUCH_BEGIN ||
6028 event->type == GDK_TOUCH_END)
6032 if (event->type == GDK_TOUCH_BEGIN)
6034 type = GDK_BUTTON_PRESS;
6035 signum = BUTTON_PRESS_EVENT;
6039 type = GDK_BUTTON_RELEASE;
6040 signum = BUTTON_RELEASE_EVENT;
6042 bevent = gdk_event_new (type);
6043 bevent->any.window = g_object_ref (event->window);
6044 bevent->any.send_event = FALSE;
6045 bevent->button.time = event->time;
6046 bevent->button.state = event->state;
6047 bevent->button.button = 1;
6048 bevent->button.x_root = event->x_root;
6049 bevent->button.y_root = event->y_root;
6050 bevent->button.x = event->x;
6051 bevent->button.y = event->y;
6052 bevent->button.device = event->device;
6053 bevent->button.axes = g_memdup (event->axes,
6054 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6055 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6057 else if (event->type == GDK_TOUCH_UPDATE)
6059 signum = MOTION_NOTIFY_EVENT;
6060 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6061 bevent->any.window = g_object_ref (event->window);
6062 bevent->any.send_event = FALSE;
6063 bevent->motion.time = event->time;
6064 bevent->motion.state = event->state;
6065 bevent->motion.x_root = event->x_root;
6066 bevent->motion.y_root = event->y_root;
6067 bevent->motion.x = event->x;
6068 bevent->motion.y = event->y;
6069 bevent->motion.device = event->device;
6070 bevent->motion.is_hint = FALSE;
6071 bevent->motion.axes = g_memdup (event->axes,
6072 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6073 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6078 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6080 gdk_event_free (bevent);
6086 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6087 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6091 * @widget: a #GtkWidget
6092 * @event: a #GdkEvent
6094 * Rarely-used function. This function is used to emit
6095 * the event signals on a widget (those signals should never
6096 * be emitted without using this function to do so).
6097 * If you want to synthesize an event though, don't use this function;
6098 * instead, use gtk_main_do_event() so the event will behave as if
6099 * it were in the event queue. Don't synthesize expose events; instead,
6100 * use gdk_window_invalidate_rect() to invalidate a region of the
6103 * Return value: return from the event signal emission (%TRUE if
6104 * the event was handled)
6107 gtk_widget_event (GtkWidget *widget,
6110 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6111 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6113 if (event->type == GDK_EXPOSE)
6115 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6116 "the same effect, call gdk_window_invalidate_rect/region(), "
6117 "followed by gdk_window_process_updates().");
6121 return gtk_widget_event_internal (widget, event);
6125 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6126 GtkCapturedEventHandler callback)
6128 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6132 _gtk_widget_captured_event (GtkWidget *widget,
6135 gboolean return_val = FALSE;
6136 GtkCapturedEventHandler handler;
6138 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6139 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6141 if (event->type == GDK_EXPOSE)
6143 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6144 "the same effect, call gdk_window_invalidate_rect/region(), "
6145 "followed by gdk_window_process_updates().");
6149 if (!event_window_is_still_viewable (event))
6152 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6156 g_object_ref (widget);
6158 return_val = handler (widget, event);
6159 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6161 /* The widget that was originally to receive the event
6162 * handles motion hints, but the capturing widget might
6163 * not, so ensure we get further motion events.
6166 event->type == GDK_MOTION_NOTIFY &&
6167 event->motion.is_hint &&
6168 (gdk_window_get_events (event->any.window) &
6169 GDK_POINTER_MOTION_HINT_MASK) != 0)
6170 gdk_event_request_motions (&event->motion);
6172 g_object_unref (widget);
6177 /* Returns TRUE if a translation should be done */
6179 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6184 GdkWindow *w, *widget_window;
6186 if (!gtk_widget_get_has_window (widget))
6188 *x = -widget->priv->allocation.x;
6189 *y = -widget->priv->allocation.y;
6197 widget_window = gtk_widget_get_window (widget);
6199 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6202 gdk_window_get_position (w, &wx, &wy);
6219 * gtk_cairo_transform_to_window:
6220 * @cr: the cairo context to transform
6221 * @widget: the widget the context is currently centered for
6222 * @window: the window to transform the context to
6224 * Transforms the given cairo context @cr that from @widget-relative
6225 * coordinates to @window-relative coordinates.
6226 * If the @widget's window is not an ancestor of @window, no
6227 * modification will be applied.
6229 * This is the inverse to the transformation GTK applies when
6230 * preparing an expose event to be emitted with the #GtkWidget::draw
6231 * signal. It is intended to help porting multiwindow widgets from
6232 * GTK+ 2 to the rendering architecture of GTK+ 3.
6237 gtk_cairo_transform_to_window (cairo_t *cr,
6243 g_return_if_fail (cr != NULL);
6244 g_return_if_fail (GTK_IS_WIDGET (widget));
6245 g_return_if_fail (GDK_IS_WINDOW (window));
6247 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6248 cairo_translate (cr, x, y);
6252 * gtk_widget_send_expose:
6253 * @widget: a #GtkWidget
6254 * @event: a expose #GdkEvent
6256 * Very rarely-used function. This function is used to emit
6257 * an expose event on a widget. This function is not normally used
6258 * directly. The only time it is used is when propagating an expose
6259 * event to a child %NO_WINDOW widget, and that is normally done
6260 * using gtk_container_propagate_draw().
6262 * If you want to force an area of a window to be redrawn,
6263 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6264 * To cause the redraw to be done immediately, follow that call
6265 * with a call to gdk_window_process_updates().
6267 * Return value: return from the event signal emission (%TRUE if
6268 * the event was handled)
6271 gtk_widget_send_expose (GtkWidget *widget,
6274 gboolean result = FALSE;
6279 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6280 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6281 g_return_val_if_fail (event != NULL, TRUE);
6282 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6284 cr = gdk_cairo_create (event->expose.window);
6285 gtk_cairo_set_event (cr, &event->expose);
6287 gdk_cairo_region (cr, event->expose.region);
6290 do_clip = _gtk_widget_get_translation_to_window (widget,
6291 event->expose.window,
6293 cairo_translate (cr, -x, -y);
6295 _gtk_widget_draw_internal (widget, cr, do_clip);
6297 /* unset here, so if someone keeps a reference to cr we
6298 * don't leak the window. */
6299 gtk_cairo_set_event (cr, NULL);
6306 event_window_is_still_viewable (GdkEvent *event)
6308 /* Check that we think the event's window is viewable before
6309 * delivering the event, to prevent suprises. We do this here
6310 * at the last moment, since the event may have been queued
6311 * up behind other events, held over a recursive main loop, etc.
6313 switch (event->type)
6316 case GDK_MOTION_NOTIFY:
6317 case GDK_BUTTON_PRESS:
6318 case GDK_2BUTTON_PRESS:
6319 case GDK_3BUTTON_PRESS:
6321 case GDK_ENTER_NOTIFY:
6322 case GDK_PROXIMITY_IN:
6324 return event->any.window && gdk_window_is_viewable (event->any.window);
6327 /* The following events are the second half of paired events;
6328 * we always deliver them to deal with widgets that clean up
6329 * on the second half.
6331 case GDK_BUTTON_RELEASE:
6332 case GDK_KEY_RELEASE:
6333 case GDK_LEAVE_NOTIFY:
6334 case GDK_PROXIMITY_OUT:
6338 /* Remaining events would make sense on an not-viewable window,
6339 * or don't have an associated window.
6346 gtk_widget_event_internal (GtkWidget *widget,
6349 gboolean return_val = FALSE;
6351 /* We check only once for is-still-visible; if someone
6352 * hides the window in on of the signals on the widget,
6353 * they are responsible for returning TRUE to terminate
6356 if (!event_window_is_still_viewable (event))
6359 g_object_ref (widget);
6361 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6362 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6367 switch (event->type)
6373 case GDK_BUTTON_PRESS:
6374 case GDK_2BUTTON_PRESS:
6375 case GDK_3BUTTON_PRESS:
6376 signal_num = BUTTON_PRESS_EVENT;
6378 case GDK_TOUCH_BEGIN:
6379 case GDK_TOUCH_UPDATE:
6381 case GDK_TOUCH_CANCEL:
6382 signal_num = TOUCH_EVENT;
6385 signal_num = SCROLL_EVENT;
6387 case GDK_BUTTON_RELEASE:
6388 signal_num = BUTTON_RELEASE_EVENT;
6390 case GDK_MOTION_NOTIFY:
6391 signal_num = MOTION_NOTIFY_EVENT;
6394 signal_num = DELETE_EVENT;
6397 signal_num = DESTROY_EVENT;
6398 _gtk_tooltip_hide (widget);
6401 signal_num = KEY_PRESS_EVENT;
6403 case GDK_KEY_RELEASE:
6404 signal_num = KEY_RELEASE_EVENT;
6406 case GDK_ENTER_NOTIFY:
6407 signal_num = ENTER_NOTIFY_EVENT;
6409 case GDK_LEAVE_NOTIFY:
6410 signal_num = LEAVE_NOTIFY_EVENT;
6412 case GDK_FOCUS_CHANGE:
6413 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6414 if (event->focus_change.in)
6415 _gtk_tooltip_focus_in (widget);
6417 _gtk_tooltip_focus_out (widget);
6420 signal_num = CONFIGURE_EVENT;
6423 signal_num = MAP_EVENT;
6426 signal_num = UNMAP_EVENT;
6428 case GDK_WINDOW_STATE:
6429 signal_num = WINDOW_STATE_EVENT;
6431 case GDK_PROPERTY_NOTIFY:
6432 signal_num = PROPERTY_NOTIFY_EVENT;
6434 case GDK_SELECTION_CLEAR:
6435 signal_num = SELECTION_CLEAR_EVENT;
6437 case GDK_SELECTION_REQUEST:
6438 signal_num = SELECTION_REQUEST_EVENT;
6440 case GDK_SELECTION_NOTIFY:
6441 signal_num = SELECTION_NOTIFY_EVENT;
6443 case GDK_PROXIMITY_IN:
6444 signal_num = PROXIMITY_IN_EVENT;
6446 case GDK_PROXIMITY_OUT:
6447 signal_num = PROXIMITY_OUT_EVENT;
6449 case GDK_VISIBILITY_NOTIFY:
6450 signal_num = VISIBILITY_NOTIFY_EVENT;
6452 case GDK_GRAB_BROKEN:
6453 signal_num = GRAB_BROKEN_EVENT;
6456 signal_num = DAMAGE_EVENT;
6459 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6463 if (signal_num != -1)
6464 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6466 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6467 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6471 g_object_unref (widget);
6477 * gtk_widget_activate:
6478 * @widget: a #GtkWidget that's activatable
6480 * For widgets that can be "activated" (buttons, menu items, etc.)
6481 * this function activates them. Activation is what happens when you
6482 * press Enter on a widget during key navigation. If @widget isn't
6483 * activatable, the function returns %FALSE.
6485 * Return value: %TRUE if the widget was activatable
6488 gtk_widget_activate (GtkWidget *widget)
6490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6492 if (WIDGET_CLASS (widget)->activate_signal)
6494 /* FIXME: we should eventually check the signals signature here */
6495 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6504 gtk_widget_reparent_subwindows (GtkWidget *widget,
6505 GdkWindow *new_window)
6507 GtkWidgetPrivate *priv = widget->priv;
6509 if (!gtk_widget_get_has_window (widget))
6511 GList *children = gdk_window_get_children (priv->window);
6514 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6516 GdkWindow *window = tmp_list->data;
6519 gdk_window_get_user_data (window, &child);
6520 while (child && child != widget)
6521 child = ((GtkWidget*) child)->priv->parent;
6524 gdk_window_reparent (window, new_window, 0, 0);
6527 g_list_free (children);
6532 GList *tmp_list, *children;
6534 parent = gdk_window_get_parent (priv->window);
6537 gdk_window_reparent (priv->window, new_window, 0, 0);
6540 children = gdk_window_get_children (parent);
6542 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6544 GdkWindow *window = tmp_list->data;
6547 gdk_window_get_user_data (window, &child);
6549 if (child == widget)
6550 gdk_window_reparent (window, new_window, 0, 0);
6553 g_list_free (children);
6559 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6560 gpointer client_data)
6562 GtkWidgetPrivate *priv = widget->priv;
6564 g_assert (client_data != NULL);
6566 if (!gtk_widget_get_has_window (widget))
6569 g_object_unref (priv->window);
6570 priv->window = (GdkWindow*) client_data;
6572 g_object_ref (priv->window);
6574 if (GTK_IS_CONTAINER (widget))
6575 gtk_container_forall (GTK_CONTAINER (widget),
6576 gtk_widget_reparent_fixup_child,
6582 * gtk_widget_reparent:
6583 * @widget: a #GtkWidget
6584 * @new_parent: a #GtkContainer to move the widget into
6586 * Moves a widget from one #GtkContainer to another, handling reference
6587 * count issues to avoid destroying the widget.
6590 gtk_widget_reparent (GtkWidget *widget,
6591 GtkWidget *new_parent)
6593 GtkWidgetPrivate *priv;
6595 g_return_if_fail (GTK_IS_WIDGET (widget));
6596 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6597 priv = widget->priv;
6598 g_return_if_fail (priv->parent != NULL);
6600 if (priv->parent != new_parent)
6602 /* First try to see if we can get away without unrealizing
6603 * the widget as we reparent it. if so we set a flag so
6604 * that gtk_widget_unparent doesn't unrealize widget
6606 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6607 priv->in_reparent = TRUE;
6609 g_object_ref (widget);
6610 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6611 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6612 g_object_unref (widget);
6614 if (priv->in_reparent)
6616 priv->in_reparent = FALSE;
6618 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6619 gtk_widget_reparent_fixup_child (widget,
6620 gtk_widget_get_parent_window (widget));
6623 g_object_notify (G_OBJECT (widget), "parent");
6628 * gtk_widget_intersect:
6629 * @widget: a #GtkWidget
6630 * @area: a rectangle
6631 * @intersection: rectangle to store intersection of @widget and @area
6633 * Computes the intersection of a @widget's area and @area, storing
6634 * the intersection in @intersection, and returns %TRUE if there was
6635 * an intersection. @intersection may be %NULL if you're only
6636 * interested in whether there was an intersection.
6638 * Return value: %TRUE if there was an intersection
6641 gtk_widget_intersect (GtkWidget *widget,
6642 const GdkRectangle *area,
6643 GdkRectangle *intersection)
6645 GtkWidgetPrivate *priv;
6650 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6651 g_return_val_if_fail (area != NULL, FALSE);
6653 priv = widget->priv;
6656 dest = intersection;
6660 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6662 if (return_val && intersection && gtk_widget_get_has_window (widget))
6664 intersection->x -= priv->allocation.x;
6665 intersection->y -= priv->allocation.y;
6672 * gtk_widget_region_intersect:
6673 * @widget: a #GtkWidget
6674 * @region: a #cairo_region_t, in the same coordinate system as
6675 * @widget->allocation. That is, relative to @widget->window
6676 * for %NO_WINDOW widgets; relative to the parent window
6677 * of @widget->window for widgets with their own window.
6679 * Computes the intersection of a @widget's area and @region, returning
6680 * the intersection. The result may be empty, use cairo_region_is_empty() to
6683 * Returns: A newly allocated region holding the intersection of @widget
6684 * and @region. The coordinates of the return value are relative to
6685 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6686 * window of @widget->window for widgets with their own window.
6689 gtk_widget_region_intersect (GtkWidget *widget,
6690 const cairo_region_t *region)
6693 cairo_region_t *dest;
6695 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6696 g_return_val_if_fail (region != NULL, NULL);
6698 gtk_widget_get_allocation (widget, &rect);
6700 dest = cairo_region_create_rectangle (&rect);
6702 cairo_region_intersect (dest, region);
6708 * _gtk_widget_grab_notify:
6709 * @widget: a #GtkWidget
6710 * @was_grabbed: whether a grab is now in effect
6712 * Emits the #GtkWidget::grab-notify signal on @widget.
6717 _gtk_widget_grab_notify (GtkWidget *widget,
6718 gboolean was_grabbed)
6720 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6724 * gtk_widget_grab_focus:
6725 * @widget: a #GtkWidget
6727 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6728 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6729 * something like #GtkFrame won't work.
6731 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6732 * gtk_widget_set_can_focus() to modify that flag.
6734 * The widget also needs to be realized and mapped. This is indicated by the
6735 * related signals. Grabbing the focus immediately after creating the widget
6736 * will likely fail and cause critical warnings.
6739 gtk_widget_grab_focus (GtkWidget *widget)
6741 g_return_if_fail (GTK_IS_WIDGET (widget));
6743 if (!gtk_widget_is_sensitive (widget))
6746 g_object_ref (widget);
6747 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6748 g_object_notify (G_OBJECT (widget), "has-focus");
6749 g_object_unref (widget);
6753 reset_focus_recurse (GtkWidget *widget,
6756 if (GTK_IS_CONTAINER (widget))
6758 GtkContainer *container;
6760 container = GTK_CONTAINER (widget);
6761 gtk_container_set_focus_child (container, NULL);
6763 gtk_container_foreach (container,
6764 reset_focus_recurse,
6770 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6772 if (gtk_widget_get_can_focus (focus_widget))
6774 GtkWidget *toplevel;
6777 /* clear the current focus setting, break if the current widget
6778 * is the focus widget's parent, since containers above that will
6779 * be set by the next loop.
6781 toplevel = gtk_widget_get_toplevel (focus_widget);
6782 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6784 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6786 if (widget == focus_widget)
6788 /* We call _gtk_window_internal_set_focus() here so that the
6789 * toplevel window can request the focus if necessary.
6790 * This is needed when the toplevel is a GtkPlug
6792 if (!gtk_widget_has_focus (widget))
6793 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6800 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
6802 if (widget != common_ancestor)
6804 while (widget->priv->parent && widget->priv->parent != common_ancestor)
6806 widget = widget->priv->parent;
6807 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6812 else if (toplevel != focus_widget)
6814 /* gtk_widget_grab_focus() operates on a tree without window...
6815 * actually, this is very questionable behaviour.
6818 gtk_container_foreach (GTK_CONTAINER (toplevel),
6819 reset_focus_recurse,
6823 /* now propagate the new focus up the widget tree and finally
6824 * set it on the window
6826 widget = focus_widget;
6827 while (widget->priv->parent)
6829 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6830 widget = widget->priv->parent;
6832 if (GTK_IS_WINDOW (widget))
6833 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6838 gtk_widget_real_query_tooltip (GtkWidget *widget,
6841 gboolean keyboard_tip,
6842 GtkTooltip *tooltip)
6844 gchar *tooltip_markup;
6845 gboolean has_tooltip;
6847 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6848 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6850 if (has_tooltip && tooltip_markup)
6852 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6860 gtk_widget_real_state_flags_changed (GtkWidget *widget,
6861 GtkStateFlags old_state)
6863 gtk_widget_update_pango_context (widget);
6867 gtk_widget_real_style_updated (GtkWidget *widget)
6869 GtkWidgetPrivate *priv = widget->priv;
6871 gtk_widget_update_pango_context (widget);
6872 gtk_widget_update_alpha (widget);
6874 if (priv->style != NULL &&
6875 priv->style != gtk_widget_get_default_style ())
6877 /* Trigger ::style-set for old
6878 * widgets not listening to this
6880 g_signal_emit (widget,
6881 widget_signals[STYLE_SET],
6883 widget->priv->style);
6886 if (widget->priv->context)
6888 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
6890 if (gtk_widget_get_realized (widget) &&
6891 gtk_widget_get_has_window (widget) &&
6892 !gtk_widget_get_app_paintable (widget))
6893 gtk_style_context_set_background (widget->priv->context,
6894 widget->priv->window);
6896 if (widget->priv->anchored)
6898 if (changes && _gtk_css_style_property_changes_affect_size (changes))
6899 gtk_widget_queue_resize (widget);
6901 gtk_widget_queue_draw (widget);
6906 if (widget->priv->anchored)
6907 gtk_widget_queue_resize (widget);
6912 gtk_widget_real_show_help (GtkWidget *widget,
6913 GtkWidgetHelpType help_type)
6915 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6917 _gtk_tooltip_toggle_keyboard_mode (widget);
6926 gtk_widget_real_focus (GtkWidget *widget,
6927 GtkDirectionType direction)
6929 if (!gtk_widget_get_can_focus (widget))
6932 if (!gtk_widget_is_focus (widget))
6934 gtk_widget_grab_focus (widget);
6942 gtk_widget_real_move_focus (GtkWidget *widget,
6943 GtkDirectionType direction)
6945 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6947 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6949 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6955 gtk_widget_real_keynav_failed (GtkWidget *widget,
6956 GtkDirectionType direction)
6958 gboolean cursor_only;
6962 case GTK_DIR_TAB_FORWARD:
6963 case GTK_DIR_TAB_BACKWARD:
6970 g_object_get (gtk_widget_get_settings (widget),
6971 "gtk-keynav-cursor-only", &cursor_only,
6978 gtk_widget_error_bell (widget);
6984 * gtk_widget_set_can_focus:
6985 * @widget: a #GtkWidget
6986 * @can_focus: whether or not @widget can own the input focus.
6988 * Specifies whether @widget can own the input focus. See
6989 * gtk_widget_grab_focus() for actually setting the input focus on a
6995 gtk_widget_set_can_focus (GtkWidget *widget,
6998 g_return_if_fail (GTK_IS_WIDGET (widget));
7000 if (widget->priv->can_focus != can_focus)
7002 widget->priv->can_focus = can_focus;
7004 gtk_widget_queue_resize (widget);
7005 g_object_notify (G_OBJECT (widget), "can-focus");
7010 * gtk_widget_get_can_focus:
7011 * @widget: a #GtkWidget
7013 * Determines whether @widget can own the input focus. See
7014 * gtk_widget_set_can_focus().
7016 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
7021 gtk_widget_get_can_focus (GtkWidget *widget)
7023 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7025 return widget->priv->can_focus;
7029 * gtk_widget_has_focus:
7030 * @widget: a #GtkWidget
7032 * Determines if the widget has the global input focus. See
7033 * gtk_widget_is_focus() for the difference between having the global
7034 * input focus, and only having the focus within a toplevel.
7036 * Return value: %TRUE if the widget has the global input focus.
7041 gtk_widget_has_focus (GtkWidget *widget)
7043 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7045 return widget->priv->has_focus;
7049 * gtk_widget_has_visible_focus:
7050 * @widget: a #GtkWidget
7052 * Determines if the widget should show a visible indication that
7053 * it has the global input focus. This is a convenience function for
7054 * use in ::draw handlers that takes into account whether focus
7055 * indication should currently be shown in the toplevel window of
7056 * @widget. See gtk_window_get_focus_visible() for more information
7057 * about focus indication.
7059 * To find out if the widget has the global input focus, use
7060 * gtk_widget_has_focus().
7062 * Return value: %TRUE if the widget should display a 'focus rectangle'
7067 gtk_widget_has_visible_focus (GtkWidget *widget)
7069 gboolean draw_focus;
7071 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7073 if (widget->priv->has_focus)
7075 GtkWidget *toplevel;
7077 toplevel = gtk_widget_get_toplevel (widget);
7079 if (GTK_IS_WINDOW (toplevel))
7080 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7091 * gtk_widget_is_focus:
7092 * @widget: a #GtkWidget
7094 * Determines if the widget is the focus widget within its
7095 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7096 * necessarily set; %HAS_FOCUS will only be set if the
7097 * toplevel widget additionally has the global input focus.)
7099 * Return value: %TRUE if the widget is the focus widget.
7102 gtk_widget_is_focus (GtkWidget *widget)
7104 GtkWidget *toplevel;
7106 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7108 toplevel = gtk_widget_get_toplevel (widget);
7110 if (GTK_IS_WINDOW (toplevel))
7111 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7117 * gtk_widget_set_can_default:
7118 * @widget: a #GtkWidget
7119 * @can_default: whether or not @widget can be a default widget.
7121 * Specifies whether @widget can be a default widget. See
7122 * gtk_widget_grab_default() for details about the meaning of
7128 gtk_widget_set_can_default (GtkWidget *widget,
7129 gboolean can_default)
7131 g_return_if_fail (GTK_IS_WIDGET (widget));
7133 if (widget->priv->can_default != can_default)
7135 widget->priv->can_default = can_default;
7137 gtk_widget_queue_resize (widget);
7138 g_object_notify (G_OBJECT (widget), "can-default");
7143 * gtk_widget_get_can_default:
7144 * @widget: a #GtkWidget
7146 * Determines whether @widget can be a default widget. See
7147 * gtk_widget_set_can_default().
7149 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7154 gtk_widget_get_can_default (GtkWidget *widget)
7156 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7158 return widget->priv->can_default;
7162 * gtk_widget_has_default:
7163 * @widget: a #GtkWidget
7165 * Determines whether @widget is the current default widget within its
7166 * toplevel. See gtk_widget_set_can_default().
7168 * Return value: %TRUE if @widget is the current default widget within
7169 * its toplevel, %FALSE otherwise
7174 gtk_widget_has_default (GtkWidget *widget)
7176 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7178 return widget->priv->has_default;
7182 _gtk_widget_set_has_default (GtkWidget *widget,
7183 gboolean has_default)
7185 GtkStyleContext *context;
7187 widget->priv->has_default = has_default;
7189 context = gtk_widget_get_style_context (widget);
7192 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7194 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7198 * gtk_widget_grab_default:
7199 * @widget: a #GtkWidget
7201 * Causes @widget to become the default widget. @widget must be able to be
7202 * a default widget; typically you would ensure this yourself
7203 * by calling gtk_widget_set_can_default() with a %TRUE value.
7204 * The default widget is activated when
7205 * the user presses Enter in a window. Default widgets must be
7206 * activatable, that is, gtk_widget_activate() should affect them. Note
7207 * that #GtkEntry widgets require the "activates-default" property
7208 * set to %TRUE before they activate the default widget when Enter
7209 * is pressed and the #GtkEntry is focused.
7212 gtk_widget_grab_default (GtkWidget *widget)
7216 g_return_if_fail (GTK_IS_WIDGET (widget));
7217 g_return_if_fail (gtk_widget_get_can_default (widget));
7219 window = gtk_widget_get_toplevel (widget);
7221 if (window && gtk_widget_is_toplevel (window))
7222 gtk_window_set_default (GTK_WINDOW (window), widget);
7224 g_warning (G_STRLOC ": widget not within a GtkWindow");
7228 * gtk_widget_set_receives_default:
7229 * @widget: a #GtkWidget
7230 * @receives_default: whether or not @widget can be a default widget.
7232 * Specifies whether @widget will be treated as the default widget
7233 * within its toplevel when it has the focus, even if another widget
7236 * See gtk_widget_grab_default() for details about the meaning of
7242 gtk_widget_set_receives_default (GtkWidget *widget,
7243 gboolean receives_default)
7245 g_return_if_fail (GTK_IS_WIDGET (widget));
7247 if (widget->priv->receives_default != receives_default)
7249 widget->priv->receives_default = receives_default;
7251 g_object_notify (G_OBJECT (widget), "receives-default");
7256 * gtk_widget_get_receives_default:
7257 * @widget: a #GtkWidget
7259 * Determines whether @widget is alyways treated as default widget
7260 * withing its toplevel when it has the focus, even if another widget
7263 * See gtk_widget_set_receives_default().
7265 * Return value: %TRUE if @widget acts as default widget when focussed,
7271 gtk_widget_get_receives_default (GtkWidget *widget)
7273 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7275 return widget->priv->receives_default;
7279 * gtk_widget_has_grab:
7280 * @widget: a #GtkWidget
7282 * Determines whether the widget is currently grabbing events, so it
7283 * is the only widget receiving input events (keyboard and mouse).
7285 * See also gtk_grab_add().
7287 * Return value: %TRUE if the widget is in the grab_widgets stack
7292 gtk_widget_has_grab (GtkWidget *widget)
7294 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7296 return widget->priv->has_grab;
7300 _gtk_widget_set_has_grab (GtkWidget *widget,
7303 widget->priv->has_grab = has_grab;
7307 * gtk_widget_device_is_shadowed:
7308 * @widget: a #GtkWidget
7309 * @device: a #GdkDevice
7311 * Returns %TRUE if @device has been shadowed by a GTK+
7312 * device grab on another widget, so it would stop sending
7313 * events to @widget. This may be used in the
7314 * #GtkWidget::grab-notify signal to check for specific
7315 * devices. See gtk_device_grab_add().
7317 * Returns: %TRUE if there is an ongoing grab on @device
7318 * by another #GtkWidget than @widget.
7323 gtk_widget_device_is_shadowed (GtkWidget *widget,
7326 GtkWindowGroup *group;
7327 GtkWidget *grab_widget, *toplevel;
7329 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7330 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7332 if (!gtk_widget_get_realized (widget))
7335 toplevel = gtk_widget_get_toplevel (widget);
7337 if (GTK_IS_WINDOW (toplevel))
7338 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7340 group = gtk_window_get_group (NULL);
7342 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7344 /* Widget not inside the hierarchy of grab_widget */
7346 widget != grab_widget &&
7347 !gtk_widget_is_ancestor (widget, grab_widget))
7350 grab_widget = gtk_window_group_get_current_grab (group);
7351 if (grab_widget && widget != grab_widget &&
7352 !gtk_widget_is_ancestor (widget, grab_widget))
7359 * gtk_widget_set_name:
7360 * @widget: a #GtkWidget
7361 * @name: name for the widget
7363 * Widgets can be named, which allows you to refer to them from a
7364 * CSS file. You can apply a style to widgets with a particular name
7365 * in the CSS file. See the documentation for the CSS syntax (on the
7366 * same page as the docs for #GtkStyleContext).
7368 * Note that the CSS syntax has certain special characters to delimit
7369 * and represent elements in a selector (period, #, >, *...),
7370 * so using these will make your widget impossible to match by name.
7371 * Any combination of alphanumeric symbols, dashes and underscores will
7375 gtk_widget_set_name (GtkWidget *widget,
7378 GtkWidgetPrivate *priv;
7381 g_return_if_fail (GTK_IS_WIDGET (widget));
7383 priv = widget->priv;
7385 new_name = g_strdup (name);
7386 g_free (priv->name);
7387 priv->name = new_name;
7389 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7391 g_object_notify (G_OBJECT (widget), "name");
7395 * gtk_widget_get_name:
7396 * @widget: a #GtkWidget
7398 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7399 * significance of widget names.
7401 * Return value: name of the widget. This string is owned by GTK+ and
7402 * should not be modified or freed
7405 gtk_widget_get_name (GtkWidget *widget)
7407 GtkWidgetPrivate *priv;
7409 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7411 priv = widget->priv;
7415 return G_OBJECT_TYPE_NAME (widget);
7419 gtk_widget_update_state_flags (GtkWidget *widget,
7420 GtkStateFlags flags_to_set,
7421 GtkStateFlags flags_to_unset)
7423 GtkWidgetPrivate *priv;
7425 priv = widget->priv;
7427 /* Handle insensitive first, since it is propagated
7428 * differently throughout the widget hierarchy.
7430 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7431 gtk_widget_set_sensitive (widget, TRUE);
7432 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7433 gtk_widget_set_sensitive (widget, FALSE);
7435 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7436 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7438 if (flags_to_set != 0 || flags_to_unset != 0)
7442 data.flags_to_set = flags_to_set;
7443 data.flags_to_unset = flags_to_unset;
7445 gtk_widget_propagate_state (widget, &data);
7450 * gtk_widget_set_state_flags:
7451 * @widget: a #GtkWidget
7452 * @flags: State flags to turn on
7453 * @clear: Whether to clear state before turning on @flags
7455 * This function is for use in widget implementations. Turns on flag
7456 * values in the current widget state (insensitive, prelighted, etc.).
7458 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7459 * will be propagated down to all non-internal children if @widget is a
7460 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7461 * down to all #GtkContainer children by different means than turning on the
7462 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7463 * gtk_widget_is_sensitive() will make use of these.
7468 gtk_widget_set_state_flags (GtkWidget *widget,
7469 GtkStateFlags flags,
7472 g_return_if_fail (GTK_IS_WIDGET (widget));
7474 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7475 (clear && widget->priv->state_flags == flags))
7479 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7481 gtk_widget_update_state_flags (widget, flags, 0);
7485 * gtk_widget_unset_state_flags:
7486 * @widget: a #GtkWidget
7487 * @flags: State flags to turn off
7489 * This function is for use in widget implementations. Turns off flag
7490 * values for the current widget state (insensitive, prelighted, etc.).
7491 * See gtk_widget_set_state_flags().
7496 gtk_widget_unset_state_flags (GtkWidget *widget,
7497 GtkStateFlags flags)
7499 g_return_if_fail (GTK_IS_WIDGET (widget));
7501 if ((widget->priv->state_flags & flags) == 0)
7504 gtk_widget_update_state_flags (widget, 0, flags);
7508 * gtk_widget_get_state_flags:
7509 * @widget: a #GtkWidget
7511 * Returns the widget state as a flag set. It is worth mentioning
7512 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7513 * returned, that is, also based on parent insensitivity, even if
7514 * @widget itself is sensitive.
7516 * Returns: The state flags for widget
7521 gtk_widget_get_state_flags (GtkWidget *widget)
7523 GtkStateFlags flags;
7525 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7527 flags = widget->priv->state_flags;
7529 if (gtk_widget_has_focus (widget))
7530 flags |= GTK_STATE_FLAG_FOCUSED;
7536 * gtk_widget_set_state:
7537 * @widget: a #GtkWidget
7538 * @state: new state for @widget
7540 * This function is for use in widget implementations. Sets the state
7541 * of a widget (insensitive, prelighted, etc.) Usually you should set
7542 * the state using wrapper functions such as gtk_widget_set_sensitive().
7544 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7547 gtk_widget_set_state (GtkWidget *widget,
7550 GtkStateFlags flags;
7552 if (state == gtk_widget_get_state (widget))
7557 case GTK_STATE_ACTIVE:
7558 flags = GTK_STATE_FLAG_ACTIVE;
7560 case GTK_STATE_PRELIGHT:
7561 flags = GTK_STATE_FLAG_PRELIGHT;
7563 case GTK_STATE_SELECTED:
7564 flags = GTK_STATE_FLAG_SELECTED;
7566 case GTK_STATE_INSENSITIVE:
7567 flags = GTK_STATE_FLAG_INSENSITIVE;
7569 case GTK_STATE_INCONSISTENT:
7570 flags = GTK_STATE_FLAG_INCONSISTENT;
7572 case GTK_STATE_FOCUSED:
7573 flags = GTK_STATE_FLAG_FOCUSED;
7575 case GTK_STATE_NORMAL:
7581 gtk_widget_update_state_flags (widget,
7583 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7584 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7588 * gtk_widget_get_state:
7589 * @widget: a #GtkWidget
7591 * Returns the widget's state. See gtk_widget_set_state().
7593 * Returns: the state of @widget.
7597 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7600 gtk_widget_get_state (GtkWidget *widget)
7602 GtkStateFlags flags;
7604 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7606 flags = gtk_widget_get_state_flags (widget);
7608 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7609 return GTK_STATE_INSENSITIVE;
7610 else if (flags & GTK_STATE_FLAG_ACTIVE)
7611 return GTK_STATE_ACTIVE;
7612 else if (flags & GTK_STATE_FLAG_SELECTED)
7613 return GTK_STATE_SELECTED;
7614 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7615 return GTK_STATE_PRELIGHT;
7617 return GTK_STATE_NORMAL;
7621 * gtk_widget_set_visible:
7622 * @widget: a #GtkWidget
7623 * @visible: whether the widget should be shown or not
7625 * Sets the visibility state of @widget. Note that setting this to
7626 * %TRUE doesn't mean the widget is actually viewable, see
7627 * gtk_widget_get_visible().
7629 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7630 * but is nicer to use when the visibility of the widget depends on
7636 gtk_widget_set_visible (GtkWidget *widget,
7639 g_return_if_fail (GTK_IS_WIDGET (widget));
7641 if (visible != gtk_widget_get_visible (widget))
7644 gtk_widget_show (widget);
7646 gtk_widget_hide (widget);
7651 _gtk_widget_set_visible_flag (GtkWidget *widget,
7654 GtkWidgetPrivate *priv = widget->priv;
7656 priv->visible = visible;
7660 priv->allocation.x = -1;
7661 priv->allocation.y = -1;
7662 priv->allocation.width = 1;
7663 priv->allocation.height = 1;
7668 * gtk_widget_get_visible:
7669 * @widget: a #GtkWidget
7671 * Determines whether the widget is visible. If you want to
7672 * take into account whether the widget's parent is also marked as
7673 * visible, use gtk_widget_is_visible() instead.
7675 * This function does not check if the widget is obscured in any way.
7677 * See gtk_widget_set_visible().
7679 * Return value: %TRUE if the widget is visible
7684 gtk_widget_get_visible (GtkWidget *widget)
7686 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7688 return widget->priv->visible;
7692 * gtk_widget_is_visible:
7693 * @widget: a #GtkWidget
7695 * Determines whether the widget and all its parents are marked as
7698 * This function does not check if the widget is obscured in any way.
7700 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7702 * Return value: %TRUE if the widget and all its parents are visible
7707 gtk_widget_is_visible (GtkWidget *widget)
7709 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7713 GtkWidgetPrivate *priv = widget->priv;
7718 widget = priv->parent;
7725 * gtk_widget_set_has_window:
7726 * @widget: a #GtkWidget
7727 * @has_window: whether or not @widget has a window.
7729 * Specifies whether @widget has a #GdkWindow of its own. Note that
7730 * all realized widgets have a non-%NULL "window" pointer
7731 * (gtk_widget_get_window() never returns a %NULL window when a widget
7732 * is realized), but for many of them it's actually the #GdkWindow of
7733 * one of its parent widgets. Widgets that do not create a %window for
7734 * themselves in #GtkWidget::realize must announce this by
7735 * calling this function with @has_window = %FALSE.
7737 * This function should only be called by widget implementations,
7738 * and they should call it in their init() function.
7743 gtk_widget_set_has_window (GtkWidget *widget,
7744 gboolean has_window)
7746 g_return_if_fail (GTK_IS_WIDGET (widget));
7748 widget->priv->no_window = !has_window;
7752 * gtk_widget_get_has_window:
7753 * @widget: a #GtkWidget
7755 * Determines whether @widget has a #GdkWindow of its own. See
7756 * gtk_widget_set_has_window().
7758 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7763 gtk_widget_get_has_window (GtkWidget *widget)
7765 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7767 return ! widget->priv->no_window;
7771 * gtk_widget_is_toplevel:
7772 * @widget: a #GtkWidget
7774 * Determines whether @widget is a toplevel widget.
7776 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
7777 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
7780 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7785 gtk_widget_is_toplevel (GtkWidget *widget)
7787 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7789 return widget->priv->toplevel;
7793 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7794 gboolean is_toplevel)
7796 widget->priv->toplevel = is_toplevel;
7800 * gtk_widget_is_drawable:
7801 * @widget: a #GtkWidget
7803 * Determines whether @widget can be drawn to. A widget can be drawn
7804 * to if it is mapped and visible.
7806 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7811 gtk_widget_is_drawable (GtkWidget *widget)
7813 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7815 return (gtk_widget_get_visible (widget) &&
7816 gtk_widget_get_mapped (widget));
7820 * gtk_widget_get_realized:
7821 * @widget: a #GtkWidget
7823 * Determines whether @widget is realized.
7825 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7830 gtk_widget_get_realized (GtkWidget *widget)
7832 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7834 return widget->priv->realized;
7838 * gtk_widget_set_realized:
7839 * @widget: a #GtkWidget
7840 * @realized: %TRUE to mark the widget as realized
7842 * Marks the widget as being realized.
7844 * This function should only ever be called in a derived widget's
7845 * "realize" or "unrealize" implementation.
7850 gtk_widget_set_realized (GtkWidget *widget,
7853 g_return_if_fail (GTK_IS_WIDGET (widget));
7855 widget->priv->realized = realized;
7859 * gtk_widget_get_mapped:
7860 * @widget: a #GtkWidget
7862 * Whether the widget is mapped.
7864 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7869 gtk_widget_get_mapped (GtkWidget *widget)
7871 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7873 return widget->priv->mapped;
7877 * gtk_widget_set_mapped:
7878 * @widget: a #GtkWidget
7879 * @mapped: %TRUE to mark the widget as mapped
7881 * Marks the widget as being realized.
7883 * This function should only ever be called in a derived widget's
7884 * "map" or "unmap" implementation.
7889 gtk_widget_set_mapped (GtkWidget *widget,
7892 g_return_if_fail (GTK_IS_WIDGET (widget));
7894 widget->priv->mapped = mapped;
7898 * gtk_widget_set_app_paintable:
7899 * @widget: a #GtkWidget
7900 * @app_paintable: %TRUE if the application will paint on the widget
7902 * Sets whether the application intends to draw on the widget in
7903 * an #GtkWidget::draw handler.
7905 * This is a hint to the widget and does not affect the behavior of
7906 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7907 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7908 * the effect is to suppress default themed drawing of the widget's
7909 * background. (Children of the widget will still be drawn.) The application
7910 * is then entirely responsible for drawing the widget background.
7912 * Note that the background is still drawn when the widget is mapped.
7915 gtk_widget_set_app_paintable (GtkWidget *widget,
7916 gboolean app_paintable)
7918 g_return_if_fail (GTK_IS_WIDGET (widget));
7920 app_paintable = (app_paintable != FALSE);
7922 if (widget->priv->app_paintable != app_paintable)
7924 widget->priv->app_paintable = app_paintable;
7926 if (gtk_widget_is_drawable (widget))
7927 gtk_widget_queue_draw (widget);
7929 g_object_notify (G_OBJECT (widget), "app-paintable");
7934 * gtk_widget_get_app_paintable:
7935 * @widget: a #GtkWidget
7937 * Determines whether the application intends to draw on the widget in
7938 * an #GtkWidget::draw handler.
7940 * See gtk_widget_set_app_paintable()
7942 * Return value: %TRUE if the widget is app paintable
7947 gtk_widget_get_app_paintable (GtkWidget *widget)
7949 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7951 return widget->priv->app_paintable;
7955 * gtk_widget_set_double_buffered:
7956 * @widget: a #GtkWidget
7957 * @double_buffered: %TRUE to double-buffer a widget
7959 * Widgets are double buffered by default; you can use this function
7960 * to turn off the buffering. "Double buffered" simply means that
7961 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7962 * automatically around expose events sent to the
7963 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
7964 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7965 * buffer to the screen. The result is that users see the window
7966 * update in one smooth step, and don't see individual graphics
7967 * primitives being rendered.
7969 * In very simple terms, double buffered widgets don't flicker,
7970 * so you would only use this function to turn off double buffering
7971 * if you had special needs and really knew what you were doing.
7973 * Note: if you turn off double-buffering, you have to handle
7974 * expose events, since even the clearing to the background color or
7975 * pixmap will not happen automatically (as it is done in
7976 * gdk_window_begin_paint_region()).
7979 gtk_widget_set_double_buffered (GtkWidget *widget,
7980 gboolean double_buffered)
7982 g_return_if_fail (GTK_IS_WIDGET (widget));
7984 double_buffered = (double_buffered != FALSE);
7986 if (widget->priv->double_buffered != double_buffered)
7988 widget->priv->double_buffered = double_buffered;
7990 g_object_notify (G_OBJECT (widget), "double-buffered");
7995 * gtk_widget_get_double_buffered:
7996 * @widget: a #GtkWidget
7998 * Determines whether the widget is double buffered.
8000 * See gtk_widget_set_double_buffered()
8002 * Return value: %TRUE if the widget is double buffered
8007 gtk_widget_get_double_buffered (GtkWidget *widget)
8009 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8011 return widget->priv->double_buffered;
8015 * gtk_widget_set_redraw_on_allocate:
8016 * @widget: a #GtkWidget
8017 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
8018 * when it is allocated to a new size. Otherwise, only the
8019 * new portion of the widget will be redrawn.
8021 * Sets whether the entire widget is queued for drawing when its size
8022 * allocation changes. By default, this setting is %TRUE and
8023 * the entire widget is redrawn on every size change. If your widget
8024 * leaves the upper left unchanged when made bigger, turning this
8025 * setting off will improve performance.
8027 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
8028 * off all allocation on resizing: the widget will not even redraw if
8029 * its position changes; this is to allow containers that don't draw
8030 * anything to avoid excess invalidations. If you set this flag on a
8031 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
8032 * you are responsible for invalidating both the old and new allocation
8033 * of the widget when the widget is moved and responsible for invalidating
8034 * regions newly when the widget increases size.
8037 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
8038 gboolean redraw_on_allocate)
8040 g_return_if_fail (GTK_IS_WIDGET (widget));
8042 widget->priv->redraw_on_alloc = redraw_on_allocate;
8046 * gtk_widget_set_sensitive:
8047 * @widget: a #GtkWidget
8048 * @sensitive: %TRUE to make the widget sensitive
8050 * Sets the sensitivity of a widget. A widget is sensitive if the user
8051 * can interact with it. Insensitive widgets are "grayed out" and the
8052 * user can't interact with them. Insensitive widgets are known as
8053 * "inactive", "disabled", or "ghosted" in some other toolkits.
8056 gtk_widget_set_sensitive (GtkWidget *widget,
8059 GtkWidgetPrivate *priv;
8061 g_return_if_fail (GTK_IS_WIDGET (widget));
8063 priv = widget->priv;
8065 sensitive = (sensitive != FALSE);
8067 if (priv->sensitive == sensitive)
8070 priv->sensitive = sensitive;
8072 if (priv->parent == NULL
8073 || gtk_widget_is_sensitive (priv->parent))
8079 data.flags_to_set = 0;
8080 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8084 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8085 data.flags_to_unset = 0;
8088 gtk_widget_propagate_state (widget, &data);
8090 gtk_widget_queue_resize (widget);
8093 g_object_notify (G_OBJECT (widget), "sensitive");
8097 * gtk_widget_get_sensitive:
8098 * @widget: a #GtkWidget
8100 * Returns the widget's sensitivity (in the sense of returning
8101 * the value that has been set using gtk_widget_set_sensitive()).
8103 * The effective sensitivity of a widget is however determined by both its
8104 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8106 * Returns: %TRUE if the widget is sensitive
8111 gtk_widget_get_sensitive (GtkWidget *widget)
8113 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8115 return widget->priv->sensitive;
8119 * gtk_widget_is_sensitive:
8120 * @widget: a #GtkWidget
8122 * Returns the widget's effective sensitivity, which means
8123 * it is sensitive itself and also its parent widget is sensitive
8125 * Returns: %TRUE if the widget is effectively sensitive
8130 gtk_widget_is_sensitive (GtkWidget *widget)
8132 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8134 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8138 * gtk_widget_set_parent:
8139 * @widget: a #GtkWidget
8140 * @parent: parent container
8142 * This function is useful only when implementing subclasses of
8144 * Sets the container as the parent of @widget, and takes care of
8145 * some details such as updating the state and style of the child
8146 * to reflect its new location. The opposite function is
8147 * gtk_widget_unparent().
8150 gtk_widget_set_parent (GtkWidget *widget,
8153 GtkStateFlags parent_flags;
8154 GtkWidgetPrivate *priv;
8157 g_return_if_fail (GTK_IS_WIDGET (widget));
8158 g_return_if_fail (GTK_IS_WIDGET (parent));
8159 g_return_if_fail (widget != parent);
8161 priv = widget->priv;
8163 if (priv->parent != NULL)
8165 g_warning ("Can't set a parent on widget which has a parent\n");
8168 if (gtk_widget_is_toplevel (widget))
8170 g_warning ("Can't set a parent on a toplevel widget\n");
8174 /* keep this function in sync with gtk_menu_attach_to_widget()
8177 g_object_ref_sink (widget);
8179 gtk_widget_push_verify_invariants (widget);
8181 priv->parent = parent;
8183 parent_flags = gtk_widget_get_state_flags (parent);
8185 /* Merge both old state and current parent state,
8186 * making sure to only propagate the right states */
8187 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8188 data.flags_to_unset = 0;
8189 gtk_widget_propagate_state (widget, &data);
8192 gtk_style_context_set_parent (priv->context,
8193 gtk_widget_get_style_context (parent));
8195 _gtk_widget_update_parent_muxer (widget);
8197 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8198 if (priv->parent->priv->anchored)
8199 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8200 g_object_notify (G_OBJECT (widget), "parent");
8202 /* Enforce realized/mapped invariants
8204 if (gtk_widget_get_realized (priv->parent))
8205 gtk_widget_realize (widget);
8207 if (gtk_widget_get_visible (priv->parent) &&
8208 gtk_widget_get_visible (widget))
8210 if (gtk_widget_get_child_visible (widget) &&
8211 gtk_widget_get_mapped (priv->parent))
8212 gtk_widget_map (widget);
8214 gtk_widget_queue_resize (widget);
8217 /* child may cause parent's expand to change, if the child is
8218 * expanded. If child is not expanded, then it can't modify the
8219 * parent's expand. If the child becomes expanded later then it will
8220 * queue compute_expand then. This optimization plus defaulting
8221 * newly-constructed widgets to need_compute_expand=FALSE should
8222 * mean that initially building a widget tree doesn't have to keep
8223 * walking up setting need_compute_expand on parents over and over.
8225 * We can't change a parent to need to expand unless we're visible.
8227 if (gtk_widget_get_visible (widget) &&
8228 (priv->need_compute_expand ||
8229 priv->computed_hexpand ||
8230 priv->computed_vexpand))
8232 gtk_widget_queue_compute_expand (parent);
8235 gtk_widget_propagate_alpha (widget);
8237 gtk_widget_pop_verify_invariants (widget);
8241 * gtk_widget_get_parent:
8242 * @widget: a #GtkWidget
8244 * Returns the parent container of @widget.
8246 * Return value: (transfer none): the parent container of @widget, or %NULL
8249 gtk_widget_get_parent (GtkWidget *widget)
8251 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8253 return widget->priv->parent;
8257 modifier_style_changed (GtkModifierStyle *style,
8260 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8263 static GtkModifierStyle *
8264 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8266 GtkModifierStyle *style;
8268 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8270 if (G_UNLIKELY (!style))
8272 GtkStyleContext *context;
8274 style = _gtk_modifier_style_new ();
8275 g_object_set_qdata_full (G_OBJECT (widget),
8276 quark_modifier_style,
8278 (GDestroyNotify) g_object_unref);
8280 g_signal_connect (style, "changed",
8281 G_CALLBACK (modifier_style_changed), widget);
8283 context = gtk_widget_get_style_context (widget);
8285 gtk_style_context_add_provider (context,
8286 GTK_STYLE_PROVIDER (style),
8287 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8294 * gtk_widget_override_color:
8295 * @widget: a #GtkWidget
8296 * @state: the state for which to set the color
8297 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8298 * of previous calls to gtk_widget_override_color()
8300 * Sets the color to use for a widget.
8302 * All other style values are left untouched.
8305 * This API is mostly meant as a quick way for applications to
8306 * change a widget appearance. If you are developing a widgets
8307 * library and intend this change to be themeable, it is better
8308 * done by setting meaningful CSS classes and regions in your
8309 * widget/container implementation through gtk_style_context_add_class()
8310 * and gtk_style_context_add_region().
8312 * This way, your widget library can install a #GtkCssProvider
8313 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8314 * to provide a default styling for those widgets that need so, and
8315 * this theming may fully overridden by the user's theme.
8318 * Note that for complex widgets this may bring in undesired
8319 * results (such as uniform background color everywhere), in
8320 * these cases it is better to fully style such widgets through a
8321 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8328 gtk_widget_override_color (GtkWidget *widget,
8329 GtkStateFlags state,
8330 const GdkRGBA *color)
8332 GtkModifierStyle *style;
8334 g_return_if_fail (GTK_IS_WIDGET (widget));
8336 style = _gtk_widget_get_modifier_properties (widget);
8337 _gtk_modifier_style_set_color (style, state, color);
8341 * gtk_widget_override_background_color:
8342 * @widget: a #GtkWidget
8343 * @state: the state for which to set the background color
8344 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8345 * of previous calls to gtk_widget_override_background_color()
8347 * Sets the background color to use for a widget.
8349 * All other style values are left untouched.
8350 * See gtk_widget_override_color().
8355 gtk_widget_override_background_color (GtkWidget *widget,
8356 GtkStateFlags state,
8357 const GdkRGBA *color)
8359 GtkModifierStyle *style;
8361 g_return_if_fail (GTK_IS_WIDGET (widget));
8363 style = _gtk_widget_get_modifier_properties (widget);
8364 _gtk_modifier_style_set_background_color (style, state, color);
8368 * gtk_widget_override_font:
8369 * @widget: a #GtkWidget
8370 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8371 * the effect of previous calls to gtk_widget_override_font()
8373 * Sets the font to use for a widget. All other style values are
8374 * left untouched. See gtk_widget_override_color().
8379 gtk_widget_override_font (GtkWidget *widget,
8380 const PangoFontDescription *font_desc)
8382 GtkModifierStyle *style;
8384 g_return_if_fail (GTK_IS_WIDGET (widget));
8386 style = _gtk_widget_get_modifier_properties (widget);
8387 _gtk_modifier_style_set_font (style, font_desc);
8391 * gtk_widget_override_symbolic_color:
8392 * @widget: a #GtkWidget
8393 * @name: the name of the symbolic color to modify
8394 * @color: (allow-none): the color to assign (does not need
8395 * to be allocated), or %NULL to undo the effect of previous
8396 * calls to gtk_widget_override_symbolic_color()
8398 * Sets a symbolic color for a widget.
8400 * All other style values are left untouched.
8401 * See gtk_widget_override_color() for overriding the foreground
8402 * or background color.
8407 gtk_widget_override_symbolic_color (GtkWidget *widget,
8409 const GdkRGBA *color)
8411 GtkModifierStyle *style;
8413 g_return_if_fail (GTK_IS_WIDGET (widget));
8415 style = _gtk_widget_get_modifier_properties (widget);
8416 _gtk_modifier_style_map_color (style, name, color);
8420 * gtk_widget_override_cursor:
8421 * @widget: a #GtkWidget
8422 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8423 * allocated), or %NULL to undo the effect of previous calls to
8424 * of gtk_widget_override_cursor().
8425 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8426 * need to be allocated), or %NULL to undo the effect of previous
8427 * calls to of gtk_widget_override_cursor().
8429 * Sets the cursor color to use in a widget, overriding the
8430 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8431 * style properties. All other style values are left untouched.
8432 * See also gtk_widget_modify_style().
8434 * Note that the underlying properties have the #GdkColor type,
8435 * so the alpha value in @primary and @secondary will be ignored.
8440 gtk_widget_override_cursor (GtkWidget *widget,
8441 const GdkRGBA *cursor,
8442 const GdkRGBA *secondary_cursor)
8444 GtkModifierStyle *style;
8446 g_return_if_fail (GTK_IS_WIDGET (widget));
8448 style = _gtk_widget_get_modifier_properties (widget);
8449 _gtk_modifier_style_set_color_property (style,
8451 "cursor-color", cursor);
8452 _gtk_modifier_style_set_color_property (style,
8454 "secondary-cursor-color",
8459 gtk_widget_real_direction_changed (GtkWidget *widget,
8460 GtkTextDirection previous_direction)
8462 gtk_widget_queue_resize (widget);
8466 gtk_widget_real_style_set (GtkWidget *widget,
8467 GtkStyle *previous_style)
8472 GtkWidget *previous_toplevel;
8473 GdkScreen *previous_screen;
8474 GdkScreen *new_screen;
8475 } HierarchyChangedInfo;
8478 do_screen_change (GtkWidget *widget,
8479 GdkScreen *old_screen,
8480 GdkScreen *new_screen)
8482 if (old_screen != new_screen)
8484 GtkWidgetPrivate *priv = widget->priv;
8488 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8490 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8493 _gtk_tooltip_hide (widget);
8495 if (new_screen && priv->context)
8496 gtk_style_context_set_screen (priv->context, new_screen);
8498 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8503 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8504 gpointer client_data)
8506 GtkWidgetPrivate *priv = widget->priv;
8507 HierarchyChangedInfo *info = client_data;
8508 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8509 (priv->parent && priv->parent->priv->anchored);
8511 if (priv->anchored != new_anchored)
8513 g_object_ref (widget);
8515 priv->anchored = new_anchored;
8517 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8518 do_screen_change (widget, info->previous_screen, info->new_screen);
8520 if (GTK_IS_CONTAINER (widget))
8521 gtk_container_forall (GTK_CONTAINER (widget),
8522 gtk_widget_propagate_hierarchy_changed_recurse,
8525 g_object_unref (widget);
8530 * _gtk_widget_propagate_hierarchy_changed:
8531 * @widget: a #GtkWidget
8532 * @previous_toplevel: Previous toplevel
8534 * Propagates changes in the anchored state to a widget and all
8535 * children, unsetting or setting the %ANCHORED flag, and
8536 * emitting #GtkWidget::hierarchy-changed.
8539 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8540 GtkWidget *previous_toplevel)
8542 GtkWidgetPrivate *priv = widget->priv;
8543 HierarchyChangedInfo info;
8545 info.previous_toplevel = previous_toplevel;
8546 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8548 if (gtk_widget_is_toplevel (widget) ||
8549 (priv->parent && priv->parent->priv->anchored))
8550 info.new_screen = gtk_widget_get_screen (widget);
8552 info.new_screen = NULL;
8554 if (info.previous_screen)
8555 g_object_ref (info.previous_screen);
8556 if (previous_toplevel)
8557 g_object_ref (previous_toplevel);
8559 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8561 if (previous_toplevel)
8562 g_object_unref (previous_toplevel);
8563 if (info.previous_screen)
8564 g_object_unref (info.previous_screen);
8568 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8569 gpointer client_data)
8571 HierarchyChangedInfo *info = client_data;
8573 g_object_ref (widget);
8575 do_screen_change (widget, info->previous_screen, info->new_screen);
8577 if (GTK_IS_CONTAINER (widget))
8578 gtk_container_forall (GTK_CONTAINER (widget),
8579 gtk_widget_propagate_screen_changed_recurse,
8582 g_object_unref (widget);
8586 * gtk_widget_is_composited:
8587 * @widget: a #GtkWidget
8589 * Whether @widget can rely on having its alpha channel
8590 * drawn correctly. On X11 this function returns whether a
8591 * compositing manager is running for @widget's screen.
8593 * Please note that the semantics of this call will change
8594 * in the future if used on a widget that has a composited
8595 * window in its hierarchy (as set by gdk_window_set_composited()).
8597 * Return value: %TRUE if the widget can rely on its alpha
8598 * channel being drawn correctly.
8603 gtk_widget_is_composited (GtkWidget *widget)
8607 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8609 screen = gtk_widget_get_screen (widget);
8611 return gdk_screen_is_composited (screen);
8615 propagate_composited_changed (GtkWidget *widget,
8618 if (GTK_IS_CONTAINER (widget))
8620 gtk_container_forall (GTK_CONTAINER (widget),
8621 propagate_composited_changed,
8625 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8629 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8631 propagate_composited_changed (widget, NULL);
8635 * _gtk_widget_propagate_screen_changed:
8636 * @widget: a #GtkWidget
8637 * @previous_screen: Previous screen
8639 * Propagates changes in the screen for a widget to all
8640 * children, emitting #GtkWidget::screen-changed.
8643 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8644 GdkScreen *previous_screen)
8646 HierarchyChangedInfo info;
8648 info.previous_screen = previous_screen;
8649 info.new_screen = gtk_widget_get_screen (widget);
8651 if (previous_screen)
8652 g_object_ref (previous_screen);
8654 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8656 if (previous_screen)
8657 g_object_unref (previous_screen);
8661 reset_style_recurse (GtkWidget *widget, gpointer data)
8663 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8665 if (GTK_IS_CONTAINER (widget))
8666 gtk_container_forall (GTK_CONTAINER (widget),
8667 reset_style_recurse,
8672 * gtk_widget_reset_style:
8673 * @widget: a #GtkWidget
8675 * Updates the style context of @widget and all descendents
8676 * by updating its widget path. #GtkContainer<!-- -->s may want
8677 * to use this on a child when reordering it in a way that a different
8678 * style might apply to it. See also gtk_container_get_path_for_child().
8683 gtk_widget_reset_style (GtkWidget *widget)
8685 g_return_if_fail (GTK_IS_WIDGET (widget));
8687 reset_style_recurse (widget, NULL);
8689 g_list_foreach (widget->priv->attached_windows,
8690 (GFunc) reset_style_recurse, NULL);
8693 #ifdef G_ENABLE_DEBUG
8695 /* Verify invariants, see docs/widget_system.txt for notes on much of
8696 * this. Invariants may be temporarily broken while we're in the
8697 * process of updating state, of course, so you can only
8698 * verify_invariants() after a given operation is complete.
8699 * Use push/pop_verify_invariants to help with that.
8702 gtk_widget_verify_invariants (GtkWidget *widget)
8706 if (widget->priv->verifying_invariants_count > 0)
8709 parent = widget->priv->parent;
8711 if (widget->priv->mapped)
8713 /* Mapped implies ... */
8715 if (!widget->priv->realized)
8716 g_warning ("%s %p is mapped but not realized",
8717 G_OBJECT_TYPE_NAME (widget), widget);
8719 if (!widget->priv->visible)
8720 g_warning ("%s %p is mapped but not visible",
8721 G_OBJECT_TYPE_NAME (widget), widget);
8723 if (!widget->priv->toplevel)
8725 if (!widget->priv->child_visible)
8726 g_warning ("%s %p is mapped but not child_visible",
8727 G_OBJECT_TYPE_NAME (widget), widget);
8732 /* Not mapped implies... */
8735 /* This check makes sense for normal toplevels, but for
8736 * something like a toplevel that is embedded within a clutter
8737 * state, mapping may depend on external factors.
8739 if (widget->priv->toplevel)
8741 if (widget->priv->visible)
8742 g_warning ("%s %p toplevel is visible but not mapped",
8743 G_OBJECT_TYPE_NAME (widget), widget);
8748 /* Parent related checks aren't possible if parent has
8749 * verifying_invariants_count > 0 because parent needs to recurse
8750 * children first before the invariants will hold.
8752 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
8755 parent->priv->realized)
8757 /* Parent realized implies... */
8760 /* This is in widget_system.txt but appears to fail
8761 * because there's no gtk_container_realize() that
8762 * realizes all children... instead we just lazily
8763 * wait for map to fix things up.
8765 if (!widget->priv->realized)
8766 g_warning ("%s %p is realized but child %s %p is not realized",
8767 G_OBJECT_TYPE_NAME (parent), parent,
8768 G_OBJECT_TYPE_NAME (widget), widget);
8771 else if (!widget->priv->toplevel)
8773 /* No parent or parent not realized on non-toplevel implies... */
8775 if (widget->priv->realized && !widget->priv->in_reparent)
8776 g_warning ("%s %p is not realized but child %s %p is realized",
8777 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8778 G_OBJECT_TYPE_NAME (widget), widget);
8782 parent->priv->mapped &&
8783 widget->priv->visible &&
8784 widget->priv->child_visible)
8786 /* Parent mapped and we are visible implies... */
8788 if (!widget->priv->mapped)
8789 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
8790 G_OBJECT_TYPE_NAME (parent), parent,
8791 G_OBJECT_TYPE_NAME (widget), widget);
8793 else if (!widget->priv->toplevel)
8795 /* No parent or parent not mapped on non-toplevel implies... */
8797 if (widget->priv->mapped && !widget->priv->in_reparent)
8798 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
8799 G_OBJECT_TYPE_NAME (widget), widget,
8800 widget->priv->visible,
8801 widget->priv->child_visible,
8802 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
8803 parent ? parent->priv->mapped : FALSE);
8807 if (!widget->priv->realized)
8809 /* Not realized implies... */
8812 /* widget_system.txt says these hold, but they don't. */
8813 if (widget->priv->alloc_needed)
8814 g_warning ("%s %p alloc needed but not realized",
8815 G_OBJECT_TYPE_NAME (widget), widget);
8817 if (widget->priv->width_request_needed)
8818 g_warning ("%s %p width request needed but not realized",
8819 G_OBJECT_TYPE_NAME (widget), widget);
8821 if (widget->priv->height_request_needed)
8822 g_warning ("%s %p height request needed but not realized",
8823 G_OBJECT_TYPE_NAME (widget), widget);
8828 /* The point of this push/pop is that invariants may not hold while
8829 * we're busy making changes. So we only check at the outermost call
8830 * on the call stack, after we finish updating everything.
8833 gtk_widget_push_verify_invariants (GtkWidget *widget)
8835 widget->priv->verifying_invariants_count += 1;
8839 gtk_widget_verify_child_invariants (GtkWidget *widget,
8840 gpointer client_data)
8842 /* We don't recurse further; this is a one-level check. */
8843 gtk_widget_verify_invariants (widget);
8847 gtk_widget_pop_verify_invariants (GtkWidget *widget)
8849 g_assert (widget->priv->verifying_invariants_count > 0);
8851 widget->priv->verifying_invariants_count -= 1;
8853 if (widget->priv->verifying_invariants_count == 0)
8855 gtk_widget_verify_invariants (widget);
8857 if (GTK_IS_CONTAINER (widget))
8859 /* Check one level of children, because our
8860 * push_verify_invariants() will have prevented some of the
8861 * checks. This does not recurse because if recursion is
8862 * needed, it will happen naturally as each child has a
8863 * push/pop on that child. For example if we're recursively
8864 * mapping children, we'll push/pop on each child as we map
8867 gtk_container_forall (GTK_CONTAINER (widget),
8868 gtk_widget_verify_child_invariants,
8873 #endif /* G_ENABLE_DEBUG */
8875 static PangoContext *
8876 gtk_widget_peek_pango_context (GtkWidget *widget)
8878 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8882 * gtk_widget_get_pango_context:
8883 * @widget: a #GtkWidget
8885 * Gets a #PangoContext with the appropriate font map, font description,
8886 * and base direction for this widget. Unlike the context returned
8887 * by gtk_widget_create_pango_context(), this context is owned by
8888 * the widget (it can be used until the screen for the widget changes
8889 * or the widget is removed from its toplevel), and will be updated to
8890 * match any changes to the widget's attributes. This can be tracked
8891 * by using the #GtkWidget::screen-changed signal on the widget.
8893 * Return value: (transfer none): the #PangoContext for the widget.
8896 gtk_widget_get_pango_context (GtkWidget *widget)
8898 PangoContext *context;
8900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8902 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8905 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8906 g_object_set_qdata_full (G_OBJECT (widget),
8907 quark_pango_context,
8916 update_pango_context (GtkWidget *widget,
8917 PangoContext *context)
8919 PangoFontDescription *font_desc;
8920 GtkStyleContext *style_context;
8922 style_context = gtk_widget_get_style_context (widget);
8923 gtk_style_context_get (style_context,
8924 gtk_widget_get_state_flags (widget),
8928 pango_context_set_font_description (context, font_desc);
8929 pango_context_set_base_dir (context,
8930 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8931 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8933 pango_font_description_free (font_desc);
8937 gtk_widget_update_pango_context (GtkWidget *widget)
8939 PangoContext *context = gtk_widget_peek_pango_context (widget);
8945 update_pango_context (widget, context);
8947 screen = gtk_widget_get_screen_unchecked (widget);
8950 pango_cairo_context_set_resolution (context,
8951 gdk_screen_get_resolution (screen));
8952 pango_cairo_context_set_font_options (context,
8953 gdk_screen_get_font_options (screen));
8959 * gtk_widget_create_pango_context:
8960 * @widget: a #GtkWidget
8962 * Creates a new #PangoContext with the appropriate font map,
8963 * font description, and base direction for drawing text for
8964 * this widget. See also gtk_widget_get_pango_context().
8966 * Return value: (transfer full): the new #PangoContext
8969 gtk_widget_create_pango_context (GtkWidget *widget)
8972 PangoContext *context;
8974 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8976 screen = gtk_widget_get_screen_unchecked (widget);
8979 GTK_NOTE (MULTIHEAD,
8980 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8982 screen = gdk_screen_get_default ();
8985 context = gdk_pango_context_get_for_screen (screen);
8987 update_pango_context (widget, context);
8988 pango_context_set_language (context, gtk_get_default_language ());
8994 * gtk_widget_create_pango_layout:
8995 * @widget: a #GtkWidget
8996 * @text: text to set on the layout (can be %NULL)
8998 * Creates a new #PangoLayout with the appropriate font map,
8999 * font description, and base direction for drawing text for
9002 * If you keep a #PangoLayout created in this way around, you need
9003 * to re-create it when the widget #PangoContext is replaced.
9004 * This can be tracked by using the #GtkWidget::screen-changed signal
9007 * Return value: (transfer full): the new #PangoLayout
9010 gtk_widget_create_pango_layout (GtkWidget *widget,
9013 PangoLayout *layout;
9014 PangoContext *context;
9016 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9018 context = gtk_widget_get_pango_context (widget);
9019 layout = pango_layout_new (context);
9022 pango_layout_set_text (layout, text, -1);
9028 * gtk_widget_render_icon_pixbuf:
9029 * @widget: a #GtkWidget
9030 * @stock_id: a stock ID
9031 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9032 * render at the size of the source and don't scale (if there are
9033 * multiple source sizes, GTK+ picks one of the available sizes).
9035 * A convenience function that uses the theme engine and style
9036 * settings for @widget to look up @stock_id and render it to
9037 * a pixbuf. @stock_id should be a stock icon ID such as
9038 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9039 * such as #GTK_ICON_SIZE_MENU.
9041 * The pixels in the returned #GdkPixbuf are shared with the rest of
9042 * the application and should not be modified. The pixbuf should be freed
9043 * after use with g_object_unref().
9045 * Return value: (transfer full): a new pixbuf, or %NULL if the
9046 * stock ID wasn't known
9051 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9052 const gchar *stock_id,
9055 GtkStyleContext *context;
9056 GtkIconSet *icon_set;
9058 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9059 g_return_val_if_fail (stock_id != NULL, NULL);
9060 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9062 context = gtk_widget_get_style_context (widget);
9063 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9065 if (icon_set == NULL)
9068 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9072 * gtk_widget_set_parent_window:
9073 * @widget: a #GtkWidget.
9074 * @parent_window: the new parent window.
9076 * Sets a non default parent window for @widget.
9078 * For GtkWindow classes, setting a @parent_window effects whether
9079 * the window is a toplevel window or can be embedded into other
9083 * For GtkWindow classes, this needs to be called before the
9084 * window is realized.
9089 gtk_widget_set_parent_window (GtkWidget *widget,
9090 GdkWindow *parent_window)
9092 GdkWindow *old_parent_window;
9094 g_return_if_fail (GTK_IS_WIDGET (widget));
9096 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9097 quark_parent_window);
9099 if (parent_window != old_parent_window)
9103 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9105 if (old_parent_window)
9106 g_object_unref (old_parent_window);
9108 g_object_ref (parent_window);
9110 /* Unset toplevel flag when adding a parent window to a widget,
9111 * this is the primary entry point to allow toplevels to be
9114 #ifdef GDK_WINDOWING_X11
9115 is_plug = GTK_IS_PLUG (widget);
9119 if (GTK_IS_WINDOW (widget) && !is_plug)
9120 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9125 * gtk_widget_get_parent_window:
9126 * @widget: a #GtkWidget.
9128 * Gets @widget's parent window.
9130 * Returns: (transfer none): the parent window of @widget.
9133 gtk_widget_get_parent_window (GtkWidget *widget)
9135 GtkWidgetPrivate *priv;
9136 GdkWindow *parent_window;
9138 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9140 priv = widget->priv;
9142 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9144 return (parent_window != NULL) ? parent_window :
9145 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9150 * gtk_widget_set_child_visible:
9151 * @widget: a #GtkWidget
9152 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9154 * Sets whether @widget should be mapped along with its when its parent
9155 * is mapped and @widget has been shown with gtk_widget_show().
9157 * The child visibility can be set for widget before it is added to
9158 * a container with gtk_widget_set_parent(), to avoid mapping
9159 * children unnecessary before immediately unmapping them. However
9160 * it will be reset to its default state of %TRUE when the widget
9161 * is removed from a container.
9163 * Note that changing the child visibility of a widget does not
9164 * queue a resize on the widget. Most of the time, the size of
9165 * a widget is computed from all visible children, whether or
9166 * not they are mapped. If this is not the case, the container
9167 * can queue a resize itself.
9169 * This function is only useful for container implementations and
9170 * never should be called by an application.
9173 gtk_widget_set_child_visible (GtkWidget *widget,
9174 gboolean is_visible)
9176 GtkWidgetPrivate *priv;
9178 g_return_if_fail (GTK_IS_WIDGET (widget));
9179 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9181 priv = widget->priv;
9183 g_object_ref (widget);
9184 gtk_widget_verify_invariants (widget);
9187 priv->child_visible = TRUE;
9190 GtkWidget *toplevel;
9192 priv->child_visible = FALSE;
9194 toplevel = gtk_widget_get_toplevel (widget);
9195 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9196 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9199 if (priv->parent && gtk_widget_get_realized (priv->parent))
9201 if (gtk_widget_get_mapped (priv->parent) &&
9202 priv->child_visible &&
9203 gtk_widget_get_visible (widget))
9204 gtk_widget_map (widget);
9206 gtk_widget_unmap (widget);
9209 gtk_widget_verify_invariants (widget);
9210 g_object_unref (widget);
9214 * gtk_widget_get_child_visible:
9215 * @widget: a #GtkWidget
9217 * Gets the value set with gtk_widget_set_child_visible().
9218 * If you feel a need to use this function, your code probably
9219 * needs reorganization.
9221 * This function is only useful for container implementations and
9222 * never should be called by an application.
9224 * Return value: %TRUE if the widget is mapped with the parent.
9227 gtk_widget_get_child_visible (GtkWidget *widget)
9229 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9231 return widget->priv->child_visible;
9235 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9237 GtkWidget *toplevel;
9239 toplevel = gtk_widget_get_toplevel (widget);
9241 if (gtk_widget_is_toplevel (toplevel))
9243 if (GTK_IS_WINDOW (toplevel))
9244 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9245 else if (GTK_IS_INVISIBLE (toplevel))
9246 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9253 * gtk_widget_get_screen:
9254 * @widget: a #GtkWidget
9256 * Get the #GdkScreen from the toplevel window associated with
9257 * this widget. This function can only be called after the widget
9258 * has been added to a widget hierarchy with a #GtkWindow
9261 * In general, you should only create screen specific
9262 * resources when a widget has been realized, and you should
9263 * free those resources when the widget is unrealized.
9265 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9270 gtk_widget_get_screen (GtkWidget *widget)
9274 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9276 screen = gtk_widget_get_screen_unchecked (widget);
9283 g_warning (G_STRLOC ": Can't get associated screen"
9284 " for a widget unless it is inside a toplevel GtkWindow\n"
9285 " widget type is %s associated top level type is %s",
9286 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9287 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9289 return gdk_screen_get_default ();
9294 * gtk_widget_has_screen:
9295 * @widget: a #GtkWidget
9297 * Checks whether there is a #GdkScreen is associated with
9298 * this widget. All toplevel widgets have an associated
9299 * screen, and all widgets added into a hierarchy with a toplevel
9300 * window at the top.
9302 * Return value: %TRUE if there is a #GdkScreen associcated
9308 gtk_widget_has_screen (GtkWidget *widget)
9310 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9312 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9316 * gtk_widget_get_display:
9317 * @widget: a #GtkWidget
9319 * Get the #GdkDisplay for the toplevel window associated with
9320 * this widget. This function can only be called after the widget
9321 * has been added to a widget hierarchy with a #GtkWindow at the top.
9323 * In general, you should only create display specific
9324 * resources when a widget has been realized, and you should
9325 * free those resources when the widget is unrealized.
9327 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9332 gtk_widget_get_display (GtkWidget *widget)
9334 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9336 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9340 * gtk_widget_get_root_window:
9341 * @widget: a #GtkWidget
9343 * Get the root window where this widget is located. This function can
9344 * only be called after the widget has been added to a widget
9345 * hierarchy with #GtkWindow at the top.
9347 * The root window is useful for such purposes as creating a popup
9348 * #GdkWindow associated with the window. In general, you should only
9349 * create display specific resources when a widget has been realized,
9350 * and you should free those resources when the widget is unrealized.
9352 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9357 gtk_widget_get_root_window (GtkWidget *widget)
9359 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9361 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9365 * gtk_widget_child_focus:
9366 * @widget: a #GtkWidget
9367 * @direction: direction of focus movement
9369 * This function is used by custom widget implementations; if you're
9370 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9371 * to a particular widget, and gtk_container_set_focus_chain() to
9372 * change the focus tab order. So you may want to investigate those
9373 * functions instead.
9375 * gtk_widget_child_focus() is called by containers as the user moves
9376 * around the window using keyboard shortcuts. @direction indicates
9377 * what kind of motion is taking place (up, down, left, right, tab
9378 * forward, tab backward). gtk_widget_child_focus() emits the
9379 * #GtkWidget::focus signal; widgets override the default handler
9380 * for this signal in order to implement appropriate focus behavior.
9382 * The default ::focus handler for a widget should return %TRUE if
9383 * moving in @direction left the focus on a focusable location inside
9384 * that widget, and %FALSE if moving in @direction moved the focus
9385 * outside the widget. If returning %TRUE, widgets normally
9386 * call gtk_widget_grab_focus() to place the focus accordingly;
9387 * if returning %FALSE, they don't modify the current focus location.
9389 * Return value: %TRUE if focus ended up inside @widget
9392 gtk_widget_child_focus (GtkWidget *widget,
9393 GtkDirectionType direction)
9395 gboolean return_val;
9397 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9399 if (!gtk_widget_get_visible (widget) ||
9400 !gtk_widget_is_sensitive (widget))
9403 /* child widgets must set CAN_FOCUS, containers
9404 * don't have to though.
9406 if (!GTK_IS_CONTAINER (widget) &&
9407 !gtk_widget_get_can_focus (widget))
9410 g_signal_emit (widget,
9411 widget_signals[FOCUS],
9413 direction, &return_val);
9419 * gtk_widget_keynav_failed:
9420 * @widget: a #GtkWidget
9421 * @direction: direction of focus movement
9423 * This function should be called whenever keyboard navigation within
9424 * a single widget hits a boundary. The function emits the
9425 * #GtkWidget::keynav-failed signal on the widget and its return
9426 * value should be interpreted in a way similar to the return value of
9427 * gtk_widget_child_focus():
9429 * When %TRUE is returned, stay in the widget, the failed keyboard
9430 * navigation is Ok and/or there is nowhere we can/should move the
9433 * When %FALSE is returned, the caller should continue with keyboard
9434 * navigation outside the widget, e.g. by calling
9435 * gtk_widget_child_focus() on the widget's toplevel.
9437 * The default ::keynav-failed handler returns %TRUE for
9438 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9439 * values of #GtkDirectionType, it looks at the
9440 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9441 * if the setting is %TRUE. This way the entire user interface
9442 * becomes cursor-navigatable on input devices such as mobile phones
9443 * which only have cursor keys but no tab key.
9445 * Whenever the default handler returns %TRUE, it also calls
9446 * gtk_widget_error_bell() to notify the user of the failed keyboard
9449 * A use case for providing an own implementation of ::keynav-failed
9450 * (either by connecting to it or by overriding it) would be a row of
9451 * #GtkEntry widgets where the user should be able to navigate the
9452 * entire row with the cursor keys, as e.g. known from user interfaces
9453 * that require entering license keys.
9455 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9456 * if the emitting widget should try to handle the keyboard
9457 * navigation attempt in its parent container(s).
9462 gtk_widget_keynav_failed (GtkWidget *widget,
9463 GtkDirectionType direction)
9465 gboolean return_val;
9467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9469 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9470 direction, &return_val);
9476 * gtk_widget_error_bell:
9477 * @widget: a #GtkWidget
9479 * Notifies the user about an input-related error on this widget.
9480 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9481 * gdk_window_beep(), otherwise it does nothing.
9483 * Note that the effect of gdk_window_beep() can be configured in many
9484 * ways, depending on the windowing backend and the desktop environment
9485 * or window manager that is used.
9490 gtk_widget_error_bell (GtkWidget *widget)
9492 GtkWidgetPrivate *priv;
9493 GtkSettings* settings;
9496 g_return_if_fail (GTK_IS_WIDGET (widget));
9498 priv = widget->priv;
9500 settings = gtk_widget_get_settings (widget);
9504 g_object_get (settings,
9505 "gtk-error-bell", &beep,
9508 if (beep && priv->window)
9509 gdk_window_beep (priv->window);
9513 gtk_widget_set_usize_internal (GtkWidget *widget,
9516 GtkQueueResizeFlags flags)
9518 GtkWidgetAuxInfo *aux_info;
9519 gboolean changed = FALSE;
9521 g_object_freeze_notify (G_OBJECT (widget));
9523 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9525 if (width > -2 && aux_info->width != width)
9527 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9528 g_object_notify (G_OBJECT (widget), "width-request");
9529 aux_info->width = width;
9532 if (height > -2 && aux_info->height != height)
9534 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9535 g_object_notify (G_OBJECT (widget), "height-request");
9536 aux_info->height = height;
9540 if (gtk_widget_get_visible (widget) && changed)
9542 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9543 gtk_widget_queue_resize (widget);
9545 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9548 g_object_thaw_notify (G_OBJECT (widget));
9552 * gtk_widget_set_size_request:
9553 * @widget: a #GtkWidget
9554 * @width: width @widget should request, or -1 to unset
9555 * @height: height @widget should request, or -1 to unset
9557 * Sets the minimum size of a widget; that is, the widget's size
9558 * request will be at least @width by @height. You can use this
9559 * function to force a widget to be larger than it normally would be.
9561 * In most cases, gtk_window_set_default_size() is a better choice for
9562 * toplevel windows than this function; setting the default size will
9563 * still allow users to shrink the window. Setting the size request
9564 * will force them to leave the window at least as large as the size
9565 * request. When dealing with window sizes,
9566 * gtk_window_set_geometry_hints() can be a useful function as well.
9568 * Note the inherent danger of setting any fixed size - themes,
9569 * translations into other languages, different fonts, and user action
9570 * can all change the appropriate size for a given widget. So, it's
9571 * basically impossible to hardcode a size that will always be
9574 * The size request of a widget is the smallest size a widget can
9575 * accept while still functioning well and drawing itself correctly.
9576 * However in some strange cases a widget may be allocated less than
9577 * its requested size, and in many cases a widget may be allocated more
9578 * space than it requested.
9580 * If the size request in a given direction is -1 (unset), then
9581 * the "natural" size request of the widget will be used instead.
9583 * The size request set here does not include any margin from the
9584 * #GtkWidget properties margin-left, margin-right, margin-top, and
9585 * margin-bottom, but it does include pretty much all other padding
9586 * or border properties set by any subclass of #GtkWidget.
9589 gtk_widget_set_size_request (GtkWidget *widget,
9593 g_return_if_fail (GTK_IS_WIDGET (widget));
9594 g_return_if_fail (width >= -1);
9595 g_return_if_fail (height >= -1);
9602 gtk_widget_set_usize_internal (widget, width, height, 0);
9607 * gtk_widget_get_size_request:
9608 * @widget: a #GtkWidget
9609 * @width: (out) (allow-none): return location for width, or %NULL
9610 * @height: (out) (allow-none): return location for height, or %NULL
9612 * Gets the size request that was explicitly set for the widget using
9613 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9614 * @height indicates that that dimension has not been set explicitly
9615 * and the natural requisition of the widget will be used intead. See
9616 * gtk_widget_set_size_request(). To get the size a widget will
9617 * actually request, call gtk_widget_get_preferred_size() instead of
9621 gtk_widget_get_size_request (GtkWidget *widget,
9625 const GtkWidgetAuxInfo *aux_info;
9627 g_return_if_fail (GTK_IS_WIDGET (widget));
9629 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9632 *width = aux_info->width;
9635 *height = aux_info->height;
9639 * _gtk_widget_override_size_request:
9640 * @widget: a #GtkWidget
9641 * @width: new forced minimum width
9642 * @height: new forced minimum height
9643 * @old_width: location to store previous forced minimum width
9644 * @old_height: location to store previous forced minumum height
9646 * Temporarily establishes a forced minimum size for a widget; this
9647 * is used by GtkWindow when calculating the size to add to the
9648 * window's geometry widget. Cached sizes for the widget and its
9649 * parents are invalidated, so that subsequent calls to the size
9650 * negotiation machinery produce the overriden result, but the
9651 * widget is not queued for relayout or redraw. The old size must
9652 * be restored with _gtk_widget_restore_size_request() or things
9656 _gtk_widget_override_size_request (GtkWidget *widget,
9662 gtk_widget_get_size_request (widget, old_width, old_height);
9663 gtk_widget_set_usize_internal (widget, width, height,
9664 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9668 * _gtk_widget_restore_size_request:
9669 * @widget: a #GtkWidget
9670 * @old_width: saved forced minimum size
9671 * @old_height: saved forced minimum size
9673 * Undoes the operation of_gtk_widget_override_size_request().
9676 _gtk_widget_restore_size_request (GtkWidget *widget,
9680 gtk_widget_set_usize_internal (widget, old_width, old_height,
9681 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9685 * gtk_widget_set_events:
9686 * @widget: a #GtkWidget
9687 * @events: event mask
9689 * Sets the event mask (see #GdkEventMask) for a widget. The event
9690 * mask determines which events a widget will receive. Keep in mind
9691 * that different widgets have different default event masks, and by
9692 * changing the event mask you may disrupt a widget's functionality,
9693 * so be careful. This function must be called while a widget is
9694 * unrealized. Consider gtk_widget_add_events() for widgets that are
9695 * already realized, or if you want to preserve the existing event
9696 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9697 * to get events on those widgets, place them inside a #GtkEventBox
9698 * and receive events on the event box.
9701 gtk_widget_set_events (GtkWidget *widget,
9704 g_return_if_fail (GTK_IS_WIDGET (widget));
9705 g_return_if_fail (!gtk_widget_get_realized (widget));
9707 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9708 GINT_TO_POINTER (events));
9709 g_object_notify (G_OBJECT (widget), "events");
9713 * gtk_widget_set_device_events:
9714 * @widget: a #GtkWidget
9715 * @device: a #GdkDevice
9716 * @events: event mask
9718 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9719 * mask determines which events a widget will receive from @device. Keep
9720 * in mind that different widgets have different default event masks, and by
9721 * changing the event mask you may disrupt a widget's functionality,
9722 * so be careful. This function must be called while a widget is
9723 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9724 * already realized, or if you want to preserve the existing event
9725 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9726 * to get events on those widgets, place them inside a #GtkEventBox
9727 * and receive events on the event box.
9732 gtk_widget_set_device_events (GtkWidget *widget,
9734 GdkEventMask events)
9736 GHashTable *device_events;
9738 g_return_if_fail (GTK_IS_WIDGET (widget));
9739 g_return_if_fail (GDK_IS_DEVICE (device));
9740 g_return_if_fail (!gtk_widget_get_realized (widget));
9742 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9744 if (G_UNLIKELY (!device_events))
9746 device_events = g_hash_table_new (NULL, NULL);
9747 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9748 (GDestroyNotify) g_hash_table_unref);
9751 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9755 * gtk_widget_set_device_enabled:
9756 * @widget: a #GtkWidget
9757 * @device: a #GdkDevice
9758 * @enabled: whether to enable the device
9760 * Enables or disables a #GdkDevice to interact with @widget
9761 * and all its children.
9763 * It does so by descending through the #GdkWindow hierarchy
9764 * and enabling the same mask that is has for core events
9765 * (i.e. the one that gdk_window_get_events() returns).
9770 gtk_widget_set_device_enabled (GtkWidget *widget,
9774 GList *enabled_devices;
9776 g_return_if_fail (GTK_IS_WIDGET (widget));
9777 g_return_if_fail (GDK_IS_DEVICE (device));
9779 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9780 enabled_devices = g_list_append (enabled_devices, device);
9782 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
9783 enabled_devices, (GDestroyNotify) g_list_free);;
9785 if (gtk_widget_get_realized (widget))
9786 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
9790 * gtk_widget_get_device_enabled:
9791 * @widget: a #GtkWidget
9792 * @device: a #GdkDevice
9794 * Returns whether @device can interact with @widget and its
9795 * children. See gtk_widget_set_device_enabled().
9797 * Return value: %TRUE is @device is enabled for @widget
9802 gtk_widget_get_device_enabled (GtkWidget *widget,
9805 GList *enabled_devices;
9807 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9808 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
9810 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
9812 return g_list_find (enabled_devices, device) != NULL;
9816 gtk_widget_add_events_internal_list (GtkWidget *widget,
9823 for (l = window_list; l != NULL; l = l->next)
9825 GdkWindow *window = l->data;
9828 gdk_window_get_user_data (window, &user_data);
9829 if (user_data == widget)
9834 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9836 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9838 children = gdk_window_get_children (window);
9839 gtk_widget_add_events_internal_list (widget, device, events, children);
9840 g_list_free (children);
9846 gtk_widget_add_events_internal (GtkWidget *widget,
9850 GtkWidgetPrivate *priv = widget->priv;
9853 if (!gtk_widget_get_has_window (widget))
9854 window_list = gdk_window_get_children (priv->window);
9856 window_list = g_list_prepend (NULL, priv->window);
9858 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9860 g_list_free (window_list);
9864 * gtk_widget_add_events:
9865 * @widget: a #GtkWidget
9866 * @events: an event mask, see #GdkEventMask
9868 * Adds the events in the bitfield @events to the event mask for
9869 * @widget. See gtk_widget_set_events() for details.
9872 gtk_widget_add_events (GtkWidget *widget,
9877 g_return_if_fail (GTK_IS_WIDGET (widget));
9879 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9880 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9881 GINT_TO_POINTER (old_events | events));
9883 if (gtk_widget_get_realized (widget))
9885 gtk_widget_add_events_internal (widget, NULL, events);
9886 gtk_widget_update_devices_mask (widget, FALSE);
9889 g_object_notify (G_OBJECT (widget), "events");
9893 * gtk_widget_add_device_events:
9894 * @widget: a #GtkWidget
9895 * @device: a #GdkDevice
9896 * @events: an event mask, see #GdkEventMask
9898 * Adds the device events in the bitfield @events to the event mask for
9899 * @widget. See gtk_widget_set_device_events() for details.
9904 gtk_widget_add_device_events (GtkWidget *widget,
9906 GdkEventMask events)
9908 GdkEventMask old_events;
9909 GHashTable *device_events;
9911 g_return_if_fail (GTK_IS_WIDGET (widget));
9912 g_return_if_fail (GDK_IS_DEVICE (device));
9914 old_events = gtk_widget_get_device_events (widget, device);
9916 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9918 if (G_UNLIKELY (!device_events))
9920 device_events = g_hash_table_new (NULL, NULL);
9921 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9922 (GDestroyNotify) g_hash_table_unref);
9925 g_hash_table_insert (device_events, device,
9926 GUINT_TO_POINTER (old_events | events));
9928 if (gtk_widget_get_realized (widget))
9929 gtk_widget_add_events_internal (widget, device, events);
9931 g_object_notify (G_OBJECT (widget), "events");
9935 * gtk_widget_get_toplevel:
9936 * @widget: a #GtkWidget
9938 * This function returns the topmost widget in the container hierarchy
9939 * @widget is a part of. If @widget has no parent widgets, it will be
9940 * returned as the topmost widget. No reference will be added to the
9941 * returned widget; it should not be unreferenced.
9943 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9944 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9946 * %NULL if @widget wasn't inside a toplevel window, and if the
9947 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
9948 * inside the toplevel #GtkWindow. While the second case may
9949 * seem unlikely, it actually happens when a #GtkPlug is embedded
9950 * inside a #GtkSocket within the same application.
9952 * To reliably find the toplevel #GtkWindow, use
9953 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9954 * is set on the result.
9956 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9957 * if (gtk_widget_is_toplevel (toplevel))
9959 * /* Perform action on toplevel. */
9963 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9964 * if there's no ancestor.
9967 gtk_widget_get_toplevel (GtkWidget *widget)
9969 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9971 while (widget->priv->parent)
9972 widget = widget->priv->parent;
9978 * gtk_widget_get_ancestor:
9979 * @widget: a #GtkWidget
9980 * @widget_type: ancestor type
9982 * Gets the first ancestor of @widget with type @widget_type. For example,
9983 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9984 * the first #GtkBox that's an ancestor of @widget. No reference will be
9985 * added to the returned widget; it should not be unreferenced. See note
9986 * about checking for a toplevel #GtkWindow in the docs for
9987 * gtk_widget_get_toplevel().
9989 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9990 * considers @widget to be an ancestor of itself.
9992 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9995 gtk_widget_get_ancestor (GtkWidget *widget,
9998 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10000 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10001 widget = widget->priv->parent;
10003 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10010 * gtk_widget_set_visual:
10011 * @widget: a #GtkWidget
10012 * @visual: visual to be used or %NULL to unset a previous one
10014 * Sets the visual that should be used for by widget and its children for
10015 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10016 * returned by gtk_widget_get_screen(), so handling the
10017 * #GtkWidget::screen-changed signal is necessary.
10019 * Setting a new @visual will not cause @widget to recreate its windows,
10020 * so you should call this function before @widget is realized.
10023 gtk_widget_set_visual (GtkWidget *widget,
10026 g_return_if_fail (GTK_IS_WIDGET (widget));
10027 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10030 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10033 g_object_set_qdata_full (G_OBJECT (widget),
10035 g_object_ref (visual),
10040 * gtk_widget_get_visual:
10041 * @widget: a #GtkWidget
10043 * Gets the visual that will be used to render @widget.
10045 * Return value: (transfer none): the visual for @widget
10048 gtk_widget_get_visual (GtkWidget *widget)
10054 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10056 if (gtk_widget_get_has_window (widget) &&
10057 widget->priv->window)
10058 return gdk_window_get_visual (widget->priv->window);
10060 screen = gtk_widget_get_screen (widget);
10062 for (w = widget; w != NULL; w = w->priv->parent)
10064 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10067 if (gdk_visual_get_screen (visual) == screen)
10070 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10071 gtk_widget_get_name (widget));
10075 return gdk_screen_get_system_visual (screen);
10079 * gtk_widget_get_settings:
10080 * @widget: a #GtkWidget
10082 * Gets the settings object holding the settings used for this widget.
10084 * Note that this function can only be called when the #GtkWidget
10085 * is attached to a toplevel, since the settings object is specific
10086 * to a particular #GdkScreen.
10088 * Return value: (transfer none): the relevant #GtkSettings object
10091 gtk_widget_get_settings (GtkWidget *widget)
10093 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10095 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10099 * gtk_widget_get_events:
10100 * @widget: a #GtkWidget
10102 * Returns the event mask for the widget (a bitfield containing flags
10103 * from the #GdkEventMask enumeration). These are the events that the widget
10106 * Return value: event mask for @widget
10109 gtk_widget_get_events (GtkWidget *widget)
10111 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10113 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10117 * gtk_widget_get_device_events:
10118 * @widget: a #GtkWidget
10119 * @device: a #GdkDevice
10121 * Returns the events mask for the widget corresponding to an specific device. These
10122 * are the events that the widget will receive when @device operates on it.
10124 * Returns: device event mask for @widget
10129 gtk_widget_get_device_events (GtkWidget *widget,
10132 GHashTable *device_events;
10134 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10135 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10137 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10139 if (!device_events)
10142 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10146 * gtk_widget_get_pointer:
10147 * @widget: a #GtkWidget
10148 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10149 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10151 * Obtains the location of the mouse pointer in widget coordinates.
10152 * Widget coordinates are a bit odd; for historical reasons, they are
10153 * defined as @widget->window coordinates for widgets that are not
10154 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10155 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10157 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10160 gtk_widget_get_pointer (GtkWidget *widget,
10164 GtkWidgetPrivate *priv;
10166 g_return_if_fail (GTK_IS_WIDGET (widget));
10168 priv = widget->priv;
10175 if (gtk_widget_get_realized (widget))
10177 gdk_window_get_device_position (priv->window,
10178 gdk_device_manager_get_client_pointer (
10179 gdk_display_get_device_manager (
10180 gtk_widget_get_display (widget))),
10183 if (!gtk_widget_get_has_window (widget))
10186 *x -= priv->allocation.x;
10188 *y -= priv->allocation.y;
10194 * gtk_widget_is_ancestor:
10195 * @widget: a #GtkWidget
10196 * @ancestor: another #GtkWidget
10198 * Determines whether @widget is somewhere inside @ancestor, possibly with
10199 * intermediate containers.
10201 * Return value: %TRUE if @ancestor contains @widget as a child,
10202 * grandchild, great grandchild, etc.
10205 gtk_widget_is_ancestor (GtkWidget *widget,
10206 GtkWidget *ancestor)
10208 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10209 g_return_val_if_fail (ancestor != NULL, FALSE);
10213 if (widget->priv->parent == ancestor)
10215 widget = widget->priv->parent;
10221 static GQuark quark_composite_name = 0;
10224 * gtk_widget_set_composite_name:
10225 * @widget: a #GtkWidget.
10226 * @name: the name to set
10228 * Sets a widgets composite name. The widget must be
10229 * a composite child of its parent; see gtk_widget_push_composite_child().
10232 gtk_widget_set_composite_name (GtkWidget *widget,
10235 g_return_if_fail (GTK_IS_WIDGET (widget));
10236 g_return_if_fail (widget->priv->composite_child);
10237 g_return_if_fail (name != NULL);
10239 if (!quark_composite_name)
10240 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10242 g_object_set_qdata_full (G_OBJECT (widget),
10243 quark_composite_name,
10249 * gtk_widget_get_composite_name:
10250 * @widget: a #GtkWidget
10252 * Obtains the composite name of a widget.
10254 * Returns: the composite name of @widget, or %NULL if @widget is not
10255 * a composite child. The string should be freed when it is no
10259 gtk_widget_get_composite_name (GtkWidget *widget)
10261 GtkWidgetPrivate *priv;
10263 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10265 priv = widget->priv;
10267 if (widget->priv->composite_child && priv->parent)
10268 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10275 * gtk_widget_push_composite_child:
10277 * Makes all newly-created widgets as composite children until
10278 * the corresponding gtk_widget_pop_composite_child() call.
10280 * A composite child is a child that's an implementation detail of the
10281 * container it's inside and should not be visible to people using the
10282 * container. Composite children aren't treated differently by GTK (but
10283 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10284 * builders might want to treat them in a different way.
10286 * Here is a simple example:
10288 * gtk_widget_push_composite_child ();
10289 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10290 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10291 * gtk_widget_pop_composite_child ();
10292 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10293 * GTK_WIDGET (scrolled_window));
10294 * g_object_ref (scrolled_window->hscrollbar);
10298 gtk_widget_push_composite_child (void)
10300 composite_child_stack++;
10304 * gtk_widget_pop_composite_child:
10306 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10309 gtk_widget_pop_composite_child (void)
10311 if (composite_child_stack)
10312 composite_child_stack--;
10316 gtk_widget_emit_direction_changed (GtkWidget *widget,
10317 GtkTextDirection old_dir)
10319 GtkTextDirection direction;
10320 GtkStateFlags state;
10322 gtk_widget_update_pango_context (widget);
10324 direction = gtk_widget_get_direction (widget);
10325 state = widget->priv->state_flags;
10326 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10330 case GTK_TEXT_DIR_LTR:
10331 state |= GTK_STATE_FLAG_DIR_LTR;
10334 case GTK_TEXT_DIR_RTL:
10335 state |= GTK_STATE_FLAG_DIR_RTL;
10338 case GTK_TEXT_DIR_NONE:
10340 g_assert_not_reached ();
10344 gtk_widget_set_state_flags (widget, state, TRUE);
10346 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10350 * gtk_widget_set_direction:
10351 * @widget: a #GtkWidget
10352 * @dir: the new direction
10354 * Sets the reading direction on a particular widget. This direction
10355 * controls the primary direction for widgets containing text,
10356 * and also the direction in which the children of a container are
10357 * packed. The ability to set the direction is present in order
10358 * so that correct localization into languages with right-to-left
10359 * reading directions can be done. Generally, applications will
10360 * let the default reading direction present, except for containers
10361 * where the containers are arranged in an order that is explicitely
10362 * visual rather than logical (such as buttons for text justification).
10364 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10365 * set by gtk_widget_set_default_direction() will be used.
10368 gtk_widget_set_direction (GtkWidget *widget,
10369 GtkTextDirection dir)
10371 GtkTextDirection old_dir;
10373 g_return_if_fail (GTK_IS_WIDGET (widget));
10374 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10376 old_dir = gtk_widget_get_direction (widget);
10378 widget->priv->direction = dir;
10380 if (old_dir != gtk_widget_get_direction (widget))
10381 gtk_widget_emit_direction_changed (widget, old_dir);
10385 * gtk_widget_get_direction:
10386 * @widget: a #GtkWidget
10388 * Gets the reading direction for a particular widget. See
10389 * gtk_widget_set_direction().
10391 * Return value: the reading direction for the widget.
10394 gtk_widget_get_direction (GtkWidget *widget)
10396 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10398 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10399 return gtk_default_direction;
10401 return widget->priv->direction;
10405 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10407 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10409 g_object_ref (widget);
10411 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10412 gtk_widget_emit_direction_changed (widget, old_dir);
10414 if (GTK_IS_CONTAINER (widget))
10415 gtk_container_forall (GTK_CONTAINER (widget),
10416 gtk_widget_set_default_direction_recurse,
10419 g_object_unref (widget);
10423 * gtk_widget_set_default_direction:
10424 * @dir: the new default direction. This cannot be
10425 * %GTK_TEXT_DIR_NONE.
10427 * Sets the default reading direction for widgets where the
10428 * direction has not been explicitly set by gtk_widget_set_direction().
10431 gtk_widget_set_default_direction (GtkTextDirection dir)
10433 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10435 if (dir != gtk_default_direction)
10437 GList *toplevels, *tmp_list;
10438 GtkTextDirection old_dir = gtk_default_direction;
10440 gtk_default_direction = dir;
10442 tmp_list = toplevels = gtk_window_list_toplevels ();
10443 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10447 gtk_widget_set_default_direction_recurse (tmp_list->data,
10448 GUINT_TO_POINTER (old_dir));
10449 g_object_unref (tmp_list->data);
10450 tmp_list = tmp_list->next;
10453 g_list_free (toplevels);
10458 * gtk_widget_get_default_direction:
10460 * Obtains the current default reading direction. See
10461 * gtk_widget_set_default_direction().
10463 * Return value: the current default direction.
10466 gtk_widget_get_default_direction (void)
10468 return gtk_default_direction;
10472 gtk_widget_constructed (GObject *object)
10474 GtkWidget *widget = GTK_WIDGET (object);
10475 GtkWidgetPrivate *priv = widget->priv;
10477 /* As strange as it may seem, this may happen on object construction.
10478 * init() implementations of parent types may eventually call this function,
10479 * each with its corresponding GType, which could leave a child
10480 * implementation with a wrong widget type in the widget path
10483 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10485 gtk_widget_path_free (priv->path);
10489 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10493 gtk_widget_dispose (GObject *object)
10495 GtkWidget *widget = GTK_WIDGET (object);
10496 GtkWidgetPrivate *priv = widget->priv;
10499 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10500 else if (gtk_widget_get_visible (widget))
10501 gtk_widget_hide (widget);
10503 priv->visible = FALSE;
10504 if (gtk_widget_get_realized (widget))
10505 gtk_widget_unrealize (widget);
10507 if (!priv->in_destruction)
10509 priv->in_destruction = TRUE;
10510 g_signal_emit (object, widget_signals[DESTROY], 0);
10511 priv->in_destruction = FALSE;
10514 g_clear_object (&priv->muxer);
10516 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10520 gtk_widget_real_destroy (GtkWidget *object)
10522 /* gtk_object_destroy() will already hold a refcount on object */
10523 GtkWidget *widget = GTK_WIDGET (object);
10524 GtkWidgetPrivate *priv = widget->priv;
10526 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10528 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10532 gtk_accessible_set_widget (accessible, NULL);
10533 g_object_unref (accessible);
10537 /* wipe accelerator closures (keep order) */
10538 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10539 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10541 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10542 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10544 gtk_grab_remove (widget);
10546 g_list_foreach (priv->frame_clock_targets, (GFunc)g_object_unref, NULL);
10547 g_list_free (priv->frame_clock_targets);
10548 priv->frame_clock_targets = NULL;
10551 g_object_unref (priv->style);
10552 priv->style = gtk_widget_get_default_style ();
10553 g_object_ref (priv->style);
10557 gtk_widget_finalize (GObject *object)
10559 GtkWidget *widget = GTK_WIDGET (object);
10560 GtkWidgetPrivate *priv = widget->priv;
10561 GtkWidgetAuxInfo *aux_info;
10562 GtkAccessible *accessible;
10564 gtk_grab_remove (widget);
10566 g_object_unref (priv->style);
10567 priv->style = NULL;
10569 g_free (priv->name);
10571 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10573 gtk_widget_aux_info_destroy (aux_info);
10575 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10577 g_object_unref (accessible);
10580 gtk_widget_path_free (priv->path);
10584 _gtk_style_context_set_widget (priv->context, NULL);
10585 g_object_unref (priv->context);
10588 _gtk_size_request_cache_free (&priv->requests);
10590 if (g_object_is_floating (object))
10591 g_warning ("A floating object was finalized. This means that someone\n"
10592 "called g_object_unref() on an object that had only a floating\n"
10593 "reference; the initial floating reference is not owned by anyone\n"
10594 "and must be removed with g_object_ref_sink().");
10596 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10599 /*****************************************
10600 * gtk_widget_real_map:
10605 *****************************************/
10608 gtk_widget_real_map (GtkWidget *widget)
10610 GtkWidgetPrivate *priv = widget->priv;
10612 g_assert (gtk_widget_get_realized (widget));
10614 if (!gtk_widget_get_mapped (widget))
10616 gtk_widget_set_mapped (widget, TRUE);
10618 if (gtk_widget_get_has_window (widget))
10619 gdk_window_show (priv->window);
10623 /*****************************************
10624 * gtk_widget_real_unmap:
10629 *****************************************/
10632 gtk_widget_real_unmap (GtkWidget *widget)
10634 GtkWidgetPrivate *priv = widget->priv;
10636 if (gtk_widget_get_mapped (widget))
10638 gtk_widget_set_mapped (widget, FALSE);
10640 if (gtk_widget_get_has_window (widget))
10641 gdk_window_hide (priv->window);
10645 /*****************************************
10646 * gtk_widget_real_realize:
10651 *****************************************/
10654 gtk_widget_real_realize (GtkWidget *widget)
10656 GtkWidgetPrivate *priv = widget->priv;
10658 g_assert (!gtk_widget_get_has_window (widget));
10660 gtk_widget_set_realized (widget, TRUE);
10663 priv->window = gtk_widget_get_parent_window (widget);
10664 g_object_ref (priv->window);
10668 /*****************************************
10669 * gtk_widget_real_unrealize:
10674 *****************************************/
10677 gtk_widget_real_unrealize (GtkWidget *widget)
10679 GtkWidgetPrivate *priv = widget->priv;
10681 g_assert (!widget->priv->mapped);
10683 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10686 /* We must do unrealize child widget BEFORE container widget.
10687 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10688 * So, unrealizing container widget bofore its children causes the problem
10689 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10692 if (GTK_IS_CONTAINER (widget))
10693 gtk_container_forall (GTK_CONTAINER (widget),
10694 (GtkCallback) gtk_widget_unrealize,
10697 if (gtk_widget_get_has_window (widget))
10699 gtk_widget_unregister_window (widget, priv->window);
10700 gdk_window_destroy (priv->window);
10701 priv->window = NULL;
10705 g_object_unref (priv->window);
10706 priv->window = NULL;
10709 gtk_selection_remove_all (widget);
10711 gtk_widget_set_realized (widget, FALSE);
10715 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10716 GtkOrientation orientation,
10717 gint *minimum_size,
10718 gint *natural_size)
10720 const GtkWidgetAuxInfo *aux_info;
10722 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10724 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10725 aux_info->width > 0)
10727 *minimum_size = MAX (*minimum_size, aux_info->width);
10729 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10730 aux_info->height > 0)
10732 *minimum_size = MAX (*minimum_size, aux_info->height);
10735 /* Fix it if set_size_request made natural size smaller than min size.
10736 * This would also silently fix broken widgets, but we warn about them
10737 * in gtksizerequest.c when calling their size request vfuncs.
10739 *natural_size = MAX (*natural_size, *minimum_size);
10741 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10743 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10744 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10748 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10749 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10754 * _gtk_widget_peek_request_cache:
10756 * Returns the address of the widget's request cache (strictly for
10757 * internal use in gtksizerequest.c)
10759 * Return value: the address of @widget's size request cache.
10762 _gtk_widget_peek_request_cache (GtkWidget *widget)
10764 /* Don't bother slowing things down with the return_if_fail guards here */
10765 return &widget->priv->requests;
10769 * _gtk_widget_set_device_window:
10770 * @widget: a #GtkWidget
10771 * @device: a #GdkDevice
10772 * @window: the new device window
10774 * Sets pointer window for @widget and @device.
10775 * Does not ref @window.
10778 _gtk_widget_set_device_window (GtkWidget *widget,
10782 GHashTable *device_window;
10784 g_return_if_fail (GTK_IS_WIDGET (widget));
10785 g_return_if_fail (GDK_IS_DEVICE (device));
10786 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
10788 if (!gtk_widget_get_mapped (widget))
10791 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10793 if (!device_window && window)
10795 device_window = g_hash_table_new (NULL, NULL);
10796 g_object_set_qdata_full (G_OBJECT (widget),
10797 quark_pointer_window,
10799 (GDestroyNotify) g_hash_table_destroy);
10803 g_hash_table_insert (device_window, device, window);
10804 else if (device_window)
10806 g_hash_table_remove (device_window, device);
10808 if (g_hash_table_size (device_window) == 0)
10809 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
10814 * _gtk_widget_get_device_window:
10815 * @widget: a #GtkWidget
10816 * @device: a #GdkDevice
10818 * Return value: the device window set on @widget, or %NULL
10821 _gtk_widget_get_device_window (GtkWidget *widget,
10824 GHashTable *device_window;
10826 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10827 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10829 if (!gtk_widget_get_mapped (widget))
10832 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10834 if (!device_window)
10837 return g_hash_table_lookup (device_window, device);
10841 * _gtk_widget_list_devices:
10842 * @widget: a #GtkWidget
10844 * Returns the list of #GdkDevices that is currently on top
10845 * of any window belonging to @widget.
10846 * Free the list with g_list_free(), the elements are owned
10847 * by GTK+ and must not be freed.
10850 _gtk_widget_list_devices (GtkWidget *widget)
10852 GHashTableIter iter;
10853 GHashTable *device_window;
10854 GList *devices = NULL;
10855 gpointer key, value;
10857 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10859 if (!gtk_widget_get_mapped (widget))
10862 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
10864 if (G_UNLIKELY (!device_window))
10867 g_hash_table_iter_init (&iter, device_window);
10869 while (g_hash_table_iter_next (&iter, &key, &value))
10870 devices = g_list_prepend (devices, key);
10876 synth_crossing (GtkWidget *widget,
10880 GdkCrossingMode mode,
10881 GdkNotifyType detail)
10885 event = gdk_event_new (type);
10887 event->crossing.window = g_object_ref (window);
10888 event->crossing.send_event = TRUE;
10889 event->crossing.subwindow = g_object_ref (window);
10890 event->crossing.time = GDK_CURRENT_TIME;
10891 event->crossing.x = event->crossing.y = 0;
10892 event->crossing.x_root = event->crossing.y_root = 0;
10893 event->crossing.mode = mode;
10894 event->crossing.detail = detail;
10895 event->crossing.focus = FALSE;
10896 event->crossing.state = 0;
10897 gdk_event_set_device (event, device);
10900 widget = gtk_get_event_widget (event);
10903 gtk_widget_event_internal (widget, event);
10905 gdk_event_free (event);
10909 * _gtk_widget_synthesize_crossing:
10910 * @from: the #GtkWidget the virtual pointer is leaving.
10911 * @to: the #GtkWidget the virtual pointer is moving to.
10912 * @mode: the #GdkCrossingMode to place on the synthesized events.
10914 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10916 * The real pointer window is the window that most recently received an enter notify
10917 * event. Windows that don't select for crossing events can't become the real
10918 * poiner window. The real pointer widget that owns the real pointer window. The
10919 * effective pointer window is the same as the real pointer window unless the real
10920 * pointer widget is either insensitive or there is a grab on a widget that is not
10921 * an ancestor of the real pointer widget (in which case the effective pointer
10922 * window should be the root window).
10924 * When the effective pointer window is the same as the real poiner window, we
10925 * receive crossing events from the windowing system. When the effective pointer
10926 * window changes to become different from the real pointer window we synthesize
10927 * crossing events, attempting to follow X protocol rules:
10929 * When the root window becomes the effective pointer window:
10930 * - leave notify on real pointer window, detail Ancestor
10931 * - leave notify on all of its ancestors, detail Virtual
10932 * - enter notify on root window, detail Inferior
10934 * When the root window ceases to be the effective pointer window:
10935 * - leave notify on root window, detail Inferior
10936 * - enter notify on all ancestors of real pointer window, detail Virtual
10937 * - enter notify on real pointer window, detail Ancestor
10940 _gtk_widget_synthesize_crossing (GtkWidget *from,
10943 GdkCrossingMode mode)
10945 GdkWindow *from_window = NULL, *to_window = NULL;
10947 g_return_if_fail (from != NULL || to != NULL);
10951 from_window = _gtk_widget_get_device_window (from, device);
10954 from_window = from->priv->window;
10959 to_window = _gtk_widget_get_device_window (to, device);
10962 to_window = to->priv->window;
10965 if (from_window == NULL && to_window == NULL)
10967 else if (from_window != NULL && to_window == NULL)
10969 GList *from_ancestors = NULL, *list;
10970 GdkWindow *from_ancestor = from_window;
10972 while (from_ancestor != NULL)
10974 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10975 if (from_ancestor == NULL)
10977 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10980 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10981 device, mode, GDK_NOTIFY_ANCESTOR);
10982 for (list = g_list_last (from_ancestors); list; list = list->prev)
10984 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10985 device, mode, GDK_NOTIFY_VIRTUAL);
10988 /* XXX: enter/inferior on root window? */
10990 g_list_free (from_ancestors);
10992 else if (from_window == NULL && to_window != NULL)
10994 GList *to_ancestors = NULL, *list;
10995 GdkWindow *to_ancestor = to_window;
10997 while (to_ancestor != NULL)
10999 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11000 if (to_ancestor == NULL)
11002 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11005 /* XXX: leave/inferior on root window? */
11007 for (list = to_ancestors; list; list = list->next)
11009 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11010 device, mode, GDK_NOTIFY_VIRTUAL);
11012 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11013 device, mode, GDK_NOTIFY_ANCESTOR);
11015 g_list_free (to_ancestors);
11017 else if (from_window == to_window)
11021 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11022 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11024 while (from_ancestor != NULL || to_ancestor != NULL)
11026 if (from_ancestor != NULL)
11028 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11029 if (from_ancestor == to_window)
11032 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11034 if (to_ancestor != NULL)
11036 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11037 if (to_ancestor == from_window)
11040 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11043 if (to_ancestor == from_window)
11045 if (mode != GDK_CROSSING_GTK_UNGRAB)
11046 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11047 device, mode, GDK_NOTIFY_INFERIOR);
11048 for (list = to_ancestors; list; list = list->next)
11049 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11050 device, mode, GDK_NOTIFY_VIRTUAL);
11051 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11052 device, mode, GDK_NOTIFY_ANCESTOR);
11054 else if (from_ancestor == to_window)
11056 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11057 device, mode, GDK_NOTIFY_ANCESTOR);
11058 for (list = g_list_last (from_ancestors); list; list = list->prev)
11060 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11061 device, mode, GDK_NOTIFY_VIRTUAL);
11063 if (mode != GDK_CROSSING_GTK_GRAB)
11064 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11065 device, mode, GDK_NOTIFY_INFERIOR);
11069 while (from_ancestors != NULL && to_ancestors != NULL
11070 && from_ancestors->data == to_ancestors->data)
11072 from_ancestors = g_list_delete_link (from_ancestors,
11074 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11077 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11078 device, mode, GDK_NOTIFY_NONLINEAR);
11080 for (list = g_list_last (from_ancestors); list; list = list->prev)
11082 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11083 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11085 for (list = to_ancestors; list; list = list->next)
11087 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11088 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11090 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11091 device, mode, GDK_NOTIFY_NONLINEAR);
11093 g_list_free (from_ancestors);
11094 g_list_free (to_ancestors);
11099 gtk_widget_propagate_state (GtkWidget *widget,
11100 GtkStateData *data)
11102 GtkWidgetPrivate *priv = widget->priv;
11103 GtkStateFlags new_flags, old_flags = priv->state_flags;
11104 GtkStateType old_state;
11106 old_state = gtk_widget_get_state (widget);
11108 priv->state_flags |= data->flags_to_set;
11109 priv->state_flags &= ~(data->flags_to_unset);
11111 /* make insensitivity unoverridable */
11112 if (!priv->sensitive)
11113 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11115 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11119 window = gtk_widget_get_toplevel (widget);
11121 if (window && gtk_widget_is_toplevel (window))
11122 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11125 new_flags = priv->state_flags;
11127 if (old_flags != new_flags)
11129 g_object_ref (widget);
11131 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11132 gtk_grab_remove (widget);
11134 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11136 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11137 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11139 if (!priv->shadowed &&
11140 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11142 GList *event_windows = NULL;
11143 GList *devices, *d;
11145 devices = _gtk_widget_list_devices (widget);
11147 for (d = devices; d; d = d->next)
11153 window = _gtk_widget_get_device_window (widget, device);
11155 /* Do not propagate more than once to the
11156 * same window if non-multidevice aware.
11158 if (!gdk_window_get_support_multidevice (window) &&
11159 g_list_find (event_windows, window))
11162 if (!gtk_widget_is_sensitive (widget))
11163 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11164 GDK_CROSSING_STATE_CHANGED);
11166 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11167 GDK_CROSSING_STATE_CHANGED);
11169 event_windows = g_list_prepend (event_windows, window);
11172 g_list_free (event_windows);
11173 g_list_free (devices);
11176 if (GTK_IS_CONTAINER (widget))
11178 GtkStateData child_data;
11180 /* Make sure to only propate the right states further */
11181 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11182 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11184 gtk_container_forall (GTK_CONTAINER (widget),
11185 (GtkCallback) gtk_widget_propagate_state,
11189 g_object_unref (widget);
11193 static const GtkWidgetAuxInfo default_aux_info = {
11201 * gtk_widget_get_aux_info:
11202 * @widget: a #GtkWidget
11203 * @create: if %TRUE, create the structure if it doesn't exist
11205 * Get the #GtkWidgetAuxInfo structure for the widget.
11207 * Return value: the #GtkAuxInfo structure for the widget, or
11208 * %NULL if @create is %FALSE and one doesn't already exist.
11210 static GtkWidgetAuxInfo *
11211 gtk_widget_get_aux_info (GtkWidget *widget,
11214 GtkWidgetAuxInfo *aux_info;
11216 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11217 if (!aux_info && create)
11219 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11221 *aux_info = default_aux_info;
11223 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11229 static const GtkWidgetAuxInfo*
11230 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11232 GtkWidgetAuxInfo *aux_info;
11234 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11235 if (aux_info == NULL)
11237 return &default_aux_info;
11245 /*****************************************
11246 * gtk_widget_aux_info_destroy:
11251 *****************************************/
11254 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11256 g_slice_free (GtkWidgetAuxInfo, aux_info);
11260 * gtk_widget_shape_combine_region:
11261 * @widget: a #GtkWidget
11262 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11264 * Sets a shape for this widget's GDK window. This allows for
11265 * transparent windows etc., see gdk_window_shape_combine_region()
11266 * for more information.
11271 gtk_widget_shape_combine_region (GtkWidget *widget,
11272 cairo_region_t *region)
11274 GtkWidgetPrivate *priv;
11276 g_return_if_fail (GTK_IS_WIDGET (widget));
11277 /* set_shape doesn't work on widgets without gdk window */
11278 g_return_if_fail (gtk_widget_get_has_window (widget));
11280 priv = widget->priv;
11282 if (region == NULL)
11284 priv->has_shape_mask = FALSE;
11287 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11289 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11293 priv->has_shape_mask = TRUE;
11295 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11296 cairo_region_copy (region),
11297 (GDestroyNotify) cairo_region_destroy);
11299 /* set shape if widget has a gdk window already.
11300 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11303 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11308 * gtk_widget_input_shape_combine_region:
11309 * @widget: a #GtkWidget
11310 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11312 * Sets an input shape for this widget's GDK window. This allows for
11313 * windows which react to mouse click in a nonrectangular region, see
11314 * gdk_window_input_shape_combine_region() for more information.
11319 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11320 cairo_region_t *region)
11322 GtkWidgetPrivate *priv;
11324 g_return_if_fail (GTK_IS_WIDGET (widget));
11325 /* set_shape doesn't work on widgets without gdk window */
11326 g_return_if_fail (gtk_widget_get_has_window (widget));
11328 priv = widget->priv;
11330 if (region == NULL)
11333 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11335 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11339 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11340 cairo_region_copy (region),
11341 (GDestroyNotify) cairo_region_destroy);
11343 /* set shape if widget has a gdk window already.
11344 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11347 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11352 /* style properties
11356 * gtk_widget_class_install_style_property_parser: (skip)
11357 * @klass: a #GtkWidgetClass
11358 * @pspec: the #GParamSpec for the style property
11359 * @parser: the parser for the style property
11361 * Installs a style property on a widget class.
11364 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11366 GtkRcPropertyParser parser)
11368 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11369 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11370 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11371 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11373 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11375 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11376 G_OBJECT_CLASS_NAME (klass),
11381 g_param_spec_ref_sink (pspec);
11382 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11383 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11387 * gtk_widget_class_install_style_property:
11388 * @klass: a #GtkWidgetClass
11389 * @pspec: the #GParamSpec for the property
11391 * Installs a style property on a widget class. The parser for the
11392 * style property is determined by the value type of @pspec.
11395 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11398 GtkRcPropertyParser parser;
11400 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11401 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11403 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11405 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11409 * gtk_widget_class_find_style_property:
11410 * @klass: a #GtkWidgetClass
11411 * @property_name: the name of the style property to find
11413 * Finds a style property of a widget class by name.
11415 * Returns: (transfer none): the #GParamSpec of the style property or
11416 * %NULL if @class has no style property with that name.
11421 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11422 const gchar *property_name)
11424 g_return_val_if_fail (property_name != NULL, NULL);
11426 return g_param_spec_pool_lookup (style_property_spec_pool,
11428 G_OBJECT_CLASS_TYPE (klass),
11433 * gtk_widget_class_list_style_properties:
11434 * @klass: a #GtkWidgetClass
11435 * @n_properties: location to return the number of style properties found
11437 * Returns all style properties of a widget class.
11439 * Returns: (array length=n_properties) (transfer container): a
11440 * newly allocated array of #GParamSpec*. The array must be
11441 * freed with g_free().
11446 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11447 guint *n_properties)
11449 GParamSpec **pspecs;
11452 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11453 G_OBJECT_CLASS_TYPE (klass),
11462 * gtk_widget_style_get_property:
11463 * @widget: a #GtkWidget
11464 * @property_name: the name of a style property
11465 * @value: location to return the property value
11467 * Gets the value of a style property of @widget.
11470 gtk_widget_style_get_property (GtkWidget *widget,
11471 const gchar *property_name,
11476 g_return_if_fail (GTK_IS_WIDGET (widget));
11477 g_return_if_fail (property_name != NULL);
11478 g_return_if_fail (G_IS_VALUE (value));
11480 g_object_ref (widget);
11481 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11483 G_OBJECT_TYPE (widget),
11486 g_warning ("%s: widget class `%s' has no property named `%s'",
11488 G_OBJECT_TYPE_NAME (widget),
11492 GtkStyleContext *context;
11493 const GValue *peek_value;
11494 GtkStateFlags state;
11496 context = gtk_widget_get_style_context (widget);
11497 state = gtk_widget_get_state_flags (widget);
11499 peek_value = _gtk_style_context_peek_style_property (context,
11500 G_OBJECT_TYPE (widget),
11503 /* auto-conversion of the caller's value type
11505 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11506 g_value_copy (peek_value, value);
11507 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11508 g_value_transform (peek_value, value);
11510 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11512 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11513 G_VALUE_TYPE_NAME (value));
11515 g_object_unref (widget);
11519 * gtk_widget_style_get_valist:
11520 * @widget: a #GtkWidget
11521 * @first_property_name: the name of the first property to get
11522 * @var_args: a <type>va_list</type> of pairs of property names and
11523 * locations to return the property values, starting with the location
11524 * for @first_property_name.
11526 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11530 gtk_widget_style_get_valist (GtkWidget *widget,
11531 const gchar *first_property_name,
11534 GtkStyleContext *context;
11535 GtkStateFlags state;
11538 g_return_if_fail (GTK_IS_WIDGET (widget));
11540 g_object_ref (widget);
11541 context = gtk_widget_get_style_context (widget);
11542 state = gtk_widget_get_state_flags (widget);
11544 name = first_property_name;
11547 const GValue *peek_value;
11551 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11553 G_OBJECT_TYPE (widget),
11557 g_warning ("%s: widget class `%s' has no property named `%s'",
11559 G_OBJECT_TYPE_NAME (widget),
11563 /* style pspecs are always readable so we can spare that check here */
11565 peek_value = _gtk_style_context_peek_style_property (context,
11566 G_OBJECT_TYPE (widget),
11569 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11572 g_warning ("%s: %s", G_STRLOC, error);
11577 name = va_arg (var_args, gchar*);
11580 g_object_unref (widget);
11584 * gtk_widget_style_get:
11585 * @widget: a #GtkWidget
11586 * @first_property_name: the name of the first property to get
11587 * @...: pairs of property names and locations to return the
11588 * property values, starting with the location for
11589 * @first_property_name, terminated by %NULL.
11591 * Gets the values of a multiple style properties of @widget.
11594 gtk_widget_style_get (GtkWidget *widget,
11595 const gchar *first_property_name,
11600 g_return_if_fail (GTK_IS_WIDGET (widget));
11602 va_start (var_args, first_property_name);
11603 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11608 * gtk_requisition_new:
11610 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11612 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11613 * be freed with gtk_requisition_free().
11618 gtk_requisition_new (void)
11620 return g_slice_new0 (GtkRequisition);
11624 * gtk_requisition_copy:
11625 * @requisition: a #GtkRequisition
11627 * Copies a #GtkRequisition.
11629 * Returns: a copy of @requisition
11632 gtk_requisition_copy (const GtkRequisition *requisition)
11634 return g_slice_dup (GtkRequisition, requisition);
11638 * gtk_requisition_free:
11639 * @requisition: a #GtkRequisition
11641 * Frees a #GtkRequisition.
11644 gtk_requisition_free (GtkRequisition *requisition)
11646 g_slice_free (GtkRequisition, requisition);
11649 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11650 gtk_requisition_copy,
11651 gtk_requisition_free)
11654 * gtk_widget_class_set_accessible_type:
11655 * @widget_class: class to set the accessible type for
11656 * @type: The object type that implements the accessible for @widget_class
11658 * Sets the type to be used for creating accessibles for widgets of
11659 * @widget_class. The given @type must be a subtype of the type used for
11660 * accessibles of the parent class.
11662 * This function should only be called from class init functions of widgets.
11667 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11670 GtkWidgetClassPrivate *priv;
11672 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11673 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11675 priv = widget_class->priv;
11677 priv->accessible_type = type;
11678 /* reset this - honoring the type's role is better. */
11679 priv->accessible_role = ATK_ROLE_INVALID;
11683 * gtk_widget_class_set_accessible_role:
11684 * @widget_class: class to set the accessible role for
11685 * @role: The role to use for accessibles created for @widget_class
11687 * Sets the default #AtkRole to be set on accessibles created for
11688 * widgets of @widget_class. Accessibles may decide to not honor this
11689 * setting if their role reporting is more refined. Calls to
11690 * gtk_widget_class_set_accessible_type() will reset this value.
11692 * In cases where you want more fine-grained control over the role of
11693 * accessibles created for @widget_class, you should provide your own
11694 * accessible type and use gtk_widget_class_set_accessible_type()
11697 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11698 * and the accessible's default role will be used instead.
11700 * This function should only be called from class init functions of widgets.
11705 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11708 GtkWidgetClassPrivate *priv;
11710 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11712 priv = widget_class->priv;
11714 priv->accessible_role = role;
11718 * _gtk_widget_peek_accessible:
11719 * @widget: a #GtkWidget
11721 * Gets the accessible for @widget, if it has been created yet.
11722 * Otherwise, this function returns %NULL. If the @widget's implementation
11723 * does not use the default way to create accessibles, %NULL will always be
11726 * Returns: the accessible for @widget or %NULL if none has been
11730 _gtk_widget_peek_accessible (GtkWidget *widget)
11732 return g_object_get_qdata (G_OBJECT (widget),
11733 quark_accessible_object);
11737 * gtk_widget_get_accessible:
11738 * @widget: a #GtkWidget
11740 * Returns the accessible object that describes the widget to an
11741 * assistive technology.
11743 * If accessibility support is not available, this #AtkObject
11744 * instance may be a no-op. Likewise, if no class-specific #AtkObject
11745 * implementation is available for the widget instance in question,
11746 * it will inherit an #AtkObject implementation from the first ancestor
11747 * class for which such an implementation is defined.
11749 * The documentation of the
11750 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
11751 * library contains more information about accessible objects and their uses.
11753 * Returns: (transfer none): the #AtkObject associated with @widget
11756 gtk_widget_get_accessible (GtkWidget *widget)
11758 GtkWidgetClass *klass;
11760 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11762 klass = GTK_WIDGET_GET_CLASS (widget);
11764 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11766 return klass->get_accessible (widget);
11770 gtk_widget_real_get_accessible (GtkWidget *widget)
11772 AtkObject* accessible;
11774 accessible = g_object_get_qdata (G_OBJECT (widget),
11775 quark_accessible_object);
11778 GtkWidgetClass *widget_class;
11779 GtkWidgetClassPrivate *priv;
11780 AtkObjectFactory *factory;
11781 AtkRegistry *default_registry;
11783 widget_class = GTK_WIDGET_GET_CLASS (widget);
11784 priv = widget_class->priv;
11786 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
11788 default_registry = atk_get_default_registry ();
11789 factory = atk_registry_get_factory (default_registry,
11790 G_TYPE_FROM_INSTANCE (widget));
11792 atk_object_factory_create_accessible (factory,
11793 G_OBJECT (widget));
11795 if (priv->accessible_role != ATK_ROLE_INVALID)
11796 atk_object_set_role (accessible, priv->accessible_role);
11798 g_object_set_qdata (G_OBJECT (widget),
11799 quark_accessible_object,
11804 accessible = g_object_new (priv->accessible_type,
11807 if (priv->accessible_role != ATK_ROLE_INVALID)
11808 atk_object_set_role (accessible, priv->accessible_role);
11810 g_object_set_qdata (G_OBJECT (widget),
11811 quark_accessible_object,
11814 atk_object_initialize (accessible, widget);
11816 /* Set the role again, since we don't want a role set
11817 * in some parent initialize() function to override
11820 if (priv->accessible_role != ATK_ROLE_INVALID)
11821 atk_object_set_role (accessible, priv->accessible_role);
11828 * Initialize a AtkImplementorIface instance's virtual pointers as
11829 * appropriate to this implementor's class (GtkWidget).
11832 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11834 iface->ref_accessible = gtk_widget_ref_accessible;
11838 gtk_widget_ref_accessible (AtkImplementor *implementor)
11840 AtkObject *accessible;
11842 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11844 g_object_ref (accessible);
11849 * Expand flag management
11853 gtk_widget_update_computed_expand (GtkWidget *widget)
11855 GtkWidgetPrivate *priv;
11857 priv = widget->priv;
11859 if (priv->need_compute_expand)
11863 if (priv->hexpand_set)
11868 if (priv->vexpand_set)
11873 /* we don't need to use compute_expand if both expands are
11874 * forced by the app
11876 if (!(priv->hexpand_set && priv->vexpand_set))
11878 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11882 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11883 priv->hexpand_set ? &ignored : &h,
11884 priv->vexpand_set ? &ignored : &v);
11888 priv->need_compute_expand = FALSE;
11889 priv->computed_hexpand = h != FALSE;
11890 priv->computed_vexpand = v != FALSE;
11895 * gtk_widget_queue_compute_expand:
11896 * @widget: a #GtkWidget
11898 * Mark @widget as needing to recompute its expand flags. Call
11899 * this function when setting legacy expand child properties
11900 * on the child of a container.
11902 * See gtk_widget_compute_expand().
11905 gtk_widget_queue_compute_expand (GtkWidget *widget)
11908 gboolean changed_anything;
11910 if (widget->priv->need_compute_expand)
11913 changed_anything = FALSE;
11915 while (parent != NULL)
11917 if (!parent->priv->need_compute_expand)
11919 parent->priv->need_compute_expand = TRUE;
11920 changed_anything = TRUE;
11923 /* Note: if we had an invariant that "if a child needs to
11924 * compute expand, its parents also do" then we could stop going
11925 * up when we got to a parent that already needed to
11926 * compute. However, in general we compute expand lazily (as
11927 * soon as we see something in a subtree that is expand, we know
11928 * we're expanding) and so this invariant does not hold and we
11929 * have to always walk all the way up in case some ancestor
11930 * is not currently need_compute_expand.
11933 parent = parent->priv->parent;
11936 /* recomputing expand always requires
11937 * a relayout as well
11939 if (changed_anything)
11940 gtk_widget_queue_resize (widget);
11944 * gtk_widget_compute_expand:
11945 * @widget: the widget
11946 * @orientation: expand direction
11948 * Computes whether a container should give this widget extra space
11949 * when possible. Containers should check this, rather than
11950 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11952 * This function already checks whether the widget is visible, so
11953 * visibility does not need to be checked separately. Non-visible
11954 * widgets are not expanded.
11956 * The computed expand value uses either the expand setting explicitly
11957 * set on the widget itself, or, if none has been explicitly set,
11958 * the widget may expand if some of its children do.
11960 * Return value: whether widget tree rooted here should be expanded
11963 gtk_widget_compute_expand (GtkWidget *widget,
11964 GtkOrientation orientation)
11966 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11968 /* We never make a widget expand if not even showing. */
11969 if (!gtk_widget_get_visible (widget))
11972 gtk_widget_update_computed_expand (widget);
11974 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11976 return widget->priv->computed_hexpand;
11980 return widget->priv->computed_vexpand;
11985 gtk_widget_set_expand (GtkWidget *widget,
11986 GtkOrientation orientation,
11989 const char *expand_prop;
11990 const char *expand_set_prop;
11992 GtkWidgetPrivate *priv;
11994 g_return_if_fail (GTK_IS_WIDGET (widget));
11996 priv = widget->priv;
11998 expand = expand != FALSE;
12000 was_both = priv->hexpand && priv->vexpand;
12002 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12004 if (priv->hexpand_set &&
12005 priv->hexpand == expand)
12008 priv->hexpand_set = TRUE;
12009 priv->hexpand = expand;
12011 expand_prop = "hexpand";
12012 expand_set_prop = "hexpand-set";
12016 if (priv->vexpand_set &&
12017 priv->vexpand == expand)
12020 priv->vexpand_set = TRUE;
12021 priv->vexpand = expand;
12023 expand_prop = "vexpand";
12024 expand_set_prop = "vexpand-set";
12027 gtk_widget_queue_compute_expand (widget);
12029 g_object_freeze_notify (G_OBJECT (widget));
12030 g_object_notify (G_OBJECT (widget), expand_prop);
12031 g_object_notify (G_OBJECT (widget), expand_set_prop);
12032 if (was_both != (priv->hexpand && priv->vexpand))
12033 g_object_notify (G_OBJECT (widget), "expand");
12034 g_object_thaw_notify (G_OBJECT (widget));
12038 gtk_widget_set_expand_set (GtkWidget *widget,
12039 GtkOrientation orientation,
12042 GtkWidgetPrivate *priv;
12045 priv = widget->priv;
12047 set = set != FALSE;
12049 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12051 if (set == priv->hexpand_set)
12054 priv->hexpand_set = set;
12055 prop = "hexpand-set";
12059 if (set == priv->vexpand_set)
12062 priv->vexpand_set = set;
12063 prop = "vexpand-set";
12066 gtk_widget_queue_compute_expand (widget);
12068 g_object_notify (G_OBJECT (widget), prop);
12072 * gtk_widget_get_hexpand:
12073 * @widget: the widget
12075 * Gets whether the widget would like any available extra horizontal
12076 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12077 * generally receive the extra space. For example, a list or
12078 * scrollable area or document in your window would often be set to
12081 * Containers should use gtk_widget_compute_expand() rather than
12082 * this function, to see whether a widget, or any of its children,
12083 * has the expand flag set. If any child of a widget wants to
12084 * expand, the parent may ask to expand also.
12086 * This function only looks at the widget's own hexpand flag, rather
12087 * than computing whether the entire widget tree rooted at this widget
12090 * Return value: whether hexpand flag is set
12093 gtk_widget_get_hexpand (GtkWidget *widget)
12095 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12097 return widget->priv->hexpand;
12101 * gtk_widget_set_hexpand:
12102 * @widget: the widget
12103 * @expand: whether to expand
12105 * Sets whether the widget would like any available extra horizontal
12106 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12107 * generally receive the extra space. For example, a list or
12108 * scrollable area or document in your window would often be set to
12111 * Call this function to set the expand flag if you would like your
12112 * widget to become larger horizontally when the window has extra
12115 * By default, widgets automatically expand if any of their children
12116 * want to expand. (To see if a widget will automatically expand given
12117 * its current children and state, call gtk_widget_compute_expand(). A
12118 * container can decide how the expandability of children affects the
12119 * expansion of the container by overriding the compute_expand virtual
12120 * method on #GtkWidget.).
12122 * Setting hexpand explicitly with this function will override the
12123 * automatic expand behavior.
12125 * This function forces the widget to expand or not to expand,
12126 * regardless of children. The override occurs because
12127 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12128 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12129 * value to be used, rather than looking at children and widget state.
12132 gtk_widget_set_hexpand (GtkWidget *widget,
12135 g_return_if_fail (GTK_IS_WIDGET (widget));
12137 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12141 * gtk_widget_get_hexpand_set:
12142 * @widget: the widget
12144 * Gets whether gtk_widget_set_hexpand() has been used to
12145 * explicitly set the expand flag on this widget.
12147 * If hexpand is set, then it overrides any computed
12148 * expand value based on child widgets. If hexpand is not
12149 * set, then the expand value depends on whether any
12150 * children of the widget would like to expand.
12152 * There are few reasons to use this function, but it's here
12153 * for completeness and consistency.
12155 * Return value: whether hexpand has been explicitly set
12158 gtk_widget_get_hexpand_set (GtkWidget *widget)
12160 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12162 return widget->priv->hexpand_set;
12166 * gtk_widget_set_hexpand_set:
12167 * @widget: the widget
12168 * @set: value for hexpand-set property
12170 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12173 * The hexpand-set property will be set automatically when you call
12174 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12175 * reason to use this function would be to unset an explicit expand
12178 * If hexpand is set, then it overrides any computed
12179 * expand value based on child widgets. If hexpand is not
12180 * set, then the expand value depends on whether any
12181 * children of the widget would like to expand.
12183 * There are few reasons to use this function, but it's here
12184 * for completeness and consistency.
12187 gtk_widget_set_hexpand_set (GtkWidget *widget,
12190 g_return_if_fail (GTK_IS_WIDGET (widget));
12192 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12197 * gtk_widget_get_vexpand:
12198 * @widget: the widget
12200 * Gets whether the widget would like any available extra vertical
12203 * See gtk_widget_get_hexpand() for more detail.
12205 * Return value: whether vexpand flag is set
12208 gtk_widget_get_vexpand (GtkWidget *widget)
12210 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12212 return widget->priv->vexpand;
12216 * gtk_widget_set_vexpand:
12217 * @widget: the widget
12218 * @expand: whether to expand
12220 * Sets whether the widget would like any available extra vertical
12223 * See gtk_widget_set_hexpand() for more detail.
12226 gtk_widget_set_vexpand (GtkWidget *widget,
12229 g_return_if_fail (GTK_IS_WIDGET (widget));
12231 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12235 * gtk_widget_get_vexpand_set:
12236 * @widget: the widget
12238 * Gets whether gtk_widget_set_vexpand() has been used to
12239 * explicitly set the expand flag on this widget.
12241 * See gtk_widget_get_hexpand_set() for more detail.
12243 * Return value: whether vexpand has been explicitly set
12246 gtk_widget_get_vexpand_set (GtkWidget *widget)
12248 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12250 return widget->priv->vexpand_set;
12254 * gtk_widget_set_vexpand_set:
12255 * @widget: the widget
12256 * @set: value for vexpand-set property
12258 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12261 * See gtk_widget_set_hexpand_set() for more detail.
12264 gtk_widget_set_vexpand_set (GtkWidget *widget,
12267 g_return_if_fail (GTK_IS_WIDGET (widget));
12269 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12273 * GtkBuildable implementation
12275 static GQuark quark_builder_has_default = 0;
12276 static GQuark quark_builder_has_focus = 0;
12277 static GQuark quark_builder_atk_relations = 0;
12278 static GQuark quark_builder_set_name = 0;
12281 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12283 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12284 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12285 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12286 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12288 iface->set_name = gtk_widget_buildable_set_name;
12289 iface->get_name = gtk_widget_buildable_get_name;
12290 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12291 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12292 iface->parser_finished = gtk_widget_buildable_parser_finished;
12293 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12294 iface->custom_finished = gtk_widget_buildable_custom_finished;
12298 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12301 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12302 g_strdup (name), g_free);
12305 static const gchar *
12306 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12308 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12312 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12313 GtkBuilder *builder,
12314 const gchar *childname)
12316 if (strcmp (childname, "accessible") == 0)
12317 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12323 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12324 GtkBuilder *builder,
12326 const GValue *value)
12328 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12329 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12330 GINT_TO_POINTER (TRUE));
12331 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12332 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12333 GINT_TO_POINTER (TRUE));
12335 g_object_set_property (G_OBJECT (buildable), name, value);
12340 gchar *action_name;
12341 GString *description;
12343 gboolean translatable;
12353 free_action (AtkActionData *data, gpointer user_data)
12355 g_free (data->action_name);
12356 g_string_free (data->description, TRUE);
12357 g_free (data->context);
12358 g_slice_free (AtkActionData, data);
12362 free_relation (AtkRelationData *data, gpointer user_data)
12364 g_free (data->target);
12365 g_free (data->type);
12366 g_slice_free (AtkRelationData, data);
12370 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12371 GtkBuilder *builder)
12373 GSList *atk_relations;
12375 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12376 gtk_widget_grab_default (GTK_WIDGET (buildable));
12377 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12378 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12380 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12381 quark_builder_atk_relations);
12384 AtkObject *accessible;
12385 AtkRelationSet *relation_set;
12388 AtkRelationType relation_type;
12389 AtkObject *target_accessible;
12391 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12392 relation_set = atk_object_ref_relation_set (accessible);
12394 for (l = atk_relations; l; l = l->next)
12396 AtkRelationData *relation = (AtkRelationData*)l->data;
12398 target = gtk_builder_get_object (builder, relation->target);
12401 g_warning ("Target object %s in <relation> does not exist",
12405 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12406 g_assert (target_accessible != NULL);
12408 relation_type = atk_relation_type_for_name (relation->type);
12409 if (relation_type == ATK_RELATION_NULL)
12411 g_warning ("<relation> type %s not found",
12415 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12416 target_accessible);
12418 g_object_unref (relation_set);
12420 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12421 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12430 } AccessibilitySubParserData;
12433 accessibility_start_element (GMarkupParseContext *context,
12434 const gchar *element_name,
12435 const gchar **names,
12436 const gchar **values,
12437 gpointer user_data,
12440 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12442 gint line_number, char_number;
12444 if (strcmp (element_name, "relation") == 0)
12446 gchar *target = NULL;
12447 gchar *type = NULL;
12448 AtkRelationData *relation;
12450 for (i = 0; names[i]; i++)
12452 if (strcmp (names[i], "target") == 0)
12453 target = g_strdup (values[i]);
12454 else if (strcmp (names[i], "type") == 0)
12455 type = g_strdup (values[i]);
12458 g_markup_parse_context_get_position (context,
12461 g_set_error (error,
12463 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12464 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12466 line_number, char_number, names[i], "relation");
12473 if (!target || !type)
12475 g_markup_parse_context_get_position (context,
12478 g_set_error (error,
12480 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12481 "%s:%d:%d <%s> requires attribute \"%s\"",
12483 line_number, char_number, "relation",
12484 type ? "target" : "type");
12490 relation = g_slice_new (AtkRelationData);
12491 relation->target = target;
12492 relation->type = type;
12494 data->relations = g_slist_prepend (data->relations, relation);
12496 else if (strcmp (element_name, "action") == 0)
12498 const gchar *action_name = NULL;
12499 const gchar *description = NULL;
12500 const gchar *msg_context = NULL;
12501 gboolean translatable = FALSE;
12502 AtkActionData *action;
12504 for (i = 0; names[i]; i++)
12506 if (strcmp (names[i], "action_name") == 0)
12507 action_name = values[i];
12508 else if (strcmp (names[i], "description") == 0)
12509 description = values[i];
12510 else if (strcmp (names[i], "translatable") == 0)
12512 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12515 else if (strcmp (names[i], "comments") == 0)
12517 /* do nothing, comments are for translators */
12519 else if (strcmp (names[i], "context") == 0)
12520 msg_context = values[i];
12523 g_markup_parse_context_get_position (context,
12526 g_set_error (error,
12528 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12529 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12531 line_number, char_number, names[i], "action");
12538 g_markup_parse_context_get_position (context,
12541 g_set_error (error,
12543 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12544 "%s:%d:%d <%s> requires attribute \"%s\"",
12546 line_number, char_number, "action",
12551 action = g_slice_new (AtkActionData);
12552 action->action_name = g_strdup (action_name);
12553 action->description = g_string_new (description);
12554 action->context = g_strdup (msg_context);
12555 action->translatable = translatable;
12557 data->actions = g_slist_prepend (data->actions, action);
12559 else if (strcmp (element_name, "accessibility") == 0)
12562 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12566 accessibility_text (GMarkupParseContext *context,
12569 gpointer user_data,
12572 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12574 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12576 AtkActionData *action = data->actions->data;
12578 g_string_append_len (action->description, text, text_len);
12582 static const GMarkupParser accessibility_parser =
12584 accessibility_start_element,
12586 accessibility_text,
12595 } AccelGroupParserData;
12598 accel_group_start_element (GMarkupParseContext *context,
12599 const gchar *element_name,
12600 const gchar **names,
12601 const gchar **values,
12602 gpointer user_data,
12607 guint modifiers = 0;
12608 gchar *signal = NULL;
12609 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12611 for (i = 0; names[i]; i++)
12613 if (strcmp (names[i], "key") == 0)
12614 key = gdk_keyval_from_name (values[i]);
12615 else if (strcmp (names[i], "modifiers") == 0)
12617 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12623 else if (strcmp (names[i], "signal") == 0)
12624 signal = g_strdup (values[i]);
12627 if (key == 0 || signal == NULL)
12629 g_warning ("<accelerator> requires key and signal attributes");
12632 parser_data->key = key;
12633 parser_data->modifiers = modifiers;
12634 parser_data->signal = signal;
12637 static const GMarkupParser accel_group_parser =
12639 accel_group_start_element,
12648 style_start_element (GMarkupParseContext *context,
12649 const gchar *element_name,
12650 const gchar **names,
12651 const gchar **values,
12652 gpointer user_data,
12655 StyleParserData *style_data = (StyleParserData *)user_data;
12658 if (strcmp (element_name, "class") == 0)
12660 if (g_markup_collect_attributes (element_name,
12664 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12665 G_MARKUP_COLLECT_INVALID))
12667 style_data->classes = g_slist_append (style_data->classes, class_name);
12670 else if (strcmp (element_name, "style") == 0)
12673 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12676 static const GMarkupParser style_parser =
12678 style_start_element,
12682 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12683 GtkBuilder *builder,
12685 const gchar *tagname,
12686 GMarkupParser *parser,
12689 g_assert (buildable);
12691 if (strcmp (tagname, "accelerator") == 0)
12693 AccelGroupParserData *parser_data;
12695 parser_data = g_slice_new0 (AccelGroupParserData);
12696 parser_data->object = g_object_ref (buildable);
12697 *parser = accel_group_parser;
12698 *data = parser_data;
12701 if (strcmp (tagname, "accessibility") == 0)
12703 AccessibilitySubParserData *parser_data;
12705 parser_data = g_slice_new0 (AccessibilitySubParserData);
12706 *parser = accessibility_parser;
12707 *data = parser_data;
12710 if (strcmp (tagname, "style") == 0)
12712 StyleParserData *parser_data;
12714 parser_data = g_slice_new0 (StyleParserData);
12715 *parser = style_parser;
12716 *data = parser_data;
12724 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12725 GtkWidget *toplevel,
12726 gpointer user_data)
12728 AccelGroupParserData *accel_data;
12729 GSList *accel_groups;
12730 GtkAccelGroup *accel_group;
12732 g_return_if_fail (GTK_IS_WIDGET (widget));
12733 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12734 g_return_if_fail (user_data != NULL);
12736 accel_data = (AccelGroupParserData*)user_data;
12737 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12738 if (g_slist_length (accel_groups) == 0)
12740 accel_group = gtk_accel_group_new ();
12741 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12745 g_assert (g_slist_length (accel_groups) == 1);
12746 accel_group = g_slist_nth_data (accel_groups, 0);
12749 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12750 accel_data->signal,
12753 accel_data->modifiers,
12754 GTK_ACCEL_VISIBLE);
12756 g_object_unref (accel_data->object);
12757 g_free (accel_data->signal);
12758 g_slice_free (AccelGroupParserData, accel_data);
12762 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12763 GtkBuilder *builder,
12765 const gchar *tagname,
12766 gpointer user_data)
12768 if (strcmp (tagname, "accelerator") == 0)
12770 AccelGroupParserData *accel_data;
12771 GtkWidget *toplevel;
12773 accel_data = (AccelGroupParserData*)user_data;
12774 g_assert (accel_data->object);
12776 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12778 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12780 else if (strcmp (tagname, "accessibility") == 0)
12782 AccessibilitySubParserData *a11y_data;
12784 a11y_data = (AccessibilitySubParserData*)user_data;
12786 if (a11y_data->actions)
12788 AtkObject *accessible;
12793 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12795 if (ATK_IS_ACTION (accessible))
12797 action = ATK_ACTION (accessible);
12798 n_actions = atk_action_get_n_actions (action);
12800 for (l = a11y_data->actions; l; l = l->next)
12802 AtkActionData *action_data = (AtkActionData*)l->data;
12804 for (i = 0; i < n_actions; i++)
12805 if (strcmp (atk_action_get_name (action, i),
12806 action_data->action_name) == 0)
12811 gchar *description;
12813 if (action_data->translatable && action_data->description->len)
12814 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12815 action_data->context,
12816 action_data->description->str);
12818 description = action_data->description->str;
12820 atk_action_set_description (action, i, description);
12825 g_warning ("accessibility action on a widget that does not implement AtkAction");
12827 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
12830 if (a11y_data->relations)
12831 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12832 a11y_data->relations);
12834 g_slice_free (AccessibilitySubParserData, a11y_data);
12836 else if (strcmp (tagname, "style") == 0)
12838 StyleParserData *style_data = (StyleParserData *)user_data;
12839 GtkStyleContext *context;
12842 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
12844 for (l = style_data->classes; l; l = l->next)
12845 gtk_style_context_add_class (context, (const gchar *)l->data);
12847 gtk_widget_reset_style (GTK_WIDGET (buildable));
12849 g_slist_free_full (style_data->classes, g_free);
12850 g_slice_free (StyleParserData, style_data);
12854 static GtkSizeRequestMode
12855 gtk_widget_real_get_request_mode (GtkWidget *widget)
12857 /* By default widgets dont trade size at all. */
12858 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
12862 gtk_widget_real_get_width (GtkWidget *widget,
12863 gint *minimum_size,
12864 gint *natural_size)
12874 gtk_widget_real_get_height (GtkWidget *widget,
12875 gint *minimum_size,
12876 gint *natural_size)
12886 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12888 gint *minimum_height,
12889 gint *natural_height)
12891 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12895 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12897 gint *minimum_width,
12898 gint *natural_width)
12900 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12904 * gtk_widget_get_halign:
12905 * @widget: a #GtkWidget
12907 * Gets the value of the #GtkWidget:halign property.
12909 * Returns: the horizontal alignment of @widget
12912 gtk_widget_get_halign (GtkWidget *widget)
12914 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12915 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12919 * gtk_widget_set_halign:
12920 * @widget: a #GtkWidget
12921 * @align: the horizontal alignment
12923 * Sets the horizontal alignment of @widget.
12924 * See the #GtkWidget:halign property.
12927 gtk_widget_set_halign (GtkWidget *widget,
12930 GtkWidgetAuxInfo *aux_info;
12932 g_return_if_fail (GTK_IS_WIDGET (widget));
12934 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12936 if (aux_info->halign == align)
12939 aux_info->halign = align;
12940 gtk_widget_queue_resize (widget);
12941 g_object_notify (G_OBJECT (widget), "halign");
12945 * gtk_widget_get_valign:
12946 * @widget: a #GtkWidget
12948 * Gets the value of the #GtkWidget:valign property.
12950 * Returns: the vertical alignment of @widget
12953 gtk_widget_get_valign (GtkWidget *widget)
12955 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12956 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12960 * gtk_widget_set_valign:
12961 * @widget: a #GtkWidget
12962 * @align: the vertical alignment
12964 * Sets the vertical alignment of @widget.
12965 * See the #GtkWidget:valign property.
12968 gtk_widget_set_valign (GtkWidget *widget,
12971 GtkWidgetAuxInfo *aux_info;
12973 g_return_if_fail (GTK_IS_WIDGET (widget));
12975 aux_info = gtk_widget_get_aux_info (widget, TRUE);
12977 if (aux_info->valign == align)
12980 aux_info->valign = align;
12981 gtk_widget_queue_resize (widget);
12982 g_object_notify (G_OBJECT (widget), "valign");
12986 * gtk_widget_get_margin_left:
12987 * @widget: a #GtkWidget
12989 * Gets the value of the #GtkWidget:margin-left property.
12991 * Returns: The left margin of @widget
12996 gtk_widget_get_margin_left (GtkWidget *widget)
12998 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13000 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13004 * gtk_widget_set_margin_left:
13005 * @widget: a #GtkWidget
13006 * @margin: the left margin
13008 * Sets the left margin of @widget.
13009 * See the #GtkWidget:margin-left property.
13014 gtk_widget_set_margin_left (GtkWidget *widget,
13017 GtkWidgetAuxInfo *aux_info;
13019 g_return_if_fail (GTK_IS_WIDGET (widget));
13020 g_return_if_fail (margin <= G_MAXINT16);
13022 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13024 if (aux_info->margin.left == margin)
13027 aux_info->margin.left = margin;
13028 gtk_widget_queue_resize (widget);
13029 g_object_notify (G_OBJECT (widget), "margin-left");
13033 * gtk_widget_get_margin_right:
13034 * @widget: a #GtkWidget
13036 * Gets the value of the #GtkWidget:margin-right property.
13038 * Returns: The right margin of @widget
13043 gtk_widget_get_margin_right (GtkWidget *widget)
13045 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13047 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13051 * gtk_widget_set_margin_right:
13052 * @widget: a #GtkWidget
13053 * @margin: the right margin
13055 * Sets the right margin of @widget.
13056 * See the #GtkWidget:margin-right property.
13061 gtk_widget_set_margin_right (GtkWidget *widget,
13064 GtkWidgetAuxInfo *aux_info;
13066 g_return_if_fail (GTK_IS_WIDGET (widget));
13067 g_return_if_fail (margin <= G_MAXINT16);
13069 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13071 if (aux_info->margin.right == margin)
13074 aux_info->margin.right = margin;
13075 gtk_widget_queue_resize (widget);
13076 g_object_notify (G_OBJECT (widget), "margin-right");
13080 * gtk_widget_get_margin_top:
13081 * @widget: a #GtkWidget
13083 * Gets the value of the #GtkWidget:margin-top property.
13085 * Returns: The top margin of @widget
13090 gtk_widget_get_margin_top (GtkWidget *widget)
13092 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13094 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13098 * gtk_widget_set_margin_top:
13099 * @widget: a #GtkWidget
13100 * @margin: the top margin
13102 * Sets the top margin of @widget.
13103 * See the #GtkWidget:margin-top property.
13108 gtk_widget_set_margin_top (GtkWidget *widget,
13111 GtkWidgetAuxInfo *aux_info;
13113 g_return_if_fail (GTK_IS_WIDGET (widget));
13114 g_return_if_fail (margin <= G_MAXINT16);
13116 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13118 if (aux_info->margin.top == margin)
13121 aux_info->margin.top = margin;
13122 gtk_widget_queue_resize (widget);
13123 g_object_notify (G_OBJECT (widget), "margin-top");
13127 * gtk_widget_get_margin_bottom:
13128 * @widget: a #GtkWidget
13130 * Gets the value of the #GtkWidget:margin-bottom property.
13132 * Returns: The bottom margin of @widget
13137 gtk_widget_get_margin_bottom (GtkWidget *widget)
13139 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13141 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13145 * gtk_widget_set_margin_bottom:
13146 * @widget: a #GtkWidget
13147 * @margin: the bottom margin
13149 * Sets the bottom margin of @widget.
13150 * See the #GtkWidget:margin-bottom property.
13155 gtk_widget_set_margin_bottom (GtkWidget *widget,
13158 GtkWidgetAuxInfo *aux_info;
13160 g_return_if_fail (GTK_IS_WIDGET (widget));
13161 g_return_if_fail (margin <= G_MAXINT16);
13163 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13165 if (aux_info->margin.bottom == margin)
13168 aux_info->margin.bottom = margin;
13169 gtk_widget_queue_resize (widget);
13170 g_object_notify (G_OBJECT (widget), "margin-bottom");
13174 * gtk_widget_get_clipboard:
13175 * @widget: a #GtkWidget
13176 * @selection: a #GdkAtom which identifies the clipboard
13177 * to use. %GDK_SELECTION_CLIPBOARD gives the
13178 * default clipboard. Another common value
13179 * is %GDK_SELECTION_PRIMARY, which gives
13180 * the primary X selection.
13182 * Returns the clipboard object for the given selection to
13183 * be used with @widget. @widget must have a #GdkDisplay
13184 * associated with it, so must be attached to a toplevel
13187 * Return value: (transfer none): the appropriate clipboard object. If no
13188 * clipboard already exists, a new one will
13189 * be created. Once a clipboard object has
13190 * been created, it is persistent for all time.
13195 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13197 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13198 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13200 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13205 * gtk_widget_list_mnemonic_labels:
13206 * @widget: a #GtkWidget
13208 * Returns a newly allocated list of the widgets, normally labels, for
13209 * which this widget is the target of a mnemonic (see for example,
13210 * gtk_label_set_mnemonic_widget()).
13212 * The widgets in the list are not individually referenced. If you
13213 * want to iterate through the list and perform actions involving
13214 * callbacks that might destroy the widgets, you
13215 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13216 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13217 * widgets afterwards.
13219 * Return value: (element-type GtkWidget) (transfer container): the list of
13220 * mnemonic labels; free this list
13221 * with g_list_free() when you are done with it.
13226 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13228 GList *list = NULL;
13231 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13233 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13234 list = g_list_prepend (list, l->data);
13240 * gtk_widget_add_mnemonic_label:
13241 * @widget: a #GtkWidget
13242 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13244 * Adds a widget to the list of mnemonic labels for
13245 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13246 * list of mnemonic labels for the widget is cleared when the
13247 * widget is destroyed, so the caller must make sure to update
13248 * its internal state at this point as well, by using a connection
13249 * to the #GtkWidget::destroy signal or a weak notifier.
13254 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13257 GSList *old_list, *new_list;
13259 g_return_if_fail (GTK_IS_WIDGET (widget));
13260 g_return_if_fail (GTK_IS_WIDGET (label));
13262 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13263 new_list = g_slist_prepend (old_list, label);
13265 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13266 new_list, (GDestroyNotify) g_slist_free);
13270 * gtk_widget_remove_mnemonic_label:
13271 * @widget: a #GtkWidget
13272 * @label: a #GtkWidget that was previously set as a mnemnic label for
13273 * @widget with gtk_widget_add_mnemonic_label().
13275 * Removes a widget from the list of mnemonic labels for
13276 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13277 * must have previously been added to the list with
13278 * gtk_widget_add_mnemonic_label().
13283 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13286 GSList *old_list, *new_list;
13288 g_return_if_fail (GTK_IS_WIDGET (widget));
13289 g_return_if_fail (GTK_IS_WIDGET (label));
13291 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13292 new_list = g_slist_remove (old_list, label);
13295 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13296 new_list, (GDestroyNotify) g_slist_free);
13300 * gtk_widget_get_no_show_all:
13301 * @widget: a #GtkWidget
13303 * Returns the current value of the #GtkWidget:no-show-all property,
13304 * which determines whether calls to gtk_widget_show_all()
13305 * will affect this widget.
13307 * Return value: the current value of the "no-show-all" property.
13312 gtk_widget_get_no_show_all (GtkWidget *widget)
13314 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13316 return widget->priv->no_show_all;
13320 * gtk_widget_set_no_show_all:
13321 * @widget: a #GtkWidget
13322 * @no_show_all: the new value for the "no-show-all" property
13324 * Sets the #GtkWidget:no-show-all property, which determines whether
13325 * calls to gtk_widget_show_all() will affect this widget.
13327 * This is mostly for use in constructing widget hierarchies with externally
13328 * controlled visibility, see #GtkUIManager.
13333 gtk_widget_set_no_show_all (GtkWidget *widget,
13334 gboolean no_show_all)
13336 g_return_if_fail (GTK_IS_WIDGET (widget));
13338 no_show_all = (no_show_all != FALSE);
13340 if (widget->priv->no_show_all != no_show_all)
13342 widget->priv->no_show_all = no_show_all;
13344 g_object_notify (G_OBJECT (widget), "no-show-all");
13350 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13351 gboolean has_tooltip,
13354 GtkWidgetPrivate *priv = widget->priv;
13355 gboolean priv_has_tooltip;
13357 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13358 quark_has_tooltip));
13360 if (priv_has_tooltip != has_tooltip || force)
13362 priv_has_tooltip = has_tooltip;
13364 if (priv_has_tooltip)
13366 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13367 gdk_window_set_events (priv->window,
13368 gdk_window_get_events (priv->window) |
13369 GDK_LEAVE_NOTIFY_MASK |
13370 GDK_POINTER_MOTION_MASK |
13371 GDK_POINTER_MOTION_HINT_MASK);
13373 if (gtk_widget_get_has_window (widget))
13374 gtk_widget_add_events (widget,
13375 GDK_LEAVE_NOTIFY_MASK |
13376 GDK_POINTER_MOTION_MASK |
13377 GDK_POINTER_MOTION_HINT_MASK);
13380 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13381 GUINT_TO_POINTER (priv_has_tooltip));
13386 * gtk_widget_set_tooltip_window:
13387 * @widget: a #GtkWidget
13388 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13390 * Replaces the default, usually yellow, window used for displaying
13391 * tooltips with @custom_window. GTK+ will take care of showing and
13392 * hiding @custom_window at the right moment, to behave likewise as
13393 * the default tooltip window. If @custom_window is %NULL, the default
13394 * tooltip window will be used.
13396 * If the custom window should have the default theming it needs to
13397 * have the name "gtk-tooltip", see gtk_widget_set_name().
13402 gtk_widget_set_tooltip_window (GtkWidget *widget,
13403 GtkWindow *custom_window)
13405 gboolean has_tooltip;
13406 gchar *tooltip_markup;
13408 g_return_if_fail (GTK_IS_WIDGET (widget));
13409 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13411 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13414 g_object_ref (custom_window);
13416 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13417 custom_window, g_object_unref);
13419 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13420 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13422 if (has_tooltip && gtk_widget_get_visible (widget))
13423 gtk_widget_queue_tooltip_query (widget);
13427 * gtk_widget_get_tooltip_window:
13428 * @widget: a #GtkWidget
13430 * Returns the #GtkWindow of the current tooltip. This can be the
13431 * GtkWindow created by default, or the custom tooltip window set
13432 * using gtk_widget_set_tooltip_window().
13434 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13439 gtk_widget_get_tooltip_window (GtkWidget *widget)
13441 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13443 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13447 * gtk_widget_trigger_tooltip_query:
13448 * @widget: a #GtkWidget
13450 * Triggers a tooltip query on the display where the toplevel of @widget
13451 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13457 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13459 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13462 static guint tooltip_query_id;
13463 static GSList *tooltip_query_displays;
13466 tooltip_query_idle (gpointer data)
13468 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13469 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13470 g_slist_free (tooltip_query_displays);
13472 tooltip_query_displays = NULL;
13473 tooltip_query_id = 0;
13479 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13481 GdkDisplay *display;
13483 display = gtk_widget_get_display (widget);
13485 if (!g_slist_find (tooltip_query_displays, display))
13486 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13488 if (tooltip_query_id == 0)
13489 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13493 * gtk_widget_set_tooltip_text:
13494 * @widget: a #GtkWidget
13495 * @text: (allow-none): the contents of the tooltip for @widget
13497 * Sets @text as the contents of the tooltip. This function will take
13498 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13499 * handler for the #GtkWidget::query-tooltip signal.
13501 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13506 gtk_widget_set_tooltip_text (GtkWidget *widget,
13509 g_return_if_fail (GTK_IS_WIDGET (widget));
13511 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13515 * gtk_widget_get_tooltip_text:
13516 * @widget: a #GtkWidget
13518 * Gets the contents of the tooltip for @widget.
13520 * Return value: the tooltip text, or %NULL. You should free the
13521 * returned string with g_free() when done.
13526 gtk_widget_get_tooltip_text (GtkWidget *widget)
13528 gchar *text = NULL;
13530 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13532 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13538 * gtk_widget_set_tooltip_markup:
13539 * @widget: a #GtkWidget
13540 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13542 * Sets @markup as the contents of the tooltip, which is marked up with
13543 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13545 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13546 * and of the default handler for the #GtkWidget::query-tooltip signal.
13548 * See also the #GtkWidget:tooltip-markup property and
13549 * gtk_tooltip_set_markup().
13554 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13555 const gchar *markup)
13557 g_return_if_fail (GTK_IS_WIDGET (widget));
13559 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13563 * gtk_widget_get_tooltip_markup:
13564 * @widget: a #GtkWidget
13566 * Gets the contents of the tooltip for @widget.
13568 * Return value: the tooltip text, or %NULL. You should free the
13569 * returned string with g_free() when done.
13574 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13576 gchar *text = NULL;
13578 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13580 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13586 * gtk_widget_set_has_tooltip:
13587 * @widget: a #GtkWidget
13588 * @has_tooltip: whether or not @widget has a tooltip.
13590 * Sets the has-tooltip property on @widget to @has_tooltip. See
13591 * #GtkWidget:has-tooltip for more information.
13596 gtk_widget_set_has_tooltip (GtkWidget *widget,
13597 gboolean has_tooltip)
13599 g_return_if_fail (GTK_IS_WIDGET (widget));
13601 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13605 * gtk_widget_get_has_tooltip:
13606 * @widget: a #GtkWidget
13608 * Returns the current value of the has-tooltip property. See
13609 * #GtkWidget:has-tooltip for more information.
13611 * Return value: current value of has-tooltip on @widget.
13616 gtk_widget_get_has_tooltip (GtkWidget *widget)
13618 gboolean has_tooltip = FALSE;
13620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13622 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13624 return has_tooltip;
13628 * gtk_widget_get_allocation:
13629 * @widget: a #GtkWidget
13630 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13632 * Retrieves the widget's allocation.
13634 * Note, when implementing a #GtkContainer: a widget's allocation will
13635 * be its "adjusted" allocation, that is, the widget's parent
13636 * container typically calls gtk_widget_size_allocate() with an
13637 * allocation, and that allocation is then adjusted (to handle margin
13638 * and alignment for example) before assignment to the widget.
13639 * gtk_widget_get_allocation() returns the adjusted allocation that
13640 * was actually assigned to the widget. The adjusted allocation is
13641 * guaranteed to be completely contained within the
13642 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13643 * is guaranteed that its children stay inside the assigned bounds,
13644 * but not that they have exactly the bounds the container assigned.
13645 * There is no way to get the original allocation assigned by
13646 * gtk_widget_size_allocate(), since it isn't stored; if a container
13647 * implementation needs that information it will have to track it itself.
13652 gtk_widget_get_allocation (GtkWidget *widget,
13653 GtkAllocation *allocation)
13655 GtkWidgetPrivate *priv;
13657 g_return_if_fail (GTK_IS_WIDGET (widget));
13658 g_return_if_fail (allocation != NULL);
13660 priv = widget->priv;
13662 *allocation = priv->allocation;
13666 * gtk_widget_set_allocation:
13667 * @widget: a #GtkWidget
13668 * @allocation: a pointer to a #GtkAllocation to copy from
13670 * Sets the widget's allocation. This should not be used
13671 * directly, but from within a widget's size_allocate method.
13673 * The allocation set should be the "adjusted" or actual
13674 * allocation. If you're implementing a #GtkContainer, you want to use
13675 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13676 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13677 * allocation inside gtk_widget_size_allocate() to create an adjusted
13683 gtk_widget_set_allocation (GtkWidget *widget,
13684 const GtkAllocation *allocation)
13686 GtkWidgetPrivate *priv;
13688 g_return_if_fail (GTK_IS_WIDGET (widget));
13689 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13690 g_return_if_fail (allocation != NULL);
13692 priv = widget->priv;
13694 priv->allocation = *allocation;
13698 * gtk_widget_get_allocated_width:
13699 * @widget: the widget to query
13701 * Returns the width that has currently been allocated to @widget.
13702 * This function is intended to be used when implementing handlers
13703 * for the #GtkWidget::draw function.
13705 * Returns: the width of the @widget
13708 gtk_widget_get_allocated_width (GtkWidget *widget)
13710 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13712 return widget->priv->allocation.width;
13716 * gtk_widget_get_allocated_height:
13717 * @widget: the widget to query
13719 * Returns the height that has currently been allocated to @widget.
13720 * This function is intended to be used when implementing handlers
13721 * for the #GtkWidget::draw function.
13723 * Returns: the height of the @widget
13726 gtk_widget_get_allocated_height (GtkWidget *widget)
13728 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13730 return widget->priv->allocation.height;
13734 * gtk_widget_get_requisition:
13735 * @widget: a #GtkWidget
13736 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13738 * Retrieves the widget's requisition.
13740 * This function should only be used by widget implementations in
13741 * order to figure whether the widget's requisition has actually
13742 * changed after some internal state change (so that they can call
13743 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13745 * Normally, gtk_widget_size_request() should be used.
13749 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13750 * removed, If you need to cache sizes across requests and allocations,
13751 * add an explicit cache to the widget in question instead.
13754 gtk_widget_get_requisition (GtkWidget *widget,
13755 GtkRequisition *requisition)
13757 g_return_if_fail (GTK_IS_WIDGET (widget));
13758 g_return_if_fail (requisition != NULL);
13760 gtk_widget_get_preferred_size (widget, requisition, NULL);
13764 * gtk_widget_set_window:
13765 * @widget: a #GtkWidget
13766 * @window: (transfer full): a #GdkWindow
13768 * Sets a widget's window. This function should only be used in a
13769 * widget's #GtkWidget::realize implementation. The %window passed is
13770 * usually either new window created with gdk_window_new(), or the
13771 * window of its parent widget as returned by
13772 * gtk_widget_get_parent_window().
13774 * Widgets must indicate whether they will create their own #GdkWindow
13775 * by calling gtk_widget_set_has_window(). This is usually done in the
13776 * widget's init() function.
13778 * <note><para>This function does not add any reference to @window.</para></note>
13783 gtk_widget_set_window (GtkWidget *widget,
13786 GtkWidgetPrivate *priv;
13788 g_return_if_fail (GTK_IS_WIDGET (widget));
13789 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13791 priv = widget->priv;
13793 if (priv->window != window)
13795 priv->window = window;
13797 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
13798 gdk_window_set_opacity (window,
13799 priv->norender ? 0 : priv->alpha / 255.0);
13801 g_object_notify (G_OBJECT (widget), "window");
13806 * gtk_widget_register_window:
13807 * @widget: a #GtkWidget
13808 * @window: a #GdkWindow
13810 * Registers a #GdkWindow with the widget and sets it up so that
13811 * the widget recieves events for it. Call gtk_widget_unregister_window()
13812 * when destroying the window.
13814 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
13815 * this up. This is now deprecated and you should use gtk_widget_register_window()
13816 * instead. Old code will keep working as is, although some new features like
13817 * transparency might not work perfectly.
13822 gtk_widget_register_window (GtkWidget *widget,
13825 GtkWidgetPrivate *priv;
13826 gpointer user_data;
13828 g_return_if_fail (GTK_IS_WIDGET (widget));
13829 g_return_if_fail (GDK_IS_WINDOW (window));
13831 gdk_window_get_user_data (window, &user_data);
13832 g_assert (user_data == NULL);
13834 priv = widget->priv;
13836 gdk_window_set_user_data (window, widget);
13837 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
13839 if (!gtk_widget_get_has_window (widget) && !gdk_window_has_native (window))
13840 gdk_window_set_opacity (window,
13841 priv->norender_children ? 0.0 : 1.0);
13845 * gtk_widget_unregister_window:
13846 * @widget: a #GtkWidget
13847 * @window: a #GdkWindow
13849 * Unregisters a #GdkWindow from the widget that was previously set up with
13850 * gtk_widget_register_window(). You need to call this when the window is
13851 * no longer used by the widget, such as when you destroy it.
13856 gtk_widget_unregister_window (GtkWidget *widget,
13859 GtkWidgetPrivate *priv;
13860 gpointer user_data;
13862 g_return_if_fail (GTK_IS_WIDGET (widget));
13863 g_return_if_fail (GDK_IS_WINDOW (window));
13865 priv = widget->priv;
13867 gdk_window_get_user_data (window, &user_data);
13868 g_assert (user_data == widget);
13869 gdk_window_set_user_data (window, NULL);
13870 priv->registered_windows = g_list_remove (priv->registered_windows, window);
13874 * gtk_widget_get_window:
13875 * @widget: a #GtkWidget
13877 * Returns the widget's window if it is realized, %NULL otherwise
13879 * Return value: (transfer none): @widget's window.
13884 gtk_widget_get_window (GtkWidget *widget)
13886 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13888 return widget->priv->window;
13892 * gtk_widget_get_support_multidevice:
13893 * @widget: a #GtkWidget
13895 * Returns %TRUE if @widget is multiple pointer aware. See
13896 * gtk_widget_set_support_multidevice() for more information.
13898 * Returns: %TRUE if @widget is multidevice aware.
13901 gtk_widget_get_support_multidevice (GtkWidget *widget)
13903 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13905 return widget->priv->multidevice;
13909 * gtk_widget_set_support_multidevice:
13910 * @widget: a #GtkWidget
13911 * @support_multidevice: %TRUE to support input from multiple devices.
13913 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13914 * @widget will start receiving multiple, per device enter/leave events. Note
13915 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13916 * gdk_window_set_support_multidevice() will have to be called manually on them.
13921 gtk_widget_set_support_multidevice (GtkWidget *widget,
13922 gboolean support_multidevice)
13924 GtkWidgetPrivate *priv;
13926 g_return_if_fail (GTK_IS_WIDGET (widget));
13928 priv = widget->priv;
13929 priv->multidevice = (support_multidevice == TRUE);
13931 if (gtk_widget_get_realized (widget))
13932 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13935 /* There are multiple alpha related sources. First of all the user can specify alpha
13936 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
13937 * are multiplied together to form the total alpha. Secondly, the user can specify
13938 * an opacity group for a widget, which means we must essentially handle it as having alpha.
13940 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
13941 * group we directly set the opacity of widget->window. This will cause gdk to properly
13942 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
13944 * However, if the widget is not windowed, or the user specified an opacity group for the
13945 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
13946 * implementation of this would break for windowed widgets or descendant widgets with
13947 * windows, as these would not be handled by the ::draw signal. To handle this we set
13948 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
13949 * to make the draw signal propagate to *all* child widgets/windows.
13951 * Note: We don't make all child windows fully transparent, we stop at the first one
13952 * in each branch when propagating down the hierarchy.
13956 /* This is called when priv->alpha or priv->opacity_group group changes, and should
13957 * update priv->norender and GdkWindow opacity for this widget and any children that
13958 * needs changing. It is also called whenver the parent changes, the parents
13959 * norender_children state changes, or the has_window state of the widget changes.
13962 gtk_widget_propagate_alpha (GtkWidget *widget)
13964 GtkWidgetPrivate *priv = widget->priv;
13966 gboolean norender, norender_children;
13969 parent = priv->parent;
13972 /* If this widget has an opacity group, never render it */
13973 priv->opacity_group ||
13974 /* If the parent has norender_children, propagate that here */
13975 (parent != NULL && parent->priv->norender_children);
13977 /* Windowed widget children should norender if: */
13978 norender_children =
13979 /* The widget is no_window (otherwise its enought to mark it norender/alpha), and */
13980 !gtk_widget_get_has_window (widget) &&
13981 ( /* norender is set, or */
13983 /* widget has an alpha */
13987 if (gtk_widget_get_has_window (widget))
13989 if (priv->window != NULL && !gdk_window_has_native (priv->window))
13990 gdk_window_set_opacity (priv->window,
13991 norender ? 0 : priv->alpha / 255.0);
13993 else /* !has_window */
13995 for (l = priv->registered_windows; l != NULL; l = l->next)
13997 GdkWindow *w = l->data;
13998 if (!gdk_window_has_native (w))
13999 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
14003 priv->norender = norender;
14004 if (priv->norender_children != norender_children)
14006 priv->norender_children = norender_children;
14008 if (GTK_IS_CONTAINER (widget))
14009 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
14012 if (gtk_widget_get_realized (widget))
14013 gtk_widget_queue_draw (widget);
14017 gtk_widget_update_alpha (GtkWidget *widget)
14019 GtkWidgetPrivate *priv;
14023 priv = widget->priv;
14025 alpha = priv->user_alpha;
14030 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
14031 GTK_CSS_PROPERTY_OPACITY),
14033 opacity = CLAMP (opacity, 0.0, 1.0);
14034 alpha = round (priv->user_alpha * opacity);
14037 if (alpha == priv->alpha)
14040 priv->alpha = alpha;
14042 gtk_widget_propagate_alpha (widget);
14047 gtk_widget_set_has_opacity_group (GtkWidget *widget,
14048 gboolean has_opacity_group)
14050 GtkWidgetPrivate *priv;
14052 g_return_if_fail (GTK_IS_WIDGET (widget));
14054 priv = widget->priv;
14056 has_opacity_group = !!has_opacity_group;
14058 if (priv->opacity_group == has_opacity_group)
14061 priv->opacity_group = has_opacity_group;
14063 gtk_widget_propagate_alpha (widget);
14067 * gtk_widget_set_opacity:
14068 * @widget: a #GtkWidget
14069 * @opacity: desired opacity, between 0 and 1
14071 * Request the @widget to be rendered partially transparent,
14072 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14073 * are clamped to the [0,1] range.).
14074 * This works on both toplevel widget, and child widgets, although there
14075 * are some limitations:
14077 * For toplevel widgets this depends on the capabilities of the windowing
14078 * system. On X11 this has any effect only on X screens with a compositing manager
14079 * running. See gtk_widget_is_composited(). On Windows it should work
14080 * always, although setting a window's opacity after the window has been
14081 * shown causes it to flicker once on Windows.
14083 * For child widgets it doesn't work if any affected widget has a native window, or
14084 * disables double buffering.
14089 gtk_widget_set_opacity (GtkWidget *widget,
14092 GtkWidgetPrivate *priv;
14095 g_return_if_fail (GTK_IS_WIDGET (widget));
14097 priv = widget->priv;
14099 opacity = CLAMP (opacity, 0.0, 1.0);
14101 alpha = round (opacity * 255);
14103 /* As a kind of hack for internal use we treat an alpha very
14104 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14105 we want the opacity group behaviour wrt draw handling, but
14106 not actually an alpha value. See bug #687842 for discussions. */
14107 gtk_widget_set_has_opacity_group (widget,
14108 alpha == 255 && opacity != 1.0);
14110 if (alpha == priv->user_alpha)
14113 priv->user_alpha = alpha;
14115 gtk_widget_update_alpha (widget);
14120 * gtk_widget_get_opacity:
14121 * @widget: a #GtkWidget
14123 * Fetches the requested opacity for this widget. See
14124 * gtk_widget_set_opacity().
14126 * Return value: the requested opacity for this widget.
14131 gtk_widget_get_opacity (GtkWidget *widget)
14133 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14135 return widget->priv->alpha / 255.0;
14139 _gtk_widget_set_has_focus (GtkWidget *widget,
14140 gboolean has_focus)
14142 widget->priv->has_focus = has_focus;
14145 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14147 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14151 * gtk_widget_send_focus_change:
14152 * @widget: a #GtkWidget
14153 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14155 * Sends the focus change @event to @widget
14157 * This function is not meant to be used by applications. The only time it
14158 * should be used is when it is necessary for a #GtkWidget to assign focus
14159 * to a widget that is semantically owned by the first widget even though
14160 * it's not a direct child - for instance, a search entry in a floating
14161 * window similar to the quick search in #GtkTreeView.
14163 * An example of its usage is:
14166 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14168 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14169 * fevent->focus_change.in = TRUE;
14170 * fevent->focus_change.window = gtk_widget_get_window (widget);
14171 * if (fevent->focus_change.window != NULL)
14172 * g_object_ref (fevent->focus_change.window);
14174 * gtk_widget_send_focus_change (widget, fevent);
14176 * gdk_event_free (event);
14179 * Return value: the return value from the event signal emission: %TRUE
14180 * if the event was handled, and %FALSE otherwise
14185 gtk_widget_send_focus_change (GtkWidget *widget,
14190 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14191 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14193 g_object_ref (widget);
14195 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14197 res = gtk_widget_event (widget, event);
14199 g_object_notify (G_OBJECT (widget), "has-focus");
14201 g_object_unref (widget);
14207 * gtk_widget_in_destruction:
14208 * @widget: a #GtkWidget
14210 * Returns whether the widget is currently being destroyed.
14211 * This information can sometimes be used to avoid doing
14212 * unnecessary work.
14214 * Returns: %TRUE if @widget is being destroyed
14217 gtk_widget_in_destruction (GtkWidget *widget)
14219 return widget->priv->in_destruction;
14223 _gtk_widget_get_in_reparent (GtkWidget *widget)
14225 return widget->priv->in_reparent;
14229 _gtk_widget_set_in_reparent (GtkWidget *widget,
14230 gboolean in_reparent)
14232 widget->priv->in_reparent = in_reparent;
14236 _gtk_widget_get_anchored (GtkWidget *widget)
14238 return widget->priv->anchored;
14242 _gtk_widget_set_anchored (GtkWidget *widget,
14245 widget->priv->anchored = anchored;
14249 _gtk_widget_get_shadowed (GtkWidget *widget)
14251 return widget->priv->shadowed;
14255 _gtk_widget_set_shadowed (GtkWidget *widget,
14258 widget->priv->shadowed = shadowed;
14262 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14264 return widget->priv->alloc_needed;
14268 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14269 gboolean alloc_needed)
14271 widget->priv->alloc_needed = alloc_needed;
14275 _gtk_widget_add_sizegroup (GtkWidget *widget,
14280 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14281 groups = g_slist_prepend (groups, group);
14282 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14284 widget->priv->have_size_groups = TRUE;
14288 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14293 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14294 groups = g_slist_remove (groups, group);
14295 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14297 widget->priv->have_size_groups = groups != NULL;
14301 _gtk_widget_get_sizegroups (GtkWidget *widget)
14303 if (widget->priv->have_size_groups)
14304 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14310 _gtk_widget_add_attached_window (GtkWidget *widget,
14313 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14317 _gtk_widget_remove_attached_window (GtkWidget *widget,
14320 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14324 * gtk_widget_path_append_for_widget:
14325 * @path: a widget path
14326 * @widget: the widget to append to the widget path
14328 * Appends the data from @widget to the widget hierarchy represented
14329 * by @path. This function is a shortcut for adding information from
14330 * @widget to the given @path. This includes setting the name or
14331 * adding the style classes from @widget.
14333 * Returns: the position where the data was inserted
14338 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14343 g_return_val_if_fail (path != NULL, 0);
14344 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14346 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14348 if (widget->priv->name)
14349 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14351 if (widget->priv->context)
14353 GList *classes, *l;
14355 /* Also add any persistent classes in
14356 * the style context the widget path
14358 classes = gtk_style_context_list_classes (widget->priv->context);
14360 for (l = classes; l; l = l->next)
14361 gtk_widget_path_iter_add_class (path, pos, l->data);
14363 g_list_free (classes);
14370 _gtk_widget_create_path (GtkWidget *widget)
14374 parent = widget->priv->parent;
14377 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14380 /* Widget is either toplevel or unparented, treat both
14381 * as toplevels style wise, since there are situations
14382 * where style properties might be retrieved on that
14385 GtkWidget *attach_widget = NULL;
14386 GtkWidgetPath *result;
14388 if (GTK_IS_WINDOW (widget))
14389 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14391 if (attach_widget != NULL)
14392 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14394 result = gtk_widget_path_new ();
14396 gtk_widget_path_append_for_widget (result, widget);
14403 * gtk_widget_get_path:
14404 * @widget: a #GtkWidget
14406 * Returns the #GtkWidgetPath representing @widget, if the widget
14407 * is not connected to a toplevel widget, a partial path will be
14410 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14413 gtk_widget_get_path (GtkWidget *widget)
14415 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14417 if (!widget->priv->path)
14418 widget->priv->path = _gtk_widget_create_path (widget);
14420 return widget->priv->path;
14424 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14426 if (widget->priv->path)
14428 gtk_widget_path_free (widget->priv->path);
14429 widget->priv->path = NULL;
14432 if (gtk_widget_get_realized (widget))
14433 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14436 /* Compress all style updates so it
14437 * is only emitted once pre-realize.
14439 widget->priv->style_update_pending = TRUE;
14444 * gtk_widget_get_style_context:
14445 * @widget: a #GtkWidget
14447 * Returns the style context associated to @widget.
14449 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14450 * must not be freed.
14453 gtk_widget_get_style_context (GtkWidget *widget)
14455 GtkWidgetPrivate *priv;
14457 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14459 priv = widget->priv;
14461 if (G_UNLIKELY (priv->context == NULL))
14465 priv->context = gtk_style_context_new ();
14467 gtk_style_context_set_state (priv->context, priv->state_flags);
14469 screen = gtk_widget_get_screen (widget);
14471 gtk_style_context_set_screen (priv->context, screen);
14474 gtk_style_context_set_parent (priv->context,
14475 gtk_widget_get_style_context (priv->parent));
14477 _gtk_style_context_set_widget (priv->context, widget);
14480 return widget->priv->context;
14484 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14485 GtkCssChange change)
14487 GtkWidgetPrivate *priv;
14489 priv = widget->priv;
14491 if (priv->context == NULL)
14494 _gtk_style_context_queue_invalidate (priv->context, change);
14498 * gtk_widget_get_modifier_mask:
14499 * @widget: a #GtkWidget
14500 * @intent: the use case for the modifier mask
14502 * Returns the modifier mask the @widget's windowing system backend
14503 * uses for a particular purpose.
14505 * See gdk_keymap_get_modifier_mask().
14507 * Returns: the modifier mask used for @intent.
14512 gtk_widget_get_modifier_mask (GtkWidget *widget,
14513 GdkModifierIntent intent)
14515 GdkDisplay *display;
14517 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14519 display = gtk_widget_get_display (widget);
14521 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14526 _gtk_widget_get_style (GtkWidget *widget)
14528 return widget->priv->style;
14532 _gtk_widget_set_style (GtkWidget *widget,
14535 widget->priv->style = style;
14539 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14542 GActionMuxer *parent_muxer;
14544 if (widget->priv->muxer == NULL)
14547 if (GTK_IS_MENU (widget))
14548 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14550 parent = gtk_widget_get_parent (widget);
14552 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14554 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14558 _gtk_widget_get_action_muxer (GtkWidget *widget)
14560 if (widget->priv->muxer == NULL)
14562 widget->priv->muxer = g_action_muxer_new ();
14563 _gtk_widget_update_parent_muxer (widget);
14566 return widget->priv->muxer;
14570 * gtk_widget_insert_action_group:
14571 * @widget: a #GtkWidget
14572 * @name: the prefix for actions in @group
14573 * @group: a #GActionGroup
14575 * Inserts @group into @widget. Children of @widget that implement
14576 * #GtkActionable can then be associated with actions in @group by
14577 * setting their 'action-name' to
14578 * @prefix.<replaceable>action-name</replaceable>.
14583 gtk_widget_insert_action_group (GtkWidget *widget,
14585 GActionGroup *group)
14587 GActionMuxer *muxer;
14589 g_return_if_fail (GTK_IS_WIDGET (widget));
14590 g_return_if_fail (name != NULL);
14592 muxer = _gtk_widget_get_action_muxer (widget);
14595 g_action_muxer_insert (muxer, name, group);
14597 g_action_muxer_remove (muxer, name);
14601 * gtk_widget_add_frame_clock_target:
14602 * @widget: a #GtkWidget
14603 * @target: the #GdkClockTarget
14605 * Associates a #GdkClockTarget with the widget. When the widget
14606 * is realized and gets a #GdkFrameClock the clock target will be
14607 * added to that frame clock.
14610 gtk_widget_add_frame_clock_target (GtkWidget *widget,
14611 GdkFrameClockTarget *target)
14613 GtkWidgetPrivate *priv;
14614 priv = widget->priv;
14616 g_return_if_fail (GTK_IS_WIDGET (widget));
14617 g_return_if_fail (GDK_IS_FRAME_CLOCK_TARGET (target));
14619 priv->frame_clock_targets = g_list_prepend (priv->frame_clock_targets, target);
14620 g_object_ref (target);
14622 if (gtk_widget_get_realized (widget))
14624 GdkFrameClock *clock;
14625 clock = gtk_widget_get_frame_clock (widget);
14626 gdk_frame_clock_target_set_clock (target, clock);
14631 * gtk_widget_remove_frame_clock_target:
14632 * @widget: a #GtkWidget
14633 * @target: the #GdkClockTarget
14635 * Removes a #GdkClockTarget previously added with
14636 * gtk_widget_add_frame_clock_target.
14639 gtk_widget_remove_frame_clock_target (GtkWidget *widget,
14640 GdkFrameClockTarget *target)
14642 GtkWidgetPrivate *priv;
14645 g_return_if_fail (GTK_IS_WIDGET (widget));
14646 g_return_if_fail (GDK_IS_FRAME_CLOCK_TARGET (target));
14648 priv = widget->priv;
14650 tmp_list = g_list_find (priv->frame_clock_targets, target);
14651 if (tmp_list == NULL)
14654 priv->frame_clock_targets = g_list_delete_link (priv->frame_clock_targets, tmp_list);
14656 if (gtk_widget_get_realized (widget))
14657 gdk_frame_clock_target_set_clock (target, NULL);
14659 g_object_unref (target);