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.h"
44 #include "gtkwidget.h"
45 #include "gtkwindow.h"
46 #include "gtkbindings.h"
47 #include "gtkprivate.h"
49 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
50 #include <gobject/gvaluecollector.h>
51 #include <gobject/gobjectnotifyqueue.c>
52 #include <cairo-gobject.h>
53 #include "gdk/gdkkeysyms.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
65 * @Short_description: Base class for all widgets
68 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
69 * widget lifecycle, states and style.
72 * <title>Height-for-width Geometry Management</title>
74 * GTK+ uses a height-for-width (and width-for-height) geometry management system.
75 * Height-for-width means that a widget can change how much vertical space it needs,
76 * depending on the amount of horizontal space that it is given (and similar for
77 * width-for-height). The most common example is a label that reflows to fill up the
78 * available width, wraps to fewer lines, and therefore needs less height.
80 * GTK+'s traditional two-pass <link linkend="size-allocation">size-allocation</link>
81 * algorithm does not allow this flexibility. #GtkWidget provides a default
82 * implementation of the height-for-width methods for existing widgets,
83 * which always requests the same height, regardless of the available width.
85 * Some important things to keep in mind when implementing
86 * height-for-width and when using it in container
89 * The geometry management system will query a logical hierarchy in
90 * only one orientation at a time. When widgets are initially queried
91 * for their minimum sizes it is generally done in a dual pass
92 * in the direction chosen by the toplevel.
94 * For instance when queried in the normal height-for-width mode:
95 * First the default minimum and natural width for each widget
96 * in the interface will computed and collectively returned to
97 * the toplevel by way of gtk_widget_get_preferred_width().
98 * Next, the toplevel will use the minimum width to query for the
99 * minimum height contextual to that width using
100 * gtk_widget_get_preferred_height_for_width(), which will also
101 * be a highly recursive operation. This minimum-for-minimum size can
102 * be used to set the minimum size constraint on the toplevel.
104 * When allocating, each container can use the minimum and natural
105 * sizes reported by their children to allocate natural sizes and
106 * expose as much content as possible with the given allocation.
108 * That means that the request operation at allocation time will
109 * usually fire again in contexts of different allocated sizes than
110 * the ones originally queried for. #GtkWidget caches a
111 * small number of results to avoid re-querying for the same
112 * allocated size in one allocation cycle.
114 * A widget that does not actually do height-for-width
115 * or width-for-height size negotiations only has to implement
116 * get_preferred_width() and get_preferred_height().
118 * If a widget does move content around to smartly use up the
119 * allocated size, then it must support the request properly in
120 * both orientations; even if the request only makes sense in
123 * For instance, a GtkLabel that does height-for-width word wrapping
124 * will not expect to have get_preferred_height() called because that
125 * call is specific to a width-for-height request. In this case the
126 * label must return the heights contextual to its minimum possible
127 * width. By following this rule any widget that handles height-for-width
128 * or width-for-height requests will always be allocated at least
129 * enough space to fit its own content.
131 * Often a widget needs to get its own request during size request or
132 * allocation, for example when computing height it may need to also
133 * compute width, or when deciding how to use an allocation the widget may
134 * need to know its natural size. In these cases, the widget should be
135 * careful to call its virtual methods directly, like this:
137 * <title>Widget calling its own size request method.</title>
139 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget), &min, &natural);
143 * It will not work to use the wrapper functions, such as
144 * gtk_widget_get_preferred_width(), inside your own size request
145 * implementation. These return a request adjusted by #GtkSizeGroup
146 * and by the GtkWidgetClass::adjust_size_request virtual method. If a
147 * widget used the wrappers inside its virtual method implementations,
148 * then the adjustments (such as widget margins) would be applied
149 * twice. GTK+ therefore does not allow this and will warn if you try
152 * Of course if you are getting the size request for
153 * <emphasis>another</emphasis> widget, such as a child of a
154 * container, you <emphasis>must</emphasis> use the wrapper APIs;
155 * otherwise, you would not properly consider widget margins,
156 * #GtkSizeGroup, and so forth.
159 * <refsect2 id="style-properties">
161 * <structname>GtkWidget</structname> introduces <firstterm>style
162 * properties</firstterm> - these are basically object properties that are stored
163 * not on the object, but in the style object associated to the widget. Style
164 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
165 * This mechanism is used for configuring such things as the location of the
166 * scrollbar arrows through the theme, giving theme authors more control over the
167 * look of applications without the need to write a theme engine in C.
170 * Use gtk_widget_class_install_style_property() to install style properties for
171 * a widget class, gtk_widget_class_find_style_property() or
172 * gtk_widget_class_list_style_properties() to get information about existing
173 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
174 * gtk_widget_style_get_valist() to obtain the value of a style property.
177 * <refsect2 id="GtkWidget-BUILDER-UI">
178 * <title>GtkWidget as GtkBuildable</title>
180 * The GtkWidget implementation of the GtkBuildable interface supports a
181 * custom <accelerator> element, which has attributes named key,
182 * modifiers and signal and allows to specify accelerators.
185 * <title>A UI definition fragment specifying an accelerator</title>
186 * <programlisting><![CDATA[
187 * <object class="GtkButton">
188 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
190 * ]]></programlisting>
193 * In addition to accelerators, <structname>GtkWidget</structname> also support a
194 * custom <accessible> element, which supports actions and relations.
195 * Properties on the accessible implementation of an object can be set by accessing the
196 * internal child "accessible" of a <structname>GtkWidget</structname>.
199 * <title>A UI definition fragment specifying an accessible</title>
200 * <programlisting><![CDATA[
201 * <object class="GtkButton" id="label1"/>
202 * <property name="label">I am a Label for a Button</property>
204 * <object class="GtkButton" id="button1">
206 * <action action_name="click" translatable="yes">Click the button.</action>
207 * <relation target="label1" type="labelled-by"/>
209 * <child internal-child="accessible">
210 * <object class="AtkObject" id="a11y-button1">
211 * <property name="AtkObject::name">Clickable Button</property>
215 * ]]></programlisting>
220 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
221 #define INIT_PATH_SIZE (512)
223 struct _GtkWidgetPrivate
225 /* The state of the widget. There are actually only
226 * 5 widget states (defined in "gtkenums.h")
231 /* The saved state of the widget. When a widget's state
232 * is changed to GTK_STATE_INSENSITIVE via
233 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
234 * the old state is kept around in this field. The state
235 * will be restored once the widget gets sensitive again.
237 guint saved_state : 3;
241 guint in_destruction : 1;
244 guint composite_child : 1;
250 guint parent_sensitive : 1;
253 guint can_default : 1;
254 guint has_default : 1;
255 guint receives_default : 1;
259 guint user_style : 1;
260 guint app_paintable : 1;
261 guint double_buffered : 1;
262 guint redraw_on_alloc : 1;
263 guint no_show_all : 1;
264 guint child_visible : 1;
265 guint multidevice : 1;
266 guint has_shape_mask : 1;
267 guint in_reparent : 1;
268 guint resize_pending : 1;
269 guint alloc_needed : 1;
270 guint width_request_needed : 1;
271 guint height_request_needed : 1;
273 /* The widget's name. If the widget does not have a name
274 * (the name is NULL), then its name (as returned by
275 * "gtk_widget_get_name") is its class's name.
276 * Among other things, the widget name is used to determine
277 * the style to use for a widget.
281 /* The style for the widget. The style contains the
282 * colors the widget should be drawn in for each state
283 * along with graphics contexts used to draw with and
284 * the font to use for text.
288 /* The widget's allocated size.
290 GtkAllocation allocation;
292 /* The widget's requested sizes */
293 SizeRequestCache requests;
295 /* The widget's window or its parent window if it does
296 * not have a window. (Which will be indicated by the
297 * GTK_NO_WINDOW flag being set).
301 /* The widget's parent.
331 BUTTON_RELEASE_EVENT,
346 PROPERTY_NOTIFY_EVENT,
347 SELECTION_CLEAR_EVENT,
348 SELECTION_REQUEST_EVENT,
349 SELECTION_NOTIFY_EVENT,
364 VISIBILITY_NOTIFY_EVENT,
368 ACCEL_CLOSURES_CHANGED,
394 PROP_RECEIVES_DEFAULT,
395 PROP_COMPOSITE_CHILD,
398 PROP_EXTENSION_EVENTS,
404 PROP_DOUBLE_BUFFERED,
414 typedef struct _GtkStateData GtkStateData;
419 guint state_restoration : 1;
420 guint parent_sensitive : 1;
421 guint use_forall : 1;
424 /* --- prototypes --- */
425 static void gtk_widget_class_init (GtkWidgetClass *klass);
426 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
427 static void gtk_widget_init (GtkWidget *widget);
428 static void gtk_widget_set_property (GObject *object,
432 static void gtk_widget_get_property (GObject *object,
436 static void gtk_widget_dispose (GObject *object);
437 static void gtk_widget_real_destroy (GtkWidget *object);
438 static void gtk_widget_finalize (GObject *object);
439 static void gtk_widget_real_show (GtkWidget *widget);
440 static void gtk_widget_real_hide (GtkWidget *widget);
441 static void gtk_widget_real_map (GtkWidget *widget);
442 static void gtk_widget_real_unmap (GtkWidget *widget);
443 static void gtk_widget_real_realize (GtkWidget *widget);
444 static void gtk_widget_real_unrealize (GtkWidget *widget);
445 static void gtk_widget_real_size_request (GtkWidget *widget,
446 GtkRequisition *requisition);
447 static void gtk_widget_real_size_allocate (GtkWidget *widget,
448 GtkAllocation *allocation);
449 static void gtk_widget_real_style_set (GtkWidget *widget,
450 GtkStyle *previous_style);
451 static void gtk_widget_real_direction_changed(GtkWidget *widget,
452 GtkTextDirection previous_direction);
454 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
455 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
458 gboolean keyboard_tip,
459 GtkTooltip *tooltip);
460 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
461 GtkWidgetHelpType help_type);
463 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
465 GParamSpec **pspecs);
466 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
468 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
470 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
471 GdkEventFocus *event);
472 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
473 GdkEventFocus *event);
474 static gboolean gtk_widget_real_focus (GtkWidget *widget,
475 GtkDirectionType direction);
476 static void gtk_widget_real_move_focus (GtkWidget *widget,
477 GtkDirectionType direction);
478 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
479 GtkDirectionType direction);
480 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
481 static void gtk_widget_update_pango_context (GtkWidget *widget);
482 static void gtk_widget_propagate_state (GtkWidget *widget,
484 static void gtk_widget_reset_rc_style (GtkWidget *widget);
485 static void gtk_widget_set_style_internal (GtkWidget *widget,
487 gboolean initial_emission);
488 static gint gtk_widget_event_internal (GtkWidget *widget,
490 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
491 gboolean group_cycling);
492 static void gtk_widget_real_get_width (GtkWidget *widget,
495 static void gtk_widget_real_get_height (GtkWidget *widget,
498 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
500 gint *minimum_height,
501 gint *natural_height);
502 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
505 gint *natural_width);
506 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
507 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
508 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
509 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
510 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
511 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
512 cairo_region_t *region);
513 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
514 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
515 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
518 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
519 gboolean has_tooltip,
521 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
522 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
524 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
525 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
527 const gchar *childname);
528 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
531 const GValue *value);
532 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
535 const gchar *tagname,
536 GMarkupParser *parser,
538 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
541 const gchar *tagname,
543 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
544 GtkBuilder *builder);
546 static void gtk_widget_real_get_width (GtkWidget *widget,
549 static void gtk_widget_real_get_height (GtkWidget *widget,
553 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
556 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
557 GtkOrientation orientation,
561 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
562 GtkAllocation *allocation);
564 static void gtk_widget_set_usize_internal (GtkWidget *widget,
568 static void gtk_widget_add_events_internal (GtkWidget *widget,
572 /* --- variables --- */
573 static gpointer gtk_widget_parent_class = NULL;
574 static guint widget_signals[LAST_SIGNAL] = { 0 };
575 static GtkStyle *gtk_default_style = NULL;
576 static guint composite_child_stack = 0;
577 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
578 static GParamSpecPool *style_property_spec_pool = NULL;
580 static GQuark quark_property_parser = 0;
581 static GQuark quark_aux_info = 0;
582 static GQuark quark_accel_path = 0;
583 static GQuark quark_accel_closures = 0;
584 static GQuark quark_event_mask = 0;
585 static GQuark quark_device_event_mask = 0;
586 static GQuark quark_extension_event_mode = 0;
587 static GQuark quark_parent_window = 0;
588 static GQuark quark_pointer_window = 0;
589 static GQuark quark_shape_info = 0;
590 static GQuark quark_input_shape_info = 0;
591 static GQuark quark_pango_context = 0;
592 static GQuark quark_rc_style = 0;
593 static GQuark quark_accessible_object = 0;
594 static GQuark quark_mnemonic_labels = 0;
595 static GQuark quark_tooltip_markup = 0;
596 static GQuark quark_has_tooltip = 0;
597 static GQuark quark_tooltip_window = 0;
598 static GQuark quark_visual = 0;
599 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
600 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
602 /* --- functions --- */
604 gtk_widget_get_type (void)
606 static GType widget_type = 0;
608 if (G_UNLIKELY (widget_type == 0))
610 const GTypeInfo widget_info =
612 sizeof (GtkWidgetClass),
613 NULL, /* base_init */
614 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
615 (GClassInitFunc) gtk_widget_class_init,
616 NULL, /* class_finalize */
617 NULL, /* class_init */
620 (GInstanceInitFunc) gtk_widget_init,
621 NULL, /* value_table */
624 const GInterfaceInfo accessibility_info =
626 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
627 (GInterfaceFinalizeFunc) NULL,
628 NULL /* interface data */
631 const GInterfaceInfo buildable_info =
633 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
634 (GInterfaceFinalizeFunc) NULL,
635 NULL /* interface data */
638 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
639 &widget_info, G_TYPE_FLAG_ABSTRACT);
641 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
642 &accessibility_info) ;
643 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
651 child_property_notify_dispatcher (GObject *object,
655 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
658 /* We guard against the draw signal callbacks modifying the state of the
659 * cairo context by surounding it with save/restore.
660 * Maybe we should also cairo_new_path() just to be sure?
663 gtk_widget_draw_marshaller (GClosure *closure,
664 GValue *return_value,
665 guint n_param_values,
666 const GValue *param_values,
667 gpointer invocation_hint,
668 gpointer marshal_data)
670 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
674 _gtk_marshal_BOOLEAN__BOXED (closure,
685 gtk_widget_class_init (GtkWidgetClass *klass)
687 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
688 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
689 GtkBindingSet *binding_set;
691 gtk_widget_parent_class = g_type_class_peek_parent (klass);
693 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
694 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
695 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
696 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
697 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
698 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
699 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
700 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
701 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
702 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
703 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
704 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
705 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
706 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
707 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
708 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
709 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
710 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
711 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
713 style_property_spec_pool = g_param_spec_pool_new (FALSE);
714 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
715 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
716 cpn_context.dispatcher = child_property_notify_dispatcher;
717 _gtk_widget_child_property_notify_context = &cpn_context;
719 gobject_class->dispose = gtk_widget_dispose;
720 gobject_class->finalize = gtk_widget_finalize;
721 gobject_class->set_property = gtk_widget_set_property;
722 gobject_class->get_property = gtk_widget_get_property;
724 klass->destroy = gtk_widget_real_destroy;
726 klass->activate_signal = 0;
727 klass->set_scroll_adjustments_signal = 0;
728 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
729 klass->show = gtk_widget_real_show;
730 klass->show_all = gtk_widget_show;
731 klass->hide = gtk_widget_real_hide;
732 klass->hide_all = gtk_widget_hide;
733 klass->map = gtk_widget_real_map;
734 klass->unmap = gtk_widget_real_unmap;
735 klass->realize = gtk_widget_real_realize;
736 klass->unrealize = gtk_widget_real_unrealize;
737 klass->size_request = gtk_widget_real_size_request;
738 klass->size_allocate = gtk_widget_real_size_allocate;
739 klass->get_preferred_width = gtk_widget_real_get_width;
740 klass->get_preferred_height = gtk_widget_real_get_height;
741 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
742 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
743 klass->state_changed = NULL;
744 klass->parent_set = NULL;
745 klass->hierarchy_changed = NULL;
746 klass->style_set = gtk_widget_real_style_set;
747 klass->direction_changed = gtk_widget_real_direction_changed;
748 klass->grab_notify = NULL;
749 klass->child_notify = NULL;
751 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
752 klass->grab_focus = gtk_widget_real_grab_focus;
753 klass->focus = gtk_widget_real_focus;
755 klass->button_press_event = NULL;
756 klass->button_release_event = NULL;
757 klass->motion_notify_event = NULL;
758 klass->delete_event = NULL;
759 klass->destroy_event = NULL;
760 klass->key_press_event = gtk_widget_real_key_press_event;
761 klass->key_release_event = gtk_widget_real_key_release_event;
762 klass->enter_notify_event = NULL;
763 klass->leave_notify_event = NULL;
764 klass->configure_event = NULL;
765 klass->focus_in_event = gtk_widget_real_focus_in_event;
766 klass->focus_out_event = gtk_widget_real_focus_out_event;
767 klass->map_event = NULL;
768 klass->unmap_event = NULL;
769 klass->window_state_event = NULL;
770 klass->property_notify_event = _gtk_selection_property_notify;
771 klass->selection_clear_event = _gtk_selection_clear;
772 klass->selection_request_event = _gtk_selection_request;
773 klass->selection_notify_event = _gtk_selection_notify;
774 klass->selection_received = NULL;
775 klass->proximity_in_event = NULL;
776 klass->proximity_out_event = NULL;
777 klass->drag_begin = NULL;
778 klass->drag_end = NULL;
779 klass->drag_data_delete = NULL;
780 klass->drag_leave = NULL;
781 klass->drag_motion = NULL;
782 klass->drag_drop = NULL;
783 klass->drag_data_received = NULL;
784 klass->screen_changed = NULL;
785 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
786 klass->grab_broken_event = NULL;
787 klass->query_tooltip = gtk_widget_real_query_tooltip;
789 klass->show_help = gtk_widget_real_show_help;
791 /* Accessibility support */
792 klass->get_accessible = gtk_widget_real_get_accessible;
794 klass->no_expose_event = NULL;
796 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
797 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
799 g_object_class_install_property (gobject_class,
801 g_param_spec_string ("name",
803 P_("The name of the widget"),
805 GTK_PARAM_READWRITE));
806 g_object_class_install_property (gobject_class,
808 g_param_spec_object ("parent",
810 P_("The parent widget of this widget. Must be a Container widget"),
812 GTK_PARAM_READWRITE));
814 g_object_class_install_property (gobject_class,
816 g_param_spec_int ("width-request",
818 P_("Override for width request of the widget, or -1 if natural request should be used"),
822 GTK_PARAM_READWRITE));
823 g_object_class_install_property (gobject_class,
825 g_param_spec_int ("height-request",
826 P_("Height request"),
827 P_("Override for height request of the widget, or -1 if natural request should be used"),
831 GTK_PARAM_READWRITE));
832 g_object_class_install_property (gobject_class,
834 g_param_spec_boolean ("visible",
836 P_("Whether the widget is visible"),
838 GTK_PARAM_READWRITE));
839 g_object_class_install_property (gobject_class,
841 g_param_spec_boolean ("sensitive",
843 P_("Whether the widget responds to input"),
845 GTK_PARAM_READWRITE));
846 g_object_class_install_property (gobject_class,
848 g_param_spec_boolean ("app-paintable",
849 P_("Application paintable"),
850 P_("Whether the application will paint directly on the widget"),
852 GTK_PARAM_READWRITE));
853 g_object_class_install_property (gobject_class,
855 g_param_spec_boolean ("can-focus",
857 P_("Whether the widget can accept the input focus"),
859 GTK_PARAM_READWRITE));
860 g_object_class_install_property (gobject_class,
862 g_param_spec_boolean ("has-focus",
864 P_("Whether the widget has the input focus"),
866 GTK_PARAM_READWRITE));
867 g_object_class_install_property (gobject_class,
869 g_param_spec_boolean ("is-focus",
871 P_("Whether the widget is the focus widget within the toplevel"),
873 GTK_PARAM_READWRITE));
874 g_object_class_install_property (gobject_class,
876 g_param_spec_boolean ("can-default",
878 P_("Whether the widget can be the default widget"),
880 GTK_PARAM_READWRITE));
881 g_object_class_install_property (gobject_class,
883 g_param_spec_boolean ("has-default",
885 P_("Whether the widget is the default widget"),
887 GTK_PARAM_READWRITE));
888 g_object_class_install_property (gobject_class,
889 PROP_RECEIVES_DEFAULT,
890 g_param_spec_boolean ("receives-default",
891 P_("Receives default"),
892 P_("If TRUE, the widget will receive the default action when it is focused"),
894 GTK_PARAM_READWRITE));
895 g_object_class_install_property (gobject_class,
896 PROP_COMPOSITE_CHILD,
897 g_param_spec_boolean ("composite-child",
898 P_("Composite child"),
899 P_("Whether the widget is part of a composite widget"),
901 GTK_PARAM_READABLE));
902 g_object_class_install_property (gobject_class,
904 g_param_spec_object ("style",
906 P_("The style of the widget, which contains information about how it will look (colors etc)"),
908 GTK_PARAM_READWRITE));
909 g_object_class_install_property (gobject_class,
911 g_param_spec_flags ("events",
913 P_("The event mask that decides what kind of GdkEvents this widget gets"),
916 GTK_PARAM_READWRITE));
917 g_object_class_install_property (gobject_class,
918 PROP_EXTENSION_EVENTS,
919 g_param_spec_enum ("extension-events",
920 P_("Extension events"),
921 P_("The mask that decides what kind of extension events this widget gets"),
922 GDK_TYPE_EXTENSION_MODE,
923 GDK_EXTENSION_EVENTS_NONE,
924 GTK_PARAM_READWRITE));
925 g_object_class_install_property (gobject_class,
927 g_param_spec_boolean ("no-show-all",
929 P_("Whether gtk_widget_show_all() should not affect this widget"),
931 GTK_PARAM_READWRITE));
934 * GtkWidget:has-tooltip:
936 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
937 * A value of %TRUE indicates that @widget can have a tooltip, in this case
938 * the widget will be queried using #GtkWidget::query-tooltip to determine
939 * whether it will provide a tooltip or not.
941 * Note that setting this property to %TRUE for the first time will change
942 * the event masks of the GdkWindows of this widget to include leave-notify
943 * and motion-notify events. This cannot and will not be undone when the
944 * property is set to %FALSE again.
948 g_object_class_install_property (gobject_class,
950 g_param_spec_boolean ("has-tooltip",
952 P_("Whether this widget has a tooltip"),
954 GTK_PARAM_READWRITE));
956 * GtkWidget:tooltip-text:
958 * Sets the text of tooltip to be the given string.
960 * Also see gtk_tooltip_set_text().
962 * This is a convenience property which will take care of getting the
963 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
964 * will automatically be set to %TRUE and there will be taken care of
965 * #GtkWidget::query-tooltip in the default signal handler.
969 g_object_class_install_property (gobject_class,
971 g_param_spec_string ("tooltip-text",
973 P_("The contents of the tooltip for this widget"),
975 GTK_PARAM_READWRITE));
977 * GtkWidget:tooltip-markup:
979 * Sets the text of tooltip to be the given string, which is marked up
980 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
981 * Also see gtk_tooltip_set_markup().
983 * This is a convenience property which will take care of getting the
984 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
985 * will automatically be set to %TRUE and there will be taken care of
986 * #GtkWidget::query-tooltip in the default signal handler.
990 g_object_class_install_property (gobject_class,
992 g_param_spec_string ("tooltip-markup",
993 P_("Tooltip markup"),
994 P_("The contents of the tooltip for this widget"),
996 GTK_PARAM_READWRITE));
1001 * The widget's window if it is realized, %NULL otherwise.
1005 g_object_class_install_property (gobject_class,
1007 g_param_spec_object ("window",
1009 P_("The widget's window if it is realized"),
1011 GTK_PARAM_READABLE));
1014 * GtkWidget:double-buffered
1016 * Whether the widget is double buffered.
1020 g_object_class_install_property (gobject_class,
1021 PROP_DOUBLE_BUFFERED,
1022 g_param_spec_boolean ("double-buffered",
1023 P_("Double Buffered"),
1024 P_("Whether the widget is double buffered"),
1026 GTK_PARAM_READWRITE));
1031 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1035 g_object_class_install_property (gobject_class,
1037 g_param_spec_enum ("halign",
1038 P_("Horizontal Alignment"),
1039 P_("How to position in extra horizontal space"),
1042 GTK_PARAM_READWRITE));
1047 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1051 g_object_class_install_property (gobject_class,
1053 g_param_spec_enum ("valign",
1054 P_("Vertical Alignment"),
1055 P_("How to position in extra vertical space"),
1058 GTK_PARAM_READWRITE));
1061 * GtkWidget:margin-left
1063 * Margin on left side of widget.
1065 * This property adds margin outside of the widget's normal size
1066 * request, the margin will be added in addition to the size from
1067 * gtk_widget_set_size_request() for example.
1071 g_object_class_install_property (gobject_class,
1073 g_param_spec_int ("margin-left",
1074 P_("Margin on Left"),
1075 P_("Pixels of extra space on the left side"),
1079 GTK_PARAM_READWRITE));
1082 * GtkWidget:margin-right
1084 * Margin on right side of widget.
1086 * This property adds margin outside of the widget's normal size
1087 * request, the margin will be added in addition to the size from
1088 * gtk_widget_set_size_request() for example.
1092 g_object_class_install_property (gobject_class,
1094 g_param_spec_int ("margin-right",
1095 P_("Margin on Right"),
1096 P_("Pixels of extra space on the right side"),
1100 GTK_PARAM_READWRITE));
1103 * GtkWidget:margin-top
1105 * Margin on top side of widget.
1107 * This property adds margin outside of the widget's normal size
1108 * request, the margin will be added in addition to the size from
1109 * gtk_widget_set_size_request() for example.
1113 g_object_class_install_property (gobject_class,
1115 g_param_spec_int ("margin-top",
1116 P_("Margin on Top"),
1117 P_("Pixels of extra space on the top side"),
1121 GTK_PARAM_READWRITE));
1124 * GtkWidget:margin-bottom
1126 * Margin on bottom side of widget.
1128 * This property adds margin outside of the widget's normal size
1129 * request, the margin will be added in addition to the size from
1130 * gtk_widget_set_size_request() for example.
1134 g_object_class_install_property (gobject_class,
1136 g_param_spec_int ("margin-bottom",
1137 P_("Margin on Bottom"),
1138 P_("Pixels of extra space on the bottom side"),
1142 GTK_PARAM_READWRITE));
1147 * Sets all four sides' margin at once. If read, returns max
1148 * margin on any side.
1152 g_object_class_install_property (gobject_class,
1154 g_param_spec_int ("margin",
1156 P_("Pixels of extra space on all four sides"),
1160 GTK_PARAM_READWRITE));
1163 * GtkWidget::destroy:
1164 * @object: the object which received the signal
1166 * Signals that all holders of a reference to the widget should release
1167 * the reference that they hold. May result in finalization of the widget
1168 * if all references are released.
1170 widget_signals[DESTROY] =
1171 g_signal_new (I_("destroy"),
1172 G_TYPE_FROM_CLASS (gobject_class),
1173 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1174 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1176 _gtk_marshal_VOID__VOID,
1181 * @widget: the object which received the signal.
1183 widget_signals[SHOW] =
1184 g_signal_new (I_("show"),
1185 G_TYPE_FROM_CLASS (gobject_class),
1187 G_STRUCT_OFFSET (GtkWidgetClass, show),
1189 _gtk_marshal_VOID__VOID,
1194 * @widget: the object which received the signal.
1196 widget_signals[HIDE] =
1197 g_signal_new (I_("hide"),
1198 G_TYPE_FROM_CLASS (gobject_class),
1200 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1202 _gtk_marshal_VOID__VOID,
1207 * @widget: the object which received the signal.
1209 widget_signals[MAP] =
1210 g_signal_new (I_("map"),
1211 G_TYPE_FROM_CLASS (gobject_class),
1213 G_STRUCT_OFFSET (GtkWidgetClass, map),
1215 _gtk_marshal_VOID__VOID,
1220 * @widget: the object which received the signal.
1222 widget_signals[UNMAP] =
1223 g_signal_new (I_("unmap"),
1224 G_TYPE_FROM_CLASS (gobject_class),
1226 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1228 _gtk_marshal_VOID__VOID,
1232 * GtkWidget::realize:
1233 * @widget: the object which received the signal.
1235 widget_signals[REALIZE] =
1236 g_signal_new (I_("realize"),
1237 G_TYPE_FROM_CLASS (gobject_class),
1239 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1241 _gtk_marshal_VOID__VOID,
1245 * GtkWidget::unrealize:
1246 * @widget: the object which received the signal.
1248 widget_signals[UNREALIZE] =
1249 g_signal_new (I_("unrealize"),
1250 G_TYPE_FROM_CLASS (gobject_class),
1252 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1254 _gtk_marshal_VOID__VOID,
1258 * GtkWidget::size-request:
1259 * @widget: the object which received the signal.
1262 widget_signals[SIZE_REQUEST] =
1263 g_signal_new (I_("size-request"),
1264 G_TYPE_FROM_CLASS (gobject_class),
1266 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1268 _gtk_marshal_VOID__BOXED,
1270 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1273 * GtkWidget::size-allocate:
1274 * @widget: the object which received the signal.
1277 widget_signals[SIZE_ALLOCATE] =
1278 g_signal_new (I_("size-allocate"),
1279 G_TYPE_FROM_CLASS (gobject_class),
1281 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1283 _gtk_marshal_VOID__BOXED,
1285 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1288 * GtkWidget::state-changed:
1289 * @widget: the object which received the signal.
1290 * @state: the previous state
1292 * The ::state-changed signal is emitted when the widget state changes.
1293 * See gtk_widget_get_state().
1295 widget_signals[STATE_CHANGED] =
1296 g_signal_new (I_("state-changed"),
1297 G_TYPE_FROM_CLASS (gobject_class),
1299 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1301 _gtk_marshal_VOID__ENUM,
1303 GTK_TYPE_STATE_TYPE);
1306 * GtkWidget::parent-set:
1307 * @widget: the object on which the signal is emitted
1308 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1309 * just got its initial parent.
1311 * The ::parent-set signal is emitted when a new parent
1312 * has been set on a widget.
1314 widget_signals[PARENT_SET] =
1315 g_signal_new (I_("parent-set"),
1316 G_TYPE_FROM_CLASS (gobject_class),
1318 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1320 _gtk_marshal_VOID__OBJECT,
1325 * GtkWidget::hierarchy-changed:
1326 * @widget: the object on which the signal is emitted
1327 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1328 * if the widget was previously unanchored
1330 * The ::hierarchy-changed signal is emitted when the
1331 * anchored state of a widget changes. A widget is
1332 * <firstterm>anchored</firstterm> when its toplevel
1333 * ancestor is a #GtkWindow. This signal is emitted when
1334 * a widget changes from un-anchored to anchored or vice-versa.
1336 widget_signals[HIERARCHY_CHANGED] =
1337 g_signal_new (I_("hierarchy-changed"),
1338 G_TYPE_FROM_CLASS (gobject_class),
1340 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1342 _gtk_marshal_VOID__OBJECT,
1347 * GtkWidget::style-set:
1348 * @widget: the object on which the signal is emitted
1349 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1350 * just got its initial style
1352 * The ::style-set signal is emitted when a new style has been set
1353 * on a widget. Note that style-modifying functions like
1354 * gtk_widget_modify_base() also cause this signal to be emitted.
1356 widget_signals[STYLE_SET] =
1357 g_signal_new (I_("style-set"),
1358 G_TYPE_FROM_CLASS (gobject_class),
1360 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1362 _gtk_marshal_VOID__OBJECT,
1367 * GtkWidget::direction-changed:
1368 * @widget: the object on which the signal is emitted
1369 * @previous_direction: the previous text direction of @widget
1371 * The ::direction-changed signal is emitted when the text direction
1372 * of a widget changes.
1374 widget_signals[DIRECTION_CHANGED] =
1375 g_signal_new (I_("direction-changed"),
1376 G_TYPE_FROM_CLASS (gobject_class),
1378 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1380 _gtk_marshal_VOID__ENUM,
1382 GTK_TYPE_TEXT_DIRECTION);
1385 * GtkWidget::grab-notify:
1386 * @widget: the object which received the signal
1387 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1388 * if it becomes unshadowed
1390 * The ::grab-notify signal is emitted when a widget becomes
1391 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1392 * another widget, or when it becomes unshadowed due to a grab
1395 * A widget is shadowed by a gtk_grab_add() when the topmost
1396 * grab widget in the grab stack of its window group is not
1399 widget_signals[GRAB_NOTIFY] =
1400 g_signal_new (I_("grab-notify"),
1401 G_TYPE_FROM_CLASS (gobject_class),
1403 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1405 _gtk_marshal_VOID__BOOLEAN,
1410 * GtkWidget::child-notify:
1411 * @widget: the object which received the signal
1412 * @pspec: the #GParamSpec of the changed child property
1414 * The ::child-notify signal is emitted for each
1415 * <link linkend="child-properties">child property</link> that has
1416 * changed on an object. The signal's detail holds the property name.
1418 widget_signals[CHILD_NOTIFY] =
1419 g_signal_new (I_("child-notify"),
1420 G_TYPE_FROM_CLASS (gobject_class),
1421 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1422 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1424 g_cclosure_marshal_VOID__PARAM,
1430 * @widget: the object which received the signal
1431 * @cr: the cairo context to draw to
1433 * This signal is emitted when a widget is supposed to render itself.
1434 * The @widget's top left corner must be painted at the origin of
1435 * the passed in context and be sized to the values returned by
1436 * gtk_widget_get_allocated_width() and
1437 * gtk_widget_get_allocated_height().
1439 * Signal handlers connected to this signal can modify the cairo
1440 * context passed as @cr in any way they like and don't need to
1441 * restore it. The signal emission takes care of calling cairo_save()
1442 * before and cairo_restore() after invoking the handler.
1444 widget_signals[DRAW] =
1445 g_signal_new (I_("draw"),
1446 G_TYPE_FROM_CLASS (gobject_class),
1448 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1449 _gtk_boolean_handled_accumulator, NULL,
1450 gtk_widget_draw_marshaller,
1452 CAIRO_GOBJECT_TYPE_CONTEXT);
1455 * GtkWidget::mnemonic-activate:
1456 * @widget: the object which received the signal.
1459 widget_signals[MNEMONIC_ACTIVATE] =
1460 g_signal_new (I_("mnemonic-activate"),
1461 G_TYPE_FROM_CLASS (gobject_class),
1463 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1464 _gtk_boolean_handled_accumulator, NULL,
1465 _gtk_marshal_BOOLEAN__BOOLEAN,
1470 * GtkWidget::grab-focus:
1471 * @widget: the object which received the signal.
1473 widget_signals[GRAB_FOCUS] =
1474 g_signal_new (I_("grab-focus"),
1475 G_TYPE_FROM_CLASS (gobject_class),
1476 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1477 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1479 _gtk_marshal_VOID__VOID,
1484 * @widget: the object which received the signal.
1487 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1489 widget_signals[FOCUS] =
1490 g_signal_new (I_("focus"),
1491 G_TYPE_FROM_CLASS (klass),
1493 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1494 _gtk_boolean_handled_accumulator, NULL,
1495 _gtk_marshal_BOOLEAN__ENUM,
1497 GTK_TYPE_DIRECTION_TYPE);
1500 * GtkWidget::move-focus:
1501 * @widget: the object which received the signal.
1504 widget_signals[MOVE_FOCUS] =
1505 g_signal_new_class_handler (I_("move-focus"),
1506 G_TYPE_FROM_CLASS (klass),
1507 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1508 G_CALLBACK (gtk_widget_real_move_focus),
1510 _gtk_marshal_VOID__ENUM,
1513 GTK_TYPE_DIRECTION_TYPE);
1517 * @widget: the object which received the signal.
1518 * @event: the #GdkEvent which triggered this signal
1520 * The GTK+ main loop will emit three signals for each GDK event delivered
1521 * to a widget: one generic ::event signal, another, more specific,
1522 * signal that matches the type of event delivered (e.g.
1523 * #GtkWidget::key-press-event) and finally a generic
1524 * #GtkWidget::event-after signal.
1526 * Returns: %TRUE to stop other handlers from being invoked for the event
1527 * and to cancel the emission of the second specific ::event signal.
1528 * %FALSE to propagate the event further and to allow the emission of
1529 * the second signal. The ::event-after signal is emitted regardless of
1532 widget_signals[EVENT] =
1533 g_signal_new (I_("event"),
1534 G_TYPE_FROM_CLASS (klass),
1536 G_STRUCT_OFFSET (GtkWidgetClass, event),
1537 _gtk_boolean_handled_accumulator, NULL,
1538 _gtk_marshal_BOOLEAN__BOXED,
1540 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1543 * GtkWidget::event-after:
1544 * @widget: the object which received the signal.
1545 * @event: the #GdkEvent which triggered this signal
1547 * After the emission of the #GtkWidget::event signal and (optionally)
1548 * the second more specific signal, ::event-after will be emitted
1549 * regardless of the previous two signals handlers return values.
1552 widget_signals[EVENT_AFTER] =
1553 g_signal_new (I_("event-after"),
1554 G_TYPE_FROM_CLASS (klass),
1558 _gtk_marshal_VOID__BOXED,
1560 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1563 * GtkWidget::button-press-event:
1564 * @widget: the object which received the signal.
1565 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1568 * The ::button-press-event signal will be emitted when a button
1569 * (typically from a mouse) is pressed.
1571 * To receive this signal, the #GdkWindow associated to the
1572 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1574 * This signal will be sent to the grab widget if there is one.
1576 * Returns: %TRUE to stop other handlers from being invoked for the event.
1577 * %FALSE to propagate the event further.
1579 widget_signals[BUTTON_PRESS_EVENT] =
1580 g_signal_new (I_("button-press-event"),
1581 G_TYPE_FROM_CLASS (klass),
1583 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1584 _gtk_boolean_handled_accumulator, NULL,
1585 _gtk_marshal_BOOLEAN__BOXED,
1587 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1590 * GtkWidget::button-release-event:
1591 * @widget: the object which received the signal.
1592 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1595 * The ::button-release-event signal will be emitted when a button
1596 * (typically from a mouse) is released.
1598 * To receive this signal, the #GdkWindow associated to the
1599 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1601 * This signal will be sent to the grab widget if there is one.
1603 * Returns: %TRUE to stop other handlers from being invoked for the event.
1604 * %FALSE to propagate the event further.
1606 widget_signals[BUTTON_RELEASE_EVENT] =
1607 g_signal_new (I_("button-release-event"),
1608 G_TYPE_FROM_CLASS (klass),
1610 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1611 _gtk_boolean_handled_accumulator, NULL,
1612 _gtk_marshal_BOOLEAN__BOXED,
1614 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1617 * GtkWidget::scroll-event:
1618 * @widget: the object which received the signal.
1619 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1622 * The ::scroll-event signal is emitted when a button in the 4 to 7
1623 * range is pressed. Wheel mice are usually configured to generate
1624 * button press events for buttons 4 and 5 when the wheel is turned.
1626 * To receive this signal, the #GdkWindow associated to the widget needs
1627 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1629 * This signal will be sent to the grab widget if there is one.
1631 * Returns: %TRUE to stop other handlers from being invoked for the event.
1632 * %FALSE to propagate the event further.
1634 widget_signals[SCROLL_EVENT] =
1635 g_signal_new (I_("scroll-event"),
1636 G_TYPE_FROM_CLASS (klass),
1638 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1639 _gtk_boolean_handled_accumulator, NULL,
1640 _gtk_marshal_BOOLEAN__BOXED,
1642 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1645 * GtkWidget::motion-notify-event:
1646 * @widget: the object which received the signal.
1647 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1650 * The ::motion-notify-event signal is emitted when the pointer moves
1651 * over the widget's #GdkWindow.
1653 * To receive this signal, the #GdkWindow associated to the widget
1654 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1656 * This signal will be sent to the grab widget if there is one.
1658 * Returns: %TRUE to stop other handlers from being invoked for the event.
1659 * %FALSE to propagate the event further.
1661 widget_signals[MOTION_NOTIFY_EVENT] =
1662 g_signal_new (I_("motion-notify-event"),
1663 G_TYPE_FROM_CLASS (klass),
1665 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1666 _gtk_boolean_handled_accumulator, NULL,
1667 _gtk_marshal_BOOLEAN__BOXED,
1669 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1672 * GtkWidget::composited-changed:
1673 * @widget: the object on which the signal is emitted
1675 * The ::composited-changed signal is emitted when the composited
1676 * status of @widget<!-- -->s screen changes.
1677 * See gdk_screen_is_composited().
1679 widget_signals[COMPOSITED_CHANGED] =
1680 g_signal_new (I_("composited-changed"),
1681 G_TYPE_FROM_CLASS (klass),
1682 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1683 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1685 _gtk_marshal_VOID__VOID,
1689 * GtkWidget::keynav-failed:
1690 * @widget: the object which received the signal
1691 * @direction: the direction of movement
1693 * Gets emitted if keyboard navigation fails.
1694 * See gtk_widget_keynav_failed() for details.
1696 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1697 * if the emitting widget should try to handle the keyboard
1698 * navigation attempt in its parent container(s).
1702 widget_signals[KEYNAV_FAILED] =
1703 g_signal_new_class_handler (I_("keynav-failed"),
1704 G_TYPE_FROM_CLASS (klass),
1706 G_CALLBACK (gtk_widget_real_keynav_failed),
1707 _gtk_boolean_handled_accumulator, NULL,
1708 _gtk_marshal_BOOLEAN__ENUM,
1710 GTK_TYPE_DIRECTION_TYPE);
1713 * GtkWidget::delete-event:
1714 * @widget: the object which received the signal
1715 * @event: the event which triggered this signal
1717 * The ::delete-event signal is emitted if a user requests that
1718 * a toplevel window is closed. The default handler for this signal
1719 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1720 * this signal will cause the window to be hidden instead, so that
1721 * it can later be shown again without reconstructing it.
1723 * Returns: %TRUE to stop other handlers from being invoked for the event.
1724 * %FALSE to propagate the event further.
1726 widget_signals[DELETE_EVENT] =
1727 g_signal_new (I_("delete-event"),
1728 G_TYPE_FROM_CLASS (klass),
1730 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1731 _gtk_boolean_handled_accumulator, NULL,
1732 _gtk_marshal_BOOLEAN__BOXED,
1734 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1737 * GtkWidget::destroy-event:
1738 * @widget: the object which received the signal.
1739 * @event: the event which triggered this signal
1741 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1742 * You rarely get this signal, because most widgets disconnect themselves
1743 * from their window before they destroy it, so no widget owns the
1744 * window at destroy time.
1746 * To receive this signal, the #GdkWindow associated to the widget needs
1747 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1748 * automatically for all new windows.
1750 * Returns: %TRUE to stop other handlers from being invoked for the event.
1751 * %FALSE to propagate the event further.
1753 widget_signals[DESTROY_EVENT] =
1754 g_signal_new (I_("destroy-event"),
1755 G_TYPE_FROM_CLASS (klass),
1757 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1758 _gtk_boolean_handled_accumulator, NULL,
1759 _gtk_marshal_BOOLEAN__BOXED,
1761 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1764 * GtkWidget::key-press-event:
1765 * @widget: the object which received the signal
1766 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1768 * The ::key-press-event signal is emitted when a key is pressed.
1770 * To receive this signal, the #GdkWindow associated to the widget needs
1771 * to enable the #GDK_KEY_PRESS_MASK mask.
1773 * This signal will be sent to the grab widget if there is one.
1775 * Returns: %TRUE to stop other handlers from being invoked for the event.
1776 * %FALSE to propagate the event further.
1778 widget_signals[KEY_PRESS_EVENT] =
1779 g_signal_new (I_("key-press-event"),
1780 G_TYPE_FROM_CLASS (klass),
1782 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1783 _gtk_boolean_handled_accumulator, NULL,
1784 _gtk_marshal_BOOLEAN__BOXED,
1786 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1789 * GtkWidget::key-release-event:
1790 * @widget: the object which received the signal
1791 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1793 * The ::key-release-event signal is emitted when a key is pressed.
1795 * To receive this signal, the #GdkWindow associated to the widget needs
1796 * to enable the #GDK_KEY_RELEASE_MASK mask.
1798 * This signal will be sent to the grab widget if there is one.
1800 * Returns: %TRUE to stop other handlers from being invoked for the event.
1801 * %FALSE to propagate the event further.
1803 widget_signals[KEY_RELEASE_EVENT] =
1804 g_signal_new (I_("key-release-event"),
1805 G_TYPE_FROM_CLASS (klass),
1807 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1808 _gtk_boolean_handled_accumulator, NULL,
1809 _gtk_marshal_BOOLEAN__BOXED,
1811 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1814 * GtkWidget::enter-notify-event:
1815 * @widget: the object which received the signal
1816 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1819 * The ::enter-notify-event will be emitted when the pointer enters
1820 * the @widget's window.
1822 * To receive this signal, the #GdkWindow associated to the widget needs
1823 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1825 * This signal will be sent to the grab widget if there is one.
1827 * Returns: %TRUE to stop other handlers from being invoked for the event.
1828 * %FALSE to propagate the event further.
1830 widget_signals[ENTER_NOTIFY_EVENT] =
1831 g_signal_new (I_("enter-notify-event"),
1832 G_TYPE_FROM_CLASS (klass),
1834 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1835 _gtk_boolean_handled_accumulator, NULL,
1836 _gtk_marshal_BOOLEAN__BOXED,
1838 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1841 * GtkWidget::leave-notify-event:
1842 * @widget: the object which received the signal
1843 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1846 * The ::leave-notify-event will be emitted when the pointer leaves
1847 * the @widget's window.
1849 * To receive this signal, the #GdkWindow associated to the widget needs
1850 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1852 * This signal will be sent to the grab widget if there is one.
1854 * Returns: %TRUE to stop other handlers from being invoked for the event.
1855 * %FALSE to propagate the event further.
1857 widget_signals[LEAVE_NOTIFY_EVENT] =
1858 g_signal_new (I_("leave-notify-event"),
1859 G_TYPE_FROM_CLASS (klass),
1861 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1862 _gtk_boolean_handled_accumulator, NULL,
1863 _gtk_marshal_BOOLEAN__BOXED,
1865 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1868 * GtkWidget::configure-event:
1869 * @widget: the object which received the signal
1870 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1873 * The ::configure-event signal will be emitted when the size, position or
1874 * stacking of the @widget's window has changed.
1876 * To receive this signal, the #GdkWindow associated to the widget needs
1877 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1878 * automatically for all new windows.
1880 * Returns: %TRUE to stop other handlers from being invoked for the event.
1881 * %FALSE to propagate the event further.
1883 widget_signals[CONFIGURE_EVENT] =
1884 g_signal_new (I_("configure-event"),
1885 G_TYPE_FROM_CLASS (klass),
1887 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1888 _gtk_boolean_handled_accumulator, NULL,
1889 _gtk_marshal_BOOLEAN__BOXED,
1891 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1894 * GtkWidget::focus-in-event:
1895 * @widget: the object which received the signal
1896 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1899 * The ::focus-in-event signal will be emitted when the keyboard focus
1900 * enters the @widget's window.
1902 * To receive this signal, the #GdkWindow associated to the widget needs
1903 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1905 * Returns: %TRUE to stop other handlers from being invoked for the event.
1906 * %FALSE to propagate the event further.
1908 widget_signals[FOCUS_IN_EVENT] =
1909 g_signal_new (I_("focus-in-event"),
1910 G_TYPE_FROM_CLASS (klass),
1912 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1913 _gtk_boolean_handled_accumulator, NULL,
1914 _gtk_marshal_BOOLEAN__BOXED,
1916 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1919 * GtkWidget::focus-out-event:
1920 * @widget: the object which received the signal
1921 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1924 * The ::focus-out-event signal will be emitted when the keyboard focus
1925 * leaves the @widget's window.
1927 * To receive this signal, the #GdkWindow associated to the widget needs
1928 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1930 * Returns: %TRUE to stop other handlers from being invoked for the event.
1931 * %FALSE to propagate the event further.
1933 widget_signals[FOCUS_OUT_EVENT] =
1934 g_signal_new (I_("focus-out-event"),
1935 G_TYPE_FROM_CLASS (klass),
1937 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1938 _gtk_boolean_handled_accumulator, NULL,
1939 _gtk_marshal_BOOLEAN__BOXED,
1941 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1944 * GtkWidget::map-event:
1945 * @widget: the object which received the signal
1946 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1948 * The ::map-event signal will be emitted when the @widget's window is
1949 * mapped. A window is mapped when it becomes visible on the screen.
1951 * To receive this signal, the #GdkWindow associated to the widget needs
1952 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1953 * automatically for all new windows.
1955 * Returns: %TRUE to stop other handlers from being invoked for the event.
1956 * %FALSE to propagate the event further.
1958 widget_signals[MAP_EVENT] =
1959 g_signal_new (I_("map-event"),
1960 G_TYPE_FROM_CLASS (klass),
1962 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1963 _gtk_boolean_handled_accumulator, NULL,
1964 _gtk_marshal_BOOLEAN__BOXED,
1966 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1969 * GtkWidget::unmap-event:
1970 * @widget: the object which received the signal
1971 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1973 * The ::unmap-event signal may be emitted when the @widget's window is
1974 * unmapped. A window is unmapped when it becomes invisible on the screen.
1976 * For performance reasons GTK+ may not emit ::unmap-event, so one
1977 * should always also implement ::unrealize in order to release
1978 * resources and disconnect signal handlers.
1980 * To receive this signal, the #GdkWindow associated to the widget needs
1981 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1982 * automatically for all new windows.
1984 * Returns: %TRUE to stop other handlers from being invoked for the event.
1985 * %FALSE to propagate the event further.
1987 widget_signals[UNMAP_EVENT] =
1988 g_signal_new (I_("unmap-event"),
1989 G_TYPE_FROM_CLASS (klass),
1991 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1992 _gtk_boolean_handled_accumulator, NULL,
1993 _gtk_marshal_BOOLEAN__BOXED,
1995 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1998 * GtkWidget::property-notify-event:
1999 * @widget: the object which received the signal
2000 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2003 * The ::property-notify-event signal will be emitted when a property on
2004 * the @widget's window has been changed or deleted.
2006 * To receive this signal, the #GdkWindow associated to the widget needs
2007 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2009 * Returns: %TRUE to stop other handlers from being invoked for the event.
2010 * %FALSE to propagate the event further.
2012 widget_signals[PROPERTY_NOTIFY_EVENT] =
2013 g_signal_new (I_("property-notify-event"),
2014 G_TYPE_FROM_CLASS (klass),
2016 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2017 _gtk_boolean_handled_accumulator, NULL,
2018 _gtk_marshal_BOOLEAN__BOXED,
2020 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2023 * GtkWidget::selection-clear-event:
2024 * @widget: the object which received the signal
2025 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2028 * The ::selection-clear-event signal will be emitted when the
2029 * the @widget's window has lost ownership of a selection.
2031 * Returns: %TRUE to stop other handlers from being invoked for the event.
2032 * %FALSE to propagate the event further.
2034 widget_signals[SELECTION_CLEAR_EVENT] =
2035 g_signal_new (I_("selection-clear-event"),
2036 G_TYPE_FROM_CLASS (klass),
2038 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2039 _gtk_boolean_handled_accumulator, NULL,
2040 _gtk_marshal_BOOLEAN__BOXED,
2042 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2045 * GtkWidget::selection-request-event:
2046 * @widget: the object which received the signal
2047 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2050 * The ::selection-request-event signal will be emitted when
2051 * another client requests ownership of the selection owned by
2052 * the @widget's window.
2054 * Returns: %TRUE to stop other handlers from being invoked for the event.
2055 * %FALSE to propagate the event further.
2057 widget_signals[SELECTION_REQUEST_EVENT] =
2058 g_signal_new (I_("selection-request-event"),
2059 G_TYPE_FROM_CLASS (klass),
2061 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2062 _gtk_boolean_handled_accumulator, NULL,
2063 _gtk_marshal_BOOLEAN__BOXED,
2065 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2068 * GtkWidget::selection-notify-event:
2069 * @widget: the object which received the signal.
2072 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2074 widget_signals[SELECTION_NOTIFY_EVENT] =
2075 g_signal_new (I_("selection-notify-event"),
2076 G_TYPE_FROM_CLASS (klass),
2078 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2079 _gtk_boolean_handled_accumulator, NULL,
2080 _gtk_marshal_BOOLEAN__BOXED,
2082 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2085 * GtkWidget::selection-received:
2086 * @widget: the object which received the signal.
2090 widget_signals[SELECTION_RECEIVED] =
2091 g_signal_new (I_("selection-received"),
2092 G_TYPE_FROM_CLASS (klass),
2094 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2096 _gtk_marshal_VOID__BOXED_UINT,
2098 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2102 * GtkWidget::selection-get:
2103 * @widget: the object which received the signal.
2108 widget_signals[SELECTION_GET] =
2109 g_signal_new (I_("selection-get"),
2110 G_TYPE_FROM_CLASS (klass),
2112 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2114 _gtk_marshal_VOID__BOXED_UINT_UINT,
2116 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2121 * GtkWidget::proximity-in-event:
2122 * @widget: the object which received the signal
2123 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2126 * To receive this signal the #GdkWindow associated to the widget needs
2127 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2129 * This signal will be sent to the grab widget if there is one.
2131 * Returns: %TRUE to stop other handlers from being invoked for the event.
2132 * %FALSE to propagate the event further.
2134 widget_signals[PROXIMITY_IN_EVENT] =
2135 g_signal_new (I_("proximity-in-event"),
2136 G_TYPE_FROM_CLASS (klass),
2138 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2139 _gtk_boolean_handled_accumulator, NULL,
2140 _gtk_marshal_BOOLEAN__BOXED,
2142 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2145 * GtkWidget::proximity-out-event:
2146 * @widget: the object which received the signal
2147 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2150 * To receive this signal the #GdkWindow associated to the widget needs
2151 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2153 * This signal will be sent to the grab widget if there is one.
2155 * Returns: %TRUE to stop other handlers from being invoked for the event.
2156 * %FALSE to propagate the event further.
2158 widget_signals[PROXIMITY_OUT_EVENT] =
2159 g_signal_new (I_("proximity-out-event"),
2160 G_TYPE_FROM_CLASS (klass),
2162 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2163 _gtk_boolean_handled_accumulator, NULL,
2164 _gtk_marshal_BOOLEAN__BOXED,
2166 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2169 * GtkWidget::drag-leave:
2170 * @widget: the object which received the signal.
2171 * @drag_context: the drag context
2172 * @time: the timestamp of the motion event
2174 * The ::drag-leave signal is emitted on the drop site when the cursor
2175 * leaves the widget. A typical reason to connect to this signal is to
2176 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2177 * with gtk_drag_unhighlight()
2179 widget_signals[DRAG_LEAVE] =
2180 g_signal_new (I_("drag-leave"),
2181 G_TYPE_FROM_CLASS (klass),
2183 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2185 _gtk_marshal_VOID__OBJECT_UINT,
2187 GDK_TYPE_DRAG_CONTEXT,
2191 * GtkWidget::drag-begin:
2192 * @widget: the object which received the signal
2193 * @drag_context: the drag context
2195 * The ::drag-begin signal is emitted on the drag source when a drag is
2196 * started. A typical reason to connect to this signal is to set up a
2197 * custom drag icon with gtk_drag_source_set_icon().
2199 * Note that some widgets set up a drag icon in the default handler of
2200 * this signal, so you may have to use g_signal_connect_after() to
2201 * override what the default handler did.
2203 widget_signals[DRAG_BEGIN] =
2204 g_signal_new (I_("drag-begin"),
2205 G_TYPE_FROM_CLASS (klass),
2207 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2209 _gtk_marshal_VOID__OBJECT,
2211 GDK_TYPE_DRAG_CONTEXT);
2214 * GtkWidget::drag-end:
2215 * @widget: the object which received the signal
2216 * @drag_context: the drag context
2218 * The ::drag-end signal is emitted on the drag source when a drag is
2219 * finished. A typical reason to connect to this signal is to undo
2220 * things done in #GtkWidget::drag-begin.
2222 widget_signals[DRAG_END] =
2223 g_signal_new (I_("drag-end"),
2224 G_TYPE_FROM_CLASS (klass),
2226 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2228 _gtk_marshal_VOID__OBJECT,
2230 GDK_TYPE_DRAG_CONTEXT);
2233 * GtkWidget::drag-data-delete:
2234 * @widget: the object which received the signal
2235 * @drag_context: the drag context
2237 * The ::drag-data-delete signal is emitted on the drag source when a drag
2238 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2239 * handler is responsible for deleting the data that has been dropped. What
2240 * "delete" means depends on the context of the drag operation.
2242 widget_signals[DRAG_DATA_DELETE] =
2243 g_signal_new (I_("drag-data-delete"),
2244 G_TYPE_FROM_CLASS (klass),
2246 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2248 _gtk_marshal_VOID__OBJECT,
2250 GDK_TYPE_DRAG_CONTEXT);
2253 * GtkWidget::drag-failed:
2254 * @widget: the object which received the signal
2255 * @drag_context: the drag context
2256 * @result: the result of the drag operation
2258 * The ::drag-failed signal is emitted on the drag source when a drag has
2259 * failed. The signal handler may hook custom code to handle a failed DND
2260 * operation based on the type of error, it returns %TRUE is the failure has
2261 * been already handled (not showing the default "drag operation failed"
2262 * animation), otherwise it returns %FALSE.
2264 * Return value: %TRUE if the failed drag operation has been already handled.
2268 widget_signals[DRAG_FAILED] =
2269 g_signal_new (I_("drag-failed"),
2270 G_TYPE_FROM_CLASS (klass),
2272 0, _gtk_boolean_handled_accumulator, NULL,
2273 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2275 GDK_TYPE_DRAG_CONTEXT,
2276 GTK_TYPE_DRAG_RESULT);
2279 * GtkWidget::drag-motion:
2280 * @widget: the object which received the signal
2281 * @drag_context: the drag context
2282 * @x: the x coordinate of the current cursor position
2283 * @y: the y coordinate of the current cursor position
2284 * @time: the timestamp of the motion event
2285 * @returns: whether the cursor position is in a drop zone
2287 * The drag-motion signal is emitted on the drop site when the user
2288 * moves the cursor over the widget during a drag. The signal handler
2289 * must determine whether the cursor position is in a drop zone or not.
2290 * If it is not in a drop zone, it returns %FALSE and no further processing
2291 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2292 * handler is responsible for providing the necessary information for
2293 * displaying feedback to the user, by calling gdk_drag_status().
2295 * If the decision whether the drop will be accepted or rejected can't be
2296 * made based solely on the cursor position and the type of the data, the
2297 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2298 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2299 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2300 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2301 * when using the drag-motion signal that way.
2303 * Also note that there is no drag-enter signal. The drag receiver has to
2304 * keep track of whether he has received any drag-motion signals since the
2305 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2306 * an "enter" signal. Upon an "enter", the handler will typically highlight
2307 * the drop site with gtk_drag_highlight().
2310 * drag_motion (GtkWidget *widget,
2311 * GdkDragContext *context,
2318 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2320 * if (!private_data->drag_highlight)
2322 * private_data->drag_highlight = 1;
2323 * gtk_drag_highlight (widget);
2326 * target = gtk_drag_dest_find_target (widget, context, NULL);
2327 * if (target == GDK_NONE)
2328 * gdk_drag_status (context, 0, time);
2331 * private_data->pending_status = context->suggested_action;
2332 * gtk_drag_get_data (widget, context, target, time);
2339 * drag_data_received (GtkWidget *widget,
2340 * GdkDragContext *context,
2343 * GtkSelectionData *selection_data,
2347 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2349 * if (private_data->suggested_action)
2351 * private_data->suggested_action = 0;
2353 * /* We are getting this data due to a request in drag_motion,
2354 * * rather than due to a request in drag_drop, so we are just
2355 * * supposed to call gdk_drag_status (), not actually paste in
2358 * str = gtk_selection_data_get_text (selection_data);
2359 * if (!data_is_acceptable (str))
2360 * gdk_drag_status (context, 0, time);
2362 * gdk_drag_status (context, private_data->suggested_action, time);
2366 * /* accept the drop */
2371 widget_signals[DRAG_MOTION] =
2372 g_signal_new (I_("drag-motion"),
2373 G_TYPE_FROM_CLASS (klass),
2375 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2376 _gtk_boolean_handled_accumulator, NULL,
2377 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2379 GDK_TYPE_DRAG_CONTEXT,
2385 * GtkWidget::drag-drop:
2386 * @widget: the object which received the signal
2387 * @drag_context: the drag context
2388 * @x: the x coordinate of the current cursor position
2389 * @y: the y coordinate of the current cursor position
2390 * @time: the timestamp of the motion event
2391 * @returns: whether the cursor position is in a drop zone
2393 * The ::drag-drop signal is emitted on the drop site when the user drops
2394 * the data onto the widget. The signal handler must determine whether
2395 * the cursor position is in a drop zone or not. If it is not in a drop
2396 * zone, it returns %FALSE and no further processing is necessary.
2397 * Otherwise, the handler returns %TRUE. In this case, the handler must
2398 * ensure that gtk_drag_finish() is called to let the source know that
2399 * the drop is done. The call to gtk_drag_finish() can be done either
2400 * directly or in a #GtkWidget::drag-data-received handler which gets
2401 * triggered by calling gtk_drag_get_data() to receive the data for one
2402 * or more of the supported targets.
2404 widget_signals[DRAG_DROP] =
2405 g_signal_new (I_("drag-drop"),
2406 G_TYPE_FROM_CLASS (klass),
2408 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2409 _gtk_boolean_handled_accumulator, NULL,
2410 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2412 GDK_TYPE_DRAG_CONTEXT,
2418 * GtkWidget::drag-data-get:
2419 * @widget: the object which received the signal
2420 * @drag_context: the drag context
2421 * @data: the #GtkSelectionData to be filled with the dragged data
2422 * @info: the info that has been registered with the target in the
2424 * @time: the timestamp at which the data was requested
2426 * The ::drag-data-get signal is emitted on the drag source when the drop
2427 * site requests the data which is dragged. It is the responsibility of
2428 * the signal handler to fill @data with the data in the format which
2429 * is indicated by @info. See gtk_selection_data_set() and
2430 * gtk_selection_data_set_text().
2432 widget_signals[DRAG_DATA_GET] =
2433 g_signal_new (I_("drag-data-get"),
2434 G_TYPE_FROM_CLASS (klass),
2436 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2438 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2440 GDK_TYPE_DRAG_CONTEXT,
2441 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2446 * GtkWidget::drag-data-received:
2447 * @widget: the object which received the signal
2448 * @drag_context: the drag context
2449 * @x: where the drop happened
2450 * @y: where the drop happened
2451 * @data: the received data
2452 * @info: the info that has been registered with the target in the
2454 * @time: the timestamp at which the data was received
2456 * The ::drag-data-received signal is emitted on the drop site when the
2457 * dragged data has been received. If the data was received in order to
2458 * determine whether the drop will be accepted, the handler is expected
2459 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2460 * If the data was received in response to a #GtkWidget::drag-drop signal
2461 * (and this is the last target to be received), the handler for this
2462 * signal is expected to process the received data and then call
2463 * gtk_drag_finish(), setting the @success parameter depending on whether
2464 * the data was processed successfully.
2466 * The handler may inspect and modify @drag_context->action before calling
2467 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2468 * following example:
2471 * drag_data_received (GtkWidget *widget,
2472 * GdkDragContext *drag_context,
2475 * GtkSelectionData *data,
2479 * if ((data->length >= 0) && (data->format == 8))
2481 * if (drag_context->action == GDK_ACTION_ASK)
2483 * GtkWidget *dialog;
2486 * dialog = gtk_message_dialog_new (NULL,
2487 * GTK_DIALOG_MODAL |
2488 * GTK_DIALOG_DESTROY_WITH_PARENT,
2490 * GTK_BUTTONS_YES_NO,
2491 * "Move the data ?\n");
2492 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2493 * gtk_widget_destroy (dialog);
2495 * if (response == GTK_RESPONSE_YES)
2496 * drag_context->action = GDK_ACTION_MOVE;
2498 * drag_context->action = GDK_ACTION_COPY;
2501 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2505 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2509 widget_signals[DRAG_DATA_RECEIVED] =
2510 g_signal_new (I_("drag-data-received"),
2511 G_TYPE_FROM_CLASS (klass),
2513 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2515 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2517 GDK_TYPE_DRAG_CONTEXT,
2520 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2525 * GtkWidget::visibility-notify-event:
2526 * @widget: the object which received the signal
2527 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2528 * triggered this signal.
2530 * The ::visibility-notify-event will be emitted when the @widget's window
2531 * is obscured or unobscured.
2533 * To receive this signal the #GdkWindow associated to the widget needs
2534 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2536 * Returns: %TRUE to stop other handlers from being invoked for the event.
2537 * %FALSE to propagate the event further.
2539 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2540 g_signal_new (I_("visibility-notify-event"),
2541 G_TYPE_FROM_CLASS (klass),
2543 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2544 _gtk_boolean_handled_accumulator, NULL,
2545 _gtk_marshal_BOOLEAN__BOXED,
2547 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2550 * GtkWidget::client-event:
2551 * @widget: the object which received the signal
2552 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2555 * The ::client-event will be emitted when the @widget's window
2556 * receives a message (via a ClientMessage event) from another
2559 * Returns: %TRUE to stop other handlers from being invoked for
2560 * the event. %FALSE to propagate the event further.
2562 widget_signals[CLIENT_EVENT] =
2563 g_signal_new (I_("client-event"),
2564 G_TYPE_FROM_CLASS (klass),
2566 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2567 _gtk_boolean_handled_accumulator, NULL,
2568 _gtk_marshal_BOOLEAN__BOXED,
2570 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2573 * GtkWidget::no-expose-event:
2574 * @widget: the object which received the signal
2575 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2578 * The ::no-expose-event will be emitted when the @widget's window is
2579 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2580 * If the source window was partially obscured #GdkEventExpose events will
2581 * be generated for those areas.
2583 * Returns: %TRUE to stop other handlers from being invoked for the event.
2584 * %FALSE to propagate the event further.
2586 widget_signals[NO_EXPOSE_EVENT] =
2587 g_signal_new (I_("no-expose-event"),
2588 G_TYPE_FROM_CLASS (klass),
2590 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2591 _gtk_boolean_handled_accumulator, NULL,
2592 _gtk_marshal_BOOLEAN__BOXED,
2594 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2597 * GtkWidget::window-state-event:
2598 * @widget: the object which received the signal
2599 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2600 * triggered this signal.
2602 * The ::window-state-event will be emitted when the state of the
2603 * toplevel window associated to the @widget changes.
2605 * To receive this signal the #GdkWindow associated to the widget
2606 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2607 * this mask automatically for all new windows.
2609 * Returns: %TRUE to stop other handlers from being invoked for the
2610 * event. %FALSE to propagate the event further.
2612 widget_signals[WINDOW_STATE_EVENT] =
2613 g_signal_new (I_("window-state-event"),
2614 G_TYPE_FROM_CLASS (klass),
2616 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2617 _gtk_boolean_handled_accumulator, NULL,
2618 _gtk_marshal_BOOLEAN__BOXED,
2620 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2623 * GtkWidget::damage-event:
2624 * @widget: the object which received the signal
2625 * @event: the #GdkEventExpose event
2627 * Emitted when a redirected window belonging to @widget gets drawn into.
2628 * The region/area members of the event shows what area of the redirected
2629 * drawable was drawn into.
2631 * Returns: %TRUE to stop other handlers from being invoked for the event.
2632 * %FALSE to propagate the event further.
2636 widget_signals[DAMAGE_EVENT] =
2637 g_signal_new (I_("damage-event"),
2638 G_TYPE_FROM_CLASS (klass),
2641 _gtk_boolean_handled_accumulator, NULL,
2642 _gtk_marshal_BOOLEAN__BOXED,
2644 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2647 * GtkWidget::grab-broken-event:
2648 * @widget: the object which received the signal
2649 * @event: the #GdkEventGrabBroken event
2651 * Emitted when a pointer or keyboard grab on a window belonging
2652 * to @widget gets broken.
2654 * On X11, this happens when the grab window becomes unviewable
2655 * (i.e. it or one of its ancestors is unmapped), or if the same
2656 * application grabs the pointer or keyboard again.
2658 * Returns: %TRUE to stop other handlers from being invoked for
2659 * the event. %FALSE to propagate the event further.
2663 widget_signals[GRAB_BROKEN] =
2664 g_signal_new (I_("grab-broken-event"),
2665 G_TYPE_FROM_CLASS (klass),
2667 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2668 _gtk_boolean_handled_accumulator, NULL,
2669 _gtk_marshal_BOOLEAN__BOXED,
2671 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2674 * GtkWidget::query-tooltip:
2675 * @widget: the object which received the signal
2676 * @x: the x coordinate of the cursor position where the request has
2677 * been emitted, relative to @widget->window
2678 * @y: the y coordinate of the cursor position where the request has
2679 * been emitted, relative to @widget->window
2680 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2681 * @tooltip: a #GtkTooltip
2683 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2684 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2685 * focus in keyboard mode.
2687 * Using the given coordinates, the signal handler should determine
2688 * whether a tooltip should be shown for @widget. If this is the case
2689 * %TRUE should be returned, %FALSE otherwise. Note that if
2690 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2691 * should not be used.
2693 * The signal handler is free to manipulate @tooltip with the therefore
2694 * destined function calls.
2696 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2700 widget_signals[QUERY_TOOLTIP] =
2701 g_signal_new (I_("query-tooltip"),
2702 G_TYPE_FROM_CLASS (klass),
2704 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2705 _gtk_boolean_handled_accumulator, NULL,
2706 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2714 * GtkWidget::popup-menu
2715 * @widget: the object which received the signal
2717 * This signal gets emitted whenever a widget should pop up a context
2718 * menu. This usually happens through the standard key binding mechanism;
2719 * by pressing a certain key while a widget is focused, the user can cause
2720 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2721 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2722 * for an example of how to use this signal.
2724 * Returns: %TRUE if a menu was activated
2726 widget_signals[POPUP_MENU] =
2727 g_signal_new (I_("popup-menu"),
2728 G_TYPE_FROM_CLASS (klass),
2729 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2730 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2731 _gtk_boolean_handled_accumulator, NULL,
2732 _gtk_marshal_BOOLEAN__VOID,
2736 * GtkWidget::show-help:
2737 * @widget: the object which received the signal.
2740 widget_signals[SHOW_HELP] =
2741 g_signal_new (I_("show-help"),
2742 G_TYPE_FROM_CLASS (klass),
2743 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2744 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2745 _gtk_boolean_handled_accumulator, NULL,
2746 _gtk_marshal_BOOLEAN__ENUM,
2748 GTK_TYPE_WIDGET_HELP_TYPE);
2751 * GtkWidget::accel-closures-changed:
2752 * @widget: the object which received the signal.
2754 widget_signals[ACCEL_CLOSURES_CHANGED] =
2755 g_signal_new (I_("accel-closures-changed"),
2756 G_TYPE_FROM_CLASS (klass),
2760 _gtk_marshal_VOID__VOID,
2764 * GtkWidget::screen-changed:
2765 * @widget: the object on which the signal is emitted
2766 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2767 * widget was not associated with a screen before
2769 * The ::screen-changed signal gets emitted when the
2770 * screen of a widget has changed.
2772 widget_signals[SCREEN_CHANGED] =
2773 g_signal_new (I_("screen-changed"),
2774 G_TYPE_FROM_CLASS (klass),
2776 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2778 _gtk_marshal_VOID__OBJECT,
2783 * GtkWidget::can-activate-accel:
2784 * @widget: the object which received the signal
2785 * @signal_id: the ID of a signal installed on @widget
2787 * Determines whether an accelerator that activates the signal
2788 * identified by @signal_id can currently be activated.
2789 * This signal is present to allow applications and derived
2790 * widgets to override the default #GtkWidget handling
2791 * for determining whether an accelerator can be activated.
2793 * Returns: %TRUE if the signal can be activated.
2795 widget_signals[CAN_ACTIVATE_ACCEL] =
2796 g_signal_new (I_("can-activate-accel"),
2797 G_TYPE_FROM_CLASS (klass),
2799 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2800 _gtk_boolean_handled_accumulator, NULL,
2801 _gtk_marshal_BOOLEAN__UINT,
2802 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2804 binding_set = gtk_binding_set_by_class (klass);
2805 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2810 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2812 GTK_TYPE_WIDGET_HELP_TYPE,
2813 GTK_WIDGET_HELP_TOOLTIP);
2814 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2816 GTK_TYPE_WIDGET_HELP_TYPE,
2817 GTK_WIDGET_HELP_TOOLTIP);
2818 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2820 GTK_TYPE_WIDGET_HELP_TYPE,
2821 GTK_WIDGET_HELP_WHATS_THIS);
2822 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2824 GTK_TYPE_WIDGET_HELP_TYPE,
2825 GTK_WIDGET_HELP_WHATS_THIS);
2827 gtk_widget_class_install_style_property (klass,
2828 g_param_spec_boolean ("interior-focus",
2829 P_("Interior Focus"),
2830 P_("Whether to draw the focus indicator inside widgets"),
2832 GTK_PARAM_READABLE));
2834 gtk_widget_class_install_style_property (klass,
2835 g_param_spec_int ("focus-line-width",
2836 P_("Focus linewidth"),
2837 P_("Width, in pixels, of the focus indicator line"),
2839 GTK_PARAM_READABLE));
2841 gtk_widget_class_install_style_property (klass,
2842 g_param_spec_string ("focus-line-pattern",
2843 P_("Focus line dash pattern"),
2844 P_("Dash pattern used to draw the focus indicator"),
2846 GTK_PARAM_READABLE));
2847 gtk_widget_class_install_style_property (klass,
2848 g_param_spec_int ("focus-padding",
2849 P_("Focus padding"),
2850 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2852 GTK_PARAM_READABLE));
2853 gtk_widget_class_install_style_property (klass,
2854 g_param_spec_boxed ("cursor-color",
2856 P_("Color with which to draw insertion cursor"),
2858 GTK_PARAM_READABLE));
2859 gtk_widget_class_install_style_property (klass,
2860 g_param_spec_boxed ("secondary-cursor-color",
2861 P_("Secondary cursor color"),
2862 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2864 GTK_PARAM_READABLE));
2865 gtk_widget_class_install_style_property (klass,
2866 g_param_spec_float ("cursor-aspect-ratio",
2867 P_("Cursor line aspect ratio"),
2868 P_("Aspect ratio with which to draw insertion cursor"),
2870 GTK_PARAM_READABLE));
2872 gtk_widget_class_install_style_property (klass,
2873 g_param_spec_boolean ("window-dragging",
2874 P_("Window dragging"),
2875 P_("Whether windows can be dragged by clicking on empty areas"),
2877 GTK_PARAM_READABLE));
2880 * GtkWidget:link-color:
2882 * The "link-color" style property defines the color of unvisited links.
2886 gtk_widget_class_install_style_property (klass,
2887 g_param_spec_boxed ("link-color",
2888 P_("Unvisited Link Color"),
2889 P_("Color of unvisited links"),
2891 GTK_PARAM_READABLE));
2894 * GtkWidget:visited-link-color:
2896 * The "visited-link-color" style property defines the color of visited links.
2900 gtk_widget_class_install_style_property (klass,
2901 g_param_spec_boxed ("visited-link-color",
2902 P_("Visited Link Color"),
2903 P_("Color of visited links"),
2905 GTK_PARAM_READABLE));
2908 * GtkWidget:wide-separators:
2910 * The "wide-separators" style property defines whether separators have
2911 * configurable width and should be drawn using a box instead of a line.
2915 gtk_widget_class_install_style_property (klass,
2916 g_param_spec_boolean ("wide-separators",
2917 P_("Wide Separators"),
2918 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2920 GTK_PARAM_READABLE));
2923 * GtkWidget:separator-width:
2925 * The "separator-width" style property defines the width of separators.
2926 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2930 gtk_widget_class_install_style_property (klass,
2931 g_param_spec_int ("separator-width",
2932 P_("Separator Width"),
2933 P_("The width of separators if wide-separators is TRUE"),
2935 GTK_PARAM_READABLE));
2938 * GtkWidget:separator-height:
2940 * The "separator-height" style property defines the height of separators.
2941 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2945 gtk_widget_class_install_style_property (klass,
2946 g_param_spec_int ("separator-height",
2947 P_("Separator Height"),
2948 P_("The height of separators if \"wide-separators\" is TRUE"),
2950 GTK_PARAM_READABLE));
2953 * GtkWidget:scroll-arrow-hlength:
2955 * The "scroll-arrow-hlength" style property defines the length of
2956 * horizontal scroll arrows.
2960 gtk_widget_class_install_style_property (klass,
2961 g_param_spec_int ("scroll-arrow-hlength",
2962 P_("Horizontal Scroll Arrow Length"),
2963 P_("The length of horizontal scroll arrows"),
2965 GTK_PARAM_READABLE));
2968 * GtkWidget:scroll-arrow-vlength:
2970 * The "scroll-arrow-vlength" style property defines the length of
2971 * vertical scroll arrows.
2975 gtk_widget_class_install_style_property (klass,
2976 g_param_spec_int ("scroll-arrow-vlength",
2977 P_("Vertical Scroll Arrow Length"),
2978 P_("The length of vertical scroll arrows"),
2980 GTK_PARAM_READABLE));
2982 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2986 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2990 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2991 for (node = list; node; node = node->next)
2993 GParamSpec *pspec = node->data;
2995 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2996 g_param_spec_unref (pspec);
3002 gtk_widget_set_property (GObject *object,
3004 const GValue *value,
3007 GtkWidget *widget = GTK_WIDGET (object);
3012 gchar *tooltip_markup;
3013 const gchar *tooltip_text;
3014 GtkWindow *tooltip_window;
3017 gtk_widget_set_name (widget, g_value_get_string (value));
3020 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3022 case PROP_WIDTH_REQUEST:
3023 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
3025 case PROP_HEIGHT_REQUEST:
3026 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
3029 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3031 case PROP_SENSITIVE:
3032 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3034 case PROP_APP_PAINTABLE:
3035 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3037 case PROP_CAN_FOCUS:
3038 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3040 case PROP_HAS_FOCUS:
3041 if (g_value_get_boolean (value))
3042 gtk_widget_grab_focus (widget);
3045 if (g_value_get_boolean (value))
3046 gtk_widget_grab_focus (widget);
3048 case PROP_CAN_DEFAULT:
3049 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3051 case PROP_HAS_DEFAULT:
3052 if (g_value_get_boolean (value))
3053 gtk_widget_grab_default (widget);
3055 case PROP_RECEIVES_DEFAULT:
3056 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3059 gtk_widget_set_style (widget, g_value_get_object (value));
3062 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3063 gtk_widget_set_events (widget, g_value_get_flags (value));
3065 case PROP_EXTENSION_EVENTS:
3066 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3068 case PROP_NO_SHOW_ALL:
3069 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3071 case PROP_HAS_TOOLTIP:
3072 gtk_widget_real_set_has_tooltip (widget,
3073 g_value_get_boolean (value), FALSE);
3075 case PROP_TOOLTIP_MARKUP:
3076 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3077 tooltip_markup = g_value_dup_string (value);
3079 /* Treat an empty string as a NULL string,
3080 * because an empty string would be useless for a tooltip:
3082 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3084 g_free (tooltip_markup);
3085 tooltip_markup = NULL;
3088 g_object_set_qdata_full (object, quark_tooltip_markup,
3089 tooltip_markup, g_free);
3091 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3092 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3093 if (gtk_widget_get_visible (widget))
3094 gtk_widget_queue_tooltip_query (widget);
3096 case PROP_TOOLTIP_TEXT:
3097 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3099 tooltip_text = g_value_get_string (value);
3101 /* Treat an empty string as a NULL string,
3102 * because an empty string would be useless for a tooltip:
3104 if (tooltip_text && (strlen (tooltip_text) == 0))
3105 tooltip_text = NULL;
3107 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3109 g_object_set_qdata_full (object, quark_tooltip_markup,
3110 tooltip_markup, g_free);
3112 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3113 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3114 if (gtk_widget_get_visible (widget))
3115 gtk_widget_queue_tooltip_query (widget);
3117 case PROP_DOUBLE_BUFFERED:
3118 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3121 gtk_widget_set_halign (widget, g_value_get_enum (value));
3124 gtk_widget_set_valign (widget, g_value_get_enum (value));
3126 case PROP_MARGIN_LEFT:
3127 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3129 case PROP_MARGIN_RIGHT:
3130 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3132 case PROP_MARGIN_TOP:
3133 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3135 case PROP_MARGIN_BOTTOM:
3136 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3139 g_object_freeze_notify (G_OBJECT (widget));
3140 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3141 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3142 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3143 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3144 g_object_thaw_notify (G_OBJECT (widget));
3147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3153 gtk_widget_get_property (GObject *object,
3158 GtkWidget *widget = GTK_WIDGET (object);
3159 GtkWidgetPrivate *priv = widget->priv;
3168 g_value_set_string (value, priv->name);
3170 g_value_set_static_string (value, "");
3173 g_value_set_object (value, priv->parent);
3175 case PROP_WIDTH_REQUEST:
3178 gtk_widget_get_size_request (widget, &w, NULL);
3179 g_value_set_int (value, w);
3182 case PROP_HEIGHT_REQUEST:
3185 gtk_widget_get_size_request (widget, NULL, &h);
3186 g_value_set_int (value, h);
3190 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3192 case PROP_SENSITIVE:
3193 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3195 case PROP_APP_PAINTABLE:
3196 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3198 case PROP_CAN_FOCUS:
3199 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3201 case PROP_HAS_FOCUS:
3202 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3205 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3207 case PROP_CAN_DEFAULT:
3208 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3210 case PROP_HAS_DEFAULT:
3211 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3213 case PROP_RECEIVES_DEFAULT:
3214 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3216 case PROP_COMPOSITE_CHILD:
3217 g_value_set_boolean (value, widget->priv->composite_child);
3220 g_value_set_object (value, gtk_widget_get_style (widget));
3223 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3224 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3226 case PROP_EXTENSION_EVENTS:
3227 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3228 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3230 case PROP_NO_SHOW_ALL:
3231 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3233 case PROP_HAS_TOOLTIP:
3234 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3236 case PROP_TOOLTIP_TEXT:
3238 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3241 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3242 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3244 g_value_take_string (value, text);
3247 case PROP_TOOLTIP_MARKUP:
3248 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3251 g_value_set_object (value, gtk_widget_get_window (widget));
3253 case PROP_DOUBLE_BUFFERED:
3254 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3257 g_value_set_enum (value, gtk_widget_get_halign (widget));
3260 g_value_set_enum (value, gtk_widget_get_valign (widget));
3262 case PROP_MARGIN_LEFT:
3263 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3265 case PROP_MARGIN_RIGHT:
3266 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3268 case PROP_MARGIN_TOP:
3269 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3271 case PROP_MARGIN_BOTTOM:
3272 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3276 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3277 if (aux_info == NULL)
3279 g_value_set_int (value, 0);
3283 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3284 aux_info->margin.right),
3285 MAX (aux_info->margin.top,
3286 aux_info->margin.bottom)));
3291 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3297 gtk_widget_init (GtkWidget *widget)
3299 GtkWidgetPrivate *priv;
3301 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3304 priv = widget->priv;
3306 priv->child_visible = TRUE;
3307 priv->state = GTK_STATE_NORMAL;
3308 priv->saved_state = GTK_STATE_NORMAL;
3310 priv->allocation.x = -1;
3311 priv->allocation.y = -1;
3312 priv->allocation.width = 1;
3313 priv->allocation.height = 1;
3314 priv->window = NULL;
3315 priv->parent = NULL;
3317 priv->sensitive = TRUE;
3318 priv->parent_sensitive = TRUE;
3319 priv->composite_child = composite_child_stack != 0;
3320 priv->double_buffered = TRUE;
3321 priv->redraw_on_alloc = TRUE;
3322 priv->width_request_needed = TRUE;
3323 priv->height_request_needed = TRUE;
3324 priv->alloc_needed = TRUE;
3326 priv->style = gtk_widget_get_default_style ();
3327 g_object_ref (priv->style);
3332 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3334 GParamSpec **pspecs)
3336 GtkWidgetPrivate *priv = widget->priv;
3337 GtkWidget *container = priv->parent;
3340 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3341 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3345 * gtk_widget_freeze_child_notify:
3346 * @widget: a #GtkWidget
3348 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3349 * signals are queued until gtk_widget_thaw_child_notify() is called
3352 * This is the analogue of g_object_freeze_notify() for child properties.
3355 gtk_widget_freeze_child_notify (GtkWidget *widget)
3357 g_return_if_fail (GTK_IS_WIDGET (widget));
3359 if (!G_OBJECT (widget)->ref_count)
3362 g_object_ref (widget);
3363 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3364 g_object_unref (widget);
3368 * gtk_widget_child_notify:
3369 * @widget: a #GtkWidget
3370 * @child_property: the name of a child property installed on the
3371 * class of @widget<!-- -->'s parent
3373 * Emits a #GtkWidget::child-notify signal for the
3374 * <link linkend="child-properties">child property</link> @child_property
3377 * This is the analogue of g_object_notify() for child properties.
3380 gtk_widget_child_notify (GtkWidget *widget,
3381 const gchar *child_property)
3383 GtkWidgetPrivate *priv = widget->priv;
3386 g_return_if_fail (GTK_IS_WIDGET (widget));
3387 g_return_if_fail (child_property != NULL);
3388 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3391 g_object_ref (widget);
3392 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3394 G_OBJECT_TYPE (priv->parent),
3397 g_warning ("%s: container class `%s' has no child property named `%s'",
3399 G_OBJECT_TYPE_NAME (priv->parent),
3403 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3405 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3406 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3408 g_object_unref (widget);
3412 * gtk_widget_thaw_child_notify:
3413 * @widget: a #GtkWidget
3415 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3416 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3420 gtk_widget_thaw_child_notify (GtkWidget *widget)
3422 GObjectNotifyQueue *nqueue;
3424 g_return_if_fail (GTK_IS_WIDGET (widget));
3426 if (!G_OBJECT (widget)->ref_count)
3429 g_object_ref (widget);
3430 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3431 if (!nqueue || !nqueue->freeze_count)
3432 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3433 G_OBJECT_TYPE_NAME (widget), widget);
3435 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3436 g_object_unref (widget);
3442 * @type: type ID of the widget to create
3443 * @first_property_name: name of first property to set
3444 * @Varargs: value of first property, followed by more properties,
3447 * This is a convenience function for creating a widget and setting
3448 * its properties in one go. For example you might write:
3449 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3450 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3451 * g_object_new(), but returns a widget so you don't have to
3452 * cast the object yourself.
3454 * Return value: a new #GtkWidget of type @widget_type
3457 gtk_widget_new (GType type,
3458 const gchar *first_property_name,
3464 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3466 va_start (var_args, first_property_name);
3467 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3474 gtk_widget_queue_draw_child (GtkWidget *widget)
3476 GtkWidgetPrivate *priv = widget->priv;
3479 parent = priv->parent;
3480 if (parent && gtk_widget_is_drawable (parent))
3481 gtk_widget_queue_draw_area (parent,
3484 priv->allocation.width,
3485 priv->allocation.height);
3489 * gtk_widget_unparent:
3490 * @widget: a #GtkWidget
3492 * This function is only for use in widget implementations.
3493 * Should be called by implementations of the remove method
3494 * on #GtkContainer, to dissociate a child from the container.
3497 gtk_widget_unparent (GtkWidget *widget)
3499 GtkWidgetPrivate *priv;
3500 GObjectNotifyQueue *nqueue;
3501 GtkWidget *toplevel;
3502 GtkWidget *old_parent;
3504 g_return_if_fail (GTK_IS_WIDGET (widget));
3506 priv = widget->priv;
3508 if (priv->parent == NULL)
3511 /* keep this function in sync with gtk_menu_detach()
3514 g_object_freeze_notify (G_OBJECT (widget));
3515 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3517 toplevel = gtk_widget_get_toplevel (widget);
3518 if (gtk_widget_is_toplevel (toplevel))
3519 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3521 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3522 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3524 /* If we are unanchoring the child, we save around the toplevel
3525 * to emit hierarchy changed
3527 if (priv->parent->priv->anchored)
3528 g_object_ref (toplevel);
3532 gtk_widget_queue_draw_child (widget);
3534 /* Reset the width and height here, to force reallocation if we
3535 * get added back to a new parent. This won't work if our new
3536 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3537 * (would 0x0 be OK here?)
3539 priv->allocation.width = 1;
3540 priv->allocation.height = 1;
3542 if (gtk_widget_get_realized (widget))
3544 if (priv->in_reparent)
3545 gtk_widget_unmap (widget);
3547 gtk_widget_unrealize (widget);
3550 /* Removing a widget from a container restores the child visible
3551 * flag to the default state, so it doesn't affect the child
3552 * in the next parent.
3554 priv->child_visible = TRUE;
3556 old_parent = priv->parent;
3557 priv->parent = NULL;
3558 gtk_widget_set_parent_window (widget, NULL);
3559 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3562 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3563 g_object_unref (toplevel);
3566 g_object_notify (G_OBJECT (widget), "parent");
3567 g_object_thaw_notify (G_OBJECT (widget));
3569 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3570 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3571 g_object_unref (widget);
3575 * gtk_widget_destroy:
3576 * @widget: a #GtkWidget
3578 * Destroys a widget.
3581 * destroyed, it will break any references it holds to other objects.
3582 * If the widget is inside a container, the widget will be removed
3583 * from the container. If the widget is a toplevel (derived from
3584 * #GtkWindow), it will be removed from the list of toplevels, and the
3585 * reference GTK+ holds to it will be removed. Removing a
3586 * widget from its container or the list of toplevels results in the
3587 * widget being finalized, unless you've added additional references
3588 * to the widget with g_object_ref().
3590 * In most cases, only toplevel widgets (windows) require explicit
3591 * destruction, because when you destroy a toplevel its children will
3592 * be destroyed as well.
3595 gtk_widget_destroy (GtkWidget *widget)
3597 g_return_if_fail (GTK_IS_WIDGET (widget));
3599 if (!widget->priv->in_destruction)
3600 g_object_run_dispose (G_OBJECT (widget));
3604 * gtk_widget_destroyed:
3605 * @widget: a #GtkWidget
3606 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3608 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3609 * %NULL. It's intended to be used as a callback connected to the
3610 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3611 * as a signal handler, and pass the address of your widget variable
3612 * as user data. Then when the widget is destroyed, the variable will
3613 * be set to %NULL. Useful for example to avoid multiple copies
3614 * of the same dialog.
3617 gtk_widget_destroyed (GtkWidget *widget,
3618 GtkWidget **widget_pointer)
3620 /* Don't make any assumptions about the
3622 * Even check widget_pointer.
3625 *widget_pointer = NULL;
3630 * @widget: a #GtkWidget
3632 * Flags a widget to be displayed. Any widget that isn't shown will
3633 * not appear on the screen. If you want to show all the widgets in a
3634 * container, it's easier to call gtk_widget_show_all() on the
3635 * container, instead of individually showing the widgets.
3637 * Remember that you have to show the containers containing a widget,
3638 * in addition to the widget itself, before it will appear onscreen.
3640 * When a toplevel container is shown, it is immediately realized and
3641 * mapped; other shown widgets are realized and mapped when their
3642 * toplevel container is realized and mapped.
3645 gtk_widget_show (GtkWidget *widget)
3647 g_return_if_fail (GTK_IS_WIDGET (widget));
3649 if (!gtk_widget_get_visible (widget))
3651 g_object_ref (widget);
3652 if (!gtk_widget_is_toplevel (widget))
3653 gtk_widget_queue_resize (widget);
3654 g_signal_emit (widget, widget_signals[SHOW], 0);
3655 g_object_notify (G_OBJECT (widget), "visible");
3656 g_object_unref (widget);
3661 gtk_widget_real_show (GtkWidget *widget)
3663 GtkWidgetPrivate *priv = widget->priv;
3665 if (!gtk_widget_get_visible (widget))
3667 priv->visible = TRUE;
3670 gtk_widget_get_mapped (priv->parent) &&
3671 gtk_widget_get_child_visible (widget) &&
3672 !gtk_widget_get_mapped (widget))
3673 gtk_widget_map (widget);
3678 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3681 g_signal_handlers_disconnect_by_func (widget,
3682 gtk_widget_show_map_callback,
3687 * gtk_widget_show_now:
3688 * @widget: a #GtkWidget
3690 * Shows a widget. If the widget is an unmapped toplevel widget
3691 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3692 * loop and wait for the window to actually be mapped. Be careful;
3693 * because the main loop is running, anything can happen during
3697 gtk_widget_show_now (GtkWidget *widget)
3701 g_return_if_fail (GTK_IS_WIDGET (widget));
3703 /* make sure we will get event */
3704 if (!gtk_widget_get_mapped (widget) &&
3705 gtk_widget_is_toplevel (widget))
3707 gtk_widget_show (widget);
3709 g_signal_connect (widget, "map-event",
3710 G_CALLBACK (gtk_widget_show_map_callback),
3714 gtk_main_iteration ();
3717 gtk_widget_show (widget);
3722 * @widget: a #GtkWidget
3724 * Reverses the effects of gtk_widget_show(), causing the widget to be
3725 * hidden (invisible to the user).
3728 gtk_widget_hide (GtkWidget *widget)
3730 g_return_if_fail (GTK_IS_WIDGET (widget));
3732 if (gtk_widget_get_visible (widget))
3734 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3736 g_object_ref (widget);
3737 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3738 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3740 g_signal_emit (widget, widget_signals[HIDE], 0);
3741 if (!gtk_widget_is_toplevel (widget))
3742 gtk_widget_queue_resize (widget);
3743 g_object_notify (G_OBJECT (widget), "visible");
3744 g_object_unref (widget);
3749 gtk_widget_real_hide (GtkWidget *widget)
3751 if (gtk_widget_get_visible (widget))
3753 widget->priv->visible = FALSE;
3755 if (gtk_widget_get_mapped (widget))
3756 gtk_widget_unmap (widget);
3761 * gtk_widget_hide_on_delete:
3762 * @widget: a #GtkWidget
3764 * Utility function; intended to be connected to the #GtkWidget::delete-event
3765 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3766 * argument, then returns %TRUE. If connected to ::delete-event, the
3767 * result is that clicking the close button for a window (on the
3768 * window frame, top right corner usually) will hide but not destroy
3769 * the window. By default, GTK+ destroys windows when ::delete-event
3772 * Return value: %TRUE
3775 gtk_widget_hide_on_delete (GtkWidget *widget)
3777 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3779 gtk_widget_hide (widget);
3785 * gtk_widget_show_all:
3786 * @widget: a #GtkWidget
3788 * Recursively shows a widget, and any child widgets (if the widget is
3792 gtk_widget_show_all (GtkWidget *widget)
3794 GtkWidgetClass *class;
3796 g_return_if_fail (GTK_IS_WIDGET (widget));
3798 if (gtk_widget_get_no_show_all (widget))
3801 class = GTK_WIDGET_GET_CLASS (widget);
3803 if (class->show_all)
3804 class->show_all (widget);
3808 * gtk_widget_hide_all:
3809 * @widget: a #GtkWidget
3811 * Recursively hides a widget and any child widgets.
3814 gtk_widget_hide_all (GtkWidget *widget)
3816 GtkWidgetClass *class;
3818 g_return_if_fail (GTK_IS_WIDGET (widget));
3820 if (gtk_widget_get_no_show_all (widget))
3823 class = GTK_WIDGET_GET_CLASS (widget);
3825 if (class->hide_all)
3826 class->hide_all (widget);
3831 * @widget: a #GtkWidget
3833 * This function is only for use in widget implementations. Causes
3834 * a widget to be mapped if it isn't already.
3837 gtk_widget_map (GtkWidget *widget)
3839 GtkWidgetPrivate *priv;
3841 g_return_if_fail (GTK_IS_WIDGET (widget));
3842 g_return_if_fail (gtk_widget_get_visible (widget));
3843 g_return_if_fail (gtk_widget_get_child_visible (widget));
3845 priv = widget->priv;
3847 if (!gtk_widget_get_mapped (widget))
3849 if (!gtk_widget_get_realized (widget))
3850 gtk_widget_realize (widget);
3852 g_signal_emit (widget, widget_signals[MAP], 0);
3854 if (!gtk_widget_get_has_window (widget))
3855 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3861 * @widget: a #GtkWidget
3863 * This function is only for use in widget implementations. Causes
3864 * a widget to be unmapped if it's currently mapped.
3867 gtk_widget_unmap (GtkWidget *widget)
3869 GtkWidgetPrivate *priv;
3871 g_return_if_fail (GTK_IS_WIDGET (widget));
3873 priv = widget->priv;
3875 if (gtk_widget_get_mapped (widget))
3877 if (!gtk_widget_get_has_window (widget))
3878 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3879 _gtk_tooltip_hide (widget);
3880 g_signal_emit (widget, widget_signals[UNMAP], 0);
3885 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3886 GdkExtensionMode mode,
3889 GtkWidgetPrivate *priv = widget->priv;
3890 GList *free_list = NULL;
3893 if (window_list == NULL)
3895 if (gtk_widget_get_has_window (widget))
3896 window_list = g_list_prepend (NULL, priv->window);
3898 window_list = gdk_window_get_children (priv->window);
3900 free_list = window_list;
3903 for (l = window_list; l != NULL; l = l->next)
3905 GdkWindow *window = l->data;
3908 gdk_window_get_user_data (window, &user_data);
3909 if (user_data == widget)
3913 gdk_input_set_extension_events (window,
3914 gdk_window_get_events (window),
3917 children = gdk_window_get_children (window);
3920 gtk_widget_set_extension_events_internal (widget, mode, children);
3921 g_list_free (children);
3927 g_list_free (free_list);
3931 _gtk_widget_enable_device_events (GtkWidget *widget)
3933 GHashTable *device_events;
3934 GHashTableIter iter;
3935 gpointer key, value;
3937 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3942 g_hash_table_iter_init (&iter, device_events);
3944 while (g_hash_table_iter_next (&iter, &key, &value))
3947 GdkEventMask event_mask;
3950 event_mask = GPOINTER_TO_UINT (value);
3951 gtk_widget_add_events_internal (widget, device, event_mask);
3956 * gtk_widget_realize:
3957 * @widget: a #GtkWidget
3959 * Creates the GDK (windowing system) resources associated with a
3960 * widget. For example, @widget->window will be created when a widget
3961 * is realized. Normally realization happens implicitly; if you show
3962 * a widget and all its parent containers, then the widget will be
3963 * realized and mapped automatically.
3965 * Realizing a widget requires all
3966 * the widget's parent widgets to be realized; calling
3967 * gtk_widget_realize() realizes the widget's parents in addition to
3968 * @widget itself. If a widget is not yet inside a toplevel window
3969 * when you realize it, bad things will happen.
3971 * This function is primarily used in widget implementations, and
3972 * isn't very useful otherwise. Many times when you think you might
3973 * need it, a better approach is to connect to a signal that will be
3974 * called after the widget is realized automatically, such as
3975 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3976 * GtkWidget::realize signal.
3979 gtk_widget_realize (GtkWidget *widget)
3981 GtkWidgetPrivate *priv;
3982 GdkExtensionMode mode;
3983 cairo_region_t *region;
3985 g_return_if_fail (GTK_IS_WIDGET (widget));
3986 g_return_if_fail (widget->priv->anchored ||
3987 GTK_IS_INVISIBLE (widget));
3989 priv = widget->priv;
3991 if (!gtk_widget_get_realized (widget))
3994 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3995 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3998 if (priv->parent == NULL &&
3999 !gtk_widget_is_toplevel (widget))
4000 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4001 "inside a toplevel window is not going to work very well. "
4002 "Widgets must be inside a toplevel container before realizing them.");
4004 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4005 gtk_widget_realize (priv->parent);
4007 gtk_widget_ensure_style (widget);
4009 g_signal_emit (widget, widget_signals[REALIZE], 0);
4011 gtk_widget_real_set_has_tooltip (widget,
4012 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4015 if (priv->has_shape_mask)
4017 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4018 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4021 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4023 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4025 mode = gtk_widget_get_extension_events (widget);
4026 if (mode != GDK_EXTENSION_EVENTS_NONE)
4027 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4029 if (priv->multidevice)
4030 gdk_window_set_support_multidevice (priv->window, TRUE);
4032 _gtk_widget_enable_device_events (widget);
4037 * gtk_widget_unrealize:
4038 * @widget: a #GtkWidget
4040 * This function is only useful in widget implementations.
4041 * Causes a widget to be unrealized (frees all GDK resources
4042 * associated with the widget, such as @widget->window).
4045 gtk_widget_unrealize (GtkWidget *widget)
4047 g_return_if_fail (GTK_IS_WIDGET (widget));
4049 if (widget->priv->has_shape_mask)
4050 gtk_widget_shape_combine_region (widget, NULL);
4052 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4053 gtk_widget_input_shape_combine_region (widget, NULL);
4055 if (gtk_widget_get_realized (widget))
4057 g_object_ref (widget);
4058 _gtk_tooltip_hide (widget);
4059 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4060 gtk_widget_set_realized (widget, FALSE);
4061 gtk_widget_set_mapped (widget, FALSE);
4062 g_object_unref (widget);
4066 /*****************************************
4068 *****************************************/
4071 * gtk_widget_queue_draw_area:
4072 * @widget: a #GtkWidget
4073 * @x: x coordinate of upper-left corner of rectangle to redraw
4074 * @y: y coordinate of upper-left corner of rectangle to redraw
4075 * @width: width of region to draw
4076 * @height: height of region to draw
4078 * Invalidates the rectangular area of @widget defined by @x, @y,
4079 * @width and @height by calling gdk_window_invalidate_rect() on the
4080 * widget's window and all its child windows. Once the main loop
4081 * becomes idle (after the current batch of events has been processed,
4082 * roughly), the window will receive expose events for the union of
4083 * all regions that have been invalidated.
4085 * Normally you would only use this function in widget
4086 * implementations. You might also use it, or
4087 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
4088 * #GtkDrawingArea or some portion thereof.
4090 * Frequently you can just call gdk_window_invalidate_rect() or
4091 * gdk_window_invalidate_region() instead of this function. Those
4092 * functions will invalidate only a single window, instead of the
4093 * widget and all its children.
4095 * The advantage of adding to the invalidated region compared to
4096 * simply drawing immediately is efficiency; using an invalid region
4097 * ensures that you only have to redraw one time.
4100 gtk_widget_queue_draw_area (GtkWidget *widget,
4106 GtkWidgetPrivate *priv;
4107 GdkRectangle invalid_rect;
4110 g_return_if_fail (GTK_IS_WIDGET (widget));
4112 priv = widget->priv;
4114 if (!gtk_widget_get_realized (widget))
4117 /* Just return if the widget or one of its ancestors isn't mapped */
4118 for (w = widget; w != NULL; w = w->priv->parent)
4119 if (!gtk_widget_get_mapped (w))
4122 /* Find the correct widget */
4124 if (gtk_widget_get_has_window (widget))
4128 /* Translate widget relative to window-relative */
4130 gint wx, wy, wwidth, wheight;
4132 gdk_window_get_position (priv->window, &wx, &wy);
4133 x -= wx - priv->allocation.x;
4134 y -= wy - priv->allocation.y;
4136 wwidth = gdk_window_get_width (priv->window);
4137 wheight = gdk_window_get_height (priv->window);
4139 if (x + width <= 0 || y + height <= 0 ||
4140 x >= wwidth || y >= wheight)
4151 if (x + width > wwidth)
4153 if (y + height > wheight)
4154 height = wheight - y;
4160 invalid_rect.width = width;
4161 invalid_rect.height = height;
4163 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4167 * gtk_widget_queue_draw:
4168 * @widget: a #GtkWidget
4170 * Equivalent to calling gtk_widget_queue_draw_area() for the
4171 * entire area of a widget.
4174 gtk_widget_queue_draw (GtkWidget *widget)
4178 g_return_if_fail (GTK_IS_WIDGET (widget));
4180 gtk_widget_get_allocation (widget, &rect);
4182 if (!gtk_widget_get_has_window (widget))
4183 gtk_widget_queue_draw_area (widget,
4184 rect.x, rect.y, rect.width, rect.height);
4186 gtk_widget_queue_draw_area (widget,
4187 0, 0, rect.width, rect.height);
4191 * gtk_widget_queue_resize:
4192 * @widget: a #GtkWidget
4194 * This function is only for use in widget implementations.
4195 * Flags a widget to have its size renegotiated; should
4196 * be called when a widget for some reason has a new size request.
4197 * For example, when you change the text in a #GtkLabel, #GtkLabel
4198 * queues a resize to ensure there's enough space for the new text.
4201 gtk_widget_queue_resize (GtkWidget *widget)
4203 g_return_if_fail (GTK_IS_WIDGET (widget));
4205 if (gtk_widget_get_realized (widget))
4206 gtk_widget_queue_shallow_draw (widget);
4208 _gtk_size_group_queue_resize (widget);
4212 * gtk_widget_queue_resize_no_redraw:
4213 * @widget: a #GtkWidget
4215 * This function works like gtk_widget_queue_resize(),
4216 * except that the widget is not invalidated.
4221 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4223 g_return_if_fail (GTK_IS_WIDGET (widget));
4225 _gtk_size_group_queue_resize (widget);
4229 * gtk_widget_size_request:
4230 * @widget: a #GtkWidget
4231 * @requisition: (out): a #GtkRequisition to be filled in
4233 * This function is typically used when implementing a #GtkContainer
4234 * subclass. Obtains the preferred size of a widget. The container
4235 * uses this information to arrange its child widgets and decide what
4236 * size allocations to give them with gtk_widget_size_allocate().
4238 * You can also call this function from an application, with some
4239 * caveats. Most notably, getting a size request requires the widget
4240 * to be associated with a screen, because font information may be
4241 * needed. Multihead-aware applications should keep this in mind.
4243 * Also remember that the size request is not necessarily the size
4244 * a widget will actually be allocated.
4246 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4249 gtk_widget_size_request (GtkWidget *widget,
4250 GtkRequisition *requisition)
4252 g_return_if_fail (GTK_IS_WIDGET (widget));
4254 gtk_widget_get_preferred_size (widget, requisition, NULL);
4258 * gtk_widget_get_child_requisition:
4259 * @widget: a #GtkWidget
4260 * @requisition: (out): a #GtkRequisition to be filled in
4262 * This function is only for use in widget implementations. Obtains
4263 * @widget->requisition, unless someone has forced a particular
4264 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4265 * in which case it returns that geometry instead of the widget's
4268 * This function differs from gtk_widget_size_request() in that
4269 * it retrieves the last size request value from @widget->requisition,
4270 * while gtk_widget_size_request() actually calls the "size_request" method
4271 * on @widget to compute the size request and fill in @widget->requisition,
4272 * and only then returns @widget->requisition.
4274 * Because this function does not call the "size_request" method, it
4275 * can only be used when you know that @widget->requisition is
4276 * up-to-date, that is, gtk_widget_size_request() has been called
4277 * since the last time a resize was queued. In general, only container
4278 * implementations have this information; applications should use
4279 * gtk_widget_size_request().
4282 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4285 gtk_widget_get_child_requisition (GtkWidget *widget,
4286 GtkRequisition *requisition)
4288 gtk_widget_get_preferred_size (widget, requisition, NULL);
4292 invalidate_predicate (GdkWindow *window,
4297 gdk_window_get_user_data (window, &user_data);
4299 return (user_data == data);
4302 /* Invalidate @region in widget->window and all children
4303 * of widget->window owned by widget. @region is in the
4304 * same coordinates as widget->allocation and will be
4305 * modified by this call.
4308 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4309 cairo_region_t *region)
4311 GtkWidgetPrivate *priv = widget->priv;
4313 if (!gtk_widget_get_realized (widget))
4316 if (gtk_widget_get_has_window (widget) && priv->parent)
4320 gdk_window_get_position (priv->window, &x, &y);
4321 cairo_region_translate (region, -x, -y);
4324 gdk_window_invalidate_maybe_recurse (priv->window, region,
4325 invalidate_predicate, widget);
4329 * gtk_widget_queue_shallow_draw:
4330 * @widget: a #GtkWidget
4332 * Like gtk_widget_queue_draw(), but only windows owned
4333 * by @widget are invalidated.
4336 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4339 cairo_region_t *region;
4341 if (!gtk_widget_get_realized (widget))
4344 gtk_widget_get_allocation (widget, &rect);
4346 region = cairo_region_create_rectangle (&rect);
4347 gtk_widget_invalidate_widget_windows (widget, region);
4348 cairo_region_destroy (region);
4352 * gtk_widget_size_allocate:
4353 * @widget: a #GtkWidget
4354 * @allocation: (inout): position and size to be allocated to @widget
4356 * This function is only used by #GtkContainer subclasses, to assign a size
4357 * and position to their child widgets.
4359 * In this function, the allocation may be adjusted. It will be forced
4360 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4361 * method on the child will be used to adjust the allocation. Standard
4362 * adjustments include removing the widget's margins, and applying the
4363 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4366 gtk_widget_size_allocate (GtkWidget *widget,
4367 GtkAllocation *allocation)
4369 GtkWidgetPrivate *priv;
4370 GdkRectangle real_allocation;
4371 GdkRectangle old_allocation;
4372 GdkRectangle adjusted_allocation;
4373 gboolean alloc_needed;
4374 gboolean size_changed;
4375 gboolean position_changed;
4377 priv = widget->priv;
4379 g_return_if_fail (GTK_IS_WIDGET (widget));
4381 #ifdef G_ENABLE_DEBUG
4382 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4393 parent = gtk_widget_get_parent (parent);
4396 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4397 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4398 2 * depth, " ", name,
4399 allocation->width, allocation->height);
4401 #endif /* G_ENABLE_DEBUG */
4403 alloc_needed = priv->alloc_needed;
4404 if (!priv->width_request_needed && !priv->height_request_needed)
4405 /* Preserve request/allocate ordering */
4406 priv->alloc_needed = FALSE;
4408 old_allocation = priv->allocation;
4409 real_allocation = *allocation;
4411 adjusted_allocation = real_allocation;
4412 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4414 if (adjusted_allocation.x < real_allocation.x ||
4415 adjusted_allocation.y < real_allocation.y ||
4416 (adjusted_allocation.x + adjusted_allocation.width) >
4417 (real_allocation.x + real_allocation.width) ||
4418 (adjusted_allocation.y + adjusted_allocation.height >
4419 real_allocation.y + real_allocation.height))
4421 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",
4422 G_OBJECT_TYPE_NAME (widget), widget,
4423 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4424 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4425 adjusted_allocation = real_allocation; /* veto it */
4429 real_allocation = adjusted_allocation;
4432 if (real_allocation.width < 0 || real_allocation.height < 0)
4434 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4435 real_allocation.width,
4436 real_allocation.height);
4439 real_allocation.width = MAX (real_allocation.width, 1);
4440 real_allocation.height = MAX (real_allocation.height, 1);
4442 size_changed = (old_allocation.width != real_allocation.width ||
4443 old_allocation.height != real_allocation.height);
4444 position_changed = (old_allocation.x != real_allocation.x ||
4445 old_allocation.y != real_allocation.y);
4447 if (!alloc_needed && !size_changed && !position_changed)
4450 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4452 if (gtk_widget_get_mapped (widget))
4454 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4456 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4458 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4459 cairo_region_union_rectangle (invalidate, &old_allocation);
4461 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4462 cairo_region_destroy (invalidate);
4467 if (priv->redraw_on_alloc)
4469 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4471 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4472 cairo_region_union_rectangle (invalidate, &old_allocation);
4474 gtk_widget_invalidate_widget_windows (widget, invalidate);
4475 cairo_region_destroy (invalidate);
4480 if ((size_changed || position_changed) && priv->parent &&
4481 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4483 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4484 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4485 cairo_region_destroy (invalidate);
4490 * gtk_widget_common_ancestor:
4491 * @widget_a: a #GtkWidget
4492 * @widget_b: a #GtkWidget
4494 * Find the common ancestor of @widget_a and @widget_b that
4495 * is closest to the two widgets.
4497 * Return value: the closest common ancestor of @widget_a and
4498 * @widget_b or %NULL if @widget_a and @widget_b do not
4499 * share a common ancestor.
4502 gtk_widget_common_ancestor (GtkWidget *widget_a,
4503 GtkWidget *widget_b)
4505 GtkWidget *parent_a;
4506 GtkWidget *parent_b;
4510 parent_a = widget_a;
4511 while (parent_a->priv->parent)
4513 parent_a = parent_a->priv->parent;
4517 parent_b = widget_b;
4518 while (parent_b->priv->parent)
4520 parent_b = parent_b->priv->parent;
4524 if (parent_a != parent_b)
4527 while (depth_a > depth_b)
4529 widget_a = widget_a->priv->parent;
4533 while (depth_b > depth_a)
4535 widget_b = widget_b->priv->parent;
4539 while (widget_a != widget_b)
4541 widget_a = widget_a->priv->parent;
4542 widget_b = widget_b->priv->parent;
4549 * gtk_widget_translate_coordinates:
4550 * @src_widget: a #GtkWidget
4551 * @dest_widget: a #GtkWidget
4552 * @src_x: X position relative to @src_widget
4553 * @src_y: Y position relative to @src_widget
4554 * @dest_x: (out): location to store X position relative to @dest_widget
4555 * @dest_y: (out): location to store Y position relative to @dest_widget
4557 * Translate coordinates relative to @src_widget's allocation to coordinates
4558 * relative to @dest_widget's allocations. In order to perform this
4559 * operation, both widgets must be realized, and must share a common
4562 * Return value: %FALSE if either widget was not realized, or there
4563 * was no common ancestor. In this case, nothing is stored in
4564 * *@dest_x and *@dest_y. Otherwise %TRUE.
4567 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4568 GtkWidget *dest_widget,
4574 GtkWidgetPrivate *src_priv = src_widget->priv;
4575 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4576 GtkWidget *ancestor;
4578 GList *dest_list = NULL;
4580 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4581 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4583 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4584 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4587 /* Translate from allocation relative to window relative */
4588 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4591 gdk_window_get_position (src_priv->window, &wx, &wy);
4593 src_x -= wx - src_priv->allocation.x;
4594 src_y -= wy - src_priv->allocation.y;
4598 src_x += src_priv->allocation.x;
4599 src_y += src_priv->allocation.y;
4602 /* Translate to the common ancestor */
4603 window = src_priv->window;
4604 while (window != ancestor->priv->window)
4608 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4613 window = gdk_window_get_effective_parent (window);
4615 if (!window) /* Handle GtkHandleBox */
4620 window = dest_priv->window;
4621 while (window != ancestor->priv->window)
4623 dest_list = g_list_prepend (dest_list, window);
4625 window = gdk_window_get_effective_parent (window);
4627 if (!window) /* Handle GtkHandleBox */
4629 g_list_free (dest_list);
4638 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4643 dest_list = g_list_remove (dest_list, dest_list->data);
4646 /* Translate from window relative to allocation relative */
4647 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4650 gdk_window_get_position (dest_priv->window, &wx, &wy);
4652 src_x += wx - dest_priv->allocation.x;
4653 src_y += wy - dest_priv->allocation.y;
4657 src_x -= dest_priv->allocation.x;
4658 src_y -= dest_priv->allocation.y;
4670 gtk_widget_real_size_allocate (GtkWidget *widget,
4671 GtkAllocation *allocation)
4673 GtkWidgetPrivate *priv = widget->priv;
4675 priv->allocation = *allocation;
4677 if (gtk_widget_get_realized (widget) &&
4678 gtk_widget_get_has_window (widget))
4680 gdk_window_move_resize (priv->window,
4681 allocation->x, allocation->y,
4682 allocation->width, allocation->height);
4687 get_span_inside_border (GtkWidget *widget,
4691 int allocated_outside_size,
4692 int natural_inside_size,
4693 int *coord_inside_p,
4696 int inside_allocated;
4700 inside_allocated = allocated_outside_size - start_pad - end_pad;
4702 content_size = natural_inside_size;
4703 if (content_size > inside_allocated)
4705 /* didn't get full natural size */
4706 content_size = inside_allocated;
4709 coord = size = 0; /* silence compiler */
4712 case GTK_ALIGN_FILL:
4714 size = inside_allocated;
4716 case GTK_ALIGN_START:
4718 size = content_size;
4721 coord = allocated_outside_size - end_pad - content_size;
4722 size = content_size;
4724 case GTK_ALIGN_CENTER:
4725 coord = start_pad + (inside_allocated - content_size) / 2;
4726 size = content_size;
4731 *coord_inside_p = coord;
4734 *size_inside_p = size;
4738 get_span_inside_border_horizontal (GtkWidget *widget,
4739 const GtkWidgetAuxInfo *aux_info,
4740 int allocated_outside_width,
4741 int natural_inside_width,
4743 int *width_inside_p)
4745 get_span_inside_border (widget,
4747 aux_info->margin.left,
4748 aux_info->margin.right,
4749 allocated_outside_width,
4750 natural_inside_width,
4756 get_span_inside_border_vertical (GtkWidget *widget,
4757 const GtkWidgetAuxInfo *aux_info,
4758 int allocated_outside_height,
4759 int natural_inside_height,
4761 int *height_inside_p)
4763 get_span_inside_border (widget,
4765 aux_info->margin.top,
4766 aux_info->margin.bottom,
4767 allocated_outside_height,
4768 natural_inside_height,
4774 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4775 GtkAllocation *allocation)
4777 const GtkWidgetAuxInfo *aux_info;
4779 gint natural_height;
4782 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4784 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4786 gtk_widget_get_preferred_width (widget, NULL, &natural_width);
4787 get_span_inside_border_horizontal (widget,
4793 gtk_widget_get_preferred_height_for_width (widget, w, NULL, &natural_height);
4794 get_span_inside_border_vertical (widget,
4800 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
4802 gtk_widget_get_preferred_height (widget, NULL, &natural_height);
4803 get_span_inside_border_vertical (widget,
4809 gtk_widget_get_preferred_width_for_height (widget, h, NULL, &natural_width);
4810 get_span_inside_border_horizontal (widget,
4819 allocation->width = w;
4820 allocation->height = h;
4824 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4827 GtkWidgetPrivate *priv = widget->priv;
4829 /* widgets must be onscreen for accels to take effect */
4830 return gtk_widget_is_sensitive (widget) &&
4831 gtk_widget_is_drawable (widget) &&
4832 gdk_window_is_viewable (priv->window);
4836 * gtk_widget_can_activate_accel:
4837 * @widget: a #GtkWidget
4838 * @signal_id: the ID of a signal installed on @widget
4840 * Determines whether an accelerator that activates the signal
4841 * identified by @signal_id can currently be activated.
4842 * This is done by emitting the #GtkWidget::can-activate-accel
4843 * signal on @widget; if the signal isn't overridden by a
4844 * handler or in a derived widget, then the default check is
4845 * that the widget must be sensitive, and the widget and all
4846 * its ancestors mapped.
4848 * Return value: %TRUE if the accelerator can be activated.
4853 gtk_widget_can_activate_accel (GtkWidget *widget,
4856 gboolean can_activate = FALSE;
4857 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4858 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4859 return can_activate;
4868 closure_accel_activate (GClosure *closure,
4869 GValue *return_value,
4870 guint n_param_values,
4871 const GValue *param_values,
4872 gpointer invocation_hint,
4873 gpointer marshal_data)
4875 AccelClosure *aclosure = (AccelClosure*) closure;
4876 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4879 g_signal_emit (closure->data, aclosure->signal_id, 0);
4881 /* whether accelerator was handled */
4882 g_value_set_boolean (return_value, can_activate);
4886 closures_destroy (gpointer data)
4888 GSList *slist, *closures = data;
4890 for (slist = closures; slist; slist = slist->next)
4892 g_closure_invalidate (slist->data);
4893 g_closure_unref (slist->data);
4895 g_slist_free (closures);
4899 widget_new_accel_closure (GtkWidget *widget,
4902 AccelClosure *aclosure;
4903 GClosure *closure = NULL;
4904 GSList *slist, *closures;
4906 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4907 for (slist = closures; slist; slist = slist->next)
4908 if (!gtk_accel_group_from_accel_closure (slist->data))
4910 /* reuse this closure */
4911 closure = slist->data;
4916 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4917 closures = g_slist_prepend (closures, g_closure_ref (closure));
4918 g_closure_sink (closure);
4919 g_closure_set_marshal (closure, closure_accel_activate);
4921 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4923 aclosure = (AccelClosure*) closure;
4924 g_assert (closure->data == widget);
4925 g_assert (closure->marshal == closure_accel_activate);
4926 aclosure->signal_id = signal_id;
4932 * gtk_widget_add_accelerator
4933 * @widget: widget to install an accelerator on
4934 * @accel_signal: widget signal to emit on accelerator activation
4935 * @accel_group: accel group for this widget, added to its toplevel
4936 * @accel_key: GDK keyval of the accelerator
4937 * @accel_mods: modifier key combination of the accelerator
4938 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4940 * Installs an accelerator for this @widget in @accel_group that causes
4941 * @accel_signal to be emitted if the accelerator is activated.
4942 * The @accel_group needs to be added to the widget's toplevel via
4943 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4944 * Accelerators added through this function are not user changeable during
4945 * runtime. If you want to support accelerators that can be changed by the
4946 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4947 * gtk_menu_item_set_accel_path() instead.
4950 gtk_widget_add_accelerator (GtkWidget *widget,
4951 const gchar *accel_signal,
4952 GtkAccelGroup *accel_group,
4954 GdkModifierType accel_mods,
4955 GtkAccelFlags accel_flags)
4960 g_return_if_fail (GTK_IS_WIDGET (widget));
4961 g_return_if_fail (accel_signal != NULL);
4962 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4964 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4965 if (!query.signal_id ||
4966 !(query.signal_flags & G_SIGNAL_ACTION) ||
4967 query.return_type != G_TYPE_NONE ||
4970 /* hmm, should be elaborate enough */
4971 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4972 G_OBJECT_TYPE_NAME (widget), accel_signal);
4976 closure = widget_new_accel_closure (widget, query.signal_id);
4978 g_object_ref (widget);
4980 /* install the accelerator. since we don't map this onto an accel_path,
4981 * the accelerator will automatically be locked.
4983 gtk_accel_group_connect (accel_group,
4986 accel_flags | GTK_ACCEL_LOCKED,
4989 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4991 g_object_unref (widget);
4995 * gtk_widget_remove_accelerator:
4996 * @widget: widget to install an accelerator on
4997 * @accel_group: accel group for this widget
4998 * @accel_key: GDK keyval of the accelerator
4999 * @accel_mods: modifier key combination of the accelerator
5000 * @returns: whether an accelerator was installed and could be removed
5002 * Removes an accelerator from @widget, previously installed with
5003 * gtk_widget_add_accelerator().
5006 gtk_widget_remove_accelerator (GtkWidget *widget,
5007 GtkAccelGroup *accel_group,
5009 GdkModifierType accel_mods)
5011 GtkAccelGroupEntry *ag_entry;
5012 GList *slist, *clist;
5015 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5016 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5018 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5019 clist = gtk_widget_list_accel_closures (widget);
5020 for (slist = clist; slist; slist = slist->next)
5024 for (i = 0; i < n; i++)
5025 if (slist->data == (gpointer) ag_entry[i].closure)
5027 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5029 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5031 g_list_free (clist);
5036 g_list_free (clist);
5038 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5039 accel_key, accel_mods, accel_group,
5040 G_OBJECT_TYPE_NAME (widget), widget);
5046 * gtk_widget_list_accel_closures:
5047 * @widget: widget to list accelerator closures for
5049 * Lists the closures used by @widget for accelerator group connections
5050 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5051 * The closures can be used to monitor accelerator changes on @widget,
5052 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5053 * #GtkAccelGroup of a closure which can be found out with
5054 * gtk_accel_group_from_accel_closure().
5056 * Return value: (transfer container) (element-type GClosure):
5057 * a newly allocated #GList of closures
5060 gtk_widget_list_accel_closures (GtkWidget *widget)
5063 GList *clist = NULL;
5065 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5067 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5068 if (gtk_accel_group_from_accel_closure (slist->data))
5069 clist = g_list_prepend (clist, slist->data);
5075 GtkAccelGroup *accel_group;
5080 destroy_accel_path (gpointer data)
5082 AccelPath *apath = data;
5084 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5086 /* closures_destroy takes care of unrefing the closure */
5087 g_object_unref (apath->accel_group);
5089 g_slice_free (AccelPath, apath);
5094 * gtk_widget_set_accel_path:
5095 * @widget: a #GtkWidget
5096 * @accel_path: (allow-none): path used to look up the accelerator
5097 * @accel_group: (allow-none): a #GtkAccelGroup.
5099 * Given an accelerator group, @accel_group, and an accelerator path,
5100 * @accel_path, sets up an accelerator in @accel_group so whenever the
5101 * key binding that is defined for @accel_path is pressed, @widget
5102 * will be activated. This removes any accelerators (for any
5103 * accelerator group) installed by previous calls to
5104 * gtk_widget_set_accel_path(). Associating accelerators with
5105 * paths allows them to be modified by the user and the modifications
5106 * to be saved for future use. (See gtk_accel_map_save().)
5108 * This function is a low level function that would most likely
5109 * be used by a menu creation system like #GtkUIManager. If you
5110 * use #GtkUIManager, setting up accelerator paths will be done
5113 * Even when you you aren't using #GtkUIManager, if you only want to
5114 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5115 * provides a somewhat more convenient interface.
5117 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5118 * pass a static string, you can save some memory by interning it first with
5119 * g_intern_static_string().
5122 gtk_widget_set_accel_path (GtkWidget *widget,
5123 const gchar *accel_path,
5124 GtkAccelGroup *accel_group)
5128 g_return_if_fail (GTK_IS_WIDGET (widget));
5129 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5133 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5134 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5136 gtk_accel_map_add_entry (accel_path, 0, 0);
5137 apath = g_slice_new (AccelPath);
5138 apath->accel_group = g_object_ref (accel_group);
5139 apath->path_quark = g_quark_from_string (accel_path);
5140 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5145 /* also removes possible old settings */
5146 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5149 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5151 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5155 _gtk_widget_get_accel_path (GtkWidget *widget,
5160 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5162 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5164 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5165 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5169 * gtk_widget_mnemonic_activate:
5170 * @widget: a #GtkWidget
5171 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5173 * Emits the #GtkWidget::mnemonic-activate signal.
5175 * The default handler for this signal activates the @widget if
5176 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5179 * Returns: %TRUE if the signal has been handled
5182 gtk_widget_mnemonic_activate (GtkWidget *widget,
5183 gboolean group_cycling)
5187 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5189 group_cycling = group_cycling != FALSE;
5190 if (!gtk_widget_is_sensitive (widget))
5193 g_signal_emit (widget,
5194 widget_signals[MNEMONIC_ACTIVATE],
5202 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5203 gboolean group_cycling)
5205 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5206 gtk_widget_activate (widget);
5207 else if (gtk_widget_get_can_focus (widget))
5208 gtk_widget_grab_focus (widget);
5211 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5212 G_OBJECT_TYPE_NAME (widget));
5213 gtk_widget_error_bell (widget);
5218 static const cairo_user_data_key_t event_key;
5221 _gtk_cairo_get_event (cairo_t *cr)
5223 g_return_val_if_fail (cr != NULL, NULL);
5225 return cairo_get_user_data (cr, &event_key);
5229 gtk_cairo_set_event (cairo_t *cr,
5230 GdkEventExpose *event)
5232 cairo_set_user_data (cr, &event_key, event, NULL);
5236 * gtk_cairo_should_draw_window:
5237 * @cr: a cairo context
5238 * @window: the window to check
5240 * This function is supposed to be called in GtkWidget::draw
5241 * implementations for widgets that support multiple windows.
5242 * @cr must be untransformed from invoking of the draw function.
5243 * This function will return %TRUE if the contents of the given
5244 * @window are supposed to be drawn and %FALSE otherwise. Note
5245 * that when the drawing was not initiated by the windowing
5246 * system this function will return %TRUE for all windows, so
5247 * you need to draw the bottommost window first. Also, do not
5248 * use "else if" statements to check which window should be drawn.
5250 * Returns: %TRUE if @window should be drawn
5253 gtk_cairo_should_draw_window (cairo_t *cr,
5256 GdkEventExpose *event;
5258 g_return_val_if_fail (cr != NULL, FALSE);
5259 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5261 event = _gtk_cairo_get_event (cr);
5263 return event == NULL ||
5264 event->window == window;
5267 /* code shared by gtk_container_propagate_draw() and
5271 _gtk_widget_draw_internal (GtkWidget *widget,
5273 gboolean clip_to_size)
5275 if (!gtk_widget_is_drawable (widget))
5280 cairo_rectangle (cr,
5282 widget->priv->allocation.width,
5283 widget->priv->allocation.height);
5287 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5291 g_signal_emit (widget, widget_signals[DRAW],
5299 * @widget: the widget to draw. It must be drawable (see
5300 * gtk_widget_is_drawable()) and a size must have been allocated.
5301 * @cr: a cairo context to draw to
5303 * Draws @widget to @cr. The top left corner of the widget will be
5304 * drawn to the currently set origin point of @cr.
5306 * You should pass a cairo context as @cr argument that is in an
5307 * original state. Otherwise the resulting drawing is undefined. For
5308 * example changing the operator using cairo_set_operator() or the
5309 * line width using cairo_set_line_width() might have unwanted side
5311 * You may however change the context's transform matrix - like with
5312 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5313 * region with cairo_clip() prior to calling this function. Also, it
5314 * is fine to modify the context with cairo_save() and
5315 * cairo_push_group() prior to calling this function.
5317 * <note><para>Special purpose widgets may contain special code for
5318 * rendering to the screen and might appear differently on screen
5319 * and when rendered using gtk_widget_draw().</para></note>
5322 gtk_widget_draw (GtkWidget *widget,
5325 GdkEventExpose *tmp_event;
5327 g_return_if_fail (GTK_IS_WIDGET (widget));
5328 g_return_if_fail (!widget->priv->alloc_needed);
5329 g_return_if_fail (cr != NULL);
5332 /* We have to reset the event here so that draw functions can call
5333 * gtk_widget_draw() on random other widgets and get the desired
5334 * effect: Drawing all contents, not just the current window.
5336 tmp_event = _gtk_cairo_get_event (cr);
5337 gtk_cairo_set_event (cr, NULL);
5339 _gtk_widget_draw_internal (widget, cr, TRUE);
5341 gtk_cairo_set_event (cr, tmp_event);
5346 gtk_widget_real_key_press_event (GtkWidget *widget,
5349 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5353 gtk_widget_real_key_release_event (GtkWidget *widget,
5356 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5360 gtk_widget_real_focus_in_event (GtkWidget *widget,
5361 GdkEventFocus *event)
5363 gtk_widget_queue_shallow_draw (widget);
5369 gtk_widget_real_focus_out_event (GtkWidget *widget,
5370 GdkEventFocus *event)
5372 gtk_widget_queue_shallow_draw (widget);
5377 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5378 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5382 * @widget: a #GtkWidget
5383 * @event: a #GdkEvent
5385 * Rarely-used function. This function is used to emit
5386 * the event signals on a widget (those signals should never
5387 * be emitted without using this function to do so).
5388 * If you want to synthesize an event though, don't use this function;
5389 * instead, use gtk_main_do_event() so the event will behave as if
5390 * it were in the event queue. Don't synthesize expose events; instead,
5391 * use gdk_window_invalidate_rect() to invalidate a region of the
5394 * Return value: return from the event signal emission (%TRUE if
5395 * the event was handled)
5398 gtk_widget_event (GtkWidget *widget,
5401 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5402 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5404 if (event->type == GDK_EXPOSE)
5406 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5407 "the same effect, call gdk_window_invalidate_rect/region(), "
5408 "followed by gdk_window_process_updates().");
5412 return gtk_widget_event_internal (widget, event);
5415 /* Returns TRUE if a translation should be done */
5417 gtk_widget_get_translation_to_window (GtkWidget *widget,
5422 GdkWindow *w, *widget_window;
5424 if (!gtk_widget_get_has_window (widget))
5426 *x = -widget->priv->allocation.x;
5427 *y = -widget->priv->allocation.y;
5435 widget_window = gtk_widget_get_window (widget);
5437 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5440 gdk_window_get_position (w, &wx, &wy);
5457 * gtk_cairo_transform_to_window:
5458 * @cr: the cairo context to transform
5459 * @widget: the widget the context is currently centered for
5460 * @window: the window to transform the context to
5462 * Transforms the given cairo context @cr that from @widget-relative
5463 * coordinates to @window-relative coordinates.
5464 * If the @widget's window is not an ancestor of @window, no
5465 * modification will be applied.
5467 * This is the inverse to the transformation GTK applies when
5468 * preparing an expose event to be emitted with the GtkWidget::draw
5469 * signal. It is intended to help porting multiwindow widgets from
5470 * GTK 2 to the rendering architecture of GTK 3.
5473 gtk_cairo_transform_to_window (cairo_t *cr,
5479 g_return_if_fail (cr != NULL);
5480 g_return_if_fail (GTK_IS_WIDGET (widget));
5481 g_return_if_fail (GDK_IS_WINDOW (window));
5483 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5484 cairo_translate (cr, x, y);
5488 * gtk_widget_send_expose:
5489 * @widget: a #GtkWidget
5490 * @event: a expose #GdkEvent
5492 * Very rarely-used function. This function is used to emit
5493 * an expose event on a widget. This function is not normally used
5494 * directly. The only time it is used is when propagating an expose
5495 * event to a child %NO_WINDOW widget, and that is normally done
5496 * using gtk_container_propagate_draw().
5498 * If you want to force an area of a window to be redrawn,
5499 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5500 * To cause the redraw to be done immediately, follow that call
5501 * with a call to gdk_window_process_updates().
5503 * Return value: return from the event signal emission (%TRUE if
5504 * the event was handled)
5507 gtk_widget_send_expose (GtkWidget *widget,
5510 gboolean result = FALSE;
5515 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5516 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5517 g_return_val_if_fail (event != NULL, TRUE);
5518 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5520 cr = gdk_cairo_create (event->expose.window);
5521 gtk_cairo_set_event (cr, &event->expose);
5523 gdk_cairo_region (cr, event->expose.region);
5526 do_clip = gtk_widget_get_translation_to_window (widget,
5527 event->expose.window,
5529 cairo_translate (cr, -x, -y);
5531 _gtk_widget_draw_internal (widget, cr, do_clip);
5533 /* unset here, so if someone keeps a reference to cr we
5534 * don't leak the window. */
5535 gtk_cairo_set_event (cr, NULL);
5542 event_window_is_still_viewable (GdkEvent *event)
5544 /* Check that we think the event's window is viewable before
5545 * delivering the event, to prevent suprises. We do this here
5546 * at the last moment, since the event may have been queued
5547 * up behind other events, held over a recursive main loop, etc.
5549 switch (event->type)
5552 case GDK_MOTION_NOTIFY:
5553 case GDK_BUTTON_PRESS:
5554 case GDK_2BUTTON_PRESS:
5555 case GDK_3BUTTON_PRESS:
5557 case GDK_ENTER_NOTIFY:
5558 case GDK_PROXIMITY_IN:
5560 return event->any.window && gdk_window_is_viewable (event->any.window);
5563 /* The following events are the second half of paired events;
5564 * we always deliver them to deal with widgets that clean up
5565 * on the second half.
5567 case GDK_BUTTON_RELEASE:
5568 case GDK_KEY_RELEASE:
5569 case GDK_LEAVE_NOTIFY:
5570 case GDK_PROXIMITY_OUT:
5574 /* Remaining events would make sense on an not-viewable window,
5575 * or don't have an associated window.
5582 gtk_widget_event_internal (GtkWidget *widget,
5585 gboolean return_val = FALSE;
5587 /* We check only once for is-still-visible; if someone
5588 * hides the window in on of the signals on the widget,
5589 * they are responsible for returning TRUE to terminate
5592 if (!event_window_is_still_viewable (event))
5595 g_object_ref (widget);
5597 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5598 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5603 switch (event->type)
5608 case GDK_BUTTON_PRESS:
5609 case GDK_2BUTTON_PRESS:
5610 case GDK_3BUTTON_PRESS:
5611 signal_num = BUTTON_PRESS_EVENT;
5614 signal_num = SCROLL_EVENT;
5616 case GDK_BUTTON_RELEASE:
5617 signal_num = BUTTON_RELEASE_EVENT;
5619 case GDK_MOTION_NOTIFY:
5620 signal_num = MOTION_NOTIFY_EVENT;
5623 signal_num = DELETE_EVENT;
5626 signal_num = DESTROY_EVENT;
5627 _gtk_tooltip_hide (widget);
5630 signal_num = KEY_PRESS_EVENT;
5632 case GDK_KEY_RELEASE:
5633 signal_num = KEY_RELEASE_EVENT;
5635 case GDK_ENTER_NOTIFY:
5636 signal_num = ENTER_NOTIFY_EVENT;
5638 case GDK_LEAVE_NOTIFY:
5639 signal_num = LEAVE_NOTIFY_EVENT;
5641 case GDK_FOCUS_CHANGE:
5642 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5643 if (event->focus_change.in)
5644 _gtk_tooltip_focus_in (widget);
5646 _gtk_tooltip_focus_out (widget);
5649 signal_num = CONFIGURE_EVENT;
5652 signal_num = MAP_EVENT;
5655 signal_num = UNMAP_EVENT;
5657 case GDK_WINDOW_STATE:
5658 signal_num = WINDOW_STATE_EVENT;
5660 case GDK_PROPERTY_NOTIFY:
5661 signal_num = PROPERTY_NOTIFY_EVENT;
5663 case GDK_SELECTION_CLEAR:
5664 signal_num = SELECTION_CLEAR_EVENT;
5666 case GDK_SELECTION_REQUEST:
5667 signal_num = SELECTION_REQUEST_EVENT;
5669 case GDK_SELECTION_NOTIFY:
5670 signal_num = SELECTION_NOTIFY_EVENT;
5672 case GDK_PROXIMITY_IN:
5673 signal_num = PROXIMITY_IN_EVENT;
5675 case GDK_PROXIMITY_OUT:
5676 signal_num = PROXIMITY_OUT_EVENT;
5679 signal_num = NO_EXPOSE_EVENT;
5681 case GDK_CLIENT_EVENT:
5682 signal_num = CLIENT_EVENT;
5685 signal_num = EXPOSE_EVENT;
5687 case GDK_VISIBILITY_NOTIFY:
5688 signal_num = VISIBILITY_NOTIFY_EVENT;
5690 case GDK_GRAB_BROKEN:
5691 signal_num = GRAB_BROKEN;
5694 signal_num = DAMAGE_EVENT;
5697 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5701 if (signal_num != -1)
5702 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5704 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5705 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5709 g_object_unref (widget);
5715 * gtk_widget_activate:
5716 * @widget: a #GtkWidget that's activatable
5718 * For widgets that can be "activated" (buttons, menu items, etc.)
5719 * this function activates them. Activation is what happens when you
5720 * press Enter on a widget during key navigation. If @widget isn't
5721 * activatable, the function returns %FALSE.
5723 * Return value: %TRUE if the widget was activatable
5726 gtk_widget_activate (GtkWidget *widget)
5728 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5730 if (WIDGET_CLASS (widget)->activate_signal)
5732 /* FIXME: we should eventually check the signals signature here */
5733 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5742 * gtk_widget_set_scroll_adjustments:
5743 * @widget: a #GtkWidget
5744 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5745 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5747 * For widgets that support scrolling, sets the scroll adjustments and
5748 * returns %TRUE. For widgets that don't support scrolling, does
5749 * nothing and returns %FALSE. Widgets that don't support scrolling
5750 * can be scrolled by placing them in a #GtkViewport, which does
5751 * support scrolling.
5753 * Return value: %TRUE if the widget supports scrolling
5756 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5757 GtkAdjustment *hadjustment,
5758 GtkAdjustment *vadjustment)
5763 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5766 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5768 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5770 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5774 g_signal_query (signal_id, &query);
5775 if (!query.signal_id ||
5776 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5777 query.return_type != G_TYPE_NONE ||
5778 query.n_params != 2 ||
5779 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5780 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5782 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5783 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5787 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5792 gtk_widget_reparent_subwindows (GtkWidget *widget,
5793 GdkWindow *new_window)
5795 GtkWidgetPrivate *priv = widget->priv;
5797 if (!gtk_widget_get_has_window (widget))
5799 GList *children = gdk_window_get_children (priv->window);
5802 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5804 GdkWindow *window = tmp_list->data;
5807 gdk_window_get_user_data (window, &child);
5808 while (child && child != widget)
5809 child = ((GtkWidget*) child)->priv->parent;
5812 gdk_window_reparent (window, new_window, 0, 0);
5815 g_list_free (children);
5820 GList *tmp_list, *children;
5822 parent = gdk_window_get_parent (priv->window);
5825 gdk_window_reparent (priv->window, new_window, 0, 0);
5828 children = gdk_window_get_children (parent);
5830 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5832 GdkWindow *window = tmp_list->data;
5835 gdk_window_get_user_data (window, &child);
5837 if (child == widget)
5838 gdk_window_reparent (window, new_window, 0, 0);
5841 g_list_free (children);
5847 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5848 gpointer client_data)
5850 GtkWidgetPrivate *priv = widget->priv;
5852 g_assert (client_data != NULL);
5854 if (!gtk_widget_get_has_window (widget))
5857 g_object_unref (priv->window);
5858 priv->window = (GdkWindow*) client_data;
5860 g_object_ref (priv->window);
5862 if (GTK_IS_CONTAINER (widget))
5863 gtk_container_forall (GTK_CONTAINER (widget),
5864 gtk_widget_reparent_fixup_child,
5870 * gtk_widget_reparent:
5871 * @widget: a #GtkWidget
5872 * @new_parent: a #GtkContainer to move the widget into
5874 * Moves a widget from one #GtkContainer to another, handling reference
5875 * count issues to avoid destroying the widget.
5878 gtk_widget_reparent (GtkWidget *widget,
5879 GtkWidget *new_parent)
5881 GtkWidgetPrivate *priv;
5883 g_return_if_fail (GTK_IS_WIDGET (widget));
5884 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5885 priv = widget->priv;
5886 g_return_if_fail (priv->parent != NULL);
5888 if (priv->parent != new_parent)
5890 /* First try to see if we can get away without unrealizing
5891 * the widget as we reparent it. if so we set a flag so
5892 * that gtk_widget_unparent doesn't unrealize widget
5894 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5895 priv->in_reparent = TRUE;
5897 g_object_ref (widget);
5898 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5899 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5900 g_object_unref (widget);
5902 if (priv->in_reparent)
5904 priv->in_reparent = FALSE;
5906 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5907 gtk_widget_reparent_fixup_child (widget,
5908 gtk_widget_get_parent_window (widget));
5911 g_object_notify (G_OBJECT (widget), "parent");
5916 * gtk_widget_intersect:
5917 * @widget: a #GtkWidget
5918 * @area: a rectangle
5919 * @intersection: rectangle to store intersection of @widget and @area
5921 * Computes the intersection of a @widget's area and @area, storing
5922 * the intersection in @intersection, and returns %TRUE if there was
5923 * an intersection. @intersection may be %NULL if you're only
5924 * interested in whether there was an intersection.
5926 * Return value: %TRUE if there was an intersection
5929 gtk_widget_intersect (GtkWidget *widget,
5930 const GdkRectangle *area,
5931 GdkRectangle *intersection)
5933 GtkWidgetPrivate *priv;
5938 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5939 g_return_val_if_fail (area != NULL, FALSE);
5941 priv = widget->priv;
5944 dest = intersection;
5948 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5950 if (return_val && intersection && gtk_widget_get_has_window (widget))
5952 intersection->x -= priv->allocation.x;
5953 intersection->y -= priv->allocation.y;
5960 * gtk_widget_region_intersect:
5961 * @widget: a #GtkWidget
5962 * @region: a #cairo_region_t, in the same coordinate system as
5963 * @widget->allocation. That is, relative to @widget->window
5964 * for %NO_WINDOW widgets; relative to the parent window
5965 * of @widget->window for widgets with their own window.
5966 * @returns: A newly allocated region holding the intersection of @widget
5967 * and @region. The coordinates of the return value are
5968 * relative to @widget->window for %NO_WINDOW widgets, and
5969 * relative to the parent window of @widget->window for
5970 * widgets with their own window.
5972 * Computes the intersection of a @widget's area and @region, returning
5973 * the intersection. The result may be empty, use cairo_region_is_empty() to
5977 gtk_widget_region_intersect (GtkWidget *widget,
5978 const cairo_region_t *region)
5981 cairo_region_t *dest;
5983 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5984 g_return_val_if_fail (region != NULL, NULL);
5986 gtk_widget_get_allocation (widget, &rect);
5988 dest = cairo_region_create_rectangle (&rect);
5990 cairo_region_intersect (dest, region);
5996 * _gtk_widget_grab_notify:
5997 * @widget: a #GtkWidget
5998 * @was_grabbed: whether a grab is now in effect
6000 * Emits the #GtkWidget::grab-notify signal on @widget.
6005 _gtk_widget_grab_notify (GtkWidget *widget,
6006 gboolean was_grabbed)
6008 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6012 * gtk_widget_grab_focus:
6013 * @widget: a #GtkWidget
6015 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6016 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6017 * something like #GtkFrame won't work.
6019 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6020 * gtk_widget_set_can_focus() to modify that flag.
6022 * The widget also needs to be realized and mapped. This is indicated by the
6023 * related signals. Grabbing the focus immediately after creating the widget
6024 * will likely fail and cause critical warnings.
6027 gtk_widget_grab_focus (GtkWidget *widget)
6029 g_return_if_fail (GTK_IS_WIDGET (widget));
6031 if (!gtk_widget_is_sensitive (widget))
6034 g_object_ref (widget);
6035 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6036 g_object_notify (G_OBJECT (widget), "has-focus");
6037 g_object_unref (widget);
6041 reset_focus_recurse (GtkWidget *widget,
6044 if (GTK_IS_CONTAINER (widget))
6046 GtkContainer *container;
6048 container = GTK_CONTAINER (widget);
6049 gtk_container_set_focus_child (container, NULL);
6051 gtk_container_foreach (container,
6052 reset_focus_recurse,
6058 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6060 if (gtk_widget_get_can_focus (focus_widget))
6062 GtkWidget *toplevel;
6065 /* clear the current focus setting, break if the current widget
6066 * is the focus widget's parent, since containers above that will
6067 * be set by the next loop.
6069 toplevel = gtk_widget_get_toplevel (focus_widget);
6070 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6072 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6074 if (widget == focus_widget)
6076 /* We call _gtk_window_internal_set_focus() here so that the
6077 * toplevel window can request the focus if necessary.
6078 * This is needed when the toplevel is a GtkPlug
6080 if (!gtk_widget_has_focus (widget))
6081 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6088 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6090 widget = widget->priv->parent;
6091 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6095 else if (toplevel != focus_widget)
6097 /* gtk_widget_grab_focus() operates on a tree without window...
6098 * actually, this is very questionable behaviour.
6101 gtk_container_foreach (GTK_CONTAINER (toplevel),
6102 reset_focus_recurse,
6106 /* now propagate the new focus up the widget tree and finally
6107 * set it on the window
6109 widget = focus_widget;
6110 while (widget->priv->parent)
6112 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6113 widget = widget->priv->parent;
6115 if (GTK_IS_WINDOW (widget))
6116 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6121 gtk_widget_real_query_tooltip (GtkWidget *widget,
6124 gboolean keyboard_tip,
6125 GtkTooltip *tooltip)
6127 gchar *tooltip_markup;
6128 gboolean has_tooltip;
6130 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6131 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6133 if (has_tooltip && tooltip_markup)
6135 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6143 gtk_widget_real_show_help (GtkWidget *widget,
6144 GtkWidgetHelpType help_type)
6146 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6148 _gtk_tooltip_toggle_keyboard_mode (widget);
6157 gtk_widget_real_focus (GtkWidget *widget,
6158 GtkDirectionType direction)
6160 if (!gtk_widget_get_can_focus (widget))
6163 if (!gtk_widget_is_focus (widget))
6165 gtk_widget_grab_focus (widget);
6173 gtk_widget_real_move_focus (GtkWidget *widget,
6174 GtkDirectionType direction)
6176 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6178 if (GTK_IS_WINDOW (toplevel) &&
6179 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
6181 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
6187 gtk_widget_real_keynav_failed (GtkWidget *widget,
6188 GtkDirectionType direction)
6190 gboolean cursor_only;
6194 case GTK_DIR_TAB_FORWARD:
6195 case GTK_DIR_TAB_BACKWARD:
6202 g_object_get (gtk_widget_get_settings (widget),
6203 "gtk-keynav-cursor-only", &cursor_only,
6210 gtk_widget_error_bell (widget);
6216 * gtk_widget_set_can_focus:
6217 * @widget: a #GtkWidget
6218 * @can_focus: whether or not @widget can own the input focus.
6220 * Specifies whether @widget can own the input focus. See
6221 * gtk_widget_grab_focus() for actually setting the input focus on a
6227 gtk_widget_set_can_focus (GtkWidget *widget,
6230 g_return_if_fail (GTK_IS_WIDGET (widget));
6232 if (widget->priv->can_focus != can_focus)
6234 widget->priv->can_focus = can_focus;
6236 gtk_widget_queue_resize (widget);
6237 g_object_notify (G_OBJECT (widget), "can-focus");
6242 * gtk_widget_get_can_focus:
6243 * @widget: a #GtkWidget
6245 * Determines whether @widget can own the input focus. See
6246 * gtk_widget_set_can_focus().
6248 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6253 gtk_widget_get_can_focus (GtkWidget *widget)
6255 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6257 return widget->priv->can_focus;
6261 * gtk_widget_has_focus:
6262 * @widget: a #GtkWidget
6264 * Determines if the widget has the global input focus. See
6265 * gtk_widget_is_focus() for the difference between having the global
6266 * input focus, and only having the focus within a toplevel.
6268 * Return value: %TRUE if the widget has the global input focus.
6273 gtk_widget_has_focus (GtkWidget *widget)
6275 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6277 return widget->priv->has_focus;
6281 * gtk_widget_is_focus:
6282 * @widget: a #GtkWidget
6284 * Determines if the widget is the focus widget within its
6285 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6286 * necessarily set; %HAS_FOCUS will only be set if the
6287 * toplevel widget additionally has the global input focus.)
6289 * Return value: %TRUE if the widget is the focus widget.
6292 gtk_widget_is_focus (GtkWidget *widget)
6294 GtkWidget *toplevel;
6296 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6298 toplevel = gtk_widget_get_toplevel (widget);
6300 if (GTK_IS_WINDOW (toplevel))
6301 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6307 * gtk_widget_set_can_default:
6308 * @widget: a #GtkWidget
6309 * @can_default: whether or not @widget can be a default widget.
6311 * Specifies whether @widget can be a default widget. See
6312 * gtk_widget_grab_default() for details about the meaning of
6318 gtk_widget_set_can_default (GtkWidget *widget,
6319 gboolean can_default)
6321 g_return_if_fail (GTK_IS_WIDGET (widget));
6323 if (widget->priv->can_default != can_default)
6325 widget->priv->can_default = can_default;
6327 gtk_widget_queue_resize (widget);
6328 g_object_notify (G_OBJECT (widget), "can-default");
6333 * gtk_widget_get_can_default:
6334 * @widget: a #GtkWidget
6336 * Determines whether @widget can be a default widget. See
6337 * gtk_widget_set_can_default().
6339 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6344 gtk_widget_get_can_default (GtkWidget *widget)
6346 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6348 return widget->priv->can_default;
6352 * gtk_widget_has_default:
6353 * @widget: a #GtkWidget
6355 * Determines whether @widget is the current default widget within its
6356 * toplevel. See gtk_widget_set_can_default().
6358 * Return value: %TRUE if @widget is the current default widget within
6359 * its toplevel, %FALSE otherwise
6364 gtk_widget_has_default (GtkWidget *widget)
6366 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6368 return widget->priv->has_default;
6372 _gtk_widget_set_has_default (GtkWidget *widget,
6373 gboolean has_default)
6375 widget->priv->has_default = has_default;
6379 * gtk_widget_grab_default:
6380 * @widget: a #GtkWidget
6382 * Causes @widget to become the default widget. @widget must have the
6383 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6384 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6385 * %TRUE)</literal>. The default widget is activated when
6386 * the user presses Enter in a window. Default widgets must be
6387 * activatable, that is, gtk_widget_activate() should affect them. Note
6388 * that #GtkEntry widgets require the "activates-default" property
6389 * set to %TRUE before they activate the default widget when Enter
6390 * is pressed and the #GtkEntry is focused.
6393 gtk_widget_grab_default (GtkWidget *widget)
6397 g_return_if_fail (GTK_IS_WIDGET (widget));
6398 g_return_if_fail (gtk_widget_get_can_default (widget));
6400 window = gtk_widget_get_toplevel (widget);
6402 if (window && gtk_widget_is_toplevel (window))
6403 gtk_window_set_default (GTK_WINDOW (window), widget);
6405 g_warning (G_STRLOC ": widget not within a GtkWindow");
6409 * gtk_widget_set_receives_default:
6410 * @widget: a #GtkWidget
6411 * @receives_default: whether or not @widget can be a default widget.
6413 * Specifies whether @widget will be treated as the default widget
6414 * within its toplevel when it has the focus, even if another widget
6417 * See gtk_widget_grab_default() for details about the meaning of
6423 gtk_widget_set_receives_default (GtkWidget *widget,
6424 gboolean receives_default)
6426 g_return_if_fail (GTK_IS_WIDGET (widget));
6428 if (widget->priv->receives_default != receives_default)
6430 widget->priv->receives_default = receives_default;
6432 g_object_notify (G_OBJECT (widget), "receives-default");
6437 * gtk_widget_get_receives_default:
6438 * @widget: a #GtkWidget
6440 * Determines whether @widget is alyways treated as default widget
6441 * withing its toplevel when it has the focus, even if another widget
6444 * See gtk_widget_set_receives_default().
6446 * Return value: %TRUE if @widget acts as default widget when focussed,
6452 gtk_widget_get_receives_default (GtkWidget *widget)
6454 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6456 return widget->priv->receives_default;
6460 * gtk_widget_has_grab:
6461 * @widget: a #GtkWidget
6463 * Determines whether the widget is currently grabbing events, so it
6464 * is the only widget receiving input events (keyboard and mouse).
6466 * See also gtk_grab_add().
6468 * Return value: %TRUE if the widget is in the grab_widgets stack
6473 gtk_widget_has_grab (GtkWidget *widget)
6475 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6477 return widget->priv->has_grab;
6481 _gtk_widget_set_has_grab (GtkWidget *widget,
6484 widget->priv->has_grab = has_grab;
6488 * gtk_widget_device_is_shadowed:
6489 * @widget: a #GtkWidget
6490 * @device: a #GdkDevice
6492 * Returns %TRUE if @device has been shadowed by a GTK+
6493 * device grab on another widget, so it would stop sending
6494 * events to @widget. This may be used in the
6495 * #GtkWidget::grab-notify signal to check for specific
6496 * devices. See gtk_device_grab_add().
6498 * Returns: %TRUE if there is an ongoing grab on @device
6499 * by another #GtkWidget than @widget.
6504 gtk_widget_device_is_shadowed (GtkWidget *widget,
6507 GtkWindowGroup *group;
6508 GtkWidget *grab_widget, *toplevel;
6510 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6511 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6513 if (!gtk_widget_get_realized (widget))
6516 toplevel = gtk_widget_get_toplevel (widget);
6518 if (GTK_IS_WINDOW (toplevel))
6519 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6521 group = gtk_window_get_group (NULL);
6523 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6525 /* Widget not inside the hierarchy of grab_widget */
6527 widget != grab_widget &&
6528 !gtk_widget_is_ancestor (widget, grab_widget))
6531 grab_widget = gtk_window_group_get_current_grab (group);
6532 if (grab_widget && widget != grab_widget &&
6533 !gtk_widget_is_ancestor (widget, grab_widget))
6540 * gtk_widget_set_name:
6541 * @widget: a #GtkWidget
6542 * @name: name for the widget
6544 * Widgets can be named, which allows you to refer to them from a
6545 * gtkrc file. You can apply a style to widgets with a particular name
6546 * in the gtkrc file. See the documentation for gtkrc files (on the
6547 * same page as the docs for #GtkRcStyle).
6549 * Note that widget names are separated by periods in paths (see
6550 * gtk_widget_path()), so names with embedded periods may cause confusion.
6553 gtk_widget_set_name (GtkWidget *widget,
6556 GtkWidgetPrivate *priv;
6559 g_return_if_fail (GTK_IS_WIDGET (widget));
6561 priv = widget->priv;
6563 new_name = g_strdup (name);
6564 g_free (priv->name);
6565 priv->name = new_name;
6568 gtk_widget_reset_rc_style (widget);
6570 g_object_notify (G_OBJECT (widget), "name");
6574 * gtk_widget_get_name:
6575 * @widget: a #GtkWidget
6577 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6578 * significance of widget names.
6580 * Return value: name of the widget. This string is owned by GTK+ and
6581 * should not be modified or freed
6583 G_CONST_RETURN gchar*
6584 gtk_widget_get_name (GtkWidget *widget)
6586 GtkWidgetPrivate *priv;
6588 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6590 priv = widget->priv;
6594 return G_OBJECT_TYPE_NAME (widget);
6598 * gtk_widget_set_state:
6599 * @widget: a #GtkWidget
6600 * @state: new state for @widget
6602 * This function is for use in widget implementations. Sets the state
6603 * of a widget (insensitive, prelighted, etc.) Usually you should set
6604 * the state using wrapper functions such as gtk_widget_set_sensitive().
6607 gtk_widget_set_state (GtkWidget *widget,
6610 GtkWidgetPrivate *priv;
6612 g_return_if_fail (GTK_IS_WIDGET (widget));
6614 priv = widget->priv;
6616 if (state == gtk_widget_get_state (widget))
6619 if (state == GTK_STATE_INSENSITIVE)
6620 gtk_widget_set_sensitive (widget, FALSE);
6626 data.state_restoration = FALSE;
6627 data.use_forall = FALSE;
6629 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6631 data.parent_sensitive = TRUE;
6633 gtk_widget_propagate_state (widget, &data);
6635 if (gtk_widget_is_drawable (widget))
6636 gtk_widget_queue_draw (widget);
6641 * gtk_widget_get_state:
6642 * @widget: a #GtkWidget
6644 * Returns the widget's state. See gtk_widget_set_state().
6646 * Returns: the state of @widget.
6651 gtk_widget_get_state (GtkWidget *widget)
6653 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6655 return widget->priv->state;
6659 * gtk_widget_set_visible:
6660 * @widget: a #GtkWidget
6661 * @visible: whether the widget should be shown or not
6663 * Sets the visibility state of @widget. Note that setting this to
6664 * %TRUE doesn't mean the widget is actually viewable, see
6665 * gtk_widget_get_visible().
6667 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6668 * but is nicer to use when the visibility of the widget depends on
6674 gtk_widget_set_visible (GtkWidget *widget,
6677 g_return_if_fail (GTK_IS_WIDGET (widget));
6679 if (visible != gtk_widget_get_visible (widget))
6682 gtk_widget_show (widget);
6684 gtk_widget_hide (widget);
6689 _gtk_widget_set_visible_flag (GtkWidget *widget,
6692 widget->priv->visible = visible;
6696 * gtk_widget_get_visible:
6697 * @widget: a #GtkWidget
6699 * Determines whether the widget is visible. Note that this doesn't
6700 * take into account whether the widget's parent is also visible
6701 * or the widget is obscured in any way.
6703 * See gtk_widget_set_visible().
6705 * Return value: %TRUE if the widget is visible
6710 gtk_widget_get_visible (GtkWidget *widget)
6712 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6714 return widget->priv->visible;
6718 * gtk_widget_set_has_window:
6719 * @widget: a #GtkWidget
6720 * @has_window: whether or not @widget has a window.
6722 * Specifies whether @widget has a #GdkWindow of its own. Note that
6723 * all realized widgets have a non-%NULL "window" pointer
6724 * (gtk_widget_get_window() never returns a %NULL window when a widget
6725 * is realized), but for many of them it's actually the #GdkWindow of
6726 * one of its parent widgets. Widgets that do not create a %window for
6727 * themselves in GtkWidget::realize() must announce this by
6728 * calling this function with @has_window = %FALSE.
6730 * This function should only be called by widget implementations,
6731 * and they should call it in their init() function.
6736 gtk_widget_set_has_window (GtkWidget *widget,
6737 gboolean has_window)
6739 g_return_if_fail (GTK_IS_WIDGET (widget));
6741 widget->priv->no_window = !has_window;
6745 * gtk_widget_get_has_window:
6746 * @widget: a #GtkWidget
6748 * Determines whether @widget has a #GdkWindow of its own. See
6749 * gtk_widget_set_has_window().
6751 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6756 gtk_widget_get_has_window (GtkWidget *widget)
6758 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6760 return ! widget->priv->no_window;
6764 * gtk_widget_is_toplevel:
6765 * @widget: a #GtkWidget
6767 * Determines whether @widget is a toplevel widget. Currently only
6768 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6769 * widgets have no parent widget.
6771 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6776 gtk_widget_is_toplevel (GtkWidget *widget)
6778 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6780 return widget->priv->toplevel;
6784 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6785 gboolean is_toplevel)
6787 widget->priv->toplevel = is_toplevel;
6791 * gtk_widget_is_drawable:
6792 * @widget: a #GtkWidget
6794 * Determines whether @widget can be drawn to. A widget can be drawn
6795 * to if it is mapped and visible.
6797 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6802 gtk_widget_is_drawable (GtkWidget *widget)
6804 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6806 return (gtk_widget_get_visible (widget) &&
6807 gtk_widget_get_mapped (widget));
6811 * gtk_widget_get_realized:
6812 * @widget: a #GtkWidget
6814 * Determines whether @widget is realized.
6816 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6821 gtk_widget_get_realized (GtkWidget *widget)
6823 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6825 return widget->priv->realized;
6829 * gtk_widget_set_realized:
6830 * @widget: a #GtkWidget
6831 * @realized: %TRUE to mark the widget as realized
6833 * Marks the widget as being realized.
6835 * This function should only ever be called in a derived widget's
6836 * "realize" or "unrealize" implementation.
6841 gtk_widget_set_realized (GtkWidget *widget,
6844 g_return_if_fail (GTK_IS_WIDGET (widget));
6846 widget->priv->realized = realized;
6850 * gtk_widget_get_mapped:
6851 * @widget: a #GtkWidget
6853 * Whether the widget is mapped.
6855 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6860 gtk_widget_get_mapped (GtkWidget *widget)
6862 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6864 return widget->priv->mapped;
6868 * gtk_widget_set_mapped:
6869 * @widget: a #GtkWidget
6870 * @mapped: %TRUE to mark the widget as mapped
6872 * Marks the widget as being realized.
6874 * This function should only ever be called in a derived widget's
6875 * "map" or "unmap" implementation.
6880 gtk_widget_set_mapped (GtkWidget *widget,
6883 g_return_if_fail (GTK_IS_WIDGET (widget));
6885 widget->priv->mapped = mapped;
6889 * gtk_widget_set_app_paintable:
6890 * @widget: a #GtkWidget
6891 * @app_paintable: %TRUE if the application will paint on the widget
6893 * Sets whether the application intends to draw on the widget in
6894 * an #GtkWidget::draw handler.
6896 * This is a hint to the widget and does not affect the behavior of
6897 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6898 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6899 * the effect is to suppress default themed drawing of the widget's
6900 * background. (Children of the widget will still be drawn.) The application
6901 * is then entirely responsible for drawing the widget background.
6903 * Note that the background is still drawn when the widget is mapped.
6906 gtk_widget_set_app_paintable (GtkWidget *widget,
6907 gboolean app_paintable)
6909 g_return_if_fail (GTK_IS_WIDGET (widget));
6911 app_paintable = (app_paintable != FALSE);
6913 if (widget->priv->app_paintable != app_paintable)
6915 widget->priv->app_paintable = app_paintable;
6917 if (gtk_widget_is_drawable (widget))
6918 gtk_widget_queue_draw (widget);
6920 g_object_notify (G_OBJECT (widget), "app-paintable");
6925 * gtk_widget_get_app_paintable:
6926 * @widget: a #GtkWidget
6928 * Determines whether the application intends to draw on the widget in
6929 * an #GtkWidget::draw handler.
6931 * See gtk_widget_set_app_paintable()
6933 * Return value: %TRUE if the widget is app paintable
6938 gtk_widget_get_app_paintable (GtkWidget *widget)
6940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6942 return widget->priv->app_paintable;
6946 * gtk_widget_set_double_buffered:
6947 * @widget: a #GtkWidget
6948 * @double_buffered: %TRUE to double-buffer a widget
6950 * Widgets are double buffered by default; you can use this function
6951 * to turn off the buffering. "Double buffered" simply means that
6952 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6953 * automatically around expose events sent to the
6954 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6955 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6956 * buffer to the screen. The result is that users see the window
6957 * update in one smooth step, and don't see individual graphics
6958 * primitives being rendered.
6960 * In very simple terms, double buffered widgets don't flicker,
6961 * so you would only use this function to turn off double buffering
6962 * if you had special needs and really knew what you were doing.
6964 * Note: if you turn off double-buffering, you have to handle
6965 * expose events, since even the clearing to the background color or
6966 * pixmap will not happen automatically (as it is done in
6967 * gdk_window_begin_paint()).
6970 gtk_widget_set_double_buffered (GtkWidget *widget,
6971 gboolean double_buffered)
6973 g_return_if_fail (GTK_IS_WIDGET (widget));
6975 double_buffered = (double_buffered != FALSE);
6977 if (widget->priv->double_buffered != double_buffered)
6979 widget->priv->double_buffered = double_buffered;
6981 g_object_notify (G_OBJECT (widget), "double-buffered");
6986 * gtk_widget_get_double_buffered:
6987 * @widget: a #GtkWidget
6989 * Determines whether the widget is double buffered.
6991 * See gtk_widget_set_double_buffered()
6993 * Return value: %TRUE if the widget is double buffered
6998 gtk_widget_get_double_buffered (GtkWidget *widget)
7000 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7002 return widget->priv->double_buffered;
7006 * gtk_widget_set_redraw_on_allocate:
7007 * @widget: a #GtkWidget
7008 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7009 * when it is allocated to a new size. Otherwise, only the
7010 * new portion of the widget will be redrawn.
7012 * Sets whether the entire widget is queued for drawing when its size
7013 * allocation changes. By default, this setting is %TRUE and
7014 * the entire widget is redrawn on every size change. If your widget
7015 * leaves the upper left unchanged when made bigger, turning this
7016 * setting off will improve performance.
7018 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7019 * off all allocation on resizing: the widget will not even redraw if
7020 * its position changes; this is to allow containers that don't draw
7021 * anything to avoid excess invalidations. If you set this flag on a
7022 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7023 * you are responsible for invalidating both the old and new allocation
7024 * of the widget when the widget is moved and responsible for invalidating
7025 * regions newly when the widget increases size.
7028 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7029 gboolean redraw_on_allocate)
7031 g_return_if_fail (GTK_IS_WIDGET (widget));
7033 widget->priv->redraw_on_alloc = redraw_on_allocate;
7037 * gtk_widget_set_sensitive:
7038 * @widget: a #GtkWidget
7039 * @sensitive: %TRUE to make the widget sensitive
7041 * Sets the sensitivity of a widget. A widget is sensitive if the user
7042 * can interact with it. Insensitive widgets are "grayed out" and the
7043 * user can't interact with them. Insensitive widgets are known as
7044 * "inactive", "disabled", or "ghosted" in some other toolkits.
7047 gtk_widget_set_sensitive (GtkWidget *widget,
7050 GtkWidgetPrivate *priv;
7053 g_return_if_fail (GTK_IS_WIDGET (widget));
7055 priv = widget->priv;
7057 sensitive = (sensitive != FALSE);
7059 if (widget->priv->sensitive == sensitive)
7064 widget->priv->sensitive = TRUE;
7065 data.state = priv->saved_state;
7069 widget->priv->sensitive = FALSE;
7070 data.state = gtk_widget_get_state (widget);
7072 data.state_restoration = TRUE;
7073 data.use_forall = TRUE;
7076 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7078 data.parent_sensitive = TRUE;
7080 gtk_widget_propagate_state (widget, &data);
7081 if (gtk_widget_is_drawable (widget))
7082 gtk_widget_queue_draw (widget);
7084 g_object_notify (G_OBJECT (widget), "sensitive");
7088 * gtk_widget_get_sensitive:
7089 * @widget: a #GtkWidget
7091 * Returns the widget's sensitivity (in the sense of returning
7092 * the value that has been set using gtk_widget_set_sensitive()).
7094 * The effective sensitivity of a widget is however determined by both its
7095 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7097 * Returns: %TRUE if the widget is sensitive
7102 gtk_widget_get_sensitive (GtkWidget *widget)
7104 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7106 return widget->priv->sensitive;
7110 * gtk_widget_is_sensitive:
7111 * @widget: a #GtkWidget
7113 * Returns the widget's effective sensitivity, which means
7114 * it is sensitive itself and also its parent widget is sensntive
7116 * Returns: %TRUE if the widget is effectively sensitive
7121 gtk_widget_is_sensitive (GtkWidget *widget)
7123 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7125 return widget->priv->sensitive && widget->priv->parent_sensitive;
7129 * gtk_widget_set_parent:
7130 * @widget: a #GtkWidget
7131 * @parent: parent container
7133 * This function is useful only when implementing subclasses of
7135 * Sets the container as the parent of @widget, and takes care of
7136 * some details such as updating the state and style of the child
7137 * to reflect its new location. The opposite function is
7138 * gtk_widget_unparent().
7141 gtk_widget_set_parent (GtkWidget *widget,
7144 GtkWidgetPrivate *priv;
7147 g_return_if_fail (GTK_IS_WIDGET (widget));
7148 g_return_if_fail (GTK_IS_WIDGET (parent));
7149 g_return_if_fail (widget != parent);
7151 priv = widget->priv;
7153 if (priv->parent != NULL)
7155 g_warning ("Can't set a parent on widget which has a parent\n");
7158 if (gtk_widget_is_toplevel (widget))
7160 g_warning ("Can't set a parent on a toplevel widget\n");
7164 /* keep this function in sync with gtk_menu_attach_to_widget()
7167 g_object_ref_sink (widget);
7168 priv->parent = parent;
7170 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7171 data.state = gtk_widget_get_state (parent);
7173 data.state = gtk_widget_get_state (widget);
7174 data.state_restoration = FALSE;
7175 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7176 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7178 gtk_widget_propagate_state (widget, &data);
7180 gtk_widget_reset_rc_styles (widget);
7182 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7183 if (priv->parent->priv->anchored)
7184 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7185 g_object_notify (G_OBJECT (widget), "parent");
7187 /* Enforce realized/mapped invariants
7189 if (gtk_widget_get_realized (priv->parent))
7190 gtk_widget_realize (widget);
7192 if (gtk_widget_get_visible (priv->parent) &&
7193 gtk_widget_get_visible (widget))
7195 if (gtk_widget_get_child_visible (widget) &&
7196 gtk_widget_get_mapped (priv->parent))
7197 gtk_widget_map (widget);
7199 gtk_widget_queue_resize (widget);
7204 * gtk_widget_get_parent:
7205 * @widget: a #GtkWidget
7207 * Returns the parent container of @widget.
7209 * Return value: (transfer none): the parent container of @widget, or %NULL
7212 gtk_widget_get_parent (GtkWidget *widget)
7214 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7216 return widget->priv->parent;
7219 /*****************************************
7221 * see docs/styles.txt
7222 *****************************************/
7225 * gtk_widget_style_attach:
7226 * @widget: a #GtkWidget
7228 * This function attaches the widget's #GtkStyle to the widget's
7229 * #GdkWindow. It is a replacement for
7232 * widget->style = gtk_style_attach (widget->style, widget->window);
7235 * and should only ever be called in a derived widget's "realize"
7236 * implementation which does not chain up to its parent class'
7237 * "realize" implementation, because one of the parent classes
7238 * (finally #GtkWidget) would attach the style itself.
7243 gtk_widget_style_attach (GtkWidget *widget)
7245 GtkWidgetPrivate *priv;
7247 g_return_if_fail (GTK_IS_WIDGET (widget));
7248 g_return_if_fail (gtk_widget_get_realized (widget));
7250 priv = widget->priv;
7252 priv->style = gtk_style_attach (priv->style, priv->window);
7256 * gtk_widget_has_rc_style:
7257 * @widget: a #GtkWidget
7259 * Determines if the widget style has been looked up through the rc mechanism.
7261 * Returns: %TRUE if the widget has been looked up through the rc
7262 * mechanism, %FALSE otherwise.
7267 gtk_widget_has_rc_style (GtkWidget *widget)
7269 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7271 return widget->priv->rc_style;
7275 * gtk_widget_set_style:
7276 * @widget: a #GtkWidget
7277 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7278 * gtk_widget_set_style() and go back to the default style
7280 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7281 * want to use this function; it interacts badly with themes, because
7282 * themes work by replacing the #GtkStyle. Instead, use
7283 * gtk_widget_modify_style().
7286 gtk_widget_set_style (GtkWidget *widget,
7289 g_return_if_fail (GTK_IS_WIDGET (widget));
7293 gboolean initial_emission;
7295 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7297 widget->priv->rc_style = FALSE;
7298 widget->priv->user_style = TRUE;
7300 gtk_widget_set_style_internal (widget, style, initial_emission);
7304 if (widget->priv->user_style)
7305 gtk_widget_reset_rc_style (widget);
7310 * gtk_widget_ensure_style:
7311 * @widget: a #GtkWidget
7313 * Ensures that @widget has a style (@widget->style). Not a very useful
7314 * function; most of the time, if you want the style, the widget is
7315 * realized, and realized widgets are guaranteed to have a style
7319 gtk_widget_ensure_style (GtkWidget *widget)
7321 g_return_if_fail (GTK_IS_WIDGET (widget));
7323 if (!widget->priv->rc_style && !widget->priv->user_style)
7324 gtk_widget_reset_rc_style (widget);
7327 /* Look up the RC style for this widget, unsetting any user style that
7328 * may be in effect currently
7331 gtk_widget_reset_rc_style (GtkWidget *widget)
7333 GtkWidgetPrivate *priv = widget->priv;
7334 GtkStyle *new_style = NULL;
7335 gboolean initial_emission;
7337 initial_emission = !priv->rc_style && !priv->user_style;
7339 priv->user_style = FALSE;
7340 priv->rc_style = TRUE;
7342 if (gtk_widget_has_screen (widget))
7343 new_style = gtk_rc_get_style (widget);
7345 new_style = gtk_widget_get_default_style ();
7347 if (initial_emission || new_style != priv->style)
7348 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7352 * gtk_widget_get_style:
7353 * @widget: a #GtkWidget
7355 * Simply an accessor function that returns @widget->style.
7357 * Return value: (transfer none): the widget's #GtkStyle
7360 gtk_widget_get_style (GtkWidget *widget)
7362 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7364 return widget->priv->style;
7368 * gtk_widget_modify_style:
7369 * @widget: a #GtkWidget
7370 * @style: the #GtkRcStyle holding the style modifications
7372 * Modifies style values on the widget. Modifications made using this
7373 * technique take precedence over style values set via an RC file,
7374 * however, they will be overriden if a style is explicitely set on
7375 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7376 * is designed so each field can either be set or unset, so it is
7377 * possible, using this function, to modify some style values and
7378 * leave the others unchanged.
7380 * Note that modifications made with this function are not cumulative
7381 * with previous calls to gtk_widget_modify_style() or with such
7382 * functions as gtk_widget_modify_fg(). If you wish to retain
7383 * previous values, you must first call gtk_widget_get_modifier_style(),
7384 * make your modifications to the returned style, then call
7385 * gtk_widget_modify_style() with that style. On the other hand,
7386 * if you first call gtk_widget_modify_style(), subsequent calls
7387 * to such functions gtk_widget_modify_fg() will have a cumulative
7388 * effect with the initial modifications.
7391 gtk_widget_modify_style (GtkWidget *widget,
7394 g_return_if_fail (GTK_IS_WIDGET (widget));
7395 g_return_if_fail (GTK_IS_RC_STYLE (style));
7397 g_object_set_qdata_full (G_OBJECT (widget),
7399 gtk_rc_style_copy (style),
7400 (GDestroyNotify) g_object_unref);
7402 /* note that "style" may be invalid here if it was the old
7403 * modifier style and the only reference was our own.
7406 if (widget->priv->rc_style)
7407 gtk_widget_reset_rc_style (widget);
7411 * gtk_widget_get_modifier_style:
7412 * @widget: a #GtkWidget
7414 * Returns the current modifier style for the widget. (As set by
7415 * gtk_widget_modify_style().) If no style has previously set, a new
7416 * #GtkRcStyle will be created with all values unset, and set as the
7417 * modifier style for the widget. If you make changes to this rc
7418 * style, you must call gtk_widget_modify_style(), passing in the
7419 * returned rc style, to make sure that your changes take effect.
7421 * Caution: passing the style back to gtk_widget_modify_style() will
7422 * normally end up destroying it, because gtk_widget_modify_style() copies
7423 * the passed-in style and sets the copy as the new modifier style,
7424 * thus dropping any reference to the old modifier style. Add a reference
7425 * to the modifier style if you want to keep it alive.
7427 * Return value: (transfer none): the modifier style for the widget. This rc style is
7428 * owned by the widget. If you want to keep a pointer to value this
7429 * around, you must add a refcount using g_object_ref().
7432 gtk_widget_get_modifier_style (GtkWidget *widget)
7434 GtkRcStyle *rc_style;
7436 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7438 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7442 rc_style = gtk_rc_style_new ();
7443 g_object_set_qdata_full (G_OBJECT (widget),
7446 (GDestroyNotify) g_object_unref);
7453 gtk_widget_modify_color_component (GtkWidget *widget,
7454 GtkRcFlags component,
7456 const GdkColor *color)
7458 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7465 rc_style->fg[state] = *color;
7468 rc_style->bg[state] = *color;
7471 rc_style->text[state] = *color;
7474 rc_style->base[state] = *color;
7477 g_assert_not_reached();
7480 rc_style->color_flags[state] |= component;
7483 rc_style->color_flags[state] &= ~component;
7485 gtk_widget_modify_style (widget, rc_style);
7489 * gtk_widget_modify_symbolic_color:
7490 * @widget: a #GtkWidget
7491 * @name: the name of the symbolic color to modify
7492 * @color: (allow-none): the color to assign (does not need to be allocated),
7493 * or %NULL to undo the effect of previous calls to
7494 * of gtk_widget_modify_symbolic_color().
7496 * Sets a symbolic color for a widget.
7497 * All other style values are left untouched. See also
7498 * gtk_widget_modify_style().
7503 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7505 const GdkColor *color)
7507 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7509 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7511 gtk_widget_modify_style (widget, rc_style);
7515 * gtk_widget_modify_fg:
7516 * @widget: a #GtkWidget
7517 * @state: the state for which to set the foreground color
7518 * @color: (allow-none): the color to assign (does not need to be allocated),
7519 * or %NULL to undo the effect of previous calls to
7520 * of gtk_widget_modify_fg().
7522 * Sets the foreground color for a widget in a particular state.
7523 * All other style values are left untouched. See also
7524 * gtk_widget_modify_style().
7527 gtk_widget_modify_fg (GtkWidget *widget,
7529 const GdkColor *color)
7531 g_return_if_fail (GTK_IS_WIDGET (widget));
7532 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7534 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7538 * gtk_widget_modify_bg:
7539 * @widget: a #GtkWidget
7540 * @state: the state for which to set the background color
7541 * @color: (allow-none): the color to assign (does not need to be allocated),
7542 * or %NULL to undo the effect of previous calls to
7543 * of gtk_widget_modify_bg().
7545 * Sets the background color for a widget in a particular state.
7546 * All other style values are left untouched. See also
7547 * gtk_widget_modify_style().
7549 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7550 * draw on their parent container's window and thus may not draw any
7551 * background themselves. This is the case for e.g. #GtkLabel. To modify
7552 * the background of such widgets, you have to set the background color
7553 * on their parent; if you want to set the background of a rectangular
7554 * area around a label, try placing the label in a #GtkEventBox widget
7555 * and setting the background color on that.
7558 gtk_widget_modify_bg (GtkWidget *widget,
7560 const GdkColor *color)
7562 g_return_if_fail (GTK_IS_WIDGET (widget));
7563 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7565 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7569 * gtk_widget_modify_text:
7570 * @widget: a #GtkWidget
7571 * @state: the state for which to set the text color
7572 * @color: (allow-none): the color to assign (does not need to be allocated),
7573 * or %NULL to undo the effect of previous calls to
7574 * of gtk_widget_modify_text().
7576 * Sets the text color for a widget in a particular state. All other
7577 * style values are left untouched. The text color is the foreground
7578 * color used along with the base color (see gtk_widget_modify_base())
7579 * for widgets such as #GtkEntry and #GtkTextView. See also
7580 * gtk_widget_modify_style().
7583 gtk_widget_modify_text (GtkWidget *widget,
7585 const GdkColor *color)
7587 g_return_if_fail (GTK_IS_WIDGET (widget));
7588 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7590 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7594 * gtk_widget_modify_base:
7595 * @widget: a #GtkWidget
7596 * @state: the state for which to set the base color
7597 * @color: (allow-none): the color to assign (does not need to be allocated),
7598 * or %NULL to undo the effect of previous calls to
7599 * of gtk_widget_modify_base().
7601 * Sets the base color for a widget in a particular state.
7602 * All other style values are left untouched. The base color
7603 * is the background color used along with the text color
7604 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7605 * and #GtkTextView. See also gtk_widget_modify_style().
7607 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7608 * draw on their parent container's window and thus may not draw any
7609 * background themselves. This is the case for e.g. #GtkLabel. To modify
7610 * the background of such widgets, you have to set the base color on their
7611 * parent; if you want to set the background of a rectangular area around
7612 * a label, try placing the label in a #GtkEventBox widget and setting
7613 * the base color on that.
7616 gtk_widget_modify_base (GtkWidget *widget,
7618 const GdkColor *color)
7620 g_return_if_fail (GTK_IS_WIDGET (widget));
7621 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7623 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7627 modify_color_property (GtkWidget *widget,
7628 GtkRcStyle *rc_style,
7630 const GdkColor *color)
7632 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7633 GQuark property_name = g_quark_from_string (name);
7637 GtkRcProperty rc_property = {0};
7640 rc_property.type_name = type_name;
7641 rc_property.property_name = property_name;
7642 rc_property.origin = NULL;
7644 color_name = gdk_color_to_string (color);
7645 g_value_init (&rc_property.value, G_TYPE_STRING);
7646 g_value_take_string (&rc_property.value, color_name);
7648 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7650 g_value_unset (&rc_property.value);
7653 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7657 * gtk_widget_modify_cursor:
7658 * @widget: a #GtkWidget
7659 * @primary: the color to use for primary cursor (does not need to be
7660 * allocated), or %NULL to undo the effect of previous calls to
7661 * of gtk_widget_modify_cursor().
7662 * @secondary: the color to use for secondary cursor (does not need to be
7663 * allocated), or %NULL to undo the effect of previous calls to
7664 * of gtk_widget_modify_cursor().
7666 * Sets the cursor color to use in a widget, overriding the
7667 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7668 * style properties. All other style values are left untouched.
7669 * See also gtk_widget_modify_style().
7674 gtk_widget_modify_cursor (GtkWidget *widget,
7675 const GdkColor *primary,
7676 const GdkColor *secondary)
7678 GtkRcStyle *rc_style;
7680 g_return_if_fail (GTK_IS_WIDGET (widget));
7682 rc_style = gtk_widget_get_modifier_style (widget);
7684 modify_color_property (widget, rc_style, "cursor-color", primary);
7685 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7687 gtk_widget_modify_style (widget, rc_style);
7691 * gtk_widget_modify_font:
7692 * @widget: a #GtkWidget
7693 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7694 * the effect of previous calls to gtk_widget_modify_font().
7696 * Sets the font to use for a widget. All other style values are left
7697 * untouched. See also gtk_widget_modify_style().
7700 gtk_widget_modify_font (GtkWidget *widget,
7701 PangoFontDescription *font_desc)
7703 GtkRcStyle *rc_style;
7705 g_return_if_fail (GTK_IS_WIDGET (widget));
7707 rc_style = gtk_widget_get_modifier_style (widget);
7709 if (rc_style->font_desc)
7710 pango_font_description_free (rc_style->font_desc);
7713 rc_style->font_desc = pango_font_description_copy (font_desc);
7715 rc_style->font_desc = NULL;
7717 gtk_widget_modify_style (widget, rc_style);
7721 gtk_widget_real_direction_changed (GtkWidget *widget,
7722 GtkTextDirection previous_direction)
7724 gtk_widget_queue_resize (widget);
7728 gtk_widget_real_style_set (GtkWidget *widget,
7729 GtkStyle *previous_style)
7731 GtkWidgetPrivate *priv = widget->priv;
7733 if (gtk_widget_get_realized (widget) &&
7734 gtk_widget_get_has_window (widget))
7735 gtk_style_set_background (priv->style, priv->window, priv->state);
7739 gtk_widget_set_style_internal (GtkWidget *widget,
7741 gboolean initial_emission)
7743 GtkWidgetPrivate *priv = widget->priv;
7745 g_object_ref (widget);
7746 g_object_freeze_notify (G_OBJECT (widget));
7748 if (priv->style != style)
7750 GtkStyle *previous_style;
7752 if (gtk_widget_get_realized (widget))
7754 gtk_widget_reset_shapes (widget);
7755 gtk_style_detach (priv->style);
7758 previous_style = priv->style;
7759 priv->style = style;
7760 g_object_ref (priv->style);
7762 if (gtk_widget_get_realized (widget))
7763 priv->style = gtk_style_attach (priv->style, priv->window);
7765 gtk_widget_update_pango_context (widget);
7766 g_signal_emit (widget,
7767 widget_signals[STYLE_SET],
7769 initial_emission ? NULL : previous_style);
7770 g_object_unref (previous_style);
7772 if (priv->anchored && !initial_emission)
7773 gtk_widget_queue_resize (widget);
7775 else if (initial_emission)
7777 gtk_widget_update_pango_context (widget);
7778 g_signal_emit (widget,
7779 widget_signals[STYLE_SET],
7783 g_object_notify (G_OBJECT (widget), "style");
7784 g_object_thaw_notify (G_OBJECT (widget));
7785 g_object_unref (widget);
7789 GtkWidget *previous_toplevel;
7790 GdkScreen *previous_screen;
7791 GdkScreen *new_screen;
7792 } HierarchyChangedInfo;
7795 do_screen_change (GtkWidget *widget,
7796 GdkScreen *old_screen,
7797 GdkScreen *new_screen)
7799 if (old_screen != new_screen)
7803 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7805 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7808 _gtk_tooltip_hide (widget);
7809 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7814 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7815 gpointer client_data)
7817 GtkWidgetPrivate *priv = widget->priv;
7818 HierarchyChangedInfo *info = client_data;
7819 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7820 (priv->parent && priv->parent->priv->anchored);
7822 if (priv->anchored != new_anchored)
7824 g_object_ref (widget);
7826 priv->anchored = new_anchored;
7828 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7829 do_screen_change (widget, info->previous_screen, info->new_screen);
7831 if (GTK_IS_CONTAINER (widget))
7832 gtk_container_forall (GTK_CONTAINER (widget),
7833 gtk_widget_propagate_hierarchy_changed_recurse,
7836 g_object_unref (widget);
7841 * _gtk_widget_propagate_hierarchy_changed:
7842 * @widget: a #GtkWidget
7843 * @previous_toplevel: Previous toplevel
7845 * Propagates changes in the anchored state to a widget and all
7846 * children, unsetting or setting the %ANCHORED flag, and
7847 * emitting #GtkWidget::hierarchy-changed.
7850 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7851 GtkWidget *previous_toplevel)
7853 GtkWidgetPrivate *priv = widget->priv;
7854 HierarchyChangedInfo info;
7856 info.previous_toplevel = previous_toplevel;
7857 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7859 if (gtk_widget_is_toplevel (widget) ||
7860 (priv->parent && priv->parent->priv->anchored))
7861 info.new_screen = gtk_widget_get_screen (widget);
7863 info.new_screen = NULL;
7865 if (info.previous_screen)
7866 g_object_ref (info.previous_screen);
7867 if (previous_toplevel)
7868 g_object_ref (previous_toplevel);
7870 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7872 if (previous_toplevel)
7873 g_object_unref (previous_toplevel);
7874 if (info.previous_screen)
7875 g_object_unref (info.previous_screen);
7879 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7880 gpointer client_data)
7882 HierarchyChangedInfo *info = client_data;
7884 g_object_ref (widget);
7886 do_screen_change (widget, info->previous_screen, info->new_screen);
7888 if (GTK_IS_CONTAINER (widget))
7889 gtk_container_forall (GTK_CONTAINER (widget),
7890 gtk_widget_propagate_screen_changed_recurse,
7893 g_object_unref (widget);
7897 * gtk_widget_is_composited:
7898 * @widget: a #GtkWidget
7900 * Whether @widget can rely on having its alpha channel
7901 * drawn correctly. On X11 this function returns whether a
7902 * compositing manager is running for @widget's screen.
7904 * Please note that the semantics of this call will change
7905 * in the future if used on a widget that has a composited
7906 * window in its hierarchy (as set by gdk_window_set_composited()).
7908 * Return value: %TRUE if the widget can rely on its alpha
7909 * channel being drawn correctly.
7914 gtk_widget_is_composited (GtkWidget *widget)
7918 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7920 screen = gtk_widget_get_screen (widget);
7922 return gdk_screen_is_composited (screen);
7926 propagate_composited_changed (GtkWidget *widget,
7929 if (GTK_IS_CONTAINER (widget))
7931 gtk_container_forall (GTK_CONTAINER (widget),
7932 propagate_composited_changed,
7936 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7940 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7942 propagate_composited_changed (widget, NULL);
7946 * _gtk_widget_propagate_screen_changed:
7947 * @widget: a #GtkWidget
7948 * @previous_screen: Previous screen
7950 * Propagates changes in the screen for a widget to all
7951 * children, emitting #GtkWidget::screen-changed.
7954 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7955 GdkScreen *previous_screen)
7957 HierarchyChangedInfo info;
7959 info.previous_screen = previous_screen;
7960 info.new_screen = gtk_widget_get_screen (widget);
7962 if (previous_screen)
7963 g_object_ref (previous_screen);
7965 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7967 if (previous_screen)
7968 g_object_unref (previous_screen);
7972 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7974 if (widget->priv->rc_style)
7975 gtk_widget_reset_rc_style (widget);
7977 if (GTK_IS_CONTAINER (widget))
7978 gtk_container_forall (GTK_CONTAINER (widget),
7979 reset_rc_styles_recurse,
7985 * gtk_widget_reset_rc_styles:
7986 * @widget: a #GtkWidget.
7988 * Reset the styles of @widget and all descendents, so when
7989 * they are looked up again, they get the correct values
7990 * for the currently loaded RC file settings.
7992 * This function is not useful for applications.
7995 gtk_widget_reset_rc_styles (GtkWidget *widget)
7997 g_return_if_fail (GTK_IS_WIDGET (widget));
7999 reset_rc_styles_recurse (widget, NULL);
8003 * gtk_widget_get_default_style:
8005 * Returns the default style used by all widgets initially.
8007 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8008 * by GTK+ and should not be modified or freed.
8011 gtk_widget_get_default_style (void)
8013 if (!gtk_default_style)
8015 gtk_default_style = gtk_style_new ();
8016 g_object_ref (gtk_default_style);
8019 return gtk_default_style;
8022 static PangoContext *
8023 gtk_widget_peek_pango_context (GtkWidget *widget)
8025 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8029 * gtk_widget_get_pango_context:
8030 * @widget: a #GtkWidget
8032 * Gets a #PangoContext with the appropriate font map, font description,
8033 * and base direction for this widget. Unlike the context returned
8034 * by gtk_widget_create_pango_context(), this context is owned by
8035 * the widget (it can be used until the screen for the widget changes
8036 * or the widget is removed from its toplevel), and will be updated to
8037 * match any changes to the widget's attributes.
8039 * If you create and keep a #PangoLayout using this context, you must
8040 * deal with changes to the context by calling pango_layout_context_changed()
8041 * on the layout in response to the #GtkWidget::style-set and
8042 * #GtkWidget::direction-changed signals for the widget.
8044 * Return value: (transfer none): the #PangoContext for the widget.
8047 gtk_widget_get_pango_context (GtkWidget *widget)
8049 PangoContext *context;
8051 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8053 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8056 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8057 g_object_set_qdata_full (G_OBJECT (widget),
8058 quark_pango_context,
8067 update_pango_context (GtkWidget *widget,
8068 PangoContext *context)
8070 GtkWidgetPrivate *priv = widget->priv;
8072 pango_context_set_font_description (context, priv->style->font_desc);
8073 pango_context_set_base_dir (context,
8074 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8075 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8079 gtk_widget_update_pango_context (GtkWidget *widget)
8081 PangoContext *context = gtk_widget_peek_pango_context (widget);
8087 update_pango_context (widget, context);
8089 screen = gtk_widget_get_screen_unchecked (widget);
8092 pango_cairo_context_set_resolution (context,
8093 gdk_screen_get_resolution (screen));
8094 pango_cairo_context_set_font_options (context,
8095 gdk_screen_get_font_options (screen));
8101 * gtk_widget_create_pango_context:
8102 * @widget: a #GtkWidget
8104 * Creates a new #PangoContext with the appropriate font map,
8105 * font description, and base direction for drawing text for
8106 * this widget. See also gtk_widget_get_pango_context().
8108 * Return value: (transfer full): the new #PangoContext
8111 gtk_widget_create_pango_context (GtkWidget *widget)
8114 PangoContext *context;
8116 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8118 screen = gtk_widget_get_screen_unchecked (widget);
8121 GTK_NOTE (MULTIHEAD,
8122 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8124 screen = gdk_screen_get_default ();
8127 context = gdk_pango_context_get_for_screen (screen);
8129 update_pango_context (widget, context);
8130 pango_context_set_language (context, gtk_get_default_language ());
8136 * gtk_widget_create_pango_layout:
8137 * @widget: a #GtkWidget
8138 * @text: text to set on the layout (can be %NULL)
8140 * Creates a new #PangoLayout with the appropriate font map,
8141 * font description, and base direction for drawing text for
8144 * If you keep a #PangoLayout created in this way around, in order to
8145 * notify the layout of changes to the base direction or font of this
8146 * widget, you must call pango_layout_context_changed() in response to
8147 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8150 * Return value: (transfer full): the new #PangoLayout
8153 gtk_widget_create_pango_layout (GtkWidget *widget,
8156 PangoLayout *layout;
8157 PangoContext *context;
8159 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8161 context = gtk_widget_get_pango_context (widget);
8162 layout = pango_layout_new (context);
8165 pango_layout_set_text (layout, text, -1);
8171 * gtk_widget_render_icon:
8172 * @widget: a #GtkWidget
8173 * @stock_id: a stock ID
8174 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8175 * render at the size of the source and don't scale (if there are
8176 * multiple source sizes, GTK+ picks one of the available sizes).
8177 * @detail: (allow-none): render detail to pass to theme engine
8179 * A convenience function that uses the theme engine and RC file
8180 * settings for @widget to look up @stock_id and render it to
8181 * a pixbuf. @stock_id should be a stock icon ID such as
8182 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8183 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8184 * identifies the widget or code doing the rendering, so that
8185 * theme engines can special-case rendering for that widget or code.
8187 * The pixels in the returned #GdkPixbuf are shared with the rest of
8188 * the application and should not be modified. The pixbuf should be freed
8189 * after use with g_object_unref().
8191 * Return value: (transfer full): a new pixbuf, or %NULL if the
8192 * stock ID wasn't known
8195 gtk_widget_render_icon (GtkWidget *widget,
8196 const gchar *stock_id,
8198 const gchar *detail)
8200 GtkWidgetPrivate *priv;
8201 GtkIconSet *icon_set;
8204 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8205 g_return_val_if_fail (stock_id != NULL, NULL);
8206 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8208 priv = widget->priv;
8210 gtk_widget_ensure_style (widget);
8212 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8214 if (icon_set == NULL)
8217 retval = gtk_icon_set_render_icon (icon_set,
8219 gtk_widget_get_direction (widget),
8220 gtk_widget_get_state (widget),
8229 * gtk_widget_set_parent_window:
8230 * @widget: a #GtkWidget.
8231 * @parent_window: the new parent window.
8233 * Sets a non default parent window for @widget.
8236 gtk_widget_set_parent_window (GtkWidget *widget,
8237 GdkWindow *parent_window)
8239 GdkWindow *old_parent_window;
8241 g_return_if_fail (GTK_IS_WIDGET (widget));
8243 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8244 quark_parent_window);
8246 if (parent_window != old_parent_window)
8248 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8250 if (old_parent_window)
8251 g_object_unref (old_parent_window);
8253 g_object_ref (parent_window);
8258 * gtk_widget_get_parent_window:
8259 * @widget: a #GtkWidget.
8261 * Gets @widget's parent window.
8263 * Returns: (transfer none): the parent window of @widget.
8266 gtk_widget_get_parent_window (GtkWidget *widget)
8268 GtkWidgetPrivate *priv;
8269 GdkWindow *parent_window;
8271 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8273 priv = widget->priv;
8275 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8277 return (parent_window != NULL) ? parent_window :
8278 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8283 * gtk_widget_set_child_visible:
8284 * @widget: a #GtkWidget
8285 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8287 * Sets whether @widget should be mapped along with its when its parent
8288 * is mapped and @widget has been shown with gtk_widget_show().
8290 * The child visibility can be set for widget before it is added to
8291 * a container with gtk_widget_set_parent(), to avoid mapping
8292 * children unnecessary before immediately unmapping them. However
8293 * it will be reset to its default state of %TRUE when the widget
8294 * is removed from a container.
8296 * Note that changing the child visibility of a widget does not
8297 * queue a resize on the widget. Most of the time, the size of
8298 * a widget is computed from all visible children, whether or
8299 * not they are mapped. If this is not the case, the container
8300 * can queue a resize itself.
8302 * This function is only useful for container implementations and
8303 * never should be called by an application.
8306 gtk_widget_set_child_visible (GtkWidget *widget,
8307 gboolean is_visible)
8309 GtkWidgetPrivate *priv;
8311 g_return_if_fail (GTK_IS_WIDGET (widget));
8312 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8314 priv = widget->priv;
8316 g_object_ref (widget);
8319 priv->child_visible = TRUE;
8322 GtkWidget *toplevel;
8324 priv->child_visible = FALSE;
8326 toplevel = gtk_widget_get_toplevel (widget);
8327 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8328 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8331 if (priv->parent && gtk_widget_get_realized (priv->parent))
8333 if (gtk_widget_get_mapped (priv->parent) &&
8334 priv->child_visible &&
8335 gtk_widget_get_visible (widget))
8336 gtk_widget_map (widget);
8338 gtk_widget_unmap (widget);
8341 g_object_unref (widget);
8345 * gtk_widget_get_child_visible:
8346 * @widget: a #GtkWidget
8348 * Gets the value set with gtk_widget_set_child_visible().
8349 * If you feel a need to use this function, your code probably
8350 * needs reorganization.
8352 * This function is only useful for container implementations and
8353 * never should be called by an application.
8355 * Return value: %TRUE if the widget is mapped with the parent.
8358 gtk_widget_get_child_visible (GtkWidget *widget)
8360 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8362 return widget->priv->child_visible;
8366 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8368 GtkWidget *toplevel;
8370 toplevel = gtk_widget_get_toplevel (widget);
8372 if (gtk_widget_is_toplevel (toplevel))
8374 if (GTK_IS_WINDOW (toplevel))
8375 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8376 else if (GTK_IS_INVISIBLE (toplevel))
8377 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8384 * gtk_widget_get_screen:
8385 * @widget: a #GtkWidget
8387 * Get the #GdkScreen from the toplevel window associated with
8388 * this widget. This function can only be called after the widget
8389 * has been added to a widget hierarchy with a #GtkWindow
8392 * In general, you should only create screen specific
8393 * resources when a widget has been realized, and you should
8394 * free those resources when the widget is unrealized.
8396 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8401 gtk_widget_get_screen (GtkWidget *widget)
8405 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8407 screen = gtk_widget_get_screen_unchecked (widget);
8414 g_warning (G_STRLOC ": Can't get associated screen"
8415 " for a widget unless it is inside a toplevel GtkWindow\n"
8416 " widget type is %s associated top level type is %s",
8417 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8418 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8420 return gdk_screen_get_default ();
8425 * gtk_widget_has_screen:
8426 * @widget: a #GtkWidget
8428 * Checks whether there is a #GdkScreen is associated with
8429 * this widget. All toplevel widgets have an associated
8430 * screen, and all widgets added into a hierarchy with a toplevel
8431 * window at the top.
8433 * Return value: %TRUE if there is a #GdkScreen associcated
8439 gtk_widget_has_screen (GtkWidget *widget)
8441 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8443 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8447 * gtk_widget_get_display:
8448 * @widget: a #GtkWidget
8450 * Get the #GdkDisplay for the toplevel window associated with
8451 * this widget. This function can only be called after the widget
8452 * has been added to a widget hierarchy with a #GtkWindow at the top.
8454 * In general, you should only create display specific
8455 * resources when a widget has been realized, and you should
8456 * free those resources when the widget is unrealized.
8458 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8463 gtk_widget_get_display (GtkWidget *widget)
8465 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8467 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8471 * gtk_widget_get_root_window:
8472 * @widget: a #GtkWidget
8474 * Get the root window where this widget is located. This function can
8475 * only be called after the widget has been added to a widget
8476 * hierarchy with #GtkWindow at the top.
8478 * The root window is useful for such purposes as creating a popup
8479 * #GdkWindow associated with the window. In general, you should only
8480 * create display specific resources when a widget has been realized,
8481 * and you should free those resources when the widget is unrealized.
8483 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8488 gtk_widget_get_root_window (GtkWidget *widget)
8490 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8492 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8496 * gtk_widget_child_focus:
8497 * @widget: a #GtkWidget
8498 * @direction: direction of focus movement
8500 * This function is used by custom widget implementations; if you're
8501 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8502 * to a particular widget, and gtk_container_set_focus_chain() to
8503 * change the focus tab order. So you may want to investigate those
8504 * functions instead.
8506 * gtk_widget_child_focus() is called by containers as the user moves
8507 * around the window using keyboard shortcuts. @direction indicates
8508 * what kind of motion is taking place (up, down, left, right, tab
8509 * forward, tab backward). gtk_widget_child_focus() emits the
8510 * #GtkWidget::focus signal; widgets override the default handler
8511 * for this signal in order to implement appropriate focus behavior.
8513 * The default ::focus handler for a widget should return %TRUE if
8514 * moving in @direction left the focus on a focusable location inside
8515 * that widget, and %FALSE if moving in @direction moved the focus
8516 * outside the widget. If returning %TRUE, widgets normally
8517 * call gtk_widget_grab_focus() to place the focus accordingly;
8518 * if returning %FALSE, they don't modify the current focus location.
8520 * Return value: %TRUE if focus ended up inside @widget
8523 gtk_widget_child_focus (GtkWidget *widget,
8524 GtkDirectionType direction)
8526 gboolean return_val;
8528 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8530 if (!gtk_widget_get_visible (widget) ||
8531 !gtk_widget_is_sensitive (widget))
8534 /* child widgets must set CAN_FOCUS, containers
8535 * don't have to though.
8537 if (!GTK_IS_CONTAINER (widget) &&
8538 !gtk_widget_get_can_focus (widget))
8541 g_signal_emit (widget,
8542 widget_signals[FOCUS],
8544 direction, &return_val);
8550 * gtk_widget_keynav_failed:
8551 * @widget: a #GtkWidget
8552 * @direction: direction of focus movement
8554 * This function should be called whenever keyboard navigation within
8555 * a single widget hits a boundary. The function emits the
8556 * #GtkWidget::keynav-failed signal on the widget and its return
8557 * value should be interpreted in a way similar to the return value of
8558 * gtk_widget_child_focus():
8560 * When %TRUE is returned, stay in the widget, the failed keyboard
8561 * navigation is Ok and/or there is nowhere we can/should move the
8564 * When %FALSE is returned, the caller should continue with keyboard
8565 * navigation outside the widget, e.g. by calling
8566 * gtk_widget_child_focus() on the widget's toplevel.
8568 * The default ::keynav-failed handler returns %TRUE for
8569 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8570 * values of #GtkDirectionType, it looks at the
8571 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8572 * if the setting is %TRUE. This way the entire user interface
8573 * becomes cursor-navigatable on input devices such as mobile phones
8574 * which only have cursor keys but no tab key.
8576 * Whenever the default handler returns %TRUE, it also calls
8577 * gtk_widget_error_bell() to notify the user of the failed keyboard
8580 * A use case for providing an own implementation of ::keynav-failed
8581 * (either by connecting to it or by overriding it) would be a row of
8582 * #GtkEntry widgets where the user should be able to navigate the
8583 * entire row with the cursor keys, as e.g. known from user interfaces
8584 * that require entering license keys.
8586 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8587 * if the emitting widget should try to handle the keyboard
8588 * navigation attempt in its parent container(s).
8593 gtk_widget_keynav_failed (GtkWidget *widget,
8594 GtkDirectionType direction)
8596 gboolean return_val;
8598 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8600 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8601 direction, &return_val);
8607 * gtk_widget_error_bell:
8608 * @widget: a #GtkWidget
8610 * Notifies the user about an input-related error on this widget.
8611 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8612 * gdk_window_beep(), otherwise it does nothing.
8614 * Note that the effect of gdk_window_beep() can be configured in many
8615 * ways, depending on the windowing backend and the desktop environment
8616 * or window manager that is used.
8621 gtk_widget_error_bell (GtkWidget *widget)
8623 GtkWidgetPrivate *priv;
8624 GtkSettings* settings;
8627 g_return_if_fail (GTK_IS_WIDGET (widget));
8629 priv = widget->priv;
8631 settings = gtk_widget_get_settings (widget);
8635 g_object_get (settings,
8636 "gtk-error-bell", &beep,
8639 if (beep && priv->window)
8640 gdk_window_beep (priv->window);
8644 gtk_widget_set_usize_internal (GtkWidget *widget,
8648 GtkWidgetAuxInfo *aux_info;
8649 gboolean changed = FALSE;
8651 g_object_freeze_notify (G_OBJECT (widget));
8653 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8655 if (width > -2 && aux_info->width != width)
8657 g_object_notify (G_OBJECT (widget), "width-request");
8658 aux_info->width = width;
8661 if (height > -2 && aux_info->height != height)
8663 g_object_notify (G_OBJECT (widget), "height-request");
8664 aux_info->height = height;
8668 if (gtk_widget_get_visible (widget) && changed)
8669 gtk_widget_queue_resize (widget);
8671 g_object_thaw_notify (G_OBJECT (widget));
8675 * gtk_widget_set_size_request:
8676 * @widget: a #GtkWidget
8677 * @width: width @widget should request, or -1 to unset
8678 * @height: height @widget should request, or -1 to unset
8680 * Sets the minimum size of a widget; that is, the widget's size
8681 * request will be @width by @height. You can use this function to
8682 * force a widget to be either larger or smaller than it normally
8685 * In most cases, gtk_window_set_default_size() is a better choice for
8686 * toplevel windows than this function; setting the default size will
8687 * still allow users to shrink the window. Setting the size request
8688 * will force them to leave the window at least as large as the size
8689 * request. When dealing with window sizes,
8690 * gtk_window_set_geometry_hints() can be a useful function as well.
8692 * Note the inherent danger of setting any fixed size - themes,
8693 * translations into other languages, different fonts, and user action
8694 * can all change the appropriate size for a given widget. So, it's
8695 * basically impossible to hardcode a size that will always be
8698 * The size request of a widget is the smallest size a widget can
8699 * accept while still functioning well and drawing itself correctly.
8700 * However in some strange cases a widget may be allocated less than
8701 * its requested size, and in many cases a widget may be allocated more
8702 * space than it requested.
8704 * If the size request in a given direction is -1 (unset), then
8705 * the "natural" size request of the widget will be used instead.
8707 * Widgets can't actually be allocated a size less than 1 by 1, but
8708 * you can pass 0,0 to this function to mean "as small as possible."
8710 * The size request set here does not include any margin from the
8711 * #GtkWidget properties margin-left, margin-right, margin-top, and
8712 * margin-bottom, but it does include pretty much all other padding
8713 * or border properties set by any subclass of #GtkWidget.
8716 gtk_widget_set_size_request (GtkWidget *widget,
8720 g_return_if_fail (GTK_IS_WIDGET (widget));
8721 g_return_if_fail (width >= -1);
8722 g_return_if_fail (height >= -1);
8729 gtk_widget_set_usize_internal (widget, width, height);
8734 * gtk_widget_get_size_request:
8735 * @widget: a #GtkWidget
8736 * @width: (out) (allow-none): return location for width, or %NULL
8737 * @height: (out) (allow-none): return location for height, or %NULL
8739 * Gets the size request that was explicitly set for the widget using
8740 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8741 * @height indicates that that dimension has not been set explicitly
8742 * and the natural requisition of the widget will be used intead. See
8743 * gtk_widget_set_size_request(). To get the size a widget will
8744 * actually request, call gtk_widget_get_preferred_size() instead of
8748 gtk_widget_get_size_request (GtkWidget *widget,
8752 const GtkWidgetAuxInfo *aux_info;
8754 g_return_if_fail (GTK_IS_WIDGET (widget));
8756 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8759 *width = aux_info->width;
8762 *height = aux_info->height;
8766 * gtk_widget_set_events:
8767 * @widget: a #GtkWidget
8768 * @events: event mask
8770 * Sets the event mask (see #GdkEventMask) for a widget. The event
8771 * mask determines which events a widget will receive. Keep in mind
8772 * that different widgets have different default event masks, and by
8773 * changing the event mask you may disrupt a widget's functionality,
8774 * so be careful. This function must be called while a widget is
8775 * unrealized. Consider gtk_widget_add_events() for widgets that are
8776 * already realized, or if you want to preserve the existing event
8777 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8778 * to get events on those widgets, place them inside a #GtkEventBox
8779 * and receive events on the event box.
8782 gtk_widget_set_events (GtkWidget *widget,
8785 g_return_if_fail (GTK_IS_WIDGET (widget));
8786 g_return_if_fail (!gtk_widget_get_realized (widget));
8788 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8789 GINT_TO_POINTER (events));
8790 g_object_notify (G_OBJECT (widget), "events");
8794 * gtk_widget_set_device_events:
8795 * @widget: a #GtkWidget
8796 * @device: a #GdkDevice
8797 * @events: event mask
8799 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8800 * mask determines which events a widget will receive from @device. Keep
8801 * in mind that different widgets have different default event masks, and by
8802 * changing the event mask you may disrupt a widget's functionality,
8803 * so be careful. This function must be called while a widget is
8804 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8805 * already realized, or if you want to preserve the existing event
8806 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8807 * to get events on those widgets, place them inside a #GtkEventBox
8808 * and receive events on the event box.
8813 gtk_widget_set_device_events (GtkWidget *widget,
8815 GdkEventMask events)
8817 GHashTable *device_events;
8819 g_return_if_fail (GTK_IS_WIDGET (widget));
8820 g_return_if_fail (GDK_IS_DEVICE (device));
8821 g_return_if_fail (!gtk_widget_get_realized (widget));
8823 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8825 if (G_UNLIKELY (!device_events))
8827 device_events = g_hash_table_new (NULL, NULL);
8828 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8829 (GDestroyNotify) g_hash_table_unref);
8832 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8836 gtk_widget_add_events_internal_list (GtkWidget *widget,
8843 for (l = window_list; l != NULL; l = l->next)
8845 GdkWindow *window = l->data;
8848 gdk_window_get_user_data (window, &user_data);
8849 if (user_data == widget)
8854 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8856 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8858 children = gdk_window_get_children (window);
8859 gtk_widget_add_events_internal_list (widget, device, events, children);
8860 g_list_free (children);
8866 gtk_widget_add_events_internal (GtkWidget *widget,
8870 GtkWidgetPrivate *priv = widget->priv;
8873 if (!gtk_widget_get_has_window (widget))
8874 window_list = gdk_window_get_children (priv->window);
8876 window_list = g_list_prepend (NULL, priv->window);
8878 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8880 g_list_free (window_list);
8884 * gtk_widget_add_events:
8885 * @widget: a #GtkWidget
8886 * @events: an event mask, see #GdkEventMask
8888 * Adds the events in the bitfield @events to the event mask for
8889 * @widget. See gtk_widget_set_events() for details.
8892 gtk_widget_add_events (GtkWidget *widget,
8897 g_return_if_fail (GTK_IS_WIDGET (widget));
8899 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8900 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8901 GINT_TO_POINTER (old_events | events));
8903 if (gtk_widget_get_realized (widget))
8904 gtk_widget_add_events_internal (widget, NULL, events);
8906 g_object_notify (G_OBJECT (widget), "events");
8910 * gtk_widget_add_device_events:
8911 * @widget: a #GtkWidget
8912 * @device: a #GdkDevice
8913 * @events: an event mask, see #GdkEventMask
8915 * Adds the device events in the bitfield @events to the event mask for
8916 * @widget. See gtk_widget_set_device_events() for details.
8921 gtk_widget_add_device_events (GtkWidget *widget,
8923 GdkEventMask events)
8925 GdkEventMask old_events;
8926 GHashTable *device_events;
8928 g_return_if_fail (GTK_IS_WIDGET (widget));
8929 g_return_if_fail (GDK_IS_DEVICE (device));
8931 old_events = gtk_widget_get_device_events (widget, device);
8933 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8935 if (G_UNLIKELY (!device_events))
8937 device_events = g_hash_table_new (NULL, NULL);
8938 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8939 (GDestroyNotify) g_hash_table_unref);
8942 g_hash_table_insert (device_events, device,
8943 GUINT_TO_POINTER (old_events | events));
8945 if (gtk_widget_get_realized (widget))
8946 gtk_widget_add_events_internal (widget, device, events);
8948 g_object_notify (G_OBJECT (widget), "events");
8952 * gtk_widget_set_extension_events:
8953 * @widget: a #GtkWidget
8954 * @mode: bitfield of extension events to receive
8956 * Sets the extension events mask to @mode. See #GdkExtensionMode
8957 * and gdk_input_set_extension_events().
8960 gtk_widget_set_extension_events (GtkWidget *widget,
8961 GdkExtensionMode mode)
8963 g_return_if_fail (GTK_IS_WIDGET (widget));
8965 if (gtk_widget_get_realized (widget))
8966 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8968 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8969 GINT_TO_POINTER (mode));
8970 g_object_notify (G_OBJECT (widget), "extension-events");
8974 * gtk_widget_get_toplevel:
8975 * @widget: a #GtkWidget
8977 * This function returns the topmost widget in the container hierarchy
8978 * @widget is a part of. If @widget has no parent widgets, it will be
8979 * returned as the topmost widget. No reference will be added to the
8980 * returned widget; it should not be unreferenced.
8982 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8983 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8985 * %NULL if @widget wasn't inside a toplevel window, and if the
8986 * window was inside a #GtkWindow-derived widget which was in turn
8987 * inside the toplevel #GtkWindow. While the second case may
8988 * seem unlikely, it actually happens when a #GtkPlug is embedded
8989 * inside a #GtkSocket within the same application.
8991 * To reliably find the toplevel #GtkWindow, use
8992 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8993 * is set on the result.
8995 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8996 * if (gtk_widget_is_toplevel (toplevel))
8998 * /* Perform action on toplevel. */
9002 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9003 * if there's no ancestor.
9006 gtk_widget_get_toplevel (GtkWidget *widget)
9008 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9010 while (widget->priv->parent)
9011 widget = widget->priv->parent;
9017 * gtk_widget_get_ancestor:
9018 * @widget: a #GtkWidget
9019 * @widget_type: ancestor type
9021 * Gets the first ancestor of @widget with type @widget_type. For example,
9022 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9023 * the first #GtkBox that's an ancestor of @widget. No reference will be
9024 * added to the returned widget; it should not be unreferenced. See note
9025 * about checking for a toplevel #GtkWindow in the docs for
9026 * gtk_widget_get_toplevel().
9028 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9029 * considers @widget to be an ancestor of itself.
9031 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9034 gtk_widget_get_ancestor (GtkWidget *widget,
9037 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9039 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9040 widget = widget->priv->parent;
9042 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9049 * gtk_widget_set_visual:
9050 * @widget: a #GtkWidget
9051 * @visual: visual to be used or %NULL to unset a previous one
9053 * Sets the visual that should be used for by widget and its children for
9054 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9055 * returned by gdk_widget_get_screen(), so handling the
9056 * GtkWidget::screen-changed signal is necessary.
9058 * Setting a new @visual will not cause @widget to recreate its windows,
9059 * so you should call this function before @widget is realized.
9062 gtk_widget_set_visual (GtkWidget *widget,
9065 g_return_if_fail (GTK_IS_WIDGET (widget));
9066 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9069 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9072 g_object_set_qdata_full (G_OBJECT (widget),
9074 g_object_ref (visual),
9079 * gtk_widget_get_visual:
9080 * @widget: a #GtkWidget
9082 * Gets the visual that will be used to render @widget.
9084 * Return value: (transfer none): the visual for @widget
9087 gtk_widget_get_visual (GtkWidget *widget)
9093 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9095 if (gtk_widget_get_has_window (widget) &&
9096 widget->priv->window)
9097 return gdk_window_get_visual (widget->priv->window);
9099 screen = gtk_widget_get_screen (widget);
9101 for (w = widget; w != NULL; w = w->priv->parent)
9103 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9106 if (gdk_visual_get_screen (visual) == screen)
9109 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9110 gtk_widget_get_name (widget));
9114 return gdk_screen_get_system_visual (screen);
9118 * gtk_widget_get_settings:
9119 * @widget: a #GtkWidget
9121 * Gets the settings object holding the settings (global property
9122 * settings, RC file information, etc) used for this widget.
9124 * Note that this function can only be called when the #GtkWidget
9125 * is attached to a toplevel, since the settings object is specific
9126 * to a particular #GdkScreen.
9128 * Return value: (transfer none): the relevant #GtkSettings object
9131 gtk_widget_get_settings (GtkWidget *widget)
9133 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9135 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9139 * gtk_widget_get_events:
9140 * @widget: a #GtkWidget
9142 * Returns the event mask for the widget (a bitfield containing flags
9143 * from the #GdkEventMask enumeration). These are the events that the widget
9146 * Return value: event mask for @widget
9149 gtk_widget_get_events (GtkWidget *widget)
9151 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9153 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9157 * gtk_widget_get_device_events:
9158 * @widget: a #GtkWidget
9159 * @device: a #GdkDevice
9161 * Returns the events mask for the widget corresponding to an specific device. These
9162 * are the events that the widget will receive when @device operates on it.
9164 * Returns: device event mask for @widget
9169 gtk_widget_get_device_events (GtkWidget *widget,
9172 GHashTable *device_events;
9174 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9175 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9177 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9182 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9186 * gtk_widget_get_extension_events:
9187 * @widget: a #GtkWidget
9189 * Retrieves the extension events the widget will receive; see
9190 * gdk_input_set_extension_events().
9192 * Return value: extension events for @widget
9195 gtk_widget_get_extension_events (GtkWidget *widget)
9197 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9199 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9203 * gtk_widget_get_pointer:
9204 * @widget: a #GtkWidget
9205 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9206 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9208 * Obtains the location of the mouse pointer in widget coordinates.
9209 * Widget coordinates are a bit odd; for historical reasons, they are
9210 * defined as @widget->window coordinates for widgets that are not
9211 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9212 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9215 gtk_widget_get_pointer (GtkWidget *widget,
9219 GtkWidgetPrivate *priv;
9221 g_return_if_fail (GTK_IS_WIDGET (widget));
9223 priv = widget->priv;
9230 if (gtk_widget_get_realized (widget))
9232 gdk_window_get_pointer (priv->window, x, y, NULL);
9234 if (!gtk_widget_get_has_window (widget))
9237 *x -= priv->allocation.x;
9239 *y -= priv->allocation.y;
9245 * gtk_widget_is_ancestor:
9246 * @widget: a #GtkWidget
9247 * @ancestor: another #GtkWidget
9249 * Determines whether @widget is somewhere inside @ancestor, possibly with
9250 * intermediate containers.
9252 * Return value: %TRUE if @ancestor contains @widget as a child,
9253 * grandchild, great grandchild, etc.
9256 gtk_widget_is_ancestor (GtkWidget *widget,
9257 GtkWidget *ancestor)
9259 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9260 g_return_val_if_fail (ancestor != NULL, FALSE);
9264 if (widget->priv->parent == ancestor)
9266 widget = widget->priv->parent;
9272 static GQuark quark_composite_name = 0;
9275 * gtk_widget_set_composite_name:
9276 * @widget: a #GtkWidget.
9277 * @name: the name to set
9279 * Sets a widgets composite name. The widget must be
9280 * a composite child of its parent; see gtk_widget_push_composite_child().
9283 gtk_widget_set_composite_name (GtkWidget *widget,
9286 g_return_if_fail (GTK_IS_WIDGET (widget));
9287 g_return_if_fail (widget->priv->composite_child);
9288 g_return_if_fail (name != NULL);
9290 if (!quark_composite_name)
9291 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9293 g_object_set_qdata_full (G_OBJECT (widget),
9294 quark_composite_name,
9300 * gtk_widget_get_composite_name:
9301 * @widget: a #GtkWidget
9303 * Obtains the composite name of a widget.
9305 * Returns: the composite name of @widget, or %NULL if @widget is not
9306 * a composite child. The string should be freed when it is no
9310 gtk_widget_get_composite_name (GtkWidget *widget)
9312 GtkWidgetPrivate *priv;
9314 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9316 priv = widget->priv;
9318 if (widget->priv->composite_child && priv->parent)
9319 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9326 * gtk_widget_push_composite_child:
9328 * Makes all newly-created widgets as composite children until
9329 * the corresponding gtk_widget_pop_composite_child() call.
9331 * A composite child is a child that's an implementation detail of the
9332 * container it's inside and should not be visible to people using the
9333 * container. Composite children aren't treated differently by GTK (but
9334 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9335 * builders might want to treat them in a different way.
9337 * Here is a simple example:
9339 * gtk_widget_push_composite_child ();
9340 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9341 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9342 * gtk_widget_pop_composite_child ();
9343 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9344 * GTK_WIDGET (scrolled_window));
9345 * g_object_ref (scrolled_window->hscrollbar);
9349 gtk_widget_push_composite_child (void)
9351 composite_child_stack++;
9355 * gtk_widget_pop_composite_child:
9357 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9360 gtk_widget_pop_composite_child (void)
9362 if (composite_child_stack)
9363 composite_child_stack--;
9367 gtk_widget_emit_direction_changed (GtkWidget *widget,
9368 GtkTextDirection old_dir)
9370 gtk_widget_update_pango_context (widget);
9372 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9376 * gtk_widget_set_direction:
9377 * @widget: a #GtkWidget
9378 * @dir: the new direction
9380 * Sets the reading direction on a particular widget. This direction
9381 * controls the primary direction for widgets containing text,
9382 * and also the direction in which the children of a container are
9383 * packed. The ability to set the direction is present in order
9384 * so that correct localization into languages with right-to-left
9385 * reading directions can be done. Generally, applications will
9386 * let the default reading direction present, except for containers
9387 * where the containers are arranged in an order that is explicitely
9388 * visual rather than logical (such as buttons for text justification).
9390 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9391 * set by gtk_widget_set_default_direction() will be used.
9394 gtk_widget_set_direction (GtkWidget *widget,
9395 GtkTextDirection dir)
9397 GtkTextDirection old_dir;
9399 g_return_if_fail (GTK_IS_WIDGET (widget));
9400 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9402 old_dir = gtk_widget_get_direction (widget);
9404 widget->priv->direction = dir;
9406 if (old_dir != gtk_widget_get_direction (widget))
9407 gtk_widget_emit_direction_changed (widget, old_dir);
9411 * gtk_widget_get_direction:
9412 * @widget: a #GtkWidget
9414 * Gets the reading direction for a particular widget. See
9415 * gtk_widget_set_direction().
9417 * Return value: the reading direction for the widget.
9420 gtk_widget_get_direction (GtkWidget *widget)
9422 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9424 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9425 return gtk_default_direction;
9427 return widget->priv->direction;
9431 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9433 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9435 g_object_ref (widget);
9437 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9438 gtk_widget_emit_direction_changed (widget, old_dir);
9440 if (GTK_IS_CONTAINER (widget))
9441 gtk_container_forall (GTK_CONTAINER (widget),
9442 gtk_widget_set_default_direction_recurse,
9445 g_object_unref (widget);
9449 * gtk_widget_set_default_direction:
9450 * @dir: the new default direction. This cannot be
9451 * %GTK_TEXT_DIR_NONE.
9453 * Sets the default reading direction for widgets where the
9454 * direction has not been explicitly set by gtk_widget_set_direction().
9457 gtk_widget_set_default_direction (GtkTextDirection dir)
9459 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9461 if (dir != gtk_default_direction)
9463 GList *toplevels, *tmp_list;
9464 GtkTextDirection old_dir = gtk_default_direction;
9466 gtk_default_direction = dir;
9468 tmp_list = toplevels = gtk_window_list_toplevels ();
9469 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9473 gtk_widget_set_default_direction_recurse (tmp_list->data,
9474 GUINT_TO_POINTER (old_dir));
9475 g_object_unref (tmp_list->data);
9476 tmp_list = tmp_list->next;
9479 g_list_free (toplevels);
9484 * gtk_widget_get_default_direction:
9486 * Obtains the current default reading direction. See
9487 * gtk_widget_set_default_direction().
9489 * Return value: the current default direction.
9492 gtk_widget_get_default_direction (void)
9494 return gtk_default_direction;
9498 gtk_widget_dispose (GObject *object)
9500 GtkWidget *widget = GTK_WIDGET (object);
9501 GtkWidgetPrivate *priv = widget->priv;
9504 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9505 else if (gtk_widget_get_visible (widget))
9506 gtk_widget_hide (widget);
9508 priv->visible = FALSE;
9509 if (gtk_widget_get_realized (widget))
9510 gtk_widget_unrealize (widget);
9512 if (!priv->in_destruction)
9514 priv->in_destruction = TRUE;
9515 g_signal_emit (object, widget_signals[DESTROY], 0);
9516 priv->in_destruction = FALSE;
9519 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9523 gtk_widget_real_destroy (GtkWidget *object)
9525 /* gtk_object_destroy() will already hold a refcount on object */
9526 GtkWidget *widget = GTK_WIDGET (object);
9527 GtkWidgetPrivate *priv = widget->priv;
9529 /* wipe accelerator closures (keep order) */
9530 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9531 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9533 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9534 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9536 gtk_grab_remove (widget);
9538 g_object_unref (priv->style);
9539 priv->style = gtk_widget_get_default_style ();
9540 g_object_ref (priv->style);
9544 gtk_widget_finalize (GObject *object)
9546 GtkWidget *widget = GTK_WIDGET (object);
9547 GtkWidgetPrivate *priv = widget->priv;
9548 GtkWidgetAuxInfo *aux_info;
9549 GtkAccessible *accessible;
9551 gtk_grab_remove (widget);
9553 g_object_unref (priv->style);
9556 g_free (priv->name);
9558 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9560 gtk_widget_aux_info_destroy (aux_info);
9562 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9564 g_object_unref (accessible);
9566 if (g_object_is_floating (object))
9567 g_warning ("A floating object was finalized. This means that someone\n"
9568 "called g_object_unref() on an object that had only a floating\n"
9569 "reference; the initial floating reference is not owned by anyone\n"
9570 "and must be removed with g_object_ref_sink().");
9572 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9575 /*****************************************
9576 * gtk_widget_real_map:
9581 *****************************************/
9584 gtk_widget_real_map (GtkWidget *widget)
9586 GtkWidgetPrivate *priv = widget->priv;
9588 g_assert (gtk_widget_get_realized (widget));
9590 if (!gtk_widget_get_mapped (widget))
9592 gtk_widget_set_mapped (widget, TRUE);
9594 if (gtk_widget_get_has_window (widget))
9595 gdk_window_show (priv->window);
9599 /*****************************************
9600 * gtk_widget_real_unmap:
9605 *****************************************/
9608 gtk_widget_real_unmap (GtkWidget *widget)
9610 GtkWidgetPrivate *priv = widget->priv;
9612 if (gtk_widget_get_mapped (widget))
9614 gtk_widget_set_mapped (widget, FALSE);
9616 if (gtk_widget_get_has_window (widget))
9617 gdk_window_hide (priv->window);
9621 /*****************************************
9622 * gtk_widget_real_realize:
9627 *****************************************/
9630 gtk_widget_real_realize (GtkWidget *widget)
9632 GtkWidgetPrivate *priv = widget->priv;
9634 g_assert (!gtk_widget_get_has_window (widget));
9636 gtk_widget_set_realized (widget, TRUE);
9639 priv->window = gtk_widget_get_parent_window (widget);
9640 g_object_ref (priv->window);
9642 priv->style = gtk_style_attach (priv->style, priv->window);
9645 /*****************************************
9646 * gtk_widget_real_unrealize:
9651 *****************************************/
9654 gtk_widget_real_unrealize (GtkWidget *widget)
9656 GtkWidgetPrivate *priv = widget->priv;
9658 if (gtk_widget_get_mapped (widget))
9659 gtk_widget_real_unmap (widget);
9661 gtk_widget_set_mapped (widget, FALSE);
9663 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9666 /* We must do unrealize child widget BEFORE container widget.
9667 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9668 * So, unrealizing container widget bofore its children causes the problem
9669 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9672 if (GTK_IS_CONTAINER (widget))
9673 gtk_container_forall (GTK_CONTAINER (widget),
9674 (GtkCallback) gtk_widget_unrealize,
9677 gtk_style_detach (priv->style);
9678 if (gtk_widget_get_has_window (widget))
9680 gdk_window_set_user_data (priv->window, NULL);
9681 gdk_window_destroy (priv->window);
9682 priv->window = NULL;
9686 g_object_unref (priv->window);
9687 priv->window = NULL;
9690 gtk_selection_remove_all (widget);
9692 gtk_widget_set_realized (widget, FALSE);
9696 gtk_widget_real_size_request (GtkWidget *widget,
9697 GtkRequisition *requisition)
9699 requisition->width = 0;
9700 requisition->height = 0;
9704 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9705 GtkOrientation orientation,
9710 const GtkWidgetAuxInfo *aux_info;
9712 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9714 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9715 aux_info->width > 0)
9717 *minimum_size = MAX (*minimum_size, aux_info->width);
9719 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9720 aux_info->height > 0)
9722 *minimum_size = MAX (*minimum_size, aux_info->height);
9725 /* Fix it if set_size_request made natural size smaller than min size.
9726 * This would also silently fix broken widgets, but we warn about them
9727 * in gtksizerequest.c when calling their size request vfuncs.
9729 *natural_size = MAX (*natural_size, *minimum_size);
9731 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9733 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9734 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9738 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9739 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9744 * _gtk_widget_peek_request_cache:
9746 * Returns the address of the widget's request cache (strictly for
9747 * internal use in gtksizerequest.c)
9749 * Return value: the address of @widget's size request cache.
9752 _gtk_widget_peek_request_cache (GtkWidget *widget)
9754 /* Don't bother slowing things down with the return_if_fail guards here */
9755 return &widget->priv->requests;
9759 * _gtk_widget_set_device_window:
9760 * @widget: a #GtkWidget.
9761 * @device: a #GdkDevice.
9762 * @window: the new device window.
9764 * Sets pointer window for @widget and @device. Does not ref @window.
9765 * Actually stores it on the #GdkScreen, but you don't need to know that.
9768 _gtk_widget_set_device_window (GtkWidget *widget,
9772 GtkWidgetPrivate *priv;
9774 GHashTable *device_window;
9776 g_return_if_fail (GTK_IS_WIDGET (widget));
9777 g_return_if_fail (GDK_IS_DEVICE (device));
9778 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9780 priv = widget->priv;
9782 if (!gtk_widget_get_realized (widget))
9785 screen = gdk_window_get_screen (priv->window);
9786 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9788 if (G_UNLIKELY (!device_window))
9790 device_window = g_hash_table_new (NULL, NULL);
9791 g_object_set_qdata_full (G_OBJECT (screen),
9792 quark_pointer_window,
9794 (GDestroyNotify) g_hash_table_destroy);
9798 g_hash_table_insert (device_window, device, window);
9800 g_hash_table_remove (device_window, device);
9804 * _gtk_widget_get_device_window:
9805 * @widget: a #GtkWidget.
9806 * @device: a #GdkDevice.
9808 * Return value: the device window set on the #GdkScreen @widget is attached
9812 _gtk_widget_get_device_window (GtkWidget *widget,
9815 GtkWidgetPrivate *priv;
9817 GHashTable *device_window;
9821 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9822 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9824 priv = widget->priv;
9826 if (!gtk_widget_get_realized (widget))
9829 screen = gdk_window_get_screen (priv->window);
9830 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9832 if (G_UNLIKELY (!device_window))
9835 window = g_hash_table_lookup (device_window, device);
9840 gdk_window_get_user_data (window, (gpointer *) &w);
9849 * _gtk_widget_list_devices:
9850 * @widget: a #GtkWidget.
9852 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9853 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9857 _gtk_widget_list_devices (GtkWidget *widget)
9859 GtkWidgetPrivate *priv;
9861 GHashTableIter iter;
9862 GHashTable *device_window;
9863 GList *devices = NULL;
9864 gpointer key, value;
9866 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9868 priv = widget->priv;
9870 if (!gtk_widget_get_realized (widget))
9873 screen = gdk_window_get_screen (priv->window);
9874 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9876 if (G_UNLIKELY (!device_window))
9879 g_hash_table_iter_init (&iter, device_window);
9881 while (g_hash_table_iter_next (&iter, &key, &value))
9883 GdkDevice *device = key;
9884 GdkWindow *window = value;
9889 gdk_window_get_user_data (window, (gpointer *) &w);
9892 devices = g_list_prepend (devices, device);
9900 synth_crossing (GtkWidget *widget,
9904 GdkCrossingMode mode,
9905 GdkNotifyType detail)
9909 event = gdk_event_new (type);
9911 event->crossing.window = g_object_ref (window);
9912 event->crossing.send_event = TRUE;
9913 event->crossing.subwindow = g_object_ref (window);
9914 event->crossing.time = GDK_CURRENT_TIME;
9915 event->crossing.x = event->crossing.y = 0;
9916 event->crossing.x_root = event->crossing.y_root = 0;
9917 event->crossing.mode = mode;
9918 event->crossing.detail = detail;
9919 event->crossing.focus = FALSE;
9920 event->crossing.state = 0;
9921 gdk_event_set_device (event, device);
9924 widget = gtk_get_event_widget (event);
9927 gtk_widget_event_internal (widget, event);
9929 gdk_event_free (event);
9933 * _gtk_widget_synthesize_crossing:
9934 * @from: the #GtkWidget the virtual pointer is leaving.
9935 * @to: the #GtkWidget the virtual pointer is moving to.
9936 * @mode: the #GdkCrossingMode to place on the synthesized events.
9938 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9940 * The real pointer window is the window that most recently received an enter notify
9941 * event. Windows that don't select for crossing events can't become the real
9942 * poiner window. The real pointer widget that owns the real pointer window. The
9943 * effective pointer window is the same as the real pointer window unless the real
9944 * pointer widget is either insensitive or there is a grab on a widget that is not
9945 * an ancestor of the real pointer widget (in which case the effective pointer
9946 * window should be the root window).
9948 * When the effective pointer window is the same as the real poiner window, we
9949 * receive crossing events from the windowing system. When the effective pointer
9950 * window changes to become different from the real pointer window we synthesize
9951 * crossing events, attempting to follow X protocol rules:
9953 * When the root window becomes the effective pointer window:
9954 * - leave notify on real pointer window, detail Ancestor
9955 * - leave notify on all of its ancestors, detail Virtual
9956 * - enter notify on root window, detail Inferior
9958 * When the root window ceases to be the effective pointer window:
9959 * - leave notify on root window, detail Inferior
9960 * - enter notify on all ancestors of real pointer window, detail Virtual
9961 * - enter notify on real pointer window, detail Ancestor
9964 _gtk_widget_synthesize_crossing (GtkWidget *from,
9967 GdkCrossingMode mode)
9969 GdkWindow *from_window = NULL, *to_window = NULL;
9971 g_return_if_fail (from != NULL || to != NULL);
9975 from_window = _gtk_widget_get_device_window (from, device);
9978 from_window = from->priv->window;
9983 to_window = _gtk_widget_get_device_window (to, device);
9986 to_window = to->priv->window;
9989 if (from_window == NULL && to_window == NULL)
9991 else if (from_window != NULL && to_window == NULL)
9993 GList *from_ancestors = NULL, *list;
9994 GdkWindow *from_ancestor = from_window;
9996 while (from_ancestor != NULL)
9998 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9999 if (from_ancestor == NULL)
10001 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10004 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10005 device, mode, GDK_NOTIFY_ANCESTOR);
10006 for (list = g_list_last (from_ancestors); list; list = list->prev)
10008 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10009 device, mode, GDK_NOTIFY_VIRTUAL);
10012 /* XXX: enter/inferior on root window? */
10014 g_list_free (from_ancestors);
10016 else if (from_window == NULL && to_window != NULL)
10018 GList *to_ancestors = NULL, *list;
10019 GdkWindow *to_ancestor = to_window;
10021 while (to_ancestor != NULL)
10023 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10024 if (to_ancestor == NULL)
10026 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10029 /* XXX: leave/inferior on root window? */
10031 for (list = to_ancestors; list; list = list->next)
10033 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10034 device, mode, GDK_NOTIFY_VIRTUAL);
10036 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10037 device, mode, GDK_NOTIFY_ANCESTOR);
10039 g_list_free (to_ancestors);
10041 else if (from_window == to_window)
10045 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10046 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10048 while (from_ancestor != NULL || to_ancestor != NULL)
10050 if (from_ancestor != NULL)
10052 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10053 if (from_ancestor == to_window)
10056 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10058 if (to_ancestor != NULL)
10060 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10061 if (to_ancestor == from_window)
10064 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10067 if (to_ancestor == from_window)
10069 if (mode != GDK_CROSSING_GTK_UNGRAB)
10070 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10071 device, mode, GDK_NOTIFY_INFERIOR);
10072 for (list = to_ancestors; list; list = list->next)
10073 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10074 device, mode, GDK_NOTIFY_VIRTUAL);
10075 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10076 device, mode, GDK_NOTIFY_ANCESTOR);
10078 else if (from_ancestor == to_window)
10080 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10081 device, mode, GDK_NOTIFY_ANCESTOR);
10082 for (list = g_list_last (from_ancestors); list; list = list->prev)
10084 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10085 device, mode, GDK_NOTIFY_VIRTUAL);
10087 if (mode != GDK_CROSSING_GTK_GRAB)
10088 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10089 device, mode, GDK_NOTIFY_INFERIOR);
10093 while (from_ancestors != NULL && to_ancestors != NULL
10094 && from_ancestors->data == to_ancestors->data)
10096 from_ancestors = g_list_delete_link (from_ancestors,
10098 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10101 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10102 device, mode, GDK_NOTIFY_NONLINEAR);
10104 for (list = g_list_last (from_ancestors); list; list = list->prev)
10106 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10107 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10109 for (list = to_ancestors; list; list = list->next)
10111 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10112 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10114 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10115 device, mode, GDK_NOTIFY_NONLINEAR);
10117 g_list_free (from_ancestors);
10118 g_list_free (to_ancestors);
10123 gtk_widget_propagate_state (GtkWidget *widget,
10124 GtkStateData *data)
10126 GtkWidgetPrivate *priv = widget->priv;
10127 guint8 old_state = gtk_widget_get_state (widget);
10128 guint8 old_saved_state = priv->saved_state;
10130 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10131 * parent_sensitive==TRUE on a sensitive widget
10135 priv->parent_sensitive = data->parent_sensitive;
10137 if (gtk_widget_is_sensitive (widget))
10139 if (data->state_restoration)
10140 priv->state = priv->saved_state;
10142 priv->state = data->state;
10146 if (!data->state_restoration)
10148 if (data->state != GTK_STATE_INSENSITIVE)
10149 priv->saved_state = data->state;
10151 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10152 priv->saved_state = gtk_widget_get_state (widget);
10153 priv->state = GTK_STATE_INSENSITIVE;
10156 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10160 window = gtk_widget_get_toplevel (widget);
10161 if (window && gtk_widget_is_toplevel (window))
10162 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10165 if (old_state != gtk_widget_get_state (widget) ||
10166 old_saved_state != priv->saved_state)
10168 g_object_ref (widget);
10170 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10171 gtk_grab_remove (widget);
10173 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10175 if (!priv->shadowed)
10177 GList *event_windows = NULL;
10178 GList *devices, *d;
10180 devices = _gtk_widget_list_devices (widget);
10182 for (d = devices; d; d = d->next)
10188 window = _gtk_widget_get_device_window (widget, device);
10190 /* Do not propagate more than once to the
10191 * same window if non-multidevice aware.
10193 if (!gdk_window_get_support_multidevice (window) &&
10194 g_list_find (event_windows, window))
10197 if (!gtk_widget_is_sensitive (widget))
10198 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10199 GDK_CROSSING_STATE_CHANGED);
10200 else if (old_state == GTK_STATE_INSENSITIVE)
10201 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10202 GDK_CROSSING_STATE_CHANGED);
10204 event_windows = g_list_prepend (event_windows, window);
10207 g_list_free (event_windows);
10208 g_list_free (devices);
10211 if (GTK_IS_CONTAINER (widget))
10213 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10214 if (data->use_forall)
10215 gtk_container_forall (GTK_CONTAINER (widget),
10216 (GtkCallback) gtk_widget_propagate_state,
10219 gtk_container_foreach (GTK_CONTAINER (widget),
10220 (GtkCallback) gtk_widget_propagate_state,
10223 g_object_unref (widget);
10227 static const GtkWidgetAuxInfo default_aux_info = {
10235 * _gtk_widget_get_aux_info:
10236 * @widget: a #GtkWidget
10237 * @create: if %TRUE, create the structure if it doesn't exist
10239 * Get the #GtkWidgetAuxInfo structure for the widget.
10241 * Return value: the #GtkAuxInfo structure for the widget, or
10242 * %NULL if @create is %FALSE and one doesn't already exist.
10245 _gtk_widget_get_aux_info (GtkWidget *widget,
10248 GtkWidgetAuxInfo *aux_info;
10250 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10251 if (!aux_info && create)
10253 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10255 *aux_info = default_aux_info;
10257 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10263 static const GtkWidgetAuxInfo*
10264 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10266 GtkWidgetAuxInfo *aux_info;
10268 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10269 if (aux_info == NULL)
10271 return &default_aux_info;
10279 /*****************************************
10280 * gtk_widget_aux_info_destroy:
10285 *****************************************/
10288 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10290 g_slice_free (GtkWidgetAuxInfo, aux_info);
10294 * gtk_widget_shape_combine_region:
10295 * @widget: a #GtkWidget
10296 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10298 * Sets a shape for this widget's GDK window. This allows for
10299 * transparent windows etc., see gdk_window_shape_combine_region()
10300 * for more information.
10305 gtk_widget_shape_combine_region (GtkWidget *widget,
10306 cairo_region_t *region)
10308 GtkWidgetPrivate *priv;
10310 g_return_if_fail (GTK_IS_WIDGET (widget));
10311 /* set_shape doesn't work on widgets without gdk window */
10312 g_return_if_fail (gtk_widget_get_has_window (widget));
10314 priv = widget->priv;
10316 if (region == NULL)
10318 priv->has_shape_mask = FALSE;
10321 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10323 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10327 priv->has_shape_mask = TRUE;
10329 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10330 cairo_region_copy (region),
10331 (GDestroyNotify) cairo_region_destroy);
10333 /* set shape if widget has a gdk window already.
10334 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10337 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10342 * gtk_widget_input_shape_combine_region:
10343 * @widget: a #GtkWidget
10344 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10346 * Sets an input shape for this widget's GDK window. This allows for
10347 * windows which react to mouse click in a nonrectangular region, see
10348 * gdk_window_input_shape_combine_region() for more information.
10353 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10354 cairo_region_t *region)
10356 GtkWidgetPrivate *priv;
10358 g_return_if_fail (GTK_IS_WIDGET (widget));
10359 /* set_shape doesn't work on widgets without gdk window */
10360 g_return_if_fail (gtk_widget_get_has_window (widget));
10362 priv = widget->priv;
10364 if (region == NULL)
10367 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10369 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10373 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10374 cairo_region_copy (region),
10375 (GDestroyNotify) cairo_region_destroy);
10377 /* set shape if widget has a gdk window already.
10378 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10381 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10387 gtk_reset_shapes_recurse (GtkWidget *widget,
10393 gdk_window_get_user_data (window, &data);
10394 if (data != widget)
10397 gdk_window_shape_combine_region (window, NULL, 0, 0);
10398 for (list = gdk_window_peek_children (window); list; list = list->next)
10399 gtk_reset_shapes_recurse (widget, list->data);
10403 * gtk_widget_reset_shapes:
10404 * @widget: a #GtkWidget
10406 * Recursively resets the shape on this widget and its descendants.
10409 gtk_widget_reset_shapes (GtkWidget *widget)
10411 GtkWidgetPrivate *priv;
10413 g_return_if_fail (GTK_IS_WIDGET (widget));
10414 g_return_if_fail (gtk_widget_get_realized (widget));
10416 priv = widget->priv;
10418 if (!priv->has_shape_mask)
10419 gtk_reset_shapes_recurse (widget, priv->window);
10422 /* style properties
10426 * gtk_widget_class_install_style_property_parser:
10427 * @klass: a #GtkWidgetClass
10428 * @pspec: the #GParamSpec for the style property
10429 * @parser: the parser for the style property
10431 * Installs a style property on a widget class.
10434 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10436 GtkRcPropertyParser parser)
10438 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10439 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10440 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10441 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10443 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10445 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10446 G_OBJECT_CLASS_NAME (klass),
10451 g_param_spec_ref_sink (pspec);
10452 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10453 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10457 * gtk_widget_class_install_style_property:
10458 * @klass: a #GtkWidgetClass
10459 * @pspec: the #GParamSpec for the property
10461 * Installs a style property on a widget class. The parser for the
10462 * style property is determined by the value type of @pspec.
10465 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10468 GtkRcPropertyParser parser;
10470 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10471 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10473 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10475 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10479 * gtk_widget_class_find_style_property:
10480 * @klass: a #GtkWidgetClass
10481 * @property_name: the name of the style property to find
10482 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10483 * style property with that name.
10485 * Finds a style property of a widget class by name.
10490 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10491 const gchar *property_name)
10493 g_return_val_if_fail (property_name != NULL, NULL);
10495 return g_param_spec_pool_lookup (style_property_spec_pool,
10497 G_OBJECT_CLASS_TYPE (klass),
10502 * gtk_widget_class_list_style_properties:
10503 * @klass: a #GtkWidgetClass
10504 * @n_properties: location to return the number of style properties found
10505 * @returns: an newly allocated array of #GParamSpec*. The array must
10506 * be freed with g_free().
10508 * Returns all style properties of a widget class.
10513 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10514 guint *n_properties)
10516 GParamSpec **pspecs;
10519 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10520 G_OBJECT_CLASS_TYPE (klass),
10529 * gtk_widget_style_get_property:
10530 * @widget: a #GtkWidget
10531 * @property_name: the name of a style property
10532 * @value: location to return the property value
10534 * Gets the value of a style property of @widget.
10537 gtk_widget_style_get_property (GtkWidget *widget,
10538 const gchar *property_name,
10541 GtkWidgetPrivate *priv;
10544 g_return_if_fail (GTK_IS_WIDGET (widget));
10545 g_return_if_fail (property_name != NULL);
10546 g_return_if_fail (G_IS_VALUE (value));
10548 priv = widget->priv;
10550 g_object_ref (widget);
10551 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10553 G_OBJECT_TYPE (widget),
10556 g_warning ("%s: widget class `%s' has no property named `%s'",
10558 G_OBJECT_TYPE_NAME (widget),
10562 const GValue *peek_value;
10564 peek_value = _gtk_style_peek_property_value (priv->style,
10565 G_OBJECT_TYPE (widget),
10567 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10569 /* auto-conversion of the caller's value type
10571 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10572 g_value_copy (peek_value, value);
10573 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10574 g_value_transform (peek_value, value);
10576 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10578 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10579 G_VALUE_TYPE_NAME (value));
10581 g_object_unref (widget);
10585 * gtk_widget_style_get_valist:
10586 * @widget: a #GtkWidget
10587 * @first_property_name: the name of the first property to get
10588 * @var_args: a <type>va_list</type> of pairs of property names and
10589 * locations to return the property values, starting with the location
10590 * for @first_property_name.
10592 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10596 gtk_widget_style_get_valist (GtkWidget *widget,
10597 const gchar *first_property_name,
10600 GtkWidgetPrivate *priv;
10603 g_return_if_fail (GTK_IS_WIDGET (widget));
10605 priv = widget->priv;
10607 g_object_ref (widget);
10609 name = first_property_name;
10612 const GValue *peek_value;
10616 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10618 G_OBJECT_TYPE (widget),
10622 g_warning ("%s: widget class `%s' has no property named `%s'",
10624 G_OBJECT_TYPE_NAME (widget),
10628 /* style pspecs are always readable so we can spare that check here */
10630 peek_value = _gtk_style_peek_property_value (priv->style,
10631 G_OBJECT_TYPE (widget),
10633 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10634 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10637 g_warning ("%s: %s", G_STRLOC, error);
10642 name = va_arg (var_args, gchar*);
10645 g_object_unref (widget);
10649 * gtk_widget_style_get:
10650 * @widget: a #GtkWidget
10651 * @first_property_name: the name of the first property to get
10652 * @Varargs: pairs of property names and locations to
10653 * return the property values, starting with the location for
10654 * @first_property_name, terminated by %NULL.
10656 * Gets the values of a multiple style properties of @widget.
10659 gtk_widget_style_get (GtkWidget *widget,
10660 const gchar *first_property_name,
10665 g_return_if_fail (GTK_IS_WIDGET (widget));
10667 va_start (var_args, first_property_name);
10668 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10674 * @widget: a #GtkWidget
10675 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10676 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10677 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10679 * Obtains the full path to @widget. The path is simply the name of a
10680 * widget and all its parents in the container hierarchy, separated by
10681 * periods. The name of a widget comes from
10682 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10683 * in gtkrc configuration files. Widget names are the type of the
10684 * widget by default (e.g. "GtkButton") or can be set to an
10685 * application-specific value with gtk_widget_set_name(). By setting
10686 * the name of a widget, you allow users or theme authors to apply
10687 * styles to that specific widget in their gtkrc
10688 * file. @path_reversed_p fills in the path in reverse order,
10689 * i.e. starting with @widget's name instead of starting with the name
10690 * of @widget's outermost ancestor.
10693 gtk_widget_path (GtkWidget *widget,
10694 guint *path_length,
10696 gchar **path_reversed)
10698 static gchar *rev_path = NULL;
10699 static guint tmp_path_len = 0;
10702 g_return_if_fail (GTK_IS_WIDGET (widget));
10707 const gchar *string;
10712 string = gtk_widget_get_name (widget);
10713 l = strlen (string);
10714 while (tmp_path_len <= len + l + 1)
10716 tmp_path_len += INIT_PATH_SIZE;
10717 rev_path = g_realloc (rev_path, tmp_path_len);
10719 s = string + l - 1;
10720 d = rev_path + len;
10721 while (s >= string)
10725 widget = widget->priv->parent;
10728 rev_path[len++] = '.';
10730 rev_path[len++] = 0;
10735 *path_length = len - 1;
10737 *path_reversed = g_strdup (rev_path);
10740 *path = g_strdup (rev_path);
10741 g_strreverse (*path);
10746 * gtk_widget_class_path:
10747 * @widget: a #GtkWidget
10748 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10749 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10750 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10753 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10754 * never uses a custom name set with gtk_widget_set_name().
10758 gtk_widget_class_path (GtkWidget *widget,
10759 guint *path_length,
10761 gchar **path_reversed)
10763 static gchar *rev_path = NULL;
10764 static guint tmp_path_len = 0;
10767 g_return_if_fail (GTK_IS_WIDGET (widget));
10772 const gchar *string;
10777 string = g_type_name (G_OBJECT_TYPE (widget));
10778 l = strlen (string);
10779 while (tmp_path_len <= len + l + 1)
10781 tmp_path_len += INIT_PATH_SIZE;
10782 rev_path = g_realloc (rev_path, tmp_path_len);
10784 s = string + l - 1;
10785 d = rev_path + len;
10786 while (s >= string)
10790 widget = widget->priv->parent;
10793 rev_path[len++] = '.';
10795 rev_path[len++] = 0;
10800 *path_length = len - 1;
10802 *path_reversed = g_strdup (rev_path);
10805 *path = g_strdup (rev_path);
10806 g_strreverse (*path);
10811 * gtk_requisition_new:
10813 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10815 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10816 * be freed with gtk_requisition_free().
10821 gtk_requisition_new (void)
10823 return g_slice_new0 (GtkRequisition);
10827 * gtk_requisition_copy:
10828 * @requisition: a #GtkRequisition
10830 * Copies a #GtkRequisition.
10832 * Returns: a copy of @requisition
10835 gtk_requisition_copy (const GtkRequisition *requisition)
10837 return g_slice_dup (GtkRequisition, requisition);
10841 * gtk_requisition_free:
10842 * @requisition: a #GtkRequisition
10844 * Frees a #GtkRequisition.
10847 gtk_requisition_free (GtkRequisition *requisition)
10849 g_slice_free (GtkRequisition, requisition);
10852 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10853 gtk_requisition_copy,
10854 gtk_requisition_free)
10857 * gtk_widget_get_accessible:
10858 * @widget: a #GtkWidget
10860 * Returns the accessible object that describes the widget to an
10861 * assistive technology.
10863 * If no accessibility library is loaded (i.e. no ATK implementation library is
10864 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10865 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10866 * if no class-specific #AtkObject implementation is available for the widget
10867 * instance in question, it will inherit an #AtkObject implementation from the
10868 * first ancestor class for which such an implementation is defined.
10870 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10871 * library contains more information about accessible objects and their uses.
10873 * Returns: (transfer none): the #AtkObject associated with @widget
10876 gtk_widget_get_accessible (GtkWidget *widget)
10878 GtkWidgetClass *klass;
10880 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10882 klass = GTK_WIDGET_GET_CLASS (widget);
10884 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10886 return klass->get_accessible (widget);
10890 gtk_widget_real_get_accessible (GtkWidget *widget)
10892 AtkObject* accessible;
10894 accessible = g_object_get_qdata (G_OBJECT (widget),
10895 quark_accessible_object);
10898 AtkObjectFactory *factory;
10899 AtkRegistry *default_registry;
10901 default_registry = atk_get_default_registry ();
10902 factory = atk_registry_get_factory (default_registry,
10903 G_TYPE_FROM_INSTANCE (widget));
10905 atk_object_factory_create_accessible (factory,
10906 G_OBJECT (widget));
10907 g_object_set_qdata (G_OBJECT (widget),
10908 quark_accessible_object,
10915 * Initialize a AtkImplementorIface instance's virtual pointers as
10916 * appropriate to this implementor's class (GtkWidget).
10919 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10921 iface->ref_accessible = gtk_widget_ref_accessible;
10925 gtk_widget_ref_accessible (AtkImplementor *implementor)
10927 AtkObject *accessible;
10929 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10931 g_object_ref (accessible);
10936 * GtkBuildable implementation
10938 static GQuark quark_builder_has_default = 0;
10939 static GQuark quark_builder_has_focus = 0;
10940 static GQuark quark_builder_atk_relations = 0;
10941 static GQuark quark_builder_set_name = 0;
10944 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10946 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10947 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10948 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10949 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10951 iface->set_name = gtk_widget_buildable_set_name;
10952 iface->get_name = gtk_widget_buildable_get_name;
10953 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10954 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10955 iface->parser_finished = gtk_widget_buildable_parser_finished;
10956 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10957 iface->custom_finished = gtk_widget_buildable_custom_finished;
10961 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10964 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10965 g_strdup (name), g_free);
10968 static const gchar *
10969 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10971 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10975 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10976 GtkBuilder *builder,
10977 const gchar *childname)
10979 if (strcmp (childname, "accessible") == 0)
10980 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10986 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10987 GtkBuilder *builder,
10989 const GValue *value)
10991 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10992 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10993 GINT_TO_POINTER (TRUE));
10994 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10995 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10996 GINT_TO_POINTER (TRUE));
10998 g_object_set_property (G_OBJECT (buildable), name, value);
11003 gchar *action_name;
11004 GString *description;
11006 gboolean translatable;
11016 free_action (AtkActionData *data, gpointer user_data)
11018 g_free (data->action_name);
11019 g_string_free (data->description, TRUE);
11020 g_free (data->context);
11021 g_slice_free (AtkActionData, data);
11025 free_relation (AtkRelationData *data, gpointer user_data)
11027 g_free (data->target);
11028 g_free (data->type);
11029 g_slice_free (AtkRelationData, data);
11033 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11034 GtkBuilder *builder)
11036 GSList *atk_relations;
11038 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11039 gtk_widget_grab_default (GTK_WIDGET (buildable));
11040 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11041 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11043 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11044 quark_builder_atk_relations);
11047 AtkObject *accessible;
11048 AtkRelationSet *relation_set;
11051 AtkRelationType relation_type;
11052 AtkObject *target_accessible;
11054 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11055 relation_set = atk_object_ref_relation_set (accessible);
11057 for (l = atk_relations; l; l = l->next)
11059 AtkRelationData *relation = (AtkRelationData*)l->data;
11061 target = gtk_builder_get_object (builder, relation->target);
11064 g_warning ("Target object %s in <relation> does not exist",
11068 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11069 g_assert (target_accessible != NULL);
11071 relation_type = atk_relation_type_for_name (relation->type);
11072 if (relation_type == ATK_RELATION_NULL)
11074 g_warning ("<relation> type %s not found",
11078 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11079 target_accessible);
11081 g_object_unref (relation_set);
11083 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11084 g_slist_free (atk_relations);
11085 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11094 } AccessibilitySubParserData;
11097 accessibility_start_element (GMarkupParseContext *context,
11098 const gchar *element_name,
11099 const gchar **names,
11100 const gchar **values,
11101 gpointer user_data,
11104 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11106 gint line_number, char_number;
11108 if (strcmp (element_name, "relation") == 0)
11110 gchar *target = NULL;
11111 gchar *type = NULL;
11112 AtkRelationData *relation;
11114 for (i = 0; names[i]; i++)
11116 if (strcmp (names[i], "target") == 0)
11117 target = g_strdup (values[i]);
11118 else if (strcmp (names[i], "type") == 0)
11119 type = g_strdup (values[i]);
11122 g_markup_parse_context_get_position (context,
11125 g_set_error (error,
11127 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11128 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11130 line_number, char_number, names[i], "relation");
11137 if (!target || !type)
11139 g_markup_parse_context_get_position (context,
11142 g_set_error (error,
11144 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11145 "%s:%d:%d <%s> requires attribute \"%s\"",
11147 line_number, char_number, "relation",
11148 type ? "target" : "type");
11154 relation = g_slice_new (AtkRelationData);
11155 relation->target = target;
11156 relation->type = type;
11158 data->relations = g_slist_prepend (data->relations, relation);
11160 else if (strcmp (element_name, "action") == 0)
11162 const gchar *action_name = NULL;
11163 const gchar *description = NULL;
11164 const gchar *msg_context = NULL;
11165 gboolean translatable = FALSE;
11166 AtkActionData *action;
11168 for (i = 0; names[i]; i++)
11170 if (strcmp (names[i], "action_name") == 0)
11171 action_name = values[i];
11172 else if (strcmp (names[i], "description") == 0)
11173 description = values[i];
11174 else if (strcmp (names[i], "translatable") == 0)
11176 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11179 else if (strcmp (names[i], "comments") == 0)
11181 /* do nothing, comments are for translators */
11183 else if (strcmp (names[i], "context") == 0)
11184 msg_context = values[i];
11187 g_markup_parse_context_get_position (context,
11190 g_set_error (error,
11192 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11193 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11195 line_number, char_number, names[i], "action");
11202 g_markup_parse_context_get_position (context,
11205 g_set_error (error,
11207 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11208 "%s:%d:%d <%s> requires attribute \"%s\"",
11210 line_number, char_number, "action",
11215 action = g_slice_new (AtkActionData);
11216 action->action_name = g_strdup (action_name);
11217 action->description = g_string_new (description);
11218 action->context = g_strdup (msg_context);
11219 action->translatable = translatable;
11221 data->actions = g_slist_prepend (data->actions, action);
11223 else if (strcmp (element_name, "accessibility") == 0)
11226 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11230 accessibility_text (GMarkupParseContext *context,
11233 gpointer user_data,
11236 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11238 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11240 AtkActionData *action = data->actions->data;
11242 g_string_append_len (action->description, text, text_len);
11246 static const GMarkupParser accessibility_parser =
11248 accessibility_start_element,
11250 accessibility_text,
11259 } AccelGroupParserData;
11262 accel_group_start_element (GMarkupParseContext *context,
11263 const gchar *element_name,
11264 const gchar **names,
11265 const gchar **values,
11266 gpointer user_data,
11271 guint modifiers = 0;
11272 gchar *signal = NULL;
11273 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11275 for (i = 0; names[i]; i++)
11277 if (strcmp (names[i], "key") == 0)
11278 key = gdk_keyval_from_name (values[i]);
11279 else if (strcmp (names[i], "modifiers") == 0)
11281 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11287 else if (strcmp (names[i], "signal") == 0)
11288 signal = g_strdup (values[i]);
11291 if (key == 0 || signal == NULL)
11293 g_warning ("<accelerator> requires key and signal attributes");
11296 parser_data->key = key;
11297 parser_data->modifiers = modifiers;
11298 parser_data->signal = signal;
11301 static const GMarkupParser accel_group_parser =
11303 accel_group_start_element,
11307 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11308 GtkBuilder *builder,
11310 const gchar *tagname,
11311 GMarkupParser *parser,
11314 g_assert (buildable);
11316 if (strcmp (tagname, "accelerator") == 0)
11318 AccelGroupParserData *parser_data;
11320 parser_data = g_slice_new0 (AccelGroupParserData);
11321 parser_data->object = g_object_ref (buildable);
11322 *parser = accel_group_parser;
11323 *data = parser_data;
11326 if (strcmp (tagname, "accessibility") == 0)
11328 AccessibilitySubParserData *parser_data;
11330 parser_data = g_slice_new0 (AccessibilitySubParserData);
11331 *parser = accessibility_parser;
11332 *data = parser_data;
11339 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11340 GtkWidget *toplevel,
11341 gpointer user_data)
11343 AccelGroupParserData *accel_data;
11344 GSList *accel_groups;
11345 GtkAccelGroup *accel_group;
11347 g_return_if_fail (GTK_IS_WIDGET (widget));
11348 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11349 g_return_if_fail (user_data != NULL);
11351 accel_data = (AccelGroupParserData*)user_data;
11352 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11353 if (g_slist_length (accel_groups) == 0)
11355 accel_group = gtk_accel_group_new ();
11356 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11360 g_assert (g_slist_length (accel_groups) == 1);
11361 accel_group = g_slist_nth_data (accel_groups, 0);
11364 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11365 accel_data->signal,
11368 accel_data->modifiers,
11369 GTK_ACCEL_VISIBLE);
11371 g_object_unref (accel_data->object);
11372 g_free (accel_data->signal);
11373 g_slice_free (AccelGroupParserData, accel_data);
11377 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11378 GtkBuilder *builder,
11380 const gchar *tagname,
11381 gpointer user_data)
11383 AccelGroupParserData *accel_data;
11384 AccessibilitySubParserData *a11y_data;
11385 GtkWidget *toplevel;
11387 if (strcmp (tagname, "accelerator") == 0)
11389 accel_data = (AccelGroupParserData*)user_data;
11390 g_assert (accel_data->object);
11392 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11394 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11396 else if (strcmp (tagname, "accessibility") == 0)
11398 a11y_data = (AccessibilitySubParserData*)user_data;
11400 if (a11y_data->actions)
11402 AtkObject *accessible;
11407 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11409 action = ATK_ACTION (accessible);
11410 n_actions = atk_action_get_n_actions (action);
11412 for (l = a11y_data->actions; l; l = l->next)
11414 AtkActionData *action_data = (AtkActionData*)l->data;
11416 for (i = 0; i < n_actions; i++)
11417 if (strcmp (atk_action_get_name (action, i),
11418 action_data->action_name) == 0)
11423 gchar *description;
11425 if (action_data->translatable && action_data->description->len)
11426 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11427 action_data->context,
11428 action_data->description->str);
11430 description = action_data->description->str;
11432 atk_action_set_description (action, i, description);
11436 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11437 g_slist_free (a11y_data->actions);
11440 if (a11y_data->relations)
11441 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11442 a11y_data->relations);
11444 g_slice_free (AccessibilitySubParserData, a11y_data);
11449 gtk_widget_real_get_width (GtkWidget *widget,
11450 gint *minimum_size,
11451 gint *natural_size)
11461 gtk_widget_real_get_height (GtkWidget *widget,
11462 gint *minimum_size,
11463 gint *natural_size)
11473 gtk_widget_real_get_height_for_width (GtkWidget *widget,
11475 gint *minimum_height,
11476 gint *natural_height)
11478 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
11482 gtk_widget_real_get_width_for_height (GtkWidget *widget,
11484 gint *minimum_width,
11485 gint *natural_width)
11487 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
11491 * gtk_widget_get_halign:
11492 * @widget: a #GtkWidget
11494 * Gets the value of the #GtkWidget:halign property.
11496 * Returns: the horizontal alignment of @widget
11499 gtk_widget_get_halign (GtkWidget *widget)
11501 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11502 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11506 * gtk_widget_set_halign:
11507 * @widget: a #GtkWidget
11508 * @align: the horizontal alignment
11510 * Sets the horizontal alignment of @widget.
11511 * See the #GtkWidget:halign property.
11514 gtk_widget_set_halign (GtkWidget *widget,
11517 GtkWidgetAuxInfo *aux_info;
11519 g_return_if_fail (GTK_IS_WIDGET (widget));
11521 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11523 if (aux_info->halign == align)
11526 aux_info->halign = align;
11527 gtk_widget_queue_resize (widget);
11528 g_object_notify (G_OBJECT (widget), "halign");
11532 * gtk_widget_get_valign:
11533 * @widget: a #GtkWidget
11535 * Gets the value of the #GtkWidget:valign property.
11537 * Returns: the vertical alignment of @widget
11540 gtk_widget_get_valign (GtkWidget *widget)
11542 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11543 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11547 * gtk_widget_set_valign:
11548 * @widget: a #GtkWidget
11549 * @align: the vertical alignment
11551 * Sets the vertical alignment of @widget.
11552 * See the #GtkWidget:valign property.
11555 gtk_widget_set_valign (GtkWidget *widget,
11558 GtkWidgetAuxInfo *aux_info;
11560 g_return_if_fail (GTK_IS_WIDGET (widget));
11562 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11564 if (aux_info->valign == align)
11567 aux_info->valign = align;
11568 gtk_widget_queue_resize (widget);
11569 g_object_notify (G_OBJECT (widget), "valign");
11573 * gtk_widget_get_margin_left:
11574 * @widget: a #GtkWidget
11576 * Gets the value of the #GtkWidget:margin-left property.
11578 * Returns: The left margin of @widget
11581 gtk_widget_get_margin_left (GtkWidget *widget)
11583 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11585 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11589 * gtk_widget_set_margin_left:
11590 * @widget: a #GtkWidget
11591 * @margin: the left margin
11593 * Sets the left margin of @widget.
11594 * See the #GtkWidget:margin-left property.
11597 gtk_widget_set_margin_left (GtkWidget *widget,
11600 GtkWidgetAuxInfo *aux_info;
11602 g_return_if_fail (GTK_IS_WIDGET (widget));
11603 g_return_if_fail (margin <= G_MAXINT16);
11605 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11607 if (aux_info->margin.left == margin)
11610 aux_info->margin.left = margin;
11611 gtk_widget_queue_resize (widget);
11612 g_object_notify (G_OBJECT (widget), "margin-left");
11616 * gtk_widget_get_margin_right:
11617 * @widget: a #GtkWidget
11619 * Gets the value of the #GtkWidget:margin-right property.
11621 * Returns: The left margin of @widget
11624 gtk_widget_get_margin_right (GtkWidget *widget)
11626 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11628 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11632 * gtk_widget_set_margin_right:
11633 * @widget: a #GtkWidget
11634 * @margin: the right margin
11636 * Sets the right margin of @widget.
11637 * See the #GtkWidget:margin-right property.
11640 gtk_widget_set_margin_right (GtkWidget *widget,
11643 GtkWidgetAuxInfo *aux_info;
11645 g_return_if_fail (GTK_IS_WIDGET (widget));
11646 g_return_if_fail (margin <= G_MAXINT16);
11648 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11650 if (aux_info->margin.right == margin)
11653 aux_info->margin.right = margin;
11654 gtk_widget_queue_resize (widget);
11655 g_object_notify (G_OBJECT (widget), "margin-right");
11659 * gtk_widget_get_margin_top:
11660 * @widget: a #GtkWidget
11662 * Gets the value of the #GtkWidget:margin-top property.
11664 * Returns: The top margin of @widget
11667 gtk_widget_get_margin_top (GtkWidget *widget)
11669 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11671 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11675 * gtk_widget_set_margin_top:
11676 * @widget: a #GtkWidget
11677 * @margin: the top margin
11679 * Sets the top margin of @widget.
11680 * See the #GtkWidget:margin-top property.
11683 gtk_widget_set_margin_top (GtkWidget *widget,
11686 GtkWidgetAuxInfo *aux_info;
11688 g_return_if_fail (GTK_IS_WIDGET (widget));
11689 g_return_if_fail (margin <= G_MAXINT16);
11691 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11693 if (aux_info->margin.top == margin)
11696 aux_info->margin.top = margin;
11697 gtk_widget_queue_resize (widget);
11698 g_object_notify (G_OBJECT (widget), "margin-top");
11702 * gtk_widget_get_margin_bottom:
11703 * @widget: a #GtkWidget
11705 * Gets the value of the #GtkWidget:margin-bottom property.
11707 * Returns: The bottom margin of @widget
11710 gtk_widget_get_margin_bottom (GtkWidget *widget)
11712 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11714 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11718 * gtk_widget_set_margin_bottom:
11719 * @widget: a #GtkWidget
11720 * @margin: the bottom margin
11722 * Sets the bottom margin of @widget.
11723 * See the #GtkWidget:margin-bottom property.
11726 gtk_widget_set_margin_bottom (GtkWidget *widget,
11729 GtkWidgetAuxInfo *aux_info;
11731 g_return_if_fail (GTK_IS_WIDGET (widget));
11732 g_return_if_fail (margin <= G_MAXINT16);
11734 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11736 if (aux_info->margin.bottom == margin)
11739 aux_info->margin.bottom = margin;
11740 gtk_widget_queue_resize (widget);
11741 g_object_notify (G_OBJECT (widget), "margin-bottom");
11745 * gtk_widget_get_clipboard:
11746 * @widget: a #GtkWidget
11747 * @selection: a #GdkAtom which identifies the clipboard
11748 * to use. %GDK_SELECTION_CLIPBOARD gives the
11749 * default clipboard. Another common value
11750 * is %GDK_SELECTION_PRIMARY, which gives
11751 * the primary X selection.
11753 * Returns the clipboard object for the given selection to
11754 * be used with @widget. @widget must have a #GdkDisplay
11755 * associated with it, so must be attached to a toplevel
11758 * Return value: (transfer none): the appropriate clipboard object. If no
11759 * clipboard already exists, a new one will
11760 * be created. Once a clipboard object has
11761 * been created, it is persistent for all time.
11766 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11768 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11769 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11771 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11776 * gtk_widget_list_mnemonic_labels:
11777 * @widget: a #GtkWidget
11779 * Returns a newly allocated list of the widgets, normally labels, for
11780 * which this widget is the target of a mnemonic (see for example,
11781 * gtk_label_set_mnemonic_widget()).
11783 * The widgets in the list are not individually referenced. If you
11784 * want to iterate through the list and perform actions involving
11785 * callbacks that might destroy the widgets, you
11786 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11787 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11788 * widgets afterwards.
11790 * Return value: (element-type GtkWidget) (transfer container): the list of
11791 * mnemonic labels; free this list
11792 * with g_list_free() when you are done with it.
11797 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11799 GList *list = NULL;
11802 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11804 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11805 list = g_list_prepend (list, l->data);
11811 * gtk_widget_add_mnemonic_label:
11812 * @widget: a #GtkWidget
11813 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11815 * Adds a widget to the list of mnemonic labels for
11816 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11817 * list of mnemonic labels for the widget is cleared when the
11818 * widget is destroyed, so the caller must make sure to update
11819 * its internal state at this point as well, by using a connection
11820 * to the #GtkWidget::destroy signal or a weak notifier.
11825 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11828 GSList *old_list, *new_list;
11830 g_return_if_fail (GTK_IS_WIDGET (widget));
11831 g_return_if_fail (GTK_IS_WIDGET (label));
11833 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11834 new_list = g_slist_prepend (old_list, label);
11836 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11837 new_list, (GDestroyNotify) g_slist_free);
11841 * gtk_widget_remove_mnemonic_label:
11842 * @widget: a #GtkWidget
11843 * @label: a #GtkWidget that was previously set as a mnemnic label for
11844 * @widget with gtk_widget_add_mnemonic_label().
11846 * Removes a widget from the list of mnemonic labels for
11847 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11848 * must have previously been added to the list with
11849 * gtk_widget_add_mnemonic_label().
11854 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11857 GSList *old_list, *new_list;
11859 g_return_if_fail (GTK_IS_WIDGET (widget));
11860 g_return_if_fail (GTK_IS_WIDGET (label));
11862 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11863 new_list = g_slist_remove (old_list, label);
11866 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11867 new_list, (GDestroyNotify) g_slist_free);
11871 * gtk_widget_get_no_show_all:
11872 * @widget: a #GtkWidget
11874 * Returns the current value of the GtkWidget:no-show-all property,
11875 * which determines whether calls to gtk_widget_show_all() and
11876 * gtk_widget_hide_all() will affect this widget.
11878 * Return value: the current value of the "no-show-all" property.
11883 gtk_widget_get_no_show_all (GtkWidget *widget)
11885 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11887 return widget->priv->no_show_all;
11891 * gtk_widget_set_no_show_all:
11892 * @widget: a #GtkWidget
11893 * @no_show_all: the new value for the "no-show-all" property
11895 * Sets the #GtkWidget:no-show-all property, which determines whether
11896 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11899 * This is mostly for use in constructing widget hierarchies with externally
11900 * controlled visibility, see #GtkUIManager.
11905 gtk_widget_set_no_show_all (GtkWidget *widget,
11906 gboolean no_show_all)
11908 g_return_if_fail (GTK_IS_WIDGET (widget));
11910 no_show_all = (no_show_all != FALSE);
11912 if (widget->priv->no_show_all != no_show_all)
11914 widget->priv->no_show_all = no_show_all;
11916 g_object_notify (G_OBJECT (widget), "no-show-all");
11922 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11923 gboolean has_tooltip,
11926 GtkWidgetPrivate *priv = widget->priv;
11927 gboolean priv_has_tooltip;
11929 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11930 quark_has_tooltip));
11932 if (priv_has_tooltip != has_tooltip || force)
11934 priv_has_tooltip = has_tooltip;
11936 if (priv_has_tooltip)
11938 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11939 gdk_window_set_events (priv->window,
11940 gdk_window_get_events (priv->window) |
11941 GDK_LEAVE_NOTIFY_MASK |
11942 GDK_POINTER_MOTION_MASK |
11943 GDK_POINTER_MOTION_HINT_MASK);
11945 if (gtk_widget_get_has_window (widget))
11946 gtk_widget_add_events (widget,
11947 GDK_LEAVE_NOTIFY_MASK |
11948 GDK_POINTER_MOTION_MASK |
11949 GDK_POINTER_MOTION_HINT_MASK);
11952 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11953 GUINT_TO_POINTER (priv_has_tooltip));
11958 * gtk_widget_set_tooltip_window:
11959 * @widget: a #GtkWidget
11960 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11962 * Replaces the default, usually yellow, window used for displaying
11963 * tooltips with @custom_window. GTK+ will take care of showing and
11964 * hiding @custom_window at the right moment, to behave likewise as
11965 * the default tooltip window. If @custom_window is %NULL, the default
11966 * tooltip window will be used.
11968 * If the custom window should have the default theming it needs to
11969 * have the name "gtk-tooltip", see gtk_widget_set_name().
11974 gtk_widget_set_tooltip_window (GtkWidget *widget,
11975 GtkWindow *custom_window)
11977 gboolean has_tooltip;
11978 gchar *tooltip_markup;
11980 g_return_if_fail (GTK_IS_WIDGET (widget));
11981 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11983 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11986 g_object_ref (custom_window);
11988 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11989 custom_window, g_object_unref);
11991 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11992 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11994 if (has_tooltip && gtk_widget_get_visible (widget))
11995 gtk_widget_queue_tooltip_query (widget);
11999 * gtk_widget_get_tooltip_window:
12000 * @widget: a #GtkWidget
12002 * Returns the #GtkWindow of the current tooltip. This can be the
12003 * GtkWindow created by default, or the custom tooltip window set
12004 * using gtk_widget_set_tooltip_window().
12006 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12011 gtk_widget_get_tooltip_window (GtkWidget *widget)
12013 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12015 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12019 * gtk_widget_trigger_tooltip_query:
12020 * @widget: a #GtkWidget
12022 * Triggers a tooltip query on the display where the toplevel of @widget
12023 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12029 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12031 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12034 static guint tooltip_query_id;
12035 static GSList *tooltip_query_displays;
12038 tooltip_query_idle (gpointer data)
12040 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12041 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12042 g_slist_free (tooltip_query_displays);
12044 tooltip_query_displays = NULL;
12045 tooltip_query_id = 0;
12051 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12053 GdkDisplay *display;
12055 display = gtk_widget_get_display (widget);
12057 if (!g_slist_find (tooltip_query_displays, display))
12058 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12060 if (tooltip_query_id == 0)
12061 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12065 * gtk_widget_set_tooltip_text:
12066 * @widget: a #GtkWidget
12067 * @text: the contents of the tooltip for @widget
12069 * Sets @text as the contents of the tooltip. This function will take
12070 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
12071 * handler for the GtkWidget::query-tooltip signal.
12073 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12078 gtk_widget_set_tooltip_text (GtkWidget *widget,
12081 g_return_if_fail (GTK_IS_WIDGET (widget));
12083 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12087 * gtk_widget_get_tooltip_text:
12088 * @widget: a #GtkWidget
12090 * Gets the contents of the tooltip for @widget.
12092 * Return value: the tooltip text, or %NULL. You should free the
12093 * returned string with g_free() when done.
12098 gtk_widget_get_tooltip_text (GtkWidget *widget)
12100 gchar *text = NULL;
12102 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12104 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12110 * gtk_widget_set_tooltip_markup:
12111 * @widget: a #GtkWidget
12112 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12114 * Sets @markup as the contents of the tooltip, which is marked up with
12115 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12117 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
12118 * and of the default handler for the GtkWidget::query-tooltip signal.
12120 * See also the GtkWidget:tooltip-markup property and
12121 * gtk_tooltip_set_markup().
12126 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12127 const gchar *markup)
12129 g_return_if_fail (GTK_IS_WIDGET (widget));
12131 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12135 * gtk_widget_get_tooltip_markup:
12136 * @widget: a #GtkWidget
12138 * Gets the contents of the tooltip for @widget.
12140 * Return value: the tooltip text, or %NULL. You should free the
12141 * returned string with g_free() when done.
12146 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12148 gchar *text = NULL;
12150 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12152 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12158 * gtk_widget_set_has_tooltip:
12159 * @widget: a #GtkWidget
12160 * @has_tooltip: whether or not @widget has a tooltip.
12162 * Sets the has-tooltip property on @widget to @has_tooltip. See
12163 * GtkWidget:has-tooltip for more information.
12168 gtk_widget_set_has_tooltip (GtkWidget *widget,
12169 gboolean has_tooltip)
12171 g_return_if_fail (GTK_IS_WIDGET (widget));
12173 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12177 * gtk_widget_get_has_tooltip:
12178 * @widget: a #GtkWidget
12180 * Returns the current value of the has-tooltip property. See
12181 * GtkWidget:has-tooltip for more information.
12183 * Return value: current value of has-tooltip on @widget.
12188 gtk_widget_get_has_tooltip (GtkWidget *widget)
12190 gboolean has_tooltip = FALSE;
12192 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12194 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12196 return has_tooltip;
12200 * gtk_widget_get_allocation:
12201 * @widget: a #GtkWidget
12202 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12204 * Retrieves the widget's allocation.
12206 * Note, when implementing a #GtkContainer: a widget's allocation will
12207 * be its "adjusted" allocation, that is, the widget's parent
12208 * container typically calls gtk_widget_size_allocate() with an
12209 * allocation, and that allocation is then adjusted (to handle margin
12210 * and alignment for example) before assignment to the widget.
12211 * gtk_widget_get_allocation() returns the adjusted allocation that
12212 * was actually assigned to the widget. The adjusted allocation is
12213 * guaranteed to be completely contained within the
12214 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12215 * is guaranteed that its children stay inside the assigned bounds,
12216 * but not that they have exactly the bounds the container assigned.
12217 * There is no way to get the original allocation assigned by
12218 * gtk_widget_size_allocate(), since it isn't stored; if a container
12219 * implementation needs that information it will have to track it itself.
12224 gtk_widget_get_allocation (GtkWidget *widget,
12225 GtkAllocation *allocation)
12227 GtkWidgetPrivate *priv;
12229 g_return_if_fail (GTK_IS_WIDGET (widget));
12230 g_return_if_fail (allocation != NULL);
12232 priv = widget->priv;
12234 *allocation = priv->allocation;
12238 * gtk_widget_set_allocation:
12239 * @widget: a #GtkWidget
12240 * @allocation: a pointer to a #GtkAllocation to copy from
12242 * Sets the widget's allocation. This should not be used
12243 * directly, but from within a widget's size_allocate method.
12245 * The allocation set should be the "adjusted" or actual
12246 * allocation. If you're implementing a #GtkContainer, you want to use
12247 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12248 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12249 * allocation inside gtk_widget_size_allocate() to create an adjusted
12255 gtk_widget_set_allocation (GtkWidget *widget,
12256 const GtkAllocation *allocation)
12258 GtkWidgetPrivate *priv;
12260 g_return_if_fail (GTK_IS_WIDGET (widget));
12261 g_return_if_fail (allocation != NULL);
12263 priv = widget->priv;
12265 priv->allocation = *allocation;
12269 * gtk_widget_get_allocated_width:
12270 * @widget: the widget to query
12272 * Returns the width that has currently been allocated to @widget.
12273 * This function is intended to be used when implementing handlers
12274 * for the GtkWidget::draw function.
12276 * Returns: the width of the @widget
12279 gtk_widget_get_allocated_width (GtkWidget *widget)
12281 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12283 return widget->priv->allocation.width;
12287 * gtk_widget_get_allocated_height:
12288 * @widget: the widget to query
12290 * Returns the height that has currently been allocated to @widget.
12291 * This function is intended to be used when implementing handlers
12292 * for the GtkWidget::draw function.
12294 * Returns: the height of the @widget
12297 gtk_widget_get_allocated_height (GtkWidget *widget)
12299 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12301 return widget->priv->allocation.height;
12305 * gtk_widget_get_requisition:
12306 * @widget: a #GtkWidget
12307 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12309 * Retrieves the widget's requisition.
12311 * This function should only be used by widget implementations in
12312 * order to figure whether the widget's requisition has actually
12313 * changed after some internal state change (so that they can call
12314 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12316 * Normally, gtk_widget_size_request() should be used.
12320 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12321 * removed, If you need to cache sizes across requests and allocations,
12322 * add an explicit cache to the widget in question instead.
12325 gtk_widget_get_requisition (GtkWidget *widget,
12326 GtkRequisition *requisition)
12328 g_return_if_fail (GTK_IS_WIDGET (widget));
12329 g_return_if_fail (requisition != NULL);
12331 gtk_widget_get_preferred_size (widget, requisition, NULL);
12335 * gtk_widget_set_window:
12336 * @widget: a #GtkWidget
12337 * @window: a #GdkWindow
12339 * Sets a widget's window. This function should only be used in a
12340 * widget's GtkWidget::realize() implementation. The %window passed is
12341 * usually either new window created with gdk_window_new(), or the
12342 * window of its parent widget as returned by
12343 * gtk_widget_get_parent_window().
12345 * Widgets must indicate whether they will create their own #GdkWindow
12346 * by calling gtk_widget_set_has_window(). This is usually done in the
12347 * widget's init() function.
12349 * <note><para>This function does not add any reference to @window.</para></note>
12354 gtk_widget_set_window (GtkWidget *widget,
12357 GtkWidgetPrivate *priv;
12359 g_return_if_fail (GTK_IS_WIDGET (widget));
12360 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12362 priv = widget->priv;
12364 if (priv->window != window)
12366 priv->window = window;
12367 g_object_notify (G_OBJECT (widget), "window");
12372 * gtk_widget_get_window:
12373 * @widget: a #GtkWidget
12375 * Returns the widget's window if it is realized, %NULL otherwise
12377 * Return value: (transfer none): @widget's window.
12382 gtk_widget_get_window (GtkWidget *widget)
12384 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12386 return widget->priv->window;
12390 * gtk_widget_get_support_multidevice:
12391 * @widget: a #GtkWidget
12393 * Returns %TRUE if @widget is multiple pointer aware. See
12394 * gtk_widget_set_support_multidevice() for more information.
12396 * Returns: %TRUE is @widget is multidevice aware.
12399 gtk_widget_get_support_multidevice (GtkWidget *widget)
12401 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12403 return widget->priv->multidevice;
12407 * gtk_widget_set_support_multidevice:
12408 * @widget: a #GtkWidget
12409 * @support_multidevice: %TRUE to support input from multiple devices.
12411 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12412 * @widget will start receiving multiple, per device enter/leave events. Note
12413 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12414 * gdk_window_set_support_multidevice() will have to be called manually on them.
12419 gtk_widget_set_support_multidevice (GtkWidget *widget,
12420 gboolean support_multidevice)
12422 GtkWidgetPrivate *priv;
12424 g_return_if_fail (GTK_IS_WIDGET (widget));
12426 priv = widget->priv;
12428 if (support_multidevice)
12430 priv->multidevice = TRUE;
12431 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12435 priv->multidevice = FALSE;
12436 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12439 if (gtk_widget_get_realized (widget))
12440 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12444 _gtk_widget_set_has_focus (GtkWidget *widget,
12445 gboolean has_focus)
12447 widget->priv->has_focus = has_focus;
12451 * gtk_widget_send_focus_change:
12452 * @widget: a #GtkWidget
12453 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12455 * Sends the focus change @event to @widget
12457 * This function is not meant to be used by applications. The only time it
12458 * should be used is when it is necessary for a #GtkWidget to assign focus
12459 * to a widget that is semantically owned by the first widget even though
12460 * it's not a direct child - for instance, a search entry in a floating
12461 * window similar to the quick search in #GtkTreeView.
12463 * An example of its usage is:
12466 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12468 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12469 * fevent->focus_change.in = TRUE;
12470 * fevent->focus_change.window = gtk_widget_get_window (widget);
12471 * if (fevent->focus_change.window != NULL)
12472 * g_object_ref (fevent->focus_change.window);
12474 * gtk_widget_send_focus_change (widget, fevent);
12476 * gdk_event_free (event);
12479 * Return value: the return value from the event signal emission: %TRUE
12480 * if the event was handled, and %FALSE otherwise
12485 gtk_widget_send_focus_change (GtkWidget *widget,
12490 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12491 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12493 g_object_ref (widget);
12495 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12497 res = gtk_widget_event (widget, event);
12499 g_object_notify (G_OBJECT (widget), "has-focus");
12501 g_object_unref (widget);
12507 gtk_widget_in_destruction (GtkWidget *widget)
12509 return widget->priv->in_destruction;
12513 _gtk_widget_get_resize_pending (GtkWidget *widget)
12515 return widget->priv->resize_pending;
12519 _gtk_widget_set_resize_pending (GtkWidget *widget,
12520 gboolean resize_pending)
12522 widget->priv->resize_pending = resize_pending;
12526 _gtk_widget_get_in_reparent (GtkWidget *widget)
12528 return widget->priv->in_reparent;
12532 _gtk_widget_set_in_reparent (GtkWidget *widget,
12533 gboolean in_reparent)
12535 widget->priv->in_reparent = in_reparent;
12539 _gtk_widget_get_anchored (GtkWidget *widget)
12541 return widget->priv->anchored;
12545 _gtk_widget_set_anchored (GtkWidget *widget,
12548 widget->priv->anchored = anchored;
12552 _gtk_widget_get_shadowed (GtkWidget *widget)
12554 return widget->priv->shadowed;
12558 _gtk_widget_set_shadowed (GtkWidget *widget,
12561 widget->priv->shadowed = shadowed;
12565 _gtk_widget_get_alloc_needed (GtkWidget *widget)
12567 return widget->priv->alloc_needed;
12571 _gtk_widget_set_alloc_needed (GtkWidget *widget,
12572 gboolean alloc_needed)
12574 widget->priv->alloc_needed = alloc_needed;
12578 _gtk_widget_get_width_request_needed (GtkWidget *widget)
12580 return widget->priv->width_request_needed;
12584 _gtk_widget_set_width_request_needed (GtkWidget *widget,
12585 gboolean width_request_needed)
12587 widget->priv->width_request_needed = width_request_needed;
12591 _gtk_widget_get_height_request_needed (GtkWidget *widget)
12593 return widget->priv->height_request_needed;
12597 _gtk_widget_set_height_request_needed (GtkWidget *widget,
12598 gboolean height_request_needed)
12600 widget->priv->height_request_needed = height_request_needed;