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_expose_event (GtkWidget *widget,
346 GdkEventExpose *event);
347 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
349 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
351 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
352 GdkEventFocus *event);
353 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
354 GdkEventFocus *event);
355 static gboolean gtk_widget_real_focus (GtkWidget *widget,
356 GtkDirectionType direction);
357 static void gtk_widget_real_move_focus (GtkWidget *widget,
358 GtkDirectionType direction);
359 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
360 GtkDirectionType direction);
361 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
362 static void gtk_widget_update_pango_context (GtkWidget *widget);
363 static void gtk_widget_propagate_state (GtkWidget *widget,
365 static void gtk_widget_reset_rc_style (GtkWidget *widget);
366 static void gtk_widget_set_style_internal (GtkWidget *widget,
368 gboolean initial_emission);
369 static gint gtk_widget_event_internal (GtkWidget *widget,
371 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
372 gboolean group_cycling);
373 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
374 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
375 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
376 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
377 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
378 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
379 cairo_region_t *region);
380 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
381 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
382 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
385 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
386 gboolean has_tooltip,
388 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
389 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
391 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
392 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
394 const gchar *childname);
395 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
398 const GValue *value);
399 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
402 const gchar *tagname,
403 GMarkupParser *parser,
405 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
408 const gchar *tagname,
410 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
411 GtkBuilder *builder);
413 static void gtk_widget_size_request_init (GtkSizeRequestIface *iface);
414 static void gtk_widget_real_get_width (GtkSizeRequest *widget,
417 static void gtk_widget_real_get_height (GtkSizeRequest *widget,
421 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
424 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
425 GtkOrientation orientation,
429 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
430 GtkAllocation *allocation);
432 static void gtk_widget_set_usize_internal (GtkWidget *widget,
436 static void gtk_widget_add_events_internal (GtkWidget *widget,
440 /* --- variables --- */
441 static gpointer gtk_widget_parent_class = NULL;
442 static guint widget_signals[LAST_SIGNAL] = { 0 };
443 static GtkStyle *gtk_default_style = NULL;
444 static guint composite_child_stack = 0;
445 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
446 static GParamSpecPool *style_property_spec_pool = NULL;
448 static GQuark quark_property_parser = 0;
449 static GQuark quark_aux_info = 0;
450 static GQuark quark_accel_path = 0;
451 static GQuark quark_accel_closures = 0;
452 static GQuark quark_event_mask = 0;
453 static GQuark quark_device_event_mask = 0;
454 static GQuark quark_extension_event_mode = 0;
455 static GQuark quark_parent_window = 0;
456 static GQuark quark_pointer_window = 0;
457 static GQuark quark_shape_info = 0;
458 static GQuark quark_input_shape_info = 0;
459 static GQuark quark_pango_context = 0;
460 static GQuark quark_rc_style = 0;
461 static GQuark quark_accessible_object = 0;
462 static GQuark quark_mnemonic_labels = 0;
463 static GQuark quark_tooltip_markup = 0;
464 static GQuark quark_has_tooltip = 0;
465 static GQuark quark_tooltip_window = 0;
466 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
467 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
469 /* --- functions --- */
471 gtk_widget_get_type (void)
473 static GType widget_type = 0;
475 if (G_UNLIKELY (widget_type == 0))
477 const GTypeInfo widget_info =
479 sizeof (GtkWidgetClass),
480 NULL, /* base_init */
481 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
482 (GClassInitFunc) gtk_widget_class_init,
483 NULL, /* class_finalize */
484 NULL, /* class_init */
487 (GInstanceInitFunc) gtk_widget_init,
488 NULL, /* value_table */
491 const GInterfaceInfo accessibility_info =
493 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
494 (GInterfaceFinalizeFunc) NULL,
495 NULL /* interface data */
498 const GInterfaceInfo buildable_info =
500 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
501 (GInterfaceFinalizeFunc) NULL,
502 NULL /* interface data */
505 const GInterfaceInfo layout_info =
507 (GInterfaceInitFunc) gtk_widget_size_request_init,
508 (GInterfaceFinalizeFunc) NULL,
509 NULL /* interface data */
512 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
513 &widget_info, G_TYPE_FLAG_ABSTRACT);
515 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
516 &accessibility_info) ;
517 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
519 g_type_add_interface_static (widget_type, GTK_TYPE_SIZE_REQUEST,
527 child_property_notify_dispatcher (GObject *object,
531 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
534 /* We guard against the draw signal callbacks modifying the state of the
535 * cairo context by surounding it with save/restore.
536 * Maybe we should also cairo_new_path() just to be sure?
539 gtk_widget_draw_marshaller (GClosure *closure,
540 GValue *return_value,
541 guint n_param_values,
542 const GValue *param_values,
543 gpointer invocation_hint,
544 gpointer marshal_data)
546 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
550 _gtk_marshal_BOOLEAN__BOXED (closure,
561 gtk_widget_class_init (GtkWidgetClass *klass)
563 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
564 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
565 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
566 GtkBindingSet *binding_set;
568 gtk_widget_parent_class = g_type_class_peek_parent (klass);
570 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
571 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
572 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
573 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
574 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
575 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
576 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
577 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
578 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
579 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
580 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
581 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
582 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
583 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
584 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
585 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
586 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
587 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
589 style_property_spec_pool = g_param_spec_pool_new (FALSE);
590 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
591 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
592 cpn_context.dispatcher = child_property_notify_dispatcher;
593 _gtk_widget_child_property_notify_context = &cpn_context;
595 gobject_class->dispose = gtk_widget_dispose;
596 gobject_class->finalize = gtk_widget_finalize;
597 gobject_class->set_property = gtk_widget_set_property;
598 gobject_class->get_property = gtk_widget_get_property;
600 object_class->destroy = gtk_widget_real_destroy;
602 klass->activate_signal = 0;
603 klass->set_scroll_adjustments_signal = 0;
604 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
605 klass->show = gtk_widget_real_show;
606 klass->show_all = gtk_widget_show;
607 klass->hide = gtk_widget_real_hide;
608 klass->hide_all = gtk_widget_hide;
609 klass->map = gtk_widget_real_map;
610 klass->unmap = gtk_widget_real_unmap;
611 klass->realize = gtk_widget_real_realize;
612 klass->unrealize = gtk_widget_real_unrealize;
613 klass->size_request = gtk_widget_real_size_request;
614 klass->size_allocate = gtk_widget_real_size_allocate;
615 klass->state_changed = NULL;
616 klass->parent_set = NULL;
617 klass->hierarchy_changed = NULL;
618 klass->style_set = gtk_widget_real_style_set;
619 klass->direction_changed = gtk_widget_real_direction_changed;
620 klass->grab_notify = NULL;
621 klass->child_notify = NULL;
623 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
624 klass->grab_focus = gtk_widget_real_grab_focus;
625 klass->focus = gtk_widget_real_focus;
627 klass->button_press_event = NULL;
628 klass->button_release_event = NULL;
629 klass->motion_notify_event = NULL;
630 klass->delete_event = NULL;
631 klass->destroy_event = NULL;
632 klass->expose_event = gtk_widget_real_expose_event;
633 klass->key_press_event = gtk_widget_real_key_press_event;
634 klass->key_release_event = gtk_widget_real_key_release_event;
635 klass->enter_notify_event = NULL;
636 klass->leave_notify_event = NULL;
637 klass->configure_event = NULL;
638 klass->focus_in_event = gtk_widget_real_focus_in_event;
639 klass->focus_out_event = gtk_widget_real_focus_out_event;
640 klass->map_event = NULL;
641 klass->unmap_event = NULL;
642 klass->window_state_event = NULL;
643 klass->property_notify_event = _gtk_selection_property_notify;
644 klass->selection_clear_event = _gtk_selection_clear;
645 klass->selection_request_event = _gtk_selection_request;
646 klass->selection_notify_event = _gtk_selection_notify;
647 klass->selection_received = NULL;
648 klass->proximity_in_event = NULL;
649 klass->proximity_out_event = NULL;
650 klass->drag_begin = NULL;
651 klass->drag_end = NULL;
652 klass->drag_data_delete = NULL;
653 klass->drag_leave = NULL;
654 klass->drag_motion = NULL;
655 klass->drag_drop = NULL;
656 klass->drag_data_received = NULL;
657 klass->screen_changed = NULL;
658 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
659 klass->grab_broken_event = NULL;
660 klass->query_tooltip = gtk_widget_real_query_tooltip;
662 klass->show_help = gtk_widget_real_show_help;
664 /* Accessibility support */
665 klass->get_accessible = gtk_widget_real_get_accessible;
667 klass->no_expose_event = NULL;
669 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
670 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
672 g_object_class_install_property (gobject_class,
674 g_param_spec_string ("name",
676 P_("The name of the widget"),
678 GTK_PARAM_READWRITE));
679 g_object_class_install_property (gobject_class,
681 g_param_spec_object ("parent",
683 P_("The parent widget of this widget. Must be a Container widget"),
685 GTK_PARAM_READWRITE));
687 g_object_class_install_property (gobject_class,
689 g_param_spec_int ("width-request",
691 P_("Override for width request of the widget, or -1 if natural request should be used"),
695 GTK_PARAM_READWRITE));
696 g_object_class_install_property (gobject_class,
698 g_param_spec_int ("height-request",
699 P_("Height request"),
700 P_("Override for height request of the widget, or -1 if natural request should be used"),
704 GTK_PARAM_READWRITE));
705 g_object_class_install_property (gobject_class,
707 g_param_spec_boolean ("visible",
709 P_("Whether the widget is visible"),
711 GTK_PARAM_READWRITE));
712 g_object_class_install_property (gobject_class,
714 g_param_spec_boolean ("sensitive",
716 P_("Whether the widget responds to input"),
718 GTK_PARAM_READWRITE));
719 g_object_class_install_property (gobject_class,
721 g_param_spec_boolean ("app-paintable",
722 P_("Application paintable"),
723 P_("Whether the application will paint directly on the widget"),
725 GTK_PARAM_READWRITE));
726 g_object_class_install_property (gobject_class,
728 g_param_spec_boolean ("can-focus",
730 P_("Whether the widget can accept the input focus"),
732 GTK_PARAM_READWRITE));
733 g_object_class_install_property (gobject_class,
735 g_param_spec_boolean ("has-focus",
737 P_("Whether the widget has the input focus"),
739 GTK_PARAM_READWRITE));
740 g_object_class_install_property (gobject_class,
742 g_param_spec_boolean ("is-focus",
744 P_("Whether the widget is the focus widget within the toplevel"),
746 GTK_PARAM_READWRITE));
747 g_object_class_install_property (gobject_class,
749 g_param_spec_boolean ("can-default",
751 P_("Whether the widget can be the default widget"),
753 GTK_PARAM_READWRITE));
754 g_object_class_install_property (gobject_class,
756 g_param_spec_boolean ("has-default",
758 P_("Whether the widget is the default widget"),
760 GTK_PARAM_READWRITE));
761 g_object_class_install_property (gobject_class,
762 PROP_RECEIVES_DEFAULT,
763 g_param_spec_boolean ("receives-default",
764 P_("Receives default"),
765 P_("If TRUE, the widget will receive the default action when it is focused"),
767 GTK_PARAM_READWRITE));
768 g_object_class_install_property (gobject_class,
769 PROP_COMPOSITE_CHILD,
770 g_param_spec_boolean ("composite-child",
771 P_("Composite child"),
772 P_("Whether the widget is part of a composite widget"),
774 GTK_PARAM_READABLE));
775 g_object_class_install_property (gobject_class,
777 g_param_spec_object ("style",
779 P_("The style of the widget, which contains information about how it will look (colors etc)"),
781 GTK_PARAM_READWRITE));
782 g_object_class_install_property (gobject_class,
784 g_param_spec_flags ("events",
786 P_("The event mask that decides what kind of GdkEvents this widget gets"),
789 GTK_PARAM_READWRITE));
790 g_object_class_install_property (gobject_class,
791 PROP_EXTENSION_EVENTS,
792 g_param_spec_enum ("extension-events",
793 P_("Extension events"),
794 P_("The mask that decides what kind of extension events this widget gets"),
795 GDK_TYPE_EXTENSION_MODE,
796 GDK_EXTENSION_EVENTS_NONE,
797 GTK_PARAM_READWRITE));
798 g_object_class_install_property (gobject_class,
800 g_param_spec_boolean ("no-show-all",
802 P_("Whether gtk_widget_show_all() should not affect this widget"),
804 GTK_PARAM_READWRITE));
807 * GtkWidget:has-tooltip:
809 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
810 * A value of %TRUE indicates that @widget can have a tooltip, in this case
811 * the widget will be queried using #GtkWidget::query-tooltip to determine
812 * whether it will provide a tooltip or not.
814 * Note that setting this property to %TRUE for the first time will change
815 * the event masks of the GdkWindows of this widget to include leave-notify
816 * and motion-notify events. This cannot and will not be undone when the
817 * property is set to %FALSE again.
821 g_object_class_install_property (gobject_class,
823 g_param_spec_boolean ("has-tooltip",
825 P_("Whether this widget has a tooltip"),
827 GTK_PARAM_READWRITE));
829 * GtkWidget:tooltip-text:
831 * Sets the text of tooltip to be the given string.
833 * Also see gtk_tooltip_set_text().
835 * This is a convenience property which will take care of getting the
836 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
837 * will automatically be set to %TRUE and there will be taken care of
838 * #GtkWidget::query-tooltip in the default signal handler.
842 g_object_class_install_property (gobject_class,
844 g_param_spec_string ("tooltip-text",
846 P_("The contents of the tooltip for this widget"),
848 GTK_PARAM_READWRITE));
850 * GtkWidget:tooltip-markup:
852 * Sets the text of tooltip to be the given string, which is marked up
853 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
854 * Also see gtk_tooltip_set_markup().
856 * This is a convenience property which will take care of getting the
857 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
858 * will automatically be set to %TRUE and there will be taken care of
859 * #GtkWidget::query-tooltip in the default signal handler.
863 g_object_class_install_property (gobject_class,
865 g_param_spec_string ("tooltip-markup",
866 P_("Tooltip markup"),
867 P_("The contents of the tooltip for this widget"),
869 GTK_PARAM_READWRITE));
874 * The widget's window if it is realized, %NULL otherwise.
878 g_object_class_install_property (gobject_class,
880 g_param_spec_object ("window",
882 P_("The widget's window if it is realized"),
884 GTK_PARAM_READABLE));
887 * GtkWidget:double-buffered
889 * Whether the widget is double buffered.
893 g_object_class_install_property (gobject_class,
894 PROP_DOUBLE_BUFFERED,
895 g_param_spec_boolean ("double-buffered",
896 P_("Double Buffered"),
897 P_("Whether the widget is double buffered"),
899 GTK_PARAM_READWRITE));
904 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
908 g_object_class_install_property (gobject_class,
910 g_param_spec_enum ("halign",
911 P_("Horizontal Alignment"),
912 P_("How to position in extra horizontal space"),
915 GTK_PARAM_READWRITE));
920 * How to distribute vertical space if widget gets extra space, see #GtkAlign
924 g_object_class_install_property (gobject_class,
926 g_param_spec_enum ("valign",
927 P_("Vertical Alignment"),
928 P_("How to position in extra vertical space"),
931 GTK_PARAM_READWRITE));
934 * GtkWidget:margin-left
936 * Margin on left side of widget.
938 * This property adds margin outside of the widget's normal size
939 * request, the margin will be added in addition to the size from
940 * gtk_widget_set_size_request() for example.
944 g_object_class_install_property (gobject_class,
946 g_param_spec_int ("margin-left",
947 P_("Margin on Left"),
948 P_("Pixels of extra space on the left side"),
952 GTK_PARAM_READWRITE));
955 * GtkWidget:margin-right
957 * Margin on right side of widget.
959 * This property adds margin outside of the widget's normal size
960 * request, the margin will be added in addition to the size from
961 * gtk_widget_set_size_request() for example.
965 g_object_class_install_property (gobject_class,
967 g_param_spec_int ("margin-right",
968 P_("Margin on Right"),
969 P_("Pixels of extra space on the right side"),
973 GTK_PARAM_READWRITE));
976 * GtkWidget:margin-top
978 * Margin on top side of widget.
980 * This property adds margin outside of the widget's normal size
981 * request, the margin will be added in addition to the size from
982 * gtk_widget_set_size_request() for example.
986 g_object_class_install_property (gobject_class,
988 g_param_spec_int ("margin-top",
990 P_("Pixels of extra space on the top side"),
994 GTK_PARAM_READWRITE));
997 * GtkWidget:margin-bottom
999 * Margin on bottom side of widget.
1001 * This property adds margin outside of the widget's normal size
1002 * request, the margin will be added in addition to the size from
1003 * gtk_widget_set_size_request() for example.
1007 g_object_class_install_property (gobject_class,
1009 g_param_spec_int ("margin-bottom",
1010 P_("Margin on Bottom"),
1011 P_("Pixels of extra space on the bottom side"),
1015 GTK_PARAM_READWRITE));
1020 * Sets all four sides' margin at once. If read, returns max
1021 * margin on any side.
1025 g_object_class_install_property (gobject_class,
1027 g_param_spec_int ("margin",
1029 P_("Pixels of extra space on all four sides"),
1033 GTK_PARAM_READWRITE));
1037 * @widget: the object which received the signal.
1039 widget_signals[SHOW] =
1040 g_signal_new (I_("show"),
1041 G_TYPE_FROM_CLASS (gobject_class),
1043 G_STRUCT_OFFSET (GtkWidgetClass, show),
1045 _gtk_marshal_VOID__VOID,
1050 * @widget: the object which received the signal.
1052 widget_signals[HIDE] =
1053 g_signal_new (I_("hide"),
1054 G_TYPE_FROM_CLASS (gobject_class),
1056 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1058 _gtk_marshal_VOID__VOID,
1063 * @widget: the object which received the signal.
1065 widget_signals[MAP] =
1066 g_signal_new (I_("map"),
1067 G_TYPE_FROM_CLASS (gobject_class),
1069 G_STRUCT_OFFSET (GtkWidgetClass, map),
1071 _gtk_marshal_VOID__VOID,
1076 * @widget: the object which received the signal.
1078 widget_signals[UNMAP] =
1079 g_signal_new (I_("unmap"),
1080 G_TYPE_FROM_CLASS (gobject_class),
1082 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1084 _gtk_marshal_VOID__VOID,
1088 * GtkWidget::realize:
1089 * @widget: the object which received the signal.
1091 widget_signals[REALIZE] =
1092 g_signal_new (I_("realize"),
1093 G_TYPE_FROM_CLASS (gobject_class),
1095 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1097 _gtk_marshal_VOID__VOID,
1101 * GtkWidget::unrealize:
1102 * @widget: the object which received the signal.
1104 widget_signals[UNREALIZE] =
1105 g_signal_new (I_("unrealize"),
1106 G_TYPE_FROM_CLASS (gobject_class),
1108 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1110 _gtk_marshal_VOID__VOID,
1114 * GtkWidget::size-request:
1115 * @widget: the object which received the signal.
1118 widget_signals[SIZE_REQUEST] =
1119 g_signal_new (I_("size-request"),
1120 G_TYPE_FROM_CLASS (gobject_class),
1122 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1124 _gtk_marshal_VOID__BOXED,
1126 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1129 * GtkWidget::size-allocate:
1130 * @widget: the object which received the signal.
1133 widget_signals[SIZE_ALLOCATE] =
1134 g_signal_new (I_("size-allocate"),
1135 G_TYPE_FROM_CLASS (gobject_class),
1137 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1139 _gtk_marshal_VOID__BOXED,
1141 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1144 * GtkWidget::state-changed:
1145 * @widget: the object which received the signal.
1146 * @state: the previous state
1148 * The ::state-changed signal is emitted when the widget state changes.
1149 * See gtk_widget_get_state().
1151 widget_signals[STATE_CHANGED] =
1152 g_signal_new (I_("state-changed"),
1153 G_TYPE_FROM_CLASS (gobject_class),
1155 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1157 _gtk_marshal_VOID__ENUM,
1159 GTK_TYPE_STATE_TYPE);
1162 * GtkWidget::parent-set:
1163 * @widget: the object on which the signal is emitted
1164 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1165 * just got its initial parent.
1167 * The ::parent-set signal is emitted when a new parent
1168 * has been set on a widget.
1170 widget_signals[PARENT_SET] =
1171 g_signal_new (I_("parent-set"),
1172 G_TYPE_FROM_CLASS (gobject_class),
1174 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1176 _gtk_marshal_VOID__OBJECT,
1181 * GtkWidget::hierarchy-changed:
1182 * @widget: the object on which the signal is emitted
1183 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1184 * if the widget was previously unanchored
1186 * The ::hierarchy-changed signal is emitted when the
1187 * anchored state of a widget changes. A widget is
1188 * <firstterm>anchored</firstterm> when its toplevel
1189 * ancestor is a #GtkWindow. This signal is emitted when
1190 * a widget changes from un-anchored to anchored or vice-versa.
1192 widget_signals[HIERARCHY_CHANGED] =
1193 g_signal_new (I_("hierarchy-changed"),
1194 G_TYPE_FROM_CLASS (gobject_class),
1196 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1198 _gtk_marshal_VOID__OBJECT,
1203 * GtkWidget::style-set:
1204 * @widget: the object on which the signal is emitted
1205 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1206 * just got its initial style
1208 * The ::style-set signal is emitted when a new style has been set
1209 * on a widget. Note that style-modifying functions like
1210 * gtk_widget_modify_base() also cause this signal to be emitted.
1212 widget_signals[STYLE_SET] =
1213 g_signal_new (I_("style-set"),
1214 G_TYPE_FROM_CLASS (gobject_class),
1216 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1218 _gtk_marshal_VOID__OBJECT,
1222 * GtkWidget::direction-changed:
1223 * @widget: the object on which the signal is emitted
1224 * @previous_direction: the previous text direction of @widget
1226 * The ::direction-changed signal is emitted when the text direction
1227 * of a widget changes.
1229 widget_signals[DIRECTION_CHANGED] =
1230 g_signal_new (I_("direction-changed"),
1231 G_TYPE_FROM_CLASS (gobject_class),
1233 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1235 _gtk_marshal_VOID__ENUM,
1237 GTK_TYPE_TEXT_DIRECTION);
1240 * GtkWidget::grab-notify:
1241 * @widget: the object which received the signal
1242 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1243 * if it becomes unshadowed
1245 * The ::grab-notify signal is emitted when a widget becomes
1246 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1247 * another widget, or when it becomes unshadowed due to a grab
1250 * A widget is shadowed by a gtk_grab_add() when the topmost
1251 * grab widget in the grab stack of its window group is not
1254 widget_signals[GRAB_NOTIFY] =
1255 g_signal_new (I_("grab-notify"),
1256 G_TYPE_FROM_CLASS (gobject_class),
1258 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1260 _gtk_marshal_VOID__BOOLEAN,
1265 * GtkWidget::child-notify:
1266 * @widget: the object which received the signal
1267 * @pspec: the #GParamSpec of the changed child property
1269 * The ::child-notify signal is emitted for each
1270 * <link linkend="child-properties">child property</link> that has
1271 * changed on an object. The signal's detail holds the property name.
1273 widget_signals[CHILD_NOTIFY] =
1274 g_signal_new (I_("child-notify"),
1275 G_TYPE_FROM_CLASS (gobject_class),
1276 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1277 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1279 g_cclosure_marshal_VOID__PARAM,
1285 * @widget: the object which received the signal
1286 * @cr: the cairo context to draw to
1287 * @width: width of the widget
1288 * @height: height of the widget
1290 * This signal is emitted when a widget is supposed to render itself.
1291 * The @widget's top left corner must be painted at the origin of
1292 * the passed in context and be sized in the given @width and @height.
1294 * Signal handlers connected to this signal can modify the cairo
1295 * context passed as @cr in any way they like and don't need to
1296 * restore it. The signal emission takes care of calling cairo_save()
1297 * before and cairo_restore() after invoking the handler.
1299 widget_signals[DRAW] =
1300 g_signal_new (I_("draw"),
1301 G_TYPE_FROM_CLASS (gobject_class),
1303 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1304 _gtk_boolean_handled_accumulator, NULL,
1305 gtk_widget_draw_marshaller,
1307 CAIRO_GOBJECT_TYPE_CONTEXT);
1310 * GtkWidget::mnemonic-activate:
1311 * @widget: the object which received the signal.
1314 widget_signals[MNEMONIC_ACTIVATE] =
1315 g_signal_new (I_("mnemonic-activate"),
1316 G_TYPE_FROM_CLASS (gobject_class),
1318 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1319 _gtk_boolean_handled_accumulator, NULL,
1320 _gtk_marshal_BOOLEAN__BOOLEAN,
1325 * GtkWidget::grab-focus:
1326 * @widget: the object which received the signal.
1328 widget_signals[GRAB_FOCUS] =
1329 g_signal_new (I_("grab-focus"),
1330 G_TYPE_FROM_CLASS (gobject_class),
1331 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1332 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1334 _gtk_marshal_VOID__VOID,
1339 * @widget: the object which received the signal.
1342 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1344 widget_signals[FOCUS] =
1345 g_signal_new (I_("focus"),
1346 G_TYPE_FROM_CLASS (object_class),
1348 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1349 _gtk_boolean_handled_accumulator, NULL,
1350 _gtk_marshal_BOOLEAN__ENUM,
1352 GTK_TYPE_DIRECTION_TYPE);
1355 * GtkWidget::move-focus:
1356 * @widget: the object which received the signal.
1359 widget_signals[MOVE_FOCUS] =
1360 g_signal_new_class_handler (I_("move-focus"),
1361 G_TYPE_FROM_CLASS (object_class),
1362 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1363 G_CALLBACK (gtk_widget_real_move_focus),
1365 _gtk_marshal_VOID__ENUM,
1368 GTK_TYPE_DIRECTION_TYPE);
1371 * @widget: the object which received the signal.
1372 * @event: the #GdkEvent which triggered this signal
1374 * The GTK+ main loop will emit three signals for each GDK event delivered
1375 * to a widget: one generic ::event signal, another, more specific,
1376 * signal that matches the type of event delivered (e.g.
1377 * #GtkWidget::key-press-event) and finally a generic
1378 * #GtkWidget::event-after signal.
1380 * Returns: %TRUE to stop other handlers from being invoked for the event
1381 * and to cancel the emission of the second specific ::event signal.
1382 * %FALSE to propagate the event further and to allow the emission of
1383 * the second signal. The ::event-after signal is emitted regardless of
1386 widget_signals[EVENT] =
1387 g_signal_new (I_("event"),
1388 G_TYPE_FROM_CLASS (gobject_class),
1390 G_STRUCT_OFFSET (GtkWidgetClass, event),
1391 _gtk_boolean_handled_accumulator, NULL,
1392 _gtk_marshal_BOOLEAN__BOXED,
1394 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1397 * GtkWidget::event-after:
1398 * @widget: the object which received the signal.
1399 * @event: the #GdkEvent which triggered this signal
1401 * After the emission of the #GtkWidget::event signal and (optionally)
1402 * the second more specific signal, ::event-after will be emitted
1403 * regardless of the previous two signals handlers return values.
1406 widget_signals[EVENT_AFTER] =
1407 g_signal_new (I_("event-after"),
1408 G_TYPE_FROM_CLASS (gobject_class),
1412 _gtk_marshal_VOID__BOXED,
1414 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1417 * GtkWidget::button-press-event:
1418 * @widget: the object which received the signal.
1419 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1422 * The ::button-press-event signal will be emitted when a button
1423 * (typically from a mouse) is pressed.
1425 * To receive this signal, the #GdkWindow associated to the
1426 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1428 * This signal will be sent to the grab widget if there is one.
1430 * Returns: %TRUE to stop other handlers from being invoked for the event.
1431 * %FALSE to propagate the event further.
1433 widget_signals[BUTTON_PRESS_EVENT] =
1434 g_signal_new (I_("button-press-event"),
1435 G_TYPE_FROM_CLASS (gobject_class),
1437 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1438 _gtk_boolean_handled_accumulator, NULL,
1439 _gtk_marshal_BOOLEAN__BOXED,
1441 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1444 * GtkWidget::button-release-event:
1445 * @widget: the object which received the signal.
1446 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1449 * The ::button-release-event signal will be emitted when a button
1450 * (typically from a mouse) is released.
1452 * To receive this signal, the #GdkWindow associated to the
1453 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1455 * This signal will be sent to the grab widget if there is one.
1457 * Returns: %TRUE to stop other handlers from being invoked for the event.
1458 * %FALSE to propagate the event further.
1460 widget_signals[BUTTON_RELEASE_EVENT] =
1461 g_signal_new (I_("button-release-event"),
1462 G_TYPE_FROM_CLASS (gobject_class),
1464 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1465 _gtk_boolean_handled_accumulator, NULL,
1466 _gtk_marshal_BOOLEAN__BOXED,
1468 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1471 * GtkWidget::scroll-event:
1472 * @widget: the object which received the signal.
1473 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1476 * The ::scroll-event signal is emitted when a button in the 4 to 7
1477 * range is pressed. Wheel mice are usually configured to generate
1478 * button press events for buttons 4 and 5 when the wheel is turned.
1480 * To receive this signal, the #GdkWindow associated to the widget needs
1481 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1483 * This signal will be sent to the grab widget if there is one.
1485 * Returns: %TRUE to stop other handlers from being invoked for the event.
1486 * %FALSE to propagate the event further.
1488 widget_signals[SCROLL_EVENT] =
1489 g_signal_new (I_("scroll-event"),
1490 G_TYPE_FROM_CLASS (gobject_class),
1492 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1493 _gtk_boolean_handled_accumulator, NULL,
1494 _gtk_marshal_BOOLEAN__BOXED,
1496 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1498 * GtkWidget::motion-notify-event:
1499 * @widget: the object which received the signal.
1500 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1503 * The ::motion-notify-event signal is emitted when the pointer moves
1504 * over the widget's #GdkWindow.
1506 * To receive this signal, the #GdkWindow associated to the widget
1507 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1509 * This signal will be sent to the grab widget if there is one.
1511 * Returns: %TRUE to stop other handlers from being invoked for the event.
1512 * %FALSE to propagate the event further.
1514 widget_signals[MOTION_NOTIFY_EVENT] =
1515 g_signal_new (I_("motion-notify-event"),
1516 G_TYPE_FROM_CLASS (gobject_class),
1518 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1519 _gtk_boolean_handled_accumulator, NULL,
1520 _gtk_marshal_BOOLEAN__BOXED,
1522 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1525 * GtkWidget::composited-changed:
1526 * @widget: the object on which the signal is emitted
1528 * The ::composited-changed signal is emitted when the composited
1529 * status of @widget<!-- -->s screen changes.
1530 * See gdk_screen_is_composited().
1532 widget_signals[COMPOSITED_CHANGED] =
1533 g_signal_new (I_("composited-changed"),
1534 G_TYPE_FROM_CLASS (gobject_class),
1535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1536 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1538 _gtk_marshal_VOID__VOID,
1542 * GtkWidget::keynav-failed:
1543 * @widget: the object which received the signal
1544 * @direction: the direction of movement
1546 * Gets emitted if keyboard navigation fails.
1547 * See gtk_widget_keynav_failed() for details.
1549 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1550 * if the emitting widget should try to handle the keyboard
1551 * navigation attempt in its parent container(s).
1555 widget_signals[KEYNAV_FAILED] =
1556 g_signal_new_class_handler (I_("keynav-failed"),
1557 G_TYPE_FROM_CLASS (gobject_class),
1559 G_CALLBACK (gtk_widget_real_keynav_failed),
1560 _gtk_boolean_handled_accumulator, NULL,
1561 _gtk_marshal_BOOLEAN__ENUM,
1563 GTK_TYPE_DIRECTION_TYPE);
1566 * GtkWidget::delete-event:
1567 * @widget: the object which received the signal
1568 * @event: the event which triggered this signal
1570 * The ::delete-event signal is emitted if a user requests that
1571 * a toplevel window is closed. The default handler for this signal
1572 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1573 * this signal will cause the window to be hidden instead, so that
1574 * it can later be shown again without reconstructing it.
1576 * Returns: %TRUE to stop other handlers from being invoked for the event.
1577 * %FALSE to propagate the event further.
1579 widget_signals[DELETE_EVENT] =
1580 g_signal_new (I_("delete-event"),
1581 G_TYPE_FROM_CLASS (gobject_class),
1583 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1584 _gtk_boolean_handled_accumulator, NULL,
1585 _gtk_marshal_BOOLEAN__BOXED,
1587 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1590 * GtkWidget::destroy-event:
1591 * @widget: the object which received the signal.
1592 * @event: the event which triggered this signal
1594 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1595 * You rarely get this signal, because most widgets disconnect themselves
1596 * from their window before they destroy it, so no widget owns the
1597 * window at destroy time.
1599 * To receive this signal, the #GdkWindow associated to the widget needs
1600 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1601 * automatically for all new windows.
1603 * Returns: %TRUE to stop other handlers from being invoked for the event.
1604 * %FALSE to propagate the event further.
1606 widget_signals[DESTROY_EVENT] =
1607 g_signal_new (I_("destroy-event"),
1608 G_TYPE_FROM_CLASS (gobject_class),
1610 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1611 _gtk_boolean_handled_accumulator, NULL,
1612 _gtk_marshal_BOOLEAN__BOXED,
1614 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1617 * GtkWidget::expose-event:
1618 * @widget: the object which received the signal.
1619 * @event: (type Gdk.EventExpose): the #GdkEventExpose which triggered
1622 * The ::expose-event signal is emitted when an area of a previously
1623 * obscured #GdkWindow is made visible and needs to be redrawn.
1624 * #GTK_NO_WINDOW widgets will get a synthesized event from their parent
1627 * To receive this signal, the #GdkWindow associated to the widget needs
1628 * to enable the #GDK_EXPOSURE_MASK mask.
1630 * Returns: %TRUE to stop other handlers from being invoked for the event.
1631 * %FALSE to propagate the event further.
1633 widget_signals[EXPOSE_EVENT] =
1634 g_signal_new (I_("expose-event"),
1635 G_TYPE_FROM_CLASS (gobject_class),
1637 G_STRUCT_OFFSET (GtkWidgetClass, expose_event),
1638 _gtk_boolean_handled_accumulator, NULL,
1639 _gtk_marshal_BOOLEAN__BOXED,
1641 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1644 * GtkWidget::key-press-event:
1645 * @widget: the object which received the signal
1646 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1648 * The ::key-press-event signal is emitted when a key is pressed.
1650 * To receive this signal, the #GdkWindow associated to the widget needs
1651 * to enable the #GDK_KEY_PRESS_MASK mask.
1653 * This signal will be sent to the grab widget if there is one.
1655 * Returns: %TRUE to stop other handlers from being invoked for the event.
1656 * %FALSE to propagate the event further.
1658 widget_signals[KEY_PRESS_EVENT] =
1659 g_signal_new (I_("key-press-event"),
1660 G_TYPE_FROM_CLASS (gobject_class),
1662 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1663 _gtk_boolean_handled_accumulator, NULL,
1664 _gtk_marshal_BOOLEAN__BOXED,
1666 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1669 * GtkWidget::key-release-event:
1670 * @widget: the object which received the signal
1671 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1673 * The ::key-release-event signal is emitted when a key is pressed.
1675 * To receive this signal, the #GdkWindow associated to the widget needs
1676 * to enable the #GDK_KEY_RELEASE_MASK mask.
1678 * This signal will be sent to the grab widget if there is one.
1680 * Returns: %TRUE to stop other handlers from being invoked for the event.
1681 * %FALSE to propagate the event further.
1683 widget_signals[KEY_RELEASE_EVENT] =
1684 g_signal_new (I_("key-release-event"),
1685 G_TYPE_FROM_CLASS (gobject_class),
1687 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1688 _gtk_boolean_handled_accumulator, NULL,
1689 _gtk_marshal_BOOLEAN__BOXED,
1691 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1694 * GtkWidget::enter-notify-event:
1695 * @widget: the object which received the signal
1696 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1699 * The ::enter-notify-event will be emitted when the pointer enters
1700 * the @widget's window.
1702 * To receive this signal, the #GdkWindow associated to the widget needs
1703 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1705 * This signal will be sent to the grab widget if there is one.
1707 * Returns: %TRUE to stop other handlers from being invoked for the event.
1708 * %FALSE to propagate the event further.
1710 widget_signals[ENTER_NOTIFY_EVENT] =
1711 g_signal_new (I_("enter-notify-event"),
1712 G_TYPE_FROM_CLASS (gobject_class),
1714 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1715 _gtk_boolean_handled_accumulator, NULL,
1716 _gtk_marshal_BOOLEAN__BOXED,
1718 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1721 * GtkWidget::leave-notify-event:
1722 * @widget: the object which received the signal
1723 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1726 * The ::leave-notify-event will be emitted when the pointer leaves
1727 * the @widget's window.
1729 * To receive this signal, the #GdkWindow associated to the widget needs
1730 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1732 * This signal will be sent to the grab widget if there is one.
1734 * Returns: %TRUE to stop other handlers from being invoked for the event.
1735 * %FALSE to propagate the event further.
1737 widget_signals[LEAVE_NOTIFY_EVENT] =
1738 g_signal_new (I_("leave-notify-event"),
1739 G_TYPE_FROM_CLASS (gobject_class),
1741 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1742 _gtk_boolean_handled_accumulator, NULL,
1743 _gtk_marshal_BOOLEAN__BOXED,
1745 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1748 * GtkWidget::configure-event
1749 * @widget: the object which received the signal
1750 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1753 * The ::configure-event signal will be emitted when the size, position or
1754 * stacking of the @widget's window has changed.
1756 * To receive this signal, the #GdkWindow associated to the widget needs
1757 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1758 * automatically for all new windows.
1760 * Returns: %TRUE to stop other handlers from being invoked for the event.
1761 * %FALSE to propagate the event further.
1763 widget_signals[CONFIGURE_EVENT] =
1764 g_signal_new (I_("configure-event"),
1765 G_TYPE_FROM_CLASS (gobject_class),
1767 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1768 _gtk_boolean_handled_accumulator, NULL,
1769 _gtk_marshal_BOOLEAN__BOXED,
1771 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1774 * GtkWidget::focus-in-event
1775 * @widget: the object which received the signal
1776 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1779 * The ::focus-in-event signal will be emitted when the keyboard focus
1780 * enters the @widget's window.
1782 * To receive this signal, the #GdkWindow associated to the widget needs
1783 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1785 * Returns: %TRUE to stop other handlers from being invoked for the event.
1786 * %FALSE to propagate the event further.
1788 widget_signals[FOCUS_IN_EVENT] =
1789 g_signal_new (I_("focus-in-event"),
1790 G_TYPE_FROM_CLASS (gobject_class),
1792 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1793 _gtk_boolean_handled_accumulator, NULL,
1794 _gtk_marshal_BOOLEAN__BOXED,
1796 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1799 * GtkWidget::focus-out-event
1800 * @widget: the object which received the signal
1801 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1804 * The ::focus-out-event signal will be emitted when the keyboard focus
1805 * leaves the @widget's window.
1807 * To receive this signal, the #GdkWindow associated to the widget needs
1808 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1810 * Returns: %TRUE to stop other handlers from being invoked for the event.
1811 * %FALSE to propagate the event further.
1813 widget_signals[FOCUS_OUT_EVENT] =
1814 g_signal_new (I_("focus-out-event"),
1815 G_TYPE_FROM_CLASS (gobject_class),
1817 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1818 _gtk_boolean_handled_accumulator, NULL,
1819 _gtk_marshal_BOOLEAN__BOXED,
1821 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1824 * GtkWidget::map-event
1825 * @widget: the object which received the signal
1826 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1828 * The ::map-event signal will be emitted when the @widget's window is
1829 * mapped. A window is mapped when it becomes visible on the screen.
1831 * To receive this signal, the #GdkWindow associated to the widget needs
1832 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1833 * automatically for all new windows.
1835 * Returns: %TRUE to stop other handlers from being invoked for the event.
1836 * %FALSE to propagate the event further.
1838 widget_signals[MAP_EVENT] =
1839 g_signal_new (I_("map-event"),
1840 G_TYPE_FROM_CLASS (gobject_class),
1842 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1843 _gtk_boolean_handled_accumulator, NULL,
1844 _gtk_marshal_BOOLEAN__BOXED,
1846 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1849 * GtkWidget::unmap-event
1850 * @widget: the object which received the signal
1851 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1853 * The ::unmap-event signal may be emitted when the @widget's window is
1854 * unmapped. A window is unmapped when it becomes invisible on the screen.
1856 * For performance reasons GTK+ may not emit ::unmap-event, so one
1857 * should always also implement ::unrealize in order to release
1858 * resources and disconnect signal handlers.
1860 * To receive this signal, the #GdkWindow associated to the widget needs
1861 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1862 * automatically for all new windows.
1864 * Returns: %TRUE to stop other handlers from being invoked for the event.
1865 * %FALSE to propagate the event further.
1867 widget_signals[UNMAP_EVENT] =
1868 g_signal_new (I_("unmap-event"),
1869 G_TYPE_FROM_CLASS (gobject_class),
1871 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1872 _gtk_boolean_handled_accumulator, NULL,
1873 _gtk_marshal_BOOLEAN__BOXED,
1875 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1878 * GtkWidget::property-notify-event
1879 * @widget: the object which received the signal
1880 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1883 * The ::property-notify-event signal will be emitted when a property on
1884 * the @widget's window has been changed or deleted.
1886 * To receive this signal, the #GdkWindow associated to the widget needs
1887 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[PROPERTY_NOTIFY_EVENT] =
1893 g_signal_new (I_("property-notify-event"),
1894 G_TYPE_FROM_CLASS (gobject_class),
1896 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1903 * GtkWidget::selection-clear-event
1904 * @widget: the object which received the signal
1905 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1908 * The ::selection-clear-event signal will be emitted when the
1909 * the @widget's window has lost ownership of a selection.
1911 * Returns: %TRUE to stop other handlers from being invoked for the event.
1912 * %FALSE to propagate the event further.
1914 widget_signals[SELECTION_CLEAR_EVENT] =
1915 g_signal_new (I_("selection-clear-event"),
1916 G_TYPE_FROM_CLASS (gobject_class),
1918 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1919 _gtk_boolean_handled_accumulator, NULL,
1920 _gtk_marshal_BOOLEAN__BOXED,
1922 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1925 * GtkWidget::selection-request-event
1926 * @widget: the object which received the signal
1927 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1930 * The ::selection-request-event signal will be emitted when
1931 * another client requests ownership of the selection owned by
1932 * the @widget's window.
1934 * Returns: %TRUE to stop other handlers from being invoked for the event.
1935 * %FALSE to propagate the event further.
1937 widget_signals[SELECTION_REQUEST_EVENT] =
1938 g_signal_new (I_("selection-request-event"),
1939 G_TYPE_FROM_CLASS (gobject_class),
1941 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1942 _gtk_boolean_handled_accumulator, NULL,
1943 _gtk_marshal_BOOLEAN__BOXED,
1945 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1948 * GtkWidget::selection-notify-event:
1949 * @widget: the object which received the signal.
1952 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1954 widget_signals[SELECTION_NOTIFY_EVENT] =
1955 g_signal_new (I_("selection-notify-event"),
1956 G_TYPE_FROM_CLASS (gobject_class),
1958 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1959 _gtk_boolean_handled_accumulator, NULL,
1960 _gtk_marshal_BOOLEAN__BOXED,
1962 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1965 * GtkWidget::selection-received:
1966 * @widget: the object which received the signal.
1970 widget_signals[SELECTION_RECEIVED] =
1971 g_signal_new (I_("selection-received"),
1972 G_TYPE_FROM_CLASS (gobject_class),
1974 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1976 _gtk_marshal_VOID__BOXED_UINT,
1978 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1982 * GtkWidget::selection-get:
1983 * @widget: the object which received the signal.
1988 widget_signals[SELECTION_GET] =
1989 g_signal_new (I_("selection-get"),
1990 G_TYPE_FROM_CLASS (gobject_class),
1992 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1994 _gtk_marshal_VOID__BOXED_UINT_UINT,
1996 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2001 * GtkWidget::proximity-in-event
2002 * @widget: the object which received the signal
2003 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2006 * To receive this signal the #GdkWindow associated to the widget needs
2007 * to enable the #GDK_PROXIMITY_IN_MASK mask.
2009 * This signal will be sent to the grab widget if there is one.
2011 * Returns: %TRUE to stop other handlers from being invoked for the event.
2012 * %FALSE to propagate the event further.
2014 widget_signals[PROXIMITY_IN_EVENT] =
2015 g_signal_new (I_("proximity-in-event"),
2016 G_TYPE_FROM_CLASS (gobject_class),
2018 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
2019 _gtk_boolean_handled_accumulator, NULL,
2020 _gtk_marshal_BOOLEAN__BOXED,
2022 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2025 * GtkWidget::proximity-out-event
2026 * @widget: the object which received the signal
2027 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2030 * To receive this signal the #GdkWindow associated to the widget needs
2031 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2033 * This signal will be sent to the grab widget if there is one.
2035 * Returns: %TRUE to stop other handlers from being invoked for the event.
2036 * %FALSE to propagate the event further.
2038 widget_signals[PROXIMITY_OUT_EVENT] =
2039 g_signal_new (I_("proximity-out-event"),
2040 G_TYPE_FROM_CLASS (gobject_class),
2042 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2043 _gtk_boolean_handled_accumulator, NULL,
2044 _gtk_marshal_BOOLEAN__BOXED,
2046 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2049 * GtkWidget::drag-leave:
2050 * @widget: the object which received the signal.
2051 * @drag_context: the drag context
2052 * @time: the timestamp of the motion event
2054 * The ::drag-leave signal is emitted on the drop site when the cursor
2055 * leaves the widget. A typical reason to connect to this signal is to
2056 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2057 * with gtk_drag_unhighlight()
2059 widget_signals[DRAG_LEAVE] =
2060 g_signal_new (I_("drag-leave"),
2061 G_TYPE_FROM_CLASS (gobject_class),
2063 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2065 _gtk_marshal_VOID__OBJECT_UINT,
2067 GDK_TYPE_DRAG_CONTEXT,
2071 * GtkWidget::drag-begin:
2072 * @widget: the object which received the signal
2073 * @drag_context: the drag context
2075 * The ::drag-begin signal is emitted on the drag source when a drag is
2076 * started. A typical reason to connect to this signal is to set up a
2077 * custom drag icon with gtk_drag_source_set_icon().
2079 * Note that some widgets set up a drag icon in the default handler of
2080 * this signal, so you may have to use g_signal_connect_after() to
2081 * override what the default handler did.
2083 widget_signals[DRAG_BEGIN] =
2084 g_signal_new (I_("drag-begin"),
2085 G_TYPE_FROM_CLASS (gobject_class),
2087 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2089 _gtk_marshal_VOID__OBJECT,
2091 GDK_TYPE_DRAG_CONTEXT);
2094 * GtkWidget::drag-end:
2095 * @widget: the object which received the signal
2096 * @drag_context: the drag context
2098 * The ::drag-end signal is emitted on the drag source when a drag is
2099 * finished. A typical reason to connect to this signal is to undo
2100 * things done in #GtkWidget::drag-begin.
2102 widget_signals[DRAG_END] =
2103 g_signal_new (I_("drag-end"),
2104 G_TYPE_FROM_CLASS (gobject_class),
2106 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2108 _gtk_marshal_VOID__OBJECT,
2110 GDK_TYPE_DRAG_CONTEXT);
2113 * GtkWidget::drag-data-delete:
2114 * @widget: the object which received the signal
2115 * @drag_context: the drag context
2117 * The ::drag-data-delete signal is emitted on the drag source when a drag
2118 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2119 * handler is responsible for deleting the data that has been dropped. What
2120 * "delete" means depends on the context of the drag operation.
2122 widget_signals[DRAG_DATA_DELETE] =
2123 g_signal_new (I_("drag-data-delete"),
2124 G_TYPE_FROM_CLASS (gobject_class),
2126 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2128 _gtk_marshal_VOID__OBJECT,
2130 GDK_TYPE_DRAG_CONTEXT);
2133 * GtkWidget::drag-failed:
2134 * @widget: the object which received the signal
2135 * @drag_context: the drag context
2136 * @result: the result of the drag operation
2138 * The ::drag-failed signal is emitted on the drag source when a drag has
2139 * failed. The signal handler may hook custom code to handle a failed DND
2140 * operation based on the type of error, it returns %TRUE is the failure has
2141 * been already handled (not showing the default "drag operation failed"
2142 * animation), otherwise it returns %FALSE.
2144 * Return value: %TRUE if the failed drag operation has been already handled.
2148 widget_signals[DRAG_FAILED] =
2149 g_signal_new (I_("drag-failed"),
2150 G_TYPE_FROM_CLASS (gobject_class),
2152 0, _gtk_boolean_handled_accumulator, NULL,
2153 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2155 GDK_TYPE_DRAG_CONTEXT,
2156 GTK_TYPE_DRAG_RESULT);
2159 * GtkWidget::drag-motion:
2160 * @widget: the object which received the signal
2161 * @drag_context: the drag context
2162 * @x: the x coordinate of the current cursor position
2163 * @y: the y coordinate of the current cursor position
2164 * @time: the timestamp of the motion event
2165 * @returns: whether the cursor position is in a drop zone
2167 * The drag-motion signal is emitted on the drop site when the user
2168 * moves the cursor over the widget during a drag. The signal handler
2169 * must determine whether the cursor position is in a drop zone or not.
2170 * If it is not in a drop zone, it returns %FALSE and no further processing
2171 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2172 * handler is responsible for providing the necessary information for
2173 * displaying feedback to the user, by calling gdk_drag_status().
2175 * If the decision whether the drop will be accepted or rejected can't be
2176 * made based solely on the cursor position and the type of the data, the
2177 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2178 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2179 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2180 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2181 * when using the drag-motion signal that way.
2183 * Also note that there is no drag-enter signal. The drag receiver has to
2184 * keep track of whether he has received any drag-motion signals since the
2185 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2186 * an "enter" signal. Upon an "enter", the handler will typically highlight
2187 * the drop site with gtk_drag_highlight().
2190 * drag_motion (GtkWidget *widget,
2191 * GdkDragContext *context,
2198 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2200 * if (!private_data->drag_highlight)
2202 * private_data->drag_highlight = 1;
2203 * gtk_drag_highlight (widget);
2206 * target = gtk_drag_dest_find_target (widget, context, NULL);
2207 * if (target == GDK_NONE)
2208 * gdk_drag_status (context, 0, time);
2211 * private_data->pending_status = context->suggested_action;
2212 * gtk_drag_get_data (widget, context, target, time);
2219 * drag_data_received (GtkWidget *widget,
2220 * GdkDragContext *context,
2223 * GtkSelectionData *selection_data,
2227 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2229 * if (private_data->suggested_action)
2231 * private_data->suggested_action = 0;
2233 * /* We are getting this data due to a request in drag_motion,
2234 * * rather than due to a request in drag_drop, so we are just
2235 * * supposed to call gdk_drag_status (), not actually paste in
2238 * str = gtk_selection_data_get_text (selection_data);
2239 * if (!data_is_acceptable (str))
2240 * gdk_drag_status (context, 0, time);
2242 * gdk_drag_status (context, private_data->suggested_action, time);
2246 * /* accept the drop */
2251 widget_signals[DRAG_MOTION] =
2252 g_signal_new (I_("drag-motion"),
2253 G_TYPE_FROM_CLASS (gobject_class),
2255 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2256 _gtk_boolean_handled_accumulator, NULL,
2257 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2259 GDK_TYPE_DRAG_CONTEXT,
2265 * GtkWidget::drag-drop:
2266 * @widget: the object which received the signal
2267 * @drag_context: the drag context
2268 * @x: the x coordinate of the current cursor position
2269 * @y: the y coordinate of the current cursor position
2270 * @time: the timestamp of the motion event
2271 * @returns: whether the cursor position is in a drop zone
2273 * The ::drag-drop signal is emitted on the drop site when the user drops
2274 * the data onto the widget. The signal handler must determine whether
2275 * the cursor position is in a drop zone or not. If it is not in a drop
2276 * zone, it returns %FALSE and no further processing is necessary.
2277 * Otherwise, the handler returns %TRUE. In this case, the handler must
2278 * ensure that gtk_drag_finish() is called to let the source know that
2279 * the drop is done. The call to gtk_drag_finish() can be done either
2280 * directly or in a #GtkWidget::drag-data-received handler which gets
2281 * triggered by calling gtk_drag_get_data() to receive the data for one
2282 * or more of the supported targets.
2284 widget_signals[DRAG_DROP] =
2285 g_signal_new (I_("drag-drop"),
2286 G_TYPE_FROM_CLASS (gobject_class),
2288 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2289 _gtk_boolean_handled_accumulator, NULL,
2290 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2292 GDK_TYPE_DRAG_CONTEXT,
2298 * GtkWidget::drag-data-get:
2299 * @widget: the object which received the signal
2300 * @drag_context: the drag context
2301 * @data: the #GtkSelectionData to be filled with the dragged data
2302 * @info: the info that has been registered with the target in the
2304 * @time: the timestamp at which the data was requested
2306 * The ::drag-data-get signal is emitted on the drag source when the drop
2307 * site requests the data which is dragged. It is the responsibility of
2308 * the signal handler to fill @data with the data in the format which
2309 * is indicated by @info. See gtk_selection_data_set() and
2310 * gtk_selection_data_set_text().
2312 widget_signals[DRAG_DATA_GET] =
2313 g_signal_new (I_("drag-data-get"),
2314 G_TYPE_FROM_CLASS (gobject_class),
2316 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2318 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2320 GDK_TYPE_DRAG_CONTEXT,
2321 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2326 * GtkWidget::drag-data-received:
2327 * @widget: the object which received the signal
2328 * @drag_context: the drag context
2329 * @x: where the drop happened
2330 * @y: where the drop happened
2331 * @data: the received data
2332 * @info: the info that has been registered with the target in the
2334 * @time: the timestamp at which the data was received
2336 * The ::drag-data-received signal is emitted on the drop site when the
2337 * dragged data has been received. If the data was received in order to
2338 * determine whether the drop will be accepted, the handler is expected
2339 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2340 * If the data was received in response to a #GtkWidget::drag-drop signal
2341 * (and this is the last target to be received), the handler for this
2342 * signal is expected to process the received data and then call
2343 * gtk_drag_finish(), setting the @success parameter depending on whether
2344 * the data was processed successfully.
2346 * The handler may inspect and modify @drag_context->action before calling
2347 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2348 * following example:
2351 * drag_data_received (GtkWidget *widget,
2352 * GdkDragContext *drag_context,
2355 * GtkSelectionData *data,
2359 * if ((data->length >= 0) && (data->format == 8))
2361 * if (drag_context->action == GDK_ACTION_ASK)
2363 * GtkWidget *dialog;
2366 * dialog = gtk_message_dialog_new (NULL,
2367 * GTK_DIALOG_MODAL |
2368 * GTK_DIALOG_DESTROY_WITH_PARENT,
2370 * GTK_BUTTONS_YES_NO,
2371 * "Move the data ?\n");
2372 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2373 * gtk_widget_destroy (dialog);
2375 * if (response == GTK_RESPONSE_YES)
2376 * drag_context->action = GDK_ACTION_MOVE;
2378 * drag_context->action = GDK_ACTION_COPY;
2381 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2385 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2389 widget_signals[DRAG_DATA_RECEIVED] =
2390 g_signal_new (I_("drag-data-received"),
2391 G_TYPE_FROM_CLASS (gobject_class),
2393 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2395 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2397 GDK_TYPE_DRAG_CONTEXT,
2400 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2405 * GtkWidget::visibility-notify-event:
2406 * @widget: the object which received the signal
2407 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2408 * triggered this signal.
2410 * The ::visibility-notify-event will be emitted when the @widget's window
2411 * is obscured or unobscured.
2413 * To receive this signal the #GdkWindow associated to the widget needs
2414 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2416 * Returns: %TRUE to stop other handlers from being invoked for the event.
2417 * %FALSE to propagate the event further.
2419 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2420 g_signal_new (I_("visibility-notify-event"),
2421 G_TYPE_FROM_CLASS (gobject_class),
2423 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2424 _gtk_boolean_handled_accumulator, NULL,
2425 _gtk_marshal_BOOLEAN__BOXED,
2427 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2430 * GtkWidget::client-event:
2431 * @widget: the object which received the signal
2432 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2435 * The ::client-event will be emitted when the @widget's window
2436 * receives a message (via a ClientMessage event) from another
2439 * Returns: %TRUE to stop other handlers from being invoked for
2440 * the event. %FALSE to propagate the event further.
2442 widget_signals[CLIENT_EVENT] =
2443 g_signal_new (I_("client-event"),
2444 G_TYPE_FROM_CLASS (gobject_class),
2446 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2447 _gtk_boolean_handled_accumulator, NULL,
2448 _gtk_marshal_BOOLEAN__BOXED,
2450 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2453 * GtkWidget::no-expose-event:
2454 * @widget: the object which received the signal
2455 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2458 * The ::no-expose-event will be emitted when the @widget's window is
2459 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2460 * If the source window was partially obscured #GdkEventExpose events will
2461 * be generated for those areas.
2463 * Returns: %TRUE to stop other handlers from being invoked for the event.
2464 * %FALSE to propagate the event further.
2466 widget_signals[NO_EXPOSE_EVENT] =
2467 g_signal_new (I_("no-expose-event"),
2468 G_TYPE_FROM_CLASS (gobject_class),
2470 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2471 _gtk_boolean_handled_accumulator, NULL,
2472 _gtk_marshal_BOOLEAN__BOXED,
2474 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2477 * GtkWidget::window-state-event:
2478 * @widget: the object which received the signal
2479 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2480 * triggered this signal.
2482 * The ::window-state-event will be emitted when the state of the
2483 * toplevel window associated to the @widget changes.
2485 * To receive this signal the #GdkWindow associated to the widget
2486 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2487 * this mask automatically for all new windows.
2489 * Returns: %TRUE to stop other handlers from being invoked for the
2490 * event. %FALSE to propagate the event further.
2492 widget_signals[WINDOW_STATE_EVENT] =
2493 g_signal_new (I_("window-state-event"),
2494 G_TYPE_FROM_CLASS (gobject_class),
2496 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2497 _gtk_boolean_handled_accumulator, NULL,
2498 _gtk_marshal_BOOLEAN__BOXED,
2500 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2503 * GtkWidget::damage-event:
2504 * @widget: the object which received the signal
2505 * @event: the #GdkEventExpose event
2507 * Emitted when a redirected window belonging to @widget gets drawn into.
2508 * The region/area members of the event shows what area of the redirected
2509 * drawable was drawn into.
2511 * Returns: %TRUE to stop other handlers from being invoked for the event.
2512 * %FALSE to propagate the event further.
2516 widget_signals[DAMAGE_EVENT] =
2517 g_signal_new (I_("damage-event"),
2518 G_TYPE_FROM_CLASS (gobject_class),
2521 _gtk_boolean_handled_accumulator, NULL,
2522 _gtk_marshal_BOOLEAN__BOXED,
2524 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2526 * GtkWidget::grab-broken-event:
2527 * @widget: the object which received the signal
2528 * @event: the #GdkEventGrabBroken event
2530 * Emitted when a pointer or keyboard grab on a window belonging
2531 * to @widget gets broken.
2533 * On X11, this happens when the grab window becomes unviewable
2534 * (i.e. it or one of its ancestors is unmapped), or if the same
2535 * application grabs the pointer or keyboard again.
2537 * Returns: %TRUE to stop other handlers from being invoked for
2538 * the event. %FALSE to propagate the event further.
2542 widget_signals[GRAB_BROKEN] =
2543 g_signal_new (I_("grab-broken-event"),
2544 G_TYPE_FROM_CLASS (gobject_class),
2546 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2547 _gtk_boolean_handled_accumulator, NULL,
2548 _gtk_marshal_BOOLEAN__BOXED,
2550 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2552 * GtkWidget::query-tooltip:
2553 * @widget: the object which received the signal
2554 * @x: the x coordinate of the cursor position where the request has
2555 * been emitted, relative to @widget->window
2556 * @y: the y coordinate of the cursor position where the request has
2557 * been emitted, relative to @widget->window
2558 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2559 * @tooltip: a #GtkTooltip
2561 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2562 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2563 * focus in keyboard mode.
2565 * Using the given coordinates, the signal handler should determine
2566 * whether a tooltip should be shown for @widget. If this is the case
2567 * %TRUE should be returned, %FALSE otherwise. Note that if
2568 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2569 * should not be used.
2571 * The signal handler is free to manipulate @tooltip with the therefore
2572 * destined function calls.
2574 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2578 widget_signals[QUERY_TOOLTIP] =
2579 g_signal_new (I_("query-tooltip"),
2580 G_TYPE_FROM_CLASS (gobject_class),
2582 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2583 _gtk_boolean_handled_accumulator, NULL,
2584 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2592 * GtkWidget::popup-menu
2593 * @widget: the object which received the signal
2595 * This signal gets emitted whenever a widget should pop up a context
2596 * menu. This usually happens through the standard key binding mechanism;
2597 * by pressing a certain key while a widget is focused, the user can cause
2598 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2599 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2600 * for an example of how to use this signal.
2602 * Returns: %TRUE if a menu was activated
2604 widget_signals[POPUP_MENU] =
2605 g_signal_new (I_("popup-menu"),
2606 G_TYPE_FROM_CLASS (gobject_class),
2607 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2608 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2609 _gtk_boolean_handled_accumulator, NULL,
2610 _gtk_marshal_BOOLEAN__VOID,
2614 * GtkWidget::show-help:
2615 * @widget: the object which received the signal.
2618 widget_signals[SHOW_HELP] =
2619 g_signal_new (I_("show-help"),
2620 G_TYPE_FROM_CLASS (gobject_class),
2621 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2622 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2623 _gtk_boolean_handled_accumulator, NULL,
2624 _gtk_marshal_BOOLEAN__ENUM,
2626 GTK_TYPE_WIDGET_HELP_TYPE);
2629 * GtkWidget::accel-closures-changed:
2630 * @widget: the object which received the signal.
2632 widget_signals[ACCEL_CLOSURES_CHANGED] =
2633 g_signal_new (I_("accel-closures-changed"),
2634 G_TYPE_FROM_CLASS (gobject_class),
2638 _gtk_marshal_VOID__VOID,
2642 * GtkWidget::screen-changed:
2643 * @widget: the object on which the signal is emitted
2644 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2645 * widget was not associated with a screen before
2647 * The ::screen-changed signal gets emitted when the
2648 * screen of a widget has changed.
2650 widget_signals[SCREEN_CHANGED] =
2651 g_signal_new (I_("screen-changed"),
2652 G_TYPE_FROM_CLASS (gobject_class),
2654 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2656 _gtk_marshal_VOID__OBJECT,
2661 * GtkWidget::can-activate-accel:
2662 * @widget: the object which received the signal
2663 * @signal_id: the ID of a signal installed on @widget
2665 * Determines whether an accelerator that activates the signal
2666 * identified by @signal_id can currently be activated.
2667 * This signal is present to allow applications and derived
2668 * widgets to override the default #GtkWidget handling
2669 * for determining whether an accelerator can be activated.
2671 * Returns: %TRUE if the signal can be activated.
2673 widget_signals[CAN_ACTIVATE_ACCEL] =
2674 g_signal_new (I_("can-activate-accel"),
2675 G_TYPE_FROM_CLASS (gobject_class),
2677 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2678 _gtk_boolean_handled_accumulator, NULL,
2679 _gtk_marshal_BOOLEAN__UINT,
2680 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2682 binding_set = gtk_binding_set_by_class (klass);
2683 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2685 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2688 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2690 GTK_TYPE_WIDGET_HELP_TYPE,
2691 GTK_WIDGET_HELP_TOOLTIP);
2692 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2694 GTK_TYPE_WIDGET_HELP_TYPE,
2695 GTK_WIDGET_HELP_TOOLTIP);
2696 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2698 GTK_TYPE_WIDGET_HELP_TYPE,
2699 GTK_WIDGET_HELP_WHATS_THIS);
2700 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2702 GTK_TYPE_WIDGET_HELP_TYPE,
2703 GTK_WIDGET_HELP_WHATS_THIS);
2705 gtk_widget_class_install_style_property (klass,
2706 g_param_spec_boolean ("interior-focus",
2707 P_("Interior Focus"),
2708 P_("Whether to draw the focus indicator inside widgets"),
2710 GTK_PARAM_READABLE));
2712 gtk_widget_class_install_style_property (klass,
2713 g_param_spec_int ("focus-line-width",
2714 P_("Focus linewidth"),
2715 P_("Width, in pixels, of the focus indicator line"),
2717 GTK_PARAM_READABLE));
2719 gtk_widget_class_install_style_property (klass,
2720 g_param_spec_string ("focus-line-pattern",
2721 P_("Focus line dash pattern"),
2722 P_("Dash pattern used to draw the focus indicator"),
2724 GTK_PARAM_READABLE));
2725 gtk_widget_class_install_style_property (klass,
2726 g_param_spec_int ("focus-padding",
2727 P_("Focus padding"),
2728 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2730 GTK_PARAM_READABLE));
2731 gtk_widget_class_install_style_property (klass,
2732 g_param_spec_boxed ("cursor-color",
2734 P_("Color with which to draw insertion cursor"),
2736 GTK_PARAM_READABLE));
2737 gtk_widget_class_install_style_property (klass,
2738 g_param_spec_boxed ("secondary-cursor-color",
2739 P_("Secondary cursor color"),
2740 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2742 GTK_PARAM_READABLE));
2743 gtk_widget_class_install_style_property (klass,
2744 g_param_spec_float ("cursor-aspect-ratio",
2745 P_("Cursor line aspect ratio"),
2746 P_("Aspect ratio with which to draw insertion cursor"),
2748 GTK_PARAM_READABLE));
2750 gtk_widget_class_install_style_property (klass,
2751 g_param_spec_boolean ("window-dragging",
2752 P_("Window dragging"),
2753 P_("Whether windows can be dragged by clicking on empty areas"),
2755 GTK_PARAM_READABLE));
2758 * GtkWidget:link-color:
2760 * The "link-color" style property defines the color of unvisited links.
2764 gtk_widget_class_install_style_property (klass,
2765 g_param_spec_boxed ("link-color",
2766 P_("Unvisited Link Color"),
2767 P_("Color of unvisited links"),
2769 GTK_PARAM_READABLE));
2772 * GtkWidget:visited-link-color:
2774 * The "visited-link-color" style property defines the color of visited links.
2778 gtk_widget_class_install_style_property (klass,
2779 g_param_spec_boxed ("visited-link-color",
2780 P_("Visited Link Color"),
2781 P_("Color of visited links"),
2783 GTK_PARAM_READABLE));
2786 * GtkWidget:wide-separators:
2788 * The "wide-separators" style property defines whether separators have
2789 * configurable width and should be drawn using a box instead of a line.
2793 gtk_widget_class_install_style_property (klass,
2794 g_param_spec_boolean ("wide-separators",
2795 P_("Wide Separators"),
2796 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2798 GTK_PARAM_READABLE));
2801 * GtkWidget:separator-width:
2803 * The "separator-width" style property defines the width of separators.
2804 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2808 gtk_widget_class_install_style_property (klass,
2809 g_param_spec_int ("separator-width",
2810 P_("Separator Width"),
2811 P_("The width of separators if wide-separators is TRUE"),
2813 GTK_PARAM_READABLE));
2816 * GtkWidget:separator-height:
2818 * The "separator-height" style property defines the height of separators.
2819 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2823 gtk_widget_class_install_style_property (klass,
2824 g_param_spec_int ("separator-height",
2825 P_("Separator Height"),
2826 P_("The height of separators if \"wide-separators\" is TRUE"),
2828 GTK_PARAM_READABLE));
2831 * GtkWidget:scroll-arrow-hlength:
2833 * The "scroll-arrow-hlength" style property defines the length of
2834 * horizontal scroll arrows.
2838 gtk_widget_class_install_style_property (klass,
2839 g_param_spec_int ("scroll-arrow-hlength",
2840 P_("Horizontal Scroll Arrow Length"),
2841 P_("The length of horizontal scroll arrows"),
2843 GTK_PARAM_READABLE));
2846 * GtkWidget:scroll-arrow-vlength:
2848 * The "scroll-arrow-vlength" style property defines the length of
2849 * vertical scroll arrows.
2853 gtk_widget_class_install_style_property (klass,
2854 g_param_spec_int ("scroll-arrow-vlength",
2855 P_("Vertical Scroll Arrow Length"),
2856 P_("The length of vertical scroll arrows"),
2858 GTK_PARAM_READABLE));
2860 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2864 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2868 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2869 for (node = list; node; node = node->next)
2871 GParamSpec *pspec = node->data;
2873 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2874 g_param_spec_unref (pspec);
2880 gtk_widget_set_property (GObject *object,
2882 const GValue *value,
2885 GtkWidget *widget = GTK_WIDGET (object);
2890 gchar *tooltip_markup;
2891 const gchar *tooltip_text;
2892 GtkWindow *tooltip_window;
2895 gtk_widget_set_name (widget, g_value_get_string (value));
2898 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2900 case PROP_WIDTH_REQUEST:
2901 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2903 case PROP_HEIGHT_REQUEST:
2904 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2907 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2909 case PROP_SENSITIVE:
2910 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2912 case PROP_APP_PAINTABLE:
2913 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2915 case PROP_CAN_FOCUS:
2916 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2918 case PROP_HAS_FOCUS:
2919 if (g_value_get_boolean (value))
2920 gtk_widget_grab_focus (widget);
2923 if (g_value_get_boolean (value))
2924 gtk_widget_grab_focus (widget);
2926 case PROP_CAN_DEFAULT:
2927 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2929 case PROP_HAS_DEFAULT:
2930 if (g_value_get_boolean (value))
2931 gtk_widget_grab_default (widget);
2933 case PROP_RECEIVES_DEFAULT:
2934 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2937 gtk_widget_set_style (widget, g_value_get_object (value));
2940 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2941 gtk_widget_set_events (widget, g_value_get_flags (value));
2943 case PROP_EXTENSION_EVENTS:
2944 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2946 case PROP_NO_SHOW_ALL:
2947 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2949 case PROP_HAS_TOOLTIP:
2950 gtk_widget_real_set_has_tooltip (widget,
2951 g_value_get_boolean (value), FALSE);
2953 case PROP_TOOLTIP_MARKUP:
2954 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2955 tooltip_markup = g_value_dup_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_markup && (strlen (tooltip_markup) == 0))
2962 g_free (tooltip_markup);
2963 tooltip_markup = NULL;
2966 g_object_set_qdata_full (object, quark_tooltip_markup,
2967 tooltip_markup, g_free);
2969 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2970 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2971 if (gtk_widget_get_visible (widget))
2972 gtk_widget_queue_tooltip_query (widget);
2974 case PROP_TOOLTIP_TEXT:
2975 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2977 tooltip_text = g_value_get_string (value);
2979 /* Treat an empty string as a NULL string,
2980 * because an empty string would be useless for a tooltip:
2982 if (tooltip_text && (strlen (tooltip_text) == 0))
2983 tooltip_text = NULL;
2985 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2987 g_object_set_qdata_full (object, quark_tooltip_markup,
2988 tooltip_markup, g_free);
2990 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2991 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2992 if (gtk_widget_get_visible (widget))
2993 gtk_widget_queue_tooltip_query (widget);
2995 case PROP_DOUBLE_BUFFERED:
2996 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2999 gtk_widget_set_halign (widget, g_value_get_enum (value));
3002 gtk_widget_set_valign (widget, g_value_get_enum (value));
3004 case PROP_MARGIN_LEFT:
3005 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3007 case PROP_MARGIN_RIGHT:
3008 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3010 case PROP_MARGIN_TOP:
3011 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3013 case PROP_MARGIN_BOTTOM:
3014 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3017 g_object_freeze_notify (G_OBJECT (widget));
3018 gtk_widget_set_margin_left (widget, g_value_get_int (value));
3019 gtk_widget_set_margin_right (widget, g_value_get_int (value));
3020 gtk_widget_set_margin_top (widget, g_value_get_int (value));
3021 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3022 g_object_thaw_notify (G_OBJECT (widget));
3025 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3031 gtk_widget_get_property (GObject *object,
3036 GtkWidget *widget = GTK_WIDGET (object);
3037 GtkWidgetPrivate *priv = widget->priv;
3046 g_value_set_string (value, priv->name);
3048 g_value_set_static_string (value, "");
3051 g_value_set_object (value, priv->parent);
3053 case PROP_WIDTH_REQUEST:
3056 gtk_widget_get_size_request (widget, &w, NULL);
3057 g_value_set_int (value, w);
3060 case PROP_HEIGHT_REQUEST:
3063 gtk_widget_get_size_request (widget, NULL, &h);
3064 g_value_set_int (value, h);
3068 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3070 case PROP_SENSITIVE:
3071 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3073 case PROP_APP_PAINTABLE:
3074 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3076 case PROP_CAN_FOCUS:
3077 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3079 case PROP_HAS_FOCUS:
3080 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3083 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3085 case PROP_CAN_DEFAULT:
3086 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3088 case PROP_HAS_DEFAULT:
3089 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3091 case PROP_RECEIVES_DEFAULT:
3092 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3094 case PROP_COMPOSITE_CHILD:
3095 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3098 g_value_set_object (value, gtk_widget_get_style (widget));
3101 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3102 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3104 case PROP_EXTENSION_EVENTS:
3105 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3106 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3108 case PROP_NO_SHOW_ALL:
3109 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3111 case PROP_HAS_TOOLTIP:
3112 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3114 case PROP_TOOLTIP_TEXT:
3116 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3119 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3120 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3122 g_value_take_string (value, text);
3125 case PROP_TOOLTIP_MARKUP:
3126 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3129 g_value_set_object (value, gtk_widget_get_window (widget));
3131 case PROP_DOUBLE_BUFFERED:
3132 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3135 g_value_set_enum (value, gtk_widget_get_halign (widget));
3138 g_value_set_enum (value, gtk_widget_get_valign (widget));
3140 case PROP_MARGIN_LEFT:
3141 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3143 case PROP_MARGIN_RIGHT:
3144 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3146 case PROP_MARGIN_TOP:
3147 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3149 case PROP_MARGIN_BOTTOM:
3150 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3154 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3155 if (aux_info == NULL)
3157 g_value_set_int (value, 0);
3161 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3162 aux_info->margin.right),
3163 MAX (aux_info->margin.top,
3164 aux_info->margin.bottom)));
3169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3175 gtk_widget_init (GtkWidget *widget)
3177 GtkWidgetPrivate *priv;
3179 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3182 priv = widget->priv;
3184 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3185 priv->state = GTK_STATE_NORMAL;
3186 priv->saved_state = GTK_STATE_NORMAL;
3188 priv->allocation.x = -1;
3189 priv->allocation.y = -1;
3190 priv->allocation.width = 1;
3191 priv->allocation.height = 1;
3192 priv->window = NULL;
3193 priv->parent = NULL;
3195 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3196 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3197 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3198 gtk_widget_set_double_buffered (widget, TRUE);
3200 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3201 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3202 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3203 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3205 priv->style = gtk_widget_get_default_style ();
3206 g_object_ref (priv->style);
3211 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3213 GParamSpec **pspecs)
3215 GtkWidgetPrivate *priv = widget->priv;
3216 GtkWidget *container = priv->parent;
3219 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3220 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3224 * gtk_widget_freeze_child_notify:
3225 * @widget: a #GtkWidget
3227 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3228 * signals are queued until gtk_widget_thaw_child_notify() is called
3231 * This is the analogue of g_object_freeze_notify() for child properties.
3234 gtk_widget_freeze_child_notify (GtkWidget *widget)
3236 g_return_if_fail (GTK_IS_WIDGET (widget));
3238 if (!G_OBJECT (widget)->ref_count)
3241 g_object_ref (widget);
3242 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3243 g_object_unref (widget);
3247 * gtk_widget_child_notify:
3248 * @widget: a #GtkWidget
3249 * @child_property: the name of a child property installed on the
3250 * class of @widget<!-- -->'s parent
3252 * Emits a #GtkWidget::child-notify signal for the
3253 * <link linkend="child-properties">child property</link> @child_property
3256 * This is the analogue of g_object_notify() for child properties.
3259 gtk_widget_child_notify (GtkWidget *widget,
3260 const gchar *child_property)
3262 GtkWidgetPrivate *priv = widget->priv;
3265 g_return_if_fail (GTK_IS_WIDGET (widget));
3266 g_return_if_fail (child_property != NULL);
3267 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3270 g_object_ref (widget);
3271 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3273 G_OBJECT_TYPE (priv->parent),
3276 g_warning ("%s: container class `%s' has no child property named `%s'",
3278 G_OBJECT_TYPE_NAME (priv->parent),
3282 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3284 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3285 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3287 g_object_unref (widget);
3291 * gtk_widget_thaw_child_notify:
3292 * @widget: a #GtkWidget
3294 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3295 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3299 gtk_widget_thaw_child_notify (GtkWidget *widget)
3301 GObjectNotifyQueue *nqueue;
3303 g_return_if_fail (GTK_IS_WIDGET (widget));
3305 if (!G_OBJECT (widget)->ref_count)
3308 g_object_ref (widget);
3309 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3310 if (!nqueue || !nqueue->freeze_count)
3311 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3312 G_OBJECT_TYPE_NAME (widget), widget);
3314 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3315 g_object_unref (widget);
3321 * @type: type ID of the widget to create
3322 * @first_property_name: name of first property to set
3323 * @Varargs: value of first property, followed by more properties,
3326 * This is a convenience function for creating a widget and setting
3327 * its properties in one go. For example you might write:
3328 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3329 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3330 * g_object_new(), but returns a widget so you don't have to
3331 * cast the object yourself.
3333 * Return value: a new #GtkWidget of type @widget_type
3336 gtk_widget_new (GType type,
3337 const gchar *first_property_name,
3343 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3345 va_start (var_args, first_property_name);
3346 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3353 gtk_widget_queue_draw_child (GtkWidget *widget)
3355 GtkWidgetPrivate *priv = widget->priv;
3358 parent = priv->parent;
3359 if (parent && gtk_widget_is_drawable (parent))
3360 gtk_widget_queue_draw_area (parent,
3363 priv->allocation.width,
3364 priv->allocation.height);
3368 * gtk_widget_unparent:
3369 * @widget: a #GtkWidget
3371 * This function is only for use in widget implementations.
3372 * Should be called by implementations of the remove method
3373 * on #GtkContainer, to dissociate a child from the container.
3376 gtk_widget_unparent (GtkWidget *widget)
3378 GtkWidgetPrivate *priv;
3379 GObjectNotifyQueue *nqueue;
3380 GtkWidget *toplevel;
3381 GtkWidget *old_parent;
3383 g_return_if_fail (GTK_IS_WIDGET (widget));
3385 priv = widget->priv;
3387 if (priv->parent == NULL)
3390 /* keep this function in sync with gtk_menu_detach()
3393 g_object_freeze_notify (G_OBJECT (widget));
3394 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3396 toplevel = gtk_widget_get_toplevel (widget);
3397 if (gtk_widget_is_toplevel (toplevel))
3398 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3400 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3401 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3403 /* If we are unanchoring the child, we save around the toplevel
3404 * to emit hierarchy changed
3406 if (GTK_WIDGET_ANCHORED (priv->parent))
3407 g_object_ref (toplevel);
3411 gtk_widget_queue_draw_child (widget);
3413 /* Reset the width and height here, to force reallocation if we
3414 * get added back to a new parent. This won't work if our new
3415 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3416 * (would 0x0 be OK here?)
3418 priv->allocation.width = 1;
3419 priv->allocation.height = 1;
3421 if (gtk_widget_get_realized (widget))
3423 if (GTK_WIDGET_IN_REPARENT (widget))
3424 gtk_widget_unmap (widget);
3426 gtk_widget_unrealize (widget);
3429 /* Removing a widget from a container restores the child visible
3430 * flag to the default state, so it doesn't affect the child
3431 * in the next parent.
3433 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3435 old_parent = priv->parent;
3436 priv->parent = NULL;
3437 gtk_widget_set_parent_window (widget, NULL);
3438 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3441 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3442 g_object_unref (toplevel);
3445 g_object_notify (G_OBJECT (widget), "parent");
3446 g_object_thaw_notify (G_OBJECT (widget));
3448 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3449 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3450 g_object_unref (widget);
3454 * gtk_widget_destroy:
3455 * @widget: a #GtkWidget
3457 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3458 * you don't have to cast the widget to #GtkObject. When a widget is
3459 * destroyed, it will break any references it holds to other objects.
3460 * If the widget is inside a container, the widget will be removed
3461 * from the container. If the widget is a toplevel (derived from
3462 * #GtkWindow), it will be removed from the list of toplevels, and the
3463 * reference GTK+ holds to it will be removed. Removing a
3464 * widget from its container or the list of toplevels results in the
3465 * widget being finalized, unless you've added additional references
3466 * to the widget with g_object_ref().
3468 * In most cases, only toplevel widgets (windows) require explicit
3469 * destruction, because when you destroy a toplevel its children will
3470 * be destroyed as well.
3473 gtk_widget_destroy (GtkWidget *widget)
3475 g_return_if_fail (GTK_IS_WIDGET (widget));
3477 gtk_object_destroy ((GtkObject*) widget);
3481 * gtk_widget_destroyed:
3482 * @widget: a #GtkWidget
3483 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3485 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3486 * %NULL. It's intended to be used as a callback connected to the
3487 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3488 * as a signal handler, and pass the address of your widget variable
3489 * as user data. Then when the widget is destroyed, the variable will
3490 * be set to %NULL. Useful for example to avoid multiple copies
3491 * of the same dialog.
3494 gtk_widget_destroyed (GtkWidget *widget,
3495 GtkWidget **widget_pointer)
3497 /* Don't make any assumptions about the
3499 * Even check widget_pointer.
3502 *widget_pointer = NULL;
3507 * @widget: a #GtkWidget
3509 * Flags a widget to be displayed. Any widget that isn't shown will
3510 * not appear on the screen. If you want to show all the widgets in a
3511 * container, it's easier to call gtk_widget_show_all() on the
3512 * container, instead of individually showing the widgets.
3514 * Remember that you have to show the containers containing a widget,
3515 * in addition to the widget itself, before it will appear onscreen.
3517 * When a toplevel container is shown, it is immediately realized and
3518 * mapped; other shown widgets are realized and mapped when their
3519 * toplevel container is realized and mapped.
3522 gtk_widget_show (GtkWidget *widget)
3524 g_return_if_fail (GTK_IS_WIDGET (widget));
3526 if (!gtk_widget_get_visible (widget))
3528 g_object_ref (widget);
3529 if (!gtk_widget_is_toplevel (widget))
3530 gtk_widget_queue_resize (widget);
3531 g_signal_emit (widget, widget_signals[SHOW], 0);
3532 g_object_notify (G_OBJECT (widget), "visible");
3533 g_object_unref (widget);
3538 gtk_widget_real_show (GtkWidget *widget)
3540 GtkWidgetPrivate *priv = widget->priv;
3542 if (!gtk_widget_get_visible (widget))
3544 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3547 gtk_widget_get_mapped (priv->parent) &&
3548 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3549 !gtk_widget_get_mapped (widget))
3550 gtk_widget_map (widget);
3555 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3558 g_signal_handlers_disconnect_by_func (widget,
3559 gtk_widget_show_map_callback,
3564 * gtk_widget_show_now:
3565 * @widget: a #GtkWidget
3567 * Shows a widget. If the widget is an unmapped toplevel widget
3568 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3569 * loop and wait for the window to actually be mapped. Be careful;
3570 * because the main loop is running, anything can happen during
3574 gtk_widget_show_now (GtkWidget *widget)
3578 g_return_if_fail (GTK_IS_WIDGET (widget));
3580 /* make sure we will get event */
3581 if (!gtk_widget_get_mapped (widget) &&
3582 gtk_widget_is_toplevel (widget))
3584 gtk_widget_show (widget);
3586 g_signal_connect (widget, "map-event",
3587 G_CALLBACK (gtk_widget_show_map_callback),
3591 gtk_main_iteration ();
3594 gtk_widget_show (widget);
3599 * @widget: a #GtkWidget
3601 * Reverses the effects of gtk_widget_show(), causing the widget to be
3602 * hidden (invisible to the user).
3605 gtk_widget_hide (GtkWidget *widget)
3607 g_return_if_fail (GTK_IS_WIDGET (widget));
3609 if (gtk_widget_get_visible (widget))
3611 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3613 g_object_ref (widget);
3614 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3615 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3617 g_signal_emit (widget, widget_signals[HIDE], 0);
3618 if (!gtk_widget_is_toplevel (widget))
3619 gtk_widget_queue_resize (widget);
3620 g_object_notify (G_OBJECT (widget), "visible");
3621 g_object_unref (widget);
3626 gtk_widget_real_hide (GtkWidget *widget)
3628 if (gtk_widget_get_visible (widget))
3630 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3632 if (gtk_widget_get_mapped (widget))
3633 gtk_widget_unmap (widget);
3638 * gtk_widget_hide_on_delete:
3639 * @widget: a #GtkWidget
3641 * Utility function; intended to be connected to the #GtkWidget::delete-event
3642 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3643 * argument, then returns %TRUE. If connected to ::delete-event, the
3644 * result is that clicking the close button for a window (on the
3645 * window frame, top right corner usually) will hide but not destroy
3646 * the window. By default, GTK+ destroys windows when ::delete-event
3649 * Return value: %TRUE
3652 gtk_widget_hide_on_delete (GtkWidget *widget)
3654 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3656 gtk_widget_hide (widget);
3662 * gtk_widget_show_all:
3663 * @widget: a #GtkWidget
3665 * Recursively shows a widget, and any child widgets (if the widget is
3669 gtk_widget_show_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->show_all)
3681 class->show_all (widget);
3685 * gtk_widget_hide_all:
3686 * @widget: a #GtkWidget
3688 * Recursively hides a widget and any child widgets.
3691 gtk_widget_hide_all (GtkWidget *widget)
3693 GtkWidgetClass *class;
3695 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 if (gtk_widget_get_no_show_all (widget))
3700 class = GTK_WIDGET_GET_CLASS (widget);
3702 if (class->hide_all)
3703 class->hide_all (widget);
3708 * @widget: a #GtkWidget
3710 * This function is only for use in widget implementations. Causes
3711 * a widget to be mapped if it isn't already.
3714 gtk_widget_map (GtkWidget *widget)
3716 GtkWidgetPrivate *priv;
3718 g_return_if_fail (GTK_IS_WIDGET (widget));
3719 g_return_if_fail (gtk_widget_get_visible (widget));
3720 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3722 priv = widget->priv;
3724 if (!gtk_widget_get_mapped (widget))
3726 if (!gtk_widget_get_realized (widget))
3727 gtk_widget_realize (widget);
3729 g_signal_emit (widget, widget_signals[MAP], 0);
3731 if (!gtk_widget_get_has_window (widget))
3732 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3738 * @widget: a #GtkWidget
3740 * This function is only for use in widget implementations. Causes
3741 * a widget to be unmapped if it's currently mapped.
3744 gtk_widget_unmap (GtkWidget *widget)
3746 GtkWidgetPrivate *priv;
3748 g_return_if_fail (GTK_IS_WIDGET (widget));
3750 priv = widget->priv;
3752 if (gtk_widget_get_mapped (widget))
3754 if (!gtk_widget_get_has_window (widget))
3755 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3756 _gtk_tooltip_hide (widget);
3757 g_signal_emit (widget, widget_signals[UNMAP], 0);
3762 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3763 GdkExtensionMode mode,
3766 GtkWidgetPrivate *priv = widget->priv;
3767 GList *free_list = NULL;
3770 if (window_list == NULL)
3772 if (gtk_widget_get_has_window (widget))
3773 window_list = g_list_prepend (NULL, priv->window);
3775 window_list = gdk_window_get_children (priv->window);
3777 free_list = window_list;
3780 for (l = window_list; l != NULL; l = l->next)
3782 GdkWindow *window = l->data;
3785 gdk_window_get_user_data (window, &user_data);
3786 if (user_data == widget)
3790 gdk_input_set_extension_events (window,
3791 gdk_window_get_events (window),
3794 children = gdk_window_get_children (window);
3797 gtk_widget_set_extension_events_internal (widget, mode, children);
3798 g_list_free (children);
3804 g_list_free (free_list);
3808 _gtk_widget_enable_device_events (GtkWidget *widget)
3810 GHashTable *device_events;
3811 GHashTableIter iter;
3812 gpointer key, value;
3814 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3819 g_hash_table_iter_init (&iter, device_events);
3821 while (g_hash_table_iter_next (&iter, &key, &value))
3824 GdkEventMask event_mask;
3827 event_mask = GPOINTER_TO_UINT (value);
3828 gtk_widget_add_events_internal (widget, device, event_mask);
3833 * gtk_widget_realize:
3834 * @widget: a #GtkWidget
3836 * Creates the GDK (windowing system) resources associated with a
3837 * widget. For example, @widget->window will be created when a widget
3838 * is realized. Normally realization happens implicitly; if you show
3839 * a widget and all its parent containers, then the widget will be
3840 * realized and mapped automatically.
3842 * Realizing a widget requires all
3843 * the widget's parent widgets to be realized; calling
3844 * gtk_widget_realize() realizes the widget's parents in addition to
3845 * @widget itself. If a widget is not yet inside a toplevel window
3846 * when you realize it, bad things will happen.
3848 * This function is primarily used in widget implementations, and
3849 * isn't very useful otherwise. Many times when you think you might
3850 * need it, a better approach is to connect to a signal that will be
3851 * called after the widget is realized automatically, such as
3852 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3853 * GtkWidget::realize signal.
3856 gtk_widget_realize (GtkWidget *widget)
3858 GtkWidgetPrivate *priv;
3859 GdkExtensionMode mode;
3860 cairo_region_t *region;
3862 g_return_if_fail (GTK_IS_WIDGET (widget));
3863 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3864 GTK_IS_INVISIBLE (widget));
3866 priv = widget->priv;
3868 if (!gtk_widget_get_realized (widget))
3871 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3872 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3875 if (priv->parent == NULL &&
3876 !gtk_widget_is_toplevel (widget))
3877 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3878 "inside a toplevel window is not going to work very well. "
3879 "Widgets must be inside a toplevel container before realizing them.");
3881 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3882 gtk_widget_realize (priv->parent);
3884 gtk_widget_ensure_style (widget);
3886 g_signal_emit (widget, widget_signals[REALIZE], 0);
3888 gtk_widget_real_set_has_tooltip (widget,
3889 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3892 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3894 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3895 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3898 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3900 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3902 mode = gtk_widget_get_extension_events (widget);
3903 if (mode != GDK_EXTENSION_EVENTS_NONE)
3904 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3906 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3907 gdk_window_set_support_multidevice (priv->window, TRUE);
3909 _gtk_widget_enable_device_events (widget);
3914 * gtk_widget_unrealize:
3915 * @widget: a #GtkWidget
3917 * This function is only useful in widget implementations.
3918 * Causes a widget to be unrealized (frees all GDK resources
3919 * associated with the widget, such as @widget->window).
3922 gtk_widget_unrealize (GtkWidget *widget)
3924 g_return_if_fail (GTK_IS_WIDGET (widget));
3926 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3927 gtk_widget_shape_combine_region (widget, NULL);
3929 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3930 gtk_widget_input_shape_combine_region (widget, NULL);
3932 if (gtk_widget_get_realized (widget))
3934 g_object_ref (widget);
3935 _gtk_tooltip_hide (widget);
3936 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3937 gtk_widget_set_realized (widget, FALSE);
3938 gtk_widget_set_mapped (widget, FALSE);
3939 g_object_unref (widget);
3943 /*****************************************
3945 *****************************************/
3948 * gtk_widget_queue_draw_area:
3949 * @widget: a #GtkWidget
3950 * @x: x coordinate of upper-left corner of rectangle to redraw
3951 * @y: y coordinate of upper-left corner of rectangle to redraw
3952 * @width: width of region to draw
3953 * @height: height of region to draw
3955 * Invalidates the rectangular area of @widget defined by @x, @y,
3956 * @width and @height by calling gdk_window_invalidate_rect() on the
3957 * widget's window and all its child windows. Once the main loop
3958 * becomes idle (after the current batch of events has been processed,
3959 * roughly), the window will receive expose events for the union of
3960 * all regions that have been invalidated.
3962 * Normally you would only use this function in widget
3963 * implementations. You might also use it, or
3964 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3965 * #GtkDrawingArea or some portion thereof.
3967 * Frequently you can just call gdk_window_invalidate_rect() or
3968 * gdk_window_invalidate_region() instead of this function. Those
3969 * functions will invalidate only a single window, instead of the
3970 * widget and all its children.
3972 * The advantage of adding to the invalidated region compared to
3973 * simply drawing immediately is efficiency; using an invalid region
3974 * ensures that you only have to redraw one time.
3977 gtk_widget_queue_draw_area (GtkWidget *widget,
3983 GtkWidgetPrivate *priv;
3984 GdkRectangle invalid_rect;
3987 g_return_if_fail (GTK_IS_WIDGET (widget));
3989 priv = widget->priv;
3991 if (!gtk_widget_get_realized (widget))
3994 /* Just return if the widget or one of its ancestors isn't mapped */
3995 for (w = widget; w != NULL; w = w->priv->parent)
3996 if (!gtk_widget_get_mapped (w))
3999 /* Find the correct widget */
4001 if (gtk_widget_get_has_window (widget))
4005 /* Translate widget relative to window-relative */
4007 gint wx, wy, wwidth, wheight;
4009 gdk_window_get_position (priv->window, &wx, &wy);
4010 x -= wx - priv->allocation.x;
4011 y -= wy - priv->allocation.y;
4013 gdk_drawable_get_size (priv->window, &wwidth, &wheight);
4015 if (x + width <= 0 || y + height <= 0 ||
4016 x >= wwidth || y >= wheight)
4027 if (x + width > wwidth)
4029 if (y + height > wheight)
4030 height = wheight - y;
4036 invalid_rect.width = width;
4037 invalid_rect.height = height;
4039 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4043 * gtk_widget_queue_draw:
4044 * @widget: a #GtkWidget
4046 * Equivalent to calling gtk_widget_queue_draw_area() for the
4047 * entire area of a widget.
4050 gtk_widget_queue_draw (GtkWidget *widget)
4054 g_return_if_fail (GTK_IS_WIDGET (widget));
4056 gtk_widget_get_allocation (widget, &rect);
4058 if (!gtk_widget_get_has_window (widget))
4059 gtk_widget_queue_draw_area (widget,
4060 rect.x, rect.y, rect.width, rect.height);
4062 gtk_widget_queue_draw_area (widget,
4063 0, 0, rect.width, rect.height);
4067 * gtk_widget_queue_resize:
4068 * @widget: a #GtkWidget
4070 * This function is only for use in widget implementations.
4071 * Flags a widget to have its size renegotiated; should
4072 * be called when a widget for some reason has a new size request.
4073 * For example, when you change the text in a #GtkLabel, #GtkLabel
4074 * queues a resize to ensure there's enough space for the new text.
4077 gtk_widget_queue_resize (GtkWidget *widget)
4079 g_return_if_fail (GTK_IS_WIDGET (widget));
4081 if (gtk_widget_get_realized (widget))
4082 gtk_widget_queue_shallow_draw (widget);
4084 _gtk_size_group_queue_resize (widget);
4088 * gtk_widget_queue_resize_no_redraw:
4089 * @widget: a #GtkWidget
4091 * This function works like gtk_widget_queue_resize(),
4092 * except that the widget is not invalidated.
4097 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4099 g_return_if_fail (GTK_IS_WIDGET (widget));
4101 _gtk_size_group_queue_resize (widget);
4105 * gtk_widget_size_request:
4106 * @widget: a #GtkWidget
4107 * @requisition: (out): a #GtkRequisition to be filled in
4109 * This function is typically used when implementing a #GtkContainer
4110 * subclass. Obtains the preferred size of a widget. The container
4111 * uses this information to arrange its child widgets and decide what
4112 * size allocations to give them with gtk_widget_size_allocate().
4114 * You can also call this function from an application, with some
4115 * caveats. Most notably, getting a size request requires the widget
4116 * to be associated with a screen, because font information may be
4117 * needed. Multihead-aware applications should keep this in mind.
4119 * Also remember that the size request is not necessarily the size
4120 * a widget will actually be allocated.
4122 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4125 gtk_widget_size_request (GtkWidget *widget,
4126 GtkRequisition *requisition)
4128 g_return_if_fail (GTK_IS_WIDGET (widget));
4130 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4134 * gtk_widget_get_child_requisition:
4135 * @widget: a #GtkWidget
4136 * @requisition: (out): a #GtkRequisition to be filled in
4138 * This function is only for use in widget implementations. Obtains
4139 * @widget->requisition, unless someone has forced a particular
4140 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4141 * in which case it returns that geometry instead of the widget's
4144 * This function differs from gtk_widget_size_request() in that
4145 * it retrieves the last size request value from @widget->requisition,
4146 * while gtk_widget_size_request() actually calls the "size_request" method
4147 * on @widget to compute the size request and fill in @widget->requisition,
4148 * and only then returns @widget->requisition.
4150 * Because this function does not call the "size_request" method, it
4151 * can only be used when you know that @widget->requisition is
4152 * up-to-date, that is, gtk_widget_size_request() has been called
4153 * since the last time a resize was queued. In general, only container
4154 * implementations have this information; applications should use
4155 * gtk_widget_size_request().
4158 * Deprecated: 3.0: Use gtk_size_request_get_size() instead.
4161 gtk_widget_get_child_requisition (GtkWidget *widget,
4162 GtkRequisition *requisition)
4164 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
4168 invalidate_predicate (GdkWindow *window,
4173 gdk_window_get_user_data (window, &user_data);
4175 return (user_data == data);
4178 /* Invalidate @region in widget->window and all children
4179 * of widget->window owned by widget. @region is in the
4180 * same coordinates as widget->allocation and will be
4181 * modified by this call.
4184 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4185 cairo_region_t *region)
4187 GtkWidgetPrivate *priv = widget->priv;
4189 if (!gtk_widget_get_realized (widget))
4192 if (gtk_widget_get_has_window (widget) && priv->parent)
4196 gdk_window_get_position (priv->window, &x, &y);
4197 cairo_region_translate (region, -x, -y);
4200 gdk_window_invalidate_maybe_recurse (priv->window, region,
4201 invalidate_predicate, widget);
4205 * gtk_widget_queue_shallow_draw:
4206 * @widget: a #GtkWidget
4208 * Like gtk_widget_queue_draw(), but only windows owned
4209 * by @widget are invalidated.
4212 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4215 cairo_region_t *region;
4217 if (!gtk_widget_get_realized (widget))
4220 gtk_widget_get_allocation (widget, &rect);
4222 region = cairo_region_create_rectangle (&rect);
4223 gtk_widget_invalidate_widget_windows (widget, region);
4224 cairo_region_destroy (region);
4228 * gtk_widget_size_allocate:
4229 * @widget: a #GtkWidget
4230 * @allocation: (inout): position and size to be allocated to @widget
4232 * This function is only used by #GtkContainer subclasses, to assign a size
4233 * and position to their child widgets.
4235 * In this function, the allocation may be adjusted. It will be forced
4236 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4237 * method on the child will be used to adjust the allocation. Standard
4238 * adjustments include removing the widget's margins, and applying the
4239 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4242 gtk_widget_size_allocate (GtkWidget *widget,
4243 GtkAllocation *allocation)
4245 GtkWidgetPrivate *priv;
4246 GdkRectangle real_allocation;
4247 GdkRectangle old_allocation;
4248 GdkRectangle adjusted_allocation;
4249 gboolean alloc_needed;
4250 gboolean size_changed;
4251 gboolean position_changed;
4253 priv = widget->priv;
4255 g_return_if_fail (GTK_IS_WIDGET (widget));
4257 #ifdef G_ENABLE_DEBUG
4258 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4269 parent = gtk_widget_get_parent (parent);
4272 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4273 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4274 2 * depth, " ", name,
4275 allocation->width, allocation->height);
4277 #endif /* G_ENABLE_DEBUG */
4279 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4280 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4281 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4282 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4284 old_allocation = priv->allocation;
4285 real_allocation = *allocation;
4287 adjusted_allocation = real_allocation;
4288 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4290 if (adjusted_allocation.x < real_allocation.x ||
4291 adjusted_allocation.y < real_allocation.y ||
4292 (adjusted_allocation.x + adjusted_allocation.width) >
4293 (real_allocation.x + real_allocation.width) ||
4294 (adjusted_allocation.y + adjusted_allocation.height >
4295 real_allocation.y + real_allocation.height))
4297 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",
4298 G_OBJECT_TYPE_NAME (widget), widget,
4299 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4300 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4301 adjusted_allocation = real_allocation; /* veto it */
4305 real_allocation = adjusted_allocation;
4308 if (real_allocation.width < 0 || real_allocation.height < 0)
4310 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4311 real_allocation.width,
4312 real_allocation.height);
4315 real_allocation.width = MAX (real_allocation.width, 1);
4316 real_allocation.height = MAX (real_allocation.height, 1);
4318 size_changed = (old_allocation.width != real_allocation.width ||
4319 old_allocation.height != real_allocation.height);
4320 position_changed = (old_allocation.x != real_allocation.x ||
4321 old_allocation.y != real_allocation.y);
4323 if (!alloc_needed && !size_changed && !position_changed)
4326 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4328 if (gtk_widget_get_mapped (widget))
4330 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4332 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4334 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4335 cairo_region_union_rectangle (invalidate, &old_allocation);
4337 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4338 cairo_region_destroy (invalidate);
4343 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4345 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4347 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4348 cairo_region_union_rectangle (invalidate, &old_allocation);
4350 gtk_widget_invalidate_widget_windows (widget, invalidate);
4351 cairo_region_destroy (invalidate);
4356 if ((size_changed || position_changed) && priv->parent &&
4357 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4359 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4360 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4361 cairo_region_destroy (invalidate);
4366 * gtk_widget_common_ancestor:
4367 * @widget_a: a #GtkWidget
4368 * @widget_b: a #GtkWidget
4370 * Find the common ancestor of @widget_a and @widget_b that
4371 * is closest to the two widgets.
4373 * Return value: the closest common ancestor of @widget_a and
4374 * @widget_b or %NULL if @widget_a and @widget_b do not
4375 * share a common ancestor.
4378 gtk_widget_common_ancestor (GtkWidget *widget_a,
4379 GtkWidget *widget_b)
4381 GtkWidget *parent_a;
4382 GtkWidget *parent_b;
4386 parent_a = widget_a;
4387 while (parent_a->priv->parent)
4389 parent_a = parent_a->priv->parent;
4393 parent_b = widget_b;
4394 while (parent_b->priv->parent)
4396 parent_b = parent_b->priv->parent;
4400 if (parent_a != parent_b)
4403 while (depth_a > depth_b)
4405 widget_a = widget_a->priv->parent;
4409 while (depth_b > depth_a)
4411 widget_b = widget_b->priv->parent;
4415 while (widget_a != widget_b)
4417 widget_a = widget_a->priv->parent;
4418 widget_b = widget_b->priv->parent;
4425 * gtk_widget_translate_coordinates:
4426 * @src_widget: a #GtkWidget
4427 * @dest_widget: a #GtkWidget
4428 * @src_x: X position relative to @src_widget
4429 * @src_y: Y position relative to @src_widget
4430 * @dest_x: (out): location to store X position relative to @dest_widget
4431 * @dest_y: (out): location to store Y position relative to @dest_widget
4433 * Translate coordinates relative to @src_widget's allocation to coordinates
4434 * relative to @dest_widget's allocations. In order to perform this
4435 * operation, both widgets must be realized, and must share a common
4438 * Return value: %FALSE if either widget was not realized, or there
4439 * was no common ancestor. In this case, nothing is stored in
4440 * *@dest_x and *@dest_y. Otherwise %TRUE.
4443 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4444 GtkWidget *dest_widget,
4450 GtkWidgetPrivate *src_priv = src_widget->priv;
4451 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4452 GtkWidget *ancestor;
4454 GList *dest_list = NULL;
4456 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4457 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4459 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4460 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4463 /* Translate from allocation relative to window relative */
4464 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4467 gdk_window_get_position (src_priv->window, &wx, &wy);
4469 src_x -= wx - src_priv->allocation.x;
4470 src_y -= wy - src_priv->allocation.y;
4474 src_x += src_priv->allocation.x;
4475 src_y += src_priv->allocation.y;
4478 /* Translate to the common ancestor */
4479 window = src_priv->window;
4480 while (window != ancestor->priv->window)
4484 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4489 window = gdk_window_get_effective_parent (window);
4491 if (!window) /* Handle GtkHandleBox */
4496 window = dest_priv->window;
4497 while (window != ancestor->priv->window)
4499 dest_list = g_list_prepend (dest_list, window);
4501 window = gdk_window_get_effective_parent (window);
4503 if (!window) /* Handle GtkHandleBox */
4505 g_list_free (dest_list);
4514 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4519 dest_list = g_list_remove (dest_list, dest_list->data);
4522 /* Translate from window relative to allocation relative */
4523 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4526 gdk_window_get_position (dest_priv->window, &wx, &wy);
4528 src_x += wx - dest_priv->allocation.x;
4529 src_y += wy - dest_priv->allocation.y;
4533 src_x -= dest_priv->allocation.x;
4534 src_y -= dest_priv->allocation.y;
4546 gtk_widget_real_size_allocate (GtkWidget *widget,
4547 GtkAllocation *allocation)
4549 GtkWidgetPrivate *priv = widget->priv;
4551 priv->allocation = *allocation;
4553 if (gtk_widget_get_realized (widget) &&
4554 gtk_widget_get_has_window (widget))
4556 gdk_window_move_resize (priv->window,
4557 allocation->x, allocation->y,
4558 allocation->width, allocation->height);
4563 get_span_inside_border (GtkWidget *widget,
4567 int allocated_outside_size,
4568 int natural_inside_size,
4569 int *coord_inside_p,
4572 int inside_allocated;
4576 inside_allocated = allocated_outside_size - start_pad - end_pad;
4578 content_size = natural_inside_size;
4579 if (content_size > inside_allocated)
4581 /* didn't get full natural size */
4582 content_size = inside_allocated;
4585 coord = size = 0; /* silence compiler */
4588 case GTK_ALIGN_FILL:
4590 size = inside_allocated;
4592 case GTK_ALIGN_START:
4594 size = content_size;
4597 coord = allocated_outside_size - end_pad - content_size;
4598 size = content_size;
4600 case GTK_ALIGN_CENTER:
4601 coord = start_pad + (inside_allocated - content_size) / 2;
4602 size = content_size;
4607 *coord_inside_p = coord;
4610 *size_inside_p = size;
4614 get_span_inside_border_horizontal (GtkWidget *widget,
4615 const GtkWidgetAuxInfo *aux_info,
4616 int allocated_outside_width,
4617 int natural_inside_width,
4619 int *width_inside_p)
4621 get_span_inside_border (widget,
4623 aux_info->margin.left,
4624 aux_info->margin.right,
4625 allocated_outside_width,
4626 natural_inside_width,
4632 get_span_inside_border_vertical (GtkWidget *widget,
4633 const GtkWidgetAuxInfo *aux_info,
4634 int allocated_outside_height,
4635 int natural_inside_height,
4637 int *height_inside_p)
4639 get_span_inside_border (widget,
4641 aux_info->margin.top,
4642 aux_info->margin.bottom,
4643 allocated_outside_height,
4644 natural_inside_height,
4650 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4651 GtkAllocation *allocation)
4653 const GtkWidgetAuxInfo *aux_info;
4654 GtkRequisition min, natural;
4657 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4659 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &min, &natural);
4661 get_span_inside_border_horizontal (widget,
4666 get_span_inside_border_vertical (widget,
4674 allocation->width = w;
4675 allocation->height = h;
4679 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4682 GtkWidgetPrivate *priv = widget->priv;
4684 /* widgets must be onscreen for accels to take effect */
4685 return gtk_widget_is_sensitive (widget) &&
4686 gtk_widget_is_drawable (widget) &&
4687 gdk_window_is_viewable (priv->window);
4691 * gtk_widget_can_activate_accel:
4692 * @widget: a #GtkWidget
4693 * @signal_id: the ID of a signal installed on @widget
4695 * Determines whether an accelerator that activates the signal
4696 * identified by @signal_id can currently be activated.
4697 * This is done by emitting the #GtkWidget::can-activate-accel
4698 * signal on @widget; if the signal isn't overridden by a
4699 * handler or in a derived widget, then the default check is
4700 * that the widget must be sensitive, and the widget and all
4701 * its ancestors mapped.
4703 * Return value: %TRUE if the accelerator can be activated.
4708 gtk_widget_can_activate_accel (GtkWidget *widget,
4711 gboolean can_activate = FALSE;
4712 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4713 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4714 return can_activate;
4723 closure_accel_activate (GClosure *closure,
4724 GValue *return_value,
4725 guint n_param_values,
4726 const GValue *param_values,
4727 gpointer invocation_hint,
4728 gpointer marshal_data)
4730 AccelClosure *aclosure = (AccelClosure*) closure;
4731 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4734 g_signal_emit (closure->data, aclosure->signal_id, 0);
4736 /* whether accelerator was handled */
4737 g_value_set_boolean (return_value, can_activate);
4741 closures_destroy (gpointer data)
4743 GSList *slist, *closures = data;
4745 for (slist = closures; slist; slist = slist->next)
4747 g_closure_invalidate (slist->data);
4748 g_closure_unref (slist->data);
4750 g_slist_free (closures);
4754 widget_new_accel_closure (GtkWidget *widget,
4757 AccelClosure *aclosure;
4758 GClosure *closure = NULL;
4759 GSList *slist, *closures;
4761 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4762 for (slist = closures; slist; slist = slist->next)
4763 if (!gtk_accel_group_from_accel_closure (slist->data))
4765 /* reuse this closure */
4766 closure = slist->data;
4771 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4772 closures = g_slist_prepend (closures, g_closure_ref (closure));
4773 g_closure_sink (closure);
4774 g_closure_set_marshal (closure, closure_accel_activate);
4776 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4778 aclosure = (AccelClosure*) closure;
4779 g_assert (closure->data == widget);
4780 g_assert (closure->marshal == closure_accel_activate);
4781 aclosure->signal_id = signal_id;
4787 * gtk_widget_add_accelerator
4788 * @widget: widget to install an accelerator on
4789 * @accel_signal: widget signal to emit on accelerator activation
4790 * @accel_group: accel group for this widget, added to its toplevel
4791 * @accel_key: GDK keyval of the accelerator
4792 * @accel_mods: modifier key combination of the accelerator
4793 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4795 * Installs an accelerator for this @widget in @accel_group that causes
4796 * @accel_signal to be emitted if the accelerator is activated.
4797 * The @accel_group needs to be added to the widget's toplevel via
4798 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4799 * Accelerators added through this function are not user changeable during
4800 * runtime. If you want to support accelerators that can be changed by the
4801 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4802 * gtk_menu_item_set_accel_path() instead.
4805 gtk_widget_add_accelerator (GtkWidget *widget,
4806 const gchar *accel_signal,
4807 GtkAccelGroup *accel_group,
4809 GdkModifierType accel_mods,
4810 GtkAccelFlags accel_flags)
4815 g_return_if_fail (GTK_IS_WIDGET (widget));
4816 g_return_if_fail (accel_signal != NULL);
4817 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4819 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4820 if (!query.signal_id ||
4821 !(query.signal_flags & G_SIGNAL_ACTION) ||
4822 query.return_type != G_TYPE_NONE ||
4825 /* hmm, should be elaborate enough */
4826 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4827 G_OBJECT_TYPE_NAME (widget), accel_signal);
4831 closure = widget_new_accel_closure (widget, query.signal_id);
4833 g_object_ref (widget);
4835 /* install the accelerator. since we don't map this onto an accel_path,
4836 * the accelerator will automatically be locked.
4838 gtk_accel_group_connect (accel_group,
4841 accel_flags | GTK_ACCEL_LOCKED,
4844 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4846 g_object_unref (widget);
4850 * gtk_widget_remove_accelerator:
4851 * @widget: widget to install an accelerator on
4852 * @accel_group: accel group for this widget
4853 * @accel_key: GDK keyval of the accelerator
4854 * @accel_mods: modifier key combination of the accelerator
4855 * @returns: whether an accelerator was installed and could be removed
4857 * Removes an accelerator from @widget, previously installed with
4858 * gtk_widget_add_accelerator().
4861 gtk_widget_remove_accelerator (GtkWidget *widget,
4862 GtkAccelGroup *accel_group,
4864 GdkModifierType accel_mods)
4866 GtkAccelGroupEntry *ag_entry;
4867 GList *slist, *clist;
4870 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4871 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4873 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4874 clist = gtk_widget_list_accel_closures (widget);
4875 for (slist = clist; slist; slist = slist->next)
4879 for (i = 0; i < n; i++)
4880 if (slist->data == (gpointer) ag_entry[i].closure)
4882 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4884 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4886 g_list_free (clist);
4891 g_list_free (clist);
4893 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4894 accel_key, accel_mods, accel_group,
4895 G_OBJECT_TYPE_NAME (widget), widget);
4901 * gtk_widget_list_accel_closures:
4902 * @widget: widget to list accelerator closures for
4904 * Lists the closures used by @widget for accelerator group connections
4905 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4906 * The closures can be used to monitor accelerator changes on @widget,
4907 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4908 * #GtkAccelGroup of a closure which can be found out with
4909 * gtk_accel_group_from_accel_closure().
4911 * Return value: (transfer container) (element-type GClosure):
4912 * a newly allocated #GList of closures
4915 gtk_widget_list_accel_closures (GtkWidget *widget)
4918 GList *clist = NULL;
4920 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4922 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4923 if (gtk_accel_group_from_accel_closure (slist->data))
4924 clist = g_list_prepend (clist, slist->data);
4930 GtkAccelGroup *accel_group;
4935 destroy_accel_path (gpointer data)
4937 AccelPath *apath = data;
4939 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4941 /* closures_destroy takes care of unrefing the closure */
4942 g_object_unref (apath->accel_group);
4944 g_slice_free (AccelPath, apath);
4949 * gtk_widget_set_accel_path:
4950 * @widget: a #GtkWidget
4951 * @accel_path: (allow-none): path used to look up the accelerator
4952 * @accel_group: (allow-none): a #GtkAccelGroup.
4954 * Given an accelerator group, @accel_group, and an accelerator path,
4955 * @accel_path, sets up an accelerator in @accel_group so whenever the
4956 * key binding that is defined for @accel_path is pressed, @widget
4957 * will be activated. This removes any accelerators (for any
4958 * accelerator group) installed by previous calls to
4959 * gtk_widget_set_accel_path(). Associating accelerators with
4960 * paths allows them to be modified by the user and the modifications
4961 * to be saved for future use. (See gtk_accel_map_save().)
4963 * This function is a low level function that would most likely
4964 * be used by a menu creation system like #GtkUIManager. If you
4965 * use #GtkUIManager, setting up accelerator paths will be done
4968 * Even when you you aren't using #GtkUIManager, if you only want to
4969 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4970 * provides a somewhat more convenient interface.
4972 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4973 * pass a static string, you can save some memory by interning it first with
4974 * g_intern_static_string().
4977 gtk_widget_set_accel_path (GtkWidget *widget,
4978 const gchar *accel_path,
4979 GtkAccelGroup *accel_group)
4983 g_return_if_fail (GTK_IS_WIDGET (widget));
4984 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4988 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4989 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4991 gtk_accel_map_add_entry (accel_path, 0, 0);
4992 apath = g_slice_new (AccelPath);
4993 apath->accel_group = g_object_ref (accel_group);
4994 apath->path_quark = g_quark_from_string (accel_path);
4995 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
5000 /* also removes possible old settings */
5001 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
5004 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
5006 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
5010 _gtk_widget_get_accel_path (GtkWidget *widget,
5015 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5017 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
5019 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
5020 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5024 * gtk_widget_mnemonic_activate:
5025 * @widget: a #GtkWidget
5026 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5028 * Emits the #GtkWidget::mnemonic-activate signal.
5030 * The default handler for this signal activates the @widget if
5031 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5034 * Returns: %TRUE if the signal has been handled
5037 gtk_widget_mnemonic_activate (GtkWidget *widget,
5038 gboolean group_cycling)
5042 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5044 group_cycling = group_cycling != FALSE;
5045 if (!gtk_widget_is_sensitive (widget))
5048 g_signal_emit (widget,
5049 widget_signals[MNEMONIC_ACTIVATE],
5057 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5058 gboolean group_cycling)
5060 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5061 gtk_widget_activate (widget);
5062 else if (gtk_widget_get_can_focus (widget))
5063 gtk_widget_grab_focus (widget);
5066 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5067 G_OBJECT_TYPE_NAME (widget));
5068 gtk_widget_error_bell (widget);
5073 static const cairo_user_data_key_t window_key;
5076 gtk_cairo_get_window (cairo_t *cr)
5078 g_return_val_if_fail (cr != NULL, NULL);
5080 return cairo_get_user_data (cr, &window_key);
5084 * gtk_cairo_should_draw_window:
5085 * @cr: a cairo context
5086 * @window: the window to check
5088 * This function is supposed to be called in GtkWidget::draw
5089 * implementations for widgets that support multiple windows.
5090 * @cr must be untransformed from invoking of the draw function.
5091 * This function will return %TRUE if the contents of the given
5092 * @window are supposed to be drawn and %FALSE otherwise. Note
5093 * that when the drawing was not initiated by the windowing
5094 * system this function will return %TRUE for all windows, so
5095 * you need to draw the bottommost window first. Also, do not
5096 * use "else if" statements to check which window should be drawn.
5098 * Returns: %TRUE if @window should be drawn
5101 gtk_cairo_should_draw_window (cairo_t *cr,
5104 GdkWindow *cairo_window;
5106 g_return_val_if_fail (cr != NULL, FALSE);
5107 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5109 cairo_window = gtk_cairo_get_window (cr);
5111 return cairo_window == NULL ||
5112 cairo_window == window;
5116 gtk_cairo_set_window (cairo_t *cr,
5119 cairo_set_user_data (cr, &window_key, window, NULL);
5122 gtk_widget_real_expose_event (GtkWidget *widget,
5123 GdkEventExpose *expose)
5126 gboolean result = FALSE;
5129 if (!gtk_widget_is_drawable (widget))
5132 cr = gdk_cairo_create (expose->window);
5133 gtk_cairo_set_window (cr, expose->window);
5135 gdk_cairo_region (cr, expose->region);
5138 /* translate cairo context properly */
5139 window = gtk_widget_get_window (widget);
5140 if (window != expose->window)
5144 if (gdk_window_get_parent (expose->window) == window)
5146 gdk_window_get_position (expose->window, &x, &y);
5151 gdk_window_get_origin (expose->window, &ex, &ey);
5152 gdk_window_get_origin (window, &x, &y);
5157 cairo_translate (cr, -x, -y);
5161 if (!gtk_widget_get_has_window (widget))
5163 cairo_translate (cr,
5164 widget->priv->allocation.x,
5165 widget->priv->allocation.y);
5168 g_signal_emit (widget, widget_signals[DRAW],
5172 /* unset here, so if someone keeps a reference to cr we
5173 * don't leak the window. */
5174 gtk_cairo_set_window (cr, NULL);
5181 gtk_widget_real_key_press_event (GtkWidget *widget,
5184 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5188 gtk_widget_real_key_release_event (GtkWidget *widget,
5191 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5195 gtk_widget_real_focus_in_event (GtkWidget *widget,
5196 GdkEventFocus *event)
5198 gtk_widget_queue_shallow_draw (widget);
5204 gtk_widget_real_focus_out_event (GtkWidget *widget,
5205 GdkEventFocus *event)
5207 gtk_widget_queue_shallow_draw (widget);
5212 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5213 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5217 * @widget: a #GtkWidget
5218 * @event: a #GdkEvent
5220 * Rarely-used function. This function is used to emit
5221 * the event signals on a widget (those signals should never
5222 * be emitted without using this function to do so).
5223 * If you want to synthesize an event though, don't use this function;
5224 * instead, use gtk_main_do_event() so the event will behave as if
5225 * it were in the event queue. Don't synthesize expose events; instead,
5226 * use gdk_window_invalidate_rect() to invalidate a region of the
5229 * Return value: return from the event signal emission (%TRUE if
5230 * the event was handled)
5233 gtk_widget_event (GtkWidget *widget,
5236 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5237 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5239 if (event->type == GDK_EXPOSE)
5241 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5242 "the same effect, call gdk_window_invalidate_rect/region(), "
5243 "followed by gdk_window_process_updates().");
5247 return gtk_widget_event_internal (widget, event);
5252 * gtk_widget_send_expose:
5253 * @widget: a #GtkWidget
5254 * @event: a expose #GdkEvent
5256 * Very rarely-used function. This function is used to emit
5257 * an expose event signals on a widget. This function is not
5258 * normally used directly. The only time it is used is when
5259 * propagating an expose event to a child %NO_WINDOW widget, and
5260 * that is normally done using gtk_container_propagate_expose().
5262 * If you want to force an area of a window to be redrawn,
5263 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5264 * To cause the redraw to be done immediately, follow that call
5265 * with a call to gdk_window_process_updates().
5267 * Return value: return from the event signal emission (%TRUE if
5268 * the event was handled)
5271 gtk_widget_send_expose (GtkWidget *widget,
5274 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5275 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5276 g_return_val_if_fail (event != NULL, TRUE);
5277 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5279 return gtk_widget_event_internal (widget, event);
5283 event_window_is_still_viewable (GdkEvent *event)
5285 /* Check that we think the event's window is viewable before
5286 * delivering the event, to prevent suprises. We do this here
5287 * at the last moment, since the event may have been queued
5288 * up behind other events, held over a recursive main loop, etc.
5290 switch (event->type)
5293 case GDK_MOTION_NOTIFY:
5294 case GDK_BUTTON_PRESS:
5295 case GDK_2BUTTON_PRESS:
5296 case GDK_3BUTTON_PRESS:
5298 case GDK_ENTER_NOTIFY:
5299 case GDK_PROXIMITY_IN:
5301 return event->any.window && gdk_window_is_viewable (event->any.window);
5304 /* The following events are the second half of paired events;
5305 * we always deliver them to deal with widgets that clean up
5306 * on the second half.
5308 case GDK_BUTTON_RELEASE:
5309 case GDK_KEY_RELEASE:
5310 case GDK_LEAVE_NOTIFY:
5311 case GDK_PROXIMITY_OUT:
5315 /* Remaining events would make sense on an not-viewable window,
5316 * or don't have an associated window.
5323 gtk_widget_event_internal (GtkWidget *widget,
5326 gboolean return_val = FALSE;
5328 /* We check only once for is-still-visible; if someone
5329 * hides the window in on of the signals on the widget,
5330 * they are responsible for returning TRUE to terminate
5333 if (!event_window_is_still_viewable (event))
5336 g_object_ref (widget);
5338 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5339 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5344 switch (event->type)
5349 case GDK_BUTTON_PRESS:
5350 case GDK_2BUTTON_PRESS:
5351 case GDK_3BUTTON_PRESS:
5352 signal_num = BUTTON_PRESS_EVENT;
5355 signal_num = SCROLL_EVENT;
5357 case GDK_BUTTON_RELEASE:
5358 signal_num = BUTTON_RELEASE_EVENT;
5360 case GDK_MOTION_NOTIFY:
5361 signal_num = MOTION_NOTIFY_EVENT;
5364 signal_num = DELETE_EVENT;
5367 signal_num = DESTROY_EVENT;
5368 _gtk_tooltip_hide (widget);
5371 signal_num = KEY_PRESS_EVENT;
5373 case GDK_KEY_RELEASE:
5374 signal_num = KEY_RELEASE_EVENT;
5376 case GDK_ENTER_NOTIFY:
5377 signal_num = ENTER_NOTIFY_EVENT;
5379 case GDK_LEAVE_NOTIFY:
5380 signal_num = LEAVE_NOTIFY_EVENT;
5382 case GDK_FOCUS_CHANGE:
5383 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5384 if (event->focus_change.in)
5385 _gtk_tooltip_focus_in (widget);
5387 _gtk_tooltip_focus_out (widget);
5390 signal_num = CONFIGURE_EVENT;
5393 signal_num = MAP_EVENT;
5396 signal_num = UNMAP_EVENT;
5398 case GDK_WINDOW_STATE:
5399 signal_num = WINDOW_STATE_EVENT;
5401 case GDK_PROPERTY_NOTIFY:
5402 signal_num = PROPERTY_NOTIFY_EVENT;
5404 case GDK_SELECTION_CLEAR:
5405 signal_num = SELECTION_CLEAR_EVENT;
5407 case GDK_SELECTION_REQUEST:
5408 signal_num = SELECTION_REQUEST_EVENT;
5410 case GDK_SELECTION_NOTIFY:
5411 signal_num = SELECTION_NOTIFY_EVENT;
5413 case GDK_PROXIMITY_IN:
5414 signal_num = PROXIMITY_IN_EVENT;
5416 case GDK_PROXIMITY_OUT:
5417 signal_num = PROXIMITY_OUT_EVENT;
5420 signal_num = NO_EXPOSE_EVENT;
5422 case GDK_CLIENT_EVENT:
5423 signal_num = CLIENT_EVENT;
5426 signal_num = EXPOSE_EVENT;
5428 case GDK_VISIBILITY_NOTIFY:
5429 signal_num = VISIBILITY_NOTIFY_EVENT;
5431 case GDK_GRAB_BROKEN:
5432 signal_num = GRAB_BROKEN;
5435 signal_num = DAMAGE_EVENT;
5438 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5442 if (signal_num != -1)
5443 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5445 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5446 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5450 g_object_unref (widget);
5456 * gtk_widget_activate:
5457 * @widget: a #GtkWidget that's activatable
5459 * For widgets that can be "activated" (buttons, menu items, etc.)
5460 * this function activates them. Activation is what happens when you
5461 * press Enter on a widget during key navigation. If @widget isn't
5462 * activatable, the function returns %FALSE.
5464 * Return value: %TRUE if the widget was activatable
5467 gtk_widget_activate (GtkWidget *widget)
5469 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5471 if (WIDGET_CLASS (widget)->activate_signal)
5473 /* FIXME: we should eventually check the signals signature here */
5474 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5483 * gtk_widget_set_scroll_adjustments:
5484 * @widget: a #GtkWidget
5485 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5486 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5488 * For widgets that support scrolling, sets the scroll adjustments and
5489 * returns %TRUE. For widgets that don't support scrolling, does
5490 * nothing and returns %FALSE. Widgets that don't support scrolling
5491 * can be scrolled by placing them in a #GtkViewport, which does
5492 * support scrolling.
5494 * Return value: %TRUE if the widget supports scrolling
5497 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5498 GtkAdjustment *hadjustment,
5499 GtkAdjustment *vadjustment)
5504 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5507 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5509 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5511 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5515 g_signal_query (signal_id, &query);
5516 if (!query.signal_id ||
5517 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5518 query.return_type != G_TYPE_NONE ||
5519 query.n_params != 2 ||
5520 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5521 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5523 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5524 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5528 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5533 gtk_widget_reparent_subwindows (GtkWidget *widget,
5534 GdkWindow *new_window)
5536 GtkWidgetPrivate *priv = widget->priv;
5538 if (!gtk_widget_get_has_window (widget))
5540 GList *children = gdk_window_get_children (priv->window);
5543 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5545 GdkWindow *window = tmp_list->data;
5548 gdk_window_get_user_data (window, &child);
5549 while (child && child != widget)
5550 child = ((GtkWidget*) child)->priv->parent;
5553 gdk_window_reparent (window, new_window, 0, 0);
5556 g_list_free (children);
5561 GList *tmp_list, *children;
5563 parent = gdk_window_get_parent (priv->window);
5566 gdk_window_reparent (priv->window, new_window, 0, 0);
5569 children = gdk_window_get_children (parent);
5571 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5573 GdkWindow *window = tmp_list->data;
5576 gdk_window_get_user_data (window, &child);
5578 if (child == widget)
5579 gdk_window_reparent (window, new_window, 0, 0);
5582 g_list_free (children);
5588 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5589 gpointer client_data)
5591 GtkWidgetPrivate *priv = widget->priv;
5593 g_assert (client_data != NULL);
5595 if (!gtk_widget_get_has_window (widget))
5598 g_object_unref (priv->window);
5599 priv->window = (GdkWindow*) client_data;
5601 g_object_ref (priv->window);
5603 if (GTK_IS_CONTAINER (widget))
5604 gtk_container_forall (GTK_CONTAINER (widget),
5605 gtk_widget_reparent_fixup_child,
5611 * gtk_widget_reparent:
5612 * @widget: a #GtkWidget
5613 * @new_parent: a #GtkContainer to move the widget into
5615 * Moves a widget from one #GtkContainer to another, handling reference
5616 * count issues to avoid destroying the widget.
5619 gtk_widget_reparent (GtkWidget *widget,
5620 GtkWidget *new_parent)
5622 GtkWidgetPrivate *priv;
5624 g_return_if_fail (GTK_IS_WIDGET (widget));
5625 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5626 priv = widget->priv;
5627 g_return_if_fail (priv->parent != NULL);
5629 if (priv->parent != new_parent)
5631 /* First try to see if we can get away without unrealizing
5632 * the widget as we reparent it. if so we set a flag so
5633 * that gtk_widget_unparent doesn't unrealize widget
5635 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5636 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5638 g_object_ref (widget);
5639 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5640 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5641 g_object_unref (widget);
5643 if (GTK_WIDGET_IN_REPARENT (widget))
5645 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5647 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5648 gtk_widget_reparent_fixup_child (widget,
5649 gtk_widget_get_parent_window (widget));
5652 g_object_notify (G_OBJECT (widget), "parent");
5657 * gtk_widget_intersect:
5658 * @widget: a #GtkWidget
5659 * @area: a rectangle
5660 * @intersection: rectangle to store intersection of @widget and @area
5662 * Computes the intersection of a @widget's area and @area, storing
5663 * the intersection in @intersection, and returns %TRUE if there was
5664 * an intersection. @intersection may be %NULL if you're only
5665 * interested in whether there was an intersection.
5667 * Return value: %TRUE if there was an intersection
5670 gtk_widget_intersect (GtkWidget *widget,
5671 const GdkRectangle *area,
5672 GdkRectangle *intersection)
5674 GtkWidgetPrivate *priv;
5679 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5680 g_return_val_if_fail (area != NULL, FALSE);
5682 priv = widget->priv;
5685 dest = intersection;
5689 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5691 if (return_val && intersection && gtk_widget_get_has_window (widget))
5693 intersection->x -= priv->allocation.x;
5694 intersection->y -= priv->allocation.y;
5701 * gtk_widget_region_intersect:
5702 * @widget: a #GtkWidget
5703 * @region: a #cairo_region_t, in the same coordinate system as
5704 * @widget->allocation. That is, relative to @widget->window
5705 * for %NO_WINDOW widgets; relative to the parent window
5706 * of @widget->window for widgets with their own window.
5707 * @returns: A newly allocated region holding the intersection of @widget
5708 * and @region. The coordinates of the return value are
5709 * relative to @widget->window for %NO_WINDOW widgets, and
5710 * relative to the parent window of @widget->window for
5711 * widgets with their own window.
5713 * Computes the intersection of a @widget's area and @region, returning
5714 * the intersection. The result may be empty, use cairo_region_is_empty() to
5718 gtk_widget_region_intersect (GtkWidget *widget,
5719 const cairo_region_t *region)
5722 cairo_region_t *dest;
5724 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5725 g_return_val_if_fail (region != NULL, NULL);
5727 gtk_widget_get_allocation (widget, &rect);
5729 dest = cairo_region_create_rectangle (&rect);
5731 cairo_region_intersect (dest, region);
5737 * _gtk_widget_grab_notify:
5738 * @widget: a #GtkWidget
5739 * @was_grabbed: whether a grab is now in effect
5741 * Emits the #GtkWidget::grab-notify signal on @widget.
5746 _gtk_widget_grab_notify (GtkWidget *widget,
5747 gboolean was_grabbed)
5749 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5753 * gtk_widget_grab_focus:
5754 * @widget: a #GtkWidget
5756 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5757 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5758 * something like #GtkFrame won't work.
5760 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5761 * gtk_widget_set_can_focus() to modify that flag.
5763 * The widget also needs to be realized and mapped. This is indicated by the
5764 * related signals. Grabbing the focus immediately after creating the widget
5765 * will likely fail and cause critical warnings.
5768 gtk_widget_grab_focus (GtkWidget *widget)
5770 g_return_if_fail (GTK_IS_WIDGET (widget));
5772 if (!gtk_widget_is_sensitive (widget))
5775 g_object_ref (widget);
5776 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5777 g_object_notify (G_OBJECT (widget), "has-focus");
5778 g_object_unref (widget);
5782 reset_focus_recurse (GtkWidget *widget,
5785 if (GTK_IS_CONTAINER (widget))
5787 GtkContainer *container;
5789 container = GTK_CONTAINER (widget);
5790 gtk_container_set_focus_child (container, NULL);
5792 gtk_container_foreach (container,
5793 reset_focus_recurse,
5799 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5801 if (gtk_widget_get_can_focus (focus_widget))
5803 GtkWidget *toplevel;
5806 /* clear the current focus setting, break if the current widget
5807 * is the focus widget's parent, since containers above that will
5808 * be set by the next loop.
5810 toplevel = gtk_widget_get_toplevel (focus_widget);
5811 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5813 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5815 if (widget == focus_widget)
5817 /* We call _gtk_window_internal_set_focus() here so that the
5818 * toplevel window can request the focus if necessary.
5819 * This is needed when the toplevel is a GtkPlug
5821 if (!gtk_widget_has_focus (widget))
5822 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5829 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5831 widget = widget->priv->parent;
5832 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5836 else if (toplevel != focus_widget)
5838 /* gtk_widget_grab_focus() operates on a tree without window...
5839 * actually, this is very questionable behaviour.
5842 gtk_container_foreach (GTK_CONTAINER (toplevel),
5843 reset_focus_recurse,
5847 /* now propagate the new focus up the widget tree and finally
5848 * set it on the window
5850 widget = focus_widget;
5851 while (widget->priv->parent)
5853 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5854 widget = widget->priv->parent;
5856 if (GTK_IS_WINDOW (widget))
5857 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5862 gtk_widget_real_query_tooltip (GtkWidget *widget,
5865 gboolean keyboard_tip,
5866 GtkTooltip *tooltip)
5868 gchar *tooltip_markup;
5869 gboolean has_tooltip;
5871 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5872 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5874 if (has_tooltip && tooltip_markup)
5876 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5884 gtk_widget_real_show_help (GtkWidget *widget,
5885 GtkWidgetHelpType help_type)
5887 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5889 _gtk_tooltip_toggle_keyboard_mode (widget);
5898 gtk_widget_real_focus (GtkWidget *widget,
5899 GtkDirectionType direction)
5901 if (!gtk_widget_get_can_focus (widget))
5904 if (!gtk_widget_is_focus (widget))
5906 gtk_widget_grab_focus (widget);
5914 gtk_widget_real_move_focus (GtkWidget *widget,
5915 GtkDirectionType direction)
5917 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
5919 if (GTK_IS_WINDOW (toplevel) &&
5920 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
5922 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
5928 gtk_widget_real_keynav_failed (GtkWidget *widget,
5929 GtkDirectionType direction)
5931 gboolean cursor_only;
5935 case GTK_DIR_TAB_FORWARD:
5936 case GTK_DIR_TAB_BACKWARD:
5943 g_object_get (gtk_widget_get_settings (widget),
5944 "gtk-keynav-cursor-only", &cursor_only,
5951 gtk_widget_error_bell (widget);
5957 * gtk_widget_set_can_focus:
5958 * @widget: a #GtkWidget
5959 * @can_focus: whether or not @widget can own the input focus.
5961 * Specifies whether @widget can own the input focus. See
5962 * gtk_widget_grab_focus() for actually setting the input focus on a
5968 gtk_widget_set_can_focus (GtkWidget *widget,
5971 g_return_if_fail (GTK_IS_WIDGET (widget));
5973 if (can_focus != gtk_widget_get_can_focus (widget))
5976 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
5978 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
5980 gtk_widget_queue_resize (widget);
5981 g_object_notify (G_OBJECT (widget), "can-focus");
5986 * gtk_widget_get_can_focus:
5987 * @widget: a #GtkWidget
5989 * Determines whether @widget can own the input focus. See
5990 * gtk_widget_set_can_focus().
5992 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
5997 gtk_widget_get_can_focus (GtkWidget *widget)
5999 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6001 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
6005 * gtk_widget_has_focus:
6006 * @widget: a #GtkWidget
6008 * Determines if the widget has the global input focus. See
6009 * gtk_widget_is_focus() for the difference between having the global
6010 * input focus, and only having the focus within a toplevel.
6012 * Return value: %TRUE if the widget has the global input focus.
6017 gtk_widget_has_focus (GtkWidget *widget)
6019 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6021 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
6025 * gtk_widget_is_focus:
6026 * @widget: a #GtkWidget
6028 * Determines if the widget is the focus widget within its
6029 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6030 * necessarily set; %HAS_FOCUS will only be set if the
6031 * toplevel widget additionally has the global input focus.)
6033 * Return value: %TRUE if the widget is the focus widget.
6036 gtk_widget_is_focus (GtkWidget *widget)
6038 GtkWidget *toplevel;
6040 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6042 toplevel = gtk_widget_get_toplevel (widget);
6044 if (GTK_IS_WINDOW (toplevel))
6045 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6051 * gtk_widget_set_can_default:
6052 * @widget: a #GtkWidget
6053 * @can_default: whether or not @widget can be a default widget.
6055 * Specifies whether @widget can be a default widget. See
6056 * gtk_widget_grab_default() for details about the meaning of
6062 gtk_widget_set_can_default (GtkWidget *widget,
6063 gboolean can_default)
6065 g_return_if_fail (GTK_IS_WIDGET (widget));
6067 if (can_default != gtk_widget_get_can_default (widget))
6070 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
6072 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
6074 gtk_widget_queue_resize (widget);
6075 g_object_notify (G_OBJECT (widget), "can-default");
6080 * gtk_widget_get_can_default:
6081 * @widget: a #GtkWidget
6083 * Determines whether @widget can be a default widget. See
6084 * gtk_widget_set_can_default().
6086 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6091 gtk_widget_get_can_default (GtkWidget *widget)
6093 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6095 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6099 * gtk_widget_has_default:
6100 * @widget: a #GtkWidget
6102 * Determines whether @widget is the current default widget within its
6103 * toplevel. See gtk_widget_set_can_default().
6105 * Return value: %TRUE if @widget is the current default widget within
6106 * its toplevel, %FALSE otherwise
6111 gtk_widget_has_default (GtkWidget *widget)
6113 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6115 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6119 _gtk_widget_set_has_default (GtkWidget *widget,
6120 gboolean has_default)
6123 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6125 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6129 * gtk_widget_grab_default:
6130 * @widget: a #GtkWidget
6132 * Causes @widget to become the default widget. @widget must have the
6133 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6134 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6135 * %TRUE)</literal>. The default widget is activated when
6136 * the user presses Enter in a window. Default widgets must be
6137 * activatable, that is, gtk_widget_activate() should affect them. Note
6138 * that #GtkEntry widgets require the "activates-default" property
6139 * set to %TRUE before they activate the default widget when Enter
6140 * is pressed and the #GtkEntry is focused.
6143 gtk_widget_grab_default (GtkWidget *widget)
6147 g_return_if_fail (GTK_IS_WIDGET (widget));
6148 g_return_if_fail (gtk_widget_get_can_default (widget));
6150 window = gtk_widget_get_toplevel (widget);
6152 if (window && gtk_widget_is_toplevel (window))
6153 gtk_window_set_default (GTK_WINDOW (window), widget);
6155 g_warning (G_STRLOC ": widget not within a GtkWindow");
6159 * gtk_widget_set_receives_default:
6160 * @widget: a #GtkWidget
6161 * @receives_default: whether or not @widget can be a default widget.
6163 * Specifies whether @widget will be treated as the default widget
6164 * within its toplevel when it has the focus, even if another widget
6167 * See gtk_widget_grab_default() for details about the meaning of
6173 gtk_widget_set_receives_default (GtkWidget *widget,
6174 gboolean receives_default)
6176 g_return_if_fail (GTK_IS_WIDGET (widget));
6178 if (receives_default != gtk_widget_get_receives_default (widget))
6180 if (receives_default)
6181 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6183 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6185 g_object_notify (G_OBJECT (widget), "receives-default");
6190 * gtk_widget_get_receives_default:
6191 * @widget: a #GtkWidget
6193 * Determines whether @widget is alyways treated as default widget
6194 * withing its toplevel when it has the focus, even if another widget
6197 * See gtk_widget_set_receives_default().
6199 * Return value: %TRUE if @widget acts as default widget when focussed,
6205 gtk_widget_get_receives_default (GtkWidget *widget)
6207 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6209 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6213 * gtk_widget_has_grab:
6214 * @widget: a #GtkWidget
6216 * Determines whether the widget is currently grabbing events, so it
6217 * is the only widget receiving input events (keyboard and mouse).
6219 * See also gtk_grab_add().
6221 * Return value: %TRUE if the widget is in the grab_widgets stack
6226 gtk_widget_has_grab (GtkWidget *widget)
6228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6230 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6234 _gtk_widget_set_has_grab (GtkWidget *widget,
6238 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6240 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6244 * gtk_widget_device_is_shadowed:
6245 * @widget: a #GtkWidget
6246 * @device: a #GdkDevice
6248 * Returns %TRUE if @device has been shadowed by a GTK+
6249 * device grab on another widget, so it would stop sending
6250 * events to @widget. This may be used in the
6251 * #GtkWidget::grab-notify signal to check for specific
6252 * devices. See gtk_device_grab_add().
6254 * Returns: %TRUE if there is an ongoing grab on @device
6255 * by another #GtkWidget than @widget.
6260 gtk_widget_device_is_shadowed (GtkWidget *widget,
6263 GtkWindowGroup *group;
6264 GtkWidget *grab_widget, *toplevel;
6266 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6267 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6269 if (!gtk_widget_get_realized (widget))
6272 toplevel = gtk_widget_get_toplevel (widget);
6274 if (GTK_IS_WINDOW (toplevel))
6275 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6277 group = gtk_window_get_group (NULL);
6279 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6281 /* Widget not inside the hierarchy of grab_widget */
6283 widget != grab_widget &&
6284 !gtk_widget_is_ancestor (widget, grab_widget))
6287 grab_widget = gtk_window_group_get_current_grab (group);
6288 if (grab_widget && widget != grab_widget &&
6289 !gtk_widget_is_ancestor (widget, grab_widget))
6296 * gtk_widget_set_name:
6297 * @widget: a #GtkWidget
6298 * @name: name for the widget
6300 * Widgets can be named, which allows you to refer to them from a
6301 * gtkrc file. You can apply a style to widgets with a particular name
6302 * in the gtkrc file. See the documentation for gtkrc files (on the
6303 * same page as the docs for #GtkRcStyle).
6305 * Note that widget names are separated by periods in paths (see
6306 * gtk_widget_path()), so names with embedded periods may cause confusion.
6309 gtk_widget_set_name (GtkWidget *widget,
6312 GtkWidgetPrivate *priv;
6315 g_return_if_fail (GTK_IS_WIDGET (widget));
6317 priv = widget->priv;
6319 new_name = g_strdup (name);
6320 g_free (priv->name);
6321 priv->name = new_name;
6323 if (gtk_widget_has_rc_style (widget))
6324 gtk_widget_reset_rc_style (widget);
6326 g_object_notify (G_OBJECT (widget), "name");
6330 * gtk_widget_get_name:
6331 * @widget: a #GtkWidget
6333 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6334 * significance of widget names.
6336 * Return value: name of the widget. This string is owned by GTK+ and
6337 * should not be modified or freed
6339 G_CONST_RETURN gchar*
6340 gtk_widget_get_name (GtkWidget *widget)
6342 GtkWidgetPrivate *priv;
6344 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6346 priv = widget->priv;
6350 return G_OBJECT_TYPE_NAME (widget);
6354 * gtk_widget_set_state:
6355 * @widget: a #GtkWidget
6356 * @state: new state for @widget
6358 * This function is for use in widget implementations. Sets the state
6359 * of a widget (insensitive, prelighted, etc.) Usually you should set
6360 * the state using wrapper functions such as gtk_widget_set_sensitive().
6363 gtk_widget_set_state (GtkWidget *widget,
6366 GtkWidgetPrivate *priv;
6368 g_return_if_fail (GTK_IS_WIDGET (widget));
6370 priv = widget->priv;
6372 if (state == gtk_widget_get_state (widget))
6375 if (state == GTK_STATE_INSENSITIVE)
6376 gtk_widget_set_sensitive (widget, FALSE);
6382 data.state_restoration = FALSE;
6383 data.use_forall = FALSE;
6385 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6387 data.parent_sensitive = TRUE;
6389 gtk_widget_propagate_state (widget, &data);
6391 if (gtk_widget_is_drawable (widget))
6392 gtk_widget_queue_draw (widget);
6397 * gtk_widget_get_state:
6398 * @widget: a #GtkWidget
6400 * Returns the widget's state. See gtk_widget_set_state().
6402 * Returns: the state of @widget.
6407 gtk_widget_get_state (GtkWidget *widget)
6409 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6411 return widget->priv->state;
6415 * gtk_widget_set_visible:
6416 * @widget: a #GtkWidget
6417 * @visible: whether the widget should be shown or not
6419 * Sets the visibility state of @widget. Note that setting this to
6420 * %TRUE doesn't mean the widget is actually viewable, see
6421 * gtk_widget_get_visible().
6423 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6424 * but is nicer to use when the visibility of the widget depends on
6430 gtk_widget_set_visible (GtkWidget *widget,
6433 g_return_if_fail (GTK_IS_WIDGET (widget));
6435 if (visible != gtk_widget_get_visible (widget))
6438 gtk_widget_show (widget);
6440 gtk_widget_hide (widget);
6445 * gtk_widget_get_visible:
6446 * @widget: a #GtkWidget
6448 * Determines whether the widget is visible. Note that this doesn't
6449 * take into account whether the widget's parent is also visible
6450 * or the widget is obscured in any way.
6452 * See gtk_widget_set_visible().
6454 * Return value: %TRUE if the widget is visible
6459 gtk_widget_get_visible (GtkWidget *widget)
6461 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6463 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6467 * gtk_widget_set_has_window:
6468 * @widget: a #GtkWidget
6469 * @has_window: whether or not @widget has a window.
6471 * Specifies whether @widget has a #GdkWindow of its own. Note that
6472 * all realized widgets have a non-%NULL "window" pointer
6473 * (gtk_widget_get_window() never returns a %NULL window when a widget
6474 * is realized), but for many of them it's actually the #GdkWindow of
6475 * one of its parent widgets. Widgets that do not create a %window for
6476 * themselves in GtkWidget::realize() must announce this by
6477 * calling this function with @has_window = %FALSE.
6479 * This function should only be called by widget implementations,
6480 * and they should call it in their init() function.
6485 gtk_widget_set_has_window (GtkWidget *widget,
6486 gboolean has_window)
6488 g_return_if_fail (GTK_IS_WIDGET (widget));
6491 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6493 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6497 * gtk_widget_get_has_window:
6498 * @widget: a #GtkWidget
6500 * Determines whether @widget has a #GdkWindow of its own. See
6501 * gtk_widget_set_has_window().
6503 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6508 gtk_widget_get_has_window (GtkWidget *widget)
6510 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6512 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6516 * gtk_widget_is_toplevel:
6517 * @widget: a #GtkWidget
6519 * Determines whether @widget is a toplevel widget. Currently only
6520 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6521 * widgets have no parent widget.
6523 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6528 gtk_widget_is_toplevel (GtkWidget *widget)
6530 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6532 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6536 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6537 gboolean is_toplevel)
6540 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6542 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6546 * gtk_widget_is_drawable:
6547 * @widget: a #GtkWidget
6549 * Determines whether @widget can be drawn to. A widget can be drawn
6550 * to if it is mapped and visible.
6552 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6557 gtk_widget_is_drawable (GtkWidget *widget)
6559 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6561 return (gtk_widget_get_visible (widget) &&
6562 gtk_widget_get_mapped (widget));
6566 * gtk_widget_get_realized:
6567 * @widget: a #GtkWidget
6569 * Determines whether @widget is realized.
6571 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6576 gtk_widget_get_realized (GtkWidget *widget)
6578 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6580 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6584 * gtk_widget_set_realized:
6585 * @widget: a #GtkWidget
6586 * @realized: %TRUE to mark the widget as realized
6588 * Marks the widget as being realized.
6590 * This function should only ever be called in a derived widget's
6591 * "realize" or "unrealize" implementation.
6596 gtk_widget_set_realized (GtkWidget *widget,
6599 g_return_if_fail (GTK_IS_WIDGET (widget));
6602 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6604 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6608 * gtk_widget_get_mapped:
6609 * @widget: a #GtkWidget
6611 * Whether the widget is mapped.
6613 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6618 gtk_widget_get_mapped (GtkWidget *widget)
6620 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6622 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6626 * gtk_widget_set_mapped:
6627 * @widget: a #GtkWidget
6628 * @mapped: %TRUE to mark the widget as mapped
6630 * Marks the widget as being realized.
6632 * This function should only ever be called in a derived widget's
6633 * "map" or "unmap" implementation.
6638 gtk_widget_set_mapped (GtkWidget *widget,
6641 g_return_if_fail (GTK_IS_WIDGET (widget));
6644 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6646 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6650 * gtk_widget_set_app_paintable:
6651 * @widget: a #GtkWidget
6652 * @app_paintable: %TRUE if the application will paint on the widget
6654 * Sets whether the application intends to draw on the widget in
6655 * an #GtkWidget::expose-event handler.
6657 * This is a hint to the widget and does not affect the behavior of
6658 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6659 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6660 * the effect is to suppress default themed drawing of the widget's
6661 * background. (Children of the widget will still be drawn.) The application
6662 * is then entirely responsible for drawing the widget background.
6664 * Note that the background is still drawn when the widget is mapped.
6667 gtk_widget_set_app_paintable (GtkWidget *widget,
6668 gboolean app_paintable)
6670 g_return_if_fail (GTK_IS_WIDGET (widget));
6672 app_paintable = (app_paintable != FALSE);
6674 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6677 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6679 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6681 if (gtk_widget_is_drawable (widget))
6682 gtk_widget_queue_draw (widget);
6684 g_object_notify (G_OBJECT (widget), "app-paintable");
6689 * gtk_widget_get_app_paintable:
6690 * @widget: a #GtkWidget
6692 * Determines whether the application intends to draw on the widget in
6693 * an #GtkWidget::expose-event handler.
6695 * See gtk_widget_set_app_paintable()
6697 * Return value: %TRUE if the widget is app paintable
6702 gtk_widget_get_app_paintable (GtkWidget *widget)
6704 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6706 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6710 * gtk_widget_set_double_buffered:
6711 * @widget: a #GtkWidget
6712 * @double_buffered: %TRUE to double-buffer a widget
6714 * Widgets are double buffered by default; you can use this function
6715 * to turn off the buffering. "Double buffered" simply means that
6716 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6717 * automatically around expose events sent to the
6718 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6719 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6720 * buffer to the screen. The result is that users see the window
6721 * update in one smooth step, and don't see individual graphics
6722 * primitives being rendered.
6724 * In very simple terms, double buffered widgets don't flicker,
6725 * so you would only use this function to turn off double buffering
6726 * if you had special needs and really knew what you were doing.
6728 * Note: if you turn off double-buffering, you have to handle
6729 * expose events, since even the clearing to the background color or
6730 * pixmap will not happen automatically (as it is done in
6731 * gdk_window_begin_paint()).
6734 gtk_widget_set_double_buffered (GtkWidget *widget,
6735 gboolean double_buffered)
6737 g_return_if_fail (GTK_IS_WIDGET (widget));
6739 double_buffered = (double_buffered != FALSE);
6741 if (double_buffered != gtk_widget_get_double_buffered (widget))
6743 if (double_buffered)
6744 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6746 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6748 g_object_notify (G_OBJECT (widget), "double-buffered");
6753 * gtk_widget_get_double_buffered:
6754 * @widget: a #GtkWidget
6756 * Determines whether the widget is double buffered.
6758 * See gtk_widget_set_double_buffered()
6760 * Return value: %TRUE if the widget is double buffered
6765 gtk_widget_get_double_buffered (GtkWidget *widget)
6767 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6769 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6773 * gtk_widget_set_redraw_on_allocate:
6774 * @widget: a #GtkWidget
6775 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6776 * when it is allocated to a new size. Otherwise, only the
6777 * new portion of the widget will be redrawn.
6779 * Sets whether the entire widget is queued for drawing when its size
6780 * allocation changes. By default, this setting is %TRUE and
6781 * the entire widget is redrawn on every size change. If your widget
6782 * leaves the upper left unchanged when made bigger, turning this
6783 * setting off will improve performance.
6785 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6786 * off all allocation on resizing: the widget will not even redraw if
6787 * its position changes; this is to allow containers that don't draw
6788 * anything to avoid excess invalidations. If you set this flag on a
6789 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6790 * you are responsible for invalidating both the old and new allocation
6791 * of the widget when the widget is moved and responsible for invalidating
6792 * regions newly when the widget increases size.
6795 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6796 gboolean redraw_on_allocate)
6798 g_return_if_fail (GTK_IS_WIDGET (widget));
6800 if (redraw_on_allocate)
6801 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6803 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6807 * gtk_widget_set_sensitive:
6808 * @widget: a #GtkWidget
6809 * @sensitive: %TRUE to make the widget sensitive
6811 * Sets the sensitivity of a widget. A widget is sensitive if the user
6812 * can interact with it. Insensitive widgets are "grayed out" and the
6813 * user can't interact with them. Insensitive widgets are known as
6814 * "inactive", "disabled", or "ghosted" in some other toolkits.
6817 gtk_widget_set_sensitive (GtkWidget *widget,
6820 GtkWidgetPrivate *priv;
6823 g_return_if_fail (GTK_IS_WIDGET (widget));
6825 priv = widget->priv;
6827 sensitive = (sensitive != FALSE);
6829 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6834 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6835 data.state = priv->saved_state;
6839 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6840 data.state = gtk_widget_get_state (widget);
6842 data.state_restoration = TRUE;
6843 data.use_forall = TRUE;
6846 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6848 data.parent_sensitive = TRUE;
6850 gtk_widget_propagate_state (widget, &data);
6851 if (gtk_widget_is_drawable (widget))
6852 gtk_widget_queue_draw (widget);
6854 g_object_notify (G_OBJECT (widget), "sensitive");
6858 * gtk_widget_get_sensitive:
6859 * @widget: a #GtkWidget
6861 * Returns the widget's sensitivity (in the sense of returning
6862 * the value that has been set using gtk_widget_set_sensitive()).
6864 * The effective sensitivity of a widget is however determined by both its
6865 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6867 * Returns: %TRUE if the widget is sensitive
6872 gtk_widget_get_sensitive (GtkWidget *widget)
6874 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6876 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6880 * gtk_widget_is_sensitive:
6881 * @widget: a #GtkWidget
6883 * Returns the widget's effective sensitivity, which means
6884 * it is sensitive itself and also its parent widget is sensntive
6886 * Returns: %TRUE if the widget is effectively sensitive
6891 gtk_widget_is_sensitive (GtkWidget *widget)
6893 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6895 return (gtk_widget_get_sensitive (widget) &&
6896 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6900 * gtk_widget_set_parent:
6901 * @widget: a #GtkWidget
6902 * @parent: parent container
6904 * This function is useful only when implementing subclasses of
6906 * Sets the container as the parent of @widget, and takes care of
6907 * some details such as updating the state and style of the child
6908 * to reflect its new location. The opposite function is
6909 * gtk_widget_unparent().
6912 gtk_widget_set_parent (GtkWidget *widget,
6915 GtkWidgetPrivate *priv;
6918 g_return_if_fail (GTK_IS_WIDGET (widget));
6919 g_return_if_fail (GTK_IS_WIDGET (parent));
6920 g_return_if_fail (widget != parent);
6922 priv = widget->priv;
6924 if (priv->parent != NULL)
6926 g_warning ("Can't set a parent on widget which has a parent\n");
6929 if (gtk_widget_is_toplevel (widget))
6931 g_warning ("Can't set a parent on a toplevel widget\n");
6935 /* keep this function in sync with gtk_menu_attach_to_widget()
6938 g_object_ref_sink (widget);
6939 priv->parent = parent;
6941 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
6942 data.state = gtk_widget_get_state (parent);
6944 data.state = gtk_widget_get_state (widget);
6945 data.state_restoration = FALSE;
6946 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
6947 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
6949 gtk_widget_propagate_state (widget, &data);
6951 gtk_widget_reset_rc_styles (widget);
6953 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
6954 if (GTK_WIDGET_ANCHORED (priv->parent))
6955 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
6956 g_object_notify (G_OBJECT (widget), "parent");
6958 /* Enforce realized/mapped invariants
6960 if (gtk_widget_get_realized (priv->parent))
6961 gtk_widget_realize (widget);
6963 if (gtk_widget_get_visible (priv->parent) &&
6964 gtk_widget_get_visible (widget))
6966 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
6967 gtk_widget_get_mapped (priv->parent))
6968 gtk_widget_map (widget);
6970 gtk_widget_queue_resize (widget);
6975 * gtk_widget_get_parent:
6976 * @widget: a #GtkWidget
6978 * Returns the parent container of @widget.
6980 * Return value: (transfer none): the parent container of @widget, or %NULL
6983 gtk_widget_get_parent (GtkWidget *widget)
6985 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6987 return widget->priv->parent;
6990 /*****************************************
6992 * see docs/styles.txt
6993 *****************************************/
6996 * gtk_widget_style_attach:
6997 * @widget: a #GtkWidget
6999 * This function attaches the widget's #GtkStyle to the widget's
7000 * #GdkWindow. It is a replacement for
7003 * widget->style = gtk_style_attach (widget->style, widget->window);
7006 * and should only ever be called in a derived widget's "realize"
7007 * implementation which does not chain up to its parent class'
7008 * "realize" implementation, because one of the parent classes
7009 * (finally #GtkWidget) would attach the style itself.
7014 gtk_widget_style_attach (GtkWidget *widget)
7016 GtkWidgetPrivate *priv;
7018 g_return_if_fail (GTK_IS_WIDGET (widget));
7019 g_return_if_fail (gtk_widget_get_realized (widget));
7021 priv = widget->priv;
7023 priv->style = gtk_style_attach (priv->style, priv->window);
7027 * gtk_widget_has_rc_style:
7028 * @widget: a #GtkWidget
7030 * Determines if the widget style has been looked up through the rc mechanism.
7032 * Returns: %TRUE if the widget has been looked up through the rc
7033 * mechanism, %FALSE otherwise.
7038 gtk_widget_has_rc_style (GtkWidget *widget)
7040 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7042 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
7046 * gtk_widget_set_style:
7047 * @widget: a #GtkWidget
7048 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7049 * gtk_widget_set_style() and go back to the default style
7051 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7052 * want to use this function; it interacts badly with themes, because
7053 * themes work by replacing the #GtkStyle. Instead, use
7054 * gtk_widget_modify_style().
7057 gtk_widget_set_style (GtkWidget *widget,
7060 g_return_if_fail (GTK_IS_WIDGET (widget));
7064 gboolean initial_emission;
7066 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7068 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
7069 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
7071 gtk_widget_set_style_internal (widget, style, initial_emission);
7075 if (GTK_WIDGET_USER_STYLE (widget))
7076 gtk_widget_reset_rc_style (widget);
7081 * gtk_widget_ensure_style:
7082 * @widget: a #GtkWidget
7084 * Ensures that @widget has a style (@widget->style). Not a very useful
7085 * function; most of the time, if you want the style, the widget is
7086 * realized, and realized widgets are guaranteed to have a style
7090 gtk_widget_ensure_style (GtkWidget *widget)
7092 g_return_if_fail (GTK_IS_WIDGET (widget));
7094 if (!GTK_WIDGET_USER_STYLE (widget) &&
7095 !gtk_widget_has_rc_style (widget))
7096 gtk_widget_reset_rc_style (widget);
7099 /* Look up the RC style for this widget, unsetting any user style that
7100 * may be in effect currently
7103 gtk_widget_reset_rc_style (GtkWidget *widget)
7105 GtkWidgetPrivate *priv = widget->priv;
7106 GtkStyle *new_style = NULL;
7107 gboolean initial_emission;
7109 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7111 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7112 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7114 if (gtk_widget_has_screen (widget))
7115 new_style = gtk_rc_get_style (widget);
7117 new_style = gtk_widget_get_default_style ();
7119 if (initial_emission || new_style != priv->style)
7120 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7124 * gtk_widget_get_style:
7125 * @widget: a #GtkWidget
7127 * Simply an accessor function that returns @widget->style.
7129 * Return value: (transfer none): the widget's #GtkStyle
7132 gtk_widget_get_style (GtkWidget *widget)
7134 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7136 return widget->priv->style;
7140 * gtk_widget_modify_style:
7141 * @widget: a #GtkWidget
7142 * @style: the #GtkRcStyle holding the style modifications
7144 * Modifies style values on the widget. Modifications made using this
7145 * technique take precedence over style values set via an RC file,
7146 * however, they will be overriden if a style is explicitely set on
7147 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7148 * is designed so each field can either be set or unset, so it is
7149 * possible, using this function, to modify some style values and
7150 * leave the others unchanged.
7152 * Note that modifications made with this function are not cumulative
7153 * with previous calls to gtk_widget_modify_style() or with such
7154 * functions as gtk_widget_modify_fg(). If you wish to retain
7155 * previous values, you must first call gtk_widget_get_modifier_style(),
7156 * make your modifications to the returned style, then call
7157 * gtk_widget_modify_style() with that style. On the other hand,
7158 * if you first call gtk_widget_modify_style(), subsequent calls
7159 * to such functions gtk_widget_modify_fg() will have a cumulative
7160 * effect with the initial modifications.
7163 gtk_widget_modify_style (GtkWidget *widget,
7166 g_return_if_fail (GTK_IS_WIDGET (widget));
7167 g_return_if_fail (GTK_IS_RC_STYLE (style));
7169 g_object_set_qdata_full (G_OBJECT (widget),
7171 gtk_rc_style_copy (style),
7172 (GDestroyNotify) g_object_unref);
7174 /* note that "style" may be invalid here if it was the old
7175 * modifier style and the only reference was our own.
7178 if (gtk_widget_has_rc_style (widget))
7179 gtk_widget_reset_rc_style (widget);
7183 * gtk_widget_get_modifier_style:
7184 * @widget: a #GtkWidget
7186 * Returns the current modifier style for the widget. (As set by
7187 * gtk_widget_modify_style().) If no style has previously set, a new
7188 * #GtkRcStyle will be created with all values unset, and set as the
7189 * modifier style for the widget. If you make changes to this rc
7190 * style, you must call gtk_widget_modify_style(), passing in the
7191 * returned rc style, to make sure that your changes take effect.
7193 * Caution: passing the style back to gtk_widget_modify_style() will
7194 * normally end up destroying it, because gtk_widget_modify_style() copies
7195 * the passed-in style and sets the copy as the new modifier style,
7196 * thus dropping any reference to the old modifier style. Add a reference
7197 * to the modifier style if you want to keep it alive.
7199 * Return value: (transfer none): the modifier style for the widget. This rc style is
7200 * owned by the widget. If you want to keep a pointer to value this
7201 * around, you must add a refcount using g_object_ref().
7204 gtk_widget_get_modifier_style (GtkWidget *widget)
7206 GtkRcStyle *rc_style;
7208 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7210 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7214 rc_style = gtk_rc_style_new ();
7215 g_object_set_qdata_full (G_OBJECT (widget),
7218 (GDestroyNotify) g_object_unref);
7225 gtk_widget_modify_color_component (GtkWidget *widget,
7226 GtkRcFlags component,
7228 const GdkColor *color)
7230 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7237 rc_style->fg[state] = *color;
7240 rc_style->bg[state] = *color;
7243 rc_style->text[state] = *color;
7246 rc_style->base[state] = *color;
7249 g_assert_not_reached();
7252 rc_style->color_flags[state] |= component;
7255 rc_style->color_flags[state] &= ~component;
7257 gtk_widget_modify_style (widget, rc_style);
7261 * gtk_widget_modify_symbolic_color:
7262 * @widget: a #GtkWidget
7263 * @name: the name of the symbolic color to modify
7264 * @color: (allow-none): the color to assign (does not need to be allocated),
7265 * or %NULL to undo the effect of previous calls to
7266 * of gtk_widget_modify_symbolic_color().
7268 * Sets a symbolic color for a widget.
7269 * All other style values are left untouched. See also
7270 * gtk_widget_modify_style().
7275 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7277 const GdkColor *color)
7279 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7281 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7283 gtk_widget_modify_style (widget, rc_style);
7287 * gtk_widget_modify_fg:
7288 * @widget: a #GtkWidget
7289 * @state: the state for which to set the foreground color
7290 * @color: (allow-none): the color to assign (does not need to be allocated),
7291 * or %NULL to undo the effect of previous calls to
7292 * of gtk_widget_modify_fg().
7294 * Sets the foreground color for a widget in a particular state.
7295 * All other style values are left untouched. See also
7296 * gtk_widget_modify_style().
7299 gtk_widget_modify_fg (GtkWidget *widget,
7301 const GdkColor *color)
7303 g_return_if_fail (GTK_IS_WIDGET (widget));
7304 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7306 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7310 * gtk_widget_modify_bg:
7311 * @widget: a #GtkWidget
7312 * @state: the state for which to set the background color
7313 * @color: (allow-none): the color to assign (does not need to be allocated),
7314 * or %NULL to undo the effect of previous calls to
7315 * of gtk_widget_modify_bg().
7317 * Sets the background color for a widget in a particular state.
7318 * All other style values are left untouched. See also
7319 * gtk_widget_modify_style().
7321 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7322 * draw on their parent container's window and thus may not draw any
7323 * background themselves. This is the case for e.g. #GtkLabel. To modify
7324 * the background of such widgets, you have to set the background color
7325 * on their parent; if you want to set the background of a rectangular
7326 * area around a label, try placing the label in a #GtkEventBox widget
7327 * and setting the background color on that.
7330 gtk_widget_modify_bg (GtkWidget *widget,
7332 const GdkColor *color)
7334 g_return_if_fail (GTK_IS_WIDGET (widget));
7335 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7337 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7341 * gtk_widget_modify_text:
7342 * @widget: a #GtkWidget
7343 * @state: the state for which to set the text color
7344 * @color: (allow-none): the color to assign (does not need to be allocated),
7345 * or %NULL to undo the effect of previous calls to
7346 * of gtk_widget_modify_text().
7348 * Sets the text color for a widget in a particular state. All other
7349 * style values are left untouched. The text color is the foreground
7350 * color used along with the base color (see gtk_widget_modify_base())
7351 * for widgets such as #GtkEntry and #GtkTextView. See also
7352 * gtk_widget_modify_style().
7355 gtk_widget_modify_text (GtkWidget *widget,
7357 const GdkColor *color)
7359 g_return_if_fail (GTK_IS_WIDGET (widget));
7360 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7362 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7366 * gtk_widget_modify_base:
7367 * @widget: a #GtkWidget
7368 * @state: the state for which to set the base color
7369 * @color: (allow-none): the color to assign (does not need to be allocated),
7370 * or %NULL to undo the effect of previous calls to
7371 * of gtk_widget_modify_base().
7373 * Sets the base color for a widget in a particular state.
7374 * All other style values are left untouched. The base color
7375 * is the background color used along with the text color
7376 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7377 * and #GtkTextView. See also gtk_widget_modify_style().
7379 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7380 * draw on their parent container's window and thus may not draw any
7381 * background themselves. This is the case for e.g. #GtkLabel. To modify
7382 * the background of such widgets, you have to set the base color on their
7383 * parent; if you want to set the background of a rectangular area around
7384 * a label, try placing the label in a #GtkEventBox widget and setting
7385 * the base color on that.
7388 gtk_widget_modify_base (GtkWidget *widget,
7390 const GdkColor *color)
7392 g_return_if_fail (GTK_IS_WIDGET (widget));
7393 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7395 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7399 modify_color_property (GtkWidget *widget,
7400 GtkRcStyle *rc_style,
7402 const GdkColor *color)
7404 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7405 GQuark property_name = g_quark_from_string (name);
7409 GtkRcProperty rc_property = {0};
7412 rc_property.type_name = type_name;
7413 rc_property.property_name = property_name;
7414 rc_property.origin = NULL;
7416 color_name = gdk_color_to_string (color);
7417 g_value_init (&rc_property.value, G_TYPE_STRING);
7418 g_value_take_string (&rc_property.value, color_name);
7420 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7422 g_value_unset (&rc_property.value);
7425 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7429 * gtk_widget_modify_cursor:
7430 * @widget: a #GtkWidget
7431 * @primary: the color to use for primary cursor (does not need to be
7432 * allocated), or %NULL to undo the effect of previous calls to
7433 * of gtk_widget_modify_cursor().
7434 * @secondary: the color to use for secondary cursor (does not need to be
7435 * allocated), or %NULL to undo the effect of previous calls to
7436 * of gtk_widget_modify_cursor().
7438 * Sets the cursor color to use in a widget, overriding the
7439 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7440 * style properties. All other style values are left untouched.
7441 * See also gtk_widget_modify_style().
7446 gtk_widget_modify_cursor (GtkWidget *widget,
7447 const GdkColor *primary,
7448 const GdkColor *secondary)
7450 GtkRcStyle *rc_style;
7452 g_return_if_fail (GTK_IS_WIDGET (widget));
7454 rc_style = gtk_widget_get_modifier_style (widget);
7456 modify_color_property (widget, rc_style, "cursor-color", primary);
7457 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7459 gtk_widget_modify_style (widget, rc_style);
7463 * gtk_widget_modify_font:
7464 * @widget: a #GtkWidget
7465 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7466 * the effect of previous calls to gtk_widget_modify_font().
7468 * Sets the font to use for a widget. All other style values are left
7469 * untouched. See also gtk_widget_modify_style().
7472 gtk_widget_modify_font (GtkWidget *widget,
7473 PangoFontDescription *font_desc)
7475 GtkRcStyle *rc_style;
7477 g_return_if_fail (GTK_IS_WIDGET (widget));
7479 rc_style = gtk_widget_get_modifier_style (widget);
7481 if (rc_style->font_desc)
7482 pango_font_description_free (rc_style->font_desc);
7485 rc_style->font_desc = pango_font_description_copy (font_desc);
7487 rc_style->font_desc = NULL;
7489 gtk_widget_modify_style (widget, rc_style);
7493 gtk_widget_real_direction_changed (GtkWidget *widget,
7494 GtkTextDirection previous_direction)
7496 gtk_widget_queue_resize (widget);
7500 gtk_widget_real_style_set (GtkWidget *widget,
7501 GtkStyle *previous_style)
7503 GtkWidgetPrivate *priv = widget->priv;
7505 if (gtk_widget_get_realized (widget) &&
7506 gtk_widget_get_has_window (widget))
7507 gtk_style_set_background (priv->style, priv->window, priv->state);
7511 gtk_widget_set_style_internal (GtkWidget *widget,
7513 gboolean initial_emission)
7515 GtkWidgetPrivate *priv = widget->priv;
7517 g_object_ref (widget);
7518 g_object_freeze_notify (G_OBJECT (widget));
7520 if (priv->style != style)
7522 GtkStyle *previous_style;
7524 if (gtk_widget_get_realized (widget))
7526 gtk_widget_reset_shapes (widget);
7527 gtk_style_detach (priv->style);
7530 previous_style = priv->style;
7531 priv->style = style;
7532 g_object_ref (priv->style);
7534 if (gtk_widget_get_realized (widget))
7535 priv->style = gtk_style_attach (priv->style, priv->window);
7537 gtk_widget_update_pango_context (widget);
7538 g_signal_emit (widget,
7539 widget_signals[STYLE_SET],
7541 initial_emission ? NULL : previous_style);
7542 g_object_unref (previous_style);
7544 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7545 gtk_widget_queue_resize (widget);
7547 else if (initial_emission)
7549 gtk_widget_update_pango_context (widget);
7550 g_signal_emit (widget,
7551 widget_signals[STYLE_SET],
7555 g_object_notify (G_OBJECT (widget), "style");
7556 g_object_thaw_notify (G_OBJECT (widget));
7557 g_object_unref (widget);
7561 GtkWidget *previous_toplevel;
7562 GdkScreen *previous_screen;
7563 GdkScreen *new_screen;
7564 } HierarchyChangedInfo;
7567 do_screen_change (GtkWidget *widget,
7568 GdkScreen *old_screen,
7569 GdkScreen *new_screen)
7571 if (old_screen != new_screen)
7575 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7577 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7580 _gtk_tooltip_hide (widget);
7581 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7586 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7587 gpointer client_data)
7589 GtkWidgetPrivate *priv = widget->priv;
7590 HierarchyChangedInfo *info = client_data;
7591 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7592 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7594 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7596 g_object_ref (widget);
7599 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7601 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7603 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7604 do_screen_change (widget, info->previous_screen, info->new_screen);
7606 if (GTK_IS_CONTAINER (widget))
7607 gtk_container_forall (GTK_CONTAINER (widget),
7608 gtk_widget_propagate_hierarchy_changed_recurse,
7611 g_object_unref (widget);
7616 * _gtk_widget_propagate_hierarchy_changed:
7617 * @widget: a #GtkWidget
7618 * @previous_toplevel: Previous toplevel
7620 * Propagates changes in the anchored state to a widget and all
7621 * children, unsetting or setting the %ANCHORED flag, and
7622 * emitting #GtkWidget::hierarchy-changed.
7625 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7626 GtkWidget *previous_toplevel)
7628 GtkWidgetPrivate *priv = widget->priv;
7629 HierarchyChangedInfo info;
7631 info.previous_toplevel = previous_toplevel;
7632 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7634 if (gtk_widget_is_toplevel (widget) ||
7635 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7636 info.new_screen = gtk_widget_get_screen (widget);
7638 info.new_screen = NULL;
7640 if (info.previous_screen)
7641 g_object_ref (info.previous_screen);
7642 if (previous_toplevel)
7643 g_object_ref (previous_toplevel);
7645 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7647 if (previous_toplevel)
7648 g_object_unref (previous_toplevel);
7649 if (info.previous_screen)
7650 g_object_unref (info.previous_screen);
7654 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7655 gpointer client_data)
7657 HierarchyChangedInfo *info = client_data;
7659 g_object_ref (widget);
7661 do_screen_change (widget, info->previous_screen, info->new_screen);
7663 if (GTK_IS_CONTAINER (widget))
7664 gtk_container_forall (GTK_CONTAINER (widget),
7665 gtk_widget_propagate_screen_changed_recurse,
7668 g_object_unref (widget);
7672 * gtk_widget_is_composited:
7673 * @widget: a #GtkWidget
7675 * Whether @widget can rely on having its alpha channel
7676 * drawn correctly. On X11 this function returns whether a
7677 * compositing manager is running for @widget's screen.
7679 * Please note that the semantics of this call will change
7680 * in the future if used on a widget that has a composited
7681 * window in its hierarchy (as set by gdk_window_set_composited()).
7683 * Return value: %TRUE if the widget can rely on its alpha
7684 * channel being drawn correctly.
7689 gtk_widget_is_composited (GtkWidget *widget)
7693 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7695 screen = gtk_widget_get_screen (widget);
7697 return gdk_screen_is_composited (screen);
7701 propagate_composited_changed (GtkWidget *widget,
7704 if (GTK_IS_CONTAINER (widget))
7706 gtk_container_forall (GTK_CONTAINER (widget),
7707 propagate_composited_changed,
7711 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7715 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7717 propagate_composited_changed (widget, NULL);
7721 * _gtk_widget_propagate_screen_changed:
7722 * @widget: a #GtkWidget
7723 * @previous_screen: Previous screen
7725 * Propagates changes in the screen for a widget to all
7726 * children, emitting #GtkWidget::screen-changed.
7729 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7730 GdkScreen *previous_screen)
7732 HierarchyChangedInfo info;
7734 info.previous_screen = previous_screen;
7735 info.new_screen = gtk_widget_get_screen (widget);
7737 if (previous_screen)
7738 g_object_ref (previous_screen);
7740 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7742 if (previous_screen)
7743 g_object_unref (previous_screen);
7747 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7749 if (gtk_widget_has_rc_style (widget))
7750 gtk_widget_reset_rc_style (widget);
7752 if (GTK_IS_CONTAINER (widget))
7753 gtk_container_forall (GTK_CONTAINER (widget),
7754 reset_rc_styles_recurse,
7760 * gtk_widget_reset_rc_styles:
7761 * @widget: a #GtkWidget.
7763 * Reset the styles of @widget and all descendents, so when
7764 * they are looked up again, they get the correct values
7765 * for the currently loaded RC file settings.
7767 * This function is not useful for applications.
7770 gtk_widget_reset_rc_styles (GtkWidget *widget)
7772 g_return_if_fail (GTK_IS_WIDGET (widget));
7774 reset_rc_styles_recurse (widget, NULL);
7778 * gtk_widget_get_default_style:
7780 * Returns the default style used by all widgets initially.
7782 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7783 * by GTK+ and should not be modified or freed.
7786 gtk_widget_get_default_style (void)
7788 if (!gtk_default_style)
7790 gtk_default_style = gtk_style_new ();
7791 g_object_ref (gtk_default_style);
7794 return gtk_default_style;
7797 static PangoContext *
7798 gtk_widget_peek_pango_context (GtkWidget *widget)
7800 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7804 * gtk_widget_get_pango_context:
7805 * @widget: a #GtkWidget
7807 * Gets a #PangoContext with the appropriate font map, font description,
7808 * and base direction for this widget. Unlike the context returned
7809 * by gtk_widget_create_pango_context(), this context is owned by
7810 * the widget (it can be used until the screen for the widget changes
7811 * or the widget is removed from its toplevel), and will be updated to
7812 * match any changes to the widget's attributes.
7814 * If you create and keep a #PangoLayout using this context, you must
7815 * deal with changes to the context by calling pango_layout_context_changed()
7816 * on the layout in response to the #GtkWidget::style-set and
7817 * #GtkWidget::direction-changed signals for the widget.
7819 * Return value: (transfer none): the #PangoContext for the widget.
7822 gtk_widget_get_pango_context (GtkWidget *widget)
7824 PangoContext *context;
7826 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7828 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7831 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7832 g_object_set_qdata_full (G_OBJECT (widget),
7833 quark_pango_context,
7842 update_pango_context (GtkWidget *widget,
7843 PangoContext *context)
7845 GtkWidgetPrivate *priv = widget->priv;
7847 pango_context_set_font_description (context, priv->style->font_desc);
7848 pango_context_set_base_dir (context,
7849 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7850 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7854 gtk_widget_update_pango_context (GtkWidget *widget)
7856 PangoContext *context = gtk_widget_peek_pango_context (widget);
7862 update_pango_context (widget, context);
7864 screen = gtk_widget_get_screen_unchecked (widget);
7867 pango_cairo_context_set_resolution (context,
7868 gdk_screen_get_resolution (screen));
7869 pango_cairo_context_set_font_options (context,
7870 gdk_screen_get_font_options (screen));
7876 * gtk_widget_create_pango_context:
7877 * @widget: a #GtkWidget
7879 * Creates a new #PangoContext with the appropriate font map,
7880 * font description, and base direction for drawing text for
7881 * this widget. See also gtk_widget_get_pango_context().
7883 * Return value: (transfer full): the new #PangoContext
7886 gtk_widget_create_pango_context (GtkWidget *widget)
7889 PangoContext *context;
7891 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7893 screen = gtk_widget_get_screen_unchecked (widget);
7896 GTK_NOTE (MULTIHEAD,
7897 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7899 screen = gdk_screen_get_default ();
7902 context = gdk_pango_context_get_for_screen (screen);
7904 update_pango_context (widget, context);
7905 pango_context_set_language (context, gtk_get_default_language ());
7911 * gtk_widget_create_pango_layout:
7912 * @widget: a #GtkWidget
7913 * @text: text to set on the layout (can be %NULL)
7915 * Creates a new #PangoLayout with the appropriate font map,
7916 * font description, and base direction for drawing text for
7919 * If you keep a #PangoLayout created in this way around, in order to
7920 * notify the layout of changes to the base direction or font of this
7921 * widget, you must call pango_layout_context_changed() in response to
7922 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
7925 * Return value: (transfer full): the new #PangoLayout
7928 gtk_widget_create_pango_layout (GtkWidget *widget,
7931 PangoLayout *layout;
7932 PangoContext *context;
7934 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7936 context = gtk_widget_get_pango_context (widget);
7937 layout = pango_layout_new (context);
7940 pango_layout_set_text (layout, text, -1);
7946 * gtk_widget_render_icon:
7947 * @widget: a #GtkWidget
7948 * @stock_id: a stock ID
7949 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
7950 * render at the size of the source and don't scale (if there are
7951 * multiple source sizes, GTK+ picks one of the available sizes).
7952 * @detail: (allow-none): render detail to pass to theme engine
7954 * A convenience function that uses the theme engine and RC file
7955 * settings for @widget to look up @stock_id and render it to
7956 * a pixbuf. @stock_id should be a stock icon ID such as
7957 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
7958 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
7959 * identifies the widget or code doing the rendering, so that
7960 * theme engines can special-case rendering for that widget or code.
7962 * The pixels in the returned #GdkPixbuf are shared with the rest of
7963 * the application and should not be modified. The pixbuf should be freed
7964 * after use with g_object_unref().
7966 * Return value: (transfer full): a new pixbuf, or %NULL if the
7967 * stock ID wasn't known
7970 gtk_widget_render_icon (GtkWidget *widget,
7971 const gchar *stock_id,
7973 const gchar *detail)
7975 GtkWidgetPrivate *priv;
7976 GtkIconSet *icon_set;
7979 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7980 g_return_val_if_fail (stock_id != NULL, NULL);
7981 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
7983 priv = widget->priv;
7985 gtk_widget_ensure_style (widget);
7987 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
7989 if (icon_set == NULL)
7992 retval = gtk_icon_set_render_icon (icon_set,
7994 gtk_widget_get_direction (widget),
7995 gtk_widget_get_state (widget),
8004 * gtk_widget_set_parent_window:
8005 * @widget: a #GtkWidget.
8006 * @parent_window: the new parent window.
8008 * Sets a non default parent window for @widget.
8011 gtk_widget_set_parent_window (GtkWidget *widget,
8012 GdkWindow *parent_window)
8014 GdkWindow *old_parent_window;
8016 g_return_if_fail (GTK_IS_WIDGET (widget));
8018 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8019 quark_parent_window);
8021 if (parent_window != old_parent_window)
8023 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8025 if (old_parent_window)
8026 g_object_unref (old_parent_window);
8028 g_object_ref (parent_window);
8033 * gtk_widget_get_parent_window:
8034 * @widget: a #GtkWidget.
8036 * Gets @widget's parent window.
8038 * Returns: (transfer none): the parent window of @widget.
8041 gtk_widget_get_parent_window (GtkWidget *widget)
8043 GtkWidgetPrivate *priv;
8044 GdkWindow *parent_window;
8046 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8048 priv = widget->priv;
8050 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8052 return (parent_window != NULL) ? parent_window :
8053 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8058 * gtk_widget_set_child_visible:
8059 * @widget: a #GtkWidget
8060 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8062 * Sets whether @widget should be mapped along with its when its parent
8063 * is mapped and @widget has been shown with gtk_widget_show().
8065 * The child visibility can be set for widget before it is added to
8066 * a container with gtk_widget_set_parent(), to avoid mapping
8067 * children unnecessary before immediately unmapping them. However
8068 * it will be reset to its default state of %TRUE when the widget
8069 * is removed from a container.
8071 * Note that changing the child visibility of a widget does not
8072 * queue a resize on the widget. Most of the time, the size of
8073 * a widget is computed from all visible children, whether or
8074 * not they are mapped. If this is not the case, the container
8075 * can queue a resize itself.
8077 * This function is only useful for container implementations and
8078 * never should be called by an application.
8081 gtk_widget_set_child_visible (GtkWidget *widget,
8082 gboolean is_visible)
8084 GtkWidgetPrivate *priv;
8086 g_return_if_fail (GTK_IS_WIDGET (widget));
8087 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8089 priv = widget->priv;
8091 g_object_ref (widget);
8094 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8097 GtkWidget *toplevel;
8099 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8101 toplevel = gtk_widget_get_toplevel (widget);
8102 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8103 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8106 if (priv->parent && gtk_widget_get_realized (priv->parent))
8108 if (gtk_widget_get_mapped (priv->parent) &&
8109 GTK_WIDGET_CHILD_VISIBLE (widget) &&
8110 gtk_widget_get_visible (widget))
8111 gtk_widget_map (widget);
8113 gtk_widget_unmap (widget);
8116 g_object_unref (widget);
8120 * gtk_widget_get_child_visible:
8121 * @widget: a #GtkWidget
8123 * Gets the value set with gtk_widget_set_child_visible().
8124 * If you feel a need to use this function, your code probably
8125 * needs reorganization.
8127 * This function is only useful for container implementations and
8128 * never should be called by an application.
8130 * Return value: %TRUE if the widget is mapped with the parent.
8133 gtk_widget_get_child_visible (GtkWidget *widget)
8135 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8137 return GTK_WIDGET_CHILD_VISIBLE (widget);
8141 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8143 GtkWidget *toplevel;
8145 toplevel = gtk_widget_get_toplevel (widget);
8147 if (gtk_widget_is_toplevel (toplevel))
8149 if (GTK_IS_WINDOW (toplevel))
8150 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8151 else if (GTK_IS_INVISIBLE (toplevel))
8152 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8159 * gtk_widget_get_screen:
8160 * @widget: a #GtkWidget
8162 * Get the #GdkScreen from the toplevel window associated with
8163 * this widget. This function can only be called after the widget
8164 * has been added to a widget hierarchy with a #GtkWindow
8167 * In general, you should only create screen specific
8168 * resources when a widget has been realized, and you should
8169 * free those resources when the widget is unrealized.
8171 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8176 gtk_widget_get_screen (GtkWidget *widget)
8180 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8182 screen = gtk_widget_get_screen_unchecked (widget);
8189 g_warning (G_STRLOC ": Can't get associated screen"
8190 " for a widget unless it is inside a toplevel GtkWindow\n"
8191 " widget type is %s associated top level type is %s",
8192 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8193 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8195 return gdk_screen_get_default ();
8200 * gtk_widget_has_screen:
8201 * @widget: a #GtkWidget
8203 * Checks whether there is a #GdkScreen is associated with
8204 * this widget. All toplevel widgets have an associated
8205 * screen, and all widgets added into a hierarchy with a toplevel
8206 * window at the top.
8208 * Return value: %TRUE if there is a #GdkScreen associcated
8214 gtk_widget_has_screen (GtkWidget *widget)
8216 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8218 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8222 * gtk_widget_get_display:
8223 * @widget: a #GtkWidget
8225 * Get the #GdkDisplay for the toplevel window associated with
8226 * this widget. This function can only be called after the widget
8227 * has been added to a widget hierarchy with a #GtkWindow at the top.
8229 * In general, you should only create display specific
8230 * resources when a widget has been realized, and you should
8231 * free those resources when the widget is unrealized.
8233 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8238 gtk_widget_get_display (GtkWidget *widget)
8240 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8242 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8246 * gtk_widget_get_root_window:
8247 * @widget: a #GtkWidget
8249 * Get the root window where this widget is located. This function can
8250 * only be called after the widget has been added to a widget
8251 * hierarchy with #GtkWindow at the top.
8253 * The root window is useful for such purposes as creating a popup
8254 * #GdkWindow associated with the window. In general, you should only
8255 * create display specific resources when a widget has been realized,
8256 * and you should free those resources when the widget is unrealized.
8258 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8263 gtk_widget_get_root_window (GtkWidget *widget)
8265 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8267 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8271 * gtk_widget_child_focus:
8272 * @widget: a #GtkWidget
8273 * @direction: direction of focus movement
8275 * This function is used by custom widget implementations; if you're
8276 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8277 * to a particular widget, and gtk_container_set_focus_chain() to
8278 * change the focus tab order. So you may want to investigate those
8279 * functions instead.
8281 * gtk_widget_child_focus() is called by containers as the user moves
8282 * around the window using keyboard shortcuts. @direction indicates
8283 * what kind of motion is taking place (up, down, left, right, tab
8284 * forward, tab backward). gtk_widget_child_focus() emits the
8285 * #GtkWidget::focus signal; widgets override the default handler
8286 * for this signal in order to implement appropriate focus behavior.
8288 * The default ::focus handler for a widget should return %TRUE if
8289 * moving in @direction left the focus on a focusable location inside
8290 * that widget, and %FALSE if moving in @direction moved the focus
8291 * outside the widget. If returning %TRUE, widgets normally
8292 * call gtk_widget_grab_focus() to place the focus accordingly;
8293 * if returning %FALSE, they don't modify the current focus location.
8295 * Return value: %TRUE if focus ended up inside @widget
8298 gtk_widget_child_focus (GtkWidget *widget,
8299 GtkDirectionType direction)
8301 gboolean return_val;
8303 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8305 if (!gtk_widget_get_visible (widget) ||
8306 !gtk_widget_is_sensitive (widget))
8309 /* child widgets must set CAN_FOCUS, containers
8310 * don't have to though.
8312 if (!GTK_IS_CONTAINER (widget) &&
8313 !gtk_widget_get_can_focus (widget))
8316 g_signal_emit (widget,
8317 widget_signals[FOCUS],
8319 direction, &return_val);
8325 * gtk_widget_keynav_failed:
8326 * @widget: a #GtkWidget
8327 * @direction: direction of focus movement
8329 * This function should be called whenever keyboard navigation within
8330 * a single widget hits a boundary. The function emits the
8331 * #GtkWidget::keynav-failed signal on the widget and its return
8332 * value should be interpreted in a way similar to the return value of
8333 * gtk_widget_child_focus():
8335 * When %TRUE is returned, stay in the widget, the failed keyboard
8336 * navigation is Ok and/or there is nowhere we can/should move the
8339 * When %FALSE is returned, the caller should continue with keyboard
8340 * navigation outside the widget, e.g. by calling
8341 * gtk_widget_child_focus() on the widget's toplevel.
8343 * The default ::keynav-failed handler returns %TRUE for
8344 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8345 * values of #GtkDirectionType, it looks at the
8346 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8347 * if the setting is %TRUE. This way the entire user interface
8348 * becomes cursor-navigatable on input devices such as mobile phones
8349 * which only have cursor keys but no tab key.
8351 * Whenever the default handler returns %TRUE, it also calls
8352 * gtk_widget_error_bell() to notify the user of the failed keyboard
8355 * A use case for providing an own implementation of ::keynav-failed
8356 * (either by connecting to it or by overriding it) would be a row of
8357 * #GtkEntry widgets where the user should be able to navigate the
8358 * entire row with the cursor keys, as e.g. known from user interfaces
8359 * that require entering license keys.
8361 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8362 * if the emitting widget should try to handle the keyboard
8363 * navigation attempt in its parent container(s).
8368 gtk_widget_keynav_failed (GtkWidget *widget,
8369 GtkDirectionType direction)
8371 gboolean return_val;
8373 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8375 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8376 direction, &return_val);
8382 * gtk_widget_error_bell:
8383 * @widget: a #GtkWidget
8385 * Notifies the user about an input-related error on this widget.
8386 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8387 * gdk_window_beep(), otherwise it does nothing.
8389 * Note that the effect of gdk_window_beep() can be configured in many
8390 * ways, depending on the windowing backend and the desktop environment
8391 * or window manager that is used.
8396 gtk_widget_error_bell (GtkWidget *widget)
8398 GtkWidgetPrivate *priv;
8399 GtkSettings* settings;
8402 g_return_if_fail (GTK_IS_WIDGET (widget));
8404 priv = widget->priv;
8406 settings = gtk_widget_get_settings (widget);
8410 g_object_get (settings,
8411 "gtk-error-bell", &beep,
8414 if (beep && priv->window)
8415 gdk_window_beep (priv->window);
8419 gtk_widget_set_usize_internal (GtkWidget *widget,
8423 GtkWidgetAuxInfo *aux_info;
8424 gboolean changed = FALSE;
8426 g_object_freeze_notify (G_OBJECT (widget));
8428 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8430 if (width > -2 && aux_info->width != width)
8432 g_object_notify (G_OBJECT (widget), "width-request");
8433 aux_info->width = width;
8436 if (height > -2 && aux_info->height != height)
8438 g_object_notify (G_OBJECT (widget), "height-request");
8439 aux_info->height = height;
8443 if (gtk_widget_get_visible (widget) && changed)
8444 gtk_widget_queue_resize (widget);
8446 g_object_thaw_notify (G_OBJECT (widget));
8450 * gtk_widget_set_size_request:
8451 * @widget: a #GtkWidget
8452 * @width: width @widget should request, or -1 to unset
8453 * @height: height @widget should request, or -1 to unset
8455 * Sets the minimum size of a widget; that is, the widget's size
8456 * request will be @width by @height. You can use this function to
8457 * force a widget to be either larger or smaller than it normally
8460 * In most cases, gtk_window_set_default_size() is a better choice for
8461 * toplevel windows than this function; setting the default size will
8462 * still allow users to shrink the window. Setting the size request
8463 * will force them to leave the window at least as large as the size
8464 * request. When dealing with window sizes,
8465 * gtk_window_set_geometry_hints() can be a useful function as well.
8467 * Note the inherent danger of setting any fixed size - themes,
8468 * translations into other languages, different fonts, and user action
8469 * can all change the appropriate size for a given widget. So, it's
8470 * basically impossible to hardcode a size that will always be
8473 * The size request of a widget is the smallest size a widget can
8474 * accept while still functioning well and drawing itself correctly.
8475 * However in some strange cases a widget may be allocated less than
8476 * its requested size, and in many cases a widget may be allocated more
8477 * space than it requested.
8479 * If the size request in a given direction is -1 (unset), then
8480 * the "natural" size request of the widget will be used instead.
8482 * Widgets can't actually be allocated a size less than 1 by 1, but
8483 * you can pass 0,0 to this function to mean "as small as possible."
8485 * The size request set here does not include any margin from the
8486 * #GtkWidget properties margin-left, margin-right, margin-top, and
8487 * margin-bottom, but it does include pretty much all other padding
8488 * or border properties set by any subclass of #GtkWidget.
8491 gtk_widget_set_size_request (GtkWidget *widget,
8495 g_return_if_fail (GTK_IS_WIDGET (widget));
8496 g_return_if_fail (width >= -1);
8497 g_return_if_fail (height >= -1);
8504 gtk_widget_set_usize_internal (widget, width, height);
8509 * gtk_widget_get_size_request:
8510 * @widget: a #GtkWidget
8511 * @width: (out) (allow-none): return location for width, or %NULL
8512 * @height: (out) (allow-none): return location for height, or %NULL
8514 * Gets the size request that was explicitly set for the widget using
8515 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8516 * @height indicates that that dimension has not been set explicitly
8517 * and the natural requisition of the widget will be used intead. See
8518 * gtk_widget_set_size_request(). To get the size a widget will
8519 * actually request, call gtk_size_request_get_size() instead of
8523 gtk_widget_get_size_request (GtkWidget *widget,
8527 const GtkWidgetAuxInfo *aux_info;
8529 g_return_if_fail (GTK_IS_WIDGET (widget));
8531 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8534 *width = aux_info->width;
8537 *height = aux_info->height;
8541 * gtk_widget_set_events:
8542 * @widget: a #GtkWidget
8543 * @events: event mask
8545 * Sets the event mask (see #GdkEventMask) for a widget. The event
8546 * mask determines which events a widget will receive. Keep in mind
8547 * that different widgets have different default event masks, and by
8548 * changing the event mask you may disrupt a widget's functionality,
8549 * so be careful. This function must be called while a widget is
8550 * unrealized. Consider gtk_widget_add_events() for widgets that are
8551 * already realized, or if you want to preserve the existing event
8552 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8553 * to get events on those widgets, place them inside a #GtkEventBox
8554 * and receive events on the event box.
8557 gtk_widget_set_events (GtkWidget *widget,
8560 g_return_if_fail (GTK_IS_WIDGET (widget));
8561 g_return_if_fail (!gtk_widget_get_realized (widget));
8563 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8564 GINT_TO_POINTER (events));
8565 g_object_notify (G_OBJECT (widget), "events");
8569 * gtk_widget_set_device_events:
8570 * @widget: a #GtkWidget
8571 * @device: a #GdkDevice
8572 * @events: event mask
8574 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8575 * mask determines which events a widget will receive from @device. Keep
8576 * in mind that different widgets have different default event masks, and by
8577 * changing the event mask you may disrupt a widget's functionality,
8578 * so be careful. This function must be called while a widget is
8579 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8580 * already realized, or if you want to preserve the existing event
8581 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8582 * to get events on those widgets, place them inside a #GtkEventBox
8583 * and receive events on the event box.
8588 gtk_widget_set_device_events (GtkWidget *widget,
8590 GdkEventMask events)
8592 GHashTable *device_events;
8594 g_return_if_fail (GTK_IS_WIDGET (widget));
8595 g_return_if_fail (GDK_IS_DEVICE (device));
8596 g_return_if_fail (!gtk_widget_get_realized (widget));
8598 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8600 if (G_UNLIKELY (!device_events))
8602 device_events = g_hash_table_new (NULL, NULL);
8603 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8604 (GDestroyNotify) g_hash_table_unref);
8607 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8611 gtk_widget_add_events_internal_list (GtkWidget *widget,
8618 for (l = window_list; l != NULL; l = l->next)
8620 GdkWindow *window = l->data;
8623 gdk_window_get_user_data (window, &user_data);
8624 if (user_data == widget)
8629 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8631 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8633 children = gdk_window_get_children (window);
8634 gtk_widget_add_events_internal_list (widget, device, events, children);
8635 g_list_free (children);
8641 gtk_widget_add_events_internal (GtkWidget *widget,
8645 GtkWidgetPrivate *priv = widget->priv;
8648 if (!gtk_widget_get_has_window (widget))
8649 window_list = gdk_window_get_children (priv->window);
8651 window_list = g_list_prepend (NULL, priv->window);
8653 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8655 g_list_free (window_list);
8659 * gtk_widget_add_events:
8660 * @widget: a #GtkWidget
8661 * @events: an event mask, see #GdkEventMask
8663 * Adds the events in the bitfield @events to the event mask for
8664 * @widget. See gtk_widget_set_events() for details.
8667 gtk_widget_add_events (GtkWidget *widget,
8672 g_return_if_fail (GTK_IS_WIDGET (widget));
8674 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8675 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8676 GINT_TO_POINTER (old_events | events));
8678 if (gtk_widget_get_realized (widget))
8679 gtk_widget_add_events_internal (widget, NULL, events);
8681 g_object_notify (G_OBJECT (widget), "events");
8685 * gtk_widget_add_device_events:
8686 * @widget: a #GtkWidget
8687 * @device: a #GdkDevice
8688 * @events: an event mask, see #GdkEventMask
8690 * Adds the device events in the bitfield @events to the event mask for
8691 * @widget. See gtk_widget_set_device_events() for details.
8696 gtk_widget_add_device_events (GtkWidget *widget,
8698 GdkEventMask events)
8700 GdkEventMask old_events;
8701 GHashTable *device_events;
8703 g_return_if_fail (GTK_IS_WIDGET (widget));
8704 g_return_if_fail (GDK_IS_DEVICE (device));
8706 old_events = gtk_widget_get_device_events (widget, device);
8708 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8710 if (G_UNLIKELY (!device_events))
8712 device_events = g_hash_table_new (NULL, NULL);
8713 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8714 (GDestroyNotify) g_hash_table_unref);
8717 g_hash_table_insert (device_events, device,
8718 GUINT_TO_POINTER (old_events | events));
8720 if (gtk_widget_get_realized (widget))
8721 gtk_widget_add_events_internal (widget, device, events);
8723 g_object_notify (G_OBJECT (widget), "events");
8727 * gtk_widget_set_extension_events:
8728 * @widget: a #GtkWidget
8729 * @mode: bitfield of extension events to receive
8731 * Sets the extension events mask to @mode. See #GdkExtensionMode
8732 * and gdk_input_set_extension_events().
8735 gtk_widget_set_extension_events (GtkWidget *widget,
8736 GdkExtensionMode mode)
8738 g_return_if_fail (GTK_IS_WIDGET (widget));
8740 if (gtk_widget_get_realized (widget))
8741 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8743 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8744 GINT_TO_POINTER (mode));
8745 g_object_notify (G_OBJECT (widget), "extension-events");
8749 * gtk_widget_get_toplevel:
8750 * @widget: a #GtkWidget
8752 * This function returns the topmost widget in the container hierarchy
8753 * @widget is a part of. If @widget has no parent widgets, it will be
8754 * returned as the topmost widget. No reference will be added to the
8755 * returned widget; it should not be unreferenced.
8757 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8758 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8760 * %NULL if @widget wasn't inside a toplevel window, and if the
8761 * window was inside a #GtkWindow-derived widget which was in turn
8762 * inside the toplevel #GtkWindow. While the second case may
8763 * seem unlikely, it actually happens when a #GtkPlug is embedded
8764 * inside a #GtkSocket within the same application.
8766 * To reliably find the toplevel #GtkWindow, use
8767 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8768 * is set on the result.
8770 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8771 * if (gtk_widget_is_toplevel (toplevel))
8773 * /* Perform action on toplevel. */
8777 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8778 * if there's no ancestor.
8781 gtk_widget_get_toplevel (GtkWidget *widget)
8783 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8785 while (widget->priv->parent)
8786 widget = widget->priv->parent;
8792 * gtk_widget_get_ancestor:
8793 * @widget: a #GtkWidget
8794 * @widget_type: ancestor type
8796 * Gets the first ancestor of @widget with type @widget_type. For example,
8797 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8798 * the first #GtkBox that's an ancestor of @widget. No reference will be
8799 * added to the returned widget; it should not be unreferenced. See note
8800 * about checking for a toplevel #GtkWindow in the docs for
8801 * gtk_widget_get_toplevel().
8803 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8804 * considers @widget to be an ancestor of itself.
8806 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8809 gtk_widget_get_ancestor (GtkWidget *widget,
8812 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8814 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8815 widget = widget->priv->parent;
8817 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8824 * gtk_widget_get_visual:
8825 * @widget: a #GtkWidget
8827 * Gets the visual that will be used to render @widget.
8829 * Return value: (transfer none): the visual for @widget
8832 gtk_widget_get_visual (GtkWidget *widget)
8836 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8838 for (w = widget; w != NULL; w = w->priv->parent)
8840 if (gtk_widget_get_has_window (w) &&
8842 return gdk_window_get_visual (w->priv->window);
8844 if (GTK_IS_WINDOW (w))
8845 return _gtk_window_get_visual (GTK_WINDOW (w));
8848 return gdk_screen_get_system_visual (gdk_screen_get_default ());
8852 * gtk_widget_get_settings:
8853 * @widget: a #GtkWidget
8855 * Gets the settings object holding the settings (global property
8856 * settings, RC file information, etc) used for this widget.
8858 * Note that this function can only be called when the #GtkWidget
8859 * is attached to a toplevel, since the settings object is specific
8860 * to a particular #GdkScreen.
8862 * Return value: (transfer none): the relevant #GtkSettings object
8865 gtk_widget_get_settings (GtkWidget *widget)
8867 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8869 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8873 * gtk_widget_get_events:
8874 * @widget: a #GtkWidget
8876 * Returns the event mask for the widget (a bitfield containing flags
8877 * from the #GdkEventMask enumeration). These are the events that the widget
8880 * Return value: event mask for @widget
8883 gtk_widget_get_events (GtkWidget *widget)
8885 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8887 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8891 * gtk_widget_get_device_events:
8892 * @widget: a #GtkWidget
8893 * @device: a #GdkDevice
8895 * Returns the events mask for the widget corresponding to an specific device. These
8896 * are the events that the widget will receive when @device operates on it.
8898 * Returns: device event mask for @widget
8903 gtk_widget_get_device_events (GtkWidget *widget,
8906 GHashTable *device_events;
8908 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8909 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
8911 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8916 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
8920 * gtk_widget_get_extension_events:
8921 * @widget: a #GtkWidget
8923 * Retrieves the extension events the widget will receive; see
8924 * gdk_input_set_extension_events().
8926 * Return value: extension events for @widget
8929 gtk_widget_get_extension_events (GtkWidget *widget)
8931 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8933 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
8937 * gtk_widget_get_pointer:
8938 * @widget: a #GtkWidget
8939 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
8940 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
8942 * Obtains the location of the mouse pointer in widget coordinates.
8943 * Widget coordinates are a bit odd; for historical reasons, they are
8944 * defined as @widget->window coordinates for widgets that are not
8945 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
8946 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
8949 gtk_widget_get_pointer (GtkWidget *widget,
8953 GtkWidgetPrivate *priv;
8955 g_return_if_fail (GTK_IS_WIDGET (widget));
8957 priv = widget->priv;
8964 if (gtk_widget_get_realized (widget))
8966 gdk_window_get_pointer (priv->window, x, y, NULL);
8968 if (!gtk_widget_get_has_window (widget))
8971 *x -= priv->allocation.x;
8973 *y -= priv->allocation.y;
8979 * gtk_widget_is_ancestor:
8980 * @widget: a #GtkWidget
8981 * @ancestor: another #GtkWidget
8983 * Determines whether @widget is somewhere inside @ancestor, possibly with
8984 * intermediate containers.
8986 * Return value: %TRUE if @ancestor contains @widget as a child,
8987 * grandchild, great grandchild, etc.
8990 gtk_widget_is_ancestor (GtkWidget *widget,
8991 GtkWidget *ancestor)
8993 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8994 g_return_val_if_fail (ancestor != NULL, FALSE);
8998 if (widget->priv->parent == ancestor)
9000 widget = widget->priv->parent;
9006 static GQuark quark_composite_name = 0;
9009 * gtk_widget_set_composite_name:
9010 * @widget: a #GtkWidget.
9011 * @name: the name to set
9013 * Sets a widgets composite name. The widget must be
9014 * a composite child of its parent; see gtk_widget_push_composite_child().
9017 gtk_widget_set_composite_name (GtkWidget *widget,
9020 g_return_if_fail (GTK_IS_WIDGET (widget));
9021 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
9022 g_return_if_fail (name != NULL);
9024 if (!quark_composite_name)
9025 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9027 g_object_set_qdata_full (G_OBJECT (widget),
9028 quark_composite_name,
9034 * gtk_widget_get_composite_name:
9035 * @widget: a #GtkWidget
9037 * Obtains the composite name of a widget.
9039 * Returns: the composite name of @widget, or %NULL if @widget is not
9040 * a composite child. The string should be freed when it is no
9044 gtk_widget_get_composite_name (GtkWidget *widget)
9046 GtkWidgetPrivate *priv;
9048 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9050 priv = widget->priv;
9052 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
9053 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9060 * gtk_widget_push_composite_child:
9062 * Makes all newly-created widgets as composite children until
9063 * the corresponding gtk_widget_pop_composite_child() call.
9065 * A composite child is a child that's an implementation detail of the
9066 * container it's inside and should not be visible to people using the
9067 * container. Composite children aren't treated differently by GTK (but
9068 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9069 * builders might want to treat them in a different way.
9071 * Here is a simple example:
9073 * gtk_widget_push_composite_child ();
9074 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9075 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9076 * gtk_widget_pop_composite_child ();
9077 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9078 * GTK_WIDGET (scrolled_window));
9079 * g_object_ref (scrolled_window->hscrollbar);
9083 gtk_widget_push_composite_child (void)
9085 composite_child_stack++;
9089 * gtk_widget_pop_composite_child:
9091 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9094 gtk_widget_pop_composite_child (void)
9096 if (composite_child_stack)
9097 composite_child_stack--;
9101 gtk_widget_emit_direction_changed (GtkWidget *widget,
9102 GtkTextDirection old_dir)
9104 gtk_widget_update_pango_context (widget);
9106 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9110 * gtk_widget_set_direction:
9111 * @widget: a #GtkWidget
9112 * @dir: the new direction
9114 * Sets the reading direction on a particular widget. This direction
9115 * controls the primary direction for widgets containing text,
9116 * and also the direction in which the children of a container are
9117 * packed. The ability to set the direction is present in order
9118 * so that correct localization into languages with right-to-left
9119 * reading directions can be done. Generally, applications will
9120 * let the default reading direction present, except for containers
9121 * where the containers are arranged in an order that is explicitely
9122 * visual rather than logical (such as buttons for text justification).
9124 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9125 * set by gtk_widget_set_default_direction() will be used.
9128 gtk_widget_set_direction (GtkWidget *widget,
9129 GtkTextDirection dir)
9131 GtkTextDirection old_dir;
9133 g_return_if_fail (GTK_IS_WIDGET (widget));
9134 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9136 old_dir = gtk_widget_get_direction (widget);
9138 if (dir == GTK_TEXT_DIR_NONE)
9139 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9142 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9143 if (dir == GTK_TEXT_DIR_LTR)
9144 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9146 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9149 if (old_dir != gtk_widget_get_direction (widget))
9150 gtk_widget_emit_direction_changed (widget, old_dir);
9154 * gtk_widget_get_direction:
9155 * @widget: a #GtkWidget
9157 * Gets the reading direction for a particular widget. See
9158 * gtk_widget_set_direction().
9160 * Return value: the reading direction for the widget.
9163 gtk_widget_get_direction (GtkWidget *widget)
9165 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9167 if (GTK_WIDGET_DIRECTION_SET (widget))
9168 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9170 return gtk_default_direction;
9174 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9176 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9178 g_object_ref (widget);
9180 if (!GTK_WIDGET_DIRECTION_SET (widget))
9181 gtk_widget_emit_direction_changed (widget, old_dir);
9183 if (GTK_IS_CONTAINER (widget))
9184 gtk_container_forall (GTK_CONTAINER (widget),
9185 gtk_widget_set_default_direction_recurse,
9188 g_object_unref (widget);
9192 * gtk_widget_set_default_direction:
9193 * @dir: the new default direction. This cannot be
9194 * %GTK_TEXT_DIR_NONE.
9196 * Sets the default reading direction for widgets where the
9197 * direction has not been explicitly set by gtk_widget_set_direction().
9200 gtk_widget_set_default_direction (GtkTextDirection dir)
9202 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9204 if (dir != gtk_default_direction)
9206 GList *toplevels, *tmp_list;
9207 GtkTextDirection old_dir = gtk_default_direction;
9209 gtk_default_direction = dir;
9211 tmp_list = toplevels = gtk_window_list_toplevels ();
9212 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9216 gtk_widget_set_default_direction_recurse (tmp_list->data,
9217 GUINT_TO_POINTER (old_dir));
9218 g_object_unref (tmp_list->data);
9219 tmp_list = tmp_list->next;
9222 g_list_free (toplevels);
9227 * gtk_widget_get_default_direction:
9229 * Obtains the current default reading direction. See
9230 * gtk_widget_set_default_direction().
9232 * Return value: the current default direction.
9235 gtk_widget_get_default_direction (void)
9237 return gtk_default_direction;
9241 gtk_widget_dispose (GObject *object)
9243 GtkWidget *widget = GTK_WIDGET (object);
9244 GtkWidgetPrivate *priv = widget->priv;
9247 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9248 else if (gtk_widget_get_visible (widget))
9249 gtk_widget_hide (widget);
9251 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9252 if (gtk_widget_get_realized (widget))
9253 gtk_widget_unrealize (widget);
9255 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9259 gtk_widget_real_destroy (GtkObject *object)
9261 /* gtk_object_destroy() will already hold a refcount on object */
9262 GtkWidget *widget = GTK_WIDGET (object);
9263 GtkWidgetPrivate *priv = widget->priv;
9265 /* wipe accelerator closures (keep order) */
9266 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9267 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9269 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9270 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9272 gtk_grab_remove (widget);
9274 g_object_unref (priv->style);
9275 priv->style = gtk_widget_get_default_style ();
9276 g_object_ref (priv->style);
9278 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9282 gtk_widget_finalize (GObject *object)
9284 GtkWidget *widget = GTK_WIDGET (object);
9285 GtkWidgetPrivate *priv = widget->priv;
9286 GtkWidgetAuxInfo *aux_info;
9287 GtkAccessible *accessible;
9289 gtk_grab_remove (widget);
9291 g_object_unref (priv->style);
9294 g_free (priv->name);
9296 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9298 gtk_widget_aux_info_destroy (aux_info);
9300 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9302 g_object_unref (accessible);
9304 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9307 /*****************************************
9308 * gtk_widget_real_map:
9313 *****************************************/
9316 gtk_widget_real_map (GtkWidget *widget)
9318 GtkWidgetPrivate *priv = widget->priv;
9320 g_assert (gtk_widget_get_realized (widget));
9322 if (!gtk_widget_get_mapped (widget))
9324 gtk_widget_set_mapped (widget, TRUE);
9326 if (gtk_widget_get_has_window (widget))
9327 gdk_window_show (priv->window);
9331 /*****************************************
9332 * gtk_widget_real_unmap:
9337 *****************************************/
9340 gtk_widget_real_unmap (GtkWidget *widget)
9342 GtkWidgetPrivate *priv = widget->priv;
9344 if (gtk_widget_get_mapped (widget))
9346 gtk_widget_set_mapped (widget, FALSE);
9348 if (gtk_widget_get_has_window (widget))
9349 gdk_window_hide (priv->window);
9353 /*****************************************
9354 * gtk_widget_real_realize:
9359 *****************************************/
9362 gtk_widget_real_realize (GtkWidget *widget)
9364 GtkWidgetPrivate *priv = widget->priv;
9366 g_assert (!gtk_widget_get_has_window (widget));
9368 gtk_widget_set_realized (widget, TRUE);
9371 priv->window = gtk_widget_get_parent_window (widget);
9372 g_object_ref (priv->window);
9374 priv->style = gtk_style_attach (priv->style, priv->window);
9377 /*****************************************
9378 * gtk_widget_real_unrealize:
9383 *****************************************/
9386 gtk_widget_real_unrealize (GtkWidget *widget)
9388 GtkWidgetPrivate *priv = widget->priv;
9390 if (gtk_widget_get_mapped (widget))
9391 gtk_widget_real_unmap (widget);
9393 gtk_widget_set_mapped (widget, FALSE);
9395 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9398 /* We must do unrealize child widget BEFORE container widget.
9399 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9400 * So, unrealizing container widget bofore its children causes the problem
9401 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9404 if (GTK_IS_CONTAINER (widget))
9405 gtk_container_forall (GTK_CONTAINER (widget),
9406 (GtkCallback) gtk_widget_unrealize,
9409 gtk_style_detach (priv->style);
9410 if (gtk_widget_get_has_window (widget))
9412 gdk_window_set_user_data (priv->window, NULL);
9413 gdk_window_destroy (priv->window);
9414 priv->window = NULL;
9418 g_object_unref (priv->window);
9419 priv->window = NULL;
9422 gtk_selection_remove_all (widget);
9424 gtk_widget_set_realized (widget, FALSE);
9428 gtk_widget_real_size_request (GtkWidget *widget,
9429 GtkRequisition *requisition)
9431 requisition->width = 0;
9432 requisition->height = 0;
9436 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9437 GtkOrientation orientation,
9442 const GtkWidgetAuxInfo *aux_info;
9444 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9446 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9447 aux_info->width > 0)
9449 *minimum_size = MAX (*minimum_size, aux_info->width);
9451 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9452 aux_info->height > 0)
9454 *minimum_size = MAX (*minimum_size, aux_info->height);
9457 /* Fix it if set_size_request made natural size smaller than min size.
9458 * This would also silently fix broken widgets, but we warn about them
9459 * in gtksizerequest.c when calling their size request vfuncs.
9461 *natural_size = MAX (*natural_size, *minimum_size);
9463 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9465 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9466 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9470 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9471 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9476 * _gtk_widget_peek_request_cache:
9478 * Returns the address of the widget's request cache (strictly for
9479 * internal use in gtksizerequest.c)
9481 * Return value: the address of @widget's size request cache.
9484 _gtk_widget_peek_request_cache (GtkWidget *widget)
9486 /* Don't bother slowing things down with the return_if_fail guards here */
9487 return &widget->priv->requests;
9491 * _gtk_widget_set_device_window:
9492 * @widget: a #GtkWidget.
9493 * @device: a #GdkDevice.
9494 * @window: the new device window.
9496 * Sets pointer window for @widget and @device. Does not ref @window.
9497 * Actually stores it on the #GdkScreen, but you don't need to know that.
9500 _gtk_widget_set_device_window (GtkWidget *widget,
9504 GtkWidgetPrivate *priv;
9506 GHashTable *device_window;
9508 g_return_if_fail (GTK_IS_WIDGET (widget));
9509 g_return_if_fail (GDK_IS_DEVICE (device));
9510 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9512 priv = widget->priv;
9514 if (!gtk_widget_get_realized (widget))
9517 screen = gdk_window_get_screen (priv->window);
9518 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9520 if (G_UNLIKELY (!device_window))
9522 device_window = g_hash_table_new (NULL, NULL);
9523 g_object_set_qdata_full (G_OBJECT (screen),
9524 quark_pointer_window,
9526 (GDestroyNotify) g_hash_table_destroy);
9530 g_hash_table_insert (device_window, device, window);
9532 g_hash_table_remove (device_window, device);
9536 * _gtk_widget_get_device_window:
9537 * @widget: a #GtkWidget.
9538 * @device: a #GdkDevice.
9540 * Return value: the device window set on the #GdkScreen @widget is attached
9544 _gtk_widget_get_device_window (GtkWidget *widget,
9547 GtkWidgetPrivate *priv;
9549 GHashTable *device_window;
9553 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9554 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9556 priv = widget->priv;
9558 if (!gtk_widget_get_realized (widget))
9561 screen = gdk_window_get_screen (priv->window);
9562 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9564 if (G_UNLIKELY (!device_window))
9567 window = g_hash_table_lookup (device_window, device);
9572 gdk_window_get_user_data (window, (gpointer *) &w);
9581 * _gtk_widget_list_devices:
9582 * @widget: a #GtkWidget.
9584 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9585 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9589 _gtk_widget_list_devices (GtkWidget *widget)
9591 GtkWidgetPrivate *priv;
9593 GHashTableIter iter;
9594 GHashTable *device_window;
9595 GList *devices = NULL;
9596 gpointer key, value;
9598 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9600 priv = widget->priv;
9602 if (!gtk_widget_get_realized (widget))
9605 screen = gdk_window_get_screen (priv->window);
9606 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9608 if (G_UNLIKELY (!device_window))
9611 g_hash_table_iter_init (&iter, device_window);
9613 while (g_hash_table_iter_next (&iter, &key, &value))
9615 GdkDevice *device = key;
9616 GdkWindow *window = value;
9621 gdk_window_get_user_data (window, (gpointer *) &w);
9624 devices = g_list_prepend (devices, device);
9632 synth_crossing (GtkWidget *widget,
9636 GdkCrossingMode mode,
9637 GdkNotifyType detail)
9641 event = gdk_event_new (type);
9643 event->crossing.window = g_object_ref (window);
9644 event->crossing.send_event = TRUE;
9645 event->crossing.subwindow = g_object_ref (window);
9646 event->crossing.time = GDK_CURRENT_TIME;
9647 event->crossing.x = event->crossing.y = 0;
9648 event->crossing.x_root = event->crossing.y_root = 0;
9649 event->crossing.mode = mode;
9650 event->crossing.detail = detail;
9651 event->crossing.focus = FALSE;
9652 event->crossing.state = 0;
9653 gdk_event_set_device (event, device);
9656 widget = gtk_get_event_widget (event);
9659 gtk_widget_event_internal (widget, event);
9661 gdk_event_free (event);
9665 * _gtk_widget_synthesize_crossing:
9666 * @from: the #GtkWidget the virtual pointer is leaving.
9667 * @to: the #GtkWidget the virtual pointer is moving to.
9668 * @mode: the #GdkCrossingMode to place on the synthesized events.
9670 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9672 * The real pointer window is the window that most recently received an enter notify
9673 * event. Windows that don't select for crossing events can't become the real
9674 * poiner window. The real pointer widget that owns the real pointer window. The
9675 * effective pointer window is the same as the real pointer window unless the real
9676 * pointer widget is either insensitive or there is a grab on a widget that is not
9677 * an ancestor of the real pointer widget (in which case the effective pointer
9678 * window should be the root window).
9680 * When the effective pointer window is the same as the real poiner window, we
9681 * receive crossing events from the windowing system. When the effective pointer
9682 * window changes to become different from the real pointer window we synthesize
9683 * crossing events, attempting to follow X protocol rules:
9685 * When the root window becomes the effective pointer window:
9686 * - leave notify on real pointer window, detail Ancestor
9687 * - leave notify on all of its ancestors, detail Virtual
9688 * - enter notify on root window, detail Inferior
9690 * When the root window ceases to be the effective pointer window:
9691 * - leave notify on root window, detail Inferior
9692 * - enter notify on all ancestors of real pointer window, detail Virtual
9693 * - enter notify on real pointer window, detail Ancestor
9696 _gtk_widget_synthesize_crossing (GtkWidget *from,
9699 GdkCrossingMode mode)
9701 GdkWindow *from_window = NULL, *to_window = NULL;
9703 g_return_if_fail (from != NULL || to != NULL);
9707 from_window = _gtk_widget_get_device_window (from, device);
9710 from_window = from->priv->window;
9715 to_window = _gtk_widget_get_device_window (to, device);
9718 to_window = to->priv->window;
9721 if (from_window == NULL && to_window == NULL)
9723 else if (from_window != NULL && to_window == NULL)
9725 GList *from_ancestors = NULL, *list;
9726 GdkWindow *from_ancestor = from_window;
9728 while (from_ancestor != NULL)
9730 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9731 if (from_ancestor == NULL)
9733 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9736 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9737 device, mode, GDK_NOTIFY_ANCESTOR);
9738 for (list = g_list_last (from_ancestors); list; list = list->prev)
9740 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9741 device, mode, GDK_NOTIFY_VIRTUAL);
9744 /* XXX: enter/inferior on root window? */
9746 g_list_free (from_ancestors);
9748 else if (from_window == NULL && to_window != NULL)
9750 GList *to_ancestors = NULL, *list;
9751 GdkWindow *to_ancestor = to_window;
9753 while (to_ancestor != NULL)
9755 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9756 if (to_ancestor == NULL)
9758 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9761 /* XXX: leave/inferior on root window? */
9763 for (list = to_ancestors; list; list = list->next)
9765 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9766 device, mode, GDK_NOTIFY_VIRTUAL);
9768 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9769 device, mode, GDK_NOTIFY_ANCESTOR);
9771 g_list_free (to_ancestors);
9773 else if (from_window == to_window)
9777 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9778 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9780 while (from_ancestor != NULL || to_ancestor != NULL)
9782 if (from_ancestor != NULL)
9784 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9785 if (from_ancestor == to_window)
9788 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9790 if (to_ancestor != NULL)
9792 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9793 if (to_ancestor == from_window)
9796 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9799 if (to_ancestor == from_window)
9801 if (mode != GDK_CROSSING_GTK_UNGRAB)
9802 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9803 device, mode, GDK_NOTIFY_INFERIOR);
9804 for (list = to_ancestors; list; list = list->next)
9805 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9806 device, mode, GDK_NOTIFY_VIRTUAL);
9807 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9808 device, mode, GDK_NOTIFY_ANCESTOR);
9810 else if (from_ancestor == to_window)
9812 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9813 device, mode, GDK_NOTIFY_ANCESTOR);
9814 for (list = g_list_last (from_ancestors); list; list = list->prev)
9816 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9817 device, mode, GDK_NOTIFY_VIRTUAL);
9819 if (mode != GDK_CROSSING_GTK_GRAB)
9820 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9821 device, mode, GDK_NOTIFY_INFERIOR);
9825 while (from_ancestors != NULL && to_ancestors != NULL
9826 && from_ancestors->data == to_ancestors->data)
9828 from_ancestors = g_list_delete_link (from_ancestors,
9830 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9833 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9834 device, mode, GDK_NOTIFY_NONLINEAR);
9836 for (list = g_list_last (from_ancestors); list; list = list->prev)
9838 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9839 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9841 for (list = to_ancestors; list; list = list->next)
9843 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9844 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9846 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9847 device, mode, GDK_NOTIFY_NONLINEAR);
9849 g_list_free (from_ancestors);
9850 g_list_free (to_ancestors);
9855 gtk_widget_propagate_state (GtkWidget *widget,
9858 GtkWidgetPrivate *priv = widget->priv;
9859 guint8 old_state = gtk_widget_get_state (widget);
9860 guint8 old_saved_state = priv->saved_state;
9862 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9863 * parent_sensitive==TRUE on a sensitive widget
9867 if (data->parent_sensitive)
9868 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9870 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9872 if (gtk_widget_is_sensitive (widget))
9874 if (data->state_restoration)
9875 priv->state = priv->saved_state;
9877 priv->state = data->state;
9881 if (!data->state_restoration)
9883 if (data->state != GTK_STATE_INSENSITIVE)
9884 priv->saved_state = data->state;
9886 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9887 priv->saved_state = gtk_widget_get_state (widget);
9888 priv->state = GTK_STATE_INSENSITIVE;
9891 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9895 window = gtk_widget_get_toplevel (widget);
9896 if (window && gtk_widget_is_toplevel (window))
9897 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9900 if (old_state != gtk_widget_get_state (widget) ||
9901 old_saved_state != priv->saved_state)
9903 g_object_ref (widget);
9905 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9906 gtk_grab_remove (widget);
9908 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
9910 if (!GTK_WIDGET_SHADOWED (widget))
9912 GList *event_windows = NULL;
9915 devices = _gtk_widget_list_devices (widget);
9917 for (d = devices; d; d = d->next)
9923 window = _gtk_widget_get_device_window (widget, device);
9925 /* Do not propagate more than once to the
9926 * same window if non-multidevice aware.
9928 if (!gdk_window_get_support_multidevice (window) &&
9929 g_list_find (event_windows, window))
9932 if (!gtk_widget_is_sensitive (widget))
9933 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
9934 GDK_CROSSING_STATE_CHANGED);
9935 else if (old_state == GTK_STATE_INSENSITIVE)
9936 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
9937 GDK_CROSSING_STATE_CHANGED);
9939 event_windows = g_list_prepend (event_windows, window);
9942 g_list_free (event_windows);
9943 g_list_free (devices);
9946 if (GTK_IS_CONTAINER (widget))
9948 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
9949 if (data->use_forall)
9950 gtk_container_forall (GTK_CONTAINER (widget),
9951 (GtkCallback) gtk_widget_propagate_state,
9954 gtk_container_foreach (GTK_CONTAINER (widget),
9955 (GtkCallback) gtk_widget_propagate_state,
9958 g_object_unref (widget);
9962 static const GtkWidgetAuxInfo default_aux_info = {
9970 * _gtk_widget_get_aux_info:
9971 * @widget: a #GtkWidget
9972 * @create: if %TRUE, create the structure if it doesn't exist
9974 * Get the #GtkWidgetAuxInfo structure for the widget.
9976 * Return value: the #GtkAuxInfo structure for the widget, or
9977 * %NULL if @create is %FALSE and one doesn't already exist.
9980 _gtk_widget_get_aux_info (GtkWidget *widget,
9983 GtkWidgetAuxInfo *aux_info;
9985 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
9986 if (!aux_info && create)
9988 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
9990 *aux_info = default_aux_info;
9992 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
9998 static const GtkWidgetAuxInfo*
9999 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10001 GtkWidgetAuxInfo *aux_info;
10003 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10004 if (aux_info == NULL)
10006 return &default_aux_info;
10014 /*****************************************
10015 * gtk_widget_aux_info_destroy:
10020 *****************************************/
10023 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10025 g_slice_free (GtkWidgetAuxInfo, aux_info);
10029 * gtk_widget_shape_combine_region:
10030 * @widget: a #GtkWidget
10031 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10033 * Sets a shape for this widget's GDK window. This allows for
10034 * transparent windows etc., see gdk_window_shape_combine_region()
10035 * for more information.
10040 gtk_widget_shape_combine_region (GtkWidget *widget,
10041 cairo_region_t *region)
10043 GtkWidgetPrivate *priv;
10045 g_return_if_fail (GTK_IS_WIDGET (widget));
10046 /* set_shape doesn't work on widgets without gdk window */
10047 g_return_if_fail (gtk_widget_get_has_window (widget));
10049 priv = widget->priv;
10051 if (region == NULL)
10053 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10056 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10058 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10062 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10064 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10065 cairo_region_copy (region),
10066 (GDestroyNotify) cairo_region_destroy);
10068 /* set shape if widget has a gdk window already.
10069 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10072 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10077 * gtk_widget_input_shape_combine_region:
10078 * @widget: a #GtkWidget
10079 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10081 * Sets an input shape for this widget's GDK window. This allows for
10082 * windows which react to mouse click in a nonrectangular region, see
10083 * gdk_window_input_shape_combine_region() for more information.
10088 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10089 cairo_region_t *region)
10091 GtkWidgetPrivate *priv;
10093 g_return_if_fail (GTK_IS_WIDGET (widget));
10094 /* set_shape doesn't work on widgets without gdk window */
10095 g_return_if_fail (gtk_widget_get_has_window (widget));
10097 priv = widget->priv;
10099 if (region == NULL)
10102 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10104 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10108 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10109 cairo_region_copy (region),
10110 (GDestroyNotify) cairo_region_destroy);
10112 /* set shape if widget has a gdk window already.
10113 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10116 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10122 gtk_reset_shapes_recurse (GtkWidget *widget,
10128 gdk_window_get_user_data (window, &data);
10129 if (data != widget)
10132 gdk_window_shape_combine_region (window, NULL, 0, 0);
10133 for (list = gdk_window_peek_children (window); list; list = list->next)
10134 gtk_reset_shapes_recurse (widget, list->data);
10138 * gtk_widget_reset_shapes:
10139 * @widget: a #GtkWidget
10141 * Recursively resets the shape on this widget and its descendants.
10144 gtk_widget_reset_shapes (GtkWidget *widget)
10146 GtkWidgetPrivate *priv;
10148 g_return_if_fail (GTK_IS_WIDGET (widget));
10149 g_return_if_fail (gtk_widget_get_realized (widget));
10151 priv = widget->priv;
10153 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10154 gtk_reset_shapes_recurse (widget, priv->window);
10157 /* style properties
10161 * gtk_widget_class_install_style_property_parser:
10162 * @klass: a #GtkWidgetClass
10163 * @pspec: the #GParamSpec for the style property
10164 * @parser: the parser for the style property
10166 * Installs a style property on a widget class.
10169 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10171 GtkRcPropertyParser parser)
10173 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10174 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10175 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10176 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10178 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10180 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10181 G_OBJECT_CLASS_NAME (klass),
10186 g_param_spec_ref_sink (pspec);
10187 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10188 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10192 * gtk_widget_class_install_style_property:
10193 * @klass: a #GtkWidgetClass
10194 * @pspec: the #GParamSpec for the property
10196 * Installs a style property on a widget class. The parser for the
10197 * style property is determined by the value type of @pspec.
10200 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10203 GtkRcPropertyParser parser;
10205 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10206 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10208 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10210 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10214 * gtk_widget_class_find_style_property:
10215 * @klass: a #GtkWidgetClass
10216 * @property_name: the name of the style property to find
10217 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10218 * style property with that name.
10220 * Finds a style property of a widget class by name.
10225 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10226 const gchar *property_name)
10228 g_return_val_if_fail (property_name != NULL, NULL);
10230 return g_param_spec_pool_lookup (style_property_spec_pool,
10232 G_OBJECT_CLASS_TYPE (klass),
10237 * gtk_widget_class_list_style_properties:
10238 * @klass: a #GtkWidgetClass
10239 * @n_properties: location to return the number of style properties found
10240 * @returns: an newly allocated array of #GParamSpec*. The array must
10241 * be freed with g_free().
10243 * Returns all style properties of a widget class.
10248 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10249 guint *n_properties)
10251 GParamSpec **pspecs;
10254 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10255 G_OBJECT_CLASS_TYPE (klass),
10264 * gtk_widget_style_get_property:
10265 * @widget: a #GtkWidget
10266 * @property_name: the name of a style property
10267 * @value: location to return the property value
10269 * Gets the value of a style property of @widget.
10272 gtk_widget_style_get_property (GtkWidget *widget,
10273 const gchar *property_name,
10276 GtkWidgetPrivate *priv;
10279 g_return_if_fail (GTK_IS_WIDGET (widget));
10280 g_return_if_fail (property_name != NULL);
10281 g_return_if_fail (G_IS_VALUE (value));
10283 priv = widget->priv;
10285 g_object_ref (widget);
10286 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10288 G_OBJECT_TYPE (widget),
10291 g_warning ("%s: widget class `%s' has no property named `%s'",
10293 G_OBJECT_TYPE_NAME (widget),
10297 const GValue *peek_value;
10299 peek_value = _gtk_style_peek_property_value (priv->style,
10300 G_OBJECT_TYPE (widget),
10302 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10304 /* auto-conversion of the caller's value type
10306 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10307 g_value_copy (peek_value, value);
10308 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10309 g_value_transform (peek_value, value);
10311 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10313 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10314 G_VALUE_TYPE_NAME (value));
10316 g_object_unref (widget);
10320 * gtk_widget_style_get_valist:
10321 * @widget: a #GtkWidget
10322 * @first_property_name: the name of the first property to get
10323 * @var_args: a <type>va_list</type> of pairs of property names and
10324 * locations to return the property values, starting with the location
10325 * for @first_property_name.
10327 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10331 gtk_widget_style_get_valist (GtkWidget *widget,
10332 const gchar *first_property_name,
10335 GtkWidgetPrivate *priv;
10338 g_return_if_fail (GTK_IS_WIDGET (widget));
10340 priv = widget->priv;
10342 g_object_ref (widget);
10344 name = first_property_name;
10347 const GValue *peek_value;
10351 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10353 G_OBJECT_TYPE (widget),
10357 g_warning ("%s: widget class `%s' has no property named `%s'",
10359 G_OBJECT_TYPE_NAME (widget),
10363 /* style pspecs are always readable so we can spare that check here */
10365 peek_value = _gtk_style_peek_property_value (priv->style,
10366 G_OBJECT_TYPE (widget),
10368 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10369 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10372 g_warning ("%s: %s", G_STRLOC, error);
10377 name = va_arg (var_args, gchar*);
10380 g_object_unref (widget);
10384 * gtk_widget_style_get:
10385 * @widget: a #GtkWidget
10386 * @first_property_name: the name of the first property to get
10387 * @Varargs: pairs of property names and locations to
10388 * return the property values, starting with the location for
10389 * @first_property_name, terminated by %NULL.
10391 * Gets the values of a multiple style properties of @widget.
10394 gtk_widget_style_get (GtkWidget *widget,
10395 const gchar *first_property_name,
10400 g_return_if_fail (GTK_IS_WIDGET (widget));
10402 va_start (var_args, first_property_name);
10403 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10409 * @widget: a #GtkWidget
10410 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10411 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10412 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10414 * Obtains the full path to @widget. The path is simply the name of a
10415 * widget and all its parents in the container hierarchy, separated by
10416 * periods. The name of a widget comes from
10417 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10418 * in gtkrc configuration files. Widget names are the type of the
10419 * widget by default (e.g. "GtkButton") or can be set to an
10420 * application-specific value with gtk_widget_set_name(). By setting
10421 * the name of a widget, you allow users or theme authors to apply
10422 * styles to that specific widget in their gtkrc
10423 * file. @path_reversed_p fills in the path in reverse order,
10424 * i.e. starting with @widget's name instead of starting with the name
10425 * of @widget's outermost ancestor.
10428 gtk_widget_path (GtkWidget *widget,
10429 guint *path_length,
10431 gchar **path_reversed)
10433 static gchar *rev_path = NULL;
10434 static guint tmp_path_len = 0;
10437 g_return_if_fail (GTK_IS_WIDGET (widget));
10442 const gchar *string;
10447 string = gtk_widget_get_name (widget);
10448 l = strlen (string);
10449 while (tmp_path_len <= len + l + 1)
10451 tmp_path_len += INIT_PATH_SIZE;
10452 rev_path = g_realloc (rev_path, tmp_path_len);
10454 s = string + l - 1;
10455 d = rev_path + len;
10456 while (s >= string)
10460 widget = widget->priv->parent;
10463 rev_path[len++] = '.';
10465 rev_path[len++] = 0;
10470 *path_length = len - 1;
10472 *path_reversed = g_strdup (rev_path);
10475 *path = g_strdup (rev_path);
10476 g_strreverse (*path);
10481 * gtk_widget_class_path:
10482 * @widget: a #GtkWidget
10483 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10484 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10485 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10488 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10489 * never uses a custom name set with gtk_widget_set_name().
10493 gtk_widget_class_path (GtkWidget *widget,
10494 guint *path_length,
10496 gchar **path_reversed)
10498 static gchar *rev_path = NULL;
10499 static guint tmp_path_len = 0;
10502 g_return_if_fail (GTK_IS_WIDGET (widget));
10507 const gchar *string;
10512 string = g_type_name (G_OBJECT_TYPE (widget));
10513 l = strlen (string);
10514 while (tmp_path_len <= len + l + 1)
10516 tmp_path_len += INIT_PATH_SIZE;
10517 rev_path = g_realloc (rev_path, tmp_path_len);
10519 s = string + l - 1;
10520 d = rev_path + len;
10521 while (s >= string)
10525 widget = widget->priv->parent;
10528 rev_path[len++] = '.';
10530 rev_path[len++] = 0;
10535 *path_length = len - 1;
10537 *path_reversed = g_strdup (rev_path);
10540 *path = g_strdup (rev_path);
10541 g_strreverse (*path);
10546 * gtk_requisition_new:
10548 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10550 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10551 * be freed with gtk_requisition_free().
10556 gtk_requisition_new (void)
10558 return g_slice_new0 (GtkRequisition);
10562 * gtk_requisition_copy:
10563 * @requisition: a #GtkRequisition
10565 * Copies a #GtkRequisition.
10567 * Returns: a copy of @requisition
10570 gtk_requisition_copy (const GtkRequisition *requisition)
10572 return g_slice_dup (GtkRequisition, requisition);
10576 * gtk_requisition_free:
10577 * @requisition: a #GtkRequisition
10579 * Frees a #GtkRequisition.
10582 gtk_requisition_free (GtkRequisition *requisition)
10584 g_slice_free (GtkRequisition, requisition);
10587 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10588 gtk_requisition_copy,
10589 gtk_requisition_free)
10592 * gtk_widget_get_accessible:
10593 * @widget: a #GtkWidget
10595 * Returns the accessible object that describes the widget to an
10596 * assistive technology.
10598 * If no accessibility library is loaded (i.e. no ATK implementation library is
10599 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10600 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10601 * if no class-specific #AtkObject implementation is available for the widget
10602 * instance in question, it will inherit an #AtkObject implementation from the
10603 * first ancestor class for which such an implementation is defined.
10605 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10606 * library contains more information about accessible objects and their uses.
10608 * Returns: (transfer none): the #AtkObject associated with @widget
10611 gtk_widget_get_accessible (GtkWidget *widget)
10613 GtkWidgetClass *klass;
10615 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10617 klass = GTK_WIDGET_GET_CLASS (widget);
10619 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10621 return klass->get_accessible (widget);
10625 gtk_widget_real_get_accessible (GtkWidget *widget)
10627 AtkObject* accessible;
10629 accessible = g_object_get_qdata (G_OBJECT (widget),
10630 quark_accessible_object);
10633 AtkObjectFactory *factory;
10634 AtkRegistry *default_registry;
10636 default_registry = atk_get_default_registry ();
10637 factory = atk_registry_get_factory (default_registry,
10638 G_TYPE_FROM_INSTANCE (widget));
10640 atk_object_factory_create_accessible (factory,
10641 G_OBJECT (widget));
10642 g_object_set_qdata (G_OBJECT (widget),
10643 quark_accessible_object,
10650 * Initialize a AtkImplementorIface instance's virtual pointers as
10651 * appropriate to this implementor's class (GtkWidget).
10654 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10656 iface->ref_accessible = gtk_widget_ref_accessible;
10660 gtk_widget_ref_accessible (AtkImplementor *implementor)
10662 AtkObject *accessible;
10664 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10666 g_object_ref (accessible);
10671 * GtkBuildable implementation
10673 static GQuark quark_builder_has_default = 0;
10674 static GQuark quark_builder_has_focus = 0;
10675 static GQuark quark_builder_atk_relations = 0;
10676 static GQuark quark_builder_set_name = 0;
10679 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10681 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10682 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10683 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10684 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10686 iface->set_name = gtk_widget_buildable_set_name;
10687 iface->get_name = gtk_widget_buildable_get_name;
10688 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10689 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10690 iface->parser_finished = gtk_widget_buildable_parser_finished;
10691 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10692 iface->custom_finished = gtk_widget_buildable_custom_finished;
10696 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10699 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10700 g_strdup (name), g_free);
10703 static const gchar *
10704 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10706 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10710 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10711 GtkBuilder *builder,
10712 const gchar *childname)
10714 if (strcmp (childname, "accessible") == 0)
10715 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10721 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10722 GtkBuilder *builder,
10724 const GValue *value)
10726 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10727 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10728 GINT_TO_POINTER (TRUE));
10729 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10730 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10731 GINT_TO_POINTER (TRUE));
10733 g_object_set_property (G_OBJECT (buildable), name, value);
10738 gchar *action_name;
10739 GString *description;
10741 gboolean translatable;
10751 free_action (AtkActionData *data, gpointer user_data)
10753 g_free (data->action_name);
10754 g_string_free (data->description, TRUE);
10755 g_free (data->context);
10756 g_slice_free (AtkActionData, data);
10760 free_relation (AtkRelationData *data, gpointer user_data)
10762 g_free (data->target);
10763 g_free (data->type);
10764 g_slice_free (AtkRelationData, data);
10768 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10769 GtkBuilder *builder)
10771 GSList *atk_relations;
10773 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10774 gtk_widget_grab_default (GTK_WIDGET (buildable));
10775 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10776 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10778 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10779 quark_builder_atk_relations);
10782 AtkObject *accessible;
10783 AtkRelationSet *relation_set;
10786 AtkRelationType relation_type;
10787 AtkObject *target_accessible;
10789 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10790 relation_set = atk_object_ref_relation_set (accessible);
10792 for (l = atk_relations; l; l = l->next)
10794 AtkRelationData *relation = (AtkRelationData*)l->data;
10796 target = gtk_builder_get_object (builder, relation->target);
10799 g_warning ("Target object %s in <relation> does not exist",
10803 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10804 g_assert (target_accessible != NULL);
10806 relation_type = atk_relation_type_for_name (relation->type);
10807 if (relation_type == ATK_RELATION_NULL)
10809 g_warning ("<relation> type %s not found",
10813 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10814 target_accessible);
10816 g_object_unref (relation_set);
10818 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10819 g_slist_free (atk_relations);
10820 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10829 } AccessibilitySubParserData;
10832 accessibility_start_element (GMarkupParseContext *context,
10833 const gchar *element_name,
10834 const gchar **names,
10835 const gchar **values,
10836 gpointer user_data,
10839 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10841 gint line_number, char_number;
10843 if (strcmp (element_name, "relation") == 0)
10845 gchar *target = NULL;
10846 gchar *type = NULL;
10847 AtkRelationData *relation;
10849 for (i = 0; names[i]; i++)
10851 if (strcmp (names[i], "target") == 0)
10852 target = g_strdup (values[i]);
10853 else if (strcmp (names[i], "type") == 0)
10854 type = g_strdup (values[i]);
10857 g_markup_parse_context_get_position (context,
10860 g_set_error (error,
10862 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10863 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10865 line_number, char_number, names[i], "relation");
10872 if (!target || !type)
10874 g_markup_parse_context_get_position (context,
10877 g_set_error (error,
10879 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10880 "%s:%d:%d <%s> requires attribute \"%s\"",
10882 line_number, char_number, "relation",
10883 type ? "target" : "type");
10889 relation = g_slice_new (AtkRelationData);
10890 relation->target = target;
10891 relation->type = type;
10893 data->relations = g_slist_prepend (data->relations, relation);
10895 else if (strcmp (element_name, "action") == 0)
10897 const gchar *action_name = NULL;
10898 const gchar *description = NULL;
10899 const gchar *msg_context = NULL;
10900 gboolean translatable = FALSE;
10901 AtkActionData *action;
10903 for (i = 0; names[i]; i++)
10905 if (strcmp (names[i], "action_name") == 0)
10906 action_name = values[i];
10907 else if (strcmp (names[i], "description") == 0)
10908 description = values[i];
10909 else if (strcmp (names[i], "translatable") == 0)
10911 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
10914 else if (strcmp (names[i], "comments") == 0)
10916 /* do nothing, comments are for translators */
10918 else if (strcmp (names[i], "context") == 0)
10919 msg_context = values[i];
10922 g_markup_parse_context_get_position (context,
10925 g_set_error (error,
10927 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10928 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10930 line_number, char_number, names[i], "action");
10937 g_markup_parse_context_get_position (context,
10940 g_set_error (error,
10942 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10943 "%s:%d:%d <%s> requires attribute \"%s\"",
10945 line_number, char_number, "action",
10950 action = g_slice_new (AtkActionData);
10951 action->action_name = g_strdup (action_name);
10952 action->description = g_string_new (description);
10953 action->context = g_strdup (msg_context);
10954 action->translatable = translatable;
10956 data->actions = g_slist_prepend (data->actions, action);
10958 else if (strcmp (element_name, "accessibility") == 0)
10961 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
10965 accessibility_text (GMarkupParseContext *context,
10968 gpointer user_data,
10971 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10973 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
10975 AtkActionData *action = data->actions->data;
10977 g_string_append_len (action->description, text, text_len);
10981 static const GMarkupParser accessibility_parser =
10983 accessibility_start_element,
10985 accessibility_text,
10994 } AccelGroupParserData;
10997 accel_group_start_element (GMarkupParseContext *context,
10998 const gchar *element_name,
10999 const gchar **names,
11000 const gchar **values,
11001 gpointer user_data,
11006 guint modifiers = 0;
11007 gchar *signal = NULL;
11008 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11010 for (i = 0; names[i]; i++)
11012 if (strcmp (names[i], "key") == 0)
11013 key = gdk_keyval_from_name (values[i]);
11014 else if (strcmp (names[i], "modifiers") == 0)
11016 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11022 else if (strcmp (names[i], "signal") == 0)
11023 signal = g_strdup (values[i]);
11026 if (key == 0 || signal == NULL)
11028 g_warning ("<accelerator> requires key and signal attributes");
11031 parser_data->key = key;
11032 parser_data->modifiers = modifiers;
11033 parser_data->signal = signal;
11036 static const GMarkupParser accel_group_parser =
11038 accel_group_start_element,
11042 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11043 GtkBuilder *builder,
11045 const gchar *tagname,
11046 GMarkupParser *parser,
11049 g_assert (buildable);
11051 if (strcmp (tagname, "accelerator") == 0)
11053 AccelGroupParserData *parser_data;
11055 parser_data = g_slice_new0 (AccelGroupParserData);
11056 parser_data->object = g_object_ref (buildable);
11057 *parser = accel_group_parser;
11058 *data = parser_data;
11061 if (strcmp (tagname, "accessibility") == 0)
11063 AccessibilitySubParserData *parser_data;
11065 parser_data = g_slice_new0 (AccessibilitySubParserData);
11066 *parser = accessibility_parser;
11067 *data = parser_data;
11074 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11075 GtkWidget *toplevel,
11076 gpointer user_data)
11078 AccelGroupParserData *accel_data;
11079 GSList *accel_groups;
11080 GtkAccelGroup *accel_group;
11082 g_return_if_fail (GTK_IS_WIDGET (widget));
11083 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11084 g_return_if_fail (user_data != NULL);
11086 accel_data = (AccelGroupParserData*)user_data;
11087 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11088 if (g_slist_length (accel_groups) == 0)
11090 accel_group = gtk_accel_group_new ();
11091 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11095 g_assert (g_slist_length (accel_groups) == 1);
11096 accel_group = g_slist_nth_data (accel_groups, 0);
11099 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11100 accel_data->signal,
11103 accel_data->modifiers,
11104 GTK_ACCEL_VISIBLE);
11106 g_object_unref (accel_data->object);
11107 g_free (accel_data->signal);
11108 g_slice_free (AccelGroupParserData, accel_data);
11112 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11113 GtkBuilder *builder,
11115 const gchar *tagname,
11116 gpointer user_data)
11118 AccelGroupParserData *accel_data;
11119 AccessibilitySubParserData *a11y_data;
11120 GtkWidget *toplevel;
11122 if (strcmp (tagname, "accelerator") == 0)
11124 accel_data = (AccelGroupParserData*)user_data;
11125 g_assert (accel_data->object);
11127 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11129 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11131 else if (strcmp (tagname, "accessibility") == 0)
11133 a11y_data = (AccessibilitySubParserData*)user_data;
11135 if (a11y_data->actions)
11137 AtkObject *accessible;
11142 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11144 action = ATK_ACTION (accessible);
11145 n_actions = atk_action_get_n_actions (action);
11147 for (l = a11y_data->actions; l; l = l->next)
11149 AtkActionData *action_data = (AtkActionData*)l->data;
11151 for (i = 0; i < n_actions; i++)
11152 if (strcmp (atk_action_get_name (action, i),
11153 action_data->action_name) == 0)
11158 gchar *description;
11160 if (action_data->translatable && action_data->description->len)
11161 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11162 action_data->context,
11163 action_data->description->str);
11165 description = action_data->description->str;
11167 atk_action_set_description (action, i, description);
11171 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11172 g_slist_free (a11y_data->actions);
11175 if (a11y_data->relations)
11176 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11177 a11y_data->relations);
11179 g_slice_free (AccessibilitySubParserData, a11y_data);
11184 * GtkSizeRequest implementation
11187 gtk_widget_real_get_width (GtkSizeRequest *widget,
11188 gint *minimum_size,
11189 gint *natural_size)
11199 gtk_widget_real_get_height (GtkSizeRequest *widget,
11200 gint *minimum_size,
11201 gint *natural_size)
11211 gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
11213 gint *minimum_height,
11214 gint *natural_height)
11216 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
11220 gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
11222 gint *minimum_width,
11223 gint *natural_width)
11225 GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
11229 gtk_widget_size_request_init (GtkSizeRequestIface *iface)
11231 iface->get_width = gtk_widget_real_get_width;
11232 iface->get_height = gtk_widget_real_get_height;
11233 iface->get_width_for_height = gtk_widget_real_get_width_for_height;
11234 iface->get_height_for_width = gtk_widget_real_get_height_for_width;
11238 * gtk_widget_get_halign:
11239 * @widget: a #GtkWidget
11241 * Gets the value of the #GtkWidget:halign property.
11243 * Returns: the horizontal alignment of @widget
11246 gtk_widget_get_halign (GtkWidget *widget)
11248 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11249 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11253 * gtk_widget_set_halign:
11254 * @widget: a #GtkWidget
11255 * @align: the horizontal alignment
11257 * Sets the horizontal alignment of @widget.
11258 * See the #GtkWidget:halign property.
11261 gtk_widget_set_halign (GtkWidget *widget,
11264 GtkWidgetAuxInfo *aux_info;
11266 g_return_if_fail (GTK_IS_WIDGET (widget));
11268 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11270 if (aux_info->halign == align)
11273 aux_info->halign = align;
11274 gtk_widget_queue_resize (widget);
11275 g_object_notify (G_OBJECT (widget), "halign");
11279 * gtk_widget_get_valign:
11280 * @widget: a #GtkWidget
11282 * Gets the value of the #GtkWidget:valign property.
11284 * Returns: the vertical alignment of @widget
11287 gtk_widget_get_valign (GtkWidget *widget)
11289 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11290 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11294 * gtk_widget_set_valign:
11295 * @widget: a #GtkWidget
11296 * @align: the vertical alignment
11298 * Sets the vertical alignment of @widget.
11299 * See the #GtkWidget:valign property.
11302 gtk_widget_set_valign (GtkWidget *widget,
11305 GtkWidgetAuxInfo *aux_info;
11307 g_return_if_fail (GTK_IS_WIDGET (widget));
11309 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11311 if (aux_info->valign == align)
11314 aux_info->valign = align;
11315 gtk_widget_queue_resize (widget);
11316 g_object_notify (G_OBJECT (widget), "valign");
11320 * gtk_widget_get_margin_left:
11321 * @widget: a #GtkWidget
11323 * Gets the value of the #GtkWidget:margin-left property.
11325 * Returns: The left margin of @widget
11328 gtk_widget_get_margin_left (GtkWidget *widget)
11330 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11332 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11336 * gtk_widget_set_margin_left:
11337 * @widget: a #GtkWidget
11338 * @margin: the left margin
11340 * Sets the left margin of @widget.
11341 * See the #GtkWidget:margin-left property.
11344 gtk_widget_set_margin_left (GtkWidget *widget,
11347 GtkWidgetAuxInfo *aux_info;
11349 g_return_if_fail (GTK_IS_WIDGET (widget));
11350 g_return_if_fail (margin <= G_MAXINT16);
11352 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11354 if (aux_info->margin.left == margin)
11357 aux_info->margin.left = margin;
11358 gtk_widget_queue_resize (widget);
11359 g_object_notify (G_OBJECT (widget), "margin-left");
11363 * gtk_widget_get_margin_right:
11364 * @widget: a #GtkWidget
11366 * Gets the value of the #GtkWidget:margin-right property.
11368 * Returns: The left margin of @widget
11371 gtk_widget_get_margin_right (GtkWidget *widget)
11373 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11375 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11379 * gtk_widget_set_margin_right:
11380 * @widget: a #GtkWidget
11381 * @margin: the right margin
11383 * Sets the right margin of @widget.
11384 * See the #GtkWidget:margin-right property.
11387 gtk_widget_set_margin_right (GtkWidget *widget,
11390 GtkWidgetAuxInfo *aux_info;
11392 g_return_if_fail (GTK_IS_WIDGET (widget));
11393 g_return_if_fail (margin <= G_MAXINT16);
11395 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11397 if (aux_info->margin.right == margin)
11400 aux_info->margin.right = margin;
11401 gtk_widget_queue_resize (widget);
11402 g_object_notify (G_OBJECT (widget), "margin-right");
11406 * gtk_widget_get_margin_top:
11407 * @widget: a #GtkWidget
11409 * Gets the value of the #GtkWidget:margin-top property.
11411 * Returns: The top margin of @widget
11414 gtk_widget_get_margin_top (GtkWidget *widget)
11416 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11418 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11422 * gtk_widget_set_margin_top:
11423 * @widget: a #GtkWidget
11424 * @margin: the top margin
11426 * Sets the top margin of @widget.
11427 * See the #GtkWidget:margin-top property.
11430 gtk_widget_set_margin_top (GtkWidget *widget,
11433 GtkWidgetAuxInfo *aux_info;
11435 g_return_if_fail (GTK_IS_WIDGET (widget));
11436 g_return_if_fail (margin <= G_MAXINT16);
11438 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11440 if (aux_info->margin.top == margin)
11443 aux_info->margin.top = margin;
11444 gtk_widget_queue_resize (widget);
11445 g_object_notify (G_OBJECT (widget), "margin-top");
11449 * gtk_widget_get_margin_bottom:
11450 * @widget: a #GtkWidget
11452 * Gets the value of the #GtkWidget:margin-bottom property.
11454 * Returns: The bottom margin of @widget
11457 gtk_widget_get_margin_bottom (GtkWidget *widget)
11459 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11461 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11465 * gtk_widget_set_margin_bottom:
11466 * @widget: a #GtkWidget
11467 * @margin: the bottom margin
11469 * Sets the bottom margin of @widget.
11470 * See the #GtkWidget:margin-bottom property.
11473 gtk_widget_set_margin_bottom (GtkWidget *widget,
11476 GtkWidgetAuxInfo *aux_info;
11478 g_return_if_fail (GTK_IS_WIDGET (widget));
11479 g_return_if_fail (margin <= G_MAXINT16);
11481 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11483 if (aux_info->margin.bottom == margin)
11486 aux_info->margin.bottom = margin;
11487 gtk_widget_queue_resize (widget);
11488 g_object_notify (G_OBJECT (widget), "margin-bottom");
11492 * gtk_widget_get_clipboard:
11493 * @widget: a #GtkWidget
11494 * @selection: a #GdkAtom which identifies the clipboard
11495 * to use. %GDK_SELECTION_CLIPBOARD gives the
11496 * default clipboard. Another common value
11497 * is %GDK_SELECTION_PRIMARY, which gives
11498 * the primary X selection.
11500 * Returns the clipboard object for the given selection to
11501 * be used with @widget. @widget must have a #GdkDisplay
11502 * associated with it, so must be attached to a toplevel
11505 * Return value: (transfer none): the appropriate clipboard object. If no
11506 * clipboard already exists, a new one will
11507 * be created. Once a clipboard object has
11508 * been created, it is persistent for all time.
11513 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11515 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11516 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11518 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11523 * gtk_widget_list_mnemonic_labels:
11524 * @widget: a #GtkWidget
11526 * Returns a newly allocated list of the widgets, normally labels, for
11527 * which this widget is the target of a mnemonic (see for example,
11528 * gtk_label_set_mnemonic_widget()).
11530 * The widgets in the list are not individually referenced. If you
11531 * want to iterate through the list and perform actions involving
11532 * callbacks that might destroy the widgets, you
11533 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11534 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11535 * widgets afterwards.
11537 * Return value: (element-type GtkWidget) (transfer container): the list of
11538 * mnemonic labels; free this list
11539 * with g_list_free() when you are done with it.
11544 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11546 GList *list = NULL;
11549 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11551 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11552 list = g_list_prepend (list, l->data);
11558 * gtk_widget_add_mnemonic_label:
11559 * @widget: a #GtkWidget
11560 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11562 * Adds a widget to the list of mnemonic labels for
11563 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11564 * list of mnemonic labels for the widget is cleared when the
11565 * widget is destroyed, so the caller must make sure to update
11566 * its internal state at this point as well, by using a connection
11567 * to the #GtkWidget::destroy signal or a weak notifier.
11572 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11575 GSList *old_list, *new_list;
11577 g_return_if_fail (GTK_IS_WIDGET (widget));
11578 g_return_if_fail (GTK_IS_WIDGET (label));
11580 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11581 new_list = g_slist_prepend (old_list, label);
11583 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11584 new_list, (GDestroyNotify) g_slist_free);
11588 * gtk_widget_remove_mnemonic_label:
11589 * @widget: a #GtkWidget
11590 * @label: a #GtkWidget that was previously set as a mnemnic label for
11591 * @widget with gtk_widget_add_mnemonic_label().
11593 * Removes a widget from the list of mnemonic labels for
11594 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11595 * must have previously been added to the list with
11596 * gtk_widget_add_mnemonic_label().
11601 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11604 GSList *old_list, *new_list;
11606 g_return_if_fail (GTK_IS_WIDGET (widget));
11607 g_return_if_fail (GTK_IS_WIDGET (label));
11609 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11610 new_list = g_slist_remove (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_get_no_show_all:
11619 * @widget: a #GtkWidget
11621 * Returns the current value of the GtkWidget:no-show-all property,
11622 * which determines whether calls to gtk_widget_show_all() and
11623 * gtk_widget_hide_all() will affect this widget.
11625 * Return value: the current value of the "no-show-all" property.
11630 gtk_widget_get_no_show_all (GtkWidget *widget)
11632 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11634 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11638 * gtk_widget_set_no_show_all:
11639 * @widget: a #GtkWidget
11640 * @no_show_all: the new value for the "no-show-all" property
11642 * Sets the #GtkWidget:no-show-all property, which determines whether
11643 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11646 * This is mostly for use in constructing widget hierarchies with externally
11647 * controlled visibility, see #GtkUIManager.
11652 gtk_widget_set_no_show_all (GtkWidget *widget,
11653 gboolean no_show_all)
11655 g_return_if_fail (GTK_IS_WIDGET (widget));
11657 no_show_all = (no_show_all != FALSE);
11659 if (no_show_all == gtk_widget_get_no_show_all (widget))
11663 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11665 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11667 g_object_notify (G_OBJECT (widget), "no-show-all");
11672 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11673 gboolean has_tooltip,
11676 GtkWidgetPrivate *priv = widget->priv;
11677 gboolean priv_has_tooltip;
11679 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11680 quark_has_tooltip));
11682 if (priv_has_tooltip != has_tooltip || force)
11684 priv_has_tooltip = has_tooltip;
11686 if (priv_has_tooltip)
11688 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11689 gdk_window_set_events (priv->window,
11690 gdk_window_get_events (priv->window) |
11691 GDK_LEAVE_NOTIFY_MASK |
11692 GDK_POINTER_MOTION_MASK |
11693 GDK_POINTER_MOTION_HINT_MASK);
11695 if (gtk_widget_get_has_window (widget))
11696 gtk_widget_add_events (widget,
11697 GDK_LEAVE_NOTIFY_MASK |
11698 GDK_POINTER_MOTION_MASK |
11699 GDK_POINTER_MOTION_HINT_MASK);
11702 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11703 GUINT_TO_POINTER (priv_has_tooltip));
11708 * gtk_widget_set_tooltip_window:
11709 * @widget: a #GtkWidget
11710 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11712 * Replaces the default, usually yellow, window used for displaying
11713 * tooltips with @custom_window. GTK+ will take care of showing and
11714 * hiding @custom_window at the right moment, to behave likewise as
11715 * the default tooltip window. If @custom_window is %NULL, the default
11716 * tooltip window will be used.
11718 * If the custom window should have the default theming it needs to
11719 * have the name "gtk-tooltip", see gtk_widget_set_name().
11724 gtk_widget_set_tooltip_window (GtkWidget *widget,
11725 GtkWindow *custom_window)
11727 gboolean has_tooltip;
11728 gchar *tooltip_markup;
11730 g_return_if_fail (GTK_IS_WIDGET (widget));
11731 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11733 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11736 g_object_ref (custom_window);
11738 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11739 custom_window, g_object_unref);
11741 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11742 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11744 if (has_tooltip && gtk_widget_get_visible (widget))
11745 gtk_widget_queue_tooltip_query (widget);
11749 * gtk_widget_get_tooltip_window:
11750 * @widget: a #GtkWidget
11752 * Returns the #GtkWindow of the current tooltip. This can be the
11753 * GtkWindow created by default, or the custom tooltip window set
11754 * using gtk_widget_set_tooltip_window().
11756 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11761 gtk_widget_get_tooltip_window (GtkWidget *widget)
11763 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11765 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11769 * gtk_widget_trigger_tooltip_query:
11770 * @widget: a #GtkWidget
11772 * Triggers a tooltip query on the display where the toplevel of @widget
11773 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11779 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11781 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11784 static guint tooltip_query_id;
11785 static GSList *tooltip_query_displays;
11788 tooltip_query_idle (gpointer data)
11790 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11791 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11792 g_slist_free (tooltip_query_displays);
11794 tooltip_query_displays = NULL;
11795 tooltip_query_id = 0;
11801 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11803 GdkDisplay *display;
11805 display = gtk_widget_get_display (widget);
11807 if (!g_slist_find (tooltip_query_displays, display))
11808 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11810 if (tooltip_query_id == 0)
11811 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11815 * gtk_widget_set_tooltip_text:
11816 * @widget: a #GtkWidget
11817 * @text: the contents of the tooltip for @widget
11819 * Sets @text as the contents of the tooltip. This function will take
11820 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11821 * handler for the GtkWidget::query-tooltip signal.
11823 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11828 gtk_widget_set_tooltip_text (GtkWidget *widget,
11831 g_return_if_fail (GTK_IS_WIDGET (widget));
11833 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11837 * gtk_widget_get_tooltip_text:
11838 * @widget: a #GtkWidget
11840 * Gets the contents of the tooltip for @widget.
11842 * Return value: the tooltip text, or %NULL. You should free the
11843 * returned string with g_free() when done.
11848 gtk_widget_get_tooltip_text (GtkWidget *widget)
11850 gchar *text = NULL;
11852 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11854 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11860 * gtk_widget_set_tooltip_markup:
11861 * @widget: a #GtkWidget
11862 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11864 * Sets @markup as the contents of the tooltip, which is marked up with
11865 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11867 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11868 * and of the default handler for the GtkWidget::query-tooltip signal.
11870 * See also the GtkWidget:tooltip-markup property and
11871 * gtk_tooltip_set_markup().
11876 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11877 const gchar *markup)
11879 g_return_if_fail (GTK_IS_WIDGET (widget));
11881 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11885 * gtk_widget_get_tooltip_markup:
11886 * @widget: a #GtkWidget
11888 * Gets the contents of the tooltip for @widget.
11890 * Return value: the tooltip text, or %NULL. You should free the
11891 * returned string with g_free() when done.
11896 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11898 gchar *text = NULL;
11900 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11902 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11908 * gtk_widget_set_has_tooltip:
11909 * @widget: a #GtkWidget
11910 * @has_tooltip: whether or not @widget has a tooltip.
11912 * Sets the has-tooltip property on @widget to @has_tooltip. See
11913 * GtkWidget:has-tooltip for more information.
11918 gtk_widget_set_has_tooltip (GtkWidget *widget,
11919 gboolean has_tooltip)
11921 g_return_if_fail (GTK_IS_WIDGET (widget));
11923 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
11927 * gtk_widget_get_has_tooltip:
11928 * @widget: a #GtkWidget
11930 * Returns the current value of the has-tooltip property. See
11931 * GtkWidget:has-tooltip for more information.
11933 * Return value: current value of has-tooltip on @widget.
11938 gtk_widget_get_has_tooltip (GtkWidget *widget)
11940 gboolean has_tooltip = FALSE;
11942 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11944 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
11946 return has_tooltip;
11950 * gtk_widget_get_allocation:
11951 * @widget: a #GtkWidget
11952 * @allocation: (out): a pointer to a #GtkAllocation to copy to
11954 * Retrieves the widget's allocation.
11956 * Note, when implementing a #GtkContainer: a widget's allocation will
11957 * be its "adjusted" allocation, that is, the widget's parent
11958 * container typically calls gtk_widget_size_allocate() with an
11959 * allocation, and that allocation is then adjusted (to handle margin
11960 * and alignment for example) before assignment to the widget.
11961 * gtk_widget_get_allocation() returns the adjusted allocation that
11962 * was actually assigned to the widget. The adjusted allocation is
11963 * guaranteed to be completely contained within the
11964 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
11965 * is guaranteed that its children stay inside the assigned bounds,
11966 * but not that they have exactly the bounds the container assigned.
11967 * There is no way to get the original allocation assigned by
11968 * gtk_widget_size_allocate(), since it isn't stored; if a container
11969 * implementation needs that information it will have to track it itself.
11974 gtk_widget_get_allocation (GtkWidget *widget,
11975 GtkAllocation *allocation)
11977 GtkWidgetPrivate *priv;
11979 g_return_if_fail (GTK_IS_WIDGET (widget));
11980 g_return_if_fail (allocation != NULL);
11982 priv = widget->priv;
11984 *allocation = priv->allocation;
11988 * gtk_widget_set_allocation:
11989 * @widget: a #GtkWidget
11990 * @allocation: a pointer to a #GtkAllocation to copy from
11992 * Sets the widget's allocation. This should not be used
11993 * directly, but from within a widget's size_allocate method.
11995 * The allocation set should be the "adjusted" or actual
11996 * allocation. If you're implementing a #GtkContainer, you want to use
11997 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
11998 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
11999 * allocation inside gtk_widget_size_allocate() to create an adjusted
12005 gtk_widget_set_allocation (GtkWidget *widget,
12006 const GtkAllocation *allocation)
12008 GtkWidgetPrivate *priv;
12010 g_return_if_fail (GTK_IS_WIDGET (widget));
12011 g_return_if_fail (allocation != NULL);
12013 priv = widget->priv;
12015 priv->allocation = *allocation;
12019 * gtk_widget_get_allocated_width:
12020 * @widget: the widget to query
12022 * Returns the width that has currently been allocated to @widget.
12023 * This function is intended to be used when implementing handlers
12024 * for the GtkWidget::draw function.
12026 * Returns: the width of the @widget
12029 gtk_widget_get_allocated_width (GtkWidget *widget)
12031 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12033 return widget->priv->allocation.width;
12037 * gtk_widget_get_allocated_height:
12038 * @widget: the widget to query
12040 * Returns the height that has currently been allocated to @widget.
12041 * This function is intended to be used when implementing handlers
12042 * for the GtkWidget::draw function.
12044 * Returns: the height of the @widget
12047 gtk_widget_get_allocated_height (GtkWidget *widget)
12049 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12051 return widget->priv->allocation.height;
12055 * gtk_widget_get_requisition:
12056 * @widget: a #GtkWidget
12057 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12059 * Retrieves the widget's requisition.
12061 * This function should only be used by widget implementations in
12062 * order to figure whether the widget's requisition has actually
12063 * changed after some internal state change (so that they can call
12064 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12066 * Normally, gtk_widget_size_request() should be used.
12070 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12071 * removed, If you need to cache sizes across requests and allocations,
12072 * add an explicit cache to the widget in question instead.
12075 gtk_widget_get_requisition (GtkWidget *widget,
12076 GtkRequisition *requisition)
12078 g_return_if_fail (GTK_IS_WIDGET (widget));
12079 g_return_if_fail (requisition != NULL);
12081 gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), requisition, NULL);
12085 * gtk_widget_set_window:
12086 * @widget: a #GtkWidget
12087 * @window: a #GdkWindow
12089 * Sets a widget's window. This function should only be used in a
12090 * widget's GtkWidget::realize() implementation. The %window passed is
12091 * usually either new window created with gdk_window_new(), or the
12092 * window of its parent widget as returned by
12093 * gtk_widget_get_parent_window().
12095 * Widgets must indicate whether they will create their own #GdkWindow
12096 * by calling gtk_widget_set_has_window(). This is usually done in the
12097 * widget's init() function.
12099 * <note><para>This function does not add any reference to @window.</para></note>
12104 gtk_widget_set_window (GtkWidget *widget,
12107 GtkWidgetPrivate *priv;
12109 g_return_if_fail (GTK_IS_WIDGET (widget));
12110 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12112 priv = widget->priv;
12114 if (priv->window != window)
12116 priv->window = window;
12117 g_object_notify (G_OBJECT (widget), "window");
12122 * gtk_widget_get_window:
12123 * @widget: a #GtkWidget
12125 * Returns the widget's window if it is realized, %NULL otherwise
12127 * Return value: (transfer none): @widget's window.
12132 gtk_widget_get_window (GtkWidget *widget)
12134 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12136 return widget->priv->window;
12140 * gtk_widget_get_support_multidevice:
12141 * @widget: a #GtkWidget
12143 * Returns %TRUE if @widget is multiple pointer aware. See
12144 * gtk_widget_set_support_multidevice() for more information.
12146 * Returns: %TRUE is @widget is multidevice aware.
12149 gtk_widget_get_support_multidevice (GtkWidget *widget)
12151 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12153 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12157 * gtk_widget_set_support_multidevice:
12158 * @widget: a #GtkWidget
12159 * @support_multidevice: %TRUE to support input from multiple devices.
12161 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12162 * @widget will start receiving multiple, per device enter/leave events. Note
12163 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12164 * gdk_window_set_support_multidevice() will have to be called manually on them.
12169 gtk_widget_set_support_multidevice (GtkWidget *widget,
12170 gboolean support_multidevice)
12172 GtkWidgetPrivate *priv;
12174 g_return_if_fail (GTK_IS_WIDGET (widget));
12176 priv = widget->priv;
12178 if (support_multidevice)
12180 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12181 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12185 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12186 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12189 if (gtk_widget_get_realized (widget))
12190 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12194 _gtk_widget_set_has_focus (GtkWidget *widget,
12195 gboolean has_focus)
12198 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12200 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12204 * gtk_widget_send_focus_change:
12205 * @widget: a #GtkWidget
12206 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12208 * Sends the focus change @event to @widget
12210 * This function is not meant to be used by applications. The only time it
12211 * should be used is when it is necessary for a #GtkWidget to assign focus
12212 * to a widget that is semantically owned by the first widget even though
12213 * it's not a direct child - for instance, a search entry in a floating
12214 * window similar to the quick search in #GtkTreeView.
12216 * An example of its usage is:
12219 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12221 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12222 * fevent->focus_change.in = TRUE;
12223 * fevent->focus_change.window = gtk_widget_get_window (widget);
12224 * if (fevent->focus_change.window != NULL)
12225 * g_object_ref (fevent->focus_change.window);
12227 * gtk_widget_send_focus_change (widget, fevent);
12229 * gdk_event_free (event);
12232 * Return value: the return value from the event signal emission: %TRUE
12233 * if the event was handled, and %FALSE otherwise
12238 gtk_widget_send_focus_change (GtkWidget *widget,
12243 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12244 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12246 g_object_ref (widget);
12248 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12250 res = gtk_widget_event (widget, event);
12252 g_object_notify (G_OBJECT (widget), "has-focus");
12254 g_object_unref (widget);