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"
66 * @Short_description: Base class for all widgets
69 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
70 * widget lifecycle, states and style.
72 * <refsect2 id="geometry-management">
73 * <title>Height-for-width Geometry Management</title>
75 * GTK+ uses a height-for-width (and width-for-height) geometry management system.
76 * Height-for-width means that a widget can change how much vertical space it needs,
77 * depending on the amount of horizontal space that it is given (and similar for
78 * width-for-height). The most common example is a label that reflows to fill up the
79 * available width, wraps to fewer lines, and therefore needs less height.
81 * GTK+'s traditional two-pass <link linkend="size-allocation">size-allocation</link>
82 * algorithm does not allow this flexibility. #GtkWidget provides a default
83 * implementation of the height-for-width methods for existing widgets,
84 * which always requests the same height, regardless of the available width.
86 * Some important things to keep in mind when implementing
87 * height-for-width and when using it in container
90 * The geometry management system will query a logical hierarchy in
91 * only one orientation at a time. When widgets are initially queried
92 * for their minimum sizes it is generally done in a dual pass
93 * in the direction chosen by the toplevel.
95 * For instance when queried in the normal height-for-width mode:
96 * First the default minimum and natural width for each widget
97 * in the interface will computed and collectively returned to
98 * the toplevel by way of gtk_widget_get_preferred_width().
99 * Next, the toplevel will use the minimum width to query for the
100 * minimum height contextual to that width using
101 * gtk_widget_get_preferred_height_for_width(), which will also
102 * be a highly recursive operation. This minimum-for-minimum size can
103 * be used to set the minimum size constraint on the toplevel.
105 * When allocating, each container can use the minimum and natural
106 * sizes reported by their children to allocate natural sizes and
107 * expose as much content as possible with the given allocation.
109 * That means that the request operation at allocation time will
110 * usually fire again in contexts of different allocated sizes than
111 * the ones originally queried for. #GtkWidget caches a
112 * small number of results to avoid re-querying for the same
113 * allocated size in one allocation cycle.
115 * A widget that does not actually do height-for-width
116 * or width-for-height size negotiations only has to implement
117 * #GtkWidgetClass.get_preferred_width() and
118 * #GtkWidgetClass.get_preferred_height().
120 * If a widget does move content around to smartly use up the
121 * allocated size, then it must support the request properly in
122 * both orientations; even if the request only makes sense in
125 * For instance, a #GtkLabel that does height-for-width word wrapping
126 * will not expect to have #GtkWidgetClass.get_preferred_height() called because that
127 * call is specific to a width-for-height request. In this case the
128 * label must return the heights contextual to its minimum possible
129 * width. By following this rule any widget that handles height-for-width
130 * or width-for-height requests will always be allocated at least
131 * enough space to fit its own content.
133 * Often a widget needs to get its own request during size request or
134 * allocation, for example when computing height it may need to also
135 * compute width, or when deciding how to use an allocation the widget may
136 * need to know its natural size. In these cases, the widget should be
137 * careful to call its virtual methods directly, like this:
139 * <title>Widget calling its own size request method.</title>
141 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget), &min, &natural);
145 * It will not work to use the wrapper functions, such as
146 * gtk_widget_get_preferred_width(), inside your own size request
147 * implementation. These return a request adjusted by #GtkSizeGroup
148 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
149 * widget used the wrappers inside its virtual method implementations,
150 * then the adjustments (such as widget margins) would be applied
151 * twice. GTK+ therefore does not allow this and will warn if you try
154 * Of course if you are getting the size request for
155 * <emphasis>another</emphasis> widget, such as a child of a
156 * container, you <emphasis>must</emphasis> use the wrapper APIs;
157 * otherwise, you would not properly consider widget margins,
158 * #GtkSizeGroup, and so forth.
161 * <refsect2 id="style-properties">
162 * <title>Style Properties</title>
164 * <structname>GtkWidget</structname> introduces <firstterm>style
165 * properties</firstterm> - these are basically object properties that are stored
166 * not on the object, but in the style object associated to the widget. Style
167 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
168 * This mechanism is used for configuring such things as the location of the
169 * scrollbar arrows through the theme, giving theme authors more control over the
170 * look of applications without the need to write a theme engine in C.
173 * Use gtk_widget_class_install_style_property() to install style properties for
174 * a widget class, gtk_widget_class_find_style_property() or
175 * gtk_widget_class_list_style_properties() to get information about existing
176 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
177 * gtk_widget_style_get_valist() to obtain the value of a style property.
180 * <refsect2 id="GtkWidget-BUILDER-UI">
181 * <title>GtkWidget as GtkBuildable</title>
183 * The GtkWidget implementation of the GtkBuildable interface supports a
184 * custom <accelerator> element, which has attributes named key,
185 * modifiers and signal and allows to specify accelerators.
188 * <title>A UI definition fragment specifying an accelerator</title>
189 * <programlisting><![CDATA[
190 * <object class="GtkButton">
191 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
193 * ]]></programlisting>
196 * In addition to accelerators, <structname>GtkWidget</structname> also support a
197 * custom <accessible> element, which supports actions and relations.
198 * Properties on the accessible implementation of an object can be set by accessing the
199 * internal child "accessible" of a <structname>GtkWidget</structname>.
202 * <title>A UI definition fragment specifying an accessible</title>
203 * <programlisting><![CDATA[
204 * <object class="GtkButton" id="label1"/>
205 * <property name="label">I am a Label for a Button</property>
207 * <object class="GtkButton" id="button1">
209 * <action action_name="click" translatable="yes">Click the button.</action>
210 * <relation target="label1" type="labelled-by"/>
212 * <child internal-child="accessible">
213 * <object class="AtkObject" id="a11y-button1">
214 * <property name="AtkObject::name">Clickable Button</property>
218 * ]]></programlisting>
223 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
224 #define INIT_PATH_SIZE (512)
226 struct _GtkWidgetPrivate
228 /* The state of the widget. There are actually only
229 * 5 widget states (defined in "gtkenums.h")
234 /* The saved state of the widget. When a widget's state
235 * is changed to GTK_STATE_INSENSITIVE via
236 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
237 * the old state is kept around in this field. The state
238 * will be restored once the widget gets sensitive again.
240 guint saved_state : 3;
244 guint in_destruction : 1;
247 guint composite_child : 1;
253 guint parent_sensitive : 1;
256 guint can_default : 1;
257 guint has_default : 1;
258 guint receives_default : 1;
262 guint user_style : 1;
263 guint app_paintable : 1;
264 guint double_buffered : 1;
265 guint redraw_on_alloc : 1;
266 guint no_show_all : 1;
267 guint child_visible : 1;
268 guint multidevice : 1;
269 guint has_shape_mask : 1;
270 guint in_reparent : 1;
271 guint resize_pending : 1;
272 guint alloc_needed : 1;
273 guint width_request_needed : 1;
274 guint height_request_needed : 1;
276 /* Expand-related flags */
277 guint need_compute_expand : 1; /* Need to recompute computed_[hv]_expand */
278 guint computed_hexpand : 1; /* computed results (composite of child flags) */
279 guint computed_vexpand : 1;
280 guint hexpand : 1; /* application-forced expand */
282 guint hexpand_set : 1; /* whether to use application-forced */
283 guint vexpand_set : 1; /* instead of computing from children */
285 /* The widget's name. If the widget does not have a name
286 * (the name is NULL), then its name (as returned by
287 * "gtk_widget_get_name") is its class's name.
288 * Among other things, the widget name is used to determine
289 * the style to use for a widget.
293 /* The style for the widget. The style contains the
294 * colors the widget should be drawn in for each state
295 * along with graphics contexts used to draw with and
296 * the font to use for text.
300 /* The widget's allocated size.
302 GtkAllocation allocation;
304 /* The widget's requested sizes */
305 SizeRequestCache requests;
307 /* The widget's window or its parent window if it does
308 * not have a window. (Which will be indicated by the
309 * GTK_NO_WINDOW flag being set).
313 /* The widget's parent.
343 BUTTON_RELEASE_EVENT,
358 PROPERTY_NOTIFY_EVENT,
359 SELECTION_CLEAR_EVENT,
360 SELECTION_REQUEST_EVENT,
361 SELECTION_NOTIFY_EVENT,
376 VISIBILITY_NOTIFY_EVENT,
380 ACCEL_CLOSURES_CHANGED,
406 PROP_RECEIVES_DEFAULT,
407 PROP_COMPOSITE_CHILD,
410 PROP_EXTENSION_EVENTS,
416 PROP_DOUBLE_BUFFERED,
431 typedef struct _GtkStateData GtkStateData;
436 guint state_restoration : 1;
437 guint parent_sensitive : 1;
438 guint use_forall : 1;
441 /* --- prototypes --- */
442 static void gtk_widget_class_init (GtkWidgetClass *klass);
443 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
444 static void gtk_widget_init (GtkWidget *widget);
445 static void gtk_widget_set_property (GObject *object,
449 static void gtk_widget_get_property (GObject *object,
453 static void gtk_widget_dispose (GObject *object);
454 static void gtk_widget_real_destroy (GtkWidget *object);
455 static void gtk_widget_finalize (GObject *object);
456 static void gtk_widget_real_show (GtkWidget *widget);
457 static void gtk_widget_real_hide (GtkWidget *widget);
458 static void gtk_widget_real_map (GtkWidget *widget);
459 static void gtk_widget_real_unmap (GtkWidget *widget);
460 static void gtk_widget_real_realize (GtkWidget *widget);
461 static void gtk_widget_real_unrealize (GtkWidget *widget);
462 static void gtk_widget_real_size_request (GtkWidget *widget,
463 GtkRequisition *requisition);
464 static void gtk_widget_real_size_allocate (GtkWidget *widget,
465 GtkAllocation *allocation);
466 static void gtk_widget_real_style_set (GtkWidget *widget,
467 GtkStyle *previous_style);
468 static void gtk_widget_real_direction_changed(GtkWidget *widget,
469 GtkTextDirection previous_direction);
471 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
472 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
475 gboolean keyboard_tip,
476 GtkTooltip *tooltip);
477 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
478 GtkWidgetHelpType help_type);
480 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
482 GParamSpec **pspecs);
483 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
485 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
487 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
488 GdkEventFocus *event);
489 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
490 GdkEventFocus *event);
491 static gboolean gtk_widget_real_focus (GtkWidget *widget,
492 GtkDirectionType direction);
493 static void gtk_widget_real_move_focus (GtkWidget *widget,
494 GtkDirectionType direction);
495 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
496 GtkDirectionType direction);
497 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
498 static void gtk_widget_update_pango_context (GtkWidget *widget);
499 static void gtk_widget_propagate_state (GtkWidget *widget,
501 static void gtk_widget_reset_rc_style (GtkWidget *widget);
502 static void gtk_widget_set_style_internal (GtkWidget *widget,
504 gboolean initial_emission);
505 static gint gtk_widget_event_internal (GtkWidget *widget,
507 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
508 gboolean group_cycling);
509 static void gtk_widget_real_get_width (GtkWidget *widget,
512 static void gtk_widget_real_get_height (GtkWidget *widget,
515 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
517 gint *minimum_height,
518 gint *natural_height);
519 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
522 gint *natural_width);
523 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
524 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
525 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
526 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
527 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
528 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
529 cairo_region_t *region);
530 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
531 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
532 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
535 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
536 gboolean has_tooltip,
538 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
539 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
541 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
542 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
544 const gchar *childname);
545 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
548 const GValue *value);
549 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
552 const gchar *tagname,
553 GMarkupParser *parser,
555 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
558 const gchar *tagname,
560 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
561 GtkBuilder *builder);
563 static void gtk_widget_real_get_width (GtkWidget *widget,
566 static void gtk_widget_real_get_height (GtkWidget *widget,
570 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
573 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
574 GtkOrientation orientation,
578 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
579 GtkAllocation *allocation);
581 static void gtk_widget_set_usize_internal (GtkWidget *widget,
584 GtkQueueResizeFlags flags);
586 static void gtk_widget_add_events_internal (GtkWidget *widget,
590 /* --- variables --- */
591 static gpointer gtk_widget_parent_class = NULL;
592 static guint widget_signals[LAST_SIGNAL] = { 0 };
593 static GtkStyle *gtk_default_style = NULL;
594 static guint composite_child_stack = 0;
595 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
596 static GParamSpecPool *style_property_spec_pool = NULL;
598 static GQuark quark_property_parser = 0;
599 static GQuark quark_aux_info = 0;
600 static GQuark quark_accel_path = 0;
601 static GQuark quark_accel_closures = 0;
602 static GQuark quark_event_mask = 0;
603 static GQuark quark_device_event_mask = 0;
604 static GQuark quark_extension_event_mode = 0;
605 static GQuark quark_parent_window = 0;
606 static GQuark quark_pointer_window = 0;
607 static GQuark quark_shape_info = 0;
608 static GQuark quark_input_shape_info = 0;
609 static GQuark quark_pango_context = 0;
610 static GQuark quark_rc_style = 0;
611 static GQuark quark_accessible_object = 0;
612 static GQuark quark_mnemonic_labels = 0;
613 static GQuark quark_tooltip_markup = 0;
614 static GQuark quark_has_tooltip = 0;
615 static GQuark quark_tooltip_window = 0;
616 static GQuark quark_visual = 0;
617 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
618 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
620 /* --- functions --- */
622 gtk_widget_get_type (void)
624 static GType widget_type = 0;
626 if (G_UNLIKELY (widget_type == 0))
628 const GTypeInfo widget_info =
630 sizeof (GtkWidgetClass),
631 NULL, /* base_init */
632 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
633 (GClassInitFunc) gtk_widget_class_init,
634 NULL, /* class_finalize */
635 NULL, /* class_init */
638 (GInstanceInitFunc) gtk_widget_init,
639 NULL, /* value_table */
642 const GInterfaceInfo accessibility_info =
644 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
645 (GInterfaceFinalizeFunc) NULL,
646 NULL /* interface data */
649 const GInterfaceInfo buildable_info =
651 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
652 (GInterfaceFinalizeFunc) NULL,
653 NULL /* interface data */
656 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
657 &widget_info, G_TYPE_FLAG_ABSTRACT);
659 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
660 &accessibility_info) ;
661 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
669 child_property_notify_dispatcher (GObject *object,
673 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
676 /* We guard against the draw signal callbacks modifying the state of the
677 * cairo context by surounding it with save/restore.
678 * Maybe we should also cairo_new_path() just to be sure?
681 gtk_widget_draw_marshaller (GClosure *closure,
682 GValue *return_value,
683 guint n_param_values,
684 const GValue *param_values,
685 gpointer invocation_hint,
686 gpointer marshal_data)
688 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
692 _gtk_marshal_BOOLEAN__BOXED (closure,
703 gtk_widget_class_init (GtkWidgetClass *klass)
705 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
706 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
707 GtkBindingSet *binding_set;
709 gtk_widget_parent_class = g_type_class_peek_parent (klass);
711 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
712 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
713 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
714 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
715 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
716 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
717 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
718 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
719 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
720 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
721 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
722 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
723 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
724 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
725 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
726 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
727 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
728 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
729 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
731 style_property_spec_pool = g_param_spec_pool_new (FALSE);
732 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
733 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
734 cpn_context.dispatcher = child_property_notify_dispatcher;
735 _gtk_widget_child_property_notify_context = &cpn_context;
737 gobject_class->dispose = gtk_widget_dispose;
738 gobject_class->finalize = gtk_widget_finalize;
739 gobject_class->set_property = gtk_widget_set_property;
740 gobject_class->get_property = gtk_widget_get_property;
742 klass->destroy = gtk_widget_real_destroy;
744 klass->activate_signal = 0;
745 klass->set_scroll_adjustments_signal = 0;
746 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
747 klass->show = gtk_widget_real_show;
748 klass->show_all = gtk_widget_show;
749 klass->hide = gtk_widget_real_hide;
750 klass->map = gtk_widget_real_map;
751 klass->unmap = gtk_widget_real_unmap;
752 klass->realize = gtk_widget_real_realize;
753 klass->unrealize = gtk_widget_real_unrealize;
754 klass->size_request = gtk_widget_real_size_request;
755 klass->size_allocate = gtk_widget_real_size_allocate;
756 klass->get_preferred_width = gtk_widget_real_get_width;
757 klass->get_preferred_height = gtk_widget_real_get_height;
758 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
759 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
760 klass->state_changed = NULL;
761 klass->parent_set = NULL;
762 klass->hierarchy_changed = NULL;
763 klass->style_set = gtk_widget_real_style_set;
764 klass->direction_changed = gtk_widget_real_direction_changed;
765 klass->grab_notify = NULL;
766 klass->child_notify = NULL;
768 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
769 klass->grab_focus = gtk_widget_real_grab_focus;
770 klass->focus = gtk_widget_real_focus;
772 klass->button_press_event = NULL;
773 klass->button_release_event = NULL;
774 klass->motion_notify_event = NULL;
775 klass->delete_event = NULL;
776 klass->destroy_event = NULL;
777 klass->key_press_event = gtk_widget_real_key_press_event;
778 klass->key_release_event = gtk_widget_real_key_release_event;
779 klass->enter_notify_event = NULL;
780 klass->leave_notify_event = NULL;
781 klass->configure_event = NULL;
782 klass->focus_in_event = gtk_widget_real_focus_in_event;
783 klass->focus_out_event = gtk_widget_real_focus_out_event;
784 klass->map_event = NULL;
785 klass->unmap_event = NULL;
786 klass->window_state_event = NULL;
787 klass->property_notify_event = _gtk_selection_property_notify;
788 klass->selection_clear_event = _gtk_selection_clear;
789 klass->selection_request_event = _gtk_selection_request;
790 klass->selection_notify_event = _gtk_selection_notify;
791 klass->selection_received = NULL;
792 klass->proximity_in_event = NULL;
793 klass->proximity_out_event = NULL;
794 klass->drag_begin = NULL;
795 klass->drag_end = NULL;
796 klass->drag_data_delete = NULL;
797 klass->drag_leave = NULL;
798 klass->drag_motion = NULL;
799 klass->drag_drop = NULL;
800 klass->drag_data_received = NULL;
801 klass->screen_changed = NULL;
802 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
803 klass->grab_broken_event = NULL;
804 klass->query_tooltip = gtk_widget_real_query_tooltip;
806 klass->show_help = gtk_widget_real_show_help;
808 /* Accessibility support */
809 klass->get_accessible = gtk_widget_real_get_accessible;
811 klass->no_expose_event = NULL;
813 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
814 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
816 g_object_class_install_property (gobject_class,
818 g_param_spec_string ("name",
820 P_("The name of the widget"),
822 GTK_PARAM_READWRITE));
823 g_object_class_install_property (gobject_class,
825 g_param_spec_object ("parent",
827 P_("The parent widget of this widget. Must be a Container widget"),
829 GTK_PARAM_READWRITE));
831 g_object_class_install_property (gobject_class,
833 g_param_spec_int ("width-request",
835 P_("Override for width request of the widget, or -1 if natural request should be used"),
839 GTK_PARAM_READWRITE));
840 g_object_class_install_property (gobject_class,
842 g_param_spec_int ("height-request",
843 P_("Height request"),
844 P_("Override for height request of the widget, or -1 if natural request should be used"),
848 GTK_PARAM_READWRITE));
849 g_object_class_install_property (gobject_class,
851 g_param_spec_boolean ("visible",
853 P_("Whether the widget is visible"),
855 GTK_PARAM_READWRITE));
856 g_object_class_install_property (gobject_class,
858 g_param_spec_boolean ("sensitive",
860 P_("Whether the widget responds to input"),
862 GTK_PARAM_READWRITE));
863 g_object_class_install_property (gobject_class,
865 g_param_spec_boolean ("app-paintable",
866 P_("Application paintable"),
867 P_("Whether the application will paint directly on the widget"),
869 GTK_PARAM_READWRITE));
870 g_object_class_install_property (gobject_class,
872 g_param_spec_boolean ("can-focus",
874 P_("Whether the widget can accept the input focus"),
876 GTK_PARAM_READWRITE));
877 g_object_class_install_property (gobject_class,
879 g_param_spec_boolean ("has-focus",
881 P_("Whether the widget has the input focus"),
883 GTK_PARAM_READWRITE));
884 g_object_class_install_property (gobject_class,
886 g_param_spec_boolean ("is-focus",
888 P_("Whether the widget is the focus widget within the toplevel"),
890 GTK_PARAM_READWRITE));
891 g_object_class_install_property (gobject_class,
893 g_param_spec_boolean ("can-default",
895 P_("Whether the widget can be the default widget"),
897 GTK_PARAM_READWRITE));
898 g_object_class_install_property (gobject_class,
900 g_param_spec_boolean ("has-default",
902 P_("Whether the widget is the default widget"),
904 GTK_PARAM_READWRITE));
905 g_object_class_install_property (gobject_class,
906 PROP_RECEIVES_DEFAULT,
907 g_param_spec_boolean ("receives-default",
908 P_("Receives default"),
909 P_("If TRUE, the widget will receive the default action when it is focused"),
911 GTK_PARAM_READWRITE));
912 g_object_class_install_property (gobject_class,
913 PROP_COMPOSITE_CHILD,
914 g_param_spec_boolean ("composite-child",
915 P_("Composite child"),
916 P_("Whether the widget is part of a composite widget"),
918 GTK_PARAM_READABLE));
919 g_object_class_install_property (gobject_class,
921 g_param_spec_object ("style",
923 P_("The style of the widget, which contains information about how it will look (colors etc)"),
925 GTK_PARAM_READWRITE));
926 g_object_class_install_property (gobject_class,
928 g_param_spec_flags ("events",
930 P_("The event mask that decides what kind of GdkEvents this widget gets"),
933 GTK_PARAM_READWRITE));
934 g_object_class_install_property (gobject_class,
935 PROP_EXTENSION_EVENTS,
936 g_param_spec_enum ("extension-events",
937 P_("Extension events"),
938 P_("The mask that decides what kind of extension events this widget gets"),
939 GDK_TYPE_EXTENSION_MODE,
940 GDK_EXTENSION_EVENTS_NONE,
941 GTK_PARAM_READWRITE));
942 g_object_class_install_property (gobject_class,
944 g_param_spec_boolean ("no-show-all",
946 P_("Whether gtk_widget_show_all() should not affect this widget"),
948 GTK_PARAM_READWRITE));
951 * GtkWidget:has-tooltip:
953 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
954 * A value of %TRUE indicates that @widget can have a tooltip, in this case
955 * the widget will be queried using #GtkWidget::query-tooltip to determine
956 * whether it will provide a tooltip or not.
958 * Note that setting this property to %TRUE for the first time will change
959 * the event masks of the GdkWindows of this widget to include leave-notify
960 * and motion-notify events. This cannot and will not be undone when the
961 * property is set to %FALSE again.
965 g_object_class_install_property (gobject_class,
967 g_param_spec_boolean ("has-tooltip",
969 P_("Whether this widget has a tooltip"),
971 GTK_PARAM_READWRITE));
973 * GtkWidget:tooltip-text:
975 * Sets the text of tooltip to be the given string.
977 * Also see gtk_tooltip_set_text().
979 * This is a convenience property which will take care of getting the
980 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
981 * will automatically be set to %TRUE and there will be taken care of
982 * #GtkWidget::query-tooltip in the default signal handler.
986 g_object_class_install_property (gobject_class,
988 g_param_spec_string ("tooltip-text",
990 P_("The contents of the tooltip for this widget"),
992 GTK_PARAM_READWRITE));
994 * GtkWidget:tooltip-markup:
996 * Sets the text of tooltip to be the given string, which is marked up
997 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
998 * Also see gtk_tooltip_set_markup().
1000 * This is a convenience property which will take care of getting the
1001 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
1002 * will automatically be set to %TRUE and there will be taken care of
1003 * #GtkWidget::query-tooltip in the default signal handler.
1007 g_object_class_install_property (gobject_class,
1008 PROP_TOOLTIP_MARKUP,
1009 g_param_spec_string ("tooltip-markup",
1010 P_("Tooltip markup"),
1011 P_("The contents of the tooltip for this widget"),
1013 GTK_PARAM_READWRITE));
1018 * The widget's window if it is realized, %NULL otherwise.
1022 g_object_class_install_property (gobject_class,
1024 g_param_spec_object ("window",
1026 P_("The widget's window if it is realized"),
1028 GTK_PARAM_READABLE));
1031 * GtkWidget:double-buffered
1033 * Whether the widget is double buffered.
1037 g_object_class_install_property (gobject_class,
1038 PROP_DOUBLE_BUFFERED,
1039 g_param_spec_boolean ("double-buffered",
1040 P_("Double Buffered"),
1041 P_("Whether the widget is double buffered"),
1043 GTK_PARAM_READWRITE));
1048 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1052 g_object_class_install_property (gobject_class,
1054 g_param_spec_enum ("halign",
1055 P_("Horizontal Alignment"),
1056 P_("How to position in extra horizontal space"),
1059 GTK_PARAM_READWRITE));
1064 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1068 g_object_class_install_property (gobject_class,
1070 g_param_spec_enum ("valign",
1071 P_("Vertical Alignment"),
1072 P_("How to position in extra vertical space"),
1075 GTK_PARAM_READWRITE));
1078 * GtkWidget:margin-left
1080 * Margin on left side of widget.
1082 * This property adds margin outside of the widget's normal size
1083 * request, the margin will be added in addition to the size from
1084 * gtk_widget_set_size_request() for example.
1088 g_object_class_install_property (gobject_class,
1090 g_param_spec_int ("margin-left",
1091 P_("Margin on Left"),
1092 P_("Pixels of extra space on the left side"),
1096 GTK_PARAM_READWRITE));
1099 * GtkWidget:margin-right
1101 * Margin on right side of widget.
1103 * This property adds margin outside of the widget's normal size
1104 * request, the margin will be added in addition to the size from
1105 * gtk_widget_set_size_request() for example.
1109 g_object_class_install_property (gobject_class,
1111 g_param_spec_int ("margin-right",
1112 P_("Margin on Right"),
1113 P_("Pixels of extra space on the right side"),
1117 GTK_PARAM_READWRITE));
1120 * GtkWidget:margin-top
1122 * Margin on top side of widget.
1124 * This property adds margin outside of the widget's normal size
1125 * request, the margin will be added in addition to the size from
1126 * gtk_widget_set_size_request() for example.
1130 g_object_class_install_property (gobject_class,
1132 g_param_spec_int ("margin-top",
1133 P_("Margin on Top"),
1134 P_("Pixels of extra space on the top side"),
1138 GTK_PARAM_READWRITE));
1141 * GtkWidget:margin-bottom
1143 * Margin on bottom side of widget.
1145 * This property adds margin outside of the widget's normal size
1146 * request, the margin will be added in addition to the size from
1147 * gtk_widget_set_size_request() for example.
1151 g_object_class_install_property (gobject_class,
1153 g_param_spec_int ("margin-bottom",
1154 P_("Margin on Bottom"),
1155 P_("Pixels of extra space on the bottom side"),
1159 GTK_PARAM_READWRITE));
1164 * Sets all four sides' margin at once. If read, returns max
1165 * margin on any side.
1169 g_object_class_install_property (gobject_class,
1171 g_param_spec_int ("margin",
1173 P_("Pixels of extra space on all four sides"),
1177 GTK_PARAM_READWRITE));
1180 * GtkWidget::destroy:
1181 * @object: the object which received the signal
1183 * Signals that all holders of a reference to the widget should release
1184 * the reference that they hold. May result in finalization of the widget
1185 * if all references are released.
1187 widget_signals[DESTROY] =
1188 g_signal_new (I_("destroy"),
1189 G_TYPE_FROM_CLASS (gobject_class),
1190 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1191 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1193 _gtk_marshal_VOID__VOID,
1199 * Whether to expand horizontally. See gtk_widget_set_hexpand().
1203 g_object_class_install_property (gobject_class,
1205 g_param_spec_boolean ("hexpand",
1206 P_("Horizontal Expand"),
1207 P_("Whether widget wants more horizontal space"),
1209 GTK_PARAM_READWRITE));
1212 * GtkWidget:hexpand-set
1214 * Whether to use the GtkWidget:hexpand property. See gtk_widget_get_hexpand_set().
1218 g_object_class_install_property (gobject_class,
1220 g_param_spec_boolean ("hexpand-set",
1221 P_("Horizontal Expand Set"),
1222 P_("Whether to use the hexpand property"),
1224 GTK_PARAM_READWRITE));
1229 * Whether to expand vertically. See gtk_widget_set_vexpand().
1233 g_object_class_install_property (gobject_class,
1235 g_param_spec_boolean ("vexpand",
1236 P_("Vertical Expand"),
1237 P_("Whether widget wants more vertical space"),
1239 GTK_PARAM_READWRITE));
1242 * GtkWidget:vexpand-set
1244 * Whether to use the GtkWidget:vexpand property. See gtk_widget_get_vexpand_set().
1248 g_object_class_install_property (gobject_class,
1250 g_param_spec_boolean ("vexpand-set",
1251 P_("Vertical Expand Set"),
1252 P_("Whether to use the vexpand property"),
1254 GTK_PARAM_READWRITE));
1259 * Whether to expand in both directions. Setting this sets both GtkWidget:hexpand and GtkWidget:vexpand
1263 g_object_class_install_property (gobject_class,
1265 g_param_spec_boolean ("expand",
1267 P_("Whether widget wants to expand in both directions"),
1269 GTK_PARAM_READWRITE));
1273 * @widget: the object which received the signal.
1275 widget_signals[SHOW] =
1276 g_signal_new (I_("show"),
1277 G_TYPE_FROM_CLASS (gobject_class),
1279 G_STRUCT_OFFSET (GtkWidgetClass, show),
1281 _gtk_marshal_VOID__VOID,
1286 * @widget: the object which received the signal.
1288 widget_signals[HIDE] =
1289 g_signal_new (I_("hide"),
1290 G_TYPE_FROM_CLASS (gobject_class),
1292 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1294 _gtk_marshal_VOID__VOID,
1299 * @widget: the object which received the signal.
1301 widget_signals[MAP] =
1302 g_signal_new (I_("map"),
1303 G_TYPE_FROM_CLASS (gobject_class),
1305 G_STRUCT_OFFSET (GtkWidgetClass, map),
1307 _gtk_marshal_VOID__VOID,
1312 * @widget: the object which received the signal.
1314 widget_signals[UNMAP] =
1315 g_signal_new (I_("unmap"),
1316 G_TYPE_FROM_CLASS (gobject_class),
1318 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1320 _gtk_marshal_VOID__VOID,
1324 * GtkWidget::realize:
1325 * @widget: the object which received the signal.
1327 widget_signals[REALIZE] =
1328 g_signal_new (I_("realize"),
1329 G_TYPE_FROM_CLASS (gobject_class),
1331 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1333 _gtk_marshal_VOID__VOID,
1337 * GtkWidget::unrealize:
1338 * @widget: the object which received the signal.
1340 widget_signals[UNREALIZE] =
1341 g_signal_new (I_("unrealize"),
1342 G_TYPE_FROM_CLASS (gobject_class),
1344 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1346 _gtk_marshal_VOID__VOID,
1350 * GtkWidget::size-request:
1351 * @widget: the object which received the signal.
1354 widget_signals[SIZE_REQUEST] =
1355 g_signal_new (I_("size-request"),
1356 G_TYPE_FROM_CLASS (gobject_class),
1358 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1360 _gtk_marshal_VOID__BOXED,
1362 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1365 * GtkWidget::size-allocate:
1366 * @widget: the object which received the signal.
1369 widget_signals[SIZE_ALLOCATE] =
1370 g_signal_new (I_("size-allocate"),
1371 G_TYPE_FROM_CLASS (gobject_class),
1373 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1375 _gtk_marshal_VOID__BOXED,
1377 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1380 * GtkWidget::state-changed:
1381 * @widget: the object which received the signal.
1382 * @state: the previous state
1384 * The ::state-changed signal is emitted when the widget state changes.
1385 * See gtk_widget_get_state().
1387 widget_signals[STATE_CHANGED] =
1388 g_signal_new (I_("state-changed"),
1389 G_TYPE_FROM_CLASS (gobject_class),
1391 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1393 _gtk_marshal_VOID__ENUM,
1395 GTK_TYPE_STATE_TYPE);
1398 * GtkWidget::parent-set:
1399 * @widget: the object on which the signal is emitted
1400 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1401 * just got its initial parent.
1403 * The ::parent-set signal is emitted when a new parent
1404 * has been set on a widget.
1406 widget_signals[PARENT_SET] =
1407 g_signal_new (I_("parent-set"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1410 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1412 _gtk_marshal_VOID__OBJECT,
1417 * GtkWidget::hierarchy-changed:
1418 * @widget: the object on which the signal is emitted
1419 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1420 * if the widget was previously unanchored
1422 * The ::hierarchy-changed signal is emitted when the
1423 * anchored state of a widget changes. A widget is
1424 * <firstterm>anchored</firstterm> when its toplevel
1425 * ancestor is a #GtkWindow. This signal is emitted when
1426 * a widget changes from un-anchored to anchored or vice-versa.
1428 widget_signals[HIERARCHY_CHANGED] =
1429 g_signal_new (I_("hierarchy-changed"),
1430 G_TYPE_FROM_CLASS (gobject_class),
1432 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1434 _gtk_marshal_VOID__OBJECT,
1439 * GtkWidget::style-set:
1440 * @widget: the object on which the signal is emitted
1441 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1442 * just got its initial style
1444 * The ::style-set signal is emitted when a new style has been set
1445 * on a widget. Note that style-modifying functions like
1446 * gtk_widget_modify_base() also cause this signal to be emitted.
1448 widget_signals[STYLE_SET] =
1449 g_signal_new (I_("style-set"),
1450 G_TYPE_FROM_CLASS (gobject_class),
1452 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1454 _gtk_marshal_VOID__OBJECT,
1459 * GtkWidget::direction-changed:
1460 * @widget: the object on which the signal is emitted
1461 * @previous_direction: the previous text direction of @widget
1463 * The ::direction-changed signal is emitted when the text direction
1464 * of a widget changes.
1466 widget_signals[DIRECTION_CHANGED] =
1467 g_signal_new (I_("direction-changed"),
1468 G_TYPE_FROM_CLASS (gobject_class),
1470 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1472 _gtk_marshal_VOID__ENUM,
1474 GTK_TYPE_TEXT_DIRECTION);
1477 * GtkWidget::grab-notify:
1478 * @widget: the object which received the signal
1479 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1480 * if it becomes unshadowed
1482 * The ::grab-notify signal is emitted when a widget becomes
1483 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1484 * another widget, or when it becomes unshadowed due to a grab
1487 * A widget is shadowed by a gtk_grab_add() when the topmost
1488 * grab widget in the grab stack of its window group is not
1491 widget_signals[GRAB_NOTIFY] =
1492 g_signal_new (I_("grab-notify"),
1493 G_TYPE_FROM_CLASS (gobject_class),
1495 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1497 _gtk_marshal_VOID__BOOLEAN,
1502 * GtkWidget::child-notify:
1503 * @widget: the object which received the signal
1504 * @pspec: the #GParamSpec of the changed child property
1506 * The ::child-notify signal is emitted for each
1507 * <link linkend="child-properties">child property</link> that has
1508 * changed on an object. The signal's detail holds the property name.
1510 widget_signals[CHILD_NOTIFY] =
1511 g_signal_new (I_("child-notify"),
1512 G_TYPE_FROM_CLASS (gobject_class),
1513 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1514 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1516 g_cclosure_marshal_VOID__PARAM,
1522 * @widget: the object which received the signal
1523 * @cr: the cairo context to draw to
1525 * This signal is emitted when a widget is supposed to render itself.
1526 * The @widget's top left corner must be painted at the origin of
1527 * the passed in context and be sized to the values returned by
1528 * gtk_widget_get_allocated_width() and
1529 * gtk_widget_get_allocated_height().
1531 * Signal handlers connected to this signal can modify the cairo
1532 * context passed as @cr in any way they like and don't need to
1533 * restore it. The signal emission takes care of calling cairo_save()
1534 * before and cairo_restore() after invoking the handler.
1536 widget_signals[DRAW] =
1537 g_signal_new (I_("draw"),
1538 G_TYPE_FROM_CLASS (gobject_class),
1540 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1541 _gtk_boolean_handled_accumulator, NULL,
1542 gtk_widget_draw_marshaller,
1544 CAIRO_GOBJECT_TYPE_CONTEXT);
1547 * GtkWidget::mnemonic-activate:
1548 * @widget: the object which received the signal.
1551 widget_signals[MNEMONIC_ACTIVATE] =
1552 g_signal_new (I_("mnemonic-activate"),
1553 G_TYPE_FROM_CLASS (gobject_class),
1555 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1556 _gtk_boolean_handled_accumulator, NULL,
1557 _gtk_marshal_BOOLEAN__BOOLEAN,
1562 * GtkWidget::grab-focus:
1563 * @widget: the object which received the signal.
1565 widget_signals[GRAB_FOCUS] =
1566 g_signal_new (I_("grab-focus"),
1567 G_TYPE_FROM_CLASS (gobject_class),
1568 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1569 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1571 _gtk_marshal_VOID__VOID,
1576 * @widget: the object which received the signal.
1579 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1581 widget_signals[FOCUS] =
1582 g_signal_new (I_("focus"),
1583 G_TYPE_FROM_CLASS (klass),
1585 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1586 _gtk_boolean_handled_accumulator, NULL,
1587 _gtk_marshal_BOOLEAN__ENUM,
1589 GTK_TYPE_DIRECTION_TYPE);
1592 * GtkWidget::move-focus:
1593 * @widget: the object which received the signal.
1596 widget_signals[MOVE_FOCUS] =
1597 g_signal_new_class_handler (I_("move-focus"),
1598 G_TYPE_FROM_CLASS (klass),
1599 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1600 G_CALLBACK (gtk_widget_real_move_focus),
1602 _gtk_marshal_VOID__ENUM,
1605 GTK_TYPE_DIRECTION_TYPE);
1609 * @widget: the object which received the signal.
1610 * @event: the #GdkEvent which triggered this signal
1612 * The GTK+ main loop will emit three signals for each GDK event delivered
1613 * to a widget: one generic ::event signal, another, more specific,
1614 * signal that matches the type of event delivered (e.g.
1615 * #GtkWidget::key-press-event) and finally a generic
1616 * #GtkWidget::event-after signal.
1618 * Returns: %TRUE to stop other handlers from being invoked for the event
1619 * and to cancel the emission of the second specific ::event signal.
1620 * %FALSE to propagate the event further and to allow the emission of
1621 * the second signal. The ::event-after signal is emitted regardless of
1624 widget_signals[EVENT] =
1625 g_signal_new (I_("event"),
1626 G_TYPE_FROM_CLASS (klass),
1628 G_STRUCT_OFFSET (GtkWidgetClass, event),
1629 _gtk_boolean_handled_accumulator, NULL,
1630 _gtk_marshal_BOOLEAN__BOXED,
1632 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1635 * GtkWidget::event-after:
1636 * @widget: the object which received the signal.
1637 * @event: the #GdkEvent which triggered this signal
1639 * After the emission of the #GtkWidget::event signal and (optionally)
1640 * the second more specific signal, ::event-after will be emitted
1641 * regardless of the previous two signals handlers return values.
1644 widget_signals[EVENT_AFTER] =
1645 g_signal_new (I_("event-after"),
1646 G_TYPE_FROM_CLASS (klass),
1650 _gtk_marshal_VOID__BOXED,
1652 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1655 * GtkWidget::button-press-event:
1656 * @widget: the object which received the signal.
1657 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1660 * The ::button-press-event signal will be emitted when a button
1661 * (typically from a mouse) is pressed.
1663 * To receive this signal, the #GdkWindow associated to the
1664 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1666 * This signal will be sent to the grab widget if there is one.
1668 * Returns: %TRUE to stop other handlers from being invoked for the event.
1669 * %FALSE to propagate the event further.
1671 widget_signals[BUTTON_PRESS_EVENT] =
1672 g_signal_new (I_("button-press-event"),
1673 G_TYPE_FROM_CLASS (klass),
1675 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1676 _gtk_boolean_handled_accumulator, NULL,
1677 _gtk_marshal_BOOLEAN__BOXED,
1679 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1682 * GtkWidget::button-release-event:
1683 * @widget: the object which received the signal.
1684 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1687 * The ::button-release-event signal will be emitted when a button
1688 * (typically from a mouse) is released.
1690 * To receive this signal, the #GdkWindow associated to the
1691 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1693 * This signal will be sent to the grab widget if there is one.
1695 * Returns: %TRUE to stop other handlers from being invoked for the event.
1696 * %FALSE to propagate the event further.
1698 widget_signals[BUTTON_RELEASE_EVENT] =
1699 g_signal_new (I_("button-release-event"),
1700 G_TYPE_FROM_CLASS (klass),
1702 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1703 _gtk_boolean_handled_accumulator, NULL,
1704 _gtk_marshal_BOOLEAN__BOXED,
1706 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1709 * GtkWidget::scroll-event:
1710 * @widget: the object which received the signal.
1711 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1714 * The ::scroll-event signal is emitted when a button in the 4 to 7
1715 * range is pressed. Wheel mice are usually configured to generate
1716 * button press events for buttons 4 and 5 when the wheel is turned.
1718 * To receive this signal, the #GdkWindow associated to the widget needs
1719 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1721 * This signal will be sent to the grab widget if there is one.
1723 * Returns: %TRUE to stop other handlers from being invoked for the event.
1724 * %FALSE to propagate the event further.
1726 widget_signals[SCROLL_EVENT] =
1727 g_signal_new (I_("scroll-event"),
1728 G_TYPE_FROM_CLASS (klass),
1730 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1731 _gtk_boolean_handled_accumulator, NULL,
1732 _gtk_marshal_BOOLEAN__BOXED,
1734 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1737 * GtkWidget::motion-notify-event:
1738 * @widget: the object which received the signal.
1739 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1742 * The ::motion-notify-event signal is emitted when the pointer moves
1743 * over the widget's #GdkWindow.
1745 * To receive this signal, the #GdkWindow associated to the widget
1746 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1748 * This signal will be sent to the grab widget if there is one.
1750 * Returns: %TRUE to stop other handlers from being invoked for the event.
1751 * %FALSE to propagate the event further.
1753 widget_signals[MOTION_NOTIFY_EVENT] =
1754 g_signal_new (I_("motion-notify-event"),
1755 G_TYPE_FROM_CLASS (klass),
1757 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1758 _gtk_boolean_handled_accumulator, NULL,
1759 _gtk_marshal_BOOLEAN__BOXED,
1761 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1764 * GtkWidget::composited-changed:
1765 * @widget: the object on which the signal is emitted
1767 * The ::composited-changed signal is emitted when the composited
1768 * status of @widget<!-- -->s screen changes.
1769 * See gdk_screen_is_composited().
1771 widget_signals[COMPOSITED_CHANGED] =
1772 g_signal_new (I_("composited-changed"),
1773 G_TYPE_FROM_CLASS (klass),
1774 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1775 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1777 _gtk_marshal_VOID__VOID,
1781 * GtkWidget::keynav-failed:
1782 * @widget: the object which received the signal
1783 * @direction: the direction of movement
1785 * Gets emitted if keyboard navigation fails.
1786 * See gtk_widget_keynav_failed() for details.
1788 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1789 * if the emitting widget should try to handle the keyboard
1790 * navigation attempt in its parent container(s).
1794 widget_signals[KEYNAV_FAILED] =
1795 g_signal_new_class_handler (I_("keynav-failed"),
1796 G_TYPE_FROM_CLASS (klass),
1798 G_CALLBACK (gtk_widget_real_keynav_failed),
1799 _gtk_boolean_handled_accumulator, NULL,
1800 _gtk_marshal_BOOLEAN__ENUM,
1802 GTK_TYPE_DIRECTION_TYPE);
1805 * GtkWidget::delete-event:
1806 * @widget: the object which received the signal
1807 * @event: the event which triggered this signal
1809 * The ::delete-event signal is emitted if a user requests that
1810 * a toplevel window is closed. The default handler for this signal
1811 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1812 * this signal will cause the window to be hidden instead, so that
1813 * it can later be shown again without reconstructing it.
1815 * Returns: %TRUE to stop other handlers from being invoked for the event.
1816 * %FALSE to propagate the event further.
1818 widget_signals[DELETE_EVENT] =
1819 g_signal_new (I_("delete-event"),
1820 G_TYPE_FROM_CLASS (klass),
1822 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1823 _gtk_boolean_handled_accumulator, NULL,
1824 _gtk_marshal_BOOLEAN__BOXED,
1826 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1829 * GtkWidget::destroy-event:
1830 * @widget: the object which received the signal.
1831 * @event: the event which triggered this signal
1833 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1834 * You rarely get this signal, because most widgets disconnect themselves
1835 * from their window before they destroy it, so no widget owns the
1836 * window at destroy time.
1838 * To receive this signal, the #GdkWindow associated to the widget needs
1839 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1840 * automatically for all new windows.
1842 * Returns: %TRUE to stop other handlers from being invoked for the event.
1843 * %FALSE to propagate the event further.
1845 widget_signals[DESTROY_EVENT] =
1846 g_signal_new (I_("destroy-event"),
1847 G_TYPE_FROM_CLASS (klass),
1849 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1850 _gtk_boolean_handled_accumulator, NULL,
1851 _gtk_marshal_BOOLEAN__BOXED,
1853 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1856 * GtkWidget::key-press-event:
1857 * @widget: the object which received the signal
1858 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1860 * The ::key-press-event signal is emitted when a key is pressed.
1862 * To receive this signal, the #GdkWindow associated to the widget needs
1863 * to enable the #GDK_KEY_PRESS_MASK mask.
1865 * This signal will be sent to the grab widget if there is one.
1867 * Returns: %TRUE to stop other handlers from being invoked for the event.
1868 * %FALSE to propagate the event further.
1870 widget_signals[KEY_PRESS_EVENT] =
1871 g_signal_new (I_("key-press-event"),
1872 G_TYPE_FROM_CLASS (klass),
1874 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1875 _gtk_boolean_handled_accumulator, NULL,
1876 _gtk_marshal_BOOLEAN__BOXED,
1878 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1881 * GtkWidget::key-release-event:
1882 * @widget: the object which received the signal
1883 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1885 * The ::key-release-event signal is emitted when a key is pressed.
1887 * To receive this signal, the #GdkWindow associated to the widget needs
1888 * to enable the #GDK_KEY_RELEASE_MASK mask.
1890 * This signal will be sent to the grab widget if there is one.
1892 * Returns: %TRUE to stop other handlers from being invoked for the event.
1893 * %FALSE to propagate the event further.
1895 widget_signals[KEY_RELEASE_EVENT] =
1896 g_signal_new (I_("key-release-event"),
1897 G_TYPE_FROM_CLASS (klass),
1899 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1900 _gtk_boolean_handled_accumulator, NULL,
1901 _gtk_marshal_BOOLEAN__BOXED,
1903 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1906 * GtkWidget::enter-notify-event:
1907 * @widget: the object which received the signal
1908 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1911 * The ::enter-notify-event will be emitted when the pointer enters
1912 * the @widget's window.
1914 * To receive this signal, the #GdkWindow associated to the widget needs
1915 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1917 * This signal will be sent to the grab widget if there is one.
1919 * Returns: %TRUE to stop other handlers from being invoked for the event.
1920 * %FALSE to propagate the event further.
1922 widget_signals[ENTER_NOTIFY_EVENT] =
1923 g_signal_new (I_("enter-notify-event"),
1924 G_TYPE_FROM_CLASS (klass),
1926 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1927 _gtk_boolean_handled_accumulator, NULL,
1928 _gtk_marshal_BOOLEAN__BOXED,
1930 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1933 * GtkWidget::leave-notify-event:
1934 * @widget: the object which received the signal
1935 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1938 * The ::leave-notify-event will be emitted when the pointer leaves
1939 * the @widget's window.
1941 * To receive this signal, the #GdkWindow associated to the widget needs
1942 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1944 * This signal will be sent to the grab widget if there is one.
1946 * Returns: %TRUE to stop other handlers from being invoked for the event.
1947 * %FALSE to propagate the event further.
1949 widget_signals[LEAVE_NOTIFY_EVENT] =
1950 g_signal_new (I_("leave-notify-event"),
1951 G_TYPE_FROM_CLASS (klass),
1953 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1954 _gtk_boolean_handled_accumulator, NULL,
1955 _gtk_marshal_BOOLEAN__BOXED,
1957 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1960 * GtkWidget::configure-event:
1961 * @widget: the object which received the signal
1962 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1965 * The ::configure-event signal will be emitted when the size, position or
1966 * stacking of the @widget's window has changed.
1968 * To receive this signal, the #GdkWindow associated to the widget needs
1969 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1970 * automatically for all new windows.
1972 * Returns: %TRUE to stop other handlers from being invoked for the event.
1973 * %FALSE to propagate the event further.
1975 widget_signals[CONFIGURE_EVENT] =
1976 g_signal_new (I_("configure-event"),
1977 G_TYPE_FROM_CLASS (klass),
1979 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1980 _gtk_boolean_handled_accumulator, NULL,
1981 _gtk_marshal_BOOLEAN__BOXED,
1983 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1986 * GtkWidget::focus-in-event:
1987 * @widget: the object which received the signal
1988 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1991 * The ::focus-in-event signal will be emitted when the keyboard focus
1992 * enters the @widget's window.
1994 * To receive this signal, the #GdkWindow associated to the widget needs
1995 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1997 * Returns: %TRUE to stop other handlers from being invoked for the event.
1998 * %FALSE to propagate the event further.
2000 widget_signals[FOCUS_IN_EVENT] =
2001 g_signal_new (I_("focus-in-event"),
2002 G_TYPE_FROM_CLASS (klass),
2004 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
2005 _gtk_boolean_handled_accumulator, NULL,
2006 _gtk_marshal_BOOLEAN__BOXED,
2008 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2011 * GtkWidget::focus-out-event:
2012 * @widget: the object which received the signal
2013 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
2016 * The ::focus-out-event signal will be emitted when the keyboard focus
2017 * leaves the @widget's window.
2019 * To receive this signal, the #GdkWindow associated to the widget needs
2020 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
2022 * Returns: %TRUE to stop other handlers from being invoked for the event.
2023 * %FALSE to propagate the event further.
2025 widget_signals[FOCUS_OUT_EVENT] =
2026 g_signal_new (I_("focus-out-event"),
2027 G_TYPE_FROM_CLASS (klass),
2029 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
2030 _gtk_boolean_handled_accumulator, NULL,
2031 _gtk_marshal_BOOLEAN__BOXED,
2033 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2036 * GtkWidget::map-event:
2037 * @widget: the object which received the signal
2038 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
2040 * The ::map-event signal will be emitted when the @widget's window is
2041 * mapped. A window is mapped when it becomes visible on the screen.
2043 * To receive this signal, the #GdkWindow associated to the widget needs
2044 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2045 * automatically for all new windows.
2047 * Returns: %TRUE to stop other handlers from being invoked for the event.
2048 * %FALSE to propagate the event further.
2050 widget_signals[MAP_EVENT] =
2051 g_signal_new (I_("map-event"),
2052 G_TYPE_FROM_CLASS (klass),
2054 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
2055 _gtk_boolean_handled_accumulator, NULL,
2056 _gtk_marshal_BOOLEAN__BOXED,
2058 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2061 * GtkWidget::unmap-event:
2062 * @widget: the object which received the signal
2063 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
2065 * The ::unmap-event signal may be emitted when the @widget's window is
2066 * unmapped. A window is unmapped when it becomes invisible on the screen.
2068 * For performance reasons GTK+ may not emit ::unmap-event, so one
2069 * should always also implement ::unrealize in order to release
2070 * resources and disconnect signal handlers.
2072 * To receive this signal, the #GdkWindow associated to the widget needs
2073 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
2074 * automatically for all new windows.
2076 * Returns: %TRUE to stop other handlers from being invoked for the event.
2077 * %FALSE to propagate the event further.
2079 widget_signals[UNMAP_EVENT] =
2080 g_signal_new (I_("unmap-event"),
2081 G_TYPE_FROM_CLASS (klass),
2083 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
2084 _gtk_boolean_handled_accumulator, NULL,
2085 _gtk_marshal_BOOLEAN__BOXED,
2087 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2090 * GtkWidget::property-notify-event:
2091 * @widget: the object which received the signal
2092 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2095 * The ::property-notify-event signal will be emitted when a property on
2096 * the @widget's window has been changed or deleted.
2098 * To receive this signal, the #GdkWindow associated to the widget needs
2099 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2101 * Returns: %TRUE to stop other handlers from being invoked for the event.
2102 * %FALSE to propagate the event further.
2104 widget_signals[PROPERTY_NOTIFY_EVENT] =
2105 g_signal_new (I_("property-notify-event"),
2106 G_TYPE_FROM_CLASS (klass),
2108 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2109 _gtk_boolean_handled_accumulator, NULL,
2110 _gtk_marshal_BOOLEAN__BOXED,
2112 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2115 * GtkWidget::selection-clear-event:
2116 * @widget: the object which received the signal
2117 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2120 * The ::selection-clear-event signal will be emitted when the
2121 * the @widget's window has lost ownership of a selection.
2123 * Returns: %TRUE to stop other handlers from being invoked for the event.
2124 * %FALSE to propagate the event further.
2126 widget_signals[SELECTION_CLEAR_EVENT] =
2127 g_signal_new (I_("selection-clear-event"),
2128 G_TYPE_FROM_CLASS (klass),
2130 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2131 _gtk_boolean_handled_accumulator, NULL,
2132 _gtk_marshal_BOOLEAN__BOXED,
2134 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2137 * GtkWidget::selection-request-event:
2138 * @widget: the object which received the signal
2139 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2142 * The ::selection-request-event signal will be emitted when
2143 * another client requests ownership of the selection owned by
2144 * the @widget's window.
2146 * Returns: %TRUE to stop other handlers from being invoked for the event.
2147 * %FALSE to propagate the event further.
2149 widget_signals[SELECTION_REQUEST_EVENT] =
2150 g_signal_new (I_("selection-request-event"),
2151 G_TYPE_FROM_CLASS (klass),
2153 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2154 _gtk_boolean_handled_accumulator, NULL,
2155 _gtk_marshal_BOOLEAN__BOXED,
2157 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2160 * GtkWidget::selection-notify-event:
2161 * @widget: the object which received the signal.
2164 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2166 widget_signals[SELECTION_NOTIFY_EVENT] =
2167 g_signal_new (I_("selection-notify-event"),
2168 G_TYPE_FROM_CLASS (klass),
2170 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2171 _gtk_boolean_handled_accumulator, NULL,
2172 _gtk_marshal_BOOLEAN__BOXED,
2174 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2177 * GtkWidget::selection-received:
2178 * @widget: the object which received the signal.
2182 widget_signals[SELECTION_RECEIVED] =
2183 g_signal_new (I_("selection-received"),
2184 G_TYPE_FROM_CLASS (klass),
2186 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2188 _gtk_marshal_VOID__BOXED_UINT,
2190 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2194 * GtkWidget::selection-get:
2195 * @widget: the object which received the signal.
2200 widget_signals[SELECTION_GET] =
2201 g_signal_new (I_("selection-get"),
2202 G_TYPE_FROM_CLASS (klass),
2204 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2206 _gtk_marshal_VOID__BOXED_UINT_UINT,
2208 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2213 * GtkWidget::proximity-in-event:
2214 * @widget: the object which received the signal
2215 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2218 * To receive this signal the #GdkWindow associated to the widget needs
2219 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2221 * This signal will be sent to the grab widget if there is one.
2223 * Returns: %TRUE to stop other handlers from being invoked for the event.
2224 * %FALSE to propagate the event further.
2226 widget_signals[PROXIMITY_IN_EVENT] =
2227 g_signal_new (I_("proximity-in-event"),
2228 G_TYPE_FROM_CLASS (klass),
2230 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2231 _gtk_boolean_handled_accumulator, NULL,
2232 _gtk_marshal_BOOLEAN__BOXED,
2234 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2237 * GtkWidget::proximity-out-event:
2238 * @widget: the object which received the signal
2239 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2242 * To receive this signal the #GdkWindow associated to the widget needs
2243 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2245 * This signal will be sent to the grab widget if there is one.
2247 * Returns: %TRUE to stop other handlers from being invoked for the event.
2248 * %FALSE to propagate the event further.
2250 widget_signals[PROXIMITY_OUT_EVENT] =
2251 g_signal_new (I_("proximity-out-event"),
2252 G_TYPE_FROM_CLASS (klass),
2254 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2255 _gtk_boolean_handled_accumulator, NULL,
2256 _gtk_marshal_BOOLEAN__BOXED,
2258 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2261 * GtkWidget::drag-leave:
2262 * @widget: the object which received the signal.
2263 * @drag_context: the drag context
2264 * @time: the timestamp of the motion event
2266 * The ::drag-leave signal is emitted on the drop site when the cursor
2267 * leaves the widget. A typical reason to connect to this signal is to
2268 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2269 * with gtk_drag_unhighlight()
2271 widget_signals[DRAG_LEAVE] =
2272 g_signal_new (I_("drag-leave"),
2273 G_TYPE_FROM_CLASS (klass),
2275 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2277 _gtk_marshal_VOID__OBJECT_UINT,
2279 GDK_TYPE_DRAG_CONTEXT,
2283 * GtkWidget::drag-begin:
2284 * @widget: the object which received the signal
2285 * @drag_context: the drag context
2287 * The ::drag-begin signal is emitted on the drag source when a drag is
2288 * started. A typical reason to connect to this signal is to set up a
2289 * custom drag icon with gtk_drag_source_set_icon().
2291 * Note that some widgets set up a drag icon in the default handler of
2292 * this signal, so you may have to use g_signal_connect_after() to
2293 * override what the default handler did.
2295 widget_signals[DRAG_BEGIN] =
2296 g_signal_new (I_("drag-begin"),
2297 G_TYPE_FROM_CLASS (klass),
2299 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2301 _gtk_marshal_VOID__OBJECT,
2303 GDK_TYPE_DRAG_CONTEXT);
2306 * GtkWidget::drag-end:
2307 * @widget: the object which received the signal
2308 * @drag_context: the drag context
2310 * The ::drag-end signal is emitted on the drag source when a drag is
2311 * finished. A typical reason to connect to this signal is to undo
2312 * things done in #GtkWidget::drag-begin.
2314 widget_signals[DRAG_END] =
2315 g_signal_new (I_("drag-end"),
2316 G_TYPE_FROM_CLASS (klass),
2318 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2320 _gtk_marshal_VOID__OBJECT,
2322 GDK_TYPE_DRAG_CONTEXT);
2325 * GtkWidget::drag-data-delete:
2326 * @widget: the object which received the signal
2327 * @drag_context: the drag context
2329 * The ::drag-data-delete signal is emitted on the drag source when a drag
2330 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2331 * handler is responsible for deleting the data that has been dropped. What
2332 * "delete" means depends on the context of the drag operation.
2334 widget_signals[DRAG_DATA_DELETE] =
2335 g_signal_new (I_("drag-data-delete"),
2336 G_TYPE_FROM_CLASS (klass),
2338 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2340 _gtk_marshal_VOID__OBJECT,
2342 GDK_TYPE_DRAG_CONTEXT);
2345 * GtkWidget::drag-failed:
2346 * @widget: the object which received the signal
2347 * @drag_context: the drag context
2348 * @result: the result of the drag operation
2350 * The ::drag-failed signal is emitted on the drag source when a drag has
2351 * failed. The signal handler may hook custom code to handle a failed DND
2352 * operation based on the type of error, it returns %TRUE is the failure has
2353 * been already handled (not showing the default "drag operation failed"
2354 * animation), otherwise it returns %FALSE.
2356 * Return value: %TRUE if the failed drag operation has been already handled.
2360 widget_signals[DRAG_FAILED] =
2361 g_signal_new (I_("drag-failed"),
2362 G_TYPE_FROM_CLASS (klass),
2364 0, _gtk_boolean_handled_accumulator, NULL,
2365 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2367 GDK_TYPE_DRAG_CONTEXT,
2368 GTK_TYPE_DRAG_RESULT);
2371 * GtkWidget::drag-motion:
2372 * @widget: the object which received the signal
2373 * @drag_context: the drag context
2374 * @x: the x coordinate of the current cursor position
2375 * @y: the y coordinate of the current cursor position
2376 * @time: the timestamp of the motion event
2377 * @returns: whether the cursor position is in a drop zone
2379 * The drag-motion signal is emitted on the drop site when the user
2380 * moves the cursor over the widget during a drag. The signal handler
2381 * must determine whether the cursor position is in a drop zone or not.
2382 * If it is not in a drop zone, it returns %FALSE and no further processing
2383 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2384 * handler is responsible for providing the necessary information for
2385 * displaying feedback to the user, by calling gdk_drag_status().
2387 * If the decision whether the drop will be accepted or rejected can't be
2388 * made based solely on the cursor position and the type of the data, the
2389 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2390 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2391 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2392 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2393 * when using the drag-motion signal that way.
2395 * Also note that there is no drag-enter signal. The drag receiver has to
2396 * keep track of whether he has received any drag-motion signals since the
2397 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2398 * an "enter" signal. Upon an "enter", the handler will typically highlight
2399 * the drop site with gtk_drag_highlight().
2402 * drag_motion (GtkWidget *widget,
2403 * GdkDragContext *context,
2410 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2412 * if (!private_data->drag_highlight)
2414 * private_data->drag_highlight = 1;
2415 * gtk_drag_highlight (widget);
2418 * target = gtk_drag_dest_find_target (widget, context, NULL);
2419 * if (target == GDK_NONE)
2420 * gdk_drag_status (context, 0, time);
2423 * private_data->pending_status = context->suggested_action;
2424 * gtk_drag_get_data (widget, context, target, time);
2431 * drag_data_received (GtkWidget *widget,
2432 * GdkDragContext *context,
2435 * GtkSelectionData *selection_data,
2439 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2441 * if (private_data->suggested_action)
2443 * private_data->suggested_action = 0;
2445 * /* We are getting this data due to a request in drag_motion,
2446 * * rather than due to a request in drag_drop, so we are just
2447 * * supposed to call gdk_drag_status (), not actually paste in
2450 * str = gtk_selection_data_get_text (selection_data);
2451 * if (!data_is_acceptable (str))
2452 * gdk_drag_status (context, 0, time);
2454 * gdk_drag_status (context, private_data->suggested_action, time);
2458 * /* accept the drop */
2463 widget_signals[DRAG_MOTION] =
2464 g_signal_new (I_("drag-motion"),
2465 G_TYPE_FROM_CLASS (klass),
2467 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2468 _gtk_boolean_handled_accumulator, NULL,
2469 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2471 GDK_TYPE_DRAG_CONTEXT,
2477 * GtkWidget::drag-drop:
2478 * @widget: the object which received the signal
2479 * @drag_context: the drag context
2480 * @x: the x coordinate of the current cursor position
2481 * @y: the y coordinate of the current cursor position
2482 * @time: the timestamp of the motion event
2483 * @returns: whether the cursor position is in a drop zone
2485 * The ::drag-drop signal is emitted on the drop site when the user drops
2486 * the data onto the widget. The signal handler must determine whether
2487 * the cursor position is in a drop zone or not. If it is not in a drop
2488 * zone, it returns %FALSE and no further processing is necessary.
2489 * Otherwise, the handler returns %TRUE. In this case, the handler must
2490 * ensure that gtk_drag_finish() is called to let the source know that
2491 * the drop is done. The call to gtk_drag_finish() can be done either
2492 * directly or in a #GtkWidget::drag-data-received handler which gets
2493 * triggered by calling gtk_drag_get_data() to receive the data for one
2494 * or more of the supported targets.
2496 widget_signals[DRAG_DROP] =
2497 g_signal_new (I_("drag-drop"),
2498 G_TYPE_FROM_CLASS (klass),
2500 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2501 _gtk_boolean_handled_accumulator, NULL,
2502 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2504 GDK_TYPE_DRAG_CONTEXT,
2510 * GtkWidget::drag-data-get:
2511 * @widget: the object which received the signal
2512 * @drag_context: the drag context
2513 * @data: the #GtkSelectionData to be filled with the dragged data
2514 * @info: the info that has been registered with the target in the
2516 * @time: the timestamp at which the data was requested
2518 * The ::drag-data-get signal is emitted on the drag source when the drop
2519 * site requests the data which is dragged. It is the responsibility of
2520 * the signal handler to fill @data with the data in the format which
2521 * is indicated by @info. See gtk_selection_data_set() and
2522 * gtk_selection_data_set_text().
2524 widget_signals[DRAG_DATA_GET] =
2525 g_signal_new (I_("drag-data-get"),
2526 G_TYPE_FROM_CLASS (klass),
2528 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2530 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2532 GDK_TYPE_DRAG_CONTEXT,
2533 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2538 * GtkWidget::drag-data-received:
2539 * @widget: the object which received the signal
2540 * @drag_context: the drag context
2541 * @x: where the drop happened
2542 * @y: where the drop happened
2543 * @data: the received data
2544 * @info: the info that has been registered with the target in the
2546 * @time: the timestamp at which the data was received
2548 * The ::drag-data-received signal is emitted on the drop site when the
2549 * dragged data has been received. If the data was received in order to
2550 * determine whether the drop will be accepted, the handler is expected
2551 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2552 * If the data was received in response to a #GtkWidget::drag-drop signal
2553 * (and this is the last target to be received), the handler for this
2554 * signal is expected to process the received data and then call
2555 * gtk_drag_finish(), setting the @success parameter depending on whether
2556 * the data was processed successfully.
2558 * The handler may inspect and modify @drag_context->action before calling
2559 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2560 * following example:
2563 * drag_data_received (GtkWidget *widget,
2564 * GdkDragContext *drag_context,
2567 * GtkSelectionData *data,
2571 * if ((data->length >= 0) && (data->format == 8))
2573 * if (drag_context->action == GDK_ACTION_ASK)
2575 * GtkWidget *dialog;
2578 * dialog = gtk_message_dialog_new (NULL,
2579 * GTK_DIALOG_MODAL |
2580 * GTK_DIALOG_DESTROY_WITH_PARENT,
2582 * GTK_BUTTONS_YES_NO,
2583 * "Move the data ?\n");
2584 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2585 * gtk_widget_destroy (dialog);
2587 * if (response == GTK_RESPONSE_YES)
2588 * drag_context->action = GDK_ACTION_MOVE;
2590 * drag_context->action = GDK_ACTION_COPY;
2593 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2597 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2601 widget_signals[DRAG_DATA_RECEIVED] =
2602 g_signal_new (I_("drag-data-received"),
2603 G_TYPE_FROM_CLASS (klass),
2605 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2607 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2609 GDK_TYPE_DRAG_CONTEXT,
2612 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2617 * GtkWidget::visibility-notify-event:
2618 * @widget: the object which received the signal
2619 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2620 * triggered this signal.
2622 * The ::visibility-notify-event will be emitted when the @widget's window
2623 * is obscured or unobscured.
2625 * To receive this signal the #GdkWindow associated to the widget needs
2626 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2628 * Returns: %TRUE to stop other handlers from being invoked for the event.
2629 * %FALSE to propagate the event further.
2631 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2632 g_signal_new (I_("visibility-notify-event"),
2633 G_TYPE_FROM_CLASS (klass),
2635 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2636 _gtk_boolean_handled_accumulator, NULL,
2637 _gtk_marshal_BOOLEAN__BOXED,
2639 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2642 * GtkWidget::client-event:
2643 * @widget: the object which received the signal
2644 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2647 * The ::client-event will be emitted when the @widget's window
2648 * receives a message (via a ClientMessage event) from another
2651 * Returns: %TRUE to stop other handlers from being invoked for
2652 * the event. %FALSE to propagate the event further.
2654 widget_signals[CLIENT_EVENT] =
2655 g_signal_new (I_("client-event"),
2656 G_TYPE_FROM_CLASS (klass),
2658 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2659 _gtk_boolean_handled_accumulator, NULL,
2660 _gtk_marshal_BOOLEAN__BOXED,
2662 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2665 * GtkWidget::no-expose-event:
2666 * @widget: the object which received the signal
2667 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2670 * The ::no-expose-event will be emitted when the @widget's window is
2671 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2672 * If the source window was partially obscured #GdkEventExpose events will
2673 * be generated for those areas.
2675 * Returns: %TRUE to stop other handlers from being invoked for the event.
2676 * %FALSE to propagate the event further.
2678 widget_signals[NO_EXPOSE_EVENT] =
2679 g_signal_new (I_("no-expose-event"),
2680 G_TYPE_FROM_CLASS (klass),
2682 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2683 _gtk_boolean_handled_accumulator, NULL,
2684 _gtk_marshal_BOOLEAN__BOXED,
2686 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2689 * GtkWidget::window-state-event:
2690 * @widget: the object which received the signal
2691 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2692 * triggered this signal.
2694 * The ::window-state-event will be emitted when the state of the
2695 * toplevel window associated to the @widget changes.
2697 * To receive this signal the #GdkWindow associated to the widget
2698 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2699 * this mask automatically for all new windows.
2701 * Returns: %TRUE to stop other handlers from being invoked for the
2702 * event. %FALSE to propagate the event further.
2704 widget_signals[WINDOW_STATE_EVENT] =
2705 g_signal_new (I_("window-state-event"),
2706 G_TYPE_FROM_CLASS (klass),
2708 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2709 _gtk_boolean_handled_accumulator, NULL,
2710 _gtk_marshal_BOOLEAN__BOXED,
2712 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2715 * GtkWidget::damage-event:
2716 * @widget: the object which received the signal
2717 * @event: the #GdkEventExpose event
2719 * Emitted when a redirected window belonging to @widget gets drawn into.
2720 * The region/area members of the event shows what area of the redirected
2721 * drawable was drawn into.
2723 * Returns: %TRUE to stop other handlers from being invoked for the event.
2724 * %FALSE to propagate the event further.
2728 widget_signals[DAMAGE_EVENT] =
2729 g_signal_new (I_("damage-event"),
2730 G_TYPE_FROM_CLASS (klass),
2733 _gtk_boolean_handled_accumulator, NULL,
2734 _gtk_marshal_BOOLEAN__BOXED,
2736 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2739 * GtkWidget::grab-broken-event:
2740 * @widget: the object which received the signal
2741 * @event: the #GdkEventGrabBroken event
2743 * Emitted when a pointer or keyboard grab on a window belonging
2744 * to @widget gets broken.
2746 * On X11, this happens when the grab window becomes unviewable
2747 * (i.e. it or one of its ancestors is unmapped), or if the same
2748 * application grabs the pointer or keyboard again.
2750 * Returns: %TRUE to stop other handlers from being invoked for
2751 * the event. %FALSE to propagate the event further.
2755 widget_signals[GRAB_BROKEN] =
2756 g_signal_new (I_("grab-broken-event"),
2757 G_TYPE_FROM_CLASS (klass),
2759 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2760 _gtk_boolean_handled_accumulator, NULL,
2761 _gtk_marshal_BOOLEAN__BOXED,
2763 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2766 * GtkWidget::query-tooltip:
2767 * @widget: the object which received the signal
2768 * @x: the x coordinate of the cursor position where the request has
2769 * been emitted, relative to @widget->window
2770 * @y: the y coordinate of the cursor position where the request has
2771 * been emitted, relative to @widget->window
2772 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2773 * @tooltip: a #GtkTooltip
2775 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2776 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2777 * focus in keyboard mode.
2779 * Using the given coordinates, the signal handler should determine
2780 * whether a tooltip should be shown for @widget. If this is the case
2781 * %TRUE should be returned, %FALSE otherwise. Note that if
2782 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2783 * should not be used.
2785 * The signal handler is free to manipulate @tooltip with the therefore
2786 * destined function calls.
2788 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2792 widget_signals[QUERY_TOOLTIP] =
2793 g_signal_new (I_("query-tooltip"),
2794 G_TYPE_FROM_CLASS (klass),
2796 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2797 _gtk_boolean_handled_accumulator, NULL,
2798 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2806 * GtkWidget::popup-menu
2807 * @widget: the object which received the signal
2809 * This signal gets emitted whenever a widget should pop up a context
2810 * menu. This usually happens through the standard key binding mechanism;
2811 * by pressing a certain key while a widget is focused, the user can cause
2812 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2813 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2814 * for an example of how to use this signal.
2816 * Returns: %TRUE if a menu was activated
2818 widget_signals[POPUP_MENU] =
2819 g_signal_new (I_("popup-menu"),
2820 G_TYPE_FROM_CLASS (klass),
2821 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2822 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2823 _gtk_boolean_handled_accumulator, NULL,
2824 _gtk_marshal_BOOLEAN__VOID,
2828 * GtkWidget::show-help:
2829 * @widget: the object which received the signal.
2832 widget_signals[SHOW_HELP] =
2833 g_signal_new (I_("show-help"),
2834 G_TYPE_FROM_CLASS (klass),
2835 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2836 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2837 _gtk_boolean_handled_accumulator, NULL,
2838 _gtk_marshal_BOOLEAN__ENUM,
2840 GTK_TYPE_WIDGET_HELP_TYPE);
2843 * GtkWidget::accel-closures-changed:
2844 * @widget: the object which received the signal.
2846 widget_signals[ACCEL_CLOSURES_CHANGED] =
2847 g_signal_new (I_("accel-closures-changed"),
2848 G_TYPE_FROM_CLASS (klass),
2852 _gtk_marshal_VOID__VOID,
2856 * GtkWidget::screen-changed:
2857 * @widget: the object on which the signal is emitted
2858 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2859 * widget was not associated with a screen before
2861 * The ::screen-changed signal gets emitted when the
2862 * screen of a widget has changed.
2864 widget_signals[SCREEN_CHANGED] =
2865 g_signal_new (I_("screen-changed"),
2866 G_TYPE_FROM_CLASS (klass),
2868 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2870 _gtk_marshal_VOID__OBJECT,
2875 * GtkWidget::can-activate-accel:
2876 * @widget: the object which received the signal
2877 * @signal_id: the ID of a signal installed on @widget
2879 * Determines whether an accelerator that activates the signal
2880 * identified by @signal_id can currently be activated.
2881 * This signal is present to allow applications and derived
2882 * widgets to override the default #GtkWidget handling
2883 * for determining whether an accelerator can be activated.
2885 * Returns: %TRUE if the signal can be activated.
2887 widget_signals[CAN_ACTIVATE_ACCEL] =
2888 g_signal_new (I_("can-activate-accel"),
2889 G_TYPE_FROM_CLASS (klass),
2891 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2892 _gtk_boolean_handled_accumulator, NULL,
2893 _gtk_marshal_BOOLEAN__UINT,
2894 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2896 binding_set = gtk_binding_set_by_class (klass);
2897 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2899 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2902 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2904 GTK_TYPE_WIDGET_HELP_TYPE,
2905 GTK_WIDGET_HELP_TOOLTIP);
2906 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2908 GTK_TYPE_WIDGET_HELP_TYPE,
2909 GTK_WIDGET_HELP_TOOLTIP);
2910 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2912 GTK_TYPE_WIDGET_HELP_TYPE,
2913 GTK_WIDGET_HELP_WHATS_THIS);
2914 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2916 GTK_TYPE_WIDGET_HELP_TYPE,
2917 GTK_WIDGET_HELP_WHATS_THIS);
2919 gtk_widget_class_install_style_property (klass,
2920 g_param_spec_boolean ("interior-focus",
2921 P_("Interior Focus"),
2922 P_("Whether to draw the focus indicator inside widgets"),
2924 GTK_PARAM_READABLE));
2926 gtk_widget_class_install_style_property (klass,
2927 g_param_spec_int ("focus-line-width",
2928 P_("Focus linewidth"),
2929 P_("Width, in pixels, of the focus indicator line"),
2931 GTK_PARAM_READABLE));
2933 gtk_widget_class_install_style_property (klass,
2934 g_param_spec_string ("focus-line-pattern",
2935 P_("Focus line dash pattern"),
2936 P_("Dash pattern used to draw the focus indicator"),
2938 GTK_PARAM_READABLE));
2939 gtk_widget_class_install_style_property (klass,
2940 g_param_spec_int ("focus-padding",
2941 P_("Focus padding"),
2942 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2944 GTK_PARAM_READABLE));
2945 gtk_widget_class_install_style_property (klass,
2946 g_param_spec_boxed ("cursor-color",
2948 P_("Color with which to draw insertion cursor"),
2950 GTK_PARAM_READABLE));
2951 gtk_widget_class_install_style_property (klass,
2952 g_param_spec_boxed ("secondary-cursor-color",
2953 P_("Secondary cursor color"),
2954 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2956 GTK_PARAM_READABLE));
2957 gtk_widget_class_install_style_property (klass,
2958 g_param_spec_float ("cursor-aspect-ratio",
2959 P_("Cursor line aspect ratio"),
2960 P_("Aspect ratio with which to draw insertion cursor"),
2962 GTK_PARAM_READABLE));
2964 gtk_widget_class_install_style_property (klass,
2965 g_param_spec_boolean ("window-dragging",
2966 P_("Window dragging"),
2967 P_("Whether windows can be dragged by clicking on empty areas"),
2969 GTK_PARAM_READABLE));
2972 * GtkWidget:link-color:
2974 * The "link-color" style property defines the color of unvisited links.
2978 gtk_widget_class_install_style_property (klass,
2979 g_param_spec_boxed ("link-color",
2980 P_("Unvisited Link Color"),
2981 P_("Color of unvisited links"),
2983 GTK_PARAM_READABLE));
2986 * GtkWidget:visited-link-color:
2988 * The "visited-link-color" style property defines the color of visited links.
2992 gtk_widget_class_install_style_property (klass,
2993 g_param_spec_boxed ("visited-link-color",
2994 P_("Visited Link Color"),
2995 P_("Color of visited links"),
2997 GTK_PARAM_READABLE));
3000 * GtkWidget:wide-separators:
3002 * The "wide-separators" style property defines whether separators have
3003 * configurable width and should be drawn using a box instead of a line.
3007 gtk_widget_class_install_style_property (klass,
3008 g_param_spec_boolean ("wide-separators",
3009 P_("Wide Separators"),
3010 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
3012 GTK_PARAM_READABLE));
3015 * GtkWidget:separator-width:
3017 * The "separator-width" style property defines the width of separators.
3018 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3022 gtk_widget_class_install_style_property (klass,
3023 g_param_spec_int ("separator-width",
3024 P_("Separator Width"),
3025 P_("The width of separators if wide-separators is TRUE"),
3027 GTK_PARAM_READABLE));
3030 * GtkWidget:separator-height:
3032 * The "separator-height" style property defines the height of separators.
3033 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
3037 gtk_widget_class_install_style_property (klass,
3038 g_param_spec_int ("separator-height",
3039 P_("Separator Height"),
3040 P_("The height of separators if \"wide-separators\" is TRUE"),
3042 GTK_PARAM_READABLE));
3045 * GtkWidget:scroll-arrow-hlength:
3047 * The "scroll-arrow-hlength" style property defines the length of
3048 * horizontal scroll arrows.
3052 gtk_widget_class_install_style_property (klass,
3053 g_param_spec_int ("scroll-arrow-hlength",
3054 P_("Horizontal Scroll Arrow Length"),
3055 P_("The length of horizontal scroll arrows"),
3057 GTK_PARAM_READABLE));
3060 * GtkWidget:scroll-arrow-vlength:
3062 * The "scroll-arrow-vlength" style property defines the length of
3063 * vertical scroll arrows.
3067 gtk_widget_class_install_style_property (klass,
3068 g_param_spec_int ("scroll-arrow-vlength",
3069 P_("Vertical Scroll Arrow Length"),
3070 P_("The length of vertical scroll arrows"),
3072 GTK_PARAM_READABLE));
3074 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
3078 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
3082 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
3083 for (node = list; node; node = node->next)
3085 GParamSpec *pspec = node->data;
3087 g_param_spec_pool_remove (style_property_spec_pool, pspec);
3088 g_param_spec_unref (pspec);
3094 gtk_widget_set_property (GObject *object,
3096 const GValue *value,
3099 GtkWidget *widget = GTK_WIDGET (object);
3104 gchar *tooltip_markup;
3105 const gchar *tooltip_text;
3106 GtkWindow *tooltip_window;
3109 gtk_widget_set_name (widget, g_value_get_string (value));
3112 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3114 case PROP_WIDTH_REQUEST:
3115 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2, 0);
3117 case PROP_HEIGHT_REQUEST:
3118 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value), 0);
3121 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3123 case PROP_SENSITIVE:
3124 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3126 case PROP_APP_PAINTABLE:
3127 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3129 case PROP_CAN_FOCUS:
3130 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3132 case PROP_HAS_FOCUS:
3133 if (g_value_get_boolean (value))
3134 gtk_widget_grab_focus (widget);
3137 if (g_value_get_boolean (value))
3138 gtk_widget_grab_focus (widget);
3140 case PROP_CAN_DEFAULT:
3141 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3143 case PROP_HAS_DEFAULT:
3144 if (g_value_get_boolean (value))
3145 gtk_widget_grab_default (widget);
3147 case PROP_RECEIVES_DEFAULT:
3148 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3151 gtk_widget_set_style (widget, g_value_get_object (value));
3154 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3155 gtk_widget_set_events (widget, g_value_get_flags (value));
3157 case PROP_EXTENSION_EVENTS:
3158 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3160 case PROP_NO_SHOW_ALL:
3161 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3163 case PROP_HAS_TOOLTIP:
3164 gtk_widget_real_set_has_tooltip (widget,
3165 g_value_get_boolean (value), FALSE);
3167 case PROP_TOOLTIP_MARKUP:
3168 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3169 tooltip_markup = g_value_dup_string (value);
3171 /* Treat an empty string as a NULL string,
3172 * because an empty string would be useless for a tooltip:
3174 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3176 g_free (tooltip_markup);
3177 tooltip_markup = NULL;
3180 g_object_set_qdata_full (object, quark_tooltip_markup,
3181 tooltip_markup, g_free);
3183 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3184 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3185 if (gtk_widget_get_visible (widget))
3186 gtk_widget_queue_tooltip_query (widget);
3188 case PROP_TOOLTIP_TEXT:
3189 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3191 tooltip_text = g_value_get_string (value);
3193 /* Treat an empty string as a NULL string,
3194 * because an empty string would be useless for a tooltip:
3196 if (tooltip_text && (strlen (tooltip_text) == 0))
3197 tooltip_text = NULL;
3199 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3201 g_object_set_qdata_full (object, quark_tooltip_markup,
3202 tooltip_markup, g_free);
3204 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3205 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3206 if (gtk_widget_get_visible (widget))
3207 gtk_widget_queue_tooltip_query (widget);
3209 case PROP_DOUBLE_BUFFERED:
3210 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3213 gtk_widget_set_halign (widget, g_value_get_enum (value));
3216 gtk_widget_set_valign (widget, g_value_get_enum (value));
3218 case PROP_MARGIN_LEFT:
3219 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3221 case PROP_MARGIN_RIGHT:
3222 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3224 case PROP_MARGIN_TOP:
3225 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3227 case PROP_MARGIN_BOTTOM:
3228 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3231 g_object_freeze_notify (G_OBJECT (widget));
3232 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3233 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3234 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3235 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3236 g_object_thaw_notify (G_OBJECT (widget));
3239 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3241 case PROP_HEXPAND_SET:
3242 gtk_widget_set_hexpand_set (widget, g_value_get_boolean (value));
3245 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3247 case PROP_VEXPAND_SET:
3248 gtk_widget_set_vexpand_set (widget, g_value_get_boolean (value));
3251 g_object_freeze_notify (G_OBJECT (widget));
3252 gtk_widget_set_hexpand (widget, g_value_get_boolean (value));
3253 gtk_widget_set_vexpand (widget, g_value_get_boolean (value));
3254 g_object_thaw_notify (G_OBJECT (widget));
3257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3263 gtk_widget_get_property (GObject *object,
3268 GtkWidget *widget = GTK_WIDGET (object);
3269 GtkWidgetPrivate *priv = widget->priv;
3278 g_value_set_string (value, priv->name);
3280 g_value_set_static_string (value, "");
3283 g_value_set_object (value, priv->parent);
3285 case PROP_WIDTH_REQUEST:
3288 gtk_widget_get_size_request (widget, &w, NULL);
3289 g_value_set_int (value, w);
3292 case PROP_HEIGHT_REQUEST:
3295 gtk_widget_get_size_request (widget, NULL, &h);
3296 g_value_set_int (value, h);
3300 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3302 case PROP_SENSITIVE:
3303 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3305 case PROP_APP_PAINTABLE:
3306 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3308 case PROP_CAN_FOCUS:
3309 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3311 case PROP_HAS_FOCUS:
3312 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3315 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3317 case PROP_CAN_DEFAULT:
3318 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3320 case PROP_HAS_DEFAULT:
3321 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3323 case PROP_RECEIVES_DEFAULT:
3324 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3326 case PROP_COMPOSITE_CHILD:
3327 g_value_set_boolean (value, widget->priv->composite_child);
3330 g_value_set_object (value, gtk_widget_get_style (widget));
3333 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3334 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3336 case PROP_EXTENSION_EVENTS:
3337 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3338 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3340 case PROP_NO_SHOW_ALL:
3341 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3343 case PROP_HAS_TOOLTIP:
3344 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3346 case PROP_TOOLTIP_TEXT:
3348 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3351 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3352 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3354 g_value_take_string (value, text);
3357 case PROP_TOOLTIP_MARKUP:
3358 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3361 g_value_set_object (value, gtk_widget_get_window (widget));
3363 case PROP_DOUBLE_BUFFERED:
3364 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3367 g_value_set_enum (value, gtk_widget_get_halign (widget));
3370 g_value_set_enum (value, gtk_widget_get_valign (widget));
3372 case PROP_MARGIN_LEFT:
3373 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3375 case PROP_MARGIN_RIGHT:
3376 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3378 case PROP_MARGIN_TOP:
3379 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3381 case PROP_MARGIN_BOTTOM:
3382 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3386 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3387 if (aux_info == NULL)
3389 g_value_set_int (value, 0);
3393 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3394 aux_info->margin.right),
3395 MAX (aux_info->margin.top,
3396 aux_info->margin.bottom)));
3401 g_value_set_boolean (value, gtk_widget_get_hexpand (widget));
3403 case PROP_HEXPAND_SET:
3404 g_value_set_boolean (value, gtk_widget_get_hexpand_set (widget));
3407 g_value_set_boolean (value, gtk_widget_get_vexpand (widget));
3409 case PROP_VEXPAND_SET:
3410 g_value_set_boolean (value, gtk_widget_get_vexpand_set (widget));
3413 g_value_set_boolean (value,
3414 gtk_widget_get_hexpand (widget) &&
3415 gtk_widget_get_vexpand (widget));
3418 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3424 gtk_widget_init (GtkWidget *widget)
3426 GtkWidgetPrivate *priv;
3428 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3431 priv = widget->priv;
3433 priv->child_visible = TRUE;
3434 priv->state = GTK_STATE_NORMAL;
3435 priv->saved_state = GTK_STATE_NORMAL;
3437 priv->allocation.x = -1;
3438 priv->allocation.y = -1;
3439 priv->allocation.width = 1;
3440 priv->allocation.height = 1;
3441 priv->window = NULL;
3442 priv->parent = NULL;
3444 priv->sensitive = TRUE;
3445 priv->parent_sensitive = TRUE;
3446 priv->composite_child = composite_child_stack != 0;
3447 priv->double_buffered = TRUE;
3448 priv->redraw_on_alloc = TRUE;
3449 priv->width_request_needed = TRUE;
3450 priv->height_request_needed = TRUE;
3451 priv->alloc_needed = TRUE;
3453 /* this will be set to TRUE if the widget gets a child or if the
3454 * expand flag is set on the widget, but until one of those happen
3455 * we know the expand is already properly FALSE.
3457 * We really want to default FALSE here to avoid computing expand
3458 * all over the place while initially building a widget tree.
3460 priv->need_compute_expand = FALSE;
3462 priv->style = gtk_widget_get_default_style ();
3463 g_object_ref (priv->style);
3468 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3470 GParamSpec **pspecs)
3472 GtkWidgetPrivate *priv = widget->priv;
3473 GtkWidget *container = priv->parent;
3476 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3477 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3481 * gtk_widget_freeze_child_notify:
3482 * @widget: a #GtkWidget
3484 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3485 * signals are queued until gtk_widget_thaw_child_notify() is called
3488 * This is the analogue of g_object_freeze_notify() for child properties.
3491 gtk_widget_freeze_child_notify (GtkWidget *widget)
3493 g_return_if_fail (GTK_IS_WIDGET (widget));
3495 if (!G_OBJECT (widget)->ref_count)
3498 g_object_ref (widget);
3499 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3500 g_object_unref (widget);
3504 * gtk_widget_child_notify:
3505 * @widget: a #GtkWidget
3506 * @child_property: the name of a child property installed on the
3507 * class of @widget<!-- -->'s parent
3509 * Emits a #GtkWidget::child-notify signal for the
3510 * <link linkend="child-properties">child property</link> @child_property
3513 * This is the analogue of g_object_notify() for child properties.
3516 gtk_widget_child_notify (GtkWidget *widget,
3517 const gchar *child_property)
3519 GtkWidgetPrivate *priv = widget->priv;
3522 g_return_if_fail (GTK_IS_WIDGET (widget));
3523 g_return_if_fail (child_property != NULL);
3524 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3527 g_object_ref (widget);
3528 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3530 G_OBJECT_TYPE (priv->parent),
3533 g_warning ("%s: container class `%s' has no child property named `%s'",
3535 G_OBJECT_TYPE_NAME (priv->parent),
3539 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3541 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3542 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3544 g_object_unref (widget);
3548 * gtk_widget_thaw_child_notify:
3549 * @widget: a #GtkWidget
3551 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3552 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3556 gtk_widget_thaw_child_notify (GtkWidget *widget)
3558 GObjectNotifyQueue *nqueue;
3560 g_return_if_fail (GTK_IS_WIDGET (widget));
3562 if (!G_OBJECT (widget)->ref_count)
3565 g_object_ref (widget);
3566 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3567 if (!nqueue || !nqueue->freeze_count)
3568 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3569 G_OBJECT_TYPE_NAME (widget), widget);
3571 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3572 g_object_unref (widget);
3578 * @type: type ID of the widget to create
3579 * @first_property_name: name of first property to set
3580 * @Varargs: value of first property, followed by more properties,
3583 * This is a convenience function for creating a widget and setting
3584 * its properties in one go. For example you might write:
3585 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3586 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3587 * g_object_new(), but returns a widget so you don't have to
3588 * cast the object yourself.
3590 * Return value: a new #GtkWidget of type @widget_type
3593 gtk_widget_new (GType type,
3594 const gchar *first_property_name,
3600 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3602 va_start (var_args, first_property_name);
3603 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3610 gtk_widget_queue_draw_child (GtkWidget *widget)
3612 GtkWidgetPrivate *priv = widget->priv;
3615 parent = priv->parent;
3616 if (parent && gtk_widget_is_drawable (parent))
3617 gtk_widget_queue_draw_area (parent,
3620 priv->allocation.width,
3621 priv->allocation.height);
3625 * gtk_widget_unparent:
3626 * @widget: a #GtkWidget
3628 * This function is only for use in widget implementations.
3629 * Should be called by implementations of the remove method
3630 * on #GtkContainer, to dissociate a child from the container.
3633 gtk_widget_unparent (GtkWidget *widget)
3635 GtkWidgetPrivate *priv;
3636 GObjectNotifyQueue *nqueue;
3637 GtkWidget *toplevel;
3638 GtkWidget *old_parent;
3640 g_return_if_fail (GTK_IS_WIDGET (widget));
3642 priv = widget->priv;
3644 if (priv->parent == NULL)
3647 /* keep this function in sync with gtk_menu_detach()
3650 g_object_freeze_notify (G_OBJECT (widget));
3651 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3653 toplevel = gtk_widget_get_toplevel (widget);
3654 if (gtk_widget_is_toplevel (toplevel))
3655 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3657 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3658 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3660 /* If we are unanchoring the child, we save around the toplevel
3661 * to emit hierarchy changed
3663 if (priv->parent->priv->anchored)
3664 g_object_ref (toplevel);
3668 gtk_widget_queue_draw_child (widget);
3670 /* Reset the width and height here, to force reallocation if we
3671 * get added back to a new parent. This won't work if our new
3672 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3673 * (would 0x0 be OK here?)
3675 priv->allocation.width = 1;
3676 priv->allocation.height = 1;
3678 if (gtk_widget_get_realized (widget))
3680 if (priv->in_reparent)
3681 gtk_widget_unmap (widget);
3683 gtk_widget_unrealize (widget);
3686 /* Removing a widget from a container restores the child visible
3687 * flag to the default state, so it doesn't affect the child
3688 * in the next parent.
3690 priv->child_visible = TRUE;
3692 old_parent = priv->parent;
3693 priv->parent = NULL;
3694 gtk_widget_set_parent_window (widget, NULL);
3696 /* parent may no longer expand if the removed
3697 * child was expand=TRUE and could therefore
3700 if (gtk_widget_get_visible (widget) &&
3701 (priv->need_compute_expand ||
3702 priv->computed_hexpand ||
3703 priv->computed_vexpand))
3705 gtk_widget_queue_compute_expand (old_parent);
3708 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3711 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3712 g_object_unref (toplevel);
3715 g_object_notify (G_OBJECT (widget), "parent");
3716 g_object_thaw_notify (G_OBJECT (widget));
3718 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3719 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3720 g_object_unref (widget);
3724 * gtk_widget_destroy:
3725 * @widget: a #GtkWidget
3727 * Destroys a widget.
3730 * destroyed, it will break any references it holds to other objects.
3731 * If the widget is inside a container, the widget will be removed
3732 * from the container. If the widget is a toplevel (derived from
3733 * #GtkWindow), it will be removed from the list of toplevels, and the
3734 * reference GTK+ holds to it will be removed. Removing a
3735 * widget from its container or the list of toplevels results in the
3736 * widget being finalized, unless you've added additional references
3737 * to the widget with g_object_ref().
3739 * In most cases, only toplevel widgets (windows) require explicit
3740 * destruction, because when you destroy a toplevel its children will
3741 * be destroyed as well.
3744 gtk_widget_destroy (GtkWidget *widget)
3746 g_return_if_fail (GTK_IS_WIDGET (widget));
3748 if (!widget->priv->in_destruction)
3749 g_object_run_dispose (G_OBJECT (widget));
3753 * gtk_widget_destroyed:
3754 * @widget: a #GtkWidget
3755 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3757 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3758 * %NULL. It's intended to be used as a callback connected to the
3759 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3760 * as a signal handler, and pass the address of your widget variable
3761 * as user data. Then when the widget is destroyed, the variable will
3762 * be set to %NULL. Useful for example to avoid multiple copies
3763 * of the same dialog.
3766 gtk_widget_destroyed (GtkWidget *widget,
3767 GtkWidget **widget_pointer)
3769 /* Don't make any assumptions about the
3771 * Even check widget_pointer.
3774 *widget_pointer = NULL;
3779 * @widget: a #GtkWidget
3781 * Flags a widget to be displayed. Any widget that isn't shown will
3782 * not appear on the screen. If you want to show all the widgets in a
3783 * container, it's easier to call gtk_widget_show_all() on the
3784 * container, instead of individually showing the widgets.
3786 * Remember that you have to show the containers containing a widget,
3787 * in addition to the widget itself, before it will appear onscreen.
3789 * When a toplevel container is shown, it is immediately realized and
3790 * mapped; other shown widgets are realized and mapped when their
3791 * toplevel container is realized and mapped.
3794 gtk_widget_show (GtkWidget *widget)
3796 g_return_if_fail (GTK_IS_WIDGET (widget));
3798 if (!gtk_widget_get_visible (widget))
3800 g_object_ref (widget);
3801 if (!gtk_widget_is_toplevel (widget))
3802 gtk_widget_queue_resize (widget);
3804 /* see comment in set_parent() for why this should and can be
3807 if (widget->priv->need_compute_expand ||
3808 widget->priv->computed_hexpand ||
3809 widget->priv->computed_vexpand)
3811 gtk_widget_queue_compute_expand (widget);
3814 g_signal_emit (widget, widget_signals[SHOW], 0);
3815 g_object_notify (G_OBJECT (widget), "visible");
3816 g_object_unref (widget);
3821 gtk_widget_real_show (GtkWidget *widget)
3823 GtkWidgetPrivate *priv = widget->priv;
3825 if (!gtk_widget_get_visible (widget))
3827 priv->visible = TRUE;
3830 gtk_widget_get_mapped (priv->parent) &&
3831 gtk_widget_get_child_visible (widget) &&
3832 !gtk_widget_get_mapped (widget))
3833 gtk_widget_map (widget);
3838 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3841 g_signal_handlers_disconnect_by_func (widget,
3842 gtk_widget_show_map_callback,
3847 * gtk_widget_show_now:
3848 * @widget: a #GtkWidget
3850 * Shows a widget. If the widget is an unmapped toplevel widget
3851 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3852 * loop and wait for the window to actually be mapped. Be careful;
3853 * because the main loop is running, anything can happen during
3857 gtk_widget_show_now (GtkWidget *widget)
3861 g_return_if_fail (GTK_IS_WIDGET (widget));
3863 /* make sure we will get event */
3864 if (!gtk_widget_get_mapped (widget) &&
3865 gtk_widget_is_toplevel (widget))
3867 gtk_widget_show (widget);
3869 g_signal_connect (widget, "map-event",
3870 G_CALLBACK (gtk_widget_show_map_callback),
3874 gtk_main_iteration ();
3877 gtk_widget_show (widget);
3882 * @widget: a #GtkWidget
3884 * Reverses the effects of gtk_widget_show(), causing the widget to be
3885 * hidden (invisible to the user).
3888 gtk_widget_hide (GtkWidget *widget)
3890 g_return_if_fail (GTK_IS_WIDGET (widget));
3892 if (gtk_widget_get_visible (widget))
3894 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3896 g_object_ref (widget);
3897 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3898 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3900 /* a parent may now be expand=FALSE since we're hidden. */
3901 if (widget->priv->need_compute_expand ||
3902 widget->priv->computed_hexpand ||
3903 widget->priv->computed_vexpand)
3905 gtk_widget_queue_compute_expand (widget);
3908 g_signal_emit (widget, widget_signals[HIDE], 0);
3909 if (!gtk_widget_is_toplevel (widget))
3910 gtk_widget_queue_resize (widget);
3911 g_object_notify (G_OBJECT (widget), "visible");
3912 g_object_unref (widget);
3917 gtk_widget_real_hide (GtkWidget *widget)
3919 if (gtk_widget_get_visible (widget))
3921 widget->priv->visible = FALSE;
3923 if (gtk_widget_get_mapped (widget))
3924 gtk_widget_unmap (widget);
3929 * gtk_widget_hide_on_delete:
3930 * @widget: a #GtkWidget
3932 * Utility function; intended to be connected to the #GtkWidget::delete-event
3933 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3934 * argument, then returns %TRUE. If connected to ::delete-event, the
3935 * result is that clicking the close button for a window (on the
3936 * window frame, top right corner usually) will hide but not destroy
3937 * the window. By default, GTK+ destroys windows when ::delete-event
3940 * Return value: %TRUE
3943 gtk_widget_hide_on_delete (GtkWidget *widget)
3945 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3947 gtk_widget_hide (widget);
3953 * gtk_widget_show_all:
3954 * @widget: a #GtkWidget
3956 * Recursively shows a widget, and any child widgets (if the widget is
3960 gtk_widget_show_all (GtkWidget *widget)
3962 GtkWidgetClass *class;
3964 g_return_if_fail (GTK_IS_WIDGET (widget));
3966 if (gtk_widget_get_no_show_all (widget))
3969 class = GTK_WIDGET_GET_CLASS (widget);
3971 if (class->show_all)
3972 class->show_all (widget);
3977 * @widget: a #GtkWidget
3979 * This function is only for use in widget implementations. Causes
3980 * a widget to be mapped if it isn't already.
3983 gtk_widget_map (GtkWidget *widget)
3985 GtkWidgetPrivate *priv;
3987 g_return_if_fail (GTK_IS_WIDGET (widget));
3988 g_return_if_fail (gtk_widget_get_visible (widget));
3989 g_return_if_fail (gtk_widget_get_child_visible (widget));
3991 priv = widget->priv;
3993 if (!gtk_widget_get_mapped (widget))
3995 if (!gtk_widget_get_realized (widget))
3996 gtk_widget_realize (widget);
3998 g_signal_emit (widget, widget_signals[MAP], 0);
4000 if (!gtk_widget_get_has_window (widget))
4001 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4007 * @widget: a #GtkWidget
4009 * This function is only for use in widget implementations. Causes
4010 * a widget to be unmapped if it's currently mapped.
4013 gtk_widget_unmap (GtkWidget *widget)
4015 GtkWidgetPrivate *priv;
4017 g_return_if_fail (GTK_IS_WIDGET (widget));
4019 priv = widget->priv;
4021 if (gtk_widget_get_mapped (widget))
4023 if (!gtk_widget_get_has_window (widget))
4024 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
4025 _gtk_tooltip_hide (widget);
4026 g_signal_emit (widget, widget_signals[UNMAP], 0);
4031 gtk_widget_set_extension_events_internal (GtkWidget *widget,
4032 GdkExtensionMode mode,
4035 GtkWidgetPrivate *priv = widget->priv;
4036 GList *free_list = NULL;
4039 if (window_list == NULL)
4041 if (gtk_widget_get_has_window (widget))
4042 window_list = g_list_prepend (NULL, priv->window);
4044 window_list = gdk_window_get_children (priv->window);
4046 free_list = window_list;
4049 for (l = window_list; l != NULL; l = l->next)
4051 GdkWindow *window = l->data;
4054 gdk_window_get_user_data (window, &user_data);
4055 if (user_data == widget)
4059 gdk_input_set_extension_events (window,
4060 gdk_window_get_events (window),
4063 children = gdk_window_get_children (window);
4066 gtk_widget_set_extension_events_internal (widget, mode, children);
4067 g_list_free (children);
4073 g_list_free (free_list);
4077 _gtk_widget_enable_device_events (GtkWidget *widget)
4079 GHashTable *device_events;
4080 GHashTableIter iter;
4081 gpointer key, value;
4083 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
4088 g_hash_table_iter_init (&iter, device_events);
4090 while (g_hash_table_iter_next (&iter, &key, &value))
4093 GdkEventMask event_mask;
4096 event_mask = GPOINTER_TO_UINT (value);
4097 gtk_widget_add_events_internal (widget, device, event_mask);
4102 * gtk_widget_realize:
4103 * @widget: a #GtkWidget
4105 * Creates the GDK (windowing system) resources associated with a
4106 * widget. For example, @widget->window will be created when a widget
4107 * is realized. Normally realization happens implicitly; if you show
4108 * a widget and all its parent containers, then the widget will be
4109 * realized and mapped automatically.
4111 * Realizing a widget requires all
4112 * the widget's parent widgets to be realized; calling
4113 * gtk_widget_realize() realizes the widget's parents in addition to
4114 * @widget itself. If a widget is not yet inside a toplevel window
4115 * when you realize it, bad things will happen.
4117 * This function is primarily used in widget implementations, and
4118 * isn't very useful otherwise. Many times when you think you might
4119 * need it, a better approach is to connect to a signal that will be
4120 * called after the widget is realized automatically, such as
4121 * GtkWidget::expose-event. Or simply g_signal_connect () to the
4122 * GtkWidget::realize signal.
4125 gtk_widget_realize (GtkWidget *widget)
4127 GtkWidgetPrivate *priv;
4128 GdkExtensionMode mode;
4129 cairo_region_t *region;
4131 g_return_if_fail (GTK_IS_WIDGET (widget));
4132 g_return_if_fail (widget->priv->anchored ||
4133 GTK_IS_INVISIBLE (widget));
4135 priv = widget->priv;
4137 if (!gtk_widget_get_realized (widget))
4140 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
4141 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4144 if (priv->parent == NULL &&
4145 !gtk_widget_is_toplevel (widget))
4146 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4147 "inside a toplevel window is not going to work very well. "
4148 "Widgets must be inside a toplevel container before realizing them.");
4150 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4151 gtk_widget_realize (priv->parent);
4153 gtk_widget_ensure_style (widget);
4155 g_signal_emit (widget, widget_signals[REALIZE], 0);
4157 gtk_widget_real_set_has_tooltip (widget,
4158 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4161 if (priv->has_shape_mask)
4163 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4164 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4167 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4169 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4171 mode = gtk_widget_get_extension_events (widget);
4172 if (mode != GDK_EXTENSION_EVENTS_NONE)
4173 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4175 if (priv->multidevice)
4176 gdk_window_set_support_multidevice (priv->window, TRUE);
4178 _gtk_widget_enable_device_events (widget);
4183 * gtk_widget_unrealize:
4184 * @widget: a #GtkWidget
4186 * This function is only useful in widget implementations.
4187 * Causes a widget to be unrealized (frees all GDK resources
4188 * associated with the widget, such as @widget->window).
4191 gtk_widget_unrealize (GtkWidget *widget)
4193 g_return_if_fail (GTK_IS_WIDGET (widget));
4195 if (widget->priv->has_shape_mask)
4196 gtk_widget_shape_combine_region (widget, NULL);
4198 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4199 gtk_widget_input_shape_combine_region (widget, NULL);
4201 if (gtk_widget_get_realized (widget))
4203 g_object_ref (widget);
4204 _gtk_tooltip_hide (widget);
4205 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4206 gtk_widget_set_realized (widget, FALSE);
4207 gtk_widget_set_mapped (widget, FALSE);
4208 g_object_unref (widget);
4212 /*****************************************
4214 *****************************************/
4217 * gtk_widget_queue_draw_region:
4218 * @widget: a #GtkWidget
4219 * @region: region to draw
4221 * Invalidates the rectangular area of @widget defined by @region by
4222 * calling gdk_window_invalidate_region() on the widget's window and
4223 * all its child windows. Once the main loop becomes idle (after the
4224 * current batch of events has been processed, roughly), the window
4225 * will receive expose events for the union of all regions that have
4228 * Normally you would only use this function in widget
4229 * implementations. You might also use it to schedule a redraw of a
4230 * #GtkDrawingArea or some portion thereof.
4233 gtk_widget_queue_draw_region (GtkWidget *widget,
4234 cairo_region_t *region)
4236 GtkWidgetPrivate *priv;
4239 g_return_if_fail (GTK_IS_WIDGET (widget));
4241 priv = widget->priv;
4243 if (!gtk_widget_get_realized (widget))
4246 /* Just return if the widget or one of its ancestors isn't mapped */
4247 for (w = widget; w != NULL; w = w->priv->parent)
4248 if (!gtk_widget_get_mapped (w))
4251 gdk_window_invalidate_region (priv->window, region, TRUE);
4255 * gtk_widget_queue_draw_area:
4256 * @widget: a #GtkWidget
4257 * @x: x coordinate of upper-left corner of rectangle to redraw
4258 * @y: y coordinate of upper-left corner of rectangle to redraw
4259 * @width: width of region to draw
4260 * @height: height of region to draw
4262 * Convenience function that calls gtk_widget_queue_draw_region() on
4263 * the region created from the given coordinates.
4266 gtk_widget_queue_draw_area (GtkWidget *widget,
4273 cairo_region_t *region;
4275 g_return_if_fail (GTK_IS_WIDGET (widget));
4280 rect.height = height;
4282 region = cairo_region_create_rectangle (&rect);
4283 gtk_widget_queue_draw_region (widget, region);
4284 cairo_region_destroy (region);
4288 * gtk_widget_queue_draw:
4289 * @widget: a #GtkWidget
4291 * Equivalent to calling gtk_widget_queue_draw_area() for the
4292 * entire area of a widget.
4295 gtk_widget_queue_draw (GtkWidget *widget)
4299 g_return_if_fail (GTK_IS_WIDGET (widget));
4301 gtk_widget_get_allocation (widget, &rect);
4303 if (!gtk_widget_get_has_window (widget))
4304 gtk_widget_queue_draw_area (widget,
4305 rect.x, rect.y, rect.width, rect.height);
4307 gtk_widget_queue_draw_area (widget,
4308 0, 0, rect.width, rect.height);
4312 * gtk_widget_queue_resize:
4313 * @widget: a #GtkWidget
4315 * This function is only for use in widget implementations.
4316 * Flags a widget to have its size renegotiated; should
4317 * be called when a widget for some reason has a new size request.
4318 * For example, when you change the text in a #GtkLabel, #GtkLabel
4319 * queues a resize to ensure there's enough space for the new text.
4322 gtk_widget_queue_resize (GtkWidget *widget)
4324 g_return_if_fail (GTK_IS_WIDGET (widget));
4326 if (gtk_widget_get_realized (widget))
4327 gtk_widget_queue_shallow_draw (widget);
4329 _gtk_size_group_queue_resize (widget, 0);
4333 * gtk_widget_queue_resize_no_redraw:
4334 * @widget: a #GtkWidget
4336 * This function works like gtk_widget_queue_resize(),
4337 * except that the widget is not invalidated.
4342 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4344 g_return_if_fail (GTK_IS_WIDGET (widget));
4346 _gtk_size_group_queue_resize (widget, 0);
4350 * gtk_widget_size_request:
4351 * @widget: a #GtkWidget
4352 * @requisition: (out): a #GtkRequisition to be filled in
4354 * This function is typically used when implementing a #GtkContainer
4355 * subclass. Obtains the preferred size of a widget. The container
4356 * uses this information to arrange its child widgets and decide what
4357 * size allocations to give them with gtk_widget_size_allocate().
4359 * You can also call this function from an application, with some
4360 * caveats. Most notably, getting a size request requires the widget
4361 * to be associated with a screen, because font information may be
4362 * needed. Multihead-aware applications should keep this in mind.
4364 * Also remember that the size request is not necessarily the size
4365 * a widget will actually be allocated.
4367 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4370 gtk_widget_size_request (GtkWidget *widget,
4371 GtkRequisition *requisition)
4373 g_return_if_fail (GTK_IS_WIDGET (widget));
4375 gtk_widget_get_preferred_size (widget, requisition, NULL);
4379 * gtk_widget_get_child_requisition:
4380 * @widget: a #GtkWidget
4381 * @requisition: (out): a #GtkRequisition to be filled in
4383 * This function is only for use in widget implementations. Obtains
4384 * @widget->requisition, unless someone has forced a particular
4385 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4386 * in which case it returns that geometry instead of the widget's
4389 * This function differs from gtk_widget_size_request() in that
4390 * it retrieves the last size request value from @widget->requisition,
4391 * while gtk_widget_size_request() actually calls the "size_request" method
4392 * on @widget to compute the size request and fill in @widget->requisition,
4393 * and only then returns @widget->requisition.
4395 * Because this function does not call the "size_request" method, it
4396 * can only be used when you know that @widget->requisition is
4397 * up-to-date, that is, gtk_widget_size_request() has been called
4398 * since the last time a resize was queued. In general, only container
4399 * implementations have this information; applications should use
4400 * gtk_widget_size_request().
4403 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4406 gtk_widget_get_child_requisition (GtkWidget *widget,
4407 GtkRequisition *requisition)
4409 gtk_widget_get_preferred_size (widget, requisition, NULL);
4413 invalidate_predicate (GdkWindow *window,
4418 gdk_window_get_user_data (window, &user_data);
4420 return (user_data == data);
4423 /* Invalidate @region in widget->window and all children
4424 * of widget->window owned by widget. @region is in the
4425 * same coordinates as widget->allocation and will be
4426 * modified by this call.
4429 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4430 cairo_region_t *region)
4432 GtkWidgetPrivate *priv = widget->priv;
4434 if (!gtk_widget_get_realized (widget))
4437 if (gtk_widget_get_has_window (widget) && priv->parent)
4441 gdk_window_get_position (priv->window, &x, &y);
4442 cairo_region_translate (region, -x, -y);
4445 gdk_window_invalidate_maybe_recurse (priv->window, region,
4446 invalidate_predicate, widget);
4450 * gtk_widget_queue_shallow_draw:
4451 * @widget: a #GtkWidget
4453 * Like gtk_widget_queue_draw(), but only windows owned
4454 * by @widget are invalidated.
4457 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4460 cairo_region_t *region;
4462 if (!gtk_widget_get_realized (widget))
4465 gtk_widget_get_allocation (widget, &rect);
4467 region = cairo_region_create_rectangle (&rect);
4468 gtk_widget_invalidate_widget_windows (widget, region);
4469 cairo_region_destroy (region);
4473 * gtk_widget_size_allocate:
4474 * @widget: a #GtkWidget
4475 * @allocation: (inout): position and size to be allocated to @widget
4477 * This function is only used by #GtkContainer subclasses, to assign a size
4478 * and position to their child widgets.
4480 * In this function, the allocation may be adjusted. It will be forced
4481 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4482 * method on the child will be used to adjust the allocation. Standard
4483 * adjustments include removing the widget's margins, and applying the
4484 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4487 gtk_widget_size_allocate (GtkWidget *widget,
4488 GtkAllocation *allocation)
4490 GtkWidgetPrivate *priv;
4491 GdkRectangle real_allocation;
4492 GdkRectangle old_allocation;
4493 GdkRectangle adjusted_allocation;
4494 gboolean alloc_needed;
4495 gboolean size_changed;
4496 gboolean position_changed;
4498 priv = widget->priv;
4500 g_return_if_fail (GTK_IS_WIDGET (widget));
4502 #ifdef G_ENABLE_DEBUG
4503 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4514 parent = gtk_widget_get_parent (parent);
4517 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4518 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4519 2 * depth, " ", name,
4520 allocation->width, allocation->height);
4522 #endif /* G_ENABLE_DEBUG */
4524 alloc_needed = priv->alloc_needed;
4525 if (!priv->width_request_needed && !priv->height_request_needed)
4526 /* Preserve request/allocate ordering */
4527 priv->alloc_needed = FALSE;
4529 old_allocation = priv->allocation;
4530 real_allocation = *allocation;
4532 adjusted_allocation = real_allocation;
4533 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4535 if (adjusted_allocation.x < real_allocation.x ||
4536 adjusted_allocation.y < real_allocation.y ||
4537 (adjusted_allocation.x + adjusted_allocation.width) >
4538 (real_allocation.x + real_allocation.width) ||
4539 (adjusted_allocation.y + adjusted_allocation.height >
4540 real_allocation.y + real_allocation.height))
4542 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",
4543 G_OBJECT_TYPE_NAME (widget), widget,
4544 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4545 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4546 adjusted_allocation = real_allocation; /* veto it */
4550 real_allocation = adjusted_allocation;
4553 if (real_allocation.width < 0 || real_allocation.height < 0)
4555 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4556 real_allocation.width,
4557 real_allocation.height);
4560 real_allocation.width = MAX (real_allocation.width, 1);
4561 real_allocation.height = MAX (real_allocation.height, 1);
4563 size_changed = (old_allocation.width != real_allocation.width ||
4564 old_allocation.height != real_allocation.height);
4565 position_changed = (old_allocation.x != real_allocation.x ||
4566 old_allocation.y != real_allocation.y);
4568 if (!alloc_needed && !size_changed && !position_changed)
4571 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4573 if (gtk_widget_get_mapped (widget))
4575 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4577 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4579 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4580 cairo_region_union_rectangle (invalidate, &old_allocation);
4582 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4583 cairo_region_destroy (invalidate);
4588 if (priv->redraw_on_alloc)
4590 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4592 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4593 cairo_region_union_rectangle (invalidate, &old_allocation);
4595 gtk_widget_invalidate_widget_windows (widget, invalidate);
4596 cairo_region_destroy (invalidate);
4601 if ((size_changed || position_changed) && priv->parent &&
4602 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4604 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4605 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4606 cairo_region_destroy (invalidate);
4611 * gtk_widget_common_ancestor:
4612 * @widget_a: a #GtkWidget
4613 * @widget_b: a #GtkWidget
4615 * Find the common ancestor of @widget_a and @widget_b that
4616 * is closest to the two widgets.
4618 * Return value: the closest common ancestor of @widget_a and
4619 * @widget_b or %NULL if @widget_a and @widget_b do not
4620 * share a common ancestor.
4623 gtk_widget_common_ancestor (GtkWidget *widget_a,
4624 GtkWidget *widget_b)
4626 GtkWidget *parent_a;
4627 GtkWidget *parent_b;
4631 parent_a = widget_a;
4632 while (parent_a->priv->parent)
4634 parent_a = parent_a->priv->parent;
4638 parent_b = widget_b;
4639 while (parent_b->priv->parent)
4641 parent_b = parent_b->priv->parent;
4645 if (parent_a != parent_b)
4648 while (depth_a > depth_b)
4650 widget_a = widget_a->priv->parent;
4654 while (depth_b > depth_a)
4656 widget_b = widget_b->priv->parent;
4660 while (widget_a != widget_b)
4662 widget_a = widget_a->priv->parent;
4663 widget_b = widget_b->priv->parent;
4670 * gtk_widget_translate_coordinates:
4671 * @src_widget: a #GtkWidget
4672 * @dest_widget: a #GtkWidget
4673 * @src_x: X position relative to @src_widget
4674 * @src_y: Y position relative to @src_widget
4675 * @dest_x: (out): location to store X position relative to @dest_widget
4676 * @dest_y: (out): location to store Y position relative to @dest_widget
4678 * Translate coordinates relative to @src_widget's allocation to coordinates
4679 * relative to @dest_widget's allocations. In order to perform this
4680 * operation, both widgets must be realized, and must share a common
4683 * Return value: %FALSE if either widget was not realized, or there
4684 * was no common ancestor. In this case, nothing is stored in
4685 * *@dest_x and *@dest_y. Otherwise %TRUE.
4688 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4689 GtkWidget *dest_widget,
4695 GtkWidgetPrivate *src_priv = src_widget->priv;
4696 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4697 GtkWidget *ancestor;
4699 GList *dest_list = NULL;
4701 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4702 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4704 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4705 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4708 /* Translate from allocation relative to window relative */
4709 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4712 gdk_window_get_position (src_priv->window, &wx, &wy);
4714 src_x -= wx - src_priv->allocation.x;
4715 src_y -= wy - src_priv->allocation.y;
4719 src_x += src_priv->allocation.x;
4720 src_y += src_priv->allocation.y;
4723 /* Translate to the common ancestor */
4724 window = src_priv->window;
4725 while (window != ancestor->priv->window)
4729 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4734 window = gdk_window_get_effective_parent (window);
4736 if (!window) /* Handle GtkHandleBox */
4741 window = dest_priv->window;
4742 while (window != ancestor->priv->window)
4744 dest_list = g_list_prepend (dest_list, window);
4746 window = gdk_window_get_effective_parent (window);
4748 if (!window) /* Handle GtkHandleBox */
4750 g_list_free (dest_list);
4759 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4764 dest_list = g_list_remove (dest_list, dest_list->data);
4767 /* Translate from window relative to allocation relative */
4768 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4771 gdk_window_get_position (dest_priv->window, &wx, &wy);
4773 src_x += wx - dest_priv->allocation.x;
4774 src_y += wy - dest_priv->allocation.y;
4778 src_x -= dest_priv->allocation.x;
4779 src_y -= dest_priv->allocation.y;
4791 gtk_widget_real_size_allocate (GtkWidget *widget,
4792 GtkAllocation *allocation)
4794 GtkWidgetPrivate *priv = widget->priv;
4796 priv->allocation = *allocation;
4798 if (gtk_widget_get_realized (widget) &&
4799 gtk_widget_get_has_window (widget))
4801 gdk_window_move_resize (priv->window,
4802 allocation->x, allocation->y,
4803 allocation->width, allocation->height);
4808 get_span_inside_border (GtkWidget *widget,
4812 int allocated_outside_size,
4813 int natural_inside_size,
4814 int *coord_inside_p,
4817 int inside_allocated;
4821 inside_allocated = allocated_outside_size - start_pad - end_pad;
4823 content_size = natural_inside_size;
4824 if (content_size > inside_allocated)
4826 /* didn't get full natural size */
4827 content_size = inside_allocated;
4830 coord = size = 0; /* silence compiler */
4833 case GTK_ALIGN_FILL:
4835 size = inside_allocated;
4837 case GTK_ALIGN_START:
4839 size = content_size;
4842 coord = allocated_outside_size - end_pad - content_size;
4843 size = content_size;
4845 case GTK_ALIGN_CENTER:
4846 coord = start_pad + (inside_allocated - content_size) / 2;
4847 size = content_size;
4852 *coord_inside_p = coord;
4855 *size_inside_p = size;
4859 get_span_inside_border_horizontal (GtkWidget *widget,
4860 const GtkWidgetAuxInfo *aux_info,
4861 int allocated_outside_width,
4862 int natural_inside_width,
4864 int *width_inside_p)
4866 get_span_inside_border (widget,
4868 aux_info->margin.left,
4869 aux_info->margin.right,
4870 allocated_outside_width,
4871 natural_inside_width,
4877 get_span_inside_border_vertical (GtkWidget *widget,
4878 const GtkWidgetAuxInfo *aux_info,
4879 int allocated_outside_height,
4880 int natural_inside_height,
4882 int *height_inside_p)
4884 get_span_inside_border (widget,
4886 aux_info->margin.top,
4887 aux_info->margin.bottom,
4888 allocated_outside_height,
4889 natural_inside_height,
4895 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4896 GtkAllocation *allocation)
4898 const GtkWidgetAuxInfo *aux_info;
4900 gint natural_height;
4903 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4905 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4907 gtk_widget_get_preferred_width (widget, NULL, &natural_width);
4908 get_span_inside_border_horizontal (widget,
4914 gtk_widget_get_preferred_height_for_width (widget, w, NULL, &natural_height);
4915 get_span_inside_border_vertical (widget,
4921 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
4923 gtk_widget_get_preferred_height (widget, NULL, &natural_height);
4924 get_span_inside_border_vertical (widget,
4930 gtk_widget_get_preferred_width_for_height (widget, h, NULL, &natural_width);
4931 get_span_inside_border_horizontal (widget,
4940 allocation->width = w;
4941 allocation->height = h;
4945 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4948 GtkWidgetPrivate *priv = widget->priv;
4950 /* widgets must be onscreen for accels to take effect */
4951 return gtk_widget_is_sensitive (widget) &&
4952 gtk_widget_is_drawable (widget) &&
4953 gdk_window_is_viewable (priv->window);
4957 * gtk_widget_can_activate_accel:
4958 * @widget: a #GtkWidget
4959 * @signal_id: the ID of a signal installed on @widget
4961 * Determines whether an accelerator that activates the signal
4962 * identified by @signal_id can currently be activated.
4963 * This is done by emitting the #GtkWidget::can-activate-accel
4964 * signal on @widget; if the signal isn't overridden by a
4965 * handler or in a derived widget, then the default check is
4966 * that the widget must be sensitive, and the widget and all
4967 * its ancestors mapped.
4969 * Return value: %TRUE if the accelerator can be activated.
4974 gtk_widget_can_activate_accel (GtkWidget *widget,
4977 gboolean can_activate = FALSE;
4978 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4979 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4980 return can_activate;
4989 closure_accel_activate (GClosure *closure,
4990 GValue *return_value,
4991 guint n_param_values,
4992 const GValue *param_values,
4993 gpointer invocation_hint,
4994 gpointer marshal_data)
4996 AccelClosure *aclosure = (AccelClosure*) closure;
4997 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
5000 g_signal_emit (closure->data, aclosure->signal_id, 0);
5002 /* whether accelerator was handled */
5003 g_value_set_boolean (return_value, can_activate);
5007 closures_destroy (gpointer data)
5009 GSList *slist, *closures = data;
5011 for (slist = closures; slist; slist = slist->next)
5013 g_closure_invalidate (slist->data);
5014 g_closure_unref (slist->data);
5016 g_slist_free (closures);
5020 widget_new_accel_closure (GtkWidget *widget,
5023 AccelClosure *aclosure;
5024 GClosure *closure = NULL;
5025 GSList *slist, *closures;
5027 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
5028 for (slist = closures; slist; slist = slist->next)
5029 if (!gtk_accel_group_from_accel_closure (slist->data))
5031 /* reuse this closure */
5032 closure = slist->data;
5037 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
5038 closures = g_slist_prepend (closures, g_closure_ref (closure));
5039 g_closure_sink (closure);
5040 g_closure_set_marshal (closure, closure_accel_activate);
5042 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
5044 aclosure = (AccelClosure*) closure;
5045 g_assert (closure->data == widget);
5046 g_assert (closure->marshal == closure_accel_activate);
5047 aclosure->signal_id = signal_id;
5053 * gtk_widget_add_accelerator
5054 * @widget: widget to install an accelerator on
5055 * @accel_signal: widget signal to emit on accelerator activation
5056 * @accel_group: accel group for this widget, added to its toplevel
5057 * @accel_key: GDK keyval of the accelerator
5058 * @accel_mods: modifier key combination of the accelerator
5059 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
5061 * Installs an accelerator for this @widget in @accel_group that causes
5062 * @accel_signal to be emitted if the accelerator is activated.
5063 * The @accel_group needs to be added to the widget's toplevel via
5064 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
5065 * Accelerators added through this function are not user changeable during
5066 * runtime. If you want to support accelerators that can be changed by the
5067 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
5068 * gtk_menu_item_set_accel_path() instead.
5071 gtk_widget_add_accelerator (GtkWidget *widget,
5072 const gchar *accel_signal,
5073 GtkAccelGroup *accel_group,
5075 GdkModifierType accel_mods,
5076 GtkAccelFlags accel_flags)
5081 g_return_if_fail (GTK_IS_WIDGET (widget));
5082 g_return_if_fail (accel_signal != NULL);
5083 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5085 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
5086 if (!query.signal_id ||
5087 !(query.signal_flags & G_SIGNAL_ACTION) ||
5088 query.return_type != G_TYPE_NONE ||
5091 /* hmm, should be elaborate enough */
5092 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
5093 G_OBJECT_TYPE_NAME (widget), accel_signal);
5097 closure = widget_new_accel_closure (widget, query.signal_id);
5099 g_object_ref (widget);
5101 /* install the accelerator. since we don't map this onto an accel_path,
5102 * the accelerator will automatically be locked.
5104 gtk_accel_group_connect (accel_group,
5107 accel_flags | GTK_ACCEL_LOCKED,
5110 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5112 g_object_unref (widget);
5116 * gtk_widget_remove_accelerator:
5117 * @widget: widget to install an accelerator on
5118 * @accel_group: accel group for this widget
5119 * @accel_key: GDK keyval of the accelerator
5120 * @accel_mods: modifier key combination of the accelerator
5121 * @returns: whether an accelerator was installed and could be removed
5123 * Removes an accelerator from @widget, previously installed with
5124 * gtk_widget_add_accelerator().
5127 gtk_widget_remove_accelerator (GtkWidget *widget,
5128 GtkAccelGroup *accel_group,
5130 GdkModifierType accel_mods)
5132 GtkAccelGroupEntry *ag_entry;
5133 GList *slist, *clist;
5136 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5137 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5139 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5140 clist = gtk_widget_list_accel_closures (widget);
5141 for (slist = clist; slist; slist = slist->next)
5145 for (i = 0; i < n; i++)
5146 if (slist->data == (gpointer) ag_entry[i].closure)
5148 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5150 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5152 g_list_free (clist);
5157 g_list_free (clist);
5159 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5160 accel_key, accel_mods, accel_group,
5161 G_OBJECT_TYPE_NAME (widget), widget);
5167 * gtk_widget_list_accel_closures:
5168 * @widget: widget to list accelerator closures for
5170 * Lists the closures used by @widget for accelerator group connections
5171 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5172 * The closures can be used to monitor accelerator changes on @widget,
5173 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5174 * #GtkAccelGroup of a closure which can be found out with
5175 * gtk_accel_group_from_accel_closure().
5177 * Return value: (transfer container) (element-type GClosure):
5178 * a newly allocated #GList of closures
5181 gtk_widget_list_accel_closures (GtkWidget *widget)
5184 GList *clist = NULL;
5186 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5188 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5189 if (gtk_accel_group_from_accel_closure (slist->data))
5190 clist = g_list_prepend (clist, slist->data);
5196 GtkAccelGroup *accel_group;
5201 destroy_accel_path (gpointer data)
5203 AccelPath *apath = data;
5205 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5207 /* closures_destroy takes care of unrefing the closure */
5208 g_object_unref (apath->accel_group);
5210 g_slice_free (AccelPath, apath);
5215 * gtk_widget_set_accel_path:
5216 * @widget: a #GtkWidget
5217 * @accel_path: (allow-none): path used to look up the accelerator
5218 * @accel_group: (allow-none): a #GtkAccelGroup.
5220 * Given an accelerator group, @accel_group, and an accelerator path,
5221 * @accel_path, sets up an accelerator in @accel_group so whenever the
5222 * key binding that is defined for @accel_path is pressed, @widget
5223 * will be activated. This removes any accelerators (for any
5224 * accelerator group) installed by previous calls to
5225 * gtk_widget_set_accel_path(). Associating accelerators with
5226 * paths allows them to be modified by the user and the modifications
5227 * to be saved for future use. (See gtk_accel_map_save().)
5229 * This function is a low level function that would most likely
5230 * be used by a menu creation system like #GtkUIManager. If you
5231 * use #GtkUIManager, setting up accelerator paths will be done
5234 * Even when you you aren't using #GtkUIManager, if you only want to
5235 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5236 * provides a somewhat more convenient interface.
5238 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5239 * pass a static string, you can save some memory by interning it first with
5240 * g_intern_static_string().
5243 gtk_widget_set_accel_path (GtkWidget *widget,
5244 const gchar *accel_path,
5245 GtkAccelGroup *accel_group)
5249 g_return_if_fail (GTK_IS_WIDGET (widget));
5250 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5254 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5255 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5257 gtk_accel_map_add_entry (accel_path, 0, 0);
5258 apath = g_slice_new (AccelPath);
5259 apath->accel_group = g_object_ref (accel_group);
5260 apath->path_quark = g_quark_from_string (accel_path);
5261 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5266 /* also removes possible old settings */
5267 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5270 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5272 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5276 _gtk_widget_get_accel_path (GtkWidget *widget,
5281 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5283 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5285 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5286 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5290 * gtk_widget_mnemonic_activate:
5291 * @widget: a #GtkWidget
5292 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5294 * Emits the #GtkWidget::mnemonic-activate signal.
5296 * The default handler for this signal activates the @widget if
5297 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5300 * Returns: %TRUE if the signal has been handled
5303 gtk_widget_mnemonic_activate (GtkWidget *widget,
5304 gboolean group_cycling)
5308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5310 group_cycling = group_cycling != FALSE;
5311 if (!gtk_widget_is_sensitive (widget))
5314 g_signal_emit (widget,
5315 widget_signals[MNEMONIC_ACTIVATE],
5323 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5324 gboolean group_cycling)
5326 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5327 gtk_widget_activate (widget);
5328 else if (gtk_widget_get_can_focus (widget))
5329 gtk_widget_grab_focus (widget);
5332 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5333 G_OBJECT_TYPE_NAME (widget));
5334 gtk_widget_error_bell (widget);
5339 static const cairo_user_data_key_t event_key;
5342 _gtk_cairo_get_event (cairo_t *cr)
5344 g_return_val_if_fail (cr != NULL, NULL);
5346 return cairo_get_user_data (cr, &event_key);
5350 gtk_cairo_set_event (cairo_t *cr,
5351 GdkEventExpose *event)
5353 cairo_set_user_data (cr, &event_key, event, NULL);
5357 * gtk_cairo_should_draw_window:
5358 * @cr: a cairo context
5359 * @window: the window to check
5361 * This function is supposed to be called in GtkWidget::draw
5362 * implementations for widgets that support multiple windows.
5363 * @cr must be untransformed from invoking of the draw function.
5364 * This function will return %TRUE if the contents of the given
5365 * @window are supposed to be drawn and %FALSE otherwise. Note
5366 * that when the drawing was not initiated by the windowing
5367 * system this function will return %TRUE for all windows, so
5368 * you need to draw the bottommost window first. Also, do not
5369 * use "else if" statements to check which window should be drawn.
5371 * Returns: %TRUE if @window should be drawn
5374 gtk_cairo_should_draw_window (cairo_t *cr,
5377 GdkEventExpose *event;
5379 g_return_val_if_fail (cr != NULL, FALSE);
5380 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5382 event = _gtk_cairo_get_event (cr);
5384 return event == NULL ||
5385 event->window == window;
5388 /* code shared by gtk_container_propagate_draw() and
5392 _gtk_widget_draw_internal (GtkWidget *widget,
5394 gboolean clip_to_size)
5396 if (!gtk_widget_is_drawable (widget))
5401 cairo_rectangle (cr,
5403 widget->priv->allocation.width,
5404 widget->priv->allocation.height);
5408 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5412 g_signal_emit (widget, widget_signals[DRAW],
5420 * @widget: the widget to draw. It must be drawable (see
5421 * gtk_widget_is_drawable()) and a size must have been allocated.
5422 * @cr: a cairo context to draw to
5424 * Draws @widget to @cr. The top left corner of the widget will be
5425 * drawn to the currently set origin point of @cr.
5427 * You should pass a cairo context as @cr argument that is in an
5428 * original state. Otherwise the resulting drawing is undefined. For
5429 * example changing the operator using cairo_set_operator() or the
5430 * line width using cairo_set_line_width() might have unwanted side
5432 * You may however change the context's transform matrix - like with
5433 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5434 * region with cairo_clip() prior to calling this function. Also, it
5435 * is fine to modify the context with cairo_save() and
5436 * cairo_push_group() prior to calling this function.
5438 * <note><para>Special purpose widgets may contain special code for
5439 * rendering to the screen and might appear differently on screen
5440 * and when rendered using gtk_widget_draw().</para></note>
5443 gtk_widget_draw (GtkWidget *widget,
5446 GdkEventExpose *tmp_event;
5448 g_return_if_fail (GTK_IS_WIDGET (widget));
5449 g_return_if_fail (!widget->priv->alloc_needed);
5450 g_return_if_fail (cr != NULL);
5453 /* We have to reset the event here so that draw functions can call
5454 * gtk_widget_draw() on random other widgets and get the desired
5455 * effect: Drawing all contents, not just the current window.
5457 tmp_event = _gtk_cairo_get_event (cr);
5458 gtk_cairo_set_event (cr, NULL);
5460 _gtk_widget_draw_internal (widget, cr, TRUE);
5462 gtk_cairo_set_event (cr, tmp_event);
5467 gtk_widget_real_key_press_event (GtkWidget *widget,
5470 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5474 gtk_widget_real_key_release_event (GtkWidget *widget,
5477 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5481 gtk_widget_real_focus_in_event (GtkWidget *widget,
5482 GdkEventFocus *event)
5484 gtk_widget_queue_shallow_draw (widget);
5490 gtk_widget_real_focus_out_event (GtkWidget *widget,
5491 GdkEventFocus *event)
5493 gtk_widget_queue_shallow_draw (widget);
5498 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5499 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5503 * @widget: a #GtkWidget
5504 * @event: a #GdkEvent
5506 * Rarely-used function. This function is used to emit
5507 * the event signals on a widget (those signals should never
5508 * be emitted without using this function to do so).
5509 * If you want to synthesize an event though, don't use this function;
5510 * instead, use gtk_main_do_event() so the event will behave as if
5511 * it were in the event queue. Don't synthesize expose events; instead,
5512 * use gdk_window_invalidate_rect() to invalidate a region of the
5515 * Return value: return from the event signal emission (%TRUE if
5516 * the event was handled)
5519 gtk_widget_event (GtkWidget *widget,
5522 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5523 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5525 if (event->type == GDK_EXPOSE)
5527 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5528 "the same effect, call gdk_window_invalidate_rect/region(), "
5529 "followed by gdk_window_process_updates().");
5533 return gtk_widget_event_internal (widget, event);
5536 /* Returns TRUE if a translation should be done */
5538 gtk_widget_get_translation_to_window (GtkWidget *widget,
5543 GdkWindow *w, *widget_window;
5545 if (!gtk_widget_get_has_window (widget))
5547 *x = -widget->priv->allocation.x;
5548 *y = -widget->priv->allocation.y;
5556 widget_window = gtk_widget_get_window (widget);
5558 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5561 gdk_window_get_position (w, &wx, &wy);
5578 * gtk_cairo_transform_to_window:
5579 * @cr: the cairo context to transform
5580 * @widget: the widget the context is currently centered for
5581 * @window: the window to transform the context to
5583 * Transforms the given cairo context @cr that from @widget-relative
5584 * coordinates to @window-relative coordinates.
5585 * If the @widget's window is not an ancestor of @window, no
5586 * modification will be applied.
5588 * This is the inverse to the transformation GTK applies when
5589 * preparing an expose event to be emitted with the GtkWidget::draw
5590 * signal. It is intended to help porting multiwindow widgets from
5591 * GTK 2 to the rendering architecture of GTK 3.
5594 gtk_cairo_transform_to_window (cairo_t *cr,
5600 g_return_if_fail (cr != NULL);
5601 g_return_if_fail (GTK_IS_WIDGET (widget));
5602 g_return_if_fail (GDK_IS_WINDOW (window));
5604 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5605 cairo_translate (cr, x, y);
5609 * gtk_widget_send_expose:
5610 * @widget: a #GtkWidget
5611 * @event: a expose #GdkEvent
5613 * Very rarely-used function. This function is used to emit
5614 * an expose event on a widget. This function is not normally used
5615 * directly. The only time it is used is when propagating an expose
5616 * event to a child %NO_WINDOW widget, and that is normally done
5617 * using gtk_container_propagate_draw().
5619 * If you want to force an area of a window to be redrawn,
5620 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5621 * To cause the redraw to be done immediately, follow that call
5622 * with a call to gdk_window_process_updates().
5624 * Return value: return from the event signal emission (%TRUE if
5625 * the event was handled)
5628 gtk_widget_send_expose (GtkWidget *widget,
5631 gboolean result = FALSE;
5636 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5637 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5638 g_return_val_if_fail (event != NULL, TRUE);
5639 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5641 cr = gdk_cairo_create (event->expose.window);
5642 gtk_cairo_set_event (cr, &event->expose);
5644 gdk_cairo_region (cr, event->expose.region);
5647 do_clip = gtk_widget_get_translation_to_window (widget,
5648 event->expose.window,
5650 cairo_translate (cr, -x, -y);
5652 _gtk_widget_draw_internal (widget, cr, do_clip);
5654 /* unset here, so if someone keeps a reference to cr we
5655 * don't leak the window. */
5656 gtk_cairo_set_event (cr, NULL);
5663 event_window_is_still_viewable (GdkEvent *event)
5665 /* Check that we think the event's window is viewable before
5666 * delivering the event, to prevent suprises. We do this here
5667 * at the last moment, since the event may have been queued
5668 * up behind other events, held over a recursive main loop, etc.
5670 switch (event->type)
5673 case GDK_MOTION_NOTIFY:
5674 case GDK_BUTTON_PRESS:
5675 case GDK_2BUTTON_PRESS:
5676 case GDK_3BUTTON_PRESS:
5678 case GDK_ENTER_NOTIFY:
5679 case GDK_PROXIMITY_IN:
5681 return event->any.window && gdk_window_is_viewable (event->any.window);
5684 /* The following events are the second half of paired events;
5685 * we always deliver them to deal with widgets that clean up
5686 * on the second half.
5688 case GDK_BUTTON_RELEASE:
5689 case GDK_KEY_RELEASE:
5690 case GDK_LEAVE_NOTIFY:
5691 case GDK_PROXIMITY_OUT:
5695 /* Remaining events would make sense on an not-viewable window,
5696 * or don't have an associated window.
5703 gtk_widget_event_internal (GtkWidget *widget,
5706 gboolean return_val = FALSE;
5708 /* We check only once for is-still-visible; if someone
5709 * hides the window in on of the signals on the widget,
5710 * they are responsible for returning TRUE to terminate
5713 if (!event_window_is_still_viewable (event))
5716 g_object_ref (widget);
5718 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5719 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5724 switch (event->type)
5729 case GDK_BUTTON_PRESS:
5730 case GDK_2BUTTON_PRESS:
5731 case GDK_3BUTTON_PRESS:
5732 signal_num = BUTTON_PRESS_EVENT;
5735 signal_num = SCROLL_EVENT;
5737 case GDK_BUTTON_RELEASE:
5738 signal_num = BUTTON_RELEASE_EVENT;
5740 case GDK_MOTION_NOTIFY:
5741 signal_num = MOTION_NOTIFY_EVENT;
5744 signal_num = DELETE_EVENT;
5747 signal_num = DESTROY_EVENT;
5748 _gtk_tooltip_hide (widget);
5751 signal_num = KEY_PRESS_EVENT;
5753 case GDK_KEY_RELEASE:
5754 signal_num = KEY_RELEASE_EVENT;
5756 case GDK_ENTER_NOTIFY:
5757 signal_num = ENTER_NOTIFY_EVENT;
5759 case GDK_LEAVE_NOTIFY:
5760 signal_num = LEAVE_NOTIFY_EVENT;
5762 case GDK_FOCUS_CHANGE:
5763 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5764 if (event->focus_change.in)
5765 _gtk_tooltip_focus_in (widget);
5767 _gtk_tooltip_focus_out (widget);
5770 signal_num = CONFIGURE_EVENT;
5773 signal_num = MAP_EVENT;
5776 signal_num = UNMAP_EVENT;
5778 case GDK_WINDOW_STATE:
5779 signal_num = WINDOW_STATE_EVENT;
5781 case GDK_PROPERTY_NOTIFY:
5782 signal_num = PROPERTY_NOTIFY_EVENT;
5784 case GDK_SELECTION_CLEAR:
5785 signal_num = SELECTION_CLEAR_EVENT;
5787 case GDK_SELECTION_REQUEST:
5788 signal_num = SELECTION_REQUEST_EVENT;
5790 case GDK_SELECTION_NOTIFY:
5791 signal_num = SELECTION_NOTIFY_EVENT;
5793 case GDK_PROXIMITY_IN:
5794 signal_num = PROXIMITY_IN_EVENT;
5796 case GDK_PROXIMITY_OUT:
5797 signal_num = PROXIMITY_OUT_EVENT;
5800 signal_num = NO_EXPOSE_EVENT;
5802 case GDK_CLIENT_EVENT:
5803 signal_num = CLIENT_EVENT;
5806 signal_num = EXPOSE_EVENT;
5808 case GDK_VISIBILITY_NOTIFY:
5809 signal_num = VISIBILITY_NOTIFY_EVENT;
5811 case GDK_GRAB_BROKEN:
5812 signal_num = GRAB_BROKEN;
5815 signal_num = DAMAGE_EVENT;
5818 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5822 if (signal_num != -1)
5823 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5825 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5826 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5830 g_object_unref (widget);
5836 * gtk_widget_activate:
5837 * @widget: a #GtkWidget that's activatable
5839 * For widgets that can be "activated" (buttons, menu items, etc.)
5840 * this function activates them. Activation is what happens when you
5841 * press Enter on a widget during key navigation. If @widget isn't
5842 * activatable, the function returns %FALSE.
5844 * Return value: %TRUE if the widget was activatable
5847 gtk_widget_activate (GtkWidget *widget)
5849 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5851 if (WIDGET_CLASS (widget)->activate_signal)
5853 /* FIXME: we should eventually check the signals signature here */
5854 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5863 * gtk_widget_set_scroll_adjustments:
5864 * @widget: a #GtkWidget
5865 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5866 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5868 * For widgets that support scrolling, sets the scroll adjustments and
5869 * returns %TRUE. For widgets that don't support scrolling, does
5870 * nothing and returns %FALSE. Widgets that don't support scrolling
5871 * can be scrolled by placing them in a #GtkViewport, which does
5872 * support scrolling.
5874 * Return value: %TRUE if the widget supports scrolling
5877 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5878 GtkAdjustment *hadjustment,
5879 GtkAdjustment *vadjustment)
5884 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5887 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5889 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5891 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5895 g_signal_query (signal_id, &query);
5896 if (!query.signal_id ||
5897 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5898 query.return_type != G_TYPE_NONE ||
5899 query.n_params != 2 ||
5900 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5901 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5903 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5904 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5908 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5913 gtk_widget_reparent_subwindows (GtkWidget *widget,
5914 GdkWindow *new_window)
5916 GtkWidgetPrivate *priv = widget->priv;
5918 if (!gtk_widget_get_has_window (widget))
5920 GList *children = gdk_window_get_children (priv->window);
5923 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5925 GdkWindow *window = tmp_list->data;
5928 gdk_window_get_user_data (window, &child);
5929 while (child && child != widget)
5930 child = ((GtkWidget*) child)->priv->parent;
5933 gdk_window_reparent (window, new_window, 0, 0);
5936 g_list_free (children);
5941 GList *tmp_list, *children;
5943 parent = gdk_window_get_parent (priv->window);
5946 gdk_window_reparent (priv->window, new_window, 0, 0);
5949 children = gdk_window_get_children (parent);
5951 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5953 GdkWindow *window = tmp_list->data;
5956 gdk_window_get_user_data (window, &child);
5958 if (child == widget)
5959 gdk_window_reparent (window, new_window, 0, 0);
5962 g_list_free (children);
5968 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5969 gpointer client_data)
5971 GtkWidgetPrivate *priv = widget->priv;
5973 g_assert (client_data != NULL);
5975 if (!gtk_widget_get_has_window (widget))
5978 g_object_unref (priv->window);
5979 priv->window = (GdkWindow*) client_data;
5981 g_object_ref (priv->window);
5983 if (GTK_IS_CONTAINER (widget))
5984 gtk_container_forall (GTK_CONTAINER (widget),
5985 gtk_widget_reparent_fixup_child,
5991 * gtk_widget_reparent:
5992 * @widget: a #GtkWidget
5993 * @new_parent: a #GtkContainer to move the widget into
5995 * Moves a widget from one #GtkContainer to another, handling reference
5996 * count issues to avoid destroying the widget.
5999 gtk_widget_reparent (GtkWidget *widget,
6000 GtkWidget *new_parent)
6002 GtkWidgetPrivate *priv;
6004 g_return_if_fail (GTK_IS_WIDGET (widget));
6005 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
6006 priv = widget->priv;
6007 g_return_if_fail (priv->parent != NULL);
6009 if (priv->parent != new_parent)
6011 /* First try to see if we can get away without unrealizing
6012 * the widget as we reparent it. if so we set a flag so
6013 * that gtk_widget_unparent doesn't unrealize widget
6015 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
6016 priv->in_reparent = TRUE;
6018 g_object_ref (widget);
6019 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
6020 gtk_container_add (GTK_CONTAINER (new_parent), widget);
6021 g_object_unref (widget);
6023 if (priv->in_reparent)
6025 priv->in_reparent = FALSE;
6027 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
6028 gtk_widget_reparent_fixup_child (widget,
6029 gtk_widget_get_parent_window (widget));
6032 g_object_notify (G_OBJECT (widget), "parent");
6037 * gtk_widget_intersect:
6038 * @widget: a #GtkWidget
6039 * @area: a rectangle
6040 * @intersection: rectangle to store intersection of @widget and @area
6042 * Computes the intersection of a @widget's area and @area, storing
6043 * the intersection in @intersection, and returns %TRUE if there was
6044 * an intersection. @intersection may be %NULL if you're only
6045 * interested in whether there was an intersection.
6047 * Return value: %TRUE if there was an intersection
6050 gtk_widget_intersect (GtkWidget *widget,
6051 const GdkRectangle *area,
6052 GdkRectangle *intersection)
6054 GtkWidgetPrivate *priv;
6059 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6060 g_return_val_if_fail (area != NULL, FALSE);
6062 priv = widget->priv;
6065 dest = intersection;
6069 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
6071 if (return_val && intersection && gtk_widget_get_has_window (widget))
6073 intersection->x -= priv->allocation.x;
6074 intersection->y -= priv->allocation.y;
6081 * gtk_widget_region_intersect:
6082 * @widget: a #GtkWidget
6083 * @region: a #cairo_region_t, in the same coordinate system as
6084 * @widget->allocation. That is, relative to @widget->window
6085 * for %NO_WINDOW widgets; relative to the parent window
6086 * of @widget->window for widgets with their own window.
6087 * @returns: A newly allocated region holding the intersection of @widget
6088 * and @region. The coordinates of the return value are
6089 * relative to @widget->window for %NO_WINDOW widgets, and
6090 * relative to the parent window of @widget->window for
6091 * widgets with their own window.
6093 * Computes the intersection of a @widget's area and @region, returning
6094 * the intersection. The result may be empty, use cairo_region_is_empty() to
6098 gtk_widget_region_intersect (GtkWidget *widget,
6099 const cairo_region_t *region)
6102 cairo_region_t *dest;
6104 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6105 g_return_val_if_fail (region != NULL, NULL);
6107 gtk_widget_get_allocation (widget, &rect);
6109 dest = cairo_region_create_rectangle (&rect);
6111 cairo_region_intersect (dest, region);
6117 * _gtk_widget_grab_notify:
6118 * @widget: a #GtkWidget
6119 * @was_grabbed: whether a grab is now in effect
6121 * Emits the #GtkWidget::grab-notify signal on @widget.
6126 _gtk_widget_grab_notify (GtkWidget *widget,
6127 gboolean was_grabbed)
6129 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6133 * gtk_widget_grab_focus:
6134 * @widget: a #GtkWidget
6136 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6137 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6138 * something like #GtkFrame won't work.
6140 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6141 * gtk_widget_set_can_focus() to modify that flag.
6143 * The widget also needs to be realized and mapped. This is indicated by the
6144 * related signals. Grabbing the focus immediately after creating the widget
6145 * will likely fail and cause critical warnings.
6148 gtk_widget_grab_focus (GtkWidget *widget)
6150 g_return_if_fail (GTK_IS_WIDGET (widget));
6152 if (!gtk_widget_is_sensitive (widget))
6155 g_object_ref (widget);
6156 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6157 g_object_notify (G_OBJECT (widget), "has-focus");
6158 g_object_unref (widget);
6162 reset_focus_recurse (GtkWidget *widget,
6165 if (GTK_IS_CONTAINER (widget))
6167 GtkContainer *container;
6169 container = GTK_CONTAINER (widget);
6170 gtk_container_set_focus_child (container, NULL);
6172 gtk_container_foreach (container,
6173 reset_focus_recurse,
6179 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6181 if (gtk_widget_get_can_focus (focus_widget))
6183 GtkWidget *toplevel;
6186 /* clear the current focus setting, break if the current widget
6187 * is the focus widget's parent, since containers above that will
6188 * be set by the next loop.
6190 toplevel = gtk_widget_get_toplevel (focus_widget);
6191 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6193 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6195 if (widget == focus_widget)
6197 /* We call _gtk_window_internal_set_focus() here so that the
6198 * toplevel window can request the focus if necessary.
6199 * This is needed when the toplevel is a GtkPlug
6201 if (!gtk_widget_has_focus (widget))
6202 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6209 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6211 widget = widget->priv->parent;
6212 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6216 else if (toplevel != focus_widget)
6218 /* gtk_widget_grab_focus() operates on a tree without window...
6219 * actually, this is very questionable behaviour.
6222 gtk_container_foreach (GTK_CONTAINER (toplevel),
6223 reset_focus_recurse,
6227 /* now propagate the new focus up the widget tree and finally
6228 * set it on the window
6230 widget = focus_widget;
6231 while (widget->priv->parent)
6233 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6234 widget = widget->priv->parent;
6236 if (GTK_IS_WINDOW (widget))
6237 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6242 gtk_widget_real_query_tooltip (GtkWidget *widget,
6245 gboolean keyboard_tip,
6246 GtkTooltip *tooltip)
6248 gchar *tooltip_markup;
6249 gboolean has_tooltip;
6251 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6252 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6254 if (has_tooltip && tooltip_markup)
6256 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6264 gtk_widget_real_show_help (GtkWidget *widget,
6265 GtkWidgetHelpType help_type)
6267 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6269 _gtk_tooltip_toggle_keyboard_mode (widget);
6278 gtk_widget_real_focus (GtkWidget *widget,
6279 GtkDirectionType direction)
6281 if (!gtk_widget_get_can_focus (widget))
6284 if (!gtk_widget_is_focus (widget))
6286 gtk_widget_grab_focus (widget);
6294 gtk_widget_real_move_focus (GtkWidget *widget,
6295 GtkDirectionType direction)
6297 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6299 if (GTK_IS_WINDOW (toplevel) &&
6300 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
6302 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
6308 gtk_widget_real_keynav_failed (GtkWidget *widget,
6309 GtkDirectionType direction)
6311 gboolean cursor_only;
6315 case GTK_DIR_TAB_FORWARD:
6316 case GTK_DIR_TAB_BACKWARD:
6323 g_object_get (gtk_widget_get_settings (widget),
6324 "gtk-keynav-cursor-only", &cursor_only,
6331 gtk_widget_error_bell (widget);
6337 * gtk_widget_set_can_focus:
6338 * @widget: a #GtkWidget
6339 * @can_focus: whether or not @widget can own the input focus.
6341 * Specifies whether @widget can own the input focus. See
6342 * gtk_widget_grab_focus() for actually setting the input focus on a
6348 gtk_widget_set_can_focus (GtkWidget *widget,
6351 g_return_if_fail (GTK_IS_WIDGET (widget));
6353 if (widget->priv->can_focus != can_focus)
6355 widget->priv->can_focus = can_focus;
6357 gtk_widget_queue_resize (widget);
6358 g_object_notify (G_OBJECT (widget), "can-focus");
6363 * gtk_widget_get_can_focus:
6364 * @widget: a #GtkWidget
6366 * Determines whether @widget can own the input focus. See
6367 * gtk_widget_set_can_focus().
6369 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6374 gtk_widget_get_can_focus (GtkWidget *widget)
6376 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6378 return widget->priv->can_focus;
6382 * gtk_widget_has_focus:
6383 * @widget: a #GtkWidget
6385 * Determines if the widget has the global input focus. See
6386 * gtk_widget_is_focus() for the difference between having the global
6387 * input focus, and only having the focus within a toplevel.
6389 * Return value: %TRUE if the widget has the global input focus.
6394 gtk_widget_has_focus (GtkWidget *widget)
6396 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6398 return widget->priv->has_focus;
6402 * gtk_widget_is_focus:
6403 * @widget: a #GtkWidget
6405 * Determines if the widget is the focus widget within its
6406 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6407 * necessarily set; %HAS_FOCUS will only be set if the
6408 * toplevel widget additionally has the global input focus.)
6410 * Return value: %TRUE if the widget is the focus widget.
6413 gtk_widget_is_focus (GtkWidget *widget)
6415 GtkWidget *toplevel;
6417 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6419 toplevel = gtk_widget_get_toplevel (widget);
6421 if (GTK_IS_WINDOW (toplevel))
6422 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6428 * gtk_widget_set_can_default:
6429 * @widget: a #GtkWidget
6430 * @can_default: whether or not @widget can be a default widget.
6432 * Specifies whether @widget can be a default widget. See
6433 * gtk_widget_grab_default() for details about the meaning of
6439 gtk_widget_set_can_default (GtkWidget *widget,
6440 gboolean can_default)
6442 g_return_if_fail (GTK_IS_WIDGET (widget));
6444 if (widget->priv->can_default != can_default)
6446 widget->priv->can_default = can_default;
6448 gtk_widget_queue_resize (widget);
6449 g_object_notify (G_OBJECT (widget), "can-default");
6454 * gtk_widget_get_can_default:
6455 * @widget: a #GtkWidget
6457 * Determines whether @widget can be a default widget. See
6458 * gtk_widget_set_can_default().
6460 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6465 gtk_widget_get_can_default (GtkWidget *widget)
6467 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6469 return widget->priv->can_default;
6473 * gtk_widget_has_default:
6474 * @widget: a #GtkWidget
6476 * Determines whether @widget is the current default widget within its
6477 * toplevel. See gtk_widget_set_can_default().
6479 * Return value: %TRUE if @widget is the current default widget within
6480 * its toplevel, %FALSE otherwise
6485 gtk_widget_has_default (GtkWidget *widget)
6487 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6489 return widget->priv->has_default;
6493 _gtk_widget_set_has_default (GtkWidget *widget,
6494 gboolean has_default)
6496 widget->priv->has_default = has_default;
6500 * gtk_widget_grab_default:
6501 * @widget: a #GtkWidget
6503 * Causes @widget to become the default widget. @widget must have the
6504 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6505 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6506 * %TRUE)</literal>. The default widget is activated when
6507 * the user presses Enter in a window. Default widgets must be
6508 * activatable, that is, gtk_widget_activate() should affect them. Note
6509 * that #GtkEntry widgets require the "activates-default" property
6510 * set to %TRUE before they activate the default widget when Enter
6511 * is pressed and the #GtkEntry is focused.
6514 gtk_widget_grab_default (GtkWidget *widget)
6518 g_return_if_fail (GTK_IS_WIDGET (widget));
6519 g_return_if_fail (gtk_widget_get_can_default (widget));
6521 window = gtk_widget_get_toplevel (widget);
6523 if (window && gtk_widget_is_toplevel (window))
6524 gtk_window_set_default (GTK_WINDOW (window), widget);
6526 g_warning (G_STRLOC ": widget not within a GtkWindow");
6530 * gtk_widget_set_receives_default:
6531 * @widget: a #GtkWidget
6532 * @receives_default: whether or not @widget can be a default widget.
6534 * Specifies whether @widget will be treated as the default widget
6535 * within its toplevel when it has the focus, even if another widget
6538 * See gtk_widget_grab_default() for details about the meaning of
6544 gtk_widget_set_receives_default (GtkWidget *widget,
6545 gboolean receives_default)
6547 g_return_if_fail (GTK_IS_WIDGET (widget));
6549 if (widget->priv->receives_default != receives_default)
6551 widget->priv->receives_default = receives_default;
6553 g_object_notify (G_OBJECT (widget), "receives-default");
6558 * gtk_widget_get_receives_default:
6559 * @widget: a #GtkWidget
6561 * Determines whether @widget is alyways treated as default widget
6562 * withing its toplevel when it has the focus, even if another widget
6565 * See gtk_widget_set_receives_default().
6567 * Return value: %TRUE if @widget acts as default widget when focussed,
6573 gtk_widget_get_receives_default (GtkWidget *widget)
6575 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6577 return widget->priv->receives_default;
6581 * gtk_widget_has_grab:
6582 * @widget: a #GtkWidget
6584 * Determines whether the widget is currently grabbing events, so it
6585 * is the only widget receiving input events (keyboard and mouse).
6587 * See also gtk_grab_add().
6589 * Return value: %TRUE if the widget is in the grab_widgets stack
6594 gtk_widget_has_grab (GtkWidget *widget)
6596 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6598 return widget->priv->has_grab;
6602 _gtk_widget_set_has_grab (GtkWidget *widget,
6605 widget->priv->has_grab = has_grab;
6609 * gtk_widget_device_is_shadowed:
6610 * @widget: a #GtkWidget
6611 * @device: a #GdkDevice
6613 * Returns %TRUE if @device has been shadowed by a GTK+
6614 * device grab on another widget, so it would stop sending
6615 * events to @widget. This may be used in the
6616 * #GtkWidget::grab-notify signal to check for specific
6617 * devices. See gtk_device_grab_add().
6619 * Returns: %TRUE if there is an ongoing grab on @device
6620 * by another #GtkWidget than @widget.
6625 gtk_widget_device_is_shadowed (GtkWidget *widget,
6628 GtkWindowGroup *group;
6629 GtkWidget *grab_widget, *toplevel;
6631 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6632 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6634 if (!gtk_widget_get_realized (widget))
6637 toplevel = gtk_widget_get_toplevel (widget);
6639 if (GTK_IS_WINDOW (toplevel))
6640 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6642 group = gtk_window_get_group (NULL);
6644 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6646 /* Widget not inside the hierarchy of grab_widget */
6648 widget != grab_widget &&
6649 !gtk_widget_is_ancestor (widget, grab_widget))
6652 grab_widget = gtk_window_group_get_current_grab (group);
6653 if (grab_widget && widget != grab_widget &&
6654 !gtk_widget_is_ancestor (widget, grab_widget))
6661 * gtk_widget_set_name:
6662 * @widget: a #GtkWidget
6663 * @name: name for the widget
6665 * Widgets can be named, which allows you to refer to them from a
6666 * gtkrc file. You can apply a style to widgets with a particular name
6667 * in the gtkrc file. See the documentation for gtkrc files (on the
6668 * same page as the docs for #GtkRcStyle).
6670 * Note that widget names are separated by periods in paths (see
6671 * gtk_widget_path()), so names with embedded periods may cause confusion.
6674 gtk_widget_set_name (GtkWidget *widget,
6677 GtkWidgetPrivate *priv;
6680 g_return_if_fail (GTK_IS_WIDGET (widget));
6682 priv = widget->priv;
6684 new_name = g_strdup (name);
6685 g_free (priv->name);
6686 priv->name = new_name;
6689 gtk_widget_reset_rc_style (widget);
6691 g_object_notify (G_OBJECT (widget), "name");
6695 * gtk_widget_get_name:
6696 * @widget: a #GtkWidget
6698 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6699 * significance of widget names.
6701 * Return value: name of the widget. This string is owned by GTK+ and
6702 * should not be modified or freed
6704 G_CONST_RETURN gchar*
6705 gtk_widget_get_name (GtkWidget *widget)
6707 GtkWidgetPrivate *priv;
6709 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6711 priv = widget->priv;
6715 return G_OBJECT_TYPE_NAME (widget);
6719 * gtk_widget_set_state:
6720 * @widget: a #GtkWidget
6721 * @state: new state for @widget
6723 * This function is for use in widget implementations. Sets the state
6724 * of a widget (insensitive, prelighted, etc.) Usually you should set
6725 * the state using wrapper functions such as gtk_widget_set_sensitive().
6728 gtk_widget_set_state (GtkWidget *widget,
6731 GtkWidgetPrivate *priv;
6733 g_return_if_fail (GTK_IS_WIDGET (widget));
6735 priv = widget->priv;
6737 if (state == gtk_widget_get_state (widget))
6740 if (state == GTK_STATE_INSENSITIVE)
6741 gtk_widget_set_sensitive (widget, FALSE);
6747 data.state_restoration = FALSE;
6748 data.use_forall = FALSE;
6750 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6752 data.parent_sensitive = TRUE;
6754 gtk_widget_propagate_state (widget, &data);
6756 if (gtk_widget_is_drawable (widget))
6757 gtk_widget_queue_draw (widget);
6762 * gtk_widget_get_state:
6763 * @widget: a #GtkWidget
6765 * Returns the widget's state. See gtk_widget_set_state().
6767 * Returns: the state of @widget.
6772 gtk_widget_get_state (GtkWidget *widget)
6774 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6776 return widget->priv->state;
6780 * gtk_widget_set_visible:
6781 * @widget: a #GtkWidget
6782 * @visible: whether the widget should be shown or not
6784 * Sets the visibility state of @widget. Note that setting this to
6785 * %TRUE doesn't mean the widget is actually viewable, see
6786 * gtk_widget_get_visible().
6788 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6789 * but is nicer to use when the visibility of the widget depends on
6795 gtk_widget_set_visible (GtkWidget *widget,
6798 g_return_if_fail (GTK_IS_WIDGET (widget));
6800 if (visible != gtk_widget_get_visible (widget))
6803 gtk_widget_show (widget);
6805 gtk_widget_hide (widget);
6810 _gtk_widget_set_visible_flag (GtkWidget *widget,
6813 widget->priv->visible = visible;
6817 * gtk_widget_get_visible:
6818 * @widget: a #GtkWidget
6820 * Determines whether the widget is visible. Note that this doesn't
6821 * take into account whether the widget's parent is also visible
6822 * or the widget is obscured in any way.
6824 * See gtk_widget_set_visible().
6826 * Return value: %TRUE if the widget is visible
6831 gtk_widget_get_visible (GtkWidget *widget)
6833 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6835 return widget->priv->visible;
6839 * gtk_widget_set_has_window:
6840 * @widget: a #GtkWidget
6841 * @has_window: whether or not @widget has a window.
6843 * Specifies whether @widget has a #GdkWindow of its own. Note that
6844 * all realized widgets have a non-%NULL "window" pointer
6845 * (gtk_widget_get_window() never returns a %NULL window when a widget
6846 * is realized), but for many of them it's actually the #GdkWindow of
6847 * one of its parent widgets. Widgets that do not create a %window for
6848 * themselves in GtkWidget::realize() must announce this by
6849 * calling this function with @has_window = %FALSE.
6851 * This function should only be called by widget implementations,
6852 * and they should call it in their init() function.
6857 gtk_widget_set_has_window (GtkWidget *widget,
6858 gboolean has_window)
6860 g_return_if_fail (GTK_IS_WIDGET (widget));
6862 widget->priv->no_window = !has_window;
6866 * gtk_widget_get_has_window:
6867 * @widget: a #GtkWidget
6869 * Determines whether @widget has a #GdkWindow of its own. See
6870 * gtk_widget_set_has_window().
6872 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6877 gtk_widget_get_has_window (GtkWidget *widget)
6879 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6881 return ! widget->priv->no_window;
6885 * gtk_widget_is_toplevel:
6886 * @widget: a #GtkWidget
6888 * Determines whether @widget is a toplevel widget. Currently only
6889 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6890 * widgets have no parent widget.
6892 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6897 gtk_widget_is_toplevel (GtkWidget *widget)
6899 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6901 return widget->priv->toplevel;
6905 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6906 gboolean is_toplevel)
6908 widget->priv->toplevel = is_toplevel;
6912 * gtk_widget_is_drawable:
6913 * @widget: a #GtkWidget
6915 * Determines whether @widget can be drawn to. A widget can be drawn
6916 * to if it is mapped and visible.
6918 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6923 gtk_widget_is_drawable (GtkWidget *widget)
6925 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6927 return (gtk_widget_get_visible (widget) &&
6928 gtk_widget_get_mapped (widget));
6932 * gtk_widget_get_realized:
6933 * @widget: a #GtkWidget
6935 * Determines whether @widget is realized.
6937 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6942 gtk_widget_get_realized (GtkWidget *widget)
6944 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6946 return widget->priv->realized;
6950 * gtk_widget_set_realized:
6951 * @widget: a #GtkWidget
6952 * @realized: %TRUE to mark the widget as realized
6954 * Marks the widget as being realized.
6956 * This function should only ever be called in a derived widget's
6957 * "realize" or "unrealize" implementation.
6962 gtk_widget_set_realized (GtkWidget *widget,
6965 g_return_if_fail (GTK_IS_WIDGET (widget));
6967 widget->priv->realized = realized;
6971 * gtk_widget_get_mapped:
6972 * @widget: a #GtkWidget
6974 * Whether the widget is mapped.
6976 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6981 gtk_widget_get_mapped (GtkWidget *widget)
6983 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6985 return widget->priv->mapped;
6989 * gtk_widget_set_mapped:
6990 * @widget: a #GtkWidget
6991 * @mapped: %TRUE to mark the widget as mapped
6993 * Marks the widget as being realized.
6995 * This function should only ever be called in a derived widget's
6996 * "map" or "unmap" implementation.
7001 gtk_widget_set_mapped (GtkWidget *widget,
7004 g_return_if_fail (GTK_IS_WIDGET (widget));
7006 widget->priv->mapped = mapped;
7010 * gtk_widget_set_app_paintable:
7011 * @widget: a #GtkWidget
7012 * @app_paintable: %TRUE if the application will paint on the widget
7014 * Sets whether the application intends to draw on the widget in
7015 * an #GtkWidget::draw handler.
7017 * This is a hint to the widget and does not affect the behavior of
7018 * the GTK+ core; many widgets ignore this flag entirely. For widgets
7019 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
7020 * the effect is to suppress default themed drawing of the widget's
7021 * background. (Children of the widget will still be drawn.) The application
7022 * is then entirely responsible for drawing the widget background.
7024 * Note that the background is still drawn when the widget is mapped.
7027 gtk_widget_set_app_paintable (GtkWidget *widget,
7028 gboolean app_paintable)
7030 g_return_if_fail (GTK_IS_WIDGET (widget));
7032 app_paintable = (app_paintable != FALSE);
7034 if (widget->priv->app_paintable != app_paintable)
7036 widget->priv->app_paintable = app_paintable;
7038 if (gtk_widget_is_drawable (widget))
7039 gtk_widget_queue_draw (widget);
7041 g_object_notify (G_OBJECT (widget), "app-paintable");
7046 * gtk_widget_get_app_paintable:
7047 * @widget: a #GtkWidget
7049 * Determines whether the application intends to draw on the widget in
7050 * an #GtkWidget::draw handler.
7052 * See gtk_widget_set_app_paintable()
7054 * Return value: %TRUE if the widget is app paintable
7059 gtk_widget_get_app_paintable (GtkWidget *widget)
7061 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7063 return widget->priv->app_paintable;
7067 * gtk_widget_set_double_buffered:
7068 * @widget: a #GtkWidget
7069 * @double_buffered: %TRUE to double-buffer a widget
7071 * Widgets are double buffered by default; you can use this function
7072 * to turn off the buffering. "Double buffered" simply means that
7073 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
7074 * automatically around expose events sent to the
7075 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
7076 * window to an offscreen buffer, and gdk_window_end_paint() draws the
7077 * buffer to the screen. The result is that users see the window
7078 * update in one smooth step, and don't see individual graphics
7079 * primitives being rendered.
7081 * In very simple terms, double buffered widgets don't flicker,
7082 * so you would only use this function to turn off double buffering
7083 * if you had special needs and really knew what you were doing.
7085 * Note: if you turn off double-buffering, you have to handle
7086 * expose events, since even the clearing to the background color or
7087 * pixmap will not happen automatically (as it is done in
7088 * gdk_window_begin_paint()).
7091 gtk_widget_set_double_buffered (GtkWidget *widget,
7092 gboolean double_buffered)
7094 g_return_if_fail (GTK_IS_WIDGET (widget));
7096 double_buffered = (double_buffered != FALSE);
7098 if (widget->priv->double_buffered != double_buffered)
7100 widget->priv->double_buffered = double_buffered;
7102 g_object_notify (G_OBJECT (widget), "double-buffered");
7107 * gtk_widget_get_double_buffered:
7108 * @widget: a #GtkWidget
7110 * Determines whether the widget is double buffered.
7112 * See gtk_widget_set_double_buffered()
7114 * Return value: %TRUE if the widget is double buffered
7119 gtk_widget_get_double_buffered (GtkWidget *widget)
7121 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7123 return widget->priv->double_buffered;
7127 * gtk_widget_set_redraw_on_allocate:
7128 * @widget: a #GtkWidget
7129 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7130 * when it is allocated to a new size. Otherwise, only the
7131 * new portion of the widget will be redrawn.
7133 * Sets whether the entire widget is queued for drawing when its size
7134 * allocation changes. By default, this setting is %TRUE and
7135 * the entire widget is redrawn on every size change. If your widget
7136 * leaves the upper left unchanged when made bigger, turning this
7137 * setting off will improve performance.
7139 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7140 * off all allocation on resizing: the widget will not even redraw if
7141 * its position changes; this is to allow containers that don't draw
7142 * anything to avoid excess invalidations. If you set this flag on a
7143 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7144 * you are responsible for invalidating both the old and new allocation
7145 * of the widget when the widget is moved and responsible for invalidating
7146 * regions newly when the widget increases size.
7149 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7150 gboolean redraw_on_allocate)
7152 g_return_if_fail (GTK_IS_WIDGET (widget));
7154 widget->priv->redraw_on_alloc = redraw_on_allocate;
7158 * gtk_widget_set_sensitive:
7159 * @widget: a #GtkWidget
7160 * @sensitive: %TRUE to make the widget sensitive
7162 * Sets the sensitivity of a widget. A widget is sensitive if the user
7163 * can interact with it. Insensitive widgets are "grayed out" and the
7164 * user can't interact with them. Insensitive widgets are known as
7165 * "inactive", "disabled", or "ghosted" in some other toolkits.
7168 gtk_widget_set_sensitive (GtkWidget *widget,
7171 GtkWidgetPrivate *priv;
7174 g_return_if_fail (GTK_IS_WIDGET (widget));
7176 priv = widget->priv;
7178 sensitive = (sensitive != FALSE);
7180 if (widget->priv->sensitive == sensitive)
7185 widget->priv->sensitive = TRUE;
7186 data.state = priv->saved_state;
7190 widget->priv->sensitive = FALSE;
7191 data.state = gtk_widget_get_state (widget);
7193 data.state_restoration = TRUE;
7194 data.use_forall = TRUE;
7197 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7199 data.parent_sensitive = TRUE;
7201 gtk_widget_propagate_state (widget, &data);
7202 if (gtk_widget_is_drawable (widget))
7203 gtk_widget_queue_draw (widget);
7205 g_object_notify (G_OBJECT (widget), "sensitive");
7209 * gtk_widget_get_sensitive:
7210 * @widget: a #GtkWidget
7212 * Returns the widget's sensitivity (in the sense of returning
7213 * the value that has been set using gtk_widget_set_sensitive()).
7215 * The effective sensitivity of a widget is however determined by both its
7216 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7218 * Returns: %TRUE if the widget is sensitive
7223 gtk_widget_get_sensitive (GtkWidget *widget)
7225 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7227 return widget->priv->sensitive;
7231 * gtk_widget_is_sensitive:
7232 * @widget: a #GtkWidget
7234 * Returns the widget's effective sensitivity, which means
7235 * it is sensitive itself and also its parent widget is sensntive
7237 * Returns: %TRUE if the widget is effectively sensitive
7242 gtk_widget_is_sensitive (GtkWidget *widget)
7244 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7246 return widget->priv->sensitive && widget->priv->parent_sensitive;
7250 * gtk_widget_set_parent:
7251 * @widget: a #GtkWidget
7252 * @parent: parent container
7254 * This function is useful only when implementing subclasses of
7256 * Sets the container as the parent of @widget, and takes care of
7257 * some details such as updating the state and style of the child
7258 * to reflect its new location. The opposite function is
7259 * gtk_widget_unparent().
7262 gtk_widget_set_parent (GtkWidget *widget,
7265 GtkWidgetPrivate *priv;
7268 g_return_if_fail (GTK_IS_WIDGET (widget));
7269 g_return_if_fail (GTK_IS_WIDGET (parent));
7270 g_return_if_fail (widget != parent);
7272 priv = widget->priv;
7274 if (priv->parent != NULL)
7276 g_warning ("Can't set a parent on widget which has a parent\n");
7279 if (gtk_widget_is_toplevel (widget))
7281 g_warning ("Can't set a parent on a toplevel widget\n");
7285 /* keep this function in sync with gtk_menu_attach_to_widget()
7288 g_object_ref_sink (widget);
7289 priv->parent = parent;
7291 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7292 data.state = gtk_widget_get_state (parent);
7294 data.state = gtk_widget_get_state (widget);
7295 data.state_restoration = FALSE;
7296 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7297 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7299 gtk_widget_propagate_state (widget, &data);
7301 gtk_widget_reset_rc_styles (widget);
7303 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7304 if (priv->parent->priv->anchored)
7305 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7306 g_object_notify (G_OBJECT (widget), "parent");
7308 /* Enforce realized/mapped invariants
7310 if (gtk_widget_get_realized (priv->parent))
7311 gtk_widget_realize (widget);
7313 if (gtk_widget_get_visible (priv->parent) &&
7314 gtk_widget_get_visible (widget))
7316 if (gtk_widget_get_child_visible (widget) &&
7317 gtk_widget_get_mapped (priv->parent))
7318 gtk_widget_map (widget);
7320 gtk_widget_queue_resize (widget);
7323 /* child may cause parent's expand to change, if the child is
7324 * expanded. If child is not expanded, then it can't modify the
7325 * parent's expand. If the child becomes expanded later then it will
7326 * queue compute_expand then. This optimization plus defaulting
7327 * newly-constructed widgets to need_compute_expand=FALSE should
7328 * mean that initially building a widget tree doesn't have to keep
7329 * walking up setting need_compute_expand on parents over and over.
7331 * We can't change a parent to need to expand unless we're visible.
7333 if (gtk_widget_get_visible (widget) &&
7334 (priv->need_compute_expand ||
7335 priv->computed_hexpand ||
7336 priv->computed_vexpand))
7338 gtk_widget_queue_compute_expand (parent);
7343 * gtk_widget_get_parent:
7344 * @widget: a #GtkWidget
7346 * Returns the parent container of @widget.
7348 * Return value: (transfer none): the parent container of @widget, or %NULL
7351 gtk_widget_get_parent (GtkWidget *widget)
7353 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7355 return widget->priv->parent;
7358 /*****************************************
7360 * see docs/styles.txt
7361 *****************************************/
7364 * gtk_widget_style_attach:
7365 * @widget: a #GtkWidget
7367 * This function attaches the widget's #GtkStyle to the widget's
7368 * #GdkWindow. It is a replacement for
7371 * widget->style = gtk_style_attach (widget->style, widget->window);
7374 * and should only ever be called in a derived widget's "realize"
7375 * implementation which does not chain up to its parent class'
7376 * "realize" implementation, because one of the parent classes
7377 * (finally #GtkWidget) would attach the style itself.
7382 gtk_widget_style_attach (GtkWidget *widget)
7384 GtkWidgetPrivate *priv;
7386 g_return_if_fail (GTK_IS_WIDGET (widget));
7387 g_return_if_fail (gtk_widget_get_realized (widget));
7389 priv = widget->priv;
7391 priv->style = gtk_style_attach (priv->style, priv->window);
7395 * gtk_widget_has_rc_style:
7396 * @widget: a #GtkWidget
7398 * Determines if the widget style has been looked up through the rc mechanism.
7400 * Returns: %TRUE if the widget has been looked up through the rc
7401 * mechanism, %FALSE otherwise.
7406 gtk_widget_has_rc_style (GtkWidget *widget)
7408 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7410 return widget->priv->rc_style;
7414 * gtk_widget_set_style:
7415 * @widget: a #GtkWidget
7416 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7417 * gtk_widget_set_style() and go back to the default style
7419 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7420 * want to use this function; it interacts badly with themes, because
7421 * themes work by replacing the #GtkStyle. Instead, use
7422 * gtk_widget_modify_style().
7425 gtk_widget_set_style (GtkWidget *widget,
7428 g_return_if_fail (GTK_IS_WIDGET (widget));
7432 gboolean initial_emission;
7434 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7436 widget->priv->rc_style = FALSE;
7437 widget->priv->user_style = TRUE;
7439 gtk_widget_set_style_internal (widget, style, initial_emission);
7443 if (widget->priv->user_style)
7444 gtk_widget_reset_rc_style (widget);
7449 * gtk_widget_ensure_style:
7450 * @widget: a #GtkWidget
7452 * Ensures that @widget has a style (@widget->style). Not a very useful
7453 * function; most of the time, if you want the style, the widget is
7454 * realized, and realized widgets are guaranteed to have a style
7458 gtk_widget_ensure_style (GtkWidget *widget)
7460 g_return_if_fail (GTK_IS_WIDGET (widget));
7462 if (!widget->priv->rc_style && !widget->priv->user_style)
7463 gtk_widget_reset_rc_style (widget);
7466 /* Look up the RC style for this widget, unsetting any user style that
7467 * may be in effect currently
7470 gtk_widget_reset_rc_style (GtkWidget *widget)
7472 GtkWidgetPrivate *priv = widget->priv;
7473 GtkStyle *new_style = NULL;
7474 gboolean initial_emission;
7476 initial_emission = !priv->rc_style && !priv->user_style;
7478 priv->user_style = FALSE;
7479 priv->rc_style = TRUE;
7481 if (gtk_widget_has_screen (widget))
7482 new_style = gtk_rc_get_style (widget);
7484 new_style = gtk_widget_get_default_style ();
7486 if (initial_emission || new_style != priv->style)
7487 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7491 * gtk_widget_get_style:
7492 * @widget: a #GtkWidget
7494 * Simply an accessor function that returns @widget->style.
7496 * Return value: (transfer none): the widget's #GtkStyle
7499 gtk_widget_get_style (GtkWidget *widget)
7501 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7503 return widget->priv->style;
7507 * gtk_widget_modify_style:
7508 * @widget: a #GtkWidget
7509 * @style: the #GtkRcStyle holding the style modifications
7511 * Modifies style values on the widget. Modifications made using this
7512 * technique take precedence over style values set via an RC file,
7513 * however, they will be overriden if a style is explicitely set on
7514 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7515 * is designed so each field can either be set or unset, so it is
7516 * possible, using this function, to modify some style values and
7517 * leave the others unchanged.
7519 * Note that modifications made with this function are not cumulative
7520 * with previous calls to gtk_widget_modify_style() or with such
7521 * functions as gtk_widget_modify_fg(). If you wish to retain
7522 * previous values, you must first call gtk_widget_get_modifier_style(),
7523 * make your modifications to the returned style, then call
7524 * gtk_widget_modify_style() with that style. On the other hand,
7525 * if you first call gtk_widget_modify_style(), subsequent calls
7526 * to such functions gtk_widget_modify_fg() will have a cumulative
7527 * effect with the initial modifications.
7530 gtk_widget_modify_style (GtkWidget *widget,
7533 g_return_if_fail (GTK_IS_WIDGET (widget));
7534 g_return_if_fail (GTK_IS_RC_STYLE (style));
7536 g_object_set_qdata_full (G_OBJECT (widget),
7538 gtk_rc_style_copy (style),
7539 (GDestroyNotify) g_object_unref);
7541 /* note that "style" may be invalid here if it was the old
7542 * modifier style and the only reference was our own.
7545 if (widget->priv->rc_style)
7546 gtk_widget_reset_rc_style (widget);
7550 * gtk_widget_get_modifier_style:
7551 * @widget: a #GtkWidget
7553 * Returns the current modifier style for the widget. (As set by
7554 * gtk_widget_modify_style().) If no style has previously set, a new
7555 * #GtkRcStyle will be created with all values unset, and set as the
7556 * modifier style for the widget. If you make changes to this rc
7557 * style, you must call gtk_widget_modify_style(), passing in the
7558 * returned rc style, to make sure that your changes take effect.
7560 * Caution: passing the style back to gtk_widget_modify_style() will
7561 * normally end up destroying it, because gtk_widget_modify_style() copies
7562 * the passed-in style and sets the copy as the new modifier style,
7563 * thus dropping any reference to the old modifier style. Add a reference
7564 * to the modifier style if you want to keep it alive.
7566 * Return value: (transfer none): the modifier style for the widget. This rc style is
7567 * owned by the widget. If you want to keep a pointer to value this
7568 * around, you must add a refcount using g_object_ref().
7571 gtk_widget_get_modifier_style (GtkWidget *widget)
7573 GtkRcStyle *rc_style;
7575 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7577 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7581 rc_style = gtk_rc_style_new ();
7582 g_object_set_qdata_full (G_OBJECT (widget),
7585 (GDestroyNotify) g_object_unref);
7592 gtk_widget_modify_color_component (GtkWidget *widget,
7593 GtkRcFlags component,
7595 const GdkColor *color)
7597 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7604 rc_style->fg[state] = *color;
7607 rc_style->bg[state] = *color;
7610 rc_style->text[state] = *color;
7613 rc_style->base[state] = *color;
7616 g_assert_not_reached();
7619 rc_style->color_flags[state] |= component;
7622 rc_style->color_flags[state] &= ~component;
7624 gtk_widget_modify_style (widget, rc_style);
7628 * gtk_widget_modify_symbolic_color:
7629 * @widget: a #GtkWidget
7630 * @name: the name of the symbolic color to modify
7631 * @color: (allow-none): the color to assign (does not need to be allocated),
7632 * or %NULL to undo the effect of previous calls to
7633 * of gtk_widget_modify_symbolic_color().
7635 * Sets a symbolic color for a widget.
7636 * All other style values are left untouched. See also
7637 * gtk_widget_modify_style().
7642 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7644 const GdkColor *color)
7646 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7648 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7650 gtk_widget_modify_style (widget, rc_style);
7654 * gtk_widget_modify_fg:
7655 * @widget: a #GtkWidget
7656 * @state: the state for which to set the foreground color
7657 * @color: (allow-none): the color to assign (does not need to be allocated),
7658 * or %NULL to undo the effect of previous calls to
7659 * of gtk_widget_modify_fg().
7661 * Sets the foreground color for a widget in a particular state.
7662 * All other style values are left untouched. See also
7663 * gtk_widget_modify_style().
7666 gtk_widget_modify_fg (GtkWidget *widget,
7668 const GdkColor *color)
7670 g_return_if_fail (GTK_IS_WIDGET (widget));
7671 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7673 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7677 * gtk_widget_modify_bg:
7678 * @widget: a #GtkWidget
7679 * @state: the state for which to set the background color
7680 * @color: (allow-none): the color to assign (does not need to be allocated),
7681 * or %NULL to undo the effect of previous calls to
7682 * of gtk_widget_modify_bg().
7684 * Sets the background color for a widget in a particular state.
7685 * All other style values are left untouched. See also
7686 * gtk_widget_modify_style().
7688 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7689 * draw on their parent container's window and thus may not draw any
7690 * background themselves. This is the case for e.g. #GtkLabel. To modify
7691 * the background of such widgets, you have to set the background color
7692 * on their parent; if you want to set the background of a rectangular
7693 * area around a label, try placing the label in a #GtkEventBox widget
7694 * and setting the background color on that.
7697 gtk_widget_modify_bg (GtkWidget *widget,
7699 const GdkColor *color)
7701 g_return_if_fail (GTK_IS_WIDGET (widget));
7702 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7704 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7708 * gtk_widget_modify_text:
7709 * @widget: a #GtkWidget
7710 * @state: the state for which to set the text color
7711 * @color: (allow-none): the color to assign (does not need to be allocated),
7712 * or %NULL to undo the effect of previous calls to
7713 * of gtk_widget_modify_text().
7715 * Sets the text color for a widget in a particular state. All other
7716 * style values are left untouched. The text color is the foreground
7717 * color used along with the base color (see gtk_widget_modify_base())
7718 * for widgets such as #GtkEntry and #GtkTextView. See also
7719 * gtk_widget_modify_style().
7722 gtk_widget_modify_text (GtkWidget *widget,
7724 const GdkColor *color)
7726 g_return_if_fail (GTK_IS_WIDGET (widget));
7727 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7729 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7733 * gtk_widget_modify_base:
7734 * @widget: a #GtkWidget
7735 * @state: the state for which to set the base color
7736 * @color: (allow-none): the color to assign (does not need to be allocated),
7737 * or %NULL to undo the effect of previous calls to
7738 * of gtk_widget_modify_base().
7740 * Sets the base color for a widget in a particular state.
7741 * All other style values are left untouched. The base color
7742 * is the background color used along with the text color
7743 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7744 * and #GtkTextView. See also gtk_widget_modify_style().
7746 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7747 * draw on their parent container's window and thus may not draw any
7748 * background themselves. This is the case for e.g. #GtkLabel. To modify
7749 * the background of such widgets, you have to set the base color on their
7750 * parent; if you want to set the background of a rectangular area around
7751 * a label, try placing the label in a #GtkEventBox widget and setting
7752 * the base color on that.
7755 gtk_widget_modify_base (GtkWidget *widget,
7757 const GdkColor *color)
7759 g_return_if_fail (GTK_IS_WIDGET (widget));
7760 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7762 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7766 modify_color_property (GtkWidget *widget,
7767 GtkRcStyle *rc_style,
7769 const GdkColor *color)
7771 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7772 GQuark property_name = g_quark_from_string (name);
7776 GtkRcProperty rc_property = {0};
7779 rc_property.type_name = type_name;
7780 rc_property.property_name = property_name;
7781 rc_property.origin = NULL;
7783 color_name = gdk_color_to_string (color);
7784 g_value_init (&rc_property.value, G_TYPE_STRING);
7785 g_value_take_string (&rc_property.value, color_name);
7787 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7789 g_value_unset (&rc_property.value);
7792 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7796 * gtk_widget_modify_cursor:
7797 * @widget: a #GtkWidget
7798 * @primary: the color to use for primary cursor (does not need to be
7799 * allocated), or %NULL to undo the effect of previous calls to
7800 * of gtk_widget_modify_cursor().
7801 * @secondary: the color to use for secondary cursor (does not need to be
7802 * allocated), or %NULL to undo the effect of previous calls to
7803 * of gtk_widget_modify_cursor().
7805 * Sets the cursor color to use in a widget, overriding the
7806 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7807 * style properties. All other style values are left untouched.
7808 * See also gtk_widget_modify_style().
7813 gtk_widget_modify_cursor (GtkWidget *widget,
7814 const GdkColor *primary,
7815 const GdkColor *secondary)
7817 GtkRcStyle *rc_style;
7819 g_return_if_fail (GTK_IS_WIDGET (widget));
7821 rc_style = gtk_widget_get_modifier_style (widget);
7823 modify_color_property (widget, rc_style, "cursor-color", primary);
7824 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7826 gtk_widget_modify_style (widget, rc_style);
7830 * gtk_widget_modify_font:
7831 * @widget: a #GtkWidget
7832 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7833 * the effect of previous calls to gtk_widget_modify_font().
7835 * Sets the font to use for a widget. All other style values are left
7836 * untouched. See also gtk_widget_modify_style().
7839 gtk_widget_modify_font (GtkWidget *widget,
7840 PangoFontDescription *font_desc)
7842 GtkRcStyle *rc_style;
7844 g_return_if_fail (GTK_IS_WIDGET (widget));
7846 rc_style = gtk_widget_get_modifier_style (widget);
7848 if (rc_style->font_desc)
7849 pango_font_description_free (rc_style->font_desc);
7852 rc_style->font_desc = pango_font_description_copy (font_desc);
7854 rc_style->font_desc = NULL;
7856 gtk_widget_modify_style (widget, rc_style);
7860 gtk_widget_real_direction_changed (GtkWidget *widget,
7861 GtkTextDirection previous_direction)
7863 gtk_widget_queue_resize (widget);
7867 gtk_widget_real_style_set (GtkWidget *widget,
7868 GtkStyle *previous_style)
7870 GtkWidgetPrivate *priv = widget->priv;
7872 if (gtk_widget_get_realized (widget) &&
7873 gtk_widget_get_has_window (widget))
7874 gtk_style_set_background (priv->style, priv->window, priv->state);
7878 gtk_widget_set_style_internal (GtkWidget *widget,
7880 gboolean initial_emission)
7882 GtkWidgetPrivate *priv = widget->priv;
7884 g_object_ref (widget);
7885 g_object_freeze_notify (G_OBJECT (widget));
7887 if (priv->style != style)
7889 GtkStyle *previous_style;
7891 if (gtk_widget_get_realized (widget))
7893 gtk_widget_reset_shapes (widget);
7894 gtk_style_detach (priv->style);
7897 previous_style = priv->style;
7898 priv->style = style;
7899 g_object_ref (priv->style);
7901 if (gtk_widget_get_realized (widget))
7902 priv->style = gtk_style_attach (priv->style, priv->window);
7904 gtk_widget_update_pango_context (widget);
7905 g_signal_emit (widget,
7906 widget_signals[STYLE_SET],
7908 initial_emission ? NULL : previous_style);
7909 g_object_unref (previous_style);
7911 if (priv->anchored && !initial_emission)
7912 gtk_widget_queue_resize (widget);
7914 else if (initial_emission)
7916 gtk_widget_update_pango_context (widget);
7917 g_signal_emit (widget,
7918 widget_signals[STYLE_SET],
7922 g_object_notify (G_OBJECT (widget), "style");
7923 g_object_thaw_notify (G_OBJECT (widget));
7924 g_object_unref (widget);
7928 GtkWidget *previous_toplevel;
7929 GdkScreen *previous_screen;
7930 GdkScreen *new_screen;
7931 } HierarchyChangedInfo;
7934 do_screen_change (GtkWidget *widget,
7935 GdkScreen *old_screen,
7936 GdkScreen *new_screen)
7938 if (old_screen != new_screen)
7942 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7944 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7947 _gtk_tooltip_hide (widget);
7948 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7953 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7954 gpointer client_data)
7956 GtkWidgetPrivate *priv = widget->priv;
7957 HierarchyChangedInfo *info = client_data;
7958 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7959 (priv->parent && priv->parent->priv->anchored);
7961 if (priv->anchored != new_anchored)
7963 g_object_ref (widget);
7965 priv->anchored = new_anchored;
7967 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7968 do_screen_change (widget, info->previous_screen, info->new_screen);
7970 if (GTK_IS_CONTAINER (widget))
7971 gtk_container_forall (GTK_CONTAINER (widget),
7972 gtk_widget_propagate_hierarchy_changed_recurse,
7975 g_object_unref (widget);
7980 * _gtk_widget_propagate_hierarchy_changed:
7981 * @widget: a #GtkWidget
7982 * @previous_toplevel: Previous toplevel
7984 * Propagates changes in the anchored state to a widget and all
7985 * children, unsetting or setting the %ANCHORED flag, and
7986 * emitting #GtkWidget::hierarchy-changed.
7989 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7990 GtkWidget *previous_toplevel)
7992 GtkWidgetPrivate *priv = widget->priv;
7993 HierarchyChangedInfo info;
7995 info.previous_toplevel = previous_toplevel;
7996 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7998 if (gtk_widget_is_toplevel (widget) ||
7999 (priv->parent && priv->parent->priv->anchored))
8000 info.new_screen = gtk_widget_get_screen (widget);
8002 info.new_screen = NULL;
8004 if (info.previous_screen)
8005 g_object_ref (info.previous_screen);
8006 if (previous_toplevel)
8007 g_object_ref (previous_toplevel);
8009 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
8011 if (previous_toplevel)
8012 g_object_unref (previous_toplevel);
8013 if (info.previous_screen)
8014 g_object_unref (info.previous_screen);
8018 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
8019 gpointer client_data)
8021 HierarchyChangedInfo *info = client_data;
8023 g_object_ref (widget);
8025 do_screen_change (widget, info->previous_screen, info->new_screen);
8027 if (GTK_IS_CONTAINER (widget))
8028 gtk_container_forall (GTK_CONTAINER (widget),
8029 gtk_widget_propagate_screen_changed_recurse,
8032 g_object_unref (widget);
8036 * gtk_widget_is_composited:
8037 * @widget: a #GtkWidget
8039 * Whether @widget can rely on having its alpha channel
8040 * drawn correctly. On X11 this function returns whether a
8041 * compositing manager is running for @widget's screen.
8043 * Please note that the semantics of this call will change
8044 * in the future if used on a widget that has a composited
8045 * window in its hierarchy (as set by gdk_window_set_composited()).
8047 * Return value: %TRUE if the widget can rely on its alpha
8048 * channel being drawn correctly.
8053 gtk_widget_is_composited (GtkWidget *widget)
8057 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8059 screen = gtk_widget_get_screen (widget);
8061 return gdk_screen_is_composited (screen);
8065 propagate_composited_changed (GtkWidget *widget,
8068 if (GTK_IS_CONTAINER (widget))
8070 gtk_container_forall (GTK_CONTAINER (widget),
8071 propagate_composited_changed,
8075 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
8079 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
8081 propagate_composited_changed (widget, NULL);
8085 * _gtk_widget_propagate_screen_changed:
8086 * @widget: a #GtkWidget
8087 * @previous_screen: Previous screen
8089 * Propagates changes in the screen for a widget to all
8090 * children, emitting #GtkWidget::screen-changed.
8093 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
8094 GdkScreen *previous_screen)
8096 HierarchyChangedInfo info;
8098 info.previous_screen = previous_screen;
8099 info.new_screen = gtk_widget_get_screen (widget);
8101 if (previous_screen)
8102 g_object_ref (previous_screen);
8104 gtk_widget_propagate_screen_changed_recurse (widget, &info);
8106 if (previous_screen)
8107 g_object_unref (previous_screen);
8111 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
8113 if (widget->priv->rc_style)
8114 gtk_widget_reset_rc_style (widget);
8116 if (GTK_IS_CONTAINER (widget))
8117 gtk_container_forall (GTK_CONTAINER (widget),
8118 reset_rc_styles_recurse,
8124 * gtk_widget_reset_rc_styles:
8125 * @widget: a #GtkWidget.
8127 * Reset the styles of @widget and all descendents, so when
8128 * they are looked up again, they get the correct values
8129 * for the currently loaded RC file settings.
8131 * This function is not useful for applications.
8134 gtk_widget_reset_rc_styles (GtkWidget *widget)
8136 g_return_if_fail (GTK_IS_WIDGET (widget));
8138 reset_rc_styles_recurse (widget, NULL);
8142 * gtk_widget_get_default_style:
8144 * Returns the default style used by all widgets initially.
8146 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8147 * by GTK+ and should not be modified or freed.
8150 gtk_widget_get_default_style (void)
8152 if (!gtk_default_style)
8154 gtk_default_style = gtk_style_new ();
8155 g_object_ref (gtk_default_style);
8158 return gtk_default_style;
8161 static PangoContext *
8162 gtk_widget_peek_pango_context (GtkWidget *widget)
8164 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8168 * gtk_widget_get_pango_context:
8169 * @widget: a #GtkWidget
8171 * Gets a #PangoContext with the appropriate font map, font description,
8172 * and base direction for this widget. Unlike the context returned
8173 * by gtk_widget_create_pango_context(), this context is owned by
8174 * the widget (it can be used until the screen for the widget changes
8175 * or the widget is removed from its toplevel), and will be updated to
8176 * match any changes to the widget's attributes.
8178 * If you create and keep a #PangoLayout using this context, you must
8179 * deal with changes to the context by calling pango_layout_context_changed()
8180 * on the layout in response to the #GtkWidget::style-set and
8181 * #GtkWidget::direction-changed signals for the widget.
8183 * Return value: (transfer none): the #PangoContext for the widget.
8186 gtk_widget_get_pango_context (GtkWidget *widget)
8188 PangoContext *context;
8190 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8192 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8195 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8196 g_object_set_qdata_full (G_OBJECT (widget),
8197 quark_pango_context,
8206 update_pango_context (GtkWidget *widget,
8207 PangoContext *context)
8209 GtkWidgetPrivate *priv = widget->priv;
8211 pango_context_set_font_description (context, priv->style->font_desc);
8212 pango_context_set_base_dir (context,
8213 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8214 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8218 gtk_widget_update_pango_context (GtkWidget *widget)
8220 PangoContext *context = gtk_widget_peek_pango_context (widget);
8226 update_pango_context (widget, context);
8228 screen = gtk_widget_get_screen_unchecked (widget);
8231 pango_cairo_context_set_resolution (context,
8232 gdk_screen_get_resolution (screen));
8233 pango_cairo_context_set_font_options (context,
8234 gdk_screen_get_font_options (screen));
8240 * gtk_widget_create_pango_context:
8241 * @widget: a #GtkWidget
8243 * Creates a new #PangoContext with the appropriate font map,
8244 * font description, and base direction for drawing text for
8245 * this widget. See also gtk_widget_get_pango_context().
8247 * Return value: (transfer full): the new #PangoContext
8250 gtk_widget_create_pango_context (GtkWidget *widget)
8253 PangoContext *context;
8255 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8257 screen = gtk_widget_get_screen_unchecked (widget);
8260 GTK_NOTE (MULTIHEAD,
8261 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8263 screen = gdk_screen_get_default ();
8266 context = gdk_pango_context_get_for_screen (screen);
8268 update_pango_context (widget, context);
8269 pango_context_set_language (context, gtk_get_default_language ());
8275 * gtk_widget_create_pango_layout:
8276 * @widget: a #GtkWidget
8277 * @text: text to set on the layout (can be %NULL)
8279 * Creates a new #PangoLayout with the appropriate font map,
8280 * font description, and base direction for drawing text for
8283 * If you keep a #PangoLayout created in this way around, in order to
8284 * notify the layout of changes to the base direction or font of this
8285 * widget, you must call pango_layout_context_changed() in response to
8286 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8289 * Return value: (transfer full): the new #PangoLayout
8292 gtk_widget_create_pango_layout (GtkWidget *widget,
8295 PangoLayout *layout;
8296 PangoContext *context;
8298 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8300 context = gtk_widget_get_pango_context (widget);
8301 layout = pango_layout_new (context);
8304 pango_layout_set_text (layout, text, -1);
8310 * gtk_widget_render_icon:
8311 * @widget: a #GtkWidget
8312 * @stock_id: a stock ID
8313 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8314 * render at the size of the source and don't scale (if there are
8315 * multiple source sizes, GTK+ picks one of the available sizes).
8316 * @detail: (allow-none): render detail to pass to theme engine
8318 * A convenience function that uses the theme engine and RC file
8319 * settings for @widget to look up @stock_id and render it to
8320 * a pixbuf. @stock_id should be a stock icon ID such as
8321 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8322 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8323 * identifies the widget or code doing the rendering, so that
8324 * theme engines can special-case rendering for that widget or code.
8326 * The pixels in the returned #GdkPixbuf are shared with the rest of
8327 * the application and should not be modified. The pixbuf should be freed
8328 * after use with g_object_unref().
8330 * Return value: (transfer full): a new pixbuf, or %NULL if the
8331 * stock ID wasn't known
8334 gtk_widget_render_icon (GtkWidget *widget,
8335 const gchar *stock_id,
8337 const gchar *detail)
8339 GtkWidgetPrivate *priv;
8340 GtkIconSet *icon_set;
8343 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8344 g_return_val_if_fail (stock_id != NULL, NULL);
8345 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8347 priv = widget->priv;
8349 gtk_widget_ensure_style (widget);
8351 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8353 if (icon_set == NULL)
8356 retval = gtk_icon_set_render_icon (icon_set,
8358 gtk_widget_get_direction (widget),
8359 gtk_widget_get_state (widget),
8368 * gtk_widget_set_parent_window:
8369 * @widget: a #GtkWidget.
8370 * @parent_window: the new parent window.
8372 * Sets a non default parent window for @widget.
8375 gtk_widget_set_parent_window (GtkWidget *widget,
8376 GdkWindow *parent_window)
8378 GdkWindow *old_parent_window;
8380 g_return_if_fail (GTK_IS_WIDGET (widget));
8382 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8383 quark_parent_window);
8385 if (parent_window != old_parent_window)
8387 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8389 if (old_parent_window)
8390 g_object_unref (old_parent_window);
8392 g_object_ref (parent_window);
8397 * gtk_widget_get_parent_window:
8398 * @widget: a #GtkWidget.
8400 * Gets @widget's parent window.
8402 * Returns: (transfer none): the parent window of @widget.
8405 gtk_widget_get_parent_window (GtkWidget *widget)
8407 GtkWidgetPrivate *priv;
8408 GdkWindow *parent_window;
8410 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8412 priv = widget->priv;
8414 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8416 return (parent_window != NULL) ? parent_window :
8417 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8422 * gtk_widget_set_child_visible:
8423 * @widget: a #GtkWidget
8424 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8426 * Sets whether @widget should be mapped along with its when its parent
8427 * is mapped and @widget has been shown with gtk_widget_show().
8429 * The child visibility can be set for widget before it is added to
8430 * a container with gtk_widget_set_parent(), to avoid mapping
8431 * children unnecessary before immediately unmapping them. However
8432 * it will be reset to its default state of %TRUE when the widget
8433 * is removed from a container.
8435 * Note that changing the child visibility of a widget does not
8436 * queue a resize on the widget. Most of the time, the size of
8437 * a widget is computed from all visible children, whether or
8438 * not they are mapped. If this is not the case, the container
8439 * can queue a resize itself.
8441 * This function is only useful for container implementations and
8442 * never should be called by an application.
8445 gtk_widget_set_child_visible (GtkWidget *widget,
8446 gboolean is_visible)
8448 GtkWidgetPrivate *priv;
8450 g_return_if_fail (GTK_IS_WIDGET (widget));
8451 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8453 priv = widget->priv;
8455 g_object_ref (widget);
8458 priv->child_visible = TRUE;
8461 GtkWidget *toplevel;
8463 priv->child_visible = FALSE;
8465 toplevel = gtk_widget_get_toplevel (widget);
8466 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8467 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8470 if (priv->parent && gtk_widget_get_realized (priv->parent))
8472 if (gtk_widget_get_mapped (priv->parent) &&
8473 priv->child_visible &&
8474 gtk_widget_get_visible (widget))
8475 gtk_widget_map (widget);
8477 gtk_widget_unmap (widget);
8480 g_object_unref (widget);
8484 * gtk_widget_get_child_visible:
8485 * @widget: a #GtkWidget
8487 * Gets the value set with gtk_widget_set_child_visible().
8488 * If you feel a need to use this function, your code probably
8489 * needs reorganization.
8491 * This function is only useful for container implementations and
8492 * never should be called by an application.
8494 * Return value: %TRUE if the widget is mapped with the parent.
8497 gtk_widget_get_child_visible (GtkWidget *widget)
8499 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8501 return widget->priv->child_visible;
8505 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8507 GtkWidget *toplevel;
8509 toplevel = gtk_widget_get_toplevel (widget);
8511 if (gtk_widget_is_toplevel (toplevel))
8513 if (GTK_IS_WINDOW (toplevel))
8514 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8515 else if (GTK_IS_INVISIBLE (toplevel))
8516 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8523 * gtk_widget_get_screen:
8524 * @widget: a #GtkWidget
8526 * Get the #GdkScreen from the toplevel window associated with
8527 * this widget. This function can only be called after the widget
8528 * has been added to a widget hierarchy with a #GtkWindow
8531 * In general, you should only create screen specific
8532 * resources when a widget has been realized, and you should
8533 * free those resources when the widget is unrealized.
8535 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8540 gtk_widget_get_screen (GtkWidget *widget)
8544 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8546 screen = gtk_widget_get_screen_unchecked (widget);
8553 g_warning (G_STRLOC ": Can't get associated screen"
8554 " for a widget unless it is inside a toplevel GtkWindow\n"
8555 " widget type is %s associated top level type is %s",
8556 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8557 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8559 return gdk_screen_get_default ();
8564 * gtk_widget_has_screen:
8565 * @widget: a #GtkWidget
8567 * Checks whether there is a #GdkScreen is associated with
8568 * this widget. All toplevel widgets have an associated
8569 * screen, and all widgets added into a hierarchy with a toplevel
8570 * window at the top.
8572 * Return value: %TRUE if there is a #GdkScreen associcated
8578 gtk_widget_has_screen (GtkWidget *widget)
8580 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8582 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8586 * gtk_widget_get_display:
8587 * @widget: a #GtkWidget
8589 * Get the #GdkDisplay for the toplevel window associated with
8590 * this widget. This function can only be called after the widget
8591 * has been added to a widget hierarchy with a #GtkWindow at the top.
8593 * In general, you should only create display specific
8594 * resources when a widget has been realized, and you should
8595 * free those resources when the widget is unrealized.
8597 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8602 gtk_widget_get_display (GtkWidget *widget)
8604 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8606 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8610 * gtk_widget_get_root_window:
8611 * @widget: a #GtkWidget
8613 * Get the root window where this widget is located. This function can
8614 * only be called after the widget has been added to a widget
8615 * hierarchy with #GtkWindow at the top.
8617 * The root window is useful for such purposes as creating a popup
8618 * #GdkWindow associated with the window. In general, you should only
8619 * create display specific resources when a widget has been realized,
8620 * and you should free those resources when the widget is unrealized.
8622 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8627 gtk_widget_get_root_window (GtkWidget *widget)
8629 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8631 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8635 * gtk_widget_child_focus:
8636 * @widget: a #GtkWidget
8637 * @direction: direction of focus movement
8639 * This function is used by custom widget implementations; if you're
8640 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8641 * to a particular widget, and gtk_container_set_focus_chain() to
8642 * change the focus tab order. So you may want to investigate those
8643 * functions instead.
8645 * gtk_widget_child_focus() is called by containers as the user moves
8646 * around the window using keyboard shortcuts. @direction indicates
8647 * what kind of motion is taking place (up, down, left, right, tab
8648 * forward, tab backward). gtk_widget_child_focus() emits the
8649 * #GtkWidget::focus signal; widgets override the default handler
8650 * for this signal in order to implement appropriate focus behavior.
8652 * The default ::focus handler for a widget should return %TRUE if
8653 * moving in @direction left the focus on a focusable location inside
8654 * that widget, and %FALSE if moving in @direction moved the focus
8655 * outside the widget. If returning %TRUE, widgets normally
8656 * call gtk_widget_grab_focus() to place the focus accordingly;
8657 * if returning %FALSE, they don't modify the current focus location.
8659 * Return value: %TRUE if focus ended up inside @widget
8662 gtk_widget_child_focus (GtkWidget *widget,
8663 GtkDirectionType direction)
8665 gboolean return_val;
8667 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8669 if (!gtk_widget_get_visible (widget) ||
8670 !gtk_widget_is_sensitive (widget))
8673 /* child widgets must set CAN_FOCUS, containers
8674 * don't have to though.
8676 if (!GTK_IS_CONTAINER (widget) &&
8677 !gtk_widget_get_can_focus (widget))
8680 g_signal_emit (widget,
8681 widget_signals[FOCUS],
8683 direction, &return_val);
8689 * gtk_widget_keynav_failed:
8690 * @widget: a #GtkWidget
8691 * @direction: direction of focus movement
8693 * This function should be called whenever keyboard navigation within
8694 * a single widget hits a boundary. The function emits the
8695 * #GtkWidget::keynav-failed signal on the widget and its return
8696 * value should be interpreted in a way similar to the return value of
8697 * gtk_widget_child_focus():
8699 * When %TRUE is returned, stay in the widget, the failed keyboard
8700 * navigation is Ok and/or there is nowhere we can/should move the
8703 * When %FALSE is returned, the caller should continue with keyboard
8704 * navigation outside the widget, e.g. by calling
8705 * gtk_widget_child_focus() on the widget's toplevel.
8707 * The default ::keynav-failed handler returns %TRUE for
8708 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8709 * values of #GtkDirectionType, it looks at the
8710 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8711 * if the setting is %TRUE. This way the entire user interface
8712 * becomes cursor-navigatable on input devices such as mobile phones
8713 * which only have cursor keys but no tab key.
8715 * Whenever the default handler returns %TRUE, it also calls
8716 * gtk_widget_error_bell() to notify the user of the failed keyboard
8719 * A use case for providing an own implementation of ::keynav-failed
8720 * (either by connecting to it or by overriding it) would be a row of
8721 * #GtkEntry widgets where the user should be able to navigate the
8722 * entire row with the cursor keys, as e.g. known from user interfaces
8723 * that require entering license keys.
8725 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8726 * if the emitting widget should try to handle the keyboard
8727 * navigation attempt in its parent container(s).
8732 gtk_widget_keynav_failed (GtkWidget *widget,
8733 GtkDirectionType direction)
8735 gboolean return_val;
8737 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8739 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8740 direction, &return_val);
8746 * gtk_widget_error_bell:
8747 * @widget: a #GtkWidget
8749 * Notifies the user about an input-related error on this widget.
8750 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8751 * gdk_window_beep(), otherwise it does nothing.
8753 * Note that the effect of gdk_window_beep() can be configured in many
8754 * ways, depending on the windowing backend and the desktop environment
8755 * or window manager that is used.
8760 gtk_widget_error_bell (GtkWidget *widget)
8762 GtkWidgetPrivate *priv;
8763 GtkSettings* settings;
8766 g_return_if_fail (GTK_IS_WIDGET (widget));
8768 priv = widget->priv;
8770 settings = gtk_widget_get_settings (widget);
8774 g_object_get (settings,
8775 "gtk-error-bell", &beep,
8778 if (beep && priv->window)
8779 gdk_window_beep (priv->window);
8783 gtk_widget_set_usize_internal (GtkWidget *widget,
8786 GtkQueueResizeFlags flags)
8788 GtkWidgetAuxInfo *aux_info;
8789 gboolean changed = FALSE;
8791 g_object_freeze_notify (G_OBJECT (widget));
8793 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8795 if (width > -2 && aux_info->width != width)
8797 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8798 g_object_notify (G_OBJECT (widget), "width-request");
8799 aux_info->width = width;
8802 if (height > -2 && aux_info->height != height)
8804 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8805 g_object_notify (G_OBJECT (widget), "height-request");
8806 aux_info->height = height;
8810 if (gtk_widget_get_visible (widget) && changed)
8812 if ((flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY) == 0)
8813 gtk_widget_queue_resize (widget);
8815 _gtk_size_group_queue_resize (widget, GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8818 g_object_thaw_notify (G_OBJECT (widget));
8822 * gtk_widget_set_size_request:
8823 * @widget: a #GtkWidget
8824 * @width: width @widget should request, or -1 to unset
8825 * @height: height @widget should request, or -1 to unset
8827 * Sets the minimum size of a widget; that is, the widget's size
8828 * request will be @width by @height. You can use this function to
8829 * force a widget to be either larger or smaller than it normally
8832 * In most cases, gtk_window_set_default_size() is a better choice for
8833 * toplevel windows than this function; setting the default size will
8834 * still allow users to shrink the window. Setting the size request
8835 * will force them to leave the window at least as large as the size
8836 * request. When dealing with window sizes,
8837 * gtk_window_set_geometry_hints() can be a useful function as well.
8839 * Note the inherent danger of setting any fixed size - themes,
8840 * translations into other languages, different fonts, and user action
8841 * can all change the appropriate size for a given widget. So, it's
8842 * basically impossible to hardcode a size that will always be
8845 * The size request of a widget is the smallest size a widget can
8846 * accept while still functioning well and drawing itself correctly.
8847 * However in some strange cases a widget may be allocated less than
8848 * its requested size, and in many cases a widget may be allocated more
8849 * space than it requested.
8851 * If the size request in a given direction is -1 (unset), then
8852 * the "natural" size request of the widget will be used instead.
8854 * Widgets can't actually be allocated a size less than 1 by 1, but
8855 * you can pass 0,0 to this function to mean "as small as possible."
8857 * The size request set here does not include any margin from the
8858 * #GtkWidget properties margin-left, margin-right, margin-top, and
8859 * margin-bottom, but it does include pretty much all other padding
8860 * or border properties set by any subclass of #GtkWidget.
8863 gtk_widget_set_size_request (GtkWidget *widget,
8867 g_return_if_fail (GTK_IS_WIDGET (widget));
8868 g_return_if_fail (width >= -1);
8869 g_return_if_fail (height >= -1);
8876 gtk_widget_set_usize_internal (widget, width, height, 0);
8881 * gtk_widget_get_size_request:
8882 * @widget: a #GtkWidget
8883 * @width: (out) (allow-none): return location for width, or %NULL
8884 * @height: (out) (allow-none): return location for height, or %NULL
8886 * Gets the size request that was explicitly set for the widget using
8887 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8888 * @height indicates that that dimension has not been set explicitly
8889 * and the natural requisition of the widget will be used intead. See
8890 * gtk_widget_set_size_request(). To get the size a widget will
8891 * actually request, call gtk_widget_get_preferred_size() instead of
8895 gtk_widget_get_size_request (GtkWidget *widget,
8899 const GtkWidgetAuxInfo *aux_info;
8901 g_return_if_fail (GTK_IS_WIDGET (widget));
8903 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8906 *width = aux_info->width;
8909 *height = aux_info->height;
8913 * _gtk_widget_override_size_request:
8914 * @widget: a #GtkWidget
8915 * @width: new forced minimum width
8916 * @height: new forced minimum height
8917 * @old_width: location to store previous forced minimum width
8918 * @old_width: location to store previous forced minumum height
8920 * Temporarily establishes a forced minimum size for a widget; this
8921 * is used by GtkWindow when calculating the size to add to the
8922 * window's geometry widget. Cached sizes for the widget and its
8923 * parents are invalidated, so that subsequent calls to the size
8924 * negotiation machinery produce the overriden result, but the
8925 * widget is not queued for relayout or redraw. The old size must
8926 * be restored with _gtk_widget_restore_size_request() or things
8930 _gtk_widget_override_size_request (GtkWidget *widget,
8936 gtk_widget_get_size_request (widget, old_width, old_height);
8937 gtk_widget_set_usize_internal (widget, width, height,
8938 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8942 * _gtk_widget_restore_size_request:
8943 * @widget: a #GtkWidget
8944 * @old_width: saved forced minimum size
8945 * @old_height: saved forced minimum size
8947 * Undoes the operation of_gtk_widget_override_size_request().
8950 _gtk_widget_restore_size_request (GtkWidget *widget,
8954 gtk_widget_set_usize_internal (widget, old_width, old_height,
8955 GTK_QUEUE_RESIZE_INVALIDATE_ONLY);
8959 * gtk_widget_set_events:
8960 * @widget: a #GtkWidget
8961 * @events: event mask
8963 * Sets the event mask (see #GdkEventMask) for a widget. The event
8964 * mask determines which events a widget will receive. Keep in mind
8965 * that different widgets have different default event masks, and by
8966 * changing the event mask you may disrupt a widget's functionality,
8967 * so be careful. This function must be called while a widget is
8968 * unrealized. Consider gtk_widget_add_events() for widgets that are
8969 * already realized, or if you want to preserve the existing event
8970 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8971 * to get events on those widgets, place them inside a #GtkEventBox
8972 * and receive events on the event box.
8975 gtk_widget_set_events (GtkWidget *widget,
8978 g_return_if_fail (GTK_IS_WIDGET (widget));
8979 g_return_if_fail (!gtk_widget_get_realized (widget));
8981 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8982 GINT_TO_POINTER (events));
8983 g_object_notify (G_OBJECT (widget), "events");
8987 * gtk_widget_set_device_events:
8988 * @widget: a #GtkWidget
8989 * @device: a #GdkDevice
8990 * @events: event mask
8992 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8993 * mask determines which events a widget will receive from @device. Keep
8994 * in mind that different widgets have different default event masks, and by
8995 * changing the event mask you may disrupt a widget's functionality,
8996 * so be careful. This function must be called while a widget is
8997 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8998 * already realized, or if you want to preserve the existing event
8999 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
9000 * to get events on those widgets, place them inside a #GtkEventBox
9001 * and receive events on the event box.
9006 gtk_widget_set_device_events (GtkWidget *widget,
9008 GdkEventMask events)
9010 GHashTable *device_events;
9012 g_return_if_fail (GTK_IS_WIDGET (widget));
9013 g_return_if_fail (GDK_IS_DEVICE (device));
9014 g_return_if_fail (!gtk_widget_get_realized (widget));
9016 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9018 if (G_UNLIKELY (!device_events))
9020 device_events = g_hash_table_new (NULL, NULL);
9021 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9022 (GDestroyNotify) g_hash_table_unref);
9025 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
9029 gtk_widget_add_events_internal_list (GtkWidget *widget,
9036 for (l = window_list; l != NULL; l = l->next)
9038 GdkWindow *window = l->data;
9041 gdk_window_get_user_data (window, &user_data);
9042 if (user_data == widget)
9047 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
9049 gdk_window_set_events (window, gdk_window_get_events (window) | events);
9051 children = gdk_window_get_children (window);
9052 gtk_widget_add_events_internal_list (widget, device, events, children);
9053 g_list_free (children);
9059 gtk_widget_add_events_internal (GtkWidget *widget,
9063 GtkWidgetPrivate *priv = widget->priv;
9066 if (!gtk_widget_get_has_window (widget))
9067 window_list = gdk_window_get_children (priv->window);
9069 window_list = g_list_prepend (NULL, priv->window);
9071 gtk_widget_add_events_internal_list (widget, device, events, window_list);
9073 g_list_free (window_list);
9077 * gtk_widget_add_events:
9078 * @widget: a #GtkWidget
9079 * @events: an event mask, see #GdkEventMask
9081 * Adds the events in the bitfield @events to the event mask for
9082 * @widget. See gtk_widget_set_events() for details.
9085 gtk_widget_add_events (GtkWidget *widget,
9090 g_return_if_fail (GTK_IS_WIDGET (widget));
9092 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9093 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
9094 GINT_TO_POINTER (old_events | events));
9096 if (gtk_widget_get_realized (widget))
9097 gtk_widget_add_events_internal (widget, NULL, events);
9099 g_object_notify (G_OBJECT (widget), "events");
9103 * gtk_widget_add_device_events:
9104 * @widget: a #GtkWidget
9105 * @device: a #GdkDevice
9106 * @events: an event mask, see #GdkEventMask
9108 * Adds the device events in the bitfield @events to the event mask for
9109 * @widget. See gtk_widget_set_device_events() for details.
9114 gtk_widget_add_device_events (GtkWidget *widget,
9116 GdkEventMask events)
9118 GdkEventMask old_events;
9119 GHashTable *device_events;
9121 g_return_if_fail (GTK_IS_WIDGET (widget));
9122 g_return_if_fail (GDK_IS_DEVICE (device));
9124 old_events = gtk_widget_get_device_events (widget, device);
9126 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9128 if (G_UNLIKELY (!device_events))
9130 device_events = g_hash_table_new (NULL, NULL);
9131 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
9132 (GDestroyNotify) g_hash_table_unref);
9135 g_hash_table_insert (device_events, device,
9136 GUINT_TO_POINTER (old_events | events));
9138 if (gtk_widget_get_realized (widget))
9139 gtk_widget_add_events_internal (widget, device, events);
9141 g_object_notify (G_OBJECT (widget), "events");
9145 * gtk_widget_set_extension_events:
9146 * @widget: a #GtkWidget
9147 * @mode: bitfield of extension events to receive
9149 * Sets the extension events mask to @mode. See #GdkExtensionMode
9150 * and gdk_input_set_extension_events().
9153 gtk_widget_set_extension_events (GtkWidget *widget,
9154 GdkExtensionMode mode)
9156 g_return_if_fail (GTK_IS_WIDGET (widget));
9158 if (gtk_widget_get_realized (widget))
9159 gtk_widget_set_extension_events_internal (widget, mode, NULL);
9161 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
9162 GINT_TO_POINTER (mode));
9163 g_object_notify (G_OBJECT (widget), "extension-events");
9167 * gtk_widget_get_toplevel:
9168 * @widget: a #GtkWidget
9170 * This function returns the topmost widget in the container hierarchy
9171 * @widget is a part of. If @widget has no parent widgets, it will be
9172 * returned as the topmost widget. No reference will be added to the
9173 * returned widget; it should not be unreferenced.
9175 * Note the difference in behavior vs. gtk_widget_get_ancestor();
9176 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
9178 * %NULL if @widget wasn't inside a toplevel window, and if the
9179 * window was inside a #GtkWindow-derived widget which was in turn
9180 * inside the toplevel #GtkWindow. While the second case may
9181 * seem unlikely, it actually happens when a #GtkPlug is embedded
9182 * inside a #GtkSocket within the same application.
9184 * To reliably find the toplevel #GtkWindow, use
9185 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
9186 * is set on the result.
9188 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
9189 * if (gtk_widget_is_toplevel (toplevel))
9191 * /* Perform action on toplevel. */
9195 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9196 * if there's no ancestor.
9199 gtk_widget_get_toplevel (GtkWidget *widget)
9201 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9203 while (widget->priv->parent)
9204 widget = widget->priv->parent;
9210 * gtk_widget_get_ancestor:
9211 * @widget: a #GtkWidget
9212 * @widget_type: ancestor type
9214 * Gets the first ancestor of @widget with type @widget_type. For example,
9215 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9216 * the first #GtkBox that's an ancestor of @widget. No reference will be
9217 * added to the returned widget; it should not be unreferenced. See note
9218 * about checking for a toplevel #GtkWindow in the docs for
9219 * gtk_widget_get_toplevel().
9221 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9222 * considers @widget to be an ancestor of itself.
9224 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9227 gtk_widget_get_ancestor (GtkWidget *widget,
9230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9232 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9233 widget = widget->priv->parent;
9235 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9242 * gtk_widget_set_visual:
9243 * @widget: a #GtkWidget
9244 * @visual: visual to be used or %NULL to unset a previous one
9246 * Sets the visual that should be used for by widget and its children for
9247 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9248 * returned by gdk_widget_get_screen(), so handling the
9249 * GtkWidget::screen-changed signal is necessary.
9251 * Setting a new @visual will not cause @widget to recreate its windows,
9252 * so you should call this function before @widget is realized.
9255 gtk_widget_set_visual (GtkWidget *widget,
9258 g_return_if_fail (GTK_IS_WIDGET (widget));
9259 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9262 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9265 g_object_set_qdata_full (G_OBJECT (widget),
9267 g_object_ref (visual),
9272 * gtk_widget_get_visual:
9273 * @widget: a #GtkWidget
9275 * Gets the visual that will be used to render @widget.
9277 * Return value: (transfer none): the visual for @widget
9280 gtk_widget_get_visual (GtkWidget *widget)
9286 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9288 if (gtk_widget_get_has_window (widget) &&
9289 widget->priv->window)
9290 return gdk_window_get_visual (widget->priv->window);
9292 screen = gtk_widget_get_screen (widget);
9294 for (w = widget; w != NULL; w = w->priv->parent)
9296 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9299 if (gdk_visual_get_screen (visual) == screen)
9302 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9303 gtk_widget_get_name (widget));
9307 return gdk_screen_get_system_visual (screen);
9311 * gtk_widget_get_settings:
9312 * @widget: a #GtkWidget
9314 * Gets the settings object holding the settings (global property
9315 * settings, RC file information, etc) used for this widget.
9317 * Note that this function can only be called when the #GtkWidget
9318 * is attached to a toplevel, since the settings object is specific
9319 * to a particular #GdkScreen.
9321 * Return value: (transfer none): the relevant #GtkSettings object
9324 gtk_widget_get_settings (GtkWidget *widget)
9326 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9328 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9332 * gtk_widget_get_events:
9333 * @widget: a #GtkWidget
9335 * Returns the event mask for the widget (a bitfield containing flags
9336 * from the #GdkEventMask enumeration). These are the events that the widget
9339 * Return value: event mask for @widget
9342 gtk_widget_get_events (GtkWidget *widget)
9344 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9346 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9350 * gtk_widget_get_device_events:
9351 * @widget: a #GtkWidget
9352 * @device: a #GdkDevice
9354 * Returns the events mask for the widget corresponding to an specific device. These
9355 * are the events that the widget will receive when @device operates on it.
9357 * Returns: device event mask for @widget
9362 gtk_widget_get_device_events (GtkWidget *widget,
9365 GHashTable *device_events;
9367 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9368 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9370 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9375 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9379 * gtk_widget_get_extension_events:
9380 * @widget: a #GtkWidget
9382 * Retrieves the extension events the widget will receive; see
9383 * gdk_input_set_extension_events().
9385 * Return value: extension events for @widget
9388 gtk_widget_get_extension_events (GtkWidget *widget)
9390 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9392 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9396 * gtk_widget_get_pointer:
9397 * @widget: a #GtkWidget
9398 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9399 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9401 * Obtains the location of the mouse pointer in widget coordinates.
9402 * Widget coordinates are a bit odd; for historical reasons, they are
9403 * defined as @widget->window coordinates for widgets that are not
9404 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9405 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9408 gtk_widget_get_pointer (GtkWidget *widget,
9412 GtkWidgetPrivate *priv;
9414 g_return_if_fail (GTK_IS_WIDGET (widget));
9416 priv = widget->priv;
9423 if (gtk_widget_get_realized (widget))
9425 gdk_window_get_pointer (priv->window, x, y, NULL);
9427 if (!gtk_widget_get_has_window (widget))
9430 *x -= priv->allocation.x;
9432 *y -= priv->allocation.y;
9438 * gtk_widget_is_ancestor:
9439 * @widget: a #GtkWidget
9440 * @ancestor: another #GtkWidget
9442 * Determines whether @widget is somewhere inside @ancestor, possibly with
9443 * intermediate containers.
9445 * Return value: %TRUE if @ancestor contains @widget as a child,
9446 * grandchild, great grandchild, etc.
9449 gtk_widget_is_ancestor (GtkWidget *widget,
9450 GtkWidget *ancestor)
9452 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9453 g_return_val_if_fail (ancestor != NULL, FALSE);
9457 if (widget->priv->parent == ancestor)
9459 widget = widget->priv->parent;
9465 static GQuark quark_composite_name = 0;
9468 * gtk_widget_set_composite_name:
9469 * @widget: a #GtkWidget.
9470 * @name: the name to set
9472 * Sets a widgets composite name. The widget must be
9473 * a composite child of its parent; see gtk_widget_push_composite_child().
9476 gtk_widget_set_composite_name (GtkWidget *widget,
9479 g_return_if_fail (GTK_IS_WIDGET (widget));
9480 g_return_if_fail (widget->priv->composite_child);
9481 g_return_if_fail (name != NULL);
9483 if (!quark_composite_name)
9484 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9486 g_object_set_qdata_full (G_OBJECT (widget),
9487 quark_composite_name,
9493 * gtk_widget_get_composite_name:
9494 * @widget: a #GtkWidget
9496 * Obtains the composite name of a widget.
9498 * Returns: the composite name of @widget, or %NULL if @widget is not
9499 * a composite child. The string should be freed when it is no
9503 gtk_widget_get_composite_name (GtkWidget *widget)
9505 GtkWidgetPrivate *priv;
9507 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9509 priv = widget->priv;
9511 if (widget->priv->composite_child && priv->parent)
9512 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9519 * gtk_widget_push_composite_child:
9521 * Makes all newly-created widgets as composite children until
9522 * the corresponding gtk_widget_pop_composite_child() call.
9524 * A composite child is a child that's an implementation detail of the
9525 * container it's inside and should not be visible to people using the
9526 * container. Composite children aren't treated differently by GTK (but
9527 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9528 * builders might want to treat them in a different way.
9530 * Here is a simple example:
9532 * gtk_widget_push_composite_child ();
9533 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9534 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9535 * gtk_widget_pop_composite_child ();
9536 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9537 * GTK_WIDGET (scrolled_window));
9538 * g_object_ref (scrolled_window->hscrollbar);
9542 gtk_widget_push_composite_child (void)
9544 composite_child_stack++;
9548 * gtk_widget_pop_composite_child:
9550 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9553 gtk_widget_pop_composite_child (void)
9555 if (composite_child_stack)
9556 composite_child_stack--;
9560 gtk_widget_emit_direction_changed (GtkWidget *widget,
9561 GtkTextDirection old_dir)
9563 gtk_widget_update_pango_context (widget);
9565 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9569 * gtk_widget_set_direction:
9570 * @widget: a #GtkWidget
9571 * @dir: the new direction
9573 * Sets the reading direction on a particular widget. This direction
9574 * controls the primary direction for widgets containing text,
9575 * and also the direction in which the children of a container are
9576 * packed. The ability to set the direction is present in order
9577 * so that correct localization into languages with right-to-left
9578 * reading directions can be done. Generally, applications will
9579 * let the default reading direction present, except for containers
9580 * where the containers are arranged in an order that is explicitely
9581 * visual rather than logical (such as buttons for text justification).
9583 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9584 * set by gtk_widget_set_default_direction() will be used.
9587 gtk_widget_set_direction (GtkWidget *widget,
9588 GtkTextDirection dir)
9590 GtkTextDirection old_dir;
9592 g_return_if_fail (GTK_IS_WIDGET (widget));
9593 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9595 old_dir = gtk_widget_get_direction (widget);
9597 widget->priv->direction = dir;
9599 if (old_dir != gtk_widget_get_direction (widget))
9600 gtk_widget_emit_direction_changed (widget, old_dir);
9604 * gtk_widget_get_direction:
9605 * @widget: a #GtkWidget
9607 * Gets the reading direction for a particular widget. See
9608 * gtk_widget_set_direction().
9610 * Return value: the reading direction for the widget.
9613 gtk_widget_get_direction (GtkWidget *widget)
9615 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9617 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9618 return gtk_default_direction;
9620 return widget->priv->direction;
9624 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9626 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9628 g_object_ref (widget);
9630 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9631 gtk_widget_emit_direction_changed (widget, old_dir);
9633 if (GTK_IS_CONTAINER (widget))
9634 gtk_container_forall (GTK_CONTAINER (widget),
9635 gtk_widget_set_default_direction_recurse,
9638 g_object_unref (widget);
9642 * gtk_widget_set_default_direction:
9643 * @dir: the new default direction. This cannot be
9644 * %GTK_TEXT_DIR_NONE.
9646 * Sets the default reading direction for widgets where the
9647 * direction has not been explicitly set by gtk_widget_set_direction().
9650 gtk_widget_set_default_direction (GtkTextDirection dir)
9652 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9654 if (dir != gtk_default_direction)
9656 GList *toplevels, *tmp_list;
9657 GtkTextDirection old_dir = gtk_default_direction;
9659 gtk_default_direction = dir;
9661 tmp_list = toplevels = gtk_window_list_toplevels ();
9662 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9666 gtk_widget_set_default_direction_recurse (tmp_list->data,
9667 GUINT_TO_POINTER (old_dir));
9668 g_object_unref (tmp_list->data);
9669 tmp_list = tmp_list->next;
9672 g_list_free (toplevels);
9677 * gtk_widget_get_default_direction:
9679 * Obtains the current default reading direction. See
9680 * gtk_widget_set_default_direction().
9682 * Return value: the current default direction.
9685 gtk_widget_get_default_direction (void)
9687 return gtk_default_direction;
9691 gtk_widget_dispose (GObject *object)
9693 GtkWidget *widget = GTK_WIDGET (object);
9694 GtkWidgetPrivate *priv = widget->priv;
9697 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9698 else if (gtk_widget_get_visible (widget))
9699 gtk_widget_hide (widget);
9701 priv->visible = FALSE;
9702 if (gtk_widget_get_realized (widget))
9703 gtk_widget_unrealize (widget);
9705 if (!priv->in_destruction)
9707 priv->in_destruction = TRUE;
9708 g_signal_emit (object, widget_signals[DESTROY], 0);
9709 priv->in_destruction = FALSE;
9712 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9716 gtk_widget_real_destroy (GtkWidget *object)
9718 /* gtk_object_destroy() will already hold a refcount on object */
9719 GtkWidget *widget = GTK_WIDGET (object);
9720 GtkWidgetPrivate *priv = widget->priv;
9722 /* wipe accelerator closures (keep order) */
9723 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9724 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9726 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9727 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9729 gtk_grab_remove (widget);
9731 g_object_unref (priv->style);
9732 priv->style = gtk_widget_get_default_style ();
9733 g_object_ref (priv->style);
9737 gtk_widget_finalize (GObject *object)
9739 GtkWidget *widget = GTK_WIDGET (object);
9740 GtkWidgetPrivate *priv = widget->priv;
9741 GtkWidgetAuxInfo *aux_info;
9742 GtkAccessible *accessible;
9744 gtk_grab_remove (widget);
9746 g_object_unref (priv->style);
9749 g_free (priv->name);
9751 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9753 gtk_widget_aux_info_destroy (aux_info);
9755 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9757 g_object_unref (accessible);
9759 if (g_object_is_floating (object))
9760 g_warning ("A floating object was finalized. This means that someone\n"
9761 "called g_object_unref() on an object that had only a floating\n"
9762 "reference; the initial floating reference is not owned by anyone\n"
9763 "and must be removed with g_object_ref_sink().");
9765 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9768 /*****************************************
9769 * gtk_widget_real_map:
9774 *****************************************/
9777 gtk_widget_real_map (GtkWidget *widget)
9779 GtkWidgetPrivate *priv = widget->priv;
9781 g_assert (gtk_widget_get_realized (widget));
9783 if (!gtk_widget_get_mapped (widget))
9785 gtk_widget_set_mapped (widget, TRUE);
9787 if (gtk_widget_get_has_window (widget))
9788 gdk_window_show (priv->window);
9792 /*****************************************
9793 * gtk_widget_real_unmap:
9798 *****************************************/
9801 gtk_widget_real_unmap (GtkWidget *widget)
9803 GtkWidgetPrivate *priv = widget->priv;
9805 if (gtk_widget_get_mapped (widget))
9807 gtk_widget_set_mapped (widget, FALSE);
9809 if (gtk_widget_get_has_window (widget))
9810 gdk_window_hide (priv->window);
9814 /*****************************************
9815 * gtk_widget_real_realize:
9820 *****************************************/
9823 gtk_widget_real_realize (GtkWidget *widget)
9825 GtkWidgetPrivate *priv = widget->priv;
9827 g_assert (!gtk_widget_get_has_window (widget));
9829 gtk_widget_set_realized (widget, TRUE);
9832 priv->window = gtk_widget_get_parent_window (widget);
9833 g_object_ref (priv->window);
9835 priv->style = gtk_style_attach (priv->style, priv->window);
9838 /*****************************************
9839 * gtk_widget_real_unrealize:
9844 *****************************************/
9847 gtk_widget_real_unrealize (GtkWidget *widget)
9849 GtkWidgetPrivate *priv = widget->priv;
9851 if (gtk_widget_get_mapped (widget))
9852 gtk_widget_real_unmap (widget);
9854 gtk_widget_set_mapped (widget, FALSE);
9856 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9859 /* We must do unrealize child widget BEFORE container widget.
9860 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9861 * So, unrealizing container widget bofore its children causes the problem
9862 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9865 if (GTK_IS_CONTAINER (widget))
9866 gtk_container_forall (GTK_CONTAINER (widget),
9867 (GtkCallback) gtk_widget_unrealize,
9870 gtk_style_detach (priv->style);
9871 if (gtk_widget_get_has_window (widget))
9873 gdk_window_set_user_data (priv->window, NULL);
9874 gdk_window_destroy (priv->window);
9875 priv->window = NULL;
9879 g_object_unref (priv->window);
9880 priv->window = NULL;
9883 gtk_selection_remove_all (widget);
9885 gtk_widget_set_realized (widget, FALSE);
9889 gtk_widget_real_size_request (GtkWidget *widget,
9890 GtkRequisition *requisition)
9892 requisition->width = 0;
9893 requisition->height = 0;
9897 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9898 GtkOrientation orientation,
9903 const GtkWidgetAuxInfo *aux_info;
9905 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9907 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9908 aux_info->width > 0)
9910 *minimum_size = MAX (*minimum_size, aux_info->width);
9912 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9913 aux_info->height > 0)
9915 *minimum_size = MAX (*minimum_size, aux_info->height);
9918 /* Fix it if set_size_request made natural size smaller than min size.
9919 * This would also silently fix broken widgets, but we warn about them
9920 * in gtksizerequest.c when calling their size request vfuncs.
9922 *natural_size = MAX (*natural_size, *minimum_size);
9924 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9926 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9927 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9931 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9932 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9937 * _gtk_widget_peek_request_cache:
9939 * Returns the address of the widget's request cache (strictly for
9940 * internal use in gtksizerequest.c)
9942 * Return value: the address of @widget's size request cache.
9945 _gtk_widget_peek_request_cache (GtkWidget *widget)
9947 /* Don't bother slowing things down with the return_if_fail guards here */
9948 return &widget->priv->requests;
9952 * _gtk_widget_set_device_window:
9953 * @widget: a #GtkWidget.
9954 * @device: a #GdkDevice.
9955 * @window: the new device window.
9957 * Sets pointer window for @widget and @device. Does not ref @window.
9958 * Actually stores it on the #GdkScreen, but you don't need to know that.
9961 _gtk_widget_set_device_window (GtkWidget *widget,
9965 GtkWidgetPrivate *priv;
9967 GHashTable *device_window;
9969 g_return_if_fail (GTK_IS_WIDGET (widget));
9970 g_return_if_fail (GDK_IS_DEVICE (device));
9971 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9973 priv = widget->priv;
9975 if (!gtk_widget_get_realized (widget))
9978 screen = gdk_window_get_screen (priv->window);
9979 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9981 if (G_UNLIKELY (!device_window))
9983 device_window = g_hash_table_new (NULL, NULL);
9984 g_object_set_qdata_full (G_OBJECT (screen),
9985 quark_pointer_window,
9987 (GDestroyNotify) g_hash_table_destroy);
9991 g_hash_table_insert (device_window, device, window);
9993 g_hash_table_remove (device_window, device);
9997 * _gtk_widget_get_device_window:
9998 * @widget: a #GtkWidget.
9999 * @device: a #GdkDevice.
10001 * Return value: the device window set on the #GdkScreen @widget is attached
10005 _gtk_widget_get_device_window (GtkWidget *widget,
10008 GtkWidgetPrivate *priv;
10010 GHashTable *device_window;
10014 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10015 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
10017 priv = widget->priv;
10019 if (!gtk_widget_get_realized (widget))
10022 screen = gdk_window_get_screen (priv->window);
10023 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10025 if (G_UNLIKELY (!device_window))
10028 window = g_hash_table_lookup (device_window, device);
10033 gdk_window_get_user_data (window, (gpointer *) &w);
10042 * _gtk_widget_list_devices:
10043 * @widget: a #GtkWidget.
10045 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
10046 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
10050 _gtk_widget_list_devices (GtkWidget *widget)
10052 GtkWidgetPrivate *priv;
10054 GHashTableIter iter;
10055 GHashTable *device_window;
10056 GList *devices = NULL;
10057 gpointer key, value;
10059 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10061 priv = widget->priv;
10063 if (!gtk_widget_get_realized (widget))
10066 screen = gdk_window_get_screen (priv->window);
10067 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
10069 if (G_UNLIKELY (!device_window))
10072 g_hash_table_iter_init (&iter, device_window);
10074 while (g_hash_table_iter_next (&iter, &key, &value))
10076 GdkDevice *device = key;
10077 GdkWindow *window = value;
10082 gdk_window_get_user_data (window, (gpointer *) &w);
10085 devices = g_list_prepend (devices, device);
10093 synth_crossing (GtkWidget *widget,
10097 GdkCrossingMode mode,
10098 GdkNotifyType detail)
10102 event = gdk_event_new (type);
10104 event->crossing.window = g_object_ref (window);
10105 event->crossing.send_event = TRUE;
10106 event->crossing.subwindow = g_object_ref (window);
10107 event->crossing.time = GDK_CURRENT_TIME;
10108 event->crossing.x = event->crossing.y = 0;
10109 event->crossing.x_root = event->crossing.y_root = 0;
10110 event->crossing.mode = mode;
10111 event->crossing.detail = detail;
10112 event->crossing.focus = FALSE;
10113 event->crossing.state = 0;
10114 gdk_event_set_device (event, device);
10117 widget = gtk_get_event_widget (event);
10120 gtk_widget_event_internal (widget, event);
10122 gdk_event_free (event);
10126 * _gtk_widget_synthesize_crossing:
10127 * @from: the #GtkWidget the virtual pointer is leaving.
10128 * @to: the #GtkWidget the virtual pointer is moving to.
10129 * @mode: the #GdkCrossingMode to place on the synthesized events.
10131 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
10133 * The real pointer window is the window that most recently received an enter notify
10134 * event. Windows that don't select for crossing events can't become the real
10135 * poiner window. The real pointer widget that owns the real pointer window. The
10136 * effective pointer window is the same as the real pointer window unless the real
10137 * pointer widget is either insensitive or there is a grab on a widget that is not
10138 * an ancestor of the real pointer widget (in which case the effective pointer
10139 * window should be the root window).
10141 * When the effective pointer window is the same as the real poiner window, we
10142 * receive crossing events from the windowing system. When the effective pointer
10143 * window changes to become different from the real pointer window we synthesize
10144 * crossing events, attempting to follow X protocol rules:
10146 * When the root window becomes the effective pointer window:
10147 * - leave notify on real pointer window, detail Ancestor
10148 * - leave notify on all of its ancestors, detail Virtual
10149 * - enter notify on root window, detail Inferior
10151 * When the root window ceases to be the effective pointer window:
10152 * - leave notify on root window, detail Inferior
10153 * - enter notify on all ancestors of real pointer window, detail Virtual
10154 * - enter notify on real pointer window, detail Ancestor
10157 _gtk_widget_synthesize_crossing (GtkWidget *from,
10160 GdkCrossingMode mode)
10162 GdkWindow *from_window = NULL, *to_window = NULL;
10164 g_return_if_fail (from != NULL || to != NULL);
10168 from_window = _gtk_widget_get_device_window (from, device);
10171 from_window = from->priv->window;
10176 to_window = _gtk_widget_get_device_window (to, device);
10179 to_window = to->priv->window;
10182 if (from_window == NULL && to_window == NULL)
10184 else if (from_window != NULL && to_window == NULL)
10186 GList *from_ancestors = NULL, *list;
10187 GdkWindow *from_ancestor = from_window;
10189 while (from_ancestor != NULL)
10191 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10192 if (from_ancestor == NULL)
10194 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10197 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10198 device, mode, GDK_NOTIFY_ANCESTOR);
10199 for (list = g_list_last (from_ancestors); list; list = list->prev)
10201 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10202 device, mode, GDK_NOTIFY_VIRTUAL);
10205 /* XXX: enter/inferior on root window? */
10207 g_list_free (from_ancestors);
10209 else if (from_window == NULL && to_window != NULL)
10211 GList *to_ancestors = NULL, *list;
10212 GdkWindow *to_ancestor = to_window;
10214 while (to_ancestor != NULL)
10216 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10217 if (to_ancestor == NULL)
10219 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10222 /* XXX: leave/inferior on root window? */
10224 for (list = to_ancestors; list; list = list->next)
10226 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10227 device, mode, GDK_NOTIFY_VIRTUAL);
10229 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10230 device, mode, GDK_NOTIFY_ANCESTOR);
10232 g_list_free (to_ancestors);
10234 else if (from_window == to_window)
10238 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10239 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10241 while (from_ancestor != NULL || to_ancestor != NULL)
10243 if (from_ancestor != NULL)
10245 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10246 if (from_ancestor == to_window)
10249 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10251 if (to_ancestor != NULL)
10253 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10254 if (to_ancestor == from_window)
10257 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10260 if (to_ancestor == from_window)
10262 if (mode != GDK_CROSSING_GTK_UNGRAB)
10263 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10264 device, mode, GDK_NOTIFY_INFERIOR);
10265 for (list = to_ancestors; list; list = list->next)
10266 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10267 device, mode, GDK_NOTIFY_VIRTUAL);
10268 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10269 device, mode, GDK_NOTIFY_ANCESTOR);
10271 else if (from_ancestor == to_window)
10273 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10274 device, mode, GDK_NOTIFY_ANCESTOR);
10275 for (list = g_list_last (from_ancestors); list; list = list->prev)
10277 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10278 device, mode, GDK_NOTIFY_VIRTUAL);
10280 if (mode != GDK_CROSSING_GTK_GRAB)
10281 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10282 device, mode, GDK_NOTIFY_INFERIOR);
10286 while (from_ancestors != NULL && to_ancestors != NULL
10287 && from_ancestors->data == to_ancestors->data)
10289 from_ancestors = g_list_delete_link (from_ancestors,
10291 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10294 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10295 device, mode, GDK_NOTIFY_NONLINEAR);
10297 for (list = g_list_last (from_ancestors); list; list = list->prev)
10299 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10300 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10302 for (list = to_ancestors; list; list = list->next)
10304 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10305 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10307 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10308 device, mode, GDK_NOTIFY_NONLINEAR);
10310 g_list_free (from_ancestors);
10311 g_list_free (to_ancestors);
10316 gtk_widget_propagate_state (GtkWidget *widget,
10317 GtkStateData *data)
10319 GtkWidgetPrivate *priv = widget->priv;
10320 guint8 old_state = gtk_widget_get_state (widget);
10321 guint8 old_saved_state = priv->saved_state;
10323 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10324 * parent_sensitive==TRUE on a sensitive widget
10328 priv->parent_sensitive = data->parent_sensitive;
10330 if (gtk_widget_is_sensitive (widget))
10332 if (data->state_restoration)
10333 priv->state = priv->saved_state;
10335 priv->state = data->state;
10339 if (!data->state_restoration)
10341 if (data->state != GTK_STATE_INSENSITIVE)
10342 priv->saved_state = data->state;
10344 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10345 priv->saved_state = gtk_widget_get_state (widget);
10346 priv->state = GTK_STATE_INSENSITIVE;
10349 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10353 window = gtk_widget_get_toplevel (widget);
10354 if (window && gtk_widget_is_toplevel (window))
10355 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10358 if (old_state != gtk_widget_get_state (widget) ||
10359 old_saved_state != priv->saved_state)
10361 g_object_ref (widget);
10363 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10364 gtk_grab_remove (widget);
10366 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10368 if (!priv->shadowed)
10370 GList *event_windows = NULL;
10371 GList *devices, *d;
10373 devices = _gtk_widget_list_devices (widget);
10375 for (d = devices; d; d = d->next)
10381 window = _gtk_widget_get_device_window (widget, device);
10383 /* Do not propagate more than once to the
10384 * same window if non-multidevice aware.
10386 if (!gdk_window_get_support_multidevice (window) &&
10387 g_list_find (event_windows, window))
10390 if (!gtk_widget_is_sensitive (widget))
10391 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10392 GDK_CROSSING_STATE_CHANGED);
10393 else if (old_state == GTK_STATE_INSENSITIVE)
10394 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10395 GDK_CROSSING_STATE_CHANGED);
10397 event_windows = g_list_prepend (event_windows, window);
10400 g_list_free (event_windows);
10401 g_list_free (devices);
10404 if (GTK_IS_CONTAINER (widget))
10406 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10407 if (data->use_forall)
10408 gtk_container_forall (GTK_CONTAINER (widget),
10409 (GtkCallback) gtk_widget_propagate_state,
10412 gtk_container_foreach (GTK_CONTAINER (widget),
10413 (GtkCallback) gtk_widget_propagate_state,
10416 g_object_unref (widget);
10420 static const GtkWidgetAuxInfo default_aux_info = {
10428 * _gtk_widget_get_aux_info:
10429 * @widget: a #GtkWidget
10430 * @create: if %TRUE, create the structure if it doesn't exist
10432 * Get the #GtkWidgetAuxInfo structure for the widget.
10434 * Return value: the #GtkAuxInfo structure for the widget, or
10435 * %NULL if @create is %FALSE and one doesn't already exist.
10438 _gtk_widget_get_aux_info (GtkWidget *widget,
10441 GtkWidgetAuxInfo *aux_info;
10443 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10444 if (!aux_info && create)
10446 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10448 *aux_info = default_aux_info;
10450 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10456 static const GtkWidgetAuxInfo*
10457 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10459 GtkWidgetAuxInfo *aux_info;
10461 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10462 if (aux_info == NULL)
10464 return &default_aux_info;
10472 /*****************************************
10473 * gtk_widget_aux_info_destroy:
10478 *****************************************/
10481 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10483 g_slice_free (GtkWidgetAuxInfo, aux_info);
10487 * gtk_widget_shape_combine_region:
10488 * @widget: a #GtkWidget
10489 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10491 * Sets a shape for this widget's GDK window. This allows for
10492 * transparent windows etc., see gdk_window_shape_combine_region()
10493 * for more information.
10498 gtk_widget_shape_combine_region (GtkWidget *widget,
10499 cairo_region_t *region)
10501 GtkWidgetPrivate *priv;
10503 g_return_if_fail (GTK_IS_WIDGET (widget));
10504 /* set_shape doesn't work on widgets without gdk window */
10505 g_return_if_fail (gtk_widget_get_has_window (widget));
10507 priv = widget->priv;
10509 if (region == NULL)
10511 priv->has_shape_mask = FALSE;
10514 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10516 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10520 priv->has_shape_mask = TRUE;
10522 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10523 cairo_region_copy (region),
10524 (GDestroyNotify) cairo_region_destroy);
10526 /* set shape if widget has a gdk window already.
10527 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10530 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10535 * gtk_widget_input_shape_combine_region:
10536 * @widget: a #GtkWidget
10537 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10539 * Sets an input shape for this widget's GDK window. This allows for
10540 * windows which react to mouse click in a nonrectangular region, see
10541 * gdk_window_input_shape_combine_region() for more information.
10546 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10547 cairo_region_t *region)
10549 GtkWidgetPrivate *priv;
10551 g_return_if_fail (GTK_IS_WIDGET (widget));
10552 /* set_shape doesn't work on widgets without gdk window */
10553 g_return_if_fail (gtk_widget_get_has_window (widget));
10555 priv = widget->priv;
10557 if (region == NULL)
10560 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10562 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10566 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10567 cairo_region_copy (region),
10568 (GDestroyNotify) cairo_region_destroy);
10570 /* set shape if widget has a gdk window already.
10571 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10574 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10580 gtk_reset_shapes_recurse (GtkWidget *widget,
10586 gdk_window_get_user_data (window, &data);
10587 if (data != widget)
10590 gdk_window_shape_combine_region (window, NULL, 0, 0);
10591 for (list = gdk_window_peek_children (window); list; list = list->next)
10592 gtk_reset_shapes_recurse (widget, list->data);
10596 * gtk_widget_reset_shapes:
10597 * @widget: a #GtkWidget
10599 * Recursively resets the shape on this widget and its descendants.
10602 gtk_widget_reset_shapes (GtkWidget *widget)
10604 GtkWidgetPrivate *priv;
10606 g_return_if_fail (GTK_IS_WIDGET (widget));
10607 g_return_if_fail (gtk_widget_get_realized (widget));
10609 priv = widget->priv;
10611 if (!priv->has_shape_mask)
10612 gtk_reset_shapes_recurse (widget, priv->window);
10615 /* style properties
10619 * gtk_widget_class_install_style_property_parser:
10620 * @klass: a #GtkWidgetClass
10621 * @pspec: the #GParamSpec for the style property
10622 * @parser: the parser for the style property
10624 * Installs a style property on a widget class.
10627 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10629 GtkRcPropertyParser parser)
10631 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10632 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10633 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10634 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10636 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10638 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10639 G_OBJECT_CLASS_NAME (klass),
10644 g_param_spec_ref_sink (pspec);
10645 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10646 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10650 * gtk_widget_class_install_style_property:
10651 * @klass: a #GtkWidgetClass
10652 * @pspec: the #GParamSpec for the property
10654 * Installs a style property on a widget class. The parser for the
10655 * style property is determined by the value type of @pspec.
10658 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10661 GtkRcPropertyParser parser;
10663 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10664 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10666 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10668 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10672 * gtk_widget_class_find_style_property:
10673 * @klass: a #GtkWidgetClass
10674 * @property_name: the name of the style property to find
10675 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10676 * style property with that name.
10678 * Finds a style property of a widget class by name.
10683 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10684 const gchar *property_name)
10686 g_return_val_if_fail (property_name != NULL, NULL);
10688 return g_param_spec_pool_lookup (style_property_spec_pool,
10690 G_OBJECT_CLASS_TYPE (klass),
10695 * gtk_widget_class_list_style_properties:
10696 * @klass: a #GtkWidgetClass
10697 * @n_properties: location to return the number of style properties found
10698 * @returns: an newly allocated array of #GParamSpec*. The array must
10699 * be freed with g_free().
10701 * Returns all style properties of a widget class.
10706 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10707 guint *n_properties)
10709 GParamSpec **pspecs;
10712 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10713 G_OBJECT_CLASS_TYPE (klass),
10722 * gtk_widget_style_get_property:
10723 * @widget: a #GtkWidget
10724 * @property_name: the name of a style property
10725 * @value: location to return the property value
10727 * Gets the value of a style property of @widget.
10730 gtk_widget_style_get_property (GtkWidget *widget,
10731 const gchar *property_name,
10734 GtkWidgetPrivate *priv;
10737 g_return_if_fail (GTK_IS_WIDGET (widget));
10738 g_return_if_fail (property_name != NULL);
10739 g_return_if_fail (G_IS_VALUE (value));
10741 priv = widget->priv;
10743 g_object_ref (widget);
10744 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10746 G_OBJECT_TYPE (widget),
10749 g_warning ("%s: widget class `%s' has no property named `%s'",
10751 G_OBJECT_TYPE_NAME (widget),
10755 const GValue *peek_value;
10757 peek_value = _gtk_style_peek_property_value (priv->style,
10758 G_OBJECT_TYPE (widget),
10760 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10762 /* auto-conversion of the caller's value type
10764 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10765 g_value_copy (peek_value, value);
10766 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10767 g_value_transform (peek_value, value);
10769 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10771 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10772 G_VALUE_TYPE_NAME (value));
10774 g_object_unref (widget);
10778 * gtk_widget_style_get_valist:
10779 * @widget: a #GtkWidget
10780 * @first_property_name: the name of the first property to get
10781 * @var_args: a <type>va_list</type> of pairs of property names and
10782 * locations to return the property values, starting with the location
10783 * for @first_property_name.
10785 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10789 gtk_widget_style_get_valist (GtkWidget *widget,
10790 const gchar *first_property_name,
10793 GtkWidgetPrivate *priv;
10796 g_return_if_fail (GTK_IS_WIDGET (widget));
10798 priv = widget->priv;
10800 g_object_ref (widget);
10802 name = first_property_name;
10805 const GValue *peek_value;
10809 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10811 G_OBJECT_TYPE (widget),
10815 g_warning ("%s: widget class `%s' has no property named `%s'",
10817 G_OBJECT_TYPE_NAME (widget),
10821 /* style pspecs are always readable so we can spare that check here */
10823 peek_value = _gtk_style_peek_property_value (priv->style,
10824 G_OBJECT_TYPE (widget),
10826 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10827 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10830 g_warning ("%s: %s", G_STRLOC, error);
10835 name = va_arg (var_args, gchar*);
10838 g_object_unref (widget);
10842 * gtk_widget_style_get:
10843 * @widget: a #GtkWidget
10844 * @first_property_name: the name of the first property to get
10845 * @Varargs: pairs of property names and locations to
10846 * return the property values, starting with the location for
10847 * @first_property_name, terminated by %NULL.
10849 * Gets the values of a multiple style properties of @widget.
10852 gtk_widget_style_get (GtkWidget *widget,
10853 const gchar *first_property_name,
10858 g_return_if_fail (GTK_IS_WIDGET (widget));
10860 va_start (var_args, first_property_name);
10861 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10867 * @widget: a #GtkWidget
10868 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10869 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10870 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10872 * Obtains the full path to @widget. The path is simply the name of a
10873 * widget and all its parents in the container hierarchy, separated by
10874 * periods. The name of a widget comes from
10875 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10876 * in gtkrc configuration files. Widget names are the type of the
10877 * widget by default (e.g. "GtkButton") or can be set to an
10878 * application-specific value with gtk_widget_set_name(). By setting
10879 * the name of a widget, you allow users or theme authors to apply
10880 * styles to that specific widget in their gtkrc
10881 * file. @path_reversed_p fills in the path in reverse order,
10882 * i.e. starting with @widget's name instead of starting with the name
10883 * of @widget's outermost ancestor.
10886 gtk_widget_path (GtkWidget *widget,
10887 guint *path_length,
10889 gchar **path_reversed)
10891 static gchar *rev_path = NULL;
10892 static guint tmp_path_len = 0;
10895 g_return_if_fail (GTK_IS_WIDGET (widget));
10900 const gchar *string;
10905 string = gtk_widget_get_name (widget);
10906 l = strlen (string);
10907 while (tmp_path_len <= len + l + 1)
10909 tmp_path_len += INIT_PATH_SIZE;
10910 rev_path = g_realloc (rev_path, tmp_path_len);
10912 s = string + l - 1;
10913 d = rev_path + len;
10914 while (s >= string)
10918 widget = widget->priv->parent;
10921 rev_path[len++] = '.';
10923 rev_path[len++] = 0;
10928 *path_length = len - 1;
10930 *path_reversed = g_strdup (rev_path);
10933 *path = g_strdup (rev_path);
10934 g_strreverse (*path);
10939 * gtk_widget_class_path:
10940 * @widget: a #GtkWidget
10941 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10942 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10943 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10946 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10947 * never uses a custom name set with gtk_widget_set_name().
10951 gtk_widget_class_path (GtkWidget *widget,
10952 guint *path_length,
10954 gchar **path_reversed)
10956 static gchar *rev_path = NULL;
10957 static guint tmp_path_len = 0;
10960 g_return_if_fail (GTK_IS_WIDGET (widget));
10965 const gchar *string;
10970 string = g_type_name (G_OBJECT_TYPE (widget));
10971 l = strlen (string);
10972 while (tmp_path_len <= len + l + 1)
10974 tmp_path_len += INIT_PATH_SIZE;
10975 rev_path = g_realloc (rev_path, tmp_path_len);
10977 s = string + l - 1;
10978 d = rev_path + len;
10979 while (s >= string)
10983 widget = widget->priv->parent;
10986 rev_path[len++] = '.';
10988 rev_path[len++] = 0;
10993 *path_length = len - 1;
10995 *path_reversed = g_strdup (rev_path);
10998 *path = g_strdup (rev_path);
10999 g_strreverse (*path);
11004 * gtk_requisition_new:
11006 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
11008 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
11009 * be freed with gtk_requisition_free().
11014 gtk_requisition_new (void)
11016 return g_slice_new0 (GtkRequisition);
11020 * gtk_requisition_copy:
11021 * @requisition: a #GtkRequisition
11023 * Copies a #GtkRequisition.
11025 * Returns: a copy of @requisition
11028 gtk_requisition_copy (const GtkRequisition *requisition)
11030 return g_slice_dup (GtkRequisition, requisition);
11034 * gtk_requisition_free:
11035 * @requisition: a #GtkRequisition
11037 * Frees a #GtkRequisition.
11040 gtk_requisition_free (GtkRequisition *requisition)
11042 g_slice_free (GtkRequisition, requisition);
11045 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
11046 gtk_requisition_copy,
11047 gtk_requisition_free)
11050 * gtk_widget_get_accessible:
11051 * @widget: a #GtkWidget
11053 * Returns the accessible object that describes the widget to an
11054 * assistive technology.
11056 * If no accessibility library is loaded (i.e. no ATK implementation library is
11057 * loaded via <envar>GTK_MODULES</envar> or via another application library,
11058 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
11059 * if no class-specific #AtkObject implementation is available for the widget
11060 * instance in question, it will inherit an #AtkObject implementation from the
11061 * first ancestor class for which such an implementation is defined.
11063 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
11064 * library contains more information about accessible objects and their uses.
11066 * Returns: (transfer none): the #AtkObject associated with @widget
11069 gtk_widget_get_accessible (GtkWidget *widget)
11071 GtkWidgetClass *klass;
11073 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11075 klass = GTK_WIDGET_GET_CLASS (widget);
11077 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
11079 return klass->get_accessible (widget);
11083 gtk_widget_real_get_accessible (GtkWidget *widget)
11085 AtkObject* accessible;
11087 accessible = g_object_get_qdata (G_OBJECT (widget),
11088 quark_accessible_object);
11091 AtkObjectFactory *factory;
11092 AtkRegistry *default_registry;
11094 default_registry = atk_get_default_registry ();
11095 factory = atk_registry_get_factory (default_registry,
11096 G_TYPE_FROM_INSTANCE (widget));
11098 atk_object_factory_create_accessible (factory,
11099 G_OBJECT (widget));
11100 g_object_set_qdata (G_OBJECT (widget),
11101 quark_accessible_object,
11108 * Initialize a AtkImplementorIface instance's virtual pointers as
11109 * appropriate to this implementor's class (GtkWidget).
11112 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
11114 iface->ref_accessible = gtk_widget_ref_accessible;
11118 gtk_widget_ref_accessible (AtkImplementor *implementor)
11120 AtkObject *accessible;
11122 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
11124 g_object_ref (accessible);
11129 * Expand flag management
11133 gtk_widget_update_computed_expand (GtkWidget *widget)
11135 GtkWidgetPrivate *priv;
11137 priv = widget->priv;
11139 if (priv->need_compute_expand)
11143 if (priv->hexpand_set)
11148 if (priv->vexpand_set)
11153 /* we don't need to use compute_expand if both expands are
11154 * forced by the app
11156 if (!(priv->hexpand_set && priv->vexpand_set))
11158 if (GTK_WIDGET_GET_CLASS (widget)->compute_expand != NULL)
11162 GTK_WIDGET_GET_CLASS (widget)->compute_expand (widget,
11163 priv->hexpand_set ? &ignored : &h,
11164 priv->vexpand_set ? &ignored : &v);
11168 priv->need_compute_expand = FALSE;
11169 priv->computed_hexpand = h != FALSE;
11170 priv->computed_vexpand = v != FALSE;
11175 gtk_widget_queue_compute_expand (GtkWidget *widget)
11178 gboolean changed_anything;
11180 if (widget->priv->need_compute_expand)
11183 changed_anything = FALSE;
11185 while (parent != NULL)
11187 if (!parent->priv->need_compute_expand)
11189 parent->priv->need_compute_expand = TRUE;
11190 changed_anything = TRUE;
11193 /* Note: if we had an invariant that "if a child needs to
11194 * compute expand, its parents also do" then we could stop going
11195 * up when we got to a parent that already needed to
11196 * compute. However, in general we compute expand lazily (as
11197 * soon as we see something in a subtree that is expand, we know
11198 * we're expanding) and so this invariant does not hold and we
11199 * have to always walk all the way up in case some ancestor
11200 * is not currently need_compute_expand.
11203 parent = parent->priv->parent;
11206 /* recomputing expand always requires
11207 * a relayout as well
11209 if (changed_anything)
11210 gtk_widget_queue_resize (widget);
11214 * gtk_widget_compute_expand:
11215 * @widget: the widget
11216 * @orientation: expand direction
11218 * Computes whether a container should give this widget extra space
11219 * when possible. Containers should check this, rather than
11220 * looking at gtk_widget_get_hexpand() or gtk_widget_get_vexpand().
11222 * This function already checks whether the widget is visible, so
11223 * visibility does not need to be checked separately. Non-visible
11224 * widgets are not expanded.
11226 * The computed expand value uses either the expand setting explicitly
11227 * set on the widget itself, or, if none has been explicitly set,
11228 * the widget may expand if some of its children do.
11230 * Return value: whether widget tree rooted here should be expanded
11233 gtk_widget_compute_expand (GtkWidget *widget,
11234 GtkOrientation orientation)
11236 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11238 /* We never make a widget expand if not even showing. */
11239 if (!gtk_widget_get_visible (widget))
11242 gtk_widget_update_computed_expand (widget);
11244 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11246 return widget->priv->computed_hexpand;
11250 return widget->priv->computed_vexpand;
11255 gtk_widget_set_expand (GtkWidget *widget,
11256 GtkOrientation orientation,
11259 const char *expand_prop;
11260 const char *expand_set_prop;
11262 GtkWidgetPrivate *priv;
11264 g_return_if_fail (GTK_IS_WIDGET (widget));
11266 priv = widget->priv;
11268 expand = expand != FALSE;
11270 was_both = priv->hexpand && priv->vexpand;
11272 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11274 if (priv->hexpand_set &&
11275 priv->hexpand == expand)
11278 priv->hexpand_set = TRUE;
11279 priv->hexpand = expand;
11281 expand_prop = "hexpand";
11282 expand_set_prop = "hexpand-set";
11286 if (priv->vexpand_set &&
11287 priv->vexpand == expand)
11290 priv->vexpand_set = TRUE;
11291 priv->vexpand = expand;
11293 expand_prop = "vexpand";
11294 expand_set_prop = "vexpand-set";
11297 gtk_widget_queue_compute_expand (widget);
11299 g_object_freeze_notify (G_OBJECT (widget));
11300 g_object_notify (G_OBJECT (widget), expand_prop);
11301 g_object_notify (G_OBJECT (widget), expand_set_prop);
11302 if (was_both != (priv->hexpand && priv->vexpand))
11303 g_object_notify (G_OBJECT (widget), "expand");
11304 g_object_thaw_notify (G_OBJECT (widget));
11308 gtk_widget_set_expand_set (GtkWidget *widget,
11309 GtkOrientation orientation,
11312 GtkWidgetPrivate *priv;
11315 priv = widget->priv;
11317 set = set != FALSE;
11319 if (orientation == GTK_ORIENTATION_HORIZONTAL)
11321 if (set == priv->hexpand_set)
11324 priv->hexpand_set = set;
11325 prop = "hexpand-set";
11329 if (set == priv->vexpand_set)
11332 priv->vexpand_set = set;
11333 prop = "vexpand-set";
11336 gtk_widget_queue_compute_expand (widget);
11338 g_object_notify (G_OBJECT (widget), prop);
11342 * gtk_widget_get_hexpand:
11343 * @widget: the widget
11345 * Gets whether the widget would like any available extra horizontal
11346 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11347 * generally receive the extra space. For example, a list or
11348 * scrollable area or document in your window would often be set to
11351 * Containers should use gtk_widget_compute_expand() rather than
11352 * this function, to see whether a widget, or any of its children,
11353 * has the expand flag set. If any child of a widget wants to
11354 * expand, the parent may ask to expand also.
11356 * This function only looks at the widget's own hexpand flag, rather
11357 * than computing whether the entire widget tree rooted at this widget
11360 * Return value: whether hexpand flag is set
11363 gtk_widget_get_hexpand (GtkWidget *widget)
11365 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11367 return widget->priv->hexpand;
11371 * gtk_widget_set_hexpand:
11372 * @widget: the widget
11373 * @expand: whether to expand
11375 * Sets whether the widget would like any available extra horizontal
11376 * space. When a user resizes a #GtkWindow, widgets with expand=TRUE
11377 * generally receive the extra space. For example, a list or
11378 * scrollable area or document in your window would often be set to
11381 * Call this function to set the expand flag if you would like your
11382 * widget to become larger horizontally when the window has extra
11385 * By default, widgets automatically expand if any of their children
11386 * want to expand. (To see if a widget will automatically expand given
11387 * its current children and state, call gtk_widget_compute_expand(). A
11388 * container can decide how the expandability of children affects the
11389 * expansion of the container by overriding the compute_expand virtual
11390 * method on #GtkWidget.).
11392 * Setting hexpand explicitly with this function will override the
11393 * automatic expand behavior.
11395 * This function forces the widget to expand or not to expand,
11396 * regardless of children. The override occurs because
11397 * gtk_widget_set_hexpand() sets the hexpand-set property (see
11398 * gtk_widget_set_hexpand_set()) which causes the widget's hexpand
11399 * value to be used, rather than looking at children and widget state.
11402 gtk_widget_set_hexpand (GtkWidget *widget,
11405 g_return_if_fail (GTK_IS_WIDGET (widget));
11407 gtk_widget_set_expand (widget, GTK_ORIENTATION_HORIZONTAL, expand);
11411 * gtk_widget_get_hexpand_set:
11412 * @widget: the widget
11414 * Gets whether gtk_widget_set_hexpand() has been used to
11415 * explicitly set the expand flag on this widget.
11417 * If hexpand is set, then it overrides any computed
11418 * expand value based on child widgets. If hexpand is not
11419 * set, then the expand value depends on whether any
11420 * children of the widget would like to expand.
11422 * There are few reasons to use this function, but it's here
11423 * for completeness and consistency.
11425 * Return value: whether hexpand has been explicitly set
11428 gtk_widget_get_hexpand_set (GtkWidget *widget)
11430 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11432 return widget->priv->hexpand_set;
11436 * gtk_widget_set_hexpand_set:
11437 * @widget: the widget
11438 * @set: value for hexpand-set property
11440 * Sets whether the hexpand flag (see gtk_widget_get_hexpand()) will
11443 * The hexpand-set property will be set automatically when you call
11444 * gtk_widget_set_hexpand() to set hexpand, so the most likely
11445 * reason to use this function would be to unset an explicit expand
11448 * If hexpand is set, then it overrides any computed
11449 * expand value based on child widgets. If hexpand is not
11450 * set, then the expand value depends on whether any
11451 * children of the widget would like to expand.
11453 * There are few reasons to use this function, but it's here
11454 * for completeness and consistency.
11456 * Return value: whether hexpand has been explicitly set
11459 gtk_widget_set_hexpand_set (GtkWidget *widget,
11462 g_return_if_fail (GTK_IS_WIDGET (widget));
11464 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_HORIZONTAL, set);
11469 * gtk_widget_get_vexpand:
11470 * @widget: the widget
11472 * Gets whether the widget would like any available extra vertical
11475 * See gtk_widget_get_hexpand() for more detail.
11477 * Return value: whether vexpand flag is set
11480 gtk_widget_get_vexpand (GtkWidget *widget)
11482 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11484 return widget->priv->vexpand;
11488 * gtk_widget_set_vexpand:
11489 * @widget: the widget
11490 * @expand: whether to expand
11492 * Sets whether the widget would like any available extra vertical
11495 * See gtk_widget_set_hexpand() for more detail.
11498 gtk_widget_set_vexpand (GtkWidget *widget,
11501 g_return_if_fail (GTK_IS_WIDGET (widget));
11503 gtk_widget_set_expand (widget, GTK_ORIENTATION_VERTICAL, expand);
11507 * gtk_widget_get_vexpand_set:
11508 * @widget: the widget
11510 * Gets whether gtk_widget_set_vexpand() has been used to
11511 * explicitly set the expand flag on this widget.
11513 * See gtk_widget_get_hexpand_set() for more detail.
11515 * Return value: whether vexpand has been explicitly set
11518 gtk_widget_get_vexpand_set (GtkWidget *widget)
11520 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11522 return widget->priv->vexpand_set;
11526 * gtk_widget_set_vexpand_set:
11527 * @widget: the widget
11528 * @set: value for vexpand-set property
11530 * Sets whether the vexpand flag (see gtk_widget_get_vexpand()) will
11533 * See gtk_widget_set_hexpand_set() for more detail.
11535 * Return value: whether vexpand has been explicitly set
11538 gtk_widget_set_vexpand_set (GtkWidget *widget,
11541 g_return_if_fail (GTK_IS_WIDGET (widget));
11543 gtk_widget_set_expand_set (widget, GTK_ORIENTATION_VERTICAL, set);
11547 * GtkBuildable implementation
11549 static GQuark quark_builder_has_default = 0;
11550 static GQuark quark_builder_has_focus = 0;
11551 static GQuark quark_builder_atk_relations = 0;
11552 static GQuark quark_builder_set_name = 0;
11555 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
11557 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
11558 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
11559 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
11560 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
11562 iface->set_name = gtk_widget_buildable_set_name;
11563 iface->get_name = gtk_widget_buildable_get_name;
11564 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
11565 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
11566 iface->parser_finished = gtk_widget_buildable_parser_finished;
11567 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
11568 iface->custom_finished = gtk_widget_buildable_custom_finished;
11572 gtk_widget_buildable_set_name (GtkBuildable *buildable,
11575 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
11576 g_strdup (name), g_free);
11579 static const gchar *
11580 gtk_widget_buildable_get_name (GtkBuildable *buildable)
11582 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
11586 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
11587 GtkBuilder *builder,
11588 const gchar *childname)
11590 if (strcmp (childname, "accessible") == 0)
11591 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
11597 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
11598 GtkBuilder *builder,
11600 const GValue *value)
11602 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
11603 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
11604 GINT_TO_POINTER (TRUE));
11605 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
11606 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
11607 GINT_TO_POINTER (TRUE));
11609 g_object_set_property (G_OBJECT (buildable), name, value);
11614 gchar *action_name;
11615 GString *description;
11617 gboolean translatable;
11627 free_action (AtkActionData *data, gpointer user_data)
11629 g_free (data->action_name);
11630 g_string_free (data->description, TRUE);
11631 g_free (data->context);
11632 g_slice_free (AtkActionData, data);
11636 free_relation (AtkRelationData *data, gpointer user_data)
11638 g_free (data->target);
11639 g_free (data->type);
11640 g_slice_free (AtkRelationData, data);
11644 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11645 GtkBuilder *builder)
11647 GSList *atk_relations;
11649 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11650 gtk_widget_grab_default (GTK_WIDGET (buildable));
11651 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11652 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11654 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11655 quark_builder_atk_relations);
11658 AtkObject *accessible;
11659 AtkRelationSet *relation_set;
11662 AtkRelationType relation_type;
11663 AtkObject *target_accessible;
11665 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11666 relation_set = atk_object_ref_relation_set (accessible);
11668 for (l = atk_relations; l; l = l->next)
11670 AtkRelationData *relation = (AtkRelationData*)l->data;
11672 target = gtk_builder_get_object (builder, relation->target);
11675 g_warning ("Target object %s in <relation> does not exist",
11679 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11680 g_assert (target_accessible != NULL);
11682 relation_type = atk_relation_type_for_name (relation->type);
11683 if (relation_type == ATK_RELATION_NULL)
11685 g_warning ("<relation> type %s not found",
11689 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11690 target_accessible);
11692 g_object_unref (relation_set);
11694 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11695 g_slist_free (atk_relations);
11696 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11705 } AccessibilitySubParserData;
11708 accessibility_start_element (GMarkupParseContext *context,
11709 const gchar *element_name,
11710 const gchar **names,
11711 const gchar **values,
11712 gpointer user_data,
11715 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11717 gint line_number, char_number;
11719 if (strcmp (element_name, "relation") == 0)
11721 gchar *target = NULL;
11722 gchar *type = NULL;
11723 AtkRelationData *relation;
11725 for (i = 0; names[i]; i++)
11727 if (strcmp (names[i], "target") == 0)
11728 target = g_strdup (values[i]);
11729 else if (strcmp (names[i], "type") == 0)
11730 type = g_strdup (values[i]);
11733 g_markup_parse_context_get_position (context,
11736 g_set_error (error,
11738 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11739 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11741 line_number, char_number, names[i], "relation");
11748 if (!target || !type)
11750 g_markup_parse_context_get_position (context,
11753 g_set_error (error,
11755 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11756 "%s:%d:%d <%s> requires attribute \"%s\"",
11758 line_number, char_number, "relation",
11759 type ? "target" : "type");
11765 relation = g_slice_new (AtkRelationData);
11766 relation->target = target;
11767 relation->type = type;
11769 data->relations = g_slist_prepend (data->relations, relation);
11771 else if (strcmp (element_name, "action") == 0)
11773 const gchar *action_name = NULL;
11774 const gchar *description = NULL;
11775 const gchar *msg_context = NULL;
11776 gboolean translatable = FALSE;
11777 AtkActionData *action;
11779 for (i = 0; names[i]; i++)
11781 if (strcmp (names[i], "action_name") == 0)
11782 action_name = values[i];
11783 else if (strcmp (names[i], "description") == 0)
11784 description = values[i];
11785 else if (strcmp (names[i], "translatable") == 0)
11787 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11790 else if (strcmp (names[i], "comments") == 0)
11792 /* do nothing, comments are for translators */
11794 else if (strcmp (names[i], "context") == 0)
11795 msg_context = values[i];
11798 g_markup_parse_context_get_position (context,
11801 g_set_error (error,
11803 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11804 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11806 line_number, char_number, names[i], "action");
11813 g_markup_parse_context_get_position (context,
11816 g_set_error (error,
11818 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11819 "%s:%d:%d <%s> requires attribute \"%s\"",
11821 line_number, char_number, "action",
11826 action = g_slice_new (AtkActionData);
11827 action->action_name = g_strdup (action_name);
11828 action->description = g_string_new (description);
11829 action->context = g_strdup (msg_context);
11830 action->translatable = translatable;
11832 data->actions = g_slist_prepend (data->actions, action);
11834 else if (strcmp (element_name, "accessibility") == 0)
11837 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11841 accessibility_text (GMarkupParseContext *context,
11844 gpointer user_data,
11847 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11849 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11851 AtkActionData *action = data->actions->data;
11853 g_string_append_len (action->description, text, text_len);
11857 static const GMarkupParser accessibility_parser =
11859 accessibility_start_element,
11861 accessibility_text,
11870 } AccelGroupParserData;
11873 accel_group_start_element (GMarkupParseContext *context,
11874 const gchar *element_name,
11875 const gchar **names,
11876 const gchar **values,
11877 gpointer user_data,
11882 guint modifiers = 0;
11883 gchar *signal = NULL;
11884 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11886 for (i = 0; names[i]; i++)
11888 if (strcmp (names[i], "key") == 0)
11889 key = gdk_keyval_from_name (values[i]);
11890 else if (strcmp (names[i], "modifiers") == 0)
11892 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11898 else if (strcmp (names[i], "signal") == 0)
11899 signal = g_strdup (values[i]);
11902 if (key == 0 || signal == NULL)
11904 g_warning ("<accelerator> requires key and signal attributes");
11907 parser_data->key = key;
11908 parser_data->modifiers = modifiers;
11909 parser_data->signal = signal;
11912 static const GMarkupParser accel_group_parser =
11914 accel_group_start_element,
11918 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11919 GtkBuilder *builder,
11921 const gchar *tagname,
11922 GMarkupParser *parser,
11925 g_assert (buildable);
11927 if (strcmp (tagname, "accelerator") == 0)
11929 AccelGroupParserData *parser_data;
11931 parser_data = g_slice_new0 (AccelGroupParserData);
11932 parser_data->object = g_object_ref (buildable);
11933 *parser = accel_group_parser;
11934 *data = parser_data;
11937 if (strcmp (tagname, "accessibility") == 0)
11939 AccessibilitySubParserData *parser_data;
11941 parser_data = g_slice_new0 (AccessibilitySubParserData);
11942 *parser = accessibility_parser;
11943 *data = parser_data;
11950 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11951 GtkWidget *toplevel,
11952 gpointer user_data)
11954 AccelGroupParserData *accel_data;
11955 GSList *accel_groups;
11956 GtkAccelGroup *accel_group;
11958 g_return_if_fail (GTK_IS_WIDGET (widget));
11959 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11960 g_return_if_fail (user_data != NULL);
11962 accel_data = (AccelGroupParserData*)user_data;
11963 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11964 if (g_slist_length (accel_groups) == 0)
11966 accel_group = gtk_accel_group_new ();
11967 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11971 g_assert (g_slist_length (accel_groups) == 1);
11972 accel_group = g_slist_nth_data (accel_groups, 0);
11975 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11976 accel_data->signal,
11979 accel_data->modifiers,
11980 GTK_ACCEL_VISIBLE);
11982 g_object_unref (accel_data->object);
11983 g_free (accel_data->signal);
11984 g_slice_free (AccelGroupParserData, accel_data);
11988 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11989 GtkBuilder *builder,
11991 const gchar *tagname,
11992 gpointer user_data)
11994 AccelGroupParserData *accel_data;
11995 AccessibilitySubParserData *a11y_data;
11996 GtkWidget *toplevel;
11998 if (strcmp (tagname, "accelerator") == 0)
12000 accel_data = (AccelGroupParserData*)user_data;
12001 g_assert (accel_data->object);
12003 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
12005 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
12007 else if (strcmp (tagname, "accessibility") == 0)
12009 a11y_data = (AccessibilitySubParserData*)user_data;
12011 if (a11y_data->actions)
12013 AtkObject *accessible;
12018 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
12020 action = ATK_ACTION (accessible);
12021 n_actions = atk_action_get_n_actions (action);
12023 for (l = a11y_data->actions; l; l = l->next)
12025 AtkActionData *action_data = (AtkActionData*)l->data;
12027 for (i = 0; i < n_actions; i++)
12028 if (strcmp (atk_action_get_name (action, i),
12029 action_data->action_name) == 0)
12034 gchar *description;
12036 if (action_data->translatable && action_data->description->len)
12037 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
12038 action_data->context,
12039 action_data->description->str);
12041 description = action_data->description->str;
12043 atk_action_set_description (action, i, description);
12047 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
12048 g_slist_free (a11y_data->actions);
12051 if (a11y_data->relations)
12052 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
12053 a11y_data->relations);
12055 g_slice_free (AccessibilitySubParserData, a11y_data);
12060 gtk_widget_real_get_width (GtkWidget *widget,
12061 gint *minimum_size,
12062 gint *natural_size)
12072 gtk_widget_real_get_height (GtkWidget *widget,
12073 gint *minimum_size,
12074 gint *natural_size)
12084 gtk_widget_real_get_height_for_width (GtkWidget *widget,
12086 gint *minimum_height,
12087 gint *natural_height)
12089 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
12093 gtk_widget_real_get_width_for_height (GtkWidget *widget,
12095 gint *minimum_width,
12096 gint *natural_width)
12098 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
12102 * gtk_widget_get_halign:
12103 * @widget: a #GtkWidget
12105 * Gets the value of the #GtkWidget:halign property.
12107 * Returns: the horizontal alignment of @widget
12110 gtk_widget_get_halign (GtkWidget *widget)
12112 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12113 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
12117 * gtk_widget_set_halign:
12118 * @widget: a #GtkWidget
12119 * @align: the horizontal alignment
12121 * Sets the horizontal alignment of @widget.
12122 * See the #GtkWidget:halign property.
12125 gtk_widget_set_halign (GtkWidget *widget,
12128 GtkWidgetAuxInfo *aux_info;
12130 g_return_if_fail (GTK_IS_WIDGET (widget));
12132 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12134 if (aux_info->halign == align)
12137 aux_info->halign = align;
12138 gtk_widget_queue_resize (widget);
12139 g_object_notify (G_OBJECT (widget), "halign");
12143 * gtk_widget_get_valign:
12144 * @widget: a #GtkWidget
12146 * Gets the value of the #GtkWidget:valign property.
12148 * Returns: the vertical alignment of @widget
12151 gtk_widget_get_valign (GtkWidget *widget)
12153 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
12154 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
12158 * gtk_widget_set_valign:
12159 * @widget: a #GtkWidget
12160 * @align: the vertical alignment
12162 * Sets the vertical alignment of @widget.
12163 * See the #GtkWidget:valign property.
12166 gtk_widget_set_valign (GtkWidget *widget,
12169 GtkWidgetAuxInfo *aux_info;
12171 g_return_if_fail (GTK_IS_WIDGET (widget));
12173 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12175 if (aux_info->valign == align)
12178 aux_info->valign = align;
12179 gtk_widget_queue_resize (widget);
12180 g_object_notify (G_OBJECT (widget), "valign");
12184 * gtk_widget_get_margin_left:
12185 * @widget: a #GtkWidget
12187 * Gets the value of the #GtkWidget:margin-left property.
12189 * Returns: The left margin of @widget
12192 gtk_widget_get_margin_left (GtkWidget *widget)
12194 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12196 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
12200 * gtk_widget_set_margin_left:
12201 * @widget: a #GtkWidget
12202 * @margin: the left margin
12204 * Sets the left margin of @widget.
12205 * See the #GtkWidget:margin-left property.
12208 gtk_widget_set_margin_left (GtkWidget *widget,
12211 GtkWidgetAuxInfo *aux_info;
12213 g_return_if_fail (GTK_IS_WIDGET (widget));
12214 g_return_if_fail (margin <= G_MAXINT16);
12216 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12218 if (aux_info->margin.left == margin)
12221 aux_info->margin.left = margin;
12222 gtk_widget_queue_resize (widget);
12223 g_object_notify (G_OBJECT (widget), "margin-left");
12227 * gtk_widget_get_margin_right:
12228 * @widget: a #GtkWidget
12230 * Gets the value of the #GtkWidget:margin-right property.
12232 * Returns: The left margin of @widget
12235 gtk_widget_get_margin_right (GtkWidget *widget)
12237 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12239 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
12243 * gtk_widget_set_margin_right:
12244 * @widget: a #GtkWidget
12245 * @margin: the right margin
12247 * Sets the right margin of @widget.
12248 * See the #GtkWidget:margin-right property.
12251 gtk_widget_set_margin_right (GtkWidget *widget,
12254 GtkWidgetAuxInfo *aux_info;
12256 g_return_if_fail (GTK_IS_WIDGET (widget));
12257 g_return_if_fail (margin <= G_MAXINT16);
12259 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12261 if (aux_info->margin.right == margin)
12264 aux_info->margin.right = margin;
12265 gtk_widget_queue_resize (widget);
12266 g_object_notify (G_OBJECT (widget), "margin-right");
12270 * gtk_widget_get_margin_top:
12271 * @widget: a #GtkWidget
12273 * Gets the value of the #GtkWidget:margin-top property.
12275 * Returns: The top margin of @widget
12278 gtk_widget_get_margin_top (GtkWidget *widget)
12280 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12282 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
12286 * gtk_widget_set_margin_top:
12287 * @widget: a #GtkWidget
12288 * @margin: the top margin
12290 * Sets the top margin of @widget.
12291 * See the #GtkWidget:margin-top property.
12294 gtk_widget_set_margin_top (GtkWidget *widget,
12297 GtkWidgetAuxInfo *aux_info;
12299 g_return_if_fail (GTK_IS_WIDGET (widget));
12300 g_return_if_fail (margin <= G_MAXINT16);
12302 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12304 if (aux_info->margin.top == margin)
12307 aux_info->margin.top = margin;
12308 gtk_widget_queue_resize (widget);
12309 g_object_notify (G_OBJECT (widget), "margin-top");
12313 * gtk_widget_get_margin_bottom:
12314 * @widget: a #GtkWidget
12316 * Gets the value of the #GtkWidget:margin-bottom property.
12318 * Returns: The bottom margin of @widget
12321 gtk_widget_get_margin_bottom (GtkWidget *widget)
12323 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12325 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
12329 * gtk_widget_set_margin_bottom:
12330 * @widget: a #GtkWidget
12331 * @margin: the bottom margin
12333 * Sets the bottom margin of @widget.
12334 * See the #GtkWidget:margin-bottom property.
12337 gtk_widget_set_margin_bottom (GtkWidget *widget,
12340 GtkWidgetAuxInfo *aux_info;
12342 g_return_if_fail (GTK_IS_WIDGET (widget));
12343 g_return_if_fail (margin <= G_MAXINT16);
12345 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
12347 if (aux_info->margin.bottom == margin)
12350 aux_info->margin.bottom = margin;
12351 gtk_widget_queue_resize (widget);
12352 g_object_notify (G_OBJECT (widget), "margin-bottom");
12356 * gtk_widget_get_clipboard:
12357 * @widget: a #GtkWidget
12358 * @selection: a #GdkAtom which identifies the clipboard
12359 * to use. %GDK_SELECTION_CLIPBOARD gives the
12360 * default clipboard. Another common value
12361 * is %GDK_SELECTION_PRIMARY, which gives
12362 * the primary X selection.
12364 * Returns the clipboard object for the given selection to
12365 * be used with @widget. @widget must have a #GdkDisplay
12366 * associated with it, so must be attached to a toplevel
12369 * Return value: (transfer none): the appropriate clipboard object. If no
12370 * clipboard already exists, a new one will
12371 * be created. Once a clipboard object has
12372 * been created, it is persistent for all time.
12377 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
12379 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12380 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
12382 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
12387 * gtk_widget_list_mnemonic_labels:
12388 * @widget: a #GtkWidget
12390 * Returns a newly allocated list of the widgets, normally labels, for
12391 * which this widget is the target of a mnemonic (see for example,
12392 * gtk_label_set_mnemonic_widget()).
12394 * The widgets in the list are not individually referenced. If you
12395 * want to iterate through the list and perform actions involving
12396 * callbacks that might destroy the widgets, you
12397 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
12398 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
12399 * widgets afterwards.
12401 * Return value: (element-type GtkWidget) (transfer container): the list of
12402 * mnemonic labels; free this list
12403 * with g_list_free() when you are done with it.
12408 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
12410 GList *list = NULL;
12413 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12415 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
12416 list = g_list_prepend (list, l->data);
12422 * gtk_widget_add_mnemonic_label:
12423 * @widget: a #GtkWidget
12424 * @label: a #GtkWidget that acts as a mnemonic label for @widget
12426 * Adds a widget to the list of mnemonic labels for
12427 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
12428 * list of mnemonic labels for the widget is cleared when the
12429 * widget is destroyed, so the caller must make sure to update
12430 * its internal state at this point as well, by using a connection
12431 * to the #GtkWidget::destroy signal or a weak notifier.
12436 gtk_widget_add_mnemonic_label (GtkWidget *widget,
12439 GSList *old_list, *new_list;
12441 g_return_if_fail (GTK_IS_WIDGET (widget));
12442 g_return_if_fail (GTK_IS_WIDGET (label));
12444 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12445 new_list = g_slist_prepend (old_list, label);
12447 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12448 new_list, (GDestroyNotify) g_slist_free);
12452 * gtk_widget_remove_mnemonic_label:
12453 * @widget: a #GtkWidget
12454 * @label: a #GtkWidget that was previously set as a mnemnic label for
12455 * @widget with gtk_widget_add_mnemonic_label().
12457 * Removes a widget from the list of mnemonic labels for
12458 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
12459 * must have previously been added to the list with
12460 * gtk_widget_add_mnemonic_label().
12465 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
12468 GSList *old_list, *new_list;
12470 g_return_if_fail (GTK_IS_WIDGET (widget));
12471 g_return_if_fail (GTK_IS_WIDGET (label));
12473 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
12474 new_list = g_slist_remove (old_list, label);
12477 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
12478 new_list, (GDestroyNotify) g_slist_free);
12482 * gtk_widget_get_no_show_all:
12483 * @widget: a #GtkWidget
12485 * Returns the current value of the GtkWidget:no-show-all property,
12486 * which determines whether calls to gtk_widget_show_all()
12487 * will affect this widget.
12489 * Return value: the current value of the "no-show-all" property.
12494 gtk_widget_get_no_show_all (GtkWidget *widget)
12496 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12498 return widget->priv->no_show_all;
12502 * gtk_widget_set_no_show_all:
12503 * @widget: a #GtkWidget
12504 * @no_show_all: the new value for the "no-show-all" property
12506 * Sets the #GtkWidget:no-show-all property, which determines whether
12507 * calls to gtk_widget_show_all() will affect this widget.
12509 * This is mostly for use in constructing widget hierarchies with externally
12510 * controlled visibility, see #GtkUIManager.
12515 gtk_widget_set_no_show_all (GtkWidget *widget,
12516 gboolean no_show_all)
12518 g_return_if_fail (GTK_IS_WIDGET (widget));
12520 no_show_all = (no_show_all != FALSE);
12522 if (widget->priv->no_show_all != no_show_all)
12524 widget->priv->no_show_all = no_show_all;
12526 g_object_notify (G_OBJECT (widget), "no-show-all");
12532 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
12533 gboolean has_tooltip,
12536 GtkWidgetPrivate *priv = widget->priv;
12537 gboolean priv_has_tooltip;
12539 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
12540 quark_has_tooltip));
12542 if (priv_has_tooltip != has_tooltip || force)
12544 priv_has_tooltip = has_tooltip;
12546 if (priv_has_tooltip)
12548 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
12549 gdk_window_set_events (priv->window,
12550 gdk_window_get_events (priv->window) |
12551 GDK_LEAVE_NOTIFY_MASK |
12552 GDK_POINTER_MOTION_MASK |
12553 GDK_POINTER_MOTION_HINT_MASK);
12555 if (gtk_widget_get_has_window (widget))
12556 gtk_widget_add_events (widget,
12557 GDK_LEAVE_NOTIFY_MASK |
12558 GDK_POINTER_MOTION_MASK |
12559 GDK_POINTER_MOTION_HINT_MASK);
12562 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
12563 GUINT_TO_POINTER (priv_has_tooltip));
12568 * gtk_widget_set_tooltip_window:
12569 * @widget: a #GtkWidget
12570 * @custom_window: (allow-none): a #GtkWindow, or %NULL
12572 * Replaces the default, usually yellow, window used for displaying
12573 * tooltips with @custom_window. GTK+ will take care of showing and
12574 * hiding @custom_window at the right moment, to behave likewise as
12575 * the default tooltip window. If @custom_window is %NULL, the default
12576 * tooltip window will be used.
12578 * If the custom window should have the default theming it needs to
12579 * have the name "gtk-tooltip", see gtk_widget_set_name().
12584 gtk_widget_set_tooltip_window (GtkWidget *widget,
12585 GtkWindow *custom_window)
12587 gboolean has_tooltip;
12588 gchar *tooltip_markup;
12590 g_return_if_fail (GTK_IS_WIDGET (widget));
12591 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
12593 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
12596 g_object_ref (custom_window);
12598 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
12599 custom_window, g_object_unref);
12601 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
12602 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
12604 if (has_tooltip && gtk_widget_get_visible (widget))
12605 gtk_widget_queue_tooltip_query (widget);
12609 * gtk_widget_get_tooltip_window:
12610 * @widget: a #GtkWidget
12612 * Returns the #GtkWindow of the current tooltip. This can be the
12613 * GtkWindow created by default, or the custom tooltip window set
12614 * using gtk_widget_set_tooltip_window().
12616 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12621 gtk_widget_get_tooltip_window (GtkWidget *widget)
12623 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12625 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12629 * gtk_widget_trigger_tooltip_query:
12630 * @widget: a #GtkWidget
12632 * Triggers a tooltip query on the display where the toplevel of @widget
12633 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12639 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12641 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12644 static guint tooltip_query_id;
12645 static GSList *tooltip_query_displays;
12648 tooltip_query_idle (gpointer data)
12650 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12651 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12652 g_slist_free (tooltip_query_displays);
12654 tooltip_query_displays = NULL;
12655 tooltip_query_id = 0;
12661 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12663 GdkDisplay *display;
12665 display = gtk_widget_get_display (widget);
12667 if (!g_slist_find (tooltip_query_displays, display))
12668 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12670 if (tooltip_query_id == 0)
12671 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12675 * gtk_widget_set_tooltip_text:
12676 * @widget: a #GtkWidget
12677 * @text: the contents of the tooltip for @widget
12679 * Sets @text as the contents of the tooltip. This function will take
12680 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
12681 * handler for the GtkWidget::query-tooltip signal.
12683 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12688 gtk_widget_set_tooltip_text (GtkWidget *widget,
12691 g_return_if_fail (GTK_IS_WIDGET (widget));
12693 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12697 * gtk_widget_get_tooltip_text:
12698 * @widget: a #GtkWidget
12700 * Gets the contents of the tooltip for @widget.
12702 * Return value: the tooltip text, or %NULL. You should free the
12703 * returned string with g_free() when done.
12708 gtk_widget_get_tooltip_text (GtkWidget *widget)
12710 gchar *text = NULL;
12712 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12714 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12720 * gtk_widget_set_tooltip_markup:
12721 * @widget: a #GtkWidget
12722 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12724 * Sets @markup as the contents of the tooltip, which is marked up with
12725 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12727 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
12728 * and of the default handler for the GtkWidget::query-tooltip signal.
12730 * See also the GtkWidget:tooltip-markup property and
12731 * gtk_tooltip_set_markup().
12736 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12737 const gchar *markup)
12739 g_return_if_fail (GTK_IS_WIDGET (widget));
12741 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12745 * gtk_widget_get_tooltip_markup:
12746 * @widget: a #GtkWidget
12748 * Gets the contents of the tooltip for @widget.
12750 * Return value: the tooltip text, or %NULL. You should free the
12751 * returned string with g_free() when done.
12756 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12758 gchar *text = NULL;
12760 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12762 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12768 * gtk_widget_set_has_tooltip:
12769 * @widget: a #GtkWidget
12770 * @has_tooltip: whether or not @widget has a tooltip.
12772 * Sets the has-tooltip property on @widget to @has_tooltip. See
12773 * GtkWidget:has-tooltip for more information.
12778 gtk_widget_set_has_tooltip (GtkWidget *widget,
12779 gboolean has_tooltip)
12781 g_return_if_fail (GTK_IS_WIDGET (widget));
12783 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12787 * gtk_widget_get_has_tooltip:
12788 * @widget: a #GtkWidget
12790 * Returns the current value of the has-tooltip property. See
12791 * GtkWidget:has-tooltip for more information.
12793 * Return value: current value of has-tooltip on @widget.
12798 gtk_widget_get_has_tooltip (GtkWidget *widget)
12800 gboolean has_tooltip = FALSE;
12802 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12804 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12806 return has_tooltip;
12810 * gtk_widget_get_allocation:
12811 * @widget: a #GtkWidget
12812 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12814 * Retrieves the widget's allocation.
12816 * Note, when implementing a #GtkContainer: a widget's allocation will
12817 * be its "adjusted" allocation, that is, the widget's parent
12818 * container typically calls gtk_widget_size_allocate() with an
12819 * allocation, and that allocation is then adjusted (to handle margin
12820 * and alignment for example) before assignment to the widget.
12821 * gtk_widget_get_allocation() returns the adjusted allocation that
12822 * was actually assigned to the widget. The adjusted allocation is
12823 * guaranteed to be completely contained within the
12824 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12825 * is guaranteed that its children stay inside the assigned bounds,
12826 * but not that they have exactly the bounds the container assigned.
12827 * There is no way to get the original allocation assigned by
12828 * gtk_widget_size_allocate(), since it isn't stored; if a container
12829 * implementation needs that information it will have to track it itself.
12834 gtk_widget_get_allocation (GtkWidget *widget,
12835 GtkAllocation *allocation)
12837 GtkWidgetPrivate *priv;
12839 g_return_if_fail (GTK_IS_WIDGET (widget));
12840 g_return_if_fail (allocation != NULL);
12842 priv = widget->priv;
12844 *allocation = priv->allocation;
12848 * gtk_widget_set_allocation:
12849 * @widget: a #GtkWidget
12850 * @allocation: a pointer to a #GtkAllocation to copy from
12852 * Sets the widget's allocation. This should not be used
12853 * directly, but from within a widget's size_allocate method.
12855 * The allocation set should be the "adjusted" or actual
12856 * allocation. If you're implementing a #GtkContainer, you want to use
12857 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12858 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12859 * allocation inside gtk_widget_size_allocate() to create an adjusted
12865 gtk_widget_set_allocation (GtkWidget *widget,
12866 const GtkAllocation *allocation)
12868 GtkWidgetPrivate *priv;
12870 g_return_if_fail (GTK_IS_WIDGET (widget));
12871 g_return_if_fail (allocation != NULL);
12873 priv = widget->priv;
12875 priv->allocation = *allocation;
12879 * gtk_widget_get_allocated_width:
12880 * @widget: the widget to query
12882 * Returns the width that has currently been allocated to @widget.
12883 * This function is intended to be used when implementing handlers
12884 * for the GtkWidget::draw function.
12886 * Returns: the width of the @widget
12889 gtk_widget_get_allocated_width (GtkWidget *widget)
12891 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12893 return widget->priv->allocation.width;
12897 * gtk_widget_get_allocated_height:
12898 * @widget: the widget to query
12900 * Returns the height that has currently been allocated to @widget.
12901 * This function is intended to be used when implementing handlers
12902 * for the GtkWidget::draw function.
12904 * Returns: the height of the @widget
12907 gtk_widget_get_allocated_height (GtkWidget *widget)
12909 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12911 return widget->priv->allocation.height;
12915 * gtk_widget_get_requisition:
12916 * @widget: a #GtkWidget
12917 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12919 * Retrieves the widget's requisition.
12921 * This function should only be used by widget implementations in
12922 * order to figure whether the widget's requisition has actually
12923 * changed after some internal state change (so that they can call
12924 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12926 * Normally, gtk_widget_size_request() should be used.
12930 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12931 * removed, If you need to cache sizes across requests and allocations,
12932 * add an explicit cache to the widget in question instead.
12935 gtk_widget_get_requisition (GtkWidget *widget,
12936 GtkRequisition *requisition)
12938 g_return_if_fail (GTK_IS_WIDGET (widget));
12939 g_return_if_fail (requisition != NULL);
12941 gtk_widget_get_preferred_size (widget, requisition, NULL);
12945 * gtk_widget_set_window:
12946 * @widget: a #GtkWidget
12947 * @window: a #GdkWindow
12949 * Sets a widget's window. This function should only be used in a
12950 * widget's GtkWidget::realize() implementation. The %window passed is
12951 * usually either new window created with gdk_window_new(), or the
12952 * window of its parent widget as returned by
12953 * gtk_widget_get_parent_window().
12955 * Widgets must indicate whether they will create their own #GdkWindow
12956 * by calling gtk_widget_set_has_window(). This is usually done in the
12957 * widget's init() function.
12959 * <note><para>This function does not add any reference to @window.</para></note>
12964 gtk_widget_set_window (GtkWidget *widget,
12967 GtkWidgetPrivate *priv;
12969 g_return_if_fail (GTK_IS_WIDGET (widget));
12970 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12972 priv = widget->priv;
12974 if (priv->window != window)
12976 priv->window = window;
12977 g_object_notify (G_OBJECT (widget), "window");
12982 * gtk_widget_get_window:
12983 * @widget: a #GtkWidget
12985 * Returns the widget's window if it is realized, %NULL otherwise
12987 * Return value: (transfer none): @widget's window.
12992 gtk_widget_get_window (GtkWidget *widget)
12994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12996 return widget->priv->window;
13000 * gtk_widget_get_support_multidevice:
13001 * @widget: a #GtkWidget
13003 * Returns %TRUE if @widget is multiple pointer aware. See
13004 * gtk_widget_set_support_multidevice() for more information.
13006 * Returns: %TRUE is @widget is multidevice aware.
13009 gtk_widget_get_support_multidevice (GtkWidget *widget)
13011 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13013 return widget->priv->multidevice;
13017 * gtk_widget_set_support_multidevice:
13018 * @widget: a #GtkWidget
13019 * @support_multidevice: %TRUE to support input from multiple devices.
13021 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
13022 * @widget will start receiving multiple, per device enter/leave events. Note
13023 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
13024 * gdk_window_set_support_multidevice() will have to be called manually on them.
13029 gtk_widget_set_support_multidevice (GtkWidget *widget,
13030 gboolean support_multidevice)
13032 GtkWidgetPrivate *priv;
13034 g_return_if_fail (GTK_IS_WIDGET (widget));
13036 priv = widget->priv;
13038 if (support_multidevice)
13040 priv->multidevice = TRUE;
13041 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
13045 priv->multidevice = FALSE;
13046 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
13049 if (gtk_widget_get_realized (widget))
13050 gdk_window_set_support_multidevice (priv->window, support_multidevice);
13054 _gtk_widget_set_has_focus (GtkWidget *widget,
13055 gboolean has_focus)
13057 widget->priv->has_focus = has_focus;
13061 * gtk_widget_send_focus_change:
13062 * @widget: a #GtkWidget
13063 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
13065 * Sends the focus change @event to @widget
13067 * This function is not meant to be used by applications. The only time it
13068 * should be used is when it is necessary for a #GtkWidget to assign focus
13069 * to a widget that is semantically owned by the first widget even though
13070 * it's not a direct child - for instance, a search entry in a floating
13071 * window similar to the quick search in #GtkTreeView.
13073 * An example of its usage is:
13076 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
13078 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
13079 * fevent->focus_change.in = TRUE;
13080 * fevent->focus_change.window = gtk_widget_get_window (widget);
13081 * if (fevent->focus_change.window != NULL)
13082 * g_object_ref (fevent->focus_change.window);
13084 * gtk_widget_send_focus_change (widget, fevent);
13086 * gdk_event_free (event);
13089 * Return value: the return value from the event signal emission: %TRUE
13090 * if the event was handled, and %FALSE otherwise
13095 gtk_widget_send_focus_change (GtkWidget *widget,
13100 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
13101 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
13103 g_object_ref (widget);
13105 _gtk_widget_set_has_focus (widget, event->focus_change.in);
13107 res = gtk_widget_event (widget, event);
13109 g_object_notify (G_OBJECT (widget), "has-focus");
13111 g_object_unref (widget);
13117 gtk_widget_in_destruction (GtkWidget *widget)
13119 return widget->priv->in_destruction;
13123 _gtk_widget_get_resize_pending (GtkWidget *widget)
13125 return widget->priv->resize_pending;
13129 _gtk_widget_set_resize_pending (GtkWidget *widget,
13130 gboolean resize_pending)
13132 widget->priv->resize_pending = resize_pending;
13136 _gtk_widget_get_in_reparent (GtkWidget *widget)
13138 return widget->priv->in_reparent;
13142 _gtk_widget_set_in_reparent (GtkWidget *widget,
13143 gboolean in_reparent)
13145 widget->priv->in_reparent = in_reparent;
13149 _gtk_widget_get_anchored (GtkWidget *widget)
13151 return widget->priv->anchored;
13155 _gtk_widget_set_anchored (GtkWidget *widget,
13158 widget->priv->anchored = anchored;
13162 _gtk_widget_get_shadowed (GtkWidget *widget)
13164 return widget->priv->shadowed;
13168 _gtk_widget_set_shadowed (GtkWidget *widget,
13171 widget->priv->shadowed = shadowed;
13175 _gtk_widget_get_alloc_needed (GtkWidget *widget)
13177 return widget->priv->alloc_needed;
13181 _gtk_widget_set_alloc_needed (GtkWidget *widget,
13182 gboolean alloc_needed)
13184 widget->priv->alloc_needed = alloc_needed;
13188 _gtk_widget_get_width_request_needed (GtkWidget *widget)
13190 return widget->priv->width_request_needed;
13194 _gtk_widget_set_width_request_needed (GtkWidget *widget,
13195 gboolean width_request_needed)
13197 widget->priv->width_request_needed = width_request_needed;
13201 _gtk_widget_get_height_request_needed (GtkWidget *widget)
13203 return widget->priv->height_request_needed;
13207 _gtk_widget_set_height_request_needed (GtkWidget *widget,
13208 gboolean height_request_needed)
13210 widget->priv->height_request_needed = height_request_needed;