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"
69 /* for the use of round() */
70 #include "fallback-c89.c"
74 * @Short_description: Base class for all widgets
77 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
78 * widget lifecycle, states and style.
80 * <refsect2 id="geometry-management">
81 * <title>Height-for-width Geometry Management</title>
83 * GTK+ uses a height-for-width (and width-for-height) geometry management
84 * system. Height-for-width means that a widget can change how much
85 * vertical space it needs, depending on the amount of horizontal space
86 * that it is given (and similar for width-for-height). The most common
87 * example is a label that reflows to fill up the available width, wraps
88 * to fewer lines, and therefore needs less height.
90 * Height-for-width geometry management is implemented in GTK+ by way
91 * of five virtual methods:
93 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
94 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
95 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
96 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
97 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
100 * There are some important things to keep in mind when implementing
101 * height-for-width and when using it in container implementations.
103 * The geometry management system will query a widget hierarchy in
104 * only one orientation at a time. When widgets are initially queried
105 * for their minimum sizes it is generally done in two initial passes
106 * in the #GtkSizeRequestMode chosen by the toplevel.
108 * For example, when queried in the normal
109 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
110 * First, the default minimum and natural width for each widget
111 * in the interface will be computed using gtk_widget_get_preferred_width().
112 * Because the preferred widths for each container depend on the preferred
113 * widths of their children, this information propagates up the hierarchy,
114 * and finally a minimum and natural width is determined for the entire
115 * toplevel. Next, the toplevel will use the minimum width to query for the
116 * minimum height contextual to that width using
117 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
118 * recursive operation. The minimum height for the minimum width is normally
119 * used to set the minimum size constraint on the toplevel
120 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
122 * After the toplevel window has initially requested its size in both
123 * dimensions it can go on to allocate itself a reasonable size (or a size
124 * previously specified with gtk_window_set_default_size()). During the
125 * recursive allocation process it's important to note that request cycles
126 * will be recursively executed while container widgets allocate their children.
127 * Each container widget, once allocated a size, will go on to first share the
128 * space in one orientation among its children and then request each child's
129 * height for its target allocated width or its width for allocated height,
130 * depending. In this way a #GtkWidget will typically be requested its size
131 * a number of times before actually being allocated a size. The size a
132 * widget is finally allocated can of course differ from the size it has
133 * requested. For this reason, #GtkWidget caches a small number of results
134 * to avoid re-querying for the same sizes in one allocation cycle.
136 * See <link linkend="container-geometry-management">GtkContainer's
137 * geometry management section</link>
138 * to learn more about how height-for-width allocations are performed
139 * by container widgets.
141 * If a widget does move content around to intelligently use up the
142 * allocated size then it must support the request in both
143 * #GtkSizeRequestModes even if the widget in question only
144 * trades sizes in a single orientation.
146 * For instance, a #GtkLabel that does height-for-width word wrapping
147 * will not expect to have #GtkWidgetClass.get_preferred_height() called
148 * because that call is specific to a width-for-height request. In this
149 * case the label must return the height required for its own minimum
150 * possible width. By following this rule any widget that handles
151 * height-for-width or width-for-height requests will always be allocated
152 * at least enough space to fit its own content.
154 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
155 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
157 * <programlisting><![CDATA[
159 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
161 * if (i_am_in_height_for_width_mode)
165 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
166 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
167 * min_height, nat_height);
171 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
172 * it will return the minimum and natural height for the rotated label here.
175 * ]]></programlisting>
177 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
178 * the minimum and natural width:
180 * <programlisting><![CDATA[
182 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
183 * gint *min_width, gint *nat_width)
185 * if (i_am_in_height_for_width_mode)
187 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
191 * ... again if a widget is sometimes operating in width-for-height mode
192 * (like a rotated GtkLabel) it can go ahead and do its real width for
193 * height calculation here.
196 * ]]></programlisting>
198 * Often a widget needs to get its own request during size request or
199 * allocation. For example, when computing height it may need to also
200 * compute width. Or when deciding how to use an allocation, the widget
201 * may need to know its natural size. In these cases, the widget should
202 * be careful to call its virtual methods directly, like this:
204 * <title>Widget calling its own size request method.</title>
206 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
211 * It will not work to use the wrapper functions, such as
212 * gtk_widget_get_preferred_width() inside your own size request
213 * implementation. These return a request adjusted by #GtkSizeGroup
214 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
215 * widget used the wrappers inside its virtual method implementations,
216 * then the adjustments (such as widget margins) would be applied
217 * twice. GTK+ therefore does not allow this and will warn if you try
220 * Of course if you are getting the size request for
221 * <emphasis>another</emphasis> widget, such as a child of a
222 * container, you <emphasis>must</emphasis> use the wrapper APIs.
223 * Otherwise, you would not properly consider widget margins,
224 * #GtkSizeGroup, and so forth.
227 * <refsect2 id="style-properties">
228 * <title>Style Properties</title>
230 * <structname>GtkWidget</structname> introduces <firstterm>style
231 * properties</firstterm> - these are basically object properties that are stored
232 * not on the object, but in the style object associated to the widget. Style
233 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
234 * This mechanism is used for configuring such things as the location of the
235 * scrollbar arrows through the theme, giving theme authors more control over the
236 * look of applications without the need to write a theme engine in C.
239 * Use gtk_widget_class_install_style_property() to install style properties for
240 * a widget class, gtk_widget_class_find_style_property() or
241 * gtk_widget_class_list_style_properties() to get information about existing
242 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
243 * gtk_widget_style_get_valist() to obtain the value of a style property.
246 * <refsect2 id="GtkWidget-BUILDER-UI">
247 * <title>GtkWidget as GtkBuildable</title>
249 * The GtkWidget implementation of the GtkBuildable interface supports a
250 * custom <accelerator> element, which has attributes named key,
251 * modifiers and signal and allows to specify accelerators.
254 * <title>A UI definition fragment specifying an accelerator</title>
255 * <programlisting><![CDATA[
256 * <object class="GtkButton">
257 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
259 * ]]></programlisting>
262 * In addition to accelerators, <structname>GtkWidget</structname> also support a
263 * custom <accessible> element, which supports actions and relations.
264 * Properties on the accessible implementation of an object can be set by accessing the
265 * internal child "accessible" of a <structname>GtkWidget</structname>.
268 * <title>A UI definition fragment specifying an accessible</title>
269 * <programlisting><![CDATA[
270 * <object class="GtkButton" id="label1"/>
271 * <property name="label">I am a Label for a Button</property>
273 * <object class="GtkButton" id="button1">
275 * <action action_name="click" translatable="yes">Click the button.</action>
276 * <relation target="label1" type="labelled-by"/>
278 * <child internal-child="accessible">
279 * <object class="AtkObject" id="a11y-button1">
280 * <property name="accessible-name">Clickable Button</property>
284 * ]]></programlisting>
287 * Finally, GtkWidget allows style information such as style classes to
288 * be associated with widgets, using the custom <style> element:
290 * <title>A UI definition fragment specifying an style class</title>
291 * <programlisting><![CDATA[
292 * <object class="GtkButton" id="button1">
294 * <class name="my-special-button-class"/>
295 * <class name="dark-button"/>
298 * ]]></programlisting>
304 /* Add flags here that should not be propagated to children. By default,
305 * all flags will be set on children (think prelight or active), but we
306 * might want to not do this for some.
308 #define GTK_STATE_FLAGS_DONT_PROPAGATE (GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)
309 #define GTK_STATE_FLAGS_DO_PROPAGATE (~GTK_STATE_FLAGS_DONT_PROPAGATE)
311 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
313 #define GTK_STATE_FLAGS_BITS 9
315 struct _GtkWidgetPrivate
317 /* The state of the widget. Needs to be able to hold all GtkStateFlags bits
318 * (defined in "gtkenums.h").
320 guint state_flags : GTK_STATE_FLAGS_BITS;
324 guint in_destruction : 1;
327 guint composite_child : 1;
335 guint can_default : 1;
336 guint has_default : 1;
337 guint receives_default : 1;
340 guint style_update_pending : 1;
341 guint app_paintable : 1;
342 guint double_buffered : 1;
343 guint redraw_on_alloc : 1;
344 guint no_show_all : 1;
345 guint child_visible : 1;
346 guint multidevice : 1;
347 guint has_shape_mask : 1;
348 guint in_reparent : 1;
350 /* Queue-resize related flags */
351 guint alloc_needed : 1;
353 /* Expand-related flags */
354 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
355 guint computed_hexpand : 1; /* computed results (composite of child flags) */
356 guint computed_vexpand : 1;
357 guint hexpand : 1; /* application-forced expand */
359 guint hexpand_set : 1; /* whether to use application-forced */
360 guint vexpand_set : 1; /* instead of computing from children */
362 /* SizeGroup related flags */
363 guint have_size_groups : 1;
365 guint opacity_group : 1;
366 guint norender_children : 1;
367 guint norender : 1; /* Don't expose windows, instead recurse via draw */
372 /* The widget's name. If the widget does not have a name
373 * (the name is NULL), then its name (as returned by
374 * "gtk_widget_get_name") is its class's name.
375 * Among other things, the widget name is used to determine
376 * the style to use for a widget.
380 /* The list of attached windows to this widget.
381 * We keep a list in order to call reset_style to all of them,
383 GList *attached_windows;
385 /* The style for the widget. The style contains the
386 * colors the widget should be drawn in for each state
387 * along with graphics contexts used to draw with and
388 * the font to use for text.
391 GtkStyleContext *context;
393 /* Widget's path for styling */
396 /* The widget's allocated size */
397 GtkAllocation allocation;
399 /* The widget's requested sizes */
400 SizeRequestCache requests;
402 /* actions attached to this or any parent widget */
405 /* The widget's window or its parent window if it does
406 * not have a window. (Which will be indicated by the
407 * GTK_NO_WINDOW flag being set).
410 GList *registered_windows;
412 /* The widget's parent */
415 /* Animations and other things to update on clock ticks */
416 GList *tick_callbacks;
418 #ifdef G_ENABLE_DEBUG
419 /* Number of gtk_widget_push_verify_invariants () */
420 guint verifying_invariants_count;
421 #endif /* G_ENABLE_DEBUG */
424 struct _GtkWidgetClassPrivate
426 GType accessible_type;
427 AtkRole accessible_role;
456 BUTTON_RELEASE_EVENT,
470 PROPERTY_NOTIFY_EVENT,
471 SELECTION_CLEAR_EVENT,
472 SELECTION_REQUEST_EVENT,
473 SELECTION_NOTIFY_EVENT,
478 VISIBILITY_NOTIFY_EVENT,
492 ACCEL_CLOSURES_CHANGED,
517 PROP_RECEIVES_DEFAULT,
518 PROP_COMPOSITE_CHILD,
527 PROP_DOUBLE_BUFFERED,
542 typedef struct _GtkStateData GtkStateData;
547 guint flags_to_unset;
550 /* --- prototypes --- */
551 static void gtk_widget_base_class_init (gpointer g_class);
552 static void gtk_widget_class_init (GtkWidgetClass *klass);
553 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
554 static void gtk_widget_init (GtkWidget *widget);
555 static void gtk_widget_set_property (GObject *object,
559 static void gtk_widget_get_property (GObject *object,
563 static void gtk_widget_constructed (GObject *object);
564 static void gtk_widget_dispose (GObject *object);
565 static void gtk_widget_real_destroy (GtkWidget *object);
566 static void gtk_widget_finalize (GObject *object);
567 static void gtk_widget_real_show (GtkWidget *widget);
568 static void gtk_widget_real_hide (GtkWidget *widget);
569 static void gtk_widget_real_map (GtkWidget *widget);
570 static void gtk_widget_real_unmap (GtkWidget *widget);
571 static void gtk_widget_real_realize (GtkWidget *widget);
572 static void gtk_widget_real_unrealize (GtkWidget *widget);
573 static void gtk_widget_real_size_allocate (GtkWidget *widget,
574 GtkAllocation *allocation);
575 static void gtk_widget_real_style_set (GtkWidget *widget,
576 GtkStyle *previous_style);
577 static void gtk_widget_real_direction_changed(GtkWidget *widget,
578 GtkTextDirection previous_direction);
580 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
581 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
584 gboolean keyboard_tip,
585 GtkTooltip *tooltip);
586 static void gtk_widget_real_style_updated (GtkWidget *widget);
587 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
588 GtkWidgetHelpType help_type);
590 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
592 GParamSpec **pspecs);
593 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
595 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
597 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
598 GdkEventFocus *event);
599 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
600 GdkEventFocus *event);
601 static gboolean gtk_widget_real_touch_event (GtkWidget *widget,
602 GdkEventTouch *event);
603 static gboolean gtk_widget_real_focus (GtkWidget *widget,
604 GtkDirectionType direction);
605 static void gtk_widget_real_move_focus (GtkWidget *widget,
606 GtkDirectionType direction);
607 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
608 GtkDirectionType direction);
609 #ifdef G_ENABLE_DEBUG
610 static void gtk_widget_verify_invariants (GtkWidget *widget);
611 static void gtk_widget_push_verify_invariants (GtkWidget *widget);
612 static void gtk_widget_pop_verify_invariants (GtkWidget *widget);
614 #define gtk_widget_verify_invariants(widget)
615 #define gtk_widget_push_verify_invariants(widget)
616 #define gtk_widget_pop_verify_invariants(widget)
618 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
619 static void gtk_widget_update_pango_context (GtkWidget *widget);
620 static void gtk_widget_propagate_state (GtkWidget *widget,
622 static void gtk_widget_update_alpha (GtkWidget *widget);
624 static gint gtk_widget_event_internal (GtkWidget *widget,
626 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
627 gboolean group_cycling);
628 static void gtk_widget_real_get_width (GtkWidget *widget,
631 static void gtk_widget_real_get_height (GtkWidget *widget,
634 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
636 gint *minimum_height,
637 gint *natural_height);
638 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
641 gint *natural_width);
642 static void gtk_widget_real_state_flags_changed (GtkWidget *widget,
643 GtkStateFlags old_state);
644 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
645 static GtkWidgetAuxInfo* gtk_widget_get_aux_info (GtkWidget *widget,
647 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
648 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
649 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
650 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
651 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
652 cairo_region_t *region);
653 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
654 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
657 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
658 gboolean has_tooltip,
660 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
661 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
663 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
664 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
666 const gchar *childname);
667 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
670 const GValue *value);
671 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
674 const gchar *tagname,
675 GMarkupParser *parser,
677 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
680 const gchar *tagname,
682 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
683 GtkBuilder *builder);
685 static GtkSizeRequestMode gtk_widget_real_get_request_mode (GtkWidget *widget);
686 static void gtk_widget_real_get_width (GtkWidget *widget,
689 static void gtk_widget_real_get_height (GtkWidget *widget,
693 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
696 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
697 GtkOrientation orientation,
700 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
701 GtkOrientation orientation,
705 gint *allocated_size);
707 static void gtk_widget_set_usize_internal (GtkWidget *widget,
710 GtkQueueResizeFlags flags);
712 static void gtk_widget_add_events_internal (GtkWidget *widget,
715 static void gtk_widget_set_device_enabled_internal (GtkWidget *widget,
720 static void gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
723 static gboolean event_window_is_still_viewable (GdkEvent *event);
724 static void gtk_cairo_set_event (cairo_t *cr,
725 GdkEventExpose *event);
726 static void gtk_widget_propagate_alpha (GtkWidget *widget);
728 /* --- variables --- */
729 static gpointer gtk_widget_parent_class = NULL;
730 static guint widget_signals[LAST_SIGNAL] = { 0 };
731 static guint composite_child_stack = 0;
732 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
733 static GParamSpecPool *style_property_spec_pool = NULL;
735 static GQuark quark_property_parser = 0;
736 static GQuark quark_aux_info = 0;
737 static GQuark quark_accel_path = 0;
738 static GQuark quark_accel_closures = 0;
739 static GQuark quark_event_mask = 0;
740 static GQuark quark_device_event_mask = 0;
741 static GQuark quark_parent_window = 0;
742 static GQuark quark_pointer_window = 0;
743 static GQuark quark_shape_info = 0;
744 static GQuark quark_input_shape_info = 0;
745 static GQuark quark_pango_context = 0;
746 static GQuark quark_accessible_object = 0;
747 static GQuark quark_mnemonic_labels = 0;
748 static GQuark quark_tooltip_markup = 0;
749 static GQuark quark_has_tooltip = 0;
750 static GQuark quark_tooltip_window = 0;
751 static GQuark quark_visual = 0;
752 static GQuark quark_modifier_style = 0;
753 static GQuark quark_enabled_devices = 0;
754 static GQuark quark_size_groups = 0;
755 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
756 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
758 /* --- functions --- */
760 gtk_widget_get_type (void)
762 static GType widget_type = 0;
764 if (G_UNLIKELY (widget_type == 0))
766 const GTypeInfo widget_info =
768 sizeof (GtkWidgetClass),
769 gtk_widget_base_class_init,
770 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
771 (GClassInitFunc) gtk_widget_class_init,
772 NULL, /* class_finalize */
773 NULL, /* class_init */
776 (GInstanceInitFunc) gtk_widget_init,
777 NULL, /* value_table */
780 const GInterfaceInfo accessibility_info =
782 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
783 (GInterfaceFinalizeFunc) NULL,
784 NULL /* interface data */
787 const GInterfaceInfo buildable_info =
789 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
790 (GInterfaceFinalizeFunc) NULL,
791 NULL /* interface data */
794 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
795 &widget_info, G_TYPE_FLAG_ABSTRACT);
797 g_type_add_class_private (widget_type, sizeof (GtkWidgetClassPrivate));
799 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
800 &accessibility_info) ;
801 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
809 gtk_widget_base_class_init (gpointer g_class)
811 GtkWidgetClass *klass = g_class;
813 klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
817 child_property_notify_dispatcher (GObject *object,
821 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
824 /* We guard against the draw signal callbacks modifying the state of the
825 * cairo context by surounding it with save/restore.
826 * Maybe we should also cairo_new_path() just to be sure?
829 gtk_widget_draw_marshaller (GClosure *closure,
830 GValue *return_value,
831 guint n_param_values,
832 const GValue *param_values,
833 gpointer invocation_hint,
834 gpointer marshal_data)
836 GtkWidget *widget = g_value_get_object (¶m_values[0]);
837 GdkEventExpose *tmp_event;
839 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
842 tmp_event = _gtk_cairo_get_event (cr);
845 widget->priv->opacity_group ||
846 (widget->priv->alpha != 255 &&
847 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
851 cairo_push_group (cr);
852 gtk_cairo_set_event (cr, NULL);
855 _gtk_marshal_BOOLEAN__BOXED (closure,
865 cairo_pop_group_to_source (cr);
866 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
867 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
870 gtk_cairo_set_event (cr, tmp_event);
875 gtk_widget_draw_marshallerv (GClosure *closure,
876 GValue *return_value,
879 gpointer marshal_data,
883 GtkWidget *widget = GTK_WIDGET (instance);
884 GdkEventExpose *tmp_event;
889 G_VA_COPY (args_copy, args);
890 cr = va_arg (args_copy, gpointer);
893 tmp_event = _gtk_cairo_get_event (cr);
896 widget->priv->opacity_group ||
897 (widget->priv->alpha != 255 &&
898 (!gtk_widget_get_has_window (widget) || tmp_event == NULL));
902 cairo_push_group (cr);
903 gtk_cairo_set_event (cr, NULL);
906 _gtk_marshal_BOOLEAN__BOXEDv (closure,
917 cairo_pop_group_to_source (cr);
918 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
919 cairo_paint_with_alpha (cr, widget->priv->alpha / 255.0);
922 gtk_cairo_set_event (cr, tmp_event);
929 gtk_widget_class_init (GtkWidgetClass *klass)
931 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
932 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
933 GtkBindingSet *binding_set;
935 gtk_widget_parent_class = g_type_class_peek_parent (klass);
937 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
938 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
939 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
940 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
941 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
942 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
943 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
944 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
945 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
946 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
947 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
948 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
949 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
950 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
951 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
952 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
953 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
954 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
955 quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices");
956 quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups");
958 style_property_spec_pool = g_param_spec_pool_new (FALSE);
959 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
960 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
961 cpn_context.dispatcher = child_property_notify_dispatcher;
962 _gtk_widget_child_property_notify_context = &cpn_context;
964 gobject_class->constructed = gtk_widget_constructed;
965 gobject_class->dispose = gtk_widget_dispose;
966 gobject_class->finalize = gtk_widget_finalize;
967 gobject_class->set_property = gtk_widget_set_property;
968 gobject_class->get_property = gtk_widget_get_property;
970 klass->destroy = gtk_widget_real_destroy;
972 klass->activate_signal = 0;
973 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
974 klass->show = gtk_widget_real_show;
975 klass->show_all = gtk_widget_show;
976 klass->hide = gtk_widget_real_hide;
977 klass->map = gtk_widget_real_map;
978 klass->unmap = gtk_widget_real_unmap;
979 klass->realize = gtk_widget_real_realize;
980 klass->unrealize = gtk_widget_real_unrealize;
981 klass->size_allocate = gtk_widget_real_size_allocate;
982 klass->get_request_mode = gtk_widget_real_get_request_mode;
983 klass->get_preferred_width = gtk_widget_real_get_width;
984 klass->get_preferred_height = gtk_widget_real_get_height;
985 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
986 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
987 klass->state_changed = NULL;
988 klass->state_flags_changed = gtk_widget_real_state_flags_changed;
989 klass->parent_set = NULL;
990 klass->hierarchy_changed = NULL;
991 klass->style_set = gtk_widget_real_style_set;
992 klass->direction_changed = gtk_widget_real_direction_changed;
993 klass->grab_notify = NULL;
994 klass->child_notify = NULL;
996 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
997 klass->grab_focus = gtk_widget_real_grab_focus;
998 klass->focus = gtk_widget_real_focus;
999 klass->move_focus = gtk_widget_real_move_focus;
1000 klass->keynav_failed = gtk_widget_real_keynav_failed;
1001 klass->event = NULL;
1002 klass->button_press_event = NULL;
1003 klass->button_release_event = NULL;
1004 klass->motion_notify_event = NULL;
1005 klass->touch_event = gtk_widget_real_touch_event;
1006 klass->delete_event = NULL;
1007 klass->destroy_event = NULL;
1008 klass->key_press_event = gtk_widget_real_key_press_event;
1009 klass->key_release_event = gtk_widget_real_key_release_event;
1010 klass->enter_notify_event = NULL;
1011 klass->leave_notify_event = NULL;
1012 klass->configure_event = NULL;
1013 klass->focus_in_event = gtk_widget_real_focus_in_event;
1014 klass->focus_out_event = gtk_widget_real_focus_out_event;
1015 klass->map_event = NULL;
1016 klass->unmap_event = NULL;
1017 klass->window_state_event = NULL;
1018 klass->property_notify_event = _gtk_selection_property_notify;
1019 klass->selection_clear_event = _gtk_selection_clear;
1020 klass->selection_request_event = _gtk_selection_request;
1021 klass->selection_notify_event = _gtk_selection_notify;
1022 klass->selection_received = NULL;
1023 klass->proximity_in_event = NULL;
1024 klass->proximity_out_event = NULL;
1025 klass->drag_begin = NULL;
1026 klass->drag_end = NULL;
1027 klass->drag_data_delete = NULL;
1028 klass->drag_leave = NULL;
1029 klass->drag_motion = NULL;
1030 klass->drag_drop = NULL;
1031 klass->drag_data_received = NULL;
1032 klass->screen_changed = NULL;
1033 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
1034 klass->grab_broken_event = NULL;
1035 klass->query_tooltip = gtk_widget_real_query_tooltip;
1036 klass->style_updated = gtk_widget_real_style_updated;
1038 klass->show_help = gtk_widget_real_show_help;
1040 /* Accessibility support */
1041 klass->priv->accessible_type = GTK_TYPE_ACCESSIBLE;
1042 klass->priv->accessible_role = ATK_ROLE_INVALID;
1043 klass->get_accessible = gtk_widget_real_get_accessible;
1045 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
1046 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
1048 g_object_class_install_property (gobject_class,
1050 g_param_spec_string ("name",
1052 P_("The name of the widget"),
1054 GTK_PARAM_READWRITE));
1055 g_object_class_install_property (gobject_class,
1057 g_param_spec_object ("parent",
1058 P_("Parent widget"),
1059 P_("The parent widget of this widget. Must be a Container widget"),
1061 GTK_PARAM_READWRITE));
1063 g_object_class_install_property (gobject_class,
1065 g_param_spec_int ("width-request",
1066 P_("Width request"),
1067 P_("Override for width request of the widget, or -1 if natural request should be used"),
1071 GTK_PARAM_READWRITE));
1072 g_object_class_install_property (gobject_class,
1073 PROP_HEIGHT_REQUEST,
1074 g_param_spec_int ("height-request",
1075 P_("Height request"),
1076 P_("Override for height request of the widget, or -1 if natural request should be used"),
1080 GTK_PARAM_READWRITE));
1081 g_object_class_install_property (gobject_class,
1083 g_param_spec_boolean ("visible",
1085 P_("Whether the widget is visible"),
1087 GTK_PARAM_READWRITE));
1088 g_object_class_install_property (gobject_class,
1090 g_param_spec_boolean ("sensitive",
1092 P_("Whether the widget responds to input"),
1094 GTK_PARAM_READWRITE));
1095 g_object_class_install_property (gobject_class,
1097 g_param_spec_boolean ("app-paintable",
1098 P_("Application paintable"),
1099 P_("Whether the application will paint directly on the widget"),
1101 GTK_PARAM_READWRITE));
1102 g_object_class_install_property (gobject_class,
1104 g_param_spec_boolean ("can-focus",
1106 P_("Whether the widget can accept the input focus"),
1108 GTK_PARAM_READWRITE));
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_boolean ("has-focus",
1113 P_("Whether the widget has the input focus"),
1115 GTK_PARAM_READWRITE));
1116 g_object_class_install_property (gobject_class,
1118 g_param_spec_boolean ("is-focus",
1120 P_("Whether the widget is the focus widget within the toplevel"),
1122 GTK_PARAM_READWRITE));
1123 g_object_class_install_property (gobject_class,
1125 g_param_spec_boolean ("can-default",
1127 P_("Whether the widget can be the default widget"),
1129 GTK_PARAM_READWRITE));
1130 g_object_class_install_property (gobject_class,
1132 g_param_spec_boolean ("has-default",
1134 P_("Whether the widget is the default widget"),
1136 GTK_PARAM_READWRITE));
1137 g_object_class_install_property (gobject_class,
1138 PROP_RECEIVES_DEFAULT,
1139 g_param_spec_boolean ("receives-default",
1140 P_("Receives default"),
1141 P_("If TRUE, the widget will receive the default action when it is focused"),
1143 GTK_PARAM_READWRITE));
1144 g_object_class_install_property (gobject_class,
1145 PROP_COMPOSITE_CHILD,
1146 g_param_spec_boolean ("composite-child",
1147 P_("Composite child"),
1148 P_("Whether the widget is part of a composite widget"),
1150 GTK_PARAM_READABLE));
1151 g_object_class_install_property (gobject_class,
1153 g_param_spec_object ("style",
1155 P_("The style of the widget, which contains information about how it will look (colors etc)"),
1157 GTK_PARAM_READWRITE));
1158 g_object_class_install_property (gobject_class,
1160 g_param_spec_flags ("events",
1162 P_("The event mask that decides what kind of GdkEvents this widget gets"),
1163 GDK_TYPE_EVENT_MASK,
1165 GTK_PARAM_READWRITE));
1166 g_object_class_install_property (gobject_class,
1168 g_param_spec_boolean ("no-show-all",
1170 P_("Whether gtk_widget_show_all() should not affect this widget"),
1172 GTK_PARAM_READWRITE));
1175 * GtkWidget:has-tooltip:
1177 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1178 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1179 * the widget will be queried using #GtkWidget::query-tooltip to determine
1180 * whether it will provide a tooltip or not.
1182 * Note that setting this property to %TRUE for the first time will change
1183 * the event masks of the GdkWindows of this widget to include leave-notify
1184 * and motion-notify events. This cannot and will not be undone when the
1185 * property is set to %FALSE again.
1189 g_object_class_install_property (gobject_class,
1191 g_param_spec_boolean ("has-tooltip",
1193 P_("Whether this widget has a tooltip"),
1195 GTK_PARAM_READWRITE));
1197 * GtkWidget:tooltip-text:
1199 * Sets the text of tooltip to be the given string.
1201 * Also see gtk_tooltip_set_text().
1203 * This is a convenience property which will take care of getting the
1204 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1205 * will automatically be set to %TRUE and there will be taken care of
1206 * #GtkWidget::query-tooltip in the default signal handler.
1210 g_object_class_install_property (gobject_class,
1212 g_param_spec_string ("tooltip-text",
1214 P_("The contents of the tooltip for this widget"),
1216 GTK_PARAM_READWRITE));
1218 * GtkWidget:tooltip-markup:
1220 * Sets the text of tooltip to be the given string, which is marked up
1221 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1222 * Also see gtk_tooltip_set_markup().
1224 * This is a convenience property which will take care of getting the
1225 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1226 * will automatically be set to %TRUE and there will be taken care of
1227 * #GtkWidget::query-tooltip in the default signal handler.
1231 g_object_class_install_property (gobject_class,
1232 PROP_TOOLTIP_MARKUP,
1233 g_param_spec_string ("tooltip-markup",
1234 P_("Tooltip markup"),
1235 P_("The contents of the tooltip for this widget"),
1237 GTK_PARAM_READWRITE));
1242 * The widget's window if it is realized, %NULL otherwise.
1246 g_object_class_install_property (gobject_class,
1248 g_param_spec_object ("window",
1250 P_("The widget's window if it is realized"),
1252 GTK_PARAM_READABLE));
1255 * GtkWidget:double-buffered:
1257 * Whether the widget is double buffered.
1261 g_object_class_install_property (gobject_class,
1262 PROP_DOUBLE_BUFFERED,
1263 g_param_spec_boolean ("double-buffered",
1264 P_("Double Buffered"),
1265 P_("Whether the widget is double buffered"),
1267 GTK_PARAM_READWRITE));
1272 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1276 g_object_class_install_property (gobject_class,
1278 g_param_spec_enum ("halign",
1279 P_("Horizontal Alignment"),
1280 P_("How to position in extra horizontal space"),
1283 GTK_PARAM_READWRITE));
1288 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1292 g_object_class_install_property (gobject_class,
1294 g_param_spec_enum ("valign",
1295 P_("Vertical Alignment"),
1296 P_("How to position in extra vertical space"),
1299 GTK_PARAM_READWRITE));
1302 * GtkWidget:margin-left:
1304 * Margin on left side of widget.
1306 * This property adds margin outside of the widget's normal size
1307 * request, the margin will be added in addition to the size from
1308 * gtk_widget_set_size_request() for example.
1312 g_object_class_install_property (gobject_class,
1314 g_param_spec_int ("margin-left",
1315 P_("Margin on Left"),
1316 P_("Pixels of extra space on the left side"),
1320 GTK_PARAM_READWRITE));
1323 * GtkWidget:margin-right:
1325 * Margin on right side of widget.
1327 * This property adds margin outside of the widget's normal size
1328 * request, the margin will be added in addition to the size from
1329 * gtk_widget_set_size_request() for example.
1333 g_object_class_install_property (gobject_class,
1335 g_param_spec_int ("margin-right",
1336 P_("Margin on Right"),
1337 P_("Pixels of extra space on the right side"),
1341 GTK_PARAM_READWRITE));
1344 * GtkWidget:margin-top:
1346 * Margin on top side of widget.
1348 * This property adds margin outside of the widget's normal size
1349 * request, the margin will be added in addition to the size from
1350 * gtk_widget_set_size_request() for example.
1354 g_object_class_install_property (gobject_class,
1356 g_param_spec_int ("margin-top",
1357 P_("Margin on Top"),
1358 P_("Pixels of extra space on the top side"),
1362 GTK_PARAM_READWRITE));
1365 * GtkWidget:margin-bottom:
1367 * Margin on bottom side of widget.
1369 * This property adds margin outside of the widget's normal size
1370 * request, the margin will be added in addition to the size from
1371 * gtk_widget_set_size_request() for example.
1375 g_object_class_install_property (gobject_class,
1377 g_param_spec_int ("margin-bottom",
1378 P_("Margin on Bottom"),
1379 P_("Pixels of extra space on the bottom side"),
1383 GTK_PARAM_READWRITE));
1388 * Sets all four sides' margin at once. If read, returns max
1389 * margin on any side.
1393 g_object_class_install_property (gobject_class,
1395 g_param_spec_int ("margin",
1397 P_("Pixels of extra space on all four sides"),
1401 GTK_PARAM_READWRITE));
1404 * GtkWidget::destroy:
1405 * @object: the object which received the signal
1407 * Signals that all holders of a reference to the widget should release
1408 * the reference that they hold. May result in finalization of the widget
1409 * if all references are released.
1411 widget_signals[DESTROY] =
1412 g_signal_new (I_("destroy"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1414 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1415 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1417 _gtk_marshal_VOID__VOID,
1421 * GtkWidget:hexpand:
1423 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1427 g_object_class_install_property (gobject_class,
1429 g_param_spec_boolean ("hexpand",
1430 P_("Horizontal Expand"),
1431 P_("Whether widget wants more horizontal space"),
1433 GTK_PARAM_READWRITE));
1436 * GtkWidget:hexpand-set:
1438 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1442 g_object_class_install_property (gobject_class,
1444 g_param_spec_boolean ("hexpand-set",
1445 P_("Horizontal Expand Set"),
1446 P_("Whether to use the hexpand property"),
1448 GTK_PARAM_READWRITE));
1451 * GtkWidget:vexpand:
1453 * Whether to expand vertically. See gtk_widget_set_vexpand().
1457 g_object_class_install_property (gobject_class,
1459 g_param_spec_boolean ("vexpand",
1460 P_("Vertical Expand"),
1461 P_("Whether widget wants more vertical space"),
1463 GTK_PARAM_READWRITE));
1466 * GtkWidget:vexpand-set:
1468 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1472 g_object_class_install_property (gobject_class,
1474 g_param_spec_boolean ("vexpand-set",
1475 P_("Vertical Expand Set"),
1476 P_("Whether to use the vexpand property"),
1478 GTK_PARAM_READWRITE));
1483 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1487 g_object_class_install_property (gobject_class,
1489 g_param_spec_boolean ("expand",
1491 P_("Whether widget wants to expand in both directions"),
1493 GTK_PARAM_READWRITE));
1496 * GtkWidget:opacity:
1498 * The requested opacity of the widget. See gtk_widget_set_opacity() for
1499 * more details about window opacity.
1501 * Before 3.8 this was only availible in GtkWindow
1505 g_object_class_install_property (gobject_class,
1507 g_param_spec_double ("opacity",
1508 P_("Opacity for Widget"),
1509 P_("The opacity of the widget, from 0 to 1"),
1513 GTK_PARAM_READWRITE));
1516 * @widget: the object which received the signal.
1518 widget_signals[SHOW] =
1519 g_signal_new (I_("show"),
1520 G_TYPE_FROM_CLASS (gobject_class),
1522 G_STRUCT_OFFSET (GtkWidgetClass, show),
1524 _gtk_marshal_VOID__VOID,
1529 * @widget: the object which received the signal.
1531 widget_signals[HIDE] =
1532 g_signal_new (I_("hide"),
1533 G_TYPE_FROM_CLASS (gobject_class),
1535 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1537 _gtk_marshal_VOID__VOID,
1542 * @widget: the object which received the signal.
1544 widget_signals[MAP] =
1545 g_signal_new (I_("map"),
1546 G_TYPE_FROM_CLASS (gobject_class),
1548 G_STRUCT_OFFSET (GtkWidgetClass, map),
1550 _gtk_marshal_VOID__VOID,
1555 * @widget: the object which received the signal.
1557 widget_signals[UNMAP] =
1558 g_signal_new (I_("unmap"),
1559 G_TYPE_FROM_CLASS (gobject_class),
1561 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1563 _gtk_marshal_VOID__VOID,
1567 * GtkWidget::realize:
1568 * @widget: the object which received the signal.
1570 widget_signals[REALIZE] =
1571 g_signal_new (I_("realize"),
1572 G_TYPE_FROM_CLASS (gobject_class),
1574 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1576 _gtk_marshal_VOID__VOID,
1580 * GtkWidget::unrealize:
1581 * @widget: the object which received the signal.
1583 widget_signals[UNREALIZE] =
1584 g_signal_new (I_("unrealize"),
1585 G_TYPE_FROM_CLASS (gobject_class),
1587 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1589 _gtk_marshal_VOID__VOID,
1593 * GtkWidget::size-allocate:
1594 * @widget: the object which received the signal.
1597 widget_signals[SIZE_ALLOCATE] =
1598 g_signal_new (I_("size-allocate"),
1599 G_TYPE_FROM_CLASS (gobject_class),
1601 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1603 _gtk_marshal_VOID__BOXED,
1605 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1608 * GtkWidget::state-changed:
1609 * @widget: the object which received the signal.
1610 * @state: the previous state
1612 * The ::state-changed signal is emitted when the widget state changes.
1613 * See gtk_widget_get_state().
1615 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1617 widget_signals[STATE_CHANGED] =
1618 g_signal_new (I_("state-changed"),
1619 G_TYPE_FROM_CLASS (gobject_class),
1621 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1623 _gtk_marshal_VOID__ENUM,
1625 GTK_TYPE_STATE_TYPE);
1628 * GtkWidget::state-flags-changed:
1629 * @widget: the object which received the signal.
1630 * @flags: The previous state flags.
1632 * The ::state-flags-changed signal is emitted when the widget state
1633 * changes, see gtk_widget_get_state_flags().
1637 widget_signals[STATE_FLAGS_CHANGED] =
1638 g_signal_new (I_("state-flags-changed"),
1639 G_TYPE_FROM_CLASS (gobject_class),
1641 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1643 _gtk_marshal_VOID__FLAGS,
1645 GTK_TYPE_STATE_FLAGS);
1648 * GtkWidget::parent-set:
1649 * @widget: the object on which the signal is emitted
1650 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1651 * just got its initial parent.
1653 * The ::parent-set signal is emitted when a new parent
1654 * has been set on a widget.
1656 widget_signals[PARENT_SET] =
1657 g_signal_new (I_("parent-set"),
1658 G_TYPE_FROM_CLASS (gobject_class),
1660 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1662 _gtk_marshal_VOID__OBJECT,
1667 * GtkWidget::hierarchy-changed:
1668 * @widget: the object on which the signal is emitted
1669 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1670 * if the widget was previously unanchored
1672 * The ::hierarchy-changed signal is emitted when the
1673 * anchored state of a widget changes. A widget is
1674 * <firstterm>anchored</firstterm> when its toplevel
1675 * ancestor is a #GtkWindow. This signal is emitted when
1676 * a widget changes from un-anchored to anchored or vice-versa.
1678 widget_signals[HIERARCHY_CHANGED] =
1679 g_signal_new (I_("hierarchy-changed"),
1680 G_TYPE_FROM_CLASS (gobject_class),
1682 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1684 _gtk_marshal_VOID__OBJECT,
1689 * GtkWidget::style-set:
1690 * @widget: the object on which the signal is emitted
1691 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1692 * just got its initial style
1694 * The ::style-set signal is emitted when a new style has been set
1695 * on a widget. Note that style-modifying functions like
1696 * gtk_widget_modify_base() also cause this signal to be emitted.
1698 * Note that this signal is emitted for changes to the deprecated
1699 * #GtkStyle. To track changes to the #GtkStyleContext associated
1700 * with a widget, use the #GtkWidget::style-updated signal.
1702 * Deprecated:3.0: Use the #GtkWidget::style-updated signal
1704 widget_signals[STYLE_SET] =
1705 g_signal_new (I_("style-set"),
1706 G_TYPE_FROM_CLASS (gobject_class),
1708 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1710 _gtk_marshal_VOID__OBJECT,
1715 * GtkWidget::style-updated:
1716 * @widget: the object on which the signal is emitted
1718 * The ::style-updated signal is emitted when the #GtkStyleContext
1719 * of a widget is changed. Note that style-modifying functions like
1720 * gtk_widget_override_color() also cause this signal to be emitted.
1724 widget_signals[STYLE_UPDATED] =
1725 g_signal_new (I_("style-updated"),
1726 G_TYPE_FROM_CLASS (gobject_class),
1728 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1730 g_cclosure_marshal_VOID__VOID,
1734 * GtkWidget::direction-changed:
1735 * @widget: the object on which the signal is emitted
1736 * @previous_direction: the previous text direction of @widget
1738 * The ::direction-changed signal is emitted when the text direction
1739 * of a widget changes.
1741 widget_signals[DIRECTION_CHANGED] =
1742 g_signal_new (I_("direction-changed"),
1743 G_TYPE_FROM_CLASS (gobject_class),
1745 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1747 _gtk_marshal_VOID__ENUM,
1749 GTK_TYPE_TEXT_DIRECTION);
1752 * GtkWidget::grab-notify:
1753 * @widget: the object which received the signal
1754 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1755 * if it becomes unshadowed
1757 * The ::grab-notify signal is emitted when a widget becomes
1758 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1759 * another widget, or when it becomes unshadowed due to a grab
1762 * A widget is shadowed by a gtk_grab_add() when the topmost
1763 * grab widget in the grab stack of its window group is not
1766 widget_signals[GRAB_NOTIFY] =
1767 g_signal_new (I_("grab-notify"),
1768 G_TYPE_FROM_CLASS (gobject_class),
1770 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1772 _gtk_marshal_VOID__BOOLEAN,
1777 * GtkWidget::child-notify:
1778 * @widget: the object which received the signal
1779 * @child_property: the #GParamSpec of the changed child property
1781 * The ::child-notify signal is emitted for each
1782 * <link linkend="child-properties">child property</link> that has
1783 * changed on an object. The signal's detail holds the property name.
1785 widget_signals[CHILD_NOTIFY] =
1786 g_signal_new (I_("child-notify"),
1787 G_TYPE_FROM_CLASS (gobject_class),
1788 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1789 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1791 g_cclosure_marshal_VOID__PARAM,
1797 * @widget: the object which received the signal
1798 * @cr: the cairo context to draw to
1800 * This signal is emitted when a widget is supposed to render itself.
1801 * The @widget's top left corner must be painted at the origin of
1802 * the passed in context and be sized to the values returned by
1803 * gtk_widget_get_allocated_width() and
1804 * gtk_widget_get_allocated_height().
1806 * Signal handlers connected to this signal can modify the cairo
1807 * context passed as @cr in any way they like and don't need to
1808 * restore it. The signal emission takes care of calling cairo_save()
1809 * before and cairo_restore() after invoking the handler.
1811 * The signal handler will get a @cr with a clip region already set to the
1812 * widget's dirty region, i.e. to the area that needs repainting. Complicated
1813 * widgets that want to avoid redrawing themselves completely can get the full
1814 * extents of the clip region with gdk_cairo_get_clip_rectangle(), or they can
1815 * get a finer-grained representation of the dirty region with
1816 * cairo_copy_clip_rectangle_list().
1818 * Returns: %TRUE to stop other handlers from being invoked for the event.
1819 % %FALSE to propagate the event further.
1823 widget_signals[DRAW] =
1824 g_signal_new (I_("draw"),
1825 G_TYPE_FROM_CLASS (gobject_class),
1827 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1828 _gtk_boolean_handled_accumulator, NULL,
1829 gtk_widget_draw_marshaller,
1831 CAIRO_GOBJECT_TYPE_CONTEXT);
1832 g_signal_set_va_marshaller (widget_signals[DRAW], G_TYPE_FROM_CLASS (klass),
1833 gtk_widget_draw_marshallerv);
1836 * GtkWidget::mnemonic-activate:
1837 * @widget: the object which received the signal.
1840 * Returns: %TRUE to stop other handlers from being invoked for the event.
1841 * %FALSE to propagate the event further.
1843 widget_signals[MNEMONIC_ACTIVATE] =
1844 g_signal_new (I_("mnemonic-activate"),
1845 G_TYPE_FROM_CLASS (gobject_class),
1847 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1848 _gtk_boolean_handled_accumulator, NULL,
1849 _gtk_marshal_BOOLEAN__BOOLEAN,
1854 * GtkWidget::grab-focus:
1855 * @widget: the object which received the signal.
1857 widget_signals[GRAB_FOCUS] =
1858 g_signal_new (I_("grab-focus"),
1859 G_TYPE_FROM_CLASS (gobject_class),
1860 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1861 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1863 _gtk_marshal_VOID__VOID,
1868 * @widget: the object which received the signal.
1871 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1873 widget_signals[FOCUS] =
1874 g_signal_new (I_("focus"),
1875 G_TYPE_FROM_CLASS (klass),
1877 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1878 _gtk_boolean_handled_accumulator, NULL,
1879 _gtk_marshal_BOOLEAN__ENUM,
1881 GTK_TYPE_DIRECTION_TYPE);
1884 * GtkWidget::move-focus:
1885 * @widget: the object which received the signal.
1888 widget_signals[MOVE_FOCUS] =
1889 g_signal_new (I_("move-focus"),
1890 G_TYPE_FROM_CLASS (klass),
1891 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1892 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1894 _gtk_marshal_VOID__ENUM,
1897 GTK_TYPE_DIRECTION_TYPE);
1900 * GtkWidget::keynav-failed:
1901 * @widget: the object which received the signal
1902 * @direction: the direction of movement
1904 * Gets emitted if keyboard navigation fails.
1905 * See gtk_widget_keynav_failed() for details.
1907 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1908 * if the emitting widget should try to handle the keyboard
1909 * navigation attempt in its parent container(s).
1913 widget_signals[KEYNAV_FAILED] =
1914 g_signal_new (I_("keynav-failed"),
1915 G_TYPE_FROM_CLASS (klass),
1917 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1918 _gtk_boolean_handled_accumulator, NULL,
1919 _gtk_marshal_BOOLEAN__ENUM,
1921 GTK_TYPE_DIRECTION_TYPE);
1925 * @widget: the object which received the signal.
1926 * @event: the #GdkEvent which triggered this signal
1928 * The GTK+ main loop will emit three signals for each GDK event delivered
1929 * to a widget: one generic ::event signal, another, more specific,
1930 * signal that matches the type of event delivered (e.g.
1931 * #GtkWidget::key-press-event) and finally a generic
1932 * #GtkWidget::event-after signal.
1934 * Returns: %TRUE to stop other handlers from being invoked for the event
1935 * and to cancel the emission of the second specific ::event signal.
1936 * %FALSE to propagate the event further and to allow the emission of
1937 * the second signal. The ::event-after signal is emitted regardless of
1940 widget_signals[EVENT] =
1941 g_signal_new (I_("event"),
1942 G_TYPE_FROM_CLASS (klass),
1944 G_STRUCT_OFFSET (GtkWidgetClass, event),
1945 _gtk_boolean_handled_accumulator, NULL,
1946 _gtk_marshal_BOOLEAN__BOXED,
1948 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1949 g_signal_set_va_marshaller (widget_signals[EVENT], G_TYPE_FROM_CLASS (klass),
1950 _gtk_marshal_BOOLEAN__BOXEDv);
1953 * GtkWidget::event-after:
1954 * @widget: the object which received the signal.
1955 * @event: the #GdkEvent which triggered this signal
1957 * After the emission of the #GtkWidget::event signal and (optionally)
1958 * the second more specific signal, ::event-after will be emitted
1959 * regardless of the previous two signals handlers return values.
1962 widget_signals[EVENT_AFTER] =
1963 g_signal_new (I_("event-after"),
1964 G_TYPE_FROM_CLASS (klass),
1968 _gtk_marshal_VOID__BOXED,
1970 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1971 g_signal_set_va_marshaller (widget_signals[EVENT_AFTER], G_TYPE_FROM_CLASS (klass),
1972 _gtk_marshal_BOOLEAN__BOXEDv);
1975 * GtkWidget::button-press-event:
1976 * @widget: the object which received the signal.
1977 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1980 * The ::button-press-event signal will be emitted when a button
1981 * (typically from a mouse) is pressed.
1983 * To receive this signal, the #GdkWindow associated to the
1984 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1986 * This signal will be sent to the grab widget if there is one.
1988 * Returns: %TRUE to stop other handlers from being invoked for the event.
1989 * %FALSE to propagate the event further.
1991 widget_signals[BUTTON_PRESS_EVENT] =
1992 g_signal_new (I_("button-press-event"),
1993 G_TYPE_FROM_CLASS (klass),
1995 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1996 _gtk_boolean_handled_accumulator, NULL,
1997 _gtk_marshal_BOOLEAN__BOXED,
1999 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2000 g_signal_set_va_marshaller (widget_signals[BUTTON_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2001 _gtk_marshal_BOOLEAN__BOXEDv);
2004 * GtkWidget::button-release-event:
2005 * @widget: the object which received the signal.
2006 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
2009 * The ::button-release-event signal will be emitted when a button
2010 * (typically from a mouse) is released.
2012 * To receive this signal, the #GdkWindow associated to the
2013 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
2015 * This signal will be sent to the grab widget if there is one.
2017 * Returns: %TRUE to stop other handlers from being invoked for the event.
2018 * %FALSE to propagate the event further.
2020 widget_signals[BUTTON_RELEASE_EVENT] =
2021 g_signal_new (I_("button-release-event"),
2022 G_TYPE_FROM_CLASS (klass),
2024 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
2025 _gtk_boolean_handled_accumulator, NULL,
2026 _gtk_marshal_BOOLEAN__BOXED,
2028 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2029 g_signal_set_va_marshaller (widget_signals[BUTTON_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2030 _gtk_marshal_BOOLEAN__BOXEDv);
2032 widget_signals[TOUCH_EVENT] =
2033 g_signal_new (I_("touch-event"),
2034 G_TYPE_FROM_CLASS (klass),
2036 G_STRUCT_OFFSET (GtkWidgetClass, touch_event),
2037 _gtk_boolean_handled_accumulator, NULL,
2038 _gtk_marshal_BOOLEAN__BOXED,
2040 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2041 g_signal_set_va_marshaller (widget_signals[TOUCH_EVENT], G_TYPE_FROM_CLASS (klass),
2042 _gtk_marshal_BOOLEAN__BOXEDv);
2045 * GtkWidget::scroll-event:
2046 * @widget: the object which received the signal.
2047 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
2050 * The ::scroll-event signal is emitted when a button in the 4 to 7
2051 * range is pressed. Wheel mice are usually configured to generate
2052 * button press events for buttons 4 and 5 when the wheel is turned.
2054 * To receive this signal, the #GdkWindow associated to the widget needs
2055 * to enable the #GDK_SCROLL_MASK mask.
2057 * This signal will be sent to the grab widget if there is one.
2059 * Returns: %TRUE to stop other handlers from being invoked for the event.
2060 * %FALSE to propagate the event further.
2062 widget_signals[SCROLL_EVENT] =
2063 g_signal_new (I_("scroll-event"),
2064 G_TYPE_FROM_CLASS (klass),
2066 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
2067 _gtk_boolean_handled_accumulator, NULL,
2068 _gtk_marshal_BOOLEAN__BOXED,
2070 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2071 g_signal_set_va_marshaller (widget_signals[SCROLL_EVENT], G_TYPE_FROM_CLASS (klass),
2072 _gtk_marshal_BOOLEAN__BOXEDv);
2075 * GtkWidget::motion-notify-event:
2076 * @widget: the object which received the signal.
2077 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
2080 * The ::motion-notify-event signal is emitted when the pointer moves
2081 * over the widget's #GdkWindow.
2083 * To receive this signal, the #GdkWindow associated to the widget
2084 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
2086 * This signal will be sent to the grab widget if there is one.
2088 * Returns: %TRUE to stop other handlers from being invoked for the event.
2089 * %FALSE to propagate the event further.
2091 widget_signals[MOTION_NOTIFY_EVENT] =
2092 g_signal_new (I_("motion-notify-event"),
2093 G_TYPE_FROM_CLASS (klass),
2095 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
2096 _gtk_boolean_handled_accumulator, NULL,
2097 _gtk_marshal_BOOLEAN__BOXED,
2099 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2100 g_signal_set_va_marshaller (widget_signals[MOTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2101 _gtk_marshal_BOOLEAN__BOXEDv);
2104 * GtkWidget::composited-changed:
2105 * @widget: the object on which the signal is emitted
2107 * The ::composited-changed signal is emitted when the composited
2108 * status of @widget<!-- -->s screen changes.
2109 * See gdk_screen_is_composited().
2111 widget_signals[COMPOSITED_CHANGED] =
2112 g_signal_new (I_("composited-changed"),
2113 G_TYPE_FROM_CLASS (klass),
2114 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2115 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
2117 _gtk_marshal_VOID__VOID,
2121 * GtkWidget::delete-event:
2122 * @widget: the object which received the signal
2123 * @event: the event which triggered this signal
2125 * The ::delete-event signal is emitted if a user requests that
2126 * a toplevel window is closed. The default handler for this signal
2127 * destroys the window. Connecting gtk_widget_hide_on_delete() to
2128 * this signal will cause the window to be hidden instead, so that
2129 * it can later be shown again without reconstructing it.
2131 * Returns: %TRUE to stop other handlers from being invoked for the event.
2132 * %FALSE to propagate the event further.
2134 widget_signals[DELETE_EVENT] =
2135 g_signal_new (I_("delete-event"),
2136 G_TYPE_FROM_CLASS (klass),
2138 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
2139 _gtk_boolean_handled_accumulator, NULL,
2140 _gtk_marshal_BOOLEAN__BOXED,
2142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2143 g_signal_set_va_marshaller (widget_signals[DELETE_EVENT], G_TYPE_FROM_CLASS (klass),
2144 _gtk_marshal_BOOLEAN__BOXEDv);
2147 * GtkWidget::destroy-event:
2148 * @widget: the object which received the signal.
2149 * @event: the event which triggered this signal
2151 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
2152 * You rarely get this signal, because most widgets disconnect themselves
2153 * from their window before they destroy it, so no widget owns the
2154 * window at destroy time.
2156 * To receive this signal, the #GdkWindow associated to the widget needs
2157 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2158 * automatically for all new windows.
2160 * Returns: %TRUE to stop other handlers from being invoked for the event.
2161 * %FALSE to propagate the event further.
2163 widget_signals[DESTROY_EVENT] =
2164 g_signal_new (I_("destroy-event"),
2165 G_TYPE_FROM_CLASS (klass),
2167 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
2168 _gtk_boolean_handled_accumulator, NULL,
2169 _gtk_marshal_BOOLEAN__BOXED,
2171 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2172 g_signal_set_va_marshaller (widget_signals[DESTROY_EVENT], G_TYPE_FROM_CLASS (klass),
2173 _gtk_marshal_BOOLEAN__BOXEDv);
2176 * GtkWidget::key-press-event:
2177 * @widget: the object which received the signal
2178 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2180 * The ::key-press-event signal is emitted when a key is pressed. The signal
2181 * emission will reoccur at the key-repeat rate when the key is kept pressed.
2183 * To receive this signal, the #GdkWindow associated to the widget needs
2184 * to enable the #GDK_KEY_PRESS_MASK mask.
2186 * This signal will be sent to the grab widget if there is one.
2188 * Returns: %TRUE to stop other handlers from being invoked for the event.
2189 * %FALSE to propagate the event further.
2191 widget_signals[KEY_PRESS_EVENT] =
2192 g_signal_new (I_("key-press-event"),
2193 G_TYPE_FROM_CLASS (klass),
2195 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
2196 _gtk_boolean_handled_accumulator, NULL,
2197 _gtk_marshal_BOOLEAN__BOXED,
2199 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2200 g_signal_set_va_marshaller (widget_signals[KEY_PRESS_EVENT], G_TYPE_FROM_CLASS (klass),
2201 _gtk_marshal_BOOLEAN__BOXEDv);
2204 * GtkWidget::key-release-event:
2205 * @widget: the object which received the signal
2206 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
2208 * The ::key-release-event signal is emitted when a key is released.
2210 * To receive this signal, the #GdkWindow associated to the widget needs
2211 * to enable the #GDK_KEY_RELEASE_MASK mask.
2213 * This signal will be sent to the grab widget if there is one.
2215 * Returns: %TRUE to stop other handlers from being invoked for the event.
2216 * %FALSE to propagate the event further.
2218 widget_signals[KEY_RELEASE_EVENT] =
2219 g_signal_new (I_("key-release-event"),
2220 G_TYPE_FROM_CLASS (klass),
2222 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
2223 _gtk_boolean_handled_accumulator, NULL,
2224 _gtk_marshal_BOOLEAN__BOXED,
2226 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2227 g_signal_set_va_marshaller (widget_signals[KEY_RELEASE_EVENT], G_TYPE_FROM_CLASS (klass),
2228 _gtk_marshal_BOOLEAN__BOXEDv);
2231 * GtkWidget::enter-notify-event:
2232 * @widget: the object which received the signal
2233 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2236 * The ::enter-notify-event will be emitted when the pointer enters
2237 * the @widget's window.
2239 * To receive this signal, the #GdkWindow associated to the widget needs
2240 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
2242 * This signal will be sent to the grab widget if there is one.
2244 * Returns: %TRUE to stop other handlers from being invoked for the event.
2245 * %FALSE to propagate the event further.
2247 widget_signals[ENTER_NOTIFY_EVENT] =
2248 g_signal_new (I_("enter-notify-event"),
2249 G_TYPE_FROM_CLASS (klass),
2251 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2252 _gtk_boolean_handled_accumulator, NULL,
2253 _gtk_marshal_BOOLEAN__BOXED,
2255 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2256 g_signal_set_va_marshaller (widget_signals[ENTER_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2257 _gtk_marshal_BOOLEAN__BOXEDv);
2260 * GtkWidget::leave-notify-event:
2261 * @widget: the object which received the signal
2262 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2265 * The ::leave-notify-event will be emitted when the pointer leaves
2266 * the @widget's window.
2268 * To receive this signal, the #GdkWindow associated to the widget needs
2269 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2271 * This signal will be sent to the grab widget if there is one.
2273 * Returns: %TRUE to stop other handlers from being invoked for the event.
2274 * %FALSE to propagate the event further.
2276 widget_signals[LEAVE_NOTIFY_EVENT] =
2277 g_signal_new (I_("leave-notify-event"),
2278 G_TYPE_FROM_CLASS (klass),
2280 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2281 _gtk_boolean_handled_accumulator, NULL,
2282 _gtk_marshal_BOOLEAN__BOXED,
2284 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2285 g_signal_set_va_marshaller (widget_signals[LEAVE_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2286 _gtk_marshal_BOOLEAN__BOXEDv);
2289 * GtkWidget::configure-event:
2290 * @widget: the object which received the signal
2291 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2294 * The ::configure-event signal will be emitted when the size, position or
2295 * stacking of the @widget's window has changed.
2297 * To receive this signal, the #GdkWindow associated to the widget needs
2298 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2299 * automatically for all new windows.
2301 * Returns: %TRUE to stop other handlers from being invoked for the event.
2302 * %FALSE to propagate the event further.
2304 widget_signals[CONFIGURE_EVENT] =
2305 g_signal_new (I_("configure-event"),
2306 G_TYPE_FROM_CLASS (klass),
2308 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2309 _gtk_boolean_handled_accumulator, NULL,
2310 _gtk_marshal_BOOLEAN__BOXED,
2312 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2313 g_signal_set_va_marshaller (widget_signals[CONFIGURE_EVENT], G_TYPE_FROM_CLASS (klass),
2314 _gtk_marshal_BOOLEAN__BOXEDv);
2317 * GtkWidget::focus-in-event:
2318 * @widget: the object which received the signal
2319 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2322 * The ::focus-in-event signal will be emitted when the keyboard focus
2323 * enters the @widget's window.
2325 * To receive this signal, the #GdkWindow associated to the widget needs
2326 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2328 * Returns: %TRUE to stop other handlers from being invoked for the event.
2329 * %FALSE to propagate the event further.
2331 widget_signals[FOCUS_IN_EVENT] =
2332 g_signal_new (I_("focus-in-event"),
2333 G_TYPE_FROM_CLASS (klass),
2335 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2336 _gtk_boolean_handled_accumulator, NULL,
2337 _gtk_marshal_BOOLEAN__BOXED,
2339 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2340 g_signal_set_va_marshaller (widget_signals[FOCUS_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2341 _gtk_marshal_BOOLEAN__BOXEDv);
2344 * GtkWidget::focus-out-event:
2345 * @widget: the object which received the signal
2346 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2349 * The ::focus-out-event signal will be emitted when the keyboard focus
2350 * leaves the @widget's window.
2352 * To receive this signal, the #GdkWindow associated to the widget needs
2353 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2355 * Returns: %TRUE to stop other handlers from being invoked for the event.
2356 * %FALSE to propagate the event further.
2358 widget_signals[FOCUS_OUT_EVENT] =
2359 g_signal_new (I_("focus-out-event"),
2360 G_TYPE_FROM_CLASS (klass),
2362 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2363 _gtk_boolean_handled_accumulator, NULL,
2364 _gtk_marshal_BOOLEAN__BOXED,
2366 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2367 g_signal_set_va_marshaller (widget_signals[FOCUS_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2368 _gtk_marshal_BOOLEAN__BOXEDv);
2371 * GtkWidget::map-event:
2372 * @widget: the object which received the signal
2373 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2375 * The ::map-event signal will be emitted when the @widget's window is
2376 * mapped. A window is mapped when it becomes visible on the screen.
2378 * To receive this signal, the #GdkWindow associated to the widget needs
2379 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2380 * automatically for all new windows.
2382 * Returns: %TRUE to stop other handlers from being invoked for the event.
2383 * %FALSE to propagate the event further.
2385 widget_signals[MAP_EVENT] =
2386 g_signal_new (I_("map-event"),
2387 G_TYPE_FROM_CLASS (klass),
2389 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2390 _gtk_boolean_handled_accumulator, NULL,
2391 _gtk_marshal_BOOLEAN__BOXED,
2393 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2394 g_signal_set_va_marshaller (widget_signals[MAP_EVENT], G_TYPE_FROM_CLASS (klass),
2395 _gtk_marshal_BOOLEAN__BOXEDv);
2398 * GtkWidget::unmap-event:
2399 * @widget: the object which received the signal
2400 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2402 * The ::unmap-event signal will be emitted when the @widget's window is
2403 * unmapped. A window is unmapped when it becomes invisible on the screen.
2405 * To receive this signal, the #GdkWindow associated to the widget needs
2406 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2407 * automatically for all new windows.
2409 * Returns: %TRUE to stop other handlers from being invoked for the event.
2410 * %FALSE to propagate the event further.
2412 widget_signals[UNMAP_EVENT] =
2413 g_signal_new (I_("unmap-event"),
2414 G_TYPE_FROM_CLASS (klass),
2416 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2417 _gtk_boolean_handled_accumulator, NULL,
2418 _gtk_marshal_BOOLEAN__BOXED,
2420 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2421 g_signal_set_va_marshaller (widget_signals[UNMAP_EVENT], G_TYPE_FROM_CLASS (klass),
2422 _gtk_marshal_BOOLEAN__BOXEDv);
2425 * GtkWidget::property-notify-event:
2426 * @widget: the object which received the signal
2427 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2430 * The ::property-notify-event signal will be emitted when a property on
2431 * the @widget's window has been changed or deleted.
2433 * To receive this signal, the #GdkWindow associated to the widget needs
2434 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2436 * Returns: %TRUE to stop other handlers from being invoked for the event.
2437 * %FALSE to propagate the event further.
2439 widget_signals[PROPERTY_NOTIFY_EVENT] =
2440 g_signal_new (I_("property-notify-event"),
2441 G_TYPE_FROM_CLASS (klass),
2443 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2444 _gtk_boolean_handled_accumulator, NULL,
2445 _gtk_marshal_BOOLEAN__BOXED,
2447 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2448 g_signal_set_va_marshaller (widget_signals[PROPERTY_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2449 _gtk_marshal_BOOLEAN__BOXEDv);
2452 * GtkWidget::selection-clear-event:
2453 * @widget: the object which received the signal
2454 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2457 * The ::selection-clear-event signal will be emitted when the
2458 * the @widget's window has lost ownership of a selection.
2460 * Returns: %TRUE to stop other handlers from being invoked for the event.
2461 * %FALSE to propagate the event further.
2463 widget_signals[SELECTION_CLEAR_EVENT] =
2464 g_signal_new (I_("selection-clear-event"),
2465 G_TYPE_FROM_CLASS (klass),
2467 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2468 _gtk_boolean_handled_accumulator, NULL,
2469 _gtk_marshal_BOOLEAN__BOXED,
2471 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2472 g_signal_set_va_marshaller (widget_signals[SELECTION_CLEAR_EVENT], G_TYPE_FROM_CLASS (klass),
2473 _gtk_marshal_BOOLEAN__BOXEDv);
2476 * GtkWidget::selection-request-event:
2477 * @widget: the object which received the signal
2478 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2481 * The ::selection-request-event signal will be emitted when
2482 * another client requests ownership of the selection owned by
2483 * the @widget's window.
2485 * Returns: %TRUE to stop other handlers from being invoked for the event.
2486 * %FALSE to propagate the event further.
2488 widget_signals[SELECTION_REQUEST_EVENT] =
2489 g_signal_new (I_("selection-request-event"),
2490 G_TYPE_FROM_CLASS (klass),
2492 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2493 _gtk_boolean_handled_accumulator, NULL,
2494 _gtk_marshal_BOOLEAN__BOXED,
2496 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2497 g_signal_set_va_marshaller (widget_signals[SELECTION_REQUEST_EVENT], G_TYPE_FROM_CLASS (klass),
2498 _gtk_marshal_BOOLEAN__BOXEDv);
2501 * GtkWidget::selection-notify-event:
2502 * @widget: the object which received the signal.
2503 * @event: (type Gdk.EventSelection):
2505 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2507 widget_signals[SELECTION_NOTIFY_EVENT] =
2508 g_signal_new (I_("selection-notify-event"),
2509 G_TYPE_FROM_CLASS (klass),
2511 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2512 _gtk_boolean_handled_accumulator, NULL,
2513 _gtk_marshal_BOOLEAN__BOXED,
2515 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2516 g_signal_set_va_marshaller (widget_signals[SELECTION_NOTIFY_EVENT], G_TYPE_FROM_CLASS (klass),
2517 _gtk_marshal_BOOLEAN__BOXEDv);
2520 * GtkWidget::selection-received:
2521 * @widget: the object which received the signal.
2525 widget_signals[SELECTION_RECEIVED] =
2526 g_signal_new (I_("selection-received"),
2527 G_TYPE_FROM_CLASS (klass),
2529 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2531 _gtk_marshal_VOID__BOXED_UINT,
2533 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2537 * GtkWidget::selection-get:
2538 * @widget: the object which received the signal.
2543 widget_signals[SELECTION_GET] =
2544 g_signal_new (I_("selection-get"),
2545 G_TYPE_FROM_CLASS (klass),
2547 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2549 _gtk_marshal_VOID__BOXED_UINT_UINT,
2551 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2556 * GtkWidget::proximity-in-event:
2557 * @widget: the object which received the signal
2558 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2561 * To receive this signal the #GdkWindow associated to the widget needs
2562 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2564 * This signal will be sent to the grab widget if there is one.
2566 * Returns: %TRUE to stop other handlers from being invoked for the event.
2567 * %FALSE to propagate the event further.
2569 widget_signals[PROXIMITY_IN_EVENT] =
2570 g_signal_new (I_("proximity-in-event"),
2571 G_TYPE_FROM_CLASS (klass),
2573 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2574 _gtk_boolean_handled_accumulator, NULL,
2575 _gtk_marshal_BOOLEAN__BOXED,
2577 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2578 g_signal_set_va_marshaller (widget_signals[PROXIMITY_IN_EVENT], G_TYPE_FROM_CLASS (klass),
2579 _gtk_marshal_BOOLEAN__BOXEDv);
2582 * GtkWidget::proximity-out-event:
2583 * @widget: the object which received the signal
2584 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2587 * To receive this signal the #GdkWindow associated to the widget needs
2588 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2590 * This signal will be sent to the grab widget if there is one.
2592 * Returns: %TRUE to stop other handlers from being invoked for the event.
2593 * %FALSE to propagate the event further.
2595 widget_signals[PROXIMITY_OUT_EVENT] =
2596 g_signal_new (I_("proximity-out-event"),
2597 G_TYPE_FROM_CLASS (klass),
2599 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2600 _gtk_boolean_handled_accumulator, NULL,
2601 _gtk_marshal_BOOLEAN__BOXED,
2603 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2604 g_signal_set_va_marshaller (widget_signals[PROXIMITY_OUT_EVENT], G_TYPE_FROM_CLASS (klass),
2605 _gtk_marshal_BOOLEAN__BOXEDv);
2608 * GtkWidget::drag-leave:
2609 * @widget: the object which received the signal.
2610 * @context: the drag context
2611 * @time: the timestamp of the motion event
2613 * The ::drag-leave signal is emitted on the drop site when the cursor
2614 * leaves the widget. A typical reason to connect to this signal is to
2615 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2616 * with gtk_drag_unhighlight()
2618 widget_signals[DRAG_LEAVE] =
2619 g_signal_new (I_("drag-leave"),
2620 G_TYPE_FROM_CLASS (klass),
2622 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2624 _gtk_marshal_VOID__OBJECT_UINT,
2626 GDK_TYPE_DRAG_CONTEXT,
2630 * GtkWidget::drag-begin:
2631 * @widget: the object which received the signal
2632 * @context: the drag context
2634 * The ::drag-begin signal is emitted on the drag source when a drag is
2635 * started. A typical reason to connect to this signal is to set up a
2636 * custom drag icon with e.g. gtk_drag_source_set_icon_pixbuf().
2638 * Note that some widgets set up a drag icon in the default handler of
2639 * this signal, so you may have to use g_signal_connect_after() to
2640 * override what the default handler did.
2642 widget_signals[DRAG_BEGIN] =
2643 g_signal_new (I_("drag-begin"),
2644 G_TYPE_FROM_CLASS (klass),
2646 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2648 _gtk_marshal_VOID__OBJECT,
2650 GDK_TYPE_DRAG_CONTEXT);
2653 * GtkWidget::drag-end:
2654 * @widget: the object which received the signal
2655 * @context: the drag context
2657 * The ::drag-end signal is emitted on the drag source when a drag is
2658 * finished. A typical reason to connect to this signal is to undo
2659 * things done in #GtkWidget::drag-begin.
2661 widget_signals[DRAG_END] =
2662 g_signal_new (I_("drag-end"),
2663 G_TYPE_FROM_CLASS (klass),
2665 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2667 _gtk_marshal_VOID__OBJECT,
2669 GDK_TYPE_DRAG_CONTEXT);
2672 * GtkWidget::drag-data-delete:
2673 * @widget: the object which received the signal
2674 * @context: the drag context
2676 * The ::drag-data-delete signal is emitted on the drag source when a drag
2677 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2678 * handler is responsible for deleting the data that has been dropped. What
2679 * "delete" means depends on the context of the drag operation.
2681 widget_signals[DRAG_DATA_DELETE] =
2682 g_signal_new (I_("drag-data-delete"),
2683 G_TYPE_FROM_CLASS (klass),
2685 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2687 _gtk_marshal_VOID__OBJECT,
2689 GDK_TYPE_DRAG_CONTEXT);
2692 * GtkWidget::drag-failed:
2693 * @widget: the object which received the signal
2694 * @context: the drag context
2695 * @result: the result of the drag operation
2697 * The ::drag-failed signal is emitted on the drag source when a drag has
2698 * failed. The signal handler may hook custom code to handle a failed DND
2699 * operation based on the type of error, it returns %TRUE is the failure has
2700 * been already handled (not showing the default "drag operation failed"
2701 * animation), otherwise it returns %FALSE.
2703 * Return value: %TRUE if the failed drag operation has been already handled.
2707 widget_signals[DRAG_FAILED] =
2708 g_signal_new (I_("drag-failed"),
2709 G_TYPE_FROM_CLASS (klass),
2711 G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
2712 _gtk_boolean_handled_accumulator, NULL,
2713 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2715 GDK_TYPE_DRAG_CONTEXT,
2716 GTK_TYPE_DRAG_RESULT);
2719 * GtkWidget::drag-motion:
2720 * @widget: the object which received the signal
2721 * @context: the drag context
2722 * @x: the x coordinate of the current cursor position
2723 * @y: the y coordinate of the current cursor position
2724 * @time: the timestamp of the motion event
2726 * The ::drag-motion signal is emitted on the drop site when the user
2727 * moves the cursor over the widget during a drag. The signal handler
2728 * must determine whether the cursor position is in a drop zone or not.
2729 * If it is not in a drop zone, it returns %FALSE and no further processing
2730 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2731 * handler is responsible for providing the necessary information for
2732 * displaying feedback to the user, by calling gdk_drag_status().
2734 * If the decision whether the drop will be accepted or rejected can't be
2735 * made based solely on the cursor position and the type of the data, the
2736 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2737 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2738 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2739 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2740 * when using the drag-motion signal that way.
2742 * Also note that there is no drag-enter signal. The drag receiver has to
2743 * keep track of whether he has received any drag-motion signals since the
2744 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2745 * an "enter" signal. Upon an "enter", the handler will typically highlight
2746 * the drop site with gtk_drag_highlight().
2749 * drag_motion (GtkWidget *widget,
2750 * GdkDragContext *context,
2757 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2759 * if (!private_data->drag_highlight)
2761 * private_data->drag_highlight = 1;
2762 * gtk_drag_highlight (widget);
2765 * target = gtk_drag_dest_find_target (widget, context, NULL);
2766 * if (target == GDK_NONE)
2767 * gdk_drag_status (context, 0, time);
2770 * private_data->pending_status = gdk_drag_context_get_suggested_action (context);
2771 * gtk_drag_get_data (widget, context, target, time);
2778 * drag_data_received (GtkWidget *widget,
2779 * GdkDragContext *context,
2782 * GtkSelectionData *selection_data,
2786 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2788 * if (private_data->suggested_action)
2790 * private_data->suggested_action = 0;
2792 * /* We are getting this data due to a request in drag_motion,
2793 * * rather than due to a request in drag_drop, so we are just
2794 * * supposed to call gdk_drag_status(), not actually paste in
2797 * str = gtk_selection_data_get_text (selection_data);
2798 * if (!data_is_acceptable (str))
2799 * gdk_drag_status (context, 0, time);
2801 * gdk_drag_status (context, private_data->suggested_action, time);
2805 * /* accept the drop */
2810 * Returns: whether the cursor position is in a drop zone
2812 widget_signals[DRAG_MOTION] =
2813 g_signal_new (I_("drag-motion"),
2814 G_TYPE_FROM_CLASS (klass),
2816 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2817 _gtk_boolean_handled_accumulator, NULL,
2818 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2820 GDK_TYPE_DRAG_CONTEXT,
2826 * GtkWidget::drag-drop:
2827 * @widget: the object which received the signal
2828 * @context: the drag context
2829 * @x: the x coordinate of the current cursor position
2830 * @y: the y coordinate of the current cursor position
2831 * @time: the timestamp of the motion event
2833 * The ::drag-drop signal is emitted on the drop site when the user drops
2834 * the data onto the widget. The signal handler must determine whether
2835 * the cursor position is in a drop zone or not. If it is not in a drop
2836 * zone, it returns %FALSE and no further processing is necessary.
2837 * Otherwise, the handler returns %TRUE. In this case, the handler must
2838 * ensure that gtk_drag_finish() is called to let the source know that
2839 * the drop is done. The call to gtk_drag_finish() can be done either
2840 * directly or in a #GtkWidget::drag-data-received handler which gets
2841 * triggered by calling gtk_drag_get_data() to receive the data for one
2842 * or more of the supported targets.
2844 * Returns: whether the cursor position is in a drop zone
2846 widget_signals[DRAG_DROP] =
2847 g_signal_new (I_("drag-drop"),
2848 G_TYPE_FROM_CLASS (klass),
2850 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2851 _gtk_boolean_handled_accumulator, NULL,
2852 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2854 GDK_TYPE_DRAG_CONTEXT,
2860 * GtkWidget::drag-data-get:
2861 * @widget: the object which received the signal
2862 * @context: the drag context
2863 * @data: the #GtkSelectionData to be filled with the dragged data
2864 * @info: the info that has been registered with the target in the
2866 * @time: the timestamp at which the data was requested
2868 * The ::drag-data-get signal is emitted on the drag source when the drop
2869 * site requests the data which is dragged. It is the responsibility of
2870 * the signal handler to fill @data with the data in the format which
2871 * is indicated by @info. See gtk_selection_data_set() and
2872 * gtk_selection_data_set_text().
2874 widget_signals[DRAG_DATA_GET] =
2875 g_signal_new (I_("drag-data-get"),
2876 G_TYPE_FROM_CLASS (klass),
2878 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2880 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2882 GDK_TYPE_DRAG_CONTEXT,
2883 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2888 * GtkWidget::drag-data-received:
2889 * @widget: the object which received the signal
2890 * @context: the drag context
2891 * @x: where the drop happened
2892 * @y: where the drop happened
2893 * @data: the received data
2894 * @info: the info that has been registered with the target in the
2896 * @time: the timestamp at which the data was received
2898 * The ::drag-data-received signal is emitted on the drop site when the
2899 * dragged data has been received. If the data was received in order to
2900 * determine whether the drop will be accepted, the handler is expected
2901 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2902 * If the data was received in response to a #GtkWidget::drag-drop signal
2903 * (and this is the last target to be received), the handler for this
2904 * signal is expected to process the received data and then call
2905 * gtk_drag_finish(), setting the @success parameter depending on
2906 * whether the data was processed successfully.
2908 * The handler may inspect the selected action with
2909 * gdk_drag_context_get_selected_action() before calling
2910 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as
2911 * shown in the following example:
2914 * drag_data_received (GtkWidget *widget,
2915 * GdkDragContext *context,
2918 * GtkSelectionData *data,
2922 * if ((data->length >= 0) && (data->format == 8))
2924 * GdkDragAction action;
2926 * /* handle data here */
2928 * action = gdk_drag_context_get_selected_action (context);
2929 * if (action == GDK_ACTION_ASK)
2931 * GtkWidget *dialog;
2934 * dialog = gtk_message_dialog_new (NULL,
2935 * GTK_DIALOG_MODAL |
2936 * GTK_DIALOG_DESTROY_WITH_PARENT,
2938 * GTK_BUTTONS_YES_NO,
2939 * "Move the data ?\n");
2940 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2941 * gtk_widget_destroy (dialog);
2943 * if (response == GTK_RESPONSE_YES)
2944 * action = GDK_ACTION_MOVE;
2946 * action = GDK_ACTION_COPY;
2949 * gtk_drag_finish (context, TRUE, action == GDK_ACTION_MOVE, time);
2952 * gtk_drag_finish (context, FALSE, FALSE, time);
2956 widget_signals[DRAG_DATA_RECEIVED] =
2957 g_signal_new (I_("drag-data-received"),
2958 G_TYPE_FROM_CLASS (klass),
2960 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2962 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2964 GDK_TYPE_DRAG_CONTEXT,
2967 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2972 * GtkWidget::visibility-notify-event:
2973 * @widget: the object which received the signal
2974 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2975 * triggered this signal.
2977 * The ::visibility-notify-event will be emitted when the @widget's window
2978 * is obscured or unobscured.
2980 * To receive this signal the #GdkWindow associated to the widget needs
2981 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2983 * Returns: %TRUE to stop other handlers from being invoked for the event.
2984 * %FALSE to propagate the event further.
2986 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2987 g_signal_new (I_("visibility-notify-event"),
2988 G_TYPE_FROM_CLASS (klass),
2990 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2991 _gtk_boolean_handled_accumulator, NULL,
2992 _gtk_marshal_BOOLEAN__BOXED,
2994 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2997 * GtkWidget::window-state-event:
2998 * @widget: the object which received the signal
2999 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
3000 * triggered this signal.
3002 * The ::window-state-event will be emitted when the state of the
3003 * toplevel window associated to the @widget changes.
3005 * To receive this signal the #GdkWindow associated to the widget
3006 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
3007 * this mask automatically for all new windows.
3009 * Returns: %TRUE to stop other handlers from being invoked for the
3010 * event. %FALSE to propagate the event further.
3012 widget_signals[WINDOW_STATE_EVENT] =
3013 g_signal_new (I_("window-state-event"),
3014 G_TYPE_FROM_CLASS (klass),
3016 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
3017 _gtk_boolean_handled_accumulator, NULL,
3018 _gtk_marshal_BOOLEAN__BOXED,
3020 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3021 g_signal_set_va_marshaller (widget_signals[WINDOW_STATE_EVENT], G_TYPE_FROM_CLASS (klass),
3022 _gtk_marshal_BOOLEAN__BOXEDv);
3025 * GtkWidget::damage-event:
3026 * @widget: the object which received the signal
3027 * @event: (type Gdk.EventExpose): the #GdkEventExpose event
3029 * Emitted when a redirected window belonging to @widget gets drawn into.
3030 * The region/area members of the event shows what area of the redirected
3031 * drawable was drawn into.
3033 * Returns: %TRUE to stop other handlers from being invoked for the event.
3034 * %FALSE to propagate the event further.
3038 widget_signals[DAMAGE_EVENT] =
3039 g_signal_new (I_("damage-event"),
3040 G_TYPE_FROM_CLASS (klass),
3042 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
3043 _gtk_boolean_handled_accumulator, NULL,
3044 _gtk_marshal_BOOLEAN__BOXED,
3046 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3047 g_signal_set_va_marshaller (widget_signals[DAMAGE_EVENT], G_TYPE_FROM_CLASS (klass),
3048 _gtk_marshal_BOOLEAN__BOXEDv);
3051 * GtkWidget::grab-broken-event:
3052 * @widget: the object which received the signal
3053 * @event: (type Gdk.EventGrabBroken): the #GdkEventGrabBroken event
3055 * Emitted when a pointer or keyboard grab on a window belonging
3056 * to @widget gets broken.
3058 * On X11, this happens when the grab window becomes unviewable
3059 * (i.e. it or one of its ancestors is unmapped), or if the same
3060 * application grabs the pointer or keyboard again.
3062 * Returns: %TRUE to stop other handlers from being invoked for
3063 * the event. %FALSE to propagate the event further.
3067 widget_signals[GRAB_BROKEN_EVENT] =
3068 g_signal_new (I_("grab-broken-event"),
3069 G_TYPE_FROM_CLASS (klass),
3071 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
3072 _gtk_boolean_handled_accumulator, NULL,
3073 _gtk_marshal_BOOLEAN__BOXED,
3075 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
3076 g_signal_set_va_marshaller (widget_signals[GRAB_BROKEN_EVENT], G_TYPE_FROM_CLASS (klass),
3077 _gtk_marshal_BOOLEAN__BOXEDv);
3080 * GtkWidget::query-tooltip:
3081 * @widget: the object which received the signal
3082 * @x: the x coordinate of the cursor position where the request has
3083 * been emitted, relative to @widget's left side
3084 * @y: the y coordinate of the cursor position where the request has
3085 * been emitted, relative to @widget's top
3086 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
3087 * @tooltip: a #GtkTooltip
3089 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
3090 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
3091 * focus in keyboard mode.
3093 * Using the given coordinates, the signal handler should determine
3094 * whether a tooltip should be shown for @widget. If this is the case
3095 * %TRUE should be returned, %FALSE otherwise. Note that if
3096 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
3097 * should not be used.
3099 * The signal handler is free to manipulate @tooltip with the therefore
3100 * destined function calls.
3102 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
3106 widget_signals[QUERY_TOOLTIP] =
3107 g_signal_new (I_("query-tooltip"),
3108 G_TYPE_FROM_CLASS (klass),
3110 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
3111 _gtk_boolean_handled_accumulator, NULL,
3112 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
3120 * GtkWidget::popup-menu:
3121 * @widget: the object which received the signal
3123 * This signal gets emitted whenever a widget should pop up a context
3124 * menu. This usually happens through the standard key binding mechanism;
3125 * by pressing a certain key while a widget is focused, the user can cause
3126 * the widget to pop up a menu. For example, the #GtkEntry widget creates
3127 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
3128 * for an example of how to use this signal.
3130 * Returns: %TRUE if a menu was activated
3132 widget_signals[POPUP_MENU] =
3133 g_signal_new (I_("popup-menu"),
3134 G_TYPE_FROM_CLASS (klass),
3135 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3136 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
3137 _gtk_boolean_handled_accumulator, NULL,
3138 _gtk_marshal_BOOLEAN__VOID,
3142 * GtkWidget::show-help:
3143 * @widget: the object which received the signal.
3146 * Returns: %TRUE to stop other handlers from being invoked for the event.
3147 * %FALSE to propagate the event further.
3149 widget_signals[SHOW_HELP] =
3150 g_signal_new (I_("show-help"),
3151 G_TYPE_FROM_CLASS (klass),
3152 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
3153 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
3154 _gtk_boolean_handled_accumulator, NULL,
3155 _gtk_marshal_BOOLEAN__ENUM,
3157 GTK_TYPE_WIDGET_HELP_TYPE);
3160 * GtkWidget::accel-closures-changed:
3161 * @widget: the object which received the signal.
3163 widget_signals[ACCEL_CLOSURES_CHANGED] =
3164 g_signal_new (I_("accel-closures-changed"),
3165 G_TYPE_FROM_CLASS (klass),
3169 _gtk_marshal_VOID__VOID,
3173 * GtkWidget::screen-changed:
3174 * @widget: the object on which the signal is emitted
3175 * @previous_screen: (allow-none): the previous screen, or %NULL if the
3176 * widget was not associated with a screen before
3178 * The ::screen-changed signal gets emitted when the
3179 * screen of a widget has changed.
3181 widget_signals[SCREEN_CHANGED] =
3182 g_signal_new (I_("screen-changed"),
3183 G_TYPE_FROM_CLASS (klass),
3185 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
3187 _gtk_marshal_VOID__OBJECT,
3192 * GtkWidget::can-activate-accel:
3193 * @widget: the object which received the signal
3194 * @signal_id: the ID of a signal installed on @widget
3196 * Determines whether an accelerator that activates the signal
3197 * identified by @signal_id can currently be activated.
3198 * This signal is present to allow applications and derived
3199 * widgets to override the default #GtkWidget handling
3200 * for determining whether an accelerator can be activated.
3202 * Returns: %TRUE if the signal can be activated.
3204 widget_signals[CAN_ACTIVATE_ACCEL] =
3205 g_signal_new (I_("can-activate-accel"),
3206 G_TYPE_FROM_CLASS (klass),
3208 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
3209 _gtk_boolean_handled_accumulator, NULL,
3210 _gtk_marshal_BOOLEAN__UINT,
3211 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
3213 binding_set = gtk_binding_set_by_class (klass);
3214 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
3216 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
3219 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
3221 GTK_TYPE_WIDGET_HELP_TYPE,
3222 GTK_WIDGET_HELP_TOOLTIP);
3223 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
3225 GTK_TYPE_WIDGET_HELP_TYPE,
3226 GTK_WIDGET_HELP_TOOLTIP);
3227 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
3229 GTK_TYPE_WIDGET_HELP_TYPE,
3230 GTK_WIDGET_HELP_WHATS_THIS);
3231 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
3233 GTK_TYPE_WIDGET_HELP_TYPE,
3234 GTK_WIDGET_HELP_WHATS_THIS);
3236 gtk_widget_class_install_style_property (klass,
3237 g_param_spec_boolean ("interior-focus",
3238 P_("Interior Focus"),
3239 P_("Whether to draw the focus indicator inside widgets"),
3241 GTK_PARAM_READABLE));
3243 gtk_widget_class_install_style_property (klass,
3244 g_param_spec_int ("focus-line-width",
3245 P_("Focus linewidth"),
3246 P_("Width, in pixels, of the focus indicator line"),
3248 GTK_PARAM_READABLE));
3250 gtk_widget_class_install_style_property (klass,
3251 g_param_spec_string ("focus-line-pattern",
3252 P_("Focus line dash pattern"),
3253 P_("Dash pattern used to draw the focus indicator"),
3255 GTK_PARAM_READABLE));
3256 gtk_widget_class_install_style_property (klass,
3257 g_param_spec_int ("focus-padding",
3258 P_("Focus padding"),
3259 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3261 GTK_PARAM_READABLE));
3262 gtk_widget_class_install_style_property (klass,
3263 g_param_spec_boxed ("cursor-color",
3265 P_("Color with which to draw insertion cursor"),
3267 GTK_PARAM_READABLE));
3268 gtk_widget_class_install_style_property (klass,
3269 g_param_spec_boxed ("secondary-cursor-color",
3270 P_("Secondary cursor color"),
3271 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3273 GTK_PARAM_READABLE));
3274 gtk_widget_class_install_style_property (klass,
3275 g_param_spec_float ("cursor-aspect-ratio",
3276 P_("Cursor line aspect ratio"),
3277 P_("Aspect ratio with which to draw insertion cursor"),
3279 GTK_PARAM_READABLE));
3281 gtk_widget_class_install_style_property (klass,
3282 g_param_spec_boolean ("window-dragging",
3283 P_("Window dragging"),
3284 P_("Whether windows can be dragged by clicking on empty areas"),
3286 GTK_PARAM_READABLE));
3289 * GtkWidget:link-color:
3291 * The "link-color" style property defines the color of unvisited links.
3295 gtk_widget_class_install_style_property (klass,
3296 g_param_spec_boxed ("link-color",
3297 P_("Unvisited Link Color"),
3298 P_("Color of unvisited links"),
3300 GTK_PARAM_READABLE));
3303 * GtkWidget:visited-link-color:
3305 * The "visited-link-color" style property defines the color of visited links.
3309 gtk_widget_class_install_style_property (klass,
3310 g_param_spec_boxed ("visited-link-color",
3311 P_("Visited Link Color"),
3312 P_("Color of visited links"),
3314 GTK_PARAM_READABLE));
3317 * GtkWidget:wide-separators:
3319 * The "wide-separators" style property defines whether separators have
3320 * configurable width and should be drawn using a box instead of a line.
3324 gtk_widget_class_install_style_property (klass,
3325 g_param_spec_boolean ("wide-separators",
3326 P_("Wide Separators"),
3327 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3329 GTK_PARAM_READABLE));
3332 * GtkWidget:separator-width:
3334 * The "separator-width" style property defines the width of separators.
3335 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3339 gtk_widget_class_install_style_property (klass,
3340 g_param_spec_int ("separator-width",
3341 P_("Separator Width"),
3342 P_("The width of separators if wide-separators is TRUE"),
3344 GTK_PARAM_READABLE));
3347 * GtkWidget:separator-height:
3349 * The "separator-height" style property defines the height of separators.
3350 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3354 gtk_widget_class_install_style_property (klass,
3355 g_param_spec_int ("separator-height",
3356 P_("Separator Height"),
3357 P_("The height of separators if \"wide-separators\" is TRUE"),
3359 GTK_PARAM_READABLE));
3362 * GtkWidget:scroll-arrow-hlength:
3364 * The "scroll-arrow-hlength" style property defines the length of
3365 * horizontal scroll arrows.
3369 gtk_widget_class_install_style_property (klass,
3370 g_param_spec_int ("scroll-arrow-hlength",
3371 P_("Horizontal Scroll Arrow Length"),
3372 P_("The length of horizontal scroll arrows"),
3374 GTK_PARAM_READABLE));
3377 * GtkWidget:scroll-arrow-vlength:
3379 * The "scroll-arrow-vlength" style property defines the length of
3380 * vertical scroll arrows.
3384 gtk_widget_class_install_style_property (klass,
3385 g_param_spec_int ("scroll-arrow-vlength",
3386 P_("Vertical Scroll Arrow Length"),
3387 P_("The length of vertical scroll arrows"),
3389 GTK_PARAM_READABLE));
3391 gtk_widget_class_install_style_property (klass,
3392 g_param_spec_int ("text-handle-width",
3393 P_("Width of text selection handles"),
3394 P_("Width of text selection handles"),
3396 GTK_PARAM_READABLE));
3397 gtk_widget_class_install_style_property (klass,
3398 g_param_spec_int ("text-handle-height",
3399 P_("Height of text selection handles"),
3400 P_("Height of text selection handles"),
3402 GTK_PARAM_READABLE));
3404 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3406 gtk_widget_class_set_accessible_type (klass, GTK_TYPE_WIDGET_ACCESSIBLE);
3410 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3414 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3415 for (node = list; node; node = node->next)
3417 GParamSpec *pspec = node->data;
3419 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3420 g_param_spec_unref (pspec);
3426 gtk_widget_set_property (GObject *object,
3428 const GValue *value,
3431 GtkWidget *widget = GTK_WIDGET (object);
3436 gchar *tooltip_markup;
3437 const gchar *tooltip_text;
3438 GtkWindow *tooltip_window;
3441 gtk_widget_set_name (widget, g_value_get_string (value));
3444 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3446 case PROP_WIDTH_REQUEST:
3447 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3449 case PROP_HEIGHT_REQUEST:
3450 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3453 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3455 case PROP_SENSITIVE:
3456 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3458 case PROP_APP_PAINTABLE:
3459 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3461 case PROP_CAN_FOCUS:
3462 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3464 case PROP_HAS_FOCUS:
3465 if (g_value_get_boolean (value))
3466 gtk_widget_grab_focus (widget);
3469 if (g_value_get_boolean (value))
3470 gtk_widget_grab_focus (widget);
3472 case PROP_CAN_DEFAULT:
3473 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3475 case PROP_HAS_DEFAULT:
3476 if (g_value_get_boolean (value))
3477 gtk_widget_grab_default (widget);
3479 case PROP_RECEIVES_DEFAULT:
3480 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3483 gtk_widget_set_style (widget, g_value_get_object (value));
3486 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3487 gtk_widget_set_events (widget, g_value_get_flags (value));
3489 case PROP_NO_SHOW_ALL:
3490 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3492 case PROP_HAS_TOOLTIP:
3493 gtk_widget_real_set_has_tooltip (widget,
3494 g_value_get_boolean (value), FALSE);
3496 case PROP_TOOLTIP_MARKUP:
3497 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3498 tooltip_markup = g_value_dup_string (value);
3500 /* Treat an empty string as a NULL string,
3501 * because an empty string would be useless for a tooltip:
3503 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3505 g_free (tooltip_markup);
3506 tooltip_markup = NULL;
3509 g_object_set_qdata_full (object, quark_tooltip_markup,
3510 tooltip_markup, g_free);
3512 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3513 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3514 if (gtk_widget_get_visible (widget))
3515 gtk_widget_queue_tooltip_query (widget);
3517 case PROP_TOOLTIP_TEXT:
3518 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3520 tooltip_text = g_value_get_string (value);
3522 /* Treat an empty string as a NULL string,
3523 * because an empty string would be useless for a tooltip:
3525 if (tooltip_text && (strlen (tooltip_text) == 0))
3526 tooltip_text = NULL;
3528 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3530 g_object_set_qdata_full (object, quark_tooltip_markup,
3531 tooltip_markup, g_free);
3533 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3534 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3535 if (gtk_widget_get_visible (widget))
3536 gtk_widget_queue_tooltip_query (widget);
3538 case PROP_DOUBLE_BUFFERED:
3539 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3542 gtk_widget_set_halign (widget, g_value_get_enum (value));
3545 gtk_widget_set_valign (widget, g_value_get_enum (value));
3547 case PROP_MARGIN_LEFT:
3548 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3550 case PROP_MARGIN_RIGHT:
3551 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3553 case PROP_MARGIN_TOP:
3554 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3556 case PROP_MARGIN_BOTTOM:
3557 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3560 g_object_freeze_notify (G_OBJECT (widget));
3561 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3562 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3563 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3564 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3565 g_object_thaw_notify (G_OBJECT (widget));
3568 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3570 case PROP_HEXPAND_SET:
3571 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3574 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3576 case PROP_VEXPAND_SET:
3577 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3580 g_object_freeze_notify (G_OBJECT (widget));
3581 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3582 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3583 g_object_thaw_notify (G_OBJECT (widget));
3586 gtk_widget_set_opacity (widget, g_value_get_double (value));
3589 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3595 gtk_widget_get_property (GObject *object,
3600 GtkWidget *widget = GTK_WIDGET (object);
3601 GtkWidgetPrivate *priv = widget->priv;
3609 g_value_set_string (value, priv->name);
3611 g_value_set_static_string (value, "");
3614 g_value_set_object (value, priv->parent);
3616 case PROP_WIDTH_REQUEST:
3619 gtk_widget_get_size_request (widget, &w, NULL);
3620 g_value_set_int (value, w);
3623 case PROP_HEIGHT_REQUEST:
3626 gtk_widget_get_size_request (widget, NULL, &h);
3627 g_value_set_int (value, h);
3631 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3633 case PROP_SENSITIVE:
3634 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3636 case PROP_APP_PAINTABLE:
3637 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3639 case PROP_CAN_FOCUS:
3640 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3642 case PROP_HAS_FOCUS:
3643 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3646 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3648 case PROP_CAN_DEFAULT:
3649 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3651 case PROP_HAS_DEFAULT:
3652 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3654 case PROP_RECEIVES_DEFAULT:
3655 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3657 case PROP_COMPOSITE_CHILD:
3658 g_value_set_boolean (value, widget->priv->composite_child);
3661 g_value_set_object (value, gtk_widget_get_style (widget));
3664 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3665 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3667 case PROP_NO_SHOW_ALL:
3668 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3670 case PROP_HAS_TOOLTIP:
3671 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3673 case PROP_TOOLTIP_TEXT:
3675 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3678 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3679 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3681 g_value_take_string (value, text);
3684 case PROP_TOOLTIP_MARKUP:
3685 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3688 g_value_set_object (value, gtk_widget_get_window (widget));
3690 case PROP_DOUBLE_BUFFERED:
3691 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3694 g_value_set_enum (value, gtk_widget_get_halign (widget));
3697 g_value_set_enum (value, gtk_widget_get_valign (widget));
3699 case PROP_MARGIN_LEFT:
3700 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3702 case PROP_MARGIN_RIGHT:
3703 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3705 case PROP_MARGIN_TOP:
3706 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3708 case PROP_MARGIN_BOTTOM:
3709 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3713 GtkWidgetAuxInfo *aux_info = gtk_widget_get_aux_info (widget, FALSE);
3714 if (aux_info == NULL)
3716 g_value_set_int (value, 0);
3720 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3721 aux_info->margin.right),
3722 MAX (aux_info->margin.top,
3723 aux_info->margin.bottom)));
3728 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3730 case PROP_HEXPAND_SET:
3731 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3734 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3736 case PROP_VEXPAND_SET:
3737 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3740 g_value_set_boolean (value,
3741 gtk_widget_get_hexpand (widget) &&
3742 gtk_widget_get_vexpand (widget));
3745 g_value_set_double (value, gtk_widget_get_opacity (widget));
3748 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3754 gtk_widget_init (GtkWidget *widget)
3756 GtkWidgetPrivate *priv;
3758 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3761 priv = widget->priv;
3763 priv->child_visible = TRUE;
3765 priv->allocation.x = -1;
3766 priv->allocation.y = -1;
3767 priv->allocation.width = 1;
3768 priv->allocation.height = 1;
3769 priv->user_alpha = 255;
3771 priv->window = NULL;
3772 priv->parent = NULL;
3774 priv->sensitive = TRUE;
3775 priv->composite_child = composite_child_stack != 0;
3776 priv->double_buffered = TRUE;
3777 priv->redraw_on_alloc = TRUE;
3778 priv->alloc_needed = TRUE;
3780 switch (gtk_widget_get_direction (widget))
3782 case GTK_TEXT_DIR_LTR:
3783 priv->state_flags = GTK_STATE_FLAG_DIR_LTR;
3786 case GTK_TEXT_DIR_RTL:
3787 priv->state_flags = GTK_STATE_FLAG_DIR_RTL;
3790 case GTK_TEXT_DIR_NONE:
3792 g_assert_not_reached ();
3797 /* this will be set to TRUE if the widget gets a child or if the
3798 * expand flag is set on the widget, but until one of those happen
3799 * we know the expand is already properly FALSE.
3801 * We really want to default FALSE here to avoid computing expand
3802 * all over the place while initially building a widget tree.
3804 priv->need_compute_expand = FALSE;
3806 _gtk_size_request_cache_init (&priv->requests);
3808 priv->style = gtk_widget_get_default_style ();
3809 g_object_ref (priv->style);
3814 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3816 GParamSpec **pspecs)
3818 GtkWidgetPrivate *priv = widget->priv;
3819 GtkWidget *container = priv->parent;
3822 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3823 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3827 * gtk_widget_freeze_child_notify:
3828 * @widget: a #GtkWidget
3830 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3831 * signals are queued until gtk_widget_thaw_child_notify() is called
3834 * This is the analogue of g_object_freeze_notify() for child properties.
3837 gtk_widget_freeze_child_notify (GtkWidget *widget)
3839 g_return_if_fail (GTK_IS_WIDGET (widget));
3841 if (!G_OBJECT (widget)->ref_count)
3844 g_object_ref (widget);
3845 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3846 g_object_unref (widget);
3850 * gtk_widget_child_notify:
3851 * @widget: a #GtkWidget
3852 * @child_property: the name of a child property installed on the
3853 * class of @widget<!-- -->'s parent
3855 * Emits a #GtkWidget::child-notify signal for the
3856 * <link linkend="child-properties">child property</link> @child_property
3859 * This is the analogue of g_object_notify() for child properties.
3861 * Also see gtk_container_child_notify().
3864 gtk_widget_child_notify (GtkWidget *widget,
3865 const gchar *child_property)
3867 if (widget->priv->parent == NULL)
3870 gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
3874 * gtk_widget_thaw_child_notify:
3875 * @widget: a #GtkWidget
3877 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3878 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3882 gtk_widget_thaw_child_notify (GtkWidget *widget)
3884 GObjectNotifyQueue *nqueue;
3886 g_return_if_fail (GTK_IS_WIDGET (widget));
3888 if (!G_OBJECT (widget)->ref_count)
3891 g_object_ref (widget);
3892 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3893 if (!nqueue || !nqueue->freeze_count)
3894 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3895 G_OBJECT_TYPE_NAME (widget), widget);
3897 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3898 g_object_unref (widget);
3904 * @type: type ID of the widget to create
3905 * @first_property_name: name of first property to set
3906 * @...: value of first property, followed by more properties,
3909 * This is a convenience function for creating a widget and setting
3910 * its properties in one go. For example you might write:
3911 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3912 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3913 * g_object_new(), but returns a widget so you don't have to
3914 * cast the object yourself.
3916 * Return value: a new #GtkWidget of type @widget_type
3919 gtk_widget_new (GType type,
3920 const gchar *first_property_name,
3926 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3928 va_start (var_args, first_property_name);
3929 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3936 gtk_widget_queue_draw_child (GtkWidget *widget)
3938 GtkWidgetPrivate *priv = widget->priv;
3941 parent = priv->parent;
3942 if (parent && gtk_widget_is_drawable (parent))
3943 gtk_widget_queue_draw_area (parent,
3946 priv->allocation.width,
3947 priv->allocation.height);
3951 * gtk_widget_unparent:
3952 * @widget: a #GtkWidget
3954 * This function is only for use in widget implementations.
3955 * Should be called by implementations of the remove method
3956 * on #GtkContainer, to dissociate a child from the container.
3959 gtk_widget_unparent (GtkWidget *widget)
3961 GtkWidgetPrivate *priv;
3962 GObjectNotifyQueue *nqueue;
3963 GtkWidget *toplevel;
3964 GtkWidget *old_parent;
3966 g_return_if_fail (GTK_IS_WIDGET (widget));
3968 priv = widget->priv;
3970 if (priv->parent == NULL)
3973 /* keep this function in sync with gtk_menu_detach() */
3975 gtk_widget_push_verify_invariants (widget);
3977 g_object_freeze_notify (G_OBJECT (widget));
3978 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3980 toplevel = gtk_widget_get_toplevel (widget);
3981 if (gtk_widget_is_toplevel (toplevel))
3982 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3984 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3985 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3987 gtk_widget_queue_draw_child (widget);
3989 /* Reset the width and height here, to force reallocation if we
3990 * get added back to a new parent. This won't work if our new
3991 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3992 * (would 0x0 be OK here?)
3994 priv->allocation.width = 1;
3995 priv->allocation.height = 1;
3997 if (gtk_widget_get_realized (widget))
3999 if (priv->in_reparent)
4000 gtk_widget_unmap (widget);
4002 gtk_widget_unrealize (widget);
4005 /* If we are unanchoring the child, we save around the toplevel
4006 * to emit hierarchy changed
4008 if (priv->parent->priv->anchored)
4009 g_object_ref (toplevel);
4013 /* Removing a widget from a container restores the child visible
4014 * flag to the default state, so it doesn't affect the child
4015 * in the next parent.
4017 priv->child_visible = TRUE;
4019 old_parent = priv->parent;
4020 priv->parent = NULL;
4022 /* parent may no longer expand if the removed
4023 * child was expand=TRUE and could therefore
4026 if (gtk_widget_get_visible (widget) &&
4027 (priv->need_compute_expand ||
4028 priv->computed_hexpand ||
4029 priv->computed_vexpand))
4031 gtk_widget_queue_compute_expand (old_parent);
4034 /* Unset BACKDROP since we are no longer inside a toplevel window */
4035 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_BACKDROP);
4037 gtk_style_context_set_parent (priv->context, NULL);
4039 _gtk_widget_update_parent_muxer (widget);
4041 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
4044 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
4045 g_object_unref (toplevel);
4048 /* Now that the parent pointer is nullified and the hierarchy-changed
4049 * already passed, go ahead and unset the parent window, if we are unparenting
4050 * an embeded GtkWindow the window will become toplevel again and hierarchy-changed
4051 * will fire again for the new subhierarchy.
4053 gtk_widget_set_parent_window (widget, NULL);
4055 g_object_notify (G_OBJECT (widget), "parent");
4056 g_object_thaw_notify (G_OBJECT (widget));
4058 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
4059 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
4061 gtk_widget_propagate_alpha (widget);
4063 gtk_widget_pop_verify_invariants (widget);
4064 g_object_unref (widget);
4068 * gtk_widget_destroy:
4069 * @widget: a #GtkWidget
4071 * Destroys a widget.
4074 * destroyed, it will break any references it holds to other objects.
4075 * If the widget is inside a container, the widget will be removed
4076 * from the container. If the widget is a toplevel (derived from
4077 * #GtkWindow), it will be removed from the list of toplevels, and the
4078 * reference GTK+ holds to it will be removed. Removing a
4079 * widget from its container or the list of toplevels results in the
4080 * widget being finalized, unless you've added additional references
4081 * to the widget with g_object_ref().
4083 * In most cases, only toplevel widgets (windows) require explicit
4084 * destruction, because when you destroy a toplevel its children will
4085 * be destroyed as well.
4088 gtk_widget_destroy (GtkWidget *widget)
4090 g_return_if_fail (GTK_IS_WIDGET (widget));
4092 if (!widget->priv->in_destruction)
4093 g_object_run_dispose (G_OBJECT (widget));
4097 * gtk_widget_destroyed:
4098 * @widget: a #GtkWidget
4099 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
4101 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
4102 * %NULL. It's intended to be used as a callback connected to the
4103 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
4104 * as a signal handler, and pass the address of your widget variable
4105 * as user data. Then when the widget is destroyed, the variable will
4106 * be set to %NULL. Useful for example to avoid multiple copies
4107 * of the same dialog.
4110 gtk_widget_destroyed (GtkWidget *widget,
4111 GtkWidget **widget_pointer)
4113 /* Don't make any assumptions about the
4115 * Even check widget_pointer.
4118 *widget_pointer = NULL;
4123 * @widget: a #GtkWidget
4125 * Flags a widget to be displayed. Any widget that isn't shown will
4126 * not appear on the screen. If you want to show all the widgets in a
4127 * container, it's easier to call gtk_widget_show_all() on the
4128 * container, instead of individually showing the widgets.
4130 * Remember that you have to show the containers containing a widget,
4131 * in addition to the widget itself, before it will appear onscreen.
4133 * When a toplevel container is shown, it is immediately realized and
4134 * mapped; other shown widgets are realized and mapped when their
4135 * toplevel container is realized and mapped.
4138 gtk_widget_show (GtkWidget *widget)
4140 g_return_if_fail (GTK_IS_WIDGET (widget));
4142 if (!gtk_widget_get_visible (widget))
4144 g_object_ref (widget);
4145 gtk_widget_push_verify_invariants (widget);
4147 if (!gtk_widget_is_toplevel (widget))
4148 gtk_widget_queue_resize (widget);
4150 /* see comment in set_parent() for why this should and can be
4153 if (widget->priv->need_compute_expand ||
4154 widget->priv->computed_hexpand ||
4155 widget->priv->computed_vexpand)
4157 if (widget->priv->parent != NULL)
4158 gtk_widget_queue_compute_expand (widget->priv->parent);
4161 g_signal_emit (widget, widget_signals[SHOW], 0);
4162 g_object_notify (G_OBJECT (widget), "visible");
4164 gtk_widget_pop_verify_invariants (widget);
4165 g_object_unref (widget);
4170 gtk_widget_real_show (GtkWidget *widget)
4172 GtkWidgetPrivate *priv = widget->priv;
4174 if (!gtk_widget_get_visible (widget))
4176 priv->visible = TRUE;
4179 gtk_widget_get_mapped (priv->parent) &&
4180 gtk_widget_get_child_visible (widget) &&
4181 !gtk_widget_get_mapped (widget))
4182 gtk_widget_map (widget);
4187 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
4190 g_signal_handlers_disconnect_by_func (widget,
4191 gtk_widget_show_map_callback,
4196 * gtk_widget_show_now:
4197 * @widget: a #GtkWidget
4199 * Shows a widget. If the widget is an unmapped toplevel widget
4200 * (i.e. a #GtkWindow that has not yet been shown), enter the main
4201 * loop and wait for the window to actually be mapped. Be careful;
4202 * because the main loop is running, anything can happen during
4206 gtk_widget_show_now (GtkWidget *widget)
4210 g_return_if_fail (GTK_IS_WIDGET (widget));
4212 /* make sure we will get event */
4213 if (!gtk_widget_get_mapped (widget) &&
4214 gtk_widget_is_toplevel (widget))
4216 gtk_widget_show (widget);
4218 g_signal_connect (widget, "map-event",
4219 G_CALLBACK (gtk_widget_show_map_callback),
4223 gtk_main_iteration ();
4226 gtk_widget_show (widget);
4231 * @widget: a #GtkWidget
4233 * Reverses the effects of gtk_widget_show(), causing the widget to be
4234 * hidden (invisible to the user).
4237 gtk_widget_hide (GtkWidget *widget)
4239 g_return_if_fail (GTK_IS_WIDGET (widget));
4241 if (gtk_widget_get_visible (widget))
4243 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
4245 g_object_ref (widget);
4246 gtk_widget_push_verify_invariants (widget);
4248 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
4249 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
4251 /* a parent may now be expand=FALSE since we're hidden. */
4252 if (widget->priv->need_compute_expand ||
4253 widget->priv->computed_hexpand ||
4254 widget->priv->computed_vexpand)
4256 gtk_widget_queue_compute_expand (widget);
4259 g_signal_emit (widget, widget_signals[HIDE], 0);
4260 if (!gtk_widget_is_toplevel (widget))
4261 gtk_widget_queue_resize (widget);
4262 g_object_notify (G_OBJECT (widget), "visible");
4264 gtk_widget_pop_verify_invariants (widget);
4265 g_object_unref (widget);
4270 gtk_widget_real_hide (GtkWidget *widget)
4272 if (gtk_widget_get_visible (widget))
4274 widget->priv->visible = FALSE;
4276 if (gtk_widget_get_mapped (widget))
4277 gtk_widget_unmap (widget);
4282 * gtk_widget_hide_on_delete:
4283 * @widget: a #GtkWidget
4285 * Utility function; intended to be connected to the #GtkWidget::delete-event
4286 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
4287 * argument, then returns %TRUE. If connected to ::delete-event, the
4288 * result is that clicking the close button for a window (on the
4289 * window frame, top right corner usually) will hide but not destroy
4290 * the window. By default, GTK+ destroys windows when ::delete-event
4293 * Return value: %TRUE
4296 gtk_widget_hide_on_delete (GtkWidget *widget)
4298 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4300 gtk_widget_hide (widget);
4306 * gtk_widget_show_all:
4307 * @widget: a #GtkWidget
4309 * Recursively shows a widget, and any child widgets (if the widget is
4313 gtk_widget_show_all (GtkWidget *widget)
4315 GtkWidgetClass *class;
4317 g_return_if_fail (GTK_IS_WIDGET (widget));
4319 if (gtk_widget_get_no_show_all (widget))
4322 class = GTK_WIDGET_GET_CLASS (widget);
4324 if (class->show_all)
4325 class->show_all (widget);
4330 * @widget: a #GtkWidget
4332 * This function is only for use in widget implementations. Causes
4333 * a widget to be mapped if it isn't already.
4336 gtk_widget_map (GtkWidget *widget)
4338 GtkWidgetPrivate *priv;
4340 g_return_if_fail (GTK_IS_WIDGET (widget));
4341 g_return_if_fail (gtk_widget_get_visible (widget));
4342 g_return_if_fail (gtk_widget_get_child_visible (widget));
4344 priv = widget->priv;
4346 if (!gtk_widget_get_mapped (widget))
4348 gtk_widget_push_verify_invariants (widget);
4350 if (!gtk_widget_get_realized (widget))
4351 gtk_widget_realize (widget);
4353 g_signal_emit (widget, widget_signals[MAP], 0);
4355 if (!gtk_widget_get_has_window (widget))
4356 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4358 if (widget->priv->context)
4359 _gtk_style_context_update_animating (widget->priv->context);
4361 gtk_widget_pop_verify_invariants (widget);
4367 * @widget: a #GtkWidget
4369 * This function is only for use in widget implementations. Causes
4370 * a widget to be unmapped if it's currently mapped.
4373 gtk_widget_unmap (GtkWidget *widget)
4375 GtkWidgetPrivate *priv;
4377 g_return_if_fail (GTK_IS_WIDGET (widget));
4379 priv = widget->priv;
4381 if (gtk_widget_get_mapped (widget))
4383 gtk_widget_push_verify_invariants (widget);
4385 if (!gtk_widget_get_has_window (widget))
4386 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4387 _gtk_tooltip_hide (widget);
4389 if (widget->priv->context)
4390 _gtk_style_context_update_animating (widget->priv->context);
4392 g_signal_emit (widget, widget_signals[UNMAP], 0);
4394 gtk_widget_pop_verify_invariants (widget);
4396 /* Unset pointer/window info */
4397 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
4402 _gtk_widget_enable_device_events (GtkWidget *widget)
4404 GHashTable *device_events;
4405 GHashTableIter iter;
4406 gpointer key, value;
4408 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4413 g_hash_table_iter_init (&iter, device_events);
4415 while (g_hash_table_iter_next (&iter, &key, &value))
4418 GdkEventMask event_mask;
4421 event_mask = GPOINTER_TO_UINT (value);
4422 gtk_widget_add_events_internal (widget, device, event_mask);
4427 get_widget_windows (GtkWidget *widget)
4429 GList *window_list, *last, *l, *children, *ret;
4431 if (gtk_widget_get_has_window (widget))
4432 window_list = g_list_prepend (NULL, gtk_widget_get_window (widget));
4434 window_list = gdk_window_peek_children (gtk_widget_get_window (widget));
4436 last = g_list_last (window_list);
4439 for (l = window_list; l; l = l->next)
4441 GtkWidget *window_widget = NULL;
4443 gdk_window_get_user_data (l->data, (gpointer *) &window_widget);
4445 if (widget != window_widget)
4448 ret = g_list_prepend (ret, l->data);
4449 children = gdk_window_peek_children (GDK_WINDOW (l->data));
4453 last = g_list_concat (last, children);
4454 last = g_list_last (last);
4458 g_list_free (window_list);
4464 device_enable_foreach (GtkWidget *widget,
4467 GdkDevice *device = user_data;
4468 gtk_widget_set_device_enabled_internal (widget, device, TRUE, TRUE);
4472 device_disable_foreach (GtkWidget *widget,
4475 GdkDevice *device = user_data;
4476 gtk_widget_set_device_enabled_internal (widget, device, TRUE, FALSE);
4480 gtk_widget_set_device_enabled_internal (GtkWidget *widget,
4485 GList *window_list, *l;
4487 window_list = get_widget_windows (widget);
4489 for (l = window_list; l; l = l->next)
4491 GdkEventMask events = 0;
4497 events = gdk_window_get_events (window);
4499 gdk_window_set_device_events (window, device, events);
4502 if (recurse && GTK_IS_CONTAINER (widget))
4505 gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, device);
4507 gtk_container_forall (GTK_CONTAINER (widget), device_disable_foreach, device);
4510 g_list_free (window_list);
4514 gtk_widget_update_devices_mask (GtkWidget *widget,
4517 GList *enabled_devices, *l;
4519 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
4521 for (l = enabled_devices; l; l = l->next)
4522 gtk_widget_set_device_enabled_internal (widget, GDK_DEVICE (l->data), recurse, TRUE);
4525 typedef struct _GtkTickCallbackInfo GtkTickCallbackInfo;
4527 struct _GtkTickCallbackInfo
4532 GtkTickCallback callback;
4534 GDestroyNotify notify;
4536 guint destroyed : 1;
4540 ref_tick_callback_info (GtkTickCallbackInfo *info)
4546 unref_tick_callback_info (GtkWidget *widget,
4547 GtkTickCallbackInfo *info,
4550 GtkWidgetPrivate *priv = widget->priv;
4553 if (info->refcount == 0)
4555 priv->tick_callbacks = g_list_delete_link (priv->tick_callbacks, link);
4557 info->notify (info->user_data);
4558 g_slice_free (GtkTickCallbackInfo, info);
4561 if (priv->tick_callbacks == NULL && priv->realized)
4563 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4564 g_signal_handlers_disconnect_by_func (frame_clock,
4565 (gpointer) gtk_widget_on_frame_clock_update,
4567 gdk_frame_clock_end_updating (frame_clock);
4572 destroy_tick_callback_info (GtkWidget *widget,
4573 GtkTickCallbackInfo *info,
4576 if (!info->destroyed)
4578 info->destroyed = TRUE;
4579 unref_tick_callback_info (widget, info, link);
4584 gtk_widget_on_frame_clock_update (GdkFrameClock *frame_clock,
4587 GtkWidgetPrivate *priv = widget->priv;
4590 g_object_ref (widget);
4592 for (l = priv->tick_callbacks; l;)
4594 GtkTickCallbackInfo *info = l->data;
4597 ref_tick_callback_info (info);
4598 if (!info->destroyed)
4600 if (info->callback (widget,
4602 info->user_data) == G_SOURCE_REMOVE)
4604 destroy_tick_callback_info (widget, info, l);
4609 unref_tick_callback_info (widget, info, l);
4613 g_object_unref (widget);
4616 static guint tick_callback_id;
4619 * gtk_widget_add_tick_callback:
4620 * @widget: a #GtkWidget
4621 * @callback: function to call for updating animations
4622 * @user_data: data to pass to @callback
4623 * @notify: function to call to free @user_data when the callback is removed.
4625 * Queues a animation frame update and adds a callback to be called
4626 * before each frame. Until the tick callback is removed, it will be
4627 * called frequently (usually at the frame rate of the output device
4628 * or as quickly as the application an be repainted, whichever is
4629 * slower). For this reason, is most suitable for handling graphics
4630 * that change every frame or every few frames. The tick callback does
4631 * not automatically imply a relayout or repaint. If you want a
4632 * repaint or relayout, and aren't changing widget properties that
4633 * would trigger that (for example, changing the text of a #GtkLabel),
4634 * then you will have to call gtk_widget_queue_resize() or
4635 * gtk_widget_queue_draw_area() yourself.
4637 * gdk_frame_clock_get_frame_time() should generally be used for timing
4638 * continuous animations and
4639 * gdk_frame_timings_get_predicted_presentation_time() if you are
4640 * trying to display isolated frames at particular times.
4642 * This is a more convenient alternative to connecting directly to the
4643 * #GdkFrameClock::update signal of #GdkFrameClock, since you don't
4644 * have to worry about when a #GdkFrameClock is assigned to a widget.
4646 * Returns: an id for the connection of this callback. Remove the callback
4647 * by passing it to gtk_widget_remove_tick_callback()
4652 gtk_widget_add_tick_callback (GtkWidget *widget,
4653 GtkTickCallback callback,
4655 GDestroyNotify notify)
4657 GtkWidgetPrivate *priv;
4658 GtkTickCallbackInfo *info;
4660 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
4662 priv = widget->priv;
4664 if (priv->tick_callbacks == NULL && priv->realized)
4666 GdkFrameClock *frame_clock = gtk_widget_get_frame_clock (widget);
4667 g_signal_connect (frame_clock, "update",
4668 G_CALLBACK (gtk_widget_on_frame_clock_update),
4670 gdk_frame_clock_begin_updating (frame_clock);
4673 info = g_slice_new0 (GtkTickCallbackInfo);
4676 info->id = ++tick_callback_id;
4677 info->callback = callback;
4678 info->user_data = user_data;
4679 info->notify = notify;
4681 priv->tick_callbacks = g_list_prepend (priv->tick_callbacks,
4688 * gtk_widget_remove_tick_callback:
4689 * @widget: a #GtkWidget
4690 * @id: an id returned by gtk_widget_add_tick_callback()
4692 * Removes a tick callback previously registered with
4693 * gtk_widget_add_tick_callback().
4698 gtk_widget_remove_tick_callback (GtkWidget *widget,
4701 GtkWidgetPrivate *priv;
4704 g_return_if_fail (GTK_IS_WIDGET (widget));
4706 priv = widget->priv;
4708 for (l = priv->tick_callbacks; l; l = l->next)
4710 GtkTickCallbackInfo *info = l->data;
4712 destroy_tick_callback_info (widget, info, l);
4717 gtk_widget_connect_frame_clock (GtkWidget *widget,
4718 GdkFrameClock *frame_clock)
4720 GtkWidgetPrivate *priv = widget->priv;
4722 if (GTK_IS_CONTAINER (widget))
4723 _gtk_container_maybe_start_idle_sizer (GTK_CONTAINER (widget));
4725 if (priv->tick_callbacks != NULL)
4727 g_signal_connect (frame_clock, "update",
4728 G_CALLBACK (gtk_widget_on_frame_clock_update),
4730 gdk_frame_clock_begin_updating (frame_clock);
4734 gtk_style_context_set_frame_clock (priv->context, frame_clock);
4738 gtk_widget_disconnect_frame_clock (GtkWidget *widget,
4739 GdkFrameClock *frame_clock)
4741 GtkWidgetPrivate *priv = widget->priv;
4743 if (GTK_IS_CONTAINER (widget))
4744 _gtk_container_stop_idle_sizer (GTK_CONTAINER (widget));
4746 if (priv->tick_callbacks)
4748 g_signal_handlers_disconnect_by_func (frame_clock,
4749 (gpointer) gtk_widget_on_frame_clock_update,
4751 gdk_frame_clock_end_updating (frame_clock);
4755 gtk_style_context_set_frame_clock (priv->context, NULL);
4759 * gtk_widget_realize:
4760 * @widget: a #GtkWidget
4762 * Creates the GDK (windowing system) resources associated with a
4763 * widget. For example, @widget->window will be created when a widget
4764 * is realized. Normally realization happens implicitly; if you show
4765 * a widget and all its parent containers, then the widget will be
4766 * realized and mapped automatically.
4768 * Realizing a widget requires all
4769 * the widget's parent widgets to be realized; calling
4770 * gtk_widget_realize() realizes the widget's parents in addition to
4771 * @widget itself. If a widget is not yet inside a toplevel window
4772 * when you realize it, bad things will happen.
4774 * This function is primarily used in widget implementations, and
4775 * isn't very useful otherwise. Many times when you think you might
4776 * need it, a better approach is to connect to a signal that will be
4777 * called after the widget is realized automatically, such as
4778 * #GtkWidget::draw. Or simply g_signal_connect () to the
4779 * #GtkWidget::realize signal.
4782 gtk_widget_realize (GtkWidget *widget)
4784 GtkWidgetPrivate *priv;
4785 cairo_region_t *region;
4787 g_return_if_fail (GTK_IS_WIDGET (widget));
4788 g_return_if_fail (widget->priv->anchored ||
4789 GTK_IS_INVISIBLE (widget));
4791 priv = widget->priv;
4793 if (!gtk_widget_get_realized (widget))
4795 gtk_widget_push_verify_invariants (widget);
4798 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4799 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4802 if (priv->parent == NULL &&
4803 !gtk_widget_is_toplevel (widget))
4804 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4805 "inside a toplevel window is not going to work very well. "
4806 "Widgets must be inside a toplevel container before realizing them.");
4808 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4809 gtk_widget_realize (priv->parent);
4811 gtk_widget_ensure_style (widget);
4813 if (priv->style_update_pending)
4814 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
4816 g_signal_emit (widget, widget_signals[REALIZE], 0);
4818 gtk_widget_real_set_has_tooltip (widget,
4819 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4822 if (priv->has_shape_mask)
4824 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4825 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4828 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4830 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4832 if (priv->multidevice)
4833 gdk_window_set_support_multidevice (priv->window, TRUE);
4835 _gtk_widget_enable_device_events (widget);
4836 gtk_widget_update_devices_mask (widget, TRUE);
4838 gtk_widget_connect_frame_clock (widget,
4839 gtk_widget_get_frame_clock (widget));
4841 gtk_widget_pop_verify_invariants (widget);
4846 * gtk_widget_unrealize:
4847 * @widget: a #GtkWidget
4849 * This function is only useful in widget implementations.
4850 * Causes a widget to be unrealized (frees all GDK resources
4851 * associated with the widget, such as @widget->window).
4854 gtk_widget_unrealize (GtkWidget *widget)
4856 g_return_if_fail (GTK_IS_WIDGET (widget));
4858 gtk_widget_push_verify_invariants (widget);
4860 if (widget->priv->has_shape_mask)
4861 gtk_widget_shape_combine_region (widget, NULL);
4863 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4864 gtk_widget_input_shape_combine_region (widget, NULL);
4866 if (gtk_widget_get_realized (widget))
4868 g_object_ref (widget);
4870 if (widget->priv->mapped)
4871 gtk_widget_unmap (widget);
4873 gtk_widget_disconnect_frame_clock (widget,
4874 gtk_widget_get_frame_clock (widget));
4876 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4877 g_assert (!widget->priv->mapped);
4878 gtk_widget_set_realized (widget, FALSE);
4880 g_object_unref (widget);
4883 gtk_widget_pop_verify_invariants (widget);
4886 /*****************************************
4888 *****************************************/
4891 * gtk_widget_queue_draw_region:
4892 * @widget: a #GtkWidget
4893 * @region: region to draw
4895 * Invalidates the rectangular area of @widget defined by @region by
4896 * calling gdk_window_invalidate_region() on the widget's window and
4897 * all its child windows. Once the main loop becomes idle (after the
4898 * current batch of events has been processed, roughly), the window
4899 * will receive expose events for the union of all regions that have
4902 * Normally you would only use this function in widget
4903 * implementations. You might also use it to schedule a redraw of a
4904 * #GtkDrawingArea or some portion thereof.
4909 gtk_widget_queue_draw_region (GtkWidget *widget,
4910 const cairo_region_t *region)
4912 GtkWidgetPrivate *priv;
4915 g_return_if_fail (GTK_IS_WIDGET (widget));
4917 priv = widget->priv;
4919 if (!gtk_widget_get_realized (widget))
4922 /* Just return if the widget or one of its ancestors isn't mapped */
4923 for (w = widget; w != NULL; w = w->priv->parent)
4924 if (!gtk_widget_get_mapped (w))
4927 gdk_window_invalidate_region (priv->window, region, TRUE);
4931 * gtk_widget_queue_draw_area:
4932 * @widget: a #GtkWidget
4933 * @x: x coordinate of upper-left corner of rectangle to redraw
4934 * @y: y coordinate of upper-left corner of rectangle to redraw
4935 * @width: width of region to draw
4936 * @height: height of region to draw
4938 * Convenience function that calls gtk_widget_queue_draw_region() on
4939 * the region created from the given coordinates.
4941 * The region here is specified in widget coordinates.
4942 * Widget coordinates are a bit odd; for historical reasons, they are
4943 * defined as @widget->window coordinates for widgets that are not
4944 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
4945 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
4948 gtk_widget_queue_draw_area (GtkWidget *widget,
4955 cairo_region_t *region;
4957 g_return_if_fail (GTK_IS_WIDGET (widget));
4962 rect.height = height;
4964 region = cairo_region_create_rectangle (&rect);
4965 gtk_widget_queue_draw_region (widget, region);
4966 cairo_region_destroy (region);
4970 * gtk_widget_queue_draw:
4971 * @widget: a #GtkWidget
4973 * Equivalent to calling gtk_widget_queue_draw_area() for the
4974 * entire area of a widget.
4977 gtk_widget_queue_draw (GtkWidget *widget)
4981 g_return_if_fail (GTK_IS_WIDGET (widget));
4983 gtk_widget_get_allocation (widget, &rect);
4985 if (!gtk_widget_get_has_window (widget))
4986 gtk_widget_queue_draw_area (widget,
4987 rect.x, rect.y, rect.width, rect.height);
4989 gtk_widget_queue_draw_area (widget,
4990 0, 0, rect.width, rect.height);
4994 * gtk_widget_queue_resize:
4995 * @widget: a #GtkWidget
4997 * This function is only for use in widget implementations.
4998 * Flags a widget to have its size renegotiated; should
4999 * be called when a widget for some reason has a new size request.
5000 * For example, when you change the text in a #GtkLabel, #GtkLabel
5001 * queues a resize to ensure there's enough space for the new text.
5003 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
5004 * from inside its implementation of the GtkWidgetClass::size_allocate
5005 * virtual method. Calls to gtk_widget_queue_resize() from inside
5006 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
5009 gtk_widget_queue_resize (GtkWidget *widget)
5011 g_return_if_fail (GTK_IS_WIDGET (widget));
5013 if (gtk_widget_get_realized (widget))
5014 gtk_widget_queue_draw (widget);
5016 _gtk_size_group_queue_resize (widget, 0);
5020 * gtk_widget_queue_resize_no_redraw:
5021 * @widget: a #GtkWidget
5023 * This function works like gtk_widget_queue_resize(),
5024 * except that the widget is not invalidated.
5029 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
5031 g_return_if_fail (GTK_IS_WIDGET (widget));
5033 _gtk_size_group_queue_resize (widget, 0);
5037 * gtk_widget_get_frame_clock:
5038 * @widget: a #GtkWidget
5040 * Obtains the frame clock for a widget. The frame clock is a global
5041 * "ticker" that can be used to drive animations and repaints. The
5042 * most common reason to get the frame clock is to call
5043 * gdk_frame_clock_get_frame_time(), in order to get a time to use for
5044 * animating. For example you might record the start of the animation
5045 * with an initial value from gdk_frame_clock_get_frame_time(), and
5046 * then update the animation by calling
5047 * gdk_frame_clock_get_frame_time() again during each repaint.
5049 * gdk_frame_clock_request_phase() will result in a new frame on the
5050 * clock, but won't necessarily repaint any widgets. To repaint a
5051 * widget, you have to use gtk_widget_queue_draw() which invalidates
5052 * the widget (thus scheduling it to receive a draw on the next
5053 * frame). gtk_widget_queue_draw() will also end up requesting a frame
5054 * on the appropriate frame clock.
5056 * A widget's frame clock will not change while the widget is
5057 * mapped. Reparenting a widget (which implies a temporary unmap) can
5058 * change the widget's frame clock.
5060 * Unrealized widgets do not have a frame clock.
5062 * Return value: (transfer none): a #GdkFrameClock (or #NULL if widget is unrealized)
5067 gtk_widget_get_frame_clock (GtkWidget *widget)
5069 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
5071 if (widget->priv->realized)
5073 /* We use gtk_widget_get_toplevel() here to make it explicit that
5074 * the frame clock is a property of the toplevel that a widget
5075 * is anchored to; gdk_window_get_toplevel() will go up the
5076 * hierarchy anyways, but should squash any funny business with
5077 * reparenting windows and widgets.
5079 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5080 GdkWindow *window = gtk_widget_get_window (toplevel);
5081 g_assert (window != NULL);
5083 return gdk_window_get_frame_clock (window);
5092 * gtk_widget_size_request:
5093 * @widget: a #GtkWidget
5094 * @requisition: (out): a #GtkRequisition to be filled in
5096 * This function is typically used when implementing a #GtkContainer
5097 * subclass. Obtains the preferred size of a widget. The container
5098 * uses this information to arrange its child widgets and decide what
5099 * size allocations to give them with gtk_widget_size_allocate().
5101 * You can also call this function from an application, with some
5102 * caveats. Most notably, getting a size request requires the widget
5103 * to be associated with a screen, because font information may be
5104 * needed. Multihead-aware applications should keep this in mind.
5106 * Also remember that the size request is not necessarily the size
5107 * a widget will actually be allocated.
5109 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5112 gtk_widget_size_request (GtkWidget *widget,
5113 GtkRequisition *requisition)
5115 g_return_if_fail (GTK_IS_WIDGET (widget));
5117 gtk_widget_get_preferred_size (widget, requisition, NULL);
5121 * gtk_widget_get_child_requisition:
5122 * @widget: a #GtkWidget
5123 * @requisition: (out): a #GtkRequisition to be filled in
5125 * This function is only for use in widget implementations. Obtains
5126 * @widget->requisition, unless someone has forced a particular
5127 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
5128 * in which case it returns that geometry instead of the widget's
5131 * This function differs from gtk_widget_size_request() in that
5132 * it retrieves the last size request value from @widget->requisition,
5133 * while gtk_widget_size_request() actually calls the "size_request" method
5134 * on @widget to compute the size request and fill in @widget->requisition,
5135 * and only then returns @widget->requisition.
5137 * Because this function does not call the "size_request" method, it
5138 * can only be used when you know that @widget->requisition is
5139 * up-to-date, that is, gtk_widget_size_request() has been called
5140 * since the last time a resize was queued. In general, only container
5141 * implementations have this information; applications should use
5142 * gtk_widget_size_request().
5145 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
5148 gtk_widget_get_child_requisition (GtkWidget *widget,
5149 GtkRequisition *requisition)
5151 gtk_widget_get_preferred_size (widget, requisition, NULL);
5155 invalidate_predicate (GdkWindow *window,
5160 gdk_window_get_user_data (window, &user_data);
5162 return (user_data == data);
5165 /* Invalidate @region in widget->window and all children
5166 * of widget->window owned by widget. @region is in the
5167 * same coordinates as widget->allocation and will be
5168 * modified by this call.
5171 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
5172 cairo_region_t *region)
5174 GtkWidgetPrivate *priv = widget->priv;
5176 if (!gtk_widget_get_realized (widget))
5179 if (gtk_widget_get_has_window (widget) && priv->parent)
5183 gdk_window_get_position (priv->window, &x, &y);
5184 cairo_region_translate (region, -x, -y);
5187 gdk_window_invalidate_maybe_recurse (priv->window, region,
5188 invalidate_predicate, widget);
5192 * gtk_widget_size_allocate:
5193 * @widget: a #GtkWidget
5194 * @allocation: position and size to be allocated to @widget
5196 * This function is only used by #GtkContainer subclasses, to assign a size
5197 * and position to their child widgets.
5199 * In this function, the allocation may be adjusted. It will be forced
5200 * to a 1x1 minimum size, and the adjust_size_allocation virtual
5201 * method on the child will be used to adjust the allocation. Standard
5202 * adjustments include removing the widget's margins, and applying the
5203 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
5206 gtk_widget_size_allocate (GtkWidget *widget,
5207 GtkAllocation *allocation)
5209 GtkWidgetPrivate *priv;
5210 GdkRectangle real_allocation;
5211 GdkRectangle old_allocation;
5212 GdkRectangle adjusted_allocation;
5213 gboolean alloc_needed;
5214 gboolean size_changed;
5215 gboolean position_changed;
5216 gint natural_width, natural_height, dummy;
5217 gint min_width, min_height;
5219 priv = widget->priv;
5221 g_return_if_fail (GTK_IS_WIDGET (widget));
5223 if (!priv->visible && !gtk_widget_is_toplevel (widget))
5226 gtk_widget_push_verify_invariants (widget);
5228 #ifdef G_ENABLE_DEBUG
5229 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5240 parent = gtk_widget_get_parent (parent);
5243 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
5244 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
5245 2 * depth, " ", name,
5246 allocation->width, allocation->height);
5248 #endif /* G_ENABLE_DEBUG */
5250 alloc_needed = priv->alloc_needed;
5251 /* Preserve request/allocate ordering */
5252 priv->alloc_needed = FALSE;
5254 old_allocation = priv->allocation;
5255 real_allocation = *allocation;
5257 adjusted_allocation = real_allocation;
5258 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
5260 /* Go ahead and request the height for allocated width, note that the internals
5261 * of get_height_for_width will internally limit the for_size to natural size
5262 * when aligning implicitly.
5264 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
5265 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &min_height, &natural_height);
5269 /* Go ahead and request the width for allocated height, note that the internals
5270 * of get_width_for_height will internally limit the for_size to natural size
5271 * when aligning implicitly.
5273 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
5274 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &min_width, &natural_width);
5277 #ifdef G_ENABLE_DEBUG
5278 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
5280 if ((min_width > real_allocation.width || min_height > real_allocation.height) &&
5281 !GTK_IS_SCROLLABLE (widget))
5282 g_warning ("gtk_widget_size_allocate(): attempt to underallocate %s%s %s %p. "
5283 "Allocation is %dx%d, but minimum required size is %dx%d.",
5284 priv->parent ? G_OBJECT_TYPE_NAME (priv->parent) : "", priv->parent ? "'s child" : "toplevel",
5285 G_OBJECT_TYPE_NAME (widget), widget,
5286 real_allocation.width, real_allocation.height,
5287 min_width, min_height);
5290 /* Now that we have the right natural height and width, go ahead and remove any margins from the
5291 * allocated sizes and possibly limit them to the natural sizes */
5292 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5293 GTK_ORIENTATION_HORIZONTAL,
5296 &adjusted_allocation.x,
5297 &adjusted_allocation.width);
5298 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
5299 GTK_ORIENTATION_VERTICAL,
5302 &adjusted_allocation.y,
5303 &adjusted_allocation.height);
5305 if (adjusted_allocation.x < real_allocation.x ||
5306 adjusted_allocation.y < real_allocation.y ||
5307 (adjusted_allocation.x + adjusted_allocation.width) >
5308 (real_allocation.x + real_allocation.width) ||
5309 (adjusted_allocation.y + adjusted_allocation.height >
5310 real_allocation.y + real_allocation.height))
5312 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",
5313 G_OBJECT_TYPE_NAME (widget), widget,
5314 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
5315 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
5316 adjusted_allocation = real_allocation; /* veto it */
5320 real_allocation = adjusted_allocation;
5323 if (real_allocation.width < 0 || real_allocation.height < 0)
5325 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
5326 real_allocation.width,
5327 real_allocation.height);
5330 real_allocation.width = MAX (real_allocation.width, 1);
5331 real_allocation.height = MAX (real_allocation.height, 1);
5333 size_changed = (old_allocation.width != real_allocation.width ||
5334 old_allocation.height != real_allocation.height);
5335 position_changed = (old_allocation.x != real_allocation.x ||
5336 old_allocation.y != real_allocation.y);
5338 if (!alloc_needed && !size_changed && !position_changed)
5341 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
5343 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
5344 priv->alloc_needed = FALSE;
5346 if (gtk_widget_get_mapped (widget))
5348 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
5350 /* Invalidate union(old_allaction,priv->allocation) in priv->window
5352 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5353 cairo_region_union_rectangle (invalidate, &old_allocation);
5355 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
5356 cairo_region_destroy (invalidate);
5361 if (priv->redraw_on_alloc)
5363 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
5365 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
5366 cairo_region_union_rectangle (invalidate, &old_allocation);
5368 gtk_widget_invalidate_widget_windows (widget, invalidate);
5369 cairo_region_destroy (invalidate);
5374 if ((size_changed || position_changed) && priv->parent &&
5375 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
5377 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
5378 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
5379 cairo_region_destroy (invalidate);
5383 gtk_widget_pop_verify_invariants (widget);
5387 * gtk_widget_common_ancestor:
5388 * @widget_a: a #GtkWidget
5389 * @widget_b: a #GtkWidget
5391 * Find the common ancestor of @widget_a and @widget_b that
5392 * is closest to the two widgets.
5394 * Return value: the closest common ancestor of @widget_a and
5395 * @widget_b or %NULL if @widget_a and @widget_b do not
5396 * share a common ancestor.
5399 gtk_widget_common_ancestor (GtkWidget *widget_a,
5400 GtkWidget *widget_b)
5402 GtkWidget *parent_a;
5403 GtkWidget *parent_b;
5407 parent_a = widget_a;
5408 while (parent_a->priv->parent)
5410 parent_a = parent_a->priv->parent;
5414 parent_b = widget_b;
5415 while (parent_b->priv->parent)
5417 parent_b = parent_b->priv->parent;
5421 if (parent_a != parent_b)
5424 while (depth_a > depth_b)
5426 widget_a = widget_a->priv->parent;
5430 while (depth_b > depth_a)
5432 widget_b = widget_b->priv->parent;
5436 while (widget_a != widget_b)
5438 widget_a = widget_a->priv->parent;
5439 widget_b = widget_b->priv->parent;
5446 * gtk_widget_translate_coordinates:
5447 * @src_widget: a #GtkWidget
5448 * @dest_widget: a #GtkWidget
5449 * @src_x: X position relative to @src_widget
5450 * @src_y: Y position relative to @src_widget
5451 * @dest_x: (out): location to store X position relative to @dest_widget
5452 * @dest_y: (out): location to store Y position relative to @dest_widget
5454 * Translate coordinates relative to @src_widget's allocation to coordinates
5455 * relative to @dest_widget's allocations. In order to perform this
5456 * operation, both widgets must be realized, and must share a common
5459 * Return value: %FALSE if either widget was not realized, or there
5460 * was no common ancestor. In this case, nothing is stored in
5461 * *@dest_x and *@dest_y. Otherwise %TRUE.
5464 gtk_widget_translate_coordinates (GtkWidget *src_widget,
5465 GtkWidget *dest_widget,
5471 GtkWidgetPrivate *src_priv = src_widget->priv;
5472 GtkWidgetPrivate *dest_priv = dest_widget->priv;
5473 GtkWidget *ancestor;
5475 GList *dest_list = NULL;
5477 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
5478 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
5480 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
5481 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
5484 /* Translate from allocation relative to window relative */
5485 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
5488 gdk_window_get_position (src_priv->window, &wx, &wy);
5490 src_x -= wx - src_priv->allocation.x;
5491 src_y -= wy - src_priv->allocation.y;
5495 src_x += src_priv->allocation.x;
5496 src_y += src_priv->allocation.y;
5499 /* Translate to the common ancestor */
5500 window = src_priv->window;
5501 while (window != ancestor->priv->window)
5505 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
5510 window = gdk_window_get_effective_parent (window);
5512 if (!window) /* Handle GtkHandleBox */
5517 window = dest_priv->window;
5518 while (window != ancestor->priv->window)
5520 dest_list = g_list_prepend (dest_list, window);
5522 window = gdk_window_get_effective_parent (window);
5524 if (!window) /* Handle GtkHandleBox */
5526 g_list_free (dest_list);
5535 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
5540 dest_list = g_list_remove (dest_list, dest_list->data);
5543 /* Translate from window relative to allocation relative */
5544 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
5547 gdk_window_get_position (dest_priv->window, &wx, &wy);
5549 src_x += wx - dest_priv->allocation.x;
5550 src_y += wy - dest_priv->allocation.y;
5554 src_x -= dest_priv->allocation.x;
5555 src_y -= dest_priv->allocation.y;
5567 gtk_widget_real_size_allocate (GtkWidget *widget,
5568 GtkAllocation *allocation)
5570 GtkWidgetPrivate *priv = widget->priv;
5572 priv->allocation = *allocation;
5574 if (gtk_widget_get_realized (widget) &&
5575 gtk_widget_get_has_window (widget))
5577 gdk_window_move_resize (priv->window,
5578 allocation->x, allocation->y,
5579 allocation->width, allocation->height);
5583 /* translate initial/final into start/end */
5585 effective_align (GtkAlign align,
5586 GtkTextDirection direction)
5590 case GTK_ALIGN_START:
5591 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
5593 return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
5600 adjust_for_align (GtkAlign align,
5602 gint *allocated_pos,
5603 gint *allocated_size)
5607 case GTK_ALIGN_FILL:
5608 /* change nothing */
5610 case GTK_ALIGN_START:
5611 /* keep *allocated_pos where it is */
5612 *allocated_size = MIN (*allocated_size, *natural_size);
5615 if (*allocated_size > *natural_size)
5617 *allocated_pos += (*allocated_size - *natural_size);
5618 *allocated_size = *natural_size;
5621 case GTK_ALIGN_CENTER:
5622 if (*allocated_size > *natural_size)
5624 *allocated_pos += (*allocated_size - *natural_size) / 2;
5625 *allocated_size = MIN (*allocated_size, *natural_size);
5632 adjust_for_margin(gint start_margin,
5636 gint *allocated_pos,
5637 gint *allocated_size)
5639 *minimum_size -= (start_margin + end_margin);
5640 *natural_size -= (start_margin + end_margin);
5641 *allocated_pos += start_margin;
5642 *allocated_size -= (start_margin + end_margin);
5646 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
5647 GtkOrientation orientation,
5650 gint *allocated_pos,
5651 gint *allocated_size)
5653 const GtkWidgetAuxInfo *aux_info;
5655 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
5657 if (orientation == GTK_ORIENTATION_HORIZONTAL)
5659 adjust_for_margin (aux_info->margin.left,
5660 aux_info->margin.right,
5661 minimum_size, natural_size,
5662 allocated_pos, allocated_size);
5663 adjust_for_align (effective_align (aux_info->halign, gtk_widget_get_direction (widget)),
5664 natural_size, allocated_pos, allocated_size);
5668 adjust_for_margin (aux_info->margin.top,
5669 aux_info->margin.bottom,
5670 minimum_size, natural_size,
5671 allocated_pos, allocated_size);
5672 adjust_for_align (effective_align (aux_info->valign, GTK_TEXT_DIR_NONE),
5673 natural_size, allocated_pos, allocated_size);
5678 gtk_widget_real_can_activate_accel (GtkWidget *widget,
5681 GtkWidgetPrivate *priv = widget->priv;
5683 /* widgets must be onscreen for accels to take effect */
5684 return gtk_widget_is_sensitive (widget) &&
5685 gtk_widget_is_drawable (widget) &&
5686 gdk_window_is_viewable (priv->window);
5690 * gtk_widget_can_activate_accel:
5691 * @widget: a #GtkWidget
5692 * @signal_id: the ID of a signal installed on @widget
5694 * Determines whether an accelerator that activates the signal
5695 * identified by @signal_id can currently be activated.
5696 * This is done by emitting the #GtkWidget::can-activate-accel
5697 * signal on @widget; if the signal isn't overridden by a
5698 * handler or in a derived widget, then the default check is
5699 * that the widget must be sensitive, and the widget and all
5700 * its ancestors mapped.
5702 * Return value: %TRUE if the accelerator can be activated.
5707 gtk_widget_can_activate_accel (GtkWidget *widget,
5710 gboolean can_activate = FALSE;
5711 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5712 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5713 return can_activate;
5722 closure_accel_activate (GClosure *closure,
5723 GValue *return_value,
5724 guint n_param_values,
5725 const GValue *param_values,
5726 gpointer invocation_hint,
5727 gpointer marshal_data)
5729 AccelClosure *aclosure = (AccelClosure*) closure;
5730 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5733 g_signal_emit (closure->data, aclosure->signal_id, 0);
5735 /* whether accelerator was handled */
5736 g_value_set_boolean (return_value, can_activate);
5740 closures_destroy (gpointer data)
5742 GSList *slist, *closures = data;
5744 for (slist = closures; slist; slist = slist->next)
5746 g_closure_invalidate (slist->data);
5747 g_closure_unref (slist->data);
5749 g_slist_free (closures);
5753 widget_new_accel_closure (GtkWidget *widget,
5756 AccelClosure *aclosure;
5757 GClosure *closure = NULL;
5758 GSList *slist, *closures;
5760 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5761 for (slist = closures; slist; slist = slist->next)
5762 if (!gtk_accel_group_from_accel_closure (slist->data))
5764 /* reuse this closure */
5765 closure = slist->data;
5770 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5771 closures = g_slist_prepend (closures, g_closure_ref (closure));
5772 g_closure_sink (closure);
5773 g_closure_set_marshal (closure, closure_accel_activate);
5775 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5777 aclosure = (AccelClosure*) closure;
5778 g_assert (closure->data == widget);
5779 g_assert (closure->marshal == closure_accel_activate);
5780 aclosure->signal_id = signal_id;
5786 * gtk_widget_add_accelerator:
5787 * @widget: widget to install an accelerator on
5788 * @accel_signal: widget signal to emit on accelerator activation
5789 * @accel_group: accel group for this widget, added to its toplevel
5790 * @accel_key: GDK keyval of the accelerator
5791 * @accel_mods: modifier key combination of the accelerator
5792 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5794 * Installs an accelerator for this @widget in @accel_group that causes
5795 * @accel_signal to be emitted if the accelerator is activated.
5796 * The @accel_group needs to be added to the widget's toplevel via
5797 * gtk_window_add_accel_group(), and the signal must be of type %G_SIGNAL_ACTION.
5798 * Accelerators added through this function are not user changeable during
5799 * runtime. If you want to support accelerators that can be changed by the
5800 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5801 * gtk_menu_item_set_accel_path() instead.
5804 gtk_widget_add_accelerator (GtkWidget *widget,
5805 const gchar *accel_signal,
5806 GtkAccelGroup *accel_group,
5808 GdkModifierType accel_mods,
5809 GtkAccelFlags accel_flags)
5814 g_return_if_fail (GTK_IS_WIDGET (widget));
5815 g_return_if_fail (accel_signal != NULL);
5816 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5818 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5819 if (!query.signal_id ||
5820 !(query.signal_flags & G_SIGNAL_ACTION) ||
5821 query.return_type != G_TYPE_NONE ||
5824 /* hmm, should be elaborate enough */
5825 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5826 G_OBJECT_TYPE_NAME (widget), accel_signal);
5830 closure = widget_new_accel_closure (widget, query.signal_id);
5832 g_object_ref (widget);
5834 /* install the accelerator. since we don't map this onto an accel_path,
5835 * the accelerator will automatically be locked.
5837 gtk_accel_group_connect (accel_group,
5840 accel_flags | GTK_ACCEL_LOCKED,
5843 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5845 g_object_unref (widget);
5849 * gtk_widget_remove_accelerator:
5850 * @widget: widget to install an accelerator on
5851 * @accel_group: accel group for this widget
5852 * @accel_key: GDK keyval of the accelerator
5853 * @accel_mods: modifier key combination of the accelerator
5855 * Removes an accelerator from @widget, previously installed with
5856 * gtk_widget_add_accelerator().
5858 * Returns: whether an accelerator was installed and could be removed
5861 gtk_widget_remove_accelerator (GtkWidget *widget,
5862 GtkAccelGroup *accel_group,
5864 GdkModifierType accel_mods)
5866 GtkAccelGroupEntry *ag_entry;
5867 GList *slist, *clist;
5870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5871 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5873 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5874 clist = gtk_widget_list_accel_closures (widget);
5875 for (slist = clist; slist; slist = slist->next)
5879 for (i = 0; i < n; i++)
5880 if (slist->data == (gpointer) ag_entry[i].closure)
5882 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5884 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5886 g_list_free (clist);
5891 g_list_free (clist);
5893 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5894 accel_key, accel_mods, accel_group,
5895 G_OBJECT_TYPE_NAME (widget), widget);
5901 * gtk_widget_list_accel_closures:
5902 * @widget: widget to list accelerator closures for
5904 * Lists the closures used by @widget for accelerator group connections
5905 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5906 * The closures can be used to monitor accelerator changes on @widget,
5907 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5908 * #GtkAccelGroup of a closure which can be found out with
5909 * gtk_accel_group_from_accel_closure().
5911 * Return value: (transfer container) (element-type GClosure):
5912 * a newly allocated #GList of closures
5915 gtk_widget_list_accel_closures (GtkWidget *widget)
5918 GList *clist = NULL;
5920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5922 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5923 if (gtk_accel_group_from_accel_closure (slist->data))
5924 clist = g_list_prepend (clist, slist->data);
5930 GtkAccelGroup *accel_group;
5935 destroy_accel_path (gpointer data)
5937 AccelPath *apath = data;
5939 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5941 /* closures_destroy takes care of unrefing the closure */
5942 g_object_unref (apath->accel_group);
5944 g_slice_free (AccelPath, apath);
5949 * gtk_widget_set_accel_path:
5950 * @widget: a #GtkWidget
5951 * @accel_path: (allow-none): path used to look up the accelerator
5952 * @accel_group: (allow-none): a #GtkAccelGroup.
5954 * Given an accelerator group, @accel_group, and an accelerator path,
5955 * @accel_path, sets up an accelerator in @accel_group so whenever the
5956 * key binding that is defined for @accel_path is pressed, @widget
5957 * will be activated. This removes any accelerators (for any
5958 * accelerator group) installed by previous calls to
5959 * gtk_widget_set_accel_path(). Associating accelerators with
5960 * paths allows them to be modified by the user and the modifications
5961 * to be saved for future use. (See gtk_accel_map_save().)
5963 * This function is a low level function that would most likely
5964 * be used by a menu creation system like #GtkUIManager. If you
5965 * use #GtkUIManager, setting up accelerator paths will be done
5968 * Even when you you aren't using #GtkUIManager, if you only want to
5969 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5970 * provides a somewhat more convenient interface.
5972 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5973 * pass a static string, you can save some memory by interning it first with
5974 * g_intern_static_string().
5977 gtk_widget_set_accel_path (GtkWidget *widget,
5978 const gchar *accel_path,
5979 GtkAccelGroup *accel_group)
5983 g_return_if_fail (GTK_IS_WIDGET (widget));
5984 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5988 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5989 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5991 gtk_accel_map_add_entry (accel_path, 0, 0);
5992 apath = g_slice_new (AccelPath);
5993 apath->accel_group = g_object_ref (accel_group);
5994 apath->path_quark = g_quark_from_string (accel_path);
5995 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
6000 /* also removes possible old settings */
6001 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
6004 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
6006 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
6010 _gtk_widget_get_accel_path (GtkWidget *widget,
6015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6017 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
6019 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
6020 return apath ? g_quark_to_string (apath->path_quark) : NULL;
6024 * gtk_widget_mnemonic_activate:
6025 * @widget: a #GtkWidget
6026 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
6028 * Emits the #GtkWidget::mnemonic-activate signal.
6030 * The default handler for this signal activates the @widget if
6031 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
6034 * Returns: %TRUE if the signal has been handled
6037 gtk_widget_mnemonic_activate (GtkWidget *widget,
6038 gboolean group_cycling)
6042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6044 group_cycling = group_cycling != FALSE;
6045 if (!gtk_widget_is_sensitive (widget))
6048 g_signal_emit (widget,
6049 widget_signals[MNEMONIC_ACTIVATE],
6057 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
6058 gboolean group_cycling)
6060 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
6061 gtk_widget_activate (widget);
6062 else if (gtk_widget_get_can_focus (widget))
6063 gtk_widget_grab_focus (widget);
6066 g_warning ("widget `%s' isn't suitable for mnemonic activation",
6067 G_OBJECT_TYPE_NAME (widget));
6068 gtk_widget_error_bell (widget);
6073 static const cairo_user_data_key_t event_key;
6076 _gtk_cairo_get_event (cairo_t *cr)
6078 g_return_val_if_fail (cr != NULL, NULL);
6080 return cairo_get_user_data (cr, &event_key);
6084 gtk_cairo_set_event (cairo_t *cr,
6085 GdkEventExpose *event)
6087 cairo_set_user_data (cr, &event_key, event, NULL);
6091 * gtk_cairo_should_draw_window:
6092 * @cr: a cairo context
6093 * @window: the window to check. @window may not be an input-only
6096 * This function is supposed to be called in #GtkWidget::draw
6097 * implementations for widgets that support multiple windows.
6098 * @cr must be untransformed from invoking of the draw function.
6099 * This function will return %TRUE if the contents of the given
6100 * @window are supposed to be drawn and %FALSE otherwise. Note
6101 * that when the drawing was not initiated by the windowing
6102 * system this function will return %TRUE for all windows, so
6103 * you need to draw the bottommost window first. Also, do not
6104 * use "else if" statements to check which window should be drawn.
6106 * Returns: %TRUE if @window should be drawn
6111 gtk_cairo_should_draw_window (cairo_t *cr,
6114 GdkEventExpose *event;
6116 g_return_val_if_fail (cr != NULL, FALSE);
6117 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
6119 event = _gtk_cairo_get_event (cr);
6121 return event == NULL ||
6122 event->window == window;
6126 gtk_widget_get_clip_draw (GtkWidget *widget)
6128 /* labels are not clipped, because clipping them would cause
6129 * mnemonics to not appear on characters that go beyond the
6131 * https://bugzilla.gnome.org/show_bug.cgi?id=648570
6133 if (GTK_IS_LABEL (widget))
6139 /* code shared by gtk_container_propagate_draw() and
6143 _gtk_widget_draw_internal (GtkWidget *widget,
6145 gboolean clip_to_size)
6147 if (!gtk_widget_is_drawable (widget))
6150 clip_to_size &= gtk_widget_get_clip_draw (widget);
6154 cairo_rectangle (cr,
6156 widget->priv->allocation.width,
6157 widget->priv->allocation.height);
6161 if (gdk_cairo_get_clip_rectangle (cr, NULL))
6165 g_signal_emit (widget, widget_signals[DRAW],
6169 if (cairo_status (cr) &&
6170 _gtk_cairo_get_event (cr))
6172 /* We check the event so we only warn about internal GTK calls.
6173 * Errors might come from PDF streams having write failures and
6174 * we don't want to spam stderr in that case.
6175 * We do want to catch errors from
6177 g_warning ("drawing failure for widget `%s': %s",
6178 G_OBJECT_TYPE_NAME (widget),
6179 cairo_status_to_string (cairo_status (cr)));
6186 * @widget: the widget to draw. It must be drawable (see
6187 * gtk_widget_is_drawable()) and a size must have been allocated.
6188 * @cr: a cairo context to draw to
6190 * Draws @widget to @cr. The top left corner of the widget will be
6191 * drawn to the currently set origin point of @cr.
6193 * You should pass a cairo context as @cr argument that is in an
6194 * original state. Otherwise the resulting drawing is undefined. For
6195 * example changing the operator using cairo_set_operator() or the
6196 * line width using cairo_set_line_width() might have unwanted side
6198 * You may however change the context's transform matrix - like with
6199 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
6200 * region with cairo_clip() prior to calling this function. Also, it
6201 * is fine to modify the context with cairo_save() and
6202 * cairo_push_group() prior to calling this function.
6204 * <note><para>Special purpose widgets may contain special code for
6205 * rendering to the screen and might appear differently on screen
6206 * and when rendered using gtk_widget_draw().</para></note>
6211 gtk_widget_draw (GtkWidget *widget,
6214 GdkEventExpose *tmp_event;
6216 g_return_if_fail (GTK_IS_WIDGET (widget));
6217 g_return_if_fail (!widget->priv->alloc_needed);
6218 g_return_if_fail (cr != NULL);
6221 /* We have to reset the event here so that draw functions can call
6222 * gtk_widget_draw() on random other widgets and get the desired
6223 * effect: Drawing all contents, not just the current window.
6225 tmp_event = _gtk_cairo_get_event (cr);
6226 gtk_cairo_set_event (cr, NULL);
6228 _gtk_widget_draw_internal (widget, cr, TRUE);
6230 gtk_cairo_set_event (cr, tmp_event);
6235 gtk_widget_real_key_press_event (GtkWidget *widget,
6238 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6242 gtk_widget_real_key_release_event (GtkWidget *widget,
6245 return gtk_bindings_activate_event (G_OBJECT (widget), event);
6249 gtk_widget_real_focus_in_event (GtkWidget *widget,
6250 GdkEventFocus *event)
6252 gtk_widget_queue_draw (widget);
6258 gtk_widget_real_focus_out_event (GtkWidget *widget,
6259 GdkEventFocus *event)
6261 gtk_widget_queue_draw (widget);
6267 gtk_widget_real_touch_event (GtkWidget *widget,
6268 GdkEventTouch *event)
6271 gboolean return_val;
6274 if (!event->emulating_pointer)
6277 if (event->type == GDK_TOUCH_BEGIN ||
6278 event->type == GDK_TOUCH_END)
6282 if (event->type == GDK_TOUCH_BEGIN)
6284 type = GDK_BUTTON_PRESS;
6285 signum = BUTTON_PRESS_EVENT;
6289 type = GDK_BUTTON_RELEASE;
6290 signum = BUTTON_RELEASE_EVENT;
6292 bevent = gdk_event_new (type);
6293 bevent->any.window = g_object_ref (event->window);
6294 bevent->any.send_event = FALSE;
6295 bevent->button.time = event->time;
6296 bevent->button.state = event->state;
6297 bevent->button.button = 1;
6298 bevent->button.x_root = event->x_root;
6299 bevent->button.y_root = event->y_root;
6300 bevent->button.x = event->x;
6301 bevent->button.y = event->y;
6302 bevent->button.device = event->device;
6303 bevent->button.axes = g_memdup (event->axes,
6304 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6305 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6307 else if (event->type == GDK_TOUCH_UPDATE)
6309 signum = MOTION_NOTIFY_EVENT;
6310 bevent = gdk_event_new (GDK_MOTION_NOTIFY);
6311 bevent->any.window = g_object_ref (event->window);
6312 bevent->any.send_event = FALSE;
6313 bevent->motion.time = event->time;
6314 bevent->motion.state = event->state;
6315 bevent->motion.x_root = event->x_root;
6316 bevent->motion.y_root = event->y_root;
6317 bevent->motion.x = event->x;
6318 bevent->motion.y = event->y;
6319 bevent->motion.device = event->device;
6320 bevent->motion.is_hint = FALSE;
6321 bevent->motion.axes = g_memdup (event->axes,
6322 sizeof (gdouble) * gdk_device_get_n_axes (event->device));
6323 gdk_event_set_source_device (bevent, gdk_event_get_source_device ((GdkEvent*)event));
6328 g_signal_emit (widget, widget_signals[signum], 0, bevent, &return_val);
6330 gdk_event_free (bevent);
6336 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
6337 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
6341 * @widget: a #GtkWidget
6342 * @event: a #GdkEvent
6344 * Rarely-used function. This function is used to emit
6345 * the event signals on a widget (those signals should never
6346 * be emitted without using this function to do so).
6347 * If you want to synthesize an event though, don't use this function;
6348 * instead, use gtk_main_do_event() so the event will behave as if
6349 * it were in the event queue. Don't synthesize expose events; instead,
6350 * use gdk_window_invalidate_rect() to invalidate a region of the
6353 * Return value: return from the event signal emission (%TRUE if
6354 * the event was handled)
6357 gtk_widget_event (GtkWidget *widget,
6360 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6361 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6363 if (event->type == GDK_EXPOSE)
6365 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6366 "the same effect, call gdk_window_invalidate_rect/region(), "
6367 "followed by gdk_window_process_updates().");
6371 return gtk_widget_event_internal (widget, event);
6375 _gtk_widget_set_captured_event_handler (GtkWidget *widget,
6376 GtkCapturedEventHandler callback)
6378 g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
6382 _gtk_widget_captured_event (GtkWidget *widget,
6385 gboolean return_val = FALSE;
6386 GtkCapturedEventHandler handler;
6388 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6389 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
6391 if (event->type == GDK_EXPOSE)
6393 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
6394 "the same effect, call gdk_window_invalidate_rect/region(), "
6395 "followed by gdk_window_process_updates().");
6399 if (!event_window_is_still_viewable (event))
6402 handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
6406 g_object_ref (widget);
6408 return_val = handler (widget, event);
6409 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6411 /* The widget that was originally to receive the event
6412 * handles motion hints, but the capturing widget might
6413 * not, so ensure we get further motion events.
6416 event->type == GDK_MOTION_NOTIFY &&
6417 event->motion.is_hint &&
6418 (gdk_window_get_events (event->any.window) &
6419 GDK_POINTER_MOTION_HINT_MASK) != 0)
6420 gdk_event_request_motions (&event->motion);
6422 g_object_unref (widget);
6427 /* Returns TRUE if a translation should be done */
6429 _gtk_widget_get_translation_to_window (GtkWidget *widget,
6434 GdkWindow *w, *widget_window;
6436 if (!gtk_widget_get_has_window (widget))
6438 *x = -widget->priv->allocation.x;
6439 *y = -widget->priv->allocation.y;
6447 widget_window = gtk_widget_get_window (widget);
6449 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
6452 gdk_window_get_position (w, &wx, &wy);
6469 * gtk_cairo_transform_to_window:
6470 * @cr: the cairo context to transform
6471 * @widget: the widget the context is currently centered for
6472 * @window: the window to transform the context to
6474 * Transforms the given cairo context @cr that from @widget-relative
6475 * coordinates to @window-relative coordinates.
6476 * If the @widget's window is not an ancestor of @window, no
6477 * modification will be applied.
6479 * This is the inverse to the transformation GTK applies when
6480 * preparing an expose event to be emitted with the #GtkWidget::draw
6481 * signal. It is intended to help porting multiwindow widgets from
6482 * GTK+ 2 to the rendering architecture of GTK+ 3.
6487 gtk_cairo_transform_to_window (cairo_t *cr,
6493 g_return_if_fail (cr != NULL);
6494 g_return_if_fail (GTK_IS_WIDGET (widget));
6495 g_return_if_fail (GDK_IS_WINDOW (window));
6497 if (_gtk_widget_get_translation_to_window (widget, window, &x, &y))
6498 cairo_translate (cr, x, y);
6502 * gtk_widget_send_expose:
6503 * @widget: a #GtkWidget
6504 * @event: a expose #GdkEvent
6506 * Very rarely-used function. This function is used to emit
6507 * an expose event on a widget. This function is not normally used
6508 * directly. The only time it is used is when propagating an expose
6509 * event to a child %NO_WINDOW widget, and that is normally done
6510 * using gtk_container_propagate_draw().
6512 * If you want to force an area of a window to be redrawn,
6513 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
6514 * To cause the redraw to be done immediately, follow that call
6515 * with a call to gdk_window_process_updates().
6517 * Return value: return from the event signal emission (%TRUE if
6518 * the event was handled)
6521 gtk_widget_send_expose (GtkWidget *widget,
6524 gboolean result = FALSE;
6529 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
6530 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
6531 g_return_val_if_fail (event != NULL, TRUE);
6532 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
6534 cr = gdk_cairo_create (event->expose.window);
6535 gtk_cairo_set_event (cr, &event->expose);
6537 gdk_cairo_region (cr, event->expose.region);
6540 do_clip = _gtk_widget_get_translation_to_window (widget,
6541 event->expose.window,
6543 cairo_translate (cr, -x, -y);
6545 _gtk_widget_draw_internal (widget, cr, do_clip);
6547 /* unset here, so if someone keeps a reference to cr we
6548 * don't leak the window. */
6549 gtk_cairo_set_event (cr, NULL);
6556 event_window_is_still_viewable (GdkEvent *event)
6558 /* Check that we think the event's window is viewable before
6559 * delivering the event, to prevent suprises. We do this here
6560 * at the last moment, since the event may have been queued
6561 * up behind other events, held over a recursive main loop, etc.
6563 switch (event->type)
6566 case GDK_MOTION_NOTIFY:
6567 case GDK_BUTTON_PRESS:
6568 case GDK_2BUTTON_PRESS:
6569 case GDK_3BUTTON_PRESS:
6571 case GDK_ENTER_NOTIFY:
6572 case GDK_PROXIMITY_IN:
6574 return event->any.window && gdk_window_is_viewable (event->any.window);
6577 /* The following events are the second half of paired events;
6578 * we always deliver them to deal with widgets that clean up
6579 * on the second half.
6581 case GDK_BUTTON_RELEASE:
6582 case GDK_KEY_RELEASE:
6583 case GDK_LEAVE_NOTIFY:
6584 case GDK_PROXIMITY_OUT:
6588 /* Remaining events would make sense on an not-viewable window,
6589 * or don't have an associated window.
6596 gtk_widget_event_internal (GtkWidget *widget,
6599 gboolean return_val = FALSE;
6601 /* We check only once for is-still-visible; if someone
6602 * hides the window in on of the signals on the widget,
6603 * they are responsible for returning TRUE to terminate
6606 if (!event_window_is_still_viewable (event))
6609 g_object_ref (widget);
6611 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
6612 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
6617 switch (event->type)
6623 case GDK_BUTTON_PRESS:
6624 case GDK_2BUTTON_PRESS:
6625 case GDK_3BUTTON_PRESS:
6626 signal_num = BUTTON_PRESS_EVENT;
6628 case GDK_TOUCH_BEGIN:
6629 case GDK_TOUCH_UPDATE:
6631 case GDK_TOUCH_CANCEL:
6632 signal_num = TOUCH_EVENT;
6635 signal_num = SCROLL_EVENT;
6637 case GDK_BUTTON_RELEASE:
6638 signal_num = BUTTON_RELEASE_EVENT;
6640 case GDK_MOTION_NOTIFY:
6641 signal_num = MOTION_NOTIFY_EVENT;
6644 signal_num = DELETE_EVENT;
6647 signal_num = DESTROY_EVENT;
6648 _gtk_tooltip_hide (widget);
6651 signal_num = KEY_PRESS_EVENT;
6653 case GDK_KEY_RELEASE:
6654 signal_num = KEY_RELEASE_EVENT;
6656 case GDK_ENTER_NOTIFY:
6657 signal_num = ENTER_NOTIFY_EVENT;
6659 case GDK_LEAVE_NOTIFY:
6660 signal_num = LEAVE_NOTIFY_EVENT;
6662 case GDK_FOCUS_CHANGE:
6663 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
6664 if (event->focus_change.in)
6665 _gtk_tooltip_focus_in (widget);
6667 _gtk_tooltip_focus_out (widget);
6670 signal_num = CONFIGURE_EVENT;
6673 signal_num = MAP_EVENT;
6676 signal_num = UNMAP_EVENT;
6678 case GDK_WINDOW_STATE:
6679 signal_num = WINDOW_STATE_EVENT;
6681 case GDK_PROPERTY_NOTIFY:
6682 signal_num = PROPERTY_NOTIFY_EVENT;
6684 case GDK_SELECTION_CLEAR:
6685 signal_num = SELECTION_CLEAR_EVENT;
6687 case GDK_SELECTION_REQUEST:
6688 signal_num = SELECTION_REQUEST_EVENT;
6690 case GDK_SELECTION_NOTIFY:
6691 signal_num = SELECTION_NOTIFY_EVENT;
6693 case GDK_PROXIMITY_IN:
6694 signal_num = PROXIMITY_IN_EVENT;
6696 case GDK_PROXIMITY_OUT:
6697 signal_num = PROXIMITY_OUT_EVENT;
6699 case GDK_VISIBILITY_NOTIFY:
6700 signal_num = VISIBILITY_NOTIFY_EVENT;
6702 case GDK_GRAB_BROKEN:
6703 signal_num = GRAB_BROKEN_EVENT;
6706 signal_num = DAMAGE_EVENT;
6709 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
6713 if (signal_num != -1)
6714 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
6716 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
6717 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
6721 g_object_unref (widget);
6727 * gtk_widget_activate:
6728 * @widget: a #GtkWidget that's activatable
6730 * For widgets that can be "activated" (buttons, menu items, etc.)
6731 * this function activates them. Activation is what happens when you
6732 * press Enter on a widget during key navigation. If @widget isn't
6733 * activatable, the function returns %FALSE.
6735 * Return value: %TRUE if the widget was activatable
6738 gtk_widget_activate (GtkWidget *widget)
6740 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6742 if (WIDGET_CLASS (widget)->activate_signal)
6744 /* FIXME: we should eventually check the signals signature here */
6745 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
6754 gtk_widget_reparent_subwindows (GtkWidget *widget,
6755 GdkWindow *new_window)
6757 GtkWidgetPrivate *priv = widget->priv;
6759 if (!gtk_widget_get_has_window (widget))
6761 GList *children = gdk_window_get_children (priv->window);
6764 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6766 GdkWindow *window = tmp_list->data;
6769 gdk_window_get_user_data (window, &child);
6770 while (child && child != widget)
6771 child = ((GtkWidget*) child)->priv->parent;
6774 gdk_window_reparent (window, new_window, 0, 0);
6777 g_list_free (children);
6782 GList *tmp_list, *children;
6784 parent = gdk_window_get_parent (priv->window);
6787 gdk_window_reparent (priv->window, new_window, 0, 0);
6790 children = gdk_window_get_children (parent);
6792 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
6794 GdkWindow *window = tmp_list->data;
6797 gdk_window_get_user_data (window, &child);
6799 if (child == widget)
6800 gdk_window_reparent (window, new_window, 0, 0);
6803 g_list_free (children);
6809 gtk_widget_reparent_fixup_child (GtkWidget *widget,
6810 gpointer client_data)
6812 GtkWidgetPrivate *priv = widget->priv;
6814 g_assert (client_data != NULL);
6816 if (!gtk_widget_get_has_window (widget))
6819 g_object_unref (priv->window);
6820 priv->window = (GdkWindow*) client_data;
6822 g_object_ref (priv->window);
6824 if (GTK_IS_CONTAINER (widget))
6825 gtk_container_forall (GTK_CONTAINER (widget),
6826 gtk_widget_reparent_fixup_child,
6832 * gtk_widget_reparent:
6833 * @widget: a #GtkWidget
6834 * @new_parent: a #GtkContainer to move the widget into
6836 * Moves a widget from one #GtkContainer to another, handling reference
6837 * count issues to avoid destroying the widget.
6840 gtk_widget_reparent (GtkWidget *widget,
6841 GtkWidget *new_parent)
6843 GtkWidgetPrivate *priv;
6845 g_return_if_fail (GTK_IS_WIDGET (widget));
6846 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6847 priv = widget->priv;
6848 g_return_if_fail (priv->parent != NULL);
6850 if (priv->parent != new_parent)
6852 /* First try to see if we can get away without unrealizing
6853 * the widget as we reparent it. if so we set a flag so
6854 * that gtk_widget_unparent doesn't unrealize widget
6856 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6857 priv->in_reparent = TRUE;
6859 g_object_ref (widget);
6860 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6861 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6862 g_object_unref (widget);
6864 if (priv->in_reparent)
6866 priv->in_reparent = FALSE;
6868 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6869 gtk_widget_reparent_fixup_child (widget,
6870 gtk_widget_get_parent_window (widget));
6873 g_object_notify (G_OBJECT (widget), "parent");
6878 * gtk_widget_intersect:
6879 * @widget: a #GtkWidget
6880 * @area: a rectangle
6881 * @intersection: rectangle to store intersection of @widget and @area
6883 * Computes the intersection of a @widget's area and @area, storing
6884 * the intersection in @intersection, and returns %TRUE if there was
6885 * an intersection. @intersection may be %NULL if you're only
6886 * interested in whether there was an intersection.
6888 * Return value: %TRUE if there was an intersection
6891 gtk_widget_intersect (GtkWidget *widget,
6892 const GdkRectangle *area,
6893 GdkRectangle *intersection)
6895 GtkWidgetPrivate *priv;
6900 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6901 g_return_val_if_fail (area != NULL, FALSE);
6903 priv = widget->priv;
6906 dest = intersection;
6910 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6912 if (return_val && intersection && gtk_widget_get_has_window (widget))
6914 intersection->x -= priv->allocation.x;
6915 intersection->y -= priv->allocation.y;
6922 * gtk_widget_region_intersect:
6923 * @widget: a #GtkWidget
6924 * @region: a #cairo_region_t, in the same coordinate system as
6925 * @widget->allocation. That is, relative to @widget->window
6926 * for %NO_WINDOW widgets; relative to the parent window
6927 * of @widget->window for widgets with their own window.
6929 * Computes the intersection of a @widget's area and @region, returning
6930 * the intersection. The result may be empty, use cairo_region_is_empty() to
6933 * Returns: A newly allocated region holding the intersection of @widget
6934 * and @region. The coordinates of the return value are relative to
6935 * @widget->window for %NO_WINDOW widgets, and relative to the parent
6936 * window of @widget->window for widgets with their own window.
6939 gtk_widget_region_intersect (GtkWidget *widget,
6940 const cairo_region_t *region)
6943 cairo_region_t *dest;
6945 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6946 g_return_val_if_fail (region != NULL, NULL);
6948 gtk_widget_get_allocation (widget, &rect);
6950 dest = cairo_region_create_rectangle (&rect);
6952 cairo_region_intersect (dest, region);
6958 * _gtk_widget_grab_notify:
6959 * @widget: a #GtkWidget
6960 * @was_grabbed: whether a grab is now in effect
6962 * Emits the #GtkWidget::grab-notify signal on @widget.
6967 _gtk_widget_grab_notify (GtkWidget *widget,
6968 gboolean was_grabbed)
6970 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6974 * gtk_widget_grab_focus:
6975 * @widget: a #GtkWidget
6977 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6978 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6979 * something like #GtkFrame won't work.
6981 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6982 * gtk_widget_set_can_focus() to modify that flag.
6984 * The widget also needs to be realized and mapped. This is indicated by the
6985 * related signals. Grabbing the focus immediately after creating the widget
6986 * will likely fail and cause critical warnings.
6989 gtk_widget_grab_focus (GtkWidget *widget)
6991 g_return_if_fail (GTK_IS_WIDGET (widget));
6993 if (!gtk_widget_is_sensitive (widget))
6996 g_object_ref (widget);
6997 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6998 g_object_notify (G_OBJECT (widget), "has-focus");
6999 g_object_unref (widget);
7003 reset_focus_recurse (GtkWidget *widget,
7006 if (GTK_IS_CONTAINER (widget))
7008 GtkContainer *container;
7010 container = GTK_CONTAINER (widget);
7011 gtk_container_set_focus_child (container, NULL);
7013 gtk_container_foreach (container,
7014 reset_focus_recurse,
7020 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
7022 if (gtk_widget_get_can_focus (focus_widget))
7024 GtkWidget *toplevel;
7027 /* clear the current focus setting, break if the current widget
7028 * is the focus widget's parent, since containers above that will
7029 * be set by the next loop.
7031 toplevel = gtk_widget_get_toplevel (focus_widget);
7032 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
7034 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
7036 if (widget == focus_widget)
7038 /* We call _gtk_window_internal_set_focus() here so that the
7039 * toplevel window can request the focus if necessary.
7040 * This is needed when the toplevel is a GtkPlug
7042 if (!gtk_widget_has_focus (widget))
7043 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
7050 GtkWidget *common_ancestor = gtk_widget_common_ancestor (widget, focus_widget);
7052 if (widget != common_ancestor)
7054 while (widget->priv->parent && widget->priv->parent != common_ancestor)
7056 widget = widget->priv->parent;
7057 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
7062 else if (toplevel != focus_widget)
7064 /* gtk_widget_grab_focus() operates on a tree without window...
7065 * actually, this is very questionable behaviour.
7068 gtk_container_foreach (GTK_CONTAINER (toplevel),
7069 reset_focus_recurse,
7073 /* now propagate the new focus up the widget tree and finally
7074 * set it on the window
7076 widget = focus_widget;
7077 while (widget->priv->parent)
7079 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
7080 widget = widget->priv->parent;
7082 if (GTK_IS_WINDOW (widget))
7083 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
7088 gtk_widget_real_query_tooltip (GtkWidget *widget,
7091 gboolean keyboard_tip,
7092 GtkTooltip *tooltip)
7094 gchar *tooltip_markup;
7095 gboolean has_tooltip;
7097 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
7098 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
7100 if (has_tooltip && tooltip_markup)
7102 gtk_tooltip_set_markup (tooltip, tooltip_markup);
7110 gtk_widget_real_state_flags_changed (GtkWidget *widget,
7111 GtkStateFlags old_state)
7113 gtk_widget_update_pango_context (widget);
7117 gtk_widget_real_style_updated (GtkWidget *widget)
7119 GtkWidgetPrivate *priv = widget->priv;
7121 gtk_widget_update_pango_context (widget);
7122 gtk_widget_update_alpha (widget);
7124 if (priv->style != NULL &&
7125 priv->style != gtk_widget_get_default_style ())
7127 /* Trigger ::style-set for old
7128 * widgets not listening to this
7130 g_signal_emit (widget,
7131 widget_signals[STYLE_SET],
7133 widget->priv->style);
7136 if (widget->priv->context)
7138 const GtkBitmask *changes = _gtk_style_context_get_changes (widget->priv->context);
7140 if (gtk_widget_get_realized (widget) &&
7141 gtk_widget_get_has_window (widget) &&
7142 !gtk_widget_get_app_paintable (widget))
7143 gtk_style_context_set_background (widget->priv->context,
7144 widget->priv->window);
7146 if (widget->priv->anchored)
7148 if (changes && _gtk_css_style_property_changes_affect_size (changes))
7149 gtk_widget_queue_resize (widget);
7151 gtk_widget_queue_draw (widget);
7156 if (widget->priv->anchored)
7157 gtk_widget_queue_resize (widget);
7162 gtk_widget_real_show_help (GtkWidget *widget,
7163 GtkWidgetHelpType help_type)
7165 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
7167 _gtk_tooltip_toggle_keyboard_mode (widget);
7176 gtk_widget_real_focus (GtkWidget *widget,
7177 GtkDirectionType direction)
7179 if (!gtk_widget_get_can_focus (widget))
7182 if (!gtk_widget_is_focus (widget))
7184 gtk_widget_grab_focus (widget);
7192 gtk_widget_real_move_focus (GtkWidget *widget,
7193 GtkDirectionType direction)
7195 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
7197 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
7199 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
7205 gtk_widget_real_keynav_failed (GtkWidget *widget,
7206 GtkDirectionType direction)
7208 gboolean cursor_only;
7212 case GTK_DIR_TAB_FORWARD:
7213 case GTK_DIR_TAB_BACKWARD:
7220 g_object_get (gtk_widget_get_settings (widget),
7221 "gtk-keynav-cursor-only", &cursor_only,
7228 gtk_widget_error_bell (widget);
7234 * gtk_widget_set_can_focus:
7235 * @widget: a #GtkWidget
7236 * @can_focus: whether or not @widget can own the input focus.
7238 * Specifies whether @widget can own the input focus. See
7239 * gtk_widget_grab_focus() for actually setting the input focus on a
7245 gtk_widget_set_can_focus (GtkWidget *widget,
7248 g_return_if_fail (GTK_IS_WIDGET (widget));
7250 if (widget->priv->can_focus != can_focus)
7252 widget->priv->can_focus = can_focus;
7254 gtk_widget_queue_resize (widget);
7255 g_object_notify (G_OBJECT (widget), "can-focus");
7260 * gtk_widget_get_can_focus:
7261 * @widget: a #GtkWidget
7263 * Determines whether @widget can own the input focus. See
7264 * gtk_widget_set_can_focus().
7266 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
7271 gtk_widget_get_can_focus (GtkWidget *widget)
7273 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7275 return widget->priv->can_focus;
7279 * gtk_widget_has_focus:
7280 * @widget: a #GtkWidget
7282 * Determines if the widget has the global input focus. See
7283 * gtk_widget_is_focus() for the difference between having the global
7284 * input focus, and only having the focus within a toplevel.
7286 * Return value: %TRUE if the widget has the global input focus.
7291 gtk_widget_has_focus (GtkWidget *widget)
7293 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7295 return widget->priv->has_focus;
7299 * gtk_widget_has_visible_focus:
7300 * @widget: a #GtkWidget
7302 * Determines if the widget should show a visible indication that
7303 * it has the global input focus. This is a convenience function for
7304 * use in ::draw handlers that takes into account whether focus
7305 * indication should currently be shown in the toplevel window of
7306 * @widget. See gtk_window_get_focus_visible() for more information
7307 * about focus indication.
7309 * To find out if the widget has the global input focus, use
7310 * gtk_widget_has_focus().
7312 * Return value: %TRUE if the widget should display a 'focus rectangle'
7317 gtk_widget_has_visible_focus (GtkWidget *widget)
7319 gboolean draw_focus;
7321 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7323 if (widget->priv->has_focus)
7325 GtkWidget *toplevel;
7327 toplevel = gtk_widget_get_toplevel (widget);
7329 if (GTK_IS_WINDOW (toplevel))
7330 draw_focus = gtk_window_get_focus_visible (GTK_WINDOW (toplevel));
7341 * gtk_widget_is_focus:
7342 * @widget: a #GtkWidget
7344 * Determines if the widget is the focus widget within its
7345 * toplevel. (This does not mean that the %HAS_FOCUS flag is
7346 * necessarily set; %HAS_FOCUS will only be set if the
7347 * toplevel widget additionally has the global input focus.)
7349 * Return value: %TRUE if the widget is the focus widget.
7352 gtk_widget_is_focus (GtkWidget *widget)
7354 GtkWidget *toplevel;
7356 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7358 toplevel = gtk_widget_get_toplevel (widget);
7360 if (GTK_IS_WINDOW (toplevel))
7361 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
7367 * gtk_widget_set_can_default:
7368 * @widget: a #GtkWidget
7369 * @can_default: whether or not @widget can be a default widget.
7371 * Specifies whether @widget can be a default widget. See
7372 * gtk_widget_grab_default() for details about the meaning of
7378 gtk_widget_set_can_default (GtkWidget *widget,
7379 gboolean can_default)
7381 g_return_if_fail (GTK_IS_WIDGET (widget));
7383 if (widget->priv->can_default != can_default)
7385 widget->priv->can_default = can_default;
7387 gtk_widget_queue_resize (widget);
7388 g_object_notify (G_OBJECT (widget), "can-default");
7393 * gtk_widget_get_can_default:
7394 * @widget: a #GtkWidget
7396 * Determines whether @widget can be a default widget. See
7397 * gtk_widget_set_can_default().
7399 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
7404 gtk_widget_get_can_default (GtkWidget *widget)
7406 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7408 return widget->priv->can_default;
7412 * gtk_widget_has_default:
7413 * @widget: a #GtkWidget
7415 * Determines whether @widget is the current default widget within its
7416 * toplevel. See gtk_widget_set_can_default().
7418 * Return value: %TRUE if @widget is the current default widget within
7419 * its toplevel, %FALSE otherwise
7424 gtk_widget_has_default (GtkWidget *widget)
7426 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7428 return widget->priv->has_default;
7432 _gtk_widget_set_has_default (GtkWidget *widget,
7433 gboolean has_default)
7435 GtkStyleContext *context;
7437 widget->priv->has_default = has_default;
7439 context = gtk_widget_get_style_context (widget);
7442 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DEFAULT);
7444 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_DEFAULT);
7448 * gtk_widget_grab_default:
7449 * @widget: a #GtkWidget
7451 * Causes @widget to become the default widget. @widget must be able to be
7452 * a default widget; typically you would ensure this yourself
7453 * by calling gtk_widget_set_can_default() with a %TRUE value.
7454 * The default widget is activated when
7455 * the user presses Enter in a window. Default widgets must be
7456 * activatable, that is, gtk_widget_activate() should affect them. Note
7457 * that #GtkEntry widgets require the "activates-default" property
7458 * set to %TRUE before they activate the default widget when Enter
7459 * is pressed and the #GtkEntry is focused.
7462 gtk_widget_grab_default (GtkWidget *widget)
7466 g_return_if_fail (GTK_IS_WIDGET (widget));
7467 g_return_if_fail (gtk_widget_get_can_default (widget));
7469 window = gtk_widget_get_toplevel (widget);
7471 if (window && gtk_widget_is_toplevel (window))
7472 gtk_window_set_default (GTK_WINDOW (window), widget);
7474 g_warning (G_STRLOC ": widget not within a GtkWindow");
7478 * gtk_widget_set_receives_default:
7479 * @widget: a #GtkWidget
7480 * @receives_default: whether or not @widget can be a default widget.
7482 * Specifies whether @widget will be treated as the default widget
7483 * within its toplevel when it has the focus, even if another widget
7486 * See gtk_widget_grab_default() for details about the meaning of
7492 gtk_widget_set_receives_default (GtkWidget *widget,
7493 gboolean receives_default)
7495 g_return_if_fail (GTK_IS_WIDGET (widget));
7497 if (widget->priv->receives_default != receives_default)
7499 widget->priv->receives_default = receives_default;
7501 g_object_notify (G_OBJECT (widget), "receives-default");
7506 * gtk_widget_get_receives_default:
7507 * @widget: a #GtkWidget
7509 * Determines whether @widget is always treated as the default widget
7510 * within its toplevel when it has the focus, even if another widget
7513 * See gtk_widget_set_receives_default().
7515 * Return value: %TRUE if @widget acts as the default widget when focussed,
7521 gtk_widget_get_receives_default (GtkWidget *widget)
7523 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7525 return widget->priv->receives_default;
7529 * gtk_widget_has_grab:
7530 * @widget: a #GtkWidget
7532 * Determines whether the widget is currently grabbing events, so it
7533 * is the only widget receiving input events (keyboard and mouse).
7535 * See also gtk_grab_add().
7537 * Return value: %TRUE if the widget is in the grab_widgets stack
7542 gtk_widget_has_grab (GtkWidget *widget)
7544 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7546 return widget->priv->has_grab;
7550 _gtk_widget_set_has_grab (GtkWidget *widget,
7553 widget->priv->has_grab = has_grab;
7557 * gtk_widget_device_is_shadowed:
7558 * @widget: a #GtkWidget
7559 * @device: a #GdkDevice
7561 * Returns %TRUE if @device has been shadowed by a GTK+
7562 * device grab on another widget, so it would stop sending
7563 * events to @widget. This may be used in the
7564 * #GtkWidget::grab-notify signal to check for specific
7565 * devices. See gtk_device_grab_add().
7567 * Returns: %TRUE if there is an ongoing grab on @device
7568 * by another #GtkWidget than @widget.
7573 gtk_widget_device_is_shadowed (GtkWidget *widget,
7576 GtkWindowGroup *group;
7577 GtkWidget *grab_widget, *toplevel;
7579 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7580 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
7582 if (!gtk_widget_get_realized (widget))
7585 toplevel = gtk_widget_get_toplevel (widget);
7587 if (GTK_IS_WINDOW (toplevel))
7588 group = gtk_window_get_group (GTK_WINDOW (toplevel));
7590 group = gtk_window_get_group (NULL);
7592 grab_widget = gtk_window_group_get_current_device_grab (group, device);
7594 /* Widget not inside the hierarchy of grab_widget */
7596 widget != grab_widget &&
7597 !gtk_widget_is_ancestor (widget, grab_widget))
7600 grab_widget = gtk_window_group_get_current_grab (group);
7601 if (grab_widget && widget != grab_widget &&
7602 !gtk_widget_is_ancestor (widget, grab_widget))
7609 * gtk_widget_set_name:
7610 * @widget: a #GtkWidget
7611 * @name: name for the widget
7613 * Widgets can be named, which allows you to refer to them from a
7614 * CSS file. You can apply a style to widgets with a particular name
7615 * in the CSS file. See the documentation for the CSS syntax (on the
7616 * same page as the docs for #GtkStyleContext).
7618 * Note that the CSS syntax has certain special characters to delimit
7619 * and represent elements in a selector (period, #, >, *...),
7620 * so using these will make your widget impossible to match by name.
7621 * Any combination of alphanumeric symbols, dashes and underscores will
7625 gtk_widget_set_name (GtkWidget *widget,
7628 GtkWidgetPrivate *priv;
7631 g_return_if_fail (GTK_IS_WIDGET (widget));
7633 priv = widget->priv;
7635 new_name = g_strdup (name);
7636 g_free (priv->name);
7637 priv->name = new_name;
7639 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_NAME);
7641 g_object_notify (G_OBJECT (widget), "name");
7645 * gtk_widget_get_name:
7646 * @widget: a #GtkWidget
7648 * Retrieves the name of a widget. See gtk_widget_set_name() for the
7649 * significance of widget names.
7651 * Return value: name of the widget. This string is owned by GTK+ and
7652 * should not be modified or freed
7655 gtk_widget_get_name (GtkWidget *widget)
7657 GtkWidgetPrivate *priv;
7659 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7661 priv = widget->priv;
7665 return G_OBJECT_TYPE_NAME (widget);
7669 gtk_widget_update_state_flags (GtkWidget *widget,
7670 GtkStateFlags flags_to_set,
7671 GtkStateFlags flags_to_unset)
7673 GtkWidgetPrivate *priv;
7675 priv = widget->priv;
7677 /* Handle insensitive first, since it is propagated
7678 * differently throughout the widget hierarchy.
7680 if ((priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_unset & GTK_STATE_FLAG_INSENSITIVE))
7681 gtk_widget_set_sensitive (widget, TRUE);
7682 else if (!(priv->state_flags & GTK_STATE_FLAG_INSENSITIVE) && (flags_to_set & GTK_STATE_FLAG_INSENSITIVE))
7683 gtk_widget_set_sensitive (widget, FALSE);
7685 flags_to_set &= ~(GTK_STATE_FLAG_INSENSITIVE);
7686 flags_to_unset &= ~(GTK_STATE_FLAG_INSENSITIVE);
7688 if (flags_to_set != 0 || flags_to_unset != 0)
7692 data.flags_to_set = flags_to_set;
7693 data.flags_to_unset = flags_to_unset;
7695 gtk_widget_propagate_state (widget, &data);
7700 * gtk_widget_set_state_flags:
7701 * @widget: a #GtkWidget
7702 * @flags: State flags to turn on
7703 * @clear: Whether to clear state before turning on @flags
7705 * This function is for use in widget implementations. Turns on flag
7706 * values in the current widget state (insensitive, prelighted, etc.).
7708 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
7709 * will be propagated down to all non-internal children if @widget is a
7710 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
7711 * down to all #GtkContainer children by different means than turning on the
7712 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
7713 * gtk_widget_is_sensitive() will make use of these.
7718 gtk_widget_set_state_flags (GtkWidget *widget,
7719 GtkStateFlags flags,
7722 g_return_if_fail (GTK_IS_WIDGET (widget));
7724 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
7725 (clear && widget->priv->state_flags == flags))
7729 gtk_widget_update_state_flags (widget, flags, ~(flags ^ (GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL)));
7731 gtk_widget_update_state_flags (widget, flags, 0);
7735 * gtk_widget_unset_state_flags:
7736 * @widget: a #GtkWidget
7737 * @flags: State flags to turn off
7739 * This function is for use in widget implementations. Turns off flag
7740 * values for the current widget state (insensitive, prelighted, etc.).
7741 * See gtk_widget_set_state_flags().
7746 gtk_widget_unset_state_flags (GtkWidget *widget,
7747 GtkStateFlags flags)
7749 g_return_if_fail (GTK_IS_WIDGET (widget));
7751 if ((widget->priv->state_flags & flags) == 0)
7754 gtk_widget_update_state_flags (widget, 0, flags);
7758 * gtk_widget_get_state_flags:
7759 * @widget: a #GtkWidget
7761 * Returns the widget state as a flag set. It is worth mentioning
7762 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
7763 * returned, that is, also based on parent insensitivity, even if
7764 * @widget itself is sensitive.
7766 * Returns: The state flags for widget
7771 gtk_widget_get_state_flags (GtkWidget *widget)
7773 GtkStateFlags flags;
7775 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
7777 flags = widget->priv->state_flags;
7779 if (gtk_widget_has_focus (widget))
7780 flags |= GTK_STATE_FLAG_FOCUSED;
7786 * gtk_widget_set_state:
7787 * @widget: a #GtkWidget
7788 * @state: new state for @widget
7790 * This function is for use in widget implementations. Sets the state
7791 * of a widget (insensitive, prelighted, etc.) Usually you should set
7792 * the state using wrapper functions such as gtk_widget_set_sensitive().
7794 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
7797 gtk_widget_set_state (GtkWidget *widget,
7800 GtkStateFlags flags;
7802 if (state == gtk_widget_get_state (widget))
7807 case GTK_STATE_ACTIVE:
7808 flags = GTK_STATE_FLAG_ACTIVE;
7810 case GTK_STATE_PRELIGHT:
7811 flags = GTK_STATE_FLAG_PRELIGHT;
7813 case GTK_STATE_SELECTED:
7814 flags = GTK_STATE_FLAG_SELECTED;
7816 case GTK_STATE_INSENSITIVE:
7817 flags = GTK_STATE_FLAG_INSENSITIVE;
7819 case GTK_STATE_INCONSISTENT:
7820 flags = GTK_STATE_FLAG_INCONSISTENT;
7822 case GTK_STATE_FOCUSED:
7823 flags = GTK_STATE_FLAG_FOCUSED;
7825 case GTK_STATE_NORMAL:
7831 gtk_widget_update_state_flags (widget,
7833 (GTK_STATE_FLAG_ACTIVE | GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_SELECTED
7834 | GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_INCONSISTENT | GTK_STATE_FLAG_FOCUSED) ^ flags);
7838 * gtk_widget_get_state:
7839 * @widget: a #GtkWidget
7841 * Returns the widget's state. See gtk_widget_set_state().
7843 * Returns: the state of @widget.
7847 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
7850 gtk_widget_get_state (GtkWidget *widget)
7852 GtkStateFlags flags;
7854 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
7856 flags = gtk_widget_get_state_flags (widget);
7858 if (flags & GTK_STATE_FLAG_INSENSITIVE)
7859 return GTK_STATE_INSENSITIVE;
7860 else if (flags & GTK_STATE_FLAG_ACTIVE)
7861 return GTK_STATE_ACTIVE;
7862 else if (flags & GTK_STATE_FLAG_SELECTED)
7863 return GTK_STATE_SELECTED;
7864 else if (flags & GTK_STATE_FLAG_PRELIGHT)
7865 return GTK_STATE_PRELIGHT;
7867 return GTK_STATE_NORMAL;
7871 * gtk_widget_set_visible:
7872 * @widget: a #GtkWidget
7873 * @visible: whether the widget should be shown or not
7875 * Sets the visibility state of @widget. Note that setting this to
7876 * %TRUE doesn't mean the widget is actually viewable, see
7877 * gtk_widget_get_visible().
7879 * This function simply calls gtk_widget_show() or gtk_widget_hide()
7880 * but is nicer to use when the visibility of the widget depends on
7886 gtk_widget_set_visible (GtkWidget *widget,
7889 g_return_if_fail (GTK_IS_WIDGET (widget));
7891 if (visible != gtk_widget_get_visible (widget))
7894 gtk_widget_show (widget);
7896 gtk_widget_hide (widget);
7901 _gtk_widget_set_visible_flag (GtkWidget *widget,
7904 GtkWidgetPrivate *priv = widget->priv;
7906 priv->visible = visible;
7910 priv->allocation.x = -1;
7911 priv->allocation.y = -1;
7912 priv->allocation.width = 1;
7913 priv->allocation.height = 1;
7918 * gtk_widget_get_visible:
7919 * @widget: a #GtkWidget
7921 * Determines whether the widget is visible. If you want to
7922 * take into account whether the widget's parent is also marked as
7923 * visible, use gtk_widget_is_visible() instead.
7925 * This function does not check if the widget is obscured in any way.
7927 * See gtk_widget_set_visible().
7929 * Return value: %TRUE if the widget is visible
7934 gtk_widget_get_visible (GtkWidget *widget)
7936 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7938 return widget->priv->visible;
7942 * gtk_widget_is_visible:
7943 * @widget: a #GtkWidget
7945 * Determines whether the widget and all its parents are marked as
7948 * This function does not check if the widget is obscured in any way.
7950 * See also gtk_widget_get_visible() and gtk_widget_set_visible()
7952 * Return value: %TRUE if the widget and all its parents are visible
7957 gtk_widget_is_visible (GtkWidget *widget)
7959 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7963 GtkWidgetPrivate *priv = widget->priv;
7968 widget = priv->parent;
7975 * gtk_widget_set_has_window:
7976 * @widget: a #GtkWidget
7977 * @has_window: whether or not @widget has a window.
7979 * Specifies whether @widget has a #GdkWindow of its own. Note that
7980 * all realized widgets have a non-%NULL "window" pointer
7981 * (gtk_widget_get_window() never returns a %NULL window when a widget
7982 * is realized), but for many of them it's actually the #GdkWindow of
7983 * one of its parent widgets. Widgets that do not create a %window for
7984 * themselves in #GtkWidget::realize must announce this by
7985 * calling this function with @has_window = %FALSE.
7987 * This function should only be called by widget implementations,
7988 * and they should call it in their init() function.
7993 gtk_widget_set_has_window (GtkWidget *widget,
7994 gboolean has_window)
7996 g_return_if_fail (GTK_IS_WIDGET (widget));
7998 widget->priv->no_window = !has_window;
8002 * gtk_widget_get_has_window:
8003 * @widget: a #GtkWidget
8005 * Determines whether @widget has a #GdkWindow of its own. See
8006 * gtk_widget_set_has_window().
8008 * Return value: %TRUE if @widget has a window, %FALSE otherwise
8013 gtk_widget_get_has_window (GtkWidget *widget)
8015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8017 return ! widget->priv->no_window;
8021 * gtk_widget_is_toplevel:
8022 * @widget: a #GtkWidget
8024 * Determines whether @widget is a toplevel widget.
8026 * Currently only #GtkWindow and #GtkInvisible (and out-of-process
8027 * #GtkPlugs) are toplevel widgets. Toplevel widgets have no parent
8030 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
8035 gtk_widget_is_toplevel (GtkWidget *widget)
8037 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8039 return widget->priv->toplevel;
8043 _gtk_widget_set_is_toplevel (GtkWidget *widget,
8044 gboolean is_toplevel)
8046 widget->priv->toplevel = is_toplevel;
8050 * gtk_widget_is_drawable:
8051 * @widget: a #GtkWidget
8053 * Determines whether @widget can be drawn to. A widget can be drawn
8054 * to if it is mapped and visible.
8056 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
8061 gtk_widget_is_drawable (GtkWidget *widget)
8063 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8065 return (gtk_widget_get_visible (widget) &&
8066 gtk_widget_get_mapped (widget));
8070 * gtk_widget_get_realized:
8071 * @widget: a #GtkWidget
8073 * Determines whether @widget is realized.
8075 * Return value: %TRUE if @widget is realized, %FALSE otherwise
8080 gtk_widget_get_realized (GtkWidget *widget)
8082 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8084 return widget->priv->realized;
8088 * gtk_widget_set_realized:
8089 * @widget: a #GtkWidget
8090 * @realized: %TRUE to mark the widget as realized
8092 * Marks the widget as being realized.
8094 * This function should only ever be called in a derived widget's
8095 * "realize" or "unrealize" implementation.
8100 gtk_widget_set_realized (GtkWidget *widget,
8103 g_return_if_fail (GTK_IS_WIDGET (widget));
8105 widget->priv->realized = realized;
8109 * gtk_widget_get_mapped:
8110 * @widget: a #GtkWidget
8112 * Whether the widget is mapped.
8114 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
8119 gtk_widget_get_mapped (GtkWidget *widget)
8121 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8123 return widget->priv->mapped;
8127 * gtk_widget_set_mapped:
8128 * @widget: a #GtkWidget
8129 * @mapped: %TRUE to mark the widget as mapped
8131 * Marks the widget as being realized.
8133 * This function should only ever be called in a derived widget's
8134 * "map" or "unmap" implementation.
8139 gtk_widget_set_mapped (GtkWidget *widget,
8142 g_return_if_fail (GTK_IS_WIDGET (widget));
8144 widget->priv->mapped = mapped;
8148 * gtk_widget_set_app_paintable:
8149 * @widget: a #GtkWidget
8150 * @app_paintable: %TRUE if the application will paint on the widget
8152 * Sets whether the application intends to draw on the widget in
8153 * an #GtkWidget::draw handler.
8155 * This is a hint to the widget and does not affect the behavior of
8156 * the GTK+ core; many widgets ignore this flag entirely. For widgets
8157 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
8158 * the effect is to suppress default themed drawing of the widget's
8159 * background. (Children of the widget will still be drawn.) The application
8160 * is then entirely responsible for drawing the widget background.
8162 * Note that the background is still drawn when the widget is mapped.
8165 gtk_widget_set_app_paintable (GtkWidget *widget,
8166 gboolean app_paintable)
8168 g_return_if_fail (GTK_IS_WIDGET (widget));
8170 app_paintable = (app_paintable != FALSE);
8172 if (widget->priv->app_paintable != app_paintable)
8174 widget->priv->app_paintable = app_paintable;
8176 if (gtk_widget_is_drawable (widget))
8177 gtk_widget_queue_draw (widget);
8179 g_object_notify (G_OBJECT (widget), "app-paintable");
8184 * gtk_widget_get_app_paintable:
8185 * @widget: a #GtkWidget
8187 * Determines whether the application intends to draw on the widget in
8188 * an #GtkWidget::draw handler.
8190 * See gtk_widget_set_app_paintable()
8192 * Return value: %TRUE if the widget is app paintable
8197 gtk_widget_get_app_paintable (GtkWidget *widget)
8199 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8201 return widget->priv->app_paintable;
8205 * gtk_widget_set_double_buffered:
8206 * @widget: a #GtkWidget
8207 * @double_buffered: %TRUE to double-buffer a widget
8209 * Widgets are double buffered by default; you can use this function
8210 * to turn off the buffering. "Double buffered" simply means that
8211 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
8212 * automatically around expose events sent to the
8213 * widget. gdk_window_begin_paint_region() diverts all drawing to a widget's
8214 * window to an offscreen buffer, and gdk_window_end_paint() draws the
8215 * buffer to the screen. The result is that users see the window
8216 * update in one smooth step, and don't see individual graphics
8217 * primitives being rendered.
8219 * In very simple terms, double buffered widgets don't flicker,
8220 * so you would only use this function to turn off double buffering
8221 * if you had special needs and really knew what you were doing.
8223 * Note: if you turn off double-buffering, you have to handle
8224 * expose events, since even the clearing to the background color or
8225 * pixmap will not happen automatically (as it is done in
8226 * gdk_window_begin_paint_region()).
8229 gtk_widget_set_double_buffered (GtkWidget *widget,
8230 gboolean double_buffered)
8232 g_return_if_fail (GTK_IS_WIDGET (widget));
8234 double_buffered = (double_buffered != FALSE);
8236 if (widget->priv->double_buffered != double_buffered)
8238 widget->priv->double_buffered = double_buffered;
8240 g_object_notify (G_OBJECT (widget), "double-buffered");
8245 * gtk_widget_get_double_buffered:
8246 * @widget: a #GtkWidget
8248 * Determines whether the widget is double buffered.
8250 * See gtk_widget_set_double_buffered()
8252 * Return value: %TRUE if the widget is double buffered
8257 gtk_widget_get_double_buffered (GtkWidget *widget)
8259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8261 return widget->priv->double_buffered;
8265 * gtk_widget_set_redraw_on_allocate:
8266 * @widget: a #GtkWidget
8267 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
8268 * when it is allocated to a new size. Otherwise, only the
8269 * new portion of the widget will be redrawn.
8271 * Sets whether the entire widget is queued for drawing when its size
8272 * allocation changes. By default, this setting is %TRUE and
8273 * the entire widget is redrawn on every size change. If your widget
8274 * leaves the upper left unchanged when made bigger, turning this
8275 * setting off will improve performance.
8277 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
8278 * off all allocation on resizing: the widget will not even redraw if
8279 * its position changes; this is to allow containers that don't draw
8280 * anything to avoid excess invalidations. If you set this flag on a
8281 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
8282 * you are responsible for invalidating both the old and new allocation
8283 * of the widget when the widget is moved and responsible for invalidating
8284 * regions newly when the widget increases size.
8287 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
8288 gboolean redraw_on_allocate)
8290 g_return_if_fail (GTK_IS_WIDGET (widget));
8292 widget->priv->redraw_on_alloc = redraw_on_allocate;
8296 * gtk_widget_set_sensitive:
8297 * @widget: a #GtkWidget
8298 * @sensitive: %TRUE to make the widget sensitive
8300 * Sets the sensitivity of a widget. A widget is sensitive if the user
8301 * can interact with it. Insensitive widgets are "grayed out" and the
8302 * user can't interact with them. Insensitive widgets are known as
8303 * "inactive", "disabled", or "ghosted" in some other toolkits.
8306 gtk_widget_set_sensitive (GtkWidget *widget,
8309 GtkWidgetPrivate *priv;
8311 g_return_if_fail (GTK_IS_WIDGET (widget));
8313 priv = widget->priv;
8315 sensitive = (sensitive != FALSE);
8317 if (priv->sensitive == sensitive)
8320 priv->sensitive = sensitive;
8322 if (priv->parent == NULL
8323 || gtk_widget_is_sensitive (priv->parent))
8329 data.flags_to_set = 0;
8330 data.flags_to_unset = GTK_STATE_FLAG_INSENSITIVE;
8334 data.flags_to_set = GTK_STATE_FLAG_INSENSITIVE;
8335 data.flags_to_unset = 0;
8338 gtk_widget_propagate_state (widget, &data);
8340 gtk_widget_queue_resize (widget);
8343 g_object_notify (G_OBJECT (widget), "sensitive");
8347 * gtk_widget_get_sensitive:
8348 * @widget: a #GtkWidget
8350 * Returns the widget's sensitivity (in the sense of returning
8351 * the value that has been set using gtk_widget_set_sensitive()).
8353 * The effective sensitivity of a widget is however determined by both its
8354 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
8356 * Returns: %TRUE if the widget is sensitive
8361 gtk_widget_get_sensitive (GtkWidget *widget)
8363 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8365 return widget->priv->sensitive;
8369 * gtk_widget_is_sensitive:
8370 * @widget: a #GtkWidget
8372 * Returns the widget's effective sensitivity, which means
8373 * it is sensitive itself and also its parent widget is sensitive
8375 * Returns: %TRUE if the widget is effectively sensitive
8380 gtk_widget_is_sensitive (GtkWidget *widget)
8382 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8384 return !(widget->priv->state_flags & GTK_STATE_FLAG_INSENSITIVE);
8388 * gtk_widget_set_parent:
8389 * @widget: a #GtkWidget
8390 * @parent: parent container
8392 * This function is useful only when implementing subclasses of
8394 * Sets the container as the parent of @widget, and takes care of
8395 * some details such as updating the state and style of the child
8396 * to reflect its new location. The opposite function is
8397 * gtk_widget_unparent().
8400 gtk_widget_set_parent (GtkWidget *widget,
8403 GtkStateFlags parent_flags;
8404 GtkWidgetPrivate *priv;
8407 g_return_if_fail (GTK_IS_WIDGET (widget));
8408 g_return_if_fail (GTK_IS_WIDGET (parent));
8409 g_return_if_fail (widget != parent);
8411 priv = widget->priv;
8413 if (priv->parent != NULL)
8415 g_warning ("Can't set a parent on widget which has a parent\n");
8418 if (gtk_widget_is_toplevel (widget))
8420 g_warning ("Can't set a parent on a toplevel widget\n");
8424 /* keep this function in sync with gtk_menu_attach_to_widget()
8427 g_object_ref_sink (widget);
8429 gtk_widget_push_verify_invariants (widget);
8431 priv->parent = parent;
8433 parent_flags = gtk_widget_get_state_flags (parent);
8435 /* Merge both old state and current parent state,
8436 * making sure to only propagate the right states */
8437 data.flags_to_set = parent_flags & GTK_STATE_FLAGS_DO_PROPAGATE;
8438 data.flags_to_unset = 0;
8439 gtk_widget_propagate_state (widget, &data);
8442 gtk_style_context_set_parent (priv->context,
8443 gtk_widget_get_style_context (parent));
8445 _gtk_widget_update_parent_muxer (widget);
8447 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
8448 if (priv->parent->priv->anchored)
8449 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
8450 g_object_notify (G_OBJECT (widget), "parent");
8452 /* Enforce realized/mapped invariants
8454 if (gtk_widget_get_realized (priv->parent))
8455 gtk_widget_realize (widget);
8457 if (gtk_widget_get_visible (priv->parent) &&
8458 gtk_widget_get_visible (widget))
8460 if (gtk_widget_get_child_visible (widget) &&
8461 gtk_widget_get_mapped (priv->parent))
8462 gtk_widget_map (widget);
8464 gtk_widget_queue_resize (widget);
8467 /* child may cause parent's expand to change, if the child is
8468 * expanded. If child is not expanded, then it can't modify the
8469 * parent's expand. If the child becomes expanded later then it will
8470 * queue compute_expand then. This optimization plus defaulting
8471 * newly-constructed widgets to need_compute_expand=FALSE should
8472 * mean that initially building a widget tree doesn't have to keep
8473 * walking up setting need_compute_expand on parents over and over.
8475 * We can't change a parent to need to expand unless we're visible.
8477 if (gtk_widget_get_visible (widget) &&
8478 (priv->need_compute_expand ||
8479 priv->computed_hexpand ||
8480 priv->computed_vexpand))
8482 gtk_widget_queue_compute_expand (parent);
8485 gtk_widget_propagate_alpha (widget);
8487 gtk_widget_pop_verify_invariants (widget);
8491 * gtk_widget_get_parent:
8492 * @widget: a #GtkWidget
8494 * Returns the parent container of @widget.
8496 * Return value: (transfer none): the parent container of @widget, or %NULL
8499 gtk_widget_get_parent (GtkWidget *widget)
8501 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8503 return widget->priv->parent;
8507 modifier_style_changed (GtkModifierStyle *style,
8510 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8513 static GtkModifierStyle *
8514 _gtk_widget_get_modifier_properties (GtkWidget *widget)
8516 GtkModifierStyle *style;
8518 style = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
8520 if (G_UNLIKELY (!style))
8522 GtkStyleContext *context;
8524 style = _gtk_modifier_style_new ();
8525 g_object_set_qdata_full (G_OBJECT (widget),
8526 quark_modifier_style,
8528 (GDestroyNotify) g_object_unref);
8530 g_signal_connect (style, "changed",
8531 G_CALLBACK (modifier_style_changed), widget);
8533 context = gtk_widget_get_style_context (widget);
8535 gtk_style_context_add_provider (context,
8536 GTK_STYLE_PROVIDER (style),
8537 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
8544 * gtk_widget_override_color:
8545 * @widget: a #GtkWidget
8546 * @state: the state for which to set the color
8547 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8548 * of previous calls to gtk_widget_override_color()
8550 * Sets the color to use for a widget.
8552 * All other style values are left untouched.
8555 * This API is mostly meant as a quick way for applications to
8556 * change a widget appearance. If you are developing a widgets
8557 * library and intend this change to be themeable, it is better
8558 * done by setting meaningful CSS classes and regions in your
8559 * widget/container implementation through gtk_style_context_add_class()
8560 * and gtk_style_context_add_region().
8562 * This way, your widget library can install a #GtkCssProvider
8563 * with the %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order
8564 * to provide a default styling for those widgets that need so, and
8565 * this theming may fully overridden by the user's theme.
8568 * Note that for complex widgets this may bring in undesired
8569 * results (such as uniform background color everywhere), in
8570 * these cases it is better to fully style such widgets through a
8571 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
8578 gtk_widget_override_color (GtkWidget *widget,
8579 GtkStateFlags state,
8580 const GdkRGBA *color)
8582 GtkModifierStyle *style;
8584 g_return_if_fail (GTK_IS_WIDGET (widget));
8586 style = _gtk_widget_get_modifier_properties (widget);
8587 _gtk_modifier_style_set_color (style, state, color);
8591 * gtk_widget_override_background_color:
8592 * @widget: a #GtkWidget
8593 * @state: the state for which to set the background color
8594 * @color: (allow-none): the color to assign, or %NULL to undo the effect
8595 * of previous calls to gtk_widget_override_background_color()
8597 * Sets the background color to use for a widget.
8599 * All other style values are left untouched.
8600 * See gtk_widget_override_color().
8605 gtk_widget_override_background_color (GtkWidget *widget,
8606 GtkStateFlags state,
8607 const GdkRGBA *color)
8609 GtkModifierStyle *style;
8611 g_return_if_fail (GTK_IS_WIDGET (widget));
8613 style = _gtk_widget_get_modifier_properties (widget);
8614 _gtk_modifier_style_set_background_color (style, state, color);
8618 * gtk_widget_override_font:
8619 * @widget: a #GtkWidget
8620 * @font_desc: (allow-none): the font descriptiong to use, or %NULL to undo
8621 * the effect of previous calls to gtk_widget_override_font()
8623 * Sets the font to use for a widget. All other style values are
8624 * left untouched. See gtk_widget_override_color().
8629 gtk_widget_override_font (GtkWidget *widget,
8630 const PangoFontDescription *font_desc)
8632 GtkModifierStyle *style;
8634 g_return_if_fail (GTK_IS_WIDGET (widget));
8636 style = _gtk_widget_get_modifier_properties (widget);
8637 _gtk_modifier_style_set_font (style, font_desc);
8641 * gtk_widget_override_symbolic_color:
8642 * @widget: a #GtkWidget
8643 * @name: the name of the symbolic color to modify
8644 * @color: (allow-none): the color to assign (does not need
8645 * to be allocated), or %NULL to undo the effect of previous
8646 * calls to gtk_widget_override_symbolic_color()
8648 * Sets a symbolic color for a widget.
8650 * All other style values are left untouched.
8651 * See gtk_widget_override_color() for overriding the foreground
8652 * or background color.
8657 gtk_widget_override_symbolic_color (GtkWidget *widget,
8659 const GdkRGBA *color)
8661 GtkModifierStyle *style;
8663 g_return_if_fail (GTK_IS_WIDGET (widget));
8665 style = _gtk_widget_get_modifier_properties (widget);
8666 _gtk_modifier_style_map_color (style, name, color);
8670 * gtk_widget_override_cursor:
8671 * @widget: a #GtkWidget
8672 * @cursor: (allow-none): the color to use for primary cursor (does not need to be
8673 * allocated), or %NULL to undo the effect of previous calls to
8674 * of gtk_widget_override_cursor().
8675 * @secondary_cursor: (allow-none): the color to use for secondary cursor (does not
8676 * need to be allocated), or %NULL to undo the effect of previous
8677 * calls to of gtk_widget_override_cursor().
8679 * Sets the cursor color to use in a widget, overriding the
8680 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8681 * style properties. All other style values are left untouched.
8682 * See also gtk_widget_modify_style().
8684 * Note that the underlying properties have the #GdkColor type,
8685 * so the alpha value in @primary and @secondary will be ignored.
8690 gtk_widget_override_cursor (GtkWidget *widget,
8691 const GdkRGBA *cursor,
8692 const GdkRGBA *secondary_cursor)
8694 GtkModifierStyle *style;
8696 g_return_if_fail (GTK_IS_WIDGET (widget));
8698 style = _gtk_widget_get_modifier_properties (widget);
8699 _gtk_modifier_style_set_color_property (style,
8701 "cursor-color", cursor);
8702 _gtk_modifier_style_set_color_property (style,
8704 "secondary-cursor-color",
8709 gtk_widget_real_direction_changed (GtkWidget *widget,
8710 GtkTextDirection previous_direction)
8712 gtk_widget_queue_resize (widget);
8716 gtk_widget_real_style_set (GtkWidget *widget,
8717 GtkStyle *previous_style)
8722 GtkWidget *previous_toplevel;
8723 GdkScreen *previous_screen;
8724 GdkScreen *new_screen;
8725 } HierarchyChangedInfo;
8728 do_screen_change (GtkWidget *widget,
8729 GdkScreen *old_screen,
8730 GdkScreen *new_screen)
8732 if (old_screen != new_screen)
8734 GtkWidgetPrivate *priv = widget->priv;
8738 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8740 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8743 _gtk_tooltip_hide (widget);
8745 if (new_screen && priv->context)
8746 gtk_style_context_set_screen (priv->context, new_screen);
8748 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8753 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8754 gpointer client_data)
8756 GtkWidgetPrivate *priv = widget->priv;
8757 HierarchyChangedInfo *info = client_data;
8758 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8759 (priv->parent && priv->parent->priv->anchored);
8761 if (priv->anchored != new_anchored)
8763 g_object_ref (widget);
8765 priv->anchored = new_anchored;
8767 /* This can only happen with gtk_widget_reparent() */
8771 gtk_widget_connect_frame_clock (widget,
8772 gtk_widget_get_frame_clock (widget));
8774 gtk_widget_disconnect_frame_clock (widget,
8775 gtk_widget_get_frame_clock (info->previous_toplevel));
8778 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8779 do_screen_change (widget, info->previous_screen, info->new_screen);
8781 if (GTK_IS_CONTAINER (widget))
8782 gtk_container_forall (GTK_CONTAINER (widget),
8783 gtk_widget_propagate_hierarchy_changed_recurse,
8786 g_object_unref (widget);
8791 * _gtk_widget_propagate_hierarchy_changed:
8792 * @widget: a #GtkWidget
8793 * @previous_toplevel: Previous toplevel
8795 * Propagates changes in the anchored state to a widget and all
8796 * children, unsetting or setting the %ANCHORED flag, and
8797 * emitting #GtkWidget::hierarchy-changed.
8800 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8801 GtkWidget *previous_toplevel)
8803 GtkWidgetPrivate *priv = widget->priv;
8804 HierarchyChangedInfo info;
8806 info.previous_toplevel = previous_toplevel;
8807 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8809 if (gtk_widget_is_toplevel (widget) ||
8810 (priv->parent && priv->parent->priv->anchored))
8811 info.new_screen = gtk_widget_get_screen (widget);
8813 info.new_screen = NULL;
8815 if (info.previous_screen)
8816 g_object_ref (info.previous_screen);
8817 if (previous_toplevel)
8818 g_object_ref (previous_toplevel);
8820 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8822 if (previous_toplevel)
8823 g_object_unref (previous_toplevel);
8824 if (info.previous_screen)
8825 g_object_unref (info.previous_screen);
8829 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8830 gpointer client_data)
8832 HierarchyChangedInfo *info = client_data;
8834 g_object_ref (widget);
8836 do_screen_change (widget, info->previous_screen, info->new_screen);
8838 if (GTK_IS_CONTAINER (widget))
8839 gtk_container_forall (GTK_CONTAINER (widget),
8840 gtk_widget_propagate_screen_changed_recurse,
8843 g_object_unref (widget);
8847 * gtk_widget_is_composited:
8848 * @widget: a #GtkWidget
8850 * Whether @widget can rely on having its alpha channel
8851 * drawn correctly. On X11 this function returns whether a
8852 * compositing manager is running for @widget's screen.
8854 * Please note that the semantics of this call will change
8855 * in the future if used on a widget that has a composited
8856 * window in its hierarchy (as set by gdk_window_set_composited()).
8858 * Return value: %TRUE if the widget can rely on its alpha
8859 * channel being drawn correctly.
8864 gtk_widget_is_composited (GtkWidget *widget)
8868 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8870 screen = gtk_widget_get_screen (widget);
8872 return gdk_screen_is_composited (screen);
8876 propagate_composited_changed (GtkWidget *widget,
8879 if (GTK_IS_CONTAINER (widget))
8881 gtk_container_forall (GTK_CONTAINER (widget),
8882 propagate_composited_changed,
8886 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8890 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8892 propagate_composited_changed (widget, NULL);
8896 * _gtk_widget_propagate_screen_changed:
8897 * @widget: a #GtkWidget
8898 * @previous_screen: Previous screen
8900 * Propagates changes in the screen for a widget to all
8901 * children, emitting #GtkWidget::screen-changed.
8904 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8905 GdkScreen *previous_screen)
8907 HierarchyChangedInfo info;
8909 info.previous_screen = previous_screen;
8910 info.new_screen = gtk_widget_get_screen (widget);
8912 if (previous_screen)
8913 g_object_ref (previous_screen);
8915 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8917 if (previous_screen)
8918 g_object_unref (previous_screen);
8922 reset_style_recurse (GtkWidget *widget, gpointer data)
8924 _gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
8926 if (GTK_IS_CONTAINER (widget))
8927 gtk_container_forall (GTK_CONTAINER (widget),
8928 reset_style_recurse,
8933 * gtk_widget_reset_style:
8934 * @widget: a #GtkWidget
8936 * Updates the style context of @widget and all descendents
8937 * by updating its widget path. #GtkContainer<!-- -->s may want
8938 * to use this on a child when reordering it in a way that a different
8939 * style might apply to it. See also gtk_container_get_path_for_child().
8944 gtk_widget_reset_style (GtkWidget *widget)
8946 g_return_if_fail (GTK_IS_WIDGET (widget));
8948 reset_style_recurse (widget, NULL);
8950 g_list_foreach (widget->priv->attached_windows,
8951 (GFunc) reset_style_recurse, NULL);
8954 #ifdef G_ENABLE_DEBUG
8956 /* Verify invariants, see docs/widget_system.txt for notes on much of
8957 * this. Invariants may be temporarily broken while we're in the
8958 * process of updating state, of course, so you can only
8959 * verify_invariants() after a given operation is complete.
8960 * Use push/pop_verify_invariants to help with that.
8963 gtk_widget_verify_invariants (GtkWidget *widget)
8967 if (widget->priv->verifying_invariants_count > 0)
8970 parent = widget->priv->parent;
8972 if (widget->priv->mapped)
8974 /* Mapped implies ... */
8976 if (!widget->priv->realized)
8977 g_warning ("%s %p is mapped but not realized",
8978 G_OBJECT_TYPE_NAME (widget), widget);
8980 if (!widget->priv->visible)
8981 g_warning ("%s %p is mapped but not visible",
8982 G_OBJECT_TYPE_NAME (widget), widget);
8984 if (!widget->priv->toplevel)
8986 if (!widget->priv->child_visible)
8987 g_warning ("%s %p is mapped but not child_visible",
8988 G_OBJECT_TYPE_NAME (widget), widget);
8993 /* Not mapped implies... */
8996 /* This check makes sense for normal toplevels, but for
8997 * something like a toplevel that is embedded within a clutter
8998 * state, mapping may depend on external factors.
9000 if (widget->priv->toplevel)
9002 if (widget->priv->visible)
9003 g_warning ("%s %p toplevel is visible but not mapped",
9004 G_OBJECT_TYPE_NAME (widget), widget);
9009 /* Parent related checks aren't possible if parent has
9010 * verifying_invariants_count > 0 because parent needs to recurse
9011 * children first before the invariants will hold.
9013 if (parent == NULL || parent->priv->verifying_invariants_count == 0)
9016 parent->priv->realized)
9018 /* Parent realized implies... */
9021 /* This is in widget_system.txt but appears to fail
9022 * because there's no gtk_container_realize() that
9023 * realizes all children... instead we just lazily
9024 * wait for map to fix things up.
9026 if (!widget->priv->realized)
9027 g_warning ("%s %p is realized but child %s %p is not realized",
9028 G_OBJECT_TYPE_NAME (parent), parent,
9029 G_OBJECT_TYPE_NAME (widget), widget);
9032 else if (!widget->priv->toplevel)
9034 /* No parent or parent not realized on non-toplevel implies... */
9036 if (widget->priv->realized && !widget->priv->in_reparent)
9037 g_warning ("%s %p is not realized but child %s %p is realized",
9038 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9039 G_OBJECT_TYPE_NAME (widget), widget);
9043 parent->priv->mapped &&
9044 widget->priv->visible &&
9045 widget->priv->child_visible)
9047 /* Parent mapped and we are visible implies... */
9049 if (!widget->priv->mapped)
9050 g_warning ("%s %p is mapped but visible child %s %p is not mapped",
9051 G_OBJECT_TYPE_NAME (parent), parent,
9052 G_OBJECT_TYPE_NAME (widget), widget);
9054 else if (!widget->priv->toplevel)
9056 /* No parent or parent not mapped on non-toplevel implies... */
9058 if (widget->priv->mapped && !widget->priv->in_reparent)
9059 g_warning ("%s %p is mapped but visible=%d child_visible=%d parent %s %p mapped=%d",
9060 G_OBJECT_TYPE_NAME (widget), widget,
9061 widget->priv->visible,
9062 widget->priv->child_visible,
9063 parent ? G_OBJECT_TYPE_NAME (parent) : "no parent", parent,
9064 parent ? parent->priv->mapped : FALSE);
9068 if (!widget->priv->realized)
9070 /* Not realized implies... */
9073 /* widget_system.txt says these hold, but they don't. */
9074 if (widget->priv->alloc_needed)
9075 g_warning ("%s %p alloc needed but not realized",
9076 G_OBJECT_TYPE_NAME (widget), widget);
9078 if (widget->priv->width_request_needed)
9079 g_warning ("%s %p width request needed but not realized",
9080 G_OBJECT_TYPE_NAME (widget), widget);
9082 if (widget->priv->height_request_needed)
9083 g_warning ("%s %p height request needed but not realized",
9084 G_OBJECT_TYPE_NAME (widget), widget);
9089 /* The point of this push/pop is that invariants may not hold while
9090 * we're busy making changes. So we only check at the outermost call
9091 * on the call stack, after we finish updating everything.
9094 gtk_widget_push_verify_invariants (GtkWidget *widget)
9096 widget->priv->verifying_invariants_count += 1;
9100 gtk_widget_verify_child_invariants (GtkWidget *widget,
9101 gpointer client_data)
9103 /* We don't recurse further; this is a one-level check. */
9104 gtk_widget_verify_invariants (widget);
9108 gtk_widget_pop_verify_invariants (GtkWidget *widget)
9110 g_assert (widget->priv->verifying_invariants_count > 0);
9112 widget->priv->verifying_invariants_count -= 1;
9114 if (widget->priv->verifying_invariants_count == 0)
9116 gtk_widget_verify_invariants (widget);
9118 if (GTK_IS_CONTAINER (widget))
9120 /* Check one level of children, because our
9121 * push_verify_invariants() will have prevented some of the
9122 * checks. This does not recurse because if recursion is
9123 * needed, it will happen naturally as each child has a
9124 * push/pop on that child. For example if we're recursively
9125 * mapping children, we'll push/pop on each child as we map
9128 gtk_container_forall (GTK_CONTAINER (widget),
9129 gtk_widget_verify_child_invariants,
9134 #endif /* G_ENABLE_DEBUG */
9136 static PangoContext *
9137 gtk_widget_peek_pango_context (GtkWidget *widget)
9139 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9143 * gtk_widget_get_pango_context:
9144 * @widget: a #GtkWidget
9146 * Gets a #PangoContext with the appropriate font map, font description,
9147 * and base direction for this widget. Unlike the context returned
9148 * by gtk_widget_create_pango_context(), this context is owned by
9149 * the widget (it can be used until the screen for the widget changes
9150 * or the widget is removed from its toplevel), and will be updated to
9151 * match any changes to the widget's attributes. This can be tracked
9152 * by using the #GtkWidget::screen-changed signal on the widget.
9154 * Return value: (transfer none): the #PangoContext for the widget.
9157 gtk_widget_get_pango_context (GtkWidget *widget)
9159 PangoContext *context;
9161 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9163 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
9166 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
9167 g_object_set_qdata_full (G_OBJECT (widget),
9168 quark_pango_context,
9177 update_pango_context (GtkWidget *widget,
9178 PangoContext *context)
9180 PangoFontDescription *font_desc;
9181 GtkStyleContext *style_context;
9183 style_context = gtk_widget_get_style_context (widget);
9184 gtk_style_context_get (style_context,
9185 gtk_widget_get_state_flags (widget),
9189 pango_context_set_font_description (context, font_desc);
9190 pango_context_set_base_dir (context,
9191 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
9192 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
9194 pango_font_description_free (font_desc);
9198 gtk_widget_update_pango_context (GtkWidget *widget)
9200 PangoContext *context = gtk_widget_peek_pango_context (widget);
9206 update_pango_context (widget, context);
9208 screen = gtk_widget_get_screen_unchecked (widget);
9211 pango_cairo_context_set_resolution (context,
9212 gdk_screen_get_resolution (screen));
9213 pango_cairo_context_set_font_options (context,
9214 gdk_screen_get_font_options (screen));
9220 * gtk_widget_create_pango_context:
9221 * @widget: a #GtkWidget
9223 * Creates a new #PangoContext with the appropriate font map,
9224 * font description, and base direction for drawing text for
9225 * this widget. See also gtk_widget_get_pango_context().
9227 * Return value: (transfer full): the new #PangoContext
9230 gtk_widget_create_pango_context (GtkWidget *widget)
9233 PangoContext *context;
9235 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9237 screen = gtk_widget_get_screen_unchecked (widget);
9240 GTK_NOTE (MULTIHEAD,
9241 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
9243 screen = gdk_screen_get_default ();
9246 context = gdk_pango_context_get_for_screen (screen);
9248 update_pango_context (widget, context);
9249 pango_context_set_language (context, gtk_get_default_language ());
9255 * gtk_widget_create_pango_layout:
9256 * @widget: a #GtkWidget
9257 * @text: text to set on the layout (can be %NULL)
9259 * Creates a new #PangoLayout with the appropriate font map,
9260 * font description, and base direction for drawing text for
9263 * If you keep a #PangoLayout created in this way around, you need
9264 * to re-create it when the widget #PangoContext is replaced.
9265 * This can be tracked by using the #GtkWidget::screen-changed signal
9268 * Return value: (transfer full): the new #PangoLayout
9271 gtk_widget_create_pango_layout (GtkWidget *widget,
9274 PangoLayout *layout;
9275 PangoContext *context;
9277 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9279 context = gtk_widget_get_pango_context (widget);
9280 layout = pango_layout_new (context);
9283 pango_layout_set_text (layout, text, -1);
9289 * gtk_widget_render_icon_pixbuf:
9290 * @widget: a #GtkWidget
9291 * @stock_id: a stock ID
9292 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
9293 * render at the size of the source and don't scale (if there are
9294 * multiple source sizes, GTK+ picks one of the available sizes).
9296 * A convenience function that uses the theme engine and style
9297 * settings for @widget to look up @stock_id and render it to
9298 * a pixbuf. @stock_id should be a stock icon ID such as
9299 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
9300 * such as #GTK_ICON_SIZE_MENU.
9302 * The pixels in the returned #GdkPixbuf are shared with the rest of
9303 * the application and should not be modified. The pixbuf should be freed
9304 * after use with g_object_unref().
9306 * Return value: (transfer full): a new pixbuf, or %NULL if the
9307 * stock ID wasn't known
9312 gtk_widget_render_icon_pixbuf (GtkWidget *widget,
9313 const gchar *stock_id,
9316 GtkStyleContext *context;
9317 GtkIconSet *icon_set;
9319 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9320 g_return_val_if_fail (stock_id != NULL, NULL);
9321 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
9323 context = gtk_widget_get_style_context (widget);
9324 icon_set = gtk_style_context_lookup_icon_set (context, stock_id);
9326 if (icon_set == NULL)
9329 return gtk_icon_set_render_icon_pixbuf (icon_set, context, size);
9333 * gtk_widget_set_parent_window:
9334 * @widget: a #GtkWidget.
9335 * @parent_window: the new parent window.
9337 * Sets a non default parent window for @widget.
9339 * For GtkWindow classes, setting a @parent_window effects whether
9340 * the window is a toplevel window or can be embedded into other
9344 * For GtkWindow classes, this needs to be called before the
9345 * window is realized.
9350 gtk_widget_set_parent_window (GtkWidget *widget,
9351 GdkWindow *parent_window)
9353 GdkWindow *old_parent_window;
9355 g_return_if_fail (GTK_IS_WIDGET (widget));
9357 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
9358 quark_parent_window);
9360 if (parent_window != old_parent_window)
9364 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
9366 if (old_parent_window)
9367 g_object_unref (old_parent_window);
9369 g_object_ref (parent_window);
9371 /* Unset toplevel flag when adding a parent window to a widget,
9372 * this is the primary entry point to allow toplevels to be
9375 #ifdef GDK_WINDOWING_X11
9376 is_plug = GTK_IS_PLUG (widget);
9380 if (GTK_IS_WINDOW (widget) && !is_plug)
9381 _gtk_window_set_is_toplevel (GTK_WINDOW (widget), parent_window == NULL);
9386 * gtk_widget_get_parent_window:
9387 * @widget: a #GtkWidget.
9389 * Gets @widget's parent window.
9391 * Returns: (transfer none): the parent window of @widget.
9394 gtk_widget_get_parent_window (GtkWidget *widget)
9396 GtkWidgetPrivate *priv;
9397 GdkWindow *parent_window;
9399 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9401 priv = widget->priv;
9403 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
9405 return (parent_window != NULL) ? parent_window :
9406 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
9411 * gtk_widget_set_child_visible:
9412 * @widget: a #GtkWidget
9413 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
9415 * Sets whether @widget should be mapped along with its when its parent
9416 * is mapped and @widget has been shown with gtk_widget_show().
9418 * The child visibility can be set for widget before it is added to
9419 * a container with gtk_widget_set_parent(), to avoid mapping
9420 * children unnecessary before immediately unmapping them. However
9421 * it will be reset to its default state of %TRUE when the widget
9422 * is removed from a container.
9424 * Note that changing the child visibility of a widget does not
9425 * queue a resize on the widget. Most of the time, the size of
9426 * a widget is computed from all visible children, whether or
9427 * not they are mapped. If this is not the case, the container
9428 * can queue a resize itself.
9430 * This function is only useful for container implementations and
9431 * never should be called by an application.
9434 gtk_widget_set_child_visible (GtkWidget *widget,
9435 gboolean is_visible)
9437 GtkWidgetPrivate *priv;
9439 g_return_if_fail (GTK_IS_WIDGET (widget));
9440 g_return_if_fail (!gtk_widget_is_toplevel (widget));
9442 priv = widget->priv;
9444 g_object_ref (widget);
9445 gtk_widget_verify_invariants (widget);
9448 priv->child_visible = TRUE;
9451 GtkWidget *toplevel;
9453 priv->child_visible = FALSE;
9455 toplevel = gtk_widget_get_toplevel (widget);
9456 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
9457 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
9460 if (priv->parent && gtk_widget_get_realized (priv->parent))
9462 if (gtk_widget_get_mapped (priv->parent) &&
9463 priv->child_visible &&
9464 gtk_widget_get_visible (widget))
9465 gtk_widget_map (widget);
9467 gtk_widget_unmap (widget);
9470 gtk_widget_verify_invariants (widget);
9471 g_object_unref (widget);
9475 * gtk_widget_get_child_visible:
9476 * @widget: a #GtkWidget
9478 * Gets the value set with gtk_widget_set_child_visible().
9479 * If you feel a need to use this function, your code probably
9480 * needs reorganization.
9482 * This function is only useful for container implementations and
9483 * never should be called by an application.
9485 * Return value: %TRUE if the widget is mapped with the parent.
9488 gtk_widget_get_child_visible (GtkWidget *widget)
9490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9492 return widget->priv->child_visible;
9496 gtk_widget_get_screen_unchecked (GtkWidget *widget)
9498 GtkWidget *toplevel;
9500 toplevel = gtk_widget_get_toplevel (widget);
9502 if (gtk_widget_is_toplevel (toplevel))
9504 if (GTK_IS_WINDOW (toplevel))
9505 return gtk_window_get_screen (GTK_WINDOW (toplevel));
9506 else if (GTK_IS_INVISIBLE (toplevel))
9507 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
9514 * gtk_widget_get_screen:
9515 * @widget: a #GtkWidget
9517 * Get the #GdkScreen from the toplevel window associated with
9518 * this widget. This function can only be called after the widget
9519 * has been added to a widget hierarchy with a #GtkWindow
9522 * In general, you should only create screen specific
9523 * resources when a widget has been realized, and you should
9524 * free those resources when the widget is unrealized.
9526 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9531 gtk_widget_get_screen (GtkWidget *widget)
9535 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9537 screen = gtk_widget_get_screen_unchecked (widget);
9544 g_warning (G_STRLOC ": Can't get associated screen"
9545 " for a widget unless it is inside a toplevel GtkWindow\n"
9546 " widget type is %s associated top level type is %s",
9547 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9548 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9550 return gdk_screen_get_default ();
9555 * gtk_widget_has_screen:
9556 * @widget: a #GtkWidget
9558 * Checks whether there is a #GdkScreen is associated with
9559 * this widget. All toplevel widgets have an associated
9560 * screen, and all widgets added into a hierarchy with a toplevel
9561 * window at the top.
9563 * Return value: %TRUE if there is a #GdkScreen associcated
9569 gtk_widget_has_screen (GtkWidget *widget)
9571 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9573 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9577 * gtk_widget_get_display:
9578 * @widget: a #GtkWidget
9580 * Get the #GdkDisplay for the toplevel window associated with
9581 * this widget. This function can only be called after the widget
9582 * has been added to a widget hierarchy with a #GtkWindow at the top.
9584 * In general, you should only create display specific
9585 * resources when a widget has been realized, and you should
9586 * free those resources when the widget is unrealized.
9588 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9593 gtk_widget_get_display (GtkWidget *widget)
9595 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9597 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9601 * gtk_widget_get_root_window:
9602 * @widget: a #GtkWidget
9604 * Get the root window where this widget is located. This function can
9605 * only be called after the widget has been added to a widget
9606 * hierarchy with #GtkWindow at the top.
9608 * The root window is useful for such purposes as creating a popup
9609 * #GdkWindow associated with the window. In general, you should only
9610 * create display specific resources when a widget has been realized,
9611 * and you should free those resources when the widget is unrealized.
9613 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9618 gtk_widget_get_root_window (GtkWidget *widget)
9620 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9622 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9626 * gtk_widget_child_focus:
9627 * @widget: a #GtkWidget
9628 * @direction: direction of focus movement
9630 * This function is used by custom widget implementations; if you're
9631 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9632 * to a particular widget, and gtk_container_set_focus_chain() to
9633 * change the focus tab order. So you may want to investigate those
9634 * functions instead.
9636 * gtk_widget_child_focus() is called by containers as the user moves
9637 * around the window using keyboard shortcuts. @direction indicates
9638 * what kind of motion is taking place (up, down, left, right, tab
9639 * forward, tab backward). gtk_widget_child_focus() emits the
9640 * #GtkWidget::focus signal; widgets override the default handler
9641 * for this signal in order to implement appropriate focus behavior.
9643 * The default ::focus handler for a widget should return %TRUE if
9644 * moving in @direction left the focus on a focusable location inside
9645 * that widget, and %FALSE if moving in @direction moved the focus
9646 * outside the widget. If returning %TRUE, widgets normally
9647 * call gtk_widget_grab_focus() to place the focus accordingly;
9648 * if returning %FALSE, they don't modify the current focus location.
9650 * Return value: %TRUE if focus ended up inside @widget
9653 gtk_widget_child_focus (GtkWidget *widget,
9654 GtkDirectionType direction)
9656 gboolean return_val;
9658 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9660 if (!gtk_widget_get_visible (widget) ||
9661 !gtk_widget_is_sensitive (widget))
9664 /* child widgets must set CAN_FOCUS, containers
9665 * don't have to though.
9667 if (!GTK_IS_CONTAINER (widget) &&
9668 !gtk_widget_get_can_focus (widget))
9671 g_signal_emit (widget,
9672 widget_signals[FOCUS],
9674 direction, &return_val);
9680 * gtk_widget_keynav_failed:
9681 * @widget: a #GtkWidget
9682 * @direction: direction of focus movement
9684 * This function should be called whenever keyboard navigation within
9685 * a single widget hits a boundary. The function emits the
9686 * #GtkWidget::keynav-failed signal on the widget and its return
9687 * value should be interpreted in a way similar to the return value of
9688 * gtk_widget_child_focus():
9690 * When %TRUE is returned, stay in the widget, the failed keyboard
9691 * navigation is Ok and/or there is nowhere we can/should move the
9694 * When %FALSE is returned, the caller should continue with keyboard
9695 * navigation outside the widget, e.g. by calling
9696 * gtk_widget_child_focus() on the widget's toplevel.
9698 * The default ::keynav-failed handler returns %TRUE for
9699 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9700 * values of #GtkDirectionType, it looks at the
9701 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9702 * if the setting is %TRUE. This way the entire user interface
9703 * becomes cursor-navigatable on input devices such as mobile phones
9704 * which only have cursor keys but no tab key.
9706 * Whenever the default handler returns %TRUE, it also calls
9707 * gtk_widget_error_bell() to notify the user of the failed keyboard
9710 * A use case for providing an own implementation of ::keynav-failed
9711 * (either by connecting to it or by overriding it) would be a row of
9712 * #GtkEntry widgets where the user should be able to navigate the
9713 * entire row with the cursor keys, as e.g. known from user interfaces
9714 * that require entering license keys.
9716 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9717 * if the emitting widget should try to handle the keyboard
9718 * navigation attempt in its parent container(s).
9723 gtk_widget_keynav_failed (GtkWidget *widget,
9724 GtkDirectionType direction)
9726 gboolean return_val;
9728 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9730 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9731 direction, &return_val);
9737 * gtk_widget_error_bell:
9738 * @widget: a #GtkWidget
9740 * Notifies the user about an input-related error on this widget.
9741 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9742 * gdk_window_beep(), otherwise it does nothing.
9744 * Note that the effect of gdk_window_beep() can be configured in many
9745 * ways, depending on the windowing backend and the desktop environment
9746 * or window manager that is used.
9751 gtk_widget_error_bell (GtkWidget *widget)
9753 GtkWidgetPrivate *priv;
9754 GtkSettings* settings;
9757 g_return_if_fail (GTK_IS_WIDGET (widget));
9759 priv = widget->priv;
9761 settings = gtk_widget_get_settings (widget);
9765 g_object_get (settings,
9766 "gtk-error-bell", &beep,
9769 if (beep && priv->window)
9770 gdk_window_beep (priv->window);
9774 gtk_widget_set_usize_internal (GtkWidget *widget,
9777 GtkQueueResizeFlags flags)
9779 GtkWidgetAuxInfo *aux_info;
9780 gboolean changed = FALSE;
9782 g_object_freeze_notify (G_OBJECT (widget));
9784 aux_info = gtk_widget_get_aux_info (widget, TRUE);
9786 if (width > -2 && aux_info->width != width)
9788 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9789 g_object_notify (G_OBJECT (widget), "width-request");
9790 aux_info->width = width;
9793 if (height > -2 && aux_info->height != height)
9795 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9796 g_object_notify (G_OBJECT (widget), "height-request");
9797 aux_info->height = height;
9801 if (gtk_widget_get_visible (widget) && changed)
9803 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9804 gtk_widget_queue_resize (widget);
9806 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9809 g_object_thaw_notify (G_OBJECT (widget));
9813 * gtk_widget_set_size_request:
9814 * @widget: a #GtkWidget
9815 * @width: width @widget should request, or -1 to unset
9816 * @height: height @widget should request, or -1 to unset
9818 * Sets the minimum size of a widget; that is, the widget's size
9819 * request will be at least @width by @height. You can use this
9820 * function to force a widget to be larger than it normally would be.
9822 * In most cases, gtk_window_set_default_size() is a better choice for
9823 * toplevel windows than this function; setting the default size will
9824 * still allow users to shrink the window. Setting the size request
9825 * will force them to leave the window at least as large as the size
9826 * request. When dealing with window sizes,
9827 * gtk_window_set_geometry_hints() can be a useful function as well.
9829 * Note the inherent danger of setting any fixed size - themes,
9830 * translations into other languages, different fonts, and user action
9831 * can all change the appropriate size for a given widget. So, it's
9832 * basically impossible to hardcode a size that will always be
9835 * The size request of a widget is the smallest size a widget can
9836 * accept while still functioning well and drawing itself correctly.
9837 * However in some strange cases a widget may be allocated less than
9838 * its requested size, and in many cases a widget may be allocated more
9839 * space than it requested.
9841 * If the size request in a given direction is -1 (unset), then
9842 * the "natural" size request of the widget will be used instead.
9844 * The size request set here does not include any margin from the
9845 * #GtkWidget properties margin-left, margin-right, margin-top, and
9846 * margin-bottom, but it does include pretty much all other padding
9847 * or border properties set by any subclass of #GtkWidget.
9850 gtk_widget_set_size_request (GtkWidget *widget,
9854 g_return_if_fail (GTK_IS_WIDGET (widget));
9855 g_return_if_fail (width >= -1);
9856 g_return_if_fail (height >= -1);
9863 gtk_widget_set_usize_internal (widget, width, height, 0);
9868 * gtk_widget_get_size_request:
9869 * @widget: a #GtkWidget
9870 * @width: (out) (allow-none): return location for width, or %NULL
9871 * @height: (out) (allow-none): return location for height, or %NULL
9873 * Gets the size request that was explicitly set for the widget using
9874 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9875 * @height indicates that that dimension has not been set explicitly
9876 * and the natural requisition of the widget will be used intead. See
9877 * gtk_widget_set_size_request(). To get the size a widget will
9878 * actually request, call gtk_widget_get_preferred_size() instead of
9882 gtk_widget_get_size_request (GtkWidget *widget,
9886 const GtkWidgetAuxInfo *aux_info;
9888 g_return_if_fail (GTK_IS_WIDGET (widget));
9890 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9893 *width = aux_info->width;
9896 *height = aux_info->height;
9900 * _gtk_widget_override_size_request:
9901 * @widget: a #GtkWidget
9902 * @width: new forced minimum width
9903 * @height: new forced minimum height
9904 * @old_width: location to store previous forced minimum width
9905 * @old_height: location to store previous forced minumum height
9907 * Temporarily establishes a forced minimum size for a widget; this
9908 * is used by GtkWindow when calculating the size to add to the
9909 * window's geometry widget. Cached sizes for the widget and its
9910 * parents are invalidated, so that subsequent calls to the size
9911 * negotiation machinery produce the overriden result, but the
9912 * widget is not queued for relayout or redraw. The old size must
9913 * be restored with _gtk_widget_restore_size_request() or things
9917 _gtk_widget_override_size_request (GtkWidget *widget,
9923 gtk_widget_get_size_request (widget, old_width, old_height);
9924 gtk_widget_set_usize_internal (widget, width, height,
9925 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9929 * _gtk_widget_restore_size_request:
9930 * @widget: a #GtkWidget
9931 * @old_width: saved forced minimum size
9932 * @old_height: saved forced minimum size
9934 * Undoes the operation of_gtk_widget_override_size_request().
9937 _gtk_widget_restore_size_request (GtkWidget *widget,
9941 gtk_widget_set_usize_internal (widget, old_width, old_height,
9942 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9946 * gtk_widget_set_events:
9947 * @widget: a #GtkWidget
9948 * @events: event mask
9950 * Sets the event mask (see #GdkEventMask) for a widget. The event
9951 * mask determines which events a widget will receive. Keep in mind
9952 * that different widgets have different default event masks, and by
9953 * changing the event mask you may disrupt a widget's functionality,
9954 * so be careful. This function must be called while a widget is
9955 * unrealized. Consider gtk_widget_add_events() for widgets that are
9956 * already realized, or if you want to preserve the existing event
9957 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9958 * to get events on those widgets, place them inside a #GtkEventBox
9959 * and receive events on the event box.
9962 gtk_widget_set_events (GtkWidget *widget,
9965 g_return_if_fail (GTK_IS_WIDGET (widget));
9966 g_return_if_fail (!gtk_widget_get_realized (widget));
9968 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9969 GINT_TO_POINTER (events));
9970 g_object_notify (G_OBJECT (widget), "events");
9974 * gtk_widget_set_device_events:
9975 * @widget: a #GtkWidget
9976 * @device: a #GdkDevice
9977 * @events: event mask
9979 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9980 * mask determines which events a widget will receive from @device. Keep
9981 * in mind that different widgets have different default event masks, and by
9982 * changing the event mask you may disrupt a widget's functionality,
9983 * so be careful. This function must be called while a widget is
9984 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9985 * already realized, or if you want to preserve the existing event
9986 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9987 * to get events on those widgets, place them inside a #GtkEventBox
9988 * and receive events on the event box.
9993 gtk_widget_set_device_events (GtkWidget *widget,
9995 GdkEventMask events)
9997 GHashTable *device_events;
9999 g_return_if_fail (GTK_IS_WIDGET (widget));
10000 g_return_if_fail (GDK_IS_DEVICE (device));
10001 g_return_if_fail (!gtk_widget_get_realized (widget));
10003 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10005 if (G_UNLIKELY (!device_events))
10007 device_events = g_hash_table_new (NULL, NULL);
10008 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10009 (GDestroyNotify) g_hash_table_unref);
10012 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
10016 * gtk_widget_set_device_enabled:
10017 * @widget: a #GtkWidget
10018 * @device: a #GdkDevice
10019 * @enabled: whether to enable the device
10021 * Enables or disables a #GdkDevice to interact with @widget
10022 * and all its children.
10024 * It does so by descending through the #GdkWindow hierarchy
10025 * and enabling the same mask that is has for core events
10026 * (i.e. the one that gdk_window_get_events() returns).
10031 gtk_widget_set_device_enabled (GtkWidget *widget,
10035 GList *enabled_devices;
10037 g_return_if_fail (GTK_IS_WIDGET (widget));
10038 g_return_if_fail (GDK_IS_DEVICE (device));
10040 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10041 enabled_devices = g_list_append (enabled_devices, device);
10043 g_object_set_qdata_full (G_OBJECT (widget), quark_enabled_devices,
10044 enabled_devices, (GDestroyNotify) g_list_free);;
10046 if (gtk_widget_get_realized (widget))
10047 gtk_widget_set_device_enabled_internal (widget, device, TRUE, enabled);
10051 * gtk_widget_get_device_enabled:
10052 * @widget: a #GtkWidget
10053 * @device: a #GdkDevice
10055 * Returns whether @device can interact with @widget and its
10056 * children. See gtk_widget_set_device_enabled().
10058 * Return value: %TRUE is @device is enabled for @widget
10063 gtk_widget_get_device_enabled (GtkWidget *widget,
10066 GList *enabled_devices;
10068 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10069 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
10071 enabled_devices = g_object_get_qdata (G_OBJECT (widget), quark_enabled_devices);
10073 return g_list_find (enabled_devices, device) != NULL;
10077 gtk_widget_add_events_internal_list (GtkWidget *widget,
10080 GList *window_list)
10084 for (l = window_list; l != NULL; l = l->next)
10086 GdkWindow *window = l->data;
10087 gpointer user_data;
10089 gdk_window_get_user_data (window, &user_data);
10090 if (user_data == widget)
10095 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
10097 gdk_window_set_events (window, gdk_window_get_events (window) | events);
10099 children = gdk_window_get_children (window);
10100 gtk_widget_add_events_internal_list (widget, device, events, children);
10101 g_list_free (children);
10107 gtk_widget_add_events_internal (GtkWidget *widget,
10111 GtkWidgetPrivate *priv = widget->priv;
10112 GList *window_list;
10114 if (!gtk_widget_get_has_window (widget))
10115 window_list = gdk_window_get_children (priv->window);
10117 window_list = g_list_prepend (NULL, priv->window);
10119 gtk_widget_add_events_internal_list (widget, device, events, window_list);
10121 g_list_free (window_list);
10125 * gtk_widget_add_events:
10126 * @widget: a #GtkWidget
10127 * @events: an event mask, see #GdkEventMask
10129 * Adds the events in the bitfield @events to the event mask for
10130 * @widget. See gtk_widget_set_events() for details.
10133 gtk_widget_add_events (GtkWidget *widget,
10138 g_return_if_fail (GTK_IS_WIDGET (widget));
10140 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10141 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
10142 GINT_TO_POINTER (old_events | events));
10144 if (gtk_widget_get_realized (widget))
10146 gtk_widget_add_events_internal (widget, NULL, events);
10147 gtk_widget_update_devices_mask (widget, FALSE);
10150 g_object_notify (G_OBJECT (widget), "events");
10154 * gtk_widget_add_device_events:
10155 * @widget: a #GtkWidget
10156 * @device: a #GdkDevice
10157 * @events: an event mask, see #GdkEventMask
10159 * Adds the device events in the bitfield @events to the event mask for
10160 * @widget. See gtk_widget_set_device_events() for details.
10165 gtk_widget_add_device_events (GtkWidget *widget,
10167 GdkEventMask events)
10169 GdkEventMask old_events;
10170 GHashTable *device_events;
10172 g_return_if_fail (GTK_IS_WIDGET (widget));
10173 g_return_if_fail (GDK_IS_DEVICE (device));
10175 old_events = gtk_widget_get_device_events (widget, device);
10177 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10179 if (G_UNLIKELY (!device_events))
10181 device_events = g_hash_table_new (NULL, NULL);
10182 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
10183 (GDestroyNotify) g_hash_table_unref);
10186 g_hash_table_insert (device_events, device,
10187 GUINT_TO_POINTER (old_events | events));
10189 if (gtk_widget_get_realized (widget))
10190 gtk_widget_add_events_internal (widget, device, events);
10192 g_object_notify (G_OBJECT (widget), "events");
10196 * gtk_widget_get_toplevel:
10197 * @widget: a #GtkWidget
10199 * This function returns the topmost widget in the container hierarchy
10200 * @widget is a part of. If @widget has no parent widgets, it will be
10201 * returned as the topmost widget. No reference will be added to the
10202 * returned widget; it should not be unreferenced.
10204 * Note the difference in behavior vs. gtk_widget_get_ancestor();
10205 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
10207 * %NULL if @widget wasn't inside a toplevel window, and if the
10208 * window was inside a #GtkWindow<!-- -->-derived widget which was in turn
10209 * inside the toplevel #GtkWindow. While the second case may
10210 * seem unlikely, it actually happens when a #GtkPlug is embedded
10211 * inside a #GtkSocket within the same application.
10213 * To reliably find the toplevel #GtkWindow, use
10214 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
10215 * is set on the result.
10217 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
10218 * if (gtk_widget_is_toplevel (toplevel))
10220 * /* Perform action on toplevel. */
10224 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
10225 * if there's no ancestor.
10228 gtk_widget_get_toplevel (GtkWidget *widget)
10230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10232 while (widget->priv->parent)
10233 widget = widget->priv->parent;
10239 * gtk_widget_get_ancestor:
10240 * @widget: a #GtkWidget
10241 * @widget_type: ancestor type
10243 * Gets the first ancestor of @widget with type @widget_type. For example,
10244 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
10245 * the first #GtkBox that's an ancestor of @widget. No reference will be
10246 * added to the returned widget; it should not be unreferenced. See note
10247 * about checking for a toplevel #GtkWindow in the docs for
10248 * gtk_widget_get_toplevel().
10250 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
10251 * considers @widget to be an ancestor of itself.
10253 * Return value: (transfer none): the ancestor widget, or %NULL if not found
10256 gtk_widget_get_ancestor (GtkWidget *widget,
10259 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10261 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
10262 widget = widget->priv->parent;
10264 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
10271 * gtk_widget_set_visual:
10272 * @widget: a #GtkWidget
10273 * @visual: visual to be used or %NULL to unset a previous one
10275 * Sets the visual that should be used for by widget and its children for
10276 * creating #GdkWindows. The visual must be on the same #GdkScreen as
10277 * returned by gtk_widget_get_screen(), so handling the
10278 * #GtkWidget::screen-changed signal is necessary.
10280 * Setting a new @visual will not cause @widget to recreate its windows,
10281 * so you should call this function before @widget is realized.
10284 gtk_widget_set_visual (GtkWidget *widget,
10287 g_return_if_fail (GTK_IS_WIDGET (widget));
10288 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
10291 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
10294 g_object_set_qdata_full (G_OBJECT (widget),
10296 g_object_ref (visual),
10301 * gtk_widget_get_visual:
10302 * @widget: a #GtkWidget
10304 * Gets the visual that will be used to render @widget.
10306 * Return value: (transfer none): the visual for @widget
10309 gtk_widget_get_visual (GtkWidget *widget)
10315 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10317 if (gtk_widget_get_has_window (widget) &&
10318 widget->priv->window)
10319 return gdk_window_get_visual (widget->priv->window);
10321 screen = gtk_widget_get_screen (widget);
10323 for (w = widget; w != NULL; w = w->priv->parent)
10325 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
10328 if (gdk_visual_get_screen (visual) == screen)
10331 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
10332 gtk_widget_get_name (widget));
10336 return gdk_screen_get_system_visual (screen);
10340 * gtk_widget_get_settings:
10341 * @widget: a #GtkWidget
10343 * Gets the settings object holding the settings used for this widget.
10345 * Note that this function can only be called when the #GtkWidget
10346 * is attached to a toplevel, since the settings object is specific
10347 * to a particular #GdkScreen.
10349 * Return value: (transfer none): the relevant #GtkSettings object
10352 gtk_widget_get_settings (GtkWidget *widget)
10354 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10356 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
10360 * gtk_widget_get_events:
10361 * @widget: a #GtkWidget
10363 * Returns the event mask for the widget (a bitfield containing flags
10364 * from the #GdkEventMask enumeration). These are the events that the widget
10367 * Return value: event mask for @widget
10370 gtk_widget_get_events (GtkWidget *widget)
10372 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10374 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
10378 * gtk_widget_get_device_events:
10379 * @widget: a #GtkWidget
10380 * @device: a #GdkDevice
10382 * Returns the events mask for the widget corresponding to an specific device. These
10383 * are the events that the widget will receive when @device operates on it.
10385 * Returns: device event mask for @widget
10390 gtk_widget_get_device_events (GtkWidget *widget,
10393 GHashTable *device_events;
10395 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
10396 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
10398 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
10400 if (!device_events)
10403 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
10407 * gtk_widget_get_pointer:
10408 * @widget: a #GtkWidget
10409 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
10410 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
10412 * Obtains the location of the mouse pointer in widget coordinates.
10413 * Widget coordinates are a bit odd; for historical reasons, they are
10414 * defined as @widget->window coordinates for widgets that are not
10415 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
10416 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
10418 * Deprecated: 3.4: Use gdk_window_get_device_position() instead.
10421 gtk_widget_get_pointer (GtkWidget *widget,
10425 GtkWidgetPrivate *priv;
10427 g_return_if_fail (GTK_IS_WIDGET (widget));
10429 priv = widget->priv;
10436 if (gtk_widget_get_realized (widget))
10438 gdk_window_get_device_position (priv->window,
10439 gdk_device_manager_get_client_pointer (
10440 gdk_display_get_device_manager (
10441 gtk_widget_get_display (widget))),
10444 if (!gtk_widget_get_has_window (widget))
10447 *x -= priv->allocation.x;
10449 *y -= priv->allocation.y;
10455 * gtk_widget_is_ancestor:
10456 * @widget: a #GtkWidget
10457 * @ancestor: another #GtkWidget
10459 * Determines whether @widget is somewhere inside @ancestor, possibly with
10460 * intermediate containers.
10462 * Return value: %TRUE if @ancestor contains @widget as a child,
10463 * grandchild, great grandchild, etc.
10466 gtk_widget_is_ancestor (GtkWidget *widget,
10467 GtkWidget *ancestor)
10469 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
10470 g_return_val_if_fail (ancestor != NULL, FALSE);
10474 if (widget->priv->parent == ancestor)
10476 widget = widget->priv->parent;
10482 static GQuark quark_composite_name = 0;
10485 * gtk_widget_set_composite_name:
10486 * @widget: a #GtkWidget.
10487 * @name: the name to set
10489 * Sets a widgets composite name. The widget must be
10490 * a composite child of its parent; see gtk_widget_push_composite_child().
10493 gtk_widget_set_composite_name (GtkWidget *widget,
10496 g_return_if_fail (GTK_IS_WIDGET (widget));
10497 g_return_if_fail (widget->priv->composite_child);
10498 g_return_if_fail (name != NULL);
10500 if (!quark_composite_name)
10501 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
10503 g_object_set_qdata_full (G_OBJECT (widget),
10504 quark_composite_name,
10510 * gtk_widget_get_composite_name:
10511 * @widget: a #GtkWidget
10513 * Obtains the composite name of a widget.
10515 * Returns: the composite name of @widget, or %NULL if @widget is not
10516 * a composite child. The string should be freed when it is no
10520 gtk_widget_get_composite_name (GtkWidget *widget)
10522 GtkWidgetPrivate *priv;
10524 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10526 priv = widget->priv;
10528 if (widget->priv->composite_child && priv->parent)
10529 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
10536 * gtk_widget_push_composite_child:
10538 * Makes all newly-created widgets as composite children until
10539 * the corresponding gtk_widget_pop_composite_child() call.
10541 * A composite child is a child that's an implementation detail of the
10542 * container it's inside and should not be visible to people using the
10543 * container. Composite children aren't treated differently by GTK (but
10544 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
10545 * builders might want to treat them in a different way.
10547 * Here is a simple example:
10549 * gtk_widget_push_composite_child ();
10550 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10551 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10552 * gtk_widget_pop_composite_child ();
10553 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10554 * GTK_WIDGET (scrolled_window));
10555 * g_object_ref (scrolled_window->hscrollbar);
10559 gtk_widget_push_composite_child (void)
10561 composite_child_stack++;
10565 * gtk_widget_pop_composite_child:
10567 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10570 gtk_widget_pop_composite_child (void)
10572 if (composite_child_stack)
10573 composite_child_stack--;
10577 gtk_widget_emit_direction_changed (GtkWidget *widget,
10578 GtkTextDirection old_dir)
10580 GtkTextDirection direction;
10581 GtkStateFlags state;
10583 gtk_widget_update_pango_context (widget);
10585 direction = gtk_widget_get_direction (widget);
10586 state = widget->priv->state_flags;
10587 state &= GTK_STATE_FLAG_DIR_LTR | GTK_STATE_FLAG_DIR_RTL;
10591 case GTK_TEXT_DIR_LTR:
10592 state |= GTK_STATE_FLAG_DIR_LTR;
10595 case GTK_TEXT_DIR_RTL:
10596 state |= GTK_STATE_FLAG_DIR_RTL;
10599 case GTK_TEXT_DIR_NONE:
10601 g_assert_not_reached ();
10605 gtk_widget_set_state_flags (widget, state, TRUE);
10607 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10611 * gtk_widget_set_direction:
10612 * @widget: a #GtkWidget
10613 * @dir: the new direction
10615 * Sets the reading direction on a particular widget. This direction
10616 * controls the primary direction for widgets containing text,
10617 * and also the direction in which the children of a container are
10618 * packed. The ability to set the direction is present in order
10619 * so that correct localization into languages with right-to-left
10620 * reading directions can be done. Generally, applications will
10621 * let the default reading direction present, except for containers
10622 * where the containers are arranged in an order that is explicitely
10623 * visual rather than logical (such as buttons for text justification).
10625 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10626 * set by gtk_widget_set_default_direction() will be used.
10629 gtk_widget_set_direction (GtkWidget *widget,
10630 GtkTextDirection dir)
10632 GtkTextDirection old_dir;
10634 g_return_if_fail (GTK_IS_WIDGET (widget));
10635 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10637 old_dir = gtk_widget_get_direction (widget);
10639 widget->priv->direction = dir;
10641 if (old_dir != gtk_widget_get_direction (widget))
10642 gtk_widget_emit_direction_changed (widget, old_dir);
10646 * gtk_widget_get_direction:
10647 * @widget: a #GtkWidget
10649 * Gets the reading direction for a particular widget. See
10650 * gtk_widget_set_direction().
10652 * Return value: the reading direction for the widget.
10655 gtk_widget_get_direction (GtkWidget *widget)
10657 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10659 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10660 return gtk_default_direction;
10662 return widget->priv->direction;
10666 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10668 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10670 g_object_ref (widget);
10672 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10673 gtk_widget_emit_direction_changed (widget, old_dir);
10675 if (GTK_IS_CONTAINER (widget))
10676 gtk_container_forall (GTK_CONTAINER (widget),
10677 gtk_widget_set_default_direction_recurse,
10680 g_object_unref (widget);
10684 * gtk_widget_set_default_direction:
10685 * @dir: the new default direction. This cannot be
10686 * %GTK_TEXT_DIR_NONE.
10688 * Sets the default reading direction for widgets where the
10689 * direction has not been explicitly set by gtk_widget_set_direction().
10692 gtk_widget_set_default_direction (GtkTextDirection dir)
10694 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10696 if (dir != gtk_default_direction)
10698 GList *toplevels, *tmp_list;
10699 GtkTextDirection old_dir = gtk_default_direction;
10701 gtk_default_direction = dir;
10703 tmp_list = toplevels = gtk_window_list_toplevels ();
10704 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10708 gtk_widget_set_default_direction_recurse (tmp_list->data,
10709 GUINT_TO_POINTER (old_dir));
10710 g_object_unref (tmp_list->data);
10711 tmp_list = tmp_list->next;
10714 g_list_free (toplevels);
10719 * gtk_widget_get_default_direction:
10721 * Obtains the current default reading direction. See
10722 * gtk_widget_set_default_direction().
10724 * Return value: the current default direction.
10727 gtk_widget_get_default_direction (void)
10729 return gtk_default_direction;
10733 gtk_widget_constructed (GObject *object)
10735 GtkWidget *widget = GTK_WIDGET (object);
10736 GtkWidgetPrivate *priv = widget->priv;
10738 /* As strange as it may seem, this may happen on object construction.
10739 * init() implementations of parent types may eventually call this function,
10740 * each with its corresponding GType, which could leave a child
10741 * implementation with a wrong widget type in the widget path
10744 G_OBJECT_TYPE (widget) != gtk_widget_path_get_object_type (priv->path))
10746 gtk_widget_path_free (priv->path);
10750 G_OBJECT_CLASS (gtk_widget_parent_class)->constructed (object);
10754 gtk_widget_dispose (GObject *object)
10756 GtkWidget *widget = GTK_WIDGET (object);
10757 GtkWidgetPrivate *priv = widget->priv;
10760 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10761 else if (gtk_widget_get_visible (widget))
10762 gtk_widget_hide (widget);
10764 priv->visible = FALSE;
10765 if (gtk_widget_get_realized (widget))
10766 gtk_widget_unrealize (widget);
10768 if (!priv->in_destruction)
10770 priv->in_destruction = TRUE;
10771 g_signal_emit (object, widget_signals[DESTROY], 0);
10772 priv->in_destruction = FALSE;
10775 g_clear_object (&priv->muxer);
10777 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10781 gtk_widget_real_destroy (GtkWidget *object)
10783 /* gtk_object_destroy() will already hold a refcount on object */
10784 GtkWidget *widget = GTK_WIDGET (object);
10785 GtkWidgetPrivate *priv = widget->priv;
10788 if (GTK_WIDGET_GET_CLASS (widget)->priv->accessible_type != GTK_TYPE_ACCESSIBLE)
10790 GtkAccessible *accessible = g_object_steal_qdata (G_OBJECT (widget), quark_accessible_object);
10794 gtk_accessible_set_widget (accessible, NULL);
10795 g_object_unref (accessible);
10799 /* wipe accelerator closures (keep order) */
10800 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10801 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10803 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10804 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10806 gtk_grab_remove (widget);
10808 for (l = priv->tick_callbacks; l;)
10810 GList *next = l->next;
10811 destroy_tick_callback_info (widget, l->data, l);
10816 g_object_unref (priv->style);
10817 priv->style = gtk_widget_get_default_style ();
10818 g_object_ref (priv->style);
10822 gtk_widget_finalize (GObject *object)
10824 GtkWidget *widget = GTK_WIDGET (object);
10825 GtkWidgetPrivate *priv = widget->priv;
10826 GtkWidgetAuxInfo *aux_info;
10827 GtkAccessible *accessible;
10829 gtk_grab_remove (widget);
10831 g_object_unref (priv->style);
10832 priv->style = NULL;
10834 g_free (priv->name);
10836 aux_info = gtk_widget_get_aux_info (widget, FALSE);
10838 gtk_widget_aux_info_destroy (aux_info);
10840 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10842 g_object_unref (accessible);
10845 gtk_widget_path_free (priv->path);
10849 _gtk_style_context_set_widget (priv->context, NULL);
10850 g_object_unref (priv->context);
10853 _gtk_size_request_cache_free (&priv->requests);
10855 if (g_object_is_floating (object))
10856 g_warning ("A floating object was finalized. This means that someone\n"
10857 "called g_object_unref() on an object that had only a floating\n"
10858 "reference; the initial floating reference is not owned by anyone\n"
10859 "and must be removed with g_object_ref_sink().");
10861 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10864 /*****************************************
10865 * gtk_widget_real_map:
10870 *****************************************/
10873 gtk_widget_real_map (GtkWidget *widget)
10875 GtkWidgetPrivate *priv = widget->priv;
10877 g_assert (gtk_widget_get_realized (widget));
10879 if (!gtk_widget_get_mapped (widget))
10881 gtk_widget_set_mapped (widget, TRUE);
10883 if (gtk_widget_get_has_window (widget))
10884 gdk_window_show (priv->window);
10888 /*****************************************
10889 * gtk_widget_real_unmap:
10894 *****************************************/
10897 gtk_widget_real_unmap (GtkWidget *widget)
10899 GtkWidgetPrivate *priv = widget->priv;
10901 if (gtk_widget_get_mapped (widget))
10903 gtk_widget_set_mapped (widget, FALSE);
10905 if (gtk_widget_get_has_window (widget))
10906 gdk_window_hide (priv->window);
10910 /*****************************************
10911 * gtk_widget_real_realize:
10916 *****************************************/
10919 gtk_widget_real_realize (GtkWidget *widget)
10921 GtkWidgetPrivate *priv = widget->priv;
10923 g_assert (!gtk_widget_get_has_window (widget));
10925 gtk_widget_set_realized (widget, TRUE);
10928 priv->window = gtk_widget_get_parent_window (widget);
10929 g_object_ref (priv->window);
10933 /*****************************************
10934 * gtk_widget_real_unrealize:
10939 *****************************************/
10942 gtk_widget_real_unrealize (GtkWidget *widget)
10944 GtkWidgetPrivate *priv = widget->priv;
10946 g_assert (!widget->priv->mapped);
10948 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10951 /* We must do unrealize child widget BEFORE container widget.
10952 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10953 * So, unrealizing container widget bofore its children causes the problem
10954 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10957 if (GTK_IS_CONTAINER (widget))
10958 gtk_container_forall (GTK_CONTAINER (widget),
10959 (GtkCallback) gtk_widget_unrealize,
10962 if (gtk_widget_get_has_window (widget))
10964 gtk_widget_unregister_window (widget, priv->window);
10965 gdk_window_destroy (priv->window);
10966 priv->window = NULL;
10970 g_object_unref (priv->window);
10971 priv->window = NULL;
10974 gtk_selection_remove_all (widget);
10976 gtk_widget_set_realized (widget, FALSE);
10980 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10981 GtkOrientation orientation,
10982 gint *minimum_size,
10983 gint *natural_size)
10985 const GtkWidgetAuxInfo *aux_info;
10987 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10989 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10990 aux_info->width > 0)
10992 *minimum_size = MAX (*minimum_size, aux_info->width);
10994 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10995 aux_info->height > 0)
10997 *minimum_size = MAX (*minimum_size, aux_info->height);
11000 /* Fix it if set_size_request made natural size smaller than min size.
11001 * This would also silently fix broken widgets, but we warn about them
11002 * in gtksizerequest.c when calling their size request vfuncs.
11004 *natural_size = MAX (*natural_size, *minimum_size);
11006 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11008 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
11009 *natural_size += (aux_info->margin.left + aux_info->margin.right);
11013 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
11014 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
11019 * _gtk_widget_peek_request_cache:
11021 * Returns the address of the widget's request cache (strictly for
11022 * internal use in gtksizerequest.c)
11024 * Return value: the address of @widget's size request cache.
11027 _gtk_widget_peek_request_cache (GtkWidget *widget)
11029 /* Don't bother slowing things down with the return_if_fail guards here */
11030 return &widget->priv->requests;
11034 * _gtk_widget_set_device_window:
11035 * @widget: a #GtkWidget
11036 * @device: a #GdkDevice
11037 * @window: the new device window
11039 * Sets pointer window for @widget and @device.
11040 * Does not ref @window.
11043 _gtk_widget_set_device_window (GtkWidget *widget,
11047 GHashTable *device_window;
11049 g_return_if_fail (GTK_IS_WIDGET (widget));
11050 g_return_if_fail (GDK_IS_DEVICE (device));
11051 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
11053 if (!gtk_widget_get_mapped (widget))
11056 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11058 if (!device_window && window)
11060 device_window = g_hash_table_new (NULL, NULL);
11061 g_object_set_qdata_full (G_OBJECT (widget),
11062 quark_pointer_window,
11064 (GDestroyNotify) g_hash_table_destroy);
11068 g_hash_table_insert (device_window, device, window);
11069 else if (device_window)
11071 g_hash_table_remove (device_window, device);
11073 if (g_hash_table_size (device_window) == 0)
11074 g_object_set_qdata (G_OBJECT (widget), quark_pointer_window, NULL);
11079 * _gtk_widget_get_device_window:
11080 * @widget: a #GtkWidget
11081 * @device: a #GdkDevice
11083 * Return value: the device window set on @widget, or %NULL
11086 _gtk_widget_get_device_window (GtkWidget *widget,
11089 GHashTable *device_window;
11091 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11092 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
11094 if (!gtk_widget_get_mapped (widget))
11097 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11099 if (!device_window)
11102 return g_hash_table_lookup (device_window, device);
11106 * _gtk_widget_list_devices:
11107 * @widget: a #GtkWidget
11109 * Returns the list of #GdkDevices that is currently on top
11110 * of any window belonging to @widget.
11111 * Free the list with g_list_free(), the elements are owned
11112 * by GTK+ and must not be freed.
11115 _gtk_widget_list_devices (GtkWidget *widget)
11117 GHashTableIter iter;
11118 GHashTable *device_window;
11119 GList *devices = NULL;
11120 gpointer key, value;
11122 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11124 if (!gtk_widget_get_mapped (widget))
11127 device_window = g_object_get_qdata (G_OBJECT (widget), quark_pointer_window);
11129 if (G_UNLIKELY (!device_window))
11132 g_hash_table_iter_init (&iter, device_window);
11134 while (g_hash_table_iter_next (&iter, &key, &value))
11135 devices = g_list_prepend (devices, key);
11141 synth_crossing (GtkWidget *widget,
11145 GdkCrossingMode mode,
11146 GdkNotifyType detail)
11150 event = gdk_event_new (type);
11152 event->crossing.window = g_object_ref (window);
11153 event->crossing.send_event = TRUE;
11154 event->crossing.subwindow = g_object_ref (window);
11155 event->crossing.time = GDK_CURRENT_TIME;
11156 event->crossing.x = event->crossing.y = 0;
11157 event->crossing.x_root = event->crossing.y_root = 0;
11158 event->crossing.mode = mode;
11159 event->crossing.detail = detail;
11160 event->crossing.focus = FALSE;
11161 event->crossing.state = 0;
11162 gdk_event_set_device (event, device);
11165 widget = gtk_get_event_widget (event);
11168 gtk_widget_event_internal (widget, event);
11170 gdk_event_free (event);
11174 * _gtk_widget_synthesize_crossing:
11175 * @from: the #GtkWidget the virtual pointer is leaving.
11176 * @to: the #GtkWidget the virtual pointer is moving to.
11177 * @mode: the #GdkCrossingMode to place on the synthesized events.
11179 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
11181 * The real pointer window is the window that most recently received an enter notify
11182 * event. Windows that don't select for crossing events can't become the real
11183 * poiner window. The real pointer widget that owns the real pointer window. The
11184 * effective pointer window is the same as the real pointer window unless the real
11185 * pointer widget is either insensitive or there is a grab on a widget that is not
11186 * an ancestor of the real pointer widget (in which case the effective pointer
11187 * window should be the root window).
11189 * When the effective pointer window is the same as the real poiner window, we
11190 * receive crossing events from the windowing system. When the effective pointer
11191 * window changes to become different from the real pointer window we synthesize
11192 * crossing events, attempting to follow X protocol rules:
11194 * When the root window becomes the effective pointer window:
11195 * - leave notify on real pointer window, detail Ancestor
11196 * - leave notify on all of its ancestors, detail Virtual
11197 * - enter notify on root window, detail Inferior
11199 * When the root window ceases to be the effective pointer window:
11200 * - leave notify on root window, detail Inferior
11201 * - enter notify on all ancestors of real pointer window, detail Virtual
11202 * - enter notify on real pointer window, detail Ancestor
11205 _gtk_widget_synthesize_crossing (GtkWidget *from,
11208 GdkCrossingMode mode)
11210 GdkWindow *from_window = NULL, *to_window = NULL;
11212 g_return_if_fail (from != NULL || to != NULL);
11216 from_window = _gtk_widget_get_device_window (from, device);
11219 from_window = from->priv->window;
11224 to_window = _gtk_widget_get_device_window (to, device);
11227 to_window = to->priv->window;
11230 if (from_window == NULL && to_window == NULL)
11232 else if (from_window != NULL && to_window == NULL)
11234 GList *from_ancestors = NULL, *list;
11235 GdkWindow *from_ancestor = from_window;
11237 while (from_ancestor != NULL)
11239 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11240 if (from_ancestor == NULL)
11242 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11245 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11246 device, mode, GDK_NOTIFY_ANCESTOR);
11247 for (list = g_list_last (from_ancestors); list; list = list->prev)
11249 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11250 device, mode, GDK_NOTIFY_VIRTUAL);
11253 /* XXX: enter/inferior on root window? */
11255 g_list_free (from_ancestors);
11257 else if (from_window == NULL && to_window != NULL)
11259 GList *to_ancestors = NULL, *list;
11260 GdkWindow *to_ancestor = to_window;
11262 while (to_ancestor != NULL)
11264 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11265 if (to_ancestor == NULL)
11267 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11270 /* XXX: leave/inferior on root window? */
11272 for (list = to_ancestors; list; list = list->next)
11274 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11275 device, mode, GDK_NOTIFY_VIRTUAL);
11277 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11278 device, mode, GDK_NOTIFY_ANCESTOR);
11280 g_list_free (to_ancestors);
11282 else if (from_window == to_window)
11286 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
11287 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
11289 while (from_ancestor != NULL || to_ancestor != NULL)
11291 if (from_ancestor != NULL)
11293 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
11294 if (from_ancestor == to_window)
11297 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
11299 if (to_ancestor != NULL)
11301 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
11302 if (to_ancestor == from_window)
11305 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
11308 if (to_ancestor == from_window)
11310 if (mode != GDK_CROSSING_GTK_UNGRAB)
11311 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11312 device, mode, GDK_NOTIFY_INFERIOR);
11313 for (list = to_ancestors; list; list = list->next)
11314 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11315 device, mode, GDK_NOTIFY_VIRTUAL);
11316 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11317 device, mode, GDK_NOTIFY_ANCESTOR);
11319 else if (from_ancestor == to_window)
11321 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11322 device, mode, GDK_NOTIFY_ANCESTOR);
11323 for (list = g_list_last (from_ancestors); list; list = list->prev)
11325 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11326 device, mode, GDK_NOTIFY_VIRTUAL);
11328 if (mode != GDK_CROSSING_GTK_GRAB)
11329 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11330 device, mode, GDK_NOTIFY_INFERIOR);
11334 while (from_ancestors != NULL && to_ancestors != NULL
11335 && from_ancestors->data == to_ancestors->data)
11337 from_ancestors = g_list_delete_link (from_ancestors,
11339 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
11342 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
11343 device, mode, GDK_NOTIFY_NONLINEAR);
11345 for (list = g_list_last (from_ancestors); list; list = list->prev)
11347 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
11348 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11350 for (list = to_ancestors; list; list = list->next)
11352 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
11353 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
11355 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
11356 device, mode, GDK_NOTIFY_NONLINEAR);
11358 g_list_free (from_ancestors);
11359 g_list_free (to_ancestors);
11364 gtk_widget_propagate_state (GtkWidget *widget,
11365 GtkStateData *data)
11367 GtkWidgetPrivate *priv = widget->priv;
11368 GtkStateFlags new_flags, old_flags = priv->state_flags;
11369 GtkStateType old_state;
11371 old_state = gtk_widget_get_state (widget);
11373 priv->state_flags |= data->flags_to_set;
11374 priv->state_flags &= ~(data->flags_to_unset);
11376 /* make insensitivity unoverridable */
11377 if (!priv->sensitive)
11378 priv->state_flags |= GTK_STATE_FLAG_INSENSITIVE;
11380 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
11384 window = gtk_widget_get_toplevel (widget);
11386 if (window && gtk_widget_is_toplevel (window))
11387 gtk_window_set_focus (GTK_WINDOW (window), NULL);
11390 new_flags = priv->state_flags;
11392 if (old_flags != new_flags)
11394 g_object_ref (widget);
11396 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
11397 gtk_grab_remove (widget);
11399 gtk_style_context_set_state (gtk_widget_get_style_context (widget), new_flags);
11401 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
11402 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
11404 if (!priv->shadowed &&
11405 (new_flags & GTK_STATE_FLAG_INSENSITIVE) != (old_flags & GTK_STATE_FLAG_INSENSITIVE))
11407 GList *event_windows = NULL;
11408 GList *devices, *d;
11410 devices = _gtk_widget_list_devices (widget);
11412 for (d = devices; d; d = d->next)
11418 window = _gtk_widget_get_device_window (widget, device);
11420 /* Do not propagate more than once to the
11421 * same window if non-multidevice aware.
11423 if (!gdk_window_get_support_multidevice (window) &&
11424 g_list_find (event_windows, window))
11427 if (!gtk_widget_is_sensitive (widget))
11428 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
11429 GDK_CROSSING_STATE_CHANGED);
11431 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
11432 GDK_CROSSING_STATE_CHANGED);
11434 event_windows = g_list_prepend (event_windows, window);
11437 g_list_free (event_windows);
11438 g_list_free (devices);
11441 if (GTK_IS_CONTAINER (widget))
11443 GtkStateData child_data;
11445 /* Make sure to only propate the right states further */
11446 child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
11447 child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
11449 gtk_container_forall (GTK_CONTAINER (widget),
11450 (GtkCallback) gtk_widget_propagate_state,
11454 g_object_unref (widget);
11458 static const GtkWidgetAuxInfo default_aux_info = {
11466 * gtk_widget_get_aux_info:
11467 * @widget: a #GtkWidget
11468 * @create: if %TRUE, create the structure if it doesn't exist
11470 * Get the #GtkWidgetAuxInfo structure for the widget.
11472 * Return value: the #GtkAuxInfo structure for the widget, or
11473 * %NULL if @create is %FALSE and one doesn't already exist.
11475 static GtkWidgetAuxInfo *
11476 gtk_widget_get_aux_info (GtkWidget *widget,
11479 GtkWidgetAuxInfo *aux_info;
11481 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
11482 if (!aux_info && create)
11484 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
11486 *aux_info = default_aux_info;
11488 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
11494 static const GtkWidgetAuxInfo*
11495 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
11497 GtkWidgetAuxInfo *aux_info;
11499 aux_info = gtk_widget_get_aux_info (widget, FALSE);
11500 if (aux_info == NULL)
11502 return &default_aux_info;
11510 /*****************************************
11511 * gtk_widget_aux_info_destroy:
11516 *****************************************/
11519 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11521 g_slice_free (GtkWidgetAuxInfo, aux_info);
11525 * gtk_widget_shape_combine_region:
11526 * @widget: a #GtkWidget
11527 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11529 * Sets a shape for this widget's GDK window. This allows for
11530 * transparent windows etc., see gdk_window_shape_combine_region()
11531 * for more information.
11536 gtk_widget_shape_combine_region (GtkWidget *widget,
11537 cairo_region_t *region)
11539 GtkWidgetPrivate *priv;
11541 g_return_if_fail (GTK_IS_WIDGET (widget));
11542 /* set_shape doesn't work on widgets without gdk window */
11543 g_return_if_fail (gtk_widget_get_has_window (widget));
11545 priv = widget->priv;
11547 if (region == NULL)
11549 priv->has_shape_mask = FALSE;
11552 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11554 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11558 priv->has_shape_mask = TRUE;
11560 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11561 cairo_region_copy (region),
11562 (GDestroyNotify) cairo_region_destroy);
11564 /* set shape if widget has a gdk window already.
11565 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11568 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11573 * gtk_widget_input_shape_combine_region:
11574 * @widget: a #GtkWidget
11575 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11577 * Sets an input shape for this widget's GDK window. This allows for
11578 * windows which react to mouse click in a nonrectangular region, see
11579 * gdk_window_input_shape_combine_region() for more information.
11584 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11585 cairo_region_t *region)
11587 GtkWidgetPrivate *priv;
11589 g_return_if_fail (GTK_IS_WIDGET (widget));
11590 /* set_shape doesn't work on widgets without gdk window */
11591 g_return_if_fail (gtk_widget_get_has_window (widget));
11593 priv = widget->priv;
11595 if (region == NULL)
11598 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11600 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11604 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11605 cairo_region_copy (region),
11606 (GDestroyNotify) cairo_region_destroy);
11608 /* set shape if widget has a gdk window already.
11609 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11612 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11617 /* style properties
11621 * gtk_widget_class_install_style_property_parser: (skip)
11622 * @klass: a #GtkWidgetClass
11623 * @pspec: the #GParamSpec for the style property
11624 * @parser: the parser for the style property
11626 * Installs a style property on a widget class.
11629 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11631 GtkRcPropertyParser parser)
11633 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11634 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11635 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11636 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11638 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11640 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11641 G_OBJECT_CLASS_NAME (klass),
11646 g_param_spec_ref_sink (pspec);
11647 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11648 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11652 * gtk_widget_class_install_style_property:
11653 * @klass: a #GtkWidgetClass
11654 * @pspec: the #GParamSpec for the property
11656 * Installs a style property on a widget class. The parser for the
11657 * style property is determined by the value type of @pspec.
11660 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11663 GtkRcPropertyParser parser;
11665 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11666 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11668 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11670 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11674 * gtk_widget_class_find_style_property:
11675 * @klass: a #GtkWidgetClass
11676 * @property_name: the name of the style property to find
11678 * Finds a style property of a widget class by name.
11680 * Returns: (transfer none): the #GParamSpec of the style property or
11681 * %NULL if @class has no style property with that name.
11686 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11687 const gchar *property_name)
11689 g_return_val_if_fail (property_name != NULL, NULL);
11691 return g_param_spec_pool_lookup (style_property_spec_pool,
11693 G_OBJECT_CLASS_TYPE (klass),
11698 * gtk_widget_class_list_style_properties:
11699 * @klass: a #GtkWidgetClass
11700 * @n_properties: location to return the number of style properties found
11702 * Returns all style properties of a widget class.
11704 * Returns: (array length=n_properties) (transfer container): a
11705 * newly allocated array of #GParamSpec*. The array must be
11706 * freed with g_free().
11711 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11712 guint *n_properties)
11714 GParamSpec **pspecs;
11717 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11718 G_OBJECT_CLASS_TYPE (klass),
11727 * gtk_widget_style_get_property:
11728 * @widget: a #GtkWidget
11729 * @property_name: the name of a style property
11730 * @value: location to return the property value
11732 * Gets the value of a style property of @widget.
11735 gtk_widget_style_get_property (GtkWidget *widget,
11736 const gchar *property_name,
11741 g_return_if_fail (GTK_IS_WIDGET (widget));
11742 g_return_if_fail (property_name != NULL);
11743 g_return_if_fail (G_IS_VALUE (value));
11745 g_object_ref (widget);
11746 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11748 G_OBJECT_TYPE (widget),
11751 g_warning ("%s: widget class `%s' has no property named `%s'",
11753 G_OBJECT_TYPE_NAME (widget),
11757 GtkStyleContext *context;
11758 const GValue *peek_value;
11759 GtkStateFlags state;
11761 context = gtk_widget_get_style_context (widget);
11762 state = gtk_widget_get_state_flags (widget);
11764 peek_value = _gtk_style_context_peek_style_property (context,
11765 G_OBJECT_TYPE (widget),
11768 /* auto-conversion of the caller's value type
11770 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11771 g_value_copy (peek_value, value);
11772 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11773 g_value_transform (peek_value, value);
11775 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11777 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11778 G_VALUE_TYPE_NAME (value));
11780 g_object_unref (widget);
11784 * gtk_widget_style_get_valist:
11785 * @widget: a #GtkWidget
11786 * @first_property_name: the name of the first property to get
11787 * @var_args: a <type>va_list</type> of pairs of property names and
11788 * locations to return the property values, starting with the location
11789 * for @first_property_name.
11791 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11795 gtk_widget_style_get_valist (GtkWidget *widget,
11796 const gchar *first_property_name,
11799 GtkStyleContext *context;
11800 GtkStateFlags state;
11803 g_return_if_fail (GTK_IS_WIDGET (widget));
11805 g_object_ref (widget);
11806 context = gtk_widget_get_style_context (widget);
11807 state = gtk_widget_get_state_flags (widget);
11809 name = first_property_name;
11812 const GValue *peek_value;
11816 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11818 G_OBJECT_TYPE (widget),
11822 g_warning ("%s: widget class `%s' has no property named `%s'",
11824 G_OBJECT_TYPE_NAME (widget),
11828 /* style pspecs are always readable so we can spare that check here */
11830 peek_value = _gtk_style_context_peek_style_property (context,
11831 G_OBJECT_TYPE (widget),
11834 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11837 g_warning ("%s: %s", G_STRLOC, error);
11842 name = va_arg (var_args, gchar*);
11845 g_object_unref (widget);
11849 * gtk_widget_style_get:
11850 * @widget: a #GtkWidget
11851 * @first_property_name: the name of the first property to get
11852 * @...: pairs of property names and locations to return the
11853 * property values, starting with the location for
11854 * @first_property_name, terminated by %NULL.
11856 * Gets the values of a multiple style properties of @widget.
11859 gtk_widget_style_get (GtkWidget *widget,
11860 const gchar *first_property_name,
11865 g_return_if_fail (GTK_IS_WIDGET (widget));
11867 va_start (var_args, first_property_name);
11868 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11873 * gtk_requisition_new:
11875 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11877 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11878 * be freed with gtk_requisition_free().
11883 gtk_requisition_new (void)
11885 return g_slice_new0 (GtkRequisition);
11889 * gtk_requisition_copy:
11890 * @requisition: a #GtkRequisition
11892 * Copies a #GtkRequisition.
11894 * Returns: a copy of @requisition
11897 gtk_requisition_copy (const GtkRequisition *requisition)
11899 return g_slice_dup (GtkRequisition, requisition);
11903 * gtk_requisition_free:
11904 * @requisition: a #GtkRequisition
11906 * Frees a #GtkRequisition.
11909 gtk_requisition_free (GtkRequisition *requisition)
11911 g_slice_free (GtkRequisition, requisition);
11914 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11915 gtk_requisition_copy,
11916 gtk_requisition_free)
11919 * gtk_widget_class_set_accessible_type:
11920 * @widget_class: class to set the accessible type for
11921 * @type: The object type that implements the accessible for @widget_class
11923 * Sets the type to be used for creating accessibles for widgets of
11924 * @widget_class. The given @type must be a subtype of the type used for
11925 * accessibles of the parent class.
11927 * This function should only be called from class init functions of widgets.
11932 gtk_widget_class_set_accessible_type (GtkWidgetClass *widget_class,
11935 GtkWidgetClassPrivate *priv;
11937 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11938 g_return_if_fail (g_type_is_a (type, widget_class->priv->accessible_type));
11940 priv = widget_class->priv;
11942 priv->accessible_type = type;
11943 /* reset this - honoring the type's role is better. */
11944 priv->accessible_role = ATK_ROLE_INVALID;
11948 * gtk_widget_class_set_accessible_role:
11949 * @widget_class: class to set the accessible role for
11950 * @role: The role to use for accessibles created for @widget_class
11952 * Sets the default #AtkRole to be set on accessibles created for
11953 * widgets of @widget_class. Accessibles may decide to not honor this
11954 * setting if their role reporting is more refined. Calls to
11955 * gtk_widget_class_set_accessible_type() will reset this value.
11957 * In cases where you want more fine-grained control over the role of
11958 * accessibles created for @widget_class, you should provide your own
11959 * accessible type and use gtk_widget_class_set_accessible_type()
11962 * If @role is #ATK_ROLE_INVALID, the default role will not be changed
11963 * and the accessible's default role will be used instead.
11965 * This function should only be called from class init functions of widgets.
11970 gtk_widget_class_set_accessible_role (GtkWidgetClass *widget_class,
11973 GtkWidgetClassPrivate *priv;
11975 g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
11977 priv = widget_class->priv;
11979 priv->accessible_role = role;
11983 * _gtk_widget_peek_accessible:
11984 * @widget: a #GtkWidget
11986 * Gets the accessible for @widget, if it has been created yet.
11987 * Otherwise, this function returns %NULL. If the @widget's implementation
11988 * does not use the default way to create accessibles, %NULL will always be
11991 * Returns: the accessible for @widget or %NULL if none has been
11995 _gtk_widget_peek_accessible (GtkWidget *widget)
11997 return g_object_get_qdata (G_OBJECT (widget),
11998 quark_accessible_object);
12002 * gtk_widget_get_accessible:
12003 * @widget: a #GtkWidget
12005 * Returns the accessible object that describes the widget to an
12006 * assistive technology.
12008 * If accessibility support is not available, this #AtkObject
12009 * instance may be a no-op. Likewise, if no class-specific #AtkObject
12010 * implementation is available for the widget instance in question,
12011 * it will inherit an #AtkObject implementation from the first ancestor
12012 * class for which such an implementation is defined.
12014 * The documentation of the
12015 * <ulink url="http://developer.gnome.org/atk/stable/">ATK</ulink>
12016 * library contains more information about accessible objects and their uses.
12018 * Returns: (transfer none): the #AtkObject associated with @widget
12021 gtk_widget_get_accessible (GtkWidget *widget)
12023 GtkWidgetClass *klass;
12025 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12027 klass = GTK_WIDGET_GET_CLASS (widget);
12029 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
12031 return klass->get_accessible (widget);
12035 gtk_widget_real_get_accessible (GtkWidget *widget)
12037 AtkObject* accessible;
12039 accessible = g_object_get_qdata (G_OBJECT (widget),
12040 quark_accessible_object);
12043 GtkWidgetClass *widget_class;
12044 GtkWidgetClassPrivate *priv;
12045 AtkObjectFactory *factory;
12046 AtkRegistry *default_registry;
12048 widget_class = GTK_WIDGET_GET_CLASS (widget);
12049 priv = widget_class->priv;
12051 if (priv->accessible_type == GTK_TYPE_ACCESSIBLE)
12053 default_registry = atk_get_default_registry ();
12054 factory = atk_registry_get_factory (default_registry,
12055 G_TYPE_FROM_INSTANCE (widget));
12057 atk_object_factory_create_accessible (factory,
12058 G_OBJECT (widget));
12060 if (priv->accessible_role != ATK_ROLE_INVALID)
12061 atk_object_set_role (accessible, priv->accessible_role);
12063 g_object_set_qdata (G_OBJECT (widget),
12064 quark_accessible_object,
12069 accessible = g_object_new (priv->accessible_type,
12072 if (priv->accessible_role != ATK_ROLE_INVALID)
12073 atk_object_set_role (accessible, priv->accessible_role);
12075 g_object_set_qdata (G_OBJECT (widget),
12076 quark_accessible_object,
12079 atk_object_initialize (accessible, widget);
12081 /* Set the role again, since we don't want a role set
12082 * in some parent initialize() function to override
12085 if (priv->accessible_role != ATK_ROLE_INVALID)
12086 atk_object_set_role (accessible, priv->accessible_role);
12093 * Initialize a AtkImplementorIface instance's virtual pointers as
12094 * appropriate to this implementor's class (GtkWidget).
12097 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
12099 iface->ref_accessible = gtk_widget_ref_accessible;
12103 gtk_widget_ref_accessible (AtkImplementor *implementor)
12105 AtkObject *accessible;
12107 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
12109 g_object_ref (accessible);
12114 * Expand flag management
12118 gtk_widget_update_computed_expand (GtkWidget *widget)
12120 GtkWidgetPrivate *priv;
12122 priv = widget->priv;
12124 if (priv->need_compute_expand)
12128 if (priv->hexpand_set)
12133 if (priv->vexpand_set)
12138 /* we don't need to use compute_expand if both expands are
12139 * forced by the app
12141 if (!(priv->hexpand_set && priv->vexpand_set))
12143 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
12147 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
12148 priv->hexpand_set ? &ignored : &h,
12149 priv->vexpand_set ? &ignored : &v);
12153 priv->need_compute_expand = FALSE;
12154 priv->computed_hexpand = h != FALSE;
12155 priv->computed_vexpand = v != FALSE;
12160 * gtk_widget_queue_compute_expand:
12161 * @widget: a #GtkWidget
12163 * Mark @widget as needing to recompute its expand flags. Call
12164 * this function when setting legacy expand child properties
12165 * on the child of a container.
12167 * See gtk_widget_compute_expand().
12170 gtk_widget_queue_compute_expand (GtkWidget *widget)
12173 gboolean changed_anything;
12175 if (widget->priv->need_compute_expand)
12178 changed_anything = FALSE;
12180 while (parent != NULL)
12182 if (!parent->priv->need_compute_expand)
12184 parent->priv->need_compute_expand = TRUE;
12185 changed_anything = TRUE;
12188 /* Note: if we had an invariant that "if a child needs to
12189 * compute expand, its parents also do" then we could stop going
12190 * up when we got to a parent that already needed to
12191 * compute. However, in general we compute expand lazily (as
12192 * soon as we see something in a subtree that is expand, we know
12193 * we're expanding) and so this invariant does not hold and we
12194 * have to always walk all the way up in case some ancestor
12195 * is not currently need_compute_expand.
12198 parent = parent->priv->parent;
12201 /* recomputing expand always requires
12202 * a relayout as well
12204 if (changed_anything)
12205 gtk_widget_queue_resize (widget);
12209 * gtk_widget_compute_expand:
12210 * @widget: the widget
12211 * @orientation: expand direction
12213 * Computes whether a container should give this widget extra space
12214 * when possible. Containers should check this, rather than
12215 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
12217 * This function already checks whether the widget is visible, so
12218 * visibility does not need to be checked separately. Non-visible
12219 * widgets are not expanded.
12221 * The computed expand value uses either the expand setting explicitly
12222 * set on the widget itself, or, if none has been explicitly set,
12223 * the widget may expand if some of its children do.
12225 * Return value: whether widget tree rooted here should be expanded
12228 gtk_widget_compute_expand (GtkWidget *widget,
12229 GtkOrientation orientation)
12231 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12233 /* We never make a widget expand if not even showing. */
12234 if (!gtk_widget_get_visible (widget))
12237 gtk_widget_update_computed_expand (widget);
12239 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12241 return widget->priv->computed_hexpand;
12245 return widget->priv->computed_vexpand;
12250 gtk_widget_set_expand (GtkWidget *widget,
12251 GtkOrientation orientation,
12254 const char *expand_prop;
12255 const char *expand_set_prop;
12257 GtkWidgetPrivate *priv;
12259 g_return_if_fail (GTK_IS_WIDGET (widget));
12261 priv = widget->priv;
12263 expand = expand != FALSE;
12265 was_both = priv->hexpand && priv->vexpand;
12267 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12269 if (priv->hexpand_set &&
12270 priv->hexpand == expand)
12273 priv->hexpand_set = TRUE;
12274 priv->hexpand = expand;
12276 expand_prop = "hexpand";
12277 expand_set_prop = "hexpand-set";
12281 if (priv->vexpand_set &&
12282 priv->vexpand == expand)
12285 priv->vexpand_set = TRUE;
12286 priv->vexpand = expand;
12288 expand_prop = "vexpand";
12289 expand_set_prop = "vexpand-set";
12292 gtk_widget_queue_compute_expand (widget);
12294 g_object_freeze_notify (G_OBJECT (widget));
12295 g_object_notify (G_OBJECT (widget), expand_prop);
12296 g_object_notify (G_OBJECT (widget), expand_set_prop);
12297 if (was_both != (priv->hexpand && priv->vexpand))
12298 g_object_notify (G_OBJECT (widget), "expand");
12299 g_object_thaw_notify (G_OBJECT (widget));
12303 gtk_widget_set_expand_set (GtkWidget *widget,
12304 GtkOrientation orientation,
12307 GtkWidgetPrivate *priv;
12310 priv = widget->priv;
12312 set = set != FALSE;
12314 if (orientation == GTK_ORIENTATION_HORIZONTAL)
12316 if (set == priv->hexpand_set)
12319 priv->hexpand_set = set;
12320 prop = "hexpand-set";
12324 if (set == priv->vexpand_set)
12327 priv->vexpand_set = set;
12328 prop = "vexpand-set";
12331 gtk_widget_queue_compute_expand (widget);
12333 g_object_notify (G_OBJECT (widget), prop);
12337 * gtk_widget_get_hexpand:
12338 * @widget: the widget
12340 * Gets whether the widget would like any available extra horizontal
12341 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12342 * generally receive the extra space. For example, a list or
12343 * scrollable area or document in your window would often be set to
12346 * Containers should use gtk_widget_compute_expand() rather than
12347 * this function, to see whether a widget, or any of its children,
12348 * has the expand flag set. If any child of a widget wants to
12349 * expand, the parent may ask to expand also.
12351 * This function only looks at the widget's own hexpand flag, rather
12352 * than computing whether the entire widget tree rooted at this widget
12355 * Return value: whether hexpand flag is set
12358 gtk_widget_get_hexpand (GtkWidget *widget)
12360 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12362 return widget->priv->hexpand;
12366 * gtk_widget_set_hexpand:
12367 * @widget: the widget
12368 * @expand: whether to expand
12370 * Sets whether the widget would like any available extra horizontal
12371 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
12372 * generally receive the extra space. For example, a list or
12373 * scrollable area or document in your window would often be set to
12376 * Call this function to set the expand flag if you would like your
12377 * widget to become larger horizontally when the window has extra
12380 * By default, widgets automatically expand if any of their children
12381 * want to expand. (To see if a widget will automatically expand given
12382 * its current children and state, call gtk_widget_compute_expand(). A
12383 * container can decide how the expandability of children affects the
12384 * expansion of the container by overriding the compute_expand virtual
12385 * method on #GtkWidget.).
12387 * Setting hexpand explicitly with this function will override the
12388 * automatic expand behavior.
12390 * This function forces the widget to expand or not to expand,
12391 * regardless of children. The override occurs because
12392 * gtk_widget_set_hexpand() sets the hexpand-set property (see
12393 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
12394 * value to be used, rather than looking at children and widget state.
12397 gtk_widget_set_hexpand (GtkWidget *widget,
12400 g_return_if_fail (GTK_IS_WIDGET (widget));
12402 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
12406 * gtk_widget_get_hexpand_set:
12407 * @widget: the widget
12409 * Gets whether gtk_widget_set_hexpand() has been used to
12410 * explicitly set the expand flag on this widget.
12412 * If hexpand is set, then it overrides any computed
12413 * expand value based on child widgets. If hexpand is not
12414 * set, then the expand value depends on whether any
12415 * children of the widget would like to expand.
12417 * There are few reasons to use this function, but it's here
12418 * for completeness and consistency.
12420 * Return value: whether hexpand has been explicitly set
12423 gtk_widget_get_hexpand_set (GtkWidget *widget)
12425 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12427 return widget->priv->hexpand_set;
12431 * gtk_widget_set_hexpand_set:
12432 * @widget: the widget
12433 * @set: value for hexpand-set property
12435 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
12438 * The hexpand-set property will be set automatically when you call
12439 * gtk_widget_set_hexpand() to set hexpand, so the most likely
12440 * reason to use this function would be to unset an explicit expand
12443 * If hexpand is set, then it overrides any computed
12444 * expand value based on child widgets. If hexpand is not
12445 * set, then the expand value depends on whether any
12446 * children of the widget would like to expand.
12448 * There are few reasons to use this function, but it's here
12449 * for completeness and consistency.
12452 gtk_widget_set_hexpand_set (GtkWidget *widget,
12455 g_return_if_fail (GTK_IS_WIDGET (widget));
12457 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12462 * gtk_widget_get_vexpand:
12463 * @widget: the widget
12465 * Gets whether the widget would like any available extra vertical
12468 * See gtk_widget_get_hexpand() for more detail.
12470 * Return value: whether vexpand flag is set
12473 gtk_widget_get_vexpand (GtkWidget *widget)
12475 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12477 return widget->priv->vexpand;
12481 * gtk_widget_set_vexpand:
12482 * @widget: the widget
12483 * @expand: whether to expand
12485 * Sets whether the widget would like any available extra vertical
12488 * See gtk_widget_set_hexpand() for more detail.
12491 gtk_widget_set_vexpand (GtkWidget *widget,
12494 g_return_if_fail (GTK_IS_WIDGET (widget));
12496 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12500 * gtk_widget_get_vexpand_set:
12501 * @widget: the widget
12503 * Gets whether gtk_widget_set_vexpand() has been used to
12504 * explicitly set the expand flag on this widget.
12506 * See gtk_widget_get_hexpand_set() for more detail.
12508 * Return value: whether vexpand has been explicitly set
12511 gtk_widget_get_vexpand_set (GtkWidget *widget)
12513 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12515 return widget->priv->vexpand_set;
12519 * gtk_widget_set_vexpand_set:
12520 * @widget: the widget
12521 * @set: value for vexpand-set property
12523 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12526 * See gtk_widget_set_hexpand_set() for more detail.
12529 gtk_widget_set_vexpand_set (GtkWidget *widget,
12532 g_return_if_fail (GTK_IS_WIDGET (widget));
12534 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12538 * GtkBuildable implementation
12540 static GQuark quark_builder_has_default = 0;
12541 static GQuark quark_builder_has_focus = 0;
12542 static GQuark quark_builder_atk_relations = 0;
12543 static GQuark quark_builder_set_name = 0;
12546 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12548 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12549 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12550 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12551 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12553 iface->set_name = gtk_widget_buildable_set_name;
12554 iface->get_name = gtk_widget_buildable_get_name;
12555 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12556 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12557 iface->parser_finished = gtk_widget_buildable_parser_finished;
12558 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12559 iface->custom_finished = gtk_widget_buildable_custom_finished;
12563 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12566 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12567 g_strdup (name), g_free);
12570 static const gchar *
12571 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12573 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12577 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12578 GtkBuilder *builder,
12579 const gchar *childname)
12581 if (strcmp (childname, "accessible") == 0)
12582 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12588 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12589 GtkBuilder *builder,
12591 const GValue *value)
12593 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12594 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12595 GINT_TO_POINTER (TRUE));
12596 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12597 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12598 GINT_TO_POINTER (TRUE));
12600 g_object_set_property (G_OBJECT (buildable), name, value);
12605 gchar *action_name;
12606 GString *description;
12608 gboolean translatable;
12618 free_action (AtkActionData *data, gpointer user_data)
12620 g_free (data->action_name);
12621 g_string_free (data->description, TRUE);
12622 g_free (data->context);
12623 g_slice_free (AtkActionData, data);
12627 free_relation (AtkRelationData *data, gpointer user_data)
12629 g_free (data->target);
12630 g_free (data->type);
12631 g_slice_free (AtkRelationData, data);
12635 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12636 GtkBuilder *builder)
12638 GSList *atk_relations;
12640 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12641 gtk_widget_grab_default (GTK_WIDGET (buildable));
12642 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12643 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12645 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12646 quark_builder_atk_relations);
12649 AtkObject *accessible;
12650 AtkRelationSet *relation_set;
12653 AtkRelationType relation_type;
12654 AtkObject *target_accessible;
12656 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12657 relation_set = atk_object_ref_relation_set (accessible);
12659 for (l = atk_relations; l; l = l->next)
12661 AtkRelationData *relation = (AtkRelationData*)l->data;
12663 target = gtk_builder_get_object (builder, relation->target);
12666 g_warning ("Target object %s in <relation> does not exist",
12670 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12671 g_assert (target_accessible != NULL);
12673 relation_type = atk_relation_type_for_name (relation->type);
12674 if (relation_type == ATK_RELATION_NULL)
12676 g_warning ("<relation> type %s not found",
12680 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12681 target_accessible);
12683 g_object_unref (relation_set);
12685 g_slist_free_full (atk_relations, (GDestroyNotify) free_relation);
12686 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12695 } AccessibilitySubParserData;
12698 accessibility_start_element (GMarkupParseContext *context,
12699 const gchar *element_name,
12700 const gchar **names,
12701 const gchar **values,
12702 gpointer user_data,
12705 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12707 gint line_number, char_number;
12709 if (strcmp (element_name, "relation") == 0)
12711 gchar *target = NULL;
12712 gchar *type = NULL;
12713 AtkRelationData *relation;
12715 for (i = 0; names[i]; i++)
12717 if (strcmp (names[i], "target") == 0)
12718 target = g_strdup (values[i]);
12719 else if (strcmp (names[i], "type") == 0)
12720 type = g_strdup (values[i]);
12723 g_markup_parse_context_get_position (context,
12726 g_set_error (error,
12728 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12729 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12731 line_number, char_number, names[i], "relation");
12738 if (!target || !type)
12740 g_markup_parse_context_get_position (context,
12743 g_set_error (error,
12745 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12746 "%s:%d:%d <%s> requires attribute \"%s\"",
12748 line_number, char_number, "relation",
12749 type ? "target" : "type");
12755 relation = g_slice_new (AtkRelationData);
12756 relation->target = target;
12757 relation->type = type;
12759 data->relations = g_slist_prepend (data->relations, relation);
12761 else if (strcmp (element_name, "action") == 0)
12763 const gchar *action_name = NULL;
12764 const gchar *description = NULL;
12765 const gchar *msg_context = NULL;
12766 gboolean translatable = FALSE;
12767 AtkActionData *action;
12769 for (i = 0; names[i]; i++)
12771 if (strcmp (names[i], "action_name") == 0)
12772 action_name = values[i];
12773 else if (strcmp (names[i], "description") == 0)
12774 description = values[i];
12775 else if (strcmp (names[i], "translatable") == 0)
12777 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12780 else if (strcmp (names[i], "comments") == 0)
12782 /* do nothing, comments are for translators */
12784 else if (strcmp (names[i], "context") == 0)
12785 msg_context = values[i];
12788 g_markup_parse_context_get_position (context,
12791 g_set_error (error,
12793 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12794 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12796 line_number, char_number, names[i], "action");
12803 g_markup_parse_context_get_position (context,
12806 g_set_error (error,
12808 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12809 "%s:%d:%d <%s> requires attribute \"%s\"",
12811 line_number, char_number, "action",
12816 action = g_slice_new (AtkActionData);
12817 action->action_name = g_strdup (action_name);
12818 action->description = g_string_new (description);
12819 action->context = g_strdup (msg_context);
12820 action->translatable = translatable;
12822 data->actions = g_slist_prepend (data->actions, action);
12824 else if (strcmp (element_name, "accessibility") == 0)
12827 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12831 accessibility_text (GMarkupParseContext *context,
12834 gpointer user_data,
12837 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12839 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12841 AtkActionData *action = data->actions->data;
12843 g_string_append_len (action->description, text, text_len);
12847 static const GMarkupParser accessibility_parser =
12849 accessibility_start_element,
12851 accessibility_text,
12860 } AccelGroupParserData;
12863 accel_group_start_element (GMarkupParseContext *context,
12864 const gchar *element_name,
12865 const gchar **names,
12866 const gchar **values,
12867 gpointer user_data,
12872 guint modifiers = 0;
12873 gchar *signal = NULL;
12874 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12876 for (i = 0; names[i]; i++)
12878 if (strcmp (names[i], "key") == 0)
12879 key = gdk_keyval_from_name (values[i]);
12880 else if (strcmp (names[i], "modifiers") == 0)
12882 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12888 else if (strcmp (names[i], "signal") == 0)
12889 signal = g_strdup (values[i]);
12892 if (key == 0 || signal == NULL)
12894 g_warning ("<accelerator> requires key and signal attributes");
12897 parser_data->key = key;
12898 parser_data->modifiers = modifiers;
12899 parser_data->signal = signal;
12902 static const GMarkupParser accel_group_parser =
12904 accel_group_start_element,
12913 style_start_element (GMarkupParseContext *context,
12914 const gchar *element_name,
12915 const gchar **names,
12916 const gchar **values,
12917 gpointer user_data,
12920 StyleParserData *style_data = (StyleParserData *)user_data;
12923 if (strcmp (element_name, "class") == 0)
12925 if (g_markup_collect_attributes (element_name,
12929 G_MARKUP_COLLECT_STRDUP, "name", &class_name,
12930 G_MARKUP_COLLECT_INVALID))
12932 style_data->classes = g_slist_append (style_data->classes, class_name);
12935 else if (strcmp (element_name, "style") == 0)
12938 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12941 static const GMarkupParser style_parser =
12943 style_start_element,
12947 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12948 GtkBuilder *builder,
12950 const gchar *tagname,
12951 GMarkupParser *parser,
12954 g_assert (buildable);
12956 if (strcmp (tagname, "accelerator") == 0)
12958 AccelGroupParserData *parser_data;
12960 parser_data = g_slice_new0 (AccelGroupParserData);
12961 parser_data->object = g_object_ref (buildable);
12962 *parser = accel_group_parser;
12963 *data = parser_data;
12966 if (strcmp (tagname, "accessibility") == 0)
12968 AccessibilitySubParserData *parser_data;
12970 parser_data = g_slice_new0 (AccessibilitySubParserData);
12971 *parser = accessibility_parser;
12972 *data = parser_data;
12975 if (strcmp (tagname, "style") == 0)
12977 StyleParserData *parser_data;
12979 parser_data = g_slice_new0 (StyleParserData);
12980 *parser = style_parser;
12981 *data = parser_data;
12989 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12990 GtkWidget *toplevel,
12991 gpointer user_data)
12993 AccelGroupParserData *accel_data;
12994 GSList *accel_groups;
12995 GtkAccelGroup *accel_group;
12997 g_return_if_fail (GTK_IS_WIDGET (widget));
12998 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12999 g_return_if_fail (user_data != NULL);
13001 accel_data = (AccelGroupParserData*)user_data;
13002 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
13003 if (g_slist_length (accel_groups) == 0)
13005 accel_group = gtk_accel_group_new ();
13006 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
13010 g_assert (g_slist_length (accel_groups) == 1);
13011 accel_group = g_slist_nth_data (accel_groups, 0);
13014 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
13015 accel_data->signal,
13018 accel_data->modifiers,
13019 GTK_ACCEL_VISIBLE);
13021 g_object_unref (accel_data->object);
13022 g_free (accel_data->signal);
13023 g_slice_free (AccelGroupParserData, accel_data);
13027 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
13028 GtkBuilder *builder,
13030 const gchar *tagname,
13031 gpointer user_data)
13033 if (strcmp (tagname, "accelerator") == 0)
13035 AccelGroupParserData *accel_data;
13036 GtkWidget *toplevel;
13038 accel_data = (AccelGroupParserData*)user_data;
13039 g_assert (accel_data->object);
13041 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
13043 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
13045 else if (strcmp (tagname, "accessibility") == 0)
13047 AccessibilitySubParserData *a11y_data;
13049 a11y_data = (AccessibilitySubParserData*)user_data;
13051 if (a11y_data->actions)
13053 AtkObject *accessible;
13058 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
13060 if (ATK_IS_ACTION (accessible))
13062 action = ATK_ACTION (accessible);
13063 n_actions = atk_action_get_n_actions (action);
13065 for (l = a11y_data->actions; l; l = l->next)
13067 AtkActionData *action_data = (AtkActionData*)l->data;
13069 for (i = 0; i < n_actions; i++)
13070 if (strcmp (atk_action_get_name (action, i),
13071 action_data->action_name) == 0)
13076 gchar *description;
13078 if (action_data->translatable && action_data->description->len)
13079 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
13080 action_data->context,
13081 action_data->description->str);
13083 description = action_data->description->str;
13085 atk_action_set_description (action, i, description);
13090 g_warning ("accessibility action on a widget that does not implement AtkAction");
13092 g_slist_free_full (a11y_data->actions, (GDestroyNotify) free_action);
13095 if (a11y_data->relations)
13096 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
13097 a11y_data->relations);
13099 g_slice_free (AccessibilitySubParserData, a11y_data);
13101 else if (strcmp (tagname, "style") == 0)
13103 StyleParserData *style_data = (StyleParserData *)user_data;
13104 GtkStyleContext *context;
13107 context = gtk_widget_get_style_context (GTK_WIDGET (buildable));
13109 for (l = style_data->classes; l; l = l->next)
13110 gtk_style_context_add_class (context, (const gchar *)l->data);
13112 gtk_widget_reset_style (GTK_WIDGET (buildable));
13114 g_slist_free_full (style_data->classes, g_free);
13115 g_slice_free (StyleParserData, style_data);
13119 static GtkSizeRequestMode
13120 gtk_widget_real_get_request_mode (GtkWidget *widget)
13122 /* By default widgets dont trade size at all. */
13123 return GTK_SIZE_REQUEST_CONSTANT_SIZE;
13127 gtk_widget_real_get_width (GtkWidget *widget,
13128 gint *minimum_size,
13129 gint *natural_size)
13139 gtk_widget_real_get_height (GtkWidget *widget,
13140 gint *minimum_size,
13141 gint *natural_size)
13151 gtk_widget_real_get_height_for_width (GtkWidget *widget,
13153 gint *minimum_height,
13154 gint *natural_height)
13156 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
13160 gtk_widget_real_get_width_for_height (GtkWidget *widget,
13162 gint *minimum_width,
13163 gint *natural_width)
13165 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
13169 * gtk_widget_get_halign:
13170 * @widget: a #GtkWidget
13172 * Gets the value of the #GtkWidget:halign property.
13174 * Returns: the horizontal alignment of @widget
13177 gtk_widget_get_halign (GtkWidget *widget)
13179 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13180 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
13184 * gtk_widget_set_halign:
13185 * @widget: a #GtkWidget
13186 * @align: the horizontal alignment
13188 * Sets the horizontal alignment of @widget.
13189 * See the #GtkWidget:halign property.
13192 gtk_widget_set_halign (GtkWidget *widget,
13195 GtkWidgetAuxInfo *aux_info;
13197 g_return_if_fail (GTK_IS_WIDGET (widget));
13199 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13201 if (aux_info->halign == align)
13204 aux_info->halign = align;
13205 gtk_widget_queue_resize (widget);
13206 g_object_notify (G_OBJECT (widget), "halign");
13210 * gtk_widget_get_valign:
13211 * @widget: a #GtkWidget
13213 * Gets the value of the #GtkWidget:valign property.
13215 * Returns: the vertical alignment of @widget
13218 gtk_widget_get_valign (GtkWidget *widget)
13220 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
13221 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
13225 * gtk_widget_set_valign:
13226 * @widget: a #GtkWidget
13227 * @align: the vertical alignment
13229 * Sets the vertical alignment of @widget.
13230 * See the #GtkWidget:valign property.
13233 gtk_widget_set_valign (GtkWidget *widget,
13236 GtkWidgetAuxInfo *aux_info;
13238 g_return_if_fail (GTK_IS_WIDGET (widget));
13240 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13242 if (aux_info->valign == align)
13245 aux_info->valign = align;
13246 gtk_widget_queue_resize (widget);
13247 g_object_notify (G_OBJECT (widget), "valign");
13251 * gtk_widget_get_margin_left:
13252 * @widget: a #GtkWidget
13254 * Gets the value of the #GtkWidget:margin-left property.
13256 * Returns: The left margin of @widget
13261 gtk_widget_get_margin_left (GtkWidget *widget)
13263 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13265 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
13269 * gtk_widget_set_margin_left:
13270 * @widget: a #GtkWidget
13271 * @margin: the left margin
13273 * Sets the left margin of @widget.
13274 * See the #GtkWidget:margin-left property.
13279 gtk_widget_set_margin_left (GtkWidget *widget,
13282 GtkWidgetAuxInfo *aux_info;
13284 g_return_if_fail (GTK_IS_WIDGET (widget));
13285 g_return_if_fail (margin <= G_MAXINT16);
13287 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13289 if (aux_info->margin.left == margin)
13292 aux_info->margin.left = margin;
13293 gtk_widget_queue_resize (widget);
13294 g_object_notify (G_OBJECT (widget), "margin-left");
13298 * gtk_widget_get_margin_right:
13299 * @widget: a #GtkWidget
13301 * Gets the value of the #GtkWidget:margin-right property.
13303 * Returns: The right margin of @widget
13308 gtk_widget_get_margin_right (GtkWidget *widget)
13310 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13312 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
13316 * gtk_widget_set_margin_right:
13317 * @widget: a #GtkWidget
13318 * @margin: the right margin
13320 * Sets the right margin of @widget.
13321 * See the #GtkWidget:margin-right property.
13326 gtk_widget_set_margin_right (GtkWidget *widget,
13329 GtkWidgetAuxInfo *aux_info;
13331 g_return_if_fail (GTK_IS_WIDGET (widget));
13332 g_return_if_fail (margin <= G_MAXINT16);
13334 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13336 if (aux_info->margin.right == margin)
13339 aux_info->margin.right = margin;
13340 gtk_widget_queue_resize (widget);
13341 g_object_notify (G_OBJECT (widget), "margin-right");
13345 * gtk_widget_get_margin_top:
13346 * @widget: a #GtkWidget
13348 * Gets the value of the #GtkWidget:margin-top property.
13350 * Returns: The top margin of @widget
13355 gtk_widget_get_margin_top (GtkWidget *widget)
13357 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13359 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
13363 * gtk_widget_set_margin_top:
13364 * @widget: a #GtkWidget
13365 * @margin: the top margin
13367 * Sets the top margin of @widget.
13368 * See the #GtkWidget:margin-top property.
13373 gtk_widget_set_margin_top (GtkWidget *widget,
13376 GtkWidgetAuxInfo *aux_info;
13378 g_return_if_fail (GTK_IS_WIDGET (widget));
13379 g_return_if_fail (margin <= G_MAXINT16);
13381 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13383 if (aux_info->margin.top == margin)
13386 aux_info->margin.top = margin;
13387 gtk_widget_queue_resize (widget);
13388 g_object_notify (G_OBJECT (widget), "margin-top");
13392 * gtk_widget_get_margin_bottom:
13393 * @widget: a #GtkWidget
13395 * Gets the value of the #GtkWidget:margin-bottom property.
13397 * Returns: The bottom margin of @widget
13402 gtk_widget_get_margin_bottom (GtkWidget *widget)
13404 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13406 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
13410 * gtk_widget_set_margin_bottom:
13411 * @widget: a #GtkWidget
13412 * @margin: the bottom margin
13414 * Sets the bottom margin of @widget.
13415 * See the #GtkWidget:margin-bottom property.
13420 gtk_widget_set_margin_bottom (GtkWidget *widget,
13423 GtkWidgetAuxInfo *aux_info;
13425 g_return_if_fail (GTK_IS_WIDGET (widget));
13426 g_return_if_fail (margin <= G_MAXINT16);
13428 aux_info = gtk_widget_get_aux_info (widget, TRUE);
13430 if (aux_info->margin.bottom == margin)
13433 aux_info->margin.bottom = margin;
13434 gtk_widget_queue_resize (widget);
13435 g_object_notify (G_OBJECT (widget), "margin-bottom");
13439 * gtk_widget_get_clipboard:
13440 * @widget: a #GtkWidget
13441 * @selection: a #GdkAtom which identifies the clipboard
13442 * to use. %GDK_SELECTION_CLIPBOARD gives the
13443 * default clipboard. Another common value
13444 * is %GDK_SELECTION_PRIMARY, which gives
13445 * the primary X selection.
13447 * Returns the clipboard object for the given selection to
13448 * be used with @widget. @widget must have a #GdkDisplay
13449 * associated with it, so must be attached to a toplevel
13452 * Return value: (transfer none): the appropriate clipboard object. If no
13453 * clipboard already exists, a new one will
13454 * be created. Once a clipboard object has
13455 * been created, it is persistent for all time.
13460 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
13462 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13463 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
13465 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
13470 * gtk_widget_list_mnemonic_labels:
13471 * @widget: a #GtkWidget
13473 * Returns a newly allocated list of the widgets, normally labels, for
13474 * which this widget is the target of a mnemonic (see for example,
13475 * gtk_label_set_mnemonic_widget()).
13477 * The widgets in the list are not individually referenced. If you
13478 * want to iterate through the list and perform actions involving
13479 * callbacks that might destroy the widgets, you
13480 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
13481 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
13482 * widgets afterwards.
13484 * Return value: (element-type GtkWidget) (transfer container): the list of
13485 * mnemonic labels; free this list
13486 * with g_list_free() when you are done with it.
13491 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
13493 GList *list = NULL;
13496 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13498 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
13499 list = g_list_prepend (list, l->data);
13505 * gtk_widget_add_mnemonic_label:
13506 * @widget: a #GtkWidget
13507 * @label: a #GtkWidget that acts as a mnemonic label for @widget
13509 * Adds a widget to the list of mnemonic labels for
13510 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
13511 * list of mnemonic labels for the widget is cleared when the
13512 * widget is destroyed, so the caller must make sure to update
13513 * its internal state at this point as well, by using a connection
13514 * to the #GtkWidget::destroy signal or a weak notifier.
13519 gtk_widget_add_mnemonic_label (GtkWidget *widget,
13522 GSList *old_list, *new_list;
13524 g_return_if_fail (GTK_IS_WIDGET (widget));
13525 g_return_if_fail (GTK_IS_WIDGET (label));
13527 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13528 new_list = g_slist_prepend (old_list, label);
13530 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13531 new_list, (GDestroyNotify) g_slist_free);
13535 * gtk_widget_remove_mnemonic_label:
13536 * @widget: a #GtkWidget
13537 * @label: a #GtkWidget that was previously set as a mnemnic label for
13538 * @widget with gtk_widget_add_mnemonic_label().
13540 * Removes a widget from the list of mnemonic labels for
13541 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
13542 * must have previously been added to the list with
13543 * gtk_widget_add_mnemonic_label().
13548 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13551 GSList *old_list, *new_list;
13553 g_return_if_fail (GTK_IS_WIDGET (widget));
13554 g_return_if_fail (GTK_IS_WIDGET (label));
13556 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13557 new_list = g_slist_remove (old_list, label);
13560 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13561 new_list, (GDestroyNotify) g_slist_free);
13565 * gtk_widget_get_no_show_all:
13566 * @widget: a #GtkWidget
13568 * Returns the current value of the #GtkWidget:no-show-all property,
13569 * which determines whether calls to gtk_widget_show_all()
13570 * will affect this widget.
13572 * Return value: the current value of the "no-show-all" property.
13577 gtk_widget_get_no_show_all (GtkWidget *widget)
13579 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13581 return widget->priv->no_show_all;
13585 * gtk_widget_set_no_show_all:
13586 * @widget: a #GtkWidget
13587 * @no_show_all: the new value for the "no-show-all" property
13589 * Sets the #GtkWidget:no-show-all property, which determines whether
13590 * calls to gtk_widget_show_all() will affect this widget.
13592 * This is mostly for use in constructing widget hierarchies with externally
13593 * controlled visibility, see #GtkUIManager.
13598 gtk_widget_set_no_show_all (GtkWidget *widget,
13599 gboolean no_show_all)
13601 g_return_if_fail (GTK_IS_WIDGET (widget));
13603 no_show_all = (no_show_all != FALSE);
13605 if (widget->priv->no_show_all != no_show_all)
13607 widget->priv->no_show_all = no_show_all;
13609 g_object_notify (G_OBJECT (widget), "no-show-all");
13615 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13616 gboolean has_tooltip,
13619 GtkWidgetPrivate *priv = widget->priv;
13620 gboolean priv_has_tooltip;
13622 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13623 quark_has_tooltip));
13625 if (priv_has_tooltip != has_tooltip || force)
13627 priv_has_tooltip = has_tooltip;
13629 if (priv_has_tooltip)
13631 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13632 gdk_window_set_events (priv->window,
13633 gdk_window_get_events (priv->window) |
13634 GDK_LEAVE_NOTIFY_MASK |
13635 GDK_POINTER_MOTION_MASK |
13636 GDK_POINTER_MOTION_HINT_MASK);
13638 if (gtk_widget_get_has_window (widget))
13639 gtk_widget_add_events (widget,
13640 GDK_LEAVE_NOTIFY_MASK |
13641 GDK_POINTER_MOTION_MASK |
13642 GDK_POINTER_MOTION_HINT_MASK);
13645 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13646 GUINT_TO_POINTER (priv_has_tooltip));
13651 * gtk_widget_set_tooltip_window:
13652 * @widget: a #GtkWidget
13653 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13655 * Replaces the default, usually yellow, window used for displaying
13656 * tooltips with @custom_window. GTK+ will take care of showing and
13657 * hiding @custom_window at the right moment, to behave likewise as
13658 * the default tooltip window. If @custom_window is %NULL, the default
13659 * tooltip window will be used.
13661 * If the custom window should have the default theming it needs to
13662 * have the name "gtk-tooltip", see gtk_widget_set_name().
13667 gtk_widget_set_tooltip_window (GtkWidget *widget,
13668 GtkWindow *custom_window)
13670 gboolean has_tooltip;
13671 gchar *tooltip_markup;
13673 g_return_if_fail (GTK_IS_WIDGET (widget));
13674 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13676 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13679 g_object_ref (custom_window);
13681 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13682 custom_window, g_object_unref);
13684 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13685 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13687 if (has_tooltip && gtk_widget_get_visible (widget))
13688 gtk_widget_queue_tooltip_query (widget);
13692 * gtk_widget_get_tooltip_window:
13693 * @widget: a #GtkWidget
13695 * Returns the #GtkWindow of the current tooltip. This can be the
13696 * GtkWindow created by default, or the custom tooltip window set
13697 * using gtk_widget_set_tooltip_window().
13699 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13704 gtk_widget_get_tooltip_window (GtkWidget *widget)
13706 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13708 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13712 * gtk_widget_trigger_tooltip_query:
13713 * @widget: a #GtkWidget
13715 * Triggers a tooltip query on the display where the toplevel of @widget
13716 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13722 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13724 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13727 static guint tooltip_query_id;
13728 static GSList *tooltip_query_displays;
13731 tooltip_query_idle (gpointer data)
13733 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13734 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13735 g_slist_free (tooltip_query_displays);
13737 tooltip_query_displays = NULL;
13738 tooltip_query_id = 0;
13744 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13746 GdkDisplay *display;
13748 display = gtk_widget_get_display (widget);
13750 if (!g_slist_find (tooltip_query_displays, display))
13751 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13753 if (tooltip_query_id == 0)
13754 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13758 * gtk_widget_set_tooltip_text:
13759 * @widget: a #GtkWidget
13760 * @text: (allow-none): the contents of the tooltip for @widget
13762 * Sets @text as the contents of the tooltip. This function will take
13763 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13764 * handler for the #GtkWidget::query-tooltip signal.
13766 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13771 gtk_widget_set_tooltip_text (GtkWidget *widget,
13774 g_return_if_fail (GTK_IS_WIDGET (widget));
13776 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13780 * gtk_widget_get_tooltip_text:
13781 * @widget: a #GtkWidget
13783 * Gets the contents of the tooltip for @widget.
13785 * Return value: the tooltip text, or %NULL. You should free the
13786 * returned string with g_free() when done.
13791 gtk_widget_get_tooltip_text (GtkWidget *widget)
13793 gchar *text = NULL;
13795 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13797 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13803 * gtk_widget_set_tooltip_markup:
13804 * @widget: a #GtkWidget
13805 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13807 * Sets @markup as the contents of the tooltip, which is marked up with
13808 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13810 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13811 * and of the default handler for the #GtkWidget::query-tooltip signal.
13813 * See also the #GtkWidget:tooltip-markup property and
13814 * gtk_tooltip_set_markup().
13819 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13820 const gchar *markup)
13822 g_return_if_fail (GTK_IS_WIDGET (widget));
13824 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13828 * gtk_widget_get_tooltip_markup:
13829 * @widget: a #GtkWidget
13831 * Gets the contents of the tooltip for @widget.
13833 * Return value: the tooltip text, or %NULL. You should free the
13834 * returned string with g_free() when done.
13839 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13841 gchar *text = NULL;
13843 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13845 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13851 * gtk_widget_set_has_tooltip:
13852 * @widget: a #GtkWidget
13853 * @has_tooltip: whether or not @widget has a tooltip.
13855 * Sets the has-tooltip property on @widget to @has_tooltip. See
13856 * #GtkWidget:has-tooltip for more information.
13861 gtk_widget_set_has_tooltip (GtkWidget *widget,
13862 gboolean has_tooltip)
13864 g_return_if_fail (GTK_IS_WIDGET (widget));
13866 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13870 * gtk_widget_get_has_tooltip:
13871 * @widget: a #GtkWidget
13873 * Returns the current value of the has-tooltip property. See
13874 * #GtkWidget:has-tooltip for more information.
13876 * Return value: current value of has-tooltip on @widget.
13881 gtk_widget_get_has_tooltip (GtkWidget *widget)
13883 gboolean has_tooltip = FALSE;
13885 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13887 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13889 return has_tooltip;
13893 * gtk_widget_get_allocation:
13894 * @widget: a #GtkWidget
13895 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13897 * Retrieves the widget's allocation.
13899 * Note, when implementing a #GtkContainer: a widget's allocation will
13900 * be its "adjusted" allocation, that is, the widget's parent
13901 * container typically calls gtk_widget_size_allocate() with an
13902 * allocation, and that allocation is then adjusted (to handle margin
13903 * and alignment for example) before assignment to the widget.
13904 * gtk_widget_get_allocation() returns the adjusted allocation that
13905 * was actually assigned to the widget. The adjusted allocation is
13906 * guaranteed to be completely contained within the
13907 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13908 * is guaranteed that its children stay inside the assigned bounds,
13909 * but not that they have exactly the bounds the container assigned.
13910 * There is no way to get the original allocation assigned by
13911 * gtk_widget_size_allocate(), since it isn't stored; if a container
13912 * implementation needs that information it will have to track it itself.
13917 gtk_widget_get_allocation (GtkWidget *widget,
13918 GtkAllocation *allocation)
13920 GtkWidgetPrivate *priv;
13922 g_return_if_fail (GTK_IS_WIDGET (widget));
13923 g_return_if_fail (allocation != NULL);
13925 priv = widget->priv;
13927 *allocation = priv->allocation;
13931 * gtk_widget_set_allocation:
13932 * @widget: a #GtkWidget
13933 * @allocation: a pointer to a #GtkAllocation to copy from
13935 * Sets the widget's allocation. This should not be used
13936 * directly, but from within a widget's size_allocate method.
13938 * The allocation set should be the "adjusted" or actual
13939 * allocation. If you're implementing a #GtkContainer, you want to use
13940 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13941 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13942 * allocation inside gtk_widget_size_allocate() to create an adjusted
13948 gtk_widget_set_allocation (GtkWidget *widget,
13949 const GtkAllocation *allocation)
13951 GtkWidgetPrivate *priv;
13953 g_return_if_fail (GTK_IS_WIDGET (widget));
13954 g_return_if_fail (gtk_widget_get_visible (widget) || gtk_widget_is_toplevel (widget));
13955 g_return_if_fail (allocation != NULL);
13957 priv = widget->priv;
13959 priv->allocation = *allocation;
13963 * gtk_widget_get_allocated_width:
13964 * @widget: the widget to query
13966 * Returns the width that has currently been allocated to @widget.
13967 * This function is intended to be used when implementing handlers
13968 * for the #GtkWidget::draw function.
13970 * Returns: the width of the @widget
13973 gtk_widget_get_allocated_width (GtkWidget *widget)
13975 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13977 return widget->priv->allocation.width;
13981 * gtk_widget_get_allocated_height:
13982 * @widget: the widget to query
13984 * Returns the height that has currently been allocated to @widget.
13985 * This function is intended to be used when implementing handlers
13986 * for the #GtkWidget::draw function.
13988 * Returns: the height of the @widget
13991 gtk_widget_get_allocated_height (GtkWidget *widget)
13993 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13995 return widget->priv->allocation.height;
13999 * gtk_widget_get_requisition:
14000 * @widget: a #GtkWidget
14001 * @requisition: (out): a pointer to a #GtkRequisition to copy to
14003 * Retrieves the widget's requisition.
14005 * This function should only be used by widget implementations in
14006 * order to figure whether the widget's requisition has actually
14007 * changed after some internal state change (so that they can call
14008 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
14010 * Normally, gtk_widget_size_request() should be used.
14014 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
14015 * removed, If you need to cache sizes across requests and allocations,
14016 * add an explicit cache to the widget in question instead.
14019 gtk_widget_get_requisition (GtkWidget *widget,
14020 GtkRequisition *requisition)
14022 g_return_if_fail (GTK_IS_WIDGET (widget));
14023 g_return_if_fail (requisition != NULL);
14025 gtk_widget_get_preferred_size (widget, requisition, NULL);
14029 * gtk_widget_set_window:
14030 * @widget: a #GtkWidget
14031 * @window: (transfer full): a #GdkWindow
14033 * Sets a widget's window. This function should only be used in a
14034 * widget's #GtkWidget::realize implementation. The %window passed is
14035 * usually either new window created with gdk_window_new(), or the
14036 * window of its parent widget as returned by
14037 * gtk_widget_get_parent_window().
14039 * Widgets must indicate whether they will create their own #GdkWindow
14040 * by calling gtk_widget_set_has_window(). This is usually done in the
14041 * widget's init() function.
14043 * <note><para>This function does not add any reference to @window.</para></note>
14048 gtk_widget_set_window (GtkWidget *widget,
14051 GtkWidgetPrivate *priv;
14053 g_return_if_fail (GTK_IS_WIDGET (widget));
14054 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
14056 priv = widget->priv;
14058 if (priv->window != window)
14060 priv->window = window;
14062 if (gtk_widget_get_has_window (widget) && window != NULL && !gdk_window_has_native (window))
14063 gdk_window_set_opacity (window,
14064 priv->norender ? 0 : priv->alpha / 255.0);
14066 g_object_notify (G_OBJECT (widget), "window");
14071 * gtk_widget_register_window:
14072 * @widget: a #GtkWidget
14073 * @window: a #GdkWindow
14075 * Registers a #GdkWindow with the widget and sets it up so that
14076 * the widget recieves events for it. Call gtk_widget_unregister_window()
14077 * when destroying the window.
14079 * Before 3.8 you needed to call gdk_window_set_user_data() directly to set
14080 * this up. This is now deprecated and you should use gtk_widget_register_window()
14081 * instead. Old code will keep working as is, although some new features like
14082 * transparency might not work perfectly.
14087 gtk_widget_register_window (GtkWidget *widget,
14090 GtkWidgetPrivate *priv;
14091 gpointer user_data;
14093 g_return_if_fail (GTK_IS_WIDGET (widget));
14094 g_return_if_fail (GDK_IS_WINDOW (window));
14096 gdk_window_get_user_data (window, &user_data);
14097 g_assert (user_data == NULL);
14099 priv = widget->priv;
14101 gdk_window_set_user_data (window, widget);
14102 priv->registered_windows = g_list_prepend (priv->registered_windows, window);
14104 if (priv->window != window && !gdk_window_has_native (window))
14105 gdk_window_set_opacity (window,
14106 priv->norender_children ? 0.0 : 1.0);
14110 * gtk_widget_unregister_window:
14111 * @widget: a #GtkWidget
14112 * @window: a #GdkWindow
14114 * Unregisters a #GdkWindow from the widget that was previously set up with
14115 * gtk_widget_register_window(). You need to call this when the window is
14116 * no longer used by the widget, such as when you destroy it.
14121 gtk_widget_unregister_window (GtkWidget *widget,
14124 GtkWidgetPrivate *priv;
14125 gpointer user_data;
14127 g_return_if_fail (GTK_IS_WIDGET (widget));
14128 g_return_if_fail (GDK_IS_WINDOW (window));
14130 priv = widget->priv;
14132 gdk_window_get_user_data (window, &user_data);
14133 g_assert (user_data == widget);
14134 gdk_window_set_user_data (window, NULL);
14135 priv->registered_windows = g_list_remove (priv->registered_windows, window);
14139 * gtk_widget_get_window:
14140 * @widget: a #GtkWidget
14142 * Returns the widget's window if it is realized, %NULL otherwise
14144 * Return value: (transfer none): @widget's window.
14149 gtk_widget_get_window (GtkWidget *widget)
14151 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14153 return widget->priv->window;
14157 * gtk_widget_get_support_multidevice:
14158 * @widget: a #GtkWidget
14160 * Returns %TRUE if @widget is multiple pointer aware. See
14161 * gtk_widget_set_support_multidevice() for more information.
14163 * Returns: %TRUE if @widget is multidevice aware.
14166 gtk_widget_get_support_multidevice (GtkWidget *widget)
14168 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14170 return widget->priv->multidevice;
14174 * gtk_widget_set_support_multidevice:
14175 * @widget: a #GtkWidget
14176 * @support_multidevice: %TRUE to support input from multiple devices.
14178 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
14179 * @widget will start receiving multiple, per device enter/leave events. Note
14180 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
14181 * gdk_window_set_support_multidevice() will have to be called manually on them.
14186 gtk_widget_set_support_multidevice (GtkWidget *widget,
14187 gboolean support_multidevice)
14189 GtkWidgetPrivate *priv;
14191 g_return_if_fail (GTK_IS_WIDGET (widget));
14193 priv = widget->priv;
14194 priv->multidevice = (support_multidevice == TRUE);
14196 if (gtk_widget_get_realized (widget))
14197 gdk_window_set_support_multidevice (priv->window, support_multidevice);
14200 /* There are multiple alpha related sources. First of all the user can specify alpha
14201 * in gtk_widget_set_opacity, secondly we can get it from the css opacity. These two
14202 * are multiplied together to form the total alpha. Secondly, the user can specify
14203 * an opacity group for a widget, which means we must essentially handle it as having alpha.
14205 * We handle opacity in two ways. For a windowed widget, with opacity set but no opacity
14206 * group we directly set the opacity of widget->window. This will cause gdk to properly
14207 * redirect drawing inside the window to a buffer and do OVER paint_with_alpha.
14209 * However, if the widget is not windowed, or the user specified an opacity group for the
14210 * widget we do the opacity handling in the ::draw marshaller for the widget. A naive
14211 * implementation of this would break for windowed widgets or descendant widgets with
14212 * windows, as these would not be handled by the ::draw signal. To handle this we set
14213 * all such gdkwindows as fully transparent and then override gtk_cairo_should_draw_window()
14214 * to make the draw signal propagate to *all* child widgets/windows.
14216 * Note: We don't make all child windows fully transparent, we stop at the first one
14217 * in each branch when propagating down the hierarchy.
14221 /* This is called when priv->alpha or priv->opacity_group group changes, and should
14222 * update priv->norender and GdkWindow opacity for this widget and any children that
14223 * needs changing. It is also called whenver the parent changes, the parents
14224 * norender_children state changes, or the has_window state of the widget changes.
14227 gtk_widget_propagate_alpha (GtkWidget *widget)
14229 GtkWidgetPrivate *priv = widget->priv;
14231 gboolean norender, norender_children;
14234 parent = priv->parent;
14236 /* Norender affects only windowed widget and means don't render widget->window in the
14238 We only set this if the parent has norender_children, because:
14239 a) For an opacity group (that does not have a norender_children parent) we still
14240 need to render the window or we will never get an expose event.
14241 b) For alpha we set the opacity of window->widget directly, so no other
14244 norender = (parent != NULL && parent->priv->norender_children);
14246 /* windows under this widget should not render if:
14247 a) This widget has an opacity group
14248 b) This widget has alpha and is no-windowed (otherwise we'd set alpha on widget->window)
14249 c) This widget has norender but is no-windowed (a windowed widget would "swallow" the norender)
14251 norender_children =
14252 priv->opacity_group ||
14253 (!gtk_widget_get_has_window (widget) &&
14254 ( norender || priv->alpha != 255));
14256 if (gtk_widget_get_has_window (widget))
14258 if (priv->window != NULL && !gdk_window_has_native (priv->window))
14259 gdk_window_set_opacity (priv->window,
14260 norender ? 0 : priv->alpha / 255.0);
14263 for (l = priv->registered_windows; l != NULL; l = l->next)
14265 GdkWindow *w = l->data;
14266 if (w != priv->window && !gdk_window_has_native (w))
14267 gdk_window_set_opacity (w, norender_children ? 0.0 : 1.0);
14270 priv->norender = norender;
14271 if (priv->norender_children != norender_children)
14273 priv->norender_children = norender_children;
14275 if (GTK_IS_CONTAINER (widget))
14276 gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)gtk_widget_propagate_alpha, NULL);
14279 if (gtk_widget_get_realized (widget))
14280 gtk_widget_queue_draw (widget);
14284 gtk_widget_update_alpha (GtkWidget *widget)
14286 GtkWidgetPrivate *priv;
14290 priv = widget->priv;
14292 alpha = priv->user_alpha;
14297 _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context,
14298 GTK_CSS_PROPERTY_OPACITY),
14300 opacity = CLAMP (opacity, 0.0, 1.0);
14301 alpha = round (priv->user_alpha * opacity);
14304 if (alpha == priv->alpha)
14307 priv->alpha = alpha;
14309 gtk_widget_propagate_alpha (widget);
14314 gtk_widget_set_has_opacity_group (GtkWidget *widget,
14315 gboolean has_opacity_group)
14317 GtkWidgetPrivate *priv;
14319 g_return_if_fail (GTK_IS_WIDGET (widget));
14321 priv = widget->priv;
14323 has_opacity_group = !!has_opacity_group;
14325 if (priv->opacity_group == has_opacity_group)
14328 priv->opacity_group = has_opacity_group;
14330 gtk_widget_propagate_alpha (widget);
14334 * gtk_widget_set_opacity:
14335 * @widget: a #GtkWidget
14336 * @opacity: desired opacity, between 0 and 1
14338 * Request the @widget to be rendered partially transparent,
14339 * with opacity 0 being fully transparent and 1 fully opaque. (Opacity values
14340 * are clamped to the [0,1] range.).
14341 * This works on both toplevel widget, and child widgets, although there
14342 * are some limitations:
14344 * For toplevel widgets this depends on the capabilities of the windowing
14345 * system. On X11 this has any effect only on X screens with a compositing manager
14346 * running. See gtk_widget_is_composited(). On Windows it should work
14347 * always, although setting a window's opacity after the window has been
14348 * shown causes it to flicker once on Windows.
14350 * For child widgets it doesn't work if any affected widget has a native window, or
14351 * disables double buffering.
14356 gtk_widget_set_opacity (GtkWidget *widget,
14359 GtkWidgetPrivate *priv;
14362 g_return_if_fail (GTK_IS_WIDGET (widget));
14364 priv = widget->priv;
14366 opacity = CLAMP (opacity, 0.0, 1.0);
14368 alpha = round (opacity * 255);
14370 /* As a kind of hack for internal use we treat an alpha very
14371 close to 1.0 (rounds to 255) but not 1.0 as specifying that
14372 we want the opacity group behaviour wrt draw handling, but
14373 not actually an alpha value. See bug #687842 for discussions. */
14374 gtk_widget_set_has_opacity_group (widget,
14375 alpha == 255 && opacity != 1.0);
14377 if (alpha == priv->user_alpha)
14380 priv->user_alpha = alpha;
14382 gtk_widget_update_alpha (widget);
14387 * gtk_widget_get_opacity:
14388 * @widget: a #GtkWidget
14390 * Fetches the requested opacity for this widget. See
14391 * gtk_widget_set_opacity().
14393 * Return value: the requested opacity for this widget.
14398 gtk_widget_get_opacity (GtkWidget *widget)
14400 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0.0);
14402 return widget->priv->alpha / 255.0;
14406 _gtk_widget_set_has_focus (GtkWidget *widget,
14407 gboolean has_focus)
14409 widget->priv->has_focus = has_focus;
14412 gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_FOCUSED, FALSE);
14414 gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_FOCUSED);
14418 * gtk_widget_send_focus_change:
14419 * @widget: a #GtkWidget
14420 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
14422 * Sends the focus change @event to @widget
14424 * This function is not meant to be used by applications. The only time it
14425 * should be used is when it is necessary for a #GtkWidget to assign focus
14426 * to a widget that is semantically owned by the first widget even though
14427 * it's not a direct child - for instance, a search entry in a floating
14428 * window similar to the quick search in #GtkTreeView.
14430 * An example of its usage is:
14433 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
14435 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
14436 * fevent->focus_change.in = TRUE;
14437 * fevent->focus_change.window = gtk_widget_get_window (widget);
14438 * if (fevent->focus_change.window != NULL)
14439 * g_object_ref (fevent->focus_change.window);
14441 * gtk_widget_send_focus_change (widget, fevent);
14443 * gdk_event_free (event);
14446 * Return value: the return value from the event signal emission: %TRUE
14447 * if the event was handled, and %FALSE otherwise
14452 gtk_widget_send_focus_change (GtkWidget *widget,
14457 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
14458 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
14460 g_object_ref (widget);
14462 _gtk_widget_set_has_focus (widget, event->focus_change.in);
14464 res = gtk_widget_event (widget, event);
14466 g_object_notify (G_OBJECT (widget), "has-focus");
14468 g_object_unref (widget);
14474 * gtk_widget_in_destruction:
14475 * @widget: a #GtkWidget
14477 * Returns whether the widget is currently being destroyed.
14478 * This information can sometimes be used to avoid doing
14479 * unnecessary work.
14481 * Returns: %TRUE if @widget is being destroyed
14484 gtk_widget_in_destruction (GtkWidget *widget)
14486 return widget->priv->in_destruction;
14490 _gtk_widget_get_in_reparent (GtkWidget *widget)
14492 return widget->priv->in_reparent;
14496 _gtk_widget_set_in_reparent (GtkWidget *widget,
14497 gboolean in_reparent)
14499 widget->priv->in_reparent = in_reparent;
14503 _gtk_widget_get_anchored (GtkWidget *widget)
14505 return widget->priv->anchored;
14509 _gtk_widget_set_anchored (GtkWidget *widget,
14512 widget->priv->anchored = anchored;
14516 _gtk_widget_get_shadowed (GtkWidget *widget)
14518 return widget->priv->shadowed;
14522 _gtk_widget_set_shadowed (GtkWidget *widget,
14525 widget->priv->shadowed = shadowed;
14529 _gtk_widget_get_alloc_needed (GtkWidget *widget)
14531 return widget->priv->alloc_needed;
14535 _gtk_widget_set_alloc_needed (GtkWidget *widget,
14536 gboolean alloc_needed)
14538 widget->priv->alloc_needed = alloc_needed;
14542 _gtk_widget_add_sizegroup (GtkWidget *widget,
14547 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14548 groups = g_slist_prepend (groups, group);
14549 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14551 widget->priv->have_size_groups = TRUE;
14555 _gtk_widget_remove_sizegroup (GtkWidget *widget,
14560 groups = g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14561 groups = g_slist_remove (groups, group);
14562 g_object_set_qdata (G_OBJECT (widget), quark_size_groups, groups);
14564 widget->priv->have_size_groups = groups != NULL;
14568 _gtk_widget_get_sizegroups (GtkWidget *widget)
14570 if (widget->priv->have_size_groups)
14571 return g_object_get_qdata (G_OBJECT (widget), quark_size_groups);
14577 _gtk_widget_add_attached_window (GtkWidget *widget,
14580 widget->priv->attached_windows = g_list_prepend (widget->priv->attached_windows, window);
14584 _gtk_widget_remove_attached_window (GtkWidget *widget,
14587 widget->priv->attached_windows = g_list_remove (widget->priv->attached_windows, window);
14591 * gtk_widget_path_append_for_widget:
14592 * @path: a widget path
14593 * @widget: the widget to append to the widget path
14595 * Appends the data from @widget to the widget hierarchy represented
14596 * by @path. This function is a shortcut for adding information from
14597 * @widget to the given @path. This includes setting the name or
14598 * adding the style classes from @widget.
14600 * Returns: the position where the data was inserted
14605 gtk_widget_path_append_for_widget (GtkWidgetPath *path,
14610 g_return_val_if_fail (path != NULL, 0);
14611 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14613 pos = gtk_widget_path_append_type (path, G_OBJECT_TYPE (widget));
14615 if (widget->priv->name)
14616 gtk_widget_path_iter_set_name (path, pos, widget->priv->name);
14618 if (widget->priv->context)
14620 GList *classes, *l;
14622 /* Also add any persistent classes in
14623 * the style context the widget path
14625 classes = gtk_style_context_list_classes (widget->priv->context);
14627 for (l = classes; l; l = l->next)
14628 gtk_widget_path_iter_add_class (path, pos, l->data);
14630 g_list_free (classes);
14637 _gtk_widget_create_path (GtkWidget *widget)
14641 parent = widget->priv->parent;
14644 return gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
14647 /* Widget is either toplevel or unparented, treat both
14648 * as toplevels style wise, since there are situations
14649 * where style properties might be retrieved on that
14652 GtkWidget *attach_widget = NULL;
14653 GtkWidgetPath *result;
14655 if (GTK_IS_WINDOW (widget))
14656 attach_widget = gtk_window_get_attached_to (GTK_WINDOW (widget));
14658 if (attach_widget != NULL)
14659 result = gtk_widget_path_copy (gtk_widget_get_path (attach_widget));
14661 result = gtk_widget_path_new ();
14663 gtk_widget_path_append_for_widget (result, widget);
14670 * gtk_widget_get_path:
14671 * @widget: a #GtkWidget
14673 * Returns the #GtkWidgetPath representing @widget, if the widget
14674 * is not connected to a toplevel widget, a partial path will be
14677 * Returns: (transfer none): The #GtkWidgetPath representing @widget
14680 gtk_widget_get_path (GtkWidget *widget)
14682 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14684 if (!widget->priv->path)
14685 widget->priv->path = _gtk_widget_create_path (widget);
14687 return widget->priv->path;
14691 _gtk_widget_style_context_invalidated (GtkWidget *widget)
14693 if (widget->priv->path)
14695 gtk_widget_path_free (widget->priv->path);
14696 widget->priv->path = NULL;
14699 if (gtk_widget_get_realized (widget))
14700 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
14703 /* Compress all style updates so it
14704 * is only emitted once pre-realize.
14706 widget->priv->style_update_pending = TRUE;
14711 * gtk_widget_get_style_context:
14712 * @widget: a #GtkWidget
14714 * Returns the style context associated to @widget.
14716 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
14717 * must not be freed.
14720 gtk_widget_get_style_context (GtkWidget *widget)
14722 GtkWidgetPrivate *priv;
14724 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
14726 priv = widget->priv;
14728 if (G_UNLIKELY (priv->context == NULL))
14731 GdkFrameClock *frame_clock;
14733 priv->context = gtk_style_context_new ();
14735 gtk_style_context_set_state (priv->context, priv->state_flags);
14737 screen = gtk_widget_get_screen (widget);
14739 gtk_style_context_set_screen (priv->context, screen);
14741 frame_clock = gtk_widget_get_frame_clock (widget);
14743 gtk_style_context_set_frame_clock (priv->context, frame_clock);
14746 gtk_style_context_set_parent (priv->context,
14747 gtk_widget_get_style_context (priv->parent));
14749 _gtk_style_context_set_widget (priv->context, widget);
14752 return widget->priv->context;
14756 _gtk_widget_invalidate_style_context (GtkWidget *widget,
14757 GtkCssChange change)
14759 GtkWidgetPrivate *priv;
14761 priv = widget->priv;
14763 if (priv->context == NULL)
14766 _gtk_style_context_queue_invalidate (priv->context, change);
14770 * gtk_widget_get_modifier_mask:
14771 * @widget: a #GtkWidget
14772 * @intent: the use case for the modifier mask
14774 * Returns the modifier mask the @widget's windowing system backend
14775 * uses for a particular purpose.
14777 * See gdk_keymap_get_modifier_mask().
14779 * Returns: the modifier mask used for @intent.
14784 gtk_widget_get_modifier_mask (GtkWidget *widget,
14785 GdkModifierIntent intent)
14787 GdkDisplay *display;
14789 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
14791 display = gtk_widget_get_display (widget);
14793 return gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
14798 _gtk_widget_get_style (GtkWidget *widget)
14800 return widget->priv->style;
14804 _gtk_widget_set_style (GtkWidget *widget,
14807 widget->priv->style = style;
14811 _gtk_widget_update_parent_muxer (GtkWidget *widget)
14814 GActionMuxer *parent_muxer;
14816 if (widget->priv->muxer == NULL)
14819 if (GTK_IS_MENU (widget))
14820 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
14822 parent = gtk_widget_get_parent (widget);
14824 parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
14826 g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
14830 _gtk_widget_get_action_muxer (GtkWidget *widget)
14832 if (widget->priv->muxer == NULL)
14834 widget->priv->muxer = g_action_muxer_new ();
14835 _gtk_widget_update_parent_muxer (widget);
14838 return widget->priv->muxer;
14842 * gtk_widget_insert_action_group:
14843 * @widget: a #GtkWidget
14844 * @name: the prefix for actions in @group
14845 * @group: a #GActionGroup
14847 * Inserts @group into @widget. Children of @widget that implement
14848 * #GtkActionable can then be associated with actions in @group by
14849 * setting their 'action-name' to
14850 * @prefix.<replaceable>action-name</replaceable>.
14855 gtk_widget_insert_action_group (GtkWidget *widget,
14857 GActionGroup *group)
14859 GActionMuxer *muxer;
14861 g_return_if_fail (GTK_IS_WIDGET (widget));
14862 g_return_if_fail (name != NULL);
14864 muxer = _gtk_widget_get_action_muxer (widget);
14867 g_action_muxer_insert (muxer, name, group);
14869 g_action_muxer_remove (muxer, name);