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"
64 * @Short_description: Base class for all widgets
67 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
68 * widget lifecycle, states and style.
70 * <refsect2 id="style-properties">
72 * <structname>GtkWidget</structname> introduces <firstterm>style
73 * properties</firstterm> - these are basically object properties that are stored
74 * not on the object, but in the style object associated to the widget. Style
75 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
76 * This mechanism is used for configuring such things as the location of the
77 * scrollbar arrows through the theme, giving theme authors more control over the
78 * look of applications without the need to write a theme engine in C.
81 * Use gtk_widget_class_install_style_property() to install style properties for
82 * a widget class, gtk_widget_class_find_style_property() or
83 * gtk_widget_class_list_style_properties() to get information about existing
84 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
85 * gtk_widget_style_get_valist() to obtain the value of a style property.
88 * <refsect2 id="GtkWidget-BUILDER-UI">
89 * <title>GtkWidget as GtkBuildable</title>
91 * The GtkWidget implementation of the GtkBuildable interface supports a
92 * custom <accelerator> element, which has attributes named key,
93 * modifiers and signal and allows to specify accelerators.
96 * <title>A UI definition fragment specifying an accelerator</title>
97 * <programlisting><![CDATA[
98 * <object class="GtkButton">
99 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
101 * ]]></programlisting>
104 * In addition to accelerators, <structname>GtkWidget</structname> also support a
105 * custom <accessible> element, which supports actions and relations.
106 * Properties on the accessible implementation of an object can be set by accessing the
107 * internal child "accessible" of a <structname>GtkWidget</structname>.
110 * <title>A UI definition fragment specifying an accessible</title>
111 * <programlisting><![CDATA[
112 * <object class="GtkButton" id="label1"/>
113 * <property name="label">I am a Label for a Button</property>
115 * <object class="GtkButton" id="button1">
117 * <action action_name="click" translatable="yes">Click the button.</action>
118 * <relation target="label1" type="labelled-by"/>
120 * <child internal-child="accessible">
121 * <object class="AtkObject" id="a11y-button1">
122 * <property name="AtkObject::name">Clickable Button</property>
126 * ]]></programlisting>
131 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
132 #define INIT_PATH_SIZE (512)
134 struct _GtkWidgetPrivate
136 /* The state of the widget. There are actually only
137 * 5 widget states (defined in "gtkenums.h")
142 /* The saved state of the widget. When a widget's state
143 * is changed to GTK_STATE_INSENSITIVE via
144 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
145 * the old state is kept around in this field. The state
146 * will be restored once the widget gets sensitive again.
148 guint saved_state : 3;
150 /* unused bits in our 32-bit block */
153 /* The widget's name. If the widget does not have a name
154 * (the name is NULL), then its name (as returned by
155 * "gtk_widget_get_name") is its class's name.
156 * Among other things, the widget name is used to determine
157 * the style to use for a widget.
161 /* The style for the widget. The style contains the
162 * colors the widget should be drawn in for each state
163 * along with graphics contexts used to draw with and
164 * the font to use for text.
168 /* The widget's allocated size.
170 GtkAllocation allocation;
172 /* The widget's requested sizes */
173 SizeRequestCache requests;
175 /* The widget's window or its parent window if it does
176 * not have a window. (Which will be indicated by the
177 * GTK_NO_WINDOW flag being set).
181 /* The widget's parent.
210 BUTTON_RELEASE_EVENT,
225 PROPERTY_NOTIFY_EVENT,
226 SELECTION_CLEAR_EVENT,
227 SELECTION_REQUEST_EVENT,
228 SELECTION_NOTIFY_EVENT,
243 VISIBILITY_NOTIFY_EVENT,
247 ACCEL_CLOSURES_CHANGED,
273 PROP_RECEIVES_DEFAULT,
274 PROP_COMPOSITE_CHILD,
277 PROP_EXTENSION_EVENTS,
283 PROP_DOUBLE_BUFFERED,
293 typedef struct _GtkStateData GtkStateData;
298 guint state_restoration : 1;
299 guint parent_sensitive : 1;
300 guint use_forall : 1;
303 /* --- prototypes --- */
304 static void gtk_widget_class_init (GtkWidgetClass *klass);
305 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
306 static void gtk_widget_init (GtkWidget *widget);
307 static void gtk_widget_set_property (GObject *object,
311 static void gtk_widget_get_property (GObject *object,
315 static void gtk_widget_dispose (GObject *object);
316 static void gtk_widget_real_destroy (GtkObject *object);
317 static void gtk_widget_finalize (GObject *object);
318 static void gtk_widget_real_show (GtkWidget *widget);
319 static void gtk_widget_real_hide (GtkWidget *widget);
320 static void gtk_widget_real_map (GtkWidget *widget);
321 static void gtk_widget_real_unmap (GtkWidget *widget);
322 static void gtk_widget_real_realize (GtkWidget *widget);
323 static void gtk_widget_real_unrealize (GtkWidget *widget);
324 static void gtk_widget_real_size_request (GtkWidget *widget,
325 GtkRequisition *requisition);
326 static void gtk_widget_real_size_allocate (GtkWidget *widget,
327 GtkAllocation *allocation);
328 static void gtk_widget_real_style_set (GtkWidget *widget,
329 GtkStyle *previous_style);
330 static void gtk_widget_real_direction_changed(GtkWidget *widget,
331 GtkTextDirection previous_direction);
333 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
334 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
337 gboolean keyboard_tip,
338 GtkTooltip *tooltip);
339 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
340 GtkWidgetHelpType help_type);
342 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
344 GParamSpec **pspecs);
345 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
347 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
349 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
350 GdkEventFocus *event);
351 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
352 GdkEventFocus *event);
353 static gboolean gtk_widget_real_focus (GtkWidget *widget,
354 GtkDirectionType direction);
355 static void gtk_widget_real_move_focus (GtkWidget *widget,
356 GtkDirectionType direction);
357 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
358 GtkDirectionType direction);
359 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
360 static void gtk_widget_update_pango_context (GtkWidget *widget);
361 static void gtk_widget_propagate_state (GtkWidget *widget,
363 static void gtk_widget_reset_rc_style (GtkWidget *widget);
364 static void gtk_widget_set_style_internal (GtkWidget *widget,
366 gboolean initial_emission);
367 static gint gtk_widget_event_internal (GtkWidget *widget,
369 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
370 gboolean group_cycling);
371 static void gtk_widget_real_get_width (GtkWidget *widget,
374 static void gtk_widget_real_get_height (GtkWidget *widget,
377 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
379 gint *minimum_height,
380 gint *natural_height);
381 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
384 gint *natural_width);
385 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
386 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
387 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
388 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
389 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
390 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
391 cairo_region_t *region);
392 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
393 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
394 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
397 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
398 gboolean has_tooltip,
400 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
401 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
403 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
404 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
406 const gchar *childname);
407 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
410 const GValue *value);
411 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
414 const gchar *tagname,
415 GMarkupParser *parser,
417 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
420 const gchar *tagname,
422 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
423 GtkBuilder *builder);
425 static void gtk_widget_real_get_width (GtkWidget *widget,
428 static void gtk_widget_real_get_height (GtkWidget *widget,
432 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
435 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
436 GtkOrientation orientation,
440 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
441 GtkAllocation *allocation);
443 static void gtk_widget_set_usize_internal (GtkWidget *widget,
447 static void gtk_widget_add_events_internal (GtkWidget *widget,
451 /* --- variables --- */
452 static gpointer gtk_widget_parent_class = NULL;
453 static guint widget_signals[LAST_SIGNAL] = { 0 };
454 static GtkStyle *gtk_default_style = NULL;
455 static guint composite_child_stack = 0;
456 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
457 static GParamSpecPool *style_property_spec_pool = NULL;
459 static GQuark quark_property_parser = 0;
460 static GQuark quark_aux_info = 0;
461 static GQuark quark_accel_path = 0;
462 static GQuark quark_accel_closures = 0;
463 static GQuark quark_event_mask = 0;
464 static GQuark quark_device_event_mask = 0;
465 static GQuark quark_extension_event_mode = 0;
466 static GQuark quark_parent_window = 0;
467 static GQuark quark_pointer_window = 0;
468 static GQuark quark_shape_info = 0;
469 static GQuark quark_input_shape_info = 0;
470 static GQuark quark_pango_context = 0;
471 static GQuark quark_rc_style = 0;
472 static GQuark quark_accessible_object = 0;
473 static GQuark quark_mnemonic_labels = 0;
474 static GQuark quark_tooltip_markup = 0;
475 static GQuark quark_has_tooltip = 0;
476 static GQuark quark_tooltip_window = 0;
477 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
478 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
480 /* --- functions --- */
482 gtk_widget_get_type (void)
484 static GType widget_type = 0;
486 if (G_UNLIKELY (widget_type == 0))
488 const GTypeInfo widget_info =
490 sizeof (GtkWidgetClass),
491 NULL, /* base_init */
492 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
493 (GClassInitFunc) gtk_widget_class_init,
494 NULL, /* class_finalize */
495 NULL, /* class_init */
498 (GInstanceInitFunc) gtk_widget_init,
499 NULL, /* value_table */
502 const GInterfaceInfo accessibility_info =
504 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
505 (GInterfaceFinalizeFunc) NULL,
506 NULL /* interface data */
509 const GInterfaceInfo buildable_info =
511 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
512 (GInterfaceFinalizeFunc) NULL,
513 NULL /* interface data */
516 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
517 &widget_info, G_TYPE_FLAG_ABSTRACT);
519 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
520 &accessibility_info) ;
521 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
529 child_property_notify_dispatcher (GObject *object,
533 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
536 /* We guard against the draw signal callbacks modifying the state of the
537 * cairo context by surounding it with save/restore.
538 * Maybe we should also cairo_new_path() just to be sure?
541 gtk_widget_draw_marshaller (GClosure *closure,
542 GValue *return_value,
543 guint n_param_values,
544 const GValue *param_values,
545 gpointer invocation_hint,
546 gpointer marshal_data)
548 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
552 _gtk_marshal_BOOLEAN__BOXED (closure,
563 gtk_widget_class_init (GtkWidgetClass *klass)
565 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
566 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
567 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
568 GtkBindingSet *binding_set;
570 gtk_widget_parent_class = g_type_class_peek_parent (klass);
572 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
573 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
574 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
575 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
576 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
577 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
578 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
579 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
580 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
581 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
582 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
583 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
584 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
585 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
586 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
587 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
588 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
589 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
591 style_property_spec_pool = g_param_spec_pool_new (FALSE);
592 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
593 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
594 cpn_context.dispatcher = child_property_notify_dispatcher;
595 _gtk_widget_child_property_notify_context = &cpn_context;
597 gobject_class->dispose = gtk_widget_dispose;
598 gobject_class->finalize = gtk_widget_finalize;
599 gobject_class->set_property = gtk_widget_set_property;
600 gobject_class->get_property = gtk_widget_get_property;
602 object_class->destroy = gtk_widget_real_destroy;
604 klass->activate_signal = 0;
605 klass->set_scroll_adjustments_signal = 0;
606 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
607 klass->show = gtk_widget_real_show;
608 klass->show_all = gtk_widget_show;
609 klass->hide = gtk_widget_real_hide;
610 klass->hide_all = gtk_widget_hide;
611 klass->map = gtk_widget_real_map;
612 klass->unmap = gtk_widget_real_unmap;
613 klass->realize = gtk_widget_real_realize;
614 klass->unrealize = gtk_widget_real_unrealize;
615 klass->size_request = gtk_widget_real_size_request;
616 klass->size_allocate = gtk_widget_real_size_allocate;
617 klass->get_preferred_width = gtk_widget_real_get_width;
618 klass->get_preferred_height = gtk_widget_real_get_height;
619 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
620 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
621 klass->state_changed = NULL;
622 klass->parent_set = NULL;
623 klass->hierarchy_changed = NULL;
624 klass->style_set = gtk_widget_real_style_set;
625 klass->direction_changed = gtk_widget_real_direction_changed;
626 klass->grab_notify = NULL;
627 klass->child_notify = NULL;
629 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
630 klass->grab_focus = gtk_widget_real_grab_focus;
631 klass->focus = gtk_widget_real_focus;
633 klass->button_press_event = NULL;
634 klass->button_release_event = NULL;
635 klass->motion_notify_event = NULL;
636 klass->delete_event = NULL;
637 klass->destroy_event = NULL;
638 klass->key_press_event = gtk_widget_real_key_press_event;
639 klass->key_release_event = gtk_widget_real_key_release_event;
640 klass->enter_notify_event = NULL;
641 klass->leave_notify_event = NULL;
642 klass->configure_event = NULL;
643 klass->focus_in_event = gtk_widget_real_focus_in_event;
644 klass->focus_out_event = gtk_widget_real_focus_out_event;
645 klass->map_event = NULL;
646 klass->unmap_event = NULL;
647 klass->window_state_event = NULL;
648 klass->property_notify_event = _gtk_selection_property_notify;
649 klass->selection_clear_event = _gtk_selection_clear;
650 klass->selection_request_event = _gtk_selection_request;
651 klass->selection_notify_event = _gtk_selection_notify;
652 klass->selection_received = NULL;
653 klass->proximity_in_event = NULL;
654 klass->proximity_out_event = NULL;
655 klass->drag_begin = NULL;
656 klass->drag_end = NULL;
657 klass->drag_data_delete = NULL;
658 klass->drag_leave = NULL;
659 klass->drag_motion = NULL;
660 klass->drag_drop = NULL;
661 klass->drag_data_received = NULL;
662 klass->screen_changed = NULL;
663 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
664 klass->grab_broken_event = NULL;
665 klass->query_tooltip = gtk_widget_real_query_tooltip;
667 klass->show_help = gtk_widget_real_show_help;
669 /* Accessibility support */
670 klass->get_accessible = gtk_widget_real_get_accessible;
672 klass->no_expose_event = NULL;
674 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
675 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
677 g_object_class_install_property (gobject_class,
679 g_param_spec_string ("name",
681 P_("The name of the widget"),
683 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_object ("parent",
688 P_("The parent widget of this widget. Must be a Container widget"),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (gobject_class,
694 g_param_spec_int ("width-request",
696 P_("Override for width request of the widget, or -1 if natural request should be used"),
700 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_int ("height-request",
704 P_("Height request"),
705 P_("Override for height request of the widget, or -1 if natural request should be used"),
709 GTK_PARAM_READWRITE));
710 g_object_class_install_property (gobject_class,
712 g_param_spec_boolean ("visible",
714 P_("Whether the widget is visible"),
716 GTK_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class,
719 g_param_spec_boolean ("sensitive",
721 P_("Whether the widget responds to input"),
723 GTK_PARAM_READWRITE));
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("app-paintable",
727 P_("Application paintable"),
728 P_("Whether the application will paint directly on the widget"),
730 GTK_PARAM_READWRITE));
731 g_object_class_install_property (gobject_class,
733 g_param_spec_boolean ("can-focus",
735 P_("Whether the widget can accept the input focus"),
737 GTK_PARAM_READWRITE));
738 g_object_class_install_property (gobject_class,
740 g_param_spec_boolean ("has-focus",
742 P_("Whether the widget has the input focus"),
744 GTK_PARAM_READWRITE));
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("is-focus",
749 P_("Whether the widget is the focus widget within the toplevel"),
751 GTK_PARAM_READWRITE));
752 g_object_class_install_property (gobject_class,
754 g_param_spec_boolean ("can-default",
756 P_("Whether the widget can be the default widget"),
758 GTK_PARAM_READWRITE));
759 g_object_class_install_property (gobject_class,
761 g_param_spec_boolean ("has-default",
763 P_("Whether the widget is the default widget"),
765 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
767 PROP_RECEIVES_DEFAULT,
768 g_param_spec_boolean ("receives-default",
769 P_("Receives default"),
770 P_("If TRUE, the widget will receive the default action when it is focused"),
772 GTK_PARAM_READWRITE));
773 g_object_class_install_property (gobject_class,
774 PROP_COMPOSITE_CHILD,
775 g_param_spec_boolean ("composite-child",
776 P_("Composite child"),
777 P_("Whether the widget is part of a composite widget"),
779 GTK_PARAM_READABLE));
780 g_object_class_install_property (gobject_class,
782 g_param_spec_object ("style",
784 P_("The style of the widget, which contains information about how it will look (colors etc)"),
786 GTK_PARAM_READWRITE));
787 g_object_class_install_property (gobject_class,
789 g_param_spec_flags ("events",
791 P_("The event mask that decides what kind of GdkEvents this widget gets"),
794 GTK_PARAM_READWRITE));
795 g_object_class_install_property (gobject_class,
796 PROP_EXTENSION_EVENTS,
797 g_param_spec_enum ("extension-events",
798 P_("Extension events"),
799 P_("The mask that decides what kind of extension events this widget gets"),
800 GDK_TYPE_EXTENSION_MODE,
801 GDK_EXTENSION_EVENTS_NONE,
802 GTK_PARAM_READWRITE));
803 g_object_class_install_property (gobject_class,
805 g_param_spec_boolean ("no-show-all",
807 P_("Whether gtk_widget_show_all() should not affect this widget"),
809 GTK_PARAM_READWRITE));
812 * GtkWidget:has-tooltip:
814 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
815 * A value of %TRUE indicates that @widget can have a tooltip, in this case
816 * the widget will be queried using #GtkWidget::query-tooltip to determine
817 * whether it will provide a tooltip or not.
819 * Note that setting this property to %TRUE for the first time will change
820 * the event masks of the GdkWindows of this widget to include leave-notify
821 * and motion-notify events. This cannot and will not be undone when the
822 * property is set to %FALSE again.
826 g_object_class_install_property (gobject_class,
828 g_param_spec_boolean ("has-tooltip",
830 P_("Whether this widget has a tooltip"),
832 GTK_PARAM_READWRITE));
834 * GtkWidget:tooltip-text:
836 * Sets the text of tooltip to be the given string.
838 * Also see gtk_tooltip_set_text().
840 * This is a convenience property which will take care of getting the
841 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
842 * will automatically be set to %TRUE and there will be taken care of
843 * #GtkWidget::query-tooltip in the default signal handler.
847 g_object_class_install_property (gobject_class,
849 g_param_spec_string ("tooltip-text",
851 P_("The contents of the tooltip for this widget"),
853 GTK_PARAM_READWRITE));
855 * GtkWidget:tooltip-markup:
857 * Sets the text of tooltip to be the given string, which is marked up
858 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
859 * Also see gtk_tooltip_set_markup().
861 * This is a convenience property which will take care of getting the
862 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
863 * will automatically be set to %TRUE and there will be taken care of
864 * #GtkWidget::query-tooltip in the default signal handler.
868 g_object_class_install_property (gobject_class,
870 g_param_spec_string ("tooltip-markup",
871 P_("Tooltip markup"),
872 P_("The contents of the tooltip for this widget"),
874 GTK_PARAM_READWRITE));
879 * The widget's window if it is realized, %NULL otherwise.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_object ("window",
887 P_("The widget's window if it is realized"),
889 GTK_PARAM_READABLE));
892 * GtkWidget:double-buffered
894 * Whether the widget is double buffered.
898 g_object_class_install_property (gobject_class,
899 PROP_DOUBLE_BUFFERED,
900 g_param_spec_boolean ("double-buffered",
901 P_("Double Buffered"),
902 P_("Whether the widget is double buffered"),
904 GTK_PARAM_READWRITE));
909 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
913 g_object_class_install_property (gobject_class,
915 g_param_spec_enum ("halign",
916 P_("Horizontal Alignment"),
917 P_("How to position in extra horizontal space"),
920 GTK_PARAM_READWRITE));
925 * How to distribute vertical space if widget gets extra space, see #GtkAlign
929 g_object_class_install_property (gobject_class,
931 g_param_spec_enum ("valign",
932 P_("Vertical Alignment"),
933 P_("How to position in extra vertical space"),
936 GTK_PARAM_READWRITE));
939 * GtkWidget:margin-left
941 * Margin on left side of widget.
943 * This property adds margin outside of the widget's normal size
944 * request, the margin will be added in addition to the size from
945 * gtk_widget_set_size_request() for example.
949 g_object_class_install_property (gobject_class,
951 g_param_spec_int ("margin-left",
952 P_("Margin on Left"),
953 P_("Pixels of extra space on the left side"),
957 GTK_PARAM_READWRITE));
960 * GtkWidget:margin-right
962 * Margin on right side of widget.
964 * This property adds margin outside of the widget's normal size
965 * request, the margin will be added in addition to the size from
966 * gtk_widget_set_size_request() for example.
970 g_object_class_install_property (gobject_class,
972 g_param_spec_int ("margin-right",
973 P_("Margin on Right"),
974 P_("Pixels of extra space on the right side"),
978 GTK_PARAM_READWRITE));
981 * GtkWidget:margin-top
983 * Margin on top side of widget.
985 * This property adds margin outside of the widget's normal size
986 * request, the margin will be added in addition to the size from
987 * gtk_widget_set_size_request() for example.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_int ("margin-top",
995 P_("Pixels of extra space on the top side"),
999 GTK_PARAM_READWRITE));
1002 * GtkWidget:margin-bottom
1004 * Margin on bottom side of widget.
1006 * This property adds margin outside of the widget's normal size
1007 * request, the margin will be added in addition to the size from
1008 * gtk_widget_set_size_request() for example.
1012 g_object_class_install_property (gobject_class,
1014 g_param_spec_int ("margin-bottom",
1015 P_("Margin on Bottom"),
1016 P_("Pixels of extra space on the bottom side"),
1020 GTK_PARAM_READWRITE));
1025 * Sets all four sides' margin at once. If read, returns max
1026 * margin on any side.
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_int ("margin",
1034 P_("Pixels of extra space on all four sides"),
1038 GTK_PARAM_READWRITE));
1042 * @widget: the object which received the signal.
1044 widget_signals[SHOW] =
1045 g_signal_new (I_("show"),
1046 G_TYPE_FROM_CLASS (gobject_class),
1048 G_STRUCT_OFFSET (GtkWidgetClass, show),
1050 _gtk_marshal_VOID__VOID,
1055 * @widget: the object which received the signal.
1057 widget_signals[HIDE] =
1058 g_signal_new (I_("hide"),
1059 G_TYPE_FROM_CLASS (gobject_class),
1061 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1063 _gtk_marshal_VOID__VOID,
1068 * @widget: the object which received the signal.
1070 widget_signals[MAP] =
1071 g_signal_new (I_("map"),
1072 G_TYPE_FROM_CLASS (gobject_class),
1074 G_STRUCT_OFFSET (GtkWidgetClass, map),
1076 _gtk_marshal_VOID__VOID,
1081 * @widget: the object which received the signal.
1083 widget_signals[UNMAP] =
1084 g_signal_new (I_("unmap"),
1085 G_TYPE_FROM_CLASS (gobject_class),
1087 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1089 _gtk_marshal_VOID__VOID,
1093 * GtkWidget::realize:
1094 * @widget: the object which received the signal.
1096 widget_signals[REALIZE] =
1097 g_signal_new (I_("realize"),
1098 G_TYPE_FROM_CLASS (gobject_class),
1100 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1102 _gtk_marshal_VOID__VOID,
1106 * GtkWidget::unrealize:
1107 * @widget: the object which received the signal.
1109 widget_signals[UNREALIZE] =
1110 g_signal_new (I_("unrealize"),
1111 G_TYPE_FROM_CLASS (gobject_class),
1113 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1115 _gtk_marshal_VOID__VOID,
1119 * GtkWidget::size-request:
1120 * @widget: the object which received the signal.
1123 widget_signals[SIZE_REQUEST] =
1124 g_signal_new (I_("size-request"),
1125 G_TYPE_FROM_CLASS (gobject_class),
1127 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1129 _gtk_marshal_VOID__BOXED,
1131 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1134 * GtkWidget::size-allocate:
1135 * @widget: the object which received the signal.
1138 widget_signals[SIZE_ALLOCATE] =
1139 g_signal_new (I_("size-allocate"),
1140 G_TYPE_FROM_CLASS (gobject_class),
1142 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1144 _gtk_marshal_VOID__BOXED,
1146 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1149 * GtkWidget::state-changed:
1150 * @widget: the object which received the signal.
1151 * @state: the previous state
1153 * The ::state-changed signal is emitted when the widget state changes.
1154 * See gtk_widget_get_state().
1156 widget_signals[STATE_CHANGED] =
1157 g_signal_new (I_("state-changed"),
1158 G_TYPE_FROM_CLASS (gobject_class),
1160 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1162 _gtk_marshal_VOID__ENUM,
1164 GTK_TYPE_STATE_TYPE);
1167 * GtkWidget::parent-set:
1168 * @widget: the object on which the signal is emitted
1169 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1170 * just got its initial parent.
1172 * The ::parent-set signal is emitted when a new parent
1173 * has been set on a widget.
1175 widget_signals[PARENT_SET] =
1176 g_signal_new (I_("parent-set"),
1177 G_TYPE_FROM_CLASS (gobject_class),
1179 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1181 _gtk_marshal_VOID__OBJECT,
1186 * GtkWidget::hierarchy-changed:
1187 * @widget: the object on which the signal is emitted
1188 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1189 * if the widget was previously unanchored
1191 * The ::hierarchy-changed signal is emitted when the
1192 * anchored state of a widget changes. A widget is
1193 * <firstterm>anchored</firstterm> when its toplevel
1194 * ancestor is a #GtkWindow. This signal is emitted when
1195 * a widget changes from un-anchored to anchored or vice-versa.
1197 widget_signals[HIERARCHY_CHANGED] =
1198 g_signal_new (I_("hierarchy-changed"),
1199 G_TYPE_FROM_CLASS (gobject_class),
1201 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1203 _gtk_marshal_VOID__OBJECT,
1208 * GtkWidget::style-set:
1209 * @widget: the object on which the signal is emitted
1210 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1211 * just got its initial style
1213 * The ::style-set signal is emitted when a new style has been set
1214 * on a widget. Note that style-modifying functions like
1215 * gtk_widget_modify_base() also cause this signal to be emitted.
1217 widget_signals[STYLE_SET] =
1218 g_signal_new (I_("style-set"),
1219 G_TYPE_FROM_CLASS (gobject_class),
1221 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1223 _gtk_marshal_VOID__OBJECT,
1227 * GtkWidget::direction-changed:
1228 * @widget: the object on which the signal is emitted
1229 * @previous_direction: the previous text direction of @widget
1231 * The ::direction-changed signal is emitted when the text direction
1232 * of a widget changes.
1234 widget_signals[DIRECTION_CHANGED] =
1235 g_signal_new (I_("direction-changed"),
1236 G_TYPE_FROM_CLASS (gobject_class),
1238 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1240 _gtk_marshal_VOID__ENUM,
1242 GTK_TYPE_TEXT_DIRECTION);
1245 * GtkWidget::grab-notify:
1246 * @widget: the object which received the signal
1247 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1248 * if it becomes unshadowed
1250 * The ::grab-notify signal is emitted when a widget becomes
1251 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1252 * another widget, or when it becomes unshadowed due to a grab
1255 * A widget is shadowed by a gtk_grab_add() when the topmost
1256 * grab widget in the grab stack of its window group is not
1259 widget_signals[GRAB_NOTIFY] =
1260 g_signal_new (I_("grab-notify"),
1261 G_TYPE_FROM_CLASS (gobject_class),
1263 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1265 _gtk_marshal_VOID__BOOLEAN,
1270 * GtkWidget::child-notify:
1271 * @widget: the object which received the signal
1272 * @pspec: the #GParamSpec of the changed child property
1274 * The ::child-notify signal is emitted for each
1275 * <link linkend="child-properties">child property</link> that has
1276 * changed on an object. The signal's detail holds the property name.
1278 widget_signals[CHILD_NOTIFY] =
1279 g_signal_new (I_("child-notify"),
1280 G_TYPE_FROM_CLASS (gobject_class),
1281 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1282 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1284 g_cclosure_marshal_VOID__PARAM,
1290 * @widget: the object which received the signal
1291 * @cr: the cairo context to draw to
1292 * @width: width of the widget
1293 * @height: height of the widget
1295 * This signal is emitted when a widget is supposed to render itself.
1296 * The @widget's top left corner must be painted at the origin of
1297 * the passed in context and be sized in the given @width and @height.
1299 * Signal handlers connected to this signal can modify the cairo
1300 * context passed as @cr in any way they like and don't need to
1301 * restore it. The signal emission takes care of calling cairo_save()
1302 * before and cairo_restore() after invoking the handler.
1304 widget_signals[DRAW] =
1305 g_signal_new (I_("draw"),
1306 G_TYPE_FROM_CLASS (gobject_class),
1308 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1309 _gtk_boolean_handled_accumulator, NULL,
1310 gtk_widget_draw_marshaller,
1312 CAIRO_GOBJECT_TYPE_CONTEXT);
1315 * GtkWidget::mnemonic-activate:
1316 * @widget: the object which received the signal.
1319 widget_signals[MNEMONIC_ACTIVATE] =
1320 g_signal_new (I_("mnemonic-activate"),
1321 G_TYPE_FROM_CLASS (gobject_class),
1323 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1324 _gtk_boolean_handled_accumulator, NULL,
1325 _gtk_marshal_BOOLEAN__BOOLEAN,
1330 * GtkWidget::grab-focus:
1331 * @widget: the object which received the signal.
1333 widget_signals[GRAB_FOCUS] =
1334 g_signal_new (I_("grab-focus"),
1335 G_TYPE_FROM_CLASS (gobject_class),
1336 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1337 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1339 _gtk_marshal_VOID__VOID,
1344 * @widget: the object which received the signal.
1347 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1349 widget_signals[FOCUS] =
1350 g_signal_new (I_("focus"),
1351 G_TYPE_FROM_CLASS (object_class),
1353 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1354 _gtk_boolean_handled_accumulator, NULL,
1355 _gtk_marshal_BOOLEAN__ENUM,
1357 GTK_TYPE_DIRECTION_TYPE);
1360 * GtkWidget::move-focus:
1361 * @widget: the object which received the signal.
1364 widget_signals[MOVE_FOCUS] =
1365 g_signal_new_class_handler (I_("move-focus"),
1366 G_TYPE_FROM_CLASS (object_class),
1367 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1368 G_CALLBACK (gtk_widget_real_move_focus),
1370 _gtk_marshal_VOID__ENUM,
1373 GTK_TYPE_DIRECTION_TYPE);
1376 * @widget: the object which received the signal.
1377 * @event: the #GdkEvent which triggered this signal
1379 * The GTK+ main loop will emit three signals for each GDK event delivered
1380 * to a widget: one generic ::event signal, another, more specific,
1381 * signal that matches the type of event delivered (e.g.
1382 * #GtkWidget::key-press-event) and finally a generic
1383 * #GtkWidget::event-after signal.
1385 * Returns: %TRUE to stop other handlers from being invoked for the event
1386 * and to cancel the emission of the second specific ::event signal.
1387 * %FALSE to propagate the event further and to allow the emission of
1388 * the second signal. The ::event-after signal is emitted regardless of
1391 widget_signals[EVENT] =
1392 g_signal_new (I_("event"),
1393 G_TYPE_FROM_CLASS (gobject_class),
1395 G_STRUCT_OFFSET (GtkWidgetClass, event),
1396 _gtk_boolean_handled_accumulator, NULL,
1397 _gtk_marshal_BOOLEAN__BOXED,
1399 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1402 * GtkWidget::event-after:
1403 * @widget: the object which received the signal.
1404 * @event: the #GdkEvent which triggered this signal
1406 * After the emission of the #GtkWidget::event signal and (optionally)
1407 * the second more specific signal, ::event-after will be emitted
1408 * regardless of the previous two signals handlers return values.
1411 widget_signals[EVENT_AFTER] =
1412 g_signal_new (I_("event-after"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1417 _gtk_marshal_VOID__BOXED,
1419 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1422 * GtkWidget::button-press-event:
1423 * @widget: the object which received the signal.
1424 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1427 * The ::button-press-event signal will be emitted when a button
1428 * (typically from a mouse) is pressed.
1430 * To receive this signal, the #GdkWindow associated to the
1431 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1433 * This signal will be sent to the grab widget if there is one.
1435 * Returns: %TRUE to stop other handlers from being invoked for the event.
1436 * %FALSE to propagate the event further.
1438 widget_signals[BUTTON_PRESS_EVENT] =
1439 g_signal_new (I_("button-press-event"),
1440 G_TYPE_FROM_CLASS (gobject_class),
1442 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1443 _gtk_boolean_handled_accumulator, NULL,
1444 _gtk_marshal_BOOLEAN__BOXED,
1446 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1449 * GtkWidget::button-release-event:
1450 * @widget: the object which received the signal.
1451 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1454 * The ::button-release-event signal will be emitted when a button
1455 * (typically from a mouse) is released.
1457 * To receive this signal, the #GdkWindow associated to the
1458 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1460 * This signal will be sent to the grab widget if there is one.
1462 * Returns: %TRUE to stop other handlers from being invoked for the event.
1463 * %FALSE to propagate the event further.
1465 widget_signals[BUTTON_RELEASE_EVENT] =
1466 g_signal_new (I_("button-release-event"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1470 _gtk_boolean_handled_accumulator, NULL,
1471 _gtk_marshal_BOOLEAN__BOXED,
1473 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1476 * GtkWidget::scroll-event:
1477 * @widget: the object which received the signal.
1478 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1481 * The ::scroll-event signal is emitted when a button in the 4 to 7
1482 * range is pressed. Wheel mice are usually configured to generate
1483 * button press events for buttons 4 and 5 when the wheel is turned.
1485 * To receive this signal, the #GdkWindow associated to the widget needs
1486 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1488 * This signal will be sent to the grab widget if there is one.
1490 * Returns: %TRUE to stop other handlers from being invoked for the event.
1491 * %FALSE to propagate the event further.
1493 widget_signals[SCROLL_EVENT] =
1494 g_signal_new (I_("scroll-event"),
1495 G_TYPE_FROM_CLASS (gobject_class),
1497 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1498 _gtk_boolean_handled_accumulator, NULL,
1499 _gtk_marshal_BOOLEAN__BOXED,
1501 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1503 * GtkWidget::motion-notify-event:
1504 * @widget: the object which received the signal.
1505 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1508 * The ::motion-notify-event signal is emitted when the pointer moves
1509 * over the widget's #GdkWindow.
1511 * To receive this signal, the #GdkWindow associated to the widget
1512 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1514 * This signal will be sent to the grab widget if there is one.
1516 * Returns: %TRUE to stop other handlers from being invoked for the event.
1517 * %FALSE to propagate the event further.
1519 widget_signals[MOTION_NOTIFY_EVENT] =
1520 g_signal_new (I_("motion-notify-event"),
1521 G_TYPE_FROM_CLASS (gobject_class),
1523 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1524 _gtk_boolean_handled_accumulator, NULL,
1525 _gtk_marshal_BOOLEAN__BOXED,
1527 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1530 * GtkWidget::composited-changed:
1531 * @widget: the object on which the signal is emitted
1533 * The ::composited-changed signal is emitted when the composited
1534 * status of @widget<!-- -->s screen changes.
1535 * See gdk_screen_is_composited().
1537 widget_signals[COMPOSITED_CHANGED] =
1538 g_signal_new (I_("composited-changed"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1540 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1541 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1543 _gtk_marshal_VOID__VOID,
1547 * GtkWidget::keynav-failed:
1548 * @widget: the object which received the signal
1549 * @direction: the direction of movement
1551 * Gets emitted if keyboard navigation fails.
1552 * See gtk_widget_keynav_failed() for details.
1554 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1555 * if the emitting widget should try to handle the keyboard
1556 * navigation attempt in its parent container(s).
1560 widget_signals[KEYNAV_FAILED] =
1561 g_signal_new_class_handler (I_("keynav-failed"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_CALLBACK (gtk_widget_real_keynav_failed),
1565 _gtk_boolean_handled_accumulator, NULL,
1566 _gtk_marshal_BOOLEAN__ENUM,
1568 GTK_TYPE_DIRECTION_TYPE);
1571 * GtkWidget::delete-event:
1572 * @widget: the object which received the signal
1573 * @event: the event which triggered this signal
1575 * The ::delete-event signal is emitted if a user requests that
1576 * a toplevel window is closed. The default handler for this signal
1577 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1578 * this signal will cause the window to be hidden instead, so that
1579 * it can later be shown again without reconstructing it.
1581 * Returns: %TRUE to stop other handlers from being invoked for the event.
1582 * %FALSE to propagate the event further.
1584 widget_signals[DELETE_EVENT] =
1585 g_signal_new (I_("delete-event"),
1586 G_TYPE_FROM_CLASS (gobject_class),
1588 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1589 _gtk_boolean_handled_accumulator, NULL,
1590 _gtk_marshal_BOOLEAN__BOXED,
1592 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1595 * GtkWidget::destroy-event:
1596 * @widget: the object which received the signal.
1597 * @event: the event which triggered this signal
1599 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1600 * You rarely get this signal, because most widgets disconnect themselves
1601 * from their window before they destroy it, so no widget owns the
1602 * window at destroy time.
1604 * To receive this signal, the #GdkWindow associated to the widget needs
1605 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1606 * automatically for all new windows.
1608 * Returns: %TRUE to stop other handlers from being invoked for the event.
1609 * %FALSE to propagate the event further.
1611 widget_signals[DESTROY_EVENT] =
1612 g_signal_new (I_("destroy-event"),
1613 G_TYPE_FROM_CLASS (gobject_class),
1615 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1616 _gtk_boolean_handled_accumulator, NULL,
1617 _gtk_marshal_BOOLEAN__BOXED,
1619 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1622 * GtkWidget::key-press-event:
1623 * @widget: the object which received the signal
1624 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1626 * The ::key-press-event signal is emitted when a key is pressed.
1628 * To receive this signal, the #GdkWindow associated to the widget needs
1629 * to enable the #GDK_KEY_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[KEY_PRESS_EVENT] =
1637 g_signal_new (I_("key-press-event"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1640 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1641 _gtk_boolean_handled_accumulator, NULL,
1642 _gtk_marshal_BOOLEAN__BOXED,
1644 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1647 * GtkWidget::key-release-event:
1648 * @widget: the object which received the signal
1649 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1651 * The ::key-release-event signal is emitted when a key is pressed.
1653 * To receive this signal, the #GdkWindow associated to the widget needs
1654 * to enable the #GDK_KEY_RELEASE_MASK mask.
1656 * This signal will be sent to the grab widget if there is one.
1658 * Returns: %TRUE to stop other handlers from being invoked for the event.
1659 * %FALSE to propagate the event further.
1661 widget_signals[KEY_RELEASE_EVENT] =
1662 g_signal_new (I_("key-release-event"),
1663 G_TYPE_FROM_CLASS (gobject_class),
1665 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1666 _gtk_boolean_handled_accumulator, NULL,
1667 _gtk_marshal_BOOLEAN__BOXED,
1669 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1672 * GtkWidget::enter-notify-event:
1673 * @widget: the object which received the signal
1674 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1677 * The ::enter-notify-event will be emitted when the pointer enters
1678 * the @widget's window.
1680 * To receive this signal, the #GdkWindow associated to the widget needs
1681 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1683 * This signal will be sent to the grab widget if there is one.
1685 * Returns: %TRUE to stop other handlers from being invoked for the event.
1686 * %FALSE to propagate the event further.
1688 widget_signals[ENTER_NOTIFY_EVENT] =
1689 g_signal_new (I_("enter-notify-event"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1692 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1693 _gtk_boolean_handled_accumulator, NULL,
1694 _gtk_marshal_BOOLEAN__BOXED,
1696 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1699 * GtkWidget::leave-notify-event:
1700 * @widget: the object which received the signal
1701 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1704 * The ::leave-notify-event will be emitted when the pointer leaves
1705 * the @widget's window.
1707 * To receive this signal, the #GdkWindow associated to the widget needs
1708 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1710 * This signal will be sent to the grab widget if there is one.
1712 * Returns: %TRUE to stop other handlers from being invoked for the event.
1713 * %FALSE to propagate the event further.
1715 widget_signals[LEAVE_NOTIFY_EVENT] =
1716 g_signal_new (I_("leave-notify-event"),
1717 G_TYPE_FROM_CLASS (gobject_class),
1719 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1720 _gtk_boolean_handled_accumulator, NULL,
1721 _gtk_marshal_BOOLEAN__BOXED,
1723 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1726 * GtkWidget::configure-event
1727 * @widget: the object which received the signal
1728 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1731 * The ::configure-event signal will be emitted when the size, position or
1732 * stacking of the @widget's window has changed.
1734 * To receive this signal, the #GdkWindow associated to the widget needs
1735 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1736 * automatically for all new windows.
1738 * Returns: %TRUE to stop other handlers from being invoked for the event.
1739 * %FALSE to propagate the event further.
1741 widget_signals[CONFIGURE_EVENT] =
1742 g_signal_new (I_("configure-event"),
1743 G_TYPE_FROM_CLASS (gobject_class),
1745 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1746 _gtk_boolean_handled_accumulator, NULL,
1747 _gtk_marshal_BOOLEAN__BOXED,
1749 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1752 * GtkWidget::focus-in-event
1753 * @widget: the object which received the signal
1754 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1757 * The ::focus-in-event signal will be emitted when the keyboard focus
1758 * enters the @widget's window.
1760 * To receive this signal, the #GdkWindow associated to the widget needs
1761 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1763 * Returns: %TRUE to stop other handlers from being invoked for the event.
1764 * %FALSE to propagate the event further.
1766 widget_signals[FOCUS_IN_EVENT] =
1767 g_signal_new (I_("focus-in-event"),
1768 G_TYPE_FROM_CLASS (gobject_class),
1770 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1771 _gtk_boolean_handled_accumulator, NULL,
1772 _gtk_marshal_BOOLEAN__BOXED,
1774 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1777 * GtkWidget::focus-out-event
1778 * @widget: the object which received the signal
1779 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1782 * The ::focus-out-event signal will be emitted when the keyboard focus
1783 * leaves the @widget's window.
1785 * To receive this signal, the #GdkWindow associated to the widget needs
1786 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1788 * Returns: %TRUE to stop other handlers from being invoked for the event.
1789 * %FALSE to propagate the event further.
1791 widget_signals[FOCUS_OUT_EVENT] =
1792 g_signal_new (I_("focus-out-event"),
1793 G_TYPE_FROM_CLASS (gobject_class),
1795 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1796 _gtk_boolean_handled_accumulator, NULL,
1797 _gtk_marshal_BOOLEAN__BOXED,
1799 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1802 * GtkWidget::map-event
1803 * @widget: the object which received the signal
1804 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1806 * The ::map-event signal will be emitted when the @widget's window is
1807 * mapped. A window is mapped when it becomes visible on the screen.
1809 * To receive this signal, the #GdkWindow associated to the widget needs
1810 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1811 * automatically for all new windows.
1813 * Returns: %TRUE to stop other handlers from being invoked for the event.
1814 * %FALSE to propagate the event further.
1816 widget_signals[MAP_EVENT] =
1817 g_signal_new (I_("map-event"),
1818 G_TYPE_FROM_CLASS (gobject_class),
1820 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1821 _gtk_boolean_handled_accumulator, NULL,
1822 _gtk_marshal_BOOLEAN__BOXED,
1824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1827 * GtkWidget::unmap-event
1828 * @widget: the object which received the signal
1829 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1831 * The ::unmap-event signal may be emitted when the @widget's window is
1832 * unmapped. A window is unmapped when it becomes invisible on the screen.
1834 * For performance reasons GTK+ may not emit ::unmap-event, so one
1835 * should always also implement ::unrealize in order to release
1836 * resources and disconnect signal handlers.
1838 * To receive this signal, the #GdkWindow associated to the widget needs
1839 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1840 * automatically for all new windows.
1842 * Returns: %TRUE to stop other handlers from being invoked for the event.
1843 * %FALSE to propagate the event further.
1845 widget_signals[UNMAP_EVENT] =
1846 g_signal_new (I_("unmap-event"),
1847 G_TYPE_FROM_CLASS (gobject_class),
1849 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1850 _gtk_boolean_handled_accumulator, NULL,
1851 _gtk_marshal_BOOLEAN__BOXED,
1853 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1856 * GtkWidget::property-notify-event
1857 * @widget: the object which received the signal
1858 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1861 * The ::property-notify-event signal will be emitted when a property on
1862 * the @widget's window has been changed or deleted.
1864 * To receive this signal, the #GdkWindow associated to the widget needs
1865 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1867 * Returns: %TRUE to stop other handlers from being invoked for the event.
1868 * %FALSE to propagate the event further.
1870 widget_signals[PROPERTY_NOTIFY_EVENT] =
1871 g_signal_new (I_("property-notify-event"),
1872 G_TYPE_FROM_CLASS (gobject_class),
1874 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1875 _gtk_boolean_handled_accumulator, NULL,
1876 _gtk_marshal_BOOLEAN__BOXED,
1878 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1881 * GtkWidget::selection-clear-event
1882 * @widget: the object which received the signal
1883 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1886 * The ::selection-clear-event signal will be emitted when the
1887 * the @widget's window has lost ownership of a selection.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[SELECTION_CLEAR_EVENT] =
1893 g_signal_new (I_("selection-clear-event"),
1894 G_TYPE_FROM_CLASS (gobject_class),
1896 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1903 * GtkWidget::selection-request-event
1904 * @widget: the object which received the signal
1905 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1908 * The ::selection-request-event signal will be emitted when
1909 * another client requests ownership of the selection owned by
1910 * the @widget's window.
1912 * Returns: %TRUE to stop other handlers from being invoked for the event.
1913 * %FALSE to propagate the event further.
1915 widget_signals[SELECTION_REQUEST_EVENT] =
1916 g_signal_new (I_("selection-request-event"),
1917 G_TYPE_FROM_CLASS (gobject_class),
1919 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1920 _gtk_boolean_handled_accumulator, NULL,
1921 _gtk_marshal_BOOLEAN__BOXED,
1923 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1926 * GtkWidget::selection-notify-event:
1927 * @widget: the object which received the signal.
1930 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1932 widget_signals[SELECTION_NOTIFY_EVENT] =
1933 g_signal_new (I_("selection-notify-event"),
1934 G_TYPE_FROM_CLASS (gobject_class),
1936 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 * GtkWidget::selection-received:
1944 * @widget: the object which received the signal.
1948 widget_signals[SELECTION_RECEIVED] =
1949 g_signal_new (I_("selection-received"),
1950 G_TYPE_FROM_CLASS (gobject_class),
1952 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1954 _gtk_marshal_VOID__BOXED_UINT,
1956 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1960 * GtkWidget::selection-get:
1961 * @widget: the object which received the signal.
1966 widget_signals[SELECTION_GET] =
1967 g_signal_new (I_("selection-get"),
1968 G_TYPE_FROM_CLASS (gobject_class),
1970 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1972 _gtk_marshal_VOID__BOXED_UINT_UINT,
1974 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1979 * GtkWidget::proximity-in-event
1980 * @widget: the object which received the signal
1981 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1984 * To receive this signal the #GdkWindow associated to the widget needs
1985 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1987 * This signal will be sent to the grab widget if there is one.
1989 * Returns: %TRUE to stop other handlers from being invoked for the event.
1990 * %FALSE to propagate the event further.
1992 widget_signals[PROXIMITY_IN_EVENT] =
1993 g_signal_new (I_("proximity-in-event"),
1994 G_TYPE_FROM_CLASS (gobject_class),
1996 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1997 _gtk_boolean_handled_accumulator, NULL,
1998 _gtk_marshal_BOOLEAN__BOXED,
2000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2003 * GtkWidget::proximity-out-event
2004 * @widget: the object which received the signal
2005 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2008 * To receive this signal the #GdkWindow associated to the widget needs
2009 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2011 * This signal will be sent to the grab widget if there is one.
2013 * Returns: %TRUE to stop other handlers from being invoked for the event.
2014 * %FALSE to propagate the event further.
2016 widget_signals[PROXIMITY_OUT_EVENT] =
2017 g_signal_new (I_("proximity-out-event"),
2018 G_TYPE_FROM_CLASS (gobject_class),
2020 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2021 _gtk_boolean_handled_accumulator, NULL,
2022 _gtk_marshal_BOOLEAN__BOXED,
2024 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2027 * GtkWidget::drag-leave:
2028 * @widget: the object which received the signal.
2029 * @drag_context: the drag context
2030 * @time: the timestamp of the motion event
2032 * The ::drag-leave signal is emitted on the drop site when the cursor
2033 * leaves the widget. A typical reason to connect to this signal is to
2034 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2035 * with gtk_drag_unhighlight()
2037 widget_signals[DRAG_LEAVE] =
2038 g_signal_new (I_("drag-leave"),
2039 G_TYPE_FROM_CLASS (gobject_class),
2041 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2043 _gtk_marshal_VOID__OBJECT_UINT,
2045 GDK_TYPE_DRAG_CONTEXT,
2049 * GtkWidget::drag-begin:
2050 * @widget: the object which received the signal
2051 * @drag_context: the drag context
2053 * The ::drag-begin signal is emitted on the drag source when a drag is
2054 * started. A typical reason to connect to this signal is to set up a
2055 * custom drag icon with gtk_drag_source_set_icon().
2057 * Note that some widgets set up a drag icon in the default handler of
2058 * this signal, so you may have to use g_signal_connect_after() to
2059 * override what the default handler did.
2061 widget_signals[DRAG_BEGIN] =
2062 g_signal_new (I_("drag-begin"),
2063 G_TYPE_FROM_CLASS (gobject_class),
2065 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2067 _gtk_marshal_VOID__OBJECT,
2069 GDK_TYPE_DRAG_CONTEXT);
2072 * GtkWidget::drag-end:
2073 * @widget: the object which received the signal
2074 * @drag_context: the drag context
2076 * The ::drag-end signal is emitted on the drag source when a drag is
2077 * finished. A typical reason to connect to this signal is to undo
2078 * things done in #GtkWidget::drag-begin.
2080 widget_signals[DRAG_END] =
2081 g_signal_new (I_("drag-end"),
2082 G_TYPE_FROM_CLASS (gobject_class),
2084 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2086 _gtk_marshal_VOID__OBJECT,
2088 GDK_TYPE_DRAG_CONTEXT);
2091 * GtkWidget::drag-data-delete:
2092 * @widget: the object which received the signal
2093 * @drag_context: the drag context
2095 * The ::drag-data-delete signal is emitted on the drag source when a drag
2096 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2097 * handler is responsible for deleting the data that has been dropped. What
2098 * "delete" means depends on the context of the drag operation.
2100 widget_signals[DRAG_DATA_DELETE] =
2101 g_signal_new (I_("drag-data-delete"),
2102 G_TYPE_FROM_CLASS (gobject_class),
2104 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2106 _gtk_marshal_VOID__OBJECT,
2108 GDK_TYPE_DRAG_CONTEXT);
2111 * GtkWidget::drag-failed:
2112 * @widget: the object which received the signal
2113 * @drag_context: the drag context
2114 * @result: the result of the drag operation
2116 * The ::drag-failed signal is emitted on the drag source when a drag has
2117 * failed. The signal handler may hook custom code to handle a failed DND
2118 * operation based on the type of error, it returns %TRUE is the failure has
2119 * been already handled (not showing the default "drag operation failed"
2120 * animation), otherwise it returns %FALSE.
2122 * Return value: %TRUE if the failed drag operation has been already handled.
2126 widget_signals[DRAG_FAILED] =
2127 g_signal_new (I_("drag-failed"),
2128 G_TYPE_FROM_CLASS (gobject_class),
2130 0, _gtk_boolean_handled_accumulator, NULL,
2131 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2133 GDK_TYPE_DRAG_CONTEXT,
2134 GTK_TYPE_DRAG_RESULT);
2137 * GtkWidget::drag-motion:
2138 * @widget: the object which received the signal
2139 * @drag_context: the drag context
2140 * @x: the x coordinate of the current cursor position
2141 * @y: the y coordinate of the current cursor position
2142 * @time: the timestamp of the motion event
2143 * @returns: whether the cursor position is in a drop zone
2145 * The drag-motion signal is emitted on the drop site when the user
2146 * moves the cursor over the widget during a drag. The signal handler
2147 * must determine whether the cursor position is in a drop zone or not.
2148 * If it is not in a drop zone, it returns %FALSE and no further processing
2149 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2150 * handler is responsible for providing the necessary information for
2151 * displaying feedback to the user, by calling gdk_drag_status().
2153 * If the decision whether the drop will be accepted or rejected can't be
2154 * made based solely on the cursor position and the type of the data, the
2155 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2156 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2157 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2158 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2159 * when using the drag-motion signal that way.
2161 * Also note that there is no drag-enter signal. The drag receiver has to
2162 * keep track of whether he has received any drag-motion signals since the
2163 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2164 * an "enter" signal. Upon an "enter", the handler will typically highlight
2165 * the drop site with gtk_drag_highlight().
2168 * drag_motion (GtkWidget *widget,
2169 * GdkDragContext *context,
2176 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2178 * if (!private_data->drag_highlight)
2180 * private_data->drag_highlight = 1;
2181 * gtk_drag_highlight (widget);
2184 * target = gtk_drag_dest_find_target (widget, context, NULL);
2185 * if (target == GDK_NONE)
2186 * gdk_drag_status (context, 0, time);
2189 * private_data->pending_status = context->suggested_action;
2190 * gtk_drag_get_data (widget, context, target, time);
2197 * drag_data_received (GtkWidget *widget,
2198 * GdkDragContext *context,
2201 * GtkSelectionData *selection_data,
2205 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2207 * if (private_data->suggested_action)
2209 * private_data->suggested_action = 0;
2211 * /* We are getting this data due to a request in drag_motion,
2212 * * rather than due to a request in drag_drop, so we are just
2213 * * supposed to call gdk_drag_status (), not actually paste in
2216 * str = gtk_selection_data_get_text (selection_data);
2217 * if (!data_is_acceptable (str))
2218 * gdk_drag_status (context, 0, time);
2220 * gdk_drag_status (context, private_data->suggested_action, time);
2224 * /* accept the drop */
2229 widget_signals[DRAG_MOTION] =
2230 g_signal_new (I_("drag-motion"),
2231 G_TYPE_FROM_CLASS (gobject_class),
2233 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2234 _gtk_boolean_handled_accumulator, NULL,
2235 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2237 GDK_TYPE_DRAG_CONTEXT,
2243 * GtkWidget::drag-drop:
2244 * @widget: the object which received the signal
2245 * @drag_context: the drag context
2246 * @x: the x coordinate of the current cursor position
2247 * @y: the y coordinate of the current cursor position
2248 * @time: the timestamp of the motion event
2249 * @returns: whether the cursor position is in a drop zone
2251 * The ::drag-drop signal is emitted on the drop site when the user drops
2252 * the data onto the widget. The signal handler must determine whether
2253 * the cursor position is in a drop zone or not. If it is not in a drop
2254 * zone, it returns %FALSE and no further processing is necessary.
2255 * Otherwise, the handler returns %TRUE. In this case, the handler must
2256 * ensure that gtk_drag_finish() is called to let the source know that
2257 * the drop is done. The call to gtk_drag_finish() can be done either
2258 * directly or in a #GtkWidget::drag-data-received handler which gets
2259 * triggered by calling gtk_drag_get_data() to receive the data for one
2260 * or more of the supported targets.
2262 widget_signals[DRAG_DROP] =
2263 g_signal_new (I_("drag-drop"),
2264 G_TYPE_FROM_CLASS (gobject_class),
2266 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2267 _gtk_boolean_handled_accumulator, NULL,
2268 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2270 GDK_TYPE_DRAG_CONTEXT,
2276 * GtkWidget::drag-data-get:
2277 * @widget: the object which received the signal
2278 * @drag_context: the drag context
2279 * @data: the #GtkSelectionData to be filled with the dragged data
2280 * @info: the info that has been registered with the target in the
2282 * @time: the timestamp at which the data was requested
2284 * The ::drag-data-get signal is emitted on the drag source when the drop
2285 * site requests the data which is dragged. It is the responsibility of
2286 * the signal handler to fill @data with the data in the format which
2287 * is indicated by @info. See gtk_selection_data_set() and
2288 * gtk_selection_data_set_text().
2290 widget_signals[DRAG_DATA_GET] =
2291 g_signal_new (I_("drag-data-get"),
2292 G_TYPE_FROM_CLASS (gobject_class),
2294 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2296 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2298 GDK_TYPE_DRAG_CONTEXT,
2299 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2304 * GtkWidget::drag-data-received:
2305 * @widget: the object which received the signal
2306 * @drag_context: the drag context
2307 * @x: where the drop happened
2308 * @y: where the drop happened
2309 * @data: the received data
2310 * @info: the info that has been registered with the target in the
2312 * @time: the timestamp at which the data was received
2314 * The ::drag-data-received signal is emitted on the drop site when the
2315 * dragged data has been received. If the data was received in order to
2316 * determine whether the drop will be accepted, the handler is expected
2317 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2318 * If the data was received in response to a #GtkWidget::drag-drop signal
2319 * (and this is the last target to be received), the handler for this
2320 * signal is expected to process the received data and then call
2321 * gtk_drag_finish(), setting the @success parameter depending on whether
2322 * the data was processed successfully.
2324 * The handler may inspect and modify @drag_context->action before calling
2325 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2326 * following example:
2329 * drag_data_received (GtkWidget *widget,
2330 * GdkDragContext *drag_context,
2333 * GtkSelectionData *data,
2337 * if ((data->length >= 0) && (data->format == 8))
2339 * if (drag_context->action == GDK_ACTION_ASK)
2341 * GtkWidget *dialog;
2344 * dialog = gtk_message_dialog_new (NULL,
2345 * GTK_DIALOG_MODAL |
2346 * GTK_DIALOG_DESTROY_WITH_PARENT,
2348 * GTK_BUTTONS_YES_NO,
2349 * "Move the data ?\n");
2350 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2351 * gtk_widget_destroy (dialog);
2353 * if (response == GTK_RESPONSE_YES)
2354 * drag_context->action = GDK_ACTION_MOVE;
2356 * drag_context->action = GDK_ACTION_COPY;
2359 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2363 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2367 widget_signals[DRAG_DATA_RECEIVED] =
2368 g_signal_new (I_("drag-data-received"),
2369 G_TYPE_FROM_CLASS (gobject_class),
2371 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2373 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2375 GDK_TYPE_DRAG_CONTEXT,
2378 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2383 * GtkWidget::visibility-notify-event:
2384 * @widget: the object which received the signal
2385 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2386 * triggered this signal.
2388 * The ::visibility-notify-event will be emitted when the @widget's window
2389 * is obscured or unobscured.
2391 * To receive this signal the #GdkWindow associated to the widget needs
2392 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2394 * Returns: %TRUE to stop other handlers from being invoked for the event.
2395 * %FALSE to propagate the event further.
2397 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2398 g_signal_new (I_("visibility-notify-event"),
2399 G_TYPE_FROM_CLASS (gobject_class),
2401 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2402 _gtk_boolean_handled_accumulator, NULL,
2403 _gtk_marshal_BOOLEAN__BOXED,
2405 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2408 * GtkWidget::client-event:
2409 * @widget: the object which received the signal
2410 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2413 * The ::client-event will be emitted when the @widget's window
2414 * receives a message (via a ClientMessage event) from another
2417 * Returns: %TRUE to stop other handlers from being invoked for
2418 * the event. %FALSE to propagate the event further.
2420 widget_signals[CLIENT_EVENT] =
2421 g_signal_new (I_("client-event"),
2422 G_TYPE_FROM_CLASS (gobject_class),
2424 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2425 _gtk_boolean_handled_accumulator, NULL,
2426 _gtk_marshal_BOOLEAN__BOXED,
2428 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2431 * GtkWidget::no-expose-event:
2432 * @widget: the object which received the signal
2433 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2436 * The ::no-expose-event will be emitted when the @widget's window is
2437 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2438 * If the source window was partially obscured #GdkEventExpose events will
2439 * be generated for those areas.
2441 * Returns: %TRUE to stop other handlers from being invoked for the event.
2442 * %FALSE to propagate the event further.
2444 widget_signals[NO_EXPOSE_EVENT] =
2445 g_signal_new (I_("no-expose-event"),
2446 G_TYPE_FROM_CLASS (gobject_class),
2448 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2449 _gtk_boolean_handled_accumulator, NULL,
2450 _gtk_marshal_BOOLEAN__BOXED,
2452 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2455 * GtkWidget::window-state-event:
2456 * @widget: the object which received the signal
2457 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2458 * triggered this signal.
2460 * The ::window-state-event will be emitted when the state of the
2461 * toplevel window associated to the @widget changes.
2463 * To receive this signal the #GdkWindow associated to the widget
2464 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2465 * this mask automatically for all new windows.
2467 * Returns: %TRUE to stop other handlers from being invoked for the
2468 * event. %FALSE to propagate the event further.
2470 widget_signals[WINDOW_STATE_EVENT] =
2471 g_signal_new (I_("window-state-event"),
2472 G_TYPE_FROM_CLASS (gobject_class),
2474 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2475 _gtk_boolean_handled_accumulator, NULL,
2476 _gtk_marshal_BOOLEAN__BOXED,
2478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2481 * GtkWidget::damage-event:
2482 * @widget: the object which received the signal
2483 * @event: the #GdkEventExpose event
2485 * Emitted when a redirected window belonging to @widget gets drawn into.
2486 * The region/area members of the event shows what area of the redirected
2487 * drawable was drawn into.
2489 * Returns: %TRUE to stop other handlers from being invoked for the event.
2490 * %FALSE to propagate the event further.
2494 widget_signals[DAMAGE_EVENT] =
2495 g_signal_new (I_("damage-event"),
2496 G_TYPE_FROM_CLASS (gobject_class),
2499 _gtk_boolean_handled_accumulator, NULL,
2500 _gtk_marshal_BOOLEAN__BOXED,
2502 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2504 * GtkWidget::grab-broken-event:
2505 * @widget: the object which received the signal
2506 * @event: the #GdkEventGrabBroken event
2508 * Emitted when a pointer or keyboard grab on a window belonging
2509 * to @widget gets broken.
2511 * On X11, this happens when the grab window becomes unviewable
2512 * (i.e. it or one of its ancestors is unmapped), or if the same
2513 * application grabs the pointer or keyboard again.
2515 * Returns: %TRUE to stop other handlers from being invoked for
2516 * the event. %FALSE to propagate the event further.
2520 widget_signals[GRAB_BROKEN] =
2521 g_signal_new (I_("grab-broken-event"),
2522 G_TYPE_FROM_CLASS (gobject_class),
2524 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2525 _gtk_boolean_handled_accumulator, NULL,
2526 _gtk_marshal_BOOLEAN__BOXED,
2528 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2530 * GtkWidget::query-tooltip:
2531 * @widget: the object which received the signal
2532 * @x: the x coordinate of the cursor position where the request has
2533 * been emitted, relative to @widget->window
2534 * @y: the y coordinate of the cursor position where the request has
2535 * been emitted, relative to @widget->window
2536 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2537 * @tooltip: a #GtkTooltip
2539 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2540 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2541 * focus in keyboard mode.
2543 * Using the given coordinates, the signal handler should determine
2544 * whether a tooltip should be shown for @widget. If this is the case
2545 * %TRUE should be returned, %FALSE otherwise. Note that if
2546 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2547 * should not be used.
2549 * The signal handler is free to manipulate @tooltip with the therefore
2550 * destined function calls.
2552 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2556 widget_signals[QUERY_TOOLTIP] =
2557 g_signal_new (I_("query-tooltip"),
2558 G_TYPE_FROM_CLASS (gobject_class),
2560 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2561 _gtk_boolean_handled_accumulator, NULL,
2562 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2570 * GtkWidget::popup-menu
2571 * @widget: the object which received the signal
2573 * This signal gets emitted whenever a widget should pop up a context
2574 * menu. This usually happens through the standard key binding mechanism;
2575 * by pressing a certain key while a widget is focused, the user can cause
2576 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2577 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2578 * for an example of how to use this signal.
2580 * Returns: %TRUE if a menu was activated
2582 widget_signals[POPUP_MENU] =
2583 g_signal_new (I_("popup-menu"),
2584 G_TYPE_FROM_CLASS (gobject_class),
2585 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2586 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2587 _gtk_boolean_handled_accumulator, NULL,
2588 _gtk_marshal_BOOLEAN__VOID,
2592 * GtkWidget::show-help:
2593 * @widget: the object which received the signal.
2596 widget_signals[SHOW_HELP] =
2597 g_signal_new (I_("show-help"),
2598 G_TYPE_FROM_CLASS (gobject_class),
2599 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2600 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2601 _gtk_boolean_handled_accumulator, NULL,
2602 _gtk_marshal_BOOLEAN__ENUM,
2604 GTK_TYPE_WIDGET_HELP_TYPE);
2607 * GtkWidget::accel-closures-changed:
2608 * @widget: the object which received the signal.
2610 widget_signals[ACCEL_CLOSURES_CHANGED] =
2611 g_signal_new (I_("accel-closures-changed"),
2612 G_TYPE_FROM_CLASS (gobject_class),
2616 _gtk_marshal_VOID__VOID,
2620 * GtkWidget::screen-changed:
2621 * @widget: the object on which the signal is emitted
2622 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2623 * widget was not associated with a screen before
2625 * The ::screen-changed signal gets emitted when the
2626 * screen of a widget has changed.
2628 widget_signals[SCREEN_CHANGED] =
2629 g_signal_new (I_("screen-changed"),
2630 G_TYPE_FROM_CLASS (gobject_class),
2632 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2634 _gtk_marshal_VOID__OBJECT,
2639 * GtkWidget::can-activate-accel:
2640 * @widget: the object which received the signal
2641 * @signal_id: the ID of a signal installed on @widget
2643 * Determines whether an accelerator that activates the signal
2644 * identified by @signal_id can currently be activated.
2645 * This signal is present to allow applications and derived
2646 * widgets to override the default #GtkWidget handling
2647 * for determining whether an accelerator can be activated.
2649 * Returns: %TRUE if the signal can be activated.
2651 widget_signals[CAN_ACTIVATE_ACCEL] =
2652 g_signal_new (I_("can-activate-accel"),
2653 G_TYPE_FROM_CLASS (gobject_class),
2655 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2656 _gtk_boolean_handled_accumulator, NULL,
2657 _gtk_marshal_BOOLEAN__UINT,
2658 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2660 binding_set = gtk_binding_set_by_class (klass);
2661 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2666 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2668 GTK_TYPE_WIDGET_HELP_TYPE,
2669 GTK_WIDGET_HELP_TOOLTIP);
2670 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2672 GTK_TYPE_WIDGET_HELP_TYPE,
2673 GTK_WIDGET_HELP_TOOLTIP);
2674 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2676 GTK_TYPE_WIDGET_HELP_TYPE,
2677 GTK_WIDGET_HELP_WHATS_THIS);
2678 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2680 GTK_TYPE_WIDGET_HELP_TYPE,
2681 GTK_WIDGET_HELP_WHATS_THIS);
2683 gtk_widget_class_install_style_property (klass,
2684 g_param_spec_boolean ("interior-focus",
2685 P_("Interior Focus"),
2686 P_("Whether to draw the focus indicator inside widgets"),
2688 GTK_PARAM_READABLE));
2690 gtk_widget_class_install_style_property (klass,
2691 g_param_spec_int ("focus-line-width",
2692 P_("Focus linewidth"),
2693 P_("Width, in pixels, of the focus indicator line"),
2695 GTK_PARAM_READABLE));
2697 gtk_widget_class_install_style_property (klass,
2698 g_param_spec_string ("focus-line-pattern",
2699 P_("Focus line dash pattern"),
2700 P_("Dash pattern used to draw the focus indicator"),
2702 GTK_PARAM_READABLE));
2703 gtk_widget_class_install_style_property (klass,
2704 g_param_spec_int ("focus-padding",
2705 P_("Focus padding"),
2706 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2708 GTK_PARAM_READABLE));
2709 gtk_widget_class_install_style_property (klass,
2710 g_param_spec_boxed ("cursor-color",
2712 P_("Color with which to draw insertion cursor"),
2714 GTK_PARAM_READABLE));
2715 gtk_widget_class_install_style_property (klass,
2716 g_param_spec_boxed ("secondary-cursor-color",
2717 P_("Secondary cursor color"),
2718 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2720 GTK_PARAM_READABLE));
2721 gtk_widget_class_install_style_property (klass,
2722 g_param_spec_float ("cursor-aspect-ratio",
2723 P_("Cursor line aspect ratio"),
2724 P_("Aspect ratio with which to draw insertion cursor"),
2726 GTK_PARAM_READABLE));
2728 gtk_widget_class_install_style_property (klass,
2729 g_param_spec_boolean ("window-dragging",
2730 P_("Window dragging"),
2731 P_("Whether windows can be dragged by clicking on empty areas"),
2733 GTK_PARAM_READABLE));
2736 * GtkWidget:link-color:
2738 * The "link-color" style property defines the color of unvisited links.
2742 gtk_widget_class_install_style_property (klass,
2743 g_param_spec_boxed ("link-color",
2744 P_("Unvisited Link Color"),
2745 P_("Color of unvisited links"),
2747 GTK_PARAM_READABLE));
2750 * GtkWidget:visited-link-color:
2752 * The "visited-link-color" style property defines the color of visited links.
2756 gtk_widget_class_install_style_property (klass,
2757 g_param_spec_boxed ("visited-link-color",
2758 P_("Visited Link Color"),
2759 P_("Color of visited links"),
2761 GTK_PARAM_READABLE));
2764 * GtkWidget:wide-separators:
2766 * The "wide-separators" style property defines whether separators have
2767 * configurable width and should be drawn using a box instead of a line.
2771 gtk_widget_class_install_style_property (klass,
2772 g_param_spec_boolean ("wide-separators",
2773 P_("Wide Separators"),
2774 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2776 GTK_PARAM_READABLE));
2779 * GtkWidget:separator-width:
2781 * The "separator-width" style property defines the width of separators.
2782 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2786 gtk_widget_class_install_style_property (klass,
2787 g_param_spec_int ("separator-width",
2788 P_("Separator Width"),
2789 P_("The width of separators if wide-separators is TRUE"),
2791 GTK_PARAM_READABLE));
2794 * GtkWidget:separator-height:
2796 * The "separator-height" style property defines the height of separators.
2797 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2801 gtk_widget_class_install_style_property (klass,
2802 g_param_spec_int ("separator-height",
2803 P_("Separator Height"),
2804 P_("The height of separators if \"wide-separators\" is TRUE"),
2806 GTK_PARAM_READABLE));
2809 * GtkWidget:scroll-arrow-hlength:
2811 * The "scroll-arrow-hlength" style property defines the length of
2812 * horizontal scroll arrows.
2816 gtk_widget_class_install_style_property (klass,
2817 g_param_spec_int ("scroll-arrow-hlength",
2818 P_("Horizontal Scroll Arrow Length"),
2819 P_("The length of horizontal scroll arrows"),
2821 GTK_PARAM_READABLE));
2824 * GtkWidget:scroll-arrow-vlength:
2826 * The "scroll-arrow-vlength" style property defines the length of
2827 * vertical scroll arrows.
2831 gtk_widget_class_install_style_property (klass,
2832 g_param_spec_int ("scroll-arrow-vlength",
2833 P_("Vertical Scroll Arrow Length"),
2834 P_("The length of vertical scroll arrows"),
2836 GTK_PARAM_READABLE));
2838 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2842 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2846 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2847 for (node = list; node; node = node->next)
2849 GParamSpec *pspec = node->data;
2851 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2852 g_param_spec_unref (pspec);
2858 gtk_widget_set_property (GObject *object,
2860 const GValue *value,
2863 GtkWidget *widget = GTK_WIDGET (object);
2868 gchar *tooltip_markup;
2869 const gchar *tooltip_text;
2870 GtkWindow *tooltip_window;
2873 gtk_widget_set_name (widget, g_value_get_string (value));
2876 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2878 case PROP_WIDTH_REQUEST:
2879 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2881 case PROP_HEIGHT_REQUEST:
2882 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2885 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2887 case PROP_SENSITIVE:
2888 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2890 case PROP_APP_PAINTABLE:
2891 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2893 case PROP_CAN_FOCUS:
2894 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2896 case PROP_HAS_FOCUS:
2897 if (g_value_get_boolean (value))
2898 gtk_widget_grab_focus (widget);
2901 if (g_value_get_boolean (value))
2902 gtk_widget_grab_focus (widget);
2904 case PROP_CAN_DEFAULT:
2905 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2907 case PROP_HAS_DEFAULT:
2908 if (g_value_get_boolean (value))
2909 gtk_widget_grab_default (widget);
2911 case PROP_RECEIVES_DEFAULT:
2912 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2915 gtk_widget_set_style (widget, g_value_get_object (value));
2918 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2919 gtk_widget_set_events (widget, g_value_get_flags (value));
2921 case PROP_EXTENSION_EVENTS:
2922 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2924 case PROP_NO_SHOW_ALL:
2925 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2927 case PROP_HAS_TOOLTIP:
2928 gtk_widget_real_set_has_tooltip (widget,
2929 g_value_get_boolean (value), FALSE);
2931 case PROP_TOOLTIP_MARKUP:
2932 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2933 tooltip_markup = g_value_dup_string (value);
2935 /* Treat an empty string as a NULL string,
2936 * because an empty string would be useless for a tooltip:
2938 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2940 g_free (tooltip_markup);
2941 tooltip_markup = NULL;
2944 g_object_set_qdata_full (object, quark_tooltip_markup,
2945 tooltip_markup, g_free);
2947 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2948 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2949 if (gtk_widget_get_visible (widget))
2950 gtk_widget_queue_tooltip_query (widget);
2952 case PROP_TOOLTIP_TEXT:
2953 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2955 tooltip_text = g_value_get_string (value);
2957 /* Treat an empty string as a NULL string,
2958 * because an empty string would be useless for a tooltip:
2960 if (tooltip_text && (strlen (tooltip_text) == 0))
2961 tooltip_text = NULL;
2963 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2965 g_object_set_qdata_full (object, quark_tooltip_markup,
2966 tooltip_markup, g_free);
2968 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2969 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2970 if (gtk_widget_get_visible (widget))
2971 gtk_widget_queue_tooltip_query (widget);
2973 case PROP_DOUBLE_BUFFERED:
2974 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2977 gtk_widget_set_halign (widget, g_value_get_enum (value));
2980 gtk_widget_set_valign (widget, g_value_get_enum (value));
2982 case PROP_MARGIN_LEFT:
2983 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2985 case PROP_MARGIN_RIGHT:
2986 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2988 case PROP_MARGIN_TOP:
2989 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2991 case PROP_MARGIN_BOTTOM:
2992 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
2995 g_object_freeze_notify (G_OBJECT (widget));
2996 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2997 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2998 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2999 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3000 g_object_thaw_notify (G_OBJECT (widget));
3003 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3009 gtk_widget_get_property (GObject *object,
3014 GtkWidget *widget = GTK_WIDGET (object);
3015 GtkWidgetPrivate *priv = widget->priv;
3024 g_value_set_string (value, priv->name);
3026 g_value_set_static_string (value, "");
3029 g_value_set_object (value, priv->parent);
3031 case PROP_WIDTH_REQUEST:
3034 gtk_widget_get_size_request (widget, &w, NULL);
3035 g_value_set_int (value, w);
3038 case PROP_HEIGHT_REQUEST:
3041 gtk_widget_get_size_request (widget, NULL, &h);
3042 g_value_set_int (value, h);
3046 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3048 case PROP_SENSITIVE:
3049 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3051 case PROP_APP_PAINTABLE:
3052 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3054 case PROP_CAN_FOCUS:
3055 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3057 case PROP_HAS_FOCUS:
3058 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3061 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3063 case PROP_CAN_DEFAULT:
3064 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3066 case PROP_HAS_DEFAULT:
3067 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3069 case PROP_RECEIVES_DEFAULT:
3070 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3072 case PROP_COMPOSITE_CHILD:
3073 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3076 g_value_set_object (value, gtk_widget_get_style (widget));
3079 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3080 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3082 case PROP_EXTENSION_EVENTS:
3083 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3084 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3086 case PROP_NO_SHOW_ALL:
3087 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3089 case PROP_HAS_TOOLTIP:
3090 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3092 case PROP_TOOLTIP_TEXT:
3094 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3097 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3098 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3100 g_value_take_string (value, text);
3103 case PROP_TOOLTIP_MARKUP:
3104 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3107 g_value_set_object (value, gtk_widget_get_window (widget));
3109 case PROP_DOUBLE_BUFFERED:
3110 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3113 g_value_set_enum (value, gtk_widget_get_halign (widget));
3116 g_value_set_enum (value, gtk_widget_get_valign (widget));
3118 case PROP_MARGIN_LEFT:
3119 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3121 case PROP_MARGIN_RIGHT:
3122 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3124 case PROP_MARGIN_TOP:
3125 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3127 case PROP_MARGIN_BOTTOM:
3128 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3132 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3133 if (aux_info == NULL)
3135 g_value_set_int (value, 0);
3139 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3140 aux_info->margin.right),
3141 MAX (aux_info->margin.top,
3142 aux_info->margin.bottom)));
3147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3153 gtk_widget_init (GtkWidget *widget)
3155 GtkWidgetPrivate *priv;
3157 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3160 priv = widget->priv;
3162 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3163 priv->state = GTK_STATE_NORMAL;
3164 priv->saved_state = GTK_STATE_NORMAL;
3166 priv->allocation.x = -1;
3167 priv->allocation.y = -1;
3168 priv->allocation.width = 1;
3169 priv->allocation.height = 1;
3170 priv->window = NULL;
3171 priv->parent = NULL;
3173 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3174 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3175 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3176 gtk_widget_set_double_buffered (widget, TRUE);
3178 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3179 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3180 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3181 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3183 priv->style = gtk_widget_get_default_style ();
3184 g_object_ref (priv->style);
3189 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3191 GParamSpec **pspecs)
3193 GtkWidgetPrivate *priv = widget->priv;
3194 GtkWidget *container = priv->parent;
3197 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3198 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3202 * gtk_widget_freeze_child_notify:
3203 * @widget: a #GtkWidget
3205 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3206 * signals are queued until gtk_widget_thaw_child_notify() is called
3209 * This is the analogue of g_object_freeze_notify() for child properties.
3212 gtk_widget_freeze_child_notify (GtkWidget *widget)
3214 g_return_if_fail (GTK_IS_WIDGET (widget));
3216 if (!G_OBJECT (widget)->ref_count)
3219 g_object_ref (widget);
3220 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3221 g_object_unref (widget);
3225 * gtk_widget_child_notify:
3226 * @widget: a #GtkWidget
3227 * @child_property: the name of a child property installed on the
3228 * class of @widget<!-- -->'s parent
3230 * Emits a #GtkWidget::child-notify signal for the
3231 * <link linkend="child-properties">child property</link> @child_property
3234 * This is the analogue of g_object_notify() for child properties.
3237 gtk_widget_child_notify (GtkWidget *widget,
3238 const gchar *child_property)
3240 GtkWidgetPrivate *priv = widget->priv;
3243 g_return_if_fail (GTK_IS_WIDGET (widget));
3244 g_return_if_fail (child_property != NULL);
3245 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3248 g_object_ref (widget);
3249 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3251 G_OBJECT_TYPE (priv->parent),
3254 g_warning ("%s: container class `%s' has no child property named `%s'",
3256 G_OBJECT_TYPE_NAME (priv->parent),
3260 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3262 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3263 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3265 g_object_unref (widget);
3269 * gtk_widget_thaw_child_notify:
3270 * @widget: a #GtkWidget
3272 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3273 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3277 gtk_widget_thaw_child_notify (GtkWidget *widget)
3279 GObjectNotifyQueue *nqueue;
3281 g_return_if_fail (GTK_IS_WIDGET (widget));
3283 if (!G_OBJECT (widget)->ref_count)
3286 g_object_ref (widget);
3287 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3288 if (!nqueue || !nqueue->freeze_count)
3289 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3290 G_OBJECT_TYPE_NAME (widget), widget);
3292 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3293 g_object_unref (widget);
3299 * @type: type ID of the widget to create
3300 * @first_property_name: name of first property to set
3301 * @Varargs: value of first property, followed by more properties,
3304 * This is a convenience function for creating a widget and setting
3305 * its properties in one go. For example you might write:
3306 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3307 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3308 * g_object_new(), but returns a widget so you don't have to
3309 * cast the object yourself.
3311 * Return value: a new #GtkWidget of type @widget_type
3314 gtk_widget_new (GType type,
3315 const gchar *first_property_name,
3321 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3323 va_start (var_args, first_property_name);
3324 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3331 gtk_widget_queue_draw_child (GtkWidget *widget)
3333 GtkWidgetPrivate *priv = widget->priv;
3336 parent = priv->parent;
3337 if (parent && gtk_widget_is_drawable (parent))
3338 gtk_widget_queue_draw_area (parent,
3341 priv->allocation.width,
3342 priv->allocation.height);
3346 * gtk_widget_unparent:
3347 * @widget: a #GtkWidget
3349 * This function is only for use in widget implementations.
3350 * Should be called by implementations of the remove method
3351 * on #GtkContainer, to dissociate a child from the container.
3354 gtk_widget_unparent (GtkWidget *widget)
3356 GtkWidgetPrivate *priv;
3357 GObjectNotifyQueue *nqueue;
3358 GtkWidget *toplevel;
3359 GtkWidget *old_parent;
3361 g_return_if_fail (GTK_IS_WIDGET (widget));
3363 priv = widget->priv;
3365 if (priv->parent == NULL)
3368 /* keep this function in sync with gtk_menu_detach()
3371 g_object_freeze_notify (G_OBJECT (widget));
3372 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3374 toplevel = gtk_widget_get_toplevel (widget);
3375 if (gtk_widget_is_toplevel (toplevel))
3376 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3378 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3379 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3381 /* If we are unanchoring the child, we save around the toplevel
3382 * to emit hierarchy changed
3384 if (GTK_WIDGET_ANCHORED (priv->parent))
3385 g_object_ref (toplevel);
3389 gtk_widget_queue_draw_child (widget);
3391 /* Reset the width and height here, to force reallocation if we
3392 * get added back to a new parent. This won't work if our new
3393 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3394 * (would 0x0 be OK here?)
3396 priv->allocation.width = 1;
3397 priv->allocation.height = 1;
3399 if (gtk_widget_get_realized (widget))
3401 if (GTK_WIDGET_IN_REPARENT (widget))
3402 gtk_widget_unmap (widget);
3404 gtk_widget_unrealize (widget);
3407 /* Removing a widget from a container restores the child visible
3408 * flag to the default state, so it doesn't affect the child
3409 * in the next parent.
3411 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3413 old_parent = priv->parent;
3414 priv->parent = NULL;
3415 gtk_widget_set_parent_window (widget, NULL);
3416 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3419 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3420 g_object_unref (toplevel);
3423 g_object_notify (G_OBJECT (widget), "parent");
3424 g_object_thaw_notify (G_OBJECT (widget));
3426 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3427 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3428 g_object_unref (widget);
3432 * gtk_widget_destroy:
3433 * @widget: a #GtkWidget
3435 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3436 * you don't have to cast the widget to #GtkObject. When a widget is
3437 * destroyed, it will break any references it holds to other objects.
3438 * If the widget is inside a container, the widget will be removed
3439 * from the container. If the widget is a toplevel (derived from
3440 * #GtkWindow), it will be removed from the list of toplevels, and the
3441 * reference GTK+ holds to it will be removed. Removing a
3442 * widget from its container or the list of toplevels results in the
3443 * widget being finalized, unless you've added additional references
3444 * to the widget with g_object_ref().
3446 * In most cases, only toplevel widgets (windows) require explicit
3447 * destruction, because when you destroy a toplevel its children will
3448 * be destroyed as well.
3451 gtk_widget_destroy (GtkWidget *widget)
3453 g_return_if_fail (GTK_IS_WIDGET (widget));
3455 gtk_object_destroy ((GtkObject*) widget);
3459 * gtk_widget_destroyed:
3460 * @widget: a #GtkWidget
3461 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3463 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3464 * %NULL. It's intended to be used as a callback connected to the
3465 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3466 * as a signal handler, and pass the address of your widget variable
3467 * as user data. Then when the widget is destroyed, the variable will
3468 * be set to %NULL. Useful for example to avoid multiple copies
3469 * of the same dialog.
3472 gtk_widget_destroyed (GtkWidget *widget,
3473 GtkWidget **widget_pointer)
3475 /* Don't make any assumptions about the
3477 * Even check widget_pointer.
3480 *widget_pointer = NULL;
3485 * @widget: a #GtkWidget
3487 * Flags a widget to be displayed. Any widget that isn't shown will
3488 * not appear on the screen. If you want to show all the widgets in a
3489 * container, it's easier to call gtk_widget_show_all() on the
3490 * container, instead of individually showing the widgets.
3492 * Remember that you have to show the containers containing a widget,
3493 * in addition to the widget itself, before it will appear onscreen.
3495 * When a toplevel container is shown, it is immediately realized and
3496 * mapped; other shown widgets are realized and mapped when their
3497 * toplevel container is realized and mapped.
3500 gtk_widget_show (GtkWidget *widget)
3502 g_return_if_fail (GTK_IS_WIDGET (widget));
3504 if (!gtk_widget_get_visible (widget))
3506 g_object_ref (widget);
3507 if (!gtk_widget_is_toplevel (widget))
3508 gtk_widget_queue_resize (widget);
3509 g_signal_emit (widget, widget_signals[SHOW], 0);
3510 g_object_notify (G_OBJECT (widget), "visible");
3511 g_object_unref (widget);
3516 gtk_widget_real_show (GtkWidget *widget)
3518 GtkWidgetPrivate *priv = widget->priv;
3520 if (!gtk_widget_get_visible (widget))
3522 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3525 gtk_widget_get_mapped (priv->parent) &&
3526 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3527 !gtk_widget_get_mapped (widget))
3528 gtk_widget_map (widget);
3533 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3536 g_signal_handlers_disconnect_by_func (widget,
3537 gtk_widget_show_map_callback,
3542 * gtk_widget_show_now:
3543 * @widget: a #GtkWidget
3545 * Shows a widget. If the widget is an unmapped toplevel widget
3546 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3547 * loop and wait for the window to actually be mapped. Be careful;
3548 * because the main loop is running, anything can happen during
3552 gtk_widget_show_now (GtkWidget *widget)
3556 g_return_if_fail (GTK_IS_WIDGET (widget));
3558 /* make sure we will get event */
3559 if (!gtk_widget_get_mapped (widget) &&
3560 gtk_widget_is_toplevel (widget))
3562 gtk_widget_show (widget);
3564 g_signal_connect (widget, "map-event",
3565 G_CALLBACK (gtk_widget_show_map_callback),
3569 gtk_main_iteration ();
3572 gtk_widget_show (widget);
3577 * @widget: a #GtkWidget
3579 * Reverses the effects of gtk_widget_show(), causing the widget to be
3580 * hidden (invisible to the user).
3583 gtk_widget_hide (GtkWidget *widget)
3585 g_return_if_fail (GTK_IS_WIDGET (widget));
3587 if (gtk_widget_get_visible (widget))
3589 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3591 g_object_ref (widget);
3592 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3593 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3595 g_signal_emit (widget, widget_signals[HIDE], 0);
3596 if (!gtk_widget_is_toplevel (widget))
3597 gtk_widget_queue_resize (widget);
3598 g_object_notify (G_OBJECT (widget), "visible");
3599 g_object_unref (widget);
3604 gtk_widget_real_hide (GtkWidget *widget)
3606 if (gtk_widget_get_visible (widget))
3608 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3610 if (gtk_widget_get_mapped (widget))
3611 gtk_widget_unmap (widget);
3616 * gtk_widget_hide_on_delete:
3617 * @widget: a #GtkWidget
3619 * Utility function; intended to be connected to the #GtkWidget::delete-event
3620 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3621 * argument, then returns %TRUE. If connected to ::delete-event, the
3622 * result is that clicking the close button for a window (on the
3623 * window frame, top right corner usually) will hide but not destroy
3624 * the window. By default, GTK+ destroys windows when ::delete-event
3627 * Return value: %TRUE
3630 gtk_widget_hide_on_delete (GtkWidget *widget)
3632 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3634 gtk_widget_hide (widget);
3640 * gtk_widget_show_all:
3641 * @widget: a #GtkWidget
3643 * Recursively shows a widget, and any child widgets (if the widget is
3647 gtk_widget_show_all (GtkWidget *widget)
3649 GtkWidgetClass *class;
3651 g_return_if_fail (GTK_IS_WIDGET (widget));
3653 if (gtk_widget_get_no_show_all (widget))
3656 class = GTK_WIDGET_GET_CLASS (widget);
3658 if (class->show_all)
3659 class->show_all (widget);
3663 * gtk_widget_hide_all:
3664 * @widget: a #GtkWidget
3666 * Recursively hides a widget and any child widgets.
3669 gtk_widget_hide_all (GtkWidget *widget)
3671 GtkWidgetClass *class;
3673 g_return_if_fail (GTK_IS_WIDGET (widget));
3675 if (gtk_widget_get_no_show_all (widget))
3678 class = GTK_WIDGET_GET_CLASS (widget);
3680 if (class->hide_all)
3681 class->hide_all (widget);
3686 * @widget: a #GtkWidget
3688 * This function is only for use in widget implementations. Causes
3689 * a widget to be mapped if it isn't already.
3692 gtk_widget_map (GtkWidget *widget)
3694 GtkWidgetPrivate *priv;
3696 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 g_return_if_fail (gtk_widget_get_visible (widget));
3698 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3700 priv = widget->priv;
3702 if (!gtk_widget_get_mapped (widget))
3704 if (!gtk_widget_get_realized (widget))
3705 gtk_widget_realize (widget);
3707 g_signal_emit (widget, widget_signals[MAP], 0);
3709 if (!gtk_widget_get_has_window (widget))
3710 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3716 * @widget: a #GtkWidget
3718 * This function is only for use in widget implementations. Causes
3719 * a widget to be unmapped if it's currently mapped.
3722 gtk_widget_unmap (GtkWidget *widget)
3724 GtkWidgetPrivate *priv;
3726 g_return_if_fail (GTK_IS_WIDGET (widget));
3728 priv = widget->priv;
3730 if (gtk_widget_get_mapped (widget))
3732 if (!gtk_widget_get_has_window (widget))
3733 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3734 _gtk_tooltip_hide (widget);
3735 g_signal_emit (widget, widget_signals[UNMAP], 0);
3740 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3741 GdkExtensionMode mode,
3744 GtkWidgetPrivate *priv = widget->priv;
3745 GList *free_list = NULL;
3748 if (window_list == NULL)
3750 if (gtk_widget_get_has_window (widget))
3751 window_list = g_list_prepend (NULL, priv->window);
3753 window_list = gdk_window_get_children (priv->window);
3755 free_list = window_list;
3758 for (l = window_list; l != NULL; l = l->next)
3760 GdkWindow *window = l->data;
3763 gdk_window_get_user_data (window, &user_data);
3764 if (user_data == widget)
3768 gdk_input_set_extension_events (window,
3769 gdk_window_get_events (window),
3772 children = gdk_window_get_children (window);
3775 gtk_widget_set_extension_events_internal (widget, mode, children);
3776 g_list_free (children);
3782 g_list_free (free_list);
3786 _gtk_widget_enable_device_events (GtkWidget *widget)
3788 GHashTable *device_events;
3789 GHashTableIter iter;
3790 gpointer key, value;
3792 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3797 g_hash_table_iter_init (&iter, device_events);
3799 while (g_hash_table_iter_next (&iter, &key, &value))
3802 GdkEventMask event_mask;
3805 event_mask = GPOINTER_TO_UINT (value);
3806 gtk_widget_add_events_internal (widget, device, event_mask);
3811 * gtk_widget_realize:
3812 * @widget: a #GtkWidget
3814 * Creates the GDK (windowing system) resources associated with a
3815 * widget. For example, @widget->window will be created when a widget
3816 * is realized. Normally realization happens implicitly; if you show
3817 * a widget and all its parent containers, then the widget will be
3818 * realized and mapped automatically.
3820 * Realizing a widget requires all
3821 * the widget's parent widgets to be realized; calling
3822 * gtk_widget_realize() realizes the widget's parents in addition to
3823 * @widget itself. If a widget is not yet inside a toplevel window
3824 * when you realize it, bad things will happen.
3826 * This function is primarily used in widget implementations, and
3827 * isn't very useful otherwise. Many times when you think you might
3828 * need it, a better approach is to connect to a signal that will be
3829 * called after the widget is realized automatically, such as
3830 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3831 * GtkWidget::realize signal.
3834 gtk_widget_realize (GtkWidget *widget)
3836 GtkWidgetPrivate *priv;
3837 GdkExtensionMode mode;
3838 cairo_region_t *region;
3840 g_return_if_fail (GTK_IS_WIDGET (widget));
3841 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3842 GTK_IS_INVISIBLE (widget));
3844 priv = widget->priv;
3846 if (!gtk_widget_get_realized (widget))
3849 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3850 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3853 if (priv->parent == NULL &&
3854 !gtk_widget_is_toplevel (widget))
3855 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3856 "inside a toplevel window is not going to work very well. "
3857 "Widgets must be inside a toplevel container before realizing them.");
3859 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3860 gtk_widget_realize (priv->parent);
3862 gtk_widget_ensure_style (widget);
3864 g_signal_emit (widget, widget_signals[REALIZE], 0);
3866 gtk_widget_real_set_has_tooltip (widget,
3867 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3870 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3872 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3873 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3876 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3878 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3880 mode = gtk_widget_get_extension_events (widget);
3881 if (mode != GDK_EXTENSION_EVENTS_NONE)
3882 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3884 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3885 gdk_window_set_support_multidevice (priv->window, TRUE);
3887 _gtk_widget_enable_device_events (widget);
3892 * gtk_widget_unrealize:
3893 * @widget: a #GtkWidget
3895 * This function is only useful in widget implementations.
3896 * Causes a widget to be unrealized (frees all GDK resources
3897 * associated with the widget, such as @widget->window).
3900 gtk_widget_unrealize (GtkWidget *widget)
3902 g_return_if_fail (GTK_IS_WIDGET (widget));
3904 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3905 gtk_widget_shape_combine_region (widget, NULL);
3907 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3908 gtk_widget_input_shape_combine_region (widget, NULL);
3910 if (gtk_widget_get_realized (widget))
3912 g_object_ref (widget);
3913 _gtk_tooltip_hide (widget);
3914 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3915 gtk_widget_set_realized (widget, FALSE);
3916 gtk_widget_set_mapped (widget, FALSE);
3917 g_object_unref (widget);
3921 /*****************************************
3923 *****************************************/
3926 * gtk_widget_queue_draw_area:
3927 * @widget: a #GtkWidget
3928 * @x: x coordinate of upper-left corner of rectangle to redraw
3929 * @y: y coordinate of upper-left corner of rectangle to redraw
3930 * @width: width of region to draw
3931 * @height: height of region to draw
3933 * Invalidates the rectangular area of @widget defined by @x, @y,
3934 * @width and @height by calling gdk_window_invalidate_rect() on the
3935 * widget's window and all its child windows. Once the main loop
3936 * becomes idle (after the current batch of events has been processed,
3937 * roughly), the window will receive expose events for the union of
3938 * all regions that have been invalidated.
3940 * Normally you would only use this function in widget
3941 * implementations. You might also use it, or
3942 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3943 * #GtkDrawingArea or some portion thereof.
3945 * Frequently you can just call gdk_window_invalidate_rect() or
3946 * gdk_window_invalidate_region() instead of this function. Those
3947 * functions will invalidate only a single window, instead of the
3948 * widget and all its children.
3950 * The advantage of adding to the invalidated region compared to
3951 * simply drawing immediately is efficiency; using an invalid region
3952 * ensures that you only have to redraw one time.
3955 gtk_widget_queue_draw_area (GtkWidget *widget,
3961 GtkWidgetPrivate *priv;
3962 GdkRectangle invalid_rect;
3965 g_return_if_fail (GTK_IS_WIDGET (widget));
3967 priv = widget->priv;
3969 if (!gtk_widget_get_realized (widget))
3972 /* Just return if the widget or one of its ancestors isn't mapped */
3973 for (w = widget; w != NULL; w = w->priv->parent)
3974 if (!gtk_widget_get_mapped (w))
3977 /* Find the correct widget */
3979 if (gtk_widget_get_has_window (widget))
3983 /* Translate widget relative to window-relative */
3985 gint wx, wy, wwidth, wheight;
3987 gdk_window_get_position (priv->window, &wx, &wy);
3988 x -= wx - priv->allocation.x;
3989 y -= wy - priv->allocation.y;
3991 wwidth = gdk_window_get_width (priv->window);
3992 wheight = gdk_window_get_height (priv->window);
3994 if (x + width <= 0 || y + height <= 0 ||
3995 x >= wwidth || y >= wheight)
4006 if (x + width > wwidth)
4008 if (y + height > wheight)
4009 height = wheight - y;
4015 invalid_rect.width = width;
4016 invalid_rect.height = height;
4018 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4022 * gtk_widget_queue_draw:
4023 * @widget: a #GtkWidget
4025 * Equivalent to calling gtk_widget_queue_draw_area() for the
4026 * entire area of a widget.
4029 gtk_widget_queue_draw (GtkWidget *widget)
4033 g_return_if_fail (GTK_IS_WIDGET (widget));
4035 gtk_widget_get_allocation (widget, &rect);
4037 if (!gtk_widget_get_has_window (widget))
4038 gtk_widget_queue_draw_area (widget,
4039 rect.x, rect.y, rect.width, rect.height);
4041 gtk_widget_queue_draw_area (widget,
4042 0, 0, rect.width, rect.height);
4046 * gtk_widget_queue_resize:
4047 * @widget: a #GtkWidget
4049 * This function is only for use in widget implementations.
4050 * Flags a widget to have its size renegotiated; should
4051 * be called when a widget for some reason has a new size request.
4052 * For example, when you change the text in a #GtkLabel, #GtkLabel
4053 * queues a resize to ensure there's enough space for the new text.
4056 gtk_widget_queue_resize (GtkWidget *widget)
4058 g_return_if_fail (GTK_IS_WIDGET (widget));
4060 if (gtk_widget_get_realized (widget))
4061 gtk_widget_queue_shallow_draw (widget);
4063 _gtk_size_group_queue_resize (widget);
4067 * gtk_widget_queue_resize_no_redraw:
4068 * @widget: a #GtkWidget
4070 * This function works like gtk_widget_queue_resize(),
4071 * except that the widget is not invalidated.
4076 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4078 g_return_if_fail (GTK_IS_WIDGET (widget));
4080 _gtk_size_group_queue_resize (widget);
4084 * gtk_widget_size_request:
4085 * @widget: a #GtkWidget
4086 * @requisition: (out): a #GtkRequisition to be filled in
4088 * This function is typically used when implementing a #GtkContainer
4089 * subclass. Obtains the preferred size of a widget. The container
4090 * uses this information to arrange its child widgets and decide what
4091 * size allocations to give them with gtk_widget_size_allocate().
4093 * You can also call this function from an application, with some
4094 * caveats. Most notably, getting a size request requires the widget
4095 * to be associated with a screen, because font information may be
4096 * needed. Multihead-aware applications should keep this in mind.
4098 * Also remember that the size request is not necessarily the size
4099 * a widget will actually be allocated.
4101 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4104 gtk_widget_size_request (GtkWidget *widget,
4105 GtkRequisition *requisition)
4107 g_return_if_fail (GTK_IS_WIDGET (widget));
4109 gtk_widget_get_preferred_size (widget, requisition, NULL);
4113 * gtk_widget_get_child_requisition:
4114 * @widget: a #GtkWidget
4115 * @requisition: (out): a #GtkRequisition to be filled in
4117 * This function is only for use in widget implementations. Obtains
4118 * @widget->requisition, unless someone has forced a particular
4119 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4120 * in which case it returns that geometry instead of the widget's
4123 * This function differs from gtk_widget_size_request() in that
4124 * it retrieves the last size request value from @widget->requisition,
4125 * while gtk_widget_size_request() actually calls the "size_request" method
4126 * on @widget to compute the size request and fill in @widget->requisition,
4127 * and only then returns @widget->requisition.
4129 * Because this function does not call the "size_request" method, it
4130 * can only be used when you know that @widget->requisition is
4131 * up-to-date, that is, gtk_widget_size_request() has been called
4132 * since the last time a resize was queued. In general, only container
4133 * implementations have this information; applications should use
4134 * gtk_widget_size_request().
4137 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4140 gtk_widget_get_child_requisition (GtkWidget *widget,
4141 GtkRequisition *requisition)
4143 gtk_widget_get_preferred_size (widget, requisition, NULL);
4147 invalidate_predicate (GdkWindow *window,
4152 gdk_window_get_user_data (window, &user_data);
4154 return (user_data == data);
4157 /* Invalidate @region in widget->window and all children
4158 * of widget->window owned by widget. @region is in the
4159 * same coordinates as widget->allocation and will be
4160 * modified by this call.
4163 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4164 cairo_region_t *region)
4166 GtkWidgetPrivate *priv = widget->priv;
4168 if (!gtk_widget_get_realized (widget))
4171 if (gtk_widget_get_has_window (widget) && priv->parent)
4175 gdk_window_get_position (priv->window, &x, &y);
4176 cairo_region_translate (region, -x, -y);
4179 gdk_window_invalidate_maybe_recurse (priv->window, region,
4180 invalidate_predicate, widget);
4184 * gtk_widget_queue_shallow_draw:
4185 * @widget: a #GtkWidget
4187 * Like gtk_widget_queue_draw(), but only windows owned
4188 * by @widget are invalidated.
4191 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4194 cairo_region_t *region;
4196 if (!gtk_widget_get_realized (widget))
4199 gtk_widget_get_allocation (widget, &rect);
4201 region = cairo_region_create_rectangle (&rect);
4202 gtk_widget_invalidate_widget_windows (widget, region);
4203 cairo_region_destroy (region);
4207 * gtk_widget_size_allocate:
4208 * @widget: a #GtkWidget
4209 * @allocation: (inout): position and size to be allocated to @widget
4211 * This function is only used by #GtkContainer subclasses, to assign a size
4212 * and position to their child widgets.
4214 * In this function, the allocation may be adjusted. It will be forced
4215 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4216 * method on the child will be used to adjust the allocation. Standard
4217 * adjustments include removing the widget's margins, and applying the
4218 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4221 gtk_widget_size_allocate (GtkWidget *widget,
4222 GtkAllocation *allocation)
4224 GtkWidgetPrivate *priv;
4225 GdkRectangle real_allocation;
4226 GdkRectangle old_allocation;
4227 GdkRectangle adjusted_allocation;
4228 gboolean alloc_needed;
4229 gboolean size_changed;
4230 gboolean position_changed;
4232 priv = widget->priv;
4234 g_return_if_fail (GTK_IS_WIDGET (widget));
4236 #ifdef G_ENABLE_DEBUG
4237 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4248 parent = gtk_widget_get_parent (parent);
4251 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4252 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4253 2 * depth, " ", name,
4254 allocation->width, allocation->height);
4256 #endif /* G_ENABLE_DEBUG */
4258 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4259 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4260 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4261 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4263 old_allocation = priv->allocation;
4264 real_allocation = *allocation;
4266 adjusted_allocation = real_allocation;
4267 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4269 if (adjusted_allocation.x < real_allocation.x ||
4270 adjusted_allocation.y < real_allocation.y ||
4271 (adjusted_allocation.x + adjusted_allocation.width) >
4272 (real_allocation.x + real_allocation.width) ||
4273 (adjusted_allocation.y + adjusted_allocation.height >
4274 real_allocation.y + real_allocation.height))
4276 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",
4277 G_OBJECT_TYPE_NAME (widget), widget,
4278 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4279 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4280 adjusted_allocation = real_allocation; /* veto it */
4284 real_allocation = adjusted_allocation;
4287 if (real_allocation.width < 0 || real_allocation.height < 0)
4289 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4290 real_allocation.width,
4291 real_allocation.height);
4294 real_allocation.width = MAX (real_allocation.width, 1);
4295 real_allocation.height = MAX (real_allocation.height, 1);
4297 size_changed = (old_allocation.width != real_allocation.width ||
4298 old_allocation.height != real_allocation.height);
4299 position_changed = (old_allocation.x != real_allocation.x ||
4300 old_allocation.y != real_allocation.y);
4302 if (!alloc_needed && !size_changed && !position_changed)
4305 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4307 if (gtk_widget_get_mapped (widget))
4309 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4311 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4313 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4314 cairo_region_union_rectangle (invalidate, &old_allocation);
4316 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4317 cairo_region_destroy (invalidate);
4322 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4324 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4326 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4327 cairo_region_union_rectangle (invalidate, &old_allocation);
4329 gtk_widget_invalidate_widget_windows (widget, invalidate);
4330 cairo_region_destroy (invalidate);
4335 if ((size_changed || position_changed) && priv->parent &&
4336 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4338 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4339 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4340 cairo_region_destroy (invalidate);
4345 * gtk_widget_common_ancestor:
4346 * @widget_a: a #GtkWidget
4347 * @widget_b: a #GtkWidget
4349 * Find the common ancestor of @widget_a and @widget_b that
4350 * is closest to the two widgets.
4352 * Return value: the closest common ancestor of @widget_a and
4353 * @widget_b or %NULL if @widget_a and @widget_b do not
4354 * share a common ancestor.
4357 gtk_widget_common_ancestor (GtkWidget *widget_a,
4358 GtkWidget *widget_b)
4360 GtkWidget *parent_a;
4361 GtkWidget *parent_b;
4365 parent_a = widget_a;
4366 while (parent_a->priv->parent)
4368 parent_a = parent_a->priv->parent;
4372 parent_b = widget_b;
4373 while (parent_b->priv->parent)
4375 parent_b = parent_b->priv->parent;
4379 if (parent_a != parent_b)
4382 while (depth_a > depth_b)
4384 widget_a = widget_a->priv->parent;
4388 while (depth_b > depth_a)
4390 widget_b = widget_b->priv->parent;
4394 while (widget_a != widget_b)
4396 widget_a = widget_a->priv->parent;
4397 widget_b = widget_b->priv->parent;
4404 * gtk_widget_translate_coordinates:
4405 * @src_widget: a #GtkWidget
4406 * @dest_widget: a #GtkWidget
4407 * @src_x: X position relative to @src_widget
4408 * @src_y: Y position relative to @src_widget
4409 * @dest_x: (out): location to store X position relative to @dest_widget
4410 * @dest_y: (out): location to store Y position relative to @dest_widget
4412 * Translate coordinates relative to @src_widget's allocation to coordinates
4413 * relative to @dest_widget's allocations. In order to perform this
4414 * operation, both widgets must be realized, and must share a common
4417 * Return value: %FALSE if either widget was not realized, or there
4418 * was no common ancestor. In this case, nothing is stored in
4419 * *@dest_x and *@dest_y. Otherwise %TRUE.
4422 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4423 GtkWidget *dest_widget,
4429 GtkWidgetPrivate *src_priv = src_widget->priv;
4430 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4431 GtkWidget *ancestor;
4433 GList *dest_list = NULL;
4435 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4436 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4438 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4439 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4442 /* Translate from allocation relative to window relative */
4443 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4446 gdk_window_get_position (src_priv->window, &wx, &wy);
4448 src_x -= wx - src_priv->allocation.x;
4449 src_y -= wy - src_priv->allocation.y;
4453 src_x += src_priv->allocation.x;
4454 src_y += src_priv->allocation.y;
4457 /* Translate to the common ancestor */
4458 window = src_priv->window;
4459 while (window != ancestor->priv->window)
4463 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4468 window = gdk_window_get_effective_parent (window);
4470 if (!window) /* Handle GtkHandleBox */
4475 window = dest_priv->window;
4476 while (window != ancestor->priv->window)
4478 dest_list = g_list_prepend (dest_list, window);
4480 window = gdk_window_get_effective_parent (window);
4482 if (!window) /* Handle GtkHandleBox */
4484 g_list_free (dest_list);
4493 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4498 dest_list = g_list_remove (dest_list, dest_list->data);
4501 /* Translate from window relative to allocation relative */
4502 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4505 gdk_window_get_position (dest_priv->window, &wx, &wy);
4507 src_x += wx - dest_priv->allocation.x;
4508 src_y += wy - dest_priv->allocation.y;
4512 src_x -= dest_priv->allocation.x;
4513 src_y -= dest_priv->allocation.y;
4525 gtk_widget_real_size_allocate (GtkWidget *widget,
4526 GtkAllocation *allocation)
4528 GtkWidgetPrivate *priv = widget->priv;
4530 priv->allocation = *allocation;
4532 if (gtk_widget_get_realized (widget) &&
4533 gtk_widget_get_has_window (widget))
4535 gdk_window_move_resize (priv->window,
4536 allocation->x, allocation->y,
4537 allocation->width, allocation->height);
4542 get_span_inside_border (GtkWidget *widget,
4546 int allocated_outside_size,
4547 int natural_inside_size,
4548 int *coord_inside_p,
4551 int inside_allocated;
4555 inside_allocated = allocated_outside_size - start_pad - end_pad;
4557 content_size = natural_inside_size;
4558 if (content_size > inside_allocated)
4560 /* didn't get full natural size */
4561 content_size = inside_allocated;
4564 coord = size = 0; /* silence compiler */
4567 case GTK_ALIGN_FILL:
4569 size = inside_allocated;
4571 case GTK_ALIGN_START:
4573 size = content_size;
4576 coord = allocated_outside_size - end_pad - content_size;
4577 size = content_size;
4579 case GTK_ALIGN_CENTER:
4580 coord = start_pad + (inside_allocated - content_size) / 2;
4581 size = content_size;
4586 *coord_inside_p = coord;
4589 *size_inside_p = size;
4593 get_span_inside_border_horizontal (GtkWidget *widget,
4594 const GtkWidgetAuxInfo *aux_info,
4595 int allocated_outside_width,
4596 int natural_inside_width,
4598 int *width_inside_p)
4600 get_span_inside_border (widget,
4602 aux_info->margin.left,
4603 aux_info->margin.right,
4604 allocated_outside_width,
4605 natural_inside_width,
4611 get_span_inside_border_vertical (GtkWidget *widget,
4612 const GtkWidgetAuxInfo *aux_info,
4613 int allocated_outside_height,
4614 int natural_inside_height,
4616 int *height_inside_p)
4618 get_span_inside_border (widget,
4620 aux_info->margin.top,
4621 aux_info->margin.bottom,
4622 allocated_outside_height,
4623 natural_inside_height,
4629 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4630 GtkAllocation *allocation)
4632 const GtkWidgetAuxInfo *aux_info;
4633 GtkRequisition min, natural;
4636 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4638 gtk_widget_get_preferred_size (widget, &min, &natural);
4640 get_span_inside_border_horizontal (widget,
4645 get_span_inside_border_vertical (widget,
4653 allocation->width = w;
4654 allocation->height = h;
4658 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4661 GtkWidgetPrivate *priv = widget->priv;
4663 /* widgets must be onscreen for accels to take effect */
4664 return gtk_widget_is_sensitive (widget) &&
4665 gtk_widget_is_drawable (widget) &&
4666 gdk_window_is_viewable (priv->window);
4670 * gtk_widget_can_activate_accel:
4671 * @widget: a #GtkWidget
4672 * @signal_id: the ID of a signal installed on @widget
4674 * Determines whether an accelerator that activates the signal
4675 * identified by @signal_id can currently be activated.
4676 * This is done by emitting the #GtkWidget::can-activate-accel
4677 * signal on @widget; if the signal isn't overridden by a
4678 * handler or in a derived widget, then the default check is
4679 * that the widget must be sensitive, and the widget and all
4680 * its ancestors mapped.
4682 * Return value: %TRUE if the accelerator can be activated.
4687 gtk_widget_can_activate_accel (GtkWidget *widget,
4690 gboolean can_activate = FALSE;
4691 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4692 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4693 return can_activate;
4702 closure_accel_activate (GClosure *closure,
4703 GValue *return_value,
4704 guint n_param_values,
4705 const GValue *param_values,
4706 gpointer invocation_hint,
4707 gpointer marshal_data)
4709 AccelClosure *aclosure = (AccelClosure*) closure;
4710 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4713 g_signal_emit (closure->data, aclosure->signal_id, 0);
4715 /* whether accelerator was handled */
4716 g_value_set_boolean (return_value, can_activate);
4720 closures_destroy (gpointer data)
4722 GSList *slist, *closures = data;
4724 for (slist = closures; slist; slist = slist->next)
4726 g_closure_invalidate (slist->data);
4727 g_closure_unref (slist->data);
4729 g_slist_free (closures);
4733 widget_new_accel_closure (GtkWidget *widget,
4736 AccelClosure *aclosure;
4737 GClosure *closure = NULL;
4738 GSList *slist, *closures;
4740 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4741 for (slist = closures; slist; slist = slist->next)
4742 if (!gtk_accel_group_from_accel_closure (slist->data))
4744 /* reuse this closure */
4745 closure = slist->data;
4750 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4751 closures = g_slist_prepend (closures, g_closure_ref (closure));
4752 g_closure_sink (closure);
4753 g_closure_set_marshal (closure, closure_accel_activate);
4755 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4757 aclosure = (AccelClosure*) closure;
4758 g_assert (closure->data == widget);
4759 g_assert (closure->marshal == closure_accel_activate);
4760 aclosure->signal_id = signal_id;
4766 * gtk_widget_add_accelerator
4767 * @widget: widget to install an accelerator on
4768 * @accel_signal: widget signal to emit on accelerator activation
4769 * @accel_group: accel group for this widget, added to its toplevel
4770 * @accel_key: GDK keyval of the accelerator
4771 * @accel_mods: modifier key combination of the accelerator
4772 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4774 * Installs an accelerator for this @widget in @accel_group that causes
4775 * @accel_signal to be emitted if the accelerator is activated.
4776 * The @accel_group needs to be added to the widget's toplevel via
4777 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4778 * Accelerators added through this function are not user changeable during
4779 * runtime. If you want to support accelerators that can be changed by the
4780 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4781 * gtk_menu_item_set_accel_path() instead.
4784 gtk_widget_add_accelerator (GtkWidget *widget,
4785 const gchar *accel_signal,
4786 GtkAccelGroup *accel_group,
4788 GdkModifierType accel_mods,
4789 GtkAccelFlags accel_flags)
4794 g_return_if_fail (GTK_IS_WIDGET (widget));
4795 g_return_if_fail (accel_signal != NULL);
4796 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4798 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4799 if (!query.signal_id ||
4800 !(query.signal_flags & G_SIGNAL_ACTION) ||
4801 query.return_type != G_TYPE_NONE ||
4804 /* hmm, should be elaborate enough */
4805 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4806 G_OBJECT_TYPE_NAME (widget), accel_signal);
4810 closure = widget_new_accel_closure (widget, query.signal_id);
4812 g_object_ref (widget);
4814 /* install the accelerator. since we don't map this onto an accel_path,
4815 * the accelerator will automatically be locked.
4817 gtk_accel_group_connect (accel_group,
4820 accel_flags | GTK_ACCEL_LOCKED,
4823 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4825 g_object_unref (widget);
4829 * gtk_widget_remove_accelerator:
4830 * @widget: widget to install an accelerator on
4831 * @accel_group: accel group for this widget
4832 * @accel_key: GDK keyval of the accelerator
4833 * @accel_mods: modifier key combination of the accelerator
4834 * @returns: whether an accelerator was installed and could be removed
4836 * Removes an accelerator from @widget, previously installed with
4837 * gtk_widget_add_accelerator().
4840 gtk_widget_remove_accelerator (GtkWidget *widget,
4841 GtkAccelGroup *accel_group,
4843 GdkModifierType accel_mods)
4845 GtkAccelGroupEntry *ag_entry;
4846 GList *slist, *clist;
4849 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4850 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4852 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4853 clist = gtk_widget_list_accel_closures (widget);
4854 for (slist = clist; slist; slist = slist->next)
4858 for (i = 0; i < n; i++)
4859 if (slist->data == (gpointer) ag_entry[i].closure)
4861 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4863 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4865 g_list_free (clist);
4870 g_list_free (clist);
4872 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4873 accel_key, accel_mods, accel_group,
4874 G_OBJECT_TYPE_NAME (widget), widget);
4880 * gtk_widget_list_accel_closures:
4881 * @widget: widget to list accelerator closures for
4883 * Lists the closures used by @widget for accelerator group connections
4884 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4885 * The closures can be used to monitor accelerator changes on @widget,
4886 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4887 * #GtkAccelGroup of a closure which can be found out with
4888 * gtk_accel_group_from_accel_closure().
4890 * Return value: (transfer container) (element-type GClosure):
4891 * a newly allocated #GList of closures
4894 gtk_widget_list_accel_closures (GtkWidget *widget)
4897 GList *clist = NULL;
4899 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4901 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4902 if (gtk_accel_group_from_accel_closure (slist->data))
4903 clist = g_list_prepend (clist, slist->data);
4909 GtkAccelGroup *accel_group;
4914 destroy_accel_path (gpointer data)
4916 AccelPath *apath = data;
4918 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4920 /* closures_destroy takes care of unrefing the closure */
4921 g_object_unref (apath->accel_group);
4923 g_slice_free (AccelPath, apath);
4928 * gtk_widget_set_accel_path:
4929 * @widget: a #GtkWidget
4930 * @accel_path: (allow-none): path used to look up the accelerator
4931 * @accel_group: (allow-none): a #GtkAccelGroup.
4933 * Given an accelerator group, @accel_group, and an accelerator path,
4934 * @accel_path, sets up an accelerator in @accel_group so whenever the
4935 * key binding that is defined for @accel_path is pressed, @widget
4936 * will be activated. This removes any accelerators (for any
4937 * accelerator group) installed by previous calls to
4938 * gtk_widget_set_accel_path(). Associating accelerators with
4939 * paths allows them to be modified by the user and the modifications
4940 * to be saved for future use. (See gtk_accel_map_save().)
4942 * This function is a low level function that would most likely
4943 * be used by a menu creation system like #GtkUIManager. If you
4944 * use #GtkUIManager, setting up accelerator paths will be done
4947 * Even when you you aren't using #GtkUIManager, if you only want to
4948 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4949 * provides a somewhat more convenient interface.
4951 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4952 * pass a static string, you can save some memory by interning it first with
4953 * g_intern_static_string().
4956 gtk_widget_set_accel_path (GtkWidget *widget,
4957 const gchar *accel_path,
4958 GtkAccelGroup *accel_group)
4962 g_return_if_fail (GTK_IS_WIDGET (widget));
4963 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4967 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4968 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4970 gtk_accel_map_add_entry (accel_path, 0, 0);
4971 apath = g_slice_new (AccelPath);
4972 apath->accel_group = g_object_ref (accel_group);
4973 apath->path_quark = g_quark_from_string (accel_path);
4974 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4979 /* also removes possible old settings */
4980 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4983 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4985 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4989 _gtk_widget_get_accel_path (GtkWidget *widget,
4994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4996 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4998 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4999 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5003 * gtk_widget_mnemonic_activate:
5004 * @widget: a #GtkWidget
5005 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5007 * Emits the #GtkWidget::mnemonic-activate signal.
5009 * The default handler for this signal activates the @widget if
5010 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5013 * Returns: %TRUE if the signal has been handled
5016 gtk_widget_mnemonic_activate (GtkWidget *widget,
5017 gboolean group_cycling)
5021 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5023 group_cycling = group_cycling != FALSE;
5024 if (!gtk_widget_is_sensitive (widget))
5027 g_signal_emit (widget,
5028 widget_signals[MNEMONIC_ACTIVATE],
5036 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5037 gboolean group_cycling)
5039 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5040 gtk_widget_activate (widget);
5041 else if (gtk_widget_get_can_focus (widget))
5042 gtk_widget_grab_focus (widget);
5045 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5046 G_OBJECT_TYPE_NAME (widget));
5047 gtk_widget_error_bell (widget);
5052 static const cairo_user_data_key_t event_key;
5055 _gtk_cairo_get_event (cairo_t *cr)
5057 g_return_val_if_fail (cr != NULL, NULL);
5059 return cairo_get_user_data (cr, &event_key);
5063 gtk_cairo_set_event (cairo_t *cr,
5064 GdkEventExpose *event)
5066 cairo_set_user_data (cr, &event_key, event, NULL);
5070 * gtk_cairo_should_draw_window:
5071 * @cr: a cairo context
5072 * @window: the window to check
5074 * This function is supposed to be called in GtkWidget::draw
5075 * implementations for widgets that support multiple windows.
5076 * @cr must be untransformed from invoking of the draw function.
5077 * This function will return %TRUE if the contents of the given
5078 * @window are supposed to be drawn and %FALSE otherwise. Note
5079 * that when the drawing was not initiated by the windowing
5080 * system this function will return %TRUE for all windows, so
5081 * you need to draw the bottommost window first. Also, do not
5082 * use "else if" statements to check which window should be drawn.
5084 * Returns: %TRUE if @window should be drawn
5087 gtk_cairo_should_draw_window (cairo_t *cr,
5090 GdkEventExpose *event;
5092 g_return_val_if_fail (cr != NULL, FALSE);
5093 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5095 event = _gtk_cairo_get_event (cr);
5097 return event == NULL ||
5098 event->window == window;
5101 /* code shared by gtk_container_propagate_draw() and
5105 _gtk_widget_draw_internal (GtkWidget *widget,
5107 gboolean clip_to_size)
5109 if (!gtk_widget_is_drawable (widget))
5114 cairo_rectangle (cr,
5116 widget->priv->allocation.width,
5117 widget->priv->allocation.height);
5121 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5125 g_signal_emit (widget, widget_signals[DRAW],
5133 * @widget: the widget to draw. It must be drawable (see
5134 * gtk_widget_is_drawable()) and a size must have been allocated.
5135 * @cr: a cairo context to draw to
5137 * Draws @widget to @cr. The top left corner of the widget will be
5138 * drawn to the currently set origin point of @cr.
5140 * You should pass a cairo context as @cr argument that is in an
5141 * original state. Otherwise the resulting drawing is undefined. For
5142 * example changing the operator using cairo_set_operator() or the
5143 * line width using cairo_set_line_width() might have unwanted side
5145 * You may however change the context's transform matrix - like with
5146 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5147 * region with cairo_clip() prior to calling this function. Also, it
5148 * is fine to modify the context with cairo_save() and
5149 * cairo_push_group() prior to calling this function.
5151 * <note><para>Special purpose widgets may contain special code for
5152 * rendering to the screen and might appear differently on screen
5153 * and when rendered using gtk_widget_draw().</para></note>
5156 gtk_widget_draw (GtkWidget *widget,
5159 GdkEventExpose *tmp_event;
5161 g_return_if_fail (GTK_IS_WIDGET (widget));
5162 g_return_if_fail (!GTK_WIDGET_ALLOC_NEEDED (widget));
5163 g_return_if_fail (cr != NULL);
5166 /* We have to reset the event here so that draw functions can call
5167 * gtk_widget_draw() on random other widgets and get the desired
5168 * effect: Drawing all contents, not just the current window.
5170 tmp_event = _gtk_cairo_get_event (cr);
5171 gtk_cairo_set_event (cr, NULL);
5173 _gtk_widget_draw_internal (widget, cr, TRUE);
5175 gtk_cairo_set_event (cr, tmp_event);
5180 gtk_widget_real_key_press_event (GtkWidget *widget,
5183 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5187 gtk_widget_real_key_release_event (GtkWidget *widget,
5190 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5194 gtk_widget_real_focus_in_event (GtkWidget *widget,
5195 GdkEventFocus *event)
5197 gtk_widget_queue_shallow_draw (widget);
5203 gtk_widget_real_focus_out_event (GtkWidget *widget,
5204 GdkEventFocus *event)
5206 gtk_widget_queue_shallow_draw (widget);
5211 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5212 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5216 * @widget: a #GtkWidget
5217 * @event: a #GdkEvent
5219 * Rarely-used function. This function is used to emit
5220 * the event signals on a widget (those signals should never
5221 * be emitted without using this function to do so).
5222 * If you want to synthesize an event though, don't use this function;
5223 * instead, use gtk_main_do_event() so the event will behave as if
5224 * it were in the event queue. Don't synthesize expose events; instead,
5225 * use gdk_window_invalidate_rect() to invalidate a region of the
5228 * Return value: return from the event signal emission (%TRUE if
5229 * the event was handled)
5232 gtk_widget_event (GtkWidget *widget,
5235 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5236 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5238 if (event->type == GDK_EXPOSE)
5240 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5241 "the same effect, call gdk_window_invalidate_rect/region(), "
5242 "followed by gdk_window_process_updates().");
5246 return gtk_widget_event_internal (widget, event);
5251 * gtk_widget_send_expose:
5252 * @widget: a #GtkWidget
5253 * @event: a expose #GdkEvent
5255 * Very rarely-used function. This function is used to emit
5256 * an expose event signals on a widget. This function is not
5257 * normally used directly. The only time it is used is when
5258 * propagating an expose event to a child %NO_WINDOW widget, and
5259 * that is normally done using gtk_container_propagate_expose().
5261 * If you want to force an area of a window to be redrawn,
5262 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5263 * To cause the redraw to be done immediately, follow that call
5264 * with a call to gdk_window_process_updates().
5266 * Return value: return from the event signal emission (%TRUE if
5267 * the event was handled)
5270 gtk_widget_send_expose (GtkWidget *widget,
5273 GdkWindow *window, *w;
5274 gboolean result = FALSE;
5278 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5279 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5280 g_return_val_if_fail (event != NULL, TRUE);
5281 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5283 cr = gdk_cairo_create (event->expose.window);
5284 gtk_cairo_set_event (cr, &event->expose);
5286 gdk_cairo_region (cr, event->expose.region);
5289 if (!gtk_widget_get_has_window (widget))
5291 x = widget->priv->allocation.x;
5292 y = widget->priv->allocation.y;
5300 /* translate cairo context properly */
5301 window = gtk_widget_get_window (widget);
5303 for (w = event->expose.window; w && w != window; w = gdk_window_get_parent (w))
5306 gdk_window_get_position (w, &wx, &wy);
5312 cairo_translate (cr, x, y);
5314 _gtk_widget_draw_internal (widget, cr, w != NULL);
5316 /* unset here, so if someone keeps a reference to cr we
5317 * don't leak the window. */
5318 gtk_cairo_set_event (cr, NULL);
5325 event_window_is_still_viewable (GdkEvent *event)
5327 /* Check that we think the event's window is viewable before
5328 * delivering the event, to prevent suprises. We do this here
5329 * at the last moment, since the event may have been queued
5330 * up behind other events, held over a recursive main loop, etc.
5332 switch (event->type)
5335 case GDK_MOTION_NOTIFY:
5336 case GDK_BUTTON_PRESS:
5337 case GDK_2BUTTON_PRESS:
5338 case GDK_3BUTTON_PRESS:
5340 case GDK_ENTER_NOTIFY:
5341 case GDK_PROXIMITY_IN:
5343 return event->any.window && gdk_window_is_viewable (event->any.window);
5346 /* The following events are the second half of paired events;
5347 * we always deliver them to deal with widgets that clean up
5348 * on the second half.
5350 case GDK_BUTTON_RELEASE:
5351 case GDK_KEY_RELEASE:
5352 case GDK_LEAVE_NOTIFY:
5353 case GDK_PROXIMITY_OUT:
5357 /* Remaining events would make sense on an not-viewable window,
5358 * or don't have an associated window.
5365 gtk_widget_event_internal (GtkWidget *widget,
5368 gboolean return_val = FALSE;
5370 /* We check only once for is-still-visible; if someone
5371 * hides the window in on of the signals on the widget,
5372 * they are responsible for returning TRUE to terminate
5375 if (!event_window_is_still_viewable (event))
5378 g_object_ref (widget);
5380 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5381 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5386 switch (event->type)
5391 case GDK_BUTTON_PRESS:
5392 case GDK_2BUTTON_PRESS:
5393 case GDK_3BUTTON_PRESS:
5394 signal_num = BUTTON_PRESS_EVENT;
5397 signal_num = SCROLL_EVENT;
5399 case GDK_BUTTON_RELEASE:
5400 signal_num = BUTTON_RELEASE_EVENT;
5402 case GDK_MOTION_NOTIFY:
5403 signal_num = MOTION_NOTIFY_EVENT;
5406 signal_num = DELETE_EVENT;
5409 signal_num = DESTROY_EVENT;
5410 _gtk_tooltip_hide (widget);
5413 signal_num = KEY_PRESS_EVENT;
5415 case GDK_KEY_RELEASE:
5416 signal_num = KEY_RELEASE_EVENT;
5418 case GDK_ENTER_NOTIFY:
5419 signal_num = ENTER_NOTIFY_EVENT;
5421 case GDK_LEAVE_NOTIFY:
5422 signal_num = LEAVE_NOTIFY_EVENT;
5424 case GDK_FOCUS_CHANGE:
5425 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5426 if (event->focus_change.in)
5427 _gtk_tooltip_focus_in (widget);
5429 _gtk_tooltip_focus_out (widget);
5432 signal_num = CONFIGURE_EVENT;
5435 signal_num = MAP_EVENT;
5438 signal_num = UNMAP_EVENT;
5440 case GDK_WINDOW_STATE:
5441 signal_num = WINDOW_STATE_EVENT;
5443 case GDK_PROPERTY_NOTIFY:
5444 signal_num = PROPERTY_NOTIFY_EVENT;
5446 case GDK_SELECTION_CLEAR:
5447 signal_num = SELECTION_CLEAR_EVENT;
5449 case GDK_SELECTION_REQUEST:
5450 signal_num = SELECTION_REQUEST_EVENT;
5452 case GDK_SELECTION_NOTIFY:
5453 signal_num = SELECTION_NOTIFY_EVENT;
5455 case GDK_PROXIMITY_IN:
5456 signal_num = PROXIMITY_IN_EVENT;
5458 case GDK_PROXIMITY_OUT:
5459 signal_num = PROXIMITY_OUT_EVENT;
5462 signal_num = NO_EXPOSE_EVENT;
5464 case GDK_CLIENT_EVENT:
5465 signal_num = CLIENT_EVENT;
5468 signal_num = EXPOSE_EVENT;
5470 case GDK_VISIBILITY_NOTIFY:
5471 signal_num = VISIBILITY_NOTIFY_EVENT;
5473 case GDK_GRAB_BROKEN:
5474 signal_num = GRAB_BROKEN;
5477 signal_num = DAMAGE_EVENT;
5480 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5484 if (signal_num != -1)
5485 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5487 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5488 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5492 g_object_unref (widget);
5498 * gtk_widget_activate:
5499 * @widget: a #GtkWidget that's activatable
5501 * For widgets that can be "activated" (buttons, menu items, etc.)
5502 * this function activates them. Activation is what happens when you
5503 * press Enter on a widget during key navigation. If @widget isn't
5504 * activatable, the function returns %FALSE.
5506 * Return value: %TRUE if the widget was activatable
5509 gtk_widget_activate (GtkWidget *widget)
5511 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5513 if (WIDGET_CLASS (widget)->activate_signal)
5515 /* FIXME: we should eventually check the signals signature here */
5516 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5525 * gtk_widget_set_scroll_adjustments:
5526 * @widget: a #GtkWidget
5527 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5528 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5530 * For widgets that support scrolling, sets the scroll adjustments and
5531 * returns %TRUE. For widgets that don't support scrolling, does
5532 * nothing and returns %FALSE. Widgets that don't support scrolling
5533 * can be scrolled by placing them in a #GtkViewport, which does
5534 * support scrolling.
5536 * Return value: %TRUE if the widget supports scrolling
5539 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5540 GtkAdjustment *hadjustment,
5541 GtkAdjustment *vadjustment)
5546 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5549 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5551 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5553 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5557 g_signal_query (signal_id, &query);
5558 if (!query.signal_id ||
5559 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5560 query.return_type != G_TYPE_NONE ||
5561 query.n_params != 2 ||
5562 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5563 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5565 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5566 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5570 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5575 gtk_widget_reparent_subwindows (GtkWidget *widget,
5576 GdkWindow *new_window)
5578 GtkWidgetPrivate *priv = widget->priv;
5580 if (!gtk_widget_get_has_window (widget))
5582 GList *children = gdk_window_get_children (priv->window);
5585 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5587 GdkWindow *window = tmp_list->data;
5590 gdk_window_get_user_data (window, &child);
5591 while (child && child != widget)
5592 child = ((GtkWidget*) child)->priv->parent;
5595 gdk_window_reparent (window, new_window, 0, 0);
5598 g_list_free (children);
5603 GList *tmp_list, *children;
5605 parent = gdk_window_get_parent (priv->window);
5608 gdk_window_reparent (priv->window, new_window, 0, 0);
5611 children = gdk_window_get_children (parent);
5613 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5615 GdkWindow *window = tmp_list->data;
5618 gdk_window_get_user_data (window, &child);
5620 if (child == widget)
5621 gdk_window_reparent (window, new_window, 0, 0);
5624 g_list_free (children);
5630 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5631 gpointer client_data)
5633 GtkWidgetPrivate *priv = widget->priv;
5635 g_assert (client_data != NULL);
5637 if (!gtk_widget_get_has_window (widget))
5640 g_object_unref (priv->window);
5641 priv->window = (GdkWindow*) client_data;
5643 g_object_ref (priv->window);
5645 if (GTK_IS_CONTAINER (widget))
5646 gtk_container_forall (GTK_CONTAINER (widget),
5647 gtk_widget_reparent_fixup_child,
5653 * gtk_widget_reparent:
5654 * @widget: a #GtkWidget
5655 * @new_parent: a #GtkContainer to move the widget into
5657 * Moves a widget from one #GtkContainer to another, handling reference
5658 * count issues to avoid destroying the widget.
5661 gtk_widget_reparent (GtkWidget *widget,
5662 GtkWidget *new_parent)
5664 GtkWidgetPrivate *priv;
5666 g_return_if_fail (GTK_IS_WIDGET (widget));
5667 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5668 priv = widget->priv;
5669 g_return_if_fail (priv->parent != NULL);
5671 if (priv->parent != new_parent)
5673 /* First try to see if we can get away without unrealizing
5674 * the widget as we reparent it. if so we set a flag so
5675 * that gtk_widget_unparent doesn't unrealize widget
5677 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5678 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5680 g_object_ref (widget);
5681 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5682 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5683 g_object_unref (widget);
5685 if (GTK_WIDGET_IN_REPARENT (widget))
5687 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5689 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5690 gtk_widget_reparent_fixup_child (widget,
5691 gtk_widget_get_parent_window (widget));
5694 g_object_notify (G_OBJECT (widget), "parent");
5699 * gtk_widget_intersect:
5700 * @widget: a #GtkWidget
5701 * @area: a rectangle
5702 * @intersection: rectangle to store intersection of @widget and @area
5704 * Computes the intersection of a @widget's area and @area, storing
5705 * the intersection in @intersection, and returns %TRUE if there was
5706 * an intersection. @intersection may be %NULL if you're only
5707 * interested in whether there was an intersection.
5709 * Return value: %TRUE if there was an intersection
5712 gtk_widget_intersect (GtkWidget *widget,
5713 const GdkRectangle *area,
5714 GdkRectangle *intersection)
5716 GtkWidgetPrivate *priv;
5721 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5722 g_return_val_if_fail (area != NULL, FALSE);
5724 priv = widget->priv;
5727 dest = intersection;
5731 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5733 if (return_val && intersection && gtk_widget_get_has_window (widget))
5735 intersection->x -= priv->allocation.x;
5736 intersection->y -= priv->allocation.y;
5743 * gtk_widget_region_intersect:
5744 * @widget: a #GtkWidget
5745 * @region: a #cairo_region_t, in the same coordinate system as
5746 * @widget->allocation. That is, relative to @widget->window
5747 * for %NO_WINDOW widgets; relative to the parent window
5748 * of @widget->window for widgets with their own window.
5749 * @returns: A newly allocated region holding the intersection of @widget
5750 * and @region. The coordinates of the return value are
5751 * relative to @widget->window for %NO_WINDOW widgets, and
5752 * relative to the parent window of @widget->window for
5753 * widgets with their own window.
5755 * Computes the intersection of a @widget's area and @region, returning
5756 * the intersection. The result may be empty, use cairo_region_is_empty() to
5760 gtk_widget_region_intersect (GtkWidget *widget,
5761 const cairo_region_t *region)
5764 cairo_region_t *dest;
5766 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5767 g_return_val_if_fail (region != NULL, NULL);
5769 gtk_widget_get_allocation (widget, &rect);
5771 dest = cairo_region_create_rectangle (&rect);
5773 cairo_region_intersect (dest, region);
5779 * _gtk_widget_grab_notify:
5780 * @widget: a #GtkWidget
5781 * @was_grabbed: whether a grab is now in effect
5783 * Emits the #GtkWidget::grab-notify signal on @widget.
5788 _gtk_widget_grab_notify (GtkWidget *widget,
5789 gboolean was_grabbed)
5791 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5795 * gtk_widget_grab_focus:
5796 * @widget: a #GtkWidget
5798 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5799 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5800 * something like #GtkFrame won't work.
5802 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5803 * gtk_widget_set_can_focus() to modify that flag.
5805 * The widget also needs to be realized and mapped. This is indicated by the
5806 * related signals. Grabbing the focus immediately after creating the widget
5807 * will likely fail and cause critical warnings.
5810 gtk_widget_grab_focus (GtkWidget *widget)
5812 g_return_if_fail (GTK_IS_WIDGET (widget));
5814 if (!gtk_widget_is_sensitive (widget))
5817 g_object_ref (widget);
5818 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5819 g_object_notify (G_OBJECT (widget), "has-focus");
5820 g_object_unref (widget);
5824 reset_focus_recurse (GtkWidget *widget,
5827 if (GTK_IS_CONTAINER (widget))
5829 GtkContainer *container;
5831 container = GTK_CONTAINER (widget);
5832 gtk_container_set_focus_child (container, NULL);
5834 gtk_container_foreach (container,
5835 reset_focus_recurse,
5841 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5843 if (gtk_widget_get_can_focus (focus_widget))
5845 GtkWidget *toplevel;
5848 /* clear the current focus setting, break if the current widget
5849 * is the focus widget's parent, since containers above that will
5850 * be set by the next loop.
5852 toplevel = gtk_widget_get_toplevel (focus_widget);
5853 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5855 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5857 if (widget == focus_widget)
5859 /* We call _gtk_window_internal_set_focus() here so that the
5860 * toplevel window can request the focus if necessary.
5861 * This is needed when the toplevel is a GtkPlug
5863 if (!gtk_widget_has_focus (widget))
5864 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5871 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5873 widget = widget->priv->parent;
5874 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5878 else if (toplevel != focus_widget)
5880 /* gtk_widget_grab_focus() operates on a tree without window...
5881 * actually, this is very questionable behaviour.
5884 gtk_container_foreach (GTK_CONTAINER (toplevel),
5885 reset_focus_recurse,
5889 /* now propagate the new focus up the widget tree and finally
5890 * set it on the window
5892 widget = focus_widget;
5893 while (widget->priv->parent)
5895 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5896 widget = widget->priv->parent;
5898 if (GTK_IS_WINDOW (widget))
5899 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5904 gtk_widget_real_query_tooltip (GtkWidget *widget,
5907 gboolean keyboard_tip,
5908 GtkTooltip *tooltip)
5910 gchar *tooltip_markup;
5911 gboolean has_tooltip;
5913 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5914 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5916 if (has_tooltip && tooltip_markup)
5918 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5926 gtk_widget_real_show_help (GtkWidget *widget,
5927 GtkWidgetHelpType help_type)
5929 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5931 _gtk_tooltip_toggle_keyboard_mode (widget);
5940 gtk_widget_real_focus (GtkWidget *widget,
5941 GtkDirectionType direction)
5943 if (!gtk_widget_get_can_focus (widget))
5946 if (!gtk_widget_is_focus (widget))
5948 gtk_widget_grab_focus (widget);
5956 gtk_widget_real_move_focus (GtkWidget *widget,
5957 GtkDirectionType direction)
5959 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5961 if (GTK_IS_WINDOW (toplevel) &&
5962 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5964 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5970 gtk_widget_real_keynav_failed (GtkWidget *widget,
5971 GtkDirectionType direction)
5973 gboolean cursor_only;
5977 case GTK_DIR_TAB_FORWARD:
5978 case GTK_DIR_TAB_BACKWARD:
5985 g_object_get (gtk_widget_get_settings (widget),
5986 "gtk-keynav-cursor-only", &cursor_only,
5993 gtk_widget_error_bell (widget);
5999 * gtk_widget_set_can_focus:
6000 * @widget: a #GtkWidget
6001 * @can_focus: whether or not @widget can own the input focus.
6003 * Specifies whether @widget can own the input focus. See
6004 * gtk_widget_grab_focus() for actually setting the input focus on a
6010 gtk_widget_set_can_focus (GtkWidget *widget,
6013 g_return_if_fail (GTK_IS_WIDGET (widget));
6015 if (can_focus != gtk_widget_get_can_focus (widget))
6018 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
6020 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
6022 gtk_widget_queue_resize (widget);
6023 g_object_notify (G_OBJECT (widget), "can-focus");
6028 * gtk_widget_get_can_focus:
6029 * @widget: a #GtkWidget
6031 * Determines whether @widget can own the input focus. See
6032 * gtk_widget_set_can_focus().
6034 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6039 gtk_widget_get_can_focus (GtkWidget *widget)
6041 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6043 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
6047 * gtk_widget_has_focus:
6048 * @widget: a #GtkWidget
6050 * Determines if the widget has the global input focus. See
6051 * gtk_widget_is_focus() for the difference between having the global
6052 * input focus, and only having the focus within a toplevel.
6054 * Return value: %TRUE if the widget has the global input focus.
6059 gtk_widget_has_focus (GtkWidget *widget)
6061 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6063 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
6067 * gtk_widget_is_focus:
6068 * @widget: a #GtkWidget
6070 * Determines if the widget is the focus widget within its
6071 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6072 * necessarily set; %HAS_FOCUS will only be set if the
6073 * toplevel widget additionally has the global input focus.)
6075 * Return value: %TRUE if the widget is the focus widget.
6078 gtk_widget_is_focus (GtkWidget *widget)
6080 GtkWidget *toplevel;
6082 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6084 toplevel = gtk_widget_get_toplevel (widget);
6086 if (GTK_IS_WINDOW (toplevel))
6087 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6093 * gtk_widget_set_can_default:
6094 * @widget: a #GtkWidget
6095 * @can_default: whether or not @widget can be a default widget.
6097 * Specifies whether @widget can be a default widget. See
6098 * gtk_widget_grab_default() for details about the meaning of
6104 gtk_widget_set_can_default (GtkWidget *widget,
6105 gboolean can_default)
6107 g_return_if_fail (GTK_IS_WIDGET (widget));
6109 if (can_default != gtk_widget_get_can_default (widget))
6112 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
6114 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
6116 gtk_widget_queue_resize (widget);
6117 g_object_notify (G_OBJECT (widget), "can-default");
6122 * gtk_widget_get_can_default:
6123 * @widget: a #GtkWidget
6125 * Determines whether @widget can be a default widget. See
6126 * gtk_widget_set_can_default().
6128 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6133 gtk_widget_get_can_default (GtkWidget *widget)
6135 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6137 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6141 * gtk_widget_has_default:
6142 * @widget: a #GtkWidget
6144 * Determines whether @widget is the current default widget within its
6145 * toplevel. See gtk_widget_set_can_default().
6147 * Return value: %TRUE if @widget is the current default widget within
6148 * its toplevel, %FALSE otherwise
6153 gtk_widget_has_default (GtkWidget *widget)
6155 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6157 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6161 _gtk_widget_set_has_default (GtkWidget *widget,
6162 gboolean has_default)
6165 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6167 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6171 * gtk_widget_grab_default:
6172 * @widget: a #GtkWidget
6174 * Causes @widget to become the default widget. @widget must have the
6175 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6176 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6177 * %TRUE)</literal>. The default widget is activated when
6178 * the user presses Enter in a window. Default widgets must be
6179 * activatable, that is, gtk_widget_activate() should affect them. Note
6180 * that #GtkEntry widgets require the "activates-default" property
6181 * set to %TRUE before they activate the default widget when Enter
6182 * is pressed and the #GtkEntry is focused.
6185 gtk_widget_grab_default (GtkWidget *widget)
6189 g_return_if_fail (GTK_IS_WIDGET (widget));
6190 g_return_if_fail (gtk_widget_get_can_default (widget));
6192 window = gtk_widget_get_toplevel (widget);
6194 if (window && gtk_widget_is_toplevel (window))
6195 gtk_window_set_default (GTK_WINDOW (window), widget);
6197 g_warning (G_STRLOC ": widget not within a GtkWindow");
6201 * gtk_widget_set_receives_default:
6202 * @widget: a #GtkWidget
6203 * @receives_default: whether or not @widget can be a default widget.
6205 * Specifies whether @widget will be treated as the default widget
6206 * within its toplevel when it has the focus, even if another widget
6209 * See gtk_widget_grab_default() for details about the meaning of
6215 gtk_widget_set_receives_default (GtkWidget *widget,
6216 gboolean receives_default)
6218 g_return_if_fail (GTK_IS_WIDGET (widget));
6220 if (receives_default != gtk_widget_get_receives_default (widget))
6222 if (receives_default)
6223 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6225 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6227 g_object_notify (G_OBJECT (widget), "receives-default");
6232 * gtk_widget_get_receives_default:
6233 * @widget: a #GtkWidget
6235 * Determines whether @widget is alyways treated as default widget
6236 * withing its toplevel when it has the focus, even if another widget
6239 * See gtk_widget_set_receives_default().
6241 * Return value: %TRUE if @widget acts as default widget when focussed,
6247 gtk_widget_get_receives_default (GtkWidget *widget)
6249 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6251 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6255 * gtk_widget_has_grab:
6256 * @widget: a #GtkWidget
6258 * Determines whether the widget is currently grabbing events, so it
6259 * is the only widget receiving input events (keyboard and mouse).
6261 * See also gtk_grab_add().
6263 * Return value: %TRUE if the widget is in the grab_widgets stack
6268 gtk_widget_has_grab (GtkWidget *widget)
6270 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6272 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6276 _gtk_widget_set_has_grab (GtkWidget *widget,
6280 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6282 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6286 * gtk_widget_device_is_shadowed:
6287 * @widget: a #GtkWidget
6288 * @device: a #GdkDevice
6290 * Returns %TRUE if @device has been shadowed by a GTK+
6291 * device grab on another widget, so it would stop sending
6292 * events to @widget. This may be used in the
6293 * #GtkWidget::grab-notify signal to check for specific
6294 * devices. See gtk_device_grab_add().
6296 * Returns: %TRUE if there is an ongoing grab on @device
6297 * by another #GtkWidget than @widget.
6302 gtk_widget_device_is_shadowed (GtkWidget *widget,
6305 GtkWindowGroup *group;
6306 GtkWidget *grab_widget, *toplevel;
6308 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6309 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6311 if (!gtk_widget_get_realized (widget))
6314 toplevel = gtk_widget_get_toplevel (widget);
6316 if (GTK_IS_WINDOW (toplevel))
6317 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6319 group = gtk_window_get_group (NULL);
6321 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6323 /* Widget not inside the hierarchy of grab_widget */
6325 widget != grab_widget &&
6326 !gtk_widget_is_ancestor (widget, grab_widget))
6329 grab_widget = gtk_window_group_get_current_grab (group);
6330 if (grab_widget && widget != grab_widget &&
6331 !gtk_widget_is_ancestor (widget, grab_widget))
6338 * gtk_widget_set_name:
6339 * @widget: a #GtkWidget
6340 * @name: name for the widget
6342 * Widgets can be named, which allows you to refer to them from a
6343 * gtkrc file. You can apply a style to widgets with a particular name
6344 * in the gtkrc file. See the documentation for gtkrc files (on the
6345 * same page as the docs for #GtkRcStyle).
6347 * Note that widget names are separated by periods in paths (see
6348 * gtk_widget_path()), so names with embedded periods may cause confusion.
6351 gtk_widget_set_name (GtkWidget *widget,
6354 GtkWidgetPrivate *priv;
6357 g_return_if_fail (GTK_IS_WIDGET (widget));
6359 priv = widget->priv;
6361 new_name = g_strdup (name);
6362 g_free (priv->name);
6363 priv->name = new_name;
6365 if (gtk_widget_has_rc_style (widget))
6366 gtk_widget_reset_rc_style (widget);
6368 g_object_notify (G_OBJECT (widget), "name");
6372 * gtk_widget_get_name:
6373 * @widget: a #GtkWidget
6375 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6376 * significance of widget names.
6378 * Return value: name of the widget. This string is owned by GTK+ and
6379 * should not be modified or freed
6381 G_CONST_RETURN gchar*
6382 gtk_widget_get_name (GtkWidget *widget)
6384 GtkWidgetPrivate *priv;
6386 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6388 priv = widget->priv;
6392 return G_OBJECT_TYPE_NAME (widget);
6396 * gtk_widget_set_state:
6397 * @widget: a #GtkWidget
6398 * @state: new state for @widget
6400 * This function is for use in widget implementations. Sets the state
6401 * of a widget (insensitive, prelighted, etc.) Usually you should set
6402 * the state using wrapper functions such as gtk_widget_set_sensitive().
6405 gtk_widget_set_state (GtkWidget *widget,
6408 GtkWidgetPrivate *priv;
6410 g_return_if_fail (GTK_IS_WIDGET (widget));
6412 priv = widget->priv;
6414 if (state == gtk_widget_get_state (widget))
6417 if (state == GTK_STATE_INSENSITIVE)
6418 gtk_widget_set_sensitive (widget, FALSE);
6424 data.state_restoration = FALSE;
6425 data.use_forall = FALSE;
6427 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6429 data.parent_sensitive = TRUE;
6431 gtk_widget_propagate_state (widget, &data);
6433 if (gtk_widget_is_drawable (widget))
6434 gtk_widget_queue_draw (widget);
6439 * gtk_widget_get_state:
6440 * @widget: a #GtkWidget
6442 * Returns the widget's state. See gtk_widget_set_state().
6444 * Returns: the state of @widget.
6449 gtk_widget_get_state (GtkWidget *widget)
6451 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6453 return widget->priv->state;
6457 * gtk_widget_set_visible:
6458 * @widget: a #GtkWidget
6459 * @visible: whether the widget should be shown or not
6461 * Sets the visibility state of @widget. Note that setting this to
6462 * %TRUE doesn't mean the widget is actually viewable, see
6463 * gtk_widget_get_visible().
6465 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6466 * but is nicer to use when the visibility of the widget depends on
6472 gtk_widget_set_visible (GtkWidget *widget,
6475 g_return_if_fail (GTK_IS_WIDGET (widget));
6477 if (visible != gtk_widget_get_visible (widget))
6480 gtk_widget_show (widget);
6482 gtk_widget_hide (widget);
6487 * gtk_widget_get_visible:
6488 * @widget: a #GtkWidget
6490 * Determines whether the widget is visible. Note that this doesn't
6491 * take into account whether the widget's parent is also visible
6492 * or the widget is obscured in any way.
6494 * See gtk_widget_set_visible().
6496 * Return value: %TRUE if the widget is visible
6501 gtk_widget_get_visible (GtkWidget *widget)
6503 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6505 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6509 * gtk_widget_set_has_window:
6510 * @widget: a #GtkWidget
6511 * @has_window: whether or not @widget has a window.
6513 * Specifies whether @widget has a #GdkWindow of its own. Note that
6514 * all realized widgets have a non-%NULL "window" pointer
6515 * (gtk_widget_get_window() never returns a %NULL window when a widget
6516 * is realized), but for many of them it's actually the #GdkWindow of
6517 * one of its parent widgets. Widgets that do not create a %window for
6518 * themselves in GtkWidget::realize() must announce this by
6519 * calling this function with @has_window = %FALSE.
6521 * This function should only be called by widget implementations,
6522 * and they should call it in their init() function.
6527 gtk_widget_set_has_window (GtkWidget *widget,
6528 gboolean has_window)
6530 g_return_if_fail (GTK_IS_WIDGET (widget));
6533 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6535 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6539 * gtk_widget_get_has_window:
6540 * @widget: a #GtkWidget
6542 * Determines whether @widget has a #GdkWindow of its own. See
6543 * gtk_widget_set_has_window().
6545 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6550 gtk_widget_get_has_window (GtkWidget *widget)
6552 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6554 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6558 * gtk_widget_is_toplevel:
6559 * @widget: a #GtkWidget
6561 * Determines whether @widget is a toplevel widget. Currently only
6562 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6563 * widgets have no parent widget.
6565 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6570 gtk_widget_is_toplevel (GtkWidget *widget)
6572 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6574 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6578 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6579 gboolean is_toplevel)
6582 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6584 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6588 * gtk_widget_is_drawable:
6589 * @widget: a #GtkWidget
6591 * Determines whether @widget can be drawn to. A widget can be drawn
6592 * to if it is mapped and visible.
6594 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6599 gtk_widget_is_drawable (GtkWidget *widget)
6601 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6603 return (gtk_widget_get_visible (widget) &&
6604 gtk_widget_get_mapped (widget));
6608 * gtk_widget_get_realized:
6609 * @widget: a #GtkWidget
6611 * Determines whether @widget is realized.
6613 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6618 gtk_widget_get_realized (GtkWidget *widget)
6620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6622 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6626 * gtk_widget_set_realized:
6627 * @widget: a #GtkWidget
6628 * @realized: %TRUE to mark the widget as realized
6630 * Marks the widget as being realized.
6632 * This function should only ever be called in a derived widget's
6633 * "realize" or "unrealize" implementation.
6638 gtk_widget_set_realized (GtkWidget *widget,
6641 g_return_if_fail (GTK_IS_WIDGET (widget));
6644 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6646 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6650 * gtk_widget_get_mapped:
6651 * @widget: a #GtkWidget
6653 * Whether the widget is mapped.
6655 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6660 gtk_widget_get_mapped (GtkWidget *widget)
6662 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6664 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6668 * gtk_widget_set_mapped:
6669 * @widget: a #GtkWidget
6670 * @mapped: %TRUE to mark the widget as mapped
6672 * Marks the widget as being realized.
6674 * This function should only ever be called in a derived widget's
6675 * "map" or "unmap" implementation.
6680 gtk_widget_set_mapped (GtkWidget *widget,
6683 g_return_if_fail (GTK_IS_WIDGET (widget));
6686 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6688 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6692 * gtk_widget_set_app_paintable:
6693 * @widget: a #GtkWidget
6694 * @app_paintable: %TRUE if the application will paint on the widget
6696 * Sets whether the application intends to draw on the widget in
6697 * an #GtkWidget::draw handler.
6699 * This is a hint to the widget and does not affect the behavior of
6700 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6701 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6702 * the effect is to suppress default themed drawing of the widget's
6703 * background. (Children of the widget will still be drawn.) The application
6704 * is then entirely responsible for drawing the widget background.
6706 * Note that the background is still drawn when the widget is mapped.
6709 gtk_widget_set_app_paintable (GtkWidget *widget,
6710 gboolean app_paintable)
6712 g_return_if_fail (GTK_IS_WIDGET (widget));
6714 app_paintable = (app_paintable != FALSE);
6716 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6719 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6721 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6723 if (gtk_widget_is_drawable (widget))
6724 gtk_widget_queue_draw (widget);
6726 g_object_notify (G_OBJECT (widget), "app-paintable");
6731 * gtk_widget_get_app_paintable:
6732 * @widget: a #GtkWidget
6734 * Determines whether the application intends to draw on the widget in
6735 * an #GtkWidget::draw handler.
6737 * See gtk_widget_set_app_paintable()
6739 * Return value: %TRUE if the widget is app paintable
6744 gtk_widget_get_app_paintable (GtkWidget *widget)
6746 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6748 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6752 * gtk_widget_set_double_buffered:
6753 * @widget: a #GtkWidget
6754 * @double_buffered: %TRUE to double-buffer a widget
6756 * Widgets are double buffered by default; you can use this function
6757 * to turn off the buffering. "Double buffered" simply means that
6758 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6759 * automatically around expose events sent to the
6760 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6761 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6762 * buffer to the screen. The result is that users see the window
6763 * update in one smooth step, and don't see individual graphics
6764 * primitives being rendered.
6766 * In very simple terms, double buffered widgets don't flicker,
6767 * so you would only use this function to turn off double buffering
6768 * if you had special needs and really knew what you were doing.
6770 * Note: if you turn off double-buffering, you have to handle
6771 * expose events, since even the clearing to the background color or
6772 * pixmap will not happen automatically (as it is done in
6773 * gdk_window_begin_paint()).
6776 gtk_widget_set_double_buffered (GtkWidget *widget,
6777 gboolean double_buffered)
6779 g_return_if_fail (GTK_IS_WIDGET (widget));
6781 double_buffered = (double_buffered != FALSE);
6783 if (double_buffered != gtk_widget_get_double_buffered (widget))
6785 if (double_buffered)
6786 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6788 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6790 g_object_notify (G_OBJECT (widget), "double-buffered");
6795 * gtk_widget_get_double_buffered:
6796 * @widget: a #GtkWidget
6798 * Determines whether the widget is double buffered.
6800 * See gtk_widget_set_double_buffered()
6802 * Return value: %TRUE if the widget is double buffered
6807 gtk_widget_get_double_buffered (GtkWidget *widget)
6809 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6811 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6815 * gtk_widget_set_redraw_on_allocate:
6816 * @widget: a #GtkWidget
6817 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6818 * when it is allocated to a new size. Otherwise, only the
6819 * new portion of the widget will be redrawn.
6821 * Sets whether the entire widget is queued for drawing when its size
6822 * allocation changes. By default, this setting is %TRUE and
6823 * the entire widget is redrawn on every size change. If your widget
6824 * leaves the upper left unchanged when made bigger, turning this
6825 * setting off will improve performance.
6827 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6828 * off all allocation on resizing: the widget will not even redraw if
6829 * its position changes; this is to allow containers that don't draw
6830 * anything to avoid excess invalidations. If you set this flag on a
6831 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6832 * you are responsible for invalidating both the old and new allocation
6833 * of the widget when the widget is moved and responsible for invalidating
6834 * regions newly when the widget increases size.
6837 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6838 gboolean redraw_on_allocate)
6840 g_return_if_fail (GTK_IS_WIDGET (widget));
6842 if (redraw_on_allocate)
6843 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6845 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6849 * gtk_widget_set_sensitive:
6850 * @widget: a #GtkWidget
6851 * @sensitive: %TRUE to make the widget sensitive
6853 * Sets the sensitivity of a widget. A widget is sensitive if the user
6854 * can interact with it. Insensitive widgets are "grayed out" and the
6855 * user can't interact with them. Insensitive widgets are known as
6856 * "inactive", "disabled", or "ghosted" in some other toolkits.
6859 gtk_widget_set_sensitive (GtkWidget *widget,
6862 GtkWidgetPrivate *priv;
6865 g_return_if_fail (GTK_IS_WIDGET (widget));
6867 priv = widget->priv;
6869 sensitive = (sensitive != FALSE);
6871 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6876 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6877 data.state = priv->saved_state;
6881 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6882 data.state = gtk_widget_get_state (widget);
6884 data.state_restoration = TRUE;
6885 data.use_forall = TRUE;
6888 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6890 data.parent_sensitive = TRUE;
6892 gtk_widget_propagate_state (widget, &data);
6893 if (gtk_widget_is_drawable (widget))
6894 gtk_widget_queue_draw (widget);
6896 g_object_notify (G_OBJECT (widget), "sensitive");
6900 * gtk_widget_get_sensitive:
6901 * @widget: a #GtkWidget
6903 * Returns the widget's sensitivity (in the sense of returning
6904 * the value that has been set using gtk_widget_set_sensitive()).
6906 * The effective sensitivity of a widget is however determined by both its
6907 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6909 * Returns: %TRUE if the widget is sensitive
6914 gtk_widget_get_sensitive (GtkWidget *widget)
6916 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6918 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6922 * gtk_widget_is_sensitive:
6923 * @widget: a #GtkWidget
6925 * Returns the widget's effective sensitivity, which means
6926 * it is sensitive itself and also its parent widget is sensntive
6928 * Returns: %TRUE if the widget is effectively sensitive
6933 gtk_widget_is_sensitive (GtkWidget *widget)
6935 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6937 return (gtk_widget_get_sensitive (widget) &&
6938 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6942 * gtk_widget_set_parent:
6943 * @widget: a #GtkWidget
6944 * @parent: parent container
6946 * This function is useful only when implementing subclasses of
6948 * Sets the container as the parent of @widget, and takes care of
6949 * some details such as updating the state and style of the child
6950 * to reflect its new location. The opposite function is
6951 * gtk_widget_unparent().
6954 gtk_widget_set_parent (GtkWidget *widget,
6957 GtkWidgetPrivate *priv;
6960 g_return_if_fail (GTK_IS_WIDGET (widget));
6961 g_return_if_fail (GTK_IS_WIDGET (parent));
6962 g_return_if_fail (widget != parent);
6964 priv = widget->priv;
6966 if (priv->parent != NULL)
6968 g_warning ("Can't set a parent on widget which has a parent\n");
6971 if (gtk_widget_is_toplevel (widget))
6973 g_warning ("Can't set a parent on a toplevel widget\n");
6977 /* keep this function in sync with gtk_menu_attach_to_widget()
6980 g_object_ref_sink (widget);
6981 priv->parent = parent;
6983 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6984 data.state = gtk_widget_get_state (parent);
6986 data.state = gtk_widget_get_state (widget);
6987 data.state_restoration = FALSE;
6988 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6989 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6991 gtk_widget_propagate_state (widget, &data);
6993 gtk_widget_reset_rc_styles (widget);
6995 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6996 if (GTK_WIDGET_ANCHORED (priv->parent))
6997 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6998 g_object_notify (G_OBJECT (widget), "parent");
7000 /* Enforce realized/mapped invariants
7002 if (gtk_widget_get_realized (priv->parent))
7003 gtk_widget_realize (widget);
7005 if (gtk_widget_get_visible (priv->parent) &&
7006 gtk_widget_get_visible (widget))
7008 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
7009 gtk_widget_get_mapped (priv->parent))
7010 gtk_widget_map (widget);
7012 gtk_widget_queue_resize (widget);
7017 * gtk_widget_get_parent:
7018 * @widget: a #GtkWidget
7020 * Returns the parent container of @widget.
7022 * Return value: (transfer none): the parent container of @widget, or %NULL
7025 gtk_widget_get_parent (GtkWidget *widget)
7027 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7029 return widget->priv->parent;
7032 /*****************************************
7034 * see docs/styles.txt
7035 *****************************************/
7038 * gtk_widget_style_attach:
7039 * @widget: a #GtkWidget
7041 * This function attaches the widget's #GtkStyle to the widget's
7042 * #GdkWindow. It is a replacement for
7045 * widget->style = gtk_style_attach (widget->style, widget->window);
7048 * and should only ever be called in a derived widget's "realize"
7049 * implementation which does not chain up to its parent class'
7050 * "realize" implementation, because one of the parent classes
7051 * (finally #GtkWidget) would attach the style itself.
7056 gtk_widget_style_attach (GtkWidget *widget)
7058 GtkWidgetPrivate *priv;
7060 g_return_if_fail (GTK_IS_WIDGET (widget));
7061 g_return_if_fail (gtk_widget_get_realized (widget));
7063 priv = widget->priv;
7065 priv->style = gtk_style_attach (priv->style, priv->window);
7069 * gtk_widget_has_rc_style:
7070 * @widget: a #GtkWidget
7072 * Determines if the widget style has been looked up through the rc mechanism.
7074 * Returns: %TRUE if the widget has been looked up through the rc
7075 * mechanism, %FALSE otherwise.
7080 gtk_widget_has_rc_style (GtkWidget *widget)
7082 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7084 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
7088 * gtk_widget_set_style:
7089 * @widget: a #GtkWidget
7090 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7091 * gtk_widget_set_style() and go back to the default style
7093 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7094 * want to use this function; it interacts badly with themes, because
7095 * themes work by replacing the #GtkStyle. Instead, use
7096 * gtk_widget_modify_style().
7099 gtk_widget_set_style (GtkWidget *widget,
7102 g_return_if_fail (GTK_IS_WIDGET (widget));
7106 gboolean initial_emission;
7108 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7110 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
7111 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
7113 gtk_widget_set_style_internal (widget, style, initial_emission);
7117 if (GTK_WIDGET_USER_STYLE (widget))
7118 gtk_widget_reset_rc_style (widget);
7123 * gtk_widget_ensure_style:
7124 * @widget: a #GtkWidget
7126 * Ensures that @widget has a style (@widget->style). Not a very useful
7127 * function; most of the time, if you want the style, the widget is
7128 * realized, and realized widgets are guaranteed to have a style
7132 gtk_widget_ensure_style (GtkWidget *widget)
7134 g_return_if_fail (GTK_IS_WIDGET (widget));
7136 if (!GTK_WIDGET_USER_STYLE (widget) &&
7137 !gtk_widget_has_rc_style (widget))
7138 gtk_widget_reset_rc_style (widget);
7141 /* Look up the RC style for this widget, unsetting any user style that
7142 * may be in effect currently
7145 gtk_widget_reset_rc_style (GtkWidget *widget)
7147 GtkWidgetPrivate *priv = widget->priv;
7148 GtkStyle *new_style = NULL;
7149 gboolean initial_emission;
7151 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7153 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7154 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7156 if (gtk_widget_has_screen (widget))
7157 new_style = gtk_rc_get_style (widget);
7159 new_style = gtk_widget_get_default_style ();
7161 if (initial_emission || new_style != priv->style)
7162 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7166 * gtk_widget_get_style:
7167 * @widget: a #GtkWidget
7169 * Simply an accessor function that returns @widget->style.
7171 * Return value: (transfer none): the widget's #GtkStyle
7174 gtk_widget_get_style (GtkWidget *widget)
7176 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7178 return widget->priv->style;
7182 * gtk_widget_modify_style:
7183 * @widget: a #GtkWidget
7184 * @style: the #GtkRcStyle holding the style modifications
7186 * Modifies style values on the widget. Modifications made using this
7187 * technique take precedence over style values set via an RC file,
7188 * however, they will be overriden if a style is explicitely set on
7189 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7190 * is designed so each field can either be set or unset, so it is
7191 * possible, using this function, to modify some style values and
7192 * leave the others unchanged.
7194 * Note that modifications made with this function are not cumulative
7195 * with previous calls to gtk_widget_modify_style() or with such
7196 * functions as gtk_widget_modify_fg(). If you wish to retain
7197 * previous values, you must first call gtk_widget_get_modifier_style(),
7198 * make your modifications to the returned style, then call
7199 * gtk_widget_modify_style() with that style. On the other hand,
7200 * if you first call gtk_widget_modify_style(), subsequent calls
7201 * to such functions gtk_widget_modify_fg() will have a cumulative
7202 * effect with the initial modifications.
7205 gtk_widget_modify_style (GtkWidget *widget,
7208 g_return_if_fail (GTK_IS_WIDGET (widget));
7209 g_return_if_fail (GTK_IS_RC_STYLE (style));
7211 g_object_set_qdata_full (G_OBJECT (widget),
7213 gtk_rc_style_copy (style),
7214 (GDestroyNotify) g_object_unref);
7216 /* note that "style" may be invalid here if it was the old
7217 * modifier style and the only reference was our own.
7220 if (gtk_widget_has_rc_style (widget))
7221 gtk_widget_reset_rc_style (widget);
7225 * gtk_widget_get_modifier_style:
7226 * @widget: a #GtkWidget
7228 * Returns the current modifier style for the widget. (As set by
7229 * gtk_widget_modify_style().) If no style has previously set, a new
7230 * #GtkRcStyle will be created with all values unset, and set as the
7231 * modifier style for the widget. If you make changes to this rc
7232 * style, you must call gtk_widget_modify_style(), passing in the
7233 * returned rc style, to make sure that your changes take effect.
7235 * Caution: passing the style back to gtk_widget_modify_style() will
7236 * normally end up destroying it, because gtk_widget_modify_style() copies
7237 * the passed-in style and sets the copy as the new modifier style,
7238 * thus dropping any reference to the old modifier style. Add a reference
7239 * to the modifier style if you want to keep it alive.
7241 * Return value: (transfer none): the modifier style for the widget. This rc style is
7242 * owned by the widget. If you want to keep a pointer to value this
7243 * around, you must add a refcount using g_object_ref().
7246 gtk_widget_get_modifier_style (GtkWidget *widget)
7248 GtkRcStyle *rc_style;
7250 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7252 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7256 rc_style = gtk_rc_style_new ();
7257 g_object_set_qdata_full (G_OBJECT (widget),
7260 (GDestroyNotify) g_object_unref);
7267 gtk_widget_modify_color_component (GtkWidget *widget,
7268 GtkRcFlags component,
7270 const GdkColor *color)
7272 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7279 rc_style->fg[state] = *color;
7282 rc_style->bg[state] = *color;
7285 rc_style->text[state] = *color;
7288 rc_style->base[state] = *color;
7291 g_assert_not_reached();
7294 rc_style->color_flags[state] |= component;
7297 rc_style->color_flags[state] &= ~component;
7299 gtk_widget_modify_style (widget, rc_style);
7303 * gtk_widget_modify_symbolic_color:
7304 * @widget: a #GtkWidget
7305 * @name: the name of the symbolic color to modify
7306 * @color: (allow-none): the color to assign (does not need to be allocated),
7307 * or %NULL to undo the effect of previous calls to
7308 * of gtk_widget_modify_symbolic_color().
7310 * Sets a symbolic color for a widget.
7311 * All other style values are left untouched. See also
7312 * gtk_widget_modify_style().
7317 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7319 const GdkColor *color)
7321 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7323 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7325 gtk_widget_modify_style (widget, rc_style);
7329 * gtk_widget_modify_fg:
7330 * @widget: a #GtkWidget
7331 * @state: the state for which to set the foreground color
7332 * @color: (allow-none): the color to assign (does not need to be allocated),
7333 * or %NULL to undo the effect of previous calls to
7334 * of gtk_widget_modify_fg().
7336 * Sets the foreground color for a widget in a particular state.
7337 * All other style values are left untouched. See also
7338 * gtk_widget_modify_style().
7341 gtk_widget_modify_fg (GtkWidget *widget,
7343 const GdkColor *color)
7345 g_return_if_fail (GTK_IS_WIDGET (widget));
7346 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7348 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7352 * gtk_widget_modify_bg:
7353 * @widget: a #GtkWidget
7354 * @state: the state for which to set the background color
7355 * @color: (allow-none): the color to assign (does not need to be allocated),
7356 * or %NULL to undo the effect of previous calls to
7357 * of gtk_widget_modify_bg().
7359 * Sets the background color for a widget in a particular state.
7360 * All other style values are left untouched. See also
7361 * gtk_widget_modify_style().
7363 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7364 * draw on their parent container's window and thus may not draw any
7365 * background themselves. This is the case for e.g. #GtkLabel. To modify
7366 * the background of such widgets, you have to set the background color
7367 * on their parent; if you want to set the background of a rectangular
7368 * area around a label, try placing the label in a #GtkEventBox widget
7369 * and setting the background color on that.
7372 gtk_widget_modify_bg (GtkWidget *widget,
7374 const GdkColor *color)
7376 g_return_if_fail (GTK_IS_WIDGET (widget));
7377 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7379 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7383 * gtk_widget_modify_text:
7384 * @widget: a #GtkWidget
7385 * @state: the state for which to set the text color
7386 * @color: (allow-none): the color to assign (does not need to be allocated),
7387 * or %NULL to undo the effect of previous calls to
7388 * of gtk_widget_modify_text().
7390 * Sets the text color for a widget in a particular state. All other
7391 * style values are left untouched. The text color is the foreground
7392 * color used along with the base color (see gtk_widget_modify_base())
7393 * for widgets such as #GtkEntry and #GtkTextView. See also
7394 * gtk_widget_modify_style().
7397 gtk_widget_modify_text (GtkWidget *widget,
7399 const GdkColor *color)
7401 g_return_if_fail (GTK_IS_WIDGET (widget));
7402 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7404 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7408 * gtk_widget_modify_base:
7409 * @widget: a #GtkWidget
7410 * @state: the state for which to set the base color
7411 * @color: (allow-none): the color to assign (does not need to be allocated),
7412 * or %NULL to undo the effect of previous calls to
7413 * of gtk_widget_modify_base().
7415 * Sets the base color for a widget in a particular state.
7416 * All other style values are left untouched. The base color
7417 * is the background color used along with the text color
7418 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7419 * and #GtkTextView. See also gtk_widget_modify_style().
7421 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7422 * draw on their parent container's window and thus may not draw any
7423 * background themselves. This is the case for e.g. #GtkLabel. To modify
7424 * the background of such widgets, you have to set the base color on their
7425 * parent; if you want to set the background of a rectangular area around
7426 * a label, try placing the label in a #GtkEventBox widget and setting
7427 * the base color on that.
7430 gtk_widget_modify_base (GtkWidget *widget,
7432 const GdkColor *color)
7434 g_return_if_fail (GTK_IS_WIDGET (widget));
7435 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7437 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7441 modify_color_property (GtkWidget *widget,
7442 GtkRcStyle *rc_style,
7444 const GdkColor *color)
7446 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7447 GQuark property_name = g_quark_from_string (name);
7451 GtkRcProperty rc_property = {0};
7454 rc_property.type_name = type_name;
7455 rc_property.property_name = property_name;
7456 rc_property.origin = NULL;
7458 color_name = gdk_color_to_string (color);
7459 g_value_init (&rc_property.value, G_TYPE_STRING);
7460 g_value_take_string (&rc_property.value, color_name);
7462 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7464 g_value_unset (&rc_property.value);
7467 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7471 * gtk_widget_modify_cursor:
7472 * @widget: a #GtkWidget
7473 * @primary: the color to use for primary cursor (does not need to be
7474 * allocated), or %NULL to undo the effect of previous calls to
7475 * of gtk_widget_modify_cursor().
7476 * @secondary: the color to use for secondary cursor (does not need to be
7477 * allocated), or %NULL to undo the effect of previous calls to
7478 * of gtk_widget_modify_cursor().
7480 * Sets the cursor color to use in a widget, overriding the
7481 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7482 * style properties. All other style values are left untouched.
7483 * See also gtk_widget_modify_style().
7488 gtk_widget_modify_cursor (GtkWidget *widget,
7489 const GdkColor *primary,
7490 const GdkColor *secondary)
7492 GtkRcStyle *rc_style;
7494 g_return_if_fail (GTK_IS_WIDGET (widget));
7496 rc_style = gtk_widget_get_modifier_style (widget);
7498 modify_color_property (widget, rc_style, "cursor-color", primary);
7499 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7501 gtk_widget_modify_style (widget, rc_style);
7505 * gtk_widget_modify_font:
7506 * @widget: a #GtkWidget
7507 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7508 * the effect of previous calls to gtk_widget_modify_font().
7510 * Sets the font to use for a widget. All other style values are left
7511 * untouched. See also gtk_widget_modify_style().
7514 gtk_widget_modify_font (GtkWidget *widget,
7515 PangoFontDescription *font_desc)
7517 GtkRcStyle *rc_style;
7519 g_return_if_fail (GTK_IS_WIDGET (widget));
7521 rc_style = gtk_widget_get_modifier_style (widget);
7523 if (rc_style->font_desc)
7524 pango_font_description_free (rc_style->font_desc);
7527 rc_style->font_desc = pango_font_description_copy (font_desc);
7529 rc_style->font_desc = NULL;
7531 gtk_widget_modify_style (widget, rc_style);
7535 gtk_widget_real_direction_changed (GtkWidget *widget,
7536 GtkTextDirection previous_direction)
7538 gtk_widget_queue_resize (widget);
7542 gtk_widget_real_style_set (GtkWidget *widget,
7543 GtkStyle *previous_style)
7545 GtkWidgetPrivate *priv = widget->priv;
7547 if (gtk_widget_get_realized (widget) &&
7548 gtk_widget_get_has_window (widget))
7549 gtk_style_set_background (priv->style, priv->window, priv->state);
7553 gtk_widget_set_style_internal (GtkWidget *widget,
7555 gboolean initial_emission)
7557 GtkWidgetPrivate *priv = widget->priv;
7559 g_object_ref (widget);
7560 g_object_freeze_notify (G_OBJECT (widget));
7562 if (priv->style != style)
7564 GtkStyle *previous_style;
7566 if (gtk_widget_get_realized (widget))
7568 gtk_widget_reset_shapes (widget);
7569 gtk_style_detach (priv->style);
7572 previous_style = priv->style;
7573 priv->style = style;
7574 g_object_ref (priv->style);
7576 if (gtk_widget_get_realized (widget))
7577 priv->style = gtk_style_attach (priv->style, priv->window);
7579 gtk_widget_update_pango_context (widget);
7580 g_signal_emit (widget,
7581 widget_signals[STYLE_SET],
7583 initial_emission ? NULL : previous_style);
7584 g_object_unref (previous_style);
7586 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7587 gtk_widget_queue_resize (widget);
7589 else if (initial_emission)
7591 gtk_widget_update_pango_context (widget);
7592 g_signal_emit (widget,
7593 widget_signals[STYLE_SET],
7597 g_object_notify (G_OBJECT (widget), "style");
7598 g_object_thaw_notify (G_OBJECT (widget));
7599 g_object_unref (widget);
7603 GtkWidget *previous_toplevel;
7604 GdkScreen *previous_screen;
7605 GdkScreen *new_screen;
7606 } HierarchyChangedInfo;
7609 do_screen_change (GtkWidget *widget,
7610 GdkScreen *old_screen,
7611 GdkScreen *new_screen)
7613 if (old_screen != new_screen)
7617 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7619 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7622 _gtk_tooltip_hide (widget);
7623 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7628 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7629 gpointer client_data)
7631 GtkWidgetPrivate *priv = widget->priv;
7632 HierarchyChangedInfo *info = client_data;
7633 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7634 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7636 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7638 g_object_ref (widget);
7641 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7643 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7645 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7646 do_screen_change (widget, info->previous_screen, info->new_screen);
7648 if (GTK_IS_CONTAINER (widget))
7649 gtk_container_forall (GTK_CONTAINER (widget),
7650 gtk_widget_propagate_hierarchy_changed_recurse,
7653 g_object_unref (widget);
7658 * _gtk_widget_propagate_hierarchy_changed:
7659 * @widget: a #GtkWidget
7660 * @previous_toplevel: Previous toplevel
7662 * Propagates changes in the anchored state to a widget and all
7663 * children, unsetting or setting the %ANCHORED flag, and
7664 * emitting #GtkWidget::hierarchy-changed.
7667 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7668 GtkWidget *previous_toplevel)
7670 GtkWidgetPrivate *priv = widget->priv;
7671 HierarchyChangedInfo info;
7673 info.previous_toplevel = previous_toplevel;
7674 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7676 if (gtk_widget_is_toplevel (widget) ||
7677 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7678 info.new_screen = gtk_widget_get_screen (widget);
7680 info.new_screen = NULL;
7682 if (info.previous_screen)
7683 g_object_ref (info.previous_screen);
7684 if (previous_toplevel)
7685 g_object_ref (previous_toplevel);
7687 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7689 if (previous_toplevel)
7690 g_object_unref (previous_toplevel);
7691 if (info.previous_screen)
7692 g_object_unref (info.previous_screen);
7696 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7697 gpointer client_data)
7699 HierarchyChangedInfo *info = client_data;
7701 g_object_ref (widget);
7703 do_screen_change (widget, info->previous_screen, info->new_screen);
7705 if (GTK_IS_CONTAINER (widget))
7706 gtk_container_forall (GTK_CONTAINER (widget),
7707 gtk_widget_propagate_screen_changed_recurse,
7710 g_object_unref (widget);
7714 * gtk_widget_is_composited:
7715 * @widget: a #GtkWidget
7717 * Whether @widget can rely on having its alpha channel
7718 * drawn correctly. On X11 this function returns whether a
7719 * compositing manager is running for @widget's screen.
7721 * Please note that the semantics of this call will change
7722 * in the future if used on a widget that has a composited
7723 * window in its hierarchy (as set by gdk_window_set_composited()).
7725 * Return value: %TRUE if the widget can rely on its alpha
7726 * channel being drawn correctly.
7731 gtk_widget_is_composited (GtkWidget *widget)
7735 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7737 screen = gtk_widget_get_screen (widget);
7739 return gdk_screen_is_composited (screen);
7743 propagate_composited_changed (GtkWidget *widget,
7746 if (GTK_IS_CONTAINER (widget))
7748 gtk_container_forall (GTK_CONTAINER (widget),
7749 propagate_composited_changed,
7753 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7757 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7759 propagate_composited_changed (widget, NULL);
7763 * _gtk_widget_propagate_screen_changed:
7764 * @widget: a #GtkWidget
7765 * @previous_screen: Previous screen
7767 * Propagates changes in the screen for a widget to all
7768 * children, emitting #GtkWidget::screen-changed.
7771 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7772 GdkScreen *previous_screen)
7774 HierarchyChangedInfo info;
7776 info.previous_screen = previous_screen;
7777 info.new_screen = gtk_widget_get_screen (widget);
7779 if (previous_screen)
7780 g_object_ref (previous_screen);
7782 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7784 if (previous_screen)
7785 g_object_unref (previous_screen);
7789 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7791 if (gtk_widget_has_rc_style (widget))
7792 gtk_widget_reset_rc_style (widget);
7794 if (GTK_IS_CONTAINER (widget))
7795 gtk_container_forall (GTK_CONTAINER (widget),
7796 reset_rc_styles_recurse,
7802 * gtk_widget_reset_rc_styles:
7803 * @widget: a #GtkWidget.
7805 * Reset the styles of @widget and all descendents, so when
7806 * they are looked up again, they get the correct values
7807 * for the currently loaded RC file settings.
7809 * This function is not useful for applications.
7812 gtk_widget_reset_rc_styles (GtkWidget *widget)
7814 g_return_if_fail (GTK_IS_WIDGET (widget));
7816 reset_rc_styles_recurse (widget, NULL);
7820 * gtk_widget_get_default_style:
7822 * Returns the default style used by all widgets initially.
7824 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7825 * by GTK+ and should not be modified or freed.
7828 gtk_widget_get_default_style (void)
7830 if (!gtk_default_style)
7832 gtk_default_style = gtk_style_new ();
7833 g_object_ref (gtk_default_style);
7836 return gtk_default_style;
7839 static PangoContext *
7840 gtk_widget_peek_pango_context (GtkWidget *widget)
7842 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7846 * gtk_widget_get_pango_context:
7847 * @widget: a #GtkWidget
7849 * Gets a #PangoContext with the appropriate font map, font description,
7850 * and base direction for this widget. Unlike the context returned
7851 * by gtk_widget_create_pango_context(), this context is owned by
7852 * the widget (it can be used until the screen for the widget changes
7853 * or the widget is removed from its toplevel), and will be updated to
7854 * match any changes to the widget's attributes.
7856 * If you create and keep a #PangoLayout using this context, you must
7857 * deal with changes to the context by calling pango_layout_context_changed()
7858 * on the layout in response to the #GtkWidget::style-set and
7859 * #GtkWidget::direction-changed signals for the widget.
7861 * Return value: (transfer none): the #PangoContext for the widget.
7864 gtk_widget_get_pango_context (GtkWidget *widget)
7866 PangoContext *context;
7868 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7870 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7873 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7874 g_object_set_qdata_full (G_OBJECT (widget),
7875 quark_pango_context,
7884 update_pango_context (GtkWidget *widget,
7885 PangoContext *context)
7887 GtkWidgetPrivate *priv = widget->priv;
7889 pango_context_set_font_description (context, priv->style->font_desc);
7890 pango_context_set_base_dir (context,
7891 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7892 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7896 gtk_widget_update_pango_context (GtkWidget *widget)
7898 PangoContext *context = gtk_widget_peek_pango_context (widget);
7904 update_pango_context (widget, context);
7906 screen = gtk_widget_get_screen_unchecked (widget);
7909 pango_cairo_context_set_resolution (context,
7910 gdk_screen_get_resolution (screen));
7911 pango_cairo_context_set_font_options (context,
7912 gdk_screen_get_font_options (screen));
7918 * gtk_widget_create_pango_context:
7919 * @widget: a #GtkWidget
7921 * Creates a new #PangoContext with the appropriate font map,
7922 * font description, and base direction for drawing text for
7923 * this widget. See also gtk_widget_get_pango_context().
7925 * Return value: (transfer full): the new #PangoContext
7928 gtk_widget_create_pango_context (GtkWidget *widget)
7931 PangoContext *context;
7933 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7935 screen = gtk_widget_get_screen_unchecked (widget);
7938 GTK_NOTE (MULTIHEAD,
7939 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7941 screen = gdk_screen_get_default ();
7944 context = gdk_pango_context_get_for_screen (screen);
7946 update_pango_context (widget, context);
7947 pango_context_set_language (context, gtk_get_default_language ());
7953 * gtk_widget_create_pango_layout:
7954 * @widget: a #GtkWidget
7955 * @text: text to set on the layout (can be %NULL)
7957 * Creates a new #PangoLayout with the appropriate font map,
7958 * font description, and base direction for drawing text for
7961 * If you keep a #PangoLayout created in this way around, in order to
7962 * notify the layout of changes to the base direction or font of this
7963 * widget, you must call pango_layout_context_changed() in response to
7964 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7967 * Return value: (transfer full): the new #PangoLayout
7970 gtk_widget_create_pango_layout (GtkWidget *widget,
7973 PangoLayout *layout;
7974 PangoContext *context;
7976 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7978 context = gtk_widget_get_pango_context (widget);
7979 layout = pango_layout_new (context);
7982 pango_layout_set_text (layout, text, -1);
7988 * gtk_widget_render_icon:
7989 * @widget: a #GtkWidget
7990 * @stock_id: a stock ID
7991 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7992 * render at the size of the source and don't scale (if there are
7993 * multiple source sizes, GTK+ picks one of the available sizes).
7994 * @detail: (allow-none): render detail to pass to theme engine
7996 * A convenience function that uses the theme engine and RC file
7997 * settings for @widget to look up @stock_id and render it to
7998 * a pixbuf. @stock_id should be a stock icon ID such as
7999 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8000 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8001 * identifies the widget or code doing the rendering, so that
8002 * theme engines can special-case rendering for that widget or code.
8004 * The pixels in the returned #GdkPixbuf are shared with the rest of
8005 * the application and should not be modified. The pixbuf should be freed
8006 * after use with g_object_unref().
8008 * Return value: (transfer full): a new pixbuf, or %NULL if the
8009 * stock ID wasn't known
8012 gtk_widget_render_icon (GtkWidget *widget,
8013 const gchar *stock_id,
8015 const gchar *detail)
8017 GtkWidgetPrivate *priv;
8018 GtkIconSet *icon_set;
8021 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8022 g_return_val_if_fail (stock_id != NULL, NULL);
8023 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8025 priv = widget->priv;
8027 gtk_widget_ensure_style (widget);
8029 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8031 if (icon_set == NULL)
8034 retval = gtk_icon_set_render_icon (icon_set,
8036 gtk_widget_get_direction (widget),
8037 gtk_widget_get_state (widget),
8046 * gtk_widget_set_parent_window:
8047 * @widget: a #GtkWidget.
8048 * @parent_window: the new parent window.
8050 * Sets a non default parent window for @widget.
8053 gtk_widget_set_parent_window (GtkWidget *widget,
8054 GdkWindow *parent_window)
8056 GdkWindow *old_parent_window;
8058 g_return_if_fail (GTK_IS_WIDGET (widget));
8060 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8061 quark_parent_window);
8063 if (parent_window != old_parent_window)
8065 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8067 if (old_parent_window)
8068 g_object_unref (old_parent_window);
8070 g_object_ref (parent_window);
8075 * gtk_widget_get_parent_window:
8076 * @widget: a #GtkWidget.
8078 * Gets @widget's parent window.
8080 * Returns: (transfer none): the parent window of @widget.
8083 gtk_widget_get_parent_window (GtkWidget *widget)
8085 GtkWidgetPrivate *priv;
8086 GdkWindow *parent_window;
8088 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8090 priv = widget->priv;
8092 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8094 return (parent_window != NULL) ? parent_window :
8095 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8100 * gtk_widget_set_child_visible:
8101 * @widget: a #GtkWidget
8102 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8104 * Sets whether @widget should be mapped along with its when its parent
8105 * is mapped and @widget has been shown with gtk_widget_show().
8107 * The child visibility can be set for widget before it is added to
8108 * a container with gtk_widget_set_parent(), to avoid mapping
8109 * children unnecessary before immediately unmapping them. However
8110 * it will be reset to its default state of %TRUE when the widget
8111 * is removed from a container.
8113 * Note that changing the child visibility of a widget does not
8114 * queue a resize on the widget. Most of the time, the size of
8115 * a widget is computed from all visible children, whether or
8116 * not they are mapped. If this is not the case, the container
8117 * can queue a resize itself.
8119 * This function is only useful for container implementations and
8120 * never should be called by an application.
8123 gtk_widget_set_child_visible (GtkWidget *widget,
8124 gboolean is_visible)
8126 GtkWidgetPrivate *priv;
8128 g_return_if_fail (GTK_IS_WIDGET (widget));
8129 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8131 priv = widget->priv;
8133 g_object_ref (widget);
8136 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8139 GtkWidget *toplevel;
8141 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8143 toplevel = gtk_widget_get_toplevel (widget);
8144 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8145 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8148 if (priv->parent && gtk_widget_get_realized (priv->parent))
8150 if (gtk_widget_get_mapped (priv->parent) &&
8151 GTK_WIDGET_CHILD_VISIBLE (widget) &&
8152 gtk_widget_get_visible (widget))
8153 gtk_widget_map (widget);
8155 gtk_widget_unmap (widget);
8158 g_object_unref (widget);
8162 * gtk_widget_get_child_visible:
8163 * @widget: a #GtkWidget
8165 * Gets the value set with gtk_widget_set_child_visible().
8166 * If you feel a need to use this function, your code probably
8167 * needs reorganization.
8169 * This function is only useful for container implementations and
8170 * never should be called by an application.
8172 * Return value: %TRUE if the widget is mapped with the parent.
8175 gtk_widget_get_child_visible (GtkWidget *widget)
8177 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8179 return GTK_WIDGET_CHILD_VISIBLE (widget);
8183 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8185 GtkWidget *toplevel;
8187 toplevel = gtk_widget_get_toplevel (widget);
8189 if (gtk_widget_is_toplevel (toplevel))
8191 if (GTK_IS_WINDOW (toplevel))
8192 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8193 else if (GTK_IS_INVISIBLE (toplevel))
8194 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8201 * gtk_widget_get_screen:
8202 * @widget: a #GtkWidget
8204 * Get the #GdkScreen from the toplevel window associated with
8205 * this widget. This function can only be called after the widget
8206 * has been added to a widget hierarchy with a #GtkWindow
8209 * In general, you should only create screen specific
8210 * resources when a widget has been realized, and you should
8211 * free those resources when the widget is unrealized.
8213 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8218 gtk_widget_get_screen (GtkWidget *widget)
8222 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8224 screen = gtk_widget_get_screen_unchecked (widget);
8231 g_warning (G_STRLOC ": Can't get associated screen"
8232 " for a widget unless it is inside a toplevel GtkWindow\n"
8233 " widget type is %s associated top level type is %s",
8234 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8235 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8237 return gdk_screen_get_default ();
8242 * gtk_widget_has_screen:
8243 * @widget: a #GtkWidget
8245 * Checks whether there is a #GdkScreen is associated with
8246 * this widget. All toplevel widgets have an associated
8247 * screen, and all widgets added into a hierarchy with a toplevel
8248 * window at the top.
8250 * Return value: %TRUE if there is a #GdkScreen associcated
8256 gtk_widget_has_screen (GtkWidget *widget)
8258 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8260 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8264 * gtk_widget_get_display:
8265 * @widget: a #GtkWidget
8267 * Get the #GdkDisplay for the toplevel window associated with
8268 * this widget. This function can only be called after the widget
8269 * has been added to a widget hierarchy with a #GtkWindow at the top.
8271 * In general, you should only create display specific
8272 * resources when a widget has been realized, and you should
8273 * free those resources when the widget is unrealized.
8275 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8280 gtk_widget_get_display (GtkWidget *widget)
8282 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8284 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8288 * gtk_widget_get_root_window:
8289 * @widget: a #GtkWidget
8291 * Get the root window where this widget is located. This function can
8292 * only be called after the widget has been added to a widget
8293 * hierarchy with #GtkWindow at the top.
8295 * The root window is useful for such purposes as creating a popup
8296 * #GdkWindow associated with the window. In general, you should only
8297 * create display specific resources when a widget has been realized,
8298 * and you should free those resources when the widget is unrealized.
8300 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8305 gtk_widget_get_root_window (GtkWidget *widget)
8307 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8309 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8313 * gtk_widget_child_focus:
8314 * @widget: a #GtkWidget
8315 * @direction: direction of focus movement
8317 * This function is used by custom widget implementations; if you're
8318 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8319 * to a particular widget, and gtk_container_set_focus_chain() to
8320 * change the focus tab order. So you may want to investigate those
8321 * functions instead.
8323 * gtk_widget_child_focus() is called by containers as the user moves
8324 * around the window using keyboard shortcuts. @direction indicates
8325 * what kind of motion is taking place (up, down, left, right, tab
8326 * forward, tab backward). gtk_widget_child_focus() emits the
8327 * #GtkWidget::focus signal; widgets override the default handler
8328 * for this signal in order to implement appropriate focus behavior.
8330 * The default ::focus handler for a widget should return %TRUE if
8331 * moving in @direction left the focus on a focusable location inside
8332 * that widget, and %FALSE if moving in @direction moved the focus
8333 * outside the widget. If returning %TRUE, widgets normally
8334 * call gtk_widget_grab_focus() to place the focus accordingly;
8335 * if returning %FALSE, they don't modify the current focus location.
8337 * Return value: %TRUE if focus ended up inside @widget
8340 gtk_widget_child_focus (GtkWidget *widget,
8341 GtkDirectionType direction)
8343 gboolean return_val;
8345 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8347 if (!gtk_widget_get_visible (widget) ||
8348 !gtk_widget_is_sensitive (widget))
8351 /* child widgets must set CAN_FOCUS, containers
8352 * don't have to though.
8354 if (!GTK_IS_CONTAINER (widget) &&
8355 !gtk_widget_get_can_focus (widget))
8358 g_signal_emit (widget,
8359 widget_signals[FOCUS],
8361 direction, &return_val);
8367 * gtk_widget_keynav_failed:
8368 * @widget: a #GtkWidget
8369 * @direction: direction of focus movement
8371 * This function should be called whenever keyboard navigation within
8372 * a single widget hits a boundary. The function emits the
8373 * #GtkWidget::keynav-failed signal on the widget and its return
8374 * value should be interpreted in a way similar to the return value of
8375 * gtk_widget_child_focus():
8377 * When %TRUE is returned, stay in the widget, the failed keyboard
8378 * navigation is Ok and/or there is nowhere we can/should move the
8381 * When %FALSE is returned, the caller should continue with keyboard
8382 * navigation outside the widget, e.g. by calling
8383 * gtk_widget_child_focus() on the widget's toplevel.
8385 * The default ::keynav-failed handler returns %TRUE for
8386 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8387 * values of #GtkDirectionType, it looks at the
8388 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8389 * if the setting is %TRUE. This way the entire user interface
8390 * becomes cursor-navigatable on input devices such as mobile phones
8391 * which only have cursor keys but no tab key.
8393 * Whenever the default handler returns %TRUE, it also calls
8394 * gtk_widget_error_bell() to notify the user of the failed keyboard
8397 * A use case for providing an own implementation of ::keynav-failed
8398 * (either by connecting to it or by overriding it) would be a row of
8399 * #GtkEntry widgets where the user should be able to navigate the
8400 * entire row with the cursor keys, as e.g. known from user interfaces
8401 * that require entering license keys.
8403 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8404 * if the emitting widget should try to handle the keyboard
8405 * navigation attempt in its parent container(s).
8410 gtk_widget_keynav_failed (GtkWidget *widget,
8411 GtkDirectionType direction)
8413 gboolean return_val;
8415 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8417 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8418 direction, &return_val);
8424 * gtk_widget_error_bell:
8425 * @widget: a #GtkWidget
8427 * Notifies the user about an input-related error on this widget.
8428 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8429 * gdk_window_beep(), otherwise it does nothing.
8431 * Note that the effect of gdk_window_beep() can be configured in many
8432 * ways, depending on the windowing backend and the desktop environment
8433 * or window manager that is used.
8438 gtk_widget_error_bell (GtkWidget *widget)
8440 GtkWidgetPrivate *priv;
8441 GtkSettings* settings;
8444 g_return_if_fail (GTK_IS_WIDGET (widget));
8446 priv = widget->priv;
8448 settings = gtk_widget_get_settings (widget);
8452 g_object_get (settings,
8453 "gtk-error-bell", &beep,
8456 if (beep && priv->window)
8457 gdk_window_beep (priv->window);
8461 gtk_widget_set_usize_internal (GtkWidget *widget,
8465 GtkWidgetAuxInfo *aux_info;
8466 gboolean changed = FALSE;
8468 g_object_freeze_notify (G_OBJECT (widget));
8470 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8472 if (width > -2 && aux_info->width != width)
8474 g_object_notify (G_OBJECT (widget), "width-request");
8475 aux_info->width = width;
8478 if (height > -2 && aux_info->height != height)
8480 g_object_notify (G_OBJECT (widget), "height-request");
8481 aux_info->height = height;
8485 if (gtk_widget_get_visible (widget) && changed)
8486 gtk_widget_queue_resize (widget);
8488 g_object_thaw_notify (G_OBJECT (widget));
8492 * gtk_widget_set_size_request:
8493 * @widget: a #GtkWidget
8494 * @width: width @widget should request, or -1 to unset
8495 * @height: height @widget should request, or -1 to unset
8497 * Sets the minimum size of a widget; that is, the widget's size
8498 * request will be @width by @height. You can use this function to
8499 * force a widget to be either larger or smaller than it normally
8502 * In most cases, gtk_window_set_default_size() is a better choice for
8503 * toplevel windows than this function; setting the default size will
8504 * still allow users to shrink the window. Setting the size request
8505 * will force them to leave the window at least as large as the size
8506 * request. When dealing with window sizes,
8507 * gtk_window_set_geometry_hints() can be a useful function as well.
8509 * Note the inherent danger of setting any fixed size - themes,
8510 * translations into other languages, different fonts, and user action
8511 * can all change the appropriate size for a given widget. So, it's
8512 * basically impossible to hardcode a size that will always be
8515 * The size request of a widget is the smallest size a widget can
8516 * accept while still functioning well and drawing itself correctly.
8517 * However in some strange cases a widget may be allocated less than
8518 * its requested size, and in many cases a widget may be allocated more
8519 * space than it requested.
8521 * If the size request in a given direction is -1 (unset), then
8522 * the "natural" size request of the widget will be used instead.
8524 * Widgets can't actually be allocated a size less than 1 by 1, but
8525 * you can pass 0,0 to this function to mean "as small as possible."
8527 * The size request set here does not include any margin from the
8528 * #GtkWidget properties margin-left, margin-right, margin-top, and
8529 * margin-bottom, but it does include pretty much all other padding
8530 * or border properties set by any subclass of #GtkWidget.
8533 gtk_widget_set_size_request (GtkWidget *widget,
8537 g_return_if_fail (GTK_IS_WIDGET (widget));
8538 g_return_if_fail (width >= -1);
8539 g_return_if_fail (height >= -1);
8546 gtk_widget_set_usize_internal (widget, width, height);
8551 * gtk_widget_get_size_request:
8552 * @widget: a #GtkWidget
8553 * @width: (out) (allow-none): return location for width, or %NULL
8554 * @height: (out) (allow-none): return location for height, or %NULL
8556 * Gets the size request that was explicitly set for the widget using
8557 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8558 * @height indicates that that dimension has not been set explicitly
8559 * and the natural requisition of the widget will be used intead. See
8560 * gtk_widget_set_size_request(). To get the size a widget will
8561 * actually request, call gtk_size_request_get_preferred_size() instead of
8565 gtk_widget_get_size_request (GtkWidget *widget,
8569 const GtkWidgetAuxInfo *aux_info;
8571 g_return_if_fail (GTK_IS_WIDGET (widget));
8573 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8576 *width = aux_info->width;
8579 *height = aux_info->height;
8583 * gtk_widget_set_events:
8584 * @widget: a #GtkWidget
8585 * @events: event mask
8587 * Sets the event mask (see #GdkEventMask) for a widget. The event
8588 * mask determines which events a widget will receive. Keep in mind
8589 * that different widgets have different default event masks, and by
8590 * changing the event mask you may disrupt a widget's functionality,
8591 * so be careful. This function must be called while a widget is
8592 * unrealized. Consider gtk_widget_add_events() for widgets that are
8593 * already realized, or if you want to preserve the existing event
8594 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8595 * to get events on those widgets, place them inside a #GtkEventBox
8596 * and receive events on the event box.
8599 gtk_widget_set_events (GtkWidget *widget,
8602 g_return_if_fail (GTK_IS_WIDGET (widget));
8603 g_return_if_fail (!gtk_widget_get_realized (widget));
8605 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8606 GINT_TO_POINTER (events));
8607 g_object_notify (G_OBJECT (widget), "events");
8611 * gtk_widget_set_device_events:
8612 * @widget: a #GtkWidget
8613 * @device: a #GdkDevice
8614 * @events: event mask
8616 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8617 * mask determines which events a widget will receive from @device. Keep
8618 * in mind that different widgets have different default event masks, and by
8619 * changing the event mask you may disrupt a widget's functionality,
8620 * so be careful. This function must be called while a widget is
8621 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8622 * already realized, or if you want to preserve the existing event
8623 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8624 * to get events on those widgets, place them inside a #GtkEventBox
8625 * and receive events on the event box.
8630 gtk_widget_set_device_events (GtkWidget *widget,
8632 GdkEventMask events)
8634 GHashTable *device_events;
8636 g_return_if_fail (GTK_IS_WIDGET (widget));
8637 g_return_if_fail (GDK_IS_DEVICE (device));
8638 g_return_if_fail (!gtk_widget_get_realized (widget));
8640 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8642 if (G_UNLIKELY (!device_events))
8644 device_events = g_hash_table_new (NULL, NULL);
8645 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8646 (GDestroyNotify) g_hash_table_unref);
8649 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8653 gtk_widget_add_events_internal_list (GtkWidget *widget,
8660 for (l = window_list; l != NULL; l = l->next)
8662 GdkWindow *window = l->data;
8665 gdk_window_get_user_data (window, &user_data);
8666 if (user_data == widget)
8671 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8673 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8675 children = gdk_window_get_children (window);
8676 gtk_widget_add_events_internal_list (widget, device, events, children);
8677 g_list_free (children);
8683 gtk_widget_add_events_internal (GtkWidget *widget,
8687 GtkWidgetPrivate *priv = widget->priv;
8690 if (!gtk_widget_get_has_window (widget))
8691 window_list = gdk_window_get_children (priv->window);
8693 window_list = g_list_prepend (NULL, priv->window);
8695 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8697 g_list_free (window_list);
8701 * gtk_widget_add_events:
8702 * @widget: a #GtkWidget
8703 * @events: an event mask, see #GdkEventMask
8705 * Adds the events in the bitfield @events to the event mask for
8706 * @widget. See gtk_widget_set_events() for details.
8709 gtk_widget_add_events (GtkWidget *widget,
8714 g_return_if_fail (GTK_IS_WIDGET (widget));
8716 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8717 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8718 GINT_TO_POINTER (old_events | events));
8720 if (gtk_widget_get_realized (widget))
8721 gtk_widget_add_events_internal (widget, NULL, events);
8723 g_object_notify (G_OBJECT (widget), "events");
8727 * gtk_widget_add_device_events:
8728 * @widget: a #GtkWidget
8729 * @device: a #GdkDevice
8730 * @events: an event mask, see #GdkEventMask
8732 * Adds the device events in the bitfield @events to the event mask for
8733 * @widget. See gtk_widget_set_device_events() for details.
8738 gtk_widget_add_device_events (GtkWidget *widget,
8740 GdkEventMask events)
8742 GdkEventMask old_events;
8743 GHashTable *device_events;
8745 g_return_if_fail (GTK_IS_WIDGET (widget));
8746 g_return_if_fail (GDK_IS_DEVICE (device));
8748 old_events = gtk_widget_get_device_events (widget, device);
8750 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8752 if (G_UNLIKELY (!device_events))
8754 device_events = g_hash_table_new (NULL, NULL);
8755 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8756 (GDestroyNotify) g_hash_table_unref);
8759 g_hash_table_insert (device_events, device,
8760 GUINT_TO_POINTER (old_events | events));
8762 if (gtk_widget_get_realized (widget))
8763 gtk_widget_add_events_internal (widget, device, events);
8765 g_object_notify (G_OBJECT (widget), "events");
8769 * gtk_widget_set_extension_events:
8770 * @widget: a #GtkWidget
8771 * @mode: bitfield of extension events to receive
8773 * Sets the extension events mask to @mode. See #GdkExtensionMode
8774 * and gdk_input_set_extension_events().
8777 gtk_widget_set_extension_events (GtkWidget *widget,
8778 GdkExtensionMode mode)
8780 g_return_if_fail (GTK_IS_WIDGET (widget));
8782 if (gtk_widget_get_realized (widget))
8783 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8785 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8786 GINT_TO_POINTER (mode));
8787 g_object_notify (G_OBJECT (widget), "extension-events");
8791 * gtk_widget_get_toplevel:
8792 * @widget: a #GtkWidget
8794 * This function returns the topmost widget in the container hierarchy
8795 * @widget is a part of. If @widget has no parent widgets, it will be
8796 * returned as the topmost widget. No reference will be added to the
8797 * returned widget; it should not be unreferenced.
8799 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8800 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8802 * %NULL if @widget wasn't inside a toplevel window, and if the
8803 * window was inside a #GtkWindow-derived widget which was in turn
8804 * inside the toplevel #GtkWindow. While the second case may
8805 * seem unlikely, it actually happens when a #GtkPlug is embedded
8806 * inside a #GtkSocket within the same application.
8808 * To reliably find the toplevel #GtkWindow, use
8809 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8810 * is set on the result.
8812 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8813 * if (gtk_widget_is_toplevel (toplevel))
8815 * /* Perform action on toplevel. */
8819 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8820 * if there's no ancestor.
8823 gtk_widget_get_toplevel (GtkWidget *widget)
8825 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8827 while (widget->priv->parent)
8828 widget = widget->priv->parent;
8834 * gtk_widget_get_ancestor:
8835 * @widget: a #GtkWidget
8836 * @widget_type: ancestor type
8838 * Gets the first ancestor of @widget with type @widget_type. For example,
8839 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8840 * the first #GtkBox that's an ancestor of @widget. No reference will be
8841 * added to the returned widget; it should not be unreferenced. See note
8842 * about checking for a toplevel #GtkWindow in the docs for
8843 * gtk_widget_get_toplevel().
8845 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8846 * considers @widget to be an ancestor of itself.
8848 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8851 gtk_widget_get_ancestor (GtkWidget *widget,
8854 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8856 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8857 widget = widget->priv->parent;
8859 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8866 * gtk_widget_get_visual:
8867 * @widget: a #GtkWidget
8869 * Gets the visual that will be used to render @widget.
8871 * Return value: (transfer none): the visual for @widget
8874 gtk_widget_get_visual (GtkWidget *widget)
8878 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8880 for (w = widget; w != NULL; w = w->priv->parent)
8882 if (gtk_widget_get_has_window (w) &&
8884 return gdk_window_get_visual (w->priv->window);
8886 if (GTK_IS_WINDOW (w))
8887 return _gtk_window_get_visual (GTK_WINDOW (w));
8890 return gdk_screen_get_system_visual (gdk_screen_get_default ());
8894 * gtk_widget_get_settings:
8895 * @widget: a #GtkWidget
8897 * Gets the settings object holding the settings (global property
8898 * settings, RC file information, etc) used for this widget.
8900 * Note that this function can only be called when the #GtkWidget
8901 * is attached to a toplevel, since the settings object is specific
8902 * to a particular #GdkScreen.
8904 * Return value: (transfer none): the relevant #GtkSettings object
8907 gtk_widget_get_settings (GtkWidget *widget)
8909 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8911 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8915 * gtk_widget_get_events:
8916 * @widget: a #GtkWidget
8918 * Returns the event mask for the widget (a bitfield containing flags
8919 * from the #GdkEventMask enumeration). These are the events that the widget
8922 * Return value: event mask for @widget
8925 gtk_widget_get_events (GtkWidget *widget)
8927 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8929 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8933 * gtk_widget_get_device_events:
8934 * @widget: a #GtkWidget
8935 * @device: a #GdkDevice
8937 * Returns the events mask for the widget corresponding to an specific device. These
8938 * are the events that the widget will receive when @device operates on it.
8940 * Returns: device event mask for @widget
8945 gtk_widget_get_device_events (GtkWidget *widget,
8948 GHashTable *device_events;
8950 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8951 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8953 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8958 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8962 * gtk_widget_get_extension_events:
8963 * @widget: a #GtkWidget
8965 * Retrieves the extension events the widget will receive; see
8966 * gdk_input_set_extension_events().
8968 * Return value: extension events for @widget
8971 gtk_widget_get_extension_events (GtkWidget *widget)
8973 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8975 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8979 * gtk_widget_get_pointer:
8980 * @widget: a #GtkWidget
8981 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8982 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8984 * Obtains the location of the mouse pointer in widget coordinates.
8985 * Widget coordinates are a bit odd; for historical reasons, they are
8986 * defined as @widget->window coordinates for widgets that are not
8987 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8988 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8991 gtk_widget_get_pointer (GtkWidget *widget,
8995 GtkWidgetPrivate *priv;
8997 g_return_if_fail (GTK_IS_WIDGET (widget));
8999 priv = widget->priv;
9006 if (gtk_widget_get_realized (widget))
9008 gdk_window_get_pointer (priv->window, x, y, NULL);
9010 if (!gtk_widget_get_has_window (widget))
9013 *x -= priv->allocation.x;
9015 *y -= priv->allocation.y;
9021 * gtk_widget_is_ancestor:
9022 * @widget: a #GtkWidget
9023 * @ancestor: another #GtkWidget
9025 * Determines whether @widget is somewhere inside @ancestor, possibly with
9026 * intermediate containers.
9028 * Return value: %TRUE if @ancestor contains @widget as a child,
9029 * grandchild, great grandchild, etc.
9032 gtk_widget_is_ancestor (GtkWidget *widget,
9033 GtkWidget *ancestor)
9035 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9036 g_return_val_if_fail (ancestor != NULL, FALSE);
9040 if (widget->priv->parent == ancestor)
9042 widget = widget->priv->parent;
9048 static GQuark quark_composite_name = 0;
9051 * gtk_widget_set_composite_name:
9052 * @widget: a #GtkWidget.
9053 * @name: the name to set
9055 * Sets a widgets composite name. The widget must be
9056 * a composite child of its parent; see gtk_widget_push_composite_child().
9059 gtk_widget_set_composite_name (GtkWidget *widget,
9062 g_return_if_fail (GTK_IS_WIDGET (widget));
9063 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
9064 g_return_if_fail (name != NULL);
9066 if (!quark_composite_name)
9067 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9069 g_object_set_qdata_full (G_OBJECT (widget),
9070 quark_composite_name,
9076 * gtk_widget_get_composite_name:
9077 * @widget: a #GtkWidget
9079 * Obtains the composite name of a widget.
9081 * Returns: the composite name of @widget, or %NULL if @widget is not
9082 * a composite child. The string should be freed when it is no
9086 gtk_widget_get_composite_name (GtkWidget *widget)
9088 GtkWidgetPrivate *priv;
9090 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9092 priv = widget->priv;
9094 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
9095 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9102 * gtk_widget_push_composite_child:
9104 * Makes all newly-created widgets as composite children until
9105 * the corresponding gtk_widget_pop_composite_child() call.
9107 * A composite child is a child that's an implementation detail of the
9108 * container it's inside and should not be visible to people using the
9109 * container. Composite children aren't treated differently by GTK (but
9110 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9111 * builders might want to treat them in a different way.
9113 * Here is a simple example:
9115 * gtk_widget_push_composite_child ();
9116 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9117 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9118 * gtk_widget_pop_composite_child ();
9119 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9120 * GTK_WIDGET (scrolled_window));
9121 * g_object_ref (scrolled_window->hscrollbar);
9125 gtk_widget_push_composite_child (void)
9127 composite_child_stack++;
9131 * gtk_widget_pop_composite_child:
9133 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9136 gtk_widget_pop_composite_child (void)
9138 if (composite_child_stack)
9139 composite_child_stack--;
9143 gtk_widget_emit_direction_changed (GtkWidget *widget,
9144 GtkTextDirection old_dir)
9146 gtk_widget_update_pango_context (widget);
9148 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9152 * gtk_widget_set_direction:
9153 * @widget: a #GtkWidget
9154 * @dir: the new direction
9156 * Sets the reading direction on a particular widget. This direction
9157 * controls the primary direction for widgets containing text,
9158 * and also the direction in which the children of a container are
9159 * packed. The ability to set the direction is present in order
9160 * so that correct localization into languages with right-to-left
9161 * reading directions can be done. Generally, applications will
9162 * let the default reading direction present, except for containers
9163 * where the containers are arranged in an order that is explicitely
9164 * visual rather than logical (such as buttons for text justification).
9166 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9167 * set by gtk_widget_set_default_direction() will be used.
9170 gtk_widget_set_direction (GtkWidget *widget,
9171 GtkTextDirection dir)
9173 GtkTextDirection old_dir;
9175 g_return_if_fail (GTK_IS_WIDGET (widget));
9176 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9178 old_dir = gtk_widget_get_direction (widget);
9180 if (dir == GTK_TEXT_DIR_NONE)
9181 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9184 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9185 if (dir == GTK_TEXT_DIR_LTR)
9186 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9188 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9191 if (old_dir != gtk_widget_get_direction (widget))
9192 gtk_widget_emit_direction_changed (widget, old_dir);
9196 * gtk_widget_get_direction:
9197 * @widget: a #GtkWidget
9199 * Gets the reading direction for a particular widget. See
9200 * gtk_widget_set_direction().
9202 * Return value: the reading direction for the widget.
9205 gtk_widget_get_direction (GtkWidget *widget)
9207 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9209 if (GTK_WIDGET_DIRECTION_SET (widget))
9210 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9212 return gtk_default_direction;
9216 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9218 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9220 g_object_ref (widget);
9222 if (!GTK_WIDGET_DIRECTION_SET (widget))
9223 gtk_widget_emit_direction_changed (widget, old_dir);
9225 if (GTK_IS_CONTAINER (widget))
9226 gtk_container_forall (GTK_CONTAINER (widget),
9227 gtk_widget_set_default_direction_recurse,
9230 g_object_unref (widget);
9234 * gtk_widget_set_default_direction:
9235 * @dir: the new default direction. This cannot be
9236 * %GTK_TEXT_DIR_NONE.
9238 * Sets the default reading direction for widgets where the
9239 * direction has not been explicitly set by gtk_widget_set_direction().
9242 gtk_widget_set_default_direction (GtkTextDirection dir)
9244 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9246 if (dir != gtk_default_direction)
9248 GList *toplevels, *tmp_list;
9249 GtkTextDirection old_dir = gtk_default_direction;
9251 gtk_default_direction = dir;
9253 tmp_list = toplevels = gtk_window_list_toplevels ();
9254 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9258 gtk_widget_set_default_direction_recurse (tmp_list->data,
9259 GUINT_TO_POINTER (old_dir));
9260 g_object_unref (tmp_list->data);
9261 tmp_list = tmp_list->next;
9264 g_list_free (toplevels);
9269 * gtk_widget_get_default_direction:
9271 * Obtains the current default reading direction. See
9272 * gtk_widget_set_default_direction().
9274 * Return value: the current default direction.
9277 gtk_widget_get_default_direction (void)
9279 return gtk_default_direction;
9283 gtk_widget_dispose (GObject *object)
9285 GtkWidget *widget = GTK_WIDGET (object);
9286 GtkWidgetPrivate *priv = widget->priv;
9289 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9290 else if (gtk_widget_get_visible (widget))
9291 gtk_widget_hide (widget);
9293 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9294 if (gtk_widget_get_realized (widget))
9295 gtk_widget_unrealize (widget);
9297 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9301 gtk_widget_real_destroy (GtkObject *object)
9303 /* gtk_object_destroy() will already hold a refcount on object */
9304 GtkWidget *widget = GTK_WIDGET (object);
9305 GtkWidgetPrivate *priv = widget->priv;
9307 /* wipe accelerator closures (keep order) */
9308 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9309 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9311 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9312 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9314 gtk_grab_remove (widget);
9316 g_object_unref (priv->style);
9317 priv->style = gtk_widget_get_default_style ();
9318 g_object_ref (priv->style);
9320 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9324 gtk_widget_finalize (GObject *object)
9326 GtkWidget *widget = GTK_WIDGET (object);
9327 GtkWidgetPrivate *priv = widget->priv;
9328 GtkWidgetAuxInfo *aux_info;
9329 GtkAccessible *accessible;
9331 gtk_grab_remove (widget);
9333 g_object_unref (priv->style);
9336 g_free (priv->name);
9338 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9340 gtk_widget_aux_info_destroy (aux_info);
9342 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9344 g_object_unref (accessible);
9346 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9349 /*****************************************
9350 * gtk_widget_real_map:
9355 *****************************************/
9358 gtk_widget_real_map (GtkWidget *widget)
9360 GtkWidgetPrivate *priv = widget->priv;
9362 g_assert (gtk_widget_get_realized (widget));
9364 if (!gtk_widget_get_mapped (widget))
9366 gtk_widget_set_mapped (widget, TRUE);
9368 if (gtk_widget_get_has_window (widget))
9369 gdk_window_show (priv->window);
9373 /*****************************************
9374 * gtk_widget_real_unmap:
9379 *****************************************/
9382 gtk_widget_real_unmap (GtkWidget *widget)
9384 GtkWidgetPrivate *priv = widget->priv;
9386 if (gtk_widget_get_mapped (widget))
9388 gtk_widget_set_mapped (widget, FALSE);
9390 if (gtk_widget_get_has_window (widget))
9391 gdk_window_hide (priv->window);
9395 /*****************************************
9396 * gtk_widget_real_realize:
9401 *****************************************/
9404 gtk_widget_real_realize (GtkWidget *widget)
9406 GtkWidgetPrivate *priv = widget->priv;
9408 g_assert (!gtk_widget_get_has_window (widget));
9410 gtk_widget_set_realized (widget, TRUE);
9413 priv->window = gtk_widget_get_parent_window (widget);
9414 g_object_ref (priv->window);
9416 priv->style = gtk_style_attach (priv->style, priv->window);
9419 /*****************************************
9420 * gtk_widget_real_unrealize:
9425 *****************************************/
9428 gtk_widget_real_unrealize (GtkWidget *widget)
9430 GtkWidgetPrivate *priv = widget->priv;
9432 if (gtk_widget_get_mapped (widget))
9433 gtk_widget_real_unmap (widget);
9435 gtk_widget_set_mapped (widget, FALSE);
9437 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9440 /* We must do unrealize child widget BEFORE container widget.
9441 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9442 * So, unrealizing container widget bofore its children causes the problem
9443 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9446 if (GTK_IS_CONTAINER (widget))
9447 gtk_container_forall (GTK_CONTAINER (widget),
9448 (GtkCallback) gtk_widget_unrealize,
9451 gtk_style_detach (priv->style);
9452 if (gtk_widget_get_has_window (widget))
9454 gdk_window_set_user_data (priv->window, NULL);
9455 gdk_window_destroy (priv->window);
9456 priv->window = NULL;
9460 g_object_unref (priv->window);
9461 priv->window = NULL;
9464 gtk_selection_remove_all (widget);
9466 gtk_widget_set_realized (widget, FALSE);
9470 gtk_widget_real_size_request (GtkWidget *widget,
9471 GtkRequisition *requisition)
9473 requisition->width = 0;
9474 requisition->height = 0;
9478 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9479 GtkOrientation orientation,
9484 const GtkWidgetAuxInfo *aux_info;
9486 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9488 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9489 aux_info->width > 0)
9491 *minimum_size = MAX (*minimum_size, aux_info->width);
9493 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9494 aux_info->height > 0)
9496 *minimum_size = MAX (*minimum_size, aux_info->height);
9499 /* Fix it if set_size_request made natural size smaller than min size.
9500 * This would also silently fix broken widgets, but we warn about them
9501 * in gtksizerequest.c when calling their size request vfuncs.
9503 *natural_size = MAX (*natural_size, *minimum_size);
9505 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9507 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9508 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9512 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9513 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9518 * _gtk_widget_peek_request_cache:
9520 * Returns the address of the widget's request cache (strictly for
9521 * internal use in gtksizerequest.c)
9523 * Return value: the address of @widget's size request cache.
9526 _gtk_widget_peek_request_cache (GtkWidget *widget)
9528 /* Don't bother slowing things down with the return_if_fail guards here */
9529 return &widget->priv->requests;
9533 * _gtk_widget_set_device_window:
9534 * @widget: a #GtkWidget.
9535 * @device: a #GdkDevice.
9536 * @window: the new device window.
9538 * Sets pointer window for @widget and @device. Does not ref @window.
9539 * Actually stores it on the #GdkScreen, but you don't need to know that.
9542 _gtk_widget_set_device_window (GtkWidget *widget,
9546 GtkWidgetPrivate *priv;
9548 GHashTable *device_window;
9550 g_return_if_fail (GTK_IS_WIDGET (widget));
9551 g_return_if_fail (GDK_IS_DEVICE (device));
9552 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9554 priv = widget->priv;
9556 if (!gtk_widget_get_realized (widget))
9559 screen = gdk_window_get_screen (priv->window);
9560 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9562 if (G_UNLIKELY (!device_window))
9564 device_window = g_hash_table_new (NULL, NULL);
9565 g_object_set_qdata_full (G_OBJECT (screen),
9566 quark_pointer_window,
9568 (GDestroyNotify) g_hash_table_destroy);
9572 g_hash_table_insert (device_window, device, window);
9574 g_hash_table_remove (device_window, device);
9578 * _gtk_widget_get_device_window:
9579 * @widget: a #GtkWidget.
9580 * @device: a #GdkDevice.
9582 * Return value: the device window set on the #GdkScreen @widget is attached
9586 _gtk_widget_get_device_window (GtkWidget *widget,
9589 GtkWidgetPrivate *priv;
9591 GHashTable *device_window;
9595 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9596 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9598 priv = widget->priv;
9600 if (!gtk_widget_get_realized (widget))
9603 screen = gdk_window_get_screen (priv->window);
9604 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9606 if (G_UNLIKELY (!device_window))
9609 window = g_hash_table_lookup (device_window, device);
9614 gdk_window_get_user_data (window, (gpointer *) &w);
9623 * _gtk_widget_list_devices:
9624 * @widget: a #GtkWidget.
9626 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9627 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9631 _gtk_widget_list_devices (GtkWidget *widget)
9633 GtkWidgetPrivate *priv;
9635 GHashTableIter iter;
9636 GHashTable *device_window;
9637 GList *devices = NULL;
9638 gpointer key, value;
9640 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9642 priv = widget->priv;
9644 if (!gtk_widget_get_realized (widget))
9647 screen = gdk_window_get_screen (priv->window);
9648 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9650 if (G_UNLIKELY (!device_window))
9653 g_hash_table_iter_init (&iter, device_window);
9655 while (g_hash_table_iter_next (&iter, &key, &value))
9657 GdkDevice *device = key;
9658 GdkWindow *window = value;
9663 gdk_window_get_user_data (window, (gpointer *) &w);
9666 devices = g_list_prepend (devices, device);
9674 synth_crossing (GtkWidget *widget,
9678 GdkCrossingMode mode,
9679 GdkNotifyType detail)
9683 event = gdk_event_new (type);
9685 event->crossing.window = g_object_ref (window);
9686 event->crossing.send_event = TRUE;
9687 event->crossing.subwindow = g_object_ref (window);
9688 event->crossing.time = GDK_CURRENT_TIME;
9689 event->crossing.x = event->crossing.y = 0;
9690 event->crossing.x_root = event->crossing.y_root = 0;
9691 event->crossing.mode = mode;
9692 event->crossing.detail = detail;
9693 event->crossing.focus = FALSE;
9694 event->crossing.state = 0;
9695 gdk_event_set_device (event, device);
9698 widget = gtk_get_event_widget (event);
9701 gtk_widget_event_internal (widget, event);
9703 gdk_event_free (event);
9707 * _gtk_widget_synthesize_crossing:
9708 * @from: the #GtkWidget the virtual pointer is leaving.
9709 * @to: the #GtkWidget the virtual pointer is moving to.
9710 * @mode: the #GdkCrossingMode to place on the synthesized events.
9712 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9714 * The real pointer window is the window that most recently received an enter notify
9715 * event. Windows that don't select for crossing events can't become the real
9716 * poiner window. The real pointer widget that owns the real pointer window. The
9717 * effective pointer window is the same as the real pointer window unless the real
9718 * pointer widget is either insensitive or there is a grab on a widget that is not
9719 * an ancestor of the real pointer widget (in which case the effective pointer
9720 * window should be the root window).
9722 * When the effective pointer window is the same as the real poiner window, we
9723 * receive crossing events from the windowing system. When the effective pointer
9724 * window changes to become different from the real pointer window we synthesize
9725 * crossing events, attempting to follow X protocol rules:
9727 * When the root window becomes the effective pointer window:
9728 * - leave notify on real pointer window, detail Ancestor
9729 * - leave notify on all of its ancestors, detail Virtual
9730 * - enter notify on root window, detail Inferior
9732 * When the root window ceases to be the effective pointer window:
9733 * - leave notify on root window, detail Inferior
9734 * - enter notify on all ancestors of real pointer window, detail Virtual
9735 * - enter notify on real pointer window, detail Ancestor
9738 _gtk_widget_synthesize_crossing (GtkWidget *from,
9741 GdkCrossingMode mode)
9743 GdkWindow *from_window = NULL, *to_window = NULL;
9745 g_return_if_fail (from != NULL || to != NULL);
9749 from_window = _gtk_widget_get_device_window (from, device);
9752 from_window = from->priv->window;
9757 to_window = _gtk_widget_get_device_window (to, device);
9760 to_window = to->priv->window;
9763 if (from_window == NULL && to_window == NULL)
9765 else if (from_window != NULL && to_window == NULL)
9767 GList *from_ancestors = NULL, *list;
9768 GdkWindow *from_ancestor = from_window;
9770 while (from_ancestor != NULL)
9772 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9773 if (from_ancestor == NULL)
9775 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9778 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9779 device, mode, GDK_NOTIFY_ANCESTOR);
9780 for (list = g_list_last (from_ancestors); list; list = list->prev)
9782 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9783 device, mode, GDK_NOTIFY_VIRTUAL);
9786 /* XXX: enter/inferior on root window? */
9788 g_list_free (from_ancestors);
9790 else if (from_window == NULL && to_window != NULL)
9792 GList *to_ancestors = NULL, *list;
9793 GdkWindow *to_ancestor = to_window;
9795 while (to_ancestor != NULL)
9797 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9798 if (to_ancestor == NULL)
9800 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9803 /* XXX: leave/inferior on root window? */
9805 for (list = to_ancestors; list; list = list->next)
9807 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9808 device, mode, GDK_NOTIFY_VIRTUAL);
9810 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9811 device, mode, GDK_NOTIFY_ANCESTOR);
9813 g_list_free (to_ancestors);
9815 else if (from_window == to_window)
9819 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9820 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9822 while (from_ancestor != NULL || to_ancestor != NULL)
9824 if (from_ancestor != NULL)
9826 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9827 if (from_ancestor == to_window)
9830 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9832 if (to_ancestor != NULL)
9834 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9835 if (to_ancestor == from_window)
9838 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9841 if (to_ancestor == from_window)
9843 if (mode != GDK_CROSSING_GTK_UNGRAB)
9844 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9845 device, mode, GDK_NOTIFY_INFERIOR);
9846 for (list = to_ancestors; list; list = list->next)
9847 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9848 device, mode, GDK_NOTIFY_VIRTUAL);
9849 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9850 device, mode, GDK_NOTIFY_ANCESTOR);
9852 else if (from_ancestor == to_window)
9854 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9855 device, mode, GDK_NOTIFY_ANCESTOR);
9856 for (list = g_list_last (from_ancestors); list; list = list->prev)
9858 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9859 device, mode, GDK_NOTIFY_VIRTUAL);
9861 if (mode != GDK_CROSSING_GTK_GRAB)
9862 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9863 device, mode, GDK_NOTIFY_INFERIOR);
9867 while (from_ancestors != NULL && to_ancestors != NULL
9868 && from_ancestors->data == to_ancestors->data)
9870 from_ancestors = g_list_delete_link (from_ancestors,
9872 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9875 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9876 device, mode, GDK_NOTIFY_NONLINEAR);
9878 for (list = g_list_last (from_ancestors); list; list = list->prev)
9880 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9881 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9883 for (list = to_ancestors; list; list = list->next)
9885 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9886 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9888 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9889 device, mode, GDK_NOTIFY_NONLINEAR);
9891 g_list_free (from_ancestors);
9892 g_list_free (to_ancestors);
9897 gtk_widget_propagate_state (GtkWidget *widget,
9900 GtkWidgetPrivate *priv = widget->priv;
9901 guint8 old_state = gtk_widget_get_state (widget);
9902 guint8 old_saved_state = priv->saved_state;
9904 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9905 * parent_sensitive==TRUE on a sensitive widget
9909 if (data->parent_sensitive)
9910 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9912 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9914 if (gtk_widget_is_sensitive (widget))
9916 if (data->state_restoration)
9917 priv->state = priv->saved_state;
9919 priv->state = data->state;
9923 if (!data->state_restoration)
9925 if (data->state != GTK_STATE_INSENSITIVE)
9926 priv->saved_state = data->state;
9928 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9929 priv->saved_state = gtk_widget_get_state (widget);
9930 priv->state = GTK_STATE_INSENSITIVE;
9933 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9937 window = gtk_widget_get_toplevel (widget);
9938 if (window && gtk_widget_is_toplevel (window))
9939 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9942 if (old_state != gtk_widget_get_state (widget) ||
9943 old_saved_state != priv->saved_state)
9945 g_object_ref (widget);
9947 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9948 gtk_grab_remove (widget);
9950 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9952 if (!GTK_WIDGET_SHADOWED (widget))
9954 GList *event_windows = NULL;
9957 devices = _gtk_widget_list_devices (widget);
9959 for (d = devices; d; d = d->next)
9965 window = _gtk_widget_get_device_window (widget, device);
9967 /* Do not propagate more than once to the
9968 * same window if non-multidevice aware.
9970 if (!gdk_window_get_support_multidevice (window) &&
9971 g_list_find (event_windows, window))
9974 if (!gtk_widget_is_sensitive (widget))
9975 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9976 GDK_CROSSING_STATE_CHANGED);
9977 else if (old_state == GTK_STATE_INSENSITIVE)
9978 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9979 GDK_CROSSING_STATE_CHANGED);
9981 event_windows = g_list_prepend (event_windows, window);
9984 g_list_free (event_windows);
9985 g_list_free (devices);
9988 if (GTK_IS_CONTAINER (widget))
9990 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9991 if (data->use_forall)
9992 gtk_container_forall (GTK_CONTAINER (widget),
9993 (GtkCallback) gtk_widget_propagate_state,
9996 gtk_container_foreach (GTK_CONTAINER (widget),
9997 (GtkCallback) gtk_widget_propagate_state,
10000 g_object_unref (widget);
10004 static const GtkWidgetAuxInfo default_aux_info = {
10012 * _gtk_widget_get_aux_info:
10013 * @widget: a #GtkWidget
10014 * @create: if %TRUE, create the structure if it doesn't exist
10016 * Get the #GtkWidgetAuxInfo structure for the widget.
10018 * Return value: the #GtkAuxInfo structure for the widget, or
10019 * %NULL if @create is %FALSE and one doesn't already exist.
10022 _gtk_widget_get_aux_info (GtkWidget *widget,
10025 GtkWidgetAuxInfo *aux_info;
10027 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10028 if (!aux_info && create)
10030 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10032 *aux_info = default_aux_info;
10034 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10040 static const GtkWidgetAuxInfo*
10041 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10043 GtkWidgetAuxInfo *aux_info;
10045 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10046 if (aux_info == NULL)
10048 return &default_aux_info;
10056 /*****************************************
10057 * gtk_widget_aux_info_destroy:
10062 *****************************************/
10065 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10067 g_slice_free (GtkWidgetAuxInfo, aux_info);
10071 * gtk_widget_shape_combine_region:
10072 * @widget: a #GtkWidget
10073 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10075 * Sets a shape for this widget's GDK window. This allows for
10076 * transparent windows etc., see gdk_window_shape_combine_region()
10077 * for more information.
10082 gtk_widget_shape_combine_region (GtkWidget *widget,
10083 cairo_region_t *region)
10085 GtkWidgetPrivate *priv;
10087 g_return_if_fail (GTK_IS_WIDGET (widget));
10088 /* set_shape doesn't work on widgets without gdk window */
10089 g_return_if_fail (gtk_widget_get_has_window (widget));
10091 priv = widget->priv;
10093 if (region == NULL)
10095 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10098 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10100 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10104 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10106 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10107 cairo_region_copy (region),
10108 (GDestroyNotify) cairo_region_destroy);
10110 /* set shape if widget has a gdk window already.
10111 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10114 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10119 * gtk_widget_input_shape_combine_region:
10120 * @widget: a #GtkWidget
10121 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10123 * Sets an input shape for this widget's GDK window. This allows for
10124 * windows which react to mouse click in a nonrectangular region, see
10125 * gdk_window_input_shape_combine_region() for more information.
10130 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10131 cairo_region_t *region)
10133 GtkWidgetPrivate *priv;
10135 g_return_if_fail (GTK_IS_WIDGET (widget));
10136 /* set_shape doesn't work on widgets without gdk window */
10137 g_return_if_fail (gtk_widget_get_has_window (widget));
10139 priv = widget->priv;
10141 if (region == NULL)
10144 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10146 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10150 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10151 cairo_region_copy (region),
10152 (GDestroyNotify) cairo_region_destroy);
10154 /* set shape if widget has a gdk window already.
10155 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10158 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10164 gtk_reset_shapes_recurse (GtkWidget *widget,
10170 gdk_window_get_user_data (window, &data);
10171 if (data != widget)
10174 gdk_window_shape_combine_region (window, NULL, 0, 0);
10175 for (list = gdk_window_peek_children (window); list; list = list->next)
10176 gtk_reset_shapes_recurse (widget, list->data);
10180 * gtk_widget_reset_shapes:
10181 * @widget: a #GtkWidget
10183 * Recursively resets the shape on this widget and its descendants.
10186 gtk_widget_reset_shapes (GtkWidget *widget)
10188 GtkWidgetPrivate *priv;
10190 g_return_if_fail (GTK_IS_WIDGET (widget));
10191 g_return_if_fail (gtk_widget_get_realized (widget));
10193 priv = widget->priv;
10195 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10196 gtk_reset_shapes_recurse (widget, priv->window);
10199 /* style properties
10203 * gtk_widget_class_install_style_property_parser:
10204 * @klass: a #GtkWidgetClass
10205 * @pspec: the #GParamSpec for the style property
10206 * @parser: the parser for the style property
10208 * Installs a style property on a widget class.
10211 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10213 GtkRcPropertyParser parser)
10215 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10216 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10217 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10218 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10220 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10222 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10223 G_OBJECT_CLASS_NAME (klass),
10228 g_param_spec_ref_sink (pspec);
10229 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10230 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10234 * gtk_widget_class_install_style_property:
10235 * @klass: a #GtkWidgetClass
10236 * @pspec: the #GParamSpec for the property
10238 * Installs a style property on a widget class. The parser for the
10239 * style property is determined by the value type of @pspec.
10242 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10245 GtkRcPropertyParser parser;
10247 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10248 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10250 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10252 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10256 * gtk_widget_class_find_style_property:
10257 * @klass: a #GtkWidgetClass
10258 * @property_name: the name of the style property to find
10259 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10260 * style property with that name.
10262 * Finds a style property of a widget class by name.
10267 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10268 const gchar *property_name)
10270 g_return_val_if_fail (property_name != NULL, NULL);
10272 return g_param_spec_pool_lookup (style_property_spec_pool,
10274 G_OBJECT_CLASS_TYPE (klass),
10279 * gtk_widget_class_list_style_properties:
10280 * @klass: a #GtkWidgetClass
10281 * @n_properties: location to return the number of style properties found
10282 * @returns: an newly allocated array of #GParamSpec*. The array must
10283 * be freed with g_free().
10285 * Returns all style properties of a widget class.
10290 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10291 guint *n_properties)
10293 GParamSpec **pspecs;
10296 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10297 G_OBJECT_CLASS_TYPE (klass),
10306 * gtk_widget_style_get_property:
10307 * @widget: a #GtkWidget
10308 * @property_name: the name of a style property
10309 * @value: location to return the property value
10311 * Gets the value of a style property of @widget.
10314 gtk_widget_style_get_property (GtkWidget *widget,
10315 const gchar *property_name,
10318 GtkWidgetPrivate *priv;
10321 g_return_if_fail (GTK_IS_WIDGET (widget));
10322 g_return_if_fail (property_name != NULL);
10323 g_return_if_fail (G_IS_VALUE (value));
10325 priv = widget->priv;
10327 g_object_ref (widget);
10328 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10330 G_OBJECT_TYPE (widget),
10333 g_warning ("%s: widget class `%s' has no property named `%s'",
10335 G_OBJECT_TYPE_NAME (widget),
10339 const GValue *peek_value;
10341 peek_value = _gtk_style_peek_property_value (priv->style,
10342 G_OBJECT_TYPE (widget),
10344 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10346 /* auto-conversion of the caller's value type
10348 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10349 g_value_copy (peek_value, value);
10350 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10351 g_value_transform (peek_value, value);
10353 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10355 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10356 G_VALUE_TYPE_NAME (value));
10358 g_object_unref (widget);
10362 * gtk_widget_style_get_valist:
10363 * @widget: a #GtkWidget
10364 * @first_property_name: the name of the first property to get
10365 * @var_args: a <type>va_list</type> of pairs of property names and
10366 * locations to return the property values, starting with the location
10367 * for @first_property_name.
10369 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10373 gtk_widget_style_get_valist (GtkWidget *widget,
10374 const gchar *first_property_name,
10377 GtkWidgetPrivate *priv;
10380 g_return_if_fail (GTK_IS_WIDGET (widget));
10382 priv = widget->priv;
10384 g_object_ref (widget);
10386 name = first_property_name;
10389 const GValue *peek_value;
10393 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10395 G_OBJECT_TYPE (widget),
10399 g_warning ("%s: widget class `%s' has no property named `%s'",
10401 G_OBJECT_TYPE_NAME (widget),
10405 /* style pspecs are always readable so we can spare that check here */
10407 peek_value = _gtk_style_peek_property_value (priv->style,
10408 G_OBJECT_TYPE (widget),
10410 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10411 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10414 g_warning ("%s: %s", G_STRLOC, error);
10419 name = va_arg (var_args, gchar*);
10422 g_object_unref (widget);
10426 * gtk_widget_style_get:
10427 * @widget: a #GtkWidget
10428 * @first_property_name: the name of the first property to get
10429 * @Varargs: pairs of property names and locations to
10430 * return the property values, starting with the location for
10431 * @first_property_name, terminated by %NULL.
10433 * Gets the values of a multiple style properties of @widget.
10436 gtk_widget_style_get (GtkWidget *widget,
10437 const gchar *first_property_name,
10442 g_return_if_fail (GTK_IS_WIDGET (widget));
10444 va_start (var_args, first_property_name);
10445 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10451 * @widget: a #GtkWidget
10452 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10453 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10454 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10456 * Obtains the full path to @widget. The path is simply the name of a
10457 * widget and all its parents in the container hierarchy, separated by
10458 * periods. The name of a widget comes from
10459 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10460 * in gtkrc configuration files. Widget names are the type of the
10461 * widget by default (e.g. "GtkButton") or can be set to an
10462 * application-specific value with gtk_widget_set_name(). By setting
10463 * the name of a widget, you allow users or theme authors to apply
10464 * styles to that specific widget in their gtkrc
10465 * file. @path_reversed_p fills in the path in reverse order,
10466 * i.e. starting with @widget's name instead of starting with the name
10467 * of @widget's outermost ancestor.
10470 gtk_widget_path (GtkWidget *widget,
10471 guint *path_length,
10473 gchar **path_reversed)
10475 static gchar *rev_path = NULL;
10476 static guint tmp_path_len = 0;
10479 g_return_if_fail (GTK_IS_WIDGET (widget));
10484 const gchar *string;
10489 string = gtk_widget_get_name (widget);
10490 l = strlen (string);
10491 while (tmp_path_len <= len + l + 1)
10493 tmp_path_len += INIT_PATH_SIZE;
10494 rev_path = g_realloc (rev_path, tmp_path_len);
10496 s = string + l - 1;
10497 d = rev_path + len;
10498 while (s >= string)
10502 widget = widget->priv->parent;
10505 rev_path[len++] = '.';
10507 rev_path[len++] = 0;
10512 *path_length = len - 1;
10514 *path_reversed = g_strdup (rev_path);
10517 *path = g_strdup (rev_path);
10518 g_strreverse (*path);
10523 * gtk_widget_class_path:
10524 * @widget: a #GtkWidget
10525 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10526 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10527 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10530 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10531 * never uses a custom name set with gtk_widget_set_name().
10535 gtk_widget_class_path (GtkWidget *widget,
10536 guint *path_length,
10538 gchar **path_reversed)
10540 static gchar *rev_path = NULL;
10541 static guint tmp_path_len = 0;
10544 g_return_if_fail (GTK_IS_WIDGET (widget));
10549 const gchar *string;
10554 string = g_type_name (G_OBJECT_TYPE (widget));
10555 l = strlen (string);
10556 while (tmp_path_len <= len + l + 1)
10558 tmp_path_len += INIT_PATH_SIZE;
10559 rev_path = g_realloc (rev_path, tmp_path_len);
10561 s = string + l - 1;
10562 d = rev_path + len;
10563 while (s >= string)
10567 widget = widget->priv->parent;
10570 rev_path[len++] = '.';
10572 rev_path[len++] = 0;
10577 *path_length = len - 1;
10579 *path_reversed = g_strdup (rev_path);
10582 *path = g_strdup (rev_path);
10583 g_strreverse (*path);
10588 * gtk_requisition_new:
10590 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10592 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10593 * be freed with gtk_requisition_free().
10598 gtk_requisition_new (void)
10600 return g_slice_new0 (GtkRequisition);
10604 * gtk_requisition_copy:
10605 * @requisition: a #GtkRequisition
10607 * Copies a #GtkRequisition.
10609 * Returns: a copy of @requisition
10612 gtk_requisition_copy (const GtkRequisition *requisition)
10614 return g_slice_dup (GtkRequisition, requisition);
10618 * gtk_requisition_free:
10619 * @requisition: a #GtkRequisition
10621 * Frees a #GtkRequisition.
10624 gtk_requisition_free (GtkRequisition *requisition)
10626 g_slice_free (GtkRequisition, requisition);
10629 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10630 gtk_requisition_copy,
10631 gtk_requisition_free)
10634 * gtk_widget_get_accessible:
10635 * @widget: a #GtkWidget
10637 * Returns the accessible object that describes the widget to an
10638 * assistive technology.
10640 * If no accessibility library is loaded (i.e. no ATK implementation library is
10641 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10642 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10643 * if no class-specific #AtkObject implementation is available for the widget
10644 * instance in question, it will inherit an #AtkObject implementation from the
10645 * first ancestor class for which such an implementation is defined.
10647 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10648 * library contains more information about accessible objects and their uses.
10650 * Returns: (transfer none): the #AtkObject associated with @widget
10653 gtk_widget_get_accessible (GtkWidget *widget)
10655 GtkWidgetClass *klass;
10657 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10659 klass = GTK_WIDGET_GET_CLASS (widget);
10661 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10663 return klass->get_accessible (widget);
10667 gtk_widget_real_get_accessible (GtkWidget *widget)
10669 AtkObject* accessible;
10671 accessible = g_object_get_qdata (G_OBJECT (widget),
10672 quark_accessible_object);
10675 AtkObjectFactory *factory;
10676 AtkRegistry *default_registry;
10678 default_registry = atk_get_default_registry ();
10679 factory = atk_registry_get_factory (default_registry,
10680 G_TYPE_FROM_INSTANCE (widget));
10682 atk_object_factory_create_accessible (factory,
10683 G_OBJECT (widget));
10684 g_object_set_qdata (G_OBJECT (widget),
10685 quark_accessible_object,
10692 * Initialize a AtkImplementorIface instance's virtual pointers as
10693 * appropriate to this implementor's class (GtkWidget).
10696 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10698 iface->ref_accessible = gtk_widget_ref_accessible;
10702 gtk_widget_ref_accessible (AtkImplementor *implementor)
10704 AtkObject *accessible;
10706 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10708 g_object_ref (accessible);
10713 * GtkBuildable implementation
10715 static GQuark quark_builder_has_default = 0;
10716 static GQuark quark_builder_has_focus = 0;
10717 static GQuark quark_builder_atk_relations = 0;
10718 static GQuark quark_builder_set_name = 0;
10721 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10723 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10724 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10725 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10726 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10728 iface->set_name = gtk_widget_buildable_set_name;
10729 iface->get_name = gtk_widget_buildable_get_name;
10730 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10731 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10732 iface->parser_finished = gtk_widget_buildable_parser_finished;
10733 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10734 iface->custom_finished = gtk_widget_buildable_custom_finished;
10738 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10741 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10742 g_strdup (name), g_free);
10745 static const gchar *
10746 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10748 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10752 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10753 GtkBuilder *builder,
10754 const gchar *childname)
10756 if (strcmp (childname, "accessible") == 0)
10757 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10763 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10764 GtkBuilder *builder,
10766 const GValue *value)
10768 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10769 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10770 GINT_TO_POINTER (TRUE));
10771 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10772 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10773 GINT_TO_POINTER (TRUE));
10775 g_object_set_property (G_OBJECT (buildable), name, value);
10780 gchar *action_name;
10781 GString *description;
10783 gboolean translatable;
10793 free_action (AtkActionData *data, gpointer user_data)
10795 g_free (data->action_name);
10796 g_string_free (data->description, TRUE);
10797 g_free (data->context);
10798 g_slice_free (AtkActionData, data);
10802 free_relation (AtkRelationData *data, gpointer user_data)
10804 g_free (data->target);
10805 g_free (data->type);
10806 g_slice_free (AtkRelationData, data);
10810 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10811 GtkBuilder *builder)
10813 GSList *atk_relations;
10815 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10816 gtk_widget_grab_default (GTK_WIDGET (buildable));
10817 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10818 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10820 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10821 quark_builder_atk_relations);
10824 AtkObject *accessible;
10825 AtkRelationSet *relation_set;
10828 AtkRelationType relation_type;
10829 AtkObject *target_accessible;
10831 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10832 relation_set = atk_object_ref_relation_set (accessible);
10834 for (l = atk_relations; l; l = l->next)
10836 AtkRelationData *relation = (AtkRelationData*)l->data;
10838 target = gtk_builder_get_object (builder, relation->target);
10841 g_warning ("Target object %s in <relation> does not exist",
10845 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10846 g_assert (target_accessible != NULL);
10848 relation_type = atk_relation_type_for_name (relation->type);
10849 if (relation_type == ATK_RELATION_NULL)
10851 g_warning ("<relation> type %s not found",
10855 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10856 target_accessible);
10858 g_object_unref (relation_set);
10860 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10861 g_slist_free (atk_relations);
10862 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10871 } AccessibilitySubParserData;
10874 accessibility_start_element (GMarkupParseContext *context,
10875 const gchar *element_name,
10876 const gchar **names,
10877 const gchar **values,
10878 gpointer user_data,
10881 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10883 gint line_number, char_number;
10885 if (strcmp (element_name, "relation") == 0)
10887 gchar *target = NULL;
10888 gchar *type = NULL;
10889 AtkRelationData *relation;
10891 for (i = 0; names[i]; i++)
10893 if (strcmp (names[i], "target") == 0)
10894 target = g_strdup (values[i]);
10895 else if (strcmp (names[i], "type") == 0)
10896 type = g_strdup (values[i]);
10899 g_markup_parse_context_get_position (context,
10902 g_set_error (error,
10904 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10905 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10907 line_number, char_number, names[i], "relation");
10914 if (!target || !type)
10916 g_markup_parse_context_get_position (context,
10919 g_set_error (error,
10921 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10922 "%s:%d:%d <%s> requires attribute \"%s\"",
10924 line_number, char_number, "relation",
10925 type ? "target" : "type");
10931 relation = g_slice_new (AtkRelationData);
10932 relation->target = target;
10933 relation->type = type;
10935 data->relations = g_slist_prepend (data->relations, relation);
10937 else if (strcmp (element_name, "action") == 0)
10939 const gchar *action_name = NULL;
10940 const gchar *description = NULL;
10941 const gchar *msg_context = NULL;
10942 gboolean translatable = FALSE;
10943 AtkActionData *action;
10945 for (i = 0; names[i]; i++)
10947 if (strcmp (names[i], "action_name") == 0)
10948 action_name = values[i];
10949 else if (strcmp (names[i], "description") == 0)
10950 description = values[i];
10951 else if (strcmp (names[i], "translatable") == 0)
10953 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10956 else if (strcmp (names[i], "comments") == 0)
10958 /* do nothing, comments are for translators */
10960 else if (strcmp (names[i], "context") == 0)
10961 msg_context = values[i];
10964 g_markup_parse_context_get_position (context,
10967 g_set_error (error,
10969 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10970 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10972 line_number, char_number, names[i], "action");
10979 g_markup_parse_context_get_position (context,
10982 g_set_error (error,
10984 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10985 "%s:%d:%d <%s> requires attribute \"%s\"",
10987 line_number, char_number, "action",
10992 action = g_slice_new (AtkActionData);
10993 action->action_name = g_strdup (action_name);
10994 action->description = g_string_new (description);
10995 action->context = g_strdup (msg_context);
10996 action->translatable = translatable;
10998 data->actions = g_slist_prepend (data->actions, action);
11000 else if (strcmp (element_name, "accessibility") == 0)
11003 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11007 accessibility_text (GMarkupParseContext *context,
11010 gpointer user_data,
11013 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11015 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11017 AtkActionData *action = data->actions->data;
11019 g_string_append_len (action->description, text, text_len);
11023 static const GMarkupParser accessibility_parser =
11025 accessibility_start_element,
11027 accessibility_text,
11036 } AccelGroupParserData;
11039 accel_group_start_element (GMarkupParseContext *context,
11040 const gchar *element_name,
11041 const gchar **names,
11042 const gchar **values,
11043 gpointer user_data,
11048 guint modifiers = 0;
11049 gchar *signal = NULL;
11050 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11052 for (i = 0; names[i]; i++)
11054 if (strcmp (names[i], "key") == 0)
11055 key = gdk_keyval_from_name (values[i]);
11056 else if (strcmp (names[i], "modifiers") == 0)
11058 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11064 else if (strcmp (names[i], "signal") == 0)
11065 signal = g_strdup (values[i]);
11068 if (key == 0 || signal == NULL)
11070 g_warning ("<accelerator> requires key and signal attributes");
11073 parser_data->key = key;
11074 parser_data->modifiers = modifiers;
11075 parser_data->signal = signal;
11078 static const GMarkupParser accel_group_parser =
11080 accel_group_start_element,
11084 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11085 GtkBuilder *builder,
11087 const gchar *tagname,
11088 GMarkupParser *parser,
11091 g_assert (buildable);
11093 if (strcmp (tagname, "accelerator") == 0)
11095 AccelGroupParserData *parser_data;
11097 parser_data = g_slice_new0 (AccelGroupParserData);
11098 parser_data->object = g_object_ref (buildable);
11099 *parser = accel_group_parser;
11100 *data = parser_data;
11103 if (strcmp (tagname, "accessibility") == 0)
11105 AccessibilitySubParserData *parser_data;
11107 parser_data = g_slice_new0 (AccessibilitySubParserData);
11108 *parser = accessibility_parser;
11109 *data = parser_data;
11116 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11117 GtkWidget *toplevel,
11118 gpointer user_data)
11120 AccelGroupParserData *accel_data;
11121 GSList *accel_groups;
11122 GtkAccelGroup *accel_group;
11124 g_return_if_fail (GTK_IS_WIDGET (widget));
11125 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11126 g_return_if_fail (user_data != NULL);
11128 accel_data = (AccelGroupParserData*)user_data;
11129 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11130 if (g_slist_length (accel_groups) == 0)
11132 accel_group = gtk_accel_group_new ();
11133 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11137 g_assert (g_slist_length (accel_groups) == 1);
11138 accel_group = g_slist_nth_data (accel_groups, 0);
11141 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11142 accel_data->signal,
11145 accel_data->modifiers,
11146 GTK_ACCEL_VISIBLE);
11148 g_object_unref (accel_data->object);
11149 g_free (accel_data->signal);
11150 g_slice_free (AccelGroupParserData, accel_data);
11154 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11155 GtkBuilder *builder,
11157 const gchar *tagname,
11158 gpointer user_data)
11160 AccelGroupParserData *accel_data;
11161 AccessibilitySubParserData *a11y_data;
11162 GtkWidget *toplevel;
11164 if (strcmp (tagname, "accelerator") == 0)
11166 accel_data = (AccelGroupParserData*)user_data;
11167 g_assert (accel_data->object);
11169 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11171 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11173 else if (strcmp (tagname, "accessibility") == 0)
11175 a11y_data = (AccessibilitySubParserData*)user_data;
11177 if (a11y_data->actions)
11179 AtkObject *accessible;
11184 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11186 action = ATK_ACTION (accessible);
11187 n_actions = atk_action_get_n_actions (action);
11189 for (l = a11y_data->actions; l; l = l->next)
11191 AtkActionData *action_data = (AtkActionData*)l->data;
11193 for (i = 0; i < n_actions; i++)
11194 if (strcmp (atk_action_get_name (action, i),
11195 action_data->action_name) == 0)
11200 gchar *description;
11202 if (action_data->translatable && action_data->description->len)
11203 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11204 action_data->context,
11205 action_data->description->str);
11207 description = action_data->description->str;
11209 atk_action_set_description (action, i, description);
11213 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11214 g_slist_free (a11y_data->actions);
11217 if (a11y_data->relations)
11218 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11219 a11y_data->relations);
11221 g_slice_free (AccessibilitySubParserData, a11y_data);
11226 gtk_widget_real_get_width (GtkWidget *widget,
11227 gint *minimum_size,
11228 gint *natural_size)
11238 gtk_widget_real_get_height (GtkWidget *widget,
11239 gint *minimum_size,
11240 gint *natural_size)
11250 gtk_widget_real_get_height_for_width (GtkWidget *widget,
11252 gint *minimum_height,
11253 gint *natural_height)
11255 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
11259 gtk_widget_real_get_width_for_height (GtkWidget *widget,
11261 gint *minimum_width,
11262 gint *natural_width)
11264 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
11268 * gtk_widget_get_halign:
11269 * @widget: a #GtkWidget
11271 * Gets the value of the #GtkWidget:halign property.
11273 * Returns: the horizontal alignment of @widget
11276 gtk_widget_get_halign (GtkWidget *widget)
11278 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11279 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11283 * gtk_widget_set_halign:
11284 * @widget: a #GtkWidget
11285 * @align: the horizontal alignment
11287 * Sets the horizontal alignment of @widget.
11288 * See the #GtkWidget:halign property.
11291 gtk_widget_set_halign (GtkWidget *widget,
11294 GtkWidgetAuxInfo *aux_info;
11296 g_return_if_fail (GTK_IS_WIDGET (widget));
11298 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11300 if (aux_info->halign == align)
11303 aux_info->halign = align;
11304 gtk_widget_queue_resize (widget);
11305 g_object_notify (G_OBJECT (widget), "halign");
11309 * gtk_widget_get_valign:
11310 * @widget: a #GtkWidget
11312 * Gets the value of the #GtkWidget:valign property.
11314 * Returns: the vertical alignment of @widget
11317 gtk_widget_get_valign (GtkWidget *widget)
11319 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11320 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11324 * gtk_widget_set_valign:
11325 * @widget: a #GtkWidget
11326 * @align: the vertical alignment
11328 * Sets the vertical alignment of @widget.
11329 * See the #GtkWidget:valign property.
11332 gtk_widget_set_valign (GtkWidget *widget,
11335 GtkWidgetAuxInfo *aux_info;
11337 g_return_if_fail (GTK_IS_WIDGET (widget));
11339 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11341 if (aux_info->valign == align)
11344 aux_info->valign = align;
11345 gtk_widget_queue_resize (widget);
11346 g_object_notify (G_OBJECT (widget), "valign");
11350 * gtk_widget_get_margin_left:
11351 * @widget: a #GtkWidget
11353 * Gets the value of the #GtkWidget:margin-left property.
11355 * Returns: The left margin of @widget
11358 gtk_widget_get_margin_left (GtkWidget *widget)
11360 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11362 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11366 * gtk_widget_set_margin_left:
11367 * @widget: a #GtkWidget
11368 * @margin: the left margin
11370 * Sets the left margin of @widget.
11371 * See the #GtkWidget:margin-left property.
11374 gtk_widget_set_margin_left (GtkWidget *widget,
11377 GtkWidgetAuxInfo *aux_info;
11379 g_return_if_fail (GTK_IS_WIDGET (widget));
11380 g_return_if_fail (margin <= G_MAXINT16);
11382 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11384 if (aux_info->margin.left == margin)
11387 aux_info->margin.left = margin;
11388 gtk_widget_queue_resize (widget);
11389 g_object_notify (G_OBJECT (widget), "margin-left");
11393 * gtk_widget_get_margin_right:
11394 * @widget: a #GtkWidget
11396 * Gets the value of the #GtkWidget:margin-right property.
11398 * Returns: The left margin of @widget
11401 gtk_widget_get_margin_right (GtkWidget *widget)
11403 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11405 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11409 * gtk_widget_set_margin_right:
11410 * @widget: a #GtkWidget
11411 * @margin: the right margin
11413 * Sets the right margin of @widget.
11414 * See the #GtkWidget:margin-right property.
11417 gtk_widget_set_margin_right (GtkWidget *widget,
11420 GtkWidgetAuxInfo *aux_info;
11422 g_return_if_fail (GTK_IS_WIDGET (widget));
11423 g_return_if_fail (margin <= G_MAXINT16);
11425 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11427 if (aux_info->margin.right == margin)
11430 aux_info->margin.right = margin;
11431 gtk_widget_queue_resize (widget);
11432 g_object_notify (G_OBJECT (widget), "margin-right");
11436 * gtk_widget_get_margin_top:
11437 * @widget: a #GtkWidget
11439 * Gets the value of the #GtkWidget:margin-top property.
11441 * Returns: The top margin of @widget
11444 gtk_widget_get_margin_top (GtkWidget *widget)
11446 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11448 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11452 * gtk_widget_set_margin_top:
11453 * @widget: a #GtkWidget
11454 * @margin: the top margin
11456 * Sets the top margin of @widget.
11457 * See the #GtkWidget:margin-top property.
11460 gtk_widget_set_margin_top (GtkWidget *widget,
11463 GtkWidgetAuxInfo *aux_info;
11465 g_return_if_fail (GTK_IS_WIDGET (widget));
11466 g_return_if_fail (margin <= G_MAXINT16);
11468 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11470 if (aux_info->margin.top == margin)
11473 aux_info->margin.top = margin;
11474 gtk_widget_queue_resize (widget);
11475 g_object_notify (G_OBJECT (widget), "margin-top");
11479 * gtk_widget_get_margin_bottom:
11480 * @widget: a #GtkWidget
11482 * Gets the value of the #GtkWidget:margin-bottom property.
11484 * Returns: The bottom margin of @widget
11487 gtk_widget_get_margin_bottom (GtkWidget *widget)
11489 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11491 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11495 * gtk_widget_set_margin_bottom:
11496 * @widget: a #GtkWidget
11497 * @margin: the bottom margin
11499 * Sets the bottom margin of @widget.
11500 * See the #GtkWidget:margin-bottom property.
11503 gtk_widget_set_margin_bottom (GtkWidget *widget,
11506 GtkWidgetAuxInfo *aux_info;
11508 g_return_if_fail (GTK_IS_WIDGET (widget));
11509 g_return_if_fail (margin <= G_MAXINT16);
11511 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11513 if (aux_info->margin.bottom == margin)
11516 aux_info->margin.bottom = margin;
11517 gtk_widget_queue_resize (widget);
11518 g_object_notify (G_OBJECT (widget), "margin-bottom");
11522 * gtk_widget_get_clipboard:
11523 * @widget: a #GtkWidget
11524 * @selection: a #GdkAtom which identifies the clipboard
11525 * to use. %GDK_SELECTION_CLIPBOARD gives the
11526 * default clipboard. Another common value
11527 * is %GDK_SELECTION_PRIMARY, which gives
11528 * the primary X selection.
11530 * Returns the clipboard object for the given selection to
11531 * be used with @widget. @widget must have a #GdkDisplay
11532 * associated with it, so must be attached to a toplevel
11535 * Return value: (transfer none): the appropriate clipboard object. If no
11536 * clipboard already exists, a new one will
11537 * be created. Once a clipboard object has
11538 * been created, it is persistent for all time.
11543 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11545 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11546 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11548 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11553 * gtk_widget_list_mnemonic_labels:
11554 * @widget: a #GtkWidget
11556 * Returns a newly allocated list of the widgets, normally labels, for
11557 * which this widget is the target of a mnemonic (see for example,
11558 * gtk_label_set_mnemonic_widget()).
11560 * The widgets in the list are not individually referenced. If you
11561 * want to iterate through the list and perform actions involving
11562 * callbacks that might destroy the widgets, you
11563 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11564 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11565 * widgets afterwards.
11567 * Return value: (element-type GtkWidget) (transfer container): the list of
11568 * mnemonic labels; free this list
11569 * with g_list_free() when you are done with it.
11574 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11576 GList *list = NULL;
11579 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11581 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11582 list = g_list_prepend (list, l->data);
11588 * gtk_widget_add_mnemonic_label:
11589 * @widget: a #GtkWidget
11590 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11592 * Adds a widget to the list of mnemonic labels for
11593 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11594 * list of mnemonic labels for the widget is cleared when the
11595 * widget is destroyed, so the caller must make sure to update
11596 * its internal state at this point as well, by using a connection
11597 * to the #GtkWidget::destroy signal or a weak notifier.
11602 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11605 GSList *old_list, *new_list;
11607 g_return_if_fail (GTK_IS_WIDGET (widget));
11608 g_return_if_fail (GTK_IS_WIDGET (label));
11610 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11611 new_list = g_slist_prepend (old_list, label);
11613 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11614 new_list, (GDestroyNotify) g_slist_free);
11618 * gtk_widget_remove_mnemonic_label:
11619 * @widget: a #GtkWidget
11620 * @label: a #GtkWidget that was previously set as a mnemnic label for
11621 * @widget with gtk_widget_add_mnemonic_label().
11623 * Removes a widget from the list of mnemonic labels for
11624 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11625 * must have previously been added to the list with
11626 * gtk_widget_add_mnemonic_label().
11631 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11634 GSList *old_list, *new_list;
11636 g_return_if_fail (GTK_IS_WIDGET (widget));
11637 g_return_if_fail (GTK_IS_WIDGET (label));
11639 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11640 new_list = g_slist_remove (old_list, label);
11643 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11644 new_list, (GDestroyNotify) g_slist_free);
11648 * gtk_widget_get_no_show_all:
11649 * @widget: a #GtkWidget
11651 * Returns the current value of the GtkWidget:no-show-all property,
11652 * which determines whether calls to gtk_widget_show_all() and
11653 * gtk_widget_hide_all() will affect this widget.
11655 * Return value: the current value of the "no-show-all" property.
11660 gtk_widget_get_no_show_all (GtkWidget *widget)
11662 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11664 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11668 * gtk_widget_set_no_show_all:
11669 * @widget: a #GtkWidget
11670 * @no_show_all: the new value for the "no-show-all" property
11672 * Sets the #GtkWidget:no-show-all property, which determines whether
11673 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11676 * This is mostly for use in constructing widget hierarchies with externally
11677 * controlled visibility, see #GtkUIManager.
11682 gtk_widget_set_no_show_all (GtkWidget *widget,
11683 gboolean no_show_all)
11685 g_return_if_fail (GTK_IS_WIDGET (widget));
11687 no_show_all = (no_show_all != FALSE);
11689 if (no_show_all == gtk_widget_get_no_show_all (widget))
11693 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11695 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11697 g_object_notify (G_OBJECT (widget), "no-show-all");
11702 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11703 gboolean has_tooltip,
11706 GtkWidgetPrivate *priv = widget->priv;
11707 gboolean priv_has_tooltip;
11709 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11710 quark_has_tooltip));
11712 if (priv_has_tooltip != has_tooltip || force)
11714 priv_has_tooltip = has_tooltip;
11716 if (priv_has_tooltip)
11718 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11719 gdk_window_set_events (priv->window,
11720 gdk_window_get_events (priv->window) |
11721 GDK_LEAVE_NOTIFY_MASK |
11722 GDK_POINTER_MOTION_MASK |
11723 GDK_POINTER_MOTION_HINT_MASK);
11725 if (gtk_widget_get_has_window (widget))
11726 gtk_widget_add_events (widget,
11727 GDK_LEAVE_NOTIFY_MASK |
11728 GDK_POINTER_MOTION_MASK |
11729 GDK_POINTER_MOTION_HINT_MASK);
11732 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11733 GUINT_TO_POINTER (priv_has_tooltip));
11738 * gtk_widget_set_tooltip_window:
11739 * @widget: a #GtkWidget
11740 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11742 * Replaces the default, usually yellow, window used for displaying
11743 * tooltips with @custom_window. GTK+ will take care of showing and
11744 * hiding @custom_window at the right moment, to behave likewise as
11745 * the default tooltip window. If @custom_window is %NULL, the default
11746 * tooltip window will be used.
11748 * If the custom window should have the default theming it needs to
11749 * have the name "gtk-tooltip", see gtk_widget_set_name().
11754 gtk_widget_set_tooltip_window (GtkWidget *widget,
11755 GtkWindow *custom_window)
11757 gboolean has_tooltip;
11758 gchar *tooltip_markup;
11760 g_return_if_fail (GTK_IS_WIDGET (widget));
11761 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11763 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11766 g_object_ref (custom_window);
11768 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11769 custom_window, g_object_unref);
11771 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11772 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11774 if (has_tooltip && gtk_widget_get_visible (widget))
11775 gtk_widget_queue_tooltip_query (widget);
11779 * gtk_widget_get_tooltip_window:
11780 * @widget: a #GtkWidget
11782 * Returns the #GtkWindow of the current tooltip. This can be the
11783 * GtkWindow created by default, or the custom tooltip window set
11784 * using gtk_widget_set_tooltip_window().
11786 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11791 gtk_widget_get_tooltip_window (GtkWidget *widget)
11793 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11795 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11799 * gtk_widget_trigger_tooltip_query:
11800 * @widget: a #GtkWidget
11802 * Triggers a tooltip query on the display where the toplevel of @widget
11803 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11809 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11811 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11814 static guint tooltip_query_id;
11815 static GSList *tooltip_query_displays;
11818 tooltip_query_idle (gpointer data)
11820 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11821 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11822 g_slist_free (tooltip_query_displays);
11824 tooltip_query_displays = NULL;
11825 tooltip_query_id = 0;
11831 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11833 GdkDisplay *display;
11835 display = gtk_widget_get_display (widget);
11837 if (!g_slist_find (tooltip_query_displays, display))
11838 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11840 if (tooltip_query_id == 0)
11841 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11845 * gtk_widget_set_tooltip_text:
11846 * @widget: a #GtkWidget
11847 * @text: the contents of the tooltip for @widget
11849 * Sets @text as the contents of the tooltip. This function will take
11850 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11851 * handler for the GtkWidget::query-tooltip signal.
11853 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11858 gtk_widget_set_tooltip_text (GtkWidget *widget,
11861 g_return_if_fail (GTK_IS_WIDGET (widget));
11863 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11867 * gtk_widget_get_tooltip_text:
11868 * @widget: a #GtkWidget
11870 * Gets the contents of the tooltip for @widget.
11872 * Return value: the tooltip text, or %NULL. You should free the
11873 * returned string with g_free() when done.
11878 gtk_widget_get_tooltip_text (GtkWidget *widget)
11880 gchar *text = NULL;
11882 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11884 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11890 * gtk_widget_set_tooltip_markup:
11891 * @widget: a #GtkWidget
11892 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11894 * Sets @markup as the contents of the tooltip, which is marked up with
11895 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11897 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11898 * and of the default handler for the GtkWidget::query-tooltip signal.
11900 * See also the GtkWidget:tooltip-markup property and
11901 * gtk_tooltip_set_markup().
11906 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11907 const gchar *markup)
11909 g_return_if_fail (GTK_IS_WIDGET (widget));
11911 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11915 * gtk_widget_get_tooltip_markup:
11916 * @widget: a #GtkWidget
11918 * Gets the contents of the tooltip for @widget.
11920 * Return value: the tooltip text, or %NULL. You should free the
11921 * returned string with g_free() when done.
11926 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11928 gchar *text = NULL;
11930 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11932 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11938 * gtk_widget_set_has_tooltip:
11939 * @widget: a #GtkWidget
11940 * @has_tooltip: whether or not @widget has a tooltip.
11942 * Sets the has-tooltip property on @widget to @has_tooltip. See
11943 * GtkWidget:has-tooltip for more information.
11948 gtk_widget_set_has_tooltip (GtkWidget *widget,
11949 gboolean has_tooltip)
11951 g_return_if_fail (GTK_IS_WIDGET (widget));
11953 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11957 * gtk_widget_get_has_tooltip:
11958 * @widget: a #GtkWidget
11960 * Returns the current value of the has-tooltip property. See
11961 * GtkWidget:has-tooltip for more information.
11963 * Return value: current value of has-tooltip on @widget.
11968 gtk_widget_get_has_tooltip (GtkWidget *widget)
11970 gboolean has_tooltip = FALSE;
11972 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11974 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11976 return has_tooltip;
11980 * gtk_widget_get_allocation:
11981 * @widget: a #GtkWidget
11982 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11984 * Retrieves the widget's allocation.
11986 * Note, when implementing a #GtkContainer: a widget's allocation will
11987 * be its "adjusted" allocation, that is, the widget's parent
11988 * container typically calls gtk_widget_size_allocate() with an
11989 * allocation, and that allocation is then adjusted (to handle margin
11990 * and alignment for example) before assignment to the widget.
11991 * gtk_widget_get_allocation() returns the adjusted allocation that
11992 * was actually assigned to the widget. The adjusted allocation is
11993 * guaranteed to be completely contained within the
11994 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11995 * is guaranteed that its children stay inside the assigned bounds,
11996 * but not that they have exactly the bounds the container assigned.
11997 * There is no way to get the original allocation assigned by
11998 * gtk_widget_size_allocate(), since it isn't stored; if a container
11999 * implementation needs that information it will have to track it itself.
12004 gtk_widget_get_allocation (GtkWidget *widget,
12005 GtkAllocation *allocation)
12007 GtkWidgetPrivate *priv;
12009 g_return_if_fail (GTK_IS_WIDGET (widget));
12010 g_return_if_fail (allocation != NULL);
12012 priv = widget->priv;
12014 *allocation = priv->allocation;
12018 * gtk_widget_set_allocation:
12019 * @widget: a #GtkWidget
12020 * @allocation: a pointer to a #GtkAllocation to copy from
12022 * Sets the widget's allocation. This should not be used
12023 * directly, but from within a widget's size_allocate method.
12025 * The allocation set should be the "adjusted" or actual
12026 * allocation. If you're implementing a #GtkContainer, you want to use
12027 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12028 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12029 * allocation inside gtk_widget_size_allocate() to create an adjusted
12035 gtk_widget_set_allocation (GtkWidget *widget,
12036 const GtkAllocation *allocation)
12038 GtkWidgetPrivate *priv;
12040 g_return_if_fail (GTK_IS_WIDGET (widget));
12041 g_return_if_fail (allocation != NULL);
12043 priv = widget->priv;
12045 priv->allocation = *allocation;
12049 * gtk_widget_get_allocated_width:
12050 * @widget: the widget to query
12052 * Returns the width that has currently been allocated to @widget.
12053 * This function is intended to be used when implementing handlers
12054 * for the GtkWidget::draw function.
12056 * Returns: the width of the @widget
12059 gtk_widget_get_allocated_width (GtkWidget *widget)
12061 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12063 return widget->priv->allocation.width;
12067 * gtk_widget_get_allocated_height:
12068 * @widget: the widget to query
12070 * Returns the height that has currently been allocated to @widget.
12071 * This function is intended to be used when implementing handlers
12072 * for the GtkWidget::draw function.
12074 * Returns: the height of the @widget
12077 gtk_widget_get_allocated_height (GtkWidget *widget)
12079 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12081 return widget->priv->allocation.height;
12085 * gtk_widget_get_requisition:
12086 * @widget: a #GtkWidget
12087 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12089 * Retrieves the widget's requisition.
12091 * This function should only be used by widget implementations in
12092 * order to figure whether the widget's requisition has actually
12093 * changed after some internal state change (so that they can call
12094 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12096 * Normally, gtk_widget_size_request() should be used.
12100 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12101 * removed, If you need to cache sizes across requests and allocations,
12102 * add an explicit cache to the widget in question instead.
12105 gtk_widget_get_requisition (GtkWidget *widget,
12106 GtkRequisition *requisition)
12108 g_return_if_fail (GTK_IS_WIDGET (widget));
12109 g_return_if_fail (requisition != NULL);
12111 gtk_widget_get_preferred_size (widget, requisition, NULL);
12115 * gtk_widget_set_window:
12116 * @widget: a #GtkWidget
12117 * @window: a #GdkWindow
12119 * Sets a widget's window. This function should only be used in a
12120 * widget's GtkWidget::realize() implementation. The %window passed is
12121 * usually either new window created with gdk_window_new(), or the
12122 * window of its parent widget as returned by
12123 * gtk_widget_get_parent_window().
12125 * Widgets must indicate whether they will create their own #GdkWindow
12126 * by calling gtk_widget_set_has_window(). This is usually done in the
12127 * widget's init() function.
12129 * <note><para>This function does not add any reference to @window.</para></note>
12134 gtk_widget_set_window (GtkWidget *widget,
12137 GtkWidgetPrivate *priv;
12139 g_return_if_fail (GTK_IS_WIDGET (widget));
12140 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12142 priv = widget->priv;
12144 if (priv->window != window)
12146 priv->window = window;
12147 g_object_notify (G_OBJECT (widget), "window");
12152 * gtk_widget_get_window:
12153 * @widget: a #GtkWidget
12155 * Returns the widget's window if it is realized, %NULL otherwise
12157 * Return value: (transfer none): @widget's window.
12162 gtk_widget_get_window (GtkWidget *widget)
12164 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12166 return widget->priv->window;
12170 * gtk_widget_get_support_multidevice:
12171 * @widget: a #GtkWidget
12173 * Returns %TRUE if @widget is multiple pointer aware. See
12174 * gtk_widget_set_support_multidevice() for more information.
12176 * Returns: %TRUE is @widget is multidevice aware.
12179 gtk_widget_get_support_multidevice (GtkWidget *widget)
12181 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12183 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12187 * gtk_widget_set_support_multidevice:
12188 * @widget: a #GtkWidget
12189 * @support_multidevice: %TRUE to support input from multiple devices.
12191 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12192 * @widget will start receiving multiple, per device enter/leave events. Note
12193 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12194 * gdk_window_set_support_multidevice() will have to be called manually on them.
12199 gtk_widget_set_support_multidevice (GtkWidget *widget,
12200 gboolean support_multidevice)
12202 GtkWidgetPrivate *priv;
12204 g_return_if_fail (GTK_IS_WIDGET (widget));
12206 priv = widget->priv;
12208 if (support_multidevice)
12210 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12211 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12215 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12216 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12219 if (gtk_widget_get_realized (widget))
12220 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12224 _gtk_widget_set_has_focus (GtkWidget *widget,
12225 gboolean has_focus)
12228 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12230 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12234 * gtk_widget_send_focus_change:
12235 * @widget: a #GtkWidget
12236 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12238 * Sends the focus change @event to @widget
12240 * This function is not meant to be used by applications. The only time it
12241 * should be used is when it is necessary for a #GtkWidget to assign focus
12242 * to a widget that is semantically owned by the first widget even though
12243 * it's not a direct child - for instance, a search entry in a floating
12244 * window similar to the quick search in #GtkTreeView.
12246 * An example of its usage is:
12249 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12251 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12252 * fevent->focus_change.in = TRUE;
12253 * fevent->focus_change.window = gtk_widget_get_window (widget);
12254 * if (fevent->focus_change.window != NULL)
12255 * g_object_ref (fevent->focus_change.window);
12257 * gtk_widget_send_focus_change (widget, fevent);
12259 * gdk_event_free (event);
12262 * Return value: the return value from the event signal emission: %TRUE
12263 * if the event was handled, and %FALSE otherwise
12268 gtk_widget_send_focus_change (GtkWidget *widget,
12273 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12274 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12276 g_object_ref (widget);
12278 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12280 res = gtk_widget_event (widget, event);
12282 g_object_notify (G_OBJECT (widget), "has-focus");
12284 g_object_unref (widget);