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.
71 * <refsect2 id="geometry-management">
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 * #GtkWidgetClass.get_preferred_width() and
117 * #GtkWidgetClass.get_preferred_height().
119 * If a widget does move content around to smartly use up the
120 * allocated size, then it must support the request properly in
121 * both orientations; even if the request only makes sense in
124 * For instance, a #GtkLabel that does height-for-width word wrapping
125 * will not expect to have #GtkWidgetClass.get_preferred_height() called because that
126 * call is specific to a width-for-height request. In this case the
127 * label must return the heights contextual to its minimum possible
128 * width. By following this rule any widget that handles height-for-width
129 * or width-for-height requests will always be allocated at least
130 * enough space to fit its own content.
132 * Often a widget needs to get its own request during size request or
133 * allocation, for example when computing height it may need to also
134 * compute width, or when deciding how to use an allocation the widget may
135 * need to know its natural size. In these cases, the widget should be
136 * careful to call its virtual methods directly, like this:
138 * <title>Widget calling its own size request method.</title>
140 * GTK_WIDGET_GET_CLASS(widget)->get_preferred_width (widget), &min, &natural);
144 * It will not work to use the wrapper functions, such as
145 * gtk_widget_get_preferred_width(), inside your own size request
146 * implementation. These return a request adjusted by #GtkSizeGroup
147 * and by the #GtkWidgetClass.adjust_size_request() virtual method. If a
148 * widget used the wrappers inside its virtual method implementations,
149 * then the adjustments (such as widget margins) would be applied
150 * twice. GTK+ therefore does not allow this and will warn if you try
153 * Of course if you are getting the size request for
154 * <emphasis>another</emphasis> widget, such as a child of a
155 * container, you <emphasis>must</emphasis> use the wrapper APIs;
156 * otherwise, you would not properly consider widget margins,
157 * #GtkSizeGroup, and so forth.
160 * <refsect2 id="style-properties">
161 * <title>Style Properties</title>
163 * <structname>GtkWidget</structname> introduces <firstterm>style
164 * properties</firstterm> - these are basically object properties that are stored
165 * not on the object, but in the style object associated to the widget. Style
166 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
167 * This mechanism is used for configuring such things as the location of the
168 * scrollbar arrows through the theme, giving theme authors more control over the
169 * look of applications without the need to write a theme engine in C.
172 * Use gtk_widget_class_install_style_property() to install style properties for
173 * a widget class, gtk_widget_class_find_style_property() or
174 * gtk_widget_class_list_style_properties() to get information about existing
175 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
176 * gtk_widget_style_get_valist() to obtain the value of a style property.
179 * <refsect2 id="GtkWidget-BUILDER-UI">
180 * <title>GtkWidget as GtkBuildable</title>
182 * The GtkWidget implementation of the GtkBuildable interface supports a
183 * custom <accelerator> element, which has attributes named key,
184 * modifiers and signal and allows to specify accelerators.
187 * <title>A UI definition fragment specifying an accelerator</title>
188 * <programlisting><![CDATA[
189 * <object class="GtkButton">
190 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
192 * ]]></programlisting>
195 * In addition to accelerators, <structname>GtkWidget</structname> also support a
196 * custom <accessible> element, which supports actions and relations.
197 * Properties on the accessible implementation of an object can be set by accessing the
198 * internal child "accessible" of a <structname>GtkWidget</structname>.
201 * <title>A UI definition fragment specifying an accessible</title>
202 * <programlisting><![CDATA[
203 * <object class="GtkButton" id="label1"/>
204 * <property name="label">I am a Label for a Button</property>
206 * <object class="GtkButton" id="button1">
208 * <action action_name="click" translatable="yes">Click the button.</action>
209 * <relation target="label1" type="labelled-by"/>
211 * <child internal-child="accessible">
212 * <object class="AtkObject" id="a11y-button1">
213 * <property name="AtkObject::name">Clickable Button</property>
217 * ]]></programlisting>
222 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
223 #define INIT_PATH_SIZE (512)
225 struct _GtkWidgetPrivate
227 /* The state of the widget. There are actually only
228 * 5 widget states (defined in "gtkenums.h")
233 /* The saved state of the widget. When a widget's state
234 * is changed to GTK_STATE_INSENSITIVE via
235 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
236 * the old state is kept around in this field. The state
237 * will be restored once the widget gets sensitive again.
239 guint saved_state : 3;
243 guint in_destruction : 1;
246 guint composite_child : 1;
252 guint parent_sensitive : 1;
255 guint can_default : 1;
256 guint has_default : 1;
257 guint receives_default : 1;
261 guint user_style : 1;
262 guint app_paintable : 1;
263 guint double_buffered : 1;
264 guint redraw_on_alloc : 1;
265 guint no_show_all : 1;
266 guint child_visible : 1;
267 guint multidevice : 1;
268 guint has_shape_mask : 1;
269 guint in_reparent : 1;
270 guint resize_pending : 1;
271 guint alloc_needed : 1;
272 guint width_request_needed : 1;
273 guint height_request_needed : 1;
275 /* The widget's name. If the widget does not have a name
276 * (the name is NULL), then its name (as returned by
277 * "gtk_widget_get_name") is its class's name.
278 * Among other things, the widget name is used to determine
279 * the style to use for a widget.
283 /* The style for the widget. The style contains the
284 * colors the widget should be drawn in for each state
285 * along with graphics contexts used to draw with and
286 * the font to use for text.
290 /* The widget's allocated size.
292 GtkAllocation allocation;
294 /* The widget's requested sizes */
295 SizeRequestCache requests;
297 /* The widget's window or its parent window if it does
298 * not have a window. (Which will be indicated by the
299 * GTK_NO_WINDOW flag being set).
303 /* The widget's parent.
333 BUTTON_RELEASE_EVENT,
348 PROPERTY_NOTIFY_EVENT,
349 SELECTION_CLEAR_EVENT,
350 SELECTION_REQUEST_EVENT,
351 SELECTION_NOTIFY_EVENT,
366 VISIBILITY_NOTIFY_EVENT,
370 ACCEL_CLOSURES_CHANGED,
396 PROP_RECEIVES_DEFAULT,
397 PROP_COMPOSITE_CHILD,
400 PROP_EXTENSION_EVENTS,
406 PROP_DOUBLE_BUFFERED,
416 typedef struct _GtkStateData GtkStateData;
421 guint state_restoration : 1;
422 guint parent_sensitive : 1;
423 guint use_forall : 1;
426 /* --- prototypes --- */
427 static void gtk_widget_class_init (GtkWidgetClass *klass);
428 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
429 static void gtk_widget_init (GtkWidget *widget);
430 static void gtk_widget_set_property (GObject *object,
434 static void gtk_widget_get_property (GObject *object,
438 static void gtk_widget_dispose (GObject *object);
439 static void gtk_widget_real_destroy (GtkWidget *object);
440 static void gtk_widget_finalize (GObject *object);
441 static void gtk_widget_real_show (GtkWidget *widget);
442 static void gtk_widget_real_hide (GtkWidget *widget);
443 static void gtk_widget_real_map (GtkWidget *widget);
444 static void gtk_widget_real_unmap (GtkWidget *widget);
445 static void gtk_widget_real_realize (GtkWidget *widget);
446 static void gtk_widget_real_unrealize (GtkWidget *widget);
447 static void gtk_widget_real_size_request (GtkWidget *widget,
448 GtkRequisition *requisition);
449 static void gtk_widget_real_size_allocate (GtkWidget *widget,
450 GtkAllocation *allocation);
451 static void gtk_widget_real_style_set (GtkWidget *widget,
452 GtkStyle *previous_style);
453 static void gtk_widget_real_direction_changed(GtkWidget *widget,
454 GtkTextDirection previous_direction);
456 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
457 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
460 gboolean keyboard_tip,
461 GtkTooltip *tooltip);
462 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
463 GtkWidgetHelpType help_type);
465 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
467 GParamSpec **pspecs);
468 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
470 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
472 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
473 GdkEventFocus *event);
474 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
475 GdkEventFocus *event);
476 static gboolean gtk_widget_real_focus (GtkWidget *widget,
477 GtkDirectionType direction);
478 static void gtk_widget_real_move_focus (GtkWidget *widget,
479 GtkDirectionType direction);
480 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
481 GtkDirectionType direction);
482 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
483 static void gtk_widget_update_pango_context (GtkWidget *widget);
484 static void gtk_widget_propagate_state (GtkWidget *widget,
486 static void gtk_widget_reset_rc_style (GtkWidget *widget);
487 static void gtk_widget_set_style_internal (GtkWidget *widget,
489 gboolean initial_emission);
490 static gint gtk_widget_event_internal (GtkWidget *widget,
492 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
493 gboolean group_cycling);
494 static void gtk_widget_real_get_width (GtkWidget *widget,
497 static void gtk_widget_real_get_height (GtkWidget *widget,
500 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
502 gint *minimum_height,
503 gint *natural_height);
504 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
507 gint *natural_width);
508 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
509 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
510 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
511 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
512 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
513 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
514 cairo_region_t *region);
515 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
516 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
517 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
520 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
521 gboolean has_tooltip,
523 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
524 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
526 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
527 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
529 const gchar *childname);
530 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
533 const GValue *value);
534 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
537 const gchar *tagname,
538 GMarkupParser *parser,
540 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
543 const gchar *tagname,
545 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
546 GtkBuilder *builder);
548 static void gtk_widget_real_get_width (GtkWidget *widget,
551 static void gtk_widget_real_get_height (GtkWidget *widget,
555 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
558 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
559 GtkOrientation orientation,
563 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
564 GtkAllocation *allocation);
566 static void gtk_widget_set_usize_internal (GtkWidget *widget,
570 static void gtk_widget_add_events_internal (GtkWidget *widget,
574 /* --- variables --- */
575 static gpointer gtk_widget_parent_class = NULL;
576 static guint widget_signals[LAST_SIGNAL] = { 0 };
577 static GtkStyle *gtk_default_style = NULL;
578 static guint composite_child_stack = 0;
579 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
580 static GParamSpecPool *style_property_spec_pool = NULL;
582 static GQuark quark_property_parser = 0;
583 static GQuark quark_aux_info = 0;
584 static GQuark quark_accel_path = 0;
585 static GQuark quark_accel_closures = 0;
586 static GQuark quark_event_mask = 0;
587 static GQuark quark_device_event_mask = 0;
588 static GQuark quark_extension_event_mode = 0;
589 static GQuark quark_parent_window = 0;
590 static GQuark quark_pointer_window = 0;
591 static GQuark quark_shape_info = 0;
592 static GQuark quark_input_shape_info = 0;
593 static GQuark quark_pango_context = 0;
594 static GQuark quark_rc_style = 0;
595 static GQuark quark_accessible_object = 0;
596 static GQuark quark_mnemonic_labels = 0;
597 static GQuark quark_tooltip_markup = 0;
598 static GQuark quark_has_tooltip = 0;
599 static GQuark quark_tooltip_window = 0;
600 static GQuark quark_visual = 0;
601 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
602 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
604 /* --- functions --- */
606 gtk_widget_get_type (void)
608 static GType widget_type = 0;
610 if (G_UNLIKELY (widget_type == 0))
612 const GTypeInfo widget_info =
614 sizeof (GtkWidgetClass),
615 NULL, /* base_init */
616 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
617 (GClassInitFunc) gtk_widget_class_init,
618 NULL, /* class_finalize */
619 NULL, /* class_init */
622 (GInstanceInitFunc) gtk_widget_init,
623 NULL, /* value_table */
626 const GInterfaceInfo accessibility_info =
628 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
629 (GInterfaceFinalizeFunc) NULL,
630 NULL /* interface data */
633 const GInterfaceInfo buildable_info =
635 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
636 (GInterfaceFinalizeFunc) NULL,
637 NULL /* interface data */
640 widget_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "GtkWidget",
641 &widget_info, G_TYPE_FLAG_ABSTRACT);
643 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
644 &accessibility_info) ;
645 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
653 child_property_notify_dispatcher (GObject *object,
657 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
660 /* We guard against the draw signal callbacks modifying the state of the
661 * cairo context by surounding it with save/restore.
662 * Maybe we should also cairo_new_path() just to be sure?
665 gtk_widget_draw_marshaller (GClosure *closure,
666 GValue *return_value,
667 guint n_param_values,
668 const GValue *param_values,
669 gpointer invocation_hint,
670 gpointer marshal_data)
672 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
676 _gtk_marshal_BOOLEAN__BOXED (closure,
687 gtk_widget_class_init (GtkWidgetClass *klass)
689 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
690 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
691 GtkBindingSet *binding_set;
693 gtk_widget_parent_class = g_type_class_peek_parent (klass);
695 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
696 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
697 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
698 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
699 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
700 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
701 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
702 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
703 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
704 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
705 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
706 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
707 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
708 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
709 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
710 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
711 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
712 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
713 quark_visual = g_quark_from_static_string ("gtk-widget-visual");
715 style_property_spec_pool = g_param_spec_pool_new (FALSE);
716 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
717 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
718 cpn_context.dispatcher = child_property_notify_dispatcher;
719 _gtk_widget_child_property_notify_context = &cpn_context;
721 gobject_class->dispose = gtk_widget_dispose;
722 gobject_class->finalize = gtk_widget_finalize;
723 gobject_class->set_property = gtk_widget_set_property;
724 gobject_class->get_property = gtk_widget_get_property;
726 klass->destroy = gtk_widget_real_destroy;
728 klass->activate_signal = 0;
729 klass->set_scroll_adjustments_signal = 0;
730 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
731 klass->show = gtk_widget_real_show;
732 klass->show_all = gtk_widget_show;
733 klass->hide = gtk_widget_real_hide;
734 klass->hide_all = gtk_widget_hide;
735 klass->map = gtk_widget_real_map;
736 klass->unmap = gtk_widget_real_unmap;
737 klass->realize = gtk_widget_real_realize;
738 klass->unrealize = gtk_widget_real_unrealize;
739 klass->size_request = gtk_widget_real_size_request;
740 klass->size_allocate = gtk_widget_real_size_allocate;
741 klass->get_preferred_width = gtk_widget_real_get_width;
742 klass->get_preferred_height = gtk_widget_real_get_height;
743 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
744 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
745 klass->state_changed = NULL;
746 klass->parent_set = NULL;
747 klass->hierarchy_changed = NULL;
748 klass->style_set = gtk_widget_real_style_set;
749 klass->direction_changed = gtk_widget_real_direction_changed;
750 klass->grab_notify = NULL;
751 klass->child_notify = NULL;
753 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
754 klass->grab_focus = gtk_widget_real_grab_focus;
755 klass->focus = gtk_widget_real_focus;
757 klass->button_press_event = NULL;
758 klass->button_release_event = NULL;
759 klass->motion_notify_event = NULL;
760 klass->delete_event = NULL;
761 klass->destroy_event = NULL;
762 klass->key_press_event = gtk_widget_real_key_press_event;
763 klass->key_release_event = gtk_widget_real_key_release_event;
764 klass->enter_notify_event = NULL;
765 klass->leave_notify_event = NULL;
766 klass->configure_event = NULL;
767 klass->focus_in_event = gtk_widget_real_focus_in_event;
768 klass->focus_out_event = gtk_widget_real_focus_out_event;
769 klass->map_event = NULL;
770 klass->unmap_event = NULL;
771 klass->window_state_event = NULL;
772 klass->property_notify_event = _gtk_selection_property_notify;
773 klass->selection_clear_event = _gtk_selection_clear;
774 klass->selection_request_event = _gtk_selection_request;
775 klass->selection_notify_event = _gtk_selection_notify;
776 klass->selection_received = NULL;
777 klass->proximity_in_event = NULL;
778 klass->proximity_out_event = NULL;
779 klass->drag_begin = NULL;
780 klass->drag_end = NULL;
781 klass->drag_data_delete = NULL;
782 klass->drag_leave = NULL;
783 klass->drag_motion = NULL;
784 klass->drag_drop = NULL;
785 klass->drag_data_received = NULL;
786 klass->screen_changed = NULL;
787 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
788 klass->grab_broken_event = NULL;
789 klass->query_tooltip = gtk_widget_real_query_tooltip;
791 klass->show_help = gtk_widget_real_show_help;
793 /* Accessibility support */
794 klass->get_accessible = gtk_widget_real_get_accessible;
796 klass->no_expose_event = NULL;
798 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
799 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
801 g_object_class_install_property (gobject_class,
803 g_param_spec_string ("name",
805 P_("The name of the widget"),
807 GTK_PARAM_READWRITE));
808 g_object_class_install_property (gobject_class,
810 g_param_spec_object ("parent",
812 P_("The parent widget of this widget. Must be a Container widget"),
814 GTK_PARAM_READWRITE));
816 g_object_class_install_property (gobject_class,
818 g_param_spec_int ("width-request",
820 P_("Override for width request of the widget, or -1 if natural request should be used"),
824 GTK_PARAM_READWRITE));
825 g_object_class_install_property (gobject_class,
827 g_param_spec_int ("height-request",
828 P_("Height request"),
829 P_("Override for height request of the widget, or -1 if natural request should be used"),
833 GTK_PARAM_READWRITE));
834 g_object_class_install_property (gobject_class,
836 g_param_spec_boolean ("visible",
838 P_("Whether the widget is visible"),
840 GTK_PARAM_READWRITE));
841 g_object_class_install_property (gobject_class,
843 g_param_spec_boolean ("sensitive",
845 P_("Whether the widget responds to input"),
847 GTK_PARAM_READWRITE));
848 g_object_class_install_property (gobject_class,
850 g_param_spec_boolean ("app-paintable",
851 P_("Application paintable"),
852 P_("Whether the application will paint directly on the widget"),
854 GTK_PARAM_READWRITE));
855 g_object_class_install_property (gobject_class,
857 g_param_spec_boolean ("can-focus",
859 P_("Whether the widget can accept the input focus"),
861 GTK_PARAM_READWRITE));
862 g_object_class_install_property (gobject_class,
864 g_param_spec_boolean ("has-focus",
866 P_("Whether the widget has the input focus"),
868 GTK_PARAM_READWRITE));
869 g_object_class_install_property (gobject_class,
871 g_param_spec_boolean ("is-focus",
873 P_("Whether the widget is the focus widget within the toplevel"),
875 GTK_PARAM_READWRITE));
876 g_object_class_install_property (gobject_class,
878 g_param_spec_boolean ("can-default",
880 P_("Whether the widget can be the default widget"),
882 GTK_PARAM_READWRITE));
883 g_object_class_install_property (gobject_class,
885 g_param_spec_boolean ("has-default",
887 P_("Whether the widget is the default widget"),
889 GTK_PARAM_READWRITE));
890 g_object_class_install_property (gobject_class,
891 PROP_RECEIVES_DEFAULT,
892 g_param_spec_boolean ("receives-default",
893 P_("Receives default"),
894 P_("If TRUE, the widget will receive the default action when it is focused"),
896 GTK_PARAM_READWRITE));
897 g_object_class_install_property (gobject_class,
898 PROP_COMPOSITE_CHILD,
899 g_param_spec_boolean ("composite-child",
900 P_("Composite child"),
901 P_("Whether the widget is part of a composite widget"),
903 GTK_PARAM_READABLE));
904 g_object_class_install_property (gobject_class,
906 g_param_spec_object ("style",
908 P_("The style of the widget, which contains information about how it will look (colors etc)"),
910 GTK_PARAM_READWRITE));
911 g_object_class_install_property (gobject_class,
913 g_param_spec_flags ("events",
915 P_("The event mask that decides what kind of GdkEvents this widget gets"),
918 GTK_PARAM_READWRITE));
919 g_object_class_install_property (gobject_class,
920 PROP_EXTENSION_EVENTS,
921 g_param_spec_enum ("extension-events",
922 P_("Extension events"),
923 P_("The mask that decides what kind of extension events this widget gets"),
924 GDK_TYPE_EXTENSION_MODE,
925 GDK_EXTENSION_EVENTS_NONE,
926 GTK_PARAM_READWRITE));
927 g_object_class_install_property (gobject_class,
929 g_param_spec_boolean ("no-show-all",
931 P_("Whether gtk_widget_show_all() should not affect this widget"),
933 GTK_PARAM_READWRITE));
936 * GtkWidget:has-tooltip:
938 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
939 * A value of %TRUE indicates that @widget can have a tooltip, in this case
940 * the widget will be queried using #GtkWidget::query-tooltip to determine
941 * whether it will provide a tooltip or not.
943 * Note that setting this property to %TRUE for the first time will change
944 * the event masks of the GdkWindows of this widget to include leave-notify
945 * and motion-notify events. This cannot and will not be undone when the
946 * property is set to %FALSE again.
950 g_object_class_install_property (gobject_class,
952 g_param_spec_boolean ("has-tooltip",
954 P_("Whether this widget has a tooltip"),
956 GTK_PARAM_READWRITE));
958 * GtkWidget:tooltip-text:
960 * Sets the text of tooltip to be the given string.
962 * Also see gtk_tooltip_set_text().
964 * This is a convenience property which will take care of getting the
965 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
966 * will automatically be set to %TRUE and there will be taken care of
967 * #GtkWidget::query-tooltip in the default signal handler.
971 g_object_class_install_property (gobject_class,
973 g_param_spec_string ("tooltip-text",
975 P_("The contents of the tooltip for this widget"),
977 GTK_PARAM_READWRITE));
979 * GtkWidget:tooltip-markup:
981 * Sets the text of tooltip to be the given string, which is marked up
982 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
983 * Also see gtk_tooltip_set_markup().
985 * This is a convenience property which will take care of getting the
986 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
987 * will automatically be set to %TRUE and there will be taken care of
988 * #GtkWidget::query-tooltip in the default signal handler.
992 g_object_class_install_property (gobject_class,
994 g_param_spec_string ("tooltip-markup",
995 P_("Tooltip markup"),
996 P_("The contents of the tooltip for this widget"),
998 GTK_PARAM_READWRITE));
1003 * The widget's window if it is realized, %NULL otherwise.
1007 g_object_class_install_property (gobject_class,
1009 g_param_spec_object ("window",
1011 P_("The widget's window if it is realized"),
1013 GTK_PARAM_READABLE));
1016 * GtkWidget:double-buffered
1018 * Whether the widget is double buffered.
1022 g_object_class_install_property (gobject_class,
1023 PROP_DOUBLE_BUFFERED,
1024 g_param_spec_boolean ("double-buffered",
1025 P_("Double Buffered"),
1026 P_("Whether the widget is double buffered"),
1028 GTK_PARAM_READWRITE));
1033 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
1037 g_object_class_install_property (gobject_class,
1039 g_param_spec_enum ("halign",
1040 P_("Horizontal Alignment"),
1041 P_("How to position in extra horizontal space"),
1044 GTK_PARAM_READWRITE));
1049 * How to distribute vertical space if widget gets extra space, see #GtkAlign
1053 g_object_class_install_property (gobject_class,
1055 g_param_spec_enum ("valign",
1056 P_("Vertical Alignment"),
1057 P_("How to position in extra vertical space"),
1060 GTK_PARAM_READWRITE));
1063 * GtkWidget:margin-left
1065 * Margin on left side of widget.
1067 * This property adds margin outside of the widget's normal size
1068 * request, the margin will be added in addition to the size from
1069 * gtk_widget_set_size_request() for example.
1073 g_object_class_install_property (gobject_class,
1075 g_param_spec_int ("margin-left",
1076 P_("Margin on Left"),
1077 P_("Pixels of extra space on the left side"),
1081 GTK_PARAM_READWRITE));
1084 * GtkWidget:margin-right
1086 * Margin on right side of widget.
1088 * This property adds margin outside of the widget's normal size
1089 * request, the margin will be added in addition to the size from
1090 * gtk_widget_set_size_request() for example.
1094 g_object_class_install_property (gobject_class,
1096 g_param_spec_int ("margin-right",
1097 P_("Margin on Right"),
1098 P_("Pixels of extra space on the right side"),
1102 GTK_PARAM_READWRITE));
1105 * GtkWidget:margin-top
1107 * Margin on top side of widget.
1109 * This property adds margin outside of the widget's normal size
1110 * request, the margin will be added in addition to the size from
1111 * gtk_widget_set_size_request() for example.
1115 g_object_class_install_property (gobject_class,
1117 g_param_spec_int ("margin-top",
1118 P_("Margin on Top"),
1119 P_("Pixels of extra space on the top side"),
1123 GTK_PARAM_READWRITE));
1126 * GtkWidget:margin-bottom
1128 * Margin on bottom side of widget.
1130 * This property adds margin outside of the widget's normal size
1131 * request, the margin will be added in addition to the size from
1132 * gtk_widget_set_size_request() for example.
1136 g_object_class_install_property (gobject_class,
1138 g_param_spec_int ("margin-bottom",
1139 P_("Margin on Bottom"),
1140 P_("Pixels of extra space on the bottom side"),
1144 GTK_PARAM_READWRITE));
1149 * Sets all four sides' margin at once. If read, returns max
1150 * margin on any side.
1154 g_object_class_install_property (gobject_class,
1156 g_param_spec_int ("margin",
1158 P_("Pixels of extra space on all four sides"),
1162 GTK_PARAM_READWRITE));
1165 * GtkWidget::destroy:
1166 * @object: the object which received the signal
1168 * Signals that all holders of a reference to the widget should release
1169 * the reference that they hold. May result in finalization of the widget
1170 * if all references are released.
1172 widget_signals[DESTROY] =
1173 g_signal_new (I_("destroy"),
1174 G_TYPE_FROM_CLASS (gobject_class),
1175 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
1176 G_STRUCT_OFFSET (GtkWidgetClass, destroy),
1178 _gtk_marshal_VOID__VOID,
1183 * @widget: the object which received the signal.
1185 widget_signals[SHOW] =
1186 g_signal_new (I_("show"),
1187 G_TYPE_FROM_CLASS (gobject_class),
1189 G_STRUCT_OFFSET (GtkWidgetClass, show),
1191 _gtk_marshal_VOID__VOID,
1196 * @widget: the object which received the signal.
1198 widget_signals[HIDE] =
1199 g_signal_new (I_("hide"),
1200 G_TYPE_FROM_CLASS (gobject_class),
1202 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1204 _gtk_marshal_VOID__VOID,
1209 * @widget: the object which received the signal.
1211 widget_signals[MAP] =
1212 g_signal_new (I_("map"),
1213 G_TYPE_FROM_CLASS (gobject_class),
1215 G_STRUCT_OFFSET (GtkWidgetClass, map),
1217 _gtk_marshal_VOID__VOID,
1222 * @widget: the object which received the signal.
1224 widget_signals[UNMAP] =
1225 g_signal_new (I_("unmap"),
1226 G_TYPE_FROM_CLASS (gobject_class),
1228 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1230 _gtk_marshal_VOID__VOID,
1234 * GtkWidget::realize:
1235 * @widget: the object which received the signal.
1237 widget_signals[REALIZE] =
1238 g_signal_new (I_("realize"),
1239 G_TYPE_FROM_CLASS (gobject_class),
1241 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1243 _gtk_marshal_VOID__VOID,
1247 * GtkWidget::unrealize:
1248 * @widget: the object which received the signal.
1250 widget_signals[UNREALIZE] =
1251 g_signal_new (I_("unrealize"),
1252 G_TYPE_FROM_CLASS (gobject_class),
1254 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1256 _gtk_marshal_VOID__VOID,
1260 * GtkWidget::size-request:
1261 * @widget: the object which received the signal.
1264 widget_signals[SIZE_REQUEST] =
1265 g_signal_new (I_("size-request"),
1266 G_TYPE_FROM_CLASS (gobject_class),
1268 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1270 _gtk_marshal_VOID__BOXED,
1272 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1275 * GtkWidget::size-allocate:
1276 * @widget: the object which received the signal.
1279 widget_signals[SIZE_ALLOCATE] =
1280 g_signal_new (I_("size-allocate"),
1281 G_TYPE_FROM_CLASS (gobject_class),
1283 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1285 _gtk_marshal_VOID__BOXED,
1287 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1290 * GtkWidget::state-changed:
1291 * @widget: the object which received the signal.
1292 * @state: the previous state
1294 * The ::state-changed signal is emitted when the widget state changes.
1295 * See gtk_widget_get_state().
1297 widget_signals[STATE_CHANGED] =
1298 g_signal_new (I_("state-changed"),
1299 G_TYPE_FROM_CLASS (gobject_class),
1301 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1303 _gtk_marshal_VOID__ENUM,
1305 GTK_TYPE_STATE_TYPE);
1308 * GtkWidget::parent-set:
1309 * @widget: the object on which the signal is emitted
1310 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1311 * just got its initial parent.
1313 * The ::parent-set signal is emitted when a new parent
1314 * has been set on a widget.
1316 widget_signals[PARENT_SET] =
1317 g_signal_new (I_("parent-set"),
1318 G_TYPE_FROM_CLASS (gobject_class),
1320 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1322 _gtk_marshal_VOID__OBJECT,
1327 * GtkWidget::hierarchy-changed:
1328 * @widget: the object on which the signal is emitted
1329 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1330 * if the widget was previously unanchored
1332 * The ::hierarchy-changed signal is emitted when the
1333 * anchored state of a widget changes. A widget is
1334 * <firstterm>anchored</firstterm> when its toplevel
1335 * ancestor is a #GtkWindow. This signal is emitted when
1336 * a widget changes from un-anchored to anchored or vice-versa.
1338 widget_signals[HIERARCHY_CHANGED] =
1339 g_signal_new (I_("hierarchy-changed"),
1340 G_TYPE_FROM_CLASS (gobject_class),
1342 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1344 _gtk_marshal_VOID__OBJECT,
1349 * GtkWidget::style-set:
1350 * @widget: the object on which the signal is emitted
1351 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1352 * just got its initial style
1354 * The ::style-set signal is emitted when a new style has been set
1355 * on a widget. Note that style-modifying functions like
1356 * gtk_widget_modify_base() also cause this signal to be emitted.
1358 widget_signals[STYLE_SET] =
1359 g_signal_new (I_("style-set"),
1360 G_TYPE_FROM_CLASS (gobject_class),
1362 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1364 _gtk_marshal_VOID__OBJECT,
1369 * GtkWidget::direction-changed:
1370 * @widget: the object on which the signal is emitted
1371 * @previous_direction: the previous text direction of @widget
1373 * The ::direction-changed signal is emitted when the text direction
1374 * of a widget changes.
1376 widget_signals[DIRECTION_CHANGED] =
1377 g_signal_new (I_("direction-changed"),
1378 G_TYPE_FROM_CLASS (gobject_class),
1380 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1382 _gtk_marshal_VOID__ENUM,
1384 GTK_TYPE_TEXT_DIRECTION);
1387 * GtkWidget::grab-notify:
1388 * @widget: the object which received the signal
1389 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1390 * if it becomes unshadowed
1392 * The ::grab-notify signal is emitted when a widget becomes
1393 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1394 * another widget, or when it becomes unshadowed due to a grab
1397 * A widget is shadowed by a gtk_grab_add() when the topmost
1398 * grab widget in the grab stack of its window group is not
1401 widget_signals[GRAB_NOTIFY] =
1402 g_signal_new (I_("grab-notify"),
1403 G_TYPE_FROM_CLASS (gobject_class),
1405 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1407 _gtk_marshal_VOID__BOOLEAN,
1412 * GtkWidget::child-notify:
1413 * @widget: the object which received the signal
1414 * @pspec: the #GParamSpec of the changed child property
1416 * The ::child-notify signal is emitted for each
1417 * <link linkend="child-properties">child property</link> that has
1418 * changed on an object. The signal's detail holds the property name.
1420 widget_signals[CHILD_NOTIFY] =
1421 g_signal_new (I_("child-notify"),
1422 G_TYPE_FROM_CLASS (gobject_class),
1423 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1424 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1426 g_cclosure_marshal_VOID__PARAM,
1432 * @widget: the object which received the signal
1433 * @cr: the cairo context to draw to
1435 * This signal is emitted when a widget is supposed to render itself.
1436 * The @widget's top left corner must be painted at the origin of
1437 * the passed in context and be sized to the values returned by
1438 * gtk_widget_get_allocated_width() and
1439 * gtk_widget_get_allocated_height().
1441 * Signal handlers connected to this signal can modify the cairo
1442 * context passed as @cr in any way they like and don't need to
1443 * restore it. The signal emission takes care of calling cairo_save()
1444 * before and cairo_restore() after invoking the handler.
1446 widget_signals[DRAW] =
1447 g_signal_new (I_("draw"),
1448 G_TYPE_FROM_CLASS (gobject_class),
1450 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1451 _gtk_boolean_handled_accumulator, NULL,
1452 gtk_widget_draw_marshaller,
1454 CAIRO_GOBJECT_TYPE_CONTEXT);
1457 * GtkWidget::mnemonic-activate:
1458 * @widget: the object which received the signal.
1461 widget_signals[MNEMONIC_ACTIVATE] =
1462 g_signal_new (I_("mnemonic-activate"),
1463 G_TYPE_FROM_CLASS (gobject_class),
1465 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1466 _gtk_boolean_handled_accumulator, NULL,
1467 _gtk_marshal_BOOLEAN__BOOLEAN,
1472 * GtkWidget::grab-focus:
1473 * @widget: the object which received the signal.
1475 widget_signals[GRAB_FOCUS] =
1476 g_signal_new (I_("grab-focus"),
1477 G_TYPE_FROM_CLASS (gobject_class),
1478 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1479 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1481 _gtk_marshal_VOID__VOID,
1486 * @widget: the object which received the signal.
1489 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1491 widget_signals[FOCUS] =
1492 g_signal_new (I_("focus"),
1493 G_TYPE_FROM_CLASS (klass),
1495 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1496 _gtk_boolean_handled_accumulator, NULL,
1497 _gtk_marshal_BOOLEAN__ENUM,
1499 GTK_TYPE_DIRECTION_TYPE);
1502 * GtkWidget::move-focus:
1503 * @widget: the object which received the signal.
1506 widget_signals[MOVE_FOCUS] =
1507 g_signal_new_class_handler (I_("move-focus"),
1508 G_TYPE_FROM_CLASS (klass),
1509 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1510 G_CALLBACK (gtk_widget_real_move_focus),
1512 _gtk_marshal_VOID__ENUM,
1515 GTK_TYPE_DIRECTION_TYPE);
1519 * @widget: the object which received the signal.
1520 * @event: the #GdkEvent which triggered this signal
1522 * The GTK+ main loop will emit three signals for each GDK event delivered
1523 * to a widget: one generic ::event signal, another, more specific,
1524 * signal that matches the type of event delivered (e.g.
1525 * #GtkWidget::key-press-event) and finally a generic
1526 * #GtkWidget::event-after signal.
1528 * Returns: %TRUE to stop other handlers from being invoked for the event
1529 * and to cancel the emission of the second specific ::event signal.
1530 * %FALSE to propagate the event further and to allow the emission of
1531 * the second signal. The ::event-after signal is emitted regardless of
1534 widget_signals[EVENT] =
1535 g_signal_new (I_("event"),
1536 G_TYPE_FROM_CLASS (klass),
1538 G_STRUCT_OFFSET (GtkWidgetClass, event),
1539 _gtk_boolean_handled_accumulator, NULL,
1540 _gtk_marshal_BOOLEAN__BOXED,
1542 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1545 * GtkWidget::event-after:
1546 * @widget: the object which received the signal.
1547 * @event: the #GdkEvent which triggered this signal
1549 * After the emission of the #GtkWidget::event signal and (optionally)
1550 * the second more specific signal, ::event-after will be emitted
1551 * regardless of the previous two signals handlers return values.
1554 widget_signals[EVENT_AFTER] =
1555 g_signal_new (I_("event-after"),
1556 G_TYPE_FROM_CLASS (klass),
1560 _gtk_marshal_VOID__BOXED,
1562 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1565 * GtkWidget::button-press-event:
1566 * @widget: the object which received the signal.
1567 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1570 * The ::button-press-event signal will be emitted when a button
1571 * (typically from a mouse) is pressed.
1573 * To receive this signal, the #GdkWindow associated to the
1574 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1576 * This signal will be sent to the grab widget if there is one.
1578 * Returns: %TRUE to stop other handlers from being invoked for the event.
1579 * %FALSE to propagate the event further.
1581 widget_signals[BUTTON_PRESS_EVENT] =
1582 g_signal_new (I_("button-press-event"),
1583 G_TYPE_FROM_CLASS (klass),
1585 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1586 _gtk_boolean_handled_accumulator, NULL,
1587 _gtk_marshal_BOOLEAN__BOXED,
1589 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1592 * GtkWidget::button-release-event:
1593 * @widget: the object which received the signal.
1594 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1597 * The ::button-release-event signal will be emitted when a button
1598 * (typically from a mouse) is released.
1600 * To receive this signal, the #GdkWindow associated to the
1601 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1603 * This signal will be sent to the grab widget if there is one.
1605 * Returns: %TRUE to stop other handlers from being invoked for the event.
1606 * %FALSE to propagate the event further.
1608 widget_signals[BUTTON_RELEASE_EVENT] =
1609 g_signal_new (I_("button-release-event"),
1610 G_TYPE_FROM_CLASS (klass),
1612 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1613 _gtk_boolean_handled_accumulator, NULL,
1614 _gtk_marshal_BOOLEAN__BOXED,
1616 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1619 * GtkWidget::scroll-event:
1620 * @widget: the object which received the signal.
1621 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1624 * The ::scroll-event signal is emitted when a button in the 4 to 7
1625 * range is pressed. Wheel mice are usually configured to generate
1626 * button press events for buttons 4 and 5 when the wheel is turned.
1628 * To receive this signal, the #GdkWindow associated to the widget needs
1629 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1631 * This signal will be sent to the grab widget if there is one.
1633 * Returns: %TRUE to stop other handlers from being invoked for the event.
1634 * %FALSE to propagate the event further.
1636 widget_signals[SCROLL_EVENT] =
1637 g_signal_new (I_("scroll-event"),
1638 G_TYPE_FROM_CLASS (klass),
1640 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1641 _gtk_boolean_handled_accumulator, NULL,
1642 _gtk_marshal_BOOLEAN__BOXED,
1644 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1647 * GtkWidget::motion-notify-event:
1648 * @widget: the object which received the signal.
1649 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1652 * The ::motion-notify-event signal is emitted when the pointer moves
1653 * over the widget's #GdkWindow.
1655 * To receive this signal, the #GdkWindow associated to the widget
1656 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1658 * This signal will be sent to the grab widget if there is one.
1660 * Returns: %TRUE to stop other handlers from being invoked for the event.
1661 * %FALSE to propagate the event further.
1663 widget_signals[MOTION_NOTIFY_EVENT] =
1664 g_signal_new (I_("motion-notify-event"),
1665 G_TYPE_FROM_CLASS (klass),
1667 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1668 _gtk_boolean_handled_accumulator, NULL,
1669 _gtk_marshal_BOOLEAN__BOXED,
1671 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1674 * GtkWidget::composited-changed:
1675 * @widget: the object on which the signal is emitted
1677 * The ::composited-changed signal is emitted when the composited
1678 * status of @widget<!-- -->s screen changes.
1679 * See gdk_screen_is_composited().
1681 widget_signals[COMPOSITED_CHANGED] =
1682 g_signal_new (I_("composited-changed"),
1683 G_TYPE_FROM_CLASS (klass),
1684 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1685 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1687 _gtk_marshal_VOID__VOID,
1691 * GtkWidget::keynav-failed:
1692 * @widget: the object which received the signal
1693 * @direction: the direction of movement
1695 * Gets emitted if keyboard navigation fails.
1696 * See gtk_widget_keynav_failed() for details.
1698 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1699 * if the emitting widget should try to handle the keyboard
1700 * navigation attempt in its parent container(s).
1704 widget_signals[KEYNAV_FAILED] =
1705 g_signal_new_class_handler (I_("keynav-failed"),
1706 G_TYPE_FROM_CLASS (klass),
1708 G_CALLBACK (gtk_widget_real_keynav_failed),
1709 _gtk_boolean_handled_accumulator, NULL,
1710 _gtk_marshal_BOOLEAN__ENUM,
1712 GTK_TYPE_DIRECTION_TYPE);
1715 * GtkWidget::delete-event:
1716 * @widget: the object which received the signal
1717 * @event: the event which triggered this signal
1719 * The ::delete-event signal is emitted if a user requests that
1720 * a toplevel window is closed. The default handler for this signal
1721 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1722 * this signal will cause the window to be hidden instead, so that
1723 * it can later be shown again without reconstructing it.
1725 * Returns: %TRUE to stop other handlers from being invoked for the event.
1726 * %FALSE to propagate the event further.
1728 widget_signals[DELETE_EVENT] =
1729 g_signal_new (I_("delete-event"),
1730 G_TYPE_FROM_CLASS (klass),
1732 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1733 _gtk_boolean_handled_accumulator, NULL,
1734 _gtk_marshal_BOOLEAN__BOXED,
1736 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1739 * GtkWidget::destroy-event:
1740 * @widget: the object which received the signal.
1741 * @event: the event which triggered this signal
1743 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1744 * You rarely get this signal, because most widgets disconnect themselves
1745 * from their window before they destroy it, so no widget owns the
1746 * window at destroy time.
1748 * To receive this signal, the #GdkWindow associated to the widget needs
1749 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1750 * automatically for all new windows.
1752 * Returns: %TRUE to stop other handlers from being invoked for the event.
1753 * %FALSE to propagate the event further.
1755 widget_signals[DESTROY_EVENT] =
1756 g_signal_new (I_("destroy-event"),
1757 G_TYPE_FROM_CLASS (klass),
1759 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1760 _gtk_boolean_handled_accumulator, NULL,
1761 _gtk_marshal_BOOLEAN__BOXED,
1763 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1766 * GtkWidget::key-press-event:
1767 * @widget: the object which received the signal
1768 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1770 * The ::key-press-event signal is emitted when a key is pressed.
1772 * To receive this signal, the #GdkWindow associated to the widget needs
1773 * to enable the #GDK_KEY_PRESS_MASK mask.
1775 * This signal will be sent to the grab widget if there is one.
1777 * Returns: %TRUE to stop other handlers from being invoked for the event.
1778 * %FALSE to propagate the event further.
1780 widget_signals[KEY_PRESS_EVENT] =
1781 g_signal_new (I_("key-press-event"),
1782 G_TYPE_FROM_CLASS (klass),
1784 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1785 _gtk_boolean_handled_accumulator, NULL,
1786 _gtk_marshal_BOOLEAN__BOXED,
1788 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1791 * GtkWidget::key-release-event:
1792 * @widget: the object which received the signal
1793 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1795 * The ::key-release-event signal is emitted when a key is pressed.
1797 * To receive this signal, the #GdkWindow associated to the widget needs
1798 * to enable the #GDK_KEY_RELEASE_MASK mask.
1800 * This signal will be sent to the grab widget if there is one.
1802 * Returns: %TRUE to stop other handlers from being invoked for the event.
1803 * %FALSE to propagate the event further.
1805 widget_signals[KEY_RELEASE_EVENT] =
1806 g_signal_new (I_("key-release-event"),
1807 G_TYPE_FROM_CLASS (klass),
1809 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1810 _gtk_boolean_handled_accumulator, NULL,
1811 _gtk_marshal_BOOLEAN__BOXED,
1813 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1816 * GtkWidget::enter-notify-event:
1817 * @widget: the object which received the signal
1818 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1821 * The ::enter-notify-event will be emitted when the pointer enters
1822 * the @widget's window.
1824 * To receive this signal, the #GdkWindow associated to the widget needs
1825 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1827 * This signal will be sent to the grab widget if there is one.
1829 * Returns: %TRUE to stop other handlers from being invoked for the event.
1830 * %FALSE to propagate the event further.
1832 widget_signals[ENTER_NOTIFY_EVENT] =
1833 g_signal_new (I_("enter-notify-event"),
1834 G_TYPE_FROM_CLASS (klass),
1836 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1837 _gtk_boolean_handled_accumulator, NULL,
1838 _gtk_marshal_BOOLEAN__BOXED,
1840 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1843 * GtkWidget::leave-notify-event:
1844 * @widget: the object which received the signal
1845 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1848 * The ::leave-notify-event will be emitted when the pointer leaves
1849 * the @widget's window.
1851 * To receive this signal, the #GdkWindow associated to the widget needs
1852 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1854 * This signal will be sent to the grab widget if there is one.
1856 * Returns: %TRUE to stop other handlers from being invoked for the event.
1857 * %FALSE to propagate the event further.
1859 widget_signals[LEAVE_NOTIFY_EVENT] =
1860 g_signal_new (I_("leave-notify-event"),
1861 G_TYPE_FROM_CLASS (klass),
1863 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1864 _gtk_boolean_handled_accumulator, NULL,
1865 _gtk_marshal_BOOLEAN__BOXED,
1867 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1870 * GtkWidget::configure-event:
1871 * @widget: the object which received the signal
1872 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1875 * The ::configure-event signal will be emitted when the size, position or
1876 * stacking of the @widget's window has changed.
1878 * To receive this signal, the #GdkWindow associated to the widget needs
1879 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1880 * automatically for all new windows.
1882 * Returns: %TRUE to stop other handlers from being invoked for the event.
1883 * %FALSE to propagate the event further.
1885 widget_signals[CONFIGURE_EVENT] =
1886 g_signal_new (I_("configure-event"),
1887 G_TYPE_FROM_CLASS (klass),
1889 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1890 _gtk_boolean_handled_accumulator, NULL,
1891 _gtk_marshal_BOOLEAN__BOXED,
1893 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1896 * GtkWidget::focus-in-event:
1897 * @widget: the object which received the signal
1898 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1901 * The ::focus-in-event signal will be emitted when the keyboard focus
1902 * enters the @widget's window.
1904 * To receive this signal, the #GdkWindow associated to the widget needs
1905 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1907 * Returns: %TRUE to stop other handlers from being invoked for the event.
1908 * %FALSE to propagate the event further.
1910 widget_signals[FOCUS_IN_EVENT] =
1911 g_signal_new (I_("focus-in-event"),
1912 G_TYPE_FROM_CLASS (klass),
1914 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1915 _gtk_boolean_handled_accumulator, NULL,
1916 _gtk_marshal_BOOLEAN__BOXED,
1918 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1921 * GtkWidget::focus-out-event:
1922 * @widget: the object which received the signal
1923 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1926 * The ::focus-out-event signal will be emitted when the keyboard focus
1927 * leaves the @widget's window.
1929 * To receive this signal, the #GdkWindow associated to the widget needs
1930 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1932 * Returns: %TRUE to stop other handlers from being invoked for the event.
1933 * %FALSE to propagate the event further.
1935 widget_signals[FOCUS_OUT_EVENT] =
1936 g_signal_new (I_("focus-out-event"),
1937 G_TYPE_FROM_CLASS (klass),
1939 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1940 _gtk_boolean_handled_accumulator, NULL,
1941 _gtk_marshal_BOOLEAN__BOXED,
1943 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1946 * GtkWidget::map-event:
1947 * @widget: the object which received the signal
1948 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1950 * The ::map-event signal will be emitted when the @widget's window is
1951 * mapped. A window is mapped when it becomes visible on the screen.
1953 * To receive this signal, the #GdkWindow associated to the widget needs
1954 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1955 * automatically for all new windows.
1957 * Returns: %TRUE to stop other handlers from being invoked for the event.
1958 * %FALSE to propagate the event further.
1960 widget_signals[MAP_EVENT] =
1961 g_signal_new (I_("map-event"),
1962 G_TYPE_FROM_CLASS (klass),
1964 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1965 _gtk_boolean_handled_accumulator, NULL,
1966 _gtk_marshal_BOOLEAN__BOXED,
1968 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1971 * GtkWidget::unmap-event:
1972 * @widget: the object which received the signal
1973 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1975 * The ::unmap-event signal may be emitted when the @widget's window is
1976 * unmapped. A window is unmapped when it becomes invisible on the screen.
1978 * For performance reasons GTK+ may not emit ::unmap-event, so one
1979 * should always also implement ::unrealize in order to release
1980 * resources and disconnect signal handlers.
1982 * To receive this signal, the #GdkWindow associated to the widget needs
1983 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1984 * automatically for all new windows.
1986 * Returns: %TRUE to stop other handlers from being invoked for the event.
1987 * %FALSE to propagate the event further.
1989 widget_signals[UNMAP_EVENT] =
1990 g_signal_new (I_("unmap-event"),
1991 G_TYPE_FROM_CLASS (klass),
1993 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1994 _gtk_boolean_handled_accumulator, NULL,
1995 _gtk_marshal_BOOLEAN__BOXED,
1997 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2000 * GtkWidget::property-notify-event:
2001 * @widget: the object which received the signal
2002 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
2005 * The ::property-notify-event signal will be emitted when a property on
2006 * the @widget's window has been changed or deleted.
2008 * To receive this signal, the #GdkWindow associated to the widget needs
2009 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
2011 * Returns: %TRUE to stop other handlers from being invoked for the event.
2012 * %FALSE to propagate the event further.
2014 widget_signals[PROPERTY_NOTIFY_EVENT] =
2015 g_signal_new (I_("property-notify-event"),
2016 G_TYPE_FROM_CLASS (klass),
2018 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
2019 _gtk_boolean_handled_accumulator, NULL,
2020 _gtk_marshal_BOOLEAN__BOXED,
2022 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2025 * GtkWidget::selection-clear-event:
2026 * @widget: the object which received the signal
2027 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2030 * The ::selection-clear-event signal will be emitted when the
2031 * the @widget's window has lost ownership of a selection.
2033 * Returns: %TRUE to stop other handlers from being invoked for the event.
2034 * %FALSE to propagate the event further.
2036 widget_signals[SELECTION_CLEAR_EVENT] =
2037 g_signal_new (I_("selection-clear-event"),
2038 G_TYPE_FROM_CLASS (klass),
2040 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
2041 _gtk_boolean_handled_accumulator, NULL,
2042 _gtk_marshal_BOOLEAN__BOXED,
2044 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2047 * GtkWidget::selection-request-event:
2048 * @widget: the object which received the signal
2049 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
2052 * The ::selection-request-event signal will be emitted when
2053 * another client requests ownership of the selection owned by
2054 * the @widget's window.
2056 * Returns: %TRUE to stop other handlers from being invoked for the event.
2057 * %FALSE to propagate the event further.
2059 widget_signals[SELECTION_REQUEST_EVENT] =
2060 g_signal_new (I_("selection-request-event"),
2061 G_TYPE_FROM_CLASS (klass),
2063 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
2064 _gtk_boolean_handled_accumulator, NULL,
2065 _gtk_marshal_BOOLEAN__BOXED,
2067 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2070 * GtkWidget::selection-notify-event:
2071 * @widget: the object which received the signal.
2074 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
2076 widget_signals[SELECTION_NOTIFY_EVENT] =
2077 g_signal_new (I_("selection-notify-event"),
2078 G_TYPE_FROM_CLASS (klass),
2080 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
2081 _gtk_boolean_handled_accumulator, NULL,
2082 _gtk_marshal_BOOLEAN__BOXED,
2084 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2087 * GtkWidget::selection-received:
2088 * @widget: the object which received the signal.
2092 widget_signals[SELECTION_RECEIVED] =
2093 g_signal_new (I_("selection-received"),
2094 G_TYPE_FROM_CLASS (klass),
2096 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
2098 _gtk_marshal_VOID__BOXED_UINT,
2100 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2104 * GtkWidget::selection-get:
2105 * @widget: the object which received the signal.
2110 widget_signals[SELECTION_GET] =
2111 g_signal_new (I_("selection-get"),
2112 G_TYPE_FROM_CLASS (klass),
2114 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
2116 _gtk_marshal_VOID__BOXED_UINT_UINT,
2118 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2123 * GtkWidget::proximity-in-event:
2124 * @widget: the object which received the signal
2125 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2128 * To receive this signal the #GdkWindow associated to the widget needs
2129 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2131 * This signal will be sent to the grab widget if there is one.
2133 * Returns: %TRUE to stop other handlers from being invoked for the event.
2134 * %FALSE to propagate the event further.
2136 widget_signals[PROXIMITY_IN_EVENT] =
2137 g_signal_new (I_("proximity-in-event"),
2138 G_TYPE_FROM_CLASS (klass),
2140 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2141 _gtk_boolean_handled_accumulator, NULL,
2142 _gtk_marshal_BOOLEAN__BOXED,
2144 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2147 * GtkWidget::proximity-out-event:
2148 * @widget: the object which received the signal
2149 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2152 * To receive this signal the #GdkWindow associated to the widget needs
2153 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2155 * This signal will be sent to the grab widget if there is one.
2157 * Returns: %TRUE to stop other handlers from being invoked for the event.
2158 * %FALSE to propagate the event further.
2160 widget_signals[PROXIMITY_OUT_EVENT] =
2161 g_signal_new (I_("proximity-out-event"),
2162 G_TYPE_FROM_CLASS (klass),
2164 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2165 _gtk_boolean_handled_accumulator, NULL,
2166 _gtk_marshal_BOOLEAN__BOXED,
2168 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2171 * GtkWidget::drag-leave:
2172 * @widget: the object which received the signal.
2173 * @drag_context: the drag context
2174 * @time: the timestamp of the motion event
2176 * The ::drag-leave signal is emitted on the drop site when the cursor
2177 * leaves the widget. A typical reason to connect to this signal is to
2178 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2179 * with gtk_drag_unhighlight()
2181 widget_signals[DRAG_LEAVE] =
2182 g_signal_new (I_("drag-leave"),
2183 G_TYPE_FROM_CLASS (klass),
2185 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2187 _gtk_marshal_VOID__OBJECT_UINT,
2189 GDK_TYPE_DRAG_CONTEXT,
2193 * GtkWidget::drag-begin:
2194 * @widget: the object which received the signal
2195 * @drag_context: the drag context
2197 * The ::drag-begin signal is emitted on the drag source when a drag is
2198 * started. A typical reason to connect to this signal is to set up a
2199 * custom drag icon with gtk_drag_source_set_icon().
2201 * Note that some widgets set up a drag icon in the default handler of
2202 * this signal, so you may have to use g_signal_connect_after() to
2203 * override what the default handler did.
2205 widget_signals[DRAG_BEGIN] =
2206 g_signal_new (I_("drag-begin"),
2207 G_TYPE_FROM_CLASS (klass),
2209 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2211 _gtk_marshal_VOID__OBJECT,
2213 GDK_TYPE_DRAG_CONTEXT);
2216 * GtkWidget::drag-end:
2217 * @widget: the object which received the signal
2218 * @drag_context: the drag context
2220 * The ::drag-end signal is emitted on the drag source when a drag is
2221 * finished. A typical reason to connect to this signal is to undo
2222 * things done in #GtkWidget::drag-begin.
2224 widget_signals[DRAG_END] =
2225 g_signal_new (I_("drag-end"),
2226 G_TYPE_FROM_CLASS (klass),
2228 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2230 _gtk_marshal_VOID__OBJECT,
2232 GDK_TYPE_DRAG_CONTEXT);
2235 * GtkWidget::drag-data-delete:
2236 * @widget: the object which received the signal
2237 * @drag_context: the drag context
2239 * The ::drag-data-delete signal is emitted on the drag source when a drag
2240 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2241 * handler is responsible for deleting the data that has been dropped. What
2242 * "delete" means depends on the context of the drag operation.
2244 widget_signals[DRAG_DATA_DELETE] =
2245 g_signal_new (I_("drag-data-delete"),
2246 G_TYPE_FROM_CLASS (klass),
2248 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2250 _gtk_marshal_VOID__OBJECT,
2252 GDK_TYPE_DRAG_CONTEXT);
2255 * GtkWidget::drag-failed:
2256 * @widget: the object which received the signal
2257 * @drag_context: the drag context
2258 * @result: the result of the drag operation
2260 * The ::drag-failed signal is emitted on the drag source when a drag has
2261 * failed. The signal handler may hook custom code to handle a failed DND
2262 * operation based on the type of error, it returns %TRUE is the failure has
2263 * been already handled (not showing the default "drag operation failed"
2264 * animation), otherwise it returns %FALSE.
2266 * Return value: %TRUE if the failed drag operation has been already handled.
2270 widget_signals[DRAG_FAILED] =
2271 g_signal_new (I_("drag-failed"),
2272 G_TYPE_FROM_CLASS (klass),
2274 0, _gtk_boolean_handled_accumulator, NULL,
2275 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2277 GDK_TYPE_DRAG_CONTEXT,
2278 GTK_TYPE_DRAG_RESULT);
2281 * GtkWidget::drag-motion:
2282 * @widget: the object which received the signal
2283 * @drag_context: the drag context
2284 * @x: the x coordinate of the current cursor position
2285 * @y: the y coordinate of the current cursor position
2286 * @time: the timestamp of the motion event
2287 * @returns: whether the cursor position is in a drop zone
2289 * The drag-motion signal is emitted on the drop site when the user
2290 * moves the cursor over the widget during a drag. The signal handler
2291 * must determine whether the cursor position is in a drop zone or not.
2292 * If it is not in a drop zone, it returns %FALSE and no further processing
2293 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2294 * handler is responsible for providing the necessary information for
2295 * displaying feedback to the user, by calling gdk_drag_status().
2297 * If the decision whether the drop will be accepted or rejected can't be
2298 * made based solely on the cursor position and the type of the data, the
2299 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2300 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2301 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2302 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2303 * when using the drag-motion signal that way.
2305 * Also note that there is no drag-enter signal. The drag receiver has to
2306 * keep track of whether he has received any drag-motion signals since the
2307 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2308 * an "enter" signal. Upon an "enter", the handler will typically highlight
2309 * the drop site with gtk_drag_highlight().
2312 * drag_motion (GtkWidget *widget,
2313 * GdkDragContext *context,
2320 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2322 * if (!private_data->drag_highlight)
2324 * private_data->drag_highlight = 1;
2325 * gtk_drag_highlight (widget);
2328 * target = gtk_drag_dest_find_target (widget, context, NULL);
2329 * if (target == GDK_NONE)
2330 * gdk_drag_status (context, 0, time);
2333 * private_data->pending_status = context->suggested_action;
2334 * gtk_drag_get_data (widget, context, target, time);
2341 * drag_data_received (GtkWidget *widget,
2342 * GdkDragContext *context,
2345 * GtkSelectionData *selection_data,
2349 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2351 * if (private_data->suggested_action)
2353 * private_data->suggested_action = 0;
2355 * /* We are getting this data due to a request in drag_motion,
2356 * * rather than due to a request in drag_drop, so we are just
2357 * * supposed to call gdk_drag_status (), not actually paste in
2360 * str = gtk_selection_data_get_text (selection_data);
2361 * if (!data_is_acceptable (str))
2362 * gdk_drag_status (context, 0, time);
2364 * gdk_drag_status (context, private_data->suggested_action, time);
2368 * /* accept the drop */
2373 widget_signals[DRAG_MOTION] =
2374 g_signal_new (I_("drag-motion"),
2375 G_TYPE_FROM_CLASS (klass),
2377 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2378 _gtk_boolean_handled_accumulator, NULL,
2379 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2381 GDK_TYPE_DRAG_CONTEXT,
2387 * GtkWidget::drag-drop:
2388 * @widget: the object which received the signal
2389 * @drag_context: the drag context
2390 * @x: the x coordinate of the current cursor position
2391 * @y: the y coordinate of the current cursor position
2392 * @time: the timestamp of the motion event
2393 * @returns: whether the cursor position is in a drop zone
2395 * The ::drag-drop signal is emitted on the drop site when the user drops
2396 * the data onto the widget. The signal handler must determine whether
2397 * the cursor position is in a drop zone or not. If it is not in a drop
2398 * zone, it returns %FALSE and no further processing is necessary.
2399 * Otherwise, the handler returns %TRUE. In this case, the handler must
2400 * ensure that gtk_drag_finish() is called to let the source know that
2401 * the drop is done. The call to gtk_drag_finish() can be done either
2402 * directly or in a #GtkWidget::drag-data-received handler which gets
2403 * triggered by calling gtk_drag_get_data() to receive the data for one
2404 * or more of the supported targets.
2406 widget_signals[DRAG_DROP] =
2407 g_signal_new (I_("drag-drop"),
2408 G_TYPE_FROM_CLASS (klass),
2410 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2411 _gtk_boolean_handled_accumulator, NULL,
2412 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2414 GDK_TYPE_DRAG_CONTEXT,
2420 * GtkWidget::drag-data-get:
2421 * @widget: the object which received the signal
2422 * @drag_context: the drag context
2423 * @data: the #GtkSelectionData to be filled with the dragged data
2424 * @info: the info that has been registered with the target in the
2426 * @time: the timestamp at which the data was requested
2428 * The ::drag-data-get signal is emitted on the drag source when the drop
2429 * site requests the data which is dragged. It is the responsibility of
2430 * the signal handler to fill @data with the data in the format which
2431 * is indicated by @info. See gtk_selection_data_set() and
2432 * gtk_selection_data_set_text().
2434 widget_signals[DRAG_DATA_GET] =
2435 g_signal_new (I_("drag-data-get"),
2436 G_TYPE_FROM_CLASS (klass),
2438 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2440 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2442 GDK_TYPE_DRAG_CONTEXT,
2443 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2448 * GtkWidget::drag-data-received:
2449 * @widget: the object which received the signal
2450 * @drag_context: the drag context
2451 * @x: where the drop happened
2452 * @y: where the drop happened
2453 * @data: the received data
2454 * @info: the info that has been registered with the target in the
2456 * @time: the timestamp at which the data was received
2458 * The ::drag-data-received signal is emitted on the drop site when the
2459 * dragged data has been received. If the data was received in order to
2460 * determine whether the drop will be accepted, the handler is expected
2461 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2462 * If the data was received in response to a #GtkWidget::drag-drop signal
2463 * (and this is the last target to be received), the handler for this
2464 * signal is expected to process the received data and then call
2465 * gtk_drag_finish(), setting the @success parameter depending on whether
2466 * the data was processed successfully.
2468 * The handler may inspect and modify @drag_context->action before calling
2469 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2470 * following example:
2473 * drag_data_received (GtkWidget *widget,
2474 * GdkDragContext *drag_context,
2477 * GtkSelectionData *data,
2481 * if ((data->length >= 0) && (data->format == 8))
2483 * if (drag_context->action == GDK_ACTION_ASK)
2485 * GtkWidget *dialog;
2488 * dialog = gtk_message_dialog_new (NULL,
2489 * GTK_DIALOG_MODAL |
2490 * GTK_DIALOG_DESTROY_WITH_PARENT,
2492 * GTK_BUTTONS_YES_NO,
2493 * "Move the data ?\n");
2494 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2495 * gtk_widget_destroy (dialog);
2497 * if (response == GTK_RESPONSE_YES)
2498 * drag_context->action = GDK_ACTION_MOVE;
2500 * drag_context->action = GDK_ACTION_COPY;
2503 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2507 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2511 widget_signals[DRAG_DATA_RECEIVED] =
2512 g_signal_new (I_("drag-data-received"),
2513 G_TYPE_FROM_CLASS (klass),
2515 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2517 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2519 GDK_TYPE_DRAG_CONTEXT,
2522 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2527 * GtkWidget::visibility-notify-event:
2528 * @widget: the object which received the signal
2529 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2530 * triggered this signal.
2532 * The ::visibility-notify-event will be emitted when the @widget's window
2533 * is obscured or unobscured.
2535 * To receive this signal the #GdkWindow associated to the widget needs
2536 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2538 * Returns: %TRUE to stop other handlers from being invoked for the event.
2539 * %FALSE to propagate the event further.
2541 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2542 g_signal_new (I_("visibility-notify-event"),
2543 G_TYPE_FROM_CLASS (klass),
2545 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2546 _gtk_boolean_handled_accumulator, NULL,
2547 _gtk_marshal_BOOLEAN__BOXED,
2549 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2552 * GtkWidget::client-event:
2553 * @widget: the object which received the signal
2554 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2557 * The ::client-event will be emitted when the @widget's window
2558 * receives a message (via a ClientMessage event) from another
2561 * Returns: %TRUE to stop other handlers from being invoked for
2562 * the event. %FALSE to propagate the event further.
2564 widget_signals[CLIENT_EVENT] =
2565 g_signal_new (I_("client-event"),
2566 G_TYPE_FROM_CLASS (klass),
2568 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2569 _gtk_boolean_handled_accumulator, NULL,
2570 _gtk_marshal_BOOLEAN__BOXED,
2572 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2575 * GtkWidget::no-expose-event:
2576 * @widget: the object which received the signal
2577 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2580 * The ::no-expose-event will be emitted when the @widget's window is
2581 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2582 * If the source window was partially obscured #GdkEventExpose events will
2583 * be generated for those areas.
2585 * Returns: %TRUE to stop other handlers from being invoked for the event.
2586 * %FALSE to propagate the event further.
2588 widget_signals[NO_EXPOSE_EVENT] =
2589 g_signal_new (I_("no-expose-event"),
2590 G_TYPE_FROM_CLASS (klass),
2592 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2593 _gtk_boolean_handled_accumulator, NULL,
2594 _gtk_marshal_BOOLEAN__BOXED,
2596 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2599 * GtkWidget::window-state-event:
2600 * @widget: the object which received the signal
2601 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2602 * triggered this signal.
2604 * The ::window-state-event will be emitted when the state of the
2605 * toplevel window associated to the @widget changes.
2607 * To receive this signal the #GdkWindow associated to the widget
2608 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2609 * this mask automatically for all new windows.
2611 * Returns: %TRUE to stop other handlers from being invoked for the
2612 * event. %FALSE to propagate the event further.
2614 widget_signals[WINDOW_STATE_EVENT] =
2615 g_signal_new (I_("window-state-event"),
2616 G_TYPE_FROM_CLASS (klass),
2618 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2619 _gtk_boolean_handled_accumulator, NULL,
2620 _gtk_marshal_BOOLEAN__BOXED,
2622 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2625 * GtkWidget::damage-event:
2626 * @widget: the object which received the signal
2627 * @event: the #GdkEventExpose event
2629 * Emitted when a redirected window belonging to @widget gets drawn into.
2630 * The region/area members of the event shows what area of the redirected
2631 * drawable was drawn into.
2633 * Returns: %TRUE to stop other handlers from being invoked for the event.
2634 * %FALSE to propagate the event further.
2638 widget_signals[DAMAGE_EVENT] =
2639 g_signal_new (I_("damage-event"),
2640 G_TYPE_FROM_CLASS (klass),
2643 _gtk_boolean_handled_accumulator, NULL,
2644 _gtk_marshal_BOOLEAN__BOXED,
2646 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2649 * GtkWidget::grab-broken-event:
2650 * @widget: the object which received the signal
2651 * @event: the #GdkEventGrabBroken event
2653 * Emitted when a pointer or keyboard grab on a window belonging
2654 * to @widget gets broken.
2656 * On X11, this happens when the grab window becomes unviewable
2657 * (i.e. it or one of its ancestors is unmapped), or if the same
2658 * application grabs the pointer or keyboard again.
2660 * Returns: %TRUE to stop other handlers from being invoked for
2661 * the event. %FALSE to propagate the event further.
2665 widget_signals[GRAB_BROKEN] =
2666 g_signal_new (I_("grab-broken-event"),
2667 G_TYPE_FROM_CLASS (klass),
2669 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2670 _gtk_boolean_handled_accumulator, NULL,
2671 _gtk_marshal_BOOLEAN__BOXED,
2673 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2676 * GtkWidget::query-tooltip:
2677 * @widget: the object which received the signal
2678 * @x: the x coordinate of the cursor position where the request has
2679 * been emitted, relative to @widget->window
2680 * @y: the y coordinate of the cursor position where the request has
2681 * been emitted, relative to @widget->window
2682 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2683 * @tooltip: a #GtkTooltip
2685 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2686 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2687 * focus in keyboard mode.
2689 * Using the given coordinates, the signal handler should determine
2690 * whether a tooltip should be shown for @widget. If this is the case
2691 * %TRUE should be returned, %FALSE otherwise. Note that if
2692 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2693 * should not be used.
2695 * The signal handler is free to manipulate @tooltip with the therefore
2696 * destined function calls.
2698 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2702 widget_signals[QUERY_TOOLTIP] =
2703 g_signal_new (I_("query-tooltip"),
2704 G_TYPE_FROM_CLASS (klass),
2706 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2707 _gtk_boolean_handled_accumulator, NULL,
2708 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2716 * GtkWidget::popup-menu
2717 * @widget: the object which received the signal
2719 * This signal gets emitted whenever a widget should pop up a context
2720 * menu. This usually happens through the standard key binding mechanism;
2721 * by pressing a certain key while a widget is focused, the user can cause
2722 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2723 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2724 * for an example of how to use this signal.
2726 * Returns: %TRUE if a menu was activated
2728 widget_signals[POPUP_MENU] =
2729 g_signal_new (I_("popup-menu"),
2730 G_TYPE_FROM_CLASS (klass),
2731 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2732 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2733 _gtk_boolean_handled_accumulator, NULL,
2734 _gtk_marshal_BOOLEAN__VOID,
2738 * GtkWidget::show-help:
2739 * @widget: the object which received the signal.
2742 widget_signals[SHOW_HELP] =
2743 g_signal_new (I_("show-help"),
2744 G_TYPE_FROM_CLASS (klass),
2745 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2746 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2747 _gtk_boolean_handled_accumulator, NULL,
2748 _gtk_marshal_BOOLEAN__ENUM,
2750 GTK_TYPE_WIDGET_HELP_TYPE);
2753 * GtkWidget::accel-closures-changed:
2754 * @widget: the object which received the signal.
2756 widget_signals[ACCEL_CLOSURES_CHANGED] =
2757 g_signal_new (I_("accel-closures-changed"),
2758 G_TYPE_FROM_CLASS (klass),
2762 _gtk_marshal_VOID__VOID,
2766 * GtkWidget::screen-changed:
2767 * @widget: the object on which the signal is emitted
2768 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2769 * widget was not associated with a screen before
2771 * The ::screen-changed signal gets emitted when the
2772 * screen of a widget has changed.
2774 widget_signals[SCREEN_CHANGED] =
2775 g_signal_new (I_("screen-changed"),
2776 G_TYPE_FROM_CLASS (klass),
2778 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2780 _gtk_marshal_VOID__OBJECT,
2785 * GtkWidget::can-activate-accel:
2786 * @widget: the object which received the signal
2787 * @signal_id: the ID of a signal installed on @widget
2789 * Determines whether an accelerator that activates the signal
2790 * identified by @signal_id can currently be activated.
2791 * This signal is present to allow applications and derived
2792 * widgets to override the default #GtkWidget handling
2793 * for determining whether an accelerator can be activated.
2795 * Returns: %TRUE if the signal can be activated.
2797 widget_signals[CAN_ACTIVATE_ACCEL] =
2798 g_signal_new (I_("can-activate-accel"),
2799 G_TYPE_FROM_CLASS (klass),
2801 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2802 _gtk_boolean_handled_accumulator, NULL,
2803 _gtk_marshal_BOOLEAN__UINT,
2804 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2806 binding_set = gtk_binding_set_by_class (klass);
2807 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2809 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2812 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2814 GTK_TYPE_WIDGET_HELP_TYPE,
2815 GTK_WIDGET_HELP_TOOLTIP);
2816 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2818 GTK_TYPE_WIDGET_HELP_TYPE,
2819 GTK_WIDGET_HELP_TOOLTIP);
2820 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2822 GTK_TYPE_WIDGET_HELP_TYPE,
2823 GTK_WIDGET_HELP_WHATS_THIS);
2824 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2826 GTK_TYPE_WIDGET_HELP_TYPE,
2827 GTK_WIDGET_HELP_WHATS_THIS);
2829 gtk_widget_class_install_style_property (klass,
2830 g_param_spec_boolean ("interior-focus",
2831 P_("Interior Focus"),
2832 P_("Whether to draw the focus indicator inside widgets"),
2834 GTK_PARAM_READABLE));
2836 gtk_widget_class_install_style_property (klass,
2837 g_param_spec_int ("focus-line-width",
2838 P_("Focus linewidth"),
2839 P_("Width, in pixels, of the focus indicator line"),
2841 GTK_PARAM_READABLE));
2843 gtk_widget_class_install_style_property (klass,
2844 g_param_spec_string ("focus-line-pattern",
2845 P_("Focus line dash pattern"),
2846 P_("Dash pattern used to draw the focus indicator"),
2848 GTK_PARAM_READABLE));
2849 gtk_widget_class_install_style_property (klass,
2850 g_param_spec_int ("focus-padding",
2851 P_("Focus padding"),
2852 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2854 GTK_PARAM_READABLE));
2855 gtk_widget_class_install_style_property (klass,
2856 g_param_spec_boxed ("cursor-color",
2858 P_("Color with which to draw insertion cursor"),
2860 GTK_PARAM_READABLE));
2861 gtk_widget_class_install_style_property (klass,
2862 g_param_spec_boxed ("secondary-cursor-color",
2863 P_("Secondary cursor color"),
2864 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2866 GTK_PARAM_READABLE));
2867 gtk_widget_class_install_style_property (klass,
2868 g_param_spec_float ("cursor-aspect-ratio",
2869 P_("Cursor line aspect ratio"),
2870 P_("Aspect ratio with which to draw insertion cursor"),
2872 GTK_PARAM_READABLE));
2874 gtk_widget_class_install_style_property (klass,
2875 g_param_spec_boolean ("window-dragging",
2876 P_("Window dragging"),
2877 P_("Whether windows can be dragged by clicking on empty areas"),
2879 GTK_PARAM_READABLE));
2882 * GtkWidget:link-color:
2884 * The "link-color" style property defines the color of unvisited links.
2888 gtk_widget_class_install_style_property (klass,
2889 g_param_spec_boxed ("link-color",
2890 P_("Unvisited Link Color"),
2891 P_("Color of unvisited links"),
2893 GTK_PARAM_READABLE));
2896 * GtkWidget:visited-link-color:
2898 * The "visited-link-color" style property defines the color of visited links.
2902 gtk_widget_class_install_style_property (klass,
2903 g_param_spec_boxed ("visited-link-color",
2904 P_("Visited Link Color"),
2905 P_("Color of visited links"),
2907 GTK_PARAM_READABLE));
2910 * GtkWidget:wide-separators:
2912 * The "wide-separators" style property defines whether separators have
2913 * configurable width and should be drawn using a box instead of a line.
2917 gtk_widget_class_install_style_property (klass,
2918 g_param_spec_boolean ("wide-separators",
2919 P_("Wide Separators"),
2920 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2922 GTK_PARAM_READABLE));
2925 * GtkWidget:separator-width:
2927 * The "separator-width" style property defines the width of separators.
2928 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2932 gtk_widget_class_install_style_property (klass,
2933 g_param_spec_int ("separator-width",
2934 P_("Separator Width"),
2935 P_("The width of separators if wide-separators is TRUE"),
2937 GTK_PARAM_READABLE));
2940 * GtkWidget:separator-height:
2942 * The "separator-height" style property defines the height of separators.
2943 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2947 gtk_widget_class_install_style_property (klass,
2948 g_param_spec_int ("separator-height",
2949 P_("Separator Height"),
2950 P_("The height of separators if \"wide-separators\" is TRUE"),
2952 GTK_PARAM_READABLE));
2955 * GtkWidget:scroll-arrow-hlength:
2957 * The "scroll-arrow-hlength" style property defines the length of
2958 * horizontal scroll arrows.
2962 gtk_widget_class_install_style_property (klass,
2963 g_param_spec_int ("scroll-arrow-hlength",
2964 P_("Horizontal Scroll Arrow Length"),
2965 P_("The length of horizontal scroll arrows"),
2967 GTK_PARAM_READABLE));
2970 * GtkWidget:scroll-arrow-vlength:
2972 * The "scroll-arrow-vlength" style property defines the length of
2973 * vertical scroll arrows.
2977 gtk_widget_class_install_style_property (klass,
2978 g_param_spec_int ("scroll-arrow-vlength",
2979 P_("Vertical Scroll Arrow Length"),
2980 P_("The length of vertical scroll arrows"),
2982 GTK_PARAM_READABLE));
2984 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2988 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2992 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2993 for (node = list; node; node = node->next)
2995 GParamSpec *pspec = node->data;
2997 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2998 g_param_spec_unref (pspec);
3004 gtk_widget_set_property (GObject *object,
3006 const GValue *value,
3009 GtkWidget *widget = GTK_WIDGET (object);
3014 gchar *tooltip_markup;
3015 const gchar *tooltip_text;
3016 GtkWindow *tooltip_window;
3019 gtk_widget_set_name (widget, g_value_get_string (value));
3022 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
3024 case PROP_WIDTH_REQUEST:
3025 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
3027 case PROP_HEIGHT_REQUEST:
3028 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
3031 gtk_widget_set_visible (widget, g_value_get_boolean (value));
3033 case PROP_SENSITIVE:
3034 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
3036 case PROP_APP_PAINTABLE:
3037 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
3039 case PROP_CAN_FOCUS:
3040 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
3042 case PROP_HAS_FOCUS:
3043 if (g_value_get_boolean (value))
3044 gtk_widget_grab_focus (widget);
3047 if (g_value_get_boolean (value))
3048 gtk_widget_grab_focus (widget);
3050 case PROP_CAN_DEFAULT:
3051 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
3053 case PROP_HAS_DEFAULT:
3054 if (g_value_get_boolean (value))
3055 gtk_widget_grab_default (widget);
3057 case PROP_RECEIVES_DEFAULT:
3058 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
3061 gtk_widget_set_style (widget, g_value_get_object (value));
3064 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
3065 gtk_widget_set_events (widget, g_value_get_flags (value));
3067 case PROP_EXTENSION_EVENTS:
3068 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
3070 case PROP_NO_SHOW_ALL:
3071 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
3073 case PROP_HAS_TOOLTIP:
3074 gtk_widget_real_set_has_tooltip (widget,
3075 g_value_get_boolean (value), FALSE);
3077 case PROP_TOOLTIP_MARKUP:
3078 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3079 tooltip_markup = g_value_dup_string (value);
3081 /* Treat an empty string as a NULL string,
3082 * because an empty string would be useless for a tooltip:
3084 if (tooltip_markup && (strlen (tooltip_markup) == 0))
3086 g_free (tooltip_markup);
3087 tooltip_markup = NULL;
3090 g_object_set_qdata_full (object, quark_tooltip_markup,
3091 tooltip_markup, g_free);
3093 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3094 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3095 if (gtk_widget_get_visible (widget))
3096 gtk_widget_queue_tooltip_query (widget);
3098 case PROP_TOOLTIP_TEXT:
3099 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
3101 tooltip_text = g_value_get_string (value);
3103 /* Treat an empty string as a NULL string,
3104 * because an empty string would be useless for a tooltip:
3106 if (tooltip_text && (strlen (tooltip_text) == 0))
3107 tooltip_text = NULL;
3109 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
3111 g_object_set_qdata_full (object, quark_tooltip_markup,
3112 tooltip_markup, g_free);
3114 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
3115 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
3116 if (gtk_widget_get_visible (widget))
3117 gtk_widget_queue_tooltip_query (widget);
3119 case PROP_DOUBLE_BUFFERED:
3120 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
3123 gtk_widget_set_halign (widget, g_value_get_enum (value));
3126 gtk_widget_set_valign (widget, g_value_get_enum (value));
3128 case PROP_MARGIN_LEFT:
3129 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3131 case PROP_MARGIN_RIGHT:
3132 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3134 case PROP_MARGIN_TOP:
3135 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3137 case PROP_MARGIN_BOTTOM:
3138 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3141 g_object_freeze_notify (G_OBJECT (widget));
3142 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3143 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3144 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3145 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3146 g_object_thaw_notify (G_OBJECT (widget));
3149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3155 gtk_widget_get_property (GObject *object,
3160 GtkWidget *widget = GTK_WIDGET (object);
3161 GtkWidgetPrivate *priv = widget->priv;
3170 g_value_set_string (value, priv->name);
3172 g_value_set_static_string (value, "");
3175 g_value_set_object (value, priv->parent);
3177 case PROP_WIDTH_REQUEST:
3180 gtk_widget_get_size_request (widget, &w, NULL);
3181 g_value_set_int (value, w);
3184 case PROP_HEIGHT_REQUEST:
3187 gtk_widget_get_size_request (widget, NULL, &h);
3188 g_value_set_int (value, h);
3192 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3194 case PROP_SENSITIVE:
3195 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3197 case PROP_APP_PAINTABLE:
3198 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3200 case PROP_CAN_FOCUS:
3201 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3203 case PROP_HAS_FOCUS:
3204 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3207 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3209 case PROP_CAN_DEFAULT:
3210 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3212 case PROP_HAS_DEFAULT:
3213 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3215 case PROP_RECEIVES_DEFAULT:
3216 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3218 case PROP_COMPOSITE_CHILD:
3219 g_value_set_boolean (value, widget->priv->composite_child);
3222 g_value_set_object (value, gtk_widget_get_style (widget));
3225 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3226 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3228 case PROP_EXTENSION_EVENTS:
3229 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3230 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3232 case PROP_NO_SHOW_ALL:
3233 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3235 case PROP_HAS_TOOLTIP:
3236 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3238 case PROP_TOOLTIP_TEXT:
3240 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3243 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3244 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3246 g_value_take_string (value, text);
3249 case PROP_TOOLTIP_MARKUP:
3250 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3253 g_value_set_object (value, gtk_widget_get_window (widget));
3255 case PROP_DOUBLE_BUFFERED:
3256 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3259 g_value_set_enum (value, gtk_widget_get_halign (widget));
3262 g_value_set_enum (value, gtk_widget_get_valign (widget));
3264 case PROP_MARGIN_LEFT:
3265 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3267 case PROP_MARGIN_RIGHT:
3268 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3270 case PROP_MARGIN_TOP:
3271 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3273 case PROP_MARGIN_BOTTOM:
3274 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3278 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3279 if (aux_info == NULL)
3281 g_value_set_int (value, 0);
3285 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3286 aux_info->margin.right),
3287 MAX (aux_info->margin.top,
3288 aux_info->margin.bottom)));
3293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3299 gtk_widget_init (GtkWidget *widget)
3301 GtkWidgetPrivate *priv;
3303 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3306 priv = widget->priv;
3308 priv->child_visible = TRUE;
3309 priv->state = GTK_STATE_NORMAL;
3310 priv->saved_state = GTK_STATE_NORMAL;
3312 priv->allocation.x = -1;
3313 priv->allocation.y = -1;
3314 priv->allocation.width = 1;
3315 priv->allocation.height = 1;
3316 priv->window = NULL;
3317 priv->parent = NULL;
3319 priv->sensitive = TRUE;
3320 priv->parent_sensitive = TRUE;
3321 priv->composite_child = composite_child_stack != 0;
3322 priv->double_buffered = TRUE;
3323 priv->redraw_on_alloc = TRUE;
3324 priv->width_request_needed = TRUE;
3325 priv->height_request_needed = TRUE;
3326 priv->alloc_needed = TRUE;
3328 priv->style = gtk_widget_get_default_style ();
3329 g_object_ref (priv->style);
3334 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3336 GParamSpec **pspecs)
3338 GtkWidgetPrivate *priv = widget->priv;
3339 GtkWidget *container = priv->parent;
3342 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3343 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3347 * gtk_widget_freeze_child_notify:
3348 * @widget: a #GtkWidget
3350 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3351 * signals are queued until gtk_widget_thaw_child_notify() is called
3354 * This is the analogue of g_object_freeze_notify() for child properties.
3357 gtk_widget_freeze_child_notify (GtkWidget *widget)
3359 g_return_if_fail (GTK_IS_WIDGET (widget));
3361 if (!G_OBJECT (widget)->ref_count)
3364 g_object_ref (widget);
3365 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3366 g_object_unref (widget);
3370 * gtk_widget_child_notify:
3371 * @widget: a #GtkWidget
3372 * @child_property: the name of a child property installed on the
3373 * class of @widget<!-- -->'s parent
3375 * Emits a #GtkWidget::child-notify signal for the
3376 * <link linkend="child-properties">child property</link> @child_property
3379 * This is the analogue of g_object_notify() for child properties.
3382 gtk_widget_child_notify (GtkWidget *widget,
3383 const gchar *child_property)
3385 GtkWidgetPrivate *priv = widget->priv;
3388 g_return_if_fail (GTK_IS_WIDGET (widget));
3389 g_return_if_fail (child_property != NULL);
3390 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3393 g_object_ref (widget);
3394 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3396 G_OBJECT_TYPE (priv->parent),
3399 g_warning ("%s: container class `%s' has no child property named `%s'",
3401 G_OBJECT_TYPE_NAME (priv->parent),
3405 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3407 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3408 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3410 g_object_unref (widget);
3414 * gtk_widget_thaw_child_notify:
3415 * @widget: a #GtkWidget
3417 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3418 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3422 gtk_widget_thaw_child_notify (GtkWidget *widget)
3424 GObjectNotifyQueue *nqueue;
3426 g_return_if_fail (GTK_IS_WIDGET (widget));
3428 if (!G_OBJECT (widget)->ref_count)
3431 g_object_ref (widget);
3432 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3433 if (!nqueue || !nqueue->freeze_count)
3434 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3435 G_OBJECT_TYPE_NAME (widget), widget);
3437 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3438 g_object_unref (widget);
3444 * @type: type ID of the widget to create
3445 * @first_property_name: name of first property to set
3446 * @Varargs: value of first property, followed by more properties,
3449 * This is a convenience function for creating a widget and setting
3450 * its properties in one go. For example you might write:
3451 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3452 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3453 * g_object_new(), but returns a widget so you don't have to
3454 * cast the object yourself.
3456 * Return value: a new #GtkWidget of type @widget_type
3459 gtk_widget_new (GType type,
3460 const gchar *first_property_name,
3466 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3468 va_start (var_args, first_property_name);
3469 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3476 gtk_widget_queue_draw_child (GtkWidget *widget)
3478 GtkWidgetPrivate *priv = widget->priv;
3481 parent = priv->parent;
3482 if (parent && gtk_widget_is_drawable (parent))
3483 gtk_widget_queue_draw_area (parent,
3486 priv->allocation.width,
3487 priv->allocation.height);
3491 * gtk_widget_unparent:
3492 * @widget: a #GtkWidget
3494 * This function is only for use in widget implementations.
3495 * Should be called by implementations of the remove method
3496 * on #GtkContainer, to dissociate a child from the container.
3499 gtk_widget_unparent (GtkWidget *widget)
3501 GtkWidgetPrivate *priv;
3502 GObjectNotifyQueue *nqueue;
3503 GtkWidget *toplevel;
3504 GtkWidget *old_parent;
3506 g_return_if_fail (GTK_IS_WIDGET (widget));
3508 priv = widget->priv;
3510 if (priv->parent == NULL)
3513 /* keep this function in sync with gtk_menu_detach()
3516 g_object_freeze_notify (G_OBJECT (widget));
3517 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3519 toplevel = gtk_widget_get_toplevel (widget);
3520 if (gtk_widget_is_toplevel (toplevel))
3521 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3523 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3524 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3526 /* If we are unanchoring the child, we save around the toplevel
3527 * to emit hierarchy changed
3529 if (priv->parent->priv->anchored)
3530 g_object_ref (toplevel);
3534 gtk_widget_queue_draw_child (widget);
3536 /* Reset the width and height here, to force reallocation if we
3537 * get added back to a new parent. This won't work if our new
3538 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3539 * (would 0x0 be OK here?)
3541 priv->allocation.width = 1;
3542 priv->allocation.height = 1;
3544 if (gtk_widget_get_realized (widget))
3546 if (priv->in_reparent)
3547 gtk_widget_unmap (widget);
3549 gtk_widget_unrealize (widget);
3552 /* Removing a widget from a container restores the child visible
3553 * flag to the default state, so it doesn't affect the child
3554 * in the next parent.
3556 priv->child_visible = TRUE;
3558 old_parent = priv->parent;
3559 priv->parent = NULL;
3560 gtk_widget_set_parent_window (widget, NULL);
3561 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3564 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3565 g_object_unref (toplevel);
3568 g_object_notify (G_OBJECT (widget), "parent");
3569 g_object_thaw_notify (G_OBJECT (widget));
3571 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3572 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3573 g_object_unref (widget);
3577 * gtk_widget_destroy:
3578 * @widget: a #GtkWidget
3580 * Destroys a widget.
3583 * destroyed, it will break any references it holds to other objects.
3584 * If the widget is inside a container, the widget will be removed
3585 * from the container. If the widget is a toplevel (derived from
3586 * #GtkWindow), it will be removed from the list of toplevels, and the
3587 * reference GTK+ holds to it will be removed. Removing a
3588 * widget from its container or the list of toplevels results in the
3589 * widget being finalized, unless you've added additional references
3590 * to the widget with g_object_ref().
3592 * In most cases, only toplevel widgets (windows) require explicit
3593 * destruction, because when you destroy a toplevel its children will
3594 * be destroyed as well.
3597 gtk_widget_destroy (GtkWidget *widget)
3599 g_return_if_fail (GTK_IS_WIDGET (widget));
3601 if (!widget->priv->in_destruction)
3602 g_object_run_dispose (G_OBJECT (widget));
3606 * gtk_widget_destroyed:
3607 * @widget: a #GtkWidget
3608 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3610 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3611 * %NULL. It's intended to be used as a callback connected to the
3612 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3613 * as a signal handler, and pass the address of your widget variable
3614 * as user data. Then when the widget is destroyed, the variable will
3615 * be set to %NULL. Useful for example to avoid multiple copies
3616 * of the same dialog.
3619 gtk_widget_destroyed (GtkWidget *widget,
3620 GtkWidget **widget_pointer)
3622 /* Don't make any assumptions about the
3624 * Even check widget_pointer.
3627 *widget_pointer = NULL;
3632 * @widget: a #GtkWidget
3634 * Flags a widget to be displayed. Any widget that isn't shown will
3635 * not appear on the screen. If you want to show all the widgets in a
3636 * container, it's easier to call gtk_widget_show_all() on the
3637 * container, instead of individually showing the widgets.
3639 * Remember that you have to show the containers containing a widget,
3640 * in addition to the widget itself, before it will appear onscreen.
3642 * When a toplevel container is shown, it is immediately realized and
3643 * mapped; other shown widgets are realized and mapped when their
3644 * toplevel container is realized and mapped.
3647 gtk_widget_show (GtkWidget *widget)
3649 g_return_if_fail (GTK_IS_WIDGET (widget));
3651 if (!gtk_widget_get_visible (widget))
3653 g_object_ref (widget);
3654 if (!gtk_widget_is_toplevel (widget))
3655 gtk_widget_queue_resize (widget);
3656 g_signal_emit (widget, widget_signals[SHOW], 0);
3657 g_object_notify (G_OBJECT (widget), "visible");
3658 g_object_unref (widget);
3663 gtk_widget_real_show (GtkWidget *widget)
3665 GtkWidgetPrivate *priv = widget->priv;
3667 if (!gtk_widget_get_visible (widget))
3669 priv->visible = TRUE;
3672 gtk_widget_get_mapped (priv->parent) &&
3673 gtk_widget_get_child_visible (widget) &&
3674 !gtk_widget_get_mapped (widget))
3675 gtk_widget_map (widget);
3680 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3683 g_signal_handlers_disconnect_by_func (widget,
3684 gtk_widget_show_map_callback,
3689 * gtk_widget_show_now:
3690 * @widget: a #GtkWidget
3692 * Shows a widget. If the widget is an unmapped toplevel widget
3693 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3694 * loop and wait for the window to actually be mapped. Be careful;
3695 * because the main loop is running, anything can happen during
3699 gtk_widget_show_now (GtkWidget *widget)
3703 g_return_if_fail (GTK_IS_WIDGET (widget));
3705 /* make sure we will get event */
3706 if (!gtk_widget_get_mapped (widget) &&
3707 gtk_widget_is_toplevel (widget))
3709 gtk_widget_show (widget);
3711 g_signal_connect (widget, "map-event",
3712 G_CALLBACK (gtk_widget_show_map_callback),
3716 gtk_main_iteration ();
3719 gtk_widget_show (widget);
3724 * @widget: a #GtkWidget
3726 * Reverses the effects of gtk_widget_show(), causing the widget to be
3727 * hidden (invisible to the user).
3730 gtk_widget_hide (GtkWidget *widget)
3732 g_return_if_fail (GTK_IS_WIDGET (widget));
3734 if (gtk_widget_get_visible (widget))
3736 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3738 g_object_ref (widget);
3739 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3740 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3742 g_signal_emit (widget, widget_signals[HIDE], 0);
3743 if (!gtk_widget_is_toplevel (widget))
3744 gtk_widget_queue_resize (widget);
3745 g_object_notify (G_OBJECT (widget), "visible");
3746 g_object_unref (widget);
3751 gtk_widget_real_hide (GtkWidget *widget)
3753 if (gtk_widget_get_visible (widget))
3755 widget->priv->visible = FALSE;
3757 if (gtk_widget_get_mapped (widget))
3758 gtk_widget_unmap (widget);
3763 * gtk_widget_hide_on_delete:
3764 * @widget: a #GtkWidget
3766 * Utility function; intended to be connected to the #GtkWidget::delete-event
3767 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3768 * argument, then returns %TRUE. If connected to ::delete-event, the
3769 * result is that clicking the close button for a window (on the
3770 * window frame, top right corner usually) will hide but not destroy
3771 * the window. By default, GTK+ destroys windows when ::delete-event
3774 * Return value: %TRUE
3777 gtk_widget_hide_on_delete (GtkWidget *widget)
3779 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3781 gtk_widget_hide (widget);
3787 * gtk_widget_show_all:
3788 * @widget: a #GtkWidget
3790 * Recursively shows a widget, and any child widgets (if the widget is
3794 gtk_widget_show_all (GtkWidget *widget)
3796 GtkWidgetClass *class;
3798 g_return_if_fail (GTK_IS_WIDGET (widget));
3800 if (gtk_widget_get_no_show_all (widget))
3803 class = GTK_WIDGET_GET_CLASS (widget);
3805 if (class->show_all)
3806 class->show_all (widget);
3810 * gtk_widget_hide_all:
3811 * @widget: a #GtkWidget
3813 * Recursively hides a widget and any child widgets.
3816 gtk_widget_hide_all (GtkWidget *widget)
3818 GtkWidgetClass *class;
3820 g_return_if_fail (GTK_IS_WIDGET (widget));
3822 if (gtk_widget_get_no_show_all (widget))
3825 class = GTK_WIDGET_GET_CLASS (widget);
3827 if (class->hide_all)
3828 class->hide_all (widget);
3833 * @widget: a #GtkWidget
3835 * This function is only for use in widget implementations. Causes
3836 * a widget to be mapped if it isn't already.
3839 gtk_widget_map (GtkWidget *widget)
3841 GtkWidgetPrivate *priv;
3843 g_return_if_fail (GTK_IS_WIDGET (widget));
3844 g_return_if_fail (gtk_widget_get_visible (widget));
3845 g_return_if_fail (gtk_widget_get_child_visible (widget));
3847 priv = widget->priv;
3849 if (!gtk_widget_get_mapped (widget))
3851 if (!gtk_widget_get_realized (widget))
3852 gtk_widget_realize (widget);
3854 g_signal_emit (widget, widget_signals[MAP], 0);
3856 if (!gtk_widget_get_has_window (widget))
3857 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3863 * @widget: a #GtkWidget
3865 * This function is only for use in widget implementations. Causes
3866 * a widget to be unmapped if it's currently mapped.
3869 gtk_widget_unmap (GtkWidget *widget)
3871 GtkWidgetPrivate *priv;
3873 g_return_if_fail (GTK_IS_WIDGET (widget));
3875 priv = widget->priv;
3877 if (gtk_widget_get_mapped (widget))
3879 if (!gtk_widget_get_has_window (widget))
3880 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3881 _gtk_tooltip_hide (widget);
3882 g_signal_emit (widget, widget_signals[UNMAP], 0);
3887 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3888 GdkExtensionMode mode,
3891 GtkWidgetPrivate *priv = widget->priv;
3892 GList *free_list = NULL;
3895 if (window_list == NULL)
3897 if (gtk_widget_get_has_window (widget))
3898 window_list = g_list_prepend (NULL, priv->window);
3900 window_list = gdk_window_get_children (priv->window);
3902 free_list = window_list;
3905 for (l = window_list; l != NULL; l = l->next)
3907 GdkWindow *window = l->data;
3910 gdk_window_get_user_data (window, &user_data);
3911 if (user_data == widget)
3915 gdk_input_set_extension_events (window,
3916 gdk_window_get_events (window),
3919 children = gdk_window_get_children (window);
3922 gtk_widget_set_extension_events_internal (widget, mode, children);
3923 g_list_free (children);
3929 g_list_free (free_list);
3933 _gtk_widget_enable_device_events (GtkWidget *widget)
3935 GHashTable *device_events;
3936 GHashTableIter iter;
3937 gpointer key, value;
3939 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3944 g_hash_table_iter_init (&iter, device_events);
3946 while (g_hash_table_iter_next (&iter, &key, &value))
3949 GdkEventMask event_mask;
3952 event_mask = GPOINTER_TO_UINT (value);
3953 gtk_widget_add_events_internal (widget, device, event_mask);
3958 * gtk_widget_realize:
3959 * @widget: a #GtkWidget
3961 * Creates the GDK (windowing system) resources associated with a
3962 * widget. For example, @widget->window will be created when a widget
3963 * is realized. Normally realization happens implicitly; if you show
3964 * a widget and all its parent containers, then the widget will be
3965 * realized and mapped automatically.
3967 * Realizing a widget requires all
3968 * the widget's parent widgets to be realized; calling
3969 * gtk_widget_realize() realizes the widget's parents in addition to
3970 * @widget itself. If a widget is not yet inside a toplevel window
3971 * when you realize it, bad things will happen.
3973 * This function is primarily used in widget implementations, and
3974 * isn't very useful otherwise. Many times when you think you might
3975 * need it, a better approach is to connect to a signal that will be
3976 * called after the widget is realized automatically, such as
3977 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3978 * GtkWidget::realize signal.
3981 gtk_widget_realize (GtkWidget *widget)
3983 GtkWidgetPrivate *priv;
3984 GdkExtensionMode mode;
3985 cairo_region_t *region;
3987 g_return_if_fail (GTK_IS_WIDGET (widget));
3988 g_return_if_fail (widget->priv->anchored ||
3989 GTK_IS_INVISIBLE (widget));
3991 priv = widget->priv;
3993 if (!gtk_widget_get_realized (widget))
3996 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3997 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
4000 if (priv->parent == NULL &&
4001 !gtk_widget_is_toplevel (widget))
4002 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
4003 "inside a toplevel window is not going to work very well. "
4004 "Widgets must be inside a toplevel container before realizing them.");
4006 if (priv->parent && !gtk_widget_get_realized (priv->parent))
4007 gtk_widget_realize (priv->parent);
4009 gtk_widget_ensure_style (widget);
4011 g_signal_emit (widget, widget_signals[REALIZE], 0);
4013 gtk_widget_real_set_has_tooltip (widget,
4014 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
4017 if (priv->has_shape_mask)
4019 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
4020 gdk_window_shape_combine_region (priv->window, region, 0, 0);
4023 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
4025 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
4027 mode = gtk_widget_get_extension_events (widget);
4028 if (mode != GDK_EXTENSION_EVENTS_NONE)
4029 gtk_widget_set_extension_events_internal (widget, mode, NULL);
4031 if (priv->multidevice)
4032 gdk_window_set_support_multidevice (priv->window, TRUE);
4034 _gtk_widget_enable_device_events (widget);
4039 * gtk_widget_unrealize:
4040 * @widget: a #GtkWidget
4042 * This function is only useful in widget implementations.
4043 * Causes a widget to be unrealized (frees all GDK resources
4044 * associated with the widget, such as @widget->window).
4047 gtk_widget_unrealize (GtkWidget *widget)
4049 g_return_if_fail (GTK_IS_WIDGET (widget));
4051 if (widget->priv->has_shape_mask)
4052 gtk_widget_shape_combine_region (widget, NULL);
4054 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
4055 gtk_widget_input_shape_combine_region (widget, NULL);
4057 if (gtk_widget_get_realized (widget))
4059 g_object_ref (widget);
4060 _gtk_tooltip_hide (widget);
4061 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
4062 gtk_widget_set_realized (widget, FALSE);
4063 gtk_widget_set_mapped (widget, FALSE);
4064 g_object_unref (widget);
4068 /*****************************************
4070 *****************************************/
4073 * gtk_widget_queue_draw_area:
4074 * @widget: a #GtkWidget
4075 * @x: x coordinate of upper-left corner of rectangle to redraw
4076 * @y: y coordinate of upper-left corner of rectangle to redraw
4077 * @width: width of region to draw
4078 * @height: height of region to draw
4080 * Invalidates the rectangular area of @widget defined by @x, @y,
4081 * @width and @height by calling gdk_window_invalidate_rect() on the
4082 * widget's window and all its child windows. Once the main loop
4083 * becomes idle (after the current batch of events has been processed,
4084 * roughly), the window will receive expose events for the union of
4085 * all regions that have been invalidated.
4087 * Normally you would only use this function in widget
4088 * implementations. You might also use it, or
4089 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
4090 * #GtkDrawingArea or some portion thereof.
4092 * Frequently you can just call gdk_window_invalidate_rect() or
4093 * gdk_window_invalidate_region() instead of this function. Those
4094 * functions will invalidate only a single window, instead of the
4095 * widget and all its children.
4097 * The advantage of adding to the invalidated region compared to
4098 * simply drawing immediately is efficiency; using an invalid region
4099 * ensures that you only have to redraw one time.
4102 gtk_widget_queue_draw_area (GtkWidget *widget,
4108 GtkWidgetPrivate *priv;
4109 GdkRectangle invalid_rect;
4112 g_return_if_fail (GTK_IS_WIDGET (widget));
4114 priv = widget->priv;
4116 if (!gtk_widget_get_realized (widget))
4119 /* Just return if the widget or one of its ancestors isn't mapped */
4120 for (w = widget; w != NULL; w = w->priv->parent)
4121 if (!gtk_widget_get_mapped (w))
4124 /* Find the correct widget */
4126 if (gtk_widget_get_has_window (widget))
4130 /* Translate widget relative to window-relative */
4132 gint wx, wy, wwidth, wheight;
4134 gdk_window_get_position (priv->window, &wx, &wy);
4135 x -= wx - priv->allocation.x;
4136 y -= wy - priv->allocation.y;
4138 wwidth = gdk_window_get_width (priv->window);
4139 wheight = gdk_window_get_height (priv->window);
4141 if (x + width <= 0 || y + height <= 0 ||
4142 x >= wwidth || y >= wheight)
4153 if (x + width > wwidth)
4155 if (y + height > wheight)
4156 height = wheight - y;
4162 invalid_rect.width = width;
4163 invalid_rect.height = height;
4165 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4169 * gtk_widget_queue_draw:
4170 * @widget: a #GtkWidget
4172 * Equivalent to calling gtk_widget_queue_draw_area() for the
4173 * entire area of a widget.
4176 gtk_widget_queue_draw (GtkWidget *widget)
4180 g_return_if_fail (GTK_IS_WIDGET (widget));
4182 gtk_widget_get_allocation (widget, &rect);
4184 if (!gtk_widget_get_has_window (widget))
4185 gtk_widget_queue_draw_area (widget,
4186 rect.x, rect.y, rect.width, rect.height);
4188 gtk_widget_queue_draw_area (widget,
4189 0, 0, rect.width, rect.height);
4193 * gtk_widget_queue_resize:
4194 * @widget: a #GtkWidget
4196 * This function is only for use in widget implementations.
4197 * Flags a widget to have its size renegotiated; should
4198 * be called when a widget for some reason has a new size request.
4199 * For example, when you change the text in a #GtkLabel, #GtkLabel
4200 * queues a resize to ensure there's enough space for the new text.
4203 gtk_widget_queue_resize (GtkWidget *widget)
4205 g_return_if_fail (GTK_IS_WIDGET (widget));
4207 if (gtk_widget_get_realized (widget))
4208 gtk_widget_queue_shallow_draw (widget);
4210 _gtk_size_group_queue_resize (widget);
4214 * gtk_widget_queue_resize_no_redraw:
4215 * @widget: a #GtkWidget
4217 * This function works like gtk_widget_queue_resize(),
4218 * except that the widget is not invalidated.
4223 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4225 g_return_if_fail (GTK_IS_WIDGET (widget));
4227 _gtk_size_group_queue_resize (widget);
4231 * gtk_widget_size_request:
4232 * @widget: a #GtkWidget
4233 * @requisition: (out): a #GtkRequisition to be filled in
4235 * This function is typically used when implementing a #GtkContainer
4236 * subclass. Obtains the preferred size of a widget. The container
4237 * uses this information to arrange its child widgets and decide what
4238 * size allocations to give them with gtk_widget_size_allocate().
4240 * You can also call this function from an application, with some
4241 * caveats. Most notably, getting a size request requires the widget
4242 * to be associated with a screen, because font information may be
4243 * needed. Multihead-aware applications should keep this in mind.
4245 * Also remember that the size request is not necessarily the size
4246 * a widget will actually be allocated.
4248 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4251 gtk_widget_size_request (GtkWidget *widget,
4252 GtkRequisition *requisition)
4254 g_return_if_fail (GTK_IS_WIDGET (widget));
4256 gtk_widget_get_preferred_size (widget, requisition, NULL);
4260 * gtk_widget_get_child_requisition:
4261 * @widget: a #GtkWidget
4262 * @requisition: (out): a #GtkRequisition to be filled in
4264 * This function is only for use in widget implementations. Obtains
4265 * @widget->requisition, unless someone has forced a particular
4266 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4267 * in which case it returns that geometry instead of the widget's
4270 * This function differs from gtk_widget_size_request() in that
4271 * it retrieves the last size request value from @widget->requisition,
4272 * while gtk_widget_size_request() actually calls the "size_request" method
4273 * on @widget to compute the size request and fill in @widget->requisition,
4274 * and only then returns @widget->requisition.
4276 * Because this function does not call the "size_request" method, it
4277 * can only be used when you know that @widget->requisition is
4278 * up-to-date, that is, gtk_widget_size_request() has been called
4279 * since the last time a resize was queued. In general, only container
4280 * implementations have this information; applications should use
4281 * gtk_widget_size_request().
4284 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4287 gtk_widget_get_child_requisition (GtkWidget *widget,
4288 GtkRequisition *requisition)
4290 gtk_widget_get_preferred_size (widget, requisition, NULL);
4294 invalidate_predicate (GdkWindow *window,
4299 gdk_window_get_user_data (window, &user_data);
4301 return (user_data == data);
4304 /* Invalidate @region in widget->window and all children
4305 * of widget->window owned by widget. @region is in the
4306 * same coordinates as widget->allocation and will be
4307 * modified by this call.
4310 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4311 cairo_region_t *region)
4313 GtkWidgetPrivate *priv = widget->priv;
4315 if (!gtk_widget_get_realized (widget))
4318 if (gtk_widget_get_has_window (widget) && priv->parent)
4322 gdk_window_get_position (priv->window, &x, &y);
4323 cairo_region_translate (region, -x, -y);
4326 gdk_window_invalidate_maybe_recurse (priv->window, region,
4327 invalidate_predicate, widget);
4331 * gtk_widget_queue_shallow_draw:
4332 * @widget: a #GtkWidget
4334 * Like gtk_widget_queue_draw(), but only windows owned
4335 * by @widget are invalidated.
4338 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4341 cairo_region_t *region;
4343 if (!gtk_widget_get_realized (widget))
4346 gtk_widget_get_allocation (widget, &rect);
4348 region = cairo_region_create_rectangle (&rect);
4349 gtk_widget_invalidate_widget_windows (widget, region);
4350 cairo_region_destroy (region);
4354 * gtk_widget_size_allocate:
4355 * @widget: a #GtkWidget
4356 * @allocation: (inout): position and size to be allocated to @widget
4358 * This function is only used by #GtkContainer subclasses, to assign a size
4359 * and position to their child widgets.
4361 * In this function, the allocation may be adjusted. It will be forced
4362 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4363 * method on the child will be used to adjust the allocation. Standard
4364 * adjustments include removing the widget's margins, and applying the
4365 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4368 gtk_widget_size_allocate (GtkWidget *widget,
4369 GtkAllocation *allocation)
4371 GtkWidgetPrivate *priv;
4372 GdkRectangle real_allocation;
4373 GdkRectangle old_allocation;
4374 GdkRectangle adjusted_allocation;
4375 gboolean alloc_needed;
4376 gboolean size_changed;
4377 gboolean position_changed;
4379 priv = widget->priv;
4381 g_return_if_fail (GTK_IS_WIDGET (widget));
4383 #ifdef G_ENABLE_DEBUG
4384 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4395 parent = gtk_widget_get_parent (parent);
4398 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4399 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4400 2 * depth, " ", name,
4401 allocation->width, allocation->height);
4403 #endif /* G_ENABLE_DEBUG */
4405 alloc_needed = priv->alloc_needed;
4406 if (!priv->width_request_needed && !priv->height_request_needed)
4407 /* Preserve request/allocate ordering */
4408 priv->alloc_needed = FALSE;
4410 old_allocation = priv->allocation;
4411 real_allocation = *allocation;
4413 adjusted_allocation = real_allocation;
4414 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4416 if (adjusted_allocation.x < real_allocation.x ||
4417 adjusted_allocation.y < real_allocation.y ||
4418 (adjusted_allocation.x + adjusted_allocation.width) >
4419 (real_allocation.x + real_allocation.width) ||
4420 (adjusted_allocation.y + adjusted_allocation.height >
4421 real_allocation.y + real_allocation.height))
4423 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",
4424 G_OBJECT_TYPE_NAME (widget), widget,
4425 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4426 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4427 adjusted_allocation = real_allocation; /* veto it */
4431 real_allocation = adjusted_allocation;
4434 if (real_allocation.width < 0 || real_allocation.height < 0)
4436 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4437 real_allocation.width,
4438 real_allocation.height);
4441 real_allocation.width = MAX (real_allocation.width, 1);
4442 real_allocation.height = MAX (real_allocation.height, 1);
4444 size_changed = (old_allocation.width != real_allocation.width ||
4445 old_allocation.height != real_allocation.height);
4446 position_changed = (old_allocation.x != real_allocation.x ||
4447 old_allocation.y != real_allocation.y);
4449 if (!alloc_needed && !size_changed && !position_changed)
4452 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4454 if (gtk_widget_get_mapped (widget))
4456 if (!gtk_widget_get_has_window (widget) && priv->redraw_on_alloc && position_changed)
4458 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4460 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4461 cairo_region_union_rectangle (invalidate, &old_allocation);
4463 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4464 cairo_region_destroy (invalidate);
4469 if (priv->redraw_on_alloc)
4471 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4473 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4474 cairo_region_union_rectangle (invalidate, &old_allocation);
4476 gtk_widget_invalidate_widget_windows (widget, invalidate);
4477 cairo_region_destroy (invalidate);
4482 if ((size_changed || position_changed) && priv->parent &&
4483 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4485 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4486 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4487 cairo_region_destroy (invalidate);
4492 * gtk_widget_common_ancestor:
4493 * @widget_a: a #GtkWidget
4494 * @widget_b: a #GtkWidget
4496 * Find the common ancestor of @widget_a and @widget_b that
4497 * is closest to the two widgets.
4499 * Return value: the closest common ancestor of @widget_a and
4500 * @widget_b or %NULL if @widget_a and @widget_b do not
4501 * share a common ancestor.
4504 gtk_widget_common_ancestor (GtkWidget *widget_a,
4505 GtkWidget *widget_b)
4507 GtkWidget *parent_a;
4508 GtkWidget *parent_b;
4512 parent_a = widget_a;
4513 while (parent_a->priv->parent)
4515 parent_a = parent_a->priv->parent;
4519 parent_b = widget_b;
4520 while (parent_b->priv->parent)
4522 parent_b = parent_b->priv->parent;
4526 if (parent_a != parent_b)
4529 while (depth_a > depth_b)
4531 widget_a = widget_a->priv->parent;
4535 while (depth_b > depth_a)
4537 widget_b = widget_b->priv->parent;
4541 while (widget_a != widget_b)
4543 widget_a = widget_a->priv->parent;
4544 widget_b = widget_b->priv->parent;
4551 * gtk_widget_translate_coordinates:
4552 * @src_widget: a #GtkWidget
4553 * @dest_widget: a #GtkWidget
4554 * @src_x: X position relative to @src_widget
4555 * @src_y: Y position relative to @src_widget
4556 * @dest_x: (out): location to store X position relative to @dest_widget
4557 * @dest_y: (out): location to store Y position relative to @dest_widget
4559 * Translate coordinates relative to @src_widget's allocation to coordinates
4560 * relative to @dest_widget's allocations. In order to perform this
4561 * operation, both widgets must be realized, and must share a common
4564 * Return value: %FALSE if either widget was not realized, or there
4565 * was no common ancestor. In this case, nothing is stored in
4566 * *@dest_x and *@dest_y. Otherwise %TRUE.
4569 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4570 GtkWidget *dest_widget,
4576 GtkWidgetPrivate *src_priv = src_widget->priv;
4577 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4578 GtkWidget *ancestor;
4580 GList *dest_list = NULL;
4582 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4583 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4585 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4586 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4589 /* Translate from allocation relative to window relative */
4590 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4593 gdk_window_get_position (src_priv->window, &wx, &wy);
4595 src_x -= wx - src_priv->allocation.x;
4596 src_y -= wy - src_priv->allocation.y;
4600 src_x += src_priv->allocation.x;
4601 src_y += src_priv->allocation.y;
4604 /* Translate to the common ancestor */
4605 window = src_priv->window;
4606 while (window != ancestor->priv->window)
4610 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4615 window = gdk_window_get_effective_parent (window);
4617 if (!window) /* Handle GtkHandleBox */
4622 window = dest_priv->window;
4623 while (window != ancestor->priv->window)
4625 dest_list = g_list_prepend (dest_list, window);
4627 window = gdk_window_get_effective_parent (window);
4629 if (!window) /* Handle GtkHandleBox */
4631 g_list_free (dest_list);
4640 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4645 dest_list = g_list_remove (dest_list, dest_list->data);
4648 /* Translate from window relative to allocation relative */
4649 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4652 gdk_window_get_position (dest_priv->window, &wx, &wy);
4654 src_x += wx - dest_priv->allocation.x;
4655 src_y += wy - dest_priv->allocation.y;
4659 src_x -= dest_priv->allocation.x;
4660 src_y -= dest_priv->allocation.y;
4672 gtk_widget_real_size_allocate (GtkWidget *widget,
4673 GtkAllocation *allocation)
4675 GtkWidgetPrivate *priv = widget->priv;
4677 priv->allocation = *allocation;
4679 if (gtk_widget_get_realized (widget) &&
4680 gtk_widget_get_has_window (widget))
4682 gdk_window_move_resize (priv->window,
4683 allocation->x, allocation->y,
4684 allocation->width, allocation->height);
4689 get_span_inside_border (GtkWidget *widget,
4693 int allocated_outside_size,
4694 int natural_inside_size,
4695 int *coord_inside_p,
4698 int inside_allocated;
4702 inside_allocated = allocated_outside_size - start_pad - end_pad;
4704 content_size = natural_inside_size;
4705 if (content_size > inside_allocated)
4707 /* didn't get full natural size */
4708 content_size = inside_allocated;
4711 coord = size = 0; /* silence compiler */
4714 case GTK_ALIGN_FILL:
4716 size = inside_allocated;
4718 case GTK_ALIGN_START:
4720 size = content_size;
4723 coord = allocated_outside_size - end_pad - content_size;
4724 size = content_size;
4726 case GTK_ALIGN_CENTER:
4727 coord = start_pad + (inside_allocated - content_size) / 2;
4728 size = content_size;
4733 *coord_inside_p = coord;
4736 *size_inside_p = size;
4740 get_span_inside_border_horizontal (GtkWidget *widget,
4741 const GtkWidgetAuxInfo *aux_info,
4742 int allocated_outside_width,
4743 int natural_inside_width,
4745 int *width_inside_p)
4747 get_span_inside_border (widget,
4749 aux_info->margin.left,
4750 aux_info->margin.right,
4751 allocated_outside_width,
4752 natural_inside_width,
4758 get_span_inside_border_vertical (GtkWidget *widget,
4759 const GtkWidgetAuxInfo *aux_info,
4760 int allocated_outside_height,
4761 int natural_inside_height,
4763 int *height_inside_p)
4765 get_span_inside_border (widget,
4767 aux_info->margin.top,
4768 aux_info->margin.bottom,
4769 allocated_outside_height,
4770 natural_inside_height,
4776 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4777 GtkAllocation *allocation)
4779 const GtkWidgetAuxInfo *aux_info;
4781 gint natural_height;
4784 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4786 if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
4788 gtk_widget_get_preferred_width (widget, NULL, &natural_width);
4789 get_span_inside_border_horizontal (widget,
4795 gtk_widget_get_preferred_height_for_width (widget, w, NULL, &natural_height);
4796 get_span_inside_border_vertical (widget,
4802 else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
4804 gtk_widget_get_preferred_height (widget, NULL, &natural_height);
4805 get_span_inside_border_vertical (widget,
4811 gtk_widget_get_preferred_width_for_height (widget, h, NULL, &natural_width);
4812 get_span_inside_border_horizontal (widget,
4821 allocation->width = w;
4822 allocation->height = h;
4826 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4829 GtkWidgetPrivate *priv = widget->priv;
4831 /* widgets must be onscreen for accels to take effect */
4832 return gtk_widget_is_sensitive (widget) &&
4833 gtk_widget_is_drawable (widget) &&
4834 gdk_window_is_viewable (priv->window);
4838 * gtk_widget_can_activate_accel:
4839 * @widget: a #GtkWidget
4840 * @signal_id: the ID of a signal installed on @widget
4842 * Determines whether an accelerator that activates the signal
4843 * identified by @signal_id can currently be activated.
4844 * This is done by emitting the #GtkWidget::can-activate-accel
4845 * signal on @widget; if the signal isn't overridden by a
4846 * handler or in a derived widget, then the default check is
4847 * that the widget must be sensitive, and the widget and all
4848 * its ancestors mapped.
4850 * Return value: %TRUE if the accelerator can be activated.
4855 gtk_widget_can_activate_accel (GtkWidget *widget,
4858 gboolean can_activate = FALSE;
4859 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4860 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4861 return can_activate;
4870 closure_accel_activate (GClosure *closure,
4871 GValue *return_value,
4872 guint n_param_values,
4873 const GValue *param_values,
4874 gpointer invocation_hint,
4875 gpointer marshal_data)
4877 AccelClosure *aclosure = (AccelClosure*) closure;
4878 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4881 g_signal_emit (closure->data, aclosure->signal_id, 0);
4883 /* whether accelerator was handled */
4884 g_value_set_boolean (return_value, can_activate);
4888 closures_destroy (gpointer data)
4890 GSList *slist, *closures = data;
4892 for (slist = closures; slist; slist = slist->next)
4894 g_closure_invalidate (slist->data);
4895 g_closure_unref (slist->data);
4897 g_slist_free (closures);
4901 widget_new_accel_closure (GtkWidget *widget,
4904 AccelClosure *aclosure;
4905 GClosure *closure = NULL;
4906 GSList *slist, *closures;
4908 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4909 for (slist = closures; slist; slist = slist->next)
4910 if (!gtk_accel_group_from_accel_closure (slist->data))
4912 /* reuse this closure */
4913 closure = slist->data;
4918 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4919 closures = g_slist_prepend (closures, g_closure_ref (closure));
4920 g_closure_sink (closure);
4921 g_closure_set_marshal (closure, closure_accel_activate);
4923 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4925 aclosure = (AccelClosure*) closure;
4926 g_assert (closure->data == widget);
4927 g_assert (closure->marshal == closure_accel_activate);
4928 aclosure->signal_id = signal_id;
4934 * gtk_widget_add_accelerator
4935 * @widget: widget to install an accelerator on
4936 * @accel_signal: widget signal to emit on accelerator activation
4937 * @accel_group: accel group for this widget, added to its toplevel
4938 * @accel_key: GDK keyval of the accelerator
4939 * @accel_mods: modifier key combination of the accelerator
4940 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4942 * Installs an accelerator for this @widget in @accel_group that causes
4943 * @accel_signal to be emitted if the accelerator is activated.
4944 * The @accel_group needs to be added to the widget's toplevel via
4945 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4946 * Accelerators added through this function are not user changeable during
4947 * runtime. If you want to support accelerators that can be changed by the
4948 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4949 * gtk_menu_item_set_accel_path() instead.
4952 gtk_widget_add_accelerator (GtkWidget *widget,
4953 const gchar *accel_signal,
4954 GtkAccelGroup *accel_group,
4956 GdkModifierType accel_mods,
4957 GtkAccelFlags accel_flags)
4962 g_return_if_fail (GTK_IS_WIDGET (widget));
4963 g_return_if_fail (accel_signal != NULL);
4964 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4966 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4967 if (!query.signal_id ||
4968 !(query.signal_flags & G_SIGNAL_ACTION) ||
4969 query.return_type != G_TYPE_NONE ||
4972 /* hmm, should be elaborate enough */
4973 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4974 G_OBJECT_TYPE_NAME (widget), accel_signal);
4978 closure = widget_new_accel_closure (widget, query.signal_id);
4980 g_object_ref (widget);
4982 /* install the accelerator. since we don't map this onto an accel_path,
4983 * the accelerator will automatically be locked.
4985 gtk_accel_group_connect (accel_group,
4988 accel_flags | GTK_ACCEL_LOCKED,
4991 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4993 g_object_unref (widget);
4997 * gtk_widget_remove_accelerator:
4998 * @widget: widget to install an accelerator on
4999 * @accel_group: accel group for this widget
5000 * @accel_key: GDK keyval of the accelerator
5001 * @accel_mods: modifier key combination of the accelerator
5002 * @returns: whether an accelerator was installed and could be removed
5004 * Removes an accelerator from @widget, previously installed with
5005 * gtk_widget_add_accelerator().
5008 gtk_widget_remove_accelerator (GtkWidget *widget,
5009 GtkAccelGroup *accel_group,
5011 GdkModifierType accel_mods)
5013 GtkAccelGroupEntry *ag_entry;
5014 GList *slist, *clist;
5017 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5018 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
5020 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
5021 clist = gtk_widget_list_accel_closures (widget);
5022 for (slist = clist; slist; slist = slist->next)
5026 for (i = 0; i < n; i++)
5027 if (slist->data == (gpointer) ag_entry[i].closure)
5029 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
5031 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5033 g_list_free (clist);
5038 g_list_free (clist);
5040 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
5041 accel_key, accel_mods, accel_group,
5042 G_OBJECT_TYPE_NAME (widget), widget);
5048 * gtk_widget_list_accel_closures:
5049 * @widget: widget to list accelerator closures for
5051 * Lists the closures used by @widget for accelerator group connections
5052 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
5053 * The closures can be used to monitor accelerator changes on @widget,
5054 * by connecting to the @GtkAccelGroup::accel-changed signal of the
5055 * #GtkAccelGroup of a closure which can be found out with
5056 * gtk_accel_group_from_accel_closure().
5058 * Return value: (transfer container) (element-type GClosure):
5059 * a newly allocated #GList of closures
5062 gtk_widget_list_accel_closures (GtkWidget *widget)
5065 GList *clist = NULL;
5067 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5069 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
5070 if (gtk_accel_group_from_accel_closure (slist->data))
5071 clist = g_list_prepend (clist, slist->data);
5077 GtkAccelGroup *accel_group;
5082 destroy_accel_path (gpointer data)
5084 AccelPath *apath = data;
5086 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
5088 /* closures_destroy takes care of unrefing the closure */
5089 g_object_unref (apath->accel_group);
5091 g_slice_free (AccelPath, apath);
5096 * gtk_widget_set_accel_path:
5097 * @widget: a #GtkWidget
5098 * @accel_path: (allow-none): path used to look up the accelerator
5099 * @accel_group: (allow-none): a #GtkAccelGroup.
5101 * Given an accelerator group, @accel_group, and an accelerator path,
5102 * @accel_path, sets up an accelerator in @accel_group so whenever the
5103 * key binding that is defined for @accel_path is pressed, @widget
5104 * will be activated. This removes any accelerators (for any
5105 * accelerator group) installed by previous calls to
5106 * gtk_widget_set_accel_path(). Associating accelerators with
5107 * paths allows them to be modified by the user and the modifications
5108 * to be saved for future use. (See gtk_accel_map_save().)
5110 * This function is a low level function that would most likely
5111 * be used by a menu creation system like #GtkUIManager. If you
5112 * use #GtkUIManager, setting up accelerator paths will be done
5115 * Even when you you aren't using #GtkUIManager, if you only want to
5116 * set up accelerators on menu items gtk_menu_item_set_accel_path()
5117 * provides a somewhat more convenient interface.
5119 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
5120 * pass a static string, you can save some memory by interning it first with
5121 * g_intern_static_string().
5124 gtk_widget_set_accel_path (GtkWidget *widget,
5125 const gchar *accel_path,
5126 GtkAccelGroup *accel_group)
5130 g_return_if_fail (GTK_IS_WIDGET (widget));
5131 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
5135 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
5136 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
5138 gtk_accel_map_add_entry (accel_path, 0, 0);
5139 apath = g_slice_new (AccelPath);
5140 apath->accel_group = g_object_ref (accel_group);
5141 apath->path_quark = g_quark_from_string (accel_path);
5142 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5147 /* also removes possible old settings */
5148 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5151 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5153 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5157 _gtk_widget_get_accel_path (GtkWidget *widget,
5162 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5164 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5166 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5167 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5171 * gtk_widget_mnemonic_activate:
5172 * @widget: a #GtkWidget
5173 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5175 * Emits the #GtkWidget::mnemonic-activate signal.
5177 * The default handler for this signal activates the @widget if
5178 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5181 * Returns: %TRUE if the signal has been handled
5184 gtk_widget_mnemonic_activate (GtkWidget *widget,
5185 gboolean group_cycling)
5189 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5191 group_cycling = group_cycling != FALSE;
5192 if (!gtk_widget_is_sensitive (widget))
5195 g_signal_emit (widget,
5196 widget_signals[MNEMONIC_ACTIVATE],
5204 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5205 gboolean group_cycling)
5207 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5208 gtk_widget_activate (widget);
5209 else if (gtk_widget_get_can_focus (widget))
5210 gtk_widget_grab_focus (widget);
5213 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5214 G_OBJECT_TYPE_NAME (widget));
5215 gtk_widget_error_bell (widget);
5220 static const cairo_user_data_key_t event_key;
5223 _gtk_cairo_get_event (cairo_t *cr)
5225 g_return_val_if_fail (cr != NULL, NULL);
5227 return cairo_get_user_data (cr, &event_key);
5231 gtk_cairo_set_event (cairo_t *cr,
5232 GdkEventExpose *event)
5234 cairo_set_user_data (cr, &event_key, event, NULL);
5238 * gtk_cairo_should_draw_window:
5239 * @cr: a cairo context
5240 * @window: the window to check
5242 * This function is supposed to be called in GtkWidget::draw
5243 * implementations for widgets that support multiple windows.
5244 * @cr must be untransformed from invoking of the draw function.
5245 * This function will return %TRUE if the contents of the given
5246 * @window are supposed to be drawn and %FALSE otherwise. Note
5247 * that when the drawing was not initiated by the windowing
5248 * system this function will return %TRUE for all windows, so
5249 * you need to draw the bottommost window first. Also, do not
5250 * use "else if" statements to check which window should be drawn.
5252 * Returns: %TRUE if @window should be drawn
5255 gtk_cairo_should_draw_window (cairo_t *cr,
5258 GdkEventExpose *event;
5260 g_return_val_if_fail (cr != NULL, FALSE);
5261 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5263 event = _gtk_cairo_get_event (cr);
5265 return event == NULL ||
5266 event->window == window;
5269 /* code shared by gtk_container_propagate_draw() and
5273 _gtk_widget_draw_internal (GtkWidget *widget,
5275 gboolean clip_to_size)
5277 if (!gtk_widget_is_drawable (widget))
5282 cairo_rectangle (cr,
5284 widget->priv->allocation.width,
5285 widget->priv->allocation.height);
5289 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5293 g_signal_emit (widget, widget_signals[DRAW],
5301 * @widget: the widget to draw. It must be drawable (see
5302 * gtk_widget_is_drawable()) and a size must have been allocated.
5303 * @cr: a cairo context to draw to
5305 * Draws @widget to @cr. The top left corner of the widget will be
5306 * drawn to the currently set origin point of @cr.
5308 * You should pass a cairo context as @cr argument that is in an
5309 * original state. Otherwise the resulting drawing is undefined. For
5310 * example changing the operator using cairo_set_operator() or the
5311 * line width using cairo_set_line_width() might have unwanted side
5313 * You may however change the context's transform matrix - like with
5314 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5315 * region with cairo_clip() prior to calling this function. Also, it
5316 * is fine to modify the context with cairo_save() and
5317 * cairo_push_group() prior to calling this function.
5319 * <note><para>Special purpose widgets may contain special code for
5320 * rendering to the screen and might appear differently on screen
5321 * and when rendered using gtk_widget_draw().</para></note>
5324 gtk_widget_draw (GtkWidget *widget,
5327 GdkEventExpose *tmp_event;
5329 g_return_if_fail (GTK_IS_WIDGET (widget));
5330 g_return_if_fail (!widget->priv->alloc_needed);
5331 g_return_if_fail (cr != NULL);
5334 /* We have to reset the event here so that draw functions can call
5335 * gtk_widget_draw() on random other widgets and get the desired
5336 * effect: Drawing all contents, not just the current window.
5338 tmp_event = _gtk_cairo_get_event (cr);
5339 gtk_cairo_set_event (cr, NULL);
5341 _gtk_widget_draw_internal (widget, cr, TRUE);
5343 gtk_cairo_set_event (cr, tmp_event);
5348 gtk_widget_real_key_press_event (GtkWidget *widget,
5351 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5355 gtk_widget_real_key_release_event (GtkWidget *widget,
5358 return gtk_bindings_activate_event (G_OBJECT (widget), event);
5362 gtk_widget_real_focus_in_event (GtkWidget *widget,
5363 GdkEventFocus *event)
5365 gtk_widget_queue_shallow_draw (widget);
5371 gtk_widget_real_focus_out_event (GtkWidget *widget,
5372 GdkEventFocus *event)
5374 gtk_widget_queue_shallow_draw (widget);
5379 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5380 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5384 * @widget: a #GtkWidget
5385 * @event: a #GdkEvent
5387 * Rarely-used function. This function is used to emit
5388 * the event signals on a widget (those signals should never
5389 * be emitted without using this function to do so).
5390 * If you want to synthesize an event though, don't use this function;
5391 * instead, use gtk_main_do_event() so the event will behave as if
5392 * it were in the event queue. Don't synthesize expose events; instead,
5393 * use gdk_window_invalidate_rect() to invalidate a region of the
5396 * Return value: return from the event signal emission (%TRUE if
5397 * the event was handled)
5400 gtk_widget_event (GtkWidget *widget,
5403 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5404 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5406 if (event->type == GDK_EXPOSE)
5408 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5409 "the same effect, call gdk_window_invalidate_rect/region(), "
5410 "followed by gdk_window_process_updates().");
5414 return gtk_widget_event_internal (widget, event);
5417 /* Returns TRUE if a translation should be done */
5419 gtk_widget_get_translation_to_window (GtkWidget *widget,
5424 GdkWindow *w, *widget_window;
5426 if (!gtk_widget_get_has_window (widget))
5428 *x = -widget->priv->allocation.x;
5429 *y = -widget->priv->allocation.y;
5437 widget_window = gtk_widget_get_window (widget);
5439 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5442 gdk_window_get_position (w, &wx, &wy);
5459 * gtk_cairo_transform_to_window:
5460 * @cr: the cairo context to transform
5461 * @widget: the widget the context is currently centered for
5462 * @window: the window to transform the context to
5464 * Transforms the given cairo context @cr that from @widget-relative
5465 * coordinates to @window-relative coordinates.
5466 * If the @widget's window is not an ancestor of @window, no
5467 * modification will be applied.
5469 * This is the inverse to the transformation GTK applies when
5470 * preparing an expose event to be emitted with the GtkWidget::draw
5471 * signal. It is intended to help porting multiwindow widgets from
5472 * GTK 2 to the rendering architecture of GTK 3.
5475 gtk_cairo_transform_to_window (cairo_t *cr,
5481 g_return_if_fail (cr != NULL);
5482 g_return_if_fail (GTK_IS_WIDGET (widget));
5483 g_return_if_fail (GDK_IS_WINDOW (window));
5485 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5486 cairo_translate (cr, x, y);
5490 * gtk_widget_send_expose:
5491 * @widget: a #GtkWidget
5492 * @event: a expose #GdkEvent
5494 * Very rarely-used function. This function is used to emit
5495 * an expose event on a widget. This function is not normally used
5496 * directly. The only time it is used is when propagating an expose
5497 * event to a child %NO_WINDOW widget, and that is normally done
5498 * using gtk_container_propagate_draw().
5500 * If you want to force an area of a window to be redrawn,
5501 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5502 * To cause the redraw to be done immediately, follow that call
5503 * with a call to gdk_window_process_updates().
5505 * Return value: return from the event signal emission (%TRUE if
5506 * the event was handled)
5509 gtk_widget_send_expose (GtkWidget *widget,
5512 gboolean result = FALSE;
5517 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5518 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5519 g_return_val_if_fail (event != NULL, TRUE);
5520 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5522 cr = gdk_cairo_create (event->expose.window);
5523 gtk_cairo_set_event (cr, &event->expose);
5525 gdk_cairo_region (cr, event->expose.region);
5528 do_clip = gtk_widget_get_translation_to_window (widget,
5529 event->expose.window,
5531 cairo_translate (cr, -x, -y);
5533 _gtk_widget_draw_internal (widget, cr, do_clip);
5535 /* unset here, so if someone keeps a reference to cr we
5536 * don't leak the window. */
5537 gtk_cairo_set_event (cr, NULL);
5544 event_window_is_still_viewable (GdkEvent *event)
5546 /* Check that we think the event's window is viewable before
5547 * delivering the event, to prevent suprises. We do this here
5548 * at the last moment, since the event may have been queued
5549 * up behind other events, held over a recursive main loop, etc.
5551 switch (event->type)
5554 case GDK_MOTION_NOTIFY:
5555 case GDK_BUTTON_PRESS:
5556 case GDK_2BUTTON_PRESS:
5557 case GDK_3BUTTON_PRESS:
5559 case GDK_ENTER_NOTIFY:
5560 case GDK_PROXIMITY_IN:
5562 return event->any.window && gdk_window_is_viewable (event->any.window);
5565 /* The following events are the second half of paired events;
5566 * we always deliver them to deal with widgets that clean up
5567 * on the second half.
5569 case GDK_BUTTON_RELEASE:
5570 case GDK_KEY_RELEASE:
5571 case GDK_LEAVE_NOTIFY:
5572 case GDK_PROXIMITY_OUT:
5576 /* Remaining events would make sense on an not-viewable window,
5577 * or don't have an associated window.
5584 gtk_widget_event_internal (GtkWidget *widget,
5587 gboolean return_val = FALSE;
5589 /* We check only once for is-still-visible; if someone
5590 * hides the window in on of the signals on the widget,
5591 * they are responsible for returning TRUE to terminate
5594 if (!event_window_is_still_viewable (event))
5597 g_object_ref (widget);
5599 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5600 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5605 switch (event->type)
5610 case GDK_BUTTON_PRESS:
5611 case GDK_2BUTTON_PRESS:
5612 case GDK_3BUTTON_PRESS:
5613 signal_num = BUTTON_PRESS_EVENT;
5616 signal_num = SCROLL_EVENT;
5618 case GDK_BUTTON_RELEASE:
5619 signal_num = BUTTON_RELEASE_EVENT;
5621 case GDK_MOTION_NOTIFY:
5622 signal_num = MOTION_NOTIFY_EVENT;
5625 signal_num = DELETE_EVENT;
5628 signal_num = DESTROY_EVENT;
5629 _gtk_tooltip_hide (widget);
5632 signal_num = KEY_PRESS_EVENT;
5634 case GDK_KEY_RELEASE:
5635 signal_num = KEY_RELEASE_EVENT;
5637 case GDK_ENTER_NOTIFY:
5638 signal_num = ENTER_NOTIFY_EVENT;
5640 case GDK_LEAVE_NOTIFY:
5641 signal_num = LEAVE_NOTIFY_EVENT;
5643 case GDK_FOCUS_CHANGE:
5644 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5645 if (event->focus_change.in)
5646 _gtk_tooltip_focus_in (widget);
5648 _gtk_tooltip_focus_out (widget);
5651 signal_num = CONFIGURE_EVENT;
5654 signal_num = MAP_EVENT;
5657 signal_num = UNMAP_EVENT;
5659 case GDK_WINDOW_STATE:
5660 signal_num = WINDOW_STATE_EVENT;
5662 case GDK_PROPERTY_NOTIFY:
5663 signal_num = PROPERTY_NOTIFY_EVENT;
5665 case GDK_SELECTION_CLEAR:
5666 signal_num = SELECTION_CLEAR_EVENT;
5668 case GDK_SELECTION_REQUEST:
5669 signal_num = SELECTION_REQUEST_EVENT;
5671 case GDK_SELECTION_NOTIFY:
5672 signal_num = SELECTION_NOTIFY_EVENT;
5674 case GDK_PROXIMITY_IN:
5675 signal_num = PROXIMITY_IN_EVENT;
5677 case GDK_PROXIMITY_OUT:
5678 signal_num = PROXIMITY_OUT_EVENT;
5681 signal_num = NO_EXPOSE_EVENT;
5683 case GDK_CLIENT_EVENT:
5684 signal_num = CLIENT_EVENT;
5687 signal_num = EXPOSE_EVENT;
5689 case GDK_VISIBILITY_NOTIFY:
5690 signal_num = VISIBILITY_NOTIFY_EVENT;
5692 case GDK_GRAB_BROKEN:
5693 signal_num = GRAB_BROKEN;
5696 signal_num = DAMAGE_EVENT;
5699 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5703 if (signal_num != -1)
5704 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5706 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5707 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5711 g_object_unref (widget);
5717 * gtk_widget_activate:
5718 * @widget: a #GtkWidget that's activatable
5720 * For widgets that can be "activated" (buttons, menu items, etc.)
5721 * this function activates them. Activation is what happens when you
5722 * press Enter on a widget during key navigation. If @widget isn't
5723 * activatable, the function returns %FALSE.
5725 * Return value: %TRUE if the widget was activatable
5728 gtk_widget_activate (GtkWidget *widget)
5730 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5732 if (WIDGET_CLASS (widget)->activate_signal)
5734 /* FIXME: we should eventually check the signals signature here */
5735 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5744 * gtk_widget_set_scroll_adjustments:
5745 * @widget: a #GtkWidget
5746 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5747 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5749 * For widgets that support scrolling, sets the scroll adjustments and
5750 * returns %TRUE. For widgets that don't support scrolling, does
5751 * nothing and returns %FALSE. Widgets that don't support scrolling
5752 * can be scrolled by placing them in a #GtkViewport, which does
5753 * support scrolling.
5755 * Return value: %TRUE if the widget supports scrolling
5758 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5759 GtkAdjustment *hadjustment,
5760 GtkAdjustment *vadjustment)
5765 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5768 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5770 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5772 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5776 g_signal_query (signal_id, &query);
5777 if (!query.signal_id ||
5778 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5779 query.return_type != G_TYPE_NONE ||
5780 query.n_params != 2 ||
5781 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5782 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5784 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5785 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5789 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5794 gtk_widget_reparent_subwindows (GtkWidget *widget,
5795 GdkWindow *new_window)
5797 GtkWidgetPrivate *priv = widget->priv;
5799 if (!gtk_widget_get_has_window (widget))
5801 GList *children = gdk_window_get_children (priv->window);
5804 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5806 GdkWindow *window = tmp_list->data;
5809 gdk_window_get_user_data (window, &child);
5810 while (child && child != widget)
5811 child = ((GtkWidget*) child)->priv->parent;
5814 gdk_window_reparent (window, new_window, 0, 0);
5817 g_list_free (children);
5822 GList *tmp_list, *children;
5824 parent = gdk_window_get_parent (priv->window);
5827 gdk_window_reparent (priv->window, new_window, 0, 0);
5830 children = gdk_window_get_children (parent);
5832 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5834 GdkWindow *window = tmp_list->data;
5837 gdk_window_get_user_data (window, &child);
5839 if (child == widget)
5840 gdk_window_reparent (window, new_window, 0, 0);
5843 g_list_free (children);
5849 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5850 gpointer client_data)
5852 GtkWidgetPrivate *priv = widget->priv;
5854 g_assert (client_data != NULL);
5856 if (!gtk_widget_get_has_window (widget))
5859 g_object_unref (priv->window);
5860 priv->window = (GdkWindow*) client_data;
5862 g_object_ref (priv->window);
5864 if (GTK_IS_CONTAINER (widget))
5865 gtk_container_forall (GTK_CONTAINER (widget),
5866 gtk_widget_reparent_fixup_child,
5872 * gtk_widget_reparent:
5873 * @widget: a #GtkWidget
5874 * @new_parent: a #GtkContainer to move the widget into
5876 * Moves a widget from one #GtkContainer to another, handling reference
5877 * count issues to avoid destroying the widget.
5880 gtk_widget_reparent (GtkWidget *widget,
5881 GtkWidget *new_parent)
5883 GtkWidgetPrivate *priv;
5885 g_return_if_fail (GTK_IS_WIDGET (widget));
5886 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5887 priv = widget->priv;
5888 g_return_if_fail (priv->parent != NULL);
5890 if (priv->parent != new_parent)
5892 /* First try to see if we can get away without unrealizing
5893 * the widget as we reparent it. if so we set a flag so
5894 * that gtk_widget_unparent doesn't unrealize widget
5896 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5897 priv->in_reparent = TRUE;
5899 g_object_ref (widget);
5900 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5901 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5902 g_object_unref (widget);
5904 if (priv->in_reparent)
5906 priv->in_reparent = FALSE;
5908 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5909 gtk_widget_reparent_fixup_child (widget,
5910 gtk_widget_get_parent_window (widget));
5913 g_object_notify (G_OBJECT (widget), "parent");
5918 * gtk_widget_intersect:
5919 * @widget: a #GtkWidget
5920 * @area: a rectangle
5921 * @intersection: rectangle to store intersection of @widget and @area
5923 * Computes the intersection of a @widget's area and @area, storing
5924 * the intersection in @intersection, and returns %TRUE if there was
5925 * an intersection. @intersection may be %NULL if you're only
5926 * interested in whether there was an intersection.
5928 * Return value: %TRUE if there was an intersection
5931 gtk_widget_intersect (GtkWidget *widget,
5932 const GdkRectangle *area,
5933 GdkRectangle *intersection)
5935 GtkWidgetPrivate *priv;
5940 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5941 g_return_val_if_fail (area != NULL, FALSE);
5943 priv = widget->priv;
5946 dest = intersection;
5950 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5952 if (return_val && intersection && gtk_widget_get_has_window (widget))
5954 intersection->x -= priv->allocation.x;
5955 intersection->y -= priv->allocation.y;
5962 * gtk_widget_region_intersect:
5963 * @widget: a #GtkWidget
5964 * @region: a #cairo_region_t, in the same coordinate system as
5965 * @widget->allocation. That is, relative to @widget->window
5966 * for %NO_WINDOW widgets; relative to the parent window
5967 * of @widget->window for widgets with their own window.
5968 * @returns: A newly allocated region holding the intersection of @widget
5969 * and @region. The coordinates of the return value are
5970 * relative to @widget->window for %NO_WINDOW widgets, and
5971 * relative to the parent window of @widget->window for
5972 * widgets with their own window.
5974 * Computes the intersection of a @widget's area and @region, returning
5975 * the intersection. The result may be empty, use cairo_region_is_empty() to
5979 gtk_widget_region_intersect (GtkWidget *widget,
5980 const cairo_region_t *region)
5983 cairo_region_t *dest;
5985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5986 g_return_val_if_fail (region != NULL, NULL);
5988 gtk_widget_get_allocation (widget, &rect);
5990 dest = cairo_region_create_rectangle (&rect);
5992 cairo_region_intersect (dest, region);
5998 * _gtk_widget_grab_notify:
5999 * @widget: a #GtkWidget
6000 * @was_grabbed: whether a grab is now in effect
6002 * Emits the #GtkWidget::grab-notify signal on @widget.
6007 _gtk_widget_grab_notify (GtkWidget *widget,
6008 gboolean was_grabbed)
6010 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
6014 * gtk_widget_grab_focus:
6015 * @widget: a #GtkWidget
6017 * Causes @widget to have the keyboard focus for the #GtkWindow it's
6018 * inside. @widget must be a focusable widget, such as a #GtkEntry;
6019 * something like #GtkFrame won't work.
6021 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
6022 * gtk_widget_set_can_focus() to modify that flag.
6024 * The widget also needs to be realized and mapped. This is indicated by the
6025 * related signals. Grabbing the focus immediately after creating the widget
6026 * will likely fail and cause critical warnings.
6029 gtk_widget_grab_focus (GtkWidget *widget)
6031 g_return_if_fail (GTK_IS_WIDGET (widget));
6033 if (!gtk_widget_is_sensitive (widget))
6036 g_object_ref (widget);
6037 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
6038 g_object_notify (G_OBJECT (widget), "has-focus");
6039 g_object_unref (widget);
6043 reset_focus_recurse (GtkWidget *widget,
6046 if (GTK_IS_CONTAINER (widget))
6048 GtkContainer *container;
6050 container = GTK_CONTAINER (widget);
6051 gtk_container_set_focus_child (container, NULL);
6053 gtk_container_foreach (container,
6054 reset_focus_recurse,
6060 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
6062 if (gtk_widget_get_can_focus (focus_widget))
6064 GtkWidget *toplevel;
6067 /* clear the current focus setting, break if the current widget
6068 * is the focus widget's parent, since containers above that will
6069 * be set by the next loop.
6071 toplevel = gtk_widget_get_toplevel (focus_widget);
6072 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
6074 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
6076 if (widget == focus_widget)
6078 /* We call _gtk_window_internal_set_focus() here so that the
6079 * toplevel window can request the focus if necessary.
6080 * This is needed when the toplevel is a GtkPlug
6082 if (!gtk_widget_has_focus (widget))
6083 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
6090 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
6092 widget = widget->priv->parent;
6093 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
6097 else if (toplevel != focus_widget)
6099 /* gtk_widget_grab_focus() operates on a tree without window...
6100 * actually, this is very questionable behaviour.
6103 gtk_container_foreach (GTK_CONTAINER (toplevel),
6104 reset_focus_recurse,
6108 /* now propagate the new focus up the widget tree and finally
6109 * set it on the window
6111 widget = focus_widget;
6112 while (widget->priv->parent)
6114 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
6115 widget = widget->priv->parent;
6117 if (GTK_IS_WINDOW (widget))
6118 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
6123 gtk_widget_real_query_tooltip (GtkWidget *widget,
6126 gboolean keyboard_tip,
6127 GtkTooltip *tooltip)
6129 gchar *tooltip_markup;
6130 gboolean has_tooltip;
6132 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
6133 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
6135 if (has_tooltip && tooltip_markup)
6137 gtk_tooltip_set_markup (tooltip, tooltip_markup);
6145 gtk_widget_real_show_help (GtkWidget *widget,
6146 GtkWidgetHelpType help_type)
6148 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
6150 _gtk_tooltip_toggle_keyboard_mode (widget);
6159 gtk_widget_real_focus (GtkWidget *widget,
6160 GtkDirectionType direction)
6162 if (!gtk_widget_get_can_focus (widget))
6165 if (!gtk_widget_is_focus (widget))
6167 gtk_widget_grab_focus (widget);
6175 gtk_widget_real_move_focus (GtkWidget *widget,
6176 GtkDirectionType direction)
6178 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6180 if (GTK_IS_WINDOW (toplevel) &&
6181 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
6183 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
6189 gtk_widget_real_keynav_failed (GtkWidget *widget,
6190 GtkDirectionType direction)
6192 gboolean cursor_only;
6196 case GTK_DIR_TAB_FORWARD:
6197 case GTK_DIR_TAB_BACKWARD:
6204 g_object_get (gtk_widget_get_settings (widget),
6205 "gtk-keynav-cursor-only", &cursor_only,
6212 gtk_widget_error_bell (widget);
6218 * gtk_widget_set_can_focus:
6219 * @widget: a #GtkWidget
6220 * @can_focus: whether or not @widget can own the input focus.
6222 * Specifies whether @widget can own the input focus. See
6223 * gtk_widget_grab_focus() for actually setting the input focus on a
6229 gtk_widget_set_can_focus (GtkWidget *widget,
6232 g_return_if_fail (GTK_IS_WIDGET (widget));
6234 if (widget->priv->can_focus != can_focus)
6236 widget->priv->can_focus = can_focus;
6238 gtk_widget_queue_resize (widget);
6239 g_object_notify (G_OBJECT (widget), "can-focus");
6244 * gtk_widget_get_can_focus:
6245 * @widget: a #GtkWidget
6247 * Determines whether @widget can own the input focus. See
6248 * gtk_widget_set_can_focus().
6250 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6255 gtk_widget_get_can_focus (GtkWidget *widget)
6257 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6259 return widget->priv->can_focus;
6263 * gtk_widget_has_focus:
6264 * @widget: a #GtkWidget
6266 * Determines if the widget has the global input focus. See
6267 * gtk_widget_is_focus() for the difference between having the global
6268 * input focus, and only having the focus within a toplevel.
6270 * Return value: %TRUE if the widget has the global input focus.
6275 gtk_widget_has_focus (GtkWidget *widget)
6277 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6279 return widget->priv->has_focus;
6283 * gtk_widget_is_focus:
6284 * @widget: a #GtkWidget
6286 * Determines if the widget is the focus widget within its
6287 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6288 * necessarily set; %HAS_FOCUS will only be set if the
6289 * toplevel widget additionally has the global input focus.)
6291 * Return value: %TRUE if the widget is the focus widget.
6294 gtk_widget_is_focus (GtkWidget *widget)
6296 GtkWidget *toplevel;
6298 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6300 toplevel = gtk_widget_get_toplevel (widget);
6302 if (GTK_IS_WINDOW (toplevel))
6303 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6309 * gtk_widget_set_can_default:
6310 * @widget: a #GtkWidget
6311 * @can_default: whether or not @widget can be a default widget.
6313 * Specifies whether @widget can be a default widget. See
6314 * gtk_widget_grab_default() for details about the meaning of
6320 gtk_widget_set_can_default (GtkWidget *widget,
6321 gboolean can_default)
6323 g_return_if_fail (GTK_IS_WIDGET (widget));
6325 if (widget->priv->can_default != can_default)
6327 widget->priv->can_default = can_default;
6329 gtk_widget_queue_resize (widget);
6330 g_object_notify (G_OBJECT (widget), "can-default");
6335 * gtk_widget_get_can_default:
6336 * @widget: a #GtkWidget
6338 * Determines whether @widget can be a default widget. See
6339 * gtk_widget_set_can_default().
6341 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6346 gtk_widget_get_can_default (GtkWidget *widget)
6348 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6350 return widget->priv->can_default;
6354 * gtk_widget_has_default:
6355 * @widget: a #GtkWidget
6357 * Determines whether @widget is the current default widget within its
6358 * toplevel. See gtk_widget_set_can_default().
6360 * Return value: %TRUE if @widget is the current default widget within
6361 * its toplevel, %FALSE otherwise
6366 gtk_widget_has_default (GtkWidget *widget)
6368 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6370 return widget->priv->has_default;
6374 _gtk_widget_set_has_default (GtkWidget *widget,
6375 gboolean has_default)
6377 widget->priv->has_default = has_default;
6381 * gtk_widget_grab_default:
6382 * @widget: a #GtkWidget
6384 * Causes @widget to become the default widget. @widget must have the
6385 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6386 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6387 * %TRUE)</literal>. The default widget is activated when
6388 * the user presses Enter in a window. Default widgets must be
6389 * activatable, that is, gtk_widget_activate() should affect them. Note
6390 * that #GtkEntry widgets require the "activates-default" property
6391 * set to %TRUE before they activate the default widget when Enter
6392 * is pressed and the #GtkEntry is focused.
6395 gtk_widget_grab_default (GtkWidget *widget)
6399 g_return_if_fail (GTK_IS_WIDGET (widget));
6400 g_return_if_fail (gtk_widget_get_can_default (widget));
6402 window = gtk_widget_get_toplevel (widget);
6404 if (window && gtk_widget_is_toplevel (window))
6405 gtk_window_set_default (GTK_WINDOW (window), widget);
6407 g_warning (G_STRLOC ": widget not within a GtkWindow");
6411 * gtk_widget_set_receives_default:
6412 * @widget: a #GtkWidget
6413 * @receives_default: whether or not @widget can be a default widget.
6415 * Specifies whether @widget will be treated as the default widget
6416 * within its toplevel when it has the focus, even if another widget
6419 * See gtk_widget_grab_default() for details about the meaning of
6425 gtk_widget_set_receives_default (GtkWidget *widget,
6426 gboolean receives_default)
6428 g_return_if_fail (GTK_IS_WIDGET (widget));
6430 if (widget->priv->receives_default != receives_default)
6432 widget->priv->receives_default = receives_default;
6434 g_object_notify (G_OBJECT (widget), "receives-default");
6439 * gtk_widget_get_receives_default:
6440 * @widget: a #GtkWidget
6442 * Determines whether @widget is alyways treated as default widget
6443 * withing its toplevel when it has the focus, even if another widget
6446 * See gtk_widget_set_receives_default().
6448 * Return value: %TRUE if @widget acts as default widget when focussed,
6454 gtk_widget_get_receives_default (GtkWidget *widget)
6456 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6458 return widget->priv->receives_default;
6462 * gtk_widget_has_grab:
6463 * @widget: a #GtkWidget
6465 * Determines whether the widget is currently grabbing events, so it
6466 * is the only widget receiving input events (keyboard and mouse).
6468 * See also gtk_grab_add().
6470 * Return value: %TRUE if the widget is in the grab_widgets stack
6475 gtk_widget_has_grab (GtkWidget *widget)
6477 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6479 return widget->priv->has_grab;
6483 _gtk_widget_set_has_grab (GtkWidget *widget,
6486 widget->priv->has_grab = has_grab;
6490 * gtk_widget_device_is_shadowed:
6491 * @widget: a #GtkWidget
6492 * @device: a #GdkDevice
6494 * Returns %TRUE if @device has been shadowed by a GTK+
6495 * device grab on another widget, so it would stop sending
6496 * events to @widget. This may be used in the
6497 * #GtkWidget::grab-notify signal to check for specific
6498 * devices. See gtk_device_grab_add().
6500 * Returns: %TRUE if there is an ongoing grab on @device
6501 * by another #GtkWidget than @widget.
6506 gtk_widget_device_is_shadowed (GtkWidget *widget,
6509 GtkWindowGroup *group;
6510 GtkWidget *grab_widget, *toplevel;
6512 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6513 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6515 if (!gtk_widget_get_realized (widget))
6518 toplevel = gtk_widget_get_toplevel (widget);
6520 if (GTK_IS_WINDOW (toplevel))
6521 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6523 group = gtk_window_get_group (NULL);
6525 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6527 /* Widget not inside the hierarchy of grab_widget */
6529 widget != grab_widget &&
6530 !gtk_widget_is_ancestor (widget, grab_widget))
6533 grab_widget = gtk_window_group_get_current_grab (group);
6534 if (grab_widget && widget != grab_widget &&
6535 !gtk_widget_is_ancestor (widget, grab_widget))
6542 * gtk_widget_set_name:
6543 * @widget: a #GtkWidget
6544 * @name: name for the widget
6546 * Widgets can be named, which allows you to refer to them from a
6547 * gtkrc file. You can apply a style to widgets with a particular name
6548 * in the gtkrc file. See the documentation for gtkrc files (on the
6549 * same page as the docs for #GtkRcStyle).
6551 * Note that widget names are separated by periods in paths (see
6552 * gtk_widget_path()), so names with embedded periods may cause confusion.
6555 gtk_widget_set_name (GtkWidget *widget,
6558 GtkWidgetPrivate *priv;
6561 g_return_if_fail (GTK_IS_WIDGET (widget));
6563 priv = widget->priv;
6565 new_name = g_strdup (name);
6566 g_free (priv->name);
6567 priv->name = new_name;
6570 gtk_widget_reset_rc_style (widget);
6572 g_object_notify (G_OBJECT (widget), "name");
6576 * gtk_widget_get_name:
6577 * @widget: a #GtkWidget
6579 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6580 * significance of widget names.
6582 * Return value: name of the widget. This string is owned by GTK+ and
6583 * should not be modified or freed
6585 G_CONST_RETURN gchar*
6586 gtk_widget_get_name (GtkWidget *widget)
6588 GtkWidgetPrivate *priv;
6590 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6592 priv = widget->priv;
6596 return G_OBJECT_TYPE_NAME (widget);
6600 * gtk_widget_set_state:
6601 * @widget: a #GtkWidget
6602 * @state: new state for @widget
6604 * This function is for use in widget implementations. Sets the state
6605 * of a widget (insensitive, prelighted, etc.) Usually you should set
6606 * the state using wrapper functions such as gtk_widget_set_sensitive().
6609 gtk_widget_set_state (GtkWidget *widget,
6612 GtkWidgetPrivate *priv;
6614 g_return_if_fail (GTK_IS_WIDGET (widget));
6616 priv = widget->priv;
6618 if (state == gtk_widget_get_state (widget))
6621 if (state == GTK_STATE_INSENSITIVE)
6622 gtk_widget_set_sensitive (widget, FALSE);
6628 data.state_restoration = FALSE;
6629 data.use_forall = FALSE;
6631 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6633 data.parent_sensitive = TRUE;
6635 gtk_widget_propagate_state (widget, &data);
6637 if (gtk_widget_is_drawable (widget))
6638 gtk_widget_queue_draw (widget);
6643 * gtk_widget_get_state:
6644 * @widget: a #GtkWidget
6646 * Returns the widget's state. See gtk_widget_set_state().
6648 * Returns: the state of @widget.
6653 gtk_widget_get_state (GtkWidget *widget)
6655 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6657 return widget->priv->state;
6661 * gtk_widget_set_visible:
6662 * @widget: a #GtkWidget
6663 * @visible: whether the widget should be shown or not
6665 * Sets the visibility state of @widget. Note that setting this to
6666 * %TRUE doesn't mean the widget is actually viewable, see
6667 * gtk_widget_get_visible().
6669 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6670 * but is nicer to use when the visibility of the widget depends on
6676 gtk_widget_set_visible (GtkWidget *widget,
6679 g_return_if_fail (GTK_IS_WIDGET (widget));
6681 if (visible != gtk_widget_get_visible (widget))
6684 gtk_widget_show (widget);
6686 gtk_widget_hide (widget);
6691 _gtk_widget_set_visible_flag (GtkWidget *widget,
6694 widget->priv->visible = visible;
6698 * gtk_widget_get_visible:
6699 * @widget: a #GtkWidget
6701 * Determines whether the widget is visible. Note that this doesn't
6702 * take into account whether the widget's parent is also visible
6703 * or the widget is obscured in any way.
6705 * See gtk_widget_set_visible().
6707 * Return value: %TRUE if the widget is visible
6712 gtk_widget_get_visible (GtkWidget *widget)
6714 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6716 return widget->priv->visible;
6720 * gtk_widget_set_has_window:
6721 * @widget: a #GtkWidget
6722 * @has_window: whether or not @widget has a window.
6724 * Specifies whether @widget has a #GdkWindow of its own. Note that
6725 * all realized widgets have a non-%NULL "window" pointer
6726 * (gtk_widget_get_window() never returns a %NULL window when a widget
6727 * is realized), but for many of them it's actually the #GdkWindow of
6728 * one of its parent widgets. Widgets that do not create a %window for
6729 * themselves in GtkWidget::realize() must announce this by
6730 * calling this function with @has_window = %FALSE.
6732 * This function should only be called by widget implementations,
6733 * and they should call it in their init() function.
6738 gtk_widget_set_has_window (GtkWidget *widget,
6739 gboolean has_window)
6741 g_return_if_fail (GTK_IS_WIDGET (widget));
6743 widget->priv->no_window = !has_window;
6747 * gtk_widget_get_has_window:
6748 * @widget: a #GtkWidget
6750 * Determines whether @widget has a #GdkWindow of its own. See
6751 * gtk_widget_set_has_window().
6753 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6758 gtk_widget_get_has_window (GtkWidget *widget)
6760 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6762 return ! widget->priv->no_window;
6766 * gtk_widget_is_toplevel:
6767 * @widget: a #GtkWidget
6769 * Determines whether @widget is a toplevel widget. Currently only
6770 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6771 * widgets have no parent widget.
6773 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6778 gtk_widget_is_toplevel (GtkWidget *widget)
6780 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6782 return widget->priv->toplevel;
6786 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6787 gboolean is_toplevel)
6789 widget->priv->toplevel = is_toplevel;
6793 * gtk_widget_is_drawable:
6794 * @widget: a #GtkWidget
6796 * Determines whether @widget can be drawn to. A widget can be drawn
6797 * to if it is mapped and visible.
6799 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6804 gtk_widget_is_drawable (GtkWidget *widget)
6806 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6808 return (gtk_widget_get_visible (widget) &&
6809 gtk_widget_get_mapped (widget));
6813 * gtk_widget_get_realized:
6814 * @widget: a #GtkWidget
6816 * Determines whether @widget is realized.
6818 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6823 gtk_widget_get_realized (GtkWidget *widget)
6825 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6827 return widget->priv->realized;
6831 * gtk_widget_set_realized:
6832 * @widget: a #GtkWidget
6833 * @realized: %TRUE to mark the widget as realized
6835 * Marks the widget as being realized.
6837 * This function should only ever be called in a derived widget's
6838 * "realize" or "unrealize" implementation.
6843 gtk_widget_set_realized (GtkWidget *widget,
6846 g_return_if_fail (GTK_IS_WIDGET (widget));
6848 widget->priv->realized = realized;
6852 * gtk_widget_get_mapped:
6853 * @widget: a #GtkWidget
6855 * Whether the widget is mapped.
6857 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6862 gtk_widget_get_mapped (GtkWidget *widget)
6864 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6866 return widget->priv->mapped;
6870 * gtk_widget_set_mapped:
6871 * @widget: a #GtkWidget
6872 * @mapped: %TRUE to mark the widget as mapped
6874 * Marks the widget as being realized.
6876 * This function should only ever be called in a derived widget's
6877 * "map" or "unmap" implementation.
6882 gtk_widget_set_mapped (GtkWidget *widget,
6885 g_return_if_fail (GTK_IS_WIDGET (widget));
6887 widget->priv->mapped = mapped;
6891 * gtk_widget_set_app_paintable:
6892 * @widget: a #GtkWidget
6893 * @app_paintable: %TRUE if the application will paint on the widget
6895 * Sets whether the application intends to draw on the widget in
6896 * an #GtkWidget::draw handler.
6898 * This is a hint to the widget and does not affect the behavior of
6899 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6900 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6901 * the effect is to suppress default themed drawing of the widget's
6902 * background. (Children of the widget will still be drawn.) The application
6903 * is then entirely responsible for drawing the widget background.
6905 * Note that the background is still drawn when the widget is mapped.
6908 gtk_widget_set_app_paintable (GtkWidget *widget,
6909 gboolean app_paintable)
6911 g_return_if_fail (GTK_IS_WIDGET (widget));
6913 app_paintable = (app_paintable != FALSE);
6915 if (widget->priv->app_paintable != app_paintable)
6917 widget->priv->app_paintable = app_paintable;
6919 if (gtk_widget_is_drawable (widget))
6920 gtk_widget_queue_draw (widget);
6922 g_object_notify (G_OBJECT (widget), "app-paintable");
6927 * gtk_widget_get_app_paintable:
6928 * @widget: a #GtkWidget
6930 * Determines whether the application intends to draw on the widget in
6931 * an #GtkWidget::draw handler.
6933 * See gtk_widget_set_app_paintable()
6935 * Return value: %TRUE if the widget is app paintable
6940 gtk_widget_get_app_paintable (GtkWidget *widget)
6942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6944 return widget->priv->app_paintable;
6948 * gtk_widget_set_double_buffered:
6949 * @widget: a #GtkWidget
6950 * @double_buffered: %TRUE to double-buffer a widget
6952 * Widgets are double buffered by default; you can use this function
6953 * to turn off the buffering. "Double buffered" simply means that
6954 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6955 * automatically around expose events sent to the
6956 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6957 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6958 * buffer to the screen. The result is that users see the window
6959 * update in one smooth step, and don't see individual graphics
6960 * primitives being rendered.
6962 * In very simple terms, double buffered widgets don't flicker,
6963 * so you would only use this function to turn off double buffering
6964 * if you had special needs and really knew what you were doing.
6966 * Note: if you turn off double-buffering, you have to handle
6967 * expose events, since even the clearing to the background color or
6968 * pixmap will not happen automatically (as it is done in
6969 * gdk_window_begin_paint()).
6972 gtk_widget_set_double_buffered (GtkWidget *widget,
6973 gboolean double_buffered)
6975 g_return_if_fail (GTK_IS_WIDGET (widget));
6977 double_buffered = (double_buffered != FALSE);
6979 if (widget->priv->double_buffered != double_buffered)
6981 widget->priv->double_buffered = double_buffered;
6983 g_object_notify (G_OBJECT (widget), "double-buffered");
6988 * gtk_widget_get_double_buffered:
6989 * @widget: a #GtkWidget
6991 * Determines whether the widget is double buffered.
6993 * See gtk_widget_set_double_buffered()
6995 * Return value: %TRUE if the widget is double buffered
7000 gtk_widget_get_double_buffered (GtkWidget *widget)
7002 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7004 return widget->priv->double_buffered;
7008 * gtk_widget_set_redraw_on_allocate:
7009 * @widget: a #GtkWidget
7010 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
7011 * when it is allocated to a new size. Otherwise, only the
7012 * new portion of the widget will be redrawn.
7014 * Sets whether the entire widget is queued for drawing when its size
7015 * allocation changes. By default, this setting is %TRUE and
7016 * the entire widget is redrawn on every size change. If your widget
7017 * leaves the upper left unchanged when made bigger, turning this
7018 * setting off will improve performance.
7020 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
7021 * off all allocation on resizing: the widget will not even redraw if
7022 * its position changes; this is to allow containers that don't draw
7023 * anything to avoid excess invalidations. If you set this flag on a
7024 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
7025 * you are responsible for invalidating both the old and new allocation
7026 * of the widget when the widget is moved and responsible for invalidating
7027 * regions newly when the widget increases size.
7030 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
7031 gboolean redraw_on_allocate)
7033 g_return_if_fail (GTK_IS_WIDGET (widget));
7035 widget->priv->redraw_on_alloc = redraw_on_allocate;
7039 * gtk_widget_set_sensitive:
7040 * @widget: a #GtkWidget
7041 * @sensitive: %TRUE to make the widget sensitive
7043 * Sets the sensitivity of a widget. A widget is sensitive if the user
7044 * can interact with it. Insensitive widgets are "grayed out" and the
7045 * user can't interact with them. Insensitive widgets are known as
7046 * "inactive", "disabled", or "ghosted" in some other toolkits.
7049 gtk_widget_set_sensitive (GtkWidget *widget,
7052 GtkWidgetPrivate *priv;
7055 g_return_if_fail (GTK_IS_WIDGET (widget));
7057 priv = widget->priv;
7059 sensitive = (sensitive != FALSE);
7061 if (widget->priv->sensitive == sensitive)
7066 widget->priv->sensitive = TRUE;
7067 data.state = priv->saved_state;
7071 widget->priv->sensitive = FALSE;
7072 data.state = gtk_widget_get_state (widget);
7074 data.state_restoration = TRUE;
7075 data.use_forall = TRUE;
7078 data.parent_sensitive = gtk_widget_is_sensitive (priv->parent);
7080 data.parent_sensitive = TRUE;
7082 gtk_widget_propagate_state (widget, &data);
7083 if (gtk_widget_is_drawable (widget))
7084 gtk_widget_queue_draw (widget);
7086 g_object_notify (G_OBJECT (widget), "sensitive");
7090 * gtk_widget_get_sensitive:
7091 * @widget: a #GtkWidget
7093 * Returns the widget's sensitivity (in the sense of returning
7094 * the value that has been set using gtk_widget_set_sensitive()).
7096 * The effective sensitivity of a widget is however determined by both its
7097 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
7099 * Returns: %TRUE if the widget is sensitive
7104 gtk_widget_get_sensitive (GtkWidget *widget)
7106 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7108 return widget->priv->sensitive;
7112 * gtk_widget_is_sensitive:
7113 * @widget: a #GtkWidget
7115 * Returns the widget's effective sensitivity, which means
7116 * it is sensitive itself and also its parent widget is sensntive
7118 * Returns: %TRUE if the widget is effectively sensitive
7123 gtk_widget_is_sensitive (GtkWidget *widget)
7125 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7127 return widget->priv->sensitive && widget->priv->parent_sensitive;
7131 * gtk_widget_set_parent:
7132 * @widget: a #GtkWidget
7133 * @parent: parent container
7135 * This function is useful only when implementing subclasses of
7137 * Sets the container as the parent of @widget, and takes care of
7138 * some details such as updating the state and style of the child
7139 * to reflect its new location. The opposite function is
7140 * gtk_widget_unparent().
7143 gtk_widget_set_parent (GtkWidget *widget,
7146 GtkWidgetPrivate *priv;
7149 g_return_if_fail (GTK_IS_WIDGET (widget));
7150 g_return_if_fail (GTK_IS_WIDGET (parent));
7151 g_return_if_fail (widget != parent);
7153 priv = widget->priv;
7155 if (priv->parent != NULL)
7157 g_warning ("Can't set a parent on widget which has a parent\n");
7160 if (gtk_widget_is_toplevel (widget))
7162 g_warning ("Can't set a parent on a toplevel widget\n");
7166 /* keep this function in sync with gtk_menu_attach_to_widget()
7169 g_object_ref_sink (widget);
7170 priv->parent = parent;
7172 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7173 data.state = gtk_widget_get_state (parent);
7175 data.state = gtk_widget_get_state (widget);
7176 data.state_restoration = FALSE;
7177 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7178 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7180 gtk_widget_propagate_state (widget, &data);
7182 gtk_widget_reset_rc_styles (widget);
7184 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7185 if (priv->parent->priv->anchored)
7186 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7187 g_object_notify (G_OBJECT (widget), "parent");
7189 /* Enforce realized/mapped invariants
7191 if (gtk_widget_get_realized (priv->parent))
7192 gtk_widget_realize (widget);
7194 if (gtk_widget_get_visible (priv->parent) &&
7195 gtk_widget_get_visible (widget))
7197 if (gtk_widget_get_child_visible (widget) &&
7198 gtk_widget_get_mapped (priv->parent))
7199 gtk_widget_map (widget);
7201 gtk_widget_queue_resize (widget);
7206 * gtk_widget_get_parent:
7207 * @widget: a #GtkWidget
7209 * Returns the parent container of @widget.
7211 * Return value: (transfer none): the parent container of @widget, or %NULL
7214 gtk_widget_get_parent (GtkWidget *widget)
7216 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7218 return widget->priv->parent;
7221 /*****************************************
7223 * see docs/styles.txt
7224 *****************************************/
7227 * gtk_widget_style_attach:
7228 * @widget: a #GtkWidget
7230 * This function attaches the widget's #GtkStyle to the widget's
7231 * #GdkWindow. It is a replacement for
7234 * widget->style = gtk_style_attach (widget->style, widget->window);
7237 * and should only ever be called in a derived widget's "realize"
7238 * implementation which does not chain up to its parent class'
7239 * "realize" implementation, because one of the parent classes
7240 * (finally #GtkWidget) would attach the style itself.
7245 gtk_widget_style_attach (GtkWidget *widget)
7247 GtkWidgetPrivate *priv;
7249 g_return_if_fail (GTK_IS_WIDGET (widget));
7250 g_return_if_fail (gtk_widget_get_realized (widget));
7252 priv = widget->priv;
7254 priv->style = gtk_style_attach (priv->style, priv->window);
7258 * gtk_widget_has_rc_style:
7259 * @widget: a #GtkWidget
7261 * Determines if the widget style has been looked up through the rc mechanism.
7263 * Returns: %TRUE if the widget has been looked up through the rc
7264 * mechanism, %FALSE otherwise.
7269 gtk_widget_has_rc_style (GtkWidget *widget)
7271 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7273 return widget->priv->rc_style;
7277 * gtk_widget_set_style:
7278 * @widget: a #GtkWidget
7279 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7280 * gtk_widget_set_style() and go back to the default style
7282 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7283 * want to use this function; it interacts badly with themes, because
7284 * themes work by replacing the #GtkStyle. Instead, use
7285 * gtk_widget_modify_style().
7288 gtk_widget_set_style (GtkWidget *widget,
7291 g_return_if_fail (GTK_IS_WIDGET (widget));
7295 gboolean initial_emission;
7297 initial_emission = !widget->priv->rc_style && !widget->priv->user_style;
7299 widget->priv->rc_style = FALSE;
7300 widget->priv->user_style = TRUE;
7302 gtk_widget_set_style_internal (widget, style, initial_emission);
7306 if (widget->priv->user_style)
7307 gtk_widget_reset_rc_style (widget);
7312 * gtk_widget_ensure_style:
7313 * @widget: a #GtkWidget
7315 * Ensures that @widget has a style (@widget->style). Not a very useful
7316 * function; most of the time, if you want the style, the widget is
7317 * realized, and realized widgets are guaranteed to have a style
7321 gtk_widget_ensure_style (GtkWidget *widget)
7323 g_return_if_fail (GTK_IS_WIDGET (widget));
7325 if (!widget->priv->rc_style && !widget->priv->user_style)
7326 gtk_widget_reset_rc_style (widget);
7329 /* Look up the RC style for this widget, unsetting any user style that
7330 * may be in effect currently
7333 gtk_widget_reset_rc_style (GtkWidget *widget)
7335 GtkWidgetPrivate *priv = widget->priv;
7336 GtkStyle *new_style = NULL;
7337 gboolean initial_emission;
7339 initial_emission = !priv->rc_style && !priv->user_style;
7341 priv->user_style = FALSE;
7342 priv->rc_style = TRUE;
7344 if (gtk_widget_has_screen (widget))
7345 new_style = gtk_rc_get_style (widget);
7347 new_style = gtk_widget_get_default_style ();
7349 if (initial_emission || new_style != priv->style)
7350 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7354 * gtk_widget_get_style:
7355 * @widget: a #GtkWidget
7357 * Simply an accessor function that returns @widget->style.
7359 * Return value: (transfer none): the widget's #GtkStyle
7362 gtk_widget_get_style (GtkWidget *widget)
7364 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7366 return widget->priv->style;
7370 * gtk_widget_modify_style:
7371 * @widget: a #GtkWidget
7372 * @style: the #GtkRcStyle holding the style modifications
7374 * Modifies style values on the widget. Modifications made using this
7375 * technique take precedence over style values set via an RC file,
7376 * however, they will be overriden if a style is explicitely set on
7377 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7378 * is designed so each field can either be set or unset, so it is
7379 * possible, using this function, to modify some style values and
7380 * leave the others unchanged.
7382 * Note that modifications made with this function are not cumulative
7383 * with previous calls to gtk_widget_modify_style() or with such
7384 * functions as gtk_widget_modify_fg(). If you wish to retain
7385 * previous values, you must first call gtk_widget_get_modifier_style(),
7386 * make your modifications to the returned style, then call
7387 * gtk_widget_modify_style() with that style. On the other hand,
7388 * if you first call gtk_widget_modify_style(), subsequent calls
7389 * to such functions gtk_widget_modify_fg() will have a cumulative
7390 * effect with the initial modifications.
7393 gtk_widget_modify_style (GtkWidget *widget,
7396 g_return_if_fail (GTK_IS_WIDGET (widget));
7397 g_return_if_fail (GTK_IS_RC_STYLE (style));
7399 g_object_set_qdata_full (G_OBJECT (widget),
7401 gtk_rc_style_copy (style),
7402 (GDestroyNotify) g_object_unref);
7404 /* note that "style" may be invalid here if it was the old
7405 * modifier style and the only reference was our own.
7408 if (widget->priv->rc_style)
7409 gtk_widget_reset_rc_style (widget);
7413 * gtk_widget_get_modifier_style:
7414 * @widget: a #GtkWidget
7416 * Returns the current modifier style for the widget. (As set by
7417 * gtk_widget_modify_style().) If no style has previously set, a new
7418 * #GtkRcStyle will be created with all values unset, and set as the
7419 * modifier style for the widget. If you make changes to this rc
7420 * style, you must call gtk_widget_modify_style(), passing in the
7421 * returned rc style, to make sure that your changes take effect.
7423 * Caution: passing the style back to gtk_widget_modify_style() will
7424 * normally end up destroying it, because gtk_widget_modify_style() copies
7425 * the passed-in style and sets the copy as the new modifier style,
7426 * thus dropping any reference to the old modifier style. Add a reference
7427 * to the modifier style if you want to keep it alive.
7429 * Return value: (transfer none): the modifier style for the widget. This rc style is
7430 * owned by the widget. If you want to keep a pointer to value this
7431 * around, you must add a refcount using g_object_ref().
7434 gtk_widget_get_modifier_style (GtkWidget *widget)
7436 GtkRcStyle *rc_style;
7438 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7440 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7444 rc_style = gtk_rc_style_new ();
7445 g_object_set_qdata_full (G_OBJECT (widget),
7448 (GDestroyNotify) g_object_unref);
7455 gtk_widget_modify_color_component (GtkWidget *widget,
7456 GtkRcFlags component,
7458 const GdkColor *color)
7460 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7467 rc_style->fg[state] = *color;
7470 rc_style->bg[state] = *color;
7473 rc_style->text[state] = *color;
7476 rc_style->base[state] = *color;
7479 g_assert_not_reached();
7482 rc_style->color_flags[state] |= component;
7485 rc_style->color_flags[state] &= ~component;
7487 gtk_widget_modify_style (widget, rc_style);
7491 * gtk_widget_modify_symbolic_color:
7492 * @widget: a #GtkWidget
7493 * @name: the name of the symbolic color to modify
7494 * @color: (allow-none): the color to assign (does not need to be allocated),
7495 * or %NULL to undo the effect of previous calls to
7496 * of gtk_widget_modify_symbolic_color().
7498 * Sets a symbolic color for a widget.
7499 * All other style values are left untouched. See also
7500 * gtk_widget_modify_style().
7505 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7507 const GdkColor *color)
7509 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7511 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7513 gtk_widget_modify_style (widget, rc_style);
7517 * gtk_widget_modify_fg:
7518 * @widget: a #GtkWidget
7519 * @state: the state for which to set the foreground color
7520 * @color: (allow-none): the color to assign (does not need to be allocated),
7521 * or %NULL to undo the effect of previous calls to
7522 * of gtk_widget_modify_fg().
7524 * Sets the foreground color for a widget in a particular state.
7525 * All other style values are left untouched. See also
7526 * gtk_widget_modify_style().
7529 gtk_widget_modify_fg (GtkWidget *widget,
7531 const GdkColor *color)
7533 g_return_if_fail (GTK_IS_WIDGET (widget));
7534 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7536 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7540 * gtk_widget_modify_bg:
7541 * @widget: a #GtkWidget
7542 * @state: the state for which to set the background color
7543 * @color: (allow-none): the color to assign (does not need to be allocated),
7544 * or %NULL to undo the effect of previous calls to
7545 * of gtk_widget_modify_bg().
7547 * Sets the background color for a widget in a particular state.
7548 * All other style values are left untouched. See also
7549 * gtk_widget_modify_style().
7551 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7552 * draw on their parent container's window and thus may not draw any
7553 * background themselves. This is the case for e.g. #GtkLabel. To modify
7554 * the background of such widgets, you have to set the background color
7555 * on their parent; if you want to set the background of a rectangular
7556 * area around a label, try placing the label in a #GtkEventBox widget
7557 * and setting the background color on that.
7560 gtk_widget_modify_bg (GtkWidget *widget,
7562 const GdkColor *color)
7564 g_return_if_fail (GTK_IS_WIDGET (widget));
7565 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7567 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7571 * gtk_widget_modify_text:
7572 * @widget: a #GtkWidget
7573 * @state: the state for which to set the text color
7574 * @color: (allow-none): the color to assign (does not need to be allocated),
7575 * or %NULL to undo the effect of previous calls to
7576 * of gtk_widget_modify_text().
7578 * Sets the text color for a widget in a particular state. All other
7579 * style values are left untouched. The text color is the foreground
7580 * color used along with the base color (see gtk_widget_modify_base())
7581 * for widgets such as #GtkEntry and #GtkTextView. See also
7582 * gtk_widget_modify_style().
7585 gtk_widget_modify_text (GtkWidget *widget,
7587 const GdkColor *color)
7589 g_return_if_fail (GTK_IS_WIDGET (widget));
7590 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7592 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7596 * gtk_widget_modify_base:
7597 * @widget: a #GtkWidget
7598 * @state: the state for which to set the base color
7599 * @color: (allow-none): the color to assign (does not need to be allocated),
7600 * or %NULL to undo the effect of previous calls to
7601 * of gtk_widget_modify_base().
7603 * Sets the base color for a widget in a particular state.
7604 * All other style values are left untouched. The base color
7605 * is the background color used along with the text color
7606 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7607 * and #GtkTextView. See also gtk_widget_modify_style().
7609 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7610 * draw on their parent container's window and thus may not draw any
7611 * background themselves. This is the case for e.g. #GtkLabel. To modify
7612 * the background of such widgets, you have to set the base color on their
7613 * parent; if you want to set the background of a rectangular area around
7614 * a label, try placing the label in a #GtkEventBox widget and setting
7615 * the base color on that.
7618 gtk_widget_modify_base (GtkWidget *widget,
7620 const GdkColor *color)
7622 g_return_if_fail (GTK_IS_WIDGET (widget));
7623 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7625 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7629 modify_color_property (GtkWidget *widget,
7630 GtkRcStyle *rc_style,
7632 const GdkColor *color)
7634 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7635 GQuark property_name = g_quark_from_string (name);
7639 GtkRcProperty rc_property = {0};
7642 rc_property.type_name = type_name;
7643 rc_property.property_name = property_name;
7644 rc_property.origin = NULL;
7646 color_name = gdk_color_to_string (color);
7647 g_value_init (&rc_property.value, G_TYPE_STRING);
7648 g_value_take_string (&rc_property.value, color_name);
7650 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7652 g_value_unset (&rc_property.value);
7655 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7659 * gtk_widget_modify_cursor:
7660 * @widget: a #GtkWidget
7661 * @primary: the color to use for primary cursor (does not need to be
7662 * allocated), or %NULL to undo the effect of previous calls to
7663 * of gtk_widget_modify_cursor().
7664 * @secondary: the color to use for secondary cursor (does not need to be
7665 * allocated), or %NULL to undo the effect of previous calls to
7666 * of gtk_widget_modify_cursor().
7668 * Sets the cursor color to use in a widget, overriding the
7669 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7670 * style properties. All other style values are left untouched.
7671 * See also gtk_widget_modify_style().
7676 gtk_widget_modify_cursor (GtkWidget *widget,
7677 const GdkColor *primary,
7678 const GdkColor *secondary)
7680 GtkRcStyle *rc_style;
7682 g_return_if_fail (GTK_IS_WIDGET (widget));
7684 rc_style = gtk_widget_get_modifier_style (widget);
7686 modify_color_property (widget, rc_style, "cursor-color", primary);
7687 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7689 gtk_widget_modify_style (widget, rc_style);
7693 * gtk_widget_modify_font:
7694 * @widget: a #GtkWidget
7695 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7696 * the effect of previous calls to gtk_widget_modify_font().
7698 * Sets the font to use for a widget. All other style values are left
7699 * untouched. See also gtk_widget_modify_style().
7702 gtk_widget_modify_font (GtkWidget *widget,
7703 PangoFontDescription *font_desc)
7705 GtkRcStyle *rc_style;
7707 g_return_if_fail (GTK_IS_WIDGET (widget));
7709 rc_style = gtk_widget_get_modifier_style (widget);
7711 if (rc_style->font_desc)
7712 pango_font_description_free (rc_style->font_desc);
7715 rc_style->font_desc = pango_font_description_copy (font_desc);
7717 rc_style->font_desc = NULL;
7719 gtk_widget_modify_style (widget, rc_style);
7723 gtk_widget_real_direction_changed (GtkWidget *widget,
7724 GtkTextDirection previous_direction)
7726 gtk_widget_queue_resize (widget);
7730 gtk_widget_real_style_set (GtkWidget *widget,
7731 GtkStyle *previous_style)
7733 GtkWidgetPrivate *priv = widget->priv;
7735 if (gtk_widget_get_realized (widget) &&
7736 gtk_widget_get_has_window (widget))
7737 gtk_style_set_background (priv->style, priv->window, priv->state);
7741 gtk_widget_set_style_internal (GtkWidget *widget,
7743 gboolean initial_emission)
7745 GtkWidgetPrivate *priv = widget->priv;
7747 g_object_ref (widget);
7748 g_object_freeze_notify (G_OBJECT (widget));
7750 if (priv->style != style)
7752 GtkStyle *previous_style;
7754 if (gtk_widget_get_realized (widget))
7756 gtk_widget_reset_shapes (widget);
7757 gtk_style_detach (priv->style);
7760 previous_style = priv->style;
7761 priv->style = style;
7762 g_object_ref (priv->style);
7764 if (gtk_widget_get_realized (widget))
7765 priv->style = gtk_style_attach (priv->style, priv->window);
7767 gtk_widget_update_pango_context (widget);
7768 g_signal_emit (widget,
7769 widget_signals[STYLE_SET],
7771 initial_emission ? NULL : previous_style);
7772 g_object_unref (previous_style);
7774 if (priv->anchored && !initial_emission)
7775 gtk_widget_queue_resize (widget);
7777 else if (initial_emission)
7779 gtk_widget_update_pango_context (widget);
7780 g_signal_emit (widget,
7781 widget_signals[STYLE_SET],
7785 g_object_notify (G_OBJECT (widget), "style");
7786 g_object_thaw_notify (G_OBJECT (widget));
7787 g_object_unref (widget);
7791 GtkWidget *previous_toplevel;
7792 GdkScreen *previous_screen;
7793 GdkScreen *new_screen;
7794 } HierarchyChangedInfo;
7797 do_screen_change (GtkWidget *widget,
7798 GdkScreen *old_screen,
7799 GdkScreen *new_screen)
7801 if (old_screen != new_screen)
7805 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7807 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7810 _gtk_tooltip_hide (widget);
7811 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7816 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7817 gpointer client_data)
7819 GtkWidgetPrivate *priv = widget->priv;
7820 HierarchyChangedInfo *info = client_data;
7821 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7822 (priv->parent && priv->parent->priv->anchored);
7824 if (priv->anchored != new_anchored)
7826 g_object_ref (widget);
7828 priv->anchored = new_anchored;
7830 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7831 do_screen_change (widget, info->previous_screen, info->new_screen);
7833 if (GTK_IS_CONTAINER (widget))
7834 gtk_container_forall (GTK_CONTAINER (widget),
7835 gtk_widget_propagate_hierarchy_changed_recurse,
7838 g_object_unref (widget);
7843 * _gtk_widget_propagate_hierarchy_changed:
7844 * @widget: a #GtkWidget
7845 * @previous_toplevel: Previous toplevel
7847 * Propagates changes in the anchored state to a widget and all
7848 * children, unsetting or setting the %ANCHORED flag, and
7849 * emitting #GtkWidget::hierarchy-changed.
7852 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7853 GtkWidget *previous_toplevel)
7855 GtkWidgetPrivate *priv = widget->priv;
7856 HierarchyChangedInfo info;
7858 info.previous_toplevel = previous_toplevel;
7859 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7861 if (gtk_widget_is_toplevel (widget) ||
7862 (priv->parent && priv->parent->priv->anchored))
7863 info.new_screen = gtk_widget_get_screen (widget);
7865 info.new_screen = NULL;
7867 if (info.previous_screen)
7868 g_object_ref (info.previous_screen);
7869 if (previous_toplevel)
7870 g_object_ref (previous_toplevel);
7872 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7874 if (previous_toplevel)
7875 g_object_unref (previous_toplevel);
7876 if (info.previous_screen)
7877 g_object_unref (info.previous_screen);
7881 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7882 gpointer client_data)
7884 HierarchyChangedInfo *info = client_data;
7886 g_object_ref (widget);
7888 do_screen_change (widget, info->previous_screen, info->new_screen);
7890 if (GTK_IS_CONTAINER (widget))
7891 gtk_container_forall (GTK_CONTAINER (widget),
7892 gtk_widget_propagate_screen_changed_recurse,
7895 g_object_unref (widget);
7899 * gtk_widget_is_composited:
7900 * @widget: a #GtkWidget
7902 * Whether @widget can rely on having its alpha channel
7903 * drawn correctly. On X11 this function returns whether a
7904 * compositing manager is running for @widget's screen.
7906 * Please note that the semantics of this call will change
7907 * in the future if used on a widget that has a composited
7908 * window in its hierarchy (as set by gdk_window_set_composited()).
7910 * Return value: %TRUE if the widget can rely on its alpha
7911 * channel being drawn correctly.
7916 gtk_widget_is_composited (GtkWidget *widget)
7920 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7922 screen = gtk_widget_get_screen (widget);
7924 return gdk_screen_is_composited (screen);
7928 propagate_composited_changed (GtkWidget *widget,
7931 if (GTK_IS_CONTAINER (widget))
7933 gtk_container_forall (GTK_CONTAINER (widget),
7934 propagate_composited_changed,
7938 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7942 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7944 propagate_composited_changed (widget, NULL);
7948 * _gtk_widget_propagate_screen_changed:
7949 * @widget: a #GtkWidget
7950 * @previous_screen: Previous screen
7952 * Propagates changes in the screen for a widget to all
7953 * children, emitting #GtkWidget::screen-changed.
7956 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7957 GdkScreen *previous_screen)
7959 HierarchyChangedInfo info;
7961 info.previous_screen = previous_screen;
7962 info.new_screen = gtk_widget_get_screen (widget);
7964 if (previous_screen)
7965 g_object_ref (previous_screen);
7967 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7969 if (previous_screen)
7970 g_object_unref (previous_screen);
7974 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7976 if (widget->priv->rc_style)
7977 gtk_widget_reset_rc_style (widget);
7979 if (GTK_IS_CONTAINER (widget))
7980 gtk_container_forall (GTK_CONTAINER (widget),
7981 reset_rc_styles_recurse,
7987 * gtk_widget_reset_rc_styles:
7988 * @widget: a #GtkWidget.
7990 * Reset the styles of @widget and all descendents, so when
7991 * they are looked up again, they get the correct values
7992 * for the currently loaded RC file settings.
7994 * This function is not useful for applications.
7997 gtk_widget_reset_rc_styles (GtkWidget *widget)
7999 g_return_if_fail (GTK_IS_WIDGET (widget));
8001 reset_rc_styles_recurse (widget, NULL);
8005 * gtk_widget_get_default_style:
8007 * Returns the default style used by all widgets initially.
8009 * Returns: (transfer none): the default style. This #GtkStyle object is owned
8010 * by GTK+ and should not be modified or freed.
8013 gtk_widget_get_default_style (void)
8015 if (!gtk_default_style)
8017 gtk_default_style = gtk_style_new ();
8018 g_object_ref (gtk_default_style);
8021 return gtk_default_style;
8024 static PangoContext *
8025 gtk_widget_peek_pango_context (GtkWidget *widget)
8027 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8031 * gtk_widget_get_pango_context:
8032 * @widget: a #GtkWidget
8034 * Gets a #PangoContext with the appropriate font map, font description,
8035 * and base direction for this widget. Unlike the context returned
8036 * by gtk_widget_create_pango_context(), this context is owned by
8037 * the widget (it can be used until the screen for the widget changes
8038 * or the widget is removed from its toplevel), and will be updated to
8039 * match any changes to the widget's attributes.
8041 * If you create and keep a #PangoLayout using this context, you must
8042 * deal with changes to the context by calling pango_layout_context_changed()
8043 * on the layout in response to the #GtkWidget::style-set and
8044 * #GtkWidget::direction-changed signals for the widget.
8046 * Return value: (transfer none): the #PangoContext for the widget.
8049 gtk_widget_get_pango_context (GtkWidget *widget)
8051 PangoContext *context;
8053 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8055 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
8058 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
8059 g_object_set_qdata_full (G_OBJECT (widget),
8060 quark_pango_context,
8069 update_pango_context (GtkWidget *widget,
8070 PangoContext *context)
8072 GtkWidgetPrivate *priv = widget->priv;
8074 pango_context_set_font_description (context, priv->style->font_desc);
8075 pango_context_set_base_dir (context,
8076 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
8077 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
8081 gtk_widget_update_pango_context (GtkWidget *widget)
8083 PangoContext *context = gtk_widget_peek_pango_context (widget);
8089 update_pango_context (widget, context);
8091 screen = gtk_widget_get_screen_unchecked (widget);
8094 pango_cairo_context_set_resolution (context,
8095 gdk_screen_get_resolution (screen));
8096 pango_cairo_context_set_font_options (context,
8097 gdk_screen_get_font_options (screen));
8103 * gtk_widget_create_pango_context:
8104 * @widget: a #GtkWidget
8106 * Creates a new #PangoContext with the appropriate font map,
8107 * font description, and base direction for drawing text for
8108 * this widget. See also gtk_widget_get_pango_context().
8110 * Return value: (transfer full): the new #PangoContext
8113 gtk_widget_create_pango_context (GtkWidget *widget)
8116 PangoContext *context;
8118 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8120 screen = gtk_widget_get_screen_unchecked (widget);
8123 GTK_NOTE (MULTIHEAD,
8124 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
8126 screen = gdk_screen_get_default ();
8129 context = gdk_pango_context_get_for_screen (screen);
8131 update_pango_context (widget, context);
8132 pango_context_set_language (context, gtk_get_default_language ());
8138 * gtk_widget_create_pango_layout:
8139 * @widget: a #GtkWidget
8140 * @text: text to set on the layout (can be %NULL)
8142 * Creates a new #PangoLayout with the appropriate font map,
8143 * font description, and base direction for drawing text for
8146 * If you keep a #PangoLayout created in this way around, in order to
8147 * notify the layout of changes to the base direction or font of this
8148 * widget, you must call pango_layout_context_changed() in response to
8149 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8152 * Return value: (transfer full): the new #PangoLayout
8155 gtk_widget_create_pango_layout (GtkWidget *widget,
8158 PangoLayout *layout;
8159 PangoContext *context;
8161 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8163 context = gtk_widget_get_pango_context (widget);
8164 layout = pango_layout_new (context);
8167 pango_layout_set_text (layout, text, -1);
8173 * gtk_widget_render_icon:
8174 * @widget: a #GtkWidget
8175 * @stock_id: a stock ID
8176 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8177 * render at the size of the source and don't scale (if there are
8178 * multiple source sizes, GTK+ picks one of the available sizes).
8179 * @detail: (allow-none): render detail to pass to theme engine
8181 * A convenience function that uses the theme engine and RC file
8182 * settings for @widget to look up @stock_id and render it to
8183 * a pixbuf. @stock_id should be a stock icon ID such as
8184 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8185 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8186 * identifies the widget or code doing the rendering, so that
8187 * theme engines can special-case rendering for that widget or code.
8189 * The pixels in the returned #GdkPixbuf are shared with the rest of
8190 * the application and should not be modified. The pixbuf should be freed
8191 * after use with g_object_unref().
8193 * Return value: (transfer full): a new pixbuf, or %NULL if the
8194 * stock ID wasn't known
8197 gtk_widget_render_icon (GtkWidget *widget,
8198 const gchar *stock_id,
8200 const gchar *detail)
8202 GtkWidgetPrivate *priv;
8203 GtkIconSet *icon_set;
8206 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8207 g_return_val_if_fail (stock_id != NULL, NULL);
8208 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8210 priv = widget->priv;
8212 gtk_widget_ensure_style (widget);
8214 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8216 if (icon_set == NULL)
8219 retval = gtk_icon_set_render_icon (icon_set,
8221 gtk_widget_get_direction (widget),
8222 gtk_widget_get_state (widget),
8231 * gtk_widget_set_parent_window:
8232 * @widget: a #GtkWidget.
8233 * @parent_window: the new parent window.
8235 * Sets a non default parent window for @widget.
8238 gtk_widget_set_parent_window (GtkWidget *widget,
8239 GdkWindow *parent_window)
8241 GdkWindow *old_parent_window;
8243 g_return_if_fail (GTK_IS_WIDGET (widget));
8245 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8246 quark_parent_window);
8248 if (parent_window != old_parent_window)
8250 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8252 if (old_parent_window)
8253 g_object_unref (old_parent_window);
8255 g_object_ref (parent_window);
8260 * gtk_widget_get_parent_window:
8261 * @widget: a #GtkWidget.
8263 * Gets @widget's parent window.
8265 * Returns: (transfer none): the parent window of @widget.
8268 gtk_widget_get_parent_window (GtkWidget *widget)
8270 GtkWidgetPrivate *priv;
8271 GdkWindow *parent_window;
8273 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8275 priv = widget->priv;
8277 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8279 return (parent_window != NULL) ? parent_window :
8280 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8285 * gtk_widget_set_child_visible:
8286 * @widget: a #GtkWidget
8287 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8289 * Sets whether @widget should be mapped along with its when its parent
8290 * is mapped and @widget has been shown with gtk_widget_show().
8292 * The child visibility can be set for widget before it is added to
8293 * a container with gtk_widget_set_parent(), to avoid mapping
8294 * children unnecessary before immediately unmapping them. However
8295 * it will be reset to its default state of %TRUE when the widget
8296 * is removed from a container.
8298 * Note that changing the child visibility of a widget does not
8299 * queue a resize on the widget. Most of the time, the size of
8300 * a widget is computed from all visible children, whether or
8301 * not they are mapped. If this is not the case, the container
8302 * can queue a resize itself.
8304 * This function is only useful for container implementations and
8305 * never should be called by an application.
8308 gtk_widget_set_child_visible (GtkWidget *widget,
8309 gboolean is_visible)
8311 GtkWidgetPrivate *priv;
8313 g_return_if_fail (GTK_IS_WIDGET (widget));
8314 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8316 priv = widget->priv;
8318 g_object_ref (widget);
8321 priv->child_visible = TRUE;
8324 GtkWidget *toplevel;
8326 priv->child_visible = FALSE;
8328 toplevel = gtk_widget_get_toplevel (widget);
8329 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8330 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8333 if (priv->parent && gtk_widget_get_realized (priv->parent))
8335 if (gtk_widget_get_mapped (priv->parent) &&
8336 priv->child_visible &&
8337 gtk_widget_get_visible (widget))
8338 gtk_widget_map (widget);
8340 gtk_widget_unmap (widget);
8343 g_object_unref (widget);
8347 * gtk_widget_get_child_visible:
8348 * @widget: a #GtkWidget
8350 * Gets the value set with gtk_widget_set_child_visible().
8351 * If you feel a need to use this function, your code probably
8352 * needs reorganization.
8354 * This function is only useful for container implementations and
8355 * never should be called by an application.
8357 * Return value: %TRUE if the widget is mapped with the parent.
8360 gtk_widget_get_child_visible (GtkWidget *widget)
8362 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8364 return widget->priv->child_visible;
8368 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8370 GtkWidget *toplevel;
8372 toplevel = gtk_widget_get_toplevel (widget);
8374 if (gtk_widget_is_toplevel (toplevel))
8376 if (GTK_IS_WINDOW (toplevel))
8377 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8378 else if (GTK_IS_INVISIBLE (toplevel))
8379 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8386 * gtk_widget_get_screen:
8387 * @widget: a #GtkWidget
8389 * Get the #GdkScreen from the toplevel window associated with
8390 * this widget. This function can only be called after the widget
8391 * has been added to a widget hierarchy with a #GtkWindow
8394 * In general, you should only create screen specific
8395 * resources when a widget has been realized, and you should
8396 * free those resources when the widget is unrealized.
8398 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8403 gtk_widget_get_screen (GtkWidget *widget)
8407 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8409 screen = gtk_widget_get_screen_unchecked (widget);
8416 g_warning (G_STRLOC ": Can't get associated screen"
8417 " for a widget unless it is inside a toplevel GtkWindow\n"
8418 " widget type is %s associated top level type is %s",
8419 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8420 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8422 return gdk_screen_get_default ();
8427 * gtk_widget_has_screen:
8428 * @widget: a #GtkWidget
8430 * Checks whether there is a #GdkScreen is associated with
8431 * this widget. All toplevel widgets have an associated
8432 * screen, and all widgets added into a hierarchy with a toplevel
8433 * window at the top.
8435 * Return value: %TRUE if there is a #GdkScreen associcated
8441 gtk_widget_has_screen (GtkWidget *widget)
8443 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8445 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8449 * gtk_widget_get_display:
8450 * @widget: a #GtkWidget
8452 * Get the #GdkDisplay for the toplevel window associated with
8453 * this widget. This function can only be called after the widget
8454 * has been added to a widget hierarchy with a #GtkWindow at the top.
8456 * In general, you should only create display specific
8457 * resources when a widget has been realized, and you should
8458 * free those resources when the widget is unrealized.
8460 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8465 gtk_widget_get_display (GtkWidget *widget)
8467 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8469 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8473 * gtk_widget_get_root_window:
8474 * @widget: a #GtkWidget
8476 * Get the root window where this widget is located. This function can
8477 * only be called after the widget has been added to a widget
8478 * hierarchy with #GtkWindow at the top.
8480 * The root window is useful for such purposes as creating a popup
8481 * #GdkWindow associated with the window. In general, you should only
8482 * create display specific resources when a widget has been realized,
8483 * and you should free those resources when the widget is unrealized.
8485 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8490 gtk_widget_get_root_window (GtkWidget *widget)
8492 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8494 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8498 * gtk_widget_child_focus:
8499 * @widget: a #GtkWidget
8500 * @direction: direction of focus movement
8502 * This function is used by custom widget implementations; if you're
8503 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8504 * to a particular widget, and gtk_container_set_focus_chain() to
8505 * change the focus tab order. So you may want to investigate those
8506 * functions instead.
8508 * gtk_widget_child_focus() is called by containers as the user moves
8509 * around the window using keyboard shortcuts. @direction indicates
8510 * what kind of motion is taking place (up, down, left, right, tab
8511 * forward, tab backward). gtk_widget_child_focus() emits the
8512 * #GtkWidget::focus signal; widgets override the default handler
8513 * for this signal in order to implement appropriate focus behavior.
8515 * The default ::focus handler for a widget should return %TRUE if
8516 * moving in @direction left the focus on a focusable location inside
8517 * that widget, and %FALSE if moving in @direction moved the focus
8518 * outside the widget. If returning %TRUE, widgets normally
8519 * call gtk_widget_grab_focus() to place the focus accordingly;
8520 * if returning %FALSE, they don't modify the current focus location.
8522 * Return value: %TRUE if focus ended up inside @widget
8525 gtk_widget_child_focus (GtkWidget *widget,
8526 GtkDirectionType direction)
8528 gboolean return_val;
8530 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8532 if (!gtk_widget_get_visible (widget) ||
8533 !gtk_widget_is_sensitive (widget))
8536 /* child widgets must set CAN_FOCUS, containers
8537 * don't have to though.
8539 if (!GTK_IS_CONTAINER (widget) &&
8540 !gtk_widget_get_can_focus (widget))
8543 g_signal_emit (widget,
8544 widget_signals[FOCUS],
8546 direction, &return_val);
8552 * gtk_widget_keynav_failed:
8553 * @widget: a #GtkWidget
8554 * @direction: direction of focus movement
8556 * This function should be called whenever keyboard navigation within
8557 * a single widget hits a boundary. The function emits the
8558 * #GtkWidget::keynav-failed signal on the widget and its return
8559 * value should be interpreted in a way similar to the return value of
8560 * gtk_widget_child_focus():
8562 * When %TRUE is returned, stay in the widget, the failed keyboard
8563 * navigation is Ok and/or there is nowhere we can/should move the
8566 * When %FALSE is returned, the caller should continue with keyboard
8567 * navigation outside the widget, e.g. by calling
8568 * gtk_widget_child_focus() on the widget's toplevel.
8570 * The default ::keynav-failed handler returns %TRUE for
8571 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8572 * values of #GtkDirectionType, it looks at the
8573 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8574 * if the setting is %TRUE. This way the entire user interface
8575 * becomes cursor-navigatable on input devices such as mobile phones
8576 * which only have cursor keys but no tab key.
8578 * Whenever the default handler returns %TRUE, it also calls
8579 * gtk_widget_error_bell() to notify the user of the failed keyboard
8582 * A use case for providing an own implementation of ::keynav-failed
8583 * (either by connecting to it or by overriding it) would be a row of
8584 * #GtkEntry widgets where the user should be able to navigate the
8585 * entire row with the cursor keys, as e.g. known from user interfaces
8586 * that require entering license keys.
8588 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8589 * if the emitting widget should try to handle the keyboard
8590 * navigation attempt in its parent container(s).
8595 gtk_widget_keynav_failed (GtkWidget *widget,
8596 GtkDirectionType direction)
8598 gboolean return_val;
8600 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8602 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8603 direction, &return_val);
8609 * gtk_widget_error_bell:
8610 * @widget: a #GtkWidget
8612 * Notifies the user about an input-related error on this widget.
8613 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8614 * gdk_window_beep(), otherwise it does nothing.
8616 * Note that the effect of gdk_window_beep() can be configured in many
8617 * ways, depending on the windowing backend and the desktop environment
8618 * or window manager that is used.
8623 gtk_widget_error_bell (GtkWidget *widget)
8625 GtkWidgetPrivate *priv;
8626 GtkSettings* settings;
8629 g_return_if_fail (GTK_IS_WIDGET (widget));
8631 priv = widget->priv;
8633 settings = gtk_widget_get_settings (widget);
8637 g_object_get (settings,
8638 "gtk-error-bell", &beep,
8641 if (beep && priv->window)
8642 gdk_window_beep (priv->window);
8646 gtk_widget_set_usize_internal (GtkWidget *widget,
8650 GtkWidgetAuxInfo *aux_info;
8651 gboolean changed = FALSE;
8653 g_object_freeze_notify (G_OBJECT (widget));
8655 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8657 if (width > -2 && aux_info->width != width)
8659 g_object_notify (G_OBJECT (widget), "width-request");
8660 aux_info->width = width;
8663 if (height > -2 && aux_info->height != height)
8665 g_object_notify (G_OBJECT (widget), "height-request");
8666 aux_info->height = height;
8670 if (gtk_widget_get_visible (widget) && changed)
8671 gtk_widget_queue_resize (widget);
8673 g_object_thaw_notify (G_OBJECT (widget));
8677 * gtk_widget_set_size_request:
8678 * @widget: a #GtkWidget
8679 * @width: width @widget should request, or -1 to unset
8680 * @height: height @widget should request, or -1 to unset
8682 * Sets the minimum size of a widget; that is, the widget's size
8683 * request will be @width by @height. You can use this function to
8684 * force a widget to be either larger or smaller than it normally
8687 * In most cases, gtk_window_set_default_size() is a better choice for
8688 * toplevel windows than this function; setting the default size will
8689 * still allow users to shrink the window. Setting the size request
8690 * will force them to leave the window at least as large as the size
8691 * request. When dealing with window sizes,
8692 * gtk_window_set_geometry_hints() can be a useful function as well.
8694 * Note the inherent danger of setting any fixed size - themes,
8695 * translations into other languages, different fonts, and user action
8696 * can all change the appropriate size for a given widget. So, it's
8697 * basically impossible to hardcode a size that will always be
8700 * The size request of a widget is the smallest size a widget can
8701 * accept while still functioning well and drawing itself correctly.
8702 * However in some strange cases a widget may be allocated less than
8703 * its requested size, and in many cases a widget may be allocated more
8704 * space than it requested.
8706 * If the size request in a given direction is -1 (unset), then
8707 * the "natural" size request of the widget will be used instead.
8709 * Widgets can't actually be allocated a size less than 1 by 1, but
8710 * you can pass 0,0 to this function to mean "as small as possible."
8712 * The size request set here does not include any margin from the
8713 * #GtkWidget properties margin-left, margin-right, margin-top, and
8714 * margin-bottom, but it does include pretty much all other padding
8715 * or border properties set by any subclass of #GtkWidget.
8718 gtk_widget_set_size_request (GtkWidget *widget,
8722 g_return_if_fail (GTK_IS_WIDGET (widget));
8723 g_return_if_fail (width >= -1);
8724 g_return_if_fail (height >= -1);
8731 gtk_widget_set_usize_internal (widget, width, height);
8736 * gtk_widget_get_size_request:
8737 * @widget: a #GtkWidget
8738 * @width: (out) (allow-none): return location for width, or %NULL
8739 * @height: (out) (allow-none): return location for height, or %NULL
8741 * Gets the size request that was explicitly set for the widget using
8742 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8743 * @height indicates that that dimension has not been set explicitly
8744 * and the natural requisition of the widget will be used intead. See
8745 * gtk_widget_set_size_request(). To get the size a widget will
8746 * actually request, call gtk_widget_get_preferred_size() instead of
8750 gtk_widget_get_size_request (GtkWidget *widget,
8754 const GtkWidgetAuxInfo *aux_info;
8756 g_return_if_fail (GTK_IS_WIDGET (widget));
8758 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8761 *width = aux_info->width;
8764 *height = aux_info->height;
8768 * gtk_widget_set_events:
8769 * @widget: a #GtkWidget
8770 * @events: event mask
8772 * Sets the event mask (see #GdkEventMask) for a widget. The event
8773 * mask determines which events a widget will receive. Keep in mind
8774 * that different widgets have different default event masks, and by
8775 * changing the event mask you may disrupt a widget's functionality,
8776 * so be careful. This function must be called while a widget is
8777 * unrealized. Consider gtk_widget_add_events() for widgets that are
8778 * already realized, or if you want to preserve the existing event
8779 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8780 * to get events on those widgets, place them inside a #GtkEventBox
8781 * and receive events on the event box.
8784 gtk_widget_set_events (GtkWidget *widget,
8787 g_return_if_fail (GTK_IS_WIDGET (widget));
8788 g_return_if_fail (!gtk_widget_get_realized (widget));
8790 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8791 GINT_TO_POINTER (events));
8792 g_object_notify (G_OBJECT (widget), "events");
8796 * gtk_widget_set_device_events:
8797 * @widget: a #GtkWidget
8798 * @device: a #GdkDevice
8799 * @events: event mask
8801 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8802 * mask determines which events a widget will receive from @device. Keep
8803 * in mind that different widgets have different default event masks, and by
8804 * changing the event mask you may disrupt a widget's functionality,
8805 * so be careful. This function must be called while a widget is
8806 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8807 * already realized, or if you want to preserve the existing event
8808 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8809 * to get events on those widgets, place them inside a #GtkEventBox
8810 * and receive events on the event box.
8815 gtk_widget_set_device_events (GtkWidget *widget,
8817 GdkEventMask events)
8819 GHashTable *device_events;
8821 g_return_if_fail (GTK_IS_WIDGET (widget));
8822 g_return_if_fail (GDK_IS_DEVICE (device));
8823 g_return_if_fail (!gtk_widget_get_realized (widget));
8825 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8827 if (G_UNLIKELY (!device_events))
8829 device_events = g_hash_table_new (NULL, NULL);
8830 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8831 (GDestroyNotify) g_hash_table_unref);
8834 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8838 gtk_widget_add_events_internal_list (GtkWidget *widget,
8845 for (l = window_list; l != NULL; l = l->next)
8847 GdkWindow *window = l->data;
8850 gdk_window_get_user_data (window, &user_data);
8851 if (user_data == widget)
8856 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8858 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8860 children = gdk_window_get_children (window);
8861 gtk_widget_add_events_internal_list (widget, device, events, children);
8862 g_list_free (children);
8868 gtk_widget_add_events_internal (GtkWidget *widget,
8872 GtkWidgetPrivate *priv = widget->priv;
8875 if (!gtk_widget_get_has_window (widget))
8876 window_list = gdk_window_get_children (priv->window);
8878 window_list = g_list_prepend (NULL, priv->window);
8880 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8882 g_list_free (window_list);
8886 * gtk_widget_add_events:
8887 * @widget: a #GtkWidget
8888 * @events: an event mask, see #GdkEventMask
8890 * Adds the events in the bitfield @events to the event mask for
8891 * @widget. See gtk_widget_set_events() for details.
8894 gtk_widget_add_events (GtkWidget *widget,
8899 g_return_if_fail (GTK_IS_WIDGET (widget));
8901 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8902 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8903 GINT_TO_POINTER (old_events | events));
8905 if (gtk_widget_get_realized (widget))
8906 gtk_widget_add_events_internal (widget, NULL, events);
8908 g_object_notify (G_OBJECT (widget), "events");
8912 * gtk_widget_add_device_events:
8913 * @widget: a #GtkWidget
8914 * @device: a #GdkDevice
8915 * @events: an event mask, see #GdkEventMask
8917 * Adds the device events in the bitfield @events to the event mask for
8918 * @widget. See gtk_widget_set_device_events() for details.
8923 gtk_widget_add_device_events (GtkWidget *widget,
8925 GdkEventMask events)
8927 GdkEventMask old_events;
8928 GHashTable *device_events;
8930 g_return_if_fail (GTK_IS_WIDGET (widget));
8931 g_return_if_fail (GDK_IS_DEVICE (device));
8933 old_events = gtk_widget_get_device_events (widget, device);
8935 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8937 if (G_UNLIKELY (!device_events))
8939 device_events = g_hash_table_new (NULL, NULL);
8940 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8941 (GDestroyNotify) g_hash_table_unref);
8944 g_hash_table_insert (device_events, device,
8945 GUINT_TO_POINTER (old_events | events));
8947 if (gtk_widget_get_realized (widget))
8948 gtk_widget_add_events_internal (widget, device, events);
8950 g_object_notify (G_OBJECT (widget), "events");
8954 * gtk_widget_set_extension_events:
8955 * @widget: a #GtkWidget
8956 * @mode: bitfield of extension events to receive
8958 * Sets the extension events mask to @mode. See #GdkExtensionMode
8959 * and gdk_input_set_extension_events().
8962 gtk_widget_set_extension_events (GtkWidget *widget,
8963 GdkExtensionMode mode)
8965 g_return_if_fail (GTK_IS_WIDGET (widget));
8967 if (gtk_widget_get_realized (widget))
8968 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8970 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8971 GINT_TO_POINTER (mode));
8972 g_object_notify (G_OBJECT (widget), "extension-events");
8976 * gtk_widget_get_toplevel:
8977 * @widget: a #GtkWidget
8979 * This function returns the topmost widget in the container hierarchy
8980 * @widget is a part of. If @widget has no parent widgets, it will be
8981 * returned as the topmost widget. No reference will be added to the
8982 * returned widget; it should not be unreferenced.
8984 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8985 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8987 * %NULL if @widget wasn't inside a toplevel window, and if the
8988 * window was inside a #GtkWindow-derived widget which was in turn
8989 * inside the toplevel #GtkWindow. While the second case may
8990 * seem unlikely, it actually happens when a #GtkPlug is embedded
8991 * inside a #GtkSocket within the same application.
8993 * To reliably find the toplevel #GtkWindow, use
8994 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8995 * is set on the result.
8997 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8998 * if (gtk_widget_is_toplevel (toplevel))
9000 * /* Perform action on toplevel. */
9004 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
9005 * if there's no ancestor.
9008 gtk_widget_get_toplevel (GtkWidget *widget)
9010 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9012 while (widget->priv->parent)
9013 widget = widget->priv->parent;
9019 * gtk_widget_get_ancestor:
9020 * @widget: a #GtkWidget
9021 * @widget_type: ancestor type
9023 * Gets the first ancestor of @widget with type @widget_type. For example,
9024 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
9025 * the first #GtkBox that's an ancestor of @widget. No reference will be
9026 * added to the returned widget; it should not be unreferenced. See note
9027 * about checking for a toplevel #GtkWindow in the docs for
9028 * gtk_widget_get_toplevel().
9030 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
9031 * considers @widget to be an ancestor of itself.
9033 * Return value: (transfer none): the ancestor widget, or %NULL if not found
9036 gtk_widget_get_ancestor (GtkWidget *widget,
9039 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9041 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
9042 widget = widget->priv->parent;
9044 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
9051 * gtk_widget_set_visual:
9052 * @widget: a #GtkWidget
9053 * @visual: visual to be used or %NULL to unset a previous one
9055 * Sets the visual that should be used for by widget and its children for
9056 * creating #GdkWindows. The visual must be on the same #GdkScreen as
9057 * returned by gdk_widget_get_screen(), so handling the
9058 * GtkWidget::screen-changed signal is necessary.
9060 * Setting a new @visual will not cause @widget to recreate its windows,
9061 * so you should call this function before @widget is realized.
9064 gtk_widget_set_visual (GtkWidget *widget,
9067 g_return_if_fail (GTK_IS_WIDGET (widget));
9068 g_return_if_fail (visual == NULL || GDK_IS_VISUAL (visual));
9071 g_return_if_fail (gtk_widget_get_screen (widget) == gdk_visual_get_screen (visual));
9074 g_object_set_qdata_full (G_OBJECT (widget),
9076 g_object_ref (visual),
9081 * gtk_widget_get_visual:
9082 * @widget: a #GtkWidget
9084 * Gets the visual that will be used to render @widget.
9086 * Return value: (transfer none): the visual for @widget
9089 gtk_widget_get_visual (GtkWidget *widget)
9095 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9097 if (gtk_widget_get_has_window (widget) &&
9098 widget->priv->window)
9099 return gdk_window_get_visual (widget->priv->window);
9101 screen = gtk_widget_get_screen (widget);
9103 for (w = widget; w != NULL; w = w->priv->parent)
9105 visual = g_object_get_qdata (G_OBJECT (w), quark_visual);
9108 if (gdk_visual_get_screen (visual) == screen)
9111 g_warning ("Ignoring visual set on widget `%s' that is not on the correct screen.",
9112 gtk_widget_get_name (widget));
9116 return gdk_screen_get_system_visual (screen);
9120 * gtk_widget_get_settings:
9121 * @widget: a #GtkWidget
9123 * Gets the settings object holding the settings (global property
9124 * settings, RC file information, etc) used for this widget.
9126 * Note that this function can only be called when the #GtkWidget
9127 * is attached to a toplevel, since the settings object is specific
9128 * to a particular #GdkScreen.
9130 * Return value: (transfer none): the relevant #GtkSettings object
9133 gtk_widget_get_settings (GtkWidget *widget)
9135 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9137 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
9141 * gtk_widget_get_events:
9142 * @widget: a #GtkWidget
9144 * Returns the event mask for the widget (a bitfield containing flags
9145 * from the #GdkEventMask enumeration). These are the events that the widget
9148 * Return value: event mask for @widget
9151 gtk_widget_get_events (GtkWidget *widget)
9153 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9155 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
9159 * gtk_widget_get_device_events:
9160 * @widget: a #GtkWidget
9161 * @device: a #GdkDevice
9163 * Returns the events mask for the widget corresponding to an specific device. These
9164 * are the events that the widget will receive when @device operates on it.
9166 * Returns: device event mask for @widget
9171 gtk_widget_get_device_events (GtkWidget *widget,
9174 GHashTable *device_events;
9176 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9177 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9179 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9184 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9188 * gtk_widget_get_extension_events:
9189 * @widget: a #GtkWidget
9191 * Retrieves the extension events the widget will receive; see
9192 * gdk_input_set_extension_events().
9194 * Return value: extension events for @widget
9197 gtk_widget_get_extension_events (GtkWidget *widget)
9199 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9201 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9205 * gtk_widget_get_pointer:
9206 * @widget: a #GtkWidget
9207 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9208 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9210 * Obtains the location of the mouse pointer in widget coordinates.
9211 * Widget coordinates are a bit odd; for historical reasons, they are
9212 * defined as @widget->window coordinates for widgets that are not
9213 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9214 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9217 gtk_widget_get_pointer (GtkWidget *widget,
9221 GtkWidgetPrivate *priv;
9223 g_return_if_fail (GTK_IS_WIDGET (widget));
9225 priv = widget->priv;
9232 if (gtk_widget_get_realized (widget))
9234 gdk_window_get_pointer (priv->window, x, y, NULL);
9236 if (!gtk_widget_get_has_window (widget))
9239 *x -= priv->allocation.x;
9241 *y -= priv->allocation.y;
9247 * gtk_widget_is_ancestor:
9248 * @widget: a #GtkWidget
9249 * @ancestor: another #GtkWidget
9251 * Determines whether @widget is somewhere inside @ancestor, possibly with
9252 * intermediate containers.
9254 * Return value: %TRUE if @ancestor contains @widget as a child,
9255 * grandchild, great grandchild, etc.
9258 gtk_widget_is_ancestor (GtkWidget *widget,
9259 GtkWidget *ancestor)
9261 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9262 g_return_val_if_fail (ancestor != NULL, FALSE);
9266 if (widget->priv->parent == ancestor)
9268 widget = widget->priv->parent;
9274 static GQuark quark_composite_name = 0;
9277 * gtk_widget_set_composite_name:
9278 * @widget: a #GtkWidget.
9279 * @name: the name to set
9281 * Sets a widgets composite name. The widget must be
9282 * a composite child of its parent; see gtk_widget_push_composite_child().
9285 gtk_widget_set_composite_name (GtkWidget *widget,
9288 g_return_if_fail (GTK_IS_WIDGET (widget));
9289 g_return_if_fail (widget->priv->composite_child);
9290 g_return_if_fail (name != NULL);
9292 if (!quark_composite_name)
9293 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9295 g_object_set_qdata_full (G_OBJECT (widget),
9296 quark_composite_name,
9302 * gtk_widget_get_composite_name:
9303 * @widget: a #GtkWidget
9305 * Obtains the composite name of a widget.
9307 * Returns: the composite name of @widget, or %NULL if @widget is not
9308 * a composite child. The string should be freed when it is no
9312 gtk_widget_get_composite_name (GtkWidget *widget)
9314 GtkWidgetPrivate *priv;
9316 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9318 priv = widget->priv;
9320 if (widget->priv->composite_child && priv->parent)
9321 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9328 * gtk_widget_push_composite_child:
9330 * Makes all newly-created widgets as composite children until
9331 * the corresponding gtk_widget_pop_composite_child() call.
9333 * A composite child is a child that's an implementation detail of the
9334 * container it's inside and should not be visible to people using the
9335 * container. Composite children aren't treated differently by GTK (but
9336 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9337 * builders might want to treat them in a different way.
9339 * Here is a simple example:
9341 * gtk_widget_push_composite_child ();
9342 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9343 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9344 * gtk_widget_pop_composite_child ();
9345 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9346 * GTK_WIDGET (scrolled_window));
9347 * g_object_ref (scrolled_window->hscrollbar);
9351 gtk_widget_push_composite_child (void)
9353 composite_child_stack++;
9357 * gtk_widget_pop_composite_child:
9359 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9362 gtk_widget_pop_composite_child (void)
9364 if (composite_child_stack)
9365 composite_child_stack--;
9369 gtk_widget_emit_direction_changed (GtkWidget *widget,
9370 GtkTextDirection old_dir)
9372 gtk_widget_update_pango_context (widget);
9374 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9378 * gtk_widget_set_direction:
9379 * @widget: a #GtkWidget
9380 * @dir: the new direction
9382 * Sets the reading direction on a particular widget. This direction
9383 * controls the primary direction for widgets containing text,
9384 * and also the direction in which the children of a container are
9385 * packed. The ability to set the direction is present in order
9386 * so that correct localization into languages with right-to-left
9387 * reading directions can be done. Generally, applications will
9388 * let the default reading direction present, except for containers
9389 * where the containers are arranged in an order that is explicitely
9390 * visual rather than logical (such as buttons for text justification).
9392 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9393 * set by gtk_widget_set_default_direction() will be used.
9396 gtk_widget_set_direction (GtkWidget *widget,
9397 GtkTextDirection dir)
9399 GtkTextDirection old_dir;
9401 g_return_if_fail (GTK_IS_WIDGET (widget));
9402 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9404 old_dir = gtk_widget_get_direction (widget);
9406 widget->priv->direction = dir;
9408 if (old_dir != gtk_widget_get_direction (widget))
9409 gtk_widget_emit_direction_changed (widget, old_dir);
9413 * gtk_widget_get_direction:
9414 * @widget: a #GtkWidget
9416 * Gets the reading direction for a particular widget. See
9417 * gtk_widget_set_direction().
9419 * Return value: the reading direction for the widget.
9422 gtk_widget_get_direction (GtkWidget *widget)
9424 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9426 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9427 return gtk_default_direction;
9429 return widget->priv->direction;
9433 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9435 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9437 g_object_ref (widget);
9439 if (widget->priv->direction == GTK_TEXT_DIR_NONE)
9440 gtk_widget_emit_direction_changed (widget, old_dir);
9442 if (GTK_IS_CONTAINER (widget))
9443 gtk_container_forall (GTK_CONTAINER (widget),
9444 gtk_widget_set_default_direction_recurse,
9447 g_object_unref (widget);
9451 * gtk_widget_set_default_direction:
9452 * @dir: the new default direction. This cannot be
9453 * %GTK_TEXT_DIR_NONE.
9455 * Sets the default reading direction for widgets where the
9456 * direction has not been explicitly set by gtk_widget_set_direction().
9459 gtk_widget_set_default_direction (GtkTextDirection dir)
9461 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9463 if (dir != gtk_default_direction)
9465 GList *toplevels, *tmp_list;
9466 GtkTextDirection old_dir = gtk_default_direction;
9468 gtk_default_direction = dir;
9470 tmp_list = toplevels = gtk_window_list_toplevels ();
9471 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9475 gtk_widget_set_default_direction_recurse (tmp_list->data,
9476 GUINT_TO_POINTER (old_dir));
9477 g_object_unref (tmp_list->data);
9478 tmp_list = tmp_list->next;
9481 g_list_free (toplevels);
9486 * gtk_widget_get_default_direction:
9488 * Obtains the current default reading direction. See
9489 * gtk_widget_set_default_direction().
9491 * Return value: the current default direction.
9494 gtk_widget_get_default_direction (void)
9496 return gtk_default_direction;
9500 gtk_widget_dispose (GObject *object)
9502 GtkWidget *widget = GTK_WIDGET (object);
9503 GtkWidgetPrivate *priv = widget->priv;
9506 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9507 else if (gtk_widget_get_visible (widget))
9508 gtk_widget_hide (widget);
9510 priv->visible = FALSE;
9511 if (gtk_widget_get_realized (widget))
9512 gtk_widget_unrealize (widget);
9514 if (!priv->in_destruction)
9516 priv->in_destruction = TRUE;
9517 g_signal_emit (object, widget_signals[DESTROY], 0);
9518 priv->in_destruction = FALSE;
9521 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9525 gtk_widget_real_destroy (GtkWidget *object)
9527 /* gtk_object_destroy() will already hold a refcount on object */
9528 GtkWidget *widget = GTK_WIDGET (object);
9529 GtkWidgetPrivate *priv = widget->priv;
9531 /* wipe accelerator closures (keep order) */
9532 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9533 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9535 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9536 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9538 gtk_grab_remove (widget);
9540 g_object_unref (priv->style);
9541 priv->style = gtk_widget_get_default_style ();
9542 g_object_ref (priv->style);
9546 gtk_widget_finalize (GObject *object)
9548 GtkWidget *widget = GTK_WIDGET (object);
9549 GtkWidgetPrivate *priv = widget->priv;
9550 GtkWidgetAuxInfo *aux_info;
9551 GtkAccessible *accessible;
9553 gtk_grab_remove (widget);
9555 g_object_unref (priv->style);
9558 g_free (priv->name);
9560 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9562 gtk_widget_aux_info_destroy (aux_info);
9564 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9566 g_object_unref (accessible);
9568 if (g_object_is_floating (object))
9569 g_warning ("A floating object was finalized. This means that someone\n"
9570 "called g_object_unref() on an object that had only a floating\n"
9571 "reference; the initial floating reference is not owned by anyone\n"
9572 "and must be removed with g_object_ref_sink().");
9574 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9577 /*****************************************
9578 * gtk_widget_real_map:
9583 *****************************************/
9586 gtk_widget_real_map (GtkWidget *widget)
9588 GtkWidgetPrivate *priv = widget->priv;
9590 g_assert (gtk_widget_get_realized (widget));
9592 if (!gtk_widget_get_mapped (widget))
9594 gtk_widget_set_mapped (widget, TRUE);
9596 if (gtk_widget_get_has_window (widget))
9597 gdk_window_show (priv->window);
9601 /*****************************************
9602 * gtk_widget_real_unmap:
9607 *****************************************/
9610 gtk_widget_real_unmap (GtkWidget *widget)
9612 GtkWidgetPrivate *priv = widget->priv;
9614 if (gtk_widget_get_mapped (widget))
9616 gtk_widget_set_mapped (widget, FALSE);
9618 if (gtk_widget_get_has_window (widget))
9619 gdk_window_hide (priv->window);
9623 /*****************************************
9624 * gtk_widget_real_realize:
9629 *****************************************/
9632 gtk_widget_real_realize (GtkWidget *widget)
9634 GtkWidgetPrivate *priv = widget->priv;
9636 g_assert (!gtk_widget_get_has_window (widget));
9638 gtk_widget_set_realized (widget, TRUE);
9641 priv->window = gtk_widget_get_parent_window (widget);
9642 g_object_ref (priv->window);
9644 priv->style = gtk_style_attach (priv->style, priv->window);
9647 /*****************************************
9648 * gtk_widget_real_unrealize:
9653 *****************************************/
9656 gtk_widget_real_unrealize (GtkWidget *widget)
9658 GtkWidgetPrivate *priv = widget->priv;
9660 if (gtk_widget_get_mapped (widget))
9661 gtk_widget_real_unmap (widget);
9663 gtk_widget_set_mapped (widget, FALSE);
9665 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9668 /* We must do unrealize child widget BEFORE container widget.
9669 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9670 * So, unrealizing container widget bofore its children causes the problem
9671 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9674 if (GTK_IS_CONTAINER (widget))
9675 gtk_container_forall (GTK_CONTAINER (widget),
9676 (GtkCallback) gtk_widget_unrealize,
9679 gtk_style_detach (priv->style);
9680 if (gtk_widget_get_has_window (widget))
9682 gdk_window_set_user_data (priv->window, NULL);
9683 gdk_window_destroy (priv->window);
9684 priv->window = NULL;
9688 g_object_unref (priv->window);
9689 priv->window = NULL;
9692 gtk_selection_remove_all (widget);
9694 gtk_widget_set_realized (widget, FALSE);
9698 gtk_widget_real_size_request (GtkWidget *widget,
9699 GtkRequisition *requisition)
9701 requisition->width = 0;
9702 requisition->height = 0;
9706 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9707 GtkOrientation orientation,
9712 const GtkWidgetAuxInfo *aux_info;
9714 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9716 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9717 aux_info->width > 0)
9719 *minimum_size = MAX (*minimum_size, aux_info->width);
9721 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9722 aux_info->height > 0)
9724 *minimum_size = MAX (*minimum_size, aux_info->height);
9727 /* Fix it if set_size_request made natural size smaller than min size.
9728 * This would also silently fix broken widgets, but we warn about them
9729 * in gtksizerequest.c when calling their size request vfuncs.
9731 *natural_size = MAX (*natural_size, *minimum_size);
9733 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9735 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9736 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9740 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9741 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9746 * _gtk_widget_peek_request_cache:
9748 * Returns the address of the widget's request cache (strictly for
9749 * internal use in gtksizerequest.c)
9751 * Return value: the address of @widget's size request cache.
9754 _gtk_widget_peek_request_cache (GtkWidget *widget)
9756 /* Don't bother slowing things down with the return_if_fail guards here */
9757 return &widget->priv->requests;
9761 * _gtk_widget_set_device_window:
9762 * @widget: a #GtkWidget.
9763 * @device: a #GdkDevice.
9764 * @window: the new device window.
9766 * Sets pointer window for @widget and @device. Does not ref @window.
9767 * Actually stores it on the #GdkScreen, but you don't need to know that.
9770 _gtk_widget_set_device_window (GtkWidget *widget,
9774 GtkWidgetPrivate *priv;
9776 GHashTable *device_window;
9778 g_return_if_fail (GTK_IS_WIDGET (widget));
9779 g_return_if_fail (GDK_IS_DEVICE (device));
9780 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9782 priv = widget->priv;
9784 if (!gtk_widget_get_realized (widget))
9787 screen = gdk_window_get_screen (priv->window);
9788 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9790 if (G_UNLIKELY (!device_window))
9792 device_window = g_hash_table_new (NULL, NULL);
9793 g_object_set_qdata_full (G_OBJECT (screen),
9794 quark_pointer_window,
9796 (GDestroyNotify) g_hash_table_destroy);
9800 g_hash_table_insert (device_window, device, window);
9802 g_hash_table_remove (device_window, device);
9806 * _gtk_widget_get_device_window:
9807 * @widget: a #GtkWidget.
9808 * @device: a #GdkDevice.
9810 * Return value: the device window set on the #GdkScreen @widget is attached
9814 _gtk_widget_get_device_window (GtkWidget *widget,
9817 GtkWidgetPrivate *priv;
9819 GHashTable *device_window;
9823 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9824 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9826 priv = widget->priv;
9828 if (!gtk_widget_get_realized (widget))
9831 screen = gdk_window_get_screen (priv->window);
9832 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9834 if (G_UNLIKELY (!device_window))
9837 window = g_hash_table_lookup (device_window, device);
9842 gdk_window_get_user_data (window, (gpointer *) &w);
9851 * _gtk_widget_list_devices:
9852 * @widget: a #GtkWidget.
9854 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9855 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9859 _gtk_widget_list_devices (GtkWidget *widget)
9861 GtkWidgetPrivate *priv;
9863 GHashTableIter iter;
9864 GHashTable *device_window;
9865 GList *devices = NULL;
9866 gpointer key, value;
9868 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9870 priv = widget->priv;
9872 if (!gtk_widget_get_realized (widget))
9875 screen = gdk_window_get_screen (priv->window);
9876 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9878 if (G_UNLIKELY (!device_window))
9881 g_hash_table_iter_init (&iter, device_window);
9883 while (g_hash_table_iter_next (&iter, &key, &value))
9885 GdkDevice *device = key;
9886 GdkWindow *window = value;
9891 gdk_window_get_user_data (window, (gpointer *) &w);
9894 devices = g_list_prepend (devices, device);
9902 synth_crossing (GtkWidget *widget,
9906 GdkCrossingMode mode,
9907 GdkNotifyType detail)
9911 event = gdk_event_new (type);
9913 event->crossing.window = g_object_ref (window);
9914 event->crossing.send_event = TRUE;
9915 event->crossing.subwindow = g_object_ref (window);
9916 event->crossing.time = GDK_CURRENT_TIME;
9917 event->crossing.x = event->crossing.y = 0;
9918 event->crossing.x_root = event->crossing.y_root = 0;
9919 event->crossing.mode = mode;
9920 event->crossing.detail = detail;
9921 event->crossing.focus = FALSE;
9922 event->crossing.state = 0;
9923 gdk_event_set_device (event, device);
9926 widget = gtk_get_event_widget (event);
9929 gtk_widget_event_internal (widget, event);
9931 gdk_event_free (event);
9935 * _gtk_widget_synthesize_crossing:
9936 * @from: the #GtkWidget the virtual pointer is leaving.
9937 * @to: the #GtkWidget the virtual pointer is moving to.
9938 * @mode: the #GdkCrossingMode to place on the synthesized events.
9940 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9942 * The real pointer window is the window that most recently received an enter notify
9943 * event. Windows that don't select for crossing events can't become the real
9944 * poiner window. The real pointer widget that owns the real pointer window. The
9945 * effective pointer window is the same as the real pointer window unless the real
9946 * pointer widget is either insensitive or there is a grab on a widget that is not
9947 * an ancestor of the real pointer widget (in which case the effective pointer
9948 * window should be the root window).
9950 * When the effective pointer window is the same as the real poiner window, we
9951 * receive crossing events from the windowing system. When the effective pointer
9952 * window changes to become different from the real pointer window we synthesize
9953 * crossing events, attempting to follow X protocol rules:
9955 * When the root window becomes the effective pointer window:
9956 * - leave notify on real pointer window, detail Ancestor
9957 * - leave notify on all of its ancestors, detail Virtual
9958 * - enter notify on root window, detail Inferior
9960 * When the root window ceases to be the effective pointer window:
9961 * - leave notify on root window, detail Inferior
9962 * - enter notify on all ancestors of real pointer window, detail Virtual
9963 * - enter notify on real pointer window, detail Ancestor
9966 _gtk_widget_synthesize_crossing (GtkWidget *from,
9969 GdkCrossingMode mode)
9971 GdkWindow *from_window = NULL, *to_window = NULL;
9973 g_return_if_fail (from != NULL || to != NULL);
9977 from_window = _gtk_widget_get_device_window (from, device);
9980 from_window = from->priv->window;
9985 to_window = _gtk_widget_get_device_window (to, device);
9988 to_window = to->priv->window;
9991 if (from_window == NULL && to_window == NULL)
9993 else if (from_window != NULL && to_window == NULL)
9995 GList *from_ancestors = NULL, *list;
9996 GdkWindow *from_ancestor = from_window;
9998 while (from_ancestor != NULL)
10000 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10001 if (from_ancestor == NULL)
10003 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10006 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10007 device, mode, GDK_NOTIFY_ANCESTOR);
10008 for (list = g_list_last (from_ancestors); list; list = list->prev)
10010 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10011 device, mode, GDK_NOTIFY_VIRTUAL);
10014 /* XXX: enter/inferior on root window? */
10016 g_list_free (from_ancestors);
10018 else if (from_window == NULL && to_window != NULL)
10020 GList *to_ancestors = NULL, *list;
10021 GdkWindow *to_ancestor = to_window;
10023 while (to_ancestor != NULL)
10025 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10026 if (to_ancestor == NULL)
10028 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10031 /* XXX: leave/inferior on root window? */
10033 for (list = to_ancestors; list; list = list->next)
10035 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10036 device, mode, GDK_NOTIFY_VIRTUAL);
10038 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10039 device, mode, GDK_NOTIFY_ANCESTOR);
10041 g_list_free (to_ancestors);
10043 else if (from_window == to_window)
10047 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
10048 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
10050 while (from_ancestor != NULL || to_ancestor != NULL)
10052 if (from_ancestor != NULL)
10054 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
10055 if (from_ancestor == to_window)
10058 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
10060 if (to_ancestor != NULL)
10062 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
10063 if (to_ancestor == from_window)
10066 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
10069 if (to_ancestor == from_window)
10071 if (mode != GDK_CROSSING_GTK_UNGRAB)
10072 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10073 device, mode, GDK_NOTIFY_INFERIOR);
10074 for (list = to_ancestors; list; list = list->next)
10075 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10076 device, mode, GDK_NOTIFY_VIRTUAL);
10077 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10078 device, mode, GDK_NOTIFY_ANCESTOR);
10080 else if (from_ancestor == to_window)
10082 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10083 device, mode, GDK_NOTIFY_ANCESTOR);
10084 for (list = g_list_last (from_ancestors); list; list = list->prev)
10086 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10087 device, mode, GDK_NOTIFY_VIRTUAL);
10089 if (mode != GDK_CROSSING_GTK_GRAB)
10090 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10091 device, mode, GDK_NOTIFY_INFERIOR);
10095 while (from_ancestors != NULL && to_ancestors != NULL
10096 && from_ancestors->data == to_ancestors->data)
10098 from_ancestors = g_list_delete_link (from_ancestors,
10100 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
10103 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
10104 device, mode, GDK_NOTIFY_NONLINEAR);
10106 for (list = g_list_last (from_ancestors); list; list = list->prev)
10108 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
10109 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10111 for (list = to_ancestors; list; list = list->next)
10113 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
10114 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
10116 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
10117 device, mode, GDK_NOTIFY_NONLINEAR);
10119 g_list_free (from_ancestors);
10120 g_list_free (to_ancestors);
10125 gtk_widget_propagate_state (GtkWidget *widget,
10126 GtkStateData *data)
10128 GtkWidgetPrivate *priv = widget->priv;
10129 guint8 old_state = gtk_widget_get_state (widget);
10130 guint8 old_saved_state = priv->saved_state;
10132 /* don't call this function with state==GTK_STATE_INSENSITIVE,
10133 * parent_sensitive==TRUE on a sensitive widget
10137 priv->parent_sensitive = data->parent_sensitive;
10139 if (gtk_widget_is_sensitive (widget))
10141 if (data->state_restoration)
10142 priv->state = priv->saved_state;
10144 priv->state = data->state;
10148 if (!data->state_restoration)
10150 if (data->state != GTK_STATE_INSENSITIVE)
10151 priv->saved_state = data->state;
10153 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
10154 priv->saved_state = gtk_widget_get_state (widget);
10155 priv->state = GTK_STATE_INSENSITIVE;
10158 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
10162 window = gtk_widget_get_toplevel (widget);
10163 if (window && gtk_widget_is_toplevel (window))
10164 gtk_window_set_focus (GTK_WINDOW (window), NULL);
10167 if (old_state != gtk_widget_get_state (widget) ||
10168 old_saved_state != priv->saved_state)
10170 g_object_ref (widget);
10172 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
10173 gtk_grab_remove (widget);
10175 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10177 if (!priv->shadowed)
10179 GList *event_windows = NULL;
10180 GList *devices, *d;
10182 devices = _gtk_widget_list_devices (widget);
10184 for (d = devices; d; d = d->next)
10190 window = _gtk_widget_get_device_window (widget, device);
10192 /* Do not propagate more than once to the
10193 * same window if non-multidevice aware.
10195 if (!gdk_window_get_support_multidevice (window) &&
10196 g_list_find (event_windows, window))
10199 if (!gtk_widget_is_sensitive (widget))
10200 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10201 GDK_CROSSING_STATE_CHANGED);
10202 else if (old_state == GTK_STATE_INSENSITIVE)
10203 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10204 GDK_CROSSING_STATE_CHANGED);
10206 event_windows = g_list_prepend (event_windows, window);
10209 g_list_free (event_windows);
10210 g_list_free (devices);
10213 if (GTK_IS_CONTAINER (widget))
10215 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10216 if (data->use_forall)
10217 gtk_container_forall (GTK_CONTAINER (widget),
10218 (GtkCallback) gtk_widget_propagate_state,
10221 gtk_container_foreach (GTK_CONTAINER (widget),
10222 (GtkCallback) gtk_widget_propagate_state,
10225 g_object_unref (widget);
10229 static const GtkWidgetAuxInfo default_aux_info = {
10237 * _gtk_widget_get_aux_info:
10238 * @widget: a #GtkWidget
10239 * @create: if %TRUE, create the structure if it doesn't exist
10241 * Get the #GtkWidgetAuxInfo structure for the widget.
10243 * Return value: the #GtkAuxInfo structure for the widget, or
10244 * %NULL if @create is %FALSE and one doesn't already exist.
10247 _gtk_widget_get_aux_info (GtkWidget *widget,
10250 GtkWidgetAuxInfo *aux_info;
10252 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10253 if (!aux_info && create)
10255 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10257 *aux_info = default_aux_info;
10259 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10265 static const GtkWidgetAuxInfo*
10266 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10268 GtkWidgetAuxInfo *aux_info;
10270 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10271 if (aux_info == NULL)
10273 return &default_aux_info;
10281 /*****************************************
10282 * gtk_widget_aux_info_destroy:
10287 *****************************************/
10290 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10292 g_slice_free (GtkWidgetAuxInfo, aux_info);
10296 * gtk_widget_shape_combine_region:
10297 * @widget: a #GtkWidget
10298 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10300 * Sets a shape for this widget's GDK window. This allows for
10301 * transparent windows etc., see gdk_window_shape_combine_region()
10302 * for more information.
10307 gtk_widget_shape_combine_region (GtkWidget *widget,
10308 cairo_region_t *region)
10310 GtkWidgetPrivate *priv;
10312 g_return_if_fail (GTK_IS_WIDGET (widget));
10313 /* set_shape doesn't work on widgets without gdk window */
10314 g_return_if_fail (gtk_widget_get_has_window (widget));
10316 priv = widget->priv;
10318 if (region == NULL)
10320 priv->has_shape_mask = FALSE;
10323 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10325 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10329 priv->has_shape_mask = TRUE;
10331 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10332 cairo_region_copy (region),
10333 (GDestroyNotify) cairo_region_destroy);
10335 /* set shape if widget has a gdk window already.
10336 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10339 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10344 * gtk_widget_input_shape_combine_region:
10345 * @widget: a #GtkWidget
10346 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10348 * Sets an input shape for this widget's GDK window. This allows for
10349 * windows which react to mouse click in a nonrectangular region, see
10350 * gdk_window_input_shape_combine_region() for more information.
10355 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10356 cairo_region_t *region)
10358 GtkWidgetPrivate *priv;
10360 g_return_if_fail (GTK_IS_WIDGET (widget));
10361 /* set_shape doesn't work on widgets without gdk window */
10362 g_return_if_fail (gtk_widget_get_has_window (widget));
10364 priv = widget->priv;
10366 if (region == NULL)
10369 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10371 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10375 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10376 cairo_region_copy (region),
10377 (GDestroyNotify) cairo_region_destroy);
10379 /* set shape if widget has a gdk window already.
10380 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10383 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10389 gtk_reset_shapes_recurse (GtkWidget *widget,
10395 gdk_window_get_user_data (window, &data);
10396 if (data != widget)
10399 gdk_window_shape_combine_region (window, NULL, 0, 0);
10400 for (list = gdk_window_peek_children (window); list; list = list->next)
10401 gtk_reset_shapes_recurse (widget, list->data);
10405 * gtk_widget_reset_shapes:
10406 * @widget: a #GtkWidget
10408 * Recursively resets the shape on this widget and its descendants.
10411 gtk_widget_reset_shapes (GtkWidget *widget)
10413 GtkWidgetPrivate *priv;
10415 g_return_if_fail (GTK_IS_WIDGET (widget));
10416 g_return_if_fail (gtk_widget_get_realized (widget));
10418 priv = widget->priv;
10420 if (!priv->has_shape_mask)
10421 gtk_reset_shapes_recurse (widget, priv->window);
10424 /* style properties
10428 * gtk_widget_class_install_style_property_parser:
10429 * @klass: a #GtkWidgetClass
10430 * @pspec: the #GParamSpec for the style property
10431 * @parser: the parser for the style property
10433 * Installs a style property on a widget class.
10436 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10438 GtkRcPropertyParser parser)
10440 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10441 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10442 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10443 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10445 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10447 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10448 G_OBJECT_CLASS_NAME (klass),
10453 g_param_spec_ref_sink (pspec);
10454 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10455 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10459 * gtk_widget_class_install_style_property:
10460 * @klass: a #GtkWidgetClass
10461 * @pspec: the #GParamSpec for the property
10463 * Installs a style property on a widget class. The parser for the
10464 * style property is determined by the value type of @pspec.
10467 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10470 GtkRcPropertyParser parser;
10472 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10473 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10475 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10477 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10481 * gtk_widget_class_find_style_property:
10482 * @klass: a #GtkWidgetClass
10483 * @property_name: the name of the style property to find
10484 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10485 * style property with that name.
10487 * Finds a style property of a widget class by name.
10492 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10493 const gchar *property_name)
10495 g_return_val_if_fail (property_name != NULL, NULL);
10497 return g_param_spec_pool_lookup (style_property_spec_pool,
10499 G_OBJECT_CLASS_TYPE (klass),
10504 * gtk_widget_class_list_style_properties:
10505 * @klass: a #GtkWidgetClass
10506 * @n_properties: location to return the number of style properties found
10507 * @returns: an newly allocated array of #GParamSpec*. The array must
10508 * be freed with g_free().
10510 * Returns all style properties of a widget class.
10515 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10516 guint *n_properties)
10518 GParamSpec **pspecs;
10521 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10522 G_OBJECT_CLASS_TYPE (klass),
10531 * gtk_widget_style_get_property:
10532 * @widget: a #GtkWidget
10533 * @property_name: the name of a style property
10534 * @value: location to return the property value
10536 * Gets the value of a style property of @widget.
10539 gtk_widget_style_get_property (GtkWidget *widget,
10540 const gchar *property_name,
10543 GtkWidgetPrivate *priv;
10546 g_return_if_fail (GTK_IS_WIDGET (widget));
10547 g_return_if_fail (property_name != NULL);
10548 g_return_if_fail (G_IS_VALUE (value));
10550 priv = widget->priv;
10552 g_object_ref (widget);
10553 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10555 G_OBJECT_TYPE (widget),
10558 g_warning ("%s: widget class `%s' has no property named `%s'",
10560 G_OBJECT_TYPE_NAME (widget),
10564 const GValue *peek_value;
10566 peek_value = _gtk_style_peek_property_value (priv->style,
10567 G_OBJECT_TYPE (widget),
10569 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10571 /* auto-conversion of the caller's value type
10573 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10574 g_value_copy (peek_value, value);
10575 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10576 g_value_transform (peek_value, value);
10578 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10580 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10581 G_VALUE_TYPE_NAME (value));
10583 g_object_unref (widget);
10587 * gtk_widget_style_get_valist:
10588 * @widget: a #GtkWidget
10589 * @first_property_name: the name of the first property to get
10590 * @var_args: a <type>va_list</type> of pairs of property names and
10591 * locations to return the property values, starting with the location
10592 * for @first_property_name.
10594 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10598 gtk_widget_style_get_valist (GtkWidget *widget,
10599 const gchar *first_property_name,
10602 GtkWidgetPrivate *priv;
10605 g_return_if_fail (GTK_IS_WIDGET (widget));
10607 priv = widget->priv;
10609 g_object_ref (widget);
10611 name = first_property_name;
10614 const GValue *peek_value;
10618 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10620 G_OBJECT_TYPE (widget),
10624 g_warning ("%s: widget class `%s' has no property named `%s'",
10626 G_OBJECT_TYPE_NAME (widget),
10630 /* style pspecs are always readable so we can spare that check here */
10632 peek_value = _gtk_style_peek_property_value (priv->style,
10633 G_OBJECT_TYPE (widget),
10635 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10636 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10639 g_warning ("%s: %s", G_STRLOC, error);
10644 name = va_arg (var_args, gchar*);
10647 g_object_unref (widget);
10651 * gtk_widget_style_get:
10652 * @widget: a #GtkWidget
10653 * @first_property_name: the name of the first property to get
10654 * @Varargs: pairs of property names and locations to
10655 * return the property values, starting with the location for
10656 * @first_property_name, terminated by %NULL.
10658 * Gets the values of a multiple style properties of @widget.
10661 gtk_widget_style_get (GtkWidget *widget,
10662 const gchar *first_property_name,
10667 g_return_if_fail (GTK_IS_WIDGET (widget));
10669 va_start (var_args, first_property_name);
10670 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10676 * @widget: a #GtkWidget
10677 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10678 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10679 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10681 * Obtains the full path to @widget. The path is simply the name of a
10682 * widget and all its parents in the container hierarchy, separated by
10683 * periods. The name of a widget comes from
10684 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10685 * in gtkrc configuration files. Widget names are the type of the
10686 * widget by default (e.g. "GtkButton") or can be set to an
10687 * application-specific value with gtk_widget_set_name(). By setting
10688 * the name of a widget, you allow users or theme authors to apply
10689 * styles to that specific widget in their gtkrc
10690 * file. @path_reversed_p fills in the path in reverse order,
10691 * i.e. starting with @widget's name instead of starting with the name
10692 * of @widget's outermost ancestor.
10695 gtk_widget_path (GtkWidget *widget,
10696 guint *path_length,
10698 gchar **path_reversed)
10700 static gchar *rev_path = NULL;
10701 static guint tmp_path_len = 0;
10704 g_return_if_fail (GTK_IS_WIDGET (widget));
10709 const gchar *string;
10714 string = gtk_widget_get_name (widget);
10715 l = strlen (string);
10716 while (tmp_path_len <= len + l + 1)
10718 tmp_path_len += INIT_PATH_SIZE;
10719 rev_path = g_realloc (rev_path, tmp_path_len);
10721 s = string + l - 1;
10722 d = rev_path + len;
10723 while (s >= string)
10727 widget = widget->priv->parent;
10730 rev_path[len++] = '.';
10732 rev_path[len++] = 0;
10737 *path_length = len - 1;
10739 *path_reversed = g_strdup (rev_path);
10742 *path = g_strdup (rev_path);
10743 g_strreverse (*path);
10748 * gtk_widget_class_path:
10749 * @widget: a #GtkWidget
10750 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10751 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10752 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10755 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10756 * never uses a custom name set with gtk_widget_set_name().
10760 gtk_widget_class_path (GtkWidget *widget,
10761 guint *path_length,
10763 gchar **path_reversed)
10765 static gchar *rev_path = NULL;
10766 static guint tmp_path_len = 0;
10769 g_return_if_fail (GTK_IS_WIDGET (widget));
10774 const gchar *string;
10779 string = g_type_name (G_OBJECT_TYPE (widget));
10780 l = strlen (string);
10781 while (tmp_path_len <= len + l + 1)
10783 tmp_path_len += INIT_PATH_SIZE;
10784 rev_path = g_realloc (rev_path, tmp_path_len);
10786 s = string + l - 1;
10787 d = rev_path + len;
10788 while (s >= string)
10792 widget = widget->priv->parent;
10795 rev_path[len++] = '.';
10797 rev_path[len++] = 0;
10802 *path_length = len - 1;
10804 *path_reversed = g_strdup (rev_path);
10807 *path = g_strdup (rev_path);
10808 g_strreverse (*path);
10813 * gtk_requisition_new:
10815 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10817 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10818 * be freed with gtk_requisition_free().
10823 gtk_requisition_new (void)
10825 return g_slice_new0 (GtkRequisition);
10829 * gtk_requisition_copy:
10830 * @requisition: a #GtkRequisition
10832 * Copies a #GtkRequisition.
10834 * Returns: a copy of @requisition
10837 gtk_requisition_copy (const GtkRequisition *requisition)
10839 return g_slice_dup (GtkRequisition, requisition);
10843 * gtk_requisition_free:
10844 * @requisition: a #GtkRequisition
10846 * Frees a #GtkRequisition.
10849 gtk_requisition_free (GtkRequisition *requisition)
10851 g_slice_free (GtkRequisition, requisition);
10854 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10855 gtk_requisition_copy,
10856 gtk_requisition_free)
10859 * gtk_widget_get_accessible:
10860 * @widget: a #GtkWidget
10862 * Returns the accessible object that describes the widget to an
10863 * assistive technology.
10865 * If no accessibility library is loaded (i.e. no ATK implementation library is
10866 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10867 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10868 * if no class-specific #AtkObject implementation is available for the widget
10869 * instance in question, it will inherit an #AtkObject implementation from the
10870 * first ancestor class for which such an implementation is defined.
10872 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10873 * library contains more information about accessible objects and their uses.
10875 * Returns: (transfer none): the #AtkObject associated with @widget
10878 gtk_widget_get_accessible (GtkWidget *widget)
10880 GtkWidgetClass *klass;
10882 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10884 klass = GTK_WIDGET_GET_CLASS (widget);
10886 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10888 return klass->get_accessible (widget);
10892 gtk_widget_real_get_accessible (GtkWidget *widget)
10894 AtkObject* accessible;
10896 accessible = g_object_get_qdata (G_OBJECT (widget),
10897 quark_accessible_object);
10900 AtkObjectFactory *factory;
10901 AtkRegistry *default_registry;
10903 default_registry = atk_get_default_registry ();
10904 factory = atk_registry_get_factory (default_registry,
10905 G_TYPE_FROM_INSTANCE (widget));
10907 atk_object_factory_create_accessible (factory,
10908 G_OBJECT (widget));
10909 g_object_set_qdata (G_OBJECT (widget),
10910 quark_accessible_object,
10917 * Initialize a AtkImplementorIface instance's virtual pointers as
10918 * appropriate to this implementor's class (GtkWidget).
10921 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10923 iface->ref_accessible = gtk_widget_ref_accessible;
10927 gtk_widget_ref_accessible (AtkImplementor *implementor)
10929 AtkObject *accessible;
10931 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10933 g_object_ref (accessible);
10938 * GtkBuildable implementation
10940 static GQuark quark_builder_has_default = 0;
10941 static GQuark quark_builder_has_focus = 0;
10942 static GQuark quark_builder_atk_relations = 0;
10943 static GQuark quark_builder_set_name = 0;
10946 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10948 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10949 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10950 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10951 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10953 iface->set_name = gtk_widget_buildable_set_name;
10954 iface->get_name = gtk_widget_buildable_get_name;
10955 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10956 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10957 iface->parser_finished = gtk_widget_buildable_parser_finished;
10958 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10959 iface->custom_finished = gtk_widget_buildable_custom_finished;
10963 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10966 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10967 g_strdup (name), g_free);
10970 static const gchar *
10971 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10973 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10977 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10978 GtkBuilder *builder,
10979 const gchar *childname)
10981 if (strcmp (childname, "accessible") == 0)
10982 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10988 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10989 GtkBuilder *builder,
10991 const GValue *value)
10993 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10994 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10995 GINT_TO_POINTER (TRUE));
10996 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10997 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10998 GINT_TO_POINTER (TRUE));
11000 g_object_set_property (G_OBJECT (buildable), name, value);
11005 gchar *action_name;
11006 GString *description;
11008 gboolean translatable;
11018 free_action (AtkActionData *data, gpointer user_data)
11020 g_free (data->action_name);
11021 g_string_free (data->description, TRUE);
11022 g_free (data->context);
11023 g_slice_free (AtkActionData, data);
11027 free_relation (AtkRelationData *data, gpointer user_data)
11029 g_free (data->target);
11030 g_free (data->type);
11031 g_slice_free (AtkRelationData, data);
11035 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
11036 GtkBuilder *builder)
11038 GSList *atk_relations;
11040 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
11041 gtk_widget_grab_default (GTK_WIDGET (buildable));
11042 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
11043 gtk_widget_grab_focus (GTK_WIDGET (buildable));
11045 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
11046 quark_builder_atk_relations);
11049 AtkObject *accessible;
11050 AtkRelationSet *relation_set;
11053 AtkRelationType relation_type;
11054 AtkObject *target_accessible;
11056 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11057 relation_set = atk_object_ref_relation_set (accessible);
11059 for (l = atk_relations; l; l = l->next)
11061 AtkRelationData *relation = (AtkRelationData*)l->data;
11063 target = gtk_builder_get_object (builder, relation->target);
11066 g_warning ("Target object %s in <relation> does not exist",
11070 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
11071 g_assert (target_accessible != NULL);
11073 relation_type = atk_relation_type_for_name (relation->type);
11074 if (relation_type == ATK_RELATION_NULL)
11076 g_warning ("<relation> type %s not found",
11080 atk_relation_set_add_relation_by_type (relation_set, relation_type,
11081 target_accessible);
11083 g_object_unref (relation_set);
11085 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
11086 g_slist_free (atk_relations);
11087 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11096 } AccessibilitySubParserData;
11099 accessibility_start_element (GMarkupParseContext *context,
11100 const gchar *element_name,
11101 const gchar **names,
11102 const gchar **values,
11103 gpointer user_data,
11106 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11108 gint line_number, char_number;
11110 if (strcmp (element_name, "relation") == 0)
11112 gchar *target = NULL;
11113 gchar *type = NULL;
11114 AtkRelationData *relation;
11116 for (i = 0; names[i]; i++)
11118 if (strcmp (names[i], "target") == 0)
11119 target = g_strdup (values[i]);
11120 else if (strcmp (names[i], "type") == 0)
11121 type = g_strdup (values[i]);
11124 g_markup_parse_context_get_position (context,
11127 g_set_error (error,
11129 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11130 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11132 line_number, char_number, names[i], "relation");
11139 if (!target || !type)
11141 g_markup_parse_context_get_position (context,
11144 g_set_error (error,
11146 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11147 "%s:%d:%d <%s> requires attribute \"%s\"",
11149 line_number, char_number, "relation",
11150 type ? "target" : "type");
11156 relation = g_slice_new (AtkRelationData);
11157 relation->target = target;
11158 relation->type = type;
11160 data->relations = g_slist_prepend (data->relations, relation);
11162 else if (strcmp (element_name, "action") == 0)
11164 const gchar *action_name = NULL;
11165 const gchar *description = NULL;
11166 const gchar *msg_context = NULL;
11167 gboolean translatable = FALSE;
11168 AtkActionData *action;
11170 for (i = 0; names[i]; i++)
11172 if (strcmp (names[i], "action_name") == 0)
11173 action_name = values[i];
11174 else if (strcmp (names[i], "description") == 0)
11175 description = values[i];
11176 else if (strcmp (names[i], "translatable") == 0)
11178 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11181 else if (strcmp (names[i], "comments") == 0)
11183 /* do nothing, comments are for translators */
11185 else if (strcmp (names[i], "context") == 0)
11186 msg_context = values[i];
11189 g_markup_parse_context_get_position (context,
11192 g_set_error (error,
11194 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11195 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11197 line_number, char_number, names[i], "action");
11204 g_markup_parse_context_get_position (context,
11207 g_set_error (error,
11209 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11210 "%s:%d:%d <%s> requires attribute \"%s\"",
11212 line_number, char_number, "action",
11217 action = g_slice_new (AtkActionData);
11218 action->action_name = g_strdup (action_name);
11219 action->description = g_string_new (description);
11220 action->context = g_strdup (msg_context);
11221 action->translatable = translatable;
11223 data->actions = g_slist_prepend (data->actions, action);
11225 else if (strcmp (element_name, "accessibility") == 0)
11228 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11232 accessibility_text (GMarkupParseContext *context,
11235 gpointer user_data,
11238 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11240 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11242 AtkActionData *action = data->actions->data;
11244 g_string_append_len (action->description, text, text_len);
11248 static const GMarkupParser accessibility_parser =
11250 accessibility_start_element,
11252 accessibility_text,
11261 } AccelGroupParserData;
11264 accel_group_start_element (GMarkupParseContext *context,
11265 const gchar *element_name,
11266 const gchar **names,
11267 const gchar **values,
11268 gpointer user_data,
11273 guint modifiers = 0;
11274 gchar *signal = NULL;
11275 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11277 for (i = 0; names[i]; i++)
11279 if (strcmp (names[i], "key") == 0)
11280 key = gdk_keyval_from_name (values[i]);
11281 else if (strcmp (names[i], "modifiers") == 0)
11283 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11289 else if (strcmp (names[i], "signal") == 0)
11290 signal = g_strdup (values[i]);
11293 if (key == 0 || signal == NULL)
11295 g_warning ("<accelerator> requires key and signal attributes");
11298 parser_data->key = key;
11299 parser_data->modifiers = modifiers;
11300 parser_data->signal = signal;
11303 static const GMarkupParser accel_group_parser =
11305 accel_group_start_element,
11309 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11310 GtkBuilder *builder,
11312 const gchar *tagname,
11313 GMarkupParser *parser,
11316 g_assert (buildable);
11318 if (strcmp (tagname, "accelerator") == 0)
11320 AccelGroupParserData *parser_data;
11322 parser_data = g_slice_new0 (AccelGroupParserData);
11323 parser_data->object = g_object_ref (buildable);
11324 *parser = accel_group_parser;
11325 *data = parser_data;
11328 if (strcmp (tagname, "accessibility") == 0)
11330 AccessibilitySubParserData *parser_data;
11332 parser_data = g_slice_new0 (AccessibilitySubParserData);
11333 *parser = accessibility_parser;
11334 *data = parser_data;
11341 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11342 GtkWidget *toplevel,
11343 gpointer user_data)
11345 AccelGroupParserData *accel_data;
11346 GSList *accel_groups;
11347 GtkAccelGroup *accel_group;
11349 g_return_if_fail (GTK_IS_WIDGET (widget));
11350 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11351 g_return_if_fail (user_data != NULL);
11353 accel_data = (AccelGroupParserData*)user_data;
11354 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11355 if (g_slist_length (accel_groups) == 0)
11357 accel_group = gtk_accel_group_new ();
11358 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11362 g_assert (g_slist_length (accel_groups) == 1);
11363 accel_group = g_slist_nth_data (accel_groups, 0);
11366 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11367 accel_data->signal,
11370 accel_data->modifiers,
11371 GTK_ACCEL_VISIBLE);
11373 g_object_unref (accel_data->object);
11374 g_free (accel_data->signal);
11375 g_slice_free (AccelGroupParserData, accel_data);
11379 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11380 GtkBuilder *builder,
11382 const gchar *tagname,
11383 gpointer user_data)
11385 AccelGroupParserData *accel_data;
11386 AccessibilitySubParserData *a11y_data;
11387 GtkWidget *toplevel;
11389 if (strcmp (tagname, "accelerator") == 0)
11391 accel_data = (AccelGroupParserData*)user_data;
11392 g_assert (accel_data->object);
11394 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11396 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11398 else if (strcmp (tagname, "accessibility") == 0)
11400 a11y_data = (AccessibilitySubParserData*)user_data;
11402 if (a11y_data->actions)
11404 AtkObject *accessible;
11409 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11411 action = ATK_ACTION (accessible);
11412 n_actions = atk_action_get_n_actions (action);
11414 for (l = a11y_data->actions; l; l = l->next)
11416 AtkActionData *action_data = (AtkActionData*)l->data;
11418 for (i = 0; i < n_actions; i++)
11419 if (strcmp (atk_action_get_name (action, i),
11420 action_data->action_name) == 0)
11425 gchar *description;
11427 if (action_data->translatable && action_data->description->len)
11428 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11429 action_data->context,
11430 action_data->description->str);
11432 description = action_data->description->str;
11434 atk_action_set_description (action, i, description);
11438 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11439 g_slist_free (a11y_data->actions);
11442 if (a11y_data->relations)
11443 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11444 a11y_data->relations);
11446 g_slice_free (AccessibilitySubParserData, a11y_data);
11451 gtk_widget_real_get_width (GtkWidget *widget,
11452 gint *minimum_size,
11453 gint *natural_size)
11463 gtk_widget_real_get_height (GtkWidget *widget,
11464 gint *minimum_size,
11465 gint *natural_size)
11475 gtk_widget_real_get_height_for_width (GtkWidget *widget,
11477 gint *minimum_height,
11478 gint *natural_height)
11480 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
11484 gtk_widget_real_get_width_for_height (GtkWidget *widget,
11486 gint *minimum_width,
11487 gint *natural_width)
11489 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
11493 * gtk_widget_get_halign:
11494 * @widget: a #GtkWidget
11496 * Gets the value of the #GtkWidget:halign property.
11498 * Returns: the horizontal alignment of @widget
11501 gtk_widget_get_halign (GtkWidget *widget)
11503 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11504 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11508 * gtk_widget_set_halign:
11509 * @widget: a #GtkWidget
11510 * @align: the horizontal alignment
11512 * Sets the horizontal alignment of @widget.
11513 * See the #GtkWidget:halign property.
11516 gtk_widget_set_halign (GtkWidget *widget,
11519 GtkWidgetAuxInfo *aux_info;
11521 g_return_if_fail (GTK_IS_WIDGET (widget));
11523 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11525 if (aux_info->halign == align)
11528 aux_info->halign = align;
11529 gtk_widget_queue_resize (widget);
11530 g_object_notify (G_OBJECT (widget), "halign");
11534 * gtk_widget_get_valign:
11535 * @widget: a #GtkWidget
11537 * Gets the value of the #GtkWidget:valign property.
11539 * Returns: the vertical alignment of @widget
11542 gtk_widget_get_valign (GtkWidget *widget)
11544 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11545 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11549 * gtk_widget_set_valign:
11550 * @widget: a #GtkWidget
11551 * @align: the vertical alignment
11553 * Sets the vertical alignment of @widget.
11554 * See the #GtkWidget:valign property.
11557 gtk_widget_set_valign (GtkWidget *widget,
11560 GtkWidgetAuxInfo *aux_info;
11562 g_return_if_fail (GTK_IS_WIDGET (widget));
11564 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11566 if (aux_info->valign == align)
11569 aux_info->valign = align;
11570 gtk_widget_queue_resize (widget);
11571 g_object_notify (G_OBJECT (widget), "valign");
11575 * gtk_widget_get_margin_left:
11576 * @widget: a #GtkWidget
11578 * Gets the value of the #GtkWidget:margin-left property.
11580 * Returns: The left margin of @widget
11583 gtk_widget_get_margin_left (GtkWidget *widget)
11585 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11587 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11591 * gtk_widget_set_margin_left:
11592 * @widget: a #GtkWidget
11593 * @margin: the left margin
11595 * Sets the left margin of @widget.
11596 * See the #GtkWidget:margin-left property.
11599 gtk_widget_set_margin_left (GtkWidget *widget,
11602 GtkWidgetAuxInfo *aux_info;
11604 g_return_if_fail (GTK_IS_WIDGET (widget));
11605 g_return_if_fail (margin <= G_MAXINT16);
11607 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11609 if (aux_info->margin.left == margin)
11612 aux_info->margin.left = margin;
11613 gtk_widget_queue_resize (widget);
11614 g_object_notify (G_OBJECT (widget), "margin-left");
11618 * gtk_widget_get_margin_right:
11619 * @widget: a #GtkWidget
11621 * Gets the value of the #GtkWidget:margin-right property.
11623 * Returns: The left margin of @widget
11626 gtk_widget_get_margin_right (GtkWidget *widget)
11628 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11630 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11634 * gtk_widget_set_margin_right:
11635 * @widget: a #GtkWidget
11636 * @margin: the right margin
11638 * Sets the right margin of @widget.
11639 * See the #GtkWidget:margin-right property.
11642 gtk_widget_set_margin_right (GtkWidget *widget,
11645 GtkWidgetAuxInfo *aux_info;
11647 g_return_if_fail (GTK_IS_WIDGET (widget));
11648 g_return_if_fail (margin <= G_MAXINT16);
11650 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11652 if (aux_info->margin.right == margin)
11655 aux_info->margin.right = margin;
11656 gtk_widget_queue_resize (widget);
11657 g_object_notify (G_OBJECT (widget), "margin-right");
11661 * gtk_widget_get_margin_top:
11662 * @widget: a #GtkWidget
11664 * Gets the value of the #GtkWidget:margin-top property.
11666 * Returns: The top margin of @widget
11669 gtk_widget_get_margin_top (GtkWidget *widget)
11671 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11673 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11677 * gtk_widget_set_margin_top:
11678 * @widget: a #GtkWidget
11679 * @margin: the top margin
11681 * Sets the top margin of @widget.
11682 * See the #GtkWidget:margin-top property.
11685 gtk_widget_set_margin_top (GtkWidget *widget,
11688 GtkWidgetAuxInfo *aux_info;
11690 g_return_if_fail (GTK_IS_WIDGET (widget));
11691 g_return_if_fail (margin <= G_MAXINT16);
11693 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11695 if (aux_info->margin.top == margin)
11698 aux_info->margin.top = margin;
11699 gtk_widget_queue_resize (widget);
11700 g_object_notify (G_OBJECT (widget), "margin-top");
11704 * gtk_widget_get_margin_bottom:
11705 * @widget: a #GtkWidget
11707 * Gets the value of the #GtkWidget:margin-bottom property.
11709 * Returns: The bottom margin of @widget
11712 gtk_widget_get_margin_bottom (GtkWidget *widget)
11714 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11716 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11720 * gtk_widget_set_margin_bottom:
11721 * @widget: a #GtkWidget
11722 * @margin: the bottom margin
11724 * Sets the bottom margin of @widget.
11725 * See the #GtkWidget:margin-bottom property.
11728 gtk_widget_set_margin_bottom (GtkWidget *widget,
11731 GtkWidgetAuxInfo *aux_info;
11733 g_return_if_fail (GTK_IS_WIDGET (widget));
11734 g_return_if_fail (margin <= G_MAXINT16);
11736 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11738 if (aux_info->margin.bottom == margin)
11741 aux_info->margin.bottom = margin;
11742 gtk_widget_queue_resize (widget);
11743 g_object_notify (G_OBJECT (widget), "margin-bottom");
11747 * gtk_widget_get_clipboard:
11748 * @widget: a #GtkWidget
11749 * @selection: a #GdkAtom which identifies the clipboard
11750 * to use. %GDK_SELECTION_CLIPBOARD gives the
11751 * default clipboard. Another common value
11752 * is %GDK_SELECTION_PRIMARY, which gives
11753 * the primary X selection.
11755 * Returns the clipboard object for the given selection to
11756 * be used with @widget. @widget must have a #GdkDisplay
11757 * associated with it, so must be attached to a toplevel
11760 * Return value: (transfer none): the appropriate clipboard object. If no
11761 * clipboard already exists, a new one will
11762 * be created. Once a clipboard object has
11763 * been created, it is persistent for all time.
11768 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11770 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11771 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11773 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11778 * gtk_widget_list_mnemonic_labels:
11779 * @widget: a #GtkWidget
11781 * Returns a newly allocated list of the widgets, normally labels, for
11782 * which this widget is the target of a mnemonic (see for example,
11783 * gtk_label_set_mnemonic_widget()).
11785 * The widgets in the list are not individually referenced. If you
11786 * want to iterate through the list and perform actions involving
11787 * callbacks that might destroy the widgets, you
11788 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11789 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11790 * widgets afterwards.
11792 * Return value: (element-type GtkWidget) (transfer container): the list of
11793 * mnemonic labels; free this list
11794 * with g_list_free() when you are done with it.
11799 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11801 GList *list = NULL;
11804 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11806 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11807 list = g_list_prepend (list, l->data);
11813 * gtk_widget_add_mnemonic_label:
11814 * @widget: a #GtkWidget
11815 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11817 * Adds a widget to the list of mnemonic labels for
11818 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11819 * list of mnemonic labels for the widget is cleared when the
11820 * widget is destroyed, so the caller must make sure to update
11821 * its internal state at this point as well, by using a connection
11822 * to the #GtkWidget::destroy signal or a weak notifier.
11827 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11830 GSList *old_list, *new_list;
11832 g_return_if_fail (GTK_IS_WIDGET (widget));
11833 g_return_if_fail (GTK_IS_WIDGET (label));
11835 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11836 new_list = g_slist_prepend (old_list, label);
11838 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11839 new_list, (GDestroyNotify) g_slist_free);
11843 * gtk_widget_remove_mnemonic_label:
11844 * @widget: a #GtkWidget
11845 * @label: a #GtkWidget that was previously set as a mnemnic label for
11846 * @widget with gtk_widget_add_mnemonic_label().
11848 * Removes a widget from the list of mnemonic labels for
11849 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11850 * must have previously been added to the list with
11851 * gtk_widget_add_mnemonic_label().
11856 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11859 GSList *old_list, *new_list;
11861 g_return_if_fail (GTK_IS_WIDGET (widget));
11862 g_return_if_fail (GTK_IS_WIDGET (label));
11864 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11865 new_list = g_slist_remove (old_list, label);
11868 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11869 new_list, (GDestroyNotify) g_slist_free);
11873 * gtk_widget_get_no_show_all:
11874 * @widget: a #GtkWidget
11876 * Returns the current value of the GtkWidget:no-show-all property,
11877 * which determines whether calls to gtk_widget_show_all() and
11878 * gtk_widget_hide_all() will affect this widget.
11880 * Return value: the current value of the "no-show-all" property.
11885 gtk_widget_get_no_show_all (GtkWidget *widget)
11887 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11889 return widget->priv->no_show_all;
11893 * gtk_widget_set_no_show_all:
11894 * @widget: a #GtkWidget
11895 * @no_show_all: the new value for the "no-show-all" property
11897 * Sets the #GtkWidget:no-show-all property, which determines whether
11898 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11901 * This is mostly for use in constructing widget hierarchies with externally
11902 * controlled visibility, see #GtkUIManager.
11907 gtk_widget_set_no_show_all (GtkWidget *widget,
11908 gboolean no_show_all)
11910 g_return_if_fail (GTK_IS_WIDGET (widget));
11912 no_show_all = (no_show_all != FALSE);
11914 if (widget->priv->no_show_all != no_show_all)
11916 widget->priv->no_show_all = no_show_all;
11918 g_object_notify (G_OBJECT (widget), "no-show-all");
11924 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11925 gboolean has_tooltip,
11928 GtkWidgetPrivate *priv = widget->priv;
11929 gboolean priv_has_tooltip;
11931 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11932 quark_has_tooltip));
11934 if (priv_has_tooltip != has_tooltip || force)
11936 priv_has_tooltip = has_tooltip;
11938 if (priv_has_tooltip)
11940 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11941 gdk_window_set_events (priv->window,
11942 gdk_window_get_events (priv->window) |
11943 GDK_LEAVE_NOTIFY_MASK |
11944 GDK_POINTER_MOTION_MASK |
11945 GDK_POINTER_MOTION_HINT_MASK);
11947 if (gtk_widget_get_has_window (widget))
11948 gtk_widget_add_events (widget,
11949 GDK_LEAVE_NOTIFY_MASK |
11950 GDK_POINTER_MOTION_MASK |
11951 GDK_POINTER_MOTION_HINT_MASK);
11954 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11955 GUINT_TO_POINTER (priv_has_tooltip));
11960 * gtk_widget_set_tooltip_window:
11961 * @widget: a #GtkWidget
11962 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11964 * Replaces the default, usually yellow, window used for displaying
11965 * tooltips with @custom_window. GTK+ will take care of showing and
11966 * hiding @custom_window at the right moment, to behave likewise as
11967 * the default tooltip window. If @custom_window is %NULL, the default
11968 * tooltip window will be used.
11970 * If the custom window should have the default theming it needs to
11971 * have the name "gtk-tooltip", see gtk_widget_set_name().
11976 gtk_widget_set_tooltip_window (GtkWidget *widget,
11977 GtkWindow *custom_window)
11979 gboolean has_tooltip;
11980 gchar *tooltip_markup;
11982 g_return_if_fail (GTK_IS_WIDGET (widget));
11983 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11985 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11988 g_object_ref (custom_window);
11990 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11991 custom_window, g_object_unref);
11993 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11994 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11996 if (has_tooltip && gtk_widget_get_visible (widget))
11997 gtk_widget_queue_tooltip_query (widget);
12001 * gtk_widget_get_tooltip_window:
12002 * @widget: a #GtkWidget
12004 * Returns the #GtkWindow of the current tooltip. This can be the
12005 * GtkWindow created by default, or the custom tooltip window set
12006 * using gtk_widget_set_tooltip_window().
12008 * Return value: (transfer none): The #GtkWindow of the current tooltip.
12013 gtk_widget_get_tooltip_window (GtkWidget *widget)
12015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12017 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
12021 * gtk_widget_trigger_tooltip_query:
12022 * @widget: a #GtkWidget
12024 * Triggers a tooltip query on the display where the toplevel of @widget
12025 * is located. See gtk_tooltip_trigger_tooltip_query() for more
12031 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
12033 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
12036 static guint tooltip_query_id;
12037 static GSList *tooltip_query_displays;
12040 tooltip_query_idle (gpointer data)
12042 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
12043 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
12044 g_slist_free (tooltip_query_displays);
12046 tooltip_query_displays = NULL;
12047 tooltip_query_id = 0;
12053 gtk_widget_queue_tooltip_query (GtkWidget *widget)
12055 GdkDisplay *display;
12057 display = gtk_widget_get_display (widget);
12059 if (!g_slist_find (tooltip_query_displays, display))
12060 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
12062 if (tooltip_query_id == 0)
12063 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
12067 * gtk_widget_set_tooltip_text:
12068 * @widget: a #GtkWidget
12069 * @text: the contents of the tooltip for @widget
12071 * Sets @text as the contents of the tooltip. This function will take
12072 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
12073 * handler for the GtkWidget::query-tooltip signal.
12075 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
12080 gtk_widget_set_tooltip_text (GtkWidget *widget,
12083 g_return_if_fail (GTK_IS_WIDGET (widget));
12085 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
12089 * gtk_widget_get_tooltip_text:
12090 * @widget: a #GtkWidget
12092 * Gets the contents of the tooltip for @widget.
12094 * Return value: the tooltip text, or %NULL. You should free the
12095 * returned string with g_free() when done.
12100 gtk_widget_get_tooltip_text (GtkWidget *widget)
12102 gchar *text = NULL;
12104 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12106 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
12112 * gtk_widget_set_tooltip_markup:
12113 * @widget: a #GtkWidget
12114 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
12116 * Sets @markup as the contents of the tooltip, which is marked up with
12117 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
12119 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
12120 * and of the default handler for the GtkWidget::query-tooltip signal.
12122 * See also the GtkWidget:tooltip-markup property and
12123 * gtk_tooltip_set_markup().
12128 gtk_widget_set_tooltip_markup (GtkWidget *widget,
12129 const gchar *markup)
12131 g_return_if_fail (GTK_IS_WIDGET (widget));
12133 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
12137 * gtk_widget_get_tooltip_markup:
12138 * @widget: a #GtkWidget
12140 * Gets the contents of the tooltip for @widget.
12142 * Return value: the tooltip text, or %NULL. You should free the
12143 * returned string with g_free() when done.
12148 gtk_widget_get_tooltip_markup (GtkWidget *widget)
12150 gchar *text = NULL;
12152 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12154 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
12160 * gtk_widget_set_has_tooltip:
12161 * @widget: a #GtkWidget
12162 * @has_tooltip: whether or not @widget has a tooltip.
12164 * Sets the has-tooltip property on @widget to @has_tooltip. See
12165 * GtkWidget:has-tooltip for more information.
12170 gtk_widget_set_has_tooltip (GtkWidget *widget,
12171 gboolean has_tooltip)
12173 g_return_if_fail (GTK_IS_WIDGET (widget));
12175 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12179 * gtk_widget_get_has_tooltip:
12180 * @widget: a #GtkWidget
12182 * Returns the current value of the has-tooltip property. See
12183 * GtkWidget:has-tooltip for more information.
12185 * Return value: current value of has-tooltip on @widget.
12190 gtk_widget_get_has_tooltip (GtkWidget *widget)
12192 gboolean has_tooltip = FALSE;
12194 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12196 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12198 return has_tooltip;
12202 * gtk_widget_get_allocation:
12203 * @widget: a #GtkWidget
12204 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12206 * Retrieves the widget's allocation.
12208 * Note, when implementing a #GtkContainer: a widget's allocation will
12209 * be its "adjusted" allocation, that is, the widget's parent
12210 * container typically calls gtk_widget_size_allocate() with an
12211 * allocation, and that allocation is then adjusted (to handle margin
12212 * and alignment for example) before assignment to the widget.
12213 * gtk_widget_get_allocation() returns the adjusted allocation that
12214 * was actually assigned to the widget. The adjusted allocation is
12215 * guaranteed to be completely contained within the
12216 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12217 * is guaranteed that its children stay inside the assigned bounds,
12218 * but not that they have exactly the bounds the container assigned.
12219 * There is no way to get the original allocation assigned by
12220 * gtk_widget_size_allocate(), since it isn't stored; if a container
12221 * implementation needs that information it will have to track it itself.
12226 gtk_widget_get_allocation (GtkWidget *widget,
12227 GtkAllocation *allocation)
12229 GtkWidgetPrivate *priv;
12231 g_return_if_fail (GTK_IS_WIDGET (widget));
12232 g_return_if_fail (allocation != NULL);
12234 priv = widget->priv;
12236 *allocation = priv->allocation;
12240 * gtk_widget_set_allocation:
12241 * @widget: a #GtkWidget
12242 * @allocation: a pointer to a #GtkAllocation to copy from
12244 * Sets the widget's allocation. This should not be used
12245 * directly, but from within a widget's size_allocate method.
12247 * The allocation set should be the "adjusted" or actual
12248 * allocation. If you're implementing a #GtkContainer, you want to use
12249 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12250 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12251 * allocation inside gtk_widget_size_allocate() to create an adjusted
12257 gtk_widget_set_allocation (GtkWidget *widget,
12258 const GtkAllocation *allocation)
12260 GtkWidgetPrivate *priv;
12262 g_return_if_fail (GTK_IS_WIDGET (widget));
12263 g_return_if_fail (allocation != NULL);
12265 priv = widget->priv;
12267 priv->allocation = *allocation;
12271 * gtk_widget_get_allocated_width:
12272 * @widget: the widget to query
12274 * Returns the width that has currently been allocated to @widget.
12275 * This function is intended to be used when implementing handlers
12276 * for the GtkWidget::draw function.
12278 * Returns: the width of the @widget
12281 gtk_widget_get_allocated_width (GtkWidget *widget)
12283 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12285 return widget->priv->allocation.width;
12289 * gtk_widget_get_allocated_height:
12290 * @widget: the widget to query
12292 * Returns the height that has currently been allocated to @widget.
12293 * This function is intended to be used when implementing handlers
12294 * for the GtkWidget::draw function.
12296 * Returns: the height of the @widget
12299 gtk_widget_get_allocated_height (GtkWidget *widget)
12301 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12303 return widget->priv->allocation.height;
12307 * gtk_widget_get_requisition:
12308 * @widget: a #GtkWidget
12309 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12311 * Retrieves the widget's requisition.
12313 * This function should only be used by widget implementations in
12314 * order to figure whether the widget's requisition has actually
12315 * changed after some internal state change (so that they can call
12316 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12318 * Normally, gtk_widget_size_request() should be used.
12322 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12323 * removed, If you need to cache sizes across requests and allocations,
12324 * add an explicit cache to the widget in question instead.
12327 gtk_widget_get_requisition (GtkWidget *widget,
12328 GtkRequisition *requisition)
12330 g_return_if_fail (GTK_IS_WIDGET (widget));
12331 g_return_if_fail (requisition != NULL);
12333 gtk_widget_get_preferred_size (widget, requisition, NULL);
12337 * gtk_widget_set_window:
12338 * @widget: a #GtkWidget
12339 * @window: a #GdkWindow
12341 * Sets a widget's window. This function should only be used in a
12342 * widget's GtkWidget::realize() implementation. The %window passed is
12343 * usually either new window created with gdk_window_new(), or the
12344 * window of its parent widget as returned by
12345 * gtk_widget_get_parent_window().
12347 * Widgets must indicate whether they will create their own #GdkWindow
12348 * by calling gtk_widget_set_has_window(). This is usually done in the
12349 * widget's init() function.
12351 * <note><para>This function does not add any reference to @window.</para></note>
12356 gtk_widget_set_window (GtkWidget *widget,
12359 GtkWidgetPrivate *priv;
12361 g_return_if_fail (GTK_IS_WIDGET (widget));
12362 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12364 priv = widget->priv;
12366 if (priv->window != window)
12368 priv->window = window;
12369 g_object_notify (G_OBJECT (widget), "window");
12374 * gtk_widget_get_window:
12375 * @widget: a #GtkWidget
12377 * Returns the widget's window if it is realized, %NULL otherwise
12379 * Return value: (transfer none): @widget's window.
12384 gtk_widget_get_window (GtkWidget *widget)
12386 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12388 return widget->priv->window;
12392 * gtk_widget_get_support_multidevice:
12393 * @widget: a #GtkWidget
12395 * Returns %TRUE if @widget is multiple pointer aware. See
12396 * gtk_widget_set_support_multidevice() for more information.
12398 * Returns: %TRUE is @widget is multidevice aware.
12401 gtk_widget_get_support_multidevice (GtkWidget *widget)
12403 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12405 return widget->priv->multidevice;
12409 * gtk_widget_set_support_multidevice:
12410 * @widget: a #GtkWidget
12411 * @support_multidevice: %TRUE to support input from multiple devices.
12413 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12414 * @widget will start receiving multiple, per device enter/leave events. Note
12415 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12416 * gdk_window_set_support_multidevice() will have to be called manually on them.
12421 gtk_widget_set_support_multidevice (GtkWidget *widget,
12422 gboolean support_multidevice)
12424 GtkWidgetPrivate *priv;
12426 g_return_if_fail (GTK_IS_WIDGET (widget));
12428 priv = widget->priv;
12430 if (support_multidevice)
12432 priv->multidevice = TRUE;
12433 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12437 priv->multidevice = FALSE;
12438 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12441 if (gtk_widget_get_realized (widget))
12442 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12446 _gtk_widget_set_has_focus (GtkWidget *widget,
12447 gboolean has_focus)
12449 widget->priv->has_focus = has_focus;
12453 * gtk_widget_send_focus_change:
12454 * @widget: a #GtkWidget
12455 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12457 * Sends the focus change @event to @widget
12459 * This function is not meant to be used by applications. The only time it
12460 * should be used is when it is necessary for a #GtkWidget to assign focus
12461 * to a widget that is semantically owned by the first widget even though
12462 * it's not a direct child - for instance, a search entry in a floating
12463 * window similar to the quick search in #GtkTreeView.
12465 * An example of its usage is:
12468 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12470 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12471 * fevent->focus_change.in = TRUE;
12472 * fevent->focus_change.window = gtk_widget_get_window (widget);
12473 * if (fevent->focus_change.window != NULL)
12474 * g_object_ref (fevent->focus_change.window);
12476 * gtk_widget_send_focus_change (widget, fevent);
12478 * gdk_event_free (event);
12481 * Return value: the return value from the event signal emission: %TRUE
12482 * if the event was handled, and %FALSE otherwise
12487 gtk_widget_send_focus_change (GtkWidget *widget,
12492 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12493 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12495 g_object_ref (widget);
12497 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12499 res = gtk_widget_event (widget, event);
12501 g_object_notify (G_OBJECT (widget), "has-focus");
12503 g_object_unref (widget);
12509 gtk_widget_in_destruction (GtkWidget *widget)
12511 return widget->priv->in_destruction;
12515 _gtk_widget_get_resize_pending (GtkWidget *widget)
12517 return widget->priv->resize_pending;
12521 _gtk_widget_set_resize_pending (GtkWidget *widget,
12522 gboolean resize_pending)
12524 widget->priv->resize_pending = resize_pending;
12528 _gtk_widget_get_in_reparent (GtkWidget *widget)
12530 return widget->priv->in_reparent;
12534 _gtk_widget_set_in_reparent (GtkWidget *widget,
12535 gboolean in_reparent)
12537 widget->priv->in_reparent = in_reparent;
12541 _gtk_widget_get_anchored (GtkWidget *widget)
12543 return widget->priv->anchored;
12547 _gtk_widget_set_anchored (GtkWidget *widget,
12550 widget->priv->anchored = anchored;
12554 _gtk_widget_get_shadowed (GtkWidget *widget)
12556 return widget->priv->shadowed;
12560 _gtk_widget_set_shadowed (GtkWidget *widget,
12563 widget->priv->shadowed = shadowed;
12567 _gtk_widget_get_alloc_needed (GtkWidget *widget)
12569 return widget->priv->alloc_needed;
12573 _gtk_widget_set_alloc_needed (GtkWidget *widget,
12574 gboolean alloc_needed)
12576 widget->priv->alloc_needed = alloc_needed;
12580 _gtk_widget_get_width_request_needed (GtkWidget *widget)
12582 return widget->priv->width_request_needed;
12586 _gtk_widget_set_width_request_needed (GtkWidget *widget,
12587 gboolean width_request_needed)
12589 widget->priv->width_request_needed = width_request_needed;
12593 _gtk_widget_get_height_request_needed (GtkWidget *widget)
12595 return widget->priv->height_request_needed;
12599 _gtk_widget_set_height_request_needed (GtkWidget *widget,
12600 gboolean height_request_needed)
12602 widget->priv->height_request_needed = height_request_needed;