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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup-private.h"
44 #include "gtkwidget.h"
45 #include "gtkwidgetprivate.h"
46 #include "gtkwindow.h"
47 #include "gtkbindings.h"
48 #include "gtkprivate.h"
50 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
51 #include <gobject/gvaluecollector.h>
52 #include <gobject/gobjectnotifyqueue.c>
53 #include <cairo-gobject.h>
54 #include "gdk/gdkkeysyms.h"
55 #include "gtkaccessible.h"
56 #include "gtktooltip.h"
57 #include "gtkinvisible.h"
58 #include "gtkbuildable.h"
59 #include "gtkbuilderprivate.h"
60 #include "gtksizerequest.h"
61 #include "gtkstylecontext.h"
62 #include "gtkcssprovider.h"
63 #include "gtkversion.h"
69 * @Short_description: Base class for all widgets
72 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
73 * widget lifecycle, states and style.
75 * <refsect2 id="geometry-management">
76 * <title>Height-for-width Geometry Management</title>
78 * GTK+ uses a height-for-width (and width-for-height) geometry management
79 * system. Height-for-width means that a widget can change how much
80 * vertical space it needs, depending on the amount of horizontal space
81 * that it is given (and similar for width-for-height). The most common
82 * example is a label that reflows to fill up the available width, wraps
83 * to fewer lines, and therefore needs less height.
85 * Height-for-width geometry management is implemented in GTK+ by way
86 * of five virtual methods:
88 * <listitem>#GtkWidgetClass.get_request_mode()</listitem>
89 * <listitem>#GtkWidgetClass.get_preferred_width()</listitem>
90 * <listitem>#GtkWidgetClass.get_preferred_height()</listitem>
91 * <listitem>#GtkWidgetClass.get_preferred_height_for_width()</listitem>
92 * <listitem>#GtkWidgetClass.get_preferred_width_for_height()</listitem>
95 * There are some important things to keep in mind when implementing
96 * height-for-width and when using it in container implementations.
98 * The geometry management system will query a widget hierarchy in
99 * only one orientation at a time. When widgets are initially queried
100 * for their minimum sizes it is generally done in two initial passes
101 * in the #GtkSizeRequestMode chosen by the toplevel.
103 * For example, when queried in the normal
104 * %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH mode:
105 * First, the default minimum and natural width for each widget
106 * in the interface will be computed using gtk_width_get_preferred_width().
107 * Because the preferred widths for each container depend on the preferred
108 * widths of their children, this information propagates up the hierarchy,
109 * and finally a minimum and natural width is determined for the entire
110 * toplevel. Next, the toplevel will use the minimum width to query for the
111 * minimum height contextual to that width using
112 * gtk_widget_get_preferred_height_for_width(), which will also be a highly
113 * recursive operation. The minimum height for the minimum width is normally
114 * used to set the minimum size constraint on the toplevel
115 * (unless gtk_window_set_geometry_hints() is explicitly used instead).
117 * After the toplevel window has initially requested its size in both
118 * dimensions it can go on to allocate itself a reasonable size (or a size
119 * previously specified with gtk_window_set_default_size()). During the
120 * recursive allocation process it's important to note that request cycles
121 * will be recursively executed while container widgets allocate their children.
122 * Each container widget, once allocated a size, will go on to first share the
123 * space in one orientation among its children and then request each child's
124 * height for its target allocated width or its width for allocated height,
125 * depending. In this way a #GtkWidget will typically be requested its size
126 * a number of times before actually being allocated a size. The size a
127 * widget is finally allocated can of course differ from the size it has
128 * requested. For this reason, #GtkWidget caches a small number of results
129 * to avoid re-querying for the same sizes in one allocation cycle.
131 * See <link linkend="container-geometry-management">GtkContainer's
132 * geometry management section</link>
133 * to learn more about how height-for-width allocations are performed
134 * by container widgets.
136 * If a widget does move content around to intelligently use up the
137 * allocated size then it must support the request in both
138 * #GtkSizeRequestModes even if the widget in question only
139 * trades sizes in a single orientation.
141 * For instance, a #GtkLabel that does height-for-width word wrapping
142 * will not expect to have #GtkWidgetClass.get_preferred_height() called
143 * because that call is specific to a width-for-height request. In this
144 * case the label must return the height required for its own minimum
145 * possible width. By following this rule any widget that handles
146 * height-for-width or width-for-height requests will always be allocated
147 * at least enough space to fit its own content.
149 * Here are some examples of how a %GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH widget
150 * generally deals with width-for-height requests, for #GtkWidgetClass.get_preferred_height()
152 * <programlisting><![CDATA[
154 * foo_widget_get_preferred_height (GtkWidget *widget, gint *min_height, gint *nat_height)
156 * if (i_am_in_height_for_width_mode)
160 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
161 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, min_width,
162 * min_height, nat_height);
166 * ... some widgets do both. For instance, if a GtkLabel is rotated to 90 degrees
167 * it will return the minimum and natural height for the rotated label here.
170 * ]]></programlisting>
172 * And in #GtkWidgetClass.get_preferred_width_for_height() it will simply return
173 * the minimum and natural width:
175 * <programlisting><![CDATA[
177 * foo_widget_get_preferred_width_for_height (GtkWidget *widget, gint for_height,
178 * gint *min_width, gint *nat_width)
180 * if (i_am_in_height_for_width_mode)
182 * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, min_width, nat_width);
186 * ... again if a widget is sometimes operating in width-for-height mode
187 * (like a rotated GtkLabel) it can go ahead and do its real width for
188 * height calculation here.
191 * ]]></programlisting>
193 * Often a widget needs to get its own request during size request or
194 * allocation. For example, when computing height it may need to also
195 * compute width. Or when deciding how to use an allocation, the widget
196 * may need to know its natural size. In these cases, the widget should
197 * be careful to call its virtual methods directly, like this:
199 * <title>Widget calling its own size request method.</title>
201 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget),
206 * It will not work to use the wrapper functions, such as
207 * gtk_widget_get_preferred_width() inside your own size request
208 * implementation. These return a request adjusted by #GtkSizeGroup
209 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
210 * widget used the wrappers inside its virtual method implementations,
211 * then the adjustments (such as widget margins) would be applied
212 * twice. GTK+ therefore does not allow this and will warn if you try
215 * Of course if you are getting the size request for
216 * <emphasis>another</emphasis> widget, such as a child of a
217 * container, you <emphasis>must</emphasis> use the wrapper APIs.
218 * Otherwise, you would not properly consider widget margins,
219 * #GtkSizeGroup, and so forth.
222 * <refsect2 id="style-properties">
223 * <title>Style Properties</title>
225 * <structname>GtkWidget</structname> introduces <firstterm>style
226 * properties</firstterm> - these are basically object properties that are stored
227 * not on the object, but in the style object associated to the widget. Style
228 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
229 * This mechanism is used for configuring such things as the location of the
230 * scrollbar arrows through the theme, giving theme authors more control over the
231 * look of applications without the need to write a theme engine in C.
234 * Use gtk_widget_class_install_style_property() to install style properties for
235 * a widget class, gtk_widget_class_find_style_property() or
236 * gtk_widget_class_list_style_properties() to get information about existing
237 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
238 * gtk_widget_style_get_valist() to obtain the value of a style property.
241 * <refsect2 id="GtkWidget-BUILDER-UI">
242 * <title>GtkWidget as GtkBuildable</title>
244 * The GtkWidget implementation of the GtkBuildable interface supports a
245 * custom <accelerator> element, which has attributes named key,
246 * modifiers and signal and allows to specify accelerators.
249 * <title>A UI definition fragment specifying an accelerator</title>
250 * <programlisting><![CDATA[
251 * <object class="GtkButton">
252 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
254 * ]]></programlisting>
257 * In addition to accelerators, <structname>GtkWidget</structname> also support a
258 * custom <accessible> element, which supports actions and relations.
259 * Properties on the accessible implementation of an object can be set by accessing the
260 * internal child "accessible" of a <structname>GtkWidget</structname>.
263 * <title>A UI definition fragment specifying an accessible</title>
264 * <programlisting><![CDATA[
265 * <object class="GtkButton" id="label1"/>
266 * <property name="label">I am a Label for a Button</property>
268 * <object class="GtkButton" id="button1">
270 * <action action_name="click" translatable="yes">Click the button.</action>
271 * <relation target="label1" type="labelled-by"/>
273 * <child internal-child="accessible">
274 * <object class="AtkObject" id="a11y-button1">
275 * <property name="AtkObject::name">Clickable Button</property>
279 * ]]></programlisting>
284 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
285 #define INIT_PATH_SIZE (512)
287 struct _GtkWidgetPrivate
289 /* The state of the widget. There are actually only
290 * 5 widget states (defined in "gtkenums.h")
293 guint state_flags : 6;
297 guint in_destruction : 1;
300 guint composite_child : 1;
306 guint parent_sensitive : 1;
309 guint can_default : 1;
310 guint has_default : 1;
311 guint receives_default : 1;
315 guint user_style : 1;
316 guint app_paintable : 1;
317 guint double_buffered : 1;
318 guint redraw_on_alloc : 1;
319 guint no_show_all : 1;
320 guint child_visible : 1;
321 guint multidevice : 1;
322 guint has_shape_mask : 1;
323 guint in_reparent : 1;
324 guint resize_pending : 1;
325 guint alloc_needed : 1;
326 guint width_request_needed : 1;
327 guint height_request_needed : 1;
329 /* Expand-related flags */
330 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
331 guint computed_hexpand : 1; /* computed results (composite of child flags) */
332 guint computed_vexpand : 1;
333 guint hexpand : 1; /* application-forced expand */
335 guint hexpand_set : 1; /* whether to use application-forced */
336 guint vexpand_set : 1; /* instead of computing from children */
338 /* The widget's name. If the widget does not have a name
339 * (the name is NULL), then its name (as returned by
340 * "gtk_widget_get_name") is its class's name.
341 * Among other things, the widget name is used to determine
342 * the style to use for a widget.
346 /* The style for the widget. The style contains the
347 * colors the widget should be drawn in for each state
348 * along with graphics contexts used to draw with and
349 * the font to use for text.
352 GtkStyleContext *context;
354 /* The widget's allocated size.
356 GtkAllocation allocation;
358 /* The widget's requested sizes */
359 SizeRequestCache requests;
361 /* The widget's window or its parent window if it does
362 * not have a window. (Which will be indicated by the
363 * GTK_NO_WINDOW flag being set).
367 /* The widget's parent.
371 /* Widget's path for styling */
401 BUTTON_RELEASE_EVENT,
416 PROPERTY_NOTIFY_EVENT,
417 SELECTION_CLEAR_EVENT,
418 SELECTION_REQUEST_EVENT,
419 SELECTION_NOTIFY_EVENT,
425 VISIBILITY_NOTIFY_EVENT,
439 ACCEL_CLOSURES_CHANGED,
463 PROP_RECEIVES_DEFAULT,
464 PROP_COMPOSITE_CHILD,
467 PROP_EXTENSION_EVENTS,
473 PROP_DOUBLE_BUFFERED,
488 typedef struct _GtkStateData GtkStateData;
491 STATE_CHANGE_REPLACE,
500 guint parent_sensitive : 1;
501 guint use_forall : 1;
504 /* --- prototypes --- */
505 static void gtk_widget_class_init (GtkWidgetClass *klass);
506 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
507 static void gtk_widget_init (GtkWidget *widget);
508 static void gtk_widget_set_property (GObject *object,
512 static void gtk_widget_get_property (GObject *object,
516 static void gtk_widget_dispose (GObject *object);
517 static void gtk_widget_real_destroy (GtkWidget *object);
518 static void gtk_widget_finalize (GObject *object);
519 static void gtk_widget_real_show (GtkWidget *widget);
520 static void gtk_widget_real_hide (GtkWidget *widget);
521 static void gtk_widget_real_map (GtkWidget *widget);
522 static void gtk_widget_real_unmap (GtkWidget *widget);
523 static void gtk_widget_real_realize (GtkWidget *widget);
524 static void gtk_widget_real_unrealize (GtkWidget *widget);
525 static void gtk_widget_real_size_allocate (GtkWidget *widget,
526 GtkAllocation *allocation);
527 static void gtk_widget_real_style_set (GtkWidget *widget,
528 GtkStyle *previous_style);
529 static void gtk_widget_real_direction_changed(GtkWidget *widget,
530 GtkTextDirection previous_direction);
532 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
533 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
536 gboolean keyboard_tip,
537 GtkTooltip *tooltip);
538 static void gtk_widget_real_style_updated (GtkWidget *widget);
539 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
540 GtkWidgetHelpType help_type);
542 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
544 GParamSpec **pspecs);
545 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
547 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
549 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
550 GdkEventFocus *event);
551 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
552 GdkEventFocus *event);
553 static gboolean gtk_widget_real_focus (GtkWidget *widget,
554 GtkDirectionType direction);
555 static void gtk_widget_real_move_focus (GtkWidget *widget,
556 GtkDirectionType direction);
557 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
558 GtkDirectionType direction);
559 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
560 static void gtk_widget_update_pango_context (GtkWidget *widget);
561 static void gtk_widget_propagate_state (GtkWidget *widget,
563 static void gtk_widget_reset_rc_style (GtkWidget *widget);
564 static void gtk_widget_set_style_internal (GtkWidget *widget,
566 gboolean initial_emission);
567 static gint gtk_widget_event_internal (GtkWidget *widget,
569 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
570 gboolean group_cycling);
571 static void gtk_widget_real_get_width (GtkWidget *widget,
574 static void gtk_widget_real_get_height (GtkWidget *widget,
577 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
579 gint *minimum_height,
580 gint *natural_height);
581 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
584 gint *natural_width);
585 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
586 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
587 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
588 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
589 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
590 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
591 cairo_region_t *region);
592 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
593 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
594 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
597 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
598 gboolean has_tooltip,
600 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
601 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
603 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
604 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
606 const gchar *childname);
607 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
610 const GValue *value);
611 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
614 const gchar *tagname,
615 GMarkupParser *parser,
617 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
620 const gchar *tagname,
622 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
623 GtkBuilder *builder);
625 static void gtk_widget_real_get_width (GtkWidget *widget,
628 static void gtk_widget_real_get_height (GtkWidget *widget,
632 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
635 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
636 GtkOrientation orientation,
639 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
640 GtkOrientation orientation,
643 gint *allocated_size);
645 static void gtk_widget_set_usize_internal (GtkWidget *widget,
648 GtkQueueResizeFlags flags);
650 static void gtk_widget_add_events_internal (GtkWidget *widget,
654 /* --- variables --- */
655 static gpointer gtk_widget_parent_class = NULL;
656 static guint widget_signals[LAST_SIGNAL] = { 0 };
657 static GtkStyle *gtk_default_style = NULL;
658 static guint composite_child_stack = 0;
659 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
660 static GParamSpecPool *style_property_spec_pool = NULL;
662 static GQuark quark_property_parser = 0;
663 static GQuark quark_aux_info = 0;
664 static GQuark quark_accel_path = 0;
665 static GQuark quark_accel_closures = 0;
666 static GQuark quark_event_mask = 0;
667 static GQuark quark_device_event_mask = 0;
668 static GQuark quark_extension_event_mode = 0;
669 static GQuark quark_parent_window = 0;
670 static GQuark quark_pointer_window = 0;
671 static GQuark quark_shape_info = 0;
672 static GQuark quark_input_shape_info = 0;
673 static GQuark quark_pango_context = 0;
674 static GQuark quark_rc_style = 0;
675 static GQuark quark_accessible_object = 0;
676 static GQuark quark_mnemonic_labels = 0;
677 static GQuark quark_tooltip_markup = 0;
678 static GQuark quark_has_tooltip = 0;
679 static GQuark quark_tooltip_window = 0;
680 static GQuark quark_visual = 0;
681 static GQuark quark_modifier_style = 0;
682 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
683 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
685 /* --- functions --- */
687 gtk_widget_get_type (void)
689 static GType widget_type = 0;
691 if (G_UNLIKELY (widget_type == 0))
693 const GTypeInfo widget_info =
695 sizeof (GtkWidgetClass),
696 NULL, /* base_init */
697 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
698 (GClassInitFunc) gtk_widget_class_init,
699 NULL, /* class_finalize */
700 NULL, /* class_init */
703 (GInstanceInitFunc) gtk_widget_init,
704 NULL, /* value_table */
707 const GInterfaceInfo accessibility_info =
709 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
710 (GInterfaceFinalizeFunc) NULL,
711 NULL /* interface data */
714 const GInterfaceInfo buildable_info =
716 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
717 (GInterfaceFinalizeFunc) NULL,
718 NULL /* interface data */
721 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
722 &widget_info, G_TYPE_FLAG_ABSTRACT);
724 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
725 &accessibility_info) ;
726 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
734 child_property_notify_dispatcher (GObject *object,
738 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
741 /* We guard against the draw signal callbacks modifying the state of the
742 * cairo context by surounding it with save/restore.
743 * Maybe we should also cairo_new_path() just to be sure?
746 gtk_widget_draw_marshaller (GClosure *closure,
747 GValue *return_value,
748 guint n_param_values,
749 const GValue *param_values,
750 gpointer invocation_hint,
751 gpointer marshal_data)
753 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
757 _gtk_marshal_BOOLEAN__BOXED (closure,
768 gtk_widget_class_init (GtkWidgetClass *klass)
770 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
771 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
772 GtkBindingSet *binding_set;
774 gtk_widget_parent_class = g_type_class_peek_parent (klass);
776 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
777 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
778 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
779 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
780 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
781 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
782 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
783 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
784 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
785 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
786 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
787 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
788 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
789 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
790 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
791 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
792 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
793 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
794 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
795 quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style");
797 style_property_spec_pool = g_param_spec_pool_new (FALSE);
798 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
799 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
800 cpn_context.dispatcher = child_property_notify_dispatcher;
801 _gtk_widget_child_property_notify_context = &cpn_context;
803 gobject_class->dispose = gtk_widget_dispose;
804 gobject_class->finalize = gtk_widget_finalize;
805 gobject_class->set_property = gtk_widget_set_property;
806 gobject_class->get_property = gtk_widget_get_property;
808 klass->destroy = gtk_widget_real_destroy;
810 klass->activate_signal = 0;
811 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
812 klass->show = gtk_widget_real_show;
813 klass->show_all = gtk_widget_show;
814 klass->hide = gtk_widget_real_hide;
815 klass->map = gtk_widget_real_map;
816 klass->unmap = gtk_widget_real_unmap;
817 klass->realize = gtk_widget_real_realize;
818 klass->unrealize = gtk_widget_real_unrealize;
819 klass->size_allocate = gtk_widget_real_size_allocate;
820 klass->get_preferred_width = gtk_widget_real_get_width;
821 klass->get_preferred_height = gtk_widget_real_get_height;
822 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
823 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
824 klass->state_changed = NULL;
825 klass->parent_set = NULL;
826 klass->hierarchy_changed = NULL;
827 klass->style_set = gtk_widget_real_style_set;
828 klass->direction_changed = gtk_widget_real_direction_changed;
829 klass->grab_notify = NULL;
830 klass->child_notify = NULL;
832 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
833 klass->grab_focus = gtk_widget_real_grab_focus;
834 klass->focus = gtk_widget_real_focus;
835 klass->move_focus = gtk_widget_real_move_focus;
836 klass->keynav_failed = gtk_widget_real_keynav_failed;
838 klass->button_press_event = NULL;
839 klass->button_release_event = NULL;
840 klass->motion_notify_event = NULL;
841 klass->delete_event = NULL;
842 klass->destroy_event = NULL;
843 klass->key_press_event = gtk_widget_real_key_press_event;
844 klass->key_release_event = gtk_widget_real_key_release_event;
845 klass->enter_notify_event = NULL;
846 klass->leave_notify_event = NULL;
847 klass->configure_event = NULL;
848 klass->focus_in_event = gtk_widget_real_focus_in_event;
849 klass->focus_out_event = gtk_widget_real_focus_out_event;
850 klass->map_event = NULL;
851 klass->unmap_event = NULL;
852 klass->window_state_event = NULL;
853 klass->property_notify_event = _gtk_selection_property_notify;
854 klass->selection_clear_event = _gtk_selection_clear;
855 klass->selection_request_event = _gtk_selection_request;
856 klass->selection_notify_event = _gtk_selection_notify;
857 klass->selection_received = NULL;
858 klass->proximity_in_event = NULL;
859 klass->proximity_out_event = NULL;
860 klass->drag_begin = NULL;
861 klass->drag_end = NULL;
862 klass->drag_data_delete = NULL;
863 klass->drag_leave = NULL;
864 klass->drag_motion = NULL;
865 klass->drag_drop = NULL;
866 klass->drag_data_received = NULL;
867 klass->screen_changed = NULL;
868 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
869 klass->grab_broken_event = NULL;
870 klass->query_tooltip = gtk_widget_real_query_tooltip;
871 klass->style_updated = gtk_widget_real_style_updated;
873 klass->show_help = gtk_widget_real_show_help;
875 /* Accessibility support */
876 klass->get_accessible = gtk_widget_real_get_accessible;
878 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
879 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
881 g_object_class_install_property (gobject_class,
883 g_param_spec_string ("name",
885 P_("The name of the widget"),
887 GTK_PARAM_READWRITE));
888 g_object_class_install_property (gobject_class,
890 g_param_spec_object ("parent",
892 P_("The parent widget of this widget. Must be a Container widget"),
894 GTK_PARAM_READWRITE));
896 g_object_class_install_property (gobject_class,
898 g_param_spec_int ("width-request",
900 P_("Override for width request of the widget, or -1 if natural request should be used"),
904 GTK_PARAM_READWRITE));
905 g_object_class_install_property (gobject_class,
907 g_param_spec_int ("height-request",
908 P_("Height request"),
909 P_("Override for height request of the widget, or -1 if natural request should be used"),
913 GTK_PARAM_READWRITE));
914 g_object_class_install_property (gobject_class,
916 g_param_spec_boolean ("visible",
918 P_("Whether the widget is visible"),
920 GTK_PARAM_READWRITE));
921 g_object_class_install_property (gobject_class,
923 g_param_spec_boolean ("sensitive",
925 P_("Whether the widget responds to input"),
927 GTK_PARAM_READWRITE));
928 g_object_class_install_property (gobject_class,
930 g_param_spec_boolean ("app-paintable",
931 P_("Application paintable"),
932 P_("Whether the application will paint directly on the widget"),
934 GTK_PARAM_READWRITE));
935 g_object_class_install_property (gobject_class,
937 g_param_spec_boolean ("can-focus",
939 P_("Whether the widget can accept the input focus"),
941 GTK_PARAM_READWRITE));
942 g_object_class_install_property (gobject_class,
944 g_param_spec_boolean ("has-focus",
946 P_("Whether the widget has the input focus"),
948 GTK_PARAM_READWRITE));
949 g_object_class_install_property (gobject_class,
951 g_param_spec_boolean ("is-focus",
953 P_("Whether the widget is the focus widget within the toplevel"),
955 GTK_PARAM_READWRITE));
956 g_object_class_install_property (gobject_class,
958 g_param_spec_boolean ("can-default",
960 P_("Whether the widget can be the default widget"),
962 GTK_PARAM_READWRITE));
963 g_object_class_install_property (gobject_class,
965 g_param_spec_boolean ("has-default",
967 P_("Whether the widget is the default widget"),
969 GTK_PARAM_READWRITE));
970 g_object_class_install_property (gobject_class,
971 PROP_RECEIVES_DEFAULT,
972 g_param_spec_boolean ("receives-default",
973 P_("Receives default"),
974 P_("If TRUE, the widget will receive the default action when it is focused"),
976 GTK_PARAM_READWRITE));
977 g_object_class_install_property (gobject_class,
978 PROP_COMPOSITE_CHILD,
979 g_param_spec_boolean ("composite-child",
980 P_("Composite child"),
981 P_("Whether the widget is part of a composite widget"),
983 GTK_PARAM_READABLE));
984 g_object_class_install_property (gobject_class,
986 g_param_spec_object ("style",
988 P_("The style of the widget, which contains information about how it will look (colors etc)"),
990 GTK_PARAM_READWRITE));
991 g_object_class_install_property (gobject_class,
993 g_param_spec_flags ("events",
995 P_("The event mask that decides what kind of GdkEvents this widget gets"),
998 GTK_PARAM_READWRITE));
999 g_object_class_install_property (gobject_class,
1000 PROP_EXTENSION_EVENTS,
1001 g_param_spec_enum ("extension-events",
1002 P_("Extension events"),
1003 P_("The mask that decides what kind of extension events this widget gets"),
1004 GDK_TYPE_EXTENSION_MODE,
1005 GDK_EXTENSION_EVENTS_NONE,
1006 GTK_PARAM_READWRITE));
1007 g_object_class_install_property (gobject_class,
1009 g_param_spec_boolean ("no-show-all",
1011 P_("Whether gtk_widget_show_all() should not affect this widget"),
1013 GTK_PARAM_READWRITE));
1016 * GtkWidget:has-tooltip:
1018 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
1019 * A value of %TRUE indicates that @widget can have a tooltip, in this case
1020 * the widget will be queried using #GtkWidget::query-tooltip to determine
1021 * whether it will provide a tooltip or not.
1023 * Note that setting this property to %TRUE for the first time will change
1024 * the event masks of the GdkWindows of this widget to include leave-notify
1025 * and motion-notify events. This cannot and will not be undone when the
1026 * property is set to %FALSE again.
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_boolean ("has-tooltip",
1034 P_("Whether this widget has a tooltip"),
1036 GTK_PARAM_READWRITE));
1038 * GtkWidget:tooltip-text:
1040 * Sets the text of tooltip to be the given string.
1042 * Also see gtk_tooltip_set_text().
1044 * This is a convenience property which will take care of getting the
1045 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1046 * will automatically be set to %TRUE and there will be taken care of
1047 * #GtkWidget::query-tooltip in the default signal handler.
1051 g_object_class_install_property (gobject_class,
1053 g_param_spec_string ("tooltip-text",
1055 P_("The contents of the tooltip for this widget"),
1057 GTK_PARAM_READWRITE));
1059 * GtkWidget:tooltip-markup:
1061 * Sets the text of tooltip to be the given string, which is marked up
1062 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
1063 * Also see gtk_tooltip_set_markup().
1065 * This is a convenience property which will take care of getting the
1066 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1067 * will automatically be set to %TRUE and there will be taken care of
1068 * #GtkWidget::query-tooltip in the default signal handler.
1072 g_object_class_install_property (gobject_class,
1073 PROP_TOOLTIP_MARKUP,
1074 g_param_spec_string ("tooltip-markup",
1075 P_("Tooltip markup"),
1076 P_("The contents of the tooltip for this widget"),
1078 GTK_PARAM_READWRITE));
1083 * The widget's window if it is realized, %NULL otherwise.
1087 g_object_class_install_property (gobject_class,
1089 g_param_spec_object ("window",
1091 P_("The widget's window if it is realized"),
1093 GTK_PARAM_READABLE));
1096 * GtkWidget:double-buffered
1098 * Whether the widget is double buffered.
1102 g_object_class_install_property (gobject_class,
1103 PROP_DOUBLE_BUFFERED,
1104 g_param_spec_boolean ("double-buffered",
1105 P_("Double Buffered"),
1106 P_("Whether the widget is double buffered"),
1108 GTK_PARAM_READWRITE));
1113 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1117 g_object_class_install_property (gobject_class,
1119 g_param_spec_enum ("halign",
1120 P_("Horizontal Alignment"),
1121 P_("How to position in extra horizontal space"),
1124 GTK_PARAM_READWRITE));
1129 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1133 g_object_class_install_property (gobject_class,
1135 g_param_spec_enum ("valign",
1136 P_("Vertical Alignment"),
1137 P_("How to position in extra vertical space"),
1140 GTK_PARAM_READWRITE));
1143 * GtkWidget:margin-left
1145 * Margin on left side of widget.
1147 * This property adds margin outside of the widget's normal size
1148 * request, the margin will be added in addition to the size from
1149 * gtk_widget_set_size_request() for example.
1153 g_object_class_install_property (gobject_class,
1155 g_param_spec_int ("margin-left",
1156 P_("Margin on Left"),
1157 P_("Pixels of extra space on the left side"),
1161 GTK_PARAM_READWRITE));
1164 * GtkWidget:margin-right
1166 * Margin on right side of widget.
1168 * This property adds margin outside of the widget's normal size
1169 * request, the margin will be added in addition to the size from
1170 * gtk_widget_set_size_request() for example.
1174 g_object_class_install_property (gobject_class,
1176 g_param_spec_int ("margin-right",
1177 P_("Margin on Right"),
1178 P_("Pixels of extra space on the right side"),
1182 GTK_PARAM_READWRITE));
1185 * GtkWidget:margin-top
1187 * Margin on top side of widget.
1189 * This property adds margin outside of the widget's normal size
1190 * request, the margin will be added in addition to the size from
1191 * gtk_widget_set_size_request() for example.
1195 g_object_class_install_property (gobject_class,
1197 g_param_spec_int ("margin-top",
1198 P_("Margin on Top"),
1199 P_("Pixels of extra space on the top side"),
1203 GTK_PARAM_READWRITE));
1206 * GtkWidget:margin-bottom
1208 * Margin on bottom side of widget.
1210 * This property adds margin outside of the widget's normal size
1211 * request, the margin will be added in addition to the size from
1212 * gtk_widget_set_size_request() for example.
1216 g_object_class_install_property (gobject_class,
1218 g_param_spec_int ("margin-bottom",
1219 P_("Margin on Bottom"),
1220 P_("Pixels of extra space on the bottom side"),
1224 GTK_PARAM_READWRITE));
1229 * Sets all four sides' margin at once. If read, returns max
1230 * margin on any side.
1234 g_object_class_install_property (gobject_class,
1236 g_param_spec_int ("margin",
1238 P_("Pixels of extra space on all four sides"),
1242 GTK_PARAM_READWRITE));
1245 * GtkWidget::destroy:
1246 * @object: the object which received the signal
1248 * Signals that all holders of a reference to the widget should release
1249 * the reference that they hold. May result in finalization of the widget
1250 * if all references are released.
1252 widget_signals[DESTROY] =
1253 g_signal_new (I_("destroy"),
1254 G_TYPE_FROM_CLASS (gobject_class),
1255 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1256 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1258 _gtk_marshal_VOID__VOID,
1264 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1268 g_object_class_install_property (gobject_class,
1270 g_param_spec_boolean ("hexpand",
1271 P_("Horizontal Expand"),
1272 P_("Whether widget wants more horizontal space"),
1274 GTK_PARAM_READWRITE));
1277 * GtkWidget:hexpand-set
1279 * Whether to use the #GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1283 g_object_class_install_property (gobject_class,
1285 g_param_spec_boolean ("hexpand-set",
1286 P_("Horizontal Expand Set"),
1287 P_("Whether to use the hexpand property"),
1289 GTK_PARAM_READWRITE));
1294 * Whether to expand vertically. See gtk_widget_set_vexpand().
1298 g_object_class_install_property (gobject_class,
1300 g_param_spec_boolean ("vexpand",
1301 P_("Vertical Expand"),
1302 P_("Whether widget wants more vertical space"),
1304 GTK_PARAM_READWRITE));
1307 * GtkWidget:vexpand-set
1309 * Whether to use the #GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1313 g_object_class_install_property (gobject_class,
1315 g_param_spec_boolean ("vexpand-set",
1316 P_("Vertical Expand Set"),
1317 P_("Whether to use the vexpand property"),
1319 GTK_PARAM_READWRITE));
1324 * Whether to expand in both directions. Setting this sets both #GtkWidget:hexpand and #GtkWidget:vexpand
1328 g_object_class_install_property (gobject_class,
1330 g_param_spec_boolean ("expand",
1332 P_("Whether widget wants to expand in both directions"),
1334 GTK_PARAM_READWRITE));
1338 * @widget: the object which received the signal.
1340 widget_signals[SHOW] =
1341 g_signal_new (I_("show"),
1342 G_TYPE_FROM_CLASS (gobject_class),
1344 G_STRUCT_OFFSET (GtkWidgetClass, show),
1346 _gtk_marshal_VOID__VOID,
1351 * @widget: the object which received the signal.
1353 widget_signals[HIDE] =
1354 g_signal_new (I_("hide"),
1355 G_TYPE_FROM_CLASS (gobject_class),
1357 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1359 _gtk_marshal_VOID__VOID,
1364 * @widget: the object which received the signal.
1366 widget_signals[MAP] =
1367 g_signal_new (I_("map"),
1368 G_TYPE_FROM_CLASS (gobject_class),
1370 G_STRUCT_OFFSET (GtkWidgetClass, map),
1372 _gtk_marshal_VOID__VOID,
1377 * @widget: the object which received the signal.
1379 widget_signals[UNMAP] =
1380 g_signal_new (I_("unmap"),
1381 G_TYPE_FROM_CLASS (gobject_class),
1383 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1385 _gtk_marshal_VOID__VOID,
1389 * GtkWidget::realize:
1390 * @widget: the object which received the signal.
1392 widget_signals[REALIZE] =
1393 g_signal_new (I_("realize"),
1394 G_TYPE_FROM_CLASS (gobject_class),
1396 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1398 _gtk_marshal_VOID__VOID,
1402 * GtkWidget::unrealize:
1403 * @widget: the object which received the signal.
1405 widget_signals[UNREALIZE] =
1406 g_signal_new (I_("unrealize"),
1407 G_TYPE_FROM_CLASS (gobject_class),
1409 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1411 _gtk_marshal_VOID__VOID,
1415 * GtkWidget::size-allocate:
1416 * @widget: the object which received the signal.
1419 widget_signals[SIZE_ALLOCATE] =
1420 g_signal_new (I_("size-allocate"),
1421 G_TYPE_FROM_CLASS (gobject_class),
1423 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1425 _gtk_marshal_VOID__BOXED,
1427 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1430 * GtkWidget::state-changed:
1431 * @widget: the object which received the signal.
1432 * @state: the previous state
1434 * The ::state-changed signal is emitted when the widget state changes.
1435 * See gtk_widget_get_state().
1437 * Deprecated: 3.0. Use #GtkWidget::state-flags-changed instead.
1439 widget_signals[STATE_CHANGED] =
1440 g_signal_new (I_("state-changed"),
1441 G_TYPE_FROM_CLASS (gobject_class),
1443 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1445 _gtk_marshal_VOID__ENUM,
1447 GTK_TYPE_STATE_TYPE);
1450 * GtkWidget::state-flags-changed:
1451 * @widget: the object which received the signal.
1452 * @flags: The previous state flags.
1454 * The ::state-flags-changed signal is emitted when the widget state
1455 * changes, see gtk_widget_get_state_flags().
1459 widget_signals[STATE_FLAGS_CHANGED] =
1460 g_signal_new (I_("state-flags-changed"),
1461 G_TYPE_FROM_CLASS (gobject_class),
1463 G_STRUCT_OFFSET (GtkWidgetClass, state_flags_changed),
1465 _gtk_marshal_VOID__FLAGS,
1467 GTK_TYPE_STATE_FLAGS);
1470 * GtkWidget::parent-set:
1471 * @widget: the object on which the signal is emitted
1472 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1473 * just got its initial parent.
1475 * The ::parent-set signal is emitted when a new parent
1476 * has been set on a widget.
1478 widget_signals[PARENT_SET] =
1479 g_signal_new (I_("parent-set"),
1480 G_TYPE_FROM_CLASS (gobject_class),
1482 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1484 _gtk_marshal_VOID__OBJECT,
1489 * GtkWidget::hierarchy-changed:
1490 * @widget: the object on which the signal is emitted
1491 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1492 * if the widget was previously unanchored
1494 * The ::hierarchy-changed signal is emitted when the
1495 * anchored state of a widget changes. A widget is
1496 * <firstterm>anchored</firstterm> when its toplevel
1497 * ancestor is a #GtkWindow. This signal is emitted when
1498 * a widget changes from un-anchored to anchored or vice-versa.
1500 widget_signals[HIERARCHY_CHANGED] =
1501 g_signal_new (I_("hierarchy-changed"),
1502 G_TYPE_FROM_CLASS (gobject_class),
1504 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1506 _gtk_marshal_VOID__OBJECT,
1511 * GtkWidget::style-set:
1512 * @widget: the object on which the signal is emitted
1513 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1514 * just got its initial style
1516 * The ::style-set signal is emitted when a new style has been set
1517 * on a widget. Note that style-modifying functions like
1518 * gtk_widget_modify_base() also cause this signal to be emitted.
1520 widget_signals[STYLE_SET] =
1521 g_signal_new (I_("style-set"),
1522 G_TYPE_FROM_CLASS (gobject_class),
1524 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1526 _gtk_marshal_VOID__OBJECT,
1530 widget_signals[STYLE_UPDATED] =
1531 g_signal_new (I_("style-updated"),
1532 G_TYPE_FROM_CLASS (gobject_class),
1534 G_STRUCT_OFFSET (GtkWidgetClass, style_updated),
1536 g_cclosure_marshal_VOID__VOID,
1540 * GtkWidget::direction-changed:
1541 * @widget: the object on which the signal is emitted
1542 * @previous_direction: the previous text direction of @widget
1544 * The ::direction-changed signal is emitted when the text direction
1545 * of a widget changes.
1547 widget_signals[DIRECTION_CHANGED] =
1548 g_signal_new (I_("direction-changed"),
1549 G_TYPE_FROM_CLASS (gobject_class),
1551 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1553 _gtk_marshal_VOID__ENUM,
1555 GTK_TYPE_TEXT_DIRECTION);
1558 * GtkWidget::grab-notify:
1559 * @widget: the object which received the signal
1560 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1561 * if it becomes unshadowed
1563 * The ::grab-notify signal is emitted when a widget becomes
1564 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1565 * another widget, or when it becomes unshadowed due to a grab
1568 * A widget is shadowed by a gtk_grab_add() when the topmost
1569 * grab widget in the grab stack of its window group is not
1572 widget_signals[GRAB_NOTIFY] =
1573 g_signal_new (I_("grab-notify"),
1574 G_TYPE_FROM_CLASS (gobject_class),
1576 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1578 _gtk_marshal_VOID__BOOLEAN,
1583 * GtkWidget::child-notify:
1584 * @widget: the object which received the signal
1585 * @pspec: the #GParamSpec of the changed child property
1587 * The ::child-notify signal is emitted for each
1588 * <link linkend="child-properties">child property</link> that has
1589 * changed on an object. The signal's detail holds the property name.
1591 widget_signals[CHILD_NOTIFY] =
1592 g_signal_new (I_("child-notify"),
1593 G_TYPE_FROM_CLASS (gobject_class),
1594 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1595 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1597 g_cclosure_marshal_VOID__PARAM,
1603 * @widget: the object which received the signal
1604 * @cr: the cairo context to draw to
1606 * This signal is emitted when a widget is supposed to render itself.
1607 * The @widget's top left corner must be painted at the origin of
1608 * the passed in context and be sized to the values returned by
1609 * gtk_widget_get_allocated_width() and
1610 * gtk_widget_get_allocated_height().
1612 * Signal handlers connected to this signal can modify the cairo
1613 * context passed as @cr in any way they like and don't need to
1614 * restore it. The signal emission takes care of calling cairo_save()
1615 * before and cairo_restore() after invoking the handler.
1617 widget_signals[DRAW] =
1618 g_signal_new (I_("draw"),
1619 G_TYPE_FROM_CLASS (gobject_class),
1621 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1622 _gtk_boolean_handled_accumulator, NULL,
1623 gtk_widget_draw_marshaller,
1625 CAIRO_GOBJECT_TYPE_CONTEXT);
1628 * GtkWidget::mnemonic-activate:
1629 * @widget: the object which received the signal.
1632 widget_signals[MNEMONIC_ACTIVATE] =
1633 g_signal_new (I_("mnemonic-activate"),
1634 G_TYPE_FROM_CLASS (gobject_class),
1636 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1637 _gtk_boolean_handled_accumulator, NULL,
1638 _gtk_marshal_BOOLEAN__BOOLEAN,
1643 * GtkWidget::grab-focus:
1644 * @widget: the object which received the signal.
1646 widget_signals[GRAB_FOCUS] =
1647 g_signal_new (I_("grab-focus"),
1648 G_TYPE_FROM_CLASS (gobject_class),
1649 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1650 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1652 _gtk_marshal_VOID__VOID,
1657 * @widget: the object which received the signal.
1660 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1662 widget_signals[FOCUS] =
1663 g_signal_new (I_("focus"),
1664 G_TYPE_FROM_CLASS (klass),
1666 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1667 _gtk_boolean_handled_accumulator, NULL,
1668 _gtk_marshal_BOOLEAN__ENUM,
1670 GTK_TYPE_DIRECTION_TYPE);
1673 * GtkWidget::move-focus:
1674 * @widget: the object which received the signal.
1677 widget_signals[MOVE_FOCUS] =
1678 g_signal_new (I_("move-focus"),
1679 G_TYPE_FROM_CLASS (klass),
1680 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1681 G_STRUCT_OFFSET (GtkWidgetClass, move_focus),
1683 _gtk_marshal_VOID__ENUM,
1686 GTK_TYPE_DIRECTION_TYPE);
1689 * GtkWidget::keynav-failed:
1690 * @widget: the object which received the signal
1691 * @direction: the direction of movement
1693 * Gets emitted if keyboard navigation fails.
1694 * See gtk_widget_keynav_failed() for details.
1696 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1697 * if the emitting widget should try to handle the keyboard
1698 * navigation attempt in its parent container(s).
1702 widget_signals[KEYNAV_FAILED] =
1703 g_signal_new (I_("keynav-failed"),
1704 G_TYPE_FROM_CLASS (klass),
1706 G_STRUCT_OFFSET (GtkWidgetClass, keynav_failed),
1707 _gtk_boolean_handled_accumulator, NULL,
1708 _gtk_marshal_BOOLEAN__ENUM,
1710 GTK_TYPE_DIRECTION_TYPE);
1714 * @widget: the object which received the signal.
1715 * @event: the #GdkEvent which triggered this signal
1717 * The GTK+ main loop will emit three signals for each GDK event delivered
1718 * to a widget: one generic ::event signal, another, more specific,
1719 * signal that matches the type of event delivered (e.g.
1720 * #GtkWidget::key-press-event) and finally a generic
1721 * #GtkWidget::event-after signal.
1723 * Returns: %TRUE to stop other handlers from being invoked for the event
1724 * and to cancel the emission of the second specific ::event signal.
1725 * %FALSE to propagate the event further and to allow the emission of
1726 * the second signal. The ::event-after signal is emitted regardless of
1729 widget_signals[EVENT] =
1730 g_signal_new (I_("event"),
1731 G_TYPE_FROM_CLASS (klass),
1733 G_STRUCT_OFFSET (GtkWidgetClass, event),
1734 _gtk_boolean_handled_accumulator, NULL,
1735 _gtk_marshal_BOOLEAN__BOXED,
1737 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1740 * GtkWidget::event-after:
1741 * @widget: the object which received the signal.
1742 * @event: the #GdkEvent which triggered this signal
1744 * After the emission of the #GtkWidget::event signal and (optionally)
1745 * the second more specific signal, ::event-after will be emitted
1746 * regardless of the previous two signals handlers return values.
1749 widget_signals[EVENT_AFTER] =
1750 g_signal_new (I_("event-after"),
1751 G_TYPE_FROM_CLASS (klass),
1755 _gtk_marshal_VOID__BOXED,
1757 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1760 * GtkWidget::button-press-event:
1761 * @widget: the object which received the signal.
1762 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1765 * The ::button-press-event signal will be emitted when a button
1766 * (typically from a mouse) is pressed.
1768 * To receive this signal, the #GdkWindow associated to the
1769 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1771 * This signal will be sent to the grab widget if there is one.
1773 * Returns: %TRUE to stop other handlers from being invoked for the event.
1774 * %FALSE to propagate the event further.
1776 widget_signals[BUTTON_PRESS_EVENT] =
1777 g_signal_new (I_("button-press-event"),
1778 G_TYPE_FROM_CLASS (klass),
1780 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1781 _gtk_boolean_handled_accumulator, NULL,
1782 _gtk_marshal_BOOLEAN__BOXED,
1784 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1787 * GtkWidget::button-release-event:
1788 * @widget: the object which received the signal.
1789 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1792 * The ::button-release-event signal will be emitted when a button
1793 * (typically from a mouse) is released.
1795 * To receive this signal, the #GdkWindow associated to the
1796 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1798 * This signal will be sent to the grab widget if there is one.
1800 * Returns: %TRUE to stop other handlers from being invoked for the event.
1801 * %FALSE to propagate the event further.
1803 widget_signals[BUTTON_RELEASE_EVENT] =
1804 g_signal_new (I_("button-release-event"),
1805 G_TYPE_FROM_CLASS (klass),
1807 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 _gtk_marshal_BOOLEAN__BOXED,
1811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1814 * GtkWidget::scroll-event:
1815 * @widget: the object which received the signal.
1816 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1819 * The ::scroll-event signal is emitted when a button in the 4 to 7
1820 * range is pressed. Wheel mice are usually configured to generate
1821 * button press events for buttons 4 and 5 when the wheel is turned.
1823 * To receive this signal, the #GdkWindow associated to the widget needs
1824 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1826 * This signal will be sent to the grab widget if there is one.
1828 * Returns: %TRUE to stop other handlers from being invoked for the event.
1829 * %FALSE to propagate the event further.
1831 widget_signals[SCROLL_EVENT] =
1832 g_signal_new (I_("scroll-event"),
1833 G_TYPE_FROM_CLASS (klass),
1835 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1836 _gtk_boolean_handled_accumulator, NULL,
1837 _gtk_marshal_BOOLEAN__BOXED,
1839 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1842 * GtkWidget::motion-notify-event:
1843 * @widget: the object which received the signal.
1844 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1847 * The ::motion-notify-event signal is emitted when the pointer moves
1848 * over the widget's #GdkWindow.
1850 * To receive this signal, the #GdkWindow associated to the widget
1851 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1853 * This signal will be sent to the grab widget if there is one.
1855 * Returns: %TRUE to stop other handlers from being invoked for the event.
1856 * %FALSE to propagate the event further.
1858 widget_signals[MOTION_NOTIFY_EVENT] =
1859 g_signal_new (I_("motion-notify-event"),
1860 G_TYPE_FROM_CLASS (klass),
1862 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1863 _gtk_boolean_handled_accumulator, NULL,
1864 _gtk_marshal_BOOLEAN__BOXED,
1866 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1869 * GtkWidget::composited-changed:
1870 * @widget: the object on which the signal is emitted
1872 * The ::composited-changed signal is emitted when the composited
1873 * status of @widget<!-- -->s screen changes.
1874 * See gdk_screen_is_composited().
1876 widget_signals[COMPOSITED_CHANGED] =
1877 g_signal_new (I_("composited-changed"),
1878 G_TYPE_FROM_CLASS (klass),
1879 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1880 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1882 _gtk_marshal_VOID__VOID,
1886 * GtkWidget::delete-event:
1887 * @widget: the object which received the signal
1888 * @event: the event which triggered this signal
1890 * The ::delete-event signal is emitted if a user requests that
1891 * a toplevel window is closed. The default handler for this signal
1892 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1893 * this signal will cause the window to be hidden instead, so that
1894 * it can later be shown again without reconstructing it.
1896 * Returns: %TRUE to stop other handlers from being invoked for the event.
1897 * %FALSE to propagate the event further.
1899 widget_signals[DELETE_EVENT] =
1900 g_signal_new (I_("delete-event"),
1901 G_TYPE_FROM_CLASS (klass),
1903 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1904 _gtk_boolean_handled_accumulator, NULL,
1905 _gtk_marshal_BOOLEAN__BOXED,
1907 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1910 * GtkWidget::destroy-event:
1911 * @widget: the object which received the signal.
1912 * @event: the event which triggered this signal
1914 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1915 * You rarely get this signal, because most widgets disconnect themselves
1916 * from their window before they destroy it, so no widget owns the
1917 * window at destroy time.
1919 * To receive this signal, the #GdkWindow associated to the widget needs
1920 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1921 * automatically for all new windows.
1923 * Returns: %TRUE to stop other handlers from being invoked for the event.
1924 * %FALSE to propagate the event further.
1926 widget_signals[DESTROY_EVENT] =
1927 g_signal_new (I_("destroy-event"),
1928 G_TYPE_FROM_CLASS (klass),
1930 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1931 _gtk_boolean_handled_accumulator, NULL,
1932 _gtk_marshal_BOOLEAN__BOXED,
1934 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1937 * GtkWidget::key-press-event:
1938 * @widget: the object which received the signal
1939 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1941 * The ::key-press-event signal is emitted when a key is pressed.
1943 * To receive this signal, the #GdkWindow associated to the widget needs
1944 * to enable the #GDK_KEY_PRESS_MASK mask.
1946 * This signal will be sent to the grab widget if there is one.
1948 * Returns: %TRUE to stop other handlers from being invoked for the event.
1949 * %FALSE to propagate the event further.
1951 widget_signals[KEY_PRESS_EVENT] =
1952 g_signal_new (I_("key-press-event"),
1953 G_TYPE_FROM_CLASS (klass),
1955 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1956 _gtk_boolean_handled_accumulator, NULL,
1957 _gtk_marshal_BOOLEAN__BOXED,
1959 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1962 * GtkWidget::key-release-event:
1963 * @widget: the object which received the signal
1964 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1966 * The ::key-release-event signal is emitted when a key is pressed.
1968 * To receive this signal, the #GdkWindow associated to the widget needs
1969 * to enable the #GDK_KEY_RELEASE_MASK mask.
1971 * This signal will be sent to the grab widget if there is one.
1973 * Returns: %TRUE to stop other handlers from being invoked for the event.
1974 * %FALSE to propagate the event further.
1976 widget_signals[KEY_RELEASE_EVENT] =
1977 g_signal_new (I_("key-release-event"),
1978 G_TYPE_FROM_CLASS (klass),
1980 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1981 _gtk_boolean_handled_accumulator, NULL,
1982 _gtk_marshal_BOOLEAN__BOXED,
1984 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1987 * GtkWidget::enter-notify-event:
1988 * @widget: the object which received the signal
1989 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1992 * The ::enter-notify-event will be emitted when the pointer enters
1993 * the @widget's window.
1995 * To receive this signal, the #GdkWindow associated to the widget needs
1996 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1998 * This signal will be sent to the grab widget if there is one.
2000 * Returns: %TRUE to stop other handlers from being invoked for the event.
2001 * %FALSE to propagate the event further.
2003 widget_signals[ENTER_NOTIFY_EVENT] =
2004 g_signal_new (I_("enter-notify-event"),
2005 G_TYPE_FROM_CLASS (klass),
2007 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
2008 _gtk_boolean_handled_accumulator, NULL,
2009 _gtk_marshal_BOOLEAN__BOXED,
2011 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2014 * GtkWidget::leave-notify-event:
2015 * @widget: the object which received the signal
2016 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
2019 * The ::leave-notify-event will be emitted when the pointer leaves
2020 * the @widget's window.
2022 * To receive this signal, the #GdkWindow associated to the widget needs
2023 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
2025 * This signal will be sent to the grab widget if there is one.
2027 * Returns: %TRUE to stop other handlers from being invoked for the event.
2028 * %FALSE to propagate the event further.
2030 widget_signals[LEAVE_NOTIFY_EVENT] =
2031 g_signal_new (I_("leave-notify-event"),
2032 G_TYPE_FROM_CLASS (klass),
2034 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
2035 _gtk_boolean_handled_accumulator, NULL,
2036 _gtk_marshal_BOOLEAN__BOXED,
2038 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2041 * GtkWidget::configure-event:
2042 * @widget: the object which received the signal
2043 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
2046 * The ::configure-event signal will be emitted when the size, position or
2047 * stacking of the @widget's window has changed.
2049 * To receive this signal, the #GdkWindow associated to the widget needs
2050 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2051 * automatically for all new windows.
2053 * Returns: %TRUE to stop other handlers from being invoked for the event.
2054 * %FALSE to propagate the event further.
2056 widget_signals[CONFIGURE_EVENT] =
2057 g_signal_new (I_("configure-event"),
2058 G_TYPE_FROM_CLASS (klass),
2060 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
2061 _gtk_boolean_handled_accumulator, NULL,
2062 _gtk_marshal_BOOLEAN__BOXED,
2064 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2067 * GtkWidget::focus-in-event:
2068 * @widget: the object which received the signal
2069 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
2072 * The ::focus-in-event signal will be emitted when the keyboard focus
2073 * enters the @widget's window.
2075 * To receive this signal, the #GdkWindow associated to the widget needs
2076 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2078 * Returns: %TRUE to stop other handlers from being invoked for the event.
2079 * %FALSE to propagate the event further.
2081 widget_signals[FOCUS_IN_EVENT] =
2082 g_signal_new (I_("focus-in-event"),
2083 G_TYPE_FROM_CLASS (klass),
2085 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2086 _gtk_boolean_handled_accumulator, NULL,
2087 _gtk_marshal_BOOLEAN__BOXED,
2089 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2092 * GtkWidget::focus-out-event:
2093 * @widget: the object which received the signal
2094 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2097 * The ::focus-out-event signal will be emitted when the keyboard focus
2098 * leaves the @widget's window.
2100 * To receive this signal, the #GdkWindow associated to the widget needs
2101 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2103 * Returns: %TRUE to stop other handlers from being invoked for the event.
2104 * %FALSE to propagate the event further.
2106 widget_signals[FOCUS_OUT_EVENT] =
2107 g_signal_new (I_("focus-out-event"),
2108 G_TYPE_FROM_CLASS (klass),
2110 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2111 _gtk_boolean_handled_accumulator, NULL,
2112 _gtk_marshal_BOOLEAN__BOXED,
2114 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2117 * GtkWidget::map-event:
2118 * @widget: the object which received the signal
2119 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2121 * The ::map-event signal will be emitted when the @widget's window is
2122 * mapped. A window is mapped when it becomes visible on the screen.
2124 * To receive this signal, the #GdkWindow associated to the widget needs
2125 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2126 * automatically for all new windows.
2128 * Returns: %TRUE to stop other handlers from being invoked for the event.
2129 * %FALSE to propagate the event further.
2131 widget_signals[MAP_EVENT] =
2132 g_signal_new (I_("map-event"),
2133 G_TYPE_FROM_CLASS (klass),
2135 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2136 _gtk_boolean_handled_accumulator, NULL,
2137 _gtk_marshal_BOOLEAN__BOXED,
2139 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2142 * GtkWidget::unmap-event:
2143 * @widget: the object which received the signal
2144 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2146 * The ::unmap-event signal may be emitted when the @widget's window is
2147 * unmapped. A window is unmapped when it becomes invisible on the screen.
2149 * For performance reasons GTK+ may not emit ::unmap-event, so one
2150 * should always also implement ::unrealize in order to release
2151 * resources and disconnect signal handlers.
2153 * To receive this signal, the #GdkWindow associated to the widget needs
2154 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2155 * automatically for all new windows.
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[UNMAP_EVENT] =
2161 g_signal_new (I_("unmap-event"),
2162 G_TYPE_FROM_CLASS (klass),
2164 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2171 * GtkWidget::property-notify-event:
2172 * @widget: the object which received the signal
2173 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2176 * The ::property-notify-event signal will be emitted when a property on
2177 * the @widget's window has been changed or deleted.
2179 * To receive this signal, the #GdkWindow associated to the widget needs
2180 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2182 * Returns: %TRUE to stop other handlers from being invoked for the event.
2183 * %FALSE to propagate the event further.
2185 widget_signals[PROPERTY_NOTIFY_EVENT] =
2186 g_signal_new (I_("property-notify-event"),
2187 G_TYPE_FROM_CLASS (klass),
2189 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2190 _gtk_boolean_handled_accumulator, NULL,
2191 _gtk_marshal_BOOLEAN__BOXED,
2193 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2196 * GtkWidget::selection-clear-event:
2197 * @widget: the object which received the signal
2198 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2201 * The ::selection-clear-event signal will be emitted when the
2202 * the @widget's window has lost ownership of a selection.
2204 * Returns: %TRUE to stop other handlers from being invoked for the event.
2205 * %FALSE to propagate the event further.
2207 widget_signals[SELECTION_CLEAR_EVENT] =
2208 g_signal_new (I_("selection-clear-event"),
2209 G_TYPE_FROM_CLASS (klass),
2211 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2212 _gtk_boolean_handled_accumulator, NULL,
2213 _gtk_marshal_BOOLEAN__BOXED,
2215 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2218 * GtkWidget::selection-request-event:
2219 * @widget: the object which received the signal
2220 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2223 * The ::selection-request-event signal will be emitted when
2224 * another client requests ownership of the selection owned by
2225 * the @widget's window.
2227 * Returns: %TRUE to stop other handlers from being invoked for the event.
2228 * %FALSE to propagate the event further.
2230 widget_signals[SELECTION_REQUEST_EVENT] =
2231 g_signal_new (I_("selection-request-event"),
2232 G_TYPE_FROM_CLASS (klass),
2234 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2235 _gtk_boolean_handled_accumulator, NULL,
2236 _gtk_marshal_BOOLEAN__BOXED,
2238 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2241 * GtkWidget::selection-notify-event:
2242 * @widget: the object which received the signal.
2245 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2247 widget_signals[SELECTION_NOTIFY_EVENT] =
2248 g_signal_new (I_("selection-notify-event"),
2249 G_TYPE_FROM_CLASS (klass),
2251 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2252 _gtk_boolean_handled_accumulator, NULL,
2253 _gtk_marshal_BOOLEAN__BOXED,
2255 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2258 * GtkWidget::selection-received:
2259 * @widget: the object which received the signal.
2263 widget_signals[SELECTION_RECEIVED] =
2264 g_signal_new (I_("selection-received"),
2265 G_TYPE_FROM_CLASS (klass),
2267 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2269 _gtk_marshal_VOID__BOXED_UINT,
2271 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2275 * GtkWidget::selection-get:
2276 * @widget: the object which received the signal.
2281 widget_signals[SELECTION_GET] =
2282 g_signal_new (I_("selection-get"),
2283 G_TYPE_FROM_CLASS (klass),
2285 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2287 _gtk_marshal_VOID__BOXED_UINT_UINT,
2289 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2294 * GtkWidget::proximity-in-event:
2295 * @widget: the object which received the signal
2296 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2299 * To receive this signal the #GdkWindow associated to the widget needs
2300 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2302 * This signal will be sent to the grab widget if there is one.
2304 * Returns: %TRUE to stop other handlers from being invoked for the event.
2305 * %FALSE to propagate the event further.
2307 widget_signals[PROXIMITY_IN_EVENT] =
2308 g_signal_new (I_("proximity-in-event"),
2309 G_TYPE_FROM_CLASS (klass),
2311 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2312 _gtk_boolean_handled_accumulator, NULL,
2313 _gtk_marshal_BOOLEAN__BOXED,
2315 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2318 * GtkWidget::proximity-out-event:
2319 * @widget: the object which received the signal
2320 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2323 * To receive this signal the #GdkWindow associated to the widget needs
2324 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2326 * This signal will be sent to the grab widget if there is one.
2328 * Returns: %TRUE to stop other handlers from being invoked for the event.
2329 * %FALSE to propagate the event further.
2331 widget_signals[PROXIMITY_OUT_EVENT] =
2332 g_signal_new (I_("proximity-out-event"),
2333 G_TYPE_FROM_CLASS (klass),
2335 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2336 _gtk_boolean_handled_accumulator, NULL,
2337 _gtk_marshal_BOOLEAN__BOXED,
2339 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2342 * GtkWidget::drag-leave:
2343 * @widget: the object which received the signal.
2344 * @drag_context: the drag context
2345 * @time: the timestamp of the motion event
2347 * The ::drag-leave signal is emitted on the drop site when the cursor
2348 * leaves the widget. A typical reason to connect to this signal is to
2349 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2350 * with gtk_drag_unhighlight()
2352 widget_signals[DRAG_LEAVE] =
2353 g_signal_new (I_("drag-leave"),
2354 G_TYPE_FROM_CLASS (klass),
2356 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2358 _gtk_marshal_VOID__OBJECT_UINT,
2360 GDK_TYPE_DRAG_CONTEXT,
2364 * GtkWidget::drag-begin:
2365 * @widget: the object which received the signal
2366 * @drag_context: the drag context
2368 * The ::drag-begin signal is emitted on the drag source when a drag is
2369 * started. A typical reason to connect to this signal is to set up a
2370 * custom drag icon with gtk_drag_source_set_icon().
2372 * Note that some widgets set up a drag icon in the default handler of
2373 * this signal, so you may have to use g_signal_connect_after() to
2374 * override what the default handler did.
2376 widget_signals[DRAG_BEGIN] =
2377 g_signal_new (I_("drag-begin"),
2378 G_TYPE_FROM_CLASS (klass),
2380 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2382 _gtk_marshal_VOID__OBJECT,
2384 GDK_TYPE_DRAG_CONTEXT);
2387 * GtkWidget::drag-end:
2388 * @widget: the object which received the signal
2389 * @drag_context: the drag context
2391 * The ::drag-end signal is emitted on the drag source when a drag is
2392 * finished. A typical reason to connect to this signal is to undo
2393 * things done in #GtkWidget::drag-begin.
2395 widget_signals[DRAG_END] =
2396 g_signal_new (I_("drag-end"),
2397 G_TYPE_FROM_CLASS (klass),
2399 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2401 _gtk_marshal_VOID__OBJECT,
2403 GDK_TYPE_DRAG_CONTEXT);
2406 * GtkWidget::drag-data-delete:
2407 * @widget: the object which received the signal
2408 * @drag_context: the drag context
2410 * The ::drag-data-delete signal is emitted on the drag source when a drag
2411 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2412 * handler is responsible for deleting the data that has been dropped. What
2413 * "delete" means depends on the context of the drag operation.
2415 widget_signals[DRAG_DATA_DELETE] =
2416 g_signal_new (I_("drag-data-delete"),
2417 G_TYPE_FROM_CLASS (klass),
2419 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2421 _gtk_marshal_VOID__OBJECT,
2423 GDK_TYPE_DRAG_CONTEXT);
2426 * GtkWidget::drag-failed:
2427 * @widget: the object which received the signal
2428 * @drag_context: the drag context
2429 * @result: the result of the drag operation
2431 * The ::drag-failed signal is emitted on the drag source when a drag has
2432 * failed. The signal handler may hook custom code to handle a failed DND
2433 * operation based on the type of error, it returns %TRUE is the failure has
2434 * been already handled (not showing the default "drag operation failed"
2435 * animation), otherwise it returns %FALSE.
2437 * Return value: %TRUE if the failed drag operation has been already handled.
2441 widget_signals[DRAG_FAILED] =
2442 g_signal_new (I_("drag-failed"),
2443 G_TYPE_FROM_CLASS (klass),
2445 0, _gtk_boolean_handled_accumulator, NULL,
2446 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2448 GDK_TYPE_DRAG_CONTEXT,
2449 GTK_TYPE_DRAG_RESULT);
2452 * GtkWidget::drag-motion:
2453 * @widget: the object which received the signal
2454 * @drag_context: the drag context
2455 * @x: the x coordinate of the current cursor position
2456 * @y: the y coordinate of the current cursor position
2457 * @time: the timestamp of the motion event
2458 * @returns: whether the cursor position is in a drop zone
2460 * The drag-motion signal is emitted on the drop site when the user
2461 * moves the cursor over the widget during a drag. The signal handler
2462 * must determine whether the cursor position is in a drop zone or not.
2463 * If it is not in a drop zone, it returns %FALSE and no further processing
2464 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2465 * handler is responsible for providing the necessary information for
2466 * displaying feedback to the user, by calling gdk_drag_status().
2468 * If the decision whether the drop will be accepted or rejected can't be
2469 * made based solely on the cursor position and the type of the data, the
2470 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2471 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2472 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2473 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2474 * when using the drag-motion signal that way.
2476 * Also note that there is no drag-enter signal. The drag receiver has to
2477 * keep track of whether he has received any drag-motion signals since the
2478 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2479 * an "enter" signal. Upon an "enter", the handler will typically highlight
2480 * the drop site with gtk_drag_highlight().
2483 * drag_motion (GtkWidget *widget,
2484 * GdkDragContext *context,
2491 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2493 * if (!private_data->drag_highlight)
2495 * private_data->drag_highlight = 1;
2496 * gtk_drag_highlight (widget);
2499 * target = gtk_drag_dest_find_target (widget, context, NULL);
2500 * if (target == GDK_NONE)
2501 * gdk_drag_status (context, 0, time);
2504 * private_data->pending_status = context->suggested_action;
2505 * gtk_drag_get_data (widget, context, target, time);
2512 * drag_data_received (GtkWidget *widget,
2513 * GdkDragContext *context,
2516 * GtkSelectionData *selection_data,
2520 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2522 * if (private_data->suggested_action)
2524 * private_data->suggested_action = 0;
2526 * /* We are getting this data due to a request in drag_motion,
2527 * * rather than due to a request in drag_drop, so we are just
2528 * * supposed to call gdk_drag_status (), not actually paste in
2531 * str = gtk_selection_data_get_text (selection_data);
2532 * if (!data_is_acceptable (str))
2533 * gdk_drag_status (context, 0, time);
2535 * gdk_drag_status (context, private_data->suggested_action, time);
2539 * /* accept the drop */
2544 widget_signals[DRAG_MOTION] =
2545 g_signal_new (I_("drag-motion"),
2546 G_TYPE_FROM_CLASS (klass),
2548 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2549 _gtk_boolean_handled_accumulator, NULL,
2550 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2552 GDK_TYPE_DRAG_CONTEXT,
2558 * GtkWidget::drag-drop:
2559 * @widget: the object which received the signal
2560 * @drag_context: the drag context
2561 * @x: the x coordinate of the current cursor position
2562 * @y: the y coordinate of the current cursor position
2563 * @time: the timestamp of the motion event
2564 * @returns: whether the cursor position is in a drop zone
2566 * The ::drag-drop signal is emitted on the drop site when the user drops
2567 * the data onto the widget. The signal handler must determine whether
2568 * the cursor position is in a drop zone or not. If it is not in a drop
2569 * zone, it returns %FALSE and no further processing is necessary.
2570 * Otherwise, the handler returns %TRUE. In this case, the handler must
2571 * ensure that gtk_drag_finish() is called to let the source know that
2572 * the drop is done. The call to gtk_drag_finish() can be done either
2573 * directly or in a #GtkWidget::drag-data-received handler which gets
2574 * triggered by calling gtk_drag_get_data() to receive the data for one
2575 * or more of the supported targets.
2577 widget_signals[DRAG_DROP] =
2578 g_signal_new (I_("drag-drop"),
2579 G_TYPE_FROM_CLASS (klass),
2581 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2582 _gtk_boolean_handled_accumulator, NULL,
2583 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2585 GDK_TYPE_DRAG_CONTEXT,
2591 * GtkWidget::drag-data-get:
2592 * @widget: the object which received the signal
2593 * @drag_context: the drag context
2594 * @data: the #GtkSelectionData to be filled with the dragged data
2595 * @info: the info that has been registered with the target in the
2597 * @time: the timestamp at which the data was requested
2599 * The ::drag-data-get signal is emitted on the drag source when the drop
2600 * site requests the data which is dragged. It is the responsibility of
2601 * the signal handler to fill @data with the data in the format which
2602 * is indicated by @info. See gtk_selection_data_set() and
2603 * gtk_selection_data_set_text().
2605 widget_signals[DRAG_DATA_GET] =
2606 g_signal_new (I_("drag-data-get"),
2607 G_TYPE_FROM_CLASS (klass),
2609 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2611 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2613 GDK_TYPE_DRAG_CONTEXT,
2614 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2619 * GtkWidget::drag-data-received:
2620 * @widget: the object which received the signal
2621 * @drag_context: the drag context
2622 * @x: where the drop happened
2623 * @y: where the drop happened
2624 * @data: the received data
2625 * @info: the info that has been registered with the target in the
2627 * @time: the timestamp at which the data was received
2629 * The ::drag-data-received signal is emitted on the drop site when the
2630 * dragged data has been received. If the data was received in order to
2631 * determine whether the drop will be accepted, the handler is expected
2632 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2633 * If the data was received in response to a #GtkWidget::drag-drop signal
2634 * (and this is the last target to be received), the handler for this
2635 * signal is expected to process the received data and then call
2636 * gtk_drag_finish(), setting the @success parameter depending on whether
2637 * the data was processed successfully.
2639 * The handler may inspect and modify @drag_context->action before calling
2640 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2641 * following example:
2644 * drag_data_received (GtkWidget *widget,
2645 * GdkDragContext *drag_context,
2648 * GtkSelectionData *data,
2652 * if ((data->length >= 0) && (data->format == 8))
2654 * if (drag_context->action == GDK_ACTION_ASK)
2656 * GtkWidget *dialog;
2659 * dialog = gtk_message_dialog_new (NULL,
2660 * GTK_DIALOG_MODAL |
2661 * GTK_DIALOG_DESTROY_WITH_PARENT,
2663 * GTK_BUTTONS_YES_NO,
2664 * "Move the data ?\n");
2665 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2666 * gtk_widget_destroy (dialog);
2668 * if (response == GTK_RESPONSE_YES)
2669 * drag_context->action = GDK_ACTION_MOVE;
2671 * drag_context->action = GDK_ACTION_COPY;
2674 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2678 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2682 widget_signals[DRAG_DATA_RECEIVED] =
2683 g_signal_new (I_("drag-data-received"),
2684 G_TYPE_FROM_CLASS (klass),
2686 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2688 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2690 GDK_TYPE_DRAG_CONTEXT,
2693 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2698 * GtkWidget::visibility-notify-event:
2699 * @widget: the object which received the signal
2700 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2701 * triggered this signal.
2703 * The ::visibility-notify-event will be emitted when the @widget's window
2704 * is obscured or unobscured.
2706 * To receive this signal the #GdkWindow associated to the widget needs
2707 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2709 * Returns: %TRUE to stop other handlers from being invoked for the event.
2710 * %FALSE to propagate the event further.
2712 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2713 g_signal_new (I_("visibility-notify-event"),
2714 G_TYPE_FROM_CLASS (klass),
2716 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2717 _gtk_boolean_handled_accumulator, NULL,
2718 _gtk_marshal_BOOLEAN__BOXED,
2720 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2723 * GtkWidget::client-event:
2724 * @widget: the object which received the signal
2725 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2728 * The ::client-event will be emitted when the @widget's window
2729 * receives a message (via a ClientMessage event) from another
2732 * Returns: %TRUE to stop other handlers from being invoked for
2733 * the event. %FALSE to propagate the event further.
2735 widget_signals[CLIENT_EVENT] =
2736 g_signal_new (I_("client-event"),
2737 G_TYPE_FROM_CLASS (klass),
2739 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2740 _gtk_boolean_handled_accumulator, NULL,
2741 _gtk_marshal_BOOLEAN__BOXED,
2743 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2746 * GtkWidget::window-state-event:
2747 * @widget: the object which received the signal
2748 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2749 * triggered this signal.
2751 * The ::window-state-event will be emitted when the state of the
2752 * toplevel window associated to the @widget changes.
2754 * To receive this signal the #GdkWindow associated to the widget
2755 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2756 * this mask automatically for all new windows.
2758 * Returns: %TRUE to stop other handlers from being invoked for the
2759 * event. %FALSE to propagate the event further.
2761 widget_signals[WINDOW_STATE_EVENT] =
2762 g_signal_new (I_("window-state-event"),
2763 G_TYPE_FROM_CLASS (klass),
2765 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2766 _gtk_boolean_handled_accumulator, NULL,
2767 _gtk_marshal_BOOLEAN__BOXED,
2769 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2772 * GtkWidget::damage-event:
2773 * @widget: the object which received the signal
2774 * @event: the #GdkEventExpose event
2776 * Emitted when a redirected window belonging to @widget gets drawn into.
2777 * The region/area members of the event shows what area of the redirected
2778 * drawable was drawn into.
2780 * Returns: %TRUE to stop other handlers from being invoked for the event.
2781 * %FALSE to propagate the event further.
2785 widget_signals[DAMAGE_EVENT] =
2786 g_signal_new (I_("damage-event"),
2787 G_TYPE_FROM_CLASS (klass),
2789 G_STRUCT_OFFSET (GtkWidgetClass, damage_event),
2790 _gtk_boolean_handled_accumulator, NULL,
2791 _gtk_marshal_BOOLEAN__BOXED,
2793 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2796 * GtkWidget::grab-broken-event:
2797 * @widget: the object which received the signal
2798 * @event: the #GdkEventGrabBroken event
2800 * Emitted when a pointer or keyboard grab on a window belonging
2801 * to @widget gets broken.
2803 * On X11, this happens when the grab window becomes unviewable
2804 * (i.e. it or one of its ancestors is unmapped), or if the same
2805 * application grabs the pointer or keyboard again.
2807 * Returns: %TRUE to stop other handlers from being invoked for
2808 * the event. %FALSE to propagate the event further.
2812 widget_signals[GRAB_BROKEN_EVENT] =
2813 g_signal_new (I_("grab-broken-event"),
2814 G_TYPE_FROM_CLASS (klass),
2816 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2817 _gtk_boolean_handled_accumulator, NULL,
2818 _gtk_marshal_BOOLEAN__BOXED,
2820 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2823 * GtkWidget::query-tooltip:
2824 * @widget: the object which received the signal
2825 * @x: the x coordinate of the cursor position where the request has
2826 * been emitted, relative to @widget->window
2827 * @y: the y coordinate of the cursor position where the request has
2828 * been emitted, relative to @widget->window
2829 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2830 * @tooltip: a #GtkTooltip
2832 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2833 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2834 * focus in keyboard mode.
2836 * Using the given coordinates, the signal handler should determine
2837 * whether a tooltip should be shown for @widget. If this is the case
2838 * %TRUE should be returned, %FALSE otherwise. Note that if
2839 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2840 * should not be used.
2842 * The signal handler is free to manipulate @tooltip with the therefore
2843 * destined function calls.
2845 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2849 widget_signals[QUERY_TOOLTIP] =
2850 g_signal_new (I_("query-tooltip"),
2851 G_TYPE_FROM_CLASS (klass),
2853 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2854 _gtk_boolean_handled_accumulator, NULL,
2855 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2863 * GtkWidget::popup-menu
2864 * @widget: the object which received the signal
2866 * This signal gets emitted whenever a widget should pop up a context
2867 * menu. This usually happens through the standard key binding mechanism;
2868 * by pressing a certain key while a widget is focused, the user can cause
2869 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2870 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2871 * for an example of how to use this signal.
2873 * Returns: %TRUE if a menu was activated
2875 widget_signals[POPUP_MENU] =
2876 g_signal_new (I_("popup-menu"),
2877 G_TYPE_FROM_CLASS (klass),
2878 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2879 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2880 _gtk_boolean_handled_accumulator, NULL,
2881 _gtk_marshal_BOOLEAN__VOID,
2885 * GtkWidget::show-help:
2886 * @widget: the object which received the signal.
2889 widget_signals[SHOW_HELP] =
2890 g_signal_new (I_("show-help"),
2891 G_TYPE_FROM_CLASS (klass),
2892 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2893 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2894 _gtk_boolean_handled_accumulator, NULL,
2895 _gtk_marshal_BOOLEAN__ENUM,
2897 GTK_TYPE_WIDGET_HELP_TYPE);
2900 * GtkWidget::accel-closures-changed:
2901 * @widget: the object which received the signal.
2903 widget_signals[ACCEL_CLOSURES_CHANGED] =
2904 g_signal_new (I_("accel-closures-changed"),
2905 G_TYPE_FROM_CLASS (klass),
2909 _gtk_marshal_VOID__VOID,
2913 * GtkWidget::screen-changed:
2914 * @widget: the object on which the signal is emitted
2915 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2916 * widget was not associated with a screen before
2918 * The ::screen-changed signal gets emitted when the
2919 * screen of a widget has changed.
2921 widget_signals[SCREEN_CHANGED] =
2922 g_signal_new (I_("screen-changed"),
2923 G_TYPE_FROM_CLASS (klass),
2925 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2927 _gtk_marshal_VOID__OBJECT,
2932 * GtkWidget::can-activate-accel:
2933 * @widget: the object which received the signal
2934 * @signal_id: the ID of a signal installed on @widget
2936 * Determines whether an accelerator that activates the signal
2937 * identified by @signal_id can currently be activated.
2938 * This signal is present to allow applications and derived
2939 * widgets to override the default #GtkWidget handling
2940 * for determining whether an accelerator can be activated.
2942 * Returns: %TRUE if the signal can be activated.
2944 widget_signals[CAN_ACTIVATE_ACCEL] =
2945 g_signal_new (I_("can-activate-accel"),
2946 G_TYPE_FROM_CLASS (klass),
2948 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2949 _gtk_boolean_handled_accumulator, NULL,
2950 _gtk_marshal_BOOLEAN__UINT,
2951 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2953 binding_set = gtk_binding_set_by_class (klass);
2954 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2956 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2959 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2961 GTK_TYPE_WIDGET_HELP_TYPE,
2962 GTK_WIDGET_HELP_TOOLTIP);
2963 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2965 GTK_TYPE_WIDGET_HELP_TYPE,
2966 GTK_WIDGET_HELP_TOOLTIP);
2967 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2969 GTK_TYPE_WIDGET_HELP_TYPE,
2970 GTK_WIDGET_HELP_WHATS_THIS);
2971 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2973 GTK_TYPE_WIDGET_HELP_TYPE,
2974 GTK_WIDGET_HELP_WHATS_THIS);
2976 gtk_widget_class_install_style_property (klass,
2977 g_param_spec_boolean ("interior-focus",
2978 P_("Interior Focus"),
2979 P_("Whether to draw the focus indicator inside widgets"),
2981 GTK_PARAM_READABLE));
2983 gtk_widget_class_install_style_property (klass,
2984 g_param_spec_int ("focus-line-width",
2985 P_("Focus linewidth"),
2986 P_("Width, in pixels, of the focus indicator line"),
2988 GTK_PARAM_READABLE));
2990 gtk_widget_class_install_style_property (klass,
2991 g_param_spec_string ("focus-line-pattern",
2992 P_("Focus line dash pattern"),
2993 P_("Dash pattern used to draw the focus indicator"),
2995 GTK_PARAM_READABLE));
2996 gtk_widget_class_install_style_property (klass,
2997 g_param_spec_int ("focus-padding",
2998 P_("Focus padding"),
2999 P_("Width, in pixels, between focus indicator and the widget 'box'"),
3001 GTK_PARAM_READABLE));
3002 gtk_widget_class_install_style_property (klass,
3003 g_param_spec_boxed ("cursor-color",
3005 P_("Color with which to draw insertion cursor"),
3007 GTK_PARAM_READABLE));
3008 gtk_widget_class_install_style_property (klass,
3009 g_param_spec_boxed ("secondary-cursor-color",
3010 P_("Secondary cursor color"),
3011 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
3013 GTK_PARAM_READABLE));
3014 gtk_widget_class_install_style_property (klass,
3015 g_param_spec_float ("cursor-aspect-ratio",
3016 P_("Cursor line aspect ratio"),
3017 P_("Aspect ratio with which to draw insertion cursor"),
3019 GTK_PARAM_READABLE));
3021 gtk_widget_class_install_style_property (klass,
3022 g_param_spec_boolean ("window-dragging",
3023 P_("Window dragging"),
3024 P_("Whether windows can be dragged by clicking on empty areas"),
3026 GTK_PARAM_READABLE));
3029 * GtkWidget:link-color:
3031 * The "link-color" style property defines the color of unvisited links.
3035 gtk_widget_class_install_style_property (klass,
3036 g_param_spec_boxed ("link-color",
3037 P_("Unvisited Link Color"),
3038 P_("Color of unvisited links"),
3040 GTK_PARAM_READABLE));
3043 * GtkWidget:visited-link-color:
3045 * The "visited-link-color" style property defines the color of visited links.
3049 gtk_widget_class_install_style_property (klass,
3050 g_param_spec_boxed ("visited-link-color",
3051 P_("Visited Link Color"),
3052 P_("Color of visited links"),
3054 GTK_PARAM_READABLE));
3057 * GtkWidget:wide-separators:
3059 * The "wide-separators" style property defines whether separators have
3060 * configurable width and should be drawn using a box instead of a line.
3064 gtk_widget_class_install_style_property (klass,
3065 g_param_spec_boolean ("wide-separators",
3066 P_("Wide Separators"),
3067 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3069 GTK_PARAM_READABLE));
3072 * GtkWidget:separator-width:
3074 * The "separator-width" style property defines the width of separators.
3075 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3079 gtk_widget_class_install_style_property (klass,
3080 g_param_spec_int ("separator-width",
3081 P_("Separator Width"),
3082 P_("The width of separators if wide-separators is TRUE"),
3084 GTK_PARAM_READABLE));
3087 * GtkWidget:separator-height:
3089 * The "separator-height" style property defines the height of separators.
3090 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3094 gtk_widget_class_install_style_property (klass,
3095 g_param_spec_int ("separator-height",
3096 P_("Separator Height"),
3097 P_("The height of separators if \"wide-separators\" is TRUE"),
3099 GTK_PARAM_READABLE));
3102 * GtkWidget:scroll-arrow-hlength:
3104 * The "scroll-arrow-hlength" style property defines the length of
3105 * horizontal scroll arrows.
3109 gtk_widget_class_install_style_property (klass,
3110 g_param_spec_int ("scroll-arrow-hlength",
3111 P_("Horizontal Scroll Arrow Length"),
3112 P_("The length of horizontal scroll arrows"),
3114 GTK_PARAM_READABLE));
3117 * GtkWidget:scroll-arrow-vlength:
3119 * The "scroll-arrow-vlength" style property defines the length of
3120 * vertical scroll arrows.
3124 gtk_widget_class_install_style_property (klass,
3125 g_param_spec_int ("scroll-arrow-vlength",
3126 P_("Vertical Scroll Arrow Length"),
3127 P_("The length of vertical scroll arrows"),
3129 GTK_PARAM_READABLE));
3131 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3135 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3139 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3140 for (node = list; node; node = node->next)
3142 GParamSpec *pspec = node->data;
3144 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3145 g_param_spec_unref (pspec);
3151 gtk_widget_set_property (GObject *object,
3153 const GValue *value,
3156 GtkWidget *widget = GTK_WIDGET (object);
3161 gchar *tooltip_markup;
3162 const gchar *tooltip_text;
3163 GtkWindow *tooltip_window;
3166 gtk_widget_set_name (widget, g_value_get_string (value));
3169 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3171 case PROP_WIDTH_REQUEST:
3172 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3174 case PROP_HEIGHT_REQUEST:
3175 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3178 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3180 case PROP_SENSITIVE:
3181 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3183 case PROP_APP_PAINTABLE:
3184 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3186 case PROP_CAN_FOCUS:
3187 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3189 case PROP_HAS_FOCUS:
3190 if (g_value_get_boolean (value))
3191 gtk_widget_grab_focus (widget);
3194 if (g_value_get_boolean (value))
3195 gtk_widget_grab_focus (widget);
3197 case PROP_CAN_DEFAULT:
3198 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3200 case PROP_HAS_DEFAULT:
3201 if (g_value_get_boolean (value))
3202 gtk_widget_grab_default (widget);
3204 case PROP_RECEIVES_DEFAULT:
3205 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3208 gtk_widget_set_style (widget, g_value_get_object (value));
3211 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3212 gtk_widget_set_events (widget, g_value_get_flags (value));
3214 case PROP_EXTENSION_EVENTS:
3215 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3217 case PROP_NO_SHOW_ALL:
3218 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3220 case PROP_HAS_TOOLTIP:
3221 gtk_widget_real_set_has_tooltip (widget,
3222 g_value_get_boolean (value), FALSE);
3224 case PROP_TOOLTIP_MARKUP:
3225 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3226 tooltip_markup = g_value_dup_string (value);
3228 /* Treat an empty string as a NULL string,
3229 * because an empty string would be useless for a tooltip:
3231 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3233 g_free (tooltip_markup);
3234 tooltip_markup = NULL;
3237 g_object_set_qdata_full (object, quark_tooltip_markup,
3238 tooltip_markup, g_free);
3240 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3241 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3242 if (gtk_widget_get_visible (widget))
3243 gtk_widget_queue_tooltip_query (widget);
3245 case PROP_TOOLTIP_TEXT:
3246 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3248 tooltip_text = g_value_get_string (value);
3250 /* Treat an empty string as a NULL string,
3251 * because an empty string would be useless for a tooltip:
3253 if (tooltip_text && (strlen (tooltip_text) == 0))
3254 tooltip_text = NULL;
3256 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3258 g_object_set_qdata_full (object, quark_tooltip_markup,
3259 tooltip_markup, g_free);
3261 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3262 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3263 if (gtk_widget_get_visible (widget))
3264 gtk_widget_queue_tooltip_query (widget);
3266 case PROP_DOUBLE_BUFFERED:
3267 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3270 gtk_widget_set_halign (widget, g_value_get_enum (value));
3273 gtk_widget_set_valign (widget, g_value_get_enum (value));
3275 case PROP_MARGIN_LEFT:
3276 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3278 case PROP_MARGIN_RIGHT:
3279 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3281 case PROP_MARGIN_TOP:
3282 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3284 case PROP_MARGIN_BOTTOM:
3285 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3288 g_object_freeze_notify (G_OBJECT (widget));
3289 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3290 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3291 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3292 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3293 g_object_thaw_notify (G_OBJECT (widget));
3296 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3298 case PROP_HEXPAND_SET:
3299 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3302 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3304 case PROP_VEXPAND_SET:
3305 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3308 g_object_freeze_notify (G_OBJECT (widget));
3309 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3310 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3311 g_object_thaw_notify (G_OBJECT (widget));
3314 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3320 gtk_widget_get_property (GObject *object,
3325 GtkWidget *widget = GTK_WIDGET (object);
3326 GtkWidgetPrivate *priv = widget->priv;
3335 g_value_set_string (value, priv->name);
3337 g_value_set_static_string (value, "");
3340 g_value_set_object (value, priv->parent);
3342 case PROP_WIDTH_REQUEST:
3345 gtk_widget_get_size_request (widget, &w, NULL);
3346 g_value_set_int (value, w);
3349 case PROP_HEIGHT_REQUEST:
3352 gtk_widget_get_size_request (widget, NULL, &h);
3353 g_value_set_int (value, h);
3357 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3359 case PROP_SENSITIVE:
3360 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3362 case PROP_APP_PAINTABLE:
3363 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3365 case PROP_CAN_FOCUS:
3366 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3368 case PROP_HAS_FOCUS:
3369 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3372 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3374 case PROP_CAN_DEFAULT:
3375 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3377 case PROP_HAS_DEFAULT:
3378 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3380 case PROP_RECEIVES_DEFAULT:
3381 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3383 case PROP_COMPOSITE_CHILD:
3384 g_value_set_boolean (value, widget->priv->composite_child);
3387 g_value_set_object (value, gtk_widget_get_style (widget));
3390 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3391 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3393 case PROP_EXTENSION_EVENTS:
3394 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3395 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3397 case PROP_NO_SHOW_ALL:
3398 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3400 case PROP_HAS_TOOLTIP:
3401 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3403 case PROP_TOOLTIP_TEXT:
3405 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3408 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3409 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3411 g_value_take_string (value, text);
3414 case PROP_TOOLTIP_MARKUP:
3415 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3418 g_value_set_object (value, gtk_widget_get_window (widget));
3420 case PROP_DOUBLE_BUFFERED:
3421 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3424 g_value_set_enum (value, gtk_widget_get_halign (widget));
3427 g_value_set_enum (value, gtk_widget_get_valign (widget));
3429 case PROP_MARGIN_LEFT:
3430 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3432 case PROP_MARGIN_RIGHT:
3433 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3435 case PROP_MARGIN_TOP:
3436 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3438 case PROP_MARGIN_BOTTOM:
3439 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3443 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3444 if (aux_info == NULL)
3446 g_value_set_int (value, 0);
3450 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3451 aux_info->margin.right),
3452 MAX (aux_info->margin.top,
3453 aux_info->margin.bottom)));
3458 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3460 case PROP_HEXPAND_SET:
3461 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3464 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3466 case PROP_VEXPAND_SET:
3467 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3470 g_value_set_boolean (value,
3471 gtk_widget_get_hexpand (widget) &&
3472 gtk_widget_get_vexpand (widget));
3475 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3481 gtk_widget_init (GtkWidget *widget)
3483 GtkWidgetPrivate *priv;
3485 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3488 priv = widget->priv;
3490 priv->child_visible = TRUE;
3492 priv->allocation.x = -1;
3493 priv->allocation.y = -1;
3494 priv->allocation.width = 1;
3495 priv->allocation.height = 1;
3496 priv->window = NULL;
3497 priv->parent = NULL;
3499 priv->sensitive = TRUE;
3500 priv->parent_sensitive = TRUE;
3501 priv->composite_child = composite_child_stack != 0;
3502 priv->double_buffered = TRUE;
3503 priv->redraw_on_alloc = TRUE;
3504 priv->width_request_needed = TRUE;
3505 priv->height_request_needed = TRUE;
3506 priv->alloc_needed = TRUE;
3508 /* this will be set to TRUE if the widget gets a child or if the
3509 * expand flag is set on the widget, but until one of those happen
3510 * we know the expand is already properly FALSE.
3512 * We really want to default FALSE here to avoid computing expand
3513 * all over the place while initially building a widget tree.
3515 priv->need_compute_expand = FALSE;
3517 priv->style = gtk_widget_get_default_style ();
3518 g_object_ref (priv->style);
3523 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3525 GParamSpec **pspecs)
3527 GtkWidgetPrivate *priv = widget->priv;
3528 GtkWidget *container = priv->parent;
3531 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3532 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3536 * gtk_widget_freeze_child_notify:
3537 * @widget: a #GtkWidget
3539 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3540 * signals are queued until gtk_widget_thaw_child_notify() is called
3543 * This is the analogue of g_object_freeze_notify() for child properties.
3546 gtk_widget_freeze_child_notify (GtkWidget *widget)
3548 g_return_if_fail (GTK_IS_WIDGET (widget));
3550 if (!G_OBJECT (widget)->ref_count)
3553 g_object_ref (widget);
3554 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3555 g_object_unref (widget);
3559 * gtk_widget_child_notify:
3560 * @widget: a #GtkWidget
3561 * @child_property: the name of a child property installed on the
3562 * class of @widget<!-- -->'s parent
3564 * Emits a #GtkWidget::child-notify signal for the
3565 * <link linkend="child-properties">child property</link> @child_property
3568 * This is the analogue of g_object_notify() for child properties.
3571 gtk_widget_child_notify (GtkWidget *widget,
3572 const gchar *child_property)
3574 GtkWidgetPrivate *priv = widget->priv;
3577 g_return_if_fail (GTK_IS_WIDGET (widget));
3578 g_return_if_fail (child_property != NULL);
3579 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3582 g_object_ref (widget);
3583 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3585 G_OBJECT_TYPE (priv->parent),
3588 g_warning ("%s: container class `%s' has no child property named `%s'",
3590 G_OBJECT_TYPE_NAME (priv->parent),
3594 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3596 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3597 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3599 g_object_unref (widget);
3603 * gtk_widget_thaw_child_notify:
3604 * @widget: a #GtkWidget
3606 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3607 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3611 gtk_widget_thaw_child_notify (GtkWidget *widget)
3613 GObjectNotifyQueue *nqueue;
3615 g_return_if_fail (GTK_IS_WIDGET (widget));
3617 if (!G_OBJECT (widget)->ref_count)
3620 g_object_ref (widget);
3621 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3622 if (!nqueue || !nqueue->freeze_count)
3623 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3624 G_OBJECT_TYPE_NAME (widget), widget);
3626 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3627 g_object_unref (widget);
3633 * @type: type ID of the widget to create
3634 * @first_property_name: name of first property to set
3635 * @Varargs: value of first property, followed by more properties,
3638 * This is a convenience function for creating a widget and setting
3639 * its properties in one go. For example you might write:
3640 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3641 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3642 * g_object_new(), but returns a widget so you don't have to
3643 * cast the object yourself.
3645 * Return value: a new #GtkWidget of type @widget_type
3648 gtk_widget_new (GType type,
3649 const gchar *first_property_name,
3655 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3657 va_start (var_args, first_property_name);
3658 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3665 gtk_widget_queue_draw_child (GtkWidget *widget)
3667 GtkWidgetPrivate *priv = widget->priv;
3670 parent = priv->parent;
3671 if (parent && gtk_widget_is_drawable (parent))
3672 gtk_widget_queue_draw_area (parent,
3675 priv->allocation.width,
3676 priv->allocation.height);
3680 * gtk_widget_unparent:
3681 * @widget: a #GtkWidget
3683 * This function is only for use in widget implementations.
3684 * Should be called by implementations of the remove method
3685 * on #GtkContainer, to dissociate a child from the container.
3688 gtk_widget_unparent (GtkWidget *widget)
3690 GtkWidgetPrivate *priv;
3691 GObjectNotifyQueue *nqueue;
3692 GtkWidget *toplevel;
3693 GtkWidget *old_parent;
3695 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 priv = widget->priv;
3699 if (priv->parent == NULL)
3702 /* keep this function in sync with gtk_menu_detach()
3705 g_object_freeze_notify (G_OBJECT (widget));
3706 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3708 toplevel = gtk_widget_get_toplevel (widget);
3709 if (gtk_widget_is_toplevel (toplevel))
3710 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3712 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3713 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3715 /* If we are unanchoring the child, we save around the toplevel
3716 * to emit hierarchy changed
3718 if (priv->parent->priv->anchored)
3719 g_object_ref (toplevel);
3723 gtk_widget_queue_draw_child (widget);
3725 /* Reset the width and height here, to force reallocation if we
3726 * get added back to a new parent. This won't work if our new
3727 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3728 * (would 0x0 be OK here?)
3730 priv->allocation.width = 1;
3731 priv->allocation.height = 1;
3733 if (gtk_widget_get_realized (widget))
3735 if (priv->in_reparent)
3736 gtk_widget_unmap (widget);
3738 gtk_widget_unrealize (widget);
3741 /* Removing a widget from a container restores the child visible
3742 * flag to the default state, so it doesn't affect the child
3743 * in the next parent.
3745 priv->child_visible = TRUE;
3747 old_parent = priv->parent;
3748 priv->parent = NULL;
3749 gtk_widget_set_parent_window (widget, NULL);
3751 /* parent may no longer expand if the removed
3752 * child was expand=TRUE and could therefore
3755 if (gtk_widget_get_visible (widget) &&
3756 (priv->need_compute_expand ||
3757 priv->computed_hexpand ||
3758 priv->computed_vexpand))
3760 gtk_widget_queue_compute_expand (old_parent);
3763 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3766 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3767 g_object_unref (toplevel);
3770 g_object_notify (G_OBJECT (widget), "parent");
3771 g_object_thaw_notify (G_OBJECT (widget));
3773 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3774 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3775 g_object_unref (widget);
3779 * gtk_widget_destroy:
3780 * @widget: a #GtkWidget
3782 * Destroys a widget.
3785 * destroyed, it will break any references it holds to other objects.
3786 * If the widget is inside a container, the widget will be removed
3787 * from the container. If the widget is a toplevel (derived from
3788 * #GtkWindow), it will be removed from the list of toplevels, and the
3789 * reference GTK+ holds to it will be removed. Removing a
3790 * widget from its container or the list of toplevels results in the
3791 * widget being finalized, unless you've added additional references
3792 * to the widget with g_object_ref().
3794 * In most cases, only toplevel widgets (windows) require explicit
3795 * destruction, because when you destroy a toplevel its children will
3796 * be destroyed as well.
3799 gtk_widget_destroy (GtkWidget *widget)
3801 g_return_if_fail (GTK_IS_WIDGET (widget));
3803 if (!widget->priv->in_destruction)
3804 g_object_run_dispose (G_OBJECT (widget));
3808 * gtk_widget_destroyed:
3809 * @widget: a #GtkWidget
3810 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3812 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3813 * %NULL. It's intended to be used as a callback connected to the
3814 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3815 * as a signal handler, and pass the address of your widget variable
3816 * as user data. Then when the widget is destroyed, the variable will
3817 * be set to %NULL. Useful for example to avoid multiple copies
3818 * of the same dialog.
3821 gtk_widget_destroyed (GtkWidget *widget,
3822 GtkWidget **widget_pointer)
3824 /* Don't make any assumptions about the
3826 * Even check widget_pointer.
3829 *widget_pointer = NULL;
3834 * @widget: a #GtkWidget
3836 * Flags a widget to be displayed. Any widget that isn't shown will
3837 * not appear on the screen. If you want to show all the widgets in a
3838 * container, it's easier to call gtk_widget_show_all() on the
3839 * container, instead of individually showing the widgets.
3841 * Remember that you have to show the containers containing a widget,
3842 * in addition to the widget itself, before it will appear onscreen.
3844 * When a toplevel container is shown, it is immediately realized and
3845 * mapped; other shown widgets are realized and mapped when their
3846 * toplevel container is realized and mapped.
3849 gtk_widget_show (GtkWidget *widget)
3851 g_return_if_fail (GTK_IS_WIDGET (widget));
3853 if (!gtk_widget_get_visible (widget))
3855 g_object_ref (widget);
3856 if (!gtk_widget_is_toplevel (widget))
3857 gtk_widget_queue_resize (widget);
3859 /* see comment in set_parent() for why this should and can be
3862 if (widget->priv->need_compute_expand ||
3863 widget->priv->computed_hexpand ||
3864 widget->priv->computed_vexpand)
3866 if (widget->priv->parent != NULL)
3867 gtk_widget_queue_compute_expand (widget->priv->parent);
3870 g_signal_emit (widget, widget_signals[SHOW], 0);
3871 g_object_notify (G_OBJECT (widget), "visible");
3872 g_object_unref (widget);
3877 gtk_widget_real_show (GtkWidget *widget)
3879 GtkWidgetPrivate *priv = widget->priv;
3881 if (!gtk_widget_get_visible (widget))
3883 priv->visible = TRUE;
3886 gtk_widget_get_mapped (priv->parent) &&
3887 gtk_widget_get_child_visible (widget) &&
3888 !gtk_widget_get_mapped (widget))
3889 gtk_widget_map (widget);
3894 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3897 g_signal_handlers_disconnect_by_func (widget,
3898 gtk_widget_show_map_callback,
3903 * gtk_widget_show_now:
3904 * @widget: a #GtkWidget
3906 * Shows a widget. If the widget is an unmapped toplevel widget
3907 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3908 * loop and wait for the window to actually be mapped. Be careful;
3909 * because the main loop is running, anything can happen during
3913 gtk_widget_show_now (GtkWidget *widget)
3917 g_return_if_fail (GTK_IS_WIDGET (widget));
3919 /* make sure we will get event */
3920 if (!gtk_widget_get_mapped (widget) &&
3921 gtk_widget_is_toplevel (widget))
3923 gtk_widget_show (widget);
3925 g_signal_connect (widget, "map-event",
3926 G_CALLBACK (gtk_widget_show_map_callback),
3930 gtk_main_iteration ();
3933 gtk_widget_show (widget);
3938 * @widget: a #GtkWidget
3940 * Reverses the effects of gtk_widget_show(), causing the widget to be
3941 * hidden (invisible to the user).
3944 gtk_widget_hide (GtkWidget *widget)
3946 g_return_if_fail (GTK_IS_WIDGET (widget));
3948 if (gtk_widget_get_visible (widget))
3950 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3952 g_object_ref (widget);
3953 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3954 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3956 /* a parent may now be expand=FALSE since we're hidden. */
3957 if (widget->priv->need_compute_expand ||
3958 widget->priv->computed_hexpand ||
3959 widget->priv->computed_vexpand)
3961 gtk_widget_queue_compute_expand (widget);
3964 g_signal_emit (widget, widget_signals[HIDE], 0);
3965 if (!gtk_widget_is_toplevel (widget))
3966 gtk_widget_queue_resize (widget);
3967 g_object_notify (G_OBJECT (widget), "visible");
3968 g_object_unref (widget);
3973 gtk_widget_real_hide (GtkWidget *widget)
3975 if (gtk_widget_get_visible (widget))
3977 widget->priv->visible = FALSE;
3979 if (gtk_widget_get_mapped (widget))
3980 gtk_widget_unmap (widget);
3985 * gtk_widget_hide_on_delete:
3986 * @widget: a #GtkWidget
3988 * Utility function; intended to be connected to the #GtkWidget::delete-event
3989 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3990 * argument, then returns %TRUE. If connected to ::delete-event, the
3991 * result is that clicking the close button for a window (on the
3992 * window frame, top right corner usually) will hide but not destroy
3993 * the window. By default, GTK+ destroys windows when ::delete-event
3996 * Return value: %TRUE
3999 gtk_widget_hide_on_delete (GtkWidget *widget)
4001 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4003 gtk_widget_hide (widget);
4009 * gtk_widget_show_all:
4010 * @widget: a #GtkWidget
4012 * Recursively shows a widget, and any child widgets (if the widget is
4016 gtk_widget_show_all (GtkWidget *widget)
4018 GtkWidgetClass *class;
4020 g_return_if_fail (GTK_IS_WIDGET (widget));
4022 if (gtk_widget_get_no_show_all (widget))
4025 class = GTK_WIDGET_GET_CLASS (widget);
4027 if (class->show_all)
4028 class->show_all (widget);
4033 * @widget: a #GtkWidget
4035 * This function is only for use in widget implementations. Causes
4036 * a widget to be mapped if it isn't already.
4039 gtk_widget_map (GtkWidget *widget)
4041 GtkWidgetPrivate *priv;
4043 g_return_if_fail (GTK_IS_WIDGET (widget));
4044 g_return_if_fail (gtk_widget_get_visible (widget));
4045 g_return_if_fail (gtk_widget_get_child_visible (widget));
4047 priv = widget->priv;
4049 if (!gtk_widget_get_mapped (widget))
4051 if (!gtk_widget_get_realized (widget))
4052 gtk_widget_realize (widget);
4054 g_signal_emit (widget, widget_signals[MAP], 0);
4056 if (!gtk_widget_get_has_window (widget))
4057 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4063 * @widget: a #GtkWidget
4065 * This function is only for use in widget implementations. Causes
4066 * a widget to be unmapped if it's currently mapped.
4069 gtk_widget_unmap (GtkWidget *widget)
4071 GtkWidgetPrivate *priv;
4073 g_return_if_fail (GTK_IS_WIDGET (widget));
4075 priv = widget->priv;
4077 if (gtk_widget_get_mapped (widget))
4079 if (!gtk_widget_get_has_window (widget))
4080 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4081 _gtk_tooltip_hide (widget);
4082 g_signal_emit (widget, widget_signals[UNMAP], 0);
4087 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4088 GdkExtensionMode mode,
4091 GtkWidgetPrivate *priv = widget->priv;
4092 GList *free_list = NULL;
4095 if (window_list == NULL)
4097 if (gtk_widget_get_has_window (widget))
4098 window_list = g_list_prepend (NULL, priv->window);
4100 window_list = gdk_window_get_children (priv->window);
4102 free_list = window_list;
4105 for (l = window_list; l != NULL; l = l->next)
4107 GdkWindow *window = l->data;
4110 gdk_window_get_user_data (window, &user_data);
4111 if (user_data == widget)
4115 gdk_input_set_extension_events (window,
4116 gdk_window_get_events (window),
4119 children = gdk_window_get_children (window);
4122 gtk_widget_set_extension_events_internal (widget, mode, children);
4123 g_list_free (children);
4129 g_list_free (free_list);
4133 _gtk_widget_enable_device_events (GtkWidget *widget)
4135 GHashTable *device_events;
4136 GHashTableIter iter;
4137 gpointer key, value;
4139 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4144 g_hash_table_iter_init (&iter, device_events);
4146 while (g_hash_table_iter_next (&iter, &key, &value))
4149 GdkEventMask event_mask;
4152 event_mask = GPOINTER_TO_UINT (value);
4153 gtk_widget_add_events_internal (widget, device, event_mask);
4158 * gtk_widget_realize:
4159 * @widget: a #GtkWidget
4161 * Creates the GDK (windowing system) resources associated with a
4162 * widget. For example, @widget->window will be created when a widget
4163 * is realized. Normally realization happens implicitly; if you show
4164 * a widget and all its parent containers, then the widget will be
4165 * realized and mapped automatically.
4167 * Realizing a widget requires all
4168 * the widget's parent widgets to be realized; calling
4169 * gtk_widget_realize() realizes the widget's parents in addition to
4170 * @widget itself. If a widget is not yet inside a toplevel window
4171 * when you realize it, bad things will happen.
4173 * This function is primarily used in widget implementations, and
4174 * isn't very useful otherwise. Many times when you think you might
4175 * need it, a better approach is to connect to a signal that will be
4176 * called after the widget is realized automatically, such as
4177 * #GtkWidget::expose-event. Or simply g_signal_connect () to the
4178 * #GtkWidget::realize signal.
4181 gtk_widget_realize (GtkWidget *widget)
4183 GtkWidgetPrivate *priv;
4184 GdkExtensionMode mode;
4185 cairo_region_t *region;
4187 g_return_if_fail (GTK_IS_WIDGET (widget));
4188 g_return_if_fail (widget->priv->anchored ||
4189 GTK_IS_INVISIBLE (widget));
4191 priv = widget->priv;
4193 if (!gtk_widget_get_realized (widget))
4196 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4197 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4200 if (priv->parent == NULL &&
4201 !gtk_widget_is_toplevel (widget))
4202 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4203 "inside a toplevel window is not going to work very well. "
4204 "Widgets must be inside a toplevel container before realizing them.");
4206 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4207 gtk_widget_realize (priv->parent);
4209 gtk_widget_ensure_style (widget);
4211 g_signal_emit (widget, widget_signals[REALIZE], 0);
4213 gtk_widget_real_set_has_tooltip (widget,
4214 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4217 if (priv->has_shape_mask)
4219 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4220 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4223 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4225 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4227 mode = gtk_widget_get_extension_events (widget);
4228 if (mode != GDK_EXTENSION_EVENTS_NONE)
4229 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4231 if (priv->multidevice)
4232 gdk_window_set_support_multidevice (priv->window, TRUE);
4234 _gtk_widget_enable_device_events (widget);
4239 * gtk_widget_unrealize:
4240 * @widget: a #GtkWidget
4242 * This function is only useful in widget implementations.
4243 * Causes a widget to be unrealized (frees all GDK resources
4244 * associated with the widget, such as @widget->window).
4247 gtk_widget_unrealize (GtkWidget *widget)
4249 g_return_if_fail (GTK_IS_WIDGET (widget));
4251 if (widget->priv->has_shape_mask)
4252 gtk_widget_shape_combine_region (widget, NULL);
4254 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4255 gtk_widget_input_shape_combine_region (widget, NULL);
4257 if (gtk_widget_get_realized (widget))
4259 g_object_ref (widget);
4260 _gtk_tooltip_hide (widget);
4261 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4262 gtk_widget_set_realized (widget, FALSE);
4263 gtk_widget_set_mapped (widget, FALSE);
4264 g_object_unref (widget);
4268 /*****************************************
4270 *****************************************/
4273 * gtk_widget_queue_draw_region:
4274 * @widget: a #GtkWidget
4275 * @region: region to draw
4277 * Invalidates the rectangular area of @widget defined by @region by
4278 * calling gdk_window_invalidate_region() on the widget's window and
4279 * all its child windows. Once the main loop becomes idle (after the
4280 * current batch of events has been processed, roughly), the window
4281 * will receive expose events for the union of all regions that have
4284 * Normally you would only use this function in widget
4285 * implementations. You might also use it to schedule a redraw of a
4286 * #GtkDrawingArea or some portion thereof.
4289 gtk_widget_queue_draw_region (GtkWidget *widget,
4290 cairo_region_t *region)
4292 GtkWidgetPrivate *priv;
4295 g_return_if_fail (GTK_IS_WIDGET (widget));
4297 priv = widget->priv;
4299 if (!gtk_widget_get_realized (widget))
4302 /* Just return if the widget or one of its ancestors isn't mapped */
4303 for (w = widget; w != NULL; w = w->priv->parent)
4304 if (!gtk_widget_get_mapped (w))
4307 gdk_window_invalidate_region (priv->window, region, TRUE);
4311 * gtk_widget_queue_draw_area:
4312 * @widget: a #GtkWidget
4313 * @x: x coordinate of upper-left corner of rectangle to redraw
4314 * @y: y coordinate of upper-left corner of rectangle to redraw
4315 * @width: width of region to draw
4316 * @height: height of region to draw
4318 * Convenience function that calls gtk_widget_queue_draw_region() on
4319 * the region created from the given coordinates.
4322 gtk_widget_queue_draw_area (GtkWidget *widget,
4329 cairo_region_t *region;
4331 g_return_if_fail (GTK_IS_WIDGET (widget));
4336 rect.height = height;
4338 region = cairo_region_create_rectangle (&rect);
4339 gtk_widget_queue_draw_region (widget, region);
4340 cairo_region_destroy (region);
4344 * gtk_widget_queue_draw:
4345 * @widget: a #GtkWidget
4347 * Equivalent to calling gtk_widget_queue_draw_area() for the
4348 * entire area of a widget.
4351 gtk_widget_queue_draw (GtkWidget *widget)
4355 g_return_if_fail (GTK_IS_WIDGET (widget));
4357 gtk_widget_get_allocation (widget, &rect);
4359 if (!gtk_widget_get_has_window (widget))
4360 gtk_widget_queue_draw_area (widget,
4361 rect.x, rect.y, rect.width, rect.height);
4363 gtk_widget_queue_draw_area (widget,
4364 0, 0, rect.width, rect.height);
4368 * gtk_widget_queue_resize:
4369 * @widget: a #GtkWidget
4371 * This function is only for use in widget implementations.
4372 * Flags a widget to have its size renegotiated; should
4373 * be called when a widget for some reason has a new size request.
4374 * For example, when you change the text in a #GtkLabel, #GtkLabel
4375 * queues a resize to ensure there's enough space for the new text.
4377 * <note><para>You cannot call gtk_widget_queue_resize() on a widget
4378 * from inside it's implementation of the GtkWidgetClass::size_allocate
4379 * virtual method. Calls to gtk_widget_queue_resize() from inside
4380 * GtkWidgetClass::size_allocate will be silently ignored.</para></note>
4383 gtk_widget_queue_resize (GtkWidget *widget)
4385 g_return_if_fail (GTK_IS_WIDGET (widget));
4387 if (gtk_widget_get_realized (widget))
4388 gtk_widget_queue_shallow_draw (widget);
4390 _gtk_size_group_queue_resize (widget, 0);
4394 * gtk_widget_queue_resize_no_redraw:
4395 * @widget: a #GtkWidget
4397 * This function works like gtk_widget_queue_resize(),
4398 * except that the widget is not invalidated.
4403 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4405 g_return_if_fail (GTK_IS_WIDGET (widget));
4407 _gtk_size_group_queue_resize (widget, 0);
4411 * gtk_widget_size_request:
4412 * @widget: a #GtkWidget
4413 * @requisition: (out): a #GtkRequisition to be filled in
4415 * This function is typically used when implementing a #GtkContainer
4416 * subclass. Obtains the preferred size of a widget. The container
4417 * uses this information to arrange its child widgets and decide what
4418 * size allocations to give them with gtk_widget_size_allocate().
4420 * You can also call this function from an application, with some
4421 * caveats. Most notably, getting a size request requires the widget
4422 * to be associated with a screen, because font information may be
4423 * needed. Multihead-aware applications should keep this in mind.
4425 * Also remember that the size request is not necessarily the size
4426 * a widget will actually be allocated.
4428 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4431 gtk_widget_size_request (GtkWidget *widget,
4432 GtkRequisition *requisition)
4434 g_return_if_fail (GTK_IS_WIDGET (widget));
4436 gtk_widget_get_preferred_size (widget, requisition, NULL);
4440 * gtk_widget_get_child_requisition:
4441 * @widget: a #GtkWidget
4442 * @requisition: (out): a #GtkRequisition to be filled in
4444 * This function is only for use in widget implementations. Obtains
4445 * @widget->requisition, unless someone has forced a particular
4446 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4447 * in which case it returns that geometry instead of the widget's
4450 * This function differs from gtk_widget_size_request() in that
4451 * it retrieves the last size request value from @widget->requisition,
4452 * while gtk_widget_size_request() actually calls the "size_request" method
4453 * on @widget to compute the size request and fill in @widget->requisition,
4454 * and only then returns @widget->requisition.
4456 * Because this function does not call the "size_request" method, it
4457 * can only be used when you know that @widget->requisition is
4458 * up-to-date, that is, gtk_widget_size_request() has been called
4459 * since the last time a resize was queued. In general, only container
4460 * implementations have this information; applications should use
4461 * gtk_widget_size_request().
4464 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4467 gtk_widget_get_child_requisition (GtkWidget *widget,
4468 GtkRequisition *requisition)
4470 gtk_widget_get_preferred_size (widget, requisition, NULL);
4474 invalidate_predicate (GdkWindow *window,
4479 gdk_window_get_user_data (window, &user_data);
4481 return (user_data == data);
4484 /* Invalidate @region in widget->window and all children
4485 * of widget->window owned by widget. @region is in the
4486 * same coordinates as widget->allocation and will be
4487 * modified by this call.
4490 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4491 cairo_region_t *region)
4493 GtkWidgetPrivate *priv = widget->priv;
4495 if (!gtk_widget_get_realized (widget))
4498 if (gtk_widget_get_has_window (widget) && priv->parent)
4502 gdk_window_get_position (priv->window, &x, &y);
4503 cairo_region_translate (region, -x, -y);
4506 gdk_window_invalidate_maybe_recurse (priv->window, region,
4507 invalidate_predicate, widget);
4511 * gtk_widget_queue_shallow_draw:
4512 * @widget: a #GtkWidget
4514 * Like gtk_widget_queue_draw(), but only windows owned
4515 * by @widget are invalidated.
4518 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4521 cairo_region_t *region;
4523 if (!gtk_widget_get_realized (widget))
4526 gtk_widget_get_allocation (widget, &rect);
4528 region = cairo_region_create_rectangle (&rect);
4529 gtk_widget_invalidate_widget_windows (widget, region);
4530 cairo_region_destroy (region);
4534 * gtk_widget_size_allocate:
4535 * @widget: a #GtkWidget
4536 * @allocation: (inout): position and size to be allocated to @widget
4538 * This function is only used by #GtkContainer subclasses, to assign a size
4539 * and position to their child widgets.
4541 * In this function, the allocation may be adjusted. It will be forced
4542 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4543 * method on the child will be used to adjust the allocation. Standard
4544 * adjustments include removing the widget's margins, and applying the
4545 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4548 gtk_widget_size_allocate (GtkWidget *widget,
4549 GtkAllocation *allocation)
4551 GtkWidgetPrivate *priv;
4552 GdkRectangle real_allocation;
4553 GdkRectangle old_allocation;
4554 GdkRectangle adjusted_allocation;
4555 gboolean alloc_needed;
4556 gboolean size_changed;
4557 gboolean position_changed;
4558 gint natural_width, natural_height;
4559 gint min_width, min_height;
4561 priv = widget->priv;
4563 g_return_if_fail (GTK_IS_WIDGET (widget));
4565 #ifdef G_ENABLE_DEBUG
4566 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4577 parent = gtk_widget_get_parent (parent);
4580 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4581 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4582 2 * depth, " ", name,
4583 allocation->width, allocation->height);
4585 #endif /* G_ENABLE_DEBUG */
4587 alloc_needed = priv->alloc_needed;
4588 if (!priv->width_request_needed && !priv->height_request_needed)
4589 /* Preserve request/allocate ordering */
4590 priv->alloc_needed = FALSE;
4592 old_allocation = priv->allocation;
4593 real_allocation = *allocation;
4595 adjusted_allocation = real_allocation;
4596 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4598 /* Go ahead and request the height for allocated width, note that the internals
4599 * of get_height_for_width will internally limit the for_size to natural size
4600 * when aligning implicitly.
4602 gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
4603 gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
4607 /* Go ahead and request the width for allocated height, note that the internals
4608 * of get_width_for_height will internally limit the for_size to natural size
4609 * when aligning implicitly.
4611 gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
4612 gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
4615 /* Now that we have the right natural height and width, go ahead and remove any margins from the
4616 * allocated sizes and possibly limit them to the natural sizes */
4617 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4618 GTK_ORIENTATION_HORIZONTAL,
4620 &adjusted_allocation.x,
4621 &adjusted_allocation.width);
4622 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
4623 GTK_ORIENTATION_VERTICAL,
4625 &adjusted_allocation.y,
4626 &adjusted_allocation.height);
4628 if (adjusted_allocation.x < real_allocation.x ||
4629 adjusted_allocation.y < real_allocation.y ||
4630 (adjusted_allocation.x + adjusted_allocation.width) >
4631 (real_allocation.x + real_allocation.width) ||
4632 (adjusted_allocation.y + adjusted_allocation.height >
4633 real_allocation.y + real_allocation.height))
4635 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",
4636 G_OBJECT_TYPE_NAME (widget), widget,
4637 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4638 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4639 adjusted_allocation = real_allocation; /* veto it */
4643 real_allocation = adjusted_allocation;
4646 if (real_allocation.width < 0 || real_allocation.height < 0)
4648 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4649 real_allocation.width,
4650 real_allocation.height);
4653 real_allocation.width = MAX (real_allocation.width, 1);
4654 real_allocation.height = MAX (real_allocation.height, 1);
4656 size_changed = (old_allocation.width != real_allocation.width ||
4657 old_allocation.height != real_allocation.height);
4658 position_changed = (old_allocation.x != real_allocation.x ||
4659 old_allocation.y != real_allocation.y);
4661 if (!alloc_needed && !size_changed && !position_changed)
4664 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4666 /* Size allocation is god... after consulting god, no further requests or allocations are needed */
4667 priv->width_request_needed = FALSE;
4668 priv->height_request_needed = FALSE;
4669 priv->alloc_needed = FALSE;
4671 if (gtk_widget_get_mapped (widget))
4673 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4675 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4677 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4678 cairo_region_union_rectangle (invalidate, &old_allocation);
4680 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4681 cairo_region_destroy (invalidate);
4686 if (priv->redraw_on_alloc)
4688 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4690 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4691 cairo_region_union_rectangle (invalidate, &old_allocation);
4693 gtk_widget_invalidate_widget_windows (widget, invalidate);
4694 cairo_region_destroy (invalidate);
4698 if (size_changed || position_changed)
4700 GtkStyleContext *context;
4702 context = gtk_widget_get_style_context (widget);
4703 _gtk_style_context_invalidate_animation_areas (context);
4707 if ((size_changed || position_changed) && priv->parent &&
4708 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4710 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4711 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4712 cairo_region_destroy (invalidate);
4717 * gtk_widget_common_ancestor:
4718 * @widget_a: a #GtkWidget
4719 * @widget_b: a #GtkWidget
4721 * Find the common ancestor of @widget_a and @widget_b that
4722 * is closest to the two widgets.
4724 * Return value: the closest common ancestor of @widget_a and
4725 * @widget_b or %NULL if @widget_a and @widget_b do not
4726 * share a common ancestor.
4729 gtk_widget_common_ancestor (GtkWidget *widget_a,
4730 GtkWidget *widget_b)
4732 GtkWidget *parent_a;
4733 GtkWidget *parent_b;
4737 parent_a = widget_a;
4738 while (parent_a->priv->parent)
4740 parent_a = parent_a->priv->parent;
4744 parent_b = widget_b;
4745 while (parent_b->priv->parent)
4747 parent_b = parent_b->priv->parent;
4751 if (parent_a != parent_b)
4754 while (depth_a > depth_b)
4756 widget_a = widget_a->priv->parent;
4760 while (depth_b > depth_a)
4762 widget_b = widget_b->priv->parent;
4766 while (widget_a != widget_b)
4768 widget_a = widget_a->priv->parent;
4769 widget_b = widget_b->priv->parent;
4776 * gtk_widget_translate_coordinates:
4777 * @src_widget: a #GtkWidget
4778 * @dest_widget: a #GtkWidget
4779 * @src_x: X position relative to @src_widget
4780 * @src_y: Y position relative to @src_widget
4781 * @dest_x: (out): location to store X position relative to @dest_widget
4782 * @dest_y: (out): location to store Y position relative to @dest_widget
4784 * Translate coordinates relative to @src_widget's allocation to coordinates
4785 * relative to @dest_widget's allocations. In order to perform this
4786 * operation, both widgets must be realized, and must share a common
4789 * Return value: %FALSE if either widget was not realized, or there
4790 * was no common ancestor. In this case, nothing is stored in
4791 * *@dest_x and *@dest_y. Otherwise %TRUE.
4794 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4795 GtkWidget *dest_widget,
4801 GtkWidgetPrivate *src_priv = src_widget->priv;
4802 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4803 GtkWidget *ancestor;
4805 GList *dest_list = NULL;
4807 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4808 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4810 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4811 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4814 /* Translate from allocation relative to window relative */
4815 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4818 gdk_window_get_position (src_priv->window, &wx, &wy);
4820 src_x -= wx - src_priv->allocation.x;
4821 src_y -= wy - src_priv->allocation.y;
4825 src_x += src_priv->allocation.x;
4826 src_y += src_priv->allocation.y;
4829 /* Translate to the common ancestor */
4830 window = src_priv->window;
4831 while (window != ancestor->priv->window)
4835 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4840 window = gdk_window_get_effective_parent (window);
4842 if (!window) /* Handle GtkHandleBox */
4847 window = dest_priv->window;
4848 while (window != ancestor->priv->window)
4850 dest_list = g_list_prepend (dest_list, window);
4852 window = gdk_window_get_effective_parent (window);
4854 if (!window) /* Handle GtkHandleBox */
4856 g_list_free (dest_list);
4865 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4870 dest_list = g_list_remove (dest_list, dest_list->data);
4873 /* Translate from window relative to allocation relative */
4874 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4877 gdk_window_get_position (dest_priv->window, &wx, &wy);
4879 src_x += wx - dest_priv->allocation.x;
4880 src_y += wy - dest_priv->allocation.y;
4884 src_x -= dest_priv->allocation.x;
4885 src_y -= dest_priv->allocation.y;
4897 gtk_widget_real_size_allocate (GtkWidget *widget,
4898 GtkAllocation *allocation)
4900 GtkWidgetPrivate *priv = widget->priv;
4902 priv->allocation = *allocation;
4904 if (gtk_widget_get_realized (widget) &&
4905 gtk_widget_get_has_window (widget))
4907 gdk_window_move_resize (priv->window,
4908 allocation->x, allocation->y,
4909 allocation->width, allocation->height);
4914 adjust_for_align(GtkAlign align,
4916 gint *allocated_pos,
4917 gint *allocated_size)
4921 case GTK_ALIGN_FILL:
4922 /* change nothing */
4924 case GTK_ALIGN_START:
4925 /* keep *allocated_pos where it is */
4926 *allocated_size = MIN (*allocated_size, *natural_size);
4929 if (*allocated_size > *natural_size)
4931 *allocated_pos += (*allocated_size - *natural_size);
4932 *allocated_size = *natural_size;
4935 case GTK_ALIGN_CENTER:
4936 if (*allocated_size > *natural_size)
4938 *allocated_pos += (*allocated_size - *natural_size) / 2;
4939 *allocated_size = MIN (*allocated_size, *natural_size);
4946 adjust_for_margin(gint start_margin,
4949 gint *allocated_pos,
4950 gint *allocated_size)
4952 *natural_size -= (start_margin + end_margin);
4953 *allocated_pos += start_margin;
4954 *allocated_size -= (start_margin + end_margin);
4958 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4959 GtkOrientation orientation,
4961 gint *allocated_pos,
4962 gint *allocated_size)
4964 const GtkWidgetAuxInfo *aux_info;
4966 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4968 if (orientation == GTK_ORIENTATION_HORIZONTAL)
4970 adjust_for_margin (aux_info->margin.left,
4971 aux_info->margin.right,
4972 natural_size, allocated_pos, allocated_size);
4973 adjust_for_align (aux_info->halign,
4974 natural_size, allocated_pos, allocated_size);
4978 adjust_for_margin (aux_info->margin.top,
4979 aux_info->margin.bottom,
4980 natural_size, allocated_pos, allocated_size);
4981 adjust_for_align (aux_info->valign,
4982 natural_size, allocated_pos, allocated_size);
4987 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4990 GtkWidgetPrivate *priv = widget->priv;
4992 /* widgets must be onscreen for accels to take effect */
4993 return gtk_widget_is_sensitive (widget) &&
4994 gtk_widget_is_drawable (widget) &&
4995 gdk_window_is_viewable (priv->window);
4999 * gtk_widget_can_activate_accel:
5000 * @widget: a #GtkWidget
5001 * @signal_id: the ID of a signal installed on @widget
5003 * Determines whether an accelerator that activates the signal
5004 * identified by @signal_id can currently be activated.
5005 * This is done by emitting the #GtkWidget::can-activate-accel
5006 * signal on @widget; if the signal isn't overridden by a
5007 * handler or in a derived widget, then the default check is
5008 * that the widget must be sensitive, and the widget and all
5009 * its ancestors mapped.
5011 * Return value: %TRUE if the accelerator can be activated.
5016 gtk_widget_can_activate_accel (GtkWidget *widget,
5019 gboolean can_activate = FALSE;
5020 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5021 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
5022 return can_activate;
5031 closure_accel_activate (GClosure *closure,
5032 GValue *return_value,
5033 guint n_param_values,
5034 const GValue *param_values,
5035 gpointer invocation_hint,
5036 gpointer marshal_data)
5038 AccelClosure *aclosure = (AccelClosure*) closure;
5039 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5042 g_signal_emit (closure->data, aclosure->signal_id, 0);
5044 /* whether accelerator was handled */
5045 g_value_set_boolean (return_value, can_activate);
5049 closures_destroy (gpointer data)
5051 GSList *slist, *closures = data;
5053 for (slist = closures; slist; slist = slist->next)
5055 g_closure_invalidate (slist->data);
5056 g_closure_unref (slist->data);
5058 g_slist_free (closures);
5062 widget_new_accel_closure (GtkWidget *widget,
5065 AccelClosure *aclosure;
5066 GClosure *closure = NULL;
5067 GSList *slist, *closures;
5069 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5070 for (slist = closures; slist; slist = slist->next)
5071 if (!gtk_accel_group_from_accel_closure (slist->data))
5073 /* reuse this closure */
5074 closure = slist->data;
5079 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5080 closures = g_slist_prepend (closures, g_closure_ref (closure));
5081 g_closure_sink (closure);
5082 g_closure_set_marshal (closure, closure_accel_activate);
5084 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5086 aclosure = (AccelClosure*) closure;
5087 g_assert (closure->data == widget);
5088 g_assert (closure->marshal == closure_accel_activate);
5089 aclosure->signal_id = signal_id;
5095 * gtk_widget_add_accelerator
5096 * @widget: widget to install an accelerator on
5097 * @accel_signal: widget signal to emit on accelerator activation
5098 * @accel_group: accel group for this widget, added to its toplevel
5099 * @accel_key: GDK keyval of the accelerator
5100 * @accel_mods: modifier key combination of the accelerator
5101 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5103 * Installs an accelerator for this @widget in @accel_group that causes
5104 * @accel_signal to be emitted if the accelerator is activated.
5105 * The @accel_group needs to be added to the widget's toplevel via
5106 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5107 * Accelerators added through this function are not user changeable during
5108 * runtime. If you want to support accelerators that can be changed by the
5109 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5110 * gtk_menu_item_set_accel_path() instead.
5113 gtk_widget_add_accelerator (GtkWidget *widget,
5114 const gchar *accel_signal,
5115 GtkAccelGroup *accel_group,
5117 GdkModifierType accel_mods,
5118 GtkAccelFlags accel_flags)
5123 g_return_if_fail (GTK_IS_WIDGET (widget));
5124 g_return_if_fail (accel_signal != NULL);
5125 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5127 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5128 if (!query.signal_id ||
5129 !(query.signal_flags & G_SIGNAL_ACTION) ||
5130 query.return_type != G_TYPE_NONE ||
5133 /* hmm, should be elaborate enough */
5134 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5135 G_OBJECT_TYPE_NAME (widget), accel_signal);
5139 closure = widget_new_accel_closure (widget, query.signal_id);
5141 g_object_ref (widget);
5143 /* install the accelerator. since we don't map this onto an accel_path,
5144 * the accelerator will automatically be locked.
5146 gtk_accel_group_connect (accel_group,
5149 accel_flags | GTK_ACCEL_LOCKED,
5152 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5154 g_object_unref (widget);
5158 * gtk_widget_remove_accelerator:
5159 * @widget: widget to install an accelerator on
5160 * @accel_group: accel group for this widget
5161 * @accel_key: GDK keyval of the accelerator
5162 * @accel_mods: modifier key combination of the accelerator
5163 * @returns: whether an accelerator was installed and could be removed
5165 * Removes an accelerator from @widget, previously installed with
5166 * gtk_widget_add_accelerator().
5169 gtk_widget_remove_accelerator (GtkWidget *widget,
5170 GtkAccelGroup *accel_group,
5172 GdkModifierType accel_mods)
5174 GtkAccelGroupEntry *ag_entry;
5175 GList *slist, *clist;
5178 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5179 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5181 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5182 clist = gtk_widget_list_accel_closures (widget);
5183 for (slist = clist; slist; slist = slist->next)
5187 for (i = 0; i < n; i++)
5188 if (slist->data == (gpointer) ag_entry[i].closure)
5190 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5192 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5194 g_list_free (clist);
5199 g_list_free (clist);
5201 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5202 accel_key, accel_mods, accel_group,
5203 G_OBJECT_TYPE_NAME (widget), widget);
5209 * gtk_widget_list_accel_closures:
5210 * @widget: widget to list accelerator closures for
5212 * Lists the closures used by @widget for accelerator group connections
5213 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5214 * The closures can be used to monitor accelerator changes on @widget,
5215 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5216 * #GtkAccelGroup of a closure which can be found out with
5217 * gtk_accel_group_from_accel_closure().
5219 * Return value: (transfer container) (element-type GClosure):
5220 * a newly allocated #GList of closures
5223 gtk_widget_list_accel_closures (GtkWidget *widget)
5226 GList *clist = NULL;
5228 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5230 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5231 if (gtk_accel_group_from_accel_closure (slist->data))
5232 clist = g_list_prepend (clist, slist->data);
5238 GtkAccelGroup *accel_group;
5243 destroy_accel_path (gpointer data)
5245 AccelPath *apath = data;
5247 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5249 /* closures_destroy takes care of unrefing the closure */
5250 g_object_unref (apath->accel_group);
5252 g_slice_free (AccelPath, apath);
5257 * gtk_widget_set_accel_path:
5258 * @widget: a #GtkWidget
5259 * @accel_path: (allow-none): path used to look up the accelerator
5260 * @accel_group: (allow-none): a #GtkAccelGroup.
5262 * Given an accelerator group, @accel_group, and an accelerator path,
5263 * @accel_path, sets up an accelerator in @accel_group so whenever the
5264 * key binding that is defined for @accel_path is pressed, @widget
5265 * will be activated. This removes any accelerators (for any
5266 * accelerator group) installed by previous calls to
5267 * gtk_widget_set_accel_path(). Associating accelerators with
5268 * paths allows them to be modified by the user and the modifications
5269 * to be saved for future use. (See gtk_accel_map_save().)
5271 * This function is a low level function that would most likely
5272 * be used by a menu creation system like #GtkUIManager. If you
5273 * use #GtkUIManager, setting up accelerator paths will be done
5276 * Even when you you aren't using #GtkUIManager, if you only want to
5277 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5278 * provides a somewhat more convenient interface.
5280 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5281 * pass a static string, you can save some memory by interning it first with
5282 * g_intern_static_string().
5285 gtk_widget_set_accel_path (GtkWidget *widget,
5286 const gchar *accel_path,
5287 GtkAccelGroup *accel_group)
5291 g_return_if_fail (GTK_IS_WIDGET (widget));
5292 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5296 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5297 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5299 gtk_accel_map_add_entry (accel_path, 0, 0);
5300 apath = g_slice_new (AccelPath);
5301 apath->accel_group = g_object_ref (accel_group);
5302 apath->path_quark = g_quark_from_string (accel_path);
5303 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5308 /* also removes possible old settings */
5309 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5312 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5314 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5318 _gtk_widget_get_accel_path (GtkWidget *widget,
5323 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5325 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5327 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5328 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5332 * gtk_widget_mnemonic_activate:
5333 * @widget: a #GtkWidget
5334 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5336 * Emits the #GtkWidget::mnemonic-activate signal.
5338 * The default handler for this signal activates the @widget if
5339 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5342 * Returns: %TRUE if the signal has been handled
5345 gtk_widget_mnemonic_activate (GtkWidget *widget,
5346 gboolean group_cycling)
5350 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5352 group_cycling = group_cycling != FALSE;
5353 if (!gtk_widget_is_sensitive (widget))
5356 g_signal_emit (widget,
5357 widget_signals[MNEMONIC_ACTIVATE],
5365 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5366 gboolean group_cycling)
5368 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5369 gtk_widget_activate (widget);
5370 else if (gtk_widget_get_can_focus (widget))
5371 gtk_widget_grab_focus (widget);
5374 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5375 G_OBJECT_TYPE_NAME (widget));
5376 gtk_widget_error_bell (widget);
5381 static const cairo_user_data_key_t event_key;
5384 _gtk_cairo_get_event (cairo_t *cr)
5386 g_return_val_if_fail (cr != NULL, NULL);
5388 return cairo_get_user_data (cr, &event_key);
5392 gtk_cairo_set_event (cairo_t *cr,
5393 GdkEventExpose *event)
5395 cairo_set_user_data (cr, &event_key, event, NULL);
5399 * gtk_cairo_should_draw_window:
5400 * @cr: a cairo context
5401 * @window: the window to check
5403 * This function is supposed to be called in #GtkWidget::draw
5404 * implementations for widgets that support multiple windows.
5405 * @cr must be untransformed from invoking of the draw function.
5406 * This function will return %TRUE if the contents of the given
5407 * @window are supposed to be drawn and %FALSE otherwise. Note
5408 * that when the drawing was not initiated by the windowing
5409 * system this function will return %TRUE for all windows, so
5410 * you need to draw the bottommost window first. Also, do not
5411 * use "else if" statements to check which window should be drawn.
5413 * Returns: %TRUE if @window should be drawn
5416 gtk_cairo_should_draw_window (cairo_t *cr,
5419 GdkEventExpose *event;
5421 g_return_val_if_fail (cr != NULL, FALSE);
5422 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5424 event = _gtk_cairo_get_event (cr);
5426 return event == NULL ||
5427 event->window == window;
5430 /* code shared by gtk_container_propagate_draw() and
5434 _gtk_widget_draw_internal (GtkWidget *widget,
5436 gboolean clip_to_size)
5438 GtkStyleContext *context;
5440 if (!gtk_widget_is_drawable (widget))
5445 cairo_rectangle (cr,
5447 widget->priv->allocation.width,
5448 widget->priv->allocation.height);
5452 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5456 g_signal_emit (widget, widget_signals[DRAW],
5461 context = gtk_widget_get_style_context (widget);
5462 _gtk_style_context_coalesce_animation_areas (context,
5463 widget->priv->allocation.x,
5464 widget->priv->allocation.y);
5469 * @widget: the widget to draw. It must be drawable (see
5470 * gtk_widget_is_drawable()) and a size must have been allocated.
5471 * @cr: a cairo context to draw to
5473 * Draws @widget to @cr. The top left corner of the widget will be
5474 * drawn to the currently set origin point of @cr.
5476 * You should pass a cairo context as @cr argument that is in an
5477 * original state. Otherwise the resulting drawing is undefined. For
5478 * example changing the operator using cairo_set_operator() or the
5479 * line width using cairo_set_line_width() might have unwanted side
5481 * You may however change the context's transform matrix - like with
5482 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5483 * region with cairo_clip() prior to calling this function. Also, it
5484 * is fine to modify the context with cairo_save() and
5485 * cairo_push_group() prior to calling this function.
5487 * <note><para>Special purpose widgets may contain special code for
5488 * rendering to the screen and might appear differently on screen
5489 * and when rendered using gtk_widget_draw().</para></note>
5492 gtk_widget_draw (GtkWidget *widget,
5495 GdkEventExpose *tmp_event;
5497 g_return_if_fail (GTK_IS_WIDGET (widget));
5498 g_return_if_fail (!widget->priv->alloc_needed);
5499 g_return_if_fail (cr != NULL);
5502 /* We have to reset the event here so that draw functions can call
5503 * gtk_widget_draw() on random other widgets and get the desired
5504 * effect: Drawing all contents, not just the current window.
5506 tmp_event = _gtk_cairo_get_event (cr);
5507 gtk_cairo_set_event (cr, NULL);
5509 _gtk_widget_draw_internal (widget, cr, TRUE);
5511 gtk_cairo_set_event (cr, tmp_event);
5516 gtk_widget_real_key_press_event (GtkWidget *widget,
5519 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5523 gtk_widget_real_key_release_event (GtkWidget *widget,
5526 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5530 gtk_widget_real_focus_in_event (GtkWidget *widget,
5531 GdkEventFocus *event)
5533 gtk_widget_queue_shallow_draw (widget);
5539 gtk_widget_real_focus_out_event (GtkWidget *widget,
5540 GdkEventFocus *event)
5542 gtk_widget_queue_shallow_draw (widget);
5547 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5548 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5552 * @widget: a #GtkWidget
5553 * @event: a #GdkEvent
5555 * Rarely-used function. This function is used to emit
5556 * the event signals on a widget (those signals should never
5557 * be emitted without using this function to do so).
5558 * If you want to synthesize an event though, don't use this function;
5559 * instead, use gtk_main_do_event() so the event will behave as if
5560 * it were in the event queue. Don't synthesize expose events; instead,
5561 * use gdk_window_invalidate_rect() to invalidate a region of the
5564 * Return value: return from the event signal emission (%TRUE if
5565 * the event was handled)
5568 gtk_widget_event (GtkWidget *widget,
5571 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5572 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5574 if (event->type == GDK_EXPOSE)
5576 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5577 "the same effect, call gdk_window_invalidate_rect/region(), "
5578 "followed by gdk_window_process_updates().");
5582 return gtk_widget_event_internal (widget, event);
5585 /* Returns TRUE if a translation should be done */
5587 gtk_widget_get_translation_to_window (GtkWidget *widget,
5592 GdkWindow *w, *widget_window;
5594 if (!gtk_widget_get_has_window (widget))
5596 *x = -widget->priv->allocation.x;
5597 *y = -widget->priv->allocation.y;
5605 widget_window = gtk_widget_get_window (widget);
5607 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5610 gdk_window_get_position (w, &wx, &wy);
5627 * gtk_cairo_transform_to_window:
5628 * @cr: the cairo context to transform
5629 * @widget: the widget the context is currently centered for
5630 * @window: the window to transform the context to
5632 * Transforms the given cairo context @cr that from @widget-relative
5633 * coordinates to @window-relative coordinates.
5634 * If the @widget's window is not an ancestor of @window, no
5635 * modification will be applied.
5637 * This is the inverse to the transformation GTK applies when
5638 * preparing an expose event to be emitted with the #GtkWidget::draw
5639 * signal. It is intended to help porting multiwindow widgets from
5640 * GTK+ 2 to the rendering architecture of GTK+ 3.
5643 gtk_cairo_transform_to_window (cairo_t *cr,
5649 g_return_if_fail (cr != NULL);
5650 g_return_if_fail (GTK_IS_WIDGET (widget));
5651 g_return_if_fail (GDK_IS_WINDOW (window));
5653 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5654 cairo_translate (cr, x, y);
5658 * gtk_widget_send_expose:
5659 * @widget: a #GtkWidget
5660 * @event: a expose #GdkEvent
5662 * Very rarely-used function. This function is used to emit
5663 * an expose event on a widget. This function is not normally used
5664 * directly. The only time it is used is when propagating an expose
5665 * event to a child %NO_WINDOW widget, and that is normally done
5666 * using gtk_container_propagate_draw().
5668 * If you want to force an area of a window to be redrawn,
5669 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5670 * To cause the redraw to be done immediately, follow that call
5671 * with a call to gdk_window_process_updates().
5673 * Return value: return from the event signal emission (%TRUE if
5674 * the event was handled)
5677 gtk_widget_send_expose (GtkWidget *widget,
5680 gboolean result = FALSE;
5685 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5686 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5687 g_return_val_if_fail (event != NULL, TRUE);
5688 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5690 cr = gdk_cairo_create (event->expose.window);
5691 gtk_cairo_set_event (cr, &event->expose);
5693 gdk_cairo_region (cr, event->expose.region);
5696 do_clip = gtk_widget_get_translation_to_window (widget,
5697 event->expose.window,
5699 cairo_translate (cr, -x, -y);
5701 _gtk_widget_draw_internal (widget, cr, do_clip);
5703 /* unset here, so if someone keeps a reference to cr we
5704 * don't leak the window. */
5705 gtk_cairo_set_event (cr, NULL);
5712 event_window_is_still_viewable (GdkEvent *event)
5714 /* Check that we think the event's window is viewable before
5715 * delivering the event, to prevent suprises. We do this here
5716 * at the last moment, since the event may have been queued
5717 * up behind other events, held over a recursive main loop, etc.
5719 switch (event->type)
5722 case GDK_MOTION_NOTIFY:
5723 case GDK_BUTTON_PRESS:
5724 case GDK_2BUTTON_PRESS:
5725 case GDK_3BUTTON_PRESS:
5727 case GDK_ENTER_NOTIFY:
5728 case GDK_PROXIMITY_IN:
5730 return event->any.window && gdk_window_is_viewable (event->any.window);
5733 /* The following events are the second half of paired events;
5734 * we always deliver them to deal with widgets that clean up
5735 * on the second half.
5737 case GDK_BUTTON_RELEASE:
5738 case GDK_KEY_RELEASE:
5739 case GDK_LEAVE_NOTIFY:
5740 case GDK_PROXIMITY_OUT:
5744 /* Remaining events would make sense on an not-viewable window,
5745 * or don't have an associated window.
5752 gtk_widget_event_internal (GtkWidget *widget,
5755 gboolean return_val = FALSE;
5757 /* We check only once for is-still-visible; if someone
5758 * hides the window in on of the signals on the widget,
5759 * they are responsible for returning TRUE to terminate
5762 if (!event_window_is_still_viewable (event))
5765 g_object_ref (widget);
5767 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5768 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5773 switch (event->type)
5778 case GDK_BUTTON_PRESS:
5779 case GDK_2BUTTON_PRESS:
5780 case GDK_3BUTTON_PRESS:
5781 signal_num = BUTTON_PRESS_EVENT;
5784 signal_num = SCROLL_EVENT;
5786 case GDK_BUTTON_RELEASE:
5787 signal_num = BUTTON_RELEASE_EVENT;
5789 case GDK_MOTION_NOTIFY:
5790 signal_num = MOTION_NOTIFY_EVENT;
5793 signal_num = DELETE_EVENT;
5796 signal_num = DESTROY_EVENT;
5797 _gtk_tooltip_hide (widget);
5800 signal_num = KEY_PRESS_EVENT;
5802 case GDK_KEY_RELEASE:
5803 signal_num = KEY_RELEASE_EVENT;
5805 case GDK_ENTER_NOTIFY:
5806 signal_num = ENTER_NOTIFY_EVENT;
5808 case GDK_LEAVE_NOTIFY:
5809 signal_num = LEAVE_NOTIFY_EVENT;
5811 case GDK_FOCUS_CHANGE:
5812 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5813 if (event->focus_change.in)
5814 _gtk_tooltip_focus_in (widget);
5816 _gtk_tooltip_focus_out (widget);
5819 signal_num = CONFIGURE_EVENT;
5822 signal_num = MAP_EVENT;
5825 signal_num = UNMAP_EVENT;
5827 case GDK_WINDOW_STATE:
5828 signal_num = WINDOW_STATE_EVENT;
5830 case GDK_PROPERTY_NOTIFY:
5831 signal_num = PROPERTY_NOTIFY_EVENT;
5833 case GDK_SELECTION_CLEAR:
5834 signal_num = SELECTION_CLEAR_EVENT;
5836 case GDK_SELECTION_REQUEST:
5837 signal_num = SELECTION_REQUEST_EVENT;
5839 case GDK_SELECTION_NOTIFY:
5840 signal_num = SELECTION_NOTIFY_EVENT;
5842 case GDK_PROXIMITY_IN:
5843 signal_num = PROXIMITY_IN_EVENT;
5845 case GDK_PROXIMITY_OUT:
5846 signal_num = PROXIMITY_OUT_EVENT;
5848 case GDK_CLIENT_EVENT:
5849 signal_num = CLIENT_EVENT;
5852 signal_num = EXPOSE_EVENT;
5854 case GDK_VISIBILITY_NOTIFY:
5855 signal_num = VISIBILITY_NOTIFY_EVENT;
5857 case GDK_GRAB_BROKEN:
5858 signal_num = GRAB_BROKEN_EVENT;
5861 signal_num = DAMAGE_EVENT;
5864 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5868 if (signal_num != -1)
5869 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5871 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5872 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5876 g_object_unref (widget);
5882 * gtk_widget_activate:
5883 * @widget: a #GtkWidget that's activatable
5885 * For widgets that can be "activated" (buttons, menu items, etc.)
5886 * this function activates them. Activation is what happens when you
5887 * press Enter on a widget during key navigation. If @widget isn't
5888 * activatable, the function returns %FALSE.
5890 * Return value: %TRUE if the widget was activatable
5893 gtk_widget_activate (GtkWidget *widget)
5895 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5897 if (WIDGET_CLASS (widget)->activate_signal)
5899 /* FIXME: we should eventually check the signals signature here */
5900 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5909 gtk_widget_reparent_subwindows (GtkWidget *widget,
5910 GdkWindow *new_window)
5912 GtkWidgetPrivate *priv = widget->priv;
5914 if (!gtk_widget_get_has_window (widget))
5916 GList *children = gdk_window_get_children (priv->window);
5919 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5921 GdkWindow *window = tmp_list->data;
5924 gdk_window_get_user_data (window, &child);
5925 while (child && child != widget)
5926 child = ((GtkWidget*) child)->priv->parent;
5929 gdk_window_reparent (window, new_window, 0, 0);
5932 g_list_free (children);
5937 GList *tmp_list, *children;
5939 parent = gdk_window_get_parent (priv->window);
5942 gdk_window_reparent (priv->window, new_window, 0, 0);
5945 children = gdk_window_get_children (parent);
5947 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5949 GdkWindow *window = tmp_list->data;
5952 gdk_window_get_user_data (window, &child);
5954 if (child == widget)
5955 gdk_window_reparent (window, new_window, 0, 0);
5958 g_list_free (children);
5964 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5965 gpointer client_data)
5967 GtkWidgetPrivate *priv = widget->priv;
5969 g_assert (client_data != NULL);
5971 if (!gtk_widget_get_has_window (widget))
5974 g_object_unref (priv->window);
5975 priv->window = (GdkWindow*) client_data;
5977 g_object_ref (priv->window);
5979 if (GTK_IS_CONTAINER (widget))
5980 gtk_container_forall (GTK_CONTAINER (widget),
5981 gtk_widget_reparent_fixup_child,
5987 * gtk_widget_reparent:
5988 * @widget: a #GtkWidget
5989 * @new_parent: a #GtkContainer to move the widget into
5991 * Moves a widget from one #GtkContainer to another, handling reference
5992 * count issues to avoid destroying the widget.
5995 gtk_widget_reparent (GtkWidget *widget,
5996 GtkWidget *new_parent)
5998 GtkWidgetPrivate *priv;
6000 g_return_if_fail (GTK_IS_WIDGET (widget));
6001 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6002 priv = widget->priv;
6003 g_return_if_fail (priv->parent != NULL);
6005 if (priv->parent != new_parent)
6007 /* First try to see if we can get away without unrealizing
6008 * the widget as we reparent it. if so we set a flag so
6009 * that gtk_widget_unparent doesn't unrealize widget
6011 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6012 priv->in_reparent = TRUE;
6014 g_object_ref (widget);
6015 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6016 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6017 g_object_unref (widget);
6019 if (priv->in_reparent)
6021 priv->in_reparent = FALSE;
6023 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6024 gtk_widget_reparent_fixup_child (widget,
6025 gtk_widget_get_parent_window (widget));
6028 g_object_notify (G_OBJECT (widget), "parent");
6033 * gtk_widget_intersect:
6034 * @widget: a #GtkWidget
6035 * @area: a rectangle
6036 * @intersection: rectangle to store intersection of @widget and @area
6038 * Computes the intersection of a @widget's area and @area, storing
6039 * the intersection in @intersection, and returns %TRUE if there was
6040 * an intersection. @intersection may be %NULL if you're only
6041 * interested in whether there was an intersection.
6043 * Return value: %TRUE if there was an intersection
6046 gtk_widget_intersect (GtkWidget *widget,
6047 const GdkRectangle *area,
6048 GdkRectangle *intersection)
6050 GtkWidgetPrivate *priv;
6055 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6056 g_return_val_if_fail (area != NULL, FALSE);
6058 priv = widget->priv;
6061 dest = intersection;
6065 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6067 if (return_val && intersection && gtk_widget_get_has_window (widget))
6069 intersection->x -= priv->allocation.x;
6070 intersection->y -= priv->allocation.y;
6077 * gtk_widget_region_intersect:
6078 * @widget: a #GtkWidget
6079 * @region: a #cairo_region_t, in the same coordinate system as
6080 * @widget->allocation. That is, relative to @widget->window
6081 * for %NO_WINDOW widgets; relative to the parent window
6082 * of @widget->window for widgets with their own window.
6083 * @returns: A newly allocated region holding the intersection of @widget
6084 * and @region. The coordinates of the return value are
6085 * relative to @widget->window for %NO_WINDOW widgets, and
6086 * relative to the parent window of @widget->window for
6087 * widgets with their own window.
6089 * Computes the intersection of a @widget's area and @region, returning
6090 * the intersection. The result may be empty, use cairo_region_is_empty() to
6094 gtk_widget_region_intersect (GtkWidget *widget,
6095 const cairo_region_t *region)
6098 cairo_region_t *dest;
6100 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6101 g_return_val_if_fail (region != NULL, NULL);
6103 gtk_widget_get_allocation (widget, &rect);
6105 dest = cairo_region_create_rectangle (&rect);
6107 cairo_region_intersect (dest, region);
6113 * _gtk_widget_grab_notify:
6114 * @widget: a #GtkWidget
6115 * @was_grabbed: whether a grab is now in effect
6117 * Emits the #GtkWidget::grab-notify signal on @widget.
6122 _gtk_widget_grab_notify (GtkWidget *widget,
6123 gboolean was_grabbed)
6125 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6129 * gtk_widget_grab_focus:
6130 * @widget: a #GtkWidget
6132 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6133 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6134 * something like #GtkFrame won't work.
6136 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6137 * gtk_widget_set_can_focus() to modify that flag.
6139 * The widget also needs to be realized and mapped. This is indicated by the
6140 * related signals. Grabbing the focus immediately after creating the widget
6141 * will likely fail and cause critical warnings.
6144 gtk_widget_grab_focus (GtkWidget *widget)
6146 g_return_if_fail (GTK_IS_WIDGET (widget));
6148 if (!gtk_widget_is_sensitive (widget))
6151 g_object_ref (widget);
6152 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6153 g_object_notify (G_OBJECT (widget), "has-focus");
6154 g_object_unref (widget);
6158 reset_focus_recurse (GtkWidget *widget,
6161 if (GTK_IS_CONTAINER (widget))
6163 GtkContainer *container;
6165 container = GTK_CONTAINER (widget);
6166 gtk_container_set_focus_child (container, NULL);
6168 gtk_container_foreach (container,
6169 reset_focus_recurse,
6175 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6177 if (gtk_widget_get_can_focus (focus_widget))
6179 GtkWidget *toplevel;
6182 /* clear the current focus setting, break if the current widget
6183 * is the focus widget's parent, since containers above that will
6184 * be set by the next loop.
6186 toplevel = gtk_widget_get_toplevel (focus_widget);
6187 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6189 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6191 if (widget == focus_widget)
6193 /* We call _gtk_window_internal_set_focus() here so that the
6194 * toplevel window can request the focus if necessary.
6195 * This is needed when the toplevel is a GtkPlug
6197 if (!gtk_widget_has_focus (widget))
6198 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6205 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6207 widget = widget->priv->parent;
6208 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6212 else if (toplevel != focus_widget)
6214 /* gtk_widget_grab_focus() operates on a tree without window...
6215 * actually, this is very questionable behaviour.
6218 gtk_container_foreach (GTK_CONTAINER (toplevel),
6219 reset_focus_recurse,
6223 /* now propagate the new focus up the widget tree and finally
6224 * set it on the window
6226 widget = focus_widget;
6227 while (widget->priv->parent)
6229 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6230 widget = widget->priv->parent;
6232 if (GTK_IS_WINDOW (widget))
6233 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6238 gtk_widget_real_query_tooltip (GtkWidget *widget,
6241 gboolean keyboard_tip,
6242 GtkTooltip *tooltip)
6244 gchar *tooltip_markup;
6245 gboolean has_tooltip;
6247 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6248 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6250 if (has_tooltip && tooltip_markup)
6252 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6260 gtk_widget_real_style_updated (GtkWidget *widget)
6262 if (widget->priv->context)
6263 gtk_style_context_invalidate (widget->priv->context);
6267 gtk_widget_real_show_help (GtkWidget *widget,
6268 GtkWidgetHelpType help_type)
6270 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6272 _gtk_tooltip_toggle_keyboard_mode (widget);
6281 gtk_widget_real_focus (GtkWidget *widget,
6282 GtkDirectionType direction)
6284 if (!gtk_widget_get_can_focus (widget))
6287 if (!gtk_widget_is_focus (widget))
6289 gtk_widget_grab_focus (widget);
6297 gtk_widget_real_move_focus (GtkWidget *widget,
6298 GtkDirectionType direction)
6300 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6302 if (widget != toplevel && GTK_IS_WINDOW (toplevel))
6304 g_signal_emit (toplevel, widget_signals[MOVE_FOCUS], 0,
6310 gtk_widget_real_keynav_failed (GtkWidget *widget,
6311 GtkDirectionType direction)
6313 gboolean cursor_only;
6317 case GTK_DIR_TAB_FORWARD:
6318 case GTK_DIR_TAB_BACKWARD:
6325 g_object_get (gtk_widget_get_settings (widget),
6326 "gtk-keynav-cursor-only", &cursor_only,
6333 gtk_widget_error_bell (widget);
6339 * gtk_widget_set_can_focus:
6340 * @widget: a #GtkWidget
6341 * @can_focus: whether or not @widget can own the input focus.
6343 * Specifies whether @widget can own the input focus. See
6344 * gtk_widget_grab_focus() for actually setting the input focus on a
6350 gtk_widget_set_can_focus (GtkWidget *widget,
6353 g_return_if_fail (GTK_IS_WIDGET (widget));
6355 if (widget->priv->can_focus != can_focus)
6357 widget->priv->can_focus = can_focus;
6359 gtk_widget_queue_resize (widget);
6360 g_object_notify (G_OBJECT (widget), "can-focus");
6365 * gtk_widget_get_can_focus:
6366 * @widget: a #GtkWidget
6368 * Determines whether @widget can own the input focus. See
6369 * gtk_widget_set_can_focus().
6371 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6376 gtk_widget_get_can_focus (GtkWidget *widget)
6378 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6380 return widget->priv->can_focus;
6384 * gtk_widget_has_focus:
6385 * @widget: a #GtkWidget
6387 * Determines if the widget has the global input focus. See
6388 * gtk_widget_is_focus() for the difference between having the global
6389 * input focus, and only having the focus within a toplevel.
6391 * Return value: %TRUE if the widget has the global input focus.
6396 gtk_widget_has_focus (GtkWidget *widget)
6398 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6400 return widget->priv->has_focus;
6404 * gtk_widget_is_focus:
6405 * @widget: a #GtkWidget
6407 * Determines if the widget is the focus widget within its
6408 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6409 * necessarily set; %HAS_FOCUS will only be set if the
6410 * toplevel widget additionally has the global input focus.)
6412 * Return value: %TRUE if the widget is the focus widget.
6415 gtk_widget_is_focus (GtkWidget *widget)
6417 GtkWidget *toplevel;
6419 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6421 toplevel = gtk_widget_get_toplevel (widget);
6423 if (GTK_IS_WINDOW (toplevel))
6424 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6430 * gtk_widget_set_can_default:
6431 * @widget: a #GtkWidget
6432 * @can_default: whether or not @widget can be a default widget.
6434 * Specifies whether @widget can be a default widget. See
6435 * gtk_widget_grab_default() for details about the meaning of
6441 gtk_widget_set_can_default (GtkWidget *widget,
6442 gboolean can_default)
6444 g_return_if_fail (GTK_IS_WIDGET (widget));
6446 if (widget->priv->can_default != can_default)
6448 widget->priv->can_default = can_default;
6450 gtk_widget_queue_resize (widget);
6451 g_object_notify (G_OBJECT (widget), "can-default");
6456 * gtk_widget_get_can_default:
6457 * @widget: a #GtkWidget
6459 * Determines whether @widget can be a default widget. See
6460 * gtk_widget_set_can_default().
6462 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6467 gtk_widget_get_can_default (GtkWidget *widget)
6469 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6471 return widget->priv->can_default;
6475 * gtk_widget_has_default:
6476 * @widget: a #GtkWidget
6478 * Determines whether @widget is the current default widget within its
6479 * toplevel. See gtk_widget_set_can_default().
6481 * Return value: %TRUE if @widget is the current default widget within
6482 * its toplevel, %FALSE otherwise
6487 gtk_widget_has_default (GtkWidget *widget)
6489 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6491 return widget->priv->has_default;
6495 _gtk_widget_set_has_default (GtkWidget *widget,
6496 gboolean has_default)
6498 widget->priv->has_default = has_default;
6502 * gtk_widget_grab_default:
6503 * @widget: a #GtkWidget
6505 * Causes @widget to become the default widget. @widget must have the
6506 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6507 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6508 * %TRUE)</literal>. The default widget is activated when
6509 * the user presses Enter in a window. Default widgets must be
6510 * activatable, that is, gtk_widget_activate() should affect them. Note
6511 * that #GtkEntry widgets require the "activates-default" property
6512 * set to %TRUE before they activate the default widget when Enter
6513 * is pressed and the #GtkEntry is focused.
6516 gtk_widget_grab_default (GtkWidget *widget)
6520 g_return_if_fail (GTK_IS_WIDGET (widget));
6521 g_return_if_fail (gtk_widget_get_can_default (widget));
6523 window = gtk_widget_get_toplevel (widget);
6525 if (window && gtk_widget_is_toplevel (window))
6526 gtk_window_set_default (GTK_WINDOW (window), widget);
6528 g_warning (G_STRLOC ": widget not within a GtkWindow");
6532 * gtk_widget_set_receives_default:
6533 * @widget: a #GtkWidget
6534 * @receives_default: whether or not @widget can be a default widget.
6536 * Specifies whether @widget will be treated as the default widget
6537 * within its toplevel when it has the focus, even if another widget
6540 * See gtk_widget_grab_default() for details about the meaning of
6546 gtk_widget_set_receives_default (GtkWidget *widget,
6547 gboolean receives_default)
6549 g_return_if_fail (GTK_IS_WIDGET (widget));
6551 if (widget->priv->receives_default != receives_default)
6553 widget->priv->receives_default = receives_default;
6555 g_object_notify (G_OBJECT (widget), "receives-default");
6560 * gtk_widget_get_receives_default:
6561 * @widget: a #GtkWidget
6563 * Determines whether @widget is alyways treated as default widget
6564 * withing its toplevel when it has the focus, even if another widget
6567 * See gtk_widget_set_receives_default().
6569 * Return value: %TRUE if @widget acts as default widget when focussed,
6575 gtk_widget_get_receives_default (GtkWidget *widget)
6577 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6579 return widget->priv->receives_default;
6583 * gtk_widget_has_grab:
6584 * @widget: a #GtkWidget
6586 * Determines whether the widget is currently grabbing events, so it
6587 * is the only widget receiving input events (keyboard and mouse).
6589 * See also gtk_grab_add().
6591 * Return value: %TRUE if the widget is in the grab_widgets stack
6596 gtk_widget_has_grab (GtkWidget *widget)
6598 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6600 return widget->priv->has_grab;
6604 _gtk_widget_set_has_grab (GtkWidget *widget,
6607 widget->priv->has_grab = has_grab;
6611 * gtk_widget_device_is_shadowed:
6612 * @widget: a #GtkWidget
6613 * @device: a #GdkDevice
6615 * Returns %TRUE if @device has been shadowed by a GTK+
6616 * device grab on another widget, so it would stop sending
6617 * events to @widget. This may be used in the
6618 * #GtkWidget::grab-notify signal to check for specific
6619 * devices. See gtk_device_grab_add().
6621 * Returns: %TRUE if there is an ongoing grab on @device
6622 * by another #GtkWidget than @widget.
6627 gtk_widget_device_is_shadowed (GtkWidget *widget,
6630 GtkWindowGroup *group;
6631 GtkWidget *grab_widget, *toplevel;
6633 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6634 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6636 if (!gtk_widget_get_realized (widget))
6639 toplevel = gtk_widget_get_toplevel (widget);
6641 if (GTK_IS_WINDOW (toplevel))
6642 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6644 group = gtk_window_get_group (NULL);
6646 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6648 /* Widget not inside the hierarchy of grab_widget */
6650 widget != grab_widget &&
6651 !gtk_widget_is_ancestor (widget, grab_widget))
6654 grab_widget = gtk_window_group_get_current_grab (group);
6655 if (grab_widget && widget != grab_widget &&
6656 !gtk_widget_is_ancestor (widget, grab_widget))
6663 * gtk_widget_set_name:
6664 * @widget: a #GtkWidget
6665 * @name: name for the widget
6667 * Widgets can be named, which allows you to refer to them from a
6668 * gtkrc file. You can apply a style to widgets with a particular name
6669 * in the gtkrc file. See the documentation for gtkrc files (on the
6670 * same page as the docs for #GtkRcStyle).
6672 * Note that widget names are separated by periods in paths (see
6673 * gtk_widget_path()), so names with embedded periods may cause confusion.
6676 gtk_widget_set_name (GtkWidget *widget,
6679 GtkWidgetPrivate *priv;
6682 g_return_if_fail (GTK_IS_WIDGET (widget));
6684 priv = widget->priv;
6686 new_name = g_strdup (name);
6687 g_free (priv->name);
6688 priv->name = new_name;
6694 pos = gtk_widget_path_length (priv->path) - 1;
6695 gtk_widget_path_iter_set_name (priv->path, pos,
6700 gtk_style_context_set_path (priv->context, priv->path);
6703 gtk_widget_reset_rc_style (widget);
6705 g_object_notify (G_OBJECT (widget), "name");
6709 * gtk_widget_get_name:
6710 * @widget: a #GtkWidget
6712 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6713 * significance of widget names.
6715 * Return value: name of the widget. This string is owned by GTK+ and
6716 * should not be modified or freed
6718 G_CONST_RETURN gchar*
6719 gtk_widget_get_name (GtkWidget *widget)
6721 GtkWidgetPrivate *priv;
6723 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6725 priv = widget->priv;
6729 return G_OBJECT_TYPE_NAME (widget);
6733 _gtk_widget_update_state_flags (GtkWidget *widget,
6734 GtkStateFlags flags,
6737 GtkWidgetPrivate *priv;
6739 priv = widget->priv;
6741 /* Handle insensitive first, since it is propagated
6742 * differently throughout the widget hierarchy.
6744 if ((flags & GTK_STATE_FLAG_INSENSITIVE) !=
6745 (priv->state_flags & GTK_STATE_FLAG_INSENSITIVE))
6746 gtk_widget_set_sensitive (widget,
6747 operation != STATE_CHANGE_UNSET);
6749 flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
6752 operation == STATE_CHANGE_REPLACE)
6757 data.operation = operation;
6758 data.use_forall = FALSE;
6761 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6763 data.parent_sensitive = TRUE;
6765 gtk_widget_propagate_state (widget, &data);
6767 if (gtk_widget_is_drawable (widget))
6768 gtk_widget_queue_draw (widget);
6773 * gtk_widget_set_state_flags:
6774 * @widget: a #GtkWidget
6775 * @flags: State flags to turn on
6776 * @clear: Whether to clear state before turning on @flags
6778 * This function is for use in widget implementations. Turns on flag
6779 * values in the current widget state (insensitive, prelighted, etc.).
6781 * It is worth mentioning that any other state than %GTK_STATE_FLAG_INSENSITIVE,
6782 * will be propagated down to all non-internal children if @widget is a
6783 * #GtkContainer, while %GTK_STATE_FLAG_INSENSITIVE itself will be propagated
6784 * down to all #GtkContainer children by different means than turning on the
6785 * state flag down the hierarchy, both gtk_widget_get_state_flags() and
6786 * gtk_widget_is_sensitive() will make use of these.
6791 gtk_widget_set_state_flags (GtkWidget *widget,
6792 GtkStateFlags flags,
6795 g_return_if_fail (GTK_IS_WIDGET (widget));
6797 if ((!clear && (widget->priv->state_flags & flags) == flags) ||
6798 (clear && widget->priv->state_flags == flags))
6802 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6804 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_SET);
6808 * gtk_widget_unset_state_flags:
6809 * @widget: a #GtkWidget
6810 * @flags: State flags to turn off
6812 * This function is for use in widget implementations. Turns off flag
6813 * values for the current widget state (insensitive, prelighted, etc.).
6814 * See gtk_widget_set_state_flags().
6819 gtk_widget_unset_state_flags (GtkWidget *widget,
6820 GtkStateFlags flags)
6822 g_return_if_fail (GTK_IS_WIDGET (widget));
6824 if ((widget->priv->state_flags & flags) == 0)
6827 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_UNSET);
6831 * gtk_widget_get_state_flags:
6832 * @widget: a #GtkWidget
6834 * Returns the widget state as a flag set. It is worth mentioning
6835 * that the effective %GTK_STATE_FLAG_INSENSITIVE state will be
6836 * returned, that is, also based on parent insensitivity, even if
6837 * @widget itself is sensitive.
6839 * Returns: The state flags for widget
6844 gtk_widget_get_state_flags (GtkWidget *widget)
6846 GtkStateFlags flags;
6848 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
6850 flags = widget->priv->state_flags;
6852 if (!gtk_widget_is_sensitive (widget))
6853 flags |= GTK_STATE_FLAG_INSENSITIVE;
6859 * gtk_widget_set_state:
6860 * @widget: a #GtkWidget
6861 * @state: new state for @widget
6863 * This function is for use in widget implementations. Sets the state
6864 * of a widget (insensitive, prelighted, etc.) Usually you should set
6865 * the state using wrapper functions such as gtk_widget_set_sensitive().
6867 * Deprecated: 3.0. Use gtk_widget_set_state_flags() instead.
6870 gtk_widget_set_state (GtkWidget *widget,
6873 GtkStateFlags flags;
6875 if (state == gtk_widget_get_state (widget))
6880 case GTK_STATE_ACTIVE:
6881 flags = GTK_STATE_FLAG_ACTIVE;
6883 case GTK_STATE_PRELIGHT:
6884 flags = GTK_STATE_FLAG_PRELIGHT;
6886 case GTK_STATE_SELECTED:
6887 flags = GTK_STATE_FLAG_SELECTED;
6889 case GTK_STATE_INSENSITIVE:
6890 flags = GTK_STATE_FLAG_INSENSITIVE;
6892 case GTK_STATE_INCONSISTENT:
6893 flags = GTK_STATE_FLAG_INCONSISTENT;
6895 case GTK_STATE_FOCUSED:
6896 flags = GTK_STATE_FLAG_FOCUSED;
6898 case GTK_STATE_NORMAL:
6904 _gtk_widget_update_state_flags (widget, flags, STATE_CHANGE_REPLACE);
6908 * gtk_widget_get_state:
6909 * @widget: a #GtkWidget
6911 * Returns the widget's state. See gtk_widget_set_state().
6913 * Returns: the state of @widget.
6917 * Deprecated: 3.0. Use gtk_widget_get_state_flags() instead.
6920 gtk_widget_get_state (GtkWidget *widget)
6922 GtkStateFlags flags;
6924 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6926 flags = gtk_widget_get_state_flags (widget);
6928 if (flags & GTK_STATE_FLAG_INSENSITIVE)
6929 return GTK_STATE_INSENSITIVE;
6930 else if (flags & GTK_STATE_FLAG_INCONSISTENT)
6931 return GTK_STATE_INCONSISTENT;
6932 else if (flags & GTK_STATE_FLAG_ACTIVE)
6933 return GTK_STATE_ACTIVE;
6934 else if (flags & GTK_STATE_FLAG_SELECTED)
6935 return GTK_STATE_SELECTED;
6936 else if (flags & GTK_STATE_FLAG_FOCUSED)
6937 return GTK_STATE_FOCUSED;
6938 else if (flags & GTK_STATE_FLAG_PRELIGHT)
6939 return GTK_STATE_PRELIGHT;
6941 return GTK_STATE_NORMAL;
6945 * gtk_widget_set_visible:
6946 * @widget: a #GtkWidget
6947 * @visible: whether the widget should be shown or not
6949 * Sets the visibility state of @widget. Note that setting this to
6950 * %TRUE doesn't mean the widget is actually viewable, see
6951 * gtk_widget_get_visible().
6953 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6954 * but is nicer to use when the visibility of the widget depends on
6960 gtk_widget_set_visible (GtkWidget *widget,
6963 g_return_if_fail (GTK_IS_WIDGET (widget));
6965 if (visible != gtk_widget_get_visible (widget))
6968 gtk_widget_show (widget);
6970 gtk_widget_hide (widget);
6975 _gtk_widget_set_visible_flag (GtkWidget *widget,
6978 widget->priv->visible = visible;
6982 * gtk_widget_get_visible:
6983 * @widget: a #GtkWidget
6985 * Determines whether the widget is visible. Note that this doesn't
6986 * take into account whether the widget's parent is also visible
6987 * or the widget is obscured in any way.
6989 * See gtk_widget_set_visible().
6991 * Return value: %TRUE if the widget is visible
6996 gtk_widget_get_visible (GtkWidget *widget)
6998 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7000 return widget->priv->visible;
7004 * gtk_widget_set_has_window:
7005 * @widget: a #GtkWidget
7006 * @has_window: whether or not @widget has a window.
7008 * Specifies whether @widget has a #GdkWindow of its own. Note that
7009 * all realized widgets have a non-%NULL "window" pointer
7010 * (gtk_widget_get_window() never returns a %NULL window when a widget
7011 * is realized), but for many of them it's actually the #GdkWindow of
7012 * one of its parent widgets. Widgets that do not create a %window for
7013 * themselves in #GtkWidget::realize must announce this by
7014 * calling this function with @has_window = %FALSE.
7016 * This function should only be called by widget implementations,
7017 * and they should call it in their init() function.
7022 gtk_widget_set_has_window (GtkWidget *widget,
7023 gboolean has_window)
7025 g_return_if_fail (GTK_IS_WIDGET (widget));
7027 widget->priv->no_window = !has_window;
7031 * gtk_widget_get_has_window:
7032 * @widget: a #GtkWidget
7034 * Determines whether @widget has a #GdkWindow of its own. See
7035 * gtk_widget_set_has_window().
7037 * Return value: %TRUE if @widget has a window, %FALSE otherwise
7042 gtk_widget_get_has_window (GtkWidget *widget)
7044 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7046 return ! widget->priv->no_window;
7050 * gtk_widget_is_toplevel:
7051 * @widget: a #GtkWidget
7053 * Determines whether @widget is a toplevel widget. Currently only
7054 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
7055 * widgets have no parent widget.
7057 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
7062 gtk_widget_is_toplevel (GtkWidget *widget)
7064 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7066 return widget->priv->toplevel;
7070 _gtk_widget_set_is_toplevel (GtkWidget *widget,
7071 gboolean is_toplevel)
7073 widget->priv->toplevel = is_toplevel;
7077 * gtk_widget_is_drawable:
7078 * @widget: a #GtkWidget
7080 * Determines whether @widget can be drawn to. A widget can be drawn
7081 * to if it is mapped and visible.
7083 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
7088 gtk_widget_is_drawable (GtkWidget *widget)
7090 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7092 return (gtk_widget_get_visible (widget) &&
7093 gtk_widget_get_mapped (widget));
7097 * gtk_widget_get_realized:
7098 * @widget: a #GtkWidget
7100 * Determines whether @widget is realized.
7102 * Return value: %TRUE if @widget is realized, %FALSE otherwise
7107 gtk_widget_get_realized (GtkWidget *widget)
7109 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7111 return widget->priv->realized;
7115 * gtk_widget_set_realized:
7116 * @widget: a #GtkWidget
7117 * @realized: %TRUE to mark the widget as realized
7119 * Marks the widget as being realized.
7121 * This function should only ever be called in a derived widget's
7122 * "realize" or "unrealize" implementation.
7127 gtk_widget_set_realized (GtkWidget *widget,
7130 g_return_if_fail (GTK_IS_WIDGET (widget));
7132 widget->priv->realized = realized;
7136 * gtk_widget_get_mapped:
7137 * @widget: a #GtkWidget
7139 * Whether the widget is mapped.
7141 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
7146 gtk_widget_get_mapped (GtkWidget *widget)
7148 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7150 return widget->priv->mapped;
7154 * gtk_widget_set_mapped:
7155 * @widget: a #GtkWidget
7156 * @mapped: %TRUE to mark the widget as mapped
7158 * Marks the widget as being realized.
7160 * This function should only ever be called in a derived widget's
7161 * "map" or "unmap" implementation.
7166 gtk_widget_set_mapped (GtkWidget *widget,
7169 g_return_if_fail (GTK_IS_WIDGET (widget));
7171 widget->priv->mapped = mapped;
7175 * gtk_widget_set_app_paintable:
7176 * @widget: a #GtkWidget
7177 * @app_paintable: %TRUE if the application will paint on the widget
7179 * Sets whether the application intends to draw on the widget in
7180 * an #GtkWidget::draw handler.
7182 * This is a hint to the widget and does not affect the behavior of
7183 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7184 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7185 * the effect is to suppress default themed drawing of the widget's
7186 * background. (Children of the widget will still be drawn.) The application
7187 * is then entirely responsible for drawing the widget background.
7189 * Note that the background is still drawn when the widget is mapped.
7192 gtk_widget_set_app_paintable (GtkWidget *widget,
7193 gboolean app_paintable)
7195 g_return_if_fail (GTK_IS_WIDGET (widget));
7197 app_paintable = (app_paintable != FALSE);
7199 if (widget->priv->app_paintable != app_paintable)
7201 widget->priv->app_paintable = app_paintable;
7203 if (gtk_widget_is_drawable (widget))
7204 gtk_widget_queue_draw (widget);
7206 g_object_notify (G_OBJECT (widget), "app-paintable");
7211 * gtk_widget_get_app_paintable:
7212 * @widget: a #GtkWidget
7214 * Determines whether the application intends to draw on the widget in
7215 * an #GtkWidget::draw handler.
7217 * See gtk_widget_set_app_paintable()
7219 * Return value: %TRUE if the widget is app paintable
7224 gtk_widget_get_app_paintable (GtkWidget *widget)
7226 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7228 return widget->priv->app_paintable;
7232 * gtk_widget_set_double_buffered:
7233 * @widget: a #GtkWidget
7234 * @double_buffered: %TRUE to double-buffer a widget
7236 * Widgets are double buffered by default; you can use this function
7237 * to turn off the buffering. "Double buffered" simply means that
7238 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7239 * automatically around expose events sent to the
7240 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7241 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7242 * buffer to the screen. The result is that users see the window
7243 * update in one smooth step, and don't see individual graphics
7244 * primitives being rendered.
7246 * In very simple terms, double buffered widgets don't flicker,
7247 * so you would only use this function to turn off double buffering
7248 * if you had special needs and really knew what you were doing.
7250 * Note: if you turn off double-buffering, you have to handle
7251 * expose events, since even the clearing to the background color or
7252 * pixmap will not happen automatically (as it is done in
7253 * gdk_window_begin_paint()).
7256 gtk_widget_set_double_buffered (GtkWidget *widget,
7257 gboolean double_buffered)
7259 g_return_if_fail (GTK_IS_WIDGET (widget));
7261 double_buffered = (double_buffered != FALSE);
7263 if (widget->priv->double_buffered != double_buffered)
7265 widget->priv->double_buffered = double_buffered;
7267 g_object_notify (G_OBJECT (widget), "double-buffered");
7272 * gtk_widget_get_double_buffered:
7273 * @widget: a #GtkWidget
7275 * Determines whether the widget is double buffered.
7277 * See gtk_widget_set_double_buffered()
7279 * Return value: %TRUE if the widget is double buffered
7284 gtk_widget_get_double_buffered (GtkWidget *widget)
7286 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7288 return widget->priv->double_buffered;
7292 * gtk_widget_set_redraw_on_allocate:
7293 * @widget: a #GtkWidget
7294 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7295 * when it is allocated to a new size. Otherwise, only the
7296 * new portion of the widget will be redrawn.
7298 * Sets whether the entire widget is queued for drawing when its size
7299 * allocation changes. By default, this setting is %TRUE and
7300 * the entire widget is redrawn on every size change. If your widget
7301 * leaves the upper left unchanged when made bigger, turning this
7302 * setting off will improve performance.
7304 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7305 * off all allocation on resizing: the widget will not even redraw if
7306 * its position changes; this is to allow containers that don't draw
7307 * anything to avoid excess invalidations. If you set this flag on a
7308 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7309 * you are responsible for invalidating both the old and new allocation
7310 * of the widget when the widget is moved and responsible for invalidating
7311 * regions newly when the widget increases size.
7314 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7315 gboolean redraw_on_allocate)
7317 g_return_if_fail (GTK_IS_WIDGET (widget));
7319 widget->priv->redraw_on_alloc = redraw_on_allocate;
7323 * gtk_widget_set_sensitive:
7324 * @widget: a #GtkWidget
7325 * @sensitive: %TRUE to make the widget sensitive
7327 * Sets the sensitivity of a widget. A widget is sensitive if the user
7328 * can interact with it. Insensitive widgets are "grayed out" and the
7329 * user can't interact with them. Insensitive widgets are known as
7330 * "inactive", "disabled", or "ghosted" in some other toolkits.
7333 gtk_widget_set_sensitive (GtkWidget *widget,
7336 GtkWidgetPrivate *priv;
7339 g_return_if_fail (GTK_IS_WIDGET (widget));
7341 priv = widget->priv;
7343 sensitive = (sensitive != FALSE);
7345 if (widget->priv->sensitive == sensitive)
7348 data.flags = GTK_STATE_FLAG_INSENSITIVE;
7352 widget->priv->sensitive = TRUE;
7353 data.operation = STATE_CHANGE_UNSET;
7357 widget->priv->sensitive = FALSE;
7358 data.operation = STATE_CHANGE_SET;
7361 data.use_forall = TRUE;
7364 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7366 data.parent_sensitive = TRUE;
7368 gtk_widget_propagate_state (widget, &data);
7370 if (gtk_widget_is_drawable (widget))
7371 gtk_widget_queue_draw (widget);
7373 g_object_notify (G_OBJECT (widget), "sensitive");
7377 * gtk_widget_get_sensitive:
7378 * @widget: a #GtkWidget
7380 * Returns the widget's sensitivity (in the sense of returning
7381 * the value that has been set using gtk_widget_set_sensitive()).
7383 * The effective sensitivity of a widget is however determined by both its
7384 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7386 * Returns: %TRUE if the widget is sensitive
7391 gtk_widget_get_sensitive (GtkWidget *widget)
7393 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7395 return widget->priv->sensitive;
7399 * gtk_widget_is_sensitive:
7400 * @widget: a #GtkWidget
7402 * Returns the widget's effective sensitivity, which means
7403 * it is sensitive itself and also its parent widget is sensntive
7405 * Returns: %TRUE if the widget is effectively sensitive
7410 gtk_widget_is_sensitive (GtkWidget *widget)
7412 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7414 return widget->priv->sensitive && widget->priv->parent_sensitive;
7418 _gtk_widget_update_path (GtkWidget *widget)
7420 if (widget->priv->path)
7422 gtk_widget_path_free (widget->priv->path);
7423 widget->priv->path = NULL;
7426 gtk_widget_get_path (widget);
7430 * gtk_widget_set_parent:
7431 * @widget: a #GtkWidget
7432 * @parent: parent container
7434 * This function is useful only when implementing subclasses of
7436 * Sets the container as the parent of @widget, and takes care of
7437 * some details such as updating the state and style of the child
7438 * to reflect its new location. The opposite function is
7439 * gtk_widget_unparent().
7442 gtk_widget_set_parent (GtkWidget *widget,
7445 GtkStateFlags parent_flags;
7446 GtkWidgetPrivate *priv;
7449 g_return_if_fail (GTK_IS_WIDGET (widget));
7450 g_return_if_fail (GTK_IS_WIDGET (parent));
7451 g_return_if_fail (widget != parent);
7453 priv = widget->priv;
7455 if (priv->parent != NULL)
7457 g_warning ("Can't set a parent on widget which has a parent\n");
7460 if (gtk_widget_is_toplevel (widget))
7462 g_warning ("Can't set a parent on a toplevel widget\n");
7466 /* keep this function in sync with gtk_menu_attach_to_widget()
7469 g_object_ref_sink (widget);
7470 priv->parent = parent;
7472 parent_flags = gtk_widget_get_state_flags (parent);
7474 /* Merge both old state and current parent state,
7475 * We don't want the insensitive flag to propagate
7476 * to the new child though */
7477 data.flags = parent_flags & ~GTK_STATE_FLAG_INSENSITIVE;
7478 data.flags |= priv->state_flags;
7480 data.operation = STATE_CHANGE_REPLACE;
7481 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7482 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7483 gtk_widget_propagate_state (widget, &data);
7485 gtk_widget_reset_rc_styles (widget);
7487 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7488 if (priv->parent->priv->anchored)
7489 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7490 g_object_notify (G_OBJECT (widget), "parent");
7492 /* Enforce realized/mapped invariants
7494 if (gtk_widget_get_realized (priv->parent))
7495 gtk_widget_realize (widget);
7497 if (gtk_widget_get_visible (priv->parent) &&
7498 gtk_widget_get_visible (widget))
7500 if (gtk_widget_get_child_visible (widget) &&
7501 gtk_widget_get_mapped (priv->parent))
7502 gtk_widget_map (widget);
7504 gtk_widget_queue_resize (widget);
7507 /* child may cause parent's expand to change, if the child is
7508 * expanded. If child is not expanded, then it can't modify the
7509 * parent's expand. If the child becomes expanded later then it will
7510 * queue compute_expand then. This optimization plus defaulting
7511 * newly-constructed widgets to need_compute_expand=FALSE should
7512 * mean that initially building a widget tree doesn't have to keep
7513 * walking up setting need_compute_expand on parents over and over.
7515 * We can't change a parent to need to expand unless we're visible.
7517 if (gtk_widget_get_visible (widget) &&
7518 (priv->need_compute_expand ||
7519 priv->computed_hexpand ||
7520 priv->computed_vexpand))
7522 gtk_widget_queue_compute_expand (parent);
7525 if (widget->priv->context)
7527 _gtk_widget_update_path (widget);
7528 gtk_style_context_set_path (widget->priv->context, widget->priv->path);
7530 gtk_style_context_set_screen (widget->priv->context,
7531 gtk_widget_get_screen (widget));
7536 * gtk_widget_get_parent:
7537 * @widget: a #GtkWidget
7539 * Returns the parent container of @widget.
7541 * Return value: (transfer none): the parent container of @widget, or %NULL
7544 gtk_widget_get_parent (GtkWidget *widget)
7546 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7548 return widget->priv->parent;
7551 /*****************************************
7553 * see docs/styles.txt
7554 *****************************************/
7557 * gtk_widget_style_attach:
7558 * @widget: a #GtkWidget
7560 * This function attaches the widget's #GtkStyle to the widget's
7561 * #GdkWindow. It is a replacement for
7564 * widget->style = gtk_style_attach (widget->style, widget->window);
7567 * and should only ever be called in a derived widget's "realize"
7568 * implementation which does not chain up to its parent class'
7569 * "realize" implementation, because one of the parent classes
7570 * (finally #GtkWidget) would attach the style itself.
7575 gtk_widget_style_attach (GtkWidget *widget)
7577 GtkWidgetPrivate *priv;
7579 g_return_if_fail (GTK_IS_WIDGET (widget));
7580 g_return_if_fail (gtk_widget_get_realized (widget));
7582 priv = widget->priv;
7584 priv->style = gtk_style_attach (priv->style, priv->window);
7588 * gtk_widget_has_rc_style:
7589 * @widget: a #GtkWidget
7591 * Determines if the widget style has been looked up through the rc mechanism.
7593 * Returns: %TRUE if the widget has been looked up through the rc
7594 * mechanism, %FALSE otherwise.
7599 gtk_widget_has_rc_style (GtkWidget *widget)
7601 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7603 return widget->priv->rc_style;
7607 * gtk_widget_set_style:
7608 * @widget: a #GtkWidget
7609 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7610 * gtk_widget_set_style() and go back to the default style
7612 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7613 * want to use this function; it interacts badly with themes, because
7614 * themes work by replacing the #GtkStyle. Instead, use
7615 * gtk_widget_modify_style().
7618 gtk_widget_set_style (GtkWidget *widget,
7621 g_return_if_fail (GTK_IS_WIDGET (widget));
7625 gboolean initial_emission;
7627 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7629 widget->priv->rc_style = FALSE;
7630 widget->priv->user_style = TRUE;
7632 gtk_widget_set_style_internal (widget, style, initial_emission);
7636 if (widget->priv->user_style)
7637 gtk_widget_reset_rc_style (widget);
7642 * gtk_widget_ensure_style:
7643 * @widget: a #GtkWidget
7645 * Ensures that @widget has a style (@widget->style). Not a very useful
7646 * function; most of the time, if you want the style, the widget is
7647 * realized, and realized widgets are guaranteed to have a style
7651 gtk_widget_ensure_style (GtkWidget *widget)
7653 g_return_if_fail (GTK_IS_WIDGET (widget));
7655 if (!widget->priv->style ||
7656 !gtk_style_has_context (widget->priv->style))
7660 style = g_object_new (GTK_TYPE_STYLE,
7661 "context", gtk_widget_get_style_context (widget),
7664 gtk_widget_set_style_internal (widget, style, TRUE);
7665 g_object_unref (style);
7669 if (!widget->priv->rc_style && !widget->priv->user_style)
7670 gtk_widget_reset_rc_style (widget);
7674 /* Look up the RC style for this widget, unsetting any user style that
7675 * may be in effect currently
7678 gtk_widget_reset_rc_style (GtkWidget *widget)
7680 GtkWidgetPrivate *priv = widget->priv;
7681 GtkStyle *new_style = NULL;
7682 gboolean initial_emission;
7684 initial_emission = !priv->rc_style && !priv->user_style;
7686 priv->user_style = FALSE;
7687 priv->rc_style = TRUE;
7689 if (gtk_widget_has_screen (widget))
7690 new_style = gtk_rc_get_style (widget);
7692 new_style = gtk_widget_get_default_style ();
7694 if (initial_emission || new_style != priv->style)
7695 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7699 * gtk_widget_get_style:
7700 * @widget: a #GtkWidget
7702 * Simply an accessor function that returns @widget->style.
7704 * Return value: (transfer none): the widget's #GtkStyle
7707 gtk_widget_get_style (GtkWidget *widget)
7709 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7711 return widget->priv->style;
7715 * gtk_widget_modify_style:
7716 * @widget: a #GtkWidget
7717 * @style: the #GtkRcStyle holding the style modifications
7719 * Modifies style values on the widget. Modifications made using this
7720 * technique take precedence over style values set via an RC file,
7721 * however, they will be overriden if a style is explicitely set on
7722 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7723 * is designed so each field can either be set or unset, so it is
7724 * possible, using this function, to modify some style values and
7725 * leave the others unchanged.
7727 * Note that modifications made with this function are not cumulative
7728 * with previous calls to gtk_widget_modify_style() or with such
7729 * functions as gtk_widget_modify_fg(). If you wish to retain
7730 * previous values, you must first call gtk_widget_get_modifier_style(),
7731 * make your modifications to the returned style, then call
7732 * gtk_widget_modify_style() with that style. On the other hand,
7733 * if you first call gtk_widget_modify_style(), subsequent calls
7734 * to such functions gtk_widget_modify_fg() will have a cumulative
7735 * effect with the initial modifications.
7738 gtk_widget_modify_style (GtkWidget *widget,
7741 g_return_if_fail (GTK_IS_WIDGET (widget));
7742 g_return_if_fail (GTK_IS_RC_STYLE (style));
7744 g_object_set_qdata_full (G_OBJECT (widget),
7746 gtk_rc_style_copy (style),
7747 (GDestroyNotify) g_object_unref);
7749 /* note that "style" may be invalid here if it was the old
7750 * modifier style and the only reference was our own.
7753 if (widget->priv->rc_style)
7754 gtk_widget_reset_rc_style (widget);
7758 * gtk_widget_get_modifier_style:
7759 * @widget: a #GtkWidget
7761 * Returns the current modifier style for the widget. (As set by
7762 * gtk_widget_modify_style().) If no style has previously set, a new
7763 * #GtkRcStyle will be created with all values unset, and set as the
7764 * modifier style for the widget. If you make changes to this rc
7765 * style, you must call gtk_widget_modify_style(), passing in the
7766 * returned rc style, to make sure that your changes take effect.
7768 * Caution: passing the style back to gtk_widget_modify_style() will
7769 * normally end up destroying it, because gtk_widget_modify_style() copies
7770 * the passed-in style and sets the copy as the new modifier style,
7771 * thus dropping any reference to the old modifier style. Add a reference
7772 * to the modifier style if you want to keep it alive.
7774 * Return value: (transfer none): the modifier style for the widget. This rc style is
7775 * owned by the widget. If you want to keep a pointer to value this
7776 * around, you must add a refcount using g_object_ref().
7779 gtk_widget_get_modifier_style (GtkWidget *widget)
7781 GtkRcStyle *rc_style;
7783 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7785 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7789 rc_style = gtk_rc_style_new ();
7790 g_object_set_qdata_full (G_OBJECT (widget),
7793 (GDestroyNotify) g_object_unref);
7800 gtk_widget_modify_color_component (GtkWidget *widget,
7801 GtkRcFlags component,
7803 const GdkColor *color)
7805 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7812 rc_style->fg[state] = *color;
7815 rc_style->bg[state] = *color;
7818 rc_style->text[state] = *color;
7821 rc_style->base[state] = *color;
7824 g_assert_not_reached();
7827 rc_style->color_flags[state] |= component;
7830 rc_style->color_flags[state] &= ~component;
7832 gtk_widget_modify_style (widget, rc_style);
7835 static GtkStyleProperties *
7836 _gtk_widget_get_modifier_properties (GtkWidget *widget)
7838 GtkStyleProperties *properties;
7840 properties = g_object_get_qdata (G_OBJECT (widget), quark_modifier_style);
7842 if (G_UNLIKELY (!properties))
7844 GtkStyleContext *context;
7846 properties = gtk_style_properties_new ();
7847 g_object_set_qdata_full (G_OBJECT (widget),
7848 quark_modifier_style,
7850 (GDestroyNotify) g_object_unref);
7852 context = gtk_widget_get_style_context (widget);
7854 gtk_style_context_add_provider (context,
7855 GTK_STYLE_PROVIDER (properties),
7856 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
7863 * gtk_widget_override_color:
7864 * @widget: a #GtkWidget
7865 * @state: the state for which to set the color
7866 * @color: the color to assign, or %NULL to undo the effect
7867 * of previous calls to gtk_widget_override_color()
7869 * Sets the color to use for a widget. All other style values are left
7874 * This API is mostly meant as a quick way for applications to change a
7875 * widget appearance. If you are developing a widgets library and intend
7876 * this change to be themeable, it is better done by setting meaningful
7877 * CSS classes and regions in your widget/container implementation through
7878 * gtk_style_context_add_class() and gtk_style_context_add_region().
7881 * This way, your widget library can install a #GtkCssProvider with the
7882 * %GTK_STYLE_PROVIDER_PRIORITY_FALLBACK priority in order to provide a
7883 * default styling for those widgets that need so, and this theming may
7884 * fully overridden by the user's theme.
7890 * Note that for complex widgets this may bring in
7891 * undesired results (such as uniform background color everywhere),
7892 * in these cases it is better to fully style such widgets through a
7893 * #GtkCssProvider with the %GTK_STYLE_PROVIDER_PRIORITY_APPLICATION
7901 gtk_widget_override_color (GtkWidget *widget,
7902 GtkStateFlags state,
7903 const GdkRGBA *color)
7905 GtkStyleProperties *properties;
7906 GtkStyleContext *context;
7908 g_return_if_fail (GTK_IS_WIDGET (widget));
7910 properties = _gtk_widget_get_modifier_properties (widget);
7912 gtk_style_properties_set (properties, state,
7916 context = gtk_widget_get_style_context (widget);
7917 gtk_style_context_invalidate (context);
7919 g_signal_emit (widget,
7920 widget_signals[STYLE_SET],
7922 widget->priv->style);
7926 * gtk_widget_override_background_color:
7927 * @widget: a #GtkWidget
7928 * @state: the state for which to set the background color
7929 * @color: the color to assign, or %NULL to undo the effect
7930 * of previous calls to gtk_widget_override_background_color()
7932 * Sets the background color to use for a widget. All other style values
7933 * are left untouched. See gtk_widget_override_color().
7938 gtk_widget_override_background_color (GtkWidget *widget,
7939 GtkStateFlags state,
7940 const GdkRGBA *color)
7942 GtkStyleProperties *properties;
7943 GtkStyleContext *context;
7945 g_return_if_fail (GTK_IS_WIDGET (widget));
7947 properties = _gtk_widget_get_modifier_properties (widget);
7949 gtk_style_properties_set (properties, state,
7950 "background-color", color,
7953 context = gtk_widget_get_style_context (widget);
7954 gtk_style_context_invalidate (context);
7956 g_signal_emit (widget,
7957 widget_signals[STYLE_SET],
7959 widget->priv->style);
7963 * gtk_widget_override_font:
7964 * @widget: a #GtkWidget
7965 * @font_desc: the font descriptiong to use, or %NULL to undo
7966 * the effect of previous calls to
7967 * gtk_widget_override_font().
7969 * Sets the font to use for a widget. All other style values are
7970 * left untouched. See gtk_widget_override_color().
7975 gtk_widget_override_font (GtkWidget *widget,
7976 const PangoFontDescription *font_desc)
7978 GtkStyleProperties *properties;
7979 GtkStyleContext *context;
7981 g_return_if_fail (GTK_IS_WIDGET (widget));
7983 properties = _gtk_widget_get_modifier_properties (widget);
7985 gtk_style_properties_set (properties, 0,
7989 context = gtk_widget_get_style_context (widget);
7990 gtk_style_context_invalidate (context);
7992 g_signal_emit (widget,
7993 widget_signals[STYLE_SET],
7995 widget->priv->style);
7999 * gtk_widget_override_symbolic_color:
8000 * @widget: a #GtkWidget
8001 * @name: the name of the symbolic color to modify
8002 * @color: (allow-none): the color to assign (does not need to be allocated),
8003 * or %NULL to undo the effect of previous calls to
8004 * gtk_widget_override_symbolic_color().
8006 * Sets a symbolic color for a widget, All other style values are left
8007 * untouched. See gtk_widget_override_color().
8012 gtk_widget_override_symbolic_color (GtkWidget *widget,
8014 const GdkRGBA *color)
8016 GtkStyleProperties *properties;
8017 GtkStyleContext *context;
8018 GtkSymbolicColor *symbolic_color;
8020 g_return_if_fail (GTK_IS_WIDGET (widget));
8022 properties = _gtk_widget_get_modifier_properties (widget);
8023 symbolic_color = gtk_symbolic_color_new_literal (color);
8025 gtk_style_properties_map_color (properties,
8026 name, symbolic_color);
8028 gtk_symbolic_color_unref (symbolic_color);
8030 context = gtk_widget_get_style_context (widget);
8031 gtk_style_context_invalidate (context);
8033 g_signal_emit (widget,
8034 widget_signals[STYLE_SET],
8036 widget->priv->style);
8040 * gtk_widget_modify_fg:
8041 * @widget: a #GtkWidget
8042 * @state: the state for which to set the foreground color
8043 * @color: (allow-none): the color to assign (does not need to be allocated),
8044 * or %NULL to undo the effect of previous calls to
8045 * of gtk_widget_modify_fg().
8047 * Sets the foreground color for a widget in a particular state.
8048 * All other style values are left untouched. See also
8049 * gtk_widget_modify_style().
8052 gtk_widget_modify_fg (GtkWidget *widget,
8054 const GdkColor *color)
8056 GtkStateFlags flags;
8059 g_return_if_fail (GTK_IS_WIDGET (widget));
8060 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8064 case GTK_STATE_ACTIVE:
8065 flags = GTK_STATE_FLAG_ACTIVE;
8067 case GTK_STATE_PRELIGHT:
8068 flags = GTK_STATE_FLAG_PRELIGHT;
8070 case GTK_STATE_SELECTED:
8071 flags = GTK_STATE_FLAG_SELECTED;
8073 case GTK_STATE_INSENSITIVE:
8074 flags = GTK_STATE_FLAG_INSENSITIVE;
8076 case GTK_STATE_NORMAL:
8083 rgba.red = color->red / 65535.;
8084 rgba.green = color->green / 65535.;
8085 rgba.blue = color->blue / 65535.;
8088 gtk_widget_override_color (widget, state, &rgba);
8091 gtk_widget_override_color (widget, state, NULL);
8095 * gtk_widget_modify_bg:
8096 * @widget: a #GtkWidget
8097 * @state: the state for which to set the background color
8098 * @color: (allow-none): the color to assign (does not need to be allocated),
8099 * or %NULL to undo the effect of previous calls to
8100 * of gtk_widget_modify_bg().
8102 * Sets the background color for a widget in a particular state.
8103 * All other style values are left untouched. See also
8104 * gtk_widget_modify_style().
8106 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8107 * draw on their parent container's window and thus may not draw any
8108 * background themselves. This is the case for e.g. #GtkLabel. To modify
8109 * the background of such widgets, you have to set the background color
8110 * on their parent; if you want to set the background of a rectangular
8111 * area around a label, try placing the label in a #GtkEventBox widget
8112 * and setting the background color on that.
8115 gtk_widget_modify_bg (GtkWidget *widget,
8117 const GdkColor *color)
8119 GtkStateFlags flags;
8122 g_return_if_fail (GTK_IS_WIDGET (widget));
8123 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8127 case GTK_STATE_ACTIVE:
8128 flags = GTK_STATE_FLAG_ACTIVE;
8130 case GTK_STATE_PRELIGHT:
8131 flags = GTK_STATE_FLAG_PRELIGHT;
8133 case GTK_STATE_SELECTED:
8134 flags = GTK_STATE_FLAG_SELECTED;
8136 case GTK_STATE_INSENSITIVE:
8137 flags = GTK_STATE_FLAG_INSENSITIVE;
8139 case GTK_STATE_NORMAL:
8146 rgba.red = color->red / 65535.;
8147 rgba.green = color->green / 65535.;
8148 rgba.blue = color->blue / 65535.;
8151 gtk_widget_override_background_color (widget, state, &rgba);
8154 gtk_widget_override_background_color (widget, state, NULL);
8158 * gtk_widget_modify_text:
8159 * @widget: a #GtkWidget
8160 * @state: the state for which to set the text color
8161 * @color: (allow-none): the color to assign (does not need to be allocated),
8162 * or %NULL to undo the effect of previous calls to
8163 * of gtk_widget_modify_text().
8165 * Sets the text color for a widget in a particular state. All other
8166 * style values are left untouched. The text color is the foreground
8167 * color used along with the base color (see gtk_widget_modify_base())
8168 * for widgets such as #GtkEntry and #GtkTextView. See also
8169 * gtk_widget_modify_style().
8172 gtk_widget_modify_text (GtkWidget *widget,
8174 const GdkColor *color)
8176 g_return_if_fail (GTK_IS_WIDGET (widget));
8177 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8179 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
8183 * gtk_widget_modify_base:
8184 * @widget: a #GtkWidget
8185 * @state: the state for which to set the base color
8186 * @color: (allow-none): the color to assign (does not need to be allocated),
8187 * or %NULL to undo the effect of previous calls to
8188 * of gtk_widget_modify_base().
8190 * Sets the base color for a widget in a particular state.
8191 * All other style values are left untouched. The base color
8192 * is the background color used along with the text color
8193 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
8194 * and #GtkTextView. See also gtk_widget_modify_style().
8196 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
8197 * draw on their parent container's window and thus may not draw any
8198 * background themselves. This is the case for e.g. #GtkLabel. To modify
8199 * the background of such widgets, you have to set the base color on their
8200 * parent; if you want to set the background of a rectangular area around
8201 * a label, try placing the label in a #GtkEventBox widget and setting
8202 * the base color on that.
8205 gtk_widget_modify_base (GtkWidget *widget,
8207 const GdkColor *color)
8209 g_return_if_fail (GTK_IS_WIDGET (widget));
8210 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
8212 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
8216 modify_color_property (GtkWidget *widget,
8217 GtkRcStyle *rc_style,
8219 const GdkColor *color)
8221 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
8222 GQuark property_name = g_quark_from_string (name);
8226 GtkRcProperty rc_property = {0};
8229 rc_property.type_name = type_name;
8230 rc_property.property_name = property_name;
8231 rc_property.origin = NULL;
8233 color_name = gdk_color_to_string (color);
8234 g_value_init (&rc_property.value, G_TYPE_STRING);
8235 g_value_take_string (&rc_property.value, color_name);
8237 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
8239 g_value_unset (&rc_property.value);
8242 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
8246 * gtk_widget_modify_cursor:
8247 * @widget: a #GtkWidget
8248 * @primary: the color to use for primary cursor (does not need to be
8249 * allocated), or %NULL to undo the effect of previous calls to
8250 * of gtk_widget_modify_cursor().
8251 * @secondary: the color to use for secondary cursor (does not need to be
8252 * allocated), or %NULL to undo the effect of previous calls to
8253 * of gtk_widget_modify_cursor().
8255 * Sets the cursor color to use in a widget, overriding the
8256 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
8257 * style properties. All other style values are left untouched.
8258 * See also gtk_widget_modify_style().
8263 gtk_widget_modify_cursor (GtkWidget *widget,
8264 const GdkColor *primary,
8265 const GdkColor *secondary)
8267 GtkRcStyle *rc_style;
8269 g_return_if_fail (GTK_IS_WIDGET (widget));
8271 rc_style = gtk_widget_get_modifier_style (widget);
8273 modify_color_property (widget, rc_style, "cursor-color", primary);
8274 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
8276 gtk_widget_modify_style (widget, rc_style);
8280 * gtk_widget_modify_font:
8281 * @widget: a #GtkWidget
8282 * @font_desc: (allow-none): the font description to use, or %NULL to undo
8283 * the effect of previous calls to gtk_widget_modify_font().
8285 * Sets the font to use for a widget. All other style values are left
8286 * untouched. See also gtk_widget_modify_style().
8289 gtk_widget_modify_font (GtkWidget *widget,
8290 PangoFontDescription *font_desc)
8292 g_return_if_fail (GTK_IS_WIDGET (widget));
8294 gtk_widget_override_font (widget, font_desc);
8298 gtk_widget_real_direction_changed (GtkWidget *widget,
8299 GtkTextDirection previous_direction)
8301 gtk_widget_queue_resize (widget);
8305 gtk_widget_real_style_set (GtkWidget *widget,
8306 GtkStyle *previous_style)
8308 GtkWidgetPrivate *priv = widget->priv;
8310 if (gtk_widget_get_realized (widget) &&
8311 gtk_widget_get_has_window (widget))
8312 gtk_style_set_background (priv->style, priv->window,
8313 gtk_widget_get_state (widget));
8317 gtk_widget_set_style_internal (GtkWidget *widget,
8319 gboolean initial_emission)
8321 GtkWidgetPrivate *priv = widget->priv;
8323 g_object_ref (widget);
8324 g_object_freeze_notify (G_OBJECT (widget));
8326 if (priv->style != style)
8328 GtkStyle *previous_style;
8330 if (gtk_widget_get_realized (widget))
8332 gtk_widget_reset_shapes (widget);
8333 gtk_style_detach (priv->style);
8336 previous_style = priv->style;
8337 priv->style = style;
8338 g_object_ref (priv->style);
8340 if (gtk_widget_get_realized (widget))
8341 priv->style = gtk_style_attach (priv->style, priv->window);
8343 gtk_widget_update_pango_context (widget);
8344 g_signal_emit (widget,
8345 widget_signals[STYLE_SET],
8347 initial_emission ? NULL : previous_style);
8348 g_object_unref (previous_style);
8350 if (priv->anchored && !initial_emission)
8351 gtk_widget_queue_resize (widget);
8353 else if (initial_emission)
8355 gtk_widget_update_pango_context (widget);
8356 g_signal_emit (widget,
8357 widget_signals[STYLE_SET],
8361 g_object_notify (G_OBJECT (widget), "style");
8362 g_object_thaw_notify (G_OBJECT (widget));
8363 g_object_unref (widget);
8367 GtkWidget *previous_toplevel;
8368 GdkScreen *previous_screen;
8369 GdkScreen *new_screen;
8370 } HierarchyChangedInfo;
8373 do_screen_change (GtkWidget *widget,
8374 GdkScreen *old_screen,
8375 GdkScreen *new_screen)
8377 if (old_screen != new_screen)
8379 GtkStyleContext *context;
8383 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8385 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
8388 _gtk_tooltip_hide (widget);
8390 context = gtk_widget_get_style_context (widget);
8391 gtk_style_context_set_screen (context, gtk_widget_get_screen (widget));
8393 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
8398 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
8399 gpointer client_data)
8401 GtkWidgetPrivate *priv = widget->priv;
8402 HierarchyChangedInfo *info = client_data;
8403 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
8404 (priv->parent && priv->parent->priv->anchored);
8406 if (priv->anchored != new_anchored)
8408 g_object_ref (widget);
8410 priv->anchored = new_anchored;
8412 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
8413 do_screen_change (widget, info->previous_screen, info->new_screen);
8415 if (GTK_IS_CONTAINER (widget))
8416 gtk_container_forall (GTK_CONTAINER (widget),
8417 gtk_widget_propagate_hierarchy_changed_recurse,
8420 g_object_unref (widget);
8425 * _gtk_widget_propagate_hierarchy_changed:
8426 * @widget: a #GtkWidget
8427 * @previous_toplevel: Previous toplevel
8429 * Propagates changes in the anchored state to a widget and all
8430 * children, unsetting or setting the %ANCHORED flag, and
8431 * emitting #GtkWidget::hierarchy-changed.
8434 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
8435 GtkWidget *previous_toplevel)
8437 GtkWidgetPrivate *priv = widget->priv;
8438 HierarchyChangedInfo info;
8440 info.previous_toplevel = previous_toplevel;
8441 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
8443 if (gtk_widget_is_toplevel (widget) ||
8444 (priv->parent && priv->parent->priv->anchored))
8445 info.new_screen = gtk_widget_get_screen (widget);
8447 info.new_screen = NULL;
8449 if (info.previous_screen)
8450 g_object_ref (info.previous_screen);
8451 if (previous_toplevel)
8452 g_object_ref (previous_toplevel);
8454 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8456 if (previous_toplevel)
8457 g_object_unref (previous_toplevel);
8458 if (info.previous_screen)
8459 g_object_unref (info.previous_screen);
8463 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8464 gpointer client_data)
8466 HierarchyChangedInfo *info = client_data;
8468 g_object_ref (widget);
8470 do_screen_change (widget, info->previous_screen, info->new_screen);
8472 if (GTK_IS_CONTAINER (widget))
8473 gtk_container_forall (GTK_CONTAINER (widget),
8474 gtk_widget_propagate_screen_changed_recurse,
8477 g_object_unref (widget);
8481 * gtk_widget_is_composited:
8482 * @widget: a #GtkWidget
8484 * Whether @widget can rely on having its alpha channel
8485 * drawn correctly. On X11 this function returns whether a
8486 * compositing manager is running for @widget's screen.
8488 * Please note that the semantics of this call will change
8489 * in the future if used on a widget that has a composited
8490 * window in its hierarchy (as set by gdk_window_set_composited()).
8492 * Return value: %TRUE if the widget can rely on its alpha
8493 * channel being drawn correctly.
8498 gtk_widget_is_composited (GtkWidget *widget)
8502 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8504 screen = gtk_widget_get_screen (widget);
8506 return gdk_screen_is_composited (screen);
8510 propagate_composited_changed (GtkWidget *widget,
8513 if (GTK_IS_CONTAINER (widget))
8515 gtk_container_forall (GTK_CONTAINER (widget),
8516 propagate_composited_changed,
8520 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8524 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8526 propagate_composited_changed (widget, NULL);
8530 * _gtk_widget_propagate_screen_changed:
8531 * @widget: a #GtkWidget
8532 * @previous_screen: Previous screen
8534 * Propagates changes in the screen for a widget to all
8535 * children, emitting #GtkWidget::screen-changed.
8538 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8539 GdkScreen *previous_screen)
8541 HierarchyChangedInfo info;
8543 info.previous_screen = previous_screen;
8544 info.new_screen = gtk_widget_get_screen (widget);
8546 if (previous_screen)
8547 g_object_ref (previous_screen);
8549 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8551 if (previous_screen)
8552 g_object_unref (previous_screen);
8556 reset_style_recurse (GtkWidget *widget, gpointer data)
8559 if (widget->priv->rc_style)
8560 gtk_widget_reset_rc_style (widget);
8563 if (widget->priv->context)
8565 _gtk_widget_update_path (widget);
8566 gtk_style_context_set_path (widget->priv->context,
8567 widget->priv->path);
8570 if (GTK_IS_CONTAINER (widget))
8571 gtk_container_forall (GTK_CONTAINER (widget),
8572 reset_style_recurse,
8577 gtk_widget_reset_style (GtkWidget *widget)
8579 g_return_if_fail (GTK_IS_WIDGET (widget));
8581 reset_style_recurse (widget, NULL);
8585 * gtk_widget_reset_rc_styles:
8586 * @widget: a #GtkWidget.
8588 * Reset the styles of @widget and all descendents, so when
8589 * they are looked up again, they get the correct values
8590 * for the currently loaded RC file settings.
8592 * This function is not useful for applications.
8595 gtk_widget_reset_rc_styles (GtkWidget *widget)
8597 g_return_if_fail (GTK_IS_WIDGET (widget));
8599 reset_style_recurse (widget, NULL);
8603 * gtk_widget_get_default_style:
8605 * Returns the default style used by all widgets initially.
8607 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8608 * by GTK+ and should not be modified or freed.
8611 gtk_widget_get_default_style (void)
8613 if (!gtk_default_style)
8615 gtk_default_style = gtk_style_new ();
8616 g_object_ref (gtk_default_style);
8619 return gtk_default_style;
8622 static PangoContext *
8623 gtk_widget_peek_pango_context (GtkWidget *widget)
8625 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8629 * gtk_widget_get_pango_context:
8630 * @widget: a #GtkWidget
8632 * Gets a #PangoContext with the appropriate font map, font description,
8633 * and base direction for this widget. Unlike the context returned
8634 * by gtk_widget_create_pango_context(), this context is owned by
8635 * the widget (it can be used until the screen for the widget changes
8636 * or the widget is removed from its toplevel), and will be updated to
8637 * match any changes to the widget's attributes.
8639 * If you create and keep a #PangoLayout using this context, you must
8640 * deal with changes to the context by calling pango_layout_context_changed()
8641 * on the layout in response to the #GtkWidget::style-set and
8642 * #GtkWidget::direction-changed signals for the widget.
8644 * Return value: (transfer none): the #PangoContext for the widget.
8647 gtk_widget_get_pango_context (GtkWidget *widget)
8649 PangoContext *context;
8651 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8653 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8656 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8657 g_object_set_qdata_full (G_OBJECT (widget),
8658 quark_pango_context,
8667 update_pango_context (GtkWidget *widget,
8668 PangoContext *context)
8670 PangoFontDescription *font_desc;
8671 GtkStyleContext *style_context;
8673 style_context = gtk_widget_get_style_context (widget);
8675 gtk_style_context_get (style_context,
8676 gtk_widget_get_state_flags (widget),
8680 pango_context_set_font_description (context, font_desc);
8681 pango_context_set_base_dir (context,
8682 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8683 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8685 pango_font_description_free (font_desc);
8689 gtk_widget_update_pango_context (GtkWidget *widget)
8691 PangoContext *context = gtk_widget_peek_pango_context (widget);
8697 update_pango_context (widget, context);
8699 screen = gtk_widget_get_screen_unchecked (widget);
8702 pango_cairo_context_set_resolution (context,
8703 gdk_screen_get_resolution (screen));
8704 pango_cairo_context_set_font_options (context,
8705 gdk_screen_get_font_options (screen));
8711 * gtk_widget_create_pango_context:
8712 * @widget: a #GtkWidget
8714 * Creates a new #PangoContext with the appropriate font map,
8715 * font description, and base direction for drawing text for
8716 * this widget. See also gtk_widget_get_pango_context().
8718 * Return value: (transfer full): the new #PangoContext
8721 gtk_widget_create_pango_context (GtkWidget *widget)
8724 PangoContext *context;
8726 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8728 screen = gtk_widget_get_screen_unchecked (widget);
8731 GTK_NOTE (MULTIHEAD,
8732 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8734 screen = gdk_screen_get_default ();
8737 context = gdk_pango_context_get_for_screen (screen);
8739 update_pango_context (widget, context);
8740 pango_context_set_language (context, gtk_get_default_language ());
8746 * gtk_widget_create_pango_layout:
8747 * @widget: a #GtkWidget
8748 * @text: text to set on the layout (can be %NULL)
8750 * Creates a new #PangoLayout with the appropriate font map,
8751 * font description, and base direction for drawing text for
8754 * If you keep a #PangoLayout created in this way around, in order to
8755 * notify the layout of changes to the base direction or font of this
8756 * widget, you must call pango_layout_context_changed() in response to
8757 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8760 * Return value: (transfer full): the new #PangoLayout
8763 gtk_widget_create_pango_layout (GtkWidget *widget,
8766 PangoLayout *layout;
8767 PangoContext *context;
8769 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8771 context = gtk_widget_get_pango_context (widget);
8772 layout = pango_layout_new (context);
8775 pango_layout_set_text (layout, text, -1);
8781 * gtk_widget_render_icon:
8782 * @widget: a #GtkWidget
8783 * @stock_id: a stock ID
8784 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8785 * render at the size of the source and don't scale (if there are
8786 * multiple source sizes, GTK+ picks one of the available sizes).
8787 * @detail: (allow-none): render detail to pass to theme engine
8789 * A convenience function that uses the theme engine and RC file
8790 * settings for @widget to look up @stock_id and render it to
8791 * a pixbuf. @stock_id should be a stock icon ID such as
8792 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8793 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8794 * identifies the widget or code doing the rendering, so that
8795 * theme engines can special-case rendering for that widget or code.
8797 * The pixels in the returned #GdkPixbuf are shared with the rest of
8798 * the application and should not be modified. The pixbuf should be freed
8799 * after use with g_object_unref().
8801 * Return value: (transfer full): a new pixbuf, or %NULL if the
8802 * stock ID wasn't known
8805 gtk_widget_render_icon (GtkWidget *widget,
8806 const gchar *stock_id,
8808 const gchar *detail)
8810 GtkWidgetPrivate *priv;
8811 GtkIconSet *icon_set;
8814 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8815 g_return_val_if_fail (stock_id != NULL, NULL);
8816 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8818 priv = widget->priv;
8820 gtk_widget_ensure_style (widget);
8822 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8824 if (icon_set == NULL)
8827 retval = gtk_icon_set_render_icon (icon_set,
8829 gtk_widget_get_direction (widget),
8830 gtk_widget_get_state (widget),
8839 * gtk_widget_set_parent_window:
8840 * @widget: a #GtkWidget.
8841 * @parent_window: the new parent window.
8843 * Sets a non default parent window for @widget.
8846 gtk_widget_set_parent_window (GtkWidget *widget,
8847 GdkWindow *parent_window)
8849 GdkWindow *old_parent_window;
8851 g_return_if_fail (GTK_IS_WIDGET (widget));
8853 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8854 quark_parent_window);
8856 if (parent_window != old_parent_window)
8858 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8860 if (old_parent_window)
8861 g_object_unref (old_parent_window);
8863 g_object_ref (parent_window);
8868 * gtk_widget_get_parent_window:
8869 * @widget: a #GtkWidget.
8871 * Gets @widget's parent window.
8873 * Returns: (transfer none): the parent window of @widget.
8876 gtk_widget_get_parent_window (GtkWidget *widget)
8878 GtkWidgetPrivate *priv;
8879 GdkWindow *parent_window;
8881 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8883 priv = widget->priv;
8885 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8887 return (parent_window != NULL) ? parent_window :
8888 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8893 * gtk_widget_set_child_visible:
8894 * @widget: a #GtkWidget
8895 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8897 * Sets whether @widget should be mapped along with its when its parent
8898 * is mapped and @widget has been shown with gtk_widget_show().
8900 * The child visibility can be set for widget before it is added to
8901 * a container with gtk_widget_set_parent(), to avoid mapping
8902 * children unnecessary before immediately unmapping them. However
8903 * it will be reset to its default state of %TRUE when the widget
8904 * is removed from a container.
8906 * Note that changing the child visibility of a widget does not
8907 * queue a resize on the widget. Most of the time, the size of
8908 * a widget is computed from all visible children, whether or
8909 * not they are mapped. If this is not the case, the container
8910 * can queue a resize itself.
8912 * This function is only useful for container implementations and
8913 * never should be called by an application.
8916 gtk_widget_set_child_visible (GtkWidget *widget,
8917 gboolean is_visible)
8919 GtkWidgetPrivate *priv;
8921 g_return_if_fail (GTK_IS_WIDGET (widget));
8922 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8924 priv = widget->priv;
8926 g_object_ref (widget);
8929 priv->child_visible = TRUE;
8932 GtkWidget *toplevel;
8934 priv->child_visible = FALSE;
8936 toplevel = gtk_widget_get_toplevel (widget);
8937 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8938 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8941 if (priv->parent && gtk_widget_get_realized (priv->parent))
8943 if (gtk_widget_get_mapped (priv->parent) &&
8944 priv->child_visible &&
8945 gtk_widget_get_visible (widget))
8946 gtk_widget_map (widget);
8948 gtk_widget_unmap (widget);
8951 g_object_unref (widget);
8955 * gtk_widget_get_child_visible:
8956 * @widget: a #GtkWidget
8958 * Gets the value set with gtk_widget_set_child_visible().
8959 * If you feel a need to use this function, your code probably
8960 * needs reorganization.
8962 * This function is only useful for container implementations and
8963 * never should be called by an application.
8965 * Return value: %TRUE if the widget is mapped with the parent.
8968 gtk_widget_get_child_visible (GtkWidget *widget)
8970 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8972 return widget->priv->child_visible;
8976 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8978 GtkWidget *toplevel;
8980 toplevel = gtk_widget_get_toplevel (widget);
8982 if (gtk_widget_is_toplevel (toplevel))
8984 if (GTK_IS_WINDOW (toplevel))
8985 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8986 else if (GTK_IS_INVISIBLE (toplevel))
8987 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8994 * gtk_widget_get_screen:
8995 * @widget: a #GtkWidget
8997 * Get the #GdkScreen from the toplevel window associated with
8998 * this widget. This function can only be called after the widget
8999 * has been added to a widget hierarchy with a #GtkWindow
9002 * In general, you should only create screen specific
9003 * resources when a widget has been realized, and you should
9004 * free those resources when the widget is unrealized.
9006 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
9011 gtk_widget_get_screen (GtkWidget *widget)
9015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9017 screen = gtk_widget_get_screen_unchecked (widget);
9024 g_warning (G_STRLOC ": Can't get associated screen"
9025 " for a widget unless it is inside a toplevel GtkWindow\n"
9026 " widget type is %s associated top level type is %s",
9027 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
9028 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
9030 return gdk_screen_get_default ();
9035 * gtk_widget_has_screen:
9036 * @widget: a #GtkWidget
9038 * Checks whether there is a #GdkScreen is associated with
9039 * this widget. All toplevel widgets have an associated
9040 * screen, and all widgets added into a hierarchy with a toplevel
9041 * window at the top.
9043 * Return value: %TRUE if there is a #GdkScreen associcated
9049 gtk_widget_has_screen (GtkWidget *widget)
9051 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9053 return (gtk_widget_get_screen_unchecked (widget) != NULL);
9057 * gtk_widget_get_display:
9058 * @widget: a #GtkWidget
9060 * Get the #GdkDisplay for the toplevel window associated with
9061 * this widget. This function can only be called after the widget
9062 * has been added to a widget hierarchy with a #GtkWindow at the top.
9064 * In general, you should only create display specific
9065 * resources when a widget has been realized, and you should
9066 * free those resources when the widget is unrealized.
9068 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
9073 gtk_widget_get_display (GtkWidget *widget)
9075 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9077 return gdk_screen_get_display (gtk_widget_get_screen (widget));
9081 * gtk_widget_get_root_window:
9082 * @widget: a #GtkWidget
9084 * Get the root window where this widget is located. This function can
9085 * only be called after the widget has been added to a widget
9086 * hierarchy with #GtkWindow at the top.
9088 * The root window is useful for such purposes as creating a popup
9089 * #GdkWindow associated with the window. In general, you should only
9090 * create display specific resources when a widget has been realized,
9091 * and you should free those resources when the widget is unrealized.
9093 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
9098 gtk_widget_get_root_window (GtkWidget *widget)
9100 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9102 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
9106 * gtk_widget_child_focus:
9107 * @widget: a #GtkWidget
9108 * @direction: direction of focus movement
9110 * This function is used by custom widget implementations; if you're
9111 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
9112 * to a particular widget, and gtk_container_set_focus_chain() to
9113 * change the focus tab order. So you may want to investigate those
9114 * functions instead.
9116 * gtk_widget_child_focus() is called by containers as the user moves
9117 * around the window using keyboard shortcuts. @direction indicates
9118 * what kind of motion is taking place (up, down, left, right, tab
9119 * forward, tab backward). gtk_widget_child_focus() emits the
9120 * #GtkWidget::focus signal; widgets override the default handler
9121 * for this signal in order to implement appropriate focus behavior.
9123 * The default ::focus handler for a widget should return %TRUE if
9124 * moving in @direction left the focus on a focusable location inside
9125 * that widget, and %FALSE if moving in @direction moved the focus
9126 * outside the widget. If returning %TRUE, widgets normally
9127 * call gtk_widget_grab_focus() to place the focus accordingly;
9128 * if returning %FALSE, they don't modify the current focus location.
9130 * Return value: %TRUE if focus ended up inside @widget
9133 gtk_widget_child_focus (GtkWidget *widget,
9134 GtkDirectionType direction)
9136 gboolean return_val;
9138 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9140 if (!gtk_widget_get_visible (widget) ||
9141 !gtk_widget_is_sensitive (widget))
9144 /* child widgets must set CAN_FOCUS, containers
9145 * don't have to though.
9147 if (!GTK_IS_CONTAINER (widget) &&
9148 !gtk_widget_get_can_focus (widget))
9151 g_signal_emit (widget,
9152 widget_signals[FOCUS],
9154 direction, &return_val);
9160 * gtk_widget_keynav_failed:
9161 * @widget: a #GtkWidget
9162 * @direction: direction of focus movement
9164 * This function should be called whenever keyboard navigation within
9165 * a single widget hits a boundary. The function emits the
9166 * #GtkWidget::keynav-failed signal on the widget and its return
9167 * value should be interpreted in a way similar to the return value of
9168 * gtk_widget_child_focus():
9170 * When %TRUE is returned, stay in the widget, the failed keyboard
9171 * navigation is Ok and/or there is nowhere we can/should move the
9174 * When %FALSE is returned, the caller should continue with keyboard
9175 * navigation outside the widget, e.g. by calling
9176 * gtk_widget_child_focus() on the widget's toplevel.
9178 * The default ::keynav-failed handler returns %TRUE for
9179 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
9180 * values of #GtkDirectionType, it looks at the
9181 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
9182 * if the setting is %TRUE. This way the entire user interface
9183 * becomes cursor-navigatable on input devices such as mobile phones
9184 * which only have cursor keys but no tab key.
9186 * Whenever the default handler returns %TRUE, it also calls
9187 * gtk_widget_error_bell() to notify the user of the failed keyboard
9190 * A use case for providing an own implementation of ::keynav-failed
9191 * (either by connecting to it or by overriding it) would be a row of
9192 * #GtkEntry widgets where the user should be able to navigate the
9193 * entire row with the cursor keys, as e.g. known from user interfaces
9194 * that require entering license keys.
9196 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
9197 * if the emitting widget should try to handle the keyboard
9198 * navigation attempt in its parent container(s).
9203 gtk_widget_keynav_failed (GtkWidget *widget,
9204 GtkDirectionType direction)
9206 gboolean return_val;
9208 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9210 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
9211 direction, &return_val);
9217 * gtk_widget_error_bell:
9218 * @widget: a #GtkWidget
9220 * Notifies the user about an input-related error on this widget.
9221 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
9222 * gdk_window_beep(), otherwise it does nothing.
9224 * Note that the effect of gdk_window_beep() can be configured in many
9225 * ways, depending on the windowing backend and the desktop environment
9226 * or window manager that is used.
9231 gtk_widget_error_bell (GtkWidget *widget)
9233 GtkWidgetPrivate *priv;
9234 GtkSettings* settings;
9237 g_return_if_fail (GTK_IS_WIDGET (widget));
9239 priv = widget->priv;
9241 settings = gtk_widget_get_settings (widget);
9245 g_object_get (settings,
9246 "gtk-error-bell", &beep,
9249 if (beep && priv->window)
9250 gdk_window_beep (priv->window);
9254 gtk_widget_set_usize_internal (GtkWidget *widget,
9257 GtkQueueResizeFlags flags)
9259 GtkWidgetAuxInfo *aux_info;
9260 gboolean changed = FALSE;
9262 g_object_freeze_notify (G_OBJECT (widget));
9264 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
9266 if (width > -2 && aux_info->width != width)
9268 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9269 g_object_notify (G_OBJECT (widget), "width-request");
9270 aux_info->width = width;
9273 if (height > -2 && aux_info->height != height)
9275 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9276 g_object_notify (G_OBJECT (widget), "height-request");
9277 aux_info->height = height;
9281 if (gtk_widget_get_visible (widget) && changed)
9283 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
9284 gtk_widget_queue_resize (widget);
9286 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9289 g_object_thaw_notify (G_OBJECT (widget));
9293 * gtk_widget_set_size_request:
9294 * @widget: a #GtkWidget
9295 * @width: width @widget should request, or -1 to unset
9296 * @height: height @widget should request, or -1 to unset
9298 * Sets the minimum size of a widget; that is, the widget's size
9299 * request will be @width by @height. You can use this function to
9300 * force a widget to be either larger or smaller than it normally
9303 * In most cases, gtk_window_set_default_size() is a better choice for
9304 * toplevel windows than this function; setting the default size will
9305 * still allow users to shrink the window. Setting the size request
9306 * will force them to leave the window at least as large as the size
9307 * request. When dealing with window sizes,
9308 * gtk_window_set_geometry_hints() can be a useful function as well.
9310 * Note the inherent danger of setting any fixed size - themes,
9311 * translations into other languages, different fonts, and user action
9312 * can all change the appropriate size for a given widget. So, it's
9313 * basically impossible to hardcode a size that will always be
9316 * The size request of a widget is the smallest size a widget can
9317 * accept while still functioning well and drawing itself correctly.
9318 * However in some strange cases a widget may be allocated less than
9319 * its requested size, and in many cases a widget may be allocated more
9320 * space than it requested.
9322 * If the size request in a given direction is -1 (unset), then
9323 * the "natural" size request of the widget will be used instead.
9325 * Widgets can't actually be allocated a size less than 1 by 1, but
9326 * you can pass 0,0 to this function to mean "as small as possible."
9328 * The size request set here does not include any margin from the
9329 * #GtkWidget properties margin-left, margin-right, margin-top, and
9330 * margin-bottom, but it does include pretty much all other padding
9331 * or border properties set by any subclass of #GtkWidget.
9334 gtk_widget_set_size_request (GtkWidget *widget,
9338 g_return_if_fail (GTK_IS_WIDGET (widget));
9339 g_return_if_fail (width >= -1);
9340 g_return_if_fail (height >= -1);
9347 gtk_widget_set_usize_internal (widget, width, height, 0);
9352 * gtk_widget_get_size_request:
9353 * @widget: a #GtkWidget
9354 * @width: (out) (allow-none): return location for width, or %NULL
9355 * @height: (out) (allow-none): return location for height, or %NULL
9357 * Gets the size request that was explicitly set for the widget using
9358 * gtk_widget_set_size_request(). A value of -1 stored in @width or
9359 * @height indicates that that dimension has not been set explicitly
9360 * and the natural requisition of the widget will be used intead. See
9361 * gtk_widget_set_size_request(). To get the size a widget will
9362 * actually request, call gtk_widget_get_preferred_size() instead of
9366 gtk_widget_get_size_request (GtkWidget *widget,
9370 const GtkWidgetAuxInfo *aux_info;
9372 g_return_if_fail (GTK_IS_WIDGET (widget));
9374 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
9377 *width = aux_info->width;
9380 *height = aux_info->height;
9384 * _gtk_widget_override_size_request:
9385 * @widget: a #GtkWidget
9386 * @width: new forced minimum width
9387 * @height: new forced minimum height
9388 * @old_width: location to store previous forced minimum width
9389 * @old_width: location to store previous forced minumum height
9391 * Temporarily establishes a forced minimum size for a widget; this
9392 * is used by GtkWindow when calculating the size to add to the
9393 * window's geometry widget. Cached sizes for the widget and its
9394 * parents are invalidated, so that subsequent calls to the size
9395 * negotiation machinery produce the overriden result, but the
9396 * widget is not queued for relayout or redraw. The old size must
9397 * be restored with _gtk_widget_restore_size_request() or things
9401 _gtk_widget_override_size_request (GtkWidget *widget,
9407 gtk_widget_get_size_request (widget, old_width, old_height);
9408 gtk_widget_set_usize_internal (widget, width, height,
9409 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9413 * _gtk_widget_restore_size_request:
9414 * @widget: a #GtkWidget
9415 * @old_width: saved forced minimum size
9416 * @old_height: saved forced minimum size
9418 * Undoes the operation of_gtk_widget_override_size_request().
9421 _gtk_widget_restore_size_request (GtkWidget *widget,
9425 gtk_widget_set_usize_internal (widget, old_width, old_height,
9426 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
9430 * gtk_widget_set_events:
9431 * @widget: a #GtkWidget
9432 * @events: event mask
9434 * Sets the event mask (see #GdkEventMask) for a widget. The event
9435 * mask determines which events a widget will receive. Keep in mind
9436 * that different widgets have different default event masks, and by
9437 * changing the event mask you may disrupt a widget's functionality,
9438 * so be careful. This function must be called while a widget is
9439 * unrealized. Consider gtk_widget_add_events() for widgets that are
9440 * already realized, or if you want to preserve the existing event
9441 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9442 * to get events on those widgets, place them inside a #GtkEventBox
9443 * and receive events on the event box.
9446 gtk_widget_set_events (GtkWidget *widget,
9449 g_return_if_fail (GTK_IS_WIDGET (widget));
9450 g_return_if_fail (!gtk_widget_get_realized (widget));
9452 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9453 GINT_TO_POINTER (events));
9454 g_object_notify (G_OBJECT (widget), "events");
9458 * gtk_widget_set_device_events:
9459 * @widget: a #GtkWidget
9460 * @device: a #GdkDevice
9461 * @events: event mask
9463 * Sets the device event mask (see #GdkEventMask) for a widget. The event
9464 * mask determines which events a widget will receive from @device. Keep
9465 * in mind that different widgets have different default event masks, and by
9466 * changing the event mask you may disrupt a widget's functionality,
9467 * so be careful. This function must be called while a widget is
9468 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
9469 * already realized, or if you want to preserve the existing event
9470 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9471 * to get events on those widgets, place them inside a #GtkEventBox
9472 * and receive events on the event box.
9477 gtk_widget_set_device_events (GtkWidget *widget,
9479 GdkEventMask events)
9481 GHashTable *device_events;
9483 g_return_if_fail (GTK_IS_WIDGET (widget));
9484 g_return_if_fail (GDK_IS_DEVICE (device));
9485 g_return_if_fail (!gtk_widget_get_realized (widget));
9487 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9489 if (G_UNLIKELY (!device_events))
9491 device_events = g_hash_table_new (NULL, NULL);
9492 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9493 (GDestroyNotify) g_hash_table_unref);
9496 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9500 gtk_widget_add_events_internal_list (GtkWidget *widget,
9507 for (l = window_list; l != NULL; l = l->next)
9509 GdkWindow *window = l->data;
9512 gdk_window_get_user_data (window, &user_data);
9513 if (user_data == widget)
9518 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9520 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9522 children = gdk_window_get_children (window);
9523 gtk_widget_add_events_internal_list (widget, device, events, children);
9524 g_list_free (children);
9530 gtk_widget_add_events_internal (GtkWidget *widget,
9534 GtkWidgetPrivate *priv = widget->priv;
9537 if (!gtk_widget_get_has_window (widget))
9538 window_list = gdk_window_get_children (priv->window);
9540 window_list = g_list_prepend (NULL, priv->window);
9542 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9544 g_list_free (window_list);
9548 * gtk_widget_add_events:
9549 * @widget: a #GtkWidget
9550 * @events: an event mask, see #GdkEventMask
9552 * Adds the events in the bitfield @events to the event mask for
9553 * @widget. See gtk_widget_set_events() for details.
9556 gtk_widget_add_events (GtkWidget *widget,
9561 g_return_if_fail (GTK_IS_WIDGET (widget));
9563 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9564 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9565 GINT_TO_POINTER (old_events | events));
9567 if (gtk_widget_get_realized (widget))
9568 gtk_widget_add_events_internal (widget, NULL, events);
9570 g_object_notify (G_OBJECT (widget), "events");
9574 * gtk_widget_add_device_events:
9575 * @widget: a #GtkWidget
9576 * @device: a #GdkDevice
9577 * @events: an event mask, see #GdkEventMask
9579 * Adds the device events in the bitfield @events to the event mask for
9580 * @widget. See gtk_widget_set_device_events() for details.
9585 gtk_widget_add_device_events (GtkWidget *widget,
9587 GdkEventMask events)
9589 GdkEventMask old_events;
9590 GHashTable *device_events;
9592 g_return_if_fail (GTK_IS_WIDGET (widget));
9593 g_return_if_fail (GDK_IS_DEVICE (device));
9595 old_events = gtk_widget_get_device_events (widget, device);
9597 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9599 if (G_UNLIKELY (!device_events))
9601 device_events = g_hash_table_new (NULL, NULL);
9602 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9603 (GDestroyNotify) g_hash_table_unref);
9606 g_hash_table_insert (device_events, device,
9607 GUINT_TO_POINTER (old_events | events));
9609 if (gtk_widget_get_realized (widget))
9610 gtk_widget_add_events_internal (widget, device, events);
9612 g_object_notify (G_OBJECT (widget), "events");
9616 * gtk_widget_set_extension_events:
9617 * @widget: a #GtkWidget
9618 * @mode: bitfield of extension events to receive
9620 * Sets the extension events mask to @mode. See #GdkExtensionMode
9621 * and gdk_input_set_extension_events().
9624 gtk_widget_set_extension_events (GtkWidget *widget,
9625 GdkExtensionMode mode)
9627 g_return_if_fail (GTK_IS_WIDGET (widget));
9629 if (gtk_widget_get_realized (widget))
9630 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9632 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9633 GINT_TO_POINTER (mode));
9634 g_object_notify (G_OBJECT (widget), "extension-events");
9638 * gtk_widget_get_toplevel:
9639 * @widget: a #GtkWidget
9641 * This function returns the topmost widget in the container hierarchy
9642 * @widget is a part of. If @widget has no parent widgets, it will be
9643 * returned as the topmost widget. No reference will be added to the
9644 * returned widget; it should not be unreferenced.
9646 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9647 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9649 * %NULL if @widget wasn't inside a toplevel window, and if the
9650 * window was inside a #GtkWindow-derived widget which was in turn
9651 * inside the toplevel #GtkWindow. While the second case may
9652 * seem unlikely, it actually happens when a #GtkPlug is embedded
9653 * inside a #GtkSocket within the same application.
9655 * To reliably find the toplevel #GtkWindow, use
9656 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9657 * is set on the result.
9659 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9660 * if (gtk_widget_is_toplevel (toplevel))
9662 * /* Perform action on toplevel. */
9666 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9667 * if there's no ancestor.
9670 gtk_widget_get_toplevel (GtkWidget *widget)
9672 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9674 while (widget->priv->parent)
9675 widget = widget->priv->parent;
9681 * gtk_widget_get_ancestor:
9682 * @widget: a #GtkWidget
9683 * @widget_type: ancestor type
9685 * Gets the first ancestor of @widget with type @widget_type. For example,
9686 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9687 * the first #GtkBox that's an ancestor of @widget. No reference will be
9688 * added to the returned widget; it should not be unreferenced. See note
9689 * about checking for a toplevel #GtkWindow in the docs for
9690 * gtk_widget_get_toplevel().
9692 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9693 * considers @widget to be an ancestor of itself.
9695 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9698 gtk_widget_get_ancestor (GtkWidget *widget,
9701 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9703 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9704 widget = widget->priv->parent;
9706 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9713 * gtk_widget_set_visual:
9714 * @widget: a #GtkWidget
9715 * @visual: visual to be used or %NULL to unset a previous one
9717 * Sets the visual that should be used for by widget and its children for
9718 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9719 * returned by gdk_widget_get_screen(), so handling the
9720 * #GtkWidget::screen-changed signal is necessary.
9722 * Setting a new @visual will not cause @widget to recreate its windows,
9723 * so you should call this function before @widget is realized.
9726 gtk_widget_set_visual (GtkWidget *widget,
9729 g_return_if_fail (GTK_IS_WIDGET (widget));
9730 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9733 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9736 g_object_set_qdata_full (G_OBJECT (widget),
9738 g_object_ref (visual),
9743 * gtk_widget_get_visual:
9744 * @widget: a #GtkWidget
9746 * Gets the visual that will be used to render @widget.
9748 * Return value: (transfer none): the visual for @widget
9751 gtk_widget_get_visual (GtkWidget *widget)
9757 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9759 if (gtk_widget_get_has_window (widget) &&
9760 widget->priv->window)
9761 return gdk_window_get_visual (widget->priv->window);
9763 screen = gtk_widget_get_screen (widget);
9765 for (w = widget; w != NULL; w = w->priv->parent)
9767 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9770 if (gdk_visual_get_screen (visual) == screen)
9773 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9774 gtk_widget_get_name (widget));
9778 return gdk_screen_get_system_visual (screen);
9782 * gtk_widget_get_settings:
9783 * @widget: a #GtkWidget
9785 * Gets the settings object holding the settings (global property
9786 * settings, RC file information, etc) used for this widget.
9788 * Note that this function can only be called when the #GtkWidget
9789 * is attached to a toplevel, since the settings object is specific
9790 * to a particular #GdkScreen.
9792 * Return value: (transfer none): the relevant #GtkSettings object
9795 gtk_widget_get_settings (GtkWidget *widget)
9797 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9799 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9803 * gtk_widget_get_events:
9804 * @widget: a #GtkWidget
9806 * Returns the event mask for the widget (a bitfield containing flags
9807 * from the #GdkEventMask enumeration). These are the events that the widget
9810 * Return value: event mask for @widget
9813 gtk_widget_get_events (GtkWidget *widget)
9815 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9817 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9821 * gtk_widget_get_device_events:
9822 * @widget: a #GtkWidget
9823 * @device: a #GdkDevice
9825 * Returns the events mask for the widget corresponding to an specific device. These
9826 * are the events that the widget will receive when @device operates on it.
9828 * Returns: device event mask for @widget
9833 gtk_widget_get_device_events (GtkWidget *widget,
9836 GHashTable *device_events;
9838 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9839 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9841 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9846 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9850 * gtk_widget_get_extension_events:
9851 * @widget: a #GtkWidget
9853 * Retrieves the extension events the widget will receive; see
9854 * gdk_input_set_extension_events().
9856 * Return value: extension events for @widget
9859 gtk_widget_get_extension_events (GtkWidget *widget)
9861 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9863 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9867 * gtk_widget_get_pointer:
9868 * @widget: a #GtkWidget
9869 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9870 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9872 * Obtains the location of the mouse pointer in widget coordinates.
9873 * Widget coordinates are a bit odd; for historical reasons, they are
9874 * defined as @widget->window coordinates for widgets that are not
9875 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9876 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9879 gtk_widget_get_pointer (GtkWidget *widget,
9883 GtkWidgetPrivate *priv;
9885 g_return_if_fail (GTK_IS_WIDGET (widget));
9887 priv = widget->priv;
9894 if (gtk_widget_get_realized (widget))
9896 gdk_window_get_pointer (priv->window, x, y, NULL);
9898 if (!gtk_widget_get_has_window (widget))
9901 *x -= priv->allocation.x;
9903 *y -= priv->allocation.y;
9909 * gtk_widget_is_ancestor:
9910 * @widget: a #GtkWidget
9911 * @ancestor: another #GtkWidget
9913 * Determines whether @widget is somewhere inside @ancestor, possibly with
9914 * intermediate containers.
9916 * Return value: %TRUE if @ancestor contains @widget as a child,
9917 * grandchild, great grandchild, etc.
9920 gtk_widget_is_ancestor (GtkWidget *widget,
9921 GtkWidget *ancestor)
9923 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9924 g_return_val_if_fail (ancestor != NULL, FALSE);
9928 if (widget->priv->parent == ancestor)
9930 widget = widget->priv->parent;
9936 static GQuark quark_composite_name = 0;
9939 * gtk_widget_set_composite_name:
9940 * @widget: a #GtkWidget.
9941 * @name: the name to set
9943 * Sets a widgets composite name. The widget must be
9944 * a composite child of its parent; see gtk_widget_push_composite_child().
9947 gtk_widget_set_composite_name (GtkWidget *widget,
9950 g_return_if_fail (GTK_IS_WIDGET (widget));
9951 g_return_if_fail (widget->priv->composite_child);
9952 g_return_if_fail (name != NULL);
9954 if (!quark_composite_name)
9955 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9957 g_object_set_qdata_full (G_OBJECT (widget),
9958 quark_composite_name,
9964 * gtk_widget_get_composite_name:
9965 * @widget: a #GtkWidget
9967 * Obtains the composite name of a widget.
9969 * Returns: the composite name of @widget, or %NULL if @widget is not
9970 * a composite child. The string should be freed when it is no
9974 gtk_widget_get_composite_name (GtkWidget *widget)
9976 GtkWidgetPrivate *priv;
9978 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9980 priv = widget->priv;
9982 if (widget->priv->composite_child && priv->parent)
9983 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9990 * gtk_widget_push_composite_child:
9992 * Makes all newly-created widgets as composite children until
9993 * the corresponding gtk_widget_pop_composite_child() call.
9995 * A composite child is a child that's an implementation detail of the
9996 * container it's inside and should not be visible to people using the
9997 * container. Composite children aren't treated differently by GTK (but
9998 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9999 * builders might want to treat them in a different way.
10001 * Here is a simple example:
10003 * gtk_widget_push_composite_child ();
10004 * scrolled_window->hscrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
10005 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
10006 * gtk_widget_pop_composite_child ();
10007 * gtk_widget_set_parent (scrolled_window->hscrollbar,
10008 * GTK_WIDGET (scrolled_window));
10009 * g_object_ref (scrolled_window->hscrollbar);
10013 gtk_widget_push_composite_child (void)
10015 composite_child_stack++;
10019 * gtk_widget_pop_composite_child:
10021 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
10024 gtk_widget_pop_composite_child (void)
10026 if (composite_child_stack)
10027 composite_child_stack--;
10031 gtk_widget_emit_direction_changed (GtkWidget *widget,
10032 GtkTextDirection old_dir)
10034 gtk_widget_update_pango_context (widget);
10036 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
10040 * gtk_widget_set_direction:
10041 * @widget: a #GtkWidget
10042 * @dir: the new direction
10044 * Sets the reading direction on a particular widget. This direction
10045 * controls the primary direction for widgets containing text,
10046 * and also the direction in which the children of a container are
10047 * packed. The ability to set the direction is present in order
10048 * so that correct localization into languages with right-to-left
10049 * reading directions can be done. Generally, applications will
10050 * let the default reading direction present, except for containers
10051 * where the containers are arranged in an order that is explicitely
10052 * visual rather than logical (such as buttons for text justification).
10054 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
10055 * set by gtk_widget_set_default_direction() will be used.
10058 gtk_widget_set_direction (GtkWidget *widget,
10059 GtkTextDirection dir)
10061 GtkTextDirection old_dir;
10063 g_return_if_fail (GTK_IS_WIDGET (widget));
10064 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
10066 old_dir = gtk_widget_get_direction (widget);
10068 widget->priv->direction = dir;
10070 if (old_dir != gtk_widget_get_direction (widget))
10072 if (widget->priv->context)
10073 gtk_style_context_set_direction (widget->priv->context,
10074 gtk_widget_get_direction (widget));
10076 gtk_widget_emit_direction_changed (widget, old_dir);
10081 * gtk_widget_get_direction:
10082 * @widget: a #GtkWidget
10084 * Gets the reading direction for a particular widget. See
10085 * gtk_widget_set_direction().
10087 * Return value: the reading direction for the widget.
10090 gtk_widget_get_direction (GtkWidget *widget)
10092 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
10094 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10095 return gtk_default_direction;
10097 return widget->priv->direction;
10101 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
10103 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
10105 g_object_ref (widget);
10107 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
10108 gtk_widget_emit_direction_changed (widget, old_dir);
10110 if (GTK_IS_CONTAINER (widget))
10111 gtk_container_forall (GTK_CONTAINER (widget),
10112 gtk_widget_set_default_direction_recurse,
10115 g_object_unref (widget);
10119 * gtk_widget_set_default_direction:
10120 * @dir: the new default direction. This cannot be
10121 * %GTK_TEXT_DIR_NONE.
10123 * Sets the default reading direction for widgets where the
10124 * direction has not been explicitly set by gtk_widget_set_direction().
10127 gtk_widget_set_default_direction (GtkTextDirection dir)
10129 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
10131 if (dir != gtk_default_direction)
10133 GList *toplevels, *tmp_list;
10134 GtkTextDirection old_dir = gtk_default_direction;
10136 gtk_default_direction = dir;
10138 tmp_list = toplevels = gtk_window_list_toplevels ();
10139 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
10143 gtk_widget_set_default_direction_recurse (tmp_list->data,
10144 GUINT_TO_POINTER (old_dir));
10145 g_object_unref (tmp_list->data);
10146 tmp_list = tmp_list->next;
10149 g_list_free (toplevels);
10154 * gtk_widget_get_default_direction:
10156 * Obtains the current default reading direction. See
10157 * gtk_widget_set_default_direction().
10159 * Return value: the current default direction.
10162 gtk_widget_get_default_direction (void)
10164 return gtk_default_direction;
10168 gtk_widget_dispose (GObject *object)
10170 GtkWidget *widget = GTK_WIDGET (object);
10171 GtkWidgetPrivate *priv = widget->priv;
10174 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
10175 else if (gtk_widget_get_visible (widget))
10176 gtk_widget_hide (widget);
10178 priv->visible = FALSE;
10179 if (gtk_widget_get_realized (widget))
10180 gtk_widget_unrealize (widget);
10182 if (!priv->in_destruction)
10184 priv->in_destruction = TRUE;
10185 g_signal_emit (object, widget_signals[DESTROY], 0);
10186 priv->in_destruction = FALSE;
10189 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
10193 gtk_widget_real_destroy (GtkWidget *object)
10195 /* gtk_object_destroy() will already hold a refcount on object */
10196 GtkWidget *widget = GTK_WIDGET (object);
10197 GtkWidgetPrivate *priv = widget->priv;
10199 /* wipe accelerator closures (keep order) */
10200 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
10201 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
10203 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
10204 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
10206 gtk_grab_remove (widget);
10208 g_object_unref (priv->style);
10209 priv->style = gtk_widget_get_default_style ();
10210 g_object_ref (priv->style);
10214 gtk_widget_finalize (GObject *object)
10216 GtkWidget *widget = GTK_WIDGET (object);
10217 GtkWidgetPrivate *priv = widget->priv;
10218 GtkWidgetAuxInfo *aux_info;
10219 GtkAccessible *accessible;
10221 gtk_grab_remove (widget);
10223 g_object_unref (priv->style);
10224 priv->style = NULL;
10226 g_free (priv->name);
10228 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
10230 gtk_widget_aux_info_destroy (aux_info);
10232 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
10234 g_object_unref (accessible);
10237 gtk_widget_path_free (priv->path);
10240 g_object_unref (priv->context);
10242 if (g_object_is_floating (object))
10243 g_warning ("A floating object was finalized. This means that someone\n"
10244 "called g_object_unref() on an object that had only a floating\n"
10245 "reference; the initial floating reference is not owned by anyone\n"
10246 "and must be removed with g_object_ref_sink().");
10248 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
10251 /*****************************************
10252 * gtk_widget_real_map:
10257 *****************************************/
10260 gtk_widget_real_map (GtkWidget *widget)
10262 GtkWidgetPrivate *priv = widget->priv;
10264 g_assert (gtk_widget_get_realized (widget));
10266 if (!gtk_widget_get_mapped (widget))
10268 gtk_widget_set_mapped (widget, TRUE);
10270 if (gtk_widget_get_has_window (widget))
10271 gdk_window_show (priv->window);
10275 /*****************************************
10276 * gtk_widget_real_unmap:
10281 *****************************************/
10284 gtk_widget_real_unmap (GtkWidget *widget)
10286 GtkWidgetPrivate *priv = widget->priv;
10288 if (gtk_widget_get_mapped (widget))
10290 gtk_widget_set_mapped (widget, FALSE);
10292 if (gtk_widget_get_has_window (widget))
10293 gdk_window_hide (priv->window);
10297 /*****************************************
10298 * gtk_widget_real_realize:
10303 *****************************************/
10306 gtk_widget_real_realize (GtkWidget *widget)
10308 GtkWidgetPrivate *priv = widget->priv;
10310 g_assert (!gtk_widget_get_has_window (widget));
10312 gtk_widget_set_realized (widget, TRUE);
10315 priv->window = gtk_widget_get_parent_window (widget);
10316 g_object_ref (priv->window);
10318 priv->style = gtk_style_attach (priv->style, priv->window);
10321 /*****************************************
10322 * gtk_widget_real_unrealize:
10327 *****************************************/
10330 gtk_widget_real_unrealize (GtkWidget *widget)
10332 GtkWidgetPrivate *priv = widget->priv;
10334 if (gtk_widget_get_mapped (widget))
10335 gtk_widget_real_unmap (widget);
10337 gtk_widget_set_mapped (widget, FALSE);
10339 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
10342 /* We must do unrealize child widget BEFORE container widget.
10343 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
10344 * So, unrealizing container widget bofore its children causes the problem
10345 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
10348 if (GTK_IS_CONTAINER (widget))
10349 gtk_container_forall (GTK_CONTAINER (widget),
10350 (GtkCallback) gtk_widget_unrealize,
10353 gtk_style_detach (priv->style);
10354 if (gtk_widget_get_has_window (widget))
10356 gdk_window_set_user_data (priv->window, NULL);
10357 gdk_window_destroy (priv->window);
10358 priv->window = NULL;
10362 g_object_unref (priv->window);
10363 priv->window = NULL;
10366 gtk_selection_remove_all (widget);
10368 gtk_widget_set_realized (widget, FALSE);
10372 gtk_widget_real_adjust_size_request (GtkWidget *widget,
10373 GtkOrientation orientation,
10374 gint *minimum_size,
10375 gint *natural_size)
10377 const GtkWidgetAuxInfo *aux_info;
10379 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
10381 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
10382 aux_info->width > 0)
10384 *minimum_size = MAX (*minimum_size, aux_info->width);
10386 else if (orientation == GTK_ORIENTATION_VERTICAL &&
10387 aux_info->height > 0)
10389 *minimum_size = MAX (*minimum_size, aux_info->height);
10392 /* Fix it if set_size_request made natural size smaller than min size.
10393 * This would also silently fix broken widgets, but we warn about them
10394 * in gtksizerequest.c when calling their size request vfuncs.
10396 *natural_size = MAX (*natural_size, *minimum_size);
10398 if (orientation == GTK_ORIENTATION_HORIZONTAL)
10400 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
10401 *natural_size += (aux_info->margin.left + aux_info->margin.right);
10405 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
10406 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
10411 * _gtk_widget_peek_request_cache:
10413 * Returns the address of the widget's request cache (strictly for
10414 * internal use in gtksizerequest.c)
10416 * Return value: the address of @widget's size request cache.
10419 _gtk_widget_peek_request_cache (GtkWidget *widget)
10421 /* Don't bother slowing things down with the return_if_fail guards here */
10422 return &widget->priv->requests;
10426 * _gtk_widget_set_device_window:
10427 * @widget: a #GtkWidget.
10428 * @device: a #GdkDevice.
10429 * @window: the new device window.
10431 * Sets pointer window for @widget and @device. Does not ref @window.
10432 * Actually stores it on the #GdkScreen, but you don't need to know that.
10435 _gtk_widget_set_device_window (GtkWidget *widget,
10439 GtkWidgetPrivate *priv;
10441 GHashTable *device_window;
10443 g_return_if_fail (GTK_IS_WIDGET (widget));
10444 g_return_if_fail (GDK_IS_DEVICE (device));
10445 g_return_if_fail (!window || GDK_IS_WINDOW (window));
10447 priv = widget->priv;
10449 if (!gtk_widget_get_realized (widget))
10452 screen = gdk_window_get_screen (priv->window);
10453 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10455 if (G_UNLIKELY (!device_window))
10457 device_window = g_hash_table_new (NULL, NULL);
10458 g_object_set_qdata_full (G_OBJECT (screen),
10459 quark_pointer_window,
10461 (GDestroyNotify) g_hash_table_destroy);
10465 g_hash_table_insert (device_window, device, window);
10467 g_hash_table_remove (device_window, device);
10471 * _gtk_widget_get_device_window:
10472 * @widget: a #GtkWidget.
10473 * @device: a #GdkDevice.
10475 * Return value: the device window set on the #GdkScreen @widget is attached
10479 _gtk_widget_get_device_window (GtkWidget *widget,
10482 GtkWidgetPrivate *priv;
10484 GHashTable *device_window;
10488 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10489 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10491 priv = widget->priv;
10493 if (!gtk_widget_get_realized (widget))
10496 screen = gdk_window_get_screen (priv->window);
10497 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10499 if (G_UNLIKELY (!device_window))
10502 window = g_hash_table_lookup (device_window, device);
10507 gdk_window_get_user_data (window, (gpointer *) &w);
10516 * _gtk_widget_list_devices:
10517 * @widget: a #GtkWidget.
10519 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10520 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10524 _gtk_widget_list_devices (GtkWidget *widget)
10526 GtkWidgetPrivate *priv;
10528 GHashTableIter iter;
10529 GHashTable *device_window;
10530 GList *devices = NULL;
10531 gpointer key, value;
10533 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10535 priv = widget->priv;
10537 if (!gtk_widget_get_realized (widget))
10540 screen = gdk_window_get_screen (priv->window);
10541 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10543 if (G_UNLIKELY (!device_window))
10546 g_hash_table_iter_init (&iter, device_window);
10548 while (g_hash_table_iter_next (&iter, &key, &value))
10550 GdkDevice *device = key;
10551 GdkWindow *window = value;
10556 gdk_window_get_user_data (window, (gpointer *) &w);
10559 devices = g_list_prepend (devices, device);
10567 synth_crossing (GtkWidget *widget,
10571 GdkCrossingMode mode,
10572 GdkNotifyType detail)
10576 event = gdk_event_new (type);
10578 event->crossing.window = g_object_ref (window);
10579 event->crossing.send_event = TRUE;
10580 event->crossing.subwindow = g_object_ref (window);
10581 event->crossing.time = GDK_CURRENT_TIME;
10582 event->crossing.x = event->crossing.y = 0;
10583 event->crossing.x_root = event->crossing.y_root = 0;
10584 event->crossing.mode = mode;
10585 event->crossing.detail = detail;
10586 event->crossing.focus = FALSE;
10587 event->crossing.state = 0;
10588 gdk_event_set_device (event, device);
10591 widget = gtk_get_event_widget (event);
10594 gtk_widget_event_internal (widget, event);
10596 gdk_event_free (event);
10600 * _gtk_widget_synthesize_crossing:
10601 * @from: the #GtkWidget the virtual pointer is leaving.
10602 * @to: the #GtkWidget the virtual pointer is moving to.
10603 * @mode: the #GdkCrossingMode to place on the synthesized events.
10605 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10607 * The real pointer window is the window that most recently received an enter notify
10608 * event. Windows that don't select for crossing events can't become the real
10609 * poiner window. The real pointer widget that owns the real pointer window. The
10610 * effective pointer window is the same as the real pointer window unless the real
10611 * pointer widget is either insensitive or there is a grab on a widget that is not
10612 * an ancestor of the real pointer widget (in which case the effective pointer
10613 * window should be the root window).
10615 * When the effective pointer window is the same as the real poiner window, we
10616 * receive crossing events from the windowing system. When the effective pointer
10617 * window changes to become different from the real pointer window we synthesize
10618 * crossing events, attempting to follow X protocol rules:
10620 * When the root window becomes the effective pointer window:
10621 * - leave notify on real pointer window, detail Ancestor
10622 * - leave notify on all of its ancestors, detail Virtual
10623 * - enter notify on root window, detail Inferior
10625 * When the root window ceases to be the effective pointer window:
10626 * - leave notify on root window, detail Inferior
10627 * - enter notify on all ancestors of real pointer window, detail Virtual
10628 * - enter notify on real pointer window, detail Ancestor
10631 _gtk_widget_synthesize_crossing (GtkWidget *from,
10634 GdkCrossingMode mode)
10636 GdkWindow *from_window = NULL, *to_window = NULL;
10638 g_return_if_fail (from != NULL || to != NULL);
10642 from_window = _gtk_widget_get_device_window (from, device);
10645 from_window = from->priv->window;
10650 to_window = _gtk_widget_get_device_window (to, device);
10653 to_window = to->priv->window;
10656 if (from_window == NULL && to_window == NULL)
10658 else if (from_window != NULL && to_window == NULL)
10660 GList *from_ancestors = NULL, *list;
10661 GdkWindow *from_ancestor = from_window;
10663 while (from_ancestor != NULL)
10665 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10666 if (from_ancestor == NULL)
10668 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10671 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10672 device, mode, GDK_NOTIFY_ANCESTOR);
10673 for (list = g_list_last (from_ancestors); list; list = list->prev)
10675 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10676 device, mode, GDK_NOTIFY_VIRTUAL);
10679 /* XXX: enter/inferior on root window? */
10681 g_list_free (from_ancestors);
10683 else if (from_window == NULL && to_window != NULL)
10685 GList *to_ancestors = NULL, *list;
10686 GdkWindow *to_ancestor = to_window;
10688 while (to_ancestor != NULL)
10690 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10691 if (to_ancestor == NULL)
10693 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10696 /* XXX: leave/inferior on root window? */
10698 for (list = to_ancestors; list; list = list->next)
10700 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10701 device, mode, GDK_NOTIFY_VIRTUAL);
10703 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10704 device, mode, GDK_NOTIFY_ANCESTOR);
10706 g_list_free (to_ancestors);
10708 else if (from_window == to_window)
10712 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10713 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10715 while (from_ancestor != NULL || to_ancestor != NULL)
10717 if (from_ancestor != NULL)
10719 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10720 if (from_ancestor == to_window)
10723 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10725 if (to_ancestor != NULL)
10727 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10728 if (to_ancestor == from_window)
10731 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10734 if (to_ancestor == from_window)
10736 if (mode != GDK_CROSSING_GTK_UNGRAB)
10737 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10738 device, mode, GDK_NOTIFY_INFERIOR);
10739 for (list = to_ancestors; list; list = list->next)
10740 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10741 device, mode, GDK_NOTIFY_VIRTUAL);
10742 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10743 device, mode, GDK_NOTIFY_ANCESTOR);
10745 else if (from_ancestor == to_window)
10747 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10748 device, mode, GDK_NOTIFY_ANCESTOR);
10749 for (list = g_list_last (from_ancestors); list; list = list->prev)
10751 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10752 device, mode, GDK_NOTIFY_VIRTUAL);
10754 if (mode != GDK_CROSSING_GTK_GRAB)
10755 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10756 device, mode, GDK_NOTIFY_INFERIOR);
10760 while (from_ancestors != NULL && to_ancestors != NULL
10761 && from_ancestors->data == to_ancestors->data)
10763 from_ancestors = g_list_delete_link (from_ancestors,
10765 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10768 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10769 device, mode, GDK_NOTIFY_NONLINEAR);
10771 for (list = g_list_last (from_ancestors); list; list = list->prev)
10773 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10774 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10776 for (list = to_ancestors; list; list = list->next)
10778 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10779 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10781 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10782 device, mode, GDK_NOTIFY_NONLINEAR);
10784 g_list_free (from_ancestors);
10785 g_list_free (to_ancestors);
10790 gtk_widget_propagate_state (GtkWidget *widget,
10791 GtkStateData *data)
10793 GtkWidgetPrivate *priv = widget->priv;
10794 GtkStateFlags new_flags, old_flags = priv->state_flags;
10795 GtkStateType old_state;
10797 old_state = gtk_widget_get_state (widget);
10799 if (!priv->parent_sensitive)
10800 old_flags |= GTK_STATE_FLAG_INSENSITIVE;
10802 priv->parent_sensitive = data->parent_sensitive;
10804 switch (data->operation)
10806 case STATE_CHANGE_REPLACE:
10807 priv->state_flags = data->flags;
10809 case STATE_CHANGE_SET:
10810 priv->state_flags |= data->flags;
10812 case STATE_CHANGE_UNSET:
10813 priv->state_flags &= ~(data->flags);
10817 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10821 window = gtk_widget_get_toplevel (widget);
10823 if (window && gtk_widget_is_toplevel (window))
10824 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10827 new_flags = gtk_widget_get_state_flags (widget);
10829 if (old_flags != new_flags)
10831 g_object_ref (widget);
10833 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10834 gtk_grab_remove (widget);
10836 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10837 g_signal_emit (widget, widget_signals[STATE_FLAGS_CHANGED], 0, old_flags);
10839 if (!priv->shadowed)
10841 GList *event_windows = NULL;
10842 GList *devices, *d;
10844 devices = _gtk_widget_list_devices (widget);
10846 for (d = devices; d; d = d->next)
10852 window = _gtk_widget_get_device_window (widget, device);
10854 /* Do not propagate more than once to the
10855 * same window if non-multidevice aware.
10857 if (!gdk_window_get_support_multidevice (window) &&
10858 g_list_find (event_windows, window))
10861 if (!gtk_widget_is_sensitive (widget))
10862 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10863 GDK_CROSSING_STATE_CHANGED);
10864 else if (old_flags & GTK_STATE_FLAG_INSENSITIVE)
10865 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10866 GDK_CROSSING_STATE_CHANGED);
10868 event_windows = g_list_prepend (event_windows, window);
10871 g_list_free (event_windows);
10872 g_list_free (devices);
10875 if (GTK_IS_CONTAINER (widget))
10877 data->parent_sensitive = gtk_widget_is_sensitive (widget);
10879 /* Do not propagate insensitive state further */
10880 data->flags &= ~(GTK_STATE_FLAG_INSENSITIVE);
10882 if (data->use_forall)
10883 gtk_container_forall (GTK_CONTAINER (widget),
10884 (GtkCallback) gtk_widget_propagate_state,
10887 gtk_container_foreach (GTK_CONTAINER (widget),
10888 (GtkCallback) gtk_widget_propagate_state,
10892 /* Trigger state change transitions for the widget */
10893 if (priv->context &&
10894 gtk_widget_get_mapped (widget))
10896 gint diff, flag = 1;
10899 diff = old_flags ^ new_flags;
10900 window = gtk_widget_get_window (widget);
10904 if ((diff & flag) != 0)
10906 GtkStateType state;
10911 case GTK_STATE_FLAG_ACTIVE:
10912 state = GTK_STATE_ACTIVE;
10914 case GTK_STATE_FLAG_PRELIGHT:
10915 state = GTK_STATE_PRELIGHT;
10917 case GTK_STATE_FLAG_SELECTED:
10918 state = GTK_STATE_SELECTED;
10920 case GTK_STATE_FLAG_INSENSITIVE:
10921 state = GTK_STATE_INSENSITIVE;
10923 case GTK_STATE_FLAG_INCONSISTENT:
10924 state = GTK_STATE_INCONSISTENT;
10926 case GTK_STATE_FLAG_FOCUSED:
10927 state = GTK_STATE_FOCUSED;
10930 state = GTK_STATE_NORMAL;
10934 target = ((new_flags & flag) != 0);
10935 gtk_style_context_notify_state_change (priv->context,
10945 g_object_unref (widget);
10949 static const GtkWidgetAuxInfo default_aux_info = {
10957 * _gtk_widget_get_aux_info:
10958 * @widget: a #GtkWidget
10959 * @create: if %TRUE, create the structure if it doesn't exist
10961 * Get the #GtkWidgetAuxInfo structure for the widget.
10963 * Return value: the #GtkAuxInfo structure for the widget, or
10964 * %NULL if @create is %FALSE and one doesn't already exist.
10967 _gtk_widget_get_aux_info (GtkWidget *widget,
10970 GtkWidgetAuxInfo *aux_info;
10972 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10973 if (!aux_info && create)
10975 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10977 *aux_info = default_aux_info;
10979 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10985 static const GtkWidgetAuxInfo*
10986 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10988 GtkWidgetAuxInfo *aux_info;
10990 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10991 if (aux_info == NULL)
10993 return &default_aux_info;
11001 /*****************************************
11002 * gtk_widget_aux_info_destroy:
11007 *****************************************/
11010 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
11012 g_slice_free (GtkWidgetAuxInfo, aux_info);
11016 * gtk_widget_shape_combine_region:
11017 * @widget: a #GtkWidget
11018 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11020 * Sets a shape for this widget's GDK window. This allows for
11021 * transparent windows etc., see gdk_window_shape_combine_region()
11022 * for more information.
11027 gtk_widget_shape_combine_region (GtkWidget *widget,
11028 cairo_region_t *region)
11030 GtkWidgetPrivate *priv;
11032 g_return_if_fail (GTK_IS_WIDGET (widget));
11033 /* set_shape doesn't work on widgets without gdk window */
11034 g_return_if_fail (gtk_widget_get_has_window (widget));
11036 priv = widget->priv;
11038 if (region == NULL)
11040 priv->has_shape_mask = FALSE;
11043 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
11045 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
11049 priv->has_shape_mask = TRUE;
11051 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
11052 cairo_region_copy (region),
11053 (GDestroyNotify) cairo_region_destroy);
11055 /* set shape if widget has a gdk window already.
11056 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11059 gdk_window_shape_combine_region (priv->window, region, 0, 0);
11064 * gtk_widget_input_shape_combine_region:
11065 * @widget: a #GtkWidget
11066 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
11068 * Sets an input shape for this widget's GDK window. This allows for
11069 * windows which react to mouse click in a nonrectangular region, see
11070 * gdk_window_input_shape_combine_region() for more information.
11075 gtk_widget_input_shape_combine_region (GtkWidget *widget,
11076 cairo_region_t *region)
11078 GtkWidgetPrivate *priv;
11080 g_return_if_fail (GTK_IS_WIDGET (widget));
11081 /* set_shape doesn't work on widgets without gdk window */
11082 g_return_if_fail (gtk_widget_get_has_window (widget));
11084 priv = widget->priv;
11086 if (region == NULL)
11089 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
11091 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
11095 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
11096 cairo_region_copy (region),
11097 (GDestroyNotify) cairo_region_destroy);
11099 /* set shape if widget has a gdk window already.
11100 * otherwise the shape is scheduled to be set by gtk_widget_realize().
11103 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
11109 gtk_reset_shapes_recurse (GtkWidget *widget,
11115 gdk_window_get_user_data (window, &data);
11116 if (data != widget)
11119 gdk_window_shape_combine_region (window, NULL, 0, 0);
11120 for (list = gdk_window_peek_children (window); list; list = list->next)
11121 gtk_reset_shapes_recurse (widget, list->data);
11125 * gtk_widget_reset_shapes:
11126 * @widget: a #GtkWidget
11128 * Recursively resets the shape on this widget and its descendants.
11131 gtk_widget_reset_shapes (GtkWidget *widget)
11133 GtkWidgetPrivate *priv;
11135 g_return_if_fail (GTK_IS_WIDGET (widget));
11136 g_return_if_fail (gtk_widget_get_realized (widget));
11138 priv = widget->priv;
11140 if (!priv->has_shape_mask)
11141 gtk_reset_shapes_recurse (widget, priv->window);
11144 /* style properties
11148 * gtk_widget_class_install_style_property_parser:
11149 * @klass: a #GtkWidgetClass
11150 * @pspec: the #GParamSpec for the style property
11151 * @parser: the parser for the style property
11153 * Installs a style property on a widget class.
11156 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
11158 GtkRcPropertyParser parser)
11160 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11161 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11162 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
11163 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
11165 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
11167 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
11168 G_OBJECT_CLASS_NAME (klass),
11173 g_param_spec_ref_sink (pspec);
11174 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
11175 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
11179 * gtk_widget_class_install_style_property:
11180 * @klass: a #GtkWidgetClass
11181 * @pspec: the #GParamSpec for the property
11183 * Installs a style property on a widget class. The parser for the
11184 * style property is determined by the value type of @pspec.
11187 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
11190 GtkRcPropertyParser parser;
11192 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
11193 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
11195 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
11197 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
11201 * gtk_widget_class_find_style_property:
11202 * @klass: a #GtkWidgetClass
11203 * @property_name: the name of the style property to find
11204 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
11205 * style property with that name.
11207 * Finds a style property of a widget class by name.
11212 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
11213 const gchar *property_name)
11215 g_return_val_if_fail (property_name != NULL, NULL);
11217 return g_param_spec_pool_lookup (style_property_spec_pool,
11219 G_OBJECT_CLASS_TYPE (klass),
11224 * gtk_widget_class_list_style_properties:
11225 * @klass: a #GtkWidgetClass
11226 * @n_properties: location to return the number of style properties found
11227 * @returns: an newly allocated array of #GParamSpec*. The array must
11228 * be freed with g_free().
11230 * Returns all style properties of a widget class.
11235 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
11236 guint *n_properties)
11238 GParamSpec **pspecs;
11241 pspecs = g_param_spec_pool_list (style_property_spec_pool,
11242 G_OBJECT_CLASS_TYPE (klass),
11251 * gtk_widget_style_get_property:
11252 * @widget: a #GtkWidget
11253 * @property_name: the name of a style property
11254 * @value: location to return the property value
11256 * Gets the value of a style property of @widget.
11259 gtk_widget_style_get_property (GtkWidget *widget,
11260 const gchar *property_name,
11265 g_return_if_fail (GTK_IS_WIDGET (widget));
11266 g_return_if_fail (property_name != NULL);
11267 g_return_if_fail (G_IS_VALUE (value));
11269 g_object_ref (widget);
11270 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11272 G_OBJECT_TYPE (widget),
11275 g_warning ("%s: widget class `%s' has no property named `%s'",
11277 G_OBJECT_TYPE_NAME (widget),
11281 GtkStyleContext *context;
11282 const GValue *peek_value;
11284 context = gtk_widget_get_style_context (widget);
11285 peek_value = _gtk_style_context_peek_style_property (context,
11286 G_OBJECT_TYPE (widget),
11289 /* auto-conversion of the caller's value type
11291 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
11292 g_value_copy (peek_value, value);
11293 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
11294 g_value_transform (peek_value, value);
11296 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
11298 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
11299 G_VALUE_TYPE_NAME (value));
11301 g_object_unref (widget);
11305 * gtk_widget_style_get_valist:
11306 * @widget: a #GtkWidget
11307 * @first_property_name: the name of the first property to get
11308 * @var_args: a <type>va_list</type> of pairs of property names and
11309 * locations to return the property values, starting with the location
11310 * for @first_property_name.
11312 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
11316 gtk_widget_style_get_valist (GtkWidget *widget,
11317 const gchar *first_property_name,
11320 GtkStyleContext *context;
11323 g_return_if_fail (GTK_IS_WIDGET (widget));
11325 g_object_ref (widget);
11326 context = gtk_widget_get_style_context (widget);
11328 name = first_property_name;
11331 const GValue *peek_value;
11335 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
11337 G_OBJECT_TYPE (widget),
11341 g_warning ("%s: widget class `%s' has no property named `%s'",
11343 G_OBJECT_TYPE_NAME (widget),
11347 /* style pspecs are always readable so we can spare that check here */
11349 peek_value = _gtk_style_context_peek_style_property (context,
11350 G_OBJECT_TYPE (widget),
11353 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
11356 g_warning ("%s: %s", G_STRLOC, error);
11361 name = va_arg (var_args, gchar*);
11364 g_object_unref (widget);
11368 * gtk_widget_style_get:
11369 * @widget: a #GtkWidget
11370 * @first_property_name: the name of the first property to get
11371 * @Varargs: pairs of property names and locations to
11372 * return the property values, starting with the location for
11373 * @first_property_name, terminated by %NULL.
11375 * Gets the values of a multiple style properties of @widget.
11378 gtk_widget_style_get (GtkWidget *widget,
11379 const gchar *first_property_name,
11384 g_return_if_fail (GTK_IS_WIDGET (widget));
11386 va_start (var_args, first_property_name);
11387 gtk_widget_style_get_valist (widget, first_property_name, var_args);
11393 * @widget: a #GtkWidget
11394 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
11395 * @path: (out) (allow-none): location to store allocated path string, or %NULL
11396 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
11398 * Obtains the full path to @widget. The path is simply the name of a
11399 * widget and all its parents in the container hierarchy, separated by
11400 * periods. The name of a widget comes from
11401 * gtk_widget_get_name(). Paths are used to apply styles to a widget
11402 * in gtkrc configuration files. Widget names are the type of the
11403 * widget by default (e.g. "GtkButton") or can be set to an
11404 * application-specific value with gtk_widget_set_name(). By setting
11405 * the name of a widget, you allow users or theme authors to apply
11406 * styles to that specific widget in their gtkrc
11407 * file. @path_reversed_p fills in the path in reverse order,
11408 * i.e. starting with @widget's name instead of starting with the name
11409 * of @widget's outermost ancestor.
11412 gtk_widget_path (GtkWidget *widget,
11413 guint *path_length,
11415 gchar **path_reversed)
11417 static gchar *rev_path = NULL;
11418 static guint tmp_path_len = 0;
11421 g_return_if_fail (GTK_IS_WIDGET (widget));
11426 const gchar *string;
11431 string = gtk_widget_get_name (widget);
11432 l = strlen (string);
11433 while (tmp_path_len <= len + l + 1)
11435 tmp_path_len += INIT_PATH_SIZE;
11436 rev_path = g_realloc (rev_path, tmp_path_len);
11438 s = string + l - 1;
11439 d = rev_path + len;
11440 while (s >= string)
11444 widget = widget->priv->parent;
11447 rev_path[len++] = '.';
11449 rev_path[len++] = 0;
11454 *path_length = len - 1;
11456 *path_reversed = g_strdup (rev_path);
11459 *path = g_strdup (rev_path);
11460 g_strreverse (*path);
11465 * gtk_widget_class_path:
11466 * @widget: a #GtkWidget
11467 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
11468 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
11469 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
11472 * Same as gtk_widget_path(), but always uses the name of a widget's type,
11473 * never uses a custom name set with gtk_widget_set_name().
11477 gtk_widget_class_path (GtkWidget *widget,
11478 guint *path_length,
11480 gchar **path_reversed)
11482 static gchar *rev_path = NULL;
11483 static guint tmp_path_len = 0;
11486 g_return_if_fail (GTK_IS_WIDGET (widget));
11491 const gchar *string;
11496 string = g_type_name (G_OBJECT_TYPE (widget));
11497 l = strlen (string);
11498 while (tmp_path_len <= len + l + 1)
11500 tmp_path_len += INIT_PATH_SIZE;
11501 rev_path = g_realloc (rev_path, tmp_path_len);
11503 s = string + l - 1;
11504 d = rev_path + len;
11505 while (s >= string)
11509 widget = widget->priv->parent;
11512 rev_path[len++] = '.';
11514 rev_path[len++] = 0;
11519 *path_length = len - 1;
11521 *path_reversed = g_strdup (rev_path);
11524 *path = g_strdup (rev_path);
11525 g_strreverse (*path);
11530 * gtk_requisition_new:
11532 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11534 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11535 * be freed with gtk_requisition_free().
11540 gtk_requisition_new (void)
11542 return g_slice_new0 (GtkRequisition);
11546 * gtk_requisition_copy:
11547 * @requisition: a #GtkRequisition
11549 * Copies a #GtkRequisition.
11551 * Returns: a copy of @requisition
11554 gtk_requisition_copy (const GtkRequisition *requisition)
11556 return g_slice_dup (GtkRequisition, requisition);
11560 * gtk_requisition_free:
11561 * @requisition: a #GtkRequisition
11563 * Frees a #GtkRequisition.
11566 gtk_requisition_free (GtkRequisition *requisition)
11568 g_slice_free (GtkRequisition, requisition);
11571 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11572 gtk_requisition_copy,
11573 gtk_requisition_free)
11576 * gtk_widget_get_accessible:
11577 * @widget: a #GtkWidget
11579 * Returns the accessible object that describes the widget to an
11580 * assistive technology.
11582 * If no accessibility library is loaded (i.e. no ATK implementation library is
11583 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11584 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11585 * if no class-specific #AtkObject implementation is available for the widget
11586 * instance in question, it will inherit an #AtkObject implementation from the
11587 * first ancestor class for which such an implementation is defined.
11589 * The documentation of the
11590 * <ulink url="http://library.gnome.org/devel/atk/stable/">ATK</ulink>
11591 * library contains more information about accessible objects and their uses.
11593 * Returns: (transfer none): the #AtkObject associated with @widget
11596 gtk_widget_get_accessible (GtkWidget *widget)
11598 GtkWidgetClass *klass;
11600 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11602 klass = GTK_WIDGET_GET_CLASS (widget);
11604 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11606 return klass->get_accessible (widget);
11610 gtk_widget_real_get_accessible (GtkWidget *widget)
11612 AtkObject* accessible;
11614 accessible = g_object_get_qdata (G_OBJECT (widget),
11615 quark_accessible_object);
11618 AtkObjectFactory *factory;
11619 AtkRegistry *default_registry;
11621 default_registry = atk_get_default_registry ();
11622 factory = atk_registry_get_factory (default_registry,
11623 G_TYPE_FROM_INSTANCE (widget));
11625 atk_object_factory_create_accessible (factory,
11626 G_OBJECT (widget));
11627 g_object_set_qdata (G_OBJECT (widget),
11628 quark_accessible_object,
11635 * Initialize a AtkImplementorIface instance's virtual pointers as
11636 * appropriate to this implementor's class (GtkWidget).
11639 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11641 iface->ref_accessible = gtk_widget_ref_accessible;
11645 gtk_widget_ref_accessible (AtkImplementor *implementor)
11647 AtkObject *accessible;
11649 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11651 g_object_ref (accessible);
11656 * Expand flag management
11660 gtk_widget_update_computed_expand (GtkWidget *widget)
11662 GtkWidgetPrivate *priv;
11664 priv = widget->priv;
11666 if (priv->need_compute_expand)
11670 if (priv->hexpand_set)
11675 if (priv->vexpand_set)
11680 /* we don't need to use compute_expand if both expands are
11681 * forced by the app
11683 if (!(priv->hexpand_set && priv->vexpand_set))
11685 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11689 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11690 priv->hexpand_set ? &ignored : &h,
11691 priv->vexpand_set ? &ignored : &v);
11695 priv->need_compute_expand = FALSE;
11696 priv->computed_hexpand = h != FALSE;
11697 priv->computed_vexpand = v != FALSE;
11702 * gtk_widget_queue_compute_expand:
11703 * @widget: a #GtkWidget
11705 * Mark @widget as needing to recompute its expand flags. Call
11706 * this function when setting legacy expand child properties
11707 * on the child of a container.
11709 * See gtk_widget_compute_expand().
11712 gtk_widget_queue_compute_expand (GtkWidget *widget)
11715 gboolean changed_anything;
11717 if (widget->priv->need_compute_expand)
11720 changed_anything = FALSE;
11722 while (parent != NULL)
11724 if (!parent->priv->need_compute_expand)
11726 parent->priv->need_compute_expand = TRUE;
11727 changed_anything = TRUE;
11730 /* Note: if we had an invariant that "if a child needs to
11731 * compute expand, its parents also do" then we could stop going
11732 * up when we got to a parent that already needed to
11733 * compute. However, in general we compute expand lazily (as
11734 * soon as we see something in a subtree that is expand, we know
11735 * we're expanding) and so this invariant does not hold and we
11736 * have to always walk all the way up in case some ancestor
11737 * is not currently need_compute_expand.
11740 parent = parent->priv->parent;
11743 /* recomputing expand always requires
11744 * a relayout as well
11746 if (changed_anything)
11747 gtk_widget_queue_resize (widget);
11751 * gtk_widget_compute_expand:
11752 * @widget: the widget
11753 * @orientation: expand direction
11755 * Computes whether a container should give this widget extra space
11756 * when possible. Containers should check this, rather than
11757 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11759 * This function already checks whether the widget is visible, so
11760 * visibility does not need to be checked separately. Non-visible
11761 * widgets are not expanded.
11763 * The computed expand value uses either the expand setting explicitly
11764 * set on the widget itself, or, if none has been explicitly set,
11765 * the widget may expand if some of its children do.
11767 * Return value: whether widget tree rooted here should be expanded
11770 gtk_widget_compute_expand (GtkWidget *widget,
11771 GtkOrientation orientation)
11773 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11775 /* We never make a widget expand if not even showing. */
11776 if (!gtk_widget_get_visible (widget))
11779 gtk_widget_update_computed_expand (widget);
11781 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11783 return widget->priv->computed_hexpand;
11787 return widget->priv->computed_vexpand;
11792 gtk_widget_set_expand (GtkWidget *widget,
11793 GtkOrientation orientation,
11796 const char *expand_prop;
11797 const char *expand_set_prop;
11799 GtkWidgetPrivate *priv;
11801 g_return_if_fail (GTK_IS_WIDGET (widget));
11803 priv = widget->priv;
11805 expand = expand != FALSE;
11807 was_both = priv->hexpand && priv->vexpand;
11809 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11811 if (priv->hexpand_set &&
11812 priv->hexpand == expand)
11815 priv->hexpand_set = TRUE;
11816 priv->hexpand = expand;
11818 expand_prop = "hexpand";
11819 expand_set_prop = "hexpand-set";
11823 if (priv->vexpand_set &&
11824 priv->vexpand == expand)
11827 priv->vexpand_set = TRUE;
11828 priv->vexpand = expand;
11830 expand_prop = "vexpand";
11831 expand_set_prop = "vexpand-set";
11834 gtk_widget_queue_compute_expand (widget);
11836 g_object_freeze_notify (G_OBJECT (widget));
11837 g_object_notify (G_OBJECT (widget), expand_prop);
11838 g_object_notify (G_OBJECT (widget), expand_set_prop);
11839 if (was_both != (priv->hexpand && priv->vexpand))
11840 g_object_notify (G_OBJECT (widget), "expand");
11841 g_object_thaw_notify (G_OBJECT (widget));
11845 gtk_widget_set_expand_set (GtkWidget *widget,
11846 GtkOrientation orientation,
11849 GtkWidgetPrivate *priv;
11852 priv = widget->priv;
11854 set = set != FALSE;
11856 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11858 if (set == priv->hexpand_set)
11861 priv->hexpand_set = set;
11862 prop = "hexpand-set";
11866 if (set == priv->vexpand_set)
11869 priv->vexpand_set = set;
11870 prop = "vexpand-set";
11873 gtk_widget_queue_compute_expand (widget);
11875 g_object_notify (G_OBJECT (widget), prop);
11879 * gtk_widget_get_hexpand:
11880 * @widget: the widget
11882 * Gets whether the widget would like any available extra horizontal
11883 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11884 * generally receive the extra space. For example, a list or
11885 * scrollable area or document in your window would often be set to
11888 * Containers should use gtk_widget_compute_expand() rather than
11889 * this function, to see whether a widget, or any of its children,
11890 * has the expand flag set. If any child of a widget wants to
11891 * expand, the parent may ask to expand also.
11893 * This function only looks at the widget's own hexpand flag, rather
11894 * than computing whether the entire widget tree rooted at this widget
11897 * Return value: whether hexpand flag is set
11900 gtk_widget_get_hexpand (GtkWidget *widget)
11902 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11904 return widget->priv->hexpand;
11908 * gtk_widget_set_hexpand:
11909 * @widget: the widget
11910 * @expand: whether to expand
11912 * Sets whether the widget would like any available extra horizontal
11913 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11914 * generally receive the extra space. For example, a list or
11915 * scrollable area or document in your window would often be set to
11918 * Call this function to set the expand flag if you would like your
11919 * widget to become larger horizontally when the window has extra
11922 * By default, widgets automatically expand if any of their children
11923 * want to expand. (To see if a widget will automatically expand given
11924 * its current children and state, call gtk_widget_compute_expand(). A
11925 * container can decide how the expandability of children affects the
11926 * expansion of the container by overriding the compute_expand virtual
11927 * method on #GtkWidget.).
11929 * Setting hexpand explicitly with this function will override the
11930 * automatic expand behavior.
11932 * This function forces the widget to expand or not to expand,
11933 * regardless of children. The override occurs because
11934 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11935 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11936 * value to be used, rather than looking at children and widget state.
11939 gtk_widget_set_hexpand (GtkWidget *widget,
11942 g_return_if_fail (GTK_IS_WIDGET (widget));
11944 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11948 * gtk_widget_get_hexpand_set:
11949 * @widget: the widget
11951 * Gets whether gtk_widget_set_hexpand() has been used to
11952 * explicitly set the expand flag on this widget.
11954 * If hexpand is set, then it overrides any computed
11955 * expand value based on child widgets. If hexpand is not
11956 * set, then the expand value depends on whether any
11957 * children of the widget would like to expand.
11959 * There are few reasons to use this function, but it's here
11960 * for completeness and consistency.
11962 * Return value: whether hexpand has been explicitly set
11965 gtk_widget_get_hexpand_set (GtkWidget *widget)
11967 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11969 return widget->priv->hexpand_set;
11973 * gtk_widget_set_hexpand_set:
11974 * @widget: the widget
11975 * @set: value for hexpand-set property
11977 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11980 * The hexpand-set property will be set automatically when you call
11981 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11982 * reason to use this function would be to unset an explicit expand
11985 * If hexpand is set, then it overrides any computed
11986 * expand value based on child widgets. If hexpand is not
11987 * set, then the expand value depends on whether any
11988 * children of the widget would like to expand.
11990 * There are few reasons to use this function, but it's here
11991 * for completeness and consistency.
11993 * Return value: whether hexpand has been explicitly set
11996 gtk_widget_set_hexpand_set (GtkWidget *widget,
11999 g_return_if_fail (GTK_IS_WIDGET (widget));
12001 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
12006 * gtk_widget_get_vexpand:
12007 * @widget: the widget
12009 * Gets whether the widget would like any available extra vertical
12012 * See gtk_widget_get_hexpand() for more detail.
12014 * Return value: whether vexpand flag is set
12017 gtk_widget_get_vexpand (GtkWidget *widget)
12019 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12021 return widget->priv->vexpand;
12025 * gtk_widget_set_vexpand:
12026 * @widget: the widget
12027 * @expand: whether to expand
12029 * Sets whether the widget would like any available extra vertical
12032 * See gtk_widget_set_hexpand() for more detail.
12035 gtk_widget_set_vexpand (GtkWidget *widget,
12038 g_return_if_fail (GTK_IS_WIDGET (widget));
12040 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
12044 * gtk_widget_get_vexpand_set:
12045 * @widget: the widget
12047 * Gets whether gtk_widget_set_vexpand() has been used to
12048 * explicitly set the expand flag on this widget.
12050 * See gtk_widget_get_hexpand_set() for more detail.
12052 * Return value: whether vexpand has been explicitly set
12055 gtk_widget_get_vexpand_set (GtkWidget *widget)
12057 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12059 return widget->priv->vexpand_set;
12063 * gtk_widget_set_vexpand_set:
12064 * @widget: the widget
12065 * @set: value for vexpand-set property
12067 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
12070 * See gtk_widget_set_hexpand_set() for more detail.
12072 * Return value: whether vexpand has been explicitly set
12075 gtk_widget_set_vexpand_set (GtkWidget *widget,
12078 g_return_if_fail (GTK_IS_WIDGET (widget));
12080 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
12084 * GtkBuildable implementation
12086 static GQuark quark_builder_has_default = 0;
12087 static GQuark quark_builder_has_focus = 0;
12088 static GQuark quark_builder_atk_relations = 0;
12089 static GQuark quark_builder_set_name = 0;
12092 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
12094 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
12095 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
12096 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
12097 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
12099 iface->set_name = gtk_widget_buildable_set_name;
12100 iface->get_name = gtk_widget_buildable_get_name;
12101 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
12102 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
12103 iface->parser_finished = gtk_widget_buildable_parser_finished;
12104 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
12105 iface->custom_finished = gtk_widget_buildable_custom_finished;
12109 gtk_widget_buildable_set_name (GtkBuildable *buildable,
12112 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
12113 g_strdup (name), g_free);
12116 static const gchar *
12117 gtk_widget_buildable_get_name (GtkBuildable *buildable)
12119 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
12123 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
12124 GtkBuilder *builder,
12125 const gchar *childname)
12127 if (strcmp (childname, "accessible") == 0)
12128 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
12134 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
12135 GtkBuilder *builder,
12137 const GValue *value)
12139 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
12140 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
12141 GINT_TO_POINTER (TRUE));
12142 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
12143 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
12144 GINT_TO_POINTER (TRUE));
12146 g_object_set_property (G_OBJECT (buildable), name, value);
12151 gchar *action_name;
12152 GString *description;
12154 gboolean translatable;
12164 free_action (AtkActionData *data, gpointer user_data)
12166 g_free (data->action_name);
12167 g_string_free (data->description, TRUE);
12168 g_free (data->context);
12169 g_slice_free (AtkActionData, data);
12173 free_relation (AtkRelationData *data, gpointer user_data)
12175 g_free (data->target);
12176 g_free (data->type);
12177 g_slice_free (AtkRelationData, data);
12181 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
12182 GtkBuilder *builder)
12184 GSList *atk_relations;
12186 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
12187 gtk_widget_grab_default (GTK_WIDGET (buildable));
12188 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
12189 gtk_widget_grab_focus (GTK_WIDGET (buildable));
12191 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
12192 quark_builder_atk_relations);
12195 AtkObject *accessible;
12196 AtkRelationSet *relation_set;
12199 AtkRelationType relation_type;
12200 AtkObject *target_accessible;
12202 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12203 relation_set = atk_object_ref_relation_set (accessible);
12205 for (l = atk_relations; l; l = l->next)
12207 AtkRelationData *relation = (AtkRelationData*)l->data;
12209 target = gtk_builder_get_object (builder, relation->target);
12212 g_warning ("Target object %s in <relation> does not exist",
12216 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
12217 g_assert (target_accessible != NULL);
12219 relation_type = atk_relation_type_for_name (relation->type);
12220 if (relation_type == ATK_RELATION_NULL)
12222 g_warning ("<relation> type %s not found",
12226 atk_relation_set_add_relation_by_type (relation_set, relation_type,
12227 target_accessible);
12229 g_object_unref (relation_set);
12231 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
12232 g_slist_free (atk_relations);
12233 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12242 } AccessibilitySubParserData;
12245 accessibility_start_element (GMarkupParseContext *context,
12246 const gchar *element_name,
12247 const gchar **names,
12248 const gchar **values,
12249 gpointer user_data,
12252 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12254 gint line_number, char_number;
12256 if (strcmp (element_name, "relation") == 0)
12258 gchar *target = NULL;
12259 gchar *type = NULL;
12260 AtkRelationData *relation;
12262 for (i = 0; names[i]; i++)
12264 if (strcmp (names[i], "target") == 0)
12265 target = g_strdup (values[i]);
12266 else if (strcmp (names[i], "type") == 0)
12267 type = g_strdup (values[i]);
12270 g_markup_parse_context_get_position (context,
12273 g_set_error (error,
12275 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12276 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12278 line_number, char_number, names[i], "relation");
12285 if (!target || !type)
12287 g_markup_parse_context_get_position (context,
12290 g_set_error (error,
12292 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12293 "%s:%d:%d <%s> requires attribute \"%s\"",
12295 line_number, char_number, "relation",
12296 type ? "target" : "type");
12302 relation = g_slice_new (AtkRelationData);
12303 relation->target = target;
12304 relation->type = type;
12306 data->relations = g_slist_prepend (data->relations, relation);
12308 else if (strcmp (element_name, "action") == 0)
12310 const gchar *action_name = NULL;
12311 const gchar *description = NULL;
12312 const gchar *msg_context = NULL;
12313 gboolean translatable = FALSE;
12314 AtkActionData *action;
12316 for (i = 0; names[i]; i++)
12318 if (strcmp (names[i], "action_name") == 0)
12319 action_name = values[i];
12320 else if (strcmp (names[i], "description") == 0)
12321 description = values[i];
12322 else if (strcmp (names[i], "translatable") == 0)
12324 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
12327 else if (strcmp (names[i], "comments") == 0)
12329 /* do nothing, comments are for translators */
12331 else if (strcmp (names[i], "context") == 0)
12332 msg_context = values[i];
12335 g_markup_parse_context_get_position (context,
12338 g_set_error (error,
12340 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
12341 "%s:%d:%d '%s' is not a valid attribute of <%s>",
12343 line_number, char_number, names[i], "action");
12350 g_markup_parse_context_get_position (context,
12353 g_set_error (error,
12355 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
12356 "%s:%d:%d <%s> requires attribute \"%s\"",
12358 line_number, char_number, "action",
12363 action = g_slice_new (AtkActionData);
12364 action->action_name = g_strdup (action_name);
12365 action->description = g_string_new (description);
12366 action->context = g_strdup (msg_context);
12367 action->translatable = translatable;
12369 data->actions = g_slist_prepend (data->actions, action);
12371 else if (strcmp (element_name, "accessibility") == 0)
12374 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
12378 accessibility_text (GMarkupParseContext *context,
12381 gpointer user_data,
12384 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
12386 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
12388 AtkActionData *action = data->actions->data;
12390 g_string_append_len (action->description, text, text_len);
12394 static const GMarkupParser accessibility_parser =
12396 accessibility_start_element,
12398 accessibility_text,
12407 } AccelGroupParserData;
12410 accel_group_start_element (GMarkupParseContext *context,
12411 const gchar *element_name,
12412 const gchar **names,
12413 const gchar **values,
12414 gpointer user_data,
12419 guint modifiers = 0;
12420 gchar *signal = NULL;
12421 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
12423 for (i = 0; names[i]; i++)
12425 if (strcmp (names[i], "key") == 0)
12426 key = gdk_keyval_from_name (values[i]);
12427 else if (strcmp (names[i], "modifiers") == 0)
12429 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
12435 else if (strcmp (names[i], "signal") == 0)
12436 signal = g_strdup (values[i]);
12439 if (key == 0 || signal == NULL)
12441 g_warning ("<accelerator> requires key and signal attributes");
12444 parser_data->key = key;
12445 parser_data->modifiers = modifiers;
12446 parser_data->signal = signal;
12449 static const GMarkupParser accel_group_parser =
12451 accel_group_start_element,
12455 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
12456 GtkBuilder *builder,
12458 const gchar *tagname,
12459 GMarkupParser *parser,
12462 g_assert (buildable);
12464 if (strcmp (tagname, "accelerator") == 0)
12466 AccelGroupParserData *parser_data;
12468 parser_data = g_slice_new0 (AccelGroupParserData);
12469 parser_data->object = g_object_ref (buildable);
12470 *parser = accel_group_parser;
12471 *data = parser_data;
12474 if (strcmp (tagname, "accessibility") == 0)
12476 AccessibilitySubParserData *parser_data;
12478 parser_data = g_slice_new0 (AccessibilitySubParserData);
12479 *parser = accessibility_parser;
12480 *data = parser_data;
12487 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
12488 GtkWidget *toplevel,
12489 gpointer user_data)
12491 AccelGroupParserData *accel_data;
12492 GSList *accel_groups;
12493 GtkAccelGroup *accel_group;
12495 g_return_if_fail (GTK_IS_WIDGET (widget));
12496 g_return_if_fail (GTK_IS_WIDGET (toplevel));
12497 g_return_if_fail (user_data != NULL);
12499 accel_data = (AccelGroupParserData*)user_data;
12500 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
12501 if (g_slist_length (accel_groups) == 0)
12503 accel_group = gtk_accel_group_new ();
12504 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
12508 g_assert (g_slist_length (accel_groups) == 1);
12509 accel_group = g_slist_nth_data (accel_groups, 0);
12512 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
12513 accel_data->signal,
12516 accel_data->modifiers,
12517 GTK_ACCEL_VISIBLE);
12519 g_object_unref (accel_data->object);
12520 g_free (accel_data->signal);
12521 g_slice_free (AccelGroupParserData, accel_data);
12525 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
12526 GtkBuilder *builder,
12528 const gchar *tagname,
12529 gpointer user_data)
12531 AccelGroupParserData *accel_data;
12532 AccessibilitySubParserData *a11y_data;
12533 GtkWidget *toplevel;
12535 if (strcmp (tagname, "accelerator") == 0)
12537 accel_data = (AccelGroupParserData*)user_data;
12538 g_assert (accel_data->object);
12540 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12542 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12544 else if (strcmp (tagname, "accessibility") == 0)
12546 a11y_data = (AccessibilitySubParserData*)user_data;
12548 if (a11y_data->actions)
12550 AtkObject *accessible;
12555 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12557 action = ATK_ACTION (accessible);
12558 n_actions = atk_action_get_n_actions (action);
12560 for (l = a11y_data->actions; l; l = l->next)
12562 AtkActionData *action_data = (AtkActionData*)l->data;
12564 for (i = 0; i < n_actions; i++)
12565 if (strcmp (atk_action_get_name (action, i),
12566 action_data->action_name) == 0)
12571 gchar *description;
12573 if (action_data->translatable && action_data->description->len)
12574 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12575 action_data->context,
12576 action_data->description->str);
12578 description = action_data->description->str;
12580 atk_action_set_description (action, i, description);
12584 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12585 g_slist_free (a11y_data->actions);
12588 if (a11y_data->relations)
12589 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12590 a11y_data->relations);
12592 g_slice_free (AccessibilitySubParserData, a11y_data);
12597 gtk_widget_real_get_width (GtkWidget *widget,
12598 gint *minimum_size,
12599 gint *natural_size)
12609 gtk_widget_real_get_height (GtkWidget *widget,
12610 gint *minimum_size,
12611 gint *natural_size)
12621 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12623 gint *minimum_height,
12624 gint *natural_height)
12626 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12630 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12632 gint *minimum_width,
12633 gint *natural_width)
12635 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12639 * gtk_widget_get_halign:
12640 * @widget: a #GtkWidget
12642 * Gets the value of the #GtkWidget:halign property.
12644 * Returns: the horizontal alignment of @widget
12647 gtk_widget_get_halign (GtkWidget *widget)
12649 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12650 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12654 * gtk_widget_set_halign:
12655 * @widget: a #GtkWidget
12656 * @align: the horizontal alignment
12658 * Sets the horizontal alignment of @widget.
12659 * See the #GtkWidget:halign property.
12662 gtk_widget_set_halign (GtkWidget *widget,
12665 GtkWidgetAuxInfo *aux_info;
12667 g_return_if_fail (GTK_IS_WIDGET (widget));
12669 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12671 if (aux_info->halign == align)
12674 aux_info->halign = align;
12675 gtk_widget_queue_resize (widget);
12676 g_object_notify (G_OBJECT (widget), "halign");
12680 * gtk_widget_get_valign:
12681 * @widget: a #GtkWidget
12683 * Gets the value of the #GtkWidget:valign property.
12685 * Returns: the vertical alignment of @widget
12688 gtk_widget_get_valign (GtkWidget *widget)
12690 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12691 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12695 * gtk_widget_set_valign:
12696 * @widget: a #GtkWidget
12697 * @align: the vertical alignment
12699 * Sets the vertical alignment of @widget.
12700 * See the #GtkWidget:valign property.
12703 gtk_widget_set_valign (GtkWidget *widget,
12706 GtkWidgetAuxInfo *aux_info;
12708 g_return_if_fail (GTK_IS_WIDGET (widget));
12710 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12712 if (aux_info->valign == align)
12715 aux_info->valign = align;
12716 gtk_widget_queue_resize (widget);
12717 g_object_notify (G_OBJECT (widget), "valign");
12721 * gtk_widget_get_margin_left:
12722 * @widget: a #GtkWidget
12724 * Gets the value of the #GtkWidget:margin-left property.
12726 * Returns: The left margin of @widget
12729 gtk_widget_get_margin_left (GtkWidget *widget)
12731 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12733 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12737 * gtk_widget_set_margin_left:
12738 * @widget: a #GtkWidget
12739 * @margin: the left margin
12741 * Sets the left margin of @widget.
12742 * See the #GtkWidget:margin-left property.
12745 gtk_widget_set_margin_left (GtkWidget *widget,
12748 GtkWidgetAuxInfo *aux_info;
12750 g_return_if_fail (GTK_IS_WIDGET (widget));
12751 g_return_if_fail (margin <= G_MAXINT16);
12753 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12755 if (aux_info->margin.left == margin)
12758 aux_info->margin.left = margin;
12759 gtk_widget_queue_resize (widget);
12760 g_object_notify (G_OBJECT (widget), "margin-left");
12764 * gtk_widget_get_margin_right:
12765 * @widget: a #GtkWidget
12767 * Gets the value of the #GtkWidget:margin-right property.
12769 * Returns: The left margin of @widget
12772 gtk_widget_get_margin_right (GtkWidget *widget)
12774 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12776 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12780 * gtk_widget_set_margin_right:
12781 * @widget: a #GtkWidget
12782 * @margin: the right margin
12784 * Sets the right margin of @widget.
12785 * See the #GtkWidget:margin-right property.
12788 gtk_widget_set_margin_right (GtkWidget *widget,
12791 GtkWidgetAuxInfo *aux_info;
12793 g_return_if_fail (GTK_IS_WIDGET (widget));
12794 g_return_if_fail (margin <= G_MAXINT16);
12796 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12798 if (aux_info->margin.right == margin)
12801 aux_info->margin.right = margin;
12802 gtk_widget_queue_resize (widget);
12803 g_object_notify (G_OBJECT (widget), "margin-right");
12807 * gtk_widget_get_margin_top:
12808 * @widget: a #GtkWidget
12810 * Gets the value of the #GtkWidget:margin-top property.
12812 * Returns: The top margin of @widget
12815 gtk_widget_get_margin_top (GtkWidget *widget)
12817 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12819 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12823 * gtk_widget_set_margin_top:
12824 * @widget: a #GtkWidget
12825 * @margin: the top margin
12827 * Sets the top margin of @widget.
12828 * See the #GtkWidget:margin-top property.
12831 gtk_widget_set_margin_top (GtkWidget *widget,
12834 GtkWidgetAuxInfo *aux_info;
12836 g_return_if_fail (GTK_IS_WIDGET (widget));
12837 g_return_if_fail (margin <= G_MAXINT16);
12839 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12841 if (aux_info->margin.top == margin)
12844 aux_info->margin.top = margin;
12845 gtk_widget_queue_resize (widget);
12846 g_object_notify (G_OBJECT (widget), "margin-top");
12850 * gtk_widget_get_margin_bottom:
12851 * @widget: a #GtkWidget
12853 * Gets the value of the #GtkWidget:margin-bottom property.
12855 * Returns: The bottom margin of @widget
12858 gtk_widget_get_margin_bottom (GtkWidget *widget)
12860 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12862 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12866 * gtk_widget_set_margin_bottom:
12867 * @widget: a #GtkWidget
12868 * @margin: the bottom margin
12870 * Sets the bottom margin of @widget.
12871 * See the #GtkWidget:margin-bottom property.
12874 gtk_widget_set_margin_bottom (GtkWidget *widget,
12877 GtkWidgetAuxInfo *aux_info;
12879 g_return_if_fail (GTK_IS_WIDGET (widget));
12880 g_return_if_fail (margin <= G_MAXINT16);
12882 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12884 if (aux_info->margin.bottom == margin)
12887 aux_info->margin.bottom = margin;
12888 gtk_widget_queue_resize (widget);
12889 g_object_notify (G_OBJECT (widget), "margin-bottom");
12893 * gtk_widget_get_clipboard:
12894 * @widget: a #GtkWidget
12895 * @selection: a #GdkAtom which identifies the clipboard
12896 * to use. %GDK_SELECTION_CLIPBOARD gives the
12897 * default clipboard. Another common value
12898 * is %GDK_SELECTION_PRIMARY, which gives
12899 * the primary X selection.
12901 * Returns the clipboard object for the given selection to
12902 * be used with @widget. @widget must have a #GdkDisplay
12903 * associated with it, so must be attached to a toplevel
12906 * Return value: (transfer none): the appropriate clipboard object. If no
12907 * clipboard already exists, a new one will
12908 * be created. Once a clipboard object has
12909 * been created, it is persistent for all time.
12914 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12916 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12917 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12919 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12924 * gtk_widget_list_mnemonic_labels:
12925 * @widget: a #GtkWidget
12927 * Returns a newly allocated list of the widgets, normally labels, for
12928 * which this widget is the target of a mnemonic (see for example,
12929 * gtk_label_set_mnemonic_widget()).
12931 * The widgets in the list are not individually referenced. If you
12932 * want to iterate through the list and perform actions involving
12933 * callbacks that might destroy the widgets, you
12934 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12935 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12936 * widgets afterwards.
12938 * Return value: (element-type GtkWidget) (transfer container): the list of
12939 * mnemonic labels; free this list
12940 * with g_list_free() when you are done with it.
12945 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12947 GList *list = NULL;
12950 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12952 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12953 list = g_list_prepend (list, l->data);
12959 * gtk_widget_add_mnemonic_label:
12960 * @widget: a #GtkWidget
12961 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12963 * Adds a widget to the list of mnemonic labels for
12964 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12965 * list of mnemonic labels for the widget is cleared when the
12966 * widget is destroyed, so the caller must make sure to update
12967 * its internal state at this point as well, by using a connection
12968 * to the #GtkWidget::destroy signal or a weak notifier.
12973 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12976 GSList *old_list, *new_list;
12978 g_return_if_fail (GTK_IS_WIDGET (widget));
12979 g_return_if_fail (GTK_IS_WIDGET (label));
12981 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12982 new_list = g_slist_prepend (old_list, label);
12984 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12985 new_list, (GDestroyNotify) g_slist_free);
12989 * gtk_widget_remove_mnemonic_label:
12990 * @widget: a #GtkWidget
12991 * @label: a #GtkWidget that was previously set as a mnemnic label for
12992 * @widget with gtk_widget_add_mnemonic_label().
12994 * Removes a widget from the list of mnemonic labels for
12995 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12996 * must have previously been added to the list with
12997 * gtk_widget_add_mnemonic_label().
13002 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
13005 GSList *old_list, *new_list;
13007 g_return_if_fail (GTK_IS_WIDGET (widget));
13008 g_return_if_fail (GTK_IS_WIDGET (label));
13010 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
13011 new_list = g_slist_remove (old_list, label);
13014 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
13015 new_list, (GDestroyNotify) g_slist_free);
13019 * gtk_widget_get_no_show_all:
13020 * @widget: a #GtkWidget
13022 * Returns the current value of the #GtkWidget:no-show-all property,
13023 * which determines whether calls to gtk_widget_show_all()
13024 * will affect this widget.
13026 * Return value: the current value of the "no-show-all" property.
13031 gtk_widget_get_no_show_all (GtkWidget *widget)
13033 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13035 return widget->priv->no_show_all;
13039 * gtk_widget_set_no_show_all:
13040 * @widget: a #GtkWidget
13041 * @no_show_all: the new value for the "no-show-all" property
13043 * Sets the #GtkWidget:no-show-all property, which determines whether
13044 * calls to gtk_widget_show_all() will affect this widget.
13046 * This is mostly for use in constructing widget hierarchies with externally
13047 * controlled visibility, see #GtkUIManager.
13052 gtk_widget_set_no_show_all (GtkWidget *widget,
13053 gboolean no_show_all)
13055 g_return_if_fail (GTK_IS_WIDGET (widget));
13057 no_show_all = (no_show_all != FALSE);
13059 if (widget->priv->no_show_all != no_show_all)
13061 widget->priv->no_show_all = no_show_all;
13063 g_object_notify (G_OBJECT (widget), "no-show-all");
13069 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
13070 gboolean has_tooltip,
13073 GtkWidgetPrivate *priv = widget->priv;
13074 gboolean priv_has_tooltip;
13076 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
13077 quark_has_tooltip));
13079 if (priv_has_tooltip != has_tooltip || force)
13081 priv_has_tooltip = has_tooltip;
13083 if (priv_has_tooltip)
13085 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
13086 gdk_window_set_events (priv->window,
13087 gdk_window_get_events (priv->window) |
13088 GDK_LEAVE_NOTIFY_MASK |
13089 GDK_POINTER_MOTION_MASK |
13090 GDK_POINTER_MOTION_HINT_MASK);
13092 if (gtk_widget_get_has_window (widget))
13093 gtk_widget_add_events (widget,
13094 GDK_LEAVE_NOTIFY_MASK |
13095 GDK_POINTER_MOTION_MASK |
13096 GDK_POINTER_MOTION_HINT_MASK);
13099 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
13100 GUINT_TO_POINTER (priv_has_tooltip));
13105 * gtk_widget_set_tooltip_window:
13106 * @widget: a #GtkWidget
13107 * @custom_window: (allow-none): a #GtkWindow, or %NULL
13109 * Replaces the default, usually yellow, window used for displaying
13110 * tooltips with @custom_window. GTK+ will take care of showing and
13111 * hiding @custom_window at the right moment, to behave likewise as
13112 * the default tooltip window. If @custom_window is %NULL, the default
13113 * tooltip window will be used.
13115 * If the custom window should have the default theming it needs to
13116 * have the name "gtk-tooltip", see gtk_widget_set_name().
13121 gtk_widget_set_tooltip_window (GtkWidget *widget,
13122 GtkWindow *custom_window)
13124 gboolean has_tooltip;
13125 gchar *tooltip_markup;
13127 g_return_if_fail (GTK_IS_WIDGET (widget));
13128 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
13130 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
13133 g_object_ref (custom_window);
13135 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
13136 custom_window, g_object_unref);
13138 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
13139 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
13141 if (has_tooltip && gtk_widget_get_visible (widget))
13142 gtk_widget_queue_tooltip_query (widget);
13146 * gtk_widget_get_tooltip_window:
13147 * @widget: a #GtkWidget
13149 * Returns the #GtkWindow of the current tooltip. This can be the
13150 * GtkWindow created by default, or the custom tooltip window set
13151 * using gtk_widget_set_tooltip_window().
13153 * Return value: (transfer none): The #GtkWindow of the current tooltip.
13158 gtk_widget_get_tooltip_window (GtkWidget *widget)
13160 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13162 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
13166 * gtk_widget_trigger_tooltip_query:
13167 * @widget: a #GtkWidget
13169 * Triggers a tooltip query on the display where the toplevel of @widget
13170 * is located. See gtk_tooltip_trigger_tooltip_query() for more
13176 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
13178 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
13181 static guint tooltip_query_id;
13182 static GSList *tooltip_query_displays;
13185 tooltip_query_idle (gpointer data)
13187 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
13188 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
13189 g_slist_free (tooltip_query_displays);
13191 tooltip_query_displays = NULL;
13192 tooltip_query_id = 0;
13198 gtk_widget_queue_tooltip_query (GtkWidget *widget)
13200 GdkDisplay *display;
13202 display = gtk_widget_get_display (widget);
13204 if (!g_slist_find (tooltip_query_displays, display))
13205 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
13207 if (tooltip_query_id == 0)
13208 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
13212 * gtk_widget_set_tooltip_text:
13213 * @widget: a #GtkWidget
13214 * @text: the contents of the tooltip for @widget
13216 * Sets @text as the contents of the tooltip. This function will take
13217 * care of setting #GtkWidget:has-tooltip to %TRUE and of the default
13218 * handler for the #GtkWidget::query-tooltip signal.
13220 * See also the #GtkWidget:tooltip-text property and gtk_tooltip_set_text().
13225 gtk_widget_set_tooltip_text (GtkWidget *widget,
13228 g_return_if_fail (GTK_IS_WIDGET (widget));
13230 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
13234 * gtk_widget_get_tooltip_text:
13235 * @widget: a #GtkWidget
13237 * Gets the contents of the tooltip for @widget.
13239 * Return value: the tooltip text, or %NULL. You should free the
13240 * returned string with g_free() when done.
13245 gtk_widget_get_tooltip_text (GtkWidget *widget)
13247 gchar *text = NULL;
13249 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13251 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
13257 * gtk_widget_set_tooltip_markup:
13258 * @widget: a #GtkWidget
13259 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
13261 * Sets @markup as the contents of the tooltip, which is marked up with
13262 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
13264 * This function will take care of setting #GtkWidget:has-tooltip to %TRUE
13265 * and of the default handler for the #GtkWidget::query-tooltip signal.
13267 * See also the #GtkWidget:tooltip-markup property and
13268 * gtk_tooltip_set_markup().
13273 gtk_widget_set_tooltip_markup (GtkWidget *widget,
13274 const gchar *markup)
13276 g_return_if_fail (GTK_IS_WIDGET (widget));
13278 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
13282 * gtk_widget_get_tooltip_markup:
13283 * @widget: a #GtkWidget
13285 * Gets the contents of the tooltip for @widget.
13287 * Return value: the tooltip text, or %NULL. You should free the
13288 * returned string with g_free() when done.
13293 gtk_widget_get_tooltip_markup (GtkWidget *widget)
13295 gchar *text = NULL;
13297 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13299 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
13305 * gtk_widget_set_has_tooltip:
13306 * @widget: a #GtkWidget
13307 * @has_tooltip: whether or not @widget has a tooltip.
13309 * Sets the has-tooltip property on @widget to @has_tooltip. See
13310 * #GtkWidget:has-tooltip for more information.
13315 gtk_widget_set_has_tooltip (GtkWidget *widget,
13316 gboolean has_tooltip)
13318 g_return_if_fail (GTK_IS_WIDGET (widget));
13320 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
13324 * gtk_widget_get_has_tooltip:
13325 * @widget: a #GtkWidget
13327 * Returns the current value of the has-tooltip property. See
13328 * #GtkWidget:has-tooltip for more information.
13330 * Return value: current value of has-tooltip on @widget.
13335 gtk_widget_get_has_tooltip (GtkWidget *widget)
13337 gboolean has_tooltip = FALSE;
13339 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13341 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
13343 return has_tooltip;
13347 * gtk_widget_get_allocation:
13348 * @widget: a #GtkWidget
13349 * @allocation: (out): a pointer to a #GtkAllocation to copy to
13351 * Retrieves the widget's allocation.
13353 * Note, when implementing a #GtkContainer: a widget's allocation will
13354 * be its "adjusted" allocation, that is, the widget's parent
13355 * container typically calls gtk_widget_size_allocate() with an
13356 * allocation, and that allocation is then adjusted (to handle margin
13357 * and alignment for example) before assignment to the widget.
13358 * gtk_widget_get_allocation() returns the adjusted allocation that
13359 * was actually assigned to the widget. The adjusted allocation is
13360 * guaranteed to be completely contained within the
13361 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
13362 * is guaranteed that its children stay inside the assigned bounds,
13363 * but not that they have exactly the bounds the container assigned.
13364 * There is no way to get the original allocation assigned by
13365 * gtk_widget_size_allocate(), since it isn't stored; if a container
13366 * implementation needs that information it will have to track it itself.
13371 gtk_widget_get_allocation (GtkWidget *widget,
13372 GtkAllocation *allocation)
13374 GtkWidgetPrivate *priv;
13376 g_return_if_fail (GTK_IS_WIDGET (widget));
13377 g_return_if_fail (allocation != NULL);
13379 priv = widget->priv;
13381 *allocation = priv->allocation;
13385 * gtk_widget_set_allocation:
13386 * @widget: a #GtkWidget
13387 * @allocation: a pointer to a #GtkAllocation to copy from
13389 * Sets the widget's allocation. This should not be used
13390 * directly, but from within a widget's size_allocate method.
13392 * The allocation set should be the "adjusted" or actual
13393 * allocation. If you're implementing a #GtkContainer, you want to use
13394 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
13395 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
13396 * allocation inside gtk_widget_size_allocate() to create an adjusted
13402 gtk_widget_set_allocation (GtkWidget *widget,
13403 const GtkAllocation *allocation)
13405 GtkWidgetPrivate *priv;
13407 g_return_if_fail (GTK_IS_WIDGET (widget));
13408 g_return_if_fail (allocation != NULL);
13410 priv = widget->priv;
13412 priv->allocation = *allocation;
13416 * gtk_widget_get_allocated_width:
13417 * @widget: the widget to query
13419 * Returns the width that has currently been allocated to @widget.
13420 * This function is intended to be used when implementing handlers
13421 * for the #GtkWidget::draw function.
13423 * Returns: the width of the @widget
13426 gtk_widget_get_allocated_width (GtkWidget *widget)
13428 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13430 return widget->priv->allocation.width;
13434 * gtk_widget_get_allocated_height:
13435 * @widget: the widget to query
13437 * Returns the height that has currently been allocated to @widget.
13438 * This function is intended to be used when implementing handlers
13439 * for the #GtkWidget::draw function.
13441 * Returns: the height of the @widget
13444 gtk_widget_get_allocated_height (GtkWidget *widget)
13446 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
13448 return widget->priv->allocation.height;
13452 * gtk_widget_get_requisition:
13453 * @widget: a #GtkWidget
13454 * @requisition: (out): a pointer to a #GtkRequisition to copy to
13456 * Retrieves the widget's requisition.
13458 * This function should only be used by widget implementations in
13459 * order to figure whether the widget's requisition has actually
13460 * changed after some internal state change (so that they can call
13461 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
13463 * Normally, gtk_widget_size_request() should be used.
13467 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
13468 * removed, If you need to cache sizes across requests and allocations,
13469 * add an explicit cache to the widget in question instead.
13472 gtk_widget_get_requisition (GtkWidget *widget,
13473 GtkRequisition *requisition)
13475 g_return_if_fail (GTK_IS_WIDGET (widget));
13476 g_return_if_fail (requisition != NULL);
13478 gtk_widget_get_preferred_size (widget, requisition, NULL);
13482 * gtk_widget_set_window:
13483 * @widget: a #GtkWidget
13484 * @window: a #GdkWindow
13486 * Sets a widget's window. This function should only be used in a
13487 * widget's #GtkWidget::realize implementation. The %window passed is
13488 * usually either new window created with gdk_window_new(), or the
13489 * window of its parent widget as returned by
13490 * gtk_widget_get_parent_window().
13492 * Widgets must indicate whether they will create their own #GdkWindow
13493 * by calling gtk_widget_set_has_window(). This is usually done in the
13494 * widget's init() function.
13496 * <note><para>This function does not add any reference to @window.</para></note>
13501 gtk_widget_set_window (GtkWidget *widget,
13504 GtkWidgetPrivate *priv;
13506 g_return_if_fail (GTK_IS_WIDGET (widget));
13507 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
13509 priv = widget->priv;
13511 if (priv->window != window)
13513 priv->window = window;
13514 g_object_notify (G_OBJECT (widget), "window");
13519 * gtk_widget_get_window:
13520 * @widget: a #GtkWidget
13522 * Returns the widget's window if it is realized, %NULL otherwise
13524 * Return value: (transfer none): @widget's window.
13529 gtk_widget_get_window (GtkWidget *widget)
13531 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13533 return widget->priv->window;
13537 * gtk_widget_get_support_multidevice:
13538 * @widget: a #GtkWidget
13540 * Returns %TRUE if @widget is multiple pointer aware. See
13541 * gtk_widget_set_support_multidevice() for more information.
13543 * Returns: %TRUE is @widget is multidevice aware.
13546 gtk_widget_get_support_multidevice (GtkWidget *widget)
13548 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13550 return widget->priv->multidevice;
13554 * gtk_widget_set_support_multidevice:
13555 * @widget: a #GtkWidget
13556 * @support_multidevice: %TRUE to support input from multiple devices.
13558 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13559 * @widget will start receiving multiple, per device enter/leave events. Note
13560 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13561 * gdk_window_set_support_multidevice() will have to be called manually on them.
13566 gtk_widget_set_support_multidevice (GtkWidget *widget,
13567 gboolean support_multidevice)
13569 GtkWidgetPrivate *priv;
13571 g_return_if_fail (GTK_IS_WIDGET (widget));
13573 priv = widget->priv;
13575 if (support_multidevice)
13577 priv->multidevice = TRUE;
13578 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13582 priv->multidevice = FALSE;
13583 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13586 if (gtk_widget_get_realized (widget))
13587 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13591 _gtk_widget_set_has_focus (GtkWidget *widget,
13592 gboolean has_focus)
13594 widget->priv->has_focus = has_focus;
13598 * gtk_widget_send_focus_change:
13599 * @widget: a #GtkWidget
13600 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13602 * Sends the focus change @event to @widget
13604 * This function is not meant to be used by applications. The only time it
13605 * should be used is when it is necessary for a #GtkWidget to assign focus
13606 * to a widget that is semantically owned by the first widget even though
13607 * it's not a direct child - for instance, a search entry in a floating
13608 * window similar to the quick search in #GtkTreeView.
13610 * An example of its usage is:
13613 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13615 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13616 * fevent->focus_change.in = TRUE;
13617 * fevent->focus_change.window = gtk_widget_get_window (widget);
13618 * if (fevent->focus_change.window != NULL)
13619 * g_object_ref (fevent->focus_change.window);
13621 * gtk_widget_send_focus_change (widget, fevent);
13623 * gdk_event_free (event);
13626 * Return value: the return value from the event signal emission: %TRUE
13627 * if the event was handled, and %FALSE otherwise
13632 gtk_widget_send_focus_change (GtkWidget *widget,
13637 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13638 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13640 g_object_ref (widget);
13642 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13644 res = gtk_widget_event (widget, event);
13646 g_object_notify (G_OBJECT (widget), "has-focus");
13648 g_object_unref (widget);
13654 * gtk_widget_in_destruction:
13655 * @widget: a #GtkWidget
13657 * Returns whether the widget is currently being destroyed.
13658 * This information can sometimes be used to avoid doing
13659 * unnecessary work.
13661 * Returns: %TRUE if @widget is being destroyed
13664 gtk_widget_in_destruction (GtkWidget *widget)
13666 return widget->priv->in_destruction;
13670 _gtk_widget_get_resize_pending (GtkWidget *widget)
13672 return widget->priv->resize_pending;
13676 _gtk_widget_set_resize_pending (GtkWidget *widget,
13677 gboolean resize_pending)
13679 widget->priv->resize_pending = resize_pending;
13683 _gtk_widget_get_in_reparent (GtkWidget *widget)
13685 return widget->priv->in_reparent;
13689 _gtk_widget_set_in_reparent (GtkWidget *widget,
13690 gboolean in_reparent)
13692 widget->priv->in_reparent = in_reparent;
13696 _gtk_widget_get_anchored (GtkWidget *widget)
13698 return widget->priv->anchored;
13702 _gtk_widget_set_anchored (GtkWidget *widget,
13705 widget->priv->anchored = anchored;
13709 _gtk_widget_get_shadowed (GtkWidget *widget)
13711 return widget->priv->shadowed;
13715 _gtk_widget_set_shadowed (GtkWidget *widget,
13718 widget->priv->shadowed = shadowed;
13722 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13724 return widget->priv->alloc_needed;
13728 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13729 gboolean alloc_needed)
13731 widget->priv->alloc_needed = alloc_needed;
13735 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13737 return widget->priv->width_request_needed;
13741 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13742 gboolean width_request_needed)
13744 widget->priv->width_request_needed = width_request_needed;
13748 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13750 return widget->priv->height_request_needed;
13754 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13755 gboolean height_request_needed)
13757 widget->priv->height_request_needed = height_request_needed;
13761 * gtk_widget_get_path:
13762 * @widget: a #GtkWidget
13764 * Returns the #GtkWidgetPath representing @widget, if the widget
13765 * is not connected to a toplevel widget, a partial path will be
13768 * Returns: (transfer none): The #GtkWidgetPath representing @widget
13771 gtk_widget_get_path (GtkWidget *widget)
13773 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13775 if (!widget->priv->path)
13780 parent = widget->priv->parent;
13783 widget->priv->path = gtk_container_get_path_for_child (GTK_CONTAINER (parent), widget);
13786 /* Widget is either toplevel or unparented, treat both
13787 * as toplevels style wise, since there are situations
13788 * where style properties might be retrieved on that
13791 widget->priv->path = gtk_widget_path_new ();
13794 pos = gtk_widget_path_append_type (widget->priv->path, G_OBJECT_TYPE (widget));
13796 if (widget->priv->name)
13797 gtk_widget_path_iter_set_name (widget->priv->path, pos, widget->priv->name);
13800 return widget->priv->path;
13804 style_context_changed (GtkStyleContext *context,
13805 gpointer user_data)
13807 GtkWidget *widget = user_data;
13809 g_signal_emit (widget, widget_signals[STYLE_UPDATED], 0);
13813 * gtk_widget_get_style_context:
13814 * @widget: a #GtkWidget
13816 * Returns the style context associated to @widget.
13818 * Returns: (transfer none): a #GtkStyleContext. This memory is owned by @widget and
13819 * must not be freed.
13822 gtk_widget_get_style_context (GtkWidget *widget)
13824 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
13826 if (G_UNLIKELY (!widget->priv->context))
13828 widget->priv->context = g_object_new (GTK_TYPE_STYLE_CONTEXT,
13829 "direction", gtk_widget_get_direction (widget),
13832 g_signal_connect (widget->priv->context, "changed",
13833 G_CALLBACK (style_context_changed), widget);
13835 gtk_style_context_set_screen (widget->priv->context,
13836 gtk_widget_get_screen (widget));
13838 _gtk_widget_update_path (widget);
13839 gtk_style_context_set_path (widget->priv->context,
13840 widget->priv->path);
13843 return widget->priv->context;