1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #undef GDK_DISABLE_DEPRECATED /* gdk_input_set_extension_events() */
33 #include "gtkcontainer.h"
34 #include "gtkaccelmap.h"
35 #include "gtkclipboard.h"
36 #include "gtkiconfactory.h"
39 #include "gtkmarshalers.h"
41 #include "gtkselection.h"
42 #include "gtksettings.h"
43 #include "gtksizegroup.h"
44 #include "gtkwidget.h"
45 #include "gtkwindow.h"
46 #include "gtkbindings.h"
47 #include "gtkprivate.h"
49 #include "gdk/gdkprivate.h" /* Used in gtk_reset_shapes_recurse to avoid copy */
50 #include <gobject/gvaluecollector.h>
51 #include <gobject/gobjectnotifyqueue.c>
52 #include <cairo-gobject.h>
53 #include "gdk/gdkkeysyms.h"
54 #include "gtkaccessible.h"
55 #include "gtktooltip.h"
56 #include "gtkinvisible.h"
57 #include "gtkbuildable.h"
58 #include "gtkbuilderprivate.h"
59 #include "gtksizerequest.h"
64 * @Short_description: Base class for all widgets
67 * GtkWidget is the base class all widgets in GTK+ derive from. It manages the
68 * widget lifecycle, states and style.
70 * <refsect2 id="style-properties">
72 * <structname>GtkWidget</structname> introduces <firstterm>style
73 * properties</firstterm> - these are basically object properties that are stored
74 * not on the object, but in the style object associated to the widget. Style
75 * properties are set in <link linkend="gtk-Resource-Files">resource files</link>.
76 * This mechanism is used for configuring such things as the location of the
77 * scrollbar arrows through the theme, giving theme authors more control over the
78 * look of applications without the need to write a theme engine in C.
81 * Use gtk_widget_class_install_style_property() to install style properties for
82 * a widget class, gtk_widget_class_find_style_property() or
83 * gtk_widget_class_list_style_properties() to get information about existing
84 * style properties and gtk_widget_style_get_property(), gtk_widget_style_get() or
85 * gtk_widget_style_get_valist() to obtain the value of a style property.
88 * <refsect2 id="GtkWidget-BUILDER-UI">
89 * <title>GtkWidget as GtkBuildable</title>
91 * The GtkWidget implementation of the GtkBuildable interface supports a
92 * custom <accelerator> element, which has attributes named key,
93 * modifiers and signal and allows to specify accelerators.
96 * <title>A UI definition fragment specifying an accelerator</title>
97 * <programlisting><![CDATA[
98 * <object class="GtkButton">
99 * <accelerator key="q" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
101 * ]]></programlisting>
104 * In addition to accelerators, <structname>GtkWidget</structname> also support a
105 * custom <accessible> element, which supports actions and relations.
106 * Properties on the accessible implementation of an object can be set by accessing the
107 * internal child "accessible" of a <structname>GtkWidget</structname>.
110 * <title>A UI definition fragment specifying an accessible</title>
111 * <programlisting><![CDATA[
112 * <object class="GtkButton" id="label1"/>
113 * <property name="label">I am a Label for a Button</property>
115 * <object class="GtkButton" id="button1">
117 * <action action_name="click" translatable="yes">Click the button.</action>
118 * <relation target="label1" type="labelled-by"/>
120 * <child internal-child="accessible">
121 * <object class="AtkObject" id="a11y-button1">
122 * <property name="AtkObject::name">Clickable Button</property>
126 * ]]></programlisting>
131 #define WIDGET_CLASS(w) GTK_WIDGET_GET_CLASS (w)
132 #define INIT_PATH_SIZE (512)
134 struct _GtkWidgetPrivate
136 /* The state of the widget. There are actually only
137 * 5 widget states (defined in "gtkenums.h")
142 /* The saved state of the widget. When a widget's state
143 * is changed to GTK_STATE_INSENSITIVE via
144 * "gtk_widget_set_state" or "gtk_widget_set_sensitive"
145 * the old state is kept around in this field. The state
146 * will be restored once the widget gets sensitive again.
148 guint saved_state : 3;
150 /* unused bits in our 32-bit block */
153 /* The widget's name. If the widget does not have a name
154 * (the name is NULL), then its name (as returned by
155 * "gtk_widget_get_name") is its class's name.
156 * Among other things, the widget name is used to determine
157 * the style to use for a widget.
161 /* The style for the widget. The style contains the
162 * colors the widget should be drawn in for each state
163 * along with graphics contexts used to draw with and
164 * the font to use for text.
168 /* The widget's allocated size.
170 GtkAllocation allocation;
172 /* The widget's requested sizes */
173 SizeRequestCache requests;
175 /* The widget's window or its parent window if it does
176 * not have a window. (Which will be indicated by the
177 * GTK_NO_WINDOW flag being set).
181 /* The widget's parent.
210 BUTTON_RELEASE_EVENT,
225 PROPERTY_NOTIFY_EVENT,
226 SELECTION_CLEAR_EVENT,
227 SELECTION_REQUEST_EVENT,
228 SELECTION_NOTIFY_EVENT,
243 VISIBILITY_NOTIFY_EVENT,
247 ACCEL_CLOSURES_CHANGED,
273 PROP_RECEIVES_DEFAULT,
274 PROP_COMPOSITE_CHILD,
277 PROP_EXTENSION_EVENTS,
283 PROP_DOUBLE_BUFFERED,
293 typedef struct _GtkStateData GtkStateData;
298 guint state_restoration : 1;
299 guint parent_sensitive : 1;
300 guint use_forall : 1;
303 /* --- prototypes --- */
304 static void gtk_widget_class_init (GtkWidgetClass *klass);
305 static void gtk_widget_base_class_finalize (GtkWidgetClass *klass);
306 static void gtk_widget_init (GtkWidget *widget);
307 static void gtk_widget_set_property (GObject *object,
311 static void gtk_widget_get_property (GObject *object,
315 static void gtk_widget_dispose (GObject *object);
316 static void gtk_widget_real_destroy (GtkObject *object);
317 static void gtk_widget_finalize (GObject *object);
318 static void gtk_widget_real_show (GtkWidget *widget);
319 static void gtk_widget_real_hide (GtkWidget *widget);
320 static void gtk_widget_real_map (GtkWidget *widget);
321 static void gtk_widget_real_unmap (GtkWidget *widget);
322 static void gtk_widget_real_realize (GtkWidget *widget);
323 static void gtk_widget_real_unrealize (GtkWidget *widget);
324 static void gtk_widget_real_size_request (GtkWidget *widget,
325 GtkRequisition *requisition);
326 static void gtk_widget_real_size_allocate (GtkWidget *widget,
327 GtkAllocation *allocation);
328 static void gtk_widget_real_style_set (GtkWidget *widget,
329 GtkStyle *previous_style);
330 static void gtk_widget_real_direction_changed(GtkWidget *widget,
331 GtkTextDirection previous_direction);
333 static void gtk_widget_real_grab_focus (GtkWidget *focus_widget);
334 static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
337 gboolean keyboard_tip,
338 GtkTooltip *tooltip);
339 static gboolean gtk_widget_real_show_help (GtkWidget *widget,
340 GtkWidgetHelpType help_type);
342 static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
344 GParamSpec **pspecs);
345 static gboolean gtk_widget_real_key_press_event (GtkWidget *widget,
347 static gboolean gtk_widget_real_key_release_event (GtkWidget *widget,
349 static gboolean gtk_widget_real_focus_in_event (GtkWidget *widget,
350 GdkEventFocus *event);
351 static gboolean gtk_widget_real_focus_out_event (GtkWidget *widget,
352 GdkEventFocus *event);
353 static gboolean gtk_widget_real_focus (GtkWidget *widget,
354 GtkDirectionType direction);
355 static void gtk_widget_real_move_focus (GtkWidget *widget,
356 GtkDirectionType direction);
357 static gboolean gtk_widget_real_keynav_failed (GtkWidget *widget,
358 GtkDirectionType direction);
359 static PangoContext* gtk_widget_peek_pango_context (GtkWidget *widget);
360 static void gtk_widget_update_pango_context (GtkWidget *widget);
361 static void gtk_widget_propagate_state (GtkWidget *widget,
363 static void gtk_widget_reset_rc_style (GtkWidget *widget);
364 static void gtk_widget_set_style_internal (GtkWidget *widget,
366 gboolean initial_emission);
367 static gint gtk_widget_event_internal (GtkWidget *widget,
369 static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
370 gboolean group_cycling);
371 static void gtk_widget_real_get_width (GtkWidget *widget,
374 static void gtk_widget_real_get_height (GtkWidget *widget,
377 static void gtk_widget_real_get_height_for_width (GtkWidget *widget,
379 gint *minimum_height,
380 gint *natural_height);
381 static void gtk_widget_real_get_width_for_height (GtkWidget *widget,
384 gint *natural_width);
385 static const GtkWidgetAuxInfo* _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget);
386 static void gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info);
387 static AtkObject* gtk_widget_real_get_accessible (GtkWidget *widget);
388 static void gtk_widget_accessible_interface_init (AtkImplementorIface *iface);
389 static AtkObject* gtk_widget_ref_accessible (AtkImplementor *implementor);
390 static void gtk_widget_invalidate_widget_windows (GtkWidget *widget,
391 cairo_region_t *region);
392 static GdkScreen * gtk_widget_get_screen_unchecked (GtkWidget *widget);
393 static void gtk_widget_queue_shallow_draw (GtkWidget *widget);
394 static gboolean gtk_widget_real_can_activate_accel (GtkWidget *widget,
397 static void gtk_widget_real_set_has_tooltip (GtkWidget *widget,
398 gboolean has_tooltip,
400 static void gtk_widget_buildable_interface_init (GtkBuildableIface *iface);
401 static void gtk_widget_buildable_set_name (GtkBuildable *buildable,
403 static const gchar * gtk_widget_buildable_get_name (GtkBuildable *buildable);
404 static GObject * gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
406 const gchar *childname);
407 static void gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
410 const GValue *value);
411 static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
414 const gchar *tagname,
415 GMarkupParser *parser,
417 static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
420 const gchar *tagname,
422 static void gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
423 GtkBuilder *builder);
425 static void gtk_widget_real_get_width (GtkWidget *widget,
428 static void gtk_widget_real_get_height (GtkWidget *widget,
432 static void gtk_widget_queue_tooltip_query (GtkWidget *widget);
435 static void gtk_widget_real_adjust_size_request (GtkWidget *widget,
436 GtkOrientation orientation,
440 static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
441 GtkAllocation *allocation);
443 static void gtk_widget_set_usize_internal (GtkWidget *widget,
447 static void gtk_widget_add_events_internal (GtkWidget *widget,
451 /* --- variables --- */
452 static gpointer gtk_widget_parent_class = NULL;
453 static guint widget_signals[LAST_SIGNAL] = { 0 };
454 static GtkStyle *gtk_default_style = NULL;
455 static guint composite_child_stack = 0;
456 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
457 static GParamSpecPool *style_property_spec_pool = NULL;
459 static GQuark quark_property_parser = 0;
460 static GQuark quark_aux_info = 0;
461 static GQuark quark_accel_path = 0;
462 static GQuark quark_accel_closures = 0;
463 static GQuark quark_event_mask = 0;
464 static GQuark quark_device_event_mask = 0;
465 static GQuark quark_extension_event_mode = 0;
466 static GQuark quark_parent_window = 0;
467 static GQuark quark_pointer_window = 0;
468 static GQuark quark_shape_info = 0;
469 static GQuark quark_input_shape_info = 0;
470 static GQuark quark_pango_context = 0;
471 static GQuark quark_rc_style = 0;
472 static GQuark quark_accessible_object = 0;
473 static GQuark quark_mnemonic_labels = 0;
474 static GQuark quark_tooltip_markup = 0;
475 static GQuark quark_has_tooltip = 0;
476 static GQuark quark_tooltip_window = 0;
477 GParamSpecPool *_gtk_widget_child_property_pool = NULL;
478 GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL;
480 /* --- functions --- */
482 gtk_widget_get_type (void)
484 static GType widget_type = 0;
486 if (G_UNLIKELY (widget_type == 0))
488 const GTypeInfo widget_info =
490 sizeof (GtkWidgetClass),
491 NULL, /* base_init */
492 (GBaseFinalizeFunc) gtk_widget_base_class_finalize,
493 (GClassInitFunc) gtk_widget_class_init,
494 NULL, /* class_finalize */
495 NULL, /* class_init */
498 (GInstanceInitFunc) gtk_widget_init,
499 NULL, /* value_table */
502 const GInterfaceInfo accessibility_info =
504 (GInterfaceInitFunc) gtk_widget_accessible_interface_init,
505 (GInterfaceFinalizeFunc) NULL,
506 NULL /* interface data */
509 const GInterfaceInfo buildable_info =
511 (GInterfaceInitFunc) gtk_widget_buildable_interface_init,
512 (GInterfaceFinalizeFunc) NULL,
513 NULL /* interface data */
516 widget_type = g_type_register_static (GTK_TYPE_OBJECT, "GtkWidget",
517 &widget_info, G_TYPE_FLAG_ABSTRACT);
519 g_type_add_interface_static (widget_type, ATK_TYPE_IMPLEMENTOR,
520 &accessibility_info) ;
521 g_type_add_interface_static (widget_type, GTK_TYPE_BUILDABLE,
529 child_property_notify_dispatcher (GObject *object,
533 GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
536 /* We guard against the draw signal callbacks modifying the state of the
537 * cairo context by surounding it with save/restore.
538 * Maybe we should also cairo_new_path() just to be sure?
541 gtk_widget_draw_marshaller (GClosure *closure,
542 GValue *return_value,
543 guint n_param_values,
544 const GValue *param_values,
545 gpointer invocation_hint,
546 gpointer marshal_data)
548 cairo_t *cr = g_value_get_boxed (¶m_values[1]);
552 _gtk_marshal_BOOLEAN__BOXED (closure,
563 gtk_widget_class_init (GtkWidgetClass *klass)
565 static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
566 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
567 GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
568 GtkBindingSet *binding_set;
570 gtk_widget_parent_class = g_type_class_peek_parent (klass);
572 quark_property_parser = g_quark_from_static_string ("gtk-rc-property-parser");
573 quark_aux_info = g_quark_from_static_string ("gtk-aux-info");
574 quark_accel_path = g_quark_from_static_string ("gtk-accel-path");
575 quark_accel_closures = g_quark_from_static_string ("gtk-accel-closures");
576 quark_event_mask = g_quark_from_static_string ("gtk-event-mask");
577 quark_device_event_mask = g_quark_from_static_string ("gtk-device-event-mask");
578 quark_extension_event_mode = g_quark_from_static_string ("gtk-extension-event-mode");
579 quark_parent_window = g_quark_from_static_string ("gtk-parent-window");
580 quark_pointer_window = g_quark_from_static_string ("gtk-pointer-window");
581 quark_shape_info = g_quark_from_static_string ("gtk-shape-info");
582 quark_input_shape_info = g_quark_from_static_string ("gtk-input-shape-info");
583 quark_pango_context = g_quark_from_static_string ("gtk-pango-context");
584 quark_rc_style = g_quark_from_static_string ("gtk-rc-style");
585 quark_accessible_object = g_quark_from_static_string ("gtk-accessible-object");
586 quark_mnemonic_labels = g_quark_from_static_string ("gtk-mnemonic-labels");
587 quark_tooltip_markup = g_quark_from_static_string ("gtk-tooltip-markup");
588 quark_has_tooltip = g_quark_from_static_string ("gtk-has-tooltip");
589 quark_tooltip_window = g_quark_from_static_string ("gtk-tooltip-window");
591 style_property_spec_pool = g_param_spec_pool_new (FALSE);
592 _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
593 cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
594 cpn_context.dispatcher = child_property_notify_dispatcher;
595 _gtk_widget_child_property_notify_context = &cpn_context;
597 gobject_class->dispose = gtk_widget_dispose;
598 gobject_class->finalize = gtk_widget_finalize;
599 gobject_class->set_property = gtk_widget_set_property;
600 gobject_class->get_property = gtk_widget_get_property;
602 object_class->destroy = gtk_widget_real_destroy;
604 klass->activate_signal = 0;
605 klass->set_scroll_adjustments_signal = 0;
606 klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
607 klass->show = gtk_widget_real_show;
608 klass->show_all = gtk_widget_show;
609 klass->hide = gtk_widget_real_hide;
610 klass->hide_all = gtk_widget_hide;
611 klass->map = gtk_widget_real_map;
612 klass->unmap = gtk_widget_real_unmap;
613 klass->realize = gtk_widget_real_realize;
614 klass->unrealize = gtk_widget_real_unrealize;
615 klass->size_request = gtk_widget_real_size_request;
616 klass->size_allocate = gtk_widget_real_size_allocate;
617 klass->get_preferred_width = gtk_widget_real_get_width;
618 klass->get_preferred_height = gtk_widget_real_get_height;
619 klass->get_preferred_width_for_height = gtk_widget_real_get_width_for_height;
620 klass->get_preferred_height_for_width = gtk_widget_real_get_height_for_width;
621 klass->state_changed = NULL;
622 klass->parent_set = NULL;
623 klass->hierarchy_changed = NULL;
624 klass->style_set = gtk_widget_real_style_set;
625 klass->direction_changed = gtk_widget_real_direction_changed;
626 klass->grab_notify = NULL;
627 klass->child_notify = NULL;
629 klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
630 klass->grab_focus = gtk_widget_real_grab_focus;
631 klass->focus = gtk_widget_real_focus;
633 klass->button_press_event = NULL;
634 klass->button_release_event = NULL;
635 klass->motion_notify_event = NULL;
636 klass->delete_event = NULL;
637 klass->destroy_event = NULL;
638 klass->key_press_event = gtk_widget_real_key_press_event;
639 klass->key_release_event = gtk_widget_real_key_release_event;
640 klass->enter_notify_event = NULL;
641 klass->leave_notify_event = NULL;
642 klass->configure_event = NULL;
643 klass->focus_in_event = gtk_widget_real_focus_in_event;
644 klass->focus_out_event = gtk_widget_real_focus_out_event;
645 klass->map_event = NULL;
646 klass->unmap_event = NULL;
647 klass->window_state_event = NULL;
648 klass->property_notify_event = _gtk_selection_property_notify;
649 klass->selection_clear_event = _gtk_selection_clear;
650 klass->selection_request_event = _gtk_selection_request;
651 klass->selection_notify_event = _gtk_selection_notify;
652 klass->selection_received = NULL;
653 klass->proximity_in_event = NULL;
654 klass->proximity_out_event = NULL;
655 klass->drag_begin = NULL;
656 klass->drag_end = NULL;
657 klass->drag_data_delete = NULL;
658 klass->drag_leave = NULL;
659 klass->drag_motion = NULL;
660 klass->drag_drop = NULL;
661 klass->drag_data_received = NULL;
662 klass->screen_changed = NULL;
663 klass->can_activate_accel = gtk_widget_real_can_activate_accel;
664 klass->grab_broken_event = NULL;
665 klass->query_tooltip = gtk_widget_real_query_tooltip;
667 klass->show_help = gtk_widget_real_show_help;
669 /* Accessibility support */
670 klass->get_accessible = gtk_widget_real_get_accessible;
672 klass->no_expose_event = NULL;
674 klass->adjust_size_request = gtk_widget_real_adjust_size_request;
675 klass->adjust_size_allocation = gtk_widget_real_adjust_size_allocation;
677 g_object_class_install_property (gobject_class,
679 g_param_spec_string ("name",
681 P_("The name of the widget"),
683 GTK_PARAM_READWRITE));
684 g_object_class_install_property (gobject_class,
686 g_param_spec_object ("parent",
688 P_("The parent widget of this widget. Must be a Container widget"),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (gobject_class,
694 g_param_spec_int ("width-request",
696 P_("Override for width request of the widget, or -1 if natural request should be used"),
700 GTK_PARAM_READWRITE));
701 g_object_class_install_property (gobject_class,
703 g_param_spec_int ("height-request",
704 P_("Height request"),
705 P_("Override for height request of the widget, or -1 if natural request should be used"),
709 GTK_PARAM_READWRITE));
710 g_object_class_install_property (gobject_class,
712 g_param_spec_boolean ("visible",
714 P_("Whether the widget is visible"),
716 GTK_PARAM_READWRITE));
717 g_object_class_install_property (gobject_class,
719 g_param_spec_boolean ("sensitive",
721 P_("Whether the widget responds to input"),
723 GTK_PARAM_READWRITE));
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("app-paintable",
727 P_("Application paintable"),
728 P_("Whether the application will paint directly on the widget"),
730 GTK_PARAM_READWRITE));
731 g_object_class_install_property (gobject_class,
733 g_param_spec_boolean ("can-focus",
735 P_("Whether the widget can accept the input focus"),
737 GTK_PARAM_READWRITE));
738 g_object_class_install_property (gobject_class,
740 g_param_spec_boolean ("has-focus",
742 P_("Whether the widget has the input focus"),
744 GTK_PARAM_READWRITE));
745 g_object_class_install_property (gobject_class,
747 g_param_spec_boolean ("is-focus",
749 P_("Whether the widget is the focus widget within the toplevel"),
751 GTK_PARAM_READWRITE));
752 g_object_class_install_property (gobject_class,
754 g_param_spec_boolean ("can-default",
756 P_("Whether the widget can be the default widget"),
758 GTK_PARAM_READWRITE));
759 g_object_class_install_property (gobject_class,
761 g_param_spec_boolean ("has-default",
763 P_("Whether the widget is the default widget"),
765 GTK_PARAM_READWRITE));
766 g_object_class_install_property (gobject_class,
767 PROP_RECEIVES_DEFAULT,
768 g_param_spec_boolean ("receives-default",
769 P_("Receives default"),
770 P_("If TRUE, the widget will receive the default action when it is focused"),
772 GTK_PARAM_READWRITE));
773 g_object_class_install_property (gobject_class,
774 PROP_COMPOSITE_CHILD,
775 g_param_spec_boolean ("composite-child",
776 P_("Composite child"),
777 P_("Whether the widget is part of a composite widget"),
779 GTK_PARAM_READABLE));
780 g_object_class_install_property (gobject_class,
782 g_param_spec_object ("style",
784 P_("The style of the widget, which contains information about how it will look (colors etc)"),
786 GTK_PARAM_READWRITE));
787 g_object_class_install_property (gobject_class,
789 g_param_spec_flags ("events",
791 P_("The event mask that decides what kind of GdkEvents this widget gets"),
794 GTK_PARAM_READWRITE));
795 g_object_class_install_property (gobject_class,
796 PROP_EXTENSION_EVENTS,
797 g_param_spec_enum ("extension-events",
798 P_("Extension events"),
799 P_("The mask that decides what kind of extension events this widget gets"),
800 GDK_TYPE_EXTENSION_MODE,
801 GDK_EXTENSION_EVENTS_NONE,
802 GTK_PARAM_READWRITE));
803 g_object_class_install_property (gobject_class,
805 g_param_spec_boolean ("no-show-all",
807 P_("Whether gtk_widget_show_all() should not affect this widget"),
809 GTK_PARAM_READWRITE));
812 * GtkWidget:has-tooltip:
814 * Enables or disables the emission of #GtkWidget::query-tooltip on @widget.
815 * A value of %TRUE indicates that @widget can have a tooltip, in this case
816 * the widget will be queried using #GtkWidget::query-tooltip to determine
817 * whether it will provide a tooltip or not.
819 * Note that setting this property to %TRUE for the first time will change
820 * the event masks of the GdkWindows of this widget to include leave-notify
821 * and motion-notify events. This cannot and will not be undone when the
822 * property is set to %FALSE again.
826 g_object_class_install_property (gobject_class,
828 g_param_spec_boolean ("has-tooltip",
830 P_("Whether this widget has a tooltip"),
832 GTK_PARAM_READWRITE));
834 * GtkWidget:tooltip-text:
836 * Sets the text of tooltip to be the given string.
838 * Also see gtk_tooltip_set_text().
840 * This is a convenience property which will take care of getting the
841 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
842 * will automatically be set to %TRUE and there will be taken care of
843 * #GtkWidget::query-tooltip in the default signal handler.
847 g_object_class_install_property (gobject_class,
849 g_param_spec_string ("tooltip-text",
851 P_("The contents of the tooltip for this widget"),
853 GTK_PARAM_READWRITE));
855 * GtkWidget:tooltip-markup:
857 * Sets the text of tooltip to be the given string, which is marked up
858 * with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
859 * Also see gtk_tooltip_set_markup().
861 * This is a convenience property which will take care of getting the
862 * tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
863 * will automatically be set to %TRUE and there will be taken care of
864 * #GtkWidget::query-tooltip in the default signal handler.
868 g_object_class_install_property (gobject_class,
870 g_param_spec_string ("tooltip-markup",
871 P_("Tooltip markup"),
872 P_("The contents of the tooltip for this widget"),
874 GTK_PARAM_READWRITE));
879 * The widget's window if it is realized, %NULL otherwise.
883 g_object_class_install_property (gobject_class,
885 g_param_spec_object ("window",
887 P_("The widget's window if it is realized"),
889 GTK_PARAM_READABLE));
892 * GtkWidget:double-buffered
894 * Whether the widget is double buffered.
898 g_object_class_install_property (gobject_class,
899 PROP_DOUBLE_BUFFERED,
900 g_param_spec_boolean ("double-buffered",
901 P_("Double Buffered"),
902 P_("Whether the widget is double buffered"),
904 GTK_PARAM_READWRITE));
909 * How to distribute horizontal space if widget gets extra space, see #GtkAlign
913 g_object_class_install_property (gobject_class,
915 g_param_spec_enum ("halign",
916 P_("Horizontal Alignment"),
917 P_("How to position in extra horizontal space"),
920 GTK_PARAM_READWRITE));
925 * How to distribute vertical space if widget gets extra space, see #GtkAlign
929 g_object_class_install_property (gobject_class,
931 g_param_spec_enum ("valign",
932 P_("Vertical Alignment"),
933 P_("How to position in extra vertical space"),
936 GTK_PARAM_READWRITE));
939 * GtkWidget:margin-left
941 * Margin on left side of widget.
943 * This property adds margin outside of the widget's normal size
944 * request, the margin will be added in addition to the size from
945 * gtk_widget_set_size_request() for example.
949 g_object_class_install_property (gobject_class,
951 g_param_spec_int ("margin-left",
952 P_("Margin on Left"),
953 P_("Pixels of extra space on the left side"),
957 GTK_PARAM_READWRITE));
960 * GtkWidget:margin-right
962 * Margin on right side of widget.
964 * This property adds margin outside of the widget's normal size
965 * request, the margin will be added in addition to the size from
966 * gtk_widget_set_size_request() for example.
970 g_object_class_install_property (gobject_class,
972 g_param_spec_int ("margin-right",
973 P_("Margin on Right"),
974 P_("Pixels of extra space on the right side"),
978 GTK_PARAM_READWRITE));
981 * GtkWidget:margin-top
983 * Margin on top side of widget.
985 * This property adds margin outside of the widget's normal size
986 * request, the margin will be added in addition to the size from
987 * gtk_widget_set_size_request() for example.
991 g_object_class_install_property (gobject_class,
993 g_param_spec_int ("margin-top",
995 P_("Pixels of extra space on the top side"),
999 GTK_PARAM_READWRITE));
1002 * GtkWidget:margin-bottom
1004 * Margin on bottom side of widget.
1006 * This property adds margin outside of the widget's normal size
1007 * request, the margin will be added in addition to the size from
1008 * gtk_widget_set_size_request() for example.
1012 g_object_class_install_property (gobject_class,
1014 g_param_spec_int ("margin-bottom",
1015 P_("Margin on Bottom"),
1016 P_("Pixels of extra space on the bottom side"),
1020 GTK_PARAM_READWRITE));
1025 * Sets all four sides' margin at once. If read, returns max
1026 * margin on any side.
1030 g_object_class_install_property (gobject_class,
1032 g_param_spec_int ("margin",
1034 P_("Pixels of extra space on all four sides"),
1038 GTK_PARAM_READWRITE));
1042 * @widget: the object which received the signal.
1044 widget_signals[SHOW] =
1045 g_signal_new (I_("show"),
1046 G_TYPE_FROM_CLASS (gobject_class),
1048 G_STRUCT_OFFSET (GtkWidgetClass, show),
1050 _gtk_marshal_VOID__VOID,
1055 * @widget: the object which received the signal.
1057 widget_signals[HIDE] =
1058 g_signal_new (I_("hide"),
1059 G_TYPE_FROM_CLASS (gobject_class),
1061 G_STRUCT_OFFSET (GtkWidgetClass, hide),
1063 _gtk_marshal_VOID__VOID,
1068 * @widget: the object which received the signal.
1070 widget_signals[MAP] =
1071 g_signal_new (I_("map"),
1072 G_TYPE_FROM_CLASS (gobject_class),
1074 G_STRUCT_OFFSET (GtkWidgetClass, map),
1076 _gtk_marshal_VOID__VOID,
1081 * @widget: the object which received the signal.
1083 widget_signals[UNMAP] =
1084 g_signal_new (I_("unmap"),
1085 G_TYPE_FROM_CLASS (gobject_class),
1087 G_STRUCT_OFFSET (GtkWidgetClass, unmap),
1089 _gtk_marshal_VOID__VOID,
1093 * GtkWidget::realize:
1094 * @widget: the object which received the signal.
1096 widget_signals[REALIZE] =
1097 g_signal_new (I_("realize"),
1098 G_TYPE_FROM_CLASS (gobject_class),
1100 G_STRUCT_OFFSET (GtkWidgetClass, realize),
1102 _gtk_marshal_VOID__VOID,
1106 * GtkWidget::unrealize:
1107 * @widget: the object which received the signal.
1109 widget_signals[UNREALIZE] =
1110 g_signal_new (I_("unrealize"),
1111 G_TYPE_FROM_CLASS (gobject_class),
1113 G_STRUCT_OFFSET (GtkWidgetClass, unrealize),
1115 _gtk_marshal_VOID__VOID,
1119 * GtkWidget::size-request:
1120 * @widget: the object which received the signal.
1123 widget_signals[SIZE_REQUEST] =
1124 g_signal_new (I_("size-request"),
1125 G_TYPE_FROM_CLASS (gobject_class),
1127 G_STRUCT_OFFSET (GtkWidgetClass, size_request),
1129 _gtk_marshal_VOID__BOXED,
1131 GTK_TYPE_REQUISITION | G_SIGNAL_TYPE_STATIC_SCOPE);
1134 * GtkWidget::size-allocate:
1135 * @widget: the object which received the signal.
1138 widget_signals[SIZE_ALLOCATE] =
1139 g_signal_new (I_("size-allocate"),
1140 G_TYPE_FROM_CLASS (gobject_class),
1142 G_STRUCT_OFFSET (GtkWidgetClass, size_allocate),
1144 _gtk_marshal_VOID__BOXED,
1146 GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
1149 * GtkWidget::state-changed:
1150 * @widget: the object which received the signal.
1151 * @state: the previous state
1153 * The ::state-changed signal is emitted when the widget state changes.
1154 * See gtk_widget_get_state().
1156 widget_signals[STATE_CHANGED] =
1157 g_signal_new (I_("state-changed"),
1158 G_TYPE_FROM_CLASS (gobject_class),
1160 G_STRUCT_OFFSET (GtkWidgetClass, state_changed),
1162 _gtk_marshal_VOID__ENUM,
1164 GTK_TYPE_STATE_TYPE);
1167 * GtkWidget::parent-set:
1168 * @widget: the object on which the signal is emitted
1169 * @old_parent: (allow-none): the previous parent, or %NULL if the widget
1170 * just got its initial parent.
1172 * The ::parent-set signal is emitted when a new parent
1173 * has been set on a widget.
1175 widget_signals[PARENT_SET] =
1176 g_signal_new (I_("parent-set"),
1177 G_TYPE_FROM_CLASS (gobject_class),
1179 G_STRUCT_OFFSET (GtkWidgetClass, parent_set),
1181 _gtk_marshal_VOID__OBJECT,
1186 * GtkWidget::hierarchy-changed:
1187 * @widget: the object on which the signal is emitted
1188 * @previous_toplevel: (allow-none): the previous toplevel ancestor, or %NULL
1189 * if the widget was previously unanchored
1191 * The ::hierarchy-changed signal is emitted when the
1192 * anchored state of a widget changes. A widget is
1193 * <firstterm>anchored</firstterm> when its toplevel
1194 * ancestor is a #GtkWindow. This signal is emitted when
1195 * a widget changes from un-anchored to anchored or vice-versa.
1197 widget_signals[HIERARCHY_CHANGED] =
1198 g_signal_new (I_("hierarchy-changed"),
1199 G_TYPE_FROM_CLASS (gobject_class),
1201 G_STRUCT_OFFSET (GtkWidgetClass, hierarchy_changed),
1203 _gtk_marshal_VOID__OBJECT,
1208 * GtkWidget::style-set:
1209 * @widget: the object on which the signal is emitted
1210 * @previous_style: (allow-none): the previous style, or %NULL if the widget
1211 * just got its initial style
1213 * The ::style-set signal is emitted when a new style has been set
1214 * on a widget. Note that style-modifying functions like
1215 * gtk_widget_modify_base() also cause this signal to be emitted.
1217 widget_signals[STYLE_SET] =
1218 g_signal_new (I_("style-set"),
1219 G_TYPE_FROM_CLASS (gobject_class),
1221 G_STRUCT_OFFSET (GtkWidgetClass, style_set),
1223 _gtk_marshal_VOID__OBJECT,
1227 * GtkWidget::direction-changed:
1228 * @widget: the object on which the signal is emitted
1229 * @previous_direction: the previous text direction of @widget
1231 * The ::direction-changed signal is emitted when the text direction
1232 * of a widget changes.
1234 widget_signals[DIRECTION_CHANGED] =
1235 g_signal_new (I_("direction-changed"),
1236 G_TYPE_FROM_CLASS (gobject_class),
1238 G_STRUCT_OFFSET (GtkWidgetClass, direction_changed),
1240 _gtk_marshal_VOID__ENUM,
1242 GTK_TYPE_TEXT_DIRECTION);
1245 * GtkWidget::grab-notify:
1246 * @widget: the object which received the signal
1247 * @was_grabbed: %FALSE if the widget becomes shadowed, %TRUE
1248 * if it becomes unshadowed
1250 * The ::grab-notify signal is emitted when a widget becomes
1251 * shadowed by a GTK+ grab (not a pointer or keyboard grab) on
1252 * another widget, or when it becomes unshadowed due to a grab
1255 * A widget is shadowed by a gtk_grab_add() when the topmost
1256 * grab widget in the grab stack of its window group is not
1259 widget_signals[GRAB_NOTIFY] =
1260 g_signal_new (I_("grab-notify"),
1261 G_TYPE_FROM_CLASS (gobject_class),
1263 G_STRUCT_OFFSET (GtkWidgetClass, grab_notify),
1265 _gtk_marshal_VOID__BOOLEAN,
1270 * GtkWidget::child-notify:
1271 * @widget: the object which received the signal
1272 * @pspec: the #GParamSpec of the changed child property
1274 * The ::child-notify signal is emitted for each
1275 * <link linkend="child-properties">child property</link> that has
1276 * changed on an object. The signal's detail holds the property name.
1278 widget_signals[CHILD_NOTIFY] =
1279 g_signal_new (I_("child-notify"),
1280 G_TYPE_FROM_CLASS (gobject_class),
1281 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
1282 G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
1284 g_cclosure_marshal_VOID__PARAM,
1290 * @widget: the object which received the signal
1291 * @cr: the cairo context to draw to
1292 * @width: width of the widget
1293 * @height: height of the widget
1295 * This signal is emitted when a widget is supposed to render itself.
1296 * The @widget's top left corner must be painted at the origin of
1297 * the passed in context and be sized in the given @width and @height.
1299 * Signal handlers connected to this signal can modify the cairo
1300 * context passed as @cr in any way they like and don't need to
1301 * restore it. The signal emission takes care of calling cairo_save()
1302 * before and cairo_restore() after invoking the handler.
1304 widget_signals[DRAW] =
1305 g_signal_new (I_("draw"),
1306 G_TYPE_FROM_CLASS (gobject_class),
1308 G_STRUCT_OFFSET (GtkWidgetClass, draw),
1309 _gtk_boolean_handled_accumulator, NULL,
1310 gtk_widget_draw_marshaller,
1312 CAIRO_GOBJECT_TYPE_CONTEXT);
1315 * GtkWidget::mnemonic-activate:
1316 * @widget: the object which received the signal.
1319 widget_signals[MNEMONIC_ACTIVATE] =
1320 g_signal_new (I_("mnemonic-activate"),
1321 G_TYPE_FROM_CLASS (gobject_class),
1323 G_STRUCT_OFFSET (GtkWidgetClass, mnemonic_activate),
1324 _gtk_boolean_handled_accumulator, NULL,
1325 _gtk_marshal_BOOLEAN__BOOLEAN,
1330 * GtkWidget::grab-focus:
1331 * @widget: the object which received the signal.
1333 widget_signals[GRAB_FOCUS] =
1334 g_signal_new (I_("grab-focus"),
1335 G_TYPE_FROM_CLASS (gobject_class),
1336 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1337 G_STRUCT_OFFSET (GtkWidgetClass, grab_focus),
1339 _gtk_marshal_VOID__VOID,
1344 * @widget: the object which received the signal.
1347 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1349 widget_signals[FOCUS] =
1350 g_signal_new (I_("focus"),
1351 G_TYPE_FROM_CLASS (object_class),
1353 G_STRUCT_OFFSET (GtkWidgetClass, focus),
1354 _gtk_boolean_handled_accumulator, NULL,
1355 _gtk_marshal_BOOLEAN__ENUM,
1357 GTK_TYPE_DIRECTION_TYPE);
1360 * GtkWidget::move-focus:
1361 * @widget: the object which received the signal.
1364 widget_signals[MOVE_FOCUS] =
1365 g_signal_new_class_handler (I_("move-focus"),
1366 G_TYPE_FROM_CLASS (object_class),
1367 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1368 G_CALLBACK (gtk_widget_real_move_focus),
1370 _gtk_marshal_VOID__ENUM,
1373 GTK_TYPE_DIRECTION_TYPE);
1376 * @widget: the object which received the signal.
1377 * @event: the #GdkEvent which triggered this signal
1379 * The GTK+ main loop will emit three signals for each GDK event delivered
1380 * to a widget: one generic ::event signal, another, more specific,
1381 * signal that matches the type of event delivered (e.g.
1382 * #GtkWidget::key-press-event) and finally a generic
1383 * #GtkWidget::event-after signal.
1385 * Returns: %TRUE to stop other handlers from being invoked for the event
1386 * and to cancel the emission of the second specific ::event signal.
1387 * %FALSE to propagate the event further and to allow the emission of
1388 * the second signal. The ::event-after signal is emitted regardless of
1391 widget_signals[EVENT] =
1392 g_signal_new (I_("event"),
1393 G_TYPE_FROM_CLASS (gobject_class),
1395 G_STRUCT_OFFSET (GtkWidgetClass, event),
1396 _gtk_boolean_handled_accumulator, NULL,
1397 _gtk_marshal_BOOLEAN__BOXED,
1399 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1402 * GtkWidget::event-after:
1403 * @widget: the object which received the signal.
1404 * @event: the #GdkEvent which triggered this signal
1406 * After the emission of the #GtkWidget::event signal and (optionally)
1407 * the second more specific signal, ::event-after will be emitted
1408 * regardless of the previous two signals handlers return values.
1411 widget_signals[EVENT_AFTER] =
1412 g_signal_new (I_("event-after"),
1413 G_TYPE_FROM_CLASS (gobject_class),
1417 _gtk_marshal_VOID__BOXED,
1419 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1422 * GtkWidget::button-press-event:
1423 * @widget: the object which received the signal.
1424 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1427 * The ::button-press-event signal will be emitted when a button
1428 * (typically from a mouse) is pressed.
1430 * To receive this signal, the #GdkWindow associated to the
1431 * widget needs to enable the #GDK_BUTTON_PRESS_MASK mask.
1433 * This signal will be sent to the grab widget if there is one.
1435 * Returns: %TRUE to stop other handlers from being invoked for the event.
1436 * %FALSE to propagate the event further.
1438 widget_signals[BUTTON_PRESS_EVENT] =
1439 g_signal_new (I_("button-press-event"),
1440 G_TYPE_FROM_CLASS (gobject_class),
1442 G_STRUCT_OFFSET (GtkWidgetClass, button_press_event),
1443 _gtk_boolean_handled_accumulator, NULL,
1444 _gtk_marshal_BOOLEAN__BOXED,
1446 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1449 * GtkWidget::button-release-event:
1450 * @widget: the object which received the signal.
1451 * @event: (type Gdk.EventButton): the #GdkEventButton which triggered
1454 * The ::button-release-event signal will be emitted when a button
1455 * (typically from a mouse) is released.
1457 * To receive this signal, the #GdkWindow associated to the
1458 * widget needs to enable the #GDK_BUTTON_RELEASE_MASK mask.
1460 * This signal will be sent to the grab widget if there is one.
1462 * Returns: %TRUE to stop other handlers from being invoked for the event.
1463 * %FALSE to propagate the event further.
1465 widget_signals[BUTTON_RELEASE_EVENT] =
1466 g_signal_new (I_("button-release-event"),
1467 G_TYPE_FROM_CLASS (gobject_class),
1469 G_STRUCT_OFFSET (GtkWidgetClass, button_release_event),
1470 _gtk_boolean_handled_accumulator, NULL,
1471 _gtk_marshal_BOOLEAN__BOXED,
1473 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1476 * GtkWidget::scroll-event:
1477 * @widget: the object which received the signal.
1478 * @event: (type Gdk.EventScroll): the #GdkEventScroll which triggered
1481 * The ::scroll-event signal is emitted when a button in the 4 to 7
1482 * range is pressed. Wheel mice are usually configured to generate
1483 * button press events for buttons 4 and 5 when the wheel is turned.
1485 * To receive this signal, the #GdkWindow associated to the widget needs
1486 * to enable the #GDK_BUTTON_PRESS_MASK mask.
1488 * This signal will be sent to the grab widget if there is one.
1490 * Returns: %TRUE to stop other handlers from being invoked for the event.
1491 * %FALSE to propagate the event further.
1493 widget_signals[SCROLL_EVENT] =
1494 g_signal_new (I_("scroll-event"),
1495 G_TYPE_FROM_CLASS (gobject_class),
1497 G_STRUCT_OFFSET (GtkWidgetClass, scroll_event),
1498 _gtk_boolean_handled_accumulator, NULL,
1499 _gtk_marshal_BOOLEAN__BOXED,
1501 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1503 * GtkWidget::motion-notify-event:
1504 * @widget: the object which received the signal.
1505 * @event: (type Gdk.EventMotion): the #GdkEventMotion which triggered
1508 * The ::motion-notify-event signal is emitted when the pointer moves
1509 * over the widget's #GdkWindow.
1511 * To receive this signal, the #GdkWindow associated to the widget
1512 * needs to enable the #GDK_POINTER_MOTION_MASK mask.
1514 * This signal will be sent to the grab widget if there is one.
1516 * Returns: %TRUE to stop other handlers from being invoked for the event.
1517 * %FALSE to propagate the event further.
1519 widget_signals[MOTION_NOTIFY_EVENT] =
1520 g_signal_new (I_("motion-notify-event"),
1521 G_TYPE_FROM_CLASS (gobject_class),
1523 G_STRUCT_OFFSET (GtkWidgetClass, motion_notify_event),
1524 _gtk_boolean_handled_accumulator, NULL,
1525 _gtk_marshal_BOOLEAN__BOXED,
1527 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1530 * GtkWidget::composited-changed:
1531 * @widget: the object on which the signal is emitted
1533 * The ::composited-changed signal is emitted when the composited
1534 * status of @widget<!-- -->s screen changes.
1535 * See gdk_screen_is_composited().
1537 widget_signals[COMPOSITED_CHANGED] =
1538 g_signal_new (I_("composited-changed"),
1539 G_TYPE_FROM_CLASS (gobject_class),
1540 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1541 G_STRUCT_OFFSET (GtkWidgetClass, composited_changed),
1543 _gtk_marshal_VOID__VOID,
1547 * GtkWidget::keynav-failed:
1548 * @widget: the object which received the signal
1549 * @direction: the direction of movement
1551 * Gets emitted if keyboard navigation fails.
1552 * See gtk_widget_keynav_failed() for details.
1554 * Returns: %TRUE if stopping keyboard navigation is fine, %FALSE
1555 * if the emitting widget should try to handle the keyboard
1556 * navigation attempt in its parent container(s).
1560 widget_signals[KEYNAV_FAILED] =
1561 g_signal_new_class_handler (I_("keynav-failed"),
1562 G_TYPE_FROM_CLASS (gobject_class),
1564 G_CALLBACK (gtk_widget_real_keynav_failed),
1565 _gtk_boolean_handled_accumulator, NULL,
1566 _gtk_marshal_BOOLEAN__ENUM,
1568 GTK_TYPE_DIRECTION_TYPE);
1571 * GtkWidget::delete-event:
1572 * @widget: the object which received the signal
1573 * @event: the event which triggered this signal
1575 * The ::delete-event signal is emitted if a user requests that
1576 * a toplevel window is closed. The default handler for this signal
1577 * destroys the window. Connecting gtk_widget_hide_on_delete() to
1578 * this signal will cause the window to be hidden instead, so that
1579 * it can later be shown again without reconstructing it.
1581 * Returns: %TRUE to stop other handlers from being invoked for the event.
1582 * %FALSE to propagate the event further.
1584 widget_signals[DELETE_EVENT] =
1585 g_signal_new (I_("delete-event"),
1586 G_TYPE_FROM_CLASS (gobject_class),
1588 G_STRUCT_OFFSET (GtkWidgetClass, delete_event),
1589 _gtk_boolean_handled_accumulator, NULL,
1590 _gtk_marshal_BOOLEAN__BOXED,
1592 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1595 * GtkWidget::destroy-event:
1596 * @widget: the object which received the signal.
1597 * @event: the event which triggered this signal
1599 * The ::destroy-event signal is emitted when a #GdkWindow is destroyed.
1600 * You rarely get this signal, because most widgets disconnect themselves
1601 * from their window before they destroy it, so no widget owns the
1602 * window at destroy time.
1604 * To receive this signal, the #GdkWindow associated to the widget needs
1605 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1606 * automatically for all new windows.
1608 * Returns: %TRUE to stop other handlers from being invoked for the event.
1609 * %FALSE to propagate the event further.
1611 widget_signals[DESTROY_EVENT] =
1612 g_signal_new (I_("destroy-event"),
1613 G_TYPE_FROM_CLASS (gobject_class),
1615 G_STRUCT_OFFSET (GtkWidgetClass, destroy_event),
1616 _gtk_boolean_handled_accumulator, NULL,
1617 _gtk_marshal_BOOLEAN__BOXED,
1619 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1622 * GtkWidget::key-press-event:
1623 * @widget: the object which received the signal
1624 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1626 * The ::key-press-event signal is emitted when a key is pressed.
1628 * To receive this signal, the #GdkWindow associated to the widget needs
1629 * to enable the #GDK_KEY_PRESS_MASK mask.
1631 * This signal will be sent to the grab widget if there is one.
1633 * Returns: %TRUE to stop other handlers from being invoked for the event.
1634 * %FALSE to propagate the event further.
1636 widget_signals[KEY_PRESS_EVENT] =
1637 g_signal_new (I_("key-press-event"),
1638 G_TYPE_FROM_CLASS (gobject_class),
1640 G_STRUCT_OFFSET (GtkWidgetClass, key_press_event),
1641 _gtk_boolean_handled_accumulator, NULL,
1642 _gtk_marshal_BOOLEAN__BOXED,
1644 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1647 * GtkWidget::key-release-event:
1648 * @widget: the object which received the signal
1649 * @event: (type Gdk.EventKey): the #GdkEventKey which triggered this signal.
1651 * The ::key-release-event signal is emitted when a key is pressed.
1653 * To receive this signal, the #GdkWindow associated to the widget needs
1654 * to enable the #GDK_KEY_RELEASE_MASK mask.
1656 * This signal will be sent to the grab widget if there is one.
1658 * Returns: %TRUE to stop other handlers from being invoked for the event.
1659 * %FALSE to propagate the event further.
1661 widget_signals[KEY_RELEASE_EVENT] =
1662 g_signal_new (I_("key-release-event"),
1663 G_TYPE_FROM_CLASS (gobject_class),
1665 G_STRUCT_OFFSET (GtkWidgetClass, key_release_event),
1666 _gtk_boolean_handled_accumulator, NULL,
1667 _gtk_marshal_BOOLEAN__BOXED,
1669 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1672 * GtkWidget::enter-notify-event:
1673 * @widget: the object which received the signal
1674 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1677 * The ::enter-notify-event will be emitted when the pointer enters
1678 * the @widget's window.
1680 * To receive this signal, the #GdkWindow associated to the widget needs
1681 * to enable the #GDK_ENTER_NOTIFY_MASK mask.
1683 * This signal will be sent to the grab widget if there is one.
1685 * Returns: %TRUE to stop other handlers from being invoked for the event.
1686 * %FALSE to propagate the event further.
1688 widget_signals[ENTER_NOTIFY_EVENT] =
1689 g_signal_new (I_("enter-notify-event"),
1690 G_TYPE_FROM_CLASS (gobject_class),
1692 G_STRUCT_OFFSET (GtkWidgetClass, enter_notify_event),
1693 _gtk_boolean_handled_accumulator, NULL,
1694 _gtk_marshal_BOOLEAN__BOXED,
1696 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1699 * GtkWidget::leave-notify-event:
1700 * @widget: the object which received the signal
1701 * @event: (type Gdk.EventCrossing): the #GdkEventCrossing which triggered
1704 * The ::leave-notify-event will be emitted when the pointer leaves
1705 * the @widget's window.
1707 * To receive this signal, the #GdkWindow associated to the widget needs
1708 * to enable the #GDK_LEAVE_NOTIFY_MASK mask.
1710 * This signal will be sent to the grab widget if there is one.
1712 * Returns: %TRUE to stop other handlers from being invoked for the event.
1713 * %FALSE to propagate the event further.
1715 widget_signals[LEAVE_NOTIFY_EVENT] =
1716 g_signal_new (I_("leave-notify-event"),
1717 G_TYPE_FROM_CLASS (gobject_class),
1719 G_STRUCT_OFFSET (GtkWidgetClass, leave_notify_event),
1720 _gtk_boolean_handled_accumulator, NULL,
1721 _gtk_marshal_BOOLEAN__BOXED,
1723 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1726 * GtkWidget::configure-event
1727 * @widget: the object which received the signal
1728 * @event: (type Gdk.EventConfigure): the #GdkEventConfigure which triggered
1731 * The ::configure-event signal will be emitted when the size, position or
1732 * stacking of the @widget's window has changed.
1734 * To receive this signal, the #GdkWindow associated to the widget needs
1735 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1736 * automatically for all new windows.
1738 * Returns: %TRUE to stop other handlers from being invoked for the event.
1739 * %FALSE to propagate the event further.
1741 widget_signals[CONFIGURE_EVENT] =
1742 g_signal_new (I_("configure-event"),
1743 G_TYPE_FROM_CLASS (gobject_class),
1745 G_STRUCT_OFFSET (GtkWidgetClass, configure_event),
1746 _gtk_boolean_handled_accumulator, NULL,
1747 _gtk_marshal_BOOLEAN__BOXED,
1749 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1752 * GtkWidget::focus-in-event
1753 * @widget: the object which received the signal
1754 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered
1757 * The ::focus-in-event signal will be emitted when the keyboard focus
1758 * enters the @widget's window.
1760 * To receive this signal, the #GdkWindow associated to the widget needs
1761 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1763 * Returns: %TRUE to stop other handlers from being invoked for the event.
1764 * %FALSE to propagate the event further.
1766 widget_signals[FOCUS_IN_EVENT] =
1767 g_signal_new (I_("focus-in-event"),
1768 G_TYPE_FROM_CLASS (gobject_class),
1770 G_STRUCT_OFFSET (GtkWidgetClass, focus_in_event),
1771 _gtk_boolean_handled_accumulator, NULL,
1772 _gtk_marshal_BOOLEAN__BOXED,
1774 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1777 * GtkWidget::focus-out-event
1778 * @widget: the object which received the signal
1779 * @event: (type Gdk.EventFocus): the #GdkEventFocus which triggered this
1782 * The ::focus-out-event signal will be emitted when the keyboard focus
1783 * leaves the @widget's window.
1785 * To receive this signal, the #GdkWindow associated to the widget needs
1786 * to enable the #GDK_FOCUS_CHANGE_MASK mask.
1788 * Returns: %TRUE to stop other handlers from being invoked for the event.
1789 * %FALSE to propagate the event further.
1791 widget_signals[FOCUS_OUT_EVENT] =
1792 g_signal_new (I_("focus-out-event"),
1793 G_TYPE_FROM_CLASS (gobject_class),
1795 G_STRUCT_OFFSET (GtkWidgetClass, focus_out_event),
1796 _gtk_boolean_handled_accumulator, NULL,
1797 _gtk_marshal_BOOLEAN__BOXED,
1799 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1802 * GtkWidget::map-event
1803 * @widget: the object which received the signal
1804 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal.
1806 * The ::map-event signal will be emitted when the @widget's window is
1807 * mapped. A window is mapped when it becomes visible on the screen.
1809 * To receive this signal, the #GdkWindow associated to the widget needs
1810 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1811 * automatically for all new windows.
1813 * Returns: %TRUE to stop other handlers from being invoked for the event.
1814 * %FALSE to propagate the event further.
1816 widget_signals[MAP_EVENT] =
1817 g_signal_new (I_("map-event"),
1818 G_TYPE_FROM_CLASS (gobject_class),
1820 G_STRUCT_OFFSET (GtkWidgetClass, map_event),
1821 _gtk_boolean_handled_accumulator, NULL,
1822 _gtk_marshal_BOOLEAN__BOXED,
1824 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1827 * GtkWidget::unmap-event
1828 * @widget: the object which received the signal
1829 * @event: (type Gdk.EventAny): the #GdkEventAny which triggered this signal
1831 * The ::unmap-event signal may be emitted when the @widget's window is
1832 * unmapped. A window is unmapped when it becomes invisible on the screen.
1834 * For performance reasons GTK+ may not emit ::unmap-event, so one
1835 * should always also implement ::unrealize in order to release
1836 * resources and disconnect signal handlers.
1838 * To receive this signal, the #GdkWindow associated to the widget needs
1839 * to enable the #GDK_STRUCTURE_MASK mask. GDK will enable this mask
1840 * automatically for all new windows.
1842 * Returns: %TRUE to stop other handlers from being invoked for the event.
1843 * %FALSE to propagate the event further.
1845 widget_signals[UNMAP_EVENT] =
1846 g_signal_new (I_("unmap-event"),
1847 G_TYPE_FROM_CLASS (gobject_class),
1849 G_STRUCT_OFFSET (GtkWidgetClass, unmap_event),
1850 _gtk_boolean_handled_accumulator, NULL,
1851 _gtk_marshal_BOOLEAN__BOXED,
1853 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1856 * GtkWidget::property-notify-event
1857 * @widget: the object which received the signal
1858 * @event: (type Gdk.EventProperty): the #GdkEventProperty which triggered
1861 * The ::property-notify-event signal will be emitted when a property on
1862 * the @widget's window has been changed or deleted.
1864 * To receive this signal, the #GdkWindow associated to the widget needs
1865 * to enable the #GDK_PROPERTY_CHANGE_MASK mask.
1867 * Returns: %TRUE to stop other handlers from being invoked for the event.
1868 * %FALSE to propagate the event further.
1870 widget_signals[PROPERTY_NOTIFY_EVENT] =
1871 g_signal_new (I_("property-notify-event"),
1872 G_TYPE_FROM_CLASS (gobject_class),
1874 G_STRUCT_OFFSET (GtkWidgetClass, property_notify_event),
1875 _gtk_boolean_handled_accumulator, NULL,
1876 _gtk_marshal_BOOLEAN__BOXED,
1878 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1881 * GtkWidget::selection-clear-event
1882 * @widget: the object which received the signal
1883 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1886 * The ::selection-clear-event signal will be emitted when the
1887 * the @widget's window has lost ownership of a selection.
1889 * Returns: %TRUE to stop other handlers from being invoked for the event.
1890 * %FALSE to propagate the event further.
1892 widget_signals[SELECTION_CLEAR_EVENT] =
1893 g_signal_new (I_("selection-clear-event"),
1894 G_TYPE_FROM_CLASS (gobject_class),
1896 G_STRUCT_OFFSET (GtkWidgetClass, selection_clear_event),
1897 _gtk_boolean_handled_accumulator, NULL,
1898 _gtk_marshal_BOOLEAN__BOXED,
1900 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1903 * GtkWidget::selection-request-event
1904 * @widget: the object which received the signal
1905 * @event: (type Gdk.EventSelection): the #GdkEventSelection which triggered
1908 * The ::selection-request-event signal will be emitted when
1909 * another client requests ownership of the selection owned by
1910 * the @widget's window.
1912 * Returns: %TRUE to stop other handlers from being invoked for the event.
1913 * %FALSE to propagate the event further.
1915 widget_signals[SELECTION_REQUEST_EVENT] =
1916 g_signal_new (I_("selection-request-event"),
1917 G_TYPE_FROM_CLASS (gobject_class),
1919 G_STRUCT_OFFSET (GtkWidgetClass, selection_request_event),
1920 _gtk_boolean_handled_accumulator, NULL,
1921 _gtk_marshal_BOOLEAN__BOXED,
1923 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1926 * GtkWidget::selection-notify-event:
1927 * @widget: the object which received the signal.
1930 * Returns: %TRUE to stop other handlers from being invoked for the event. %FALSE to propagate the event further.
1932 widget_signals[SELECTION_NOTIFY_EVENT] =
1933 g_signal_new (I_("selection-notify-event"),
1934 G_TYPE_FROM_CLASS (gobject_class),
1936 G_STRUCT_OFFSET (GtkWidgetClass, selection_notify_event),
1937 _gtk_boolean_handled_accumulator, NULL,
1938 _gtk_marshal_BOOLEAN__BOXED,
1940 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
1943 * GtkWidget::selection-received:
1944 * @widget: the object which received the signal.
1948 widget_signals[SELECTION_RECEIVED] =
1949 g_signal_new (I_("selection-received"),
1950 G_TYPE_FROM_CLASS (gobject_class),
1952 G_STRUCT_OFFSET (GtkWidgetClass, selection_received),
1954 _gtk_marshal_VOID__BOXED_UINT,
1956 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1960 * GtkWidget::selection-get:
1961 * @widget: the object which received the signal.
1966 widget_signals[SELECTION_GET] =
1967 g_signal_new (I_("selection-get"),
1968 G_TYPE_FROM_CLASS (gobject_class),
1970 G_STRUCT_OFFSET (GtkWidgetClass, selection_get),
1972 _gtk_marshal_VOID__BOXED_UINT_UINT,
1974 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
1979 * GtkWidget::proximity-in-event
1980 * @widget: the object which received the signal
1981 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
1984 * To receive this signal the #GdkWindow associated to the widget needs
1985 * to enable the #GDK_PROXIMITY_IN_MASK mask.
1987 * This signal will be sent to the grab widget if there is one.
1989 * Returns: %TRUE to stop other handlers from being invoked for the event.
1990 * %FALSE to propagate the event further.
1992 widget_signals[PROXIMITY_IN_EVENT] =
1993 g_signal_new (I_("proximity-in-event"),
1994 G_TYPE_FROM_CLASS (gobject_class),
1996 G_STRUCT_OFFSET (GtkWidgetClass, proximity_in_event),
1997 _gtk_boolean_handled_accumulator, NULL,
1998 _gtk_marshal_BOOLEAN__BOXED,
2000 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2003 * GtkWidget::proximity-out-event
2004 * @widget: the object which received the signal
2005 * @event: (type Gdk.EventProximity): the #GdkEventProximity which triggered
2008 * To receive this signal the #GdkWindow associated to the widget needs
2009 * to enable the #GDK_PROXIMITY_OUT_MASK mask.
2011 * This signal will be sent to the grab widget if there is one.
2013 * Returns: %TRUE to stop other handlers from being invoked for the event.
2014 * %FALSE to propagate the event further.
2016 widget_signals[PROXIMITY_OUT_EVENT] =
2017 g_signal_new (I_("proximity-out-event"),
2018 G_TYPE_FROM_CLASS (gobject_class),
2020 G_STRUCT_OFFSET (GtkWidgetClass, proximity_out_event),
2021 _gtk_boolean_handled_accumulator, NULL,
2022 _gtk_marshal_BOOLEAN__BOXED,
2024 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2027 * GtkWidget::drag-leave:
2028 * @widget: the object which received the signal.
2029 * @drag_context: the drag context
2030 * @time: the timestamp of the motion event
2032 * The ::drag-leave signal is emitted on the drop site when the cursor
2033 * leaves the widget. A typical reason to connect to this signal is to
2034 * undo things done in #GtkWidget::drag-motion, e.g. undo highlighting
2035 * with gtk_drag_unhighlight()
2037 widget_signals[DRAG_LEAVE] =
2038 g_signal_new (I_("drag-leave"),
2039 G_TYPE_FROM_CLASS (gobject_class),
2041 G_STRUCT_OFFSET (GtkWidgetClass, drag_leave),
2043 _gtk_marshal_VOID__OBJECT_UINT,
2045 GDK_TYPE_DRAG_CONTEXT,
2049 * GtkWidget::drag-begin:
2050 * @widget: the object which received the signal
2051 * @drag_context: the drag context
2053 * The ::drag-begin signal is emitted on the drag source when a drag is
2054 * started. A typical reason to connect to this signal is to set up a
2055 * custom drag icon with gtk_drag_source_set_icon().
2057 * Note that some widgets set up a drag icon in the default handler of
2058 * this signal, so you may have to use g_signal_connect_after() to
2059 * override what the default handler did.
2061 widget_signals[DRAG_BEGIN] =
2062 g_signal_new (I_("drag-begin"),
2063 G_TYPE_FROM_CLASS (gobject_class),
2065 G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
2067 _gtk_marshal_VOID__OBJECT,
2069 GDK_TYPE_DRAG_CONTEXT);
2072 * GtkWidget::drag-end:
2073 * @widget: the object which received the signal
2074 * @drag_context: the drag context
2076 * The ::drag-end signal is emitted on the drag source when a drag is
2077 * finished. A typical reason to connect to this signal is to undo
2078 * things done in #GtkWidget::drag-begin.
2080 widget_signals[DRAG_END] =
2081 g_signal_new (I_("drag-end"),
2082 G_TYPE_FROM_CLASS (gobject_class),
2084 G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
2086 _gtk_marshal_VOID__OBJECT,
2088 GDK_TYPE_DRAG_CONTEXT);
2091 * GtkWidget::drag-data-delete:
2092 * @widget: the object which received the signal
2093 * @drag_context: the drag context
2095 * The ::drag-data-delete signal is emitted on the drag source when a drag
2096 * with the action %GDK_ACTION_MOVE is successfully completed. The signal
2097 * handler is responsible for deleting the data that has been dropped. What
2098 * "delete" means depends on the context of the drag operation.
2100 widget_signals[DRAG_DATA_DELETE] =
2101 g_signal_new (I_("drag-data-delete"),
2102 G_TYPE_FROM_CLASS (gobject_class),
2104 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
2106 _gtk_marshal_VOID__OBJECT,
2108 GDK_TYPE_DRAG_CONTEXT);
2111 * GtkWidget::drag-failed:
2112 * @widget: the object which received the signal
2113 * @drag_context: the drag context
2114 * @result: the result of the drag operation
2116 * The ::drag-failed signal is emitted on the drag source when a drag has
2117 * failed. The signal handler may hook custom code to handle a failed DND
2118 * operation based on the type of error, it returns %TRUE is the failure has
2119 * been already handled (not showing the default "drag operation failed"
2120 * animation), otherwise it returns %FALSE.
2122 * Return value: %TRUE if the failed drag operation has been already handled.
2126 widget_signals[DRAG_FAILED] =
2127 g_signal_new (I_("drag-failed"),
2128 G_TYPE_FROM_CLASS (gobject_class),
2130 0, _gtk_boolean_handled_accumulator, NULL,
2131 _gtk_marshal_BOOLEAN__OBJECT_ENUM,
2133 GDK_TYPE_DRAG_CONTEXT,
2134 GTK_TYPE_DRAG_RESULT);
2137 * GtkWidget::drag-motion:
2138 * @widget: the object which received the signal
2139 * @drag_context: the drag context
2140 * @x: the x coordinate of the current cursor position
2141 * @y: the y coordinate of the current cursor position
2142 * @time: the timestamp of the motion event
2143 * @returns: whether the cursor position is in a drop zone
2145 * The drag-motion signal is emitted on the drop site when the user
2146 * moves the cursor over the widget during a drag. The signal handler
2147 * must determine whether the cursor position is in a drop zone or not.
2148 * If it is not in a drop zone, it returns %FALSE and no further processing
2149 * is necessary. Otherwise, the handler returns %TRUE. In this case, the
2150 * handler is responsible for providing the necessary information for
2151 * displaying feedback to the user, by calling gdk_drag_status().
2153 * If the decision whether the drop will be accepted or rejected can't be
2154 * made based solely on the cursor position and the type of the data, the
2155 * handler may inspect the dragged data by calling gtk_drag_get_data() and
2156 * defer the gdk_drag_status() call to the #GtkWidget::drag-data-received
2157 * handler. Note that you cannot not pass #GTK_DEST_DEFAULT_DROP,
2158 * #GTK_DEST_DEFAULT_MOTION or #GTK_DEST_DEFAULT_ALL to gtk_drag_dest_set()
2159 * when using the drag-motion signal that way.
2161 * Also note that there is no drag-enter signal. The drag receiver has to
2162 * keep track of whether he has received any drag-motion signals since the
2163 * last #GtkWidget::drag-leave and if not, treat the drag-motion signal as
2164 * an "enter" signal. Upon an "enter", the handler will typically highlight
2165 * the drop site with gtk_drag_highlight().
2168 * drag_motion (GtkWidget *widget,
2169 * GdkDragContext *context,
2176 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2178 * if (!private_data->drag_highlight)
2180 * private_data->drag_highlight = 1;
2181 * gtk_drag_highlight (widget);
2184 * target = gtk_drag_dest_find_target (widget, context, NULL);
2185 * if (target == GDK_NONE)
2186 * gdk_drag_status (context, 0, time);
2189 * private_data->pending_status = context->suggested_action;
2190 * gtk_drag_get_data (widget, context, target, time);
2197 * drag_data_received (GtkWidget *widget,
2198 * GdkDragContext *context,
2201 * GtkSelectionData *selection_data,
2205 * PrivateData *private_data = GET_PRIVATE_DATA (widget);
2207 * if (private_data->suggested_action)
2209 * private_data->suggested_action = 0;
2211 * /* We are getting this data due to a request in drag_motion,
2212 * * rather than due to a request in drag_drop, so we are just
2213 * * supposed to call gdk_drag_status (), not actually paste in
2216 * str = gtk_selection_data_get_text (selection_data);
2217 * if (!data_is_acceptable (str))
2218 * gdk_drag_status (context, 0, time);
2220 * gdk_drag_status (context, private_data->suggested_action, time);
2224 * /* accept the drop */
2229 widget_signals[DRAG_MOTION] =
2230 g_signal_new (I_("drag-motion"),
2231 G_TYPE_FROM_CLASS (gobject_class),
2233 G_STRUCT_OFFSET (GtkWidgetClass, drag_motion),
2234 _gtk_boolean_handled_accumulator, NULL,
2235 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2237 GDK_TYPE_DRAG_CONTEXT,
2243 * GtkWidget::drag-drop:
2244 * @widget: the object which received the signal
2245 * @drag_context: the drag context
2246 * @x: the x coordinate of the current cursor position
2247 * @y: the y coordinate of the current cursor position
2248 * @time: the timestamp of the motion event
2249 * @returns: whether the cursor position is in a drop zone
2251 * The ::drag-drop signal is emitted on the drop site when the user drops
2252 * the data onto the widget. The signal handler must determine whether
2253 * the cursor position is in a drop zone or not. If it is not in a drop
2254 * zone, it returns %FALSE and no further processing is necessary.
2255 * Otherwise, the handler returns %TRUE. In this case, the handler must
2256 * ensure that gtk_drag_finish() is called to let the source know that
2257 * the drop is done. The call to gtk_drag_finish() can be done either
2258 * directly or in a #GtkWidget::drag-data-received handler which gets
2259 * triggered by calling gtk_drag_get_data() to receive the data for one
2260 * or more of the supported targets.
2262 widget_signals[DRAG_DROP] =
2263 g_signal_new (I_("drag-drop"),
2264 G_TYPE_FROM_CLASS (gobject_class),
2266 G_STRUCT_OFFSET (GtkWidgetClass, drag_drop),
2267 _gtk_boolean_handled_accumulator, NULL,
2268 _gtk_marshal_BOOLEAN__OBJECT_INT_INT_UINT,
2270 GDK_TYPE_DRAG_CONTEXT,
2276 * GtkWidget::drag-data-get:
2277 * @widget: the object which received the signal
2278 * @drag_context: the drag context
2279 * @data: the #GtkSelectionData to be filled with the dragged data
2280 * @info: the info that has been registered with the target in the
2282 * @time: the timestamp at which the data was requested
2284 * The ::drag-data-get signal is emitted on the drag source when the drop
2285 * site requests the data which is dragged. It is the responsibility of
2286 * the signal handler to fill @data with the data in the format which
2287 * is indicated by @info. See gtk_selection_data_set() and
2288 * gtk_selection_data_set_text().
2290 widget_signals[DRAG_DATA_GET] =
2291 g_signal_new (I_("drag-data-get"),
2292 G_TYPE_FROM_CLASS (gobject_class),
2294 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
2296 _gtk_marshal_VOID__OBJECT_BOXED_UINT_UINT,
2298 GDK_TYPE_DRAG_CONTEXT,
2299 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2304 * GtkWidget::drag-data-received:
2305 * @widget: the object which received the signal
2306 * @drag_context: the drag context
2307 * @x: where the drop happened
2308 * @y: where the drop happened
2309 * @data: the received data
2310 * @info: the info that has been registered with the target in the
2312 * @time: the timestamp at which the data was received
2314 * The ::drag-data-received signal is emitted on the drop site when the
2315 * dragged data has been received. If the data was received in order to
2316 * determine whether the drop will be accepted, the handler is expected
2317 * to call gdk_drag_status() and <emphasis>not</emphasis> finish the drag.
2318 * If the data was received in response to a #GtkWidget::drag-drop signal
2319 * (and this is the last target to be received), the handler for this
2320 * signal is expected to process the received data and then call
2321 * gtk_drag_finish(), setting the @success parameter depending on whether
2322 * the data was processed successfully.
2324 * The handler may inspect and modify @drag_context->action before calling
2325 * gtk_drag_finish(), e.g. to implement %GDK_ACTION_ASK as shown in the
2326 * following example:
2329 * drag_data_received (GtkWidget *widget,
2330 * GdkDragContext *drag_context,
2333 * GtkSelectionData *data,
2337 * if ((data->length >= 0) && (data->format == 8))
2339 * if (drag_context->action == GDK_ACTION_ASK)
2341 * GtkWidget *dialog;
2344 * dialog = gtk_message_dialog_new (NULL,
2345 * GTK_DIALOG_MODAL |
2346 * GTK_DIALOG_DESTROY_WITH_PARENT,
2348 * GTK_BUTTONS_YES_NO,
2349 * "Move the data ?\n");
2350 * response = gtk_dialog_run (GTK_DIALOG (dialog));
2351 * gtk_widget_destroy (dialog);
2353 * if (response == GTK_RESPONSE_YES)
2354 * drag_context->action = GDK_ACTION_MOVE;
2356 * drag_context->action = GDK_ACTION_COPY;
2359 * gtk_drag_finish (drag_context, TRUE, FALSE, time);
2363 * gtk_drag_finish (drag_context, FALSE, FALSE, time);
2367 widget_signals[DRAG_DATA_RECEIVED] =
2368 g_signal_new (I_("drag-data-received"),
2369 G_TYPE_FROM_CLASS (gobject_class),
2371 G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
2373 _gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT_UINT,
2375 GDK_TYPE_DRAG_CONTEXT,
2378 GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
2383 * GtkWidget::visibility-notify-event:
2384 * @widget: the object which received the signal
2385 * @event: (type Gdk.EventVisibility): the #GdkEventVisibility which
2386 * triggered this signal.
2388 * The ::visibility-notify-event will be emitted when the @widget's window
2389 * is obscured or unobscured.
2391 * To receive this signal the #GdkWindow associated to the widget needs
2392 * to enable the #GDK_VISIBILITY_NOTIFY_MASK mask.
2394 * Returns: %TRUE to stop other handlers from being invoked for the event.
2395 * %FALSE to propagate the event further.
2397 widget_signals[VISIBILITY_NOTIFY_EVENT] =
2398 g_signal_new (I_("visibility-notify-event"),
2399 G_TYPE_FROM_CLASS (gobject_class),
2401 G_STRUCT_OFFSET (GtkWidgetClass, visibility_notify_event),
2402 _gtk_boolean_handled_accumulator, NULL,
2403 _gtk_marshal_BOOLEAN__BOXED,
2405 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2408 * GtkWidget::client-event:
2409 * @widget: the object which received the signal
2410 * @event: (type Gdk.EventClient): the #GdkEventClient which triggered
2413 * The ::client-event will be emitted when the @widget's window
2414 * receives a message (via a ClientMessage event) from another
2417 * Returns: %TRUE to stop other handlers from being invoked for
2418 * the event. %FALSE to propagate the event further.
2420 widget_signals[CLIENT_EVENT] =
2421 g_signal_new (I_("client-event"),
2422 G_TYPE_FROM_CLASS (gobject_class),
2424 G_STRUCT_OFFSET (GtkWidgetClass, client_event),
2425 _gtk_boolean_handled_accumulator, NULL,
2426 _gtk_marshal_BOOLEAN__BOXED,
2428 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2431 * GtkWidget::no-expose-event:
2432 * @widget: the object which received the signal
2433 * @event: (type Gdk.EventNoExpose): the #GdkEventNoExpose which triggered
2436 * The ::no-expose-event will be emitted when the @widget's window is
2437 * drawn as a copy of another #GdkDrawable which was completely unobscured.
2438 * If the source window was partially obscured #GdkEventExpose events will
2439 * be generated for those areas.
2441 * Returns: %TRUE to stop other handlers from being invoked for the event.
2442 * %FALSE to propagate the event further.
2444 widget_signals[NO_EXPOSE_EVENT] =
2445 g_signal_new (I_("no-expose-event"),
2446 G_TYPE_FROM_CLASS (gobject_class),
2448 G_STRUCT_OFFSET (GtkWidgetClass, no_expose_event),
2449 _gtk_boolean_handled_accumulator, NULL,
2450 _gtk_marshal_BOOLEAN__BOXED,
2452 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2455 * GtkWidget::window-state-event:
2456 * @widget: the object which received the signal
2457 * @event: (type Gdk.EventWindowState): the #GdkEventWindowState which
2458 * triggered this signal.
2460 * The ::window-state-event will be emitted when the state of the
2461 * toplevel window associated to the @widget changes.
2463 * To receive this signal the #GdkWindow associated to the widget
2464 * needs to enable the #GDK_STRUCTURE_MASK mask. GDK will enable
2465 * this mask automatically for all new windows.
2467 * Returns: %TRUE to stop other handlers from being invoked for the
2468 * event. %FALSE to propagate the event further.
2470 widget_signals[WINDOW_STATE_EVENT] =
2471 g_signal_new (I_("window-state-event"),
2472 G_TYPE_FROM_CLASS (gobject_class),
2474 G_STRUCT_OFFSET (GtkWidgetClass, window_state_event),
2475 _gtk_boolean_handled_accumulator, NULL,
2476 _gtk_marshal_BOOLEAN__BOXED,
2478 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2481 * GtkWidget::damage-event:
2482 * @widget: the object which received the signal
2483 * @event: the #GdkEventExpose event
2485 * Emitted when a redirected window belonging to @widget gets drawn into.
2486 * The region/area members of the event shows what area of the redirected
2487 * drawable was drawn into.
2489 * Returns: %TRUE to stop other handlers from being invoked for the event.
2490 * %FALSE to propagate the event further.
2494 widget_signals[DAMAGE_EVENT] =
2495 g_signal_new (I_("damage-event"),
2496 G_TYPE_FROM_CLASS (gobject_class),
2499 _gtk_boolean_handled_accumulator, NULL,
2500 _gtk_marshal_BOOLEAN__BOXED,
2502 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2504 * GtkWidget::grab-broken-event:
2505 * @widget: the object which received the signal
2506 * @event: the #GdkEventGrabBroken event
2508 * Emitted when a pointer or keyboard grab on a window belonging
2509 * to @widget gets broken.
2511 * On X11, this happens when the grab window becomes unviewable
2512 * (i.e. it or one of its ancestors is unmapped), or if the same
2513 * application grabs the pointer or keyboard again.
2515 * Returns: %TRUE to stop other handlers from being invoked for
2516 * the event. %FALSE to propagate the event further.
2520 widget_signals[GRAB_BROKEN] =
2521 g_signal_new (I_("grab-broken-event"),
2522 G_TYPE_FROM_CLASS (gobject_class),
2524 G_STRUCT_OFFSET (GtkWidgetClass, grab_broken_event),
2525 _gtk_boolean_handled_accumulator, NULL,
2526 _gtk_marshal_BOOLEAN__BOXED,
2528 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
2530 * GtkWidget::query-tooltip:
2531 * @widget: the object which received the signal
2532 * @x: the x coordinate of the cursor position where the request has
2533 * been emitted, relative to @widget->window
2534 * @y: the y coordinate of the cursor position where the request has
2535 * been emitted, relative to @widget->window
2536 * @keyboard_mode: %TRUE if the tooltip was trigged using the keyboard
2537 * @tooltip: a #GtkTooltip
2539 * Emitted when #GtkWidget:has-tooltip is %TRUE and the #GtkSettings:gtk-tooltip-timeout
2540 * has expired with the cursor hovering "above" @widget; or emitted when @widget got
2541 * focus in keyboard mode.
2543 * Using the given coordinates, the signal handler should determine
2544 * whether a tooltip should be shown for @widget. If this is the case
2545 * %TRUE should be returned, %FALSE otherwise. Note that if
2546 * @keyboard_mode is %TRUE, the values of @x and @y are undefined and
2547 * should not be used.
2549 * The signal handler is free to manipulate @tooltip with the therefore
2550 * destined function calls.
2552 * Returns: %TRUE if @tooltip should be shown right now, %FALSE otherwise.
2556 widget_signals[QUERY_TOOLTIP] =
2557 g_signal_new (I_("query-tooltip"),
2558 G_TYPE_FROM_CLASS (gobject_class),
2560 G_STRUCT_OFFSET (GtkWidgetClass, query_tooltip),
2561 _gtk_boolean_handled_accumulator, NULL,
2562 _gtk_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2570 * GtkWidget::popup-menu
2571 * @widget: the object which received the signal
2573 * This signal gets emitted whenever a widget should pop up a context
2574 * menu. This usually happens through the standard key binding mechanism;
2575 * by pressing a certain key while a widget is focused, the user can cause
2576 * the widget to pop up a menu. For example, the #GtkEntry widget creates
2577 * a menu with clipboard commands. See <xref linkend="checklist-popup-menu"/>
2578 * for an example of how to use this signal.
2580 * Returns: %TRUE if a menu was activated
2582 widget_signals[POPUP_MENU] =
2583 g_signal_new (I_("popup-menu"),
2584 G_TYPE_FROM_CLASS (gobject_class),
2585 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2586 G_STRUCT_OFFSET (GtkWidgetClass, popup_menu),
2587 _gtk_boolean_handled_accumulator, NULL,
2588 _gtk_marshal_BOOLEAN__VOID,
2592 * GtkWidget::show-help:
2593 * @widget: the object which received the signal.
2596 widget_signals[SHOW_HELP] =
2597 g_signal_new (I_("show-help"),
2598 G_TYPE_FROM_CLASS (gobject_class),
2599 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
2600 G_STRUCT_OFFSET (GtkWidgetClass, show_help),
2601 _gtk_boolean_handled_accumulator, NULL,
2602 _gtk_marshal_BOOLEAN__ENUM,
2604 GTK_TYPE_WIDGET_HELP_TYPE);
2607 * GtkWidget::accel-closures-changed:
2608 * @widget: the object which received the signal.
2610 widget_signals[ACCEL_CLOSURES_CHANGED] =
2611 g_signal_new (I_("accel-closures-changed"),
2612 G_TYPE_FROM_CLASS (gobject_class),
2616 _gtk_marshal_VOID__VOID,
2620 * GtkWidget::screen-changed:
2621 * @widget: the object on which the signal is emitted
2622 * @previous_screen: (allow-none): the previous screen, or %NULL if the
2623 * widget was not associated with a screen before
2625 * The ::screen-changed signal gets emitted when the
2626 * screen of a widget has changed.
2628 widget_signals[SCREEN_CHANGED] =
2629 g_signal_new (I_("screen-changed"),
2630 G_TYPE_FROM_CLASS (gobject_class),
2632 G_STRUCT_OFFSET (GtkWidgetClass, screen_changed),
2634 _gtk_marshal_VOID__OBJECT,
2639 * GtkWidget::can-activate-accel:
2640 * @widget: the object which received the signal
2641 * @signal_id: the ID of a signal installed on @widget
2643 * Determines whether an accelerator that activates the signal
2644 * identified by @signal_id can currently be activated.
2645 * This signal is present to allow applications and derived
2646 * widgets to override the default #GtkWidget handling
2647 * for determining whether an accelerator can be activated.
2649 * Returns: %TRUE if the signal can be activated.
2651 widget_signals[CAN_ACTIVATE_ACCEL] =
2652 g_signal_new (I_("can-activate-accel"),
2653 G_TYPE_FROM_CLASS (gobject_class),
2655 G_STRUCT_OFFSET (GtkWidgetClass, can_activate_accel),
2656 _gtk_boolean_handled_accumulator, NULL,
2657 _gtk_marshal_BOOLEAN__UINT,
2658 G_TYPE_BOOLEAN, 1, G_TYPE_UINT);
2660 binding_set = gtk_binding_set_by_class (klass);
2661 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F10, GDK_SHIFT_MASK,
2663 gtk_binding_entry_add_signal (binding_set, GDK_KEY_Menu, 0,
2666 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_CONTROL_MASK,
2668 GTK_TYPE_WIDGET_HELP_TYPE,
2669 GTK_WIDGET_HELP_TOOLTIP);
2670 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_CONTROL_MASK,
2672 GTK_TYPE_WIDGET_HELP_TYPE,
2673 GTK_WIDGET_HELP_TOOLTIP);
2674 gtk_binding_entry_add_signal (binding_set, GDK_KEY_F1, GDK_SHIFT_MASK,
2676 GTK_TYPE_WIDGET_HELP_TYPE,
2677 GTK_WIDGET_HELP_WHATS_THIS);
2678 gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_F1, GDK_SHIFT_MASK,
2680 GTK_TYPE_WIDGET_HELP_TYPE,
2681 GTK_WIDGET_HELP_WHATS_THIS);
2683 gtk_widget_class_install_style_property (klass,
2684 g_param_spec_boolean ("interior-focus",
2685 P_("Interior Focus"),
2686 P_("Whether to draw the focus indicator inside widgets"),
2688 GTK_PARAM_READABLE));
2690 gtk_widget_class_install_style_property (klass,
2691 g_param_spec_int ("focus-line-width",
2692 P_("Focus linewidth"),
2693 P_("Width, in pixels, of the focus indicator line"),
2695 GTK_PARAM_READABLE));
2697 gtk_widget_class_install_style_property (klass,
2698 g_param_spec_string ("focus-line-pattern",
2699 P_("Focus line dash pattern"),
2700 P_("Dash pattern used to draw the focus indicator"),
2702 GTK_PARAM_READABLE));
2703 gtk_widget_class_install_style_property (klass,
2704 g_param_spec_int ("focus-padding",
2705 P_("Focus padding"),
2706 P_("Width, in pixels, between focus indicator and the widget 'box'"),
2708 GTK_PARAM_READABLE));
2709 gtk_widget_class_install_style_property (klass,
2710 g_param_spec_boxed ("cursor-color",
2712 P_("Color with which to draw insertion cursor"),
2714 GTK_PARAM_READABLE));
2715 gtk_widget_class_install_style_property (klass,
2716 g_param_spec_boxed ("secondary-cursor-color",
2717 P_("Secondary cursor color"),
2718 P_("Color with which to draw the secondary insertion cursor when editing mixed right-to-left and left-to-right text"),
2720 GTK_PARAM_READABLE));
2721 gtk_widget_class_install_style_property (klass,
2722 g_param_spec_float ("cursor-aspect-ratio",
2723 P_("Cursor line aspect ratio"),
2724 P_("Aspect ratio with which to draw insertion cursor"),
2726 GTK_PARAM_READABLE));
2728 gtk_widget_class_install_style_property (klass,
2729 g_param_spec_boolean ("window-dragging",
2730 P_("Window dragging"),
2731 P_("Whether windows can be dragged by clicking on empty areas"),
2733 GTK_PARAM_READABLE));
2736 * GtkWidget:link-color:
2738 * The "link-color" style property defines the color of unvisited links.
2742 gtk_widget_class_install_style_property (klass,
2743 g_param_spec_boxed ("link-color",
2744 P_("Unvisited Link Color"),
2745 P_("Color of unvisited links"),
2747 GTK_PARAM_READABLE));
2750 * GtkWidget:visited-link-color:
2752 * The "visited-link-color" style property defines the color of visited links.
2756 gtk_widget_class_install_style_property (klass,
2757 g_param_spec_boxed ("visited-link-color",
2758 P_("Visited Link Color"),
2759 P_("Color of visited links"),
2761 GTK_PARAM_READABLE));
2764 * GtkWidget:wide-separators:
2766 * The "wide-separators" style property defines whether separators have
2767 * configurable width and should be drawn using a box instead of a line.
2771 gtk_widget_class_install_style_property (klass,
2772 g_param_spec_boolean ("wide-separators",
2773 P_("Wide Separators"),
2774 P_("Whether separators have configurable width and should be drawn using a box instead of a line"),
2776 GTK_PARAM_READABLE));
2779 * GtkWidget:separator-width:
2781 * The "separator-width" style property defines the width of separators.
2782 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2786 gtk_widget_class_install_style_property (klass,
2787 g_param_spec_int ("separator-width",
2788 P_("Separator Width"),
2789 P_("The width of separators if wide-separators is TRUE"),
2791 GTK_PARAM_READABLE));
2794 * GtkWidget:separator-height:
2796 * The "separator-height" style property defines the height of separators.
2797 * This property only takes effect if #GtkWidget:wide-separators is %TRUE.
2801 gtk_widget_class_install_style_property (klass,
2802 g_param_spec_int ("separator-height",
2803 P_("Separator Height"),
2804 P_("The height of separators if \"wide-separators\" is TRUE"),
2806 GTK_PARAM_READABLE));
2809 * GtkWidget:scroll-arrow-hlength:
2811 * The "scroll-arrow-hlength" style property defines the length of
2812 * horizontal scroll arrows.
2816 gtk_widget_class_install_style_property (klass,
2817 g_param_spec_int ("scroll-arrow-hlength",
2818 P_("Horizontal Scroll Arrow Length"),
2819 P_("The length of horizontal scroll arrows"),
2821 GTK_PARAM_READABLE));
2824 * GtkWidget:scroll-arrow-vlength:
2826 * The "scroll-arrow-vlength" style property defines the length of
2827 * vertical scroll arrows.
2831 gtk_widget_class_install_style_property (klass,
2832 g_param_spec_int ("scroll-arrow-vlength",
2833 P_("Vertical Scroll Arrow Length"),
2834 P_("The length of vertical scroll arrows"),
2836 GTK_PARAM_READABLE));
2838 g_type_class_add_private (klass, sizeof (GtkWidgetPrivate));
2842 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
2846 list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
2847 for (node = list; node; node = node->next)
2849 GParamSpec *pspec = node->data;
2851 g_param_spec_pool_remove (style_property_spec_pool, pspec);
2852 g_param_spec_unref (pspec);
2858 gtk_widget_set_property (GObject *object,
2860 const GValue *value,
2863 GtkWidget *widget = GTK_WIDGET (object);
2868 gchar *tooltip_markup;
2869 const gchar *tooltip_text;
2870 GtkWindow *tooltip_window;
2873 gtk_widget_set_name (widget, g_value_get_string (value));
2876 gtk_container_add (GTK_CONTAINER (g_value_get_object (value)), widget);
2878 case PROP_WIDTH_REQUEST:
2879 gtk_widget_set_usize_internal (widget, g_value_get_int (value), -2);
2881 case PROP_HEIGHT_REQUEST:
2882 gtk_widget_set_usize_internal (widget, -2, g_value_get_int (value));
2885 gtk_widget_set_visible (widget, g_value_get_boolean (value));
2887 case PROP_SENSITIVE:
2888 gtk_widget_set_sensitive (widget, g_value_get_boolean (value));
2890 case PROP_APP_PAINTABLE:
2891 gtk_widget_set_app_paintable (widget, g_value_get_boolean (value));
2893 case PROP_CAN_FOCUS:
2894 gtk_widget_set_can_focus (widget, g_value_get_boolean (value));
2896 case PROP_HAS_FOCUS:
2897 if (g_value_get_boolean (value))
2898 gtk_widget_grab_focus (widget);
2901 if (g_value_get_boolean (value))
2902 gtk_widget_grab_focus (widget);
2904 case PROP_CAN_DEFAULT:
2905 gtk_widget_set_can_default (widget, g_value_get_boolean (value));
2907 case PROP_HAS_DEFAULT:
2908 if (g_value_get_boolean (value))
2909 gtk_widget_grab_default (widget);
2911 case PROP_RECEIVES_DEFAULT:
2912 gtk_widget_set_receives_default (widget, g_value_get_boolean (value));
2915 gtk_widget_set_style (widget, g_value_get_object (value));
2918 if (!gtk_widget_get_realized (widget) && gtk_widget_get_has_window (widget))
2919 gtk_widget_set_events (widget, g_value_get_flags (value));
2921 case PROP_EXTENSION_EVENTS:
2922 gtk_widget_set_extension_events (widget, g_value_get_enum (value));
2924 case PROP_NO_SHOW_ALL:
2925 gtk_widget_set_no_show_all (widget, g_value_get_boolean (value));
2927 case PROP_HAS_TOOLTIP:
2928 gtk_widget_real_set_has_tooltip (widget,
2929 g_value_get_boolean (value), FALSE);
2931 case PROP_TOOLTIP_MARKUP:
2932 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2933 tooltip_markup = g_value_dup_string (value);
2935 /* Treat an empty string as a NULL string,
2936 * because an empty string would be useless for a tooltip:
2938 if (tooltip_markup && (strlen (tooltip_markup) == 0))
2940 g_free (tooltip_markup);
2941 tooltip_markup = NULL;
2944 g_object_set_qdata_full (object, quark_tooltip_markup,
2945 tooltip_markup, g_free);
2947 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2948 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2949 if (gtk_widget_get_visible (widget))
2950 gtk_widget_queue_tooltip_query (widget);
2952 case PROP_TOOLTIP_TEXT:
2953 tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
2955 tooltip_text = g_value_get_string (value);
2957 /* Treat an empty string as a NULL string,
2958 * because an empty string would be useless for a tooltip:
2960 if (tooltip_text && (strlen (tooltip_text) == 0))
2961 tooltip_text = NULL;
2963 tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
2965 g_object_set_qdata_full (object, quark_tooltip_markup,
2966 tooltip_markup, g_free);
2968 tmp = (tooltip_window != NULL || tooltip_markup != NULL);
2969 gtk_widget_real_set_has_tooltip (widget, tmp, FALSE);
2970 if (gtk_widget_get_visible (widget))
2971 gtk_widget_queue_tooltip_query (widget);
2973 case PROP_DOUBLE_BUFFERED:
2974 gtk_widget_set_double_buffered (widget, g_value_get_boolean (value));
2977 gtk_widget_set_halign (widget, g_value_get_enum (value));
2980 gtk_widget_set_valign (widget, g_value_get_enum (value));
2982 case PROP_MARGIN_LEFT:
2983 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2985 case PROP_MARGIN_RIGHT:
2986 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2988 case PROP_MARGIN_TOP:
2989 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2991 case PROP_MARGIN_BOTTOM:
2992 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
2995 g_object_freeze_notify (G_OBJECT (widget));
2996 gtk_widget_set_margin_left (widget, g_value_get_int (value));
2997 gtk_widget_set_margin_right (widget, g_value_get_int (value));
2998 gtk_widget_set_margin_top (widget, g_value_get_int (value));
2999 gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
3000 g_object_thaw_notify (G_OBJECT (widget));
3003 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3009 gtk_widget_get_property (GObject *object,
3014 GtkWidget *widget = GTK_WIDGET (object);
3015 GtkWidgetPrivate *priv = widget->priv;
3024 g_value_set_string (value, priv->name);
3026 g_value_set_static_string (value, "");
3029 g_value_set_object (value, priv->parent);
3031 case PROP_WIDTH_REQUEST:
3034 gtk_widget_get_size_request (widget, &w, NULL);
3035 g_value_set_int (value, w);
3038 case PROP_HEIGHT_REQUEST:
3041 gtk_widget_get_size_request (widget, NULL, &h);
3042 g_value_set_int (value, h);
3046 g_value_set_boolean (value, (gtk_widget_get_visible (widget) != FALSE));
3048 case PROP_SENSITIVE:
3049 g_value_set_boolean (value, (gtk_widget_get_sensitive (widget) != FALSE));
3051 case PROP_APP_PAINTABLE:
3052 g_value_set_boolean (value, (gtk_widget_get_app_paintable (widget) != FALSE));
3054 case PROP_CAN_FOCUS:
3055 g_value_set_boolean (value, (gtk_widget_get_can_focus (widget) != FALSE));
3057 case PROP_HAS_FOCUS:
3058 g_value_set_boolean (value, (gtk_widget_has_focus (widget) != FALSE));
3061 g_value_set_boolean (value, (gtk_widget_is_focus (widget)));
3063 case PROP_CAN_DEFAULT:
3064 g_value_set_boolean (value, (gtk_widget_get_can_default (widget) != FALSE));
3066 case PROP_HAS_DEFAULT:
3067 g_value_set_boolean (value, (gtk_widget_has_default (widget) != FALSE));
3069 case PROP_RECEIVES_DEFAULT:
3070 g_value_set_boolean (value, (gtk_widget_get_receives_default (widget) != FALSE));
3072 case PROP_COMPOSITE_CHILD:
3073 g_value_set_boolean (value, (GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0 );
3076 g_value_set_object (value, gtk_widget_get_style (widget));
3079 eventp = g_object_get_qdata (G_OBJECT (widget), quark_event_mask);
3080 g_value_set_flags (value, GPOINTER_TO_INT (eventp));
3082 case PROP_EXTENSION_EVENTS:
3083 modep = g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode);
3084 g_value_set_enum (value, GPOINTER_TO_INT (modep));
3086 case PROP_NO_SHOW_ALL:
3087 g_value_set_boolean (value, gtk_widget_get_no_show_all (widget));
3089 case PROP_HAS_TOOLTIP:
3090 g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
3092 case PROP_TOOLTIP_TEXT:
3094 gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
3097 if (escaped && !pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
3098 g_assert (NULL == text); /* text should still be NULL in case of markup errors */
3100 g_value_take_string (value, text);
3103 case PROP_TOOLTIP_MARKUP:
3104 g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
3107 g_value_set_object (value, gtk_widget_get_window (widget));
3109 case PROP_DOUBLE_BUFFERED:
3110 g_value_set_boolean (value, gtk_widget_get_double_buffered (widget));
3113 g_value_set_enum (value, gtk_widget_get_halign (widget));
3116 g_value_set_enum (value, gtk_widget_get_valign (widget));
3118 case PROP_MARGIN_LEFT:
3119 g_value_set_int (value, gtk_widget_get_margin_left (widget));
3121 case PROP_MARGIN_RIGHT:
3122 g_value_set_int (value, gtk_widget_get_margin_right (widget));
3124 case PROP_MARGIN_TOP:
3125 g_value_set_int (value, gtk_widget_get_margin_top (widget));
3127 case PROP_MARGIN_BOTTOM:
3128 g_value_set_int (value, gtk_widget_get_margin_bottom (widget));
3132 GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
3133 if (aux_info == NULL)
3135 g_value_set_int (value, 0);
3139 g_value_set_int (value, MAX (MAX (aux_info->margin.left,
3140 aux_info->margin.right),
3141 MAX (aux_info->margin.top,
3142 aux_info->margin.bottom)));
3147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3153 gtk_widget_init (GtkWidget *widget)
3155 GtkWidgetPrivate *priv;
3157 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
3160 priv = widget->priv;
3162 GTK_PRIVATE_FLAGS (widget) = PRIVATE_GTK_CHILD_VISIBLE;
3163 priv->state = GTK_STATE_NORMAL;
3164 priv->saved_state = GTK_STATE_NORMAL;
3166 priv->allocation.x = -1;
3167 priv->allocation.y = -1;
3168 priv->allocation.width = 1;
3169 priv->allocation.height = 1;
3170 priv->window = NULL;
3171 priv->parent = NULL;
3173 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
3174 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
3175 GTK_OBJECT_FLAGS (widget) |= composite_child_stack ? GTK_COMPOSITE_CHILD : 0;
3176 gtk_widget_set_double_buffered (widget, TRUE);
3178 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
3179 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
3180 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
3181 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
3183 priv->style = gtk_widget_get_default_style ();
3184 g_object_ref (priv->style);
3189 gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
3191 GParamSpec **pspecs)
3193 GtkWidgetPrivate *priv = widget->priv;
3194 GtkWidget *container = priv->parent;
3197 for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
3198 g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
3202 * gtk_widget_freeze_child_notify:
3203 * @widget: a #GtkWidget
3205 * Stops emission of #GtkWidget::child-notify signals on @widget. The
3206 * signals are queued until gtk_widget_thaw_child_notify() is called
3209 * This is the analogue of g_object_freeze_notify() for child properties.
3212 gtk_widget_freeze_child_notify (GtkWidget *widget)
3214 g_return_if_fail (GTK_IS_WIDGET (widget));
3216 if (!G_OBJECT (widget)->ref_count)
3219 g_object_ref (widget);
3220 g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3221 g_object_unref (widget);
3225 * gtk_widget_child_notify:
3226 * @widget: a #GtkWidget
3227 * @child_property: the name of a child property installed on the
3228 * class of @widget<!-- -->'s parent
3230 * Emits a #GtkWidget::child-notify signal for the
3231 * <link linkend="child-properties">child property</link> @child_property
3234 * This is the analogue of g_object_notify() for child properties.
3237 gtk_widget_child_notify (GtkWidget *widget,
3238 const gchar *child_property)
3240 GtkWidgetPrivate *priv = widget->priv;
3243 g_return_if_fail (GTK_IS_WIDGET (widget));
3244 g_return_if_fail (child_property != NULL);
3245 if (!G_OBJECT (widget)->ref_count || !priv->parent)
3248 g_object_ref (widget);
3249 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
3251 G_OBJECT_TYPE (priv->parent),
3254 g_warning ("%s: container class `%s' has no child property named `%s'",
3256 G_OBJECT_TYPE_NAME (priv->parent),
3260 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3262 g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
3263 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3265 g_object_unref (widget);
3269 * gtk_widget_thaw_child_notify:
3270 * @widget: a #GtkWidget
3272 * Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
3273 * This causes all queued #GtkWidget::child-notify signals on @widget to be
3277 gtk_widget_thaw_child_notify (GtkWidget *widget)
3279 GObjectNotifyQueue *nqueue;
3281 g_return_if_fail (GTK_IS_WIDGET (widget));
3283 if (!G_OBJECT (widget)->ref_count)
3286 g_object_ref (widget);
3287 nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3288 if (!nqueue || !nqueue->freeze_count)
3289 g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
3290 G_OBJECT_TYPE_NAME (widget), widget);
3292 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3293 g_object_unref (widget);
3299 * @type: type ID of the widget to create
3300 * @first_property_name: name of first property to set
3301 * @Varargs: value of first property, followed by more properties,
3304 * This is a convenience function for creating a widget and setting
3305 * its properties in one go. For example you might write:
3306 * <literal>gtk_widget_new (GTK_TYPE_LABEL, "label", "Hello World", "xalign",
3307 * 0.0, NULL)</literal> to create a left-aligned label. Equivalent to
3308 * g_object_new(), but returns a widget so you don't have to
3309 * cast the object yourself.
3311 * Return value: a new #GtkWidget of type @widget_type
3314 gtk_widget_new (GType type,
3315 const gchar *first_property_name,
3321 g_return_val_if_fail (g_type_is_a (type, GTK_TYPE_WIDGET), NULL);
3323 va_start (var_args, first_property_name);
3324 widget = (GtkWidget *)g_object_new_valist (type, first_property_name, var_args);
3331 gtk_widget_queue_draw_child (GtkWidget *widget)
3333 GtkWidgetPrivate *priv = widget->priv;
3336 parent = priv->parent;
3337 if (parent && gtk_widget_is_drawable (parent))
3338 gtk_widget_queue_draw_area (parent,
3341 priv->allocation.width,
3342 priv->allocation.height);
3346 * gtk_widget_unparent:
3347 * @widget: a #GtkWidget
3349 * This function is only for use in widget implementations.
3350 * Should be called by implementations of the remove method
3351 * on #GtkContainer, to dissociate a child from the container.
3354 gtk_widget_unparent (GtkWidget *widget)
3356 GtkWidgetPrivate *priv;
3357 GObjectNotifyQueue *nqueue;
3358 GtkWidget *toplevel;
3359 GtkWidget *old_parent;
3361 g_return_if_fail (GTK_IS_WIDGET (widget));
3363 priv = widget->priv;
3365 if (priv->parent == NULL)
3368 /* keep this function in sync with gtk_menu_detach()
3371 g_object_freeze_notify (G_OBJECT (widget));
3372 nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
3374 toplevel = gtk_widget_get_toplevel (widget);
3375 if (gtk_widget_is_toplevel (toplevel))
3376 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3378 if (gtk_container_get_focus_child (GTK_CONTAINER (priv->parent)) == widget)
3379 gtk_container_set_focus_child (GTK_CONTAINER (priv->parent), NULL);
3381 /* If we are unanchoring the child, we save around the toplevel
3382 * to emit hierarchy changed
3384 if (GTK_WIDGET_ANCHORED (priv->parent))
3385 g_object_ref (toplevel);
3389 gtk_widget_queue_draw_child (widget);
3391 /* Reset the width and height here, to force reallocation if we
3392 * get added back to a new parent. This won't work if our new
3393 * allocation is smaller than 1x1 and we actually want a size of 1x1...
3394 * (would 0x0 be OK here?)
3396 priv->allocation.width = 1;
3397 priv->allocation.height = 1;
3399 if (gtk_widget_get_realized (widget))
3401 if (GTK_WIDGET_IN_REPARENT (widget))
3402 gtk_widget_unmap (widget);
3404 gtk_widget_unrealize (widget);
3407 /* Removing a widget from a container restores the child visible
3408 * flag to the default state, so it doesn't affect the child
3409 * in the next parent.
3411 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
3413 old_parent = priv->parent;
3414 priv->parent = NULL;
3415 gtk_widget_set_parent_window (widget, NULL);
3416 g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
3419 _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
3420 g_object_unref (toplevel);
3423 g_object_notify (G_OBJECT (widget), "parent");
3424 g_object_thaw_notify (G_OBJECT (widget));
3426 g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
3427 g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
3428 g_object_unref (widget);
3432 * gtk_widget_destroy:
3433 * @widget: a #GtkWidget
3435 * Destroys a widget. Equivalent to gtk_object_destroy(), except that
3436 * you don't have to cast the widget to #GtkObject. When a widget is
3437 * destroyed, it will break any references it holds to other objects.
3438 * If the widget is inside a container, the widget will be removed
3439 * from the container. If the widget is a toplevel (derived from
3440 * #GtkWindow), it will be removed from the list of toplevels, and the
3441 * reference GTK+ holds to it will be removed. Removing a
3442 * widget from its container or the list of toplevels results in the
3443 * widget being finalized, unless you've added additional references
3444 * to the widget with g_object_ref().
3446 * In most cases, only toplevel widgets (windows) require explicit
3447 * destruction, because when you destroy a toplevel its children will
3448 * be destroyed as well.
3451 gtk_widget_destroy (GtkWidget *widget)
3453 g_return_if_fail (GTK_IS_WIDGET (widget));
3455 gtk_object_destroy ((GtkObject*) widget);
3459 * gtk_widget_destroyed:
3460 * @widget: a #GtkWidget
3461 * @widget_pointer: (inout) (transfer none): address of a variable that contains @widget
3463 * This function sets *@widget_pointer to %NULL if @widget_pointer !=
3464 * %NULL. It's intended to be used as a callback connected to the
3465 * "destroy" signal of a widget. You connect gtk_widget_destroyed()
3466 * as a signal handler, and pass the address of your widget variable
3467 * as user data. Then when the widget is destroyed, the variable will
3468 * be set to %NULL. Useful for example to avoid multiple copies
3469 * of the same dialog.
3472 gtk_widget_destroyed (GtkWidget *widget,
3473 GtkWidget **widget_pointer)
3475 /* Don't make any assumptions about the
3477 * Even check widget_pointer.
3480 *widget_pointer = NULL;
3485 * @widget: a #GtkWidget
3487 * Flags a widget to be displayed. Any widget that isn't shown will
3488 * not appear on the screen. If you want to show all the widgets in a
3489 * container, it's easier to call gtk_widget_show_all() on the
3490 * container, instead of individually showing the widgets.
3492 * Remember that you have to show the containers containing a widget,
3493 * in addition to the widget itself, before it will appear onscreen.
3495 * When a toplevel container is shown, it is immediately realized and
3496 * mapped; other shown widgets are realized and mapped when their
3497 * toplevel container is realized and mapped.
3500 gtk_widget_show (GtkWidget *widget)
3502 g_return_if_fail (GTK_IS_WIDGET (widget));
3504 if (!gtk_widget_get_visible (widget))
3506 g_object_ref (widget);
3507 if (!gtk_widget_is_toplevel (widget))
3508 gtk_widget_queue_resize (widget);
3509 g_signal_emit (widget, widget_signals[SHOW], 0);
3510 g_object_notify (G_OBJECT (widget), "visible");
3511 g_object_unref (widget);
3516 gtk_widget_real_show (GtkWidget *widget)
3518 GtkWidgetPrivate *priv = widget->priv;
3520 if (!gtk_widget_get_visible (widget))
3522 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
3525 gtk_widget_get_mapped (priv->parent) &&
3526 GTK_WIDGET_CHILD_VISIBLE (widget) &&
3527 !gtk_widget_get_mapped (widget))
3528 gtk_widget_map (widget);
3533 gtk_widget_show_map_callback (GtkWidget *widget, GdkEvent *event, gint *flag)
3536 g_signal_handlers_disconnect_by_func (widget,
3537 gtk_widget_show_map_callback,
3542 * gtk_widget_show_now:
3543 * @widget: a #GtkWidget
3545 * Shows a widget. If the widget is an unmapped toplevel widget
3546 * (i.e. a #GtkWindow that has not yet been shown), enter the main
3547 * loop and wait for the window to actually be mapped. Be careful;
3548 * because the main loop is running, anything can happen during
3552 gtk_widget_show_now (GtkWidget *widget)
3556 g_return_if_fail (GTK_IS_WIDGET (widget));
3558 /* make sure we will get event */
3559 if (!gtk_widget_get_mapped (widget) &&
3560 gtk_widget_is_toplevel (widget))
3562 gtk_widget_show (widget);
3564 g_signal_connect (widget, "map-event",
3565 G_CALLBACK (gtk_widget_show_map_callback),
3569 gtk_main_iteration ();
3572 gtk_widget_show (widget);
3577 * @widget: a #GtkWidget
3579 * Reverses the effects of gtk_widget_show(), causing the widget to be
3580 * hidden (invisible to the user).
3583 gtk_widget_hide (GtkWidget *widget)
3585 g_return_if_fail (GTK_IS_WIDGET (widget));
3587 if (gtk_widget_get_visible (widget))
3589 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
3591 g_object_ref (widget);
3592 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
3593 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
3595 g_signal_emit (widget, widget_signals[HIDE], 0);
3596 if (!gtk_widget_is_toplevel (widget))
3597 gtk_widget_queue_resize (widget);
3598 g_object_notify (G_OBJECT (widget), "visible");
3599 g_object_unref (widget);
3604 gtk_widget_real_hide (GtkWidget *widget)
3606 if (gtk_widget_get_visible (widget))
3608 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
3610 if (gtk_widget_get_mapped (widget))
3611 gtk_widget_unmap (widget);
3616 * gtk_widget_hide_on_delete:
3617 * @widget: a #GtkWidget
3619 * Utility function; intended to be connected to the #GtkWidget::delete-event
3620 * signal on a #GtkWindow. The function calls gtk_widget_hide() on its
3621 * argument, then returns %TRUE. If connected to ::delete-event, the
3622 * result is that clicking the close button for a window (on the
3623 * window frame, top right corner usually) will hide but not destroy
3624 * the window. By default, GTK+ destroys windows when ::delete-event
3627 * Return value: %TRUE
3630 gtk_widget_hide_on_delete (GtkWidget *widget)
3632 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
3634 gtk_widget_hide (widget);
3640 * gtk_widget_show_all:
3641 * @widget: a #GtkWidget
3643 * Recursively shows a widget, and any child widgets (if the widget is
3647 gtk_widget_show_all (GtkWidget *widget)
3649 GtkWidgetClass *class;
3651 g_return_if_fail (GTK_IS_WIDGET (widget));
3653 if (gtk_widget_get_no_show_all (widget))
3656 class = GTK_WIDGET_GET_CLASS (widget);
3658 if (class->show_all)
3659 class->show_all (widget);
3663 * gtk_widget_hide_all:
3664 * @widget: a #GtkWidget
3666 * Recursively hides a widget and any child widgets.
3669 gtk_widget_hide_all (GtkWidget *widget)
3671 GtkWidgetClass *class;
3673 g_return_if_fail (GTK_IS_WIDGET (widget));
3675 if (gtk_widget_get_no_show_all (widget))
3678 class = GTK_WIDGET_GET_CLASS (widget);
3680 if (class->hide_all)
3681 class->hide_all (widget);
3686 * @widget: a #GtkWidget
3688 * This function is only for use in widget implementations. Causes
3689 * a widget to be mapped if it isn't already.
3692 gtk_widget_map (GtkWidget *widget)
3694 GtkWidgetPrivate *priv;
3696 g_return_if_fail (GTK_IS_WIDGET (widget));
3697 g_return_if_fail (gtk_widget_get_visible (widget));
3698 g_return_if_fail (GTK_WIDGET_CHILD_VISIBLE (widget));
3700 priv = widget->priv;
3702 if (!gtk_widget_get_mapped (widget))
3704 if (!gtk_widget_get_realized (widget))
3705 gtk_widget_realize (widget);
3707 g_signal_emit (widget, widget_signals[MAP], 0);
3709 if (!gtk_widget_get_has_window (widget))
3710 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3716 * @widget: a #GtkWidget
3718 * This function is only for use in widget implementations. Causes
3719 * a widget to be unmapped if it's currently mapped.
3722 gtk_widget_unmap (GtkWidget *widget)
3724 GtkWidgetPrivate *priv;
3726 g_return_if_fail (GTK_IS_WIDGET (widget));
3728 priv = widget->priv;
3730 if (gtk_widget_get_mapped (widget))
3732 if (!gtk_widget_get_has_window (widget))
3733 gdk_window_invalidate_rect (priv->window, &priv->allocation, FALSE);
3734 _gtk_tooltip_hide (widget);
3735 g_signal_emit (widget, widget_signals[UNMAP], 0);
3740 gtk_widget_set_extension_events_internal (GtkWidget *widget,
3741 GdkExtensionMode mode,
3744 GtkWidgetPrivate *priv = widget->priv;
3745 GList *free_list = NULL;
3748 if (window_list == NULL)
3750 if (gtk_widget_get_has_window (widget))
3751 window_list = g_list_prepend (NULL, priv->window);
3753 window_list = gdk_window_get_children (priv->window);
3755 free_list = window_list;
3758 for (l = window_list; l != NULL; l = l->next)
3760 GdkWindow *window = l->data;
3763 gdk_window_get_user_data (window, &user_data);
3764 if (user_data == widget)
3768 gdk_input_set_extension_events (window,
3769 gdk_window_get_events (window),
3772 children = gdk_window_get_children (window);
3775 gtk_widget_set_extension_events_internal (widget, mode, children);
3776 g_list_free (children);
3782 g_list_free (free_list);
3786 _gtk_widget_enable_device_events (GtkWidget *widget)
3788 GHashTable *device_events;
3789 GHashTableIter iter;
3790 gpointer key, value;
3792 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
3797 g_hash_table_iter_init (&iter, device_events);
3799 while (g_hash_table_iter_next (&iter, &key, &value))
3802 GdkEventMask event_mask;
3805 event_mask = GPOINTER_TO_UINT (value);
3806 gtk_widget_add_events_internal (widget, device, event_mask);
3811 * gtk_widget_realize:
3812 * @widget: a #GtkWidget
3814 * Creates the GDK (windowing system) resources associated with a
3815 * widget. For example, @widget->window will be created when a widget
3816 * is realized. Normally realization happens implicitly; if you show
3817 * a widget and all its parent containers, then the widget will be
3818 * realized and mapped automatically.
3820 * Realizing a widget requires all
3821 * the widget's parent widgets to be realized; calling
3822 * gtk_widget_realize() realizes the widget's parents in addition to
3823 * @widget itself. If a widget is not yet inside a toplevel window
3824 * when you realize it, bad things will happen.
3826 * This function is primarily used in widget implementations, and
3827 * isn't very useful otherwise. Many times when you think you might
3828 * need it, a better approach is to connect to a signal that will be
3829 * called after the widget is realized automatically, such as
3830 * GtkWidget::expose-event. Or simply g_signal_connect () to the
3831 * GtkWidget::realize signal.
3834 gtk_widget_realize (GtkWidget *widget)
3836 GtkWidgetPrivate *priv;
3837 GdkExtensionMode mode;
3838 cairo_region_t *region;
3840 g_return_if_fail (GTK_IS_WIDGET (widget));
3841 g_return_if_fail (GTK_WIDGET_ANCHORED (widget) ||
3842 GTK_IS_INVISIBLE (widget));
3844 priv = widget->priv;
3846 if (!gtk_widget_get_realized (widget))
3849 if (GTK_IS_CONTAINER (widget) && gtk_widget_get_has_window (widget))
3850 g_message ("gtk_widget_realize(%s)", G_OBJECT_TYPE_NAME (widget));
3853 if (priv->parent == NULL &&
3854 !gtk_widget_is_toplevel (widget))
3855 g_warning ("Calling gtk_widget_realize() on a widget that isn't "
3856 "inside a toplevel window is not going to work very well. "
3857 "Widgets must be inside a toplevel container before realizing them.");
3859 if (priv->parent && !gtk_widget_get_realized (priv->parent))
3860 gtk_widget_realize (priv->parent);
3862 gtk_widget_ensure_style (widget);
3864 g_signal_emit (widget, widget_signals[REALIZE], 0);
3866 gtk_widget_real_set_has_tooltip (widget,
3867 GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip)),
3870 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3872 region = g_object_get_qdata (G_OBJECT (widget), quark_shape_info);
3873 gdk_window_shape_combine_region (priv->window, region, 0, 0);
3876 region = g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info);
3878 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
3880 mode = gtk_widget_get_extension_events (widget);
3881 if (mode != GDK_EXTENSION_EVENTS_NONE)
3882 gtk_widget_set_extension_events_internal (widget, mode, NULL);
3884 if ((GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE) != 0)
3885 gdk_window_set_support_multidevice (priv->window, TRUE);
3887 _gtk_widget_enable_device_events (widget);
3892 * gtk_widget_unrealize:
3893 * @widget: a #GtkWidget
3895 * This function is only useful in widget implementations.
3896 * Causes a widget to be unrealized (frees all GDK resources
3897 * associated with the widget, such as @widget->window).
3900 gtk_widget_unrealize (GtkWidget *widget)
3902 g_return_if_fail (GTK_IS_WIDGET (widget));
3904 if (GTK_WIDGET_HAS_SHAPE_MASK (widget))
3905 gtk_widget_shape_combine_region (widget, NULL);
3907 if (g_object_get_qdata (G_OBJECT (widget), quark_input_shape_info))
3908 gtk_widget_input_shape_combine_region (widget, NULL);
3910 if (gtk_widget_get_realized (widget))
3912 g_object_ref (widget);
3913 _gtk_tooltip_hide (widget);
3914 g_signal_emit (widget, widget_signals[UNREALIZE], 0);
3915 gtk_widget_set_realized (widget, FALSE);
3916 gtk_widget_set_mapped (widget, FALSE);
3917 g_object_unref (widget);
3921 /*****************************************
3923 *****************************************/
3926 * gtk_widget_queue_draw_area:
3927 * @widget: a #GtkWidget
3928 * @x: x coordinate of upper-left corner of rectangle to redraw
3929 * @y: y coordinate of upper-left corner of rectangle to redraw
3930 * @width: width of region to draw
3931 * @height: height of region to draw
3933 * Invalidates the rectangular area of @widget defined by @x, @y,
3934 * @width and @height by calling gdk_window_invalidate_rect() on the
3935 * widget's window and all its child windows. Once the main loop
3936 * becomes idle (after the current batch of events has been processed,
3937 * roughly), the window will receive expose events for the union of
3938 * all regions that have been invalidated.
3940 * Normally you would only use this function in widget
3941 * implementations. You might also use it, or
3942 * gdk_window_invalidate_rect() directly, to schedule a redraw of a
3943 * #GtkDrawingArea or some portion thereof.
3945 * Frequently you can just call gdk_window_invalidate_rect() or
3946 * gdk_window_invalidate_region() instead of this function. Those
3947 * functions will invalidate only a single window, instead of the
3948 * widget and all its children.
3950 * The advantage of adding to the invalidated region compared to
3951 * simply drawing immediately is efficiency; using an invalid region
3952 * ensures that you only have to redraw one time.
3955 gtk_widget_queue_draw_area (GtkWidget *widget,
3961 GtkWidgetPrivate *priv;
3962 GdkRectangle invalid_rect;
3965 g_return_if_fail (GTK_IS_WIDGET (widget));
3967 priv = widget->priv;
3969 if (!gtk_widget_get_realized (widget))
3972 /* Just return if the widget or one of its ancestors isn't mapped */
3973 for (w = widget; w != NULL; w = w->priv->parent)
3974 if (!gtk_widget_get_mapped (w))
3977 /* Find the correct widget */
3979 if (gtk_widget_get_has_window (widget))
3983 /* Translate widget relative to window-relative */
3985 gint wx, wy, wwidth, wheight;
3987 gdk_window_get_position (priv->window, &wx, &wy);
3988 x -= wx - priv->allocation.x;
3989 y -= wy - priv->allocation.y;
3991 wwidth = gdk_window_get_width (priv->window);
3992 wheight = gdk_window_get_height (priv->window);
3994 if (x + width <= 0 || y + height <= 0 ||
3995 x >= wwidth || y >= wheight)
4006 if (x + width > wwidth)
4008 if (y + height > wheight)
4009 height = wheight - y;
4015 invalid_rect.width = width;
4016 invalid_rect.height = height;
4018 gdk_window_invalidate_rect (priv->window, &invalid_rect, TRUE);
4022 * gtk_widget_queue_draw:
4023 * @widget: a #GtkWidget
4025 * Equivalent to calling gtk_widget_queue_draw_area() for the
4026 * entire area of a widget.
4029 gtk_widget_queue_draw (GtkWidget *widget)
4033 g_return_if_fail (GTK_IS_WIDGET (widget));
4035 gtk_widget_get_allocation (widget, &rect);
4037 if (!gtk_widget_get_has_window (widget))
4038 gtk_widget_queue_draw_area (widget,
4039 rect.x, rect.y, rect.width, rect.height);
4041 gtk_widget_queue_draw_area (widget,
4042 0, 0, rect.width, rect.height);
4046 * gtk_widget_queue_resize:
4047 * @widget: a #GtkWidget
4049 * This function is only for use in widget implementations.
4050 * Flags a widget to have its size renegotiated; should
4051 * be called when a widget for some reason has a new size request.
4052 * For example, when you change the text in a #GtkLabel, #GtkLabel
4053 * queues a resize to ensure there's enough space for the new text.
4056 gtk_widget_queue_resize (GtkWidget *widget)
4058 g_return_if_fail (GTK_IS_WIDGET (widget));
4060 if (gtk_widget_get_realized (widget))
4061 gtk_widget_queue_shallow_draw (widget);
4063 _gtk_size_group_queue_resize (widget);
4067 * gtk_widget_queue_resize_no_redraw:
4068 * @widget: a #GtkWidget
4070 * This function works like gtk_widget_queue_resize(),
4071 * except that the widget is not invalidated.
4076 gtk_widget_queue_resize_no_redraw (GtkWidget *widget)
4078 g_return_if_fail (GTK_IS_WIDGET (widget));
4080 _gtk_size_group_queue_resize (widget);
4084 * gtk_widget_size_request:
4085 * @widget: a #GtkWidget
4086 * @requisition: (out): a #GtkRequisition to be filled in
4088 * This function is typically used when implementing a #GtkContainer
4089 * subclass. Obtains the preferred size of a widget. The container
4090 * uses this information to arrange its child widgets and decide what
4091 * size allocations to give them with gtk_widget_size_allocate().
4093 * You can also call this function from an application, with some
4094 * caveats. Most notably, getting a size request requires the widget
4095 * to be associated with a screen, because font information may be
4096 * needed. Multihead-aware applications should keep this in mind.
4098 * Also remember that the size request is not necessarily the size
4099 * a widget will actually be allocated.
4101 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4104 gtk_widget_size_request (GtkWidget *widget,
4105 GtkRequisition *requisition)
4107 g_return_if_fail (GTK_IS_WIDGET (widget));
4109 gtk_widget_get_preferred_size (widget, requisition, NULL);
4113 * gtk_widget_get_child_requisition:
4114 * @widget: a #GtkWidget
4115 * @requisition: (out): a #GtkRequisition to be filled in
4117 * This function is only for use in widget implementations. Obtains
4118 * @widget->requisition, unless someone has forced a particular
4119 * geometry on the widget (e.g. with gtk_widget_set_size_request()),
4120 * in which case it returns that geometry instead of the widget's
4123 * This function differs from gtk_widget_size_request() in that
4124 * it retrieves the last size request value from @widget->requisition,
4125 * while gtk_widget_size_request() actually calls the "size_request" method
4126 * on @widget to compute the size request and fill in @widget->requisition,
4127 * and only then returns @widget->requisition.
4129 * Because this function does not call the "size_request" method, it
4130 * can only be used when you know that @widget->requisition is
4131 * up-to-date, that is, gtk_widget_size_request() has been called
4132 * since the last time a resize was queued. In general, only container
4133 * implementations have this information; applications should use
4134 * gtk_widget_size_request().
4137 * Deprecated: 3.0: Use gtk_widget_get_preferred_size() instead.
4140 gtk_widget_get_child_requisition (GtkWidget *widget,
4141 GtkRequisition *requisition)
4143 gtk_widget_get_preferred_size (widget, requisition, NULL);
4147 invalidate_predicate (GdkWindow *window,
4152 gdk_window_get_user_data (window, &user_data);
4154 return (user_data == data);
4157 /* Invalidate @region in widget->window and all children
4158 * of widget->window owned by widget. @region is in the
4159 * same coordinates as widget->allocation and will be
4160 * modified by this call.
4163 gtk_widget_invalidate_widget_windows (GtkWidget *widget,
4164 cairo_region_t *region)
4166 GtkWidgetPrivate *priv = widget->priv;
4168 if (!gtk_widget_get_realized (widget))
4171 if (gtk_widget_get_has_window (widget) && priv->parent)
4175 gdk_window_get_position (priv->window, &x, &y);
4176 cairo_region_translate (region, -x, -y);
4179 gdk_window_invalidate_maybe_recurse (priv->window, region,
4180 invalidate_predicate, widget);
4184 * gtk_widget_queue_shallow_draw:
4185 * @widget: a #GtkWidget
4187 * Like gtk_widget_queue_draw(), but only windows owned
4188 * by @widget are invalidated.
4191 gtk_widget_queue_shallow_draw (GtkWidget *widget)
4194 cairo_region_t *region;
4196 if (!gtk_widget_get_realized (widget))
4199 gtk_widget_get_allocation (widget, &rect);
4201 region = cairo_region_create_rectangle (&rect);
4202 gtk_widget_invalidate_widget_windows (widget, region);
4203 cairo_region_destroy (region);
4207 * gtk_widget_size_allocate:
4208 * @widget: a #GtkWidget
4209 * @allocation: (inout): position and size to be allocated to @widget
4211 * This function is only used by #GtkContainer subclasses, to assign a size
4212 * and position to their child widgets.
4214 * In this function, the allocation may be adjusted. It will be forced
4215 * to a 1x1 minimum size, and the adjust_size_allocation virtual
4216 * method on the child will be used to adjust the allocation. Standard
4217 * adjustments include removing the widget's margins, and applying the
4218 * widget's #GtkWidget:halign and #GtkWidget:valign properties.
4221 gtk_widget_size_allocate (GtkWidget *widget,
4222 GtkAllocation *allocation)
4224 GtkWidgetPrivate *priv;
4225 GdkRectangle real_allocation;
4226 GdkRectangle old_allocation;
4227 GdkRectangle adjusted_allocation;
4228 gboolean alloc_needed;
4229 gboolean size_changed;
4230 gboolean position_changed;
4232 priv = widget->priv;
4234 g_return_if_fail (GTK_IS_WIDGET (widget));
4236 #ifdef G_ENABLE_DEBUG
4237 if (gtk_get_debug_flags () & GTK_DEBUG_GEOMETRY)
4248 parent = gtk_widget_get_parent (parent);
4251 name = g_type_name (G_OBJECT_TYPE (G_OBJECT (widget)));
4252 g_print ("gtk_widget_size_allocate: %*s%s %d %d\n",
4253 2 * depth, " ", name,
4254 allocation->width, allocation->height);
4256 #endif /* G_ENABLE_DEBUG */
4258 alloc_needed = GTK_WIDGET_ALLOC_NEEDED (widget);
4259 if (!GTK_WIDGET_WIDTH_REQUEST_NEEDED (widget) &&
4260 !GTK_WIDGET_HEIGHT_REQUEST_NEEDED (widget)) /* Preserve request/allocate ordering */
4261 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ALLOC_NEEDED);
4263 old_allocation = priv->allocation;
4264 real_allocation = *allocation;
4266 adjusted_allocation = real_allocation;
4267 GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget, &adjusted_allocation);
4269 if (adjusted_allocation.x < real_allocation.x ||
4270 adjusted_allocation.y < real_allocation.y ||
4271 (adjusted_allocation.x + adjusted_allocation.width) >
4272 (real_allocation.x + real_allocation.width) ||
4273 (adjusted_allocation.y + adjusted_allocation.height >
4274 real_allocation.y + real_allocation.height))
4276 g_warning ("%s %p attempted to adjust its size allocation from %d,%d %dx%d to %d,%d %dx%d. adjust_size_allocation must keep allocation inside original bounds",
4277 G_OBJECT_TYPE_NAME (widget), widget,
4278 real_allocation.x, real_allocation.y, real_allocation.width, real_allocation.height,
4279 adjusted_allocation.x, adjusted_allocation.y, adjusted_allocation.width, adjusted_allocation.height);
4280 adjusted_allocation = real_allocation; /* veto it */
4284 real_allocation = adjusted_allocation;
4287 if (real_allocation.width < 0 || real_allocation.height < 0)
4289 g_warning ("gtk_widget_size_allocate(): attempt to allocate widget with width %d and height %d",
4290 real_allocation.width,
4291 real_allocation.height);
4294 real_allocation.width = MAX (real_allocation.width, 1);
4295 real_allocation.height = MAX (real_allocation.height, 1);
4297 size_changed = (old_allocation.width != real_allocation.width ||
4298 old_allocation.height != real_allocation.height);
4299 position_changed = (old_allocation.x != real_allocation.x ||
4300 old_allocation.y != real_allocation.y);
4302 if (!alloc_needed && !size_changed && !position_changed)
4305 g_signal_emit (widget, widget_signals[SIZE_ALLOCATE], 0, &real_allocation);
4307 if (gtk_widget_get_mapped (widget))
4309 if (!gtk_widget_get_has_window (widget) && GTK_WIDGET_REDRAW_ON_ALLOC (widget) && position_changed)
4311 /* Invalidate union(old_allaction,priv->allocation) in priv->window
4313 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4314 cairo_region_union_rectangle (invalidate, &old_allocation);
4316 gdk_window_invalidate_region (priv->window, invalidate, FALSE);
4317 cairo_region_destroy (invalidate);
4322 if (GTK_WIDGET_REDRAW_ON_ALLOC (widget))
4324 /* Invalidate union(old_allaction,priv->allocation) in priv->window and descendents owned by widget
4326 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->allocation);
4327 cairo_region_union_rectangle (invalidate, &old_allocation);
4329 gtk_widget_invalidate_widget_windows (widget, invalidate);
4330 cairo_region_destroy (invalidate);
4335 if ((size_changed || position_changed) && priv->parent &&
4336 gtk_widget_get_realized (priv->parent) && _gtk_container_get_reallocate_redraws (GTK_CONTAINER (priv->parent)))
4338 cairo_region_t *invalidate = cairo_region_create_rectangle (&priv->parent->priv->allocation);
4339 gtk_widget_invalidate_widget_windows (priv->parent, invalidate);
4340 cairo_region_destroy (invalidate);
4345 * gtk_widget_common_ancestor:
4346 * @widget_a: a #GtkWidget
4347 * @widget_b: a #GtkWidget
4349 * Find the common ancestor of @widget_a and @widget_b that
4350 * is closest to the two widgets.
4352 * Return value: the closest common ancestor of @widget_a and
4353 * @widget_b or %NULL if @widget_a and @widget_b do not
4354 * share a common ancestor.
4357 gtk_widget_common_ancestor (GtkWidget *widget_a,
4358 GtkWidget *widget_b)
4360 GtkWidget *parent_a;
4361 GtkWidget *parent_b;
4365 parent_a = widget_a;
4366 while (parent_a->priv->parent)
4368 parent_a = parent_a->priv->parent;
4372 parent_b = widget_b;
4373 while (parent_b->priv->parent)
4375 parent_b = parent_b->priv->parent;
4379 if (parent_a != parent_b)
4382 while (depth_a > depth_b)
4384 widget_a = widget_a->priv->parent;
4388 while (depth_b > depth_a)
4390 widget_b = widget_b->priv->parent;
4394 while (widget_a != widget_b)
4396 widget_a = widget_a->priv->parent;
4397 widget_b = widget_b->priv->parent;
4404 * gtk_widget_translate_coordinates:
4405 * @src_widget: a #GtkWidget
4406 * @dest_widget: a #GtkWidget
4407 * @src_x: X position relative to @src_widget
4408 * @src_y: Y position relative to @src_widget
4409 * @dest_x: (out): location to store X position relative to @dest_widget
4410 * @dest_y: (out): location to store Y position relative to @dest_widget
4412 * Translate coordinates relative to @src_widget's allocation to coordinates
4413 * relative to @dest_widget's allocations. In order to perform this
4414 * operation, both widgets must be realized, and must share a common
4417 * Return value: %FALSE if either widget was not realized, or there
4418 * was no common ancestor. In this case, nothing is stored in
4419 * *@dest_x and *@dest_y. Otherwise %TRUE.
4422 gtk_widget_translate_coordinates (GtkWidget *src_widget,
4423 GtkWidget *dest_widget,
4429 GtkWidgetPrivate *src_priv = src_widget->priv;
4430 GtkWidgetPrivate *dest_priv = dest_widget->priv;
4431 GtkWidget *ancestor;
4433 GList *dest_list = NULL;
4435 g_return_val_if_fail (GTK_IS_WIDGET (src_widget), FALSE);
4436 g_return_val_if_fail (GTK_IS_WIDGET (dest_widget), FALSE);
4438 ancestor = gtk_widget_common_ancestor (src_widget, dest_widget);
4439 if (!ancestor || !gtk_widget_get_realized (src_widget) || !gtk_widget_get_realized (dest_widget))
4442 /* Translate from allocation relative to window relative */
4443 if (gtk_widget_get_has_window (src_widget) && src_priv->parent)
4446 gdk_window_get_position (src_priv->window, &wx, &wy);
4448 src_x -= wx - src_priv->allocation.x;
4449 src_y -= wy - src_priv->allocation.y;
4453 src_x += src_priv->allocation.x;
4454 src_y += src_priv->allocation.y;
4457 /* Translate to the common ancestor */
4458 window = src_priv->window;
4459 while (window != ancestor->priv->window)
4463 gdk_window_coords_to_parent (window, src_x, src_y, &dx, &dy);
4468 window = gdk_window_get_effective_parent (window);
4470 if (!window) /* Handle GtkHandleBox */
4475 window = dest_priv->window;
4476 while (window != ancestor->priv->window)
4478 dest_list = g_list_prepend (dest_list, window);
4480 window = gdk_window_get_effective_parent (window);
4482 if (!window) /* Handle GtkHandleBox */
4484 g_list_free (dest_list);
4493 gdk_window_coords_from_parent (dest_list->data, src_x, src_y, &dx, &dy);
4498 dest_list = g_list_remove (dest_list, dest_list->data);
4501 /* Translate from window relative to allocation relative */
4502 if (gtk_widget_get_has_window (dest_widget) && dest_priv->parent)
4505 gdk_window_get_position (dest_priv->window, &wx, &wy);
4507 src_x += wx - dest_priv->allocation.x;
4508 src_y += wy - dest_priv->allocation.y;
4512 src_x -= dest_priv->allocation.x;
4513 src_y -= dest_priv->allocation.y;
4525 gtk_widget_real_size_allocate (GtkWidget *widget,
4526 GtkAllocation *allocation)
4528 GtkWidgetPrivate *priv = widget->priv;
4530 priv->allocation = *allocation;
4532 if (gtk_widget_get_realized (widget) &&
4533 gtk_widget_get_has_window (widget))
4535 gdk_window_move_resize (priv->window,
4536 allocation->x, allocation->y,
4537 allocation->width, allocation->height);
4542 get_span_inside_border (GtkWidget *widget,
4546 int allocated_outside_size,
4547 int natural_inside_size,
4548 int *coord_inside_p,
4551 int inside_allocated;
4555 inside_allocated = allocated_outside_size - start_pad - end_pad;
4557 content_size = natural_inside_size;
4558 if (content_size > inside_allocated)
4560 /* didn't get full natural size */
4561 content_size = inside_allocated;
4564 coord = size = 0; /* silence compiler */
4567 case GTK_ALIGN_FILL:
4569 size = inside_allocated;
4571 case GTK_ALIGN_START:
4573 size = content_size;
4576 coord = allocated_outside_size - end_pad - content_size;
4577 size = content_size;
4579 case GTK_ALIGN_CENTER:
4580 coord = start_pad + (inside_allocated - content_size) / 2;
4581 size = content_size;
4586 *coord_inside_p = coord;
4589 *size_inside_p = size;
4593 get_span_inside_border_horizontal (GtkWidget *widget,
4594 const GtkWidgetAuxInfo *aux_info,
4595 int allocated_outside_width,
4596 int natural_inside_width,
4598 int *width_inside_p)
4600 get_span_inside_border (widget,
4602 aux_info->margin.left,
4603 aux_info->margin.right,
4604 allocated_outside_width,
4605 natural_inside_width,
4611 get_span_inside_border_vertical (GtkWidget *widget,
4612 const GtkWidgetAuxInfo *aux_info,
4613 int allocated_outside_height,
4614 int natural_inside_height,
4616 int *height_inside_p)
4618 get_span_inside_border (widget,
4620 aux_info->margin.top,
4621 aux_info->margin.bottom,
4622 allocated_outside_height,
4623 natural_inside_height,
4629 gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
4630 GtkAllocation *allocation)
4632 const GtkWidgetAuxInfo *aux_info;
4633 GtkRequisition min, natural;
4636 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
4638 gtk_widget_get_preferred_size (widget, &min, &natural);
4640 get_span_inside_border_horizontal (widget,
4645 get_span_inside_border_vertical (widget,
4653 allocation->width = w;
4654 allocation->height = h;
4658 gtk_widget_real_can_activate_accel (GtkWidget *widget,
4661 GtkWidgetPrivate *priv = widget->priv;
4663 /* widgets must be onscreen for accels to take effect */
4664 return gtk_widget_is_sensitive (widget) &&
4665 gtk_widget_is_drawable (widget) &&
4666 gdk_window_is_viewable (priv->window);
4670 * gtk_widget_can_activate_accel:
4671 * @widget: a #GtkWidget
4672 * @signal_id: the ID of a signal installed on @widget
4674 * Determines whether an accelerator that activates the signal
4675 * identified by @signal_id can currently be activated.
4676 * This is done by emitting the #GtkWidget::can-activate-accel
4677 * signal on @widget; if the signal isn't overridden by a
4678 * handler or in a derived widget, then the default check is
4679 * that the widget must be sensitive, and the widget and all
4680 * its ancestors mapped.
4682 * Return value: %TRUE if the accelerator can be activated.
4687 gtk_widget_can_activate_accel (GtkWidget *widget,
4690 gboolean can_activate = FALSE;
4691 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4692 g_signal_emit (widget, widget_signals[CAN_ACTIVATE_ACCEL], 0, signal_id, &can_activate);
4693 return can_activate;
4702 closure_accel_activate (GClosure *closure,
4703 GValue *return_value,
4704 guint n_param_values,
4705 const GValue *param_values,
4706 gpointer invocation_hint,
4707 gpointer marshal_data)
4709 AccelClosure *aclosure = (AccelClosure*) closure;
4710 gboolean can_activate = gtk_widget_can_activate_accel (closure->data, aclosure->signal_id);
4713 g_signal_emit (closure->data, aclosure->signal_id, 0);
4715 /* whether accelerator was handled */
4716 g_value_set_boolean (return_value, can_activate);
4720 closures_destroy (gpointer data)
4722 GSList *slist, *closures = data;
4724 for (slist = closures; slist; slist = slist->next)
4726 g_closure_invalidate (slist->data);
4727 g_closure_unref (slist->data);
4729 g_slist_free (closures);
4733 widget_new_accel_closure (GtkWidget *widget,
4736 AccelClosure *aclosure;
4737 GClosure *closure = NULL;
4738 GSList *slist, *closures;
4740 closures = g_object_steal_qdata (G_OBJECT (widget), quark_accel_closures);
4741 for (slist = closures; slist; slist = slist->next)
4742 if (!gtk_accel_group_from_accel_closure (slist->data))
4744 /* reuse this closure */
4745 closure = slist->data;
4750 closure = g_closure_new_object (sizeof (AccelClosure), G_OBJECT (widget));
4751 closures = g_slist_prepend (closures, g_closure_ref (closure));
4752 g_closure_sink (closure);
4753 g_closure_set_marshal (closure, closure_accel_activate);
4755 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_closures, closures, closures_destroy);
4757 aclosure = (AccelClosure*) closure;
4758 g_assert (closure->data == widget);
4759 g_assert (closure->marshal == closure_accel_activate);
4760 aclosure->signal_id = signal_id;
4766 * gtk_widget_add_accelerator
4767 * @widget: widget to install an accelerator on
4768 * @accel_signal: widget signal to emit on accelerator activation
4769 * @accel_group: accel group for this widget, added to its toplevel
4770 * @accel_key: GDK keyval of the accelerator
4771 * @accel_mods: modifier key combination of the accelerator
4772 * @accel_flags: flag accelerators, e.g. %GTK_ACCEL_VISIBLE
4774 * Installs an accelerator for this @widget in @accel_group that causes
4775 * @accel_signal to be emitted if the accelerator is activated.
4776 * The @accel_group needs to be added to the widget's toplevel via
4777 * gtk_window_add_accel_group(), and the signal must be of type %G_RUN_ACTION.
4778 * Accelerators added through this function are not user changeable during
4779 * runtime. If you want to support accelerators that can be changed by the
4780 * user, use gtk_accel_map_add_entry() and gtk_widget_set_accel_path() or
4781 * gtk_menu_item_set_accel_path() instead.
4784 gtk_widget_add_accelerator (GtkWidget *widget,
4785 const gchar *accel_signal,
4786 GtkAccelGroup *accel_group,
4788 GdkModifierType accel_mods,
4789 GtkAccelFlags accel_flags)
4794 g_return_if_fail (GTK_IS_WIDGET (widget));
4795 g_return_if_fail (accel_signal != NULL);
4796 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4798 g_signal_query (g_signal_lookup (accel_signal, G_OBJECT_TYPE (widget)), &query);
4799 if (!query.signal_id ||
4800 !(query.signal_flags & G_SIGNAL_ACTION) ||
4801 query.return_type != G_TYPE_NONE ||
4804 /* hmm, should be elaborate enough */
4805 g_warning (G_STRLOC ": widget `%s' has no activatable signal \"%s\" without arguments",
4806 G_OBJECT_TYPE_NAME (widget), accel_signal);
4810 closure = widget_new_accel_closure (widget, query.signal_id);
4812 g_object_ref (widget);
4814 /* install the accelerator. since we don't map this onto an accel_path,
4815 * the accelerator will automatically be locked.
4817 gtk_accel_group_connect (accel_group,
4820 accel_flags | GTK_ACCEL_LOCKED,
4823 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4825 g_object_unref (widget);
4829 * gtk_widget_remove_accelerator:
4830 * @widget: widget to install an accelerator on
4831 * @accel_group: accel group for this widget
4832 * @accel_key: GDK keyval of the accelerator
4833 * @accel_mods: modifier key combination of the accelerator
4834 * @returns: whether an accelerator was installed and could be removed
4836 * Removes an accelerator from @widget, previously installed with
4837 * gtk_widget_add_accelerator().
4840 gtk_widget_remove_accelerator (GtkWidget *widget,
4841 GtkAccelGroup *accel_group,
4843 GdkModifierType accel_mods)
4845 GtkAccelGroupEntry *ag_entry;
4846 GList *slist, *clist;
4849 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
4850 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
4852 ag_entry = gtk_accel_group_query (accel_group, accel_key, accel_mods, &n);
4853 clist = gtk_widget_list_accel_closures (widget);
4854 for (slist = clist; slist; slist = slist->next)
4858 for (i = 0; i < n; i++)
4859 if (slist->data == (gpointer) ag_entry[i].closure)
4861 gboolean is_removed = gtk_accel_group_disconnect (accel_group, slist->data);
4863 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4865 g_list_free (clist);
4870 g_list_free (clist);
4872 g_warning (G_STRLOC ": no accelerator (%u,%u) installed in accel group (%p) for %s (%p)",
4873 accel_key, accel_mods, accel_group,
4874 G_OBJECT_TYPE_NAME (widget), widget);
4880 * gtk_widget_list_accel_closures:
4881 * @widget: widget to list accelerator closures for
4883 * Lists the closures used by @widget for accelerator group connections
4884 * with gtk_accel_group_connect_by_path() or gtk_accel_group_connect().
4885 * The closures can be used to monitor accelerator changes on @widget,
4886 * by connecting to the @GtkAccelGroup::accel-changed signal of the
4887 * #GtkAccelGroup of a closure which can be found out with
4888 * gtk_accel_group_from_accel_closure().
4890 * Return value: (transfer container) (element-type GClosure):
4891 * a newly allocated #GList of closures
4894 gtk_widget_list_accel_closures (GtkWidget *widget)
4897 GList *clist = NULL;
4899 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4901 for (slist = g_object_get_qdata (G_OBJECT (widget), quark_accel_closures); slist; slist = slist->next)
4902 if (gtk_accel_group_from_accel_closure (slist->data))
4903 clist = g_list_prepend (clist, slist->data);
4909 GtkAccelGroup *accel_group;
4914 destroy_accel_path (gpointer data)
4916 AccelPath *apath = data;
4918 gtk_accel_group_disconnect (apath->accel_group, apath->closure);
4920 /* closures_destroy takes care of unrefing the closure */
4921 g_object_unref (apath->accel_group);
4923 g_slice_free (AccelPath, apath);
4928 * gtk_widget_set_accel_path:
4929 * @widget: a #GtkWidget
4930 * @accel_path: (allow-none): path used to look up the accelerator
4931 * @accel_group: (allow-none): a #GtkAccelGroup.
4933 * Given an accelerator group, @accel_group, and an accelerator path,
4934 * @accel_path, sets up an accelerator in @accel_group so whenever the
4935 * key binding that is defined for @accel_path is pressed, @widget
4936 * will be activated. This removes any accelerators (for any
4937 * accelerator group) installed by previous calls to
4938 * gtk_widget_set_accel_path(). Associating accelerators with
4939 * paths allows them to be modified by the user and the modifications
4940 * to be saved for future use. (See gtk_accel_map_save().)
4942 * This function is a low level function that would most likely
4943 * be used by a menu creation system like #GtkUIManager. If you
4944 * use #GtkUIManager, setting up accelerator paths will be done
4947 * Even when you you aren't using #GtkUIManager, if you only want to
4948 * set up accelerators on menu items gtk_menu_item_set_accel_path()
4949 * provides a somewhat more convenient interface.
4951 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
4952 * pass a static string, you can save some memory by interning it first with
4953 * g_intern_static_string().
4956 gtk_widget_set_accel_path (GtkWidget *widget,
4957 const gchar *accel_path,
4958 GtkAccelGroup *accel_group)
4962 g_return_if_fail (GTK_IS_WIDGET (widget));
4963 g_return_if_fail (GTK_WIDGET_GET_CLASS (widget)->activate_signal != 0);
4967 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
4968 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
4970 gtk_accel_map_add_entry (accel_path, 0, 0);
4971 apath = g_slice_new (AccelPath);
4972 apath->accel_group = g_object_ref (accel_group);
4973 apath->path_quark = g_quark_from_string (accel_path);
4974 apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
4979 /* also removes possible old settings */
4980 g_object_set_qdata_full (G_OBJECT (widget), quark_accel_path, apath, destroy_accel_path);
4983 gtk_accel_group_connect_by_path (apath->accel_group, g_quark_to_string (apath->path_quark), apath->closure);
4985 g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
4989 _gtk_widget_get_accel_path (GtkWidget *widget,
4994 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
4996 apath = g_object_get_qdata (G_OBJECT (widget), quark_accel_path);
4998 *locked = apath ? gtk_accel_group_get_is_locked (apath->accel_group) : TRUE;
4999 return apath ? g_quark_to_string (apath->path_quark) : NULL;
5003 * gtk_widget_mnemonic_activate:
5004 * @widget: a #GtkWidget
5005 * @group_cycling: %TRUE if there are other widgets with the same mnemonic
5007 * Emits the #GtkWidget::mnemonic-activate signal.
5009 * The default handler for this signal activates the @widget if
5010 * @group_cycling is %FALSE, and just grabs the focus if @group_cycling
5013 * Returns: %TRUE if the signal has been handled
5016 gtk_widget_mnemonic_activate (GtkWidget *widget,
5017 gboolean group_cycling)
5021 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5023 group_cycling = group_cycling != FALSE;
5024 if (!gtk_widget_is_sensitive (widget))
5027 g_signal_emit (widget,
5028 widget_signals[MNEMONIC_ACTIVATE],
5036 gtk_widget_real_mnemonic_activate (GtkWidget *widget,
5037 gboolean group_cycling)
5039 if (!group_cycling && GTK_WIDGET_GET_CLASS (widget)->activate_signal)
5040 gtk_widget_activate (widget);
5041 else if (gtk_widget_get_can_focus (widget))
5042 gtk_widget_grab_focus (widget);
5045 g_warning ("widget `%s' isn't suitable for mnemonic activation",
5046 G_OBJECT_TYPE_NAME (widget));
5047 gtk_widget_error_bell (widget);
5052 static const cairo_user_data_key_t event_key;
5055 _gtk_cairo_get_event (cairo_t *cr)
5057 g_return_val_if_fail (cr != NULL, NULL);
5059 return cairo_get_user_data (cr, &event_key);
5063 gtk_cairo_set_event (cairo_t *cr,
5064 GdkEventExpose *event)
5066 cairo_set_user_data (cr, &event_key, event, NULL);
5070 * gtk_cairo_should_draw_window:
5071 * @cr: a cairo context
5072 * @window: the window to check
5074 * This function is supposed to be called in GtkWidget::draw
5075 * implementations for widgets that support multiple windows.
5076 * @cr must be untransformed from invoking of the draw function.
5077 * This function will return %TRUE if the contents of the given
5078 * @window are supposed to be drawn and %FALSE otherwise. Note
5079 * that when the drawing was not initiated by the windowing
5080 * system this function will return %TRUE for all windows, so
5081 * you need to draw the bottommost window first. Also, do not
5082 * use "else if" statements to check which window should be drawn.
5084 * Returns: %TRUE if @window should be drawn
5087 gtk_cairo_should_draw_window (cairo_t *cr,
5090 GdkEventExpose *event;
5092 g_return_val_if_fail (cr != NULL, FALSE);
5093 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
5095 event = _gtk_cairo_get_event (cr);
5097 return event == NULL ||
5098 event->window == window;
5101 /* code shared by gtk_container_propagate_draw() and
5105 _gtk_widget_draw_internal (GtkWidget *widget,
5107 gboolean clip_to_size)
5109 if (!gtk_widget_is_drawable (widget))
5114 cairo_rectangle (cr,
5116 widget->priv->allocation.width,
5117 widget->priv->allocation.height);
5121 if (gdk_cairo_get_clip_rectangle (cr, NULL))
5125 g_signal_emit (widget, widget_signals[DRAW],
5133 * @widget: the widget to draw. It must be drawable (see
5134 * gtk_widget_is_drawable()) and a size must have been allocated.
5135 * @cr: a cairo context to draw to
5137 * Draws @widget to @cr. The top left corner of the widget will be
5138 * drawn to the currently set origin point of @cr.
5140 * You should pass a cairo context as @cr argument that is in an
5141 * original state. Otherwise the resulting drawing is undefined. For
5142 * example changing the operator using cairo_set_operator() or the
5143 * line width using cairo_set_line_width() might have unwanted side
5145 * You may however change the context's transform matrix - like with
5146 * cairo_scale(), cairo_translate() or cairo_set_matrix() and clip
5147 * region with cairo_clip() prior to calling this function. Also, it
5148 * is fine to modify the context with cairo_save() and
5149 * cairo_push_group() prior to calling this function.
5151 * <note><para>Special purpose widgets may contain special code for
5152 * rendering to the screen and might appear differently on screen
5153 * and when rendered using gtk_widget_draw().</para></note>
5156 gtk_widget_draw (GtkWidget *widget,
5159 GdkEventExpose *tmp_event;
5161 g_return_if_fail (GTK_IS_WIDGET (widget));
5162 g_return_if_fail (!GTK_WIDGET_ALLOC_NEEDED (widget));
5163 g_return_if_fail (cr != NULL);
5166 /* We have to reset the event here so that draw functions can call
5167 * gtk_widget_draw() on random other widgets and get the desired
5168 * effect: Drawing all contents, not just the current window.
5170 tmp_event = _gtk_cairo_get_event (cr);
5171 gtk_cairo_set_event (cr, NULL);
5173 _gtk_widget_draw_internal (widget, cr, TRUE);
5175 gtk_cairo_set_event (cr, tmp_event);
5180 gtk_widget_real_key_press_event (GtkWidget *widget,
5183 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5187 gtk_widget_real_key_release_event (GtkWidget *widget,
5190 return gtk_bindings_activate_event (GTK_OBJECT (widget), event);
5194 gtk_widget_real_focus_in_event (GtkWidget *widget,
5195 GdkEventFocus *event)
5197 gtk_widget_queue_shallow_draw (widget);
5203 gtk_widget_real_focus_out_event (GtkWidget *widget,
5204 GdkEventFocus *event)
5206 gtk_widget_queue_shallow_draw (widget);
5211 #define WIDGET_REALIZED_FOR_EVENT(widget, event) \
5212 (event->type == GDK_FOCUS_CHANGE || gtk_widget_get_realized(widget))
5216 * @widget: a #GtkWidget
5217 * @event: a #GdkEvent
5219 * Rarely-used function. This function is used to emit
5220 * the event signals on a widget (those signals should never
5221 * be emitted without using this function to do so).
5222 * If you want to synthesize an event though, don't use this function;
5223 * instead, use gtk_main_do_event() so the event will behave as if
5224 * it were in the event queue. Don't synthesize expose events; instead,
5225 * use gdk_window_invalidate_rect() to invalidate a region of the
5228 * Return value: return from the event signal emission (%TRUE if
5229 * the event was handled)
5232 gtk_widget_event (GtkWidget *widget,
5235 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5236 g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
5238 if (event->type == GDK_EXPOSE)
5240 g_warning ("Events of type GDK_EXPOSE cannot be synthesized. To get "
5241 "the same effect, call gdk_window_invalidate_rect/region(), "
5242 "followed by gdk_window_process_updates().");
5246 return gtk_widget_event_internal (widget, event);
5249 /* Returns TRUE if a translation should be done */
5251 gtk_widget_get_translation_to_window (GtkWidget *widget,
5256 GdkWindow *w, *widget_window;
5258 if (!gtk_widget_get_has_window (widget))
5260 *x = -widget->priv->allocation.x;
5261 *y = -widget->priv->allocation.y;
5269 widget_window = gtk_widget_get_window (widget);
5271 for (w = window; w && w != widget_window; w = gdk_window_get_parent (w))
5274 gdk_window_get_position (w, &wx, &wy);
5291 * gtk_cairo_transform_to_window:
5292 * @cr: the cairo context to transform
5293 * @widget: the widget the context is currently centered for
5294 * @window: the window to transform the context to
5296 * Transforms the given cairo context @cr that from @widget-relative
5297 * coordinates to @window-relative coordinates.
5298 * If the @widget's window is not an ancestor of @window, no
5299 * modification will be applied.
5301 * This is the inverse to the transformation GTK applies when
5302 * preparing an expose event to be emitted with the GtkWidget::draw
5303 * signal. It is intended to help porting multiwindow widgets from
5304 * GTK 2 to the rendering architecture of GTK 3.
5307 gtk_cairo_transform_to_window (cairo_t *cr,
5313 g_return_if_fail (cr != NULL);
5314 g_return_if_fail (GTK_IS_WIDGET (widget));
5315 g_return_if_fail (GDK_IS_WINDOW (window));
5317 if (gtk_widget_get_translation_to_window (widget, window, &x, &y))
5318 cairo_translate (cr, x, y);
5322 * gtk_widget_send_expose:
5323 * @widget: a #GtkWidget
5324 * @event: a expose #GdkEvent
5326 * Very rarely-used function. This function is used to emit
5327 * an expose event signals on a widget. This function is not
5328 * normally used directly. The only time it is used is when
5329 * propagating an expose event to a child %NO_WINDOW widget, and
5330 * that is normally done using gtk_container_propagate_expose().
5332 * If you want to force an area of a window to be redrawn,
5333 * use gdk_window_invalidate_rect() or gdk_window_invalidate_region().
5334 * To cause the redraw to be done immediately, follow that call
5335 * with a call to gdk_window_process_updates().
5337 * Return value: return from the event signal emission (%TRUE if
5338 * the event was handled)
5341 gtk_widget_send_expose (GtkWidget *widget,
5344 gboolean result = FALSE;
5349 g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
5350 g_return_val_if_fail (gtk_widget_get_realized (widget), TRUE);
5351 g_return_val_if_fail (event != NULL, TRUE);
5352 g_return_val_if_fail (event->type == GDK_EXPOSE, TRUE);
5354 cr = gdk_cairo_create (event->expose.window);
5355 gtk_cairo_set_event (cr, &event->expose);
5357 gdk_cairo_region (cr, event->expose.region);
5360 do_clip = gtk_widget_get_translation_to_window (widget,
5361 event->expose.window,
5363 cairo_translate (cr, -x, -y);
5365 _gtk_widget_draw_internal (widget, cr, do_clip);
5367 /* unset here, so if someone keeps a reference to cr we
5368 * don't leak the window. */
5369 gtk_cairo_set_event (cr, NULL);
5376 event_window_is_still_viewable (GdkEvent *event)
5378 /* Check that we think the event's window is viewable before
5379 * delivering the event, to prevent suprises. We do this here
5380 * at the last moment, since the event may have been queued
5381 * up behind other events, held over a recursive main loop, etc.
5383 switch (event->type)
5386 case GDK_MOTION_NOTIFY:
5387 case GDK_BUTTON_PRESS:
5388 case GDK_2BUTTON_PRESS:
5389 case GDK_3BUTTON_PRESS:
5391 case GDK_ENTER_NOTIFY:
5392 case GDK_PROXIMITY_IN:
5394 return event->any.window && gdk_window_is_viewable (event->any.window);
5397 /* The following events are the second half of paired events;
5398 * we always deliver them to deal with widgets that clean up
5399 * on the second half.
5401 case GDK_BUTTON_RELEASE:
5402 case GDK_KEY_RELEASE:
5403 case GDK_LEAVE_NOTIFY:
5404 case GDK_PROXIMITY_OUT:
5408 /* Remaining events would make sense on an not-viewable window,
5409 * or don't have an associated window.
5416 gtk_widget_event_internal (GtkWidget *widget,
5419 gboolean return_val = FALSE;
5421 /* We check only once for is-still-visible; if someone
5422 * hides the window in on of the signals on the widget,
5423 * they are responsible for returning TRUE to terminate
5426 if (!event_window_is_still_viewable (event))
5429 g_object_ref (widget);
5431 g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
5432 return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
5437 switch (event->type)
5442 case GDK_BUTTON_PRESS:
5443 case GDK_2BUTTON_PRESS:
5444 case GDK_3BUTTON_PRESS:
5445 signal_num = BUTTON_PRESS_EVENT;
5448 signal_num = SCROLL_EVENT;
5450 case GDK_BUTTON_RELEASE:
5451 signal_num = BUTTON_RELEASE_EVENT;
5453 case GDK_MOTION_NOTIFY:
5454 signal_num = MOTION_NOTIFY_EVENT;
5457 signal_num = DELETE_EVENT;
5460 signal_num = DESTROY_EVENT;
5461 _gtk_tooltip_hide (widget);
5464 signal_num = KEY_PRESS_EVENT;
5466 case GDK_KEY_RELEASE:
5467 signal_num = KEY_RELEASE_EVENT;
5469 case GDK_ENTER_NOTIFY:
5470 signal_num = ENTER_NOTIFY_EVENT;
5472 case GDK_LEAVE_NOTIFY:
5473 signal_num = LEAVE_NOTIFY_EVENT;
5475 case GDK_FOCUS_CHANGE:
5476 signal_num = event->focus_change.in ? FOCUS_IN_EVENT : FOCUS_OUT_EVENT;
5477 if (event->focus_change.in)
5478 _gtk_tooltip_focus_in (widget);
5480 _gtk_tooltip_focus_out (widget);
5483 signal_num = CONFIGURE_EVENT;
5486 signal_num = MAP_EVENT;
5489 signal_num = UNMAP_EVENT;
5491 case GDK_WINDOW_STATE:
5492 signal_num = WINDOW_STATE_EVENT;
5494 case GDK_PROPERTY_NOTIFY:
5495 signal_num = PROPERTY_NOTIFY_EVENT;
5497 case GDK_SELECTION_CLEAR:
5498 signal_num = SELECTION_CLEAR_EVENT;
5500 case GDK_SELECTION_REQUEST:
5501 signal_num = SELECTION_REQUEST_EVENT;
5503 case GDK_SELECTION_NOTIFY:
5504 signal_num = SELECTION_NOTIFY_EVENT;
5506 case GDK_PROXIMITY_IN:
5507 signal_num = PROXIMITY_IN_EVENT;
5509 case GDK_PROXIMITY_OUT:
5510 signal_num = PROXIMITY_OUT_EVENT;
5513 signal_num = NO_EXPOSE_EVENT;
5515 case GDK_CLIENT_EVENT:
5516 signal_num = CLIENT_EVENT;
5519 signal_num = EXPOSE_EVENT;
5521 case GDK_VISIBILITY_NOTIFY:
5522 signal_num = VISIBILITY_NOTIFY_EVENT;
5524 case GDK_GRAB_BROKEN:
5525 signal_num = GRAB_BROKEN;
5528 signal_num = DAMAGE_EVENT;
5531 g_warning ("gtk_widget_event(): unhandled event type: %d", event->type);
5535 if (signal_num != -1)
5536 g_signal_emit (widget, widget_signals[signal_num], 0, event, &return_val);
5538 if (WIDGET_REALIZED_FOR_EVENT (widget, event))
5539 g_signal_emit (widget, widget_signals[EVENT_AFTER], 0, event);
5543 g_object_unref (widget);
5549 * gtk_widget_activate:
5550 * @widget: a #GtkWidget that's activatable
5552 * For widgets that can be "activated" (buttons, menu items, etc.)
5553 * this function activates them. Activation is what happens when you
5554 * press Enter on a widget during key navigation. If @widget isn't
5555 * activatable, the function returns %FALSE.
5557 * Return value: %TRUE if the widget was activatable
5560 gtk_widget_activate (GtkWidget *widget)
5562 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5564 if (WIDGET_CLASS (widget)->activate_signal)
5566 /* FIXME: we should eventually check the signals signature here */
5567 g_signal_emit (widget, WIDGET_CLASS (widget)->activate_signal, 0);
5576 * gtk_widget_set_scroll_adjustments:
5577 * @widget: a #GtkWidget
5578 * @hadjustment: (allow-none): an adjustment for horizontal scrolling, or %NULL
5579 * @vadjustment: (allow-none): an adjustment for vertical scrolling, or %NULL
5581 * For widgets that support scrolling, sets the scroll adjustments and
5582 * returns %TRUE. For widgets that don't support scrolling, does
5583 * nothing and returns %FALSE. Widgets that don't support scrolling
5584 * can be scrolled by placing them in a #GtkViewport, which does
5585 * support scrolling.
5587 * Return value: %TRUE if the widget supports scrolling
5590 gtk_widget_set_scroll_adjustments (GtkWidget *widget,
5591 GtkAdjustment *hadjustment,
5592 GtkAdjustment *vadjustment)
5597 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5600 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadjustment), FALSE);
5602 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadjustment), FALSE);
5604 signal_id = WIDGET_CLASS (widget)->set_scroll_adjustments_signal;
5608 g_signal_query (signal_id, &query);
5609 if (!query.signal_id ||
5610 !g_type_is_a (query.itype, GTK_TYPE_WIDGET) ||
5611 query.return_type != G_TYPE_NONE ||
5612 query.n_params != 2 ||
5613 query.param_types[0] != GTK_TYPE_ADJUSTMENT ||
5614 query.param_types[1] != GTK_TYPE_ADJUSTMENT)
5616 g_warning (G_STRLOC ": signal \"%s::%s\" has wrong signature",
5617 G_OBJECT_TYPE_NAME (widget), query.signal_name);
5621 g_signal_emit (widget, signal_id, 0, hadjustment, vadjustment);
5626 gtk_widget_reparent_subwindows (GtkWidget *widget,
5627 GdkWindow *new_window)
5629 GtkWidgetPrivate *priv = widget->priv;
5631 if (!gtk_widget_get_has_window (widget))
5633 GList *children = gdk_window_get_children (priv->window);
5636 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5638 GdkWindow *window = tmp_list->data;
5641 gdk_window_get_user_data (window, &child);
5642 while (child && child != widget)
5643 child = ((GtkWidget*) child)->priv->parent;
5646 gdk_window_reparent (window, new_window, 0, 0);
5649 g_list_free (children);
5654 GList *tmp_list, *children;
5656 parent = gdk_window_get_parent (priv->window);
5659 gdk_window_reparent (priv->window, new_window, 0, 0);
5662 children = gdk_window_get_children (parent);
5664 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
5666 GdkWindow *window = tmp_list->data;
5669 gdk_window_get_user_data (window, &child);
5671 if (child == widget)
5672 gdk_window_reparent (window, new_window, 0, 0);
5675 g_list_free (children);
5681 gtk_widget_reparent_fixup_child (GtkWidget *widget,
5682 gpointer client_data)
5684 GtkWidgetPrivate *priv = widget->priv;
5686 g_assert (client_data != NULL);
5688 if (!gtk_widget_get_has_window (widget))
5691 g_object_unref (priv->window);
5692 priv->window = (GdkWindow*) client_data;
5694 g_object_ref (priv->window);
5696 if (GTK_IS_CONTAINER (widget))
5697 gtk_container_forall (GTK_CONTAINER (widget),
5698 gtk_widget_reparent_fixup_child,
5704 * gtk_widget_reparent:
5705 * @widget: a #GtkWidget
5706 * @new_parent: a #GtkContainer to move the widget into
5708 * Moves a widget from one #GtkContainer to another, handling reference
5709 * count issues to avoid destroying the widget.
5712 gtk_widget_reparent (GtkWidget *widget,
5713 GtkWidget *new_parent)
5715 GtkWidgetPrivate *priv;
5717 g_return_if_fail (GTK_IS_WIDGET (widget));
5718 g_return_if_fail (GTK_IS_CONTAINER (new_parent));
5719 priv = widget->priv;
5720 g_return_if_fail (priv->parent != NULL);
5722 if (priv->parent != new_parent)
5724 /* First try to see if we can get away without unrealizing
5725 * the widget as we reparent it. if so we set a flag so
5726 * that gtk_widget_unparent doesn't unrealize widget
5728 if (gtk_widget_get_realized (widget) && gtk_widget_get_realized (new_parent))
5729 GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
5731 g_object_ref (widget);
5732 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
5733 gtk_container_add (GTK_CONTAINER (new_parent), widget);
5734 g_object_unref (widget);
5736 if (GTK_WIDGET_IN_REPARENT (widget))
5738 GTK_PRIVATE_UNSET_FLAG (widget, GTK_IN_REPARENT);
5740 gtk_widget_reparent_subwindows (widget, gtk_widget_get_parent_window (widget));
5741 gtk_widget_reparent_fixup_child (widget,
5742 gtk_widget_get_parent_window (widget));
5745 g_object_notify (G_OBJECT (widget), "parent");
5750 * gtk_widget_intersect:
5751 * @widget: a #GtkWidget
5752 * @area: a rectangle
5753 * @intersection: rectangle to store intersection of @widget and @area
5755 * Computes the intersection of a @widget's area and @area, storing
5756 * the intersection in @intersection, and returns %TRUE if there was
5757 * an intersection. @intersection may be %NULL if you're only
5758 * interested in whether there was an intersection.
5760 * Return value: %TRUE if there was an intersection
5763 gtk_widget_intersect (GtkWidget *widget,
5764 const GdkRectangle *area,
5765 GdkRectangle *intersection)
5767 GtkWidgetPrivate *priv;
5772 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
5773 g_return_val_if_fail (area != NULL, FALSE);
5775 priv = widget->priv;
5778 dest = intersection;
5782 return_val = gdk_rectangle_intersect (&priv->allocation, area, dest);
5784 if (return_val && intersection && gtk_widget_get_has_window (widget))
5786 intersection->x -= priv->allocation.x;
5787 intersection->y -= priv->allocation.y;
5794 * gtk_widget_region_intersect:
5795 * @widget: a #GtkWidget
5796 * @region: a #cairo_region_t, in the same coordinate system as
5797 * @widget->allocation. That is, relative to @widget->window
5798 * for %NO_WINDOW widgets; relative to the parent window
5799 * of @widget->window for widgets with their own window.
5800 * @returns: A newly allocated region holding the intersection of @widget
5801 * and @region. The coordinates of the return value are
5802 * relative to @widget->window for %NO_WINDOW widgets, and
5803 * relative to the parent window of @widget->window for
5804 * widgets with their own window.
5806 * Computes the intersection of a @widget's area and @region, returning
5807 * the intersection. The result may be empty, use cairo_region_is_empty() to
5811 gtk_widget_region_intersect (GtkWidget *widget,
5812 const cairo_region_t *region)
5815 cairo_region_t *dest;
5817 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
5818 g_return_val_if_fail (region != NULL, NULL);
5820 gtk_widget_get_allocation (widget, &rect);
5822 dest = cairo_region_create_rectangle (&rect);
5824 cairo_region_intersect (dest, region);
5830 * _gtk_widget_grab_notify:
5831 * @widget: a #GtkWidget
5832 * @was_grabbed: whether a grab is now in effect
5834 * Emits the #GtkWidget::grab-notify signal on @widget.
5839 _gtk_widget_grab_notify (GtkWidget *widget,
5840 gboolean was_grabbed)
5842 g_signal_emit (widget, widget_signals[GRAB_NOTIFY], 0, was_grabbed);
5846 * gtk_widget_grab_focus:
5847 * @widget: a #GtkWidget
5849 * Causes @widget to have the keyboard focus for the #GtkWindow it's
5850 * inside. @widget must be a focusable widget, such as a #GtkEntry;
5851 * something like #GtkFrame won't work.
5853 * More precisely, it must have the %GTK_CAN_FOCUS flag set. Use
5854 * gtk_widget_set_can_focus() to modify that flag.
5856 * The widget also needs to be realized and mapped. This is indicated by the
5857 * related signals. Grabbing the focus immediately after creating the widget
5858 * will likely fail and cause critical warnings.
5861 gtk_widget_grab_focus (GtkWidget *widget)
5863 g_return_if_fail (GTK_IS_WIDGET (widget));
5865 if (!gtk_widget_is_sensitive (widget))
5868 g_object_ref (widget);
5869 g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
5870 g_object_notify (G_OBJECT (widget), "has-focus");
5871 g_object_unref (widget);
5875 reset_focus_recurse (GtkWidget *widget,
5878 if (GTK_IS_CONTAINER (widget))
5880 GtkContainer *container;
5882 container = GTK_CONTAINER (widget);
5883 gtk_container_set_focus_child (container, NULL);
5885 gtk_container_foreach (container,
5886 reset_focus_recurse,
5892 gtk_widget_real_grab_focus (GtkWidget *focus_widget)
5894 if (gtk_widget_get_can_focus (focus_widget))
5896 GtkWidget *toplevel;
5899 /* clear the current focus setting, break if the current widget
5900 * is the focus widget's parent, since containers above that will
5901 * be set by the next loop.
5903 toplevel = gtk_widget_get_toplevel (focus_widget);
5904 if (gtk_widget_is_toplevel (toplevel) && GTK_IS_WINDOW (toplevel))
5906 widget = gtk_window_get_focus (GTK_WINDOW (toplevel));
5908 if (widget == focus_widget)
5910 /* We call _gtk_window_internal_set_focus() here so that the
5911 * toplevel window can request the focus if necessary.
5912 * This is needed when the toplevel is a GtkPlug
5914 if (!gtk_widget_has_focus (widget))
5915 _gtk_window_internal_set_focus (GTK_WINDOW (toplevel), focus_widget);
5922 while (widget->priv->parent && widget->priv->parent != focus_widget->priv->parent)
5924 widget = widget->priv->parent;
5925 gtk_container_set_focus_child (GTK_CONTAINER (widget), NULL);
5929 else if (toplevel != focus_widget)
5931 /* gtk_widget_grab_focus() operates on a tree without window...
5932 * actually, this is very questionable behaviour.
5935 gtk_container_foreach (GTK_CONTAINER (toplevel),
5936 reset_focus_recurse,
5940 /* now propagate the new focus up the widget tree and finally
5941 * set it on the window
5943 widget = focus_widget;
5944 while (widget->priv->parent)
5946 gtk_container_set_focus_child (GTK_CONTAINER (widget->priv->parent), widget);
5947 widget = widget->priv->parent;
5949 if (GTK_IS_WINDOW (widget))
5950 _gtk_window_internal_set_focus (GTK_WINDOW (widget), focus_widget);
5955 gtk_widget_real_query_tooltip (GtkWidget *widget,
5958 gboolean keyboard_tip,
5959 GtkTooltip *tooltip)
5961 gchar *tooltip_markup;
5962 gboolean has_tooltip;
5964 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
5965 has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget), quark_has_tooltip));
5967 if (has_tooltip && tooltip_markup)
5969 gtk_tooltip_set_markup (tooltip, tooltip_markup);
5977 gtk_widget_real_show_help (GtkWidget *widget,
5978 GtkWidgetHelpType help_type)
5980 if (help_type == GTK_WIDGET_HELP_TOOLTIP)
5982 _gtk_tooltip_toggle_keyboard_mode (widget);
5991 gtk_widget_real_focus (GtkWidget *widget,
5992 GtkDirectionType direction)
5994 if (!gtk_widget_get_can_focus (widget))
5997 if (!gtk_widget_is_focus (widget))
5999 gtk_widget_grab_focus (widget);
6007 gtk_widget_real_move_focus (GtkWidget *widget,
6008 GtkDirectionType direction)
6010 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
6012 if (GTK_IS_WINDOW (toplevel) &&
6013 GTK_WINDOW_GET_CLASS (toplevel)->move_focus)
6015 GTK_WINDOW_GET_CLASS (toplevel)->move_focus (GTK_WINDOW (toplevel),
6021 gtk_widget_real_keynav_failed (GtkWidget *widget,
6022 GtkDirectionType direction)
6024 gboolean cursor_only;
6028 case GTK_DIR_TAB_FORWARD:
6029 case GTK_DIR_TAB_BACKWARD:
6036 g_object_get (gtk_widget_get_settings (widget),
6037 "gtk-keynav-cursor-only", &cursor_only,
6044 gtk_widget_error_bell (widget);
6050 * gtk_widget_set_can_focus:
6051 * @widget: a #GtkWidget
6052 * @can_focus: whether or not @widget can own the input focus.
6054 * Specifies whether @widget can own the input focus. See
6055 * gtk_widget_grab_focus() for actually setting the input focus on a
6061 gtk_widget_set_can_focus (GtkWidget *widget,
6064 g_return_if_fail (GTK_IS_WIDGET (widget));
6066 if (can_focus != gtk_widget_get_can_focus (widget))
6069 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS;
6071 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS);
6073 gtk_widget_queue_resize (widget);
6074 g_object_notify (G_OBJECT (widget), "can-focus");
6079 * gtk_widget_get_can_focus:
6080 * @widget: a #GtkWidget
6082 * Determines whether @widget can own the input focus. See
6083 * gtk_widget_set_can_focus().
6085 * Return value: %TRUE if @widget can own the input focus, %FALSE otherwise
6090 gtk_widget_get_can_focus (GtkWidget *widget)
6092 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6094 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_FOCUS) != 0;
6098 * gtk_widget_has_focus:
6099 * @widget: a #GtkWidget
6101 * Determines if the widget has the global input focus. See
6102 * gtk_widget_is_focus() for the difference between having the global
6103 * input focus, and only having the focus within a toplevel.
6105 * Return value: %TRUE if the widget has the global input focus.
6110 gtk_widget_has_focus (GtkWidget *widget)
6112 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6114 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_FOCUS) != 0;
6118 * gtk_widget_is_focus:
6119 * @widget: a #GtkWidget
6121 * Determines if the widget is the focus widget within its
6122 * toplevel. (This does not mean that the %HAS_FOCUS flag is
6123 * necessarily set; %HAS_FOCUS will only be set if the
6124 * toplevel widget additionally has the global input focus.)
6126 * Return value: %TRUE if the widget is the focus widget.
6129 gtk_widget_is_focus (GtkWidget *widget)
6131 GtkWidget *toplevel;
6133 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6135 toplevel = gtk_widget_get_toplevel (widget);
6137 if (GTK_IS_WINDOW (toplevel))
6138 return widget == gtk_window_get_focus (GTK_WINDOW (toplevel));
6144 * gtk_widget_set_can_default:
6145 * @widget: a #GtkWidget
6146 * @can_default: whether or not @widget can be a default widget.
6148 * Specifies whether @widget can be a default widget. See
6149 * gtk_widget_grab_default() for details about the meaning of
6155 gtk_widget_set_can_default (GtkWidget *widget,
6156 gboolean can_default)
6158 g_return_if_fail (GTK_IS_WIDGET (widget));
6160 if (can_default != gtk_widget_get_can_default (widget))
6163 GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT;
6165 GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT);
6167 gtk_widget_queue_resize (widget);
6168 g_object_notify (G_OBJECT (widget), "can-default");
6173 * gtk_widget_get_can_default:
6174 * @widget: a #GtkWidget
6176 * Determines whether @widget can be a default widget. See
6177 * gtk_widget_set_can_default().
6179 * Return value: %TRUE if @widget can be a default widget, %FALSE otherwise
6184 gtk_widget_get_can_default (GtkWidget *widget)
6186 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6188 return (GTK_OBJECT_FLAGS (widget) & GTK_CAN_DEFAULT) != 0;
6192 * gtk_widget_has_default:
6193 * @widget: a #GtkWidget
6195 * Determines whether @widget is the current default widget within its
6196 * toplevel. See gtk_widget_set_can_default().
6198 * Return value: %TRUE if @widget is the current default widget within
6199 * its toplevel, %FALSE otherwise
6204 gtk_widget_has_default (GtkWidget *widget)
6206 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6208 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_DEFAULT) != 0;
6212 _gtk_widget_set_has_default (GtkWidget *widget,
6213 gboolean has_default)
6216 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_DEFAULT;
6218 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_DEFAULT);
6222 * gtk_widget_grab_default:
6223 * @widget: a #GtkWidget
6225 * Causes @widget to become the default widget. @widget must have the
6226 * %GTK_CAN_DEFAULT flag set; typically you have to set this flag
6227 * yourself by calling <literal>gtk_widget_set_can_default (@widget,
6228 * %TRUE)</literal>. The default widget is activated when
6229 * the user presses Enter in a window. Default widgets must be
6230 * activatable, that is, gtk_widget_activate() should affect them. Note
6231 * that #GtkEntry widgets require the "activates-default" property
6232 * set to %TRUE before they activate the default widget when Enter
6233 * is pressed and the #GtkEntry is focused.
6236 gtk_widget_grab_default (GtkWidget *widget)
6240 g_return_if_fail (GTK_IS_WIDGET (widget));
6241 g_return_if_fail (gtk_widget_get_can_default (widget));
6243 window = gtk_widget_get_toplevel (widget);
6245 if (window && gtk_widget_is_toplevel (window))
6246 gtk_window_set_default (GTK_WINDOW (window), widget);
6248 g_warning (G_STRLOC ": widget not within a GtkWindow");
6252 * gtk_widget_set_receives_default:
6253 * @widget: a #GtkWidget
6254 * @receives_default: whether or not @widget can be a default widget.
6256 * Specifies whether @widget will be treated as the default widget
6257 * within its toplevel when it has the focus, even if another widget
6260 * See gtk_widget_grab_default() for details about the meaning of
6266 gtk_widget_set_receives_default (GtkWidget *widget,
6267 gboolean receives_default)
6269 g_return_if_fail (GTK_IS_WIDGET (widget));
6271 if (receives_default != gtk_widget_get_receives_default (widget))
6273 if (receives_default)
6274 GTK_OBJECT_FLAGS (widget) |= GTK_RECEIVES_DEFAULT;
6276 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RECEIVES_DEFAULT);
6278 g_object_notify (G_OBJECT (widget), "receives-default");
6283 * gtk_widget_get_receives_default:
6284 * @widget: a #GtkWidget
6286 * Determines whether @widget is alyways treated as default widget
6287 * withing its toplevel when it has the focus, even if another widget
6290 * See gtk_widget_set_receives_default().
6292 * Return value: %TRUE if @widget acts as default widget when focussed,
6298 gtk_widget_get_receives_default (GtkWidget *widget)
6300 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6302 return (GTK_OBJECT_FLAGS (widget) & GTK_RECEIVES_DEFAULT) != 0;
6306 * gtk_widget_has_grab:
6307 * @widget: a #GtkWidget
6309 * Determines whether the widget is currently grabbing events, so it
6310 * is the only widget receiving input events (keyboard and mouse).
6312 * See also gtk_grab_add().
6314 * Return value: %TRUE if the widget is in the grab_widgets stack
6319 gtk_widget_has_grab (GtkWidget *widget)
6321 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6323 return (GTK_OBJECT_FLAGS (widget) & GTK_HAS_GRAB) != 0;
6327 _gtk_widget_set_has_grab (GtkWidget *widget,
6331 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_GRAB;
6333 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_GRAB);
6337 * gtk_widget_device_is_shadowed:
6338 * @widget: a #GtkWidget
6339 * @device: a #GdkDevice
6341 * Returns %TRUE if @device has been shadowed by a GTK+
6342 * device grab on another widget, so it would stop sending
6343 * events to @widget. This may be used in the
6344 * #GtkWidget::grab-notify signal to check for specific
6345 * devices. See gtk_device_grab_add().
6347 * Returns: %TRUE if there is an ongoing grab on @device
6348 * by another #GtkWidget than @widget.
6353 gtk_widget_device_is_shadowed (GtkWidget *widget,
6356 GtkWindowGroup *group;
6357 GtkWidget *grab_widget, *toplevel;
6359 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6360 g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
6362 if (!gtk_widget_get_realized (widget))
6365 toplevel = gtk_widget_get_toplevel (widget);
6367 if (GTK_IS_WINDOW (toplevel))
6368 group = gtk_window_get_group (GTK_WINDOW (toplevel));
6370 group = gtk_window_get_group (NULL);
6372 grab_widget = gtk_window_group_get_current_device_grab (group, device);
6374 /* Widget not inside the hierarchy of grab_widget */
6376 widget != grab_widget &&
6377 !gtk_widget_is_ancestor (widget, grab_widget))
6380 grab_widget = gtk_window_group_get_current_grab (group);
6381 if (grab_widget && widget != grab_widget &&
6382 !gtk_widget_is_ancestor (widget, grab_widget))
6389 * gtk_widget_set_name:
6390 * @widget: a #GtkWidget
6391 * @name: name for the widget
6393 * Widgets can be named, which allows you to refer to them from a
6394 * gtkrc file. You can apply a style to widgets with a particular name
6395 * in the gtkrc file. See the documentation for gtkrc files (on the
6396 * same page as the docs for #GtkRcStyle).
6398 * Note that widget names are separated by periods in paths (see
6399 * gtk_widget_path()), so names with embedded periods may cause confusion.
6402 gtk_widget_set_name (GtkWidget *widget,
6405 GtkWidgetPrivate *priv;
6408 g_return_if_fail (GTK_IS_WIDGET (widget));
6410 priv = widget->priv;
6412 new_name = g_strdup (name);
6413 g_free (priv->name);
6414 priv->name = new_name;
6416 if (gtk_widget_has_rc_style (widget))
6417 gtk_widget_reset_rc_style (widget);
6419 g_object_notify (G_OBJECT (widget), "name");
6423 * gtk_widget_get_name:
6424 * @widget: a #GtkWidget
6426 * Retrieves the name of a widget. See gtk_widget_set_name() for the
6427 * significance of widget names.
6429 * Return value: name of the widget. This string is owned by GTK+ and
6430 * should not be modified or freed
6432 G_CONST_RETURN gchar*
6433 gtk_widget_get_name (GtkWidget *widget)
6435 GtkWidgetPrivate *priv;
6437 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
6439 priv = widget->priv;
6443 return G_OBJECT_TYPE_NAME (widget);
6447 * gtk_widget_set_state:
6448 * @widget: a #GtkWidget
6449 * @state: new state for @widget
6451 * This function is for use in widget implementations. Sets the state
6452 * of a widget (insensitive, prelighted, etc.) Usually you should set
6453 * the state using wrapper functions such as gtk_widget_set_sensitive().
6456 gtk_widget_set_state (GtkWidget *widget,
6459 GtkWidgetPrivate *priv;
6461 g_return_if_fail (GTK_IS_WIDGET (widget));
6463 priv = widget->priv;
6465 if (state == gtk_widget_get_state (widget))
6468 if (state == GTK_STATE_INSENSITIVE)
6469 gtk_widget_set_sensitive (widget, FALSE);
6475 data.state_restoration = FALSE;
6476 data.use_forall = FALSE;
6478 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6480 data.parent_sensitive = TRUE;
6482 gtk_widget_propagate_state (widget, &data);
6484 if (gtk_widget_is_drawable (widget))
6485 gtk_widget_queue_draw (widget);
6490 * gtk_widget_get_state:
6491 * @widget: a #GtkWidget
6493 * Returns the widget's state. See gtk_widget_set_state().
6495 * Returns: the state of @widget.
6500 gtk_widget_get_state (GtkWidget *widget)
6502 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_STATE_NORMAL);
6504 return widget->priv->state;
6508 * gtk_widget_set_visible:
6509 * @widget: a #GtkWidget
6510 * @visible: whether the widget should be shown or not
6512 * Sets the visibility state of @widget. Note that setting this to
6513 * %TRUE doesn't mean the widget is actually viewable, see
6514 * gtk_widget_get_visible().
6516 * This function simply calls gtk_widget_show() or gtk_widget_hide()
6517 * but is nicer to use when the visibility of the widget depends on
6523 gtk_widget_set_visible (GtkWidget *widget,
6526 g_return_if_fail (GTK_IS_WIDGET (widget));
6528 if (visible != gtk_widget_get_visible (widget))
6531 gtk_widget_show (widget);
6533 gtk_widget_hide (widget);
6538 * gtk_widget_get_visible:
6539 * @widget: a #GtkWidget
6541 * Determines whether the widget is visible. Note that this doesn't
6542 * take into account whether the widget's parent is also visible
6543 * or the widget is obscured in any way.
6545 * See gtk_widget_set_visible().
6547 * Return value: %TRUE if the widget is visible
6552 gtk_widget_get_visible (GtkWidget *widget)
6554 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6556 return (GTK_OBJECT_FLAGS (widget) & GTK_VISIBLE) != 0;
6560 * gtk_widget_set_has_window:
6561 * @widget: a #GtkWidget
6562 * @has_window: whether or not @widget has a window.
6564 * Specifies whether @widget has a #GdkWindow of its own. Note that
6565 * all realized widgets have a non-%NULL "window" pointer
6566 * (gtk_widget_get_window() never returns a %NULL window when a widget
6567 * is realized), but for many of them it's actually the #GdkWindow of
6568 * one of its parent widgets. Widgets that do not create a %window for
6569 * themselves in GtkWidget::realize() must announce this by
6570 * calling this function with @has_window = %FALSE.
6572 * This function should only be called by widget implementations,
6573 * and they should call it in their init() function.
6578 gtk_widget_set_has_window (GtkWidget *widget,
6579 gboolean has_window)
6581 g_return_if_fail (GTK_IS_WIDGET (widget));
6584 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW);
6586 GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW;
6590 * gtk_widget_get_has_window:
6591 * @widget: a #GtkWidget
6593 * Determines whether @widget has a #GdkWindow of its own. See
6594 * gtk_widget_set_has_window().
6596 * Return value: %TRUE if @widget has a window, %FALSE otherwise
6601 gtk_widget_get_has_window (GtkWidget *widget)
6603 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6605 return !((GTK_OBJECT_FLAGS (widget) & GTK_NO_WINDOW) != 0);
6609 * gtk_widget_is_toplevel:
6610 * @widget: a #GtkWidget
6612 * Determines whether @widget is a toplevel widget. Currently only
6613 * #GtkWindow and #GtkInvisible are toplevel widgets. Toplevel
6614 * widgets have no parent widget.
6616 * Return value: %TRUE if @widget is a toplevel, %FALSE otherwise
6621 gtk_widget_is_toplevel (GtkWidget *widget)
6623 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6625 return (GTK_OBJECT_FLAGS (widget) & GTK_TOPLEVEL) != 0;
6629 _gtk_widget_set_is_toplevel (GtkWidget *widget,
6630 gboolean is_toplevel)
6633 GTK_OBJECT_FLAGS (widget) |= GTK_TOPLEVEL;
6635 GTK_OBJECT_FLAGS (widget) &= ~(GTK_TOPLEVEL);
6639 * gtk_widget_is_drawable:
6640 * @widget: a #GtkWidget
6642 * Determines whether @widget can be drawn to. A widget can be drawn
6643 * to if it is mapped and visible.
6645 * Return value: %TRUE if @widget is drawable, %FALSE otherwise
6650 gtk_widget_is_drawable (GtkWidget *widget)
6652 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6654 return (gtk_widget_get_visible (widget) &&
6655 gtk_widget_get_mapped (widget));
6659 * gtk_widget_get_realized:
6660 * @widget: a #GtkWidget
6662 * Determines whether @widget is realized.
6664 * Return value: %TRUE if @widget is realized, %FALSE otherwise
6669 gtk_widget_get_realized (GtkWidget *widget)
6671 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6673 return (GTK_OBJECT_FLAGS (widget) & GTK_REALIZED) != 0;
6677 * gtk_widget_set_realized:
6678 * @widget: a #GtkWidget
6679 * @realized: %TRUE to mark the widget as realized
6681 * Marks the widget as being realized.
6683 * This function should only ever be called in a derived widget's
6684 * "realize" or "unrealize" implementation.
6689 gtk_widget_set_realized (GtkWidget *widget,
6692 g_return_if_fail (GTK_IS_WIDGET (widget));
6695 GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED;
6697 GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED);
6701 * gtk_widget_get_mapped:
6702 * @widget: a #GtkWidget
6704 * Whether the widget is mapped.
6706 * Return value: %TRUE if the widget is mapped, %FALSE otherwise.
6711 gtk_widget_get_mapped (GtkWidget *widget)
6713 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6715 return (GTK_OBJECT_FLAGS (widget) & GTK_MAPPED) != 0;
6719 * gtk_widget_set_mapped:
6720 * @widget: a #GtkWidget
6721 * @mapped: %TRUE to mark the widget as mapped
6723 * Marks the widget as being realized.
6725 * This function should only ever be called in a derived widget's
6726 * "map" or "unmap" implementation.
6731 gtk_widget_set_mapped (GtkWidget *widget,
6734 g_return_if_fail (GTK_IS_WIDGET (widget));
6737 GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED;
6739 GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED);
6743 * gtk_widget_set_app_paintable:
6744 * @widget: a #GtkWidget
6745 * @app_paintable: %TRUE if the application will paint on the widget
6747 * Sets whether the application intends to draw on the widget in
6748 * an #GtkWidget::draw handler.
6750 * This is a hint to the widget and does not affect the behavior of
6751 * the GTK+ core; many widgets ignore this flag entirely. For widgets
6752 * that do pay attention to the flag, such as #GtkEventBox and #GtkWindow,
6753 * the effect is to suppress default themed drawing of the widget's
6754 * background. (Children of the widget will still be drawn.) The application
6755 * is then entirely responsible for drawing the widget background.
6757 * Note that the background is still drawn when the widget is mapped.
6760 gtk_widget_set_app_paintable (GtkWidget *widget,
6761 gboolean app_paintable)
6763 g_return_if_fail (GTK_IS_WIDGET (widget));
6765 app_paintable = (app_paintable != FALSE);
6767 if (gtk_widget_get_app_paintable (widget) != app_paintable)
6770 GTK_OBJECT_FLAGS (widget) |= GTK_APP_PAINTABLE;
6772 GTK_OBJECT_FLAGS (widget) &= ~(GTK_APP_PAINTABLE);
6774 if (gtk_widget_is_drawable (widget))
6775 gtk_widget_queue_draw (widget);
6777 g_object_notify (G_OBJECT (widget), "app-paintable");
6782 * gtk_widget_get_app_paintable:
6783 * @widget: a #GtkWidget
6785 * Determines whether the application intends to draw on the widget in
6786 * an #GtkWidget::draw handler.
6788 * See gtk_widget_set_app_paintable()
6790 * Return value: %TRUE if the widget is app paintable
6795 gtk_widget_get_app_paintable (GtkWidget *widget)
6797 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6799 return (GTK_OBJECT_FLAGS (widget) & GTK_APP_PAINTABLE) != 0;
6803 * gtk_widget_set_double_buffered:
6804 * @widget: a #GtkWidget
6805 * @double_buffered: %TRUE to double-buffer a widget
6807 * Widgets are double buffered by default; you can use this function
6808 * to turn off the buffering. "Double buffered" simply means that
6809 * gdk_window_begin_paint_region() and gdk_window_end_paint() are called
6810 * automatically around expose events sent to the
6811 * widget. gdk_window_begin_paint() diverts all drawing to a widget's
6812 * window to an offscreen buffer, and gdk_window_end_paint() draws the
6813 * buffer to the screen. The result is that users see the window
6814 * update in one smooth step, and don't see individual graphics
6815 * primitives being rendered.
6817 * In very simple terms, double buffered widgets don't flicker,
6818 * so you would only use this function to turn off double buffering
6819 * if you had special needs and really knew what you were doing.
6821 * Note: if you turn off double-buffering, you have to handle
6822 * expose events, since even the clearing to the background color or
6823 * pixmap will not happen automatically (as it is done in
6824 * gdk_window_begin_paint()).
6827 gtk_widget_set_double_buffered (GtkWidget *widget,
6828 gboolean double_buffered)
6830 g_return_if_fail (GTK_IS_WIDGET (widget));
6832 double_buffered = (double_buffered != FALSE);
6834 if (double_buffered != gtk_widget_get_double_buffered (widget))
6836 if (double_buffered)
6837 GTK_OBJECT_FLAGS (widget) |= GTK_DOUBLE_BUFFERED;
6839 GTK_OBJECT_FLAGS (widget) &= ~(GTK_DOUBLE_BUFFERED);
6841 g_object_notify (G_OBJECT (widget), "double-buffered");
6846 * gtk_widget_get_double_buffered:
6847 * @widget: a #GtkWidget
6849 * Determines whether the widget is double buffered.
6851 * See gtk_widget_set_double_buffered()
6853 * Return value: %TRUE if the widget is double buffered
6858 gtk_widget_get_double_buffered (GtkWidget *widget)
6860 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6862 return (GTK_OBJECT_FLAGS (widget) & GTK_DOUBLE_BUFFERED) != 0;
6866 * gtk_widget_set_redraw_on_allocate:
6867 * @widget: a #GtkWidget
6868 * @redraw_on_allocate: if %TRUE, the entire widget will be redrawn
6869 * when it is allocated to a new size. Otherwise, only the
6870 * new portion of the widget will be redrawn.
6872 * Sets whether the entire widget is queued for drawing when its size
6873 * allocation changes. By default, this setting is %TRUE and
6874 * the entire widget is redrawn on every size change. If your widget
6875 * leaves the upper left unchanged when made bigger, turning this
6876 * setting off will improve performance.
6878 * Note that for %NO_WINDOW widgets setting this flag to %FALSE turns
6879 * off all allocation on resizing: the widget will not even redraw if
6880 * its position changes; this is to allow containers that don't draw
6881 * anything to avoid excess invalidations. If you set this flag on a
6882 * %NO_WINDOW widget that <emphasis>does</emphasis> draw on @widget->window,
6883 * you are responsible for invalidating both the old and new allocation
6884 * of the widget when the widget is moved and responsible for invalidating
6885 * regions newly when the widget increases size.
6888 gtk_widget_set_redraw_on_allocate (GtkWidget *widget,
6889 gboolean redraw_on_allocate)
6891 g_return_if_fail (GTK_IS_WIDGET (widget));
6893 if (redraw_on_allocate)
6894 GTK_PRIVATE_SET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6896 GTK_PRIVATE_UNSET_FLAG (widget, GTK_REDRAW_ON_ALLOC);
6900 * gtk_widget_set_sensitive:
6901 * @widget: a #GtkWidget
6902 * @sensitive: %TRUE to make the widget sensitive
6904 * Sets the sensitivity of a widget. A widget is sensitive if the user
6905 * can interact with it. Insensitive widgets are "grayed out" and the
6906 * user can't interact with them. Insensitive widgets are known as
6907 * "inactive", "disabled", or "ghosted" in some other toolkits.
6910 gtk_widget_set_sensitive (GtkWidget *widget,
6913 GtkWidgetPrivate *priv;
6916 g_return_if_fail (GTK_IS_WIDGET (widget));
6918 priv = widget->priv;
6920 sensitive = (sensitive != FALSE);
6922 if (sensitive == (gtk_widget_get_sensitive (widget) != FALSE))
6927 GTK_OBJECT_FLAGS (widget) |= GTK_SENSITIVE;
6928 data.state = priv->saved_state;
6932 GTK_OBJECT_FLAGS (widget) &= ~(GTK_SENSITIVE);
6933 data.state = gtk_widget_get_state (widget);
6935 data.state_restoration = TRUE;
6936 data.use_forall = TRUE;
6939 data.parent_sensitive = (gtk_widget_is_sensitive (priv->parent) != FALSE);
6941 data.parent_sensitive = TRUE;
6943 gtk_widget_propagate_state (widget, &data);
6944 if (gtk_widget_is_drawable (widget))
6945 gtk_widget_queue_draw (widget);
6947 g_object_notify (G_OBJECT (widget), "sensitive");
6951 * gtk_widget_get_sensitive:
6952 * @widget: a #GtkWidget
6954 * Returns the widget's sensitivity (in the sense of returning
6955 * the value that has been set using gtk_widget_set_sensitive()).
6957 * The effective sensitivity of a widget is however determined by both its
6958 * own and its parent widget's sensitivity. See gtk_widget_is_sensitive().
6960 * Returns: %TRUE if the widget is sensitive
6965 gtk_widget_get_sensitive (GtkWidget *widget)
6967 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6969 return (GTK_OBJECT_FLAGS (widget) & GTK_SENSITIVE) != 0;
6973 * gtk_widget_is_sensitive:
6974 * @widget: a #GtkWidget
6976 * Returns the widget's effective sensitivity, which means
6977 * it is sensitive itself and also its parent widget is sensntive
6979 * Returns: %TRUE if the widget is effectively sensitive
6984 gtk_widget_is_sensitive (GtkWidget *widget)
6986 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
6988 return (gtk_widget_get_sensitive (widget) &&
6989 (GTK_OBJECT_FLAGS (widget) & GTK_PARENT_SENSITIVE) != 0);
6993 * gtk_widget_set_parent:
6994 * @widget: a #GtkWidget
6995 * @parent: parent container
6997 * This function is useful only when implementing subclasses of
6999 * Sets the container as the parent of @widget, and takes care of
7000 * some details such as updating the state and style of the child
7001 * to reflect its new location. The opposite function is
7002 * gtk_widget_unparent().
7005 gtk_widget_set_parent (GtkWidget *widget,
7008 GtkWidgetPrivate *priv;
7011 g_return_if_fail (GTK_IS_WIDGET (widget));
7012 g_return_if_fail (GTK_IS_WIDGET (parent));
7013 g_return_if_fail (widget != parent);
7015 priv = widget->priv;
7017 if (priv->parent != NULL)
7019 g_warning ("Can't set a parent on widget which has a parent\n");
7022 if (gtk_widget_is_toplevel (widget))
7024 g_warning ("Can't set a parent on a toplevel widget\n");
7028 /* keep this function in sync with gtk_menu_attach_to_widget()
7031 g_object_ref_sink (widget);
7032 priv->parent = parent;
7034 if (gtk_widget_get_state (parent) != GTK_STATE_NORMAL)
7035 data.state = gtk_widget_get_state (parent);
7037 data.state = gtk_widget_get_state (widget);
7038 data.state_restoration = FALSE;
7039 data.parent_sensitive = (gtk_widget_is_sensitive (parent) != FALSE);
7040 data.use_forall = gtk_widget_is_sensitive (parent) != gtk_widget_is_sensitive (widget);
7042 gtk_widget_propagate_state (widget, &data);
7044 gtk_widget_reset_rc_styles (widget);
7046 g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
7047 if (GTK_WIDGET_ANCHORED (priv->parent))
7048 _gtk_widget_propagate_hierarchy_changed (widget, NULL);
7049 g_object_notify (G_OBJECT (widget), "parent");
7051 /* Enforce realized/mapped invariants
7053 if (gtk_widget_get_realized (priv->parent))
7054 gtk_widget_realize (widget);
7056 if (gtk_widget_get_visible (priv->parent) &&
7057 gtk_widget_get_visible (widget))
7059 if (GTK_WIDGET_CHILD_VISIBLE (widget) &&
7060 gtk_widget_get_mapped (priv->parent))
7061 gtk_widget_map (widget);
7063 gtk_widget_queue_resize (widget);
7068 * gtk_widget_get_parent:
7069 * @widget: a #GtkWidget
7071 * Returns the parent container of @widget.
7073 * Return value: (transfer none): the parent container of @widget, or %NULL
7076 gtk_widget_get_parent (GtkWidget *widget)
7078 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7080 return widget->priv->parent;
7083 /*****************************************
7085 * see docs/styles.txt
7086 *****************************************/
7089 * gtk_widget_style_attach:
7090 * @widget: a #GtkWidget
7092 * This function attaches the widget's #GtkStyle to the widget's
7093 * #GdkWindow. It is a replacement for
7096 * widget->style = gtk_style_attach (widget->style, widget->window);
7099 * and should only ever be called in a derived widget's "realize"
7100 * implementation which does not chain up to its parent class'
7101 * "realize" implementation, because one of the parent classes
7102 * (finally #GtkWidget) would attach the style itself.
7107 gtk_widget_style_attach (GtkWidget *widget)
7109 GtkWidgetPrivate *priv;
7111 g_return_if_fail (GTK_IS_WIDGET (widget));
7112 g_return_if_fail (gtk_widget_get_realized (widget));
7114 priv = widget->priv;
7116 priv->style = gtk_style_attach (priv->style, priv->window);
7120 * gtk_widget_has_rc_style:
7121 * @widget: a #GtkWidget
7123 * Determines if the widget style has been looked up through the rc mechanism.
7125 * Returns: %TRUE if the widget has been looked up through the rc
7126 * mechanism, %FALSE otherwise.
7131 gtk_widget_has_rc_style (GtkWidget *widget)
7133 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7135 return (GTK_OBJECT_FLAGS (widget) & GTK_RC_STYLE) != 0;
7139 * gtk_widget_set_style:
7140 * @widget: a #GtkWidget
7141 * @style: (allow-none): a #GtkStyle, or %NULL to remove the effect of a previous
7142 * gtk_widget_set_style() and go back to the default style
7144 * Sets the #GtkStyle for a widget (@widget->style). You probably don't
7145 * want to use this function; it interacts badly with themes, because
7146 * themes work by replacing the #GtkStyle. Instead, use
7147 * gtk_widget_modify_style().
7150 gtk_widget_set_style (GtkWidget *widget,
7153 g_return_if_fail (GTK_IS_WIDGET (widget));
7157 gboolean initial_emission;
7159 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7161 GTK_OBJECT_FLAGS (widget) &= ~(GTK_RC_STYLE);
7162 GTK_PRIVATE_SET_FLAG (widget, GTK_USER_STYLE);
7164 gtk_widget_set_style_internal (widget, style, initial_emission);
7168 if (GTK_WIDGET_USER_STYLE (widget))
7169 gtk_widget_reset_rc_style (widget);
7174 * gtk_widget_ensure_style:
7175 * @widget: a #GtkWidget
7177 * Ensures that @widget has a style (@widget->style). Not a very useful
7178 * function; most of the time, if you want the style, the widget is
7179 * realized, and realized widgets are guaranteed to have a style
7183 gtk_widget_ensure_style (GtkWidget *widget)
7185 g_return_if_fail (GTK_IS_WIDGET (widget));
7187 if (!GTK_WIDGET_USER_STYLE (widget) &&
7188 !gtk_widget_has_rc_style (widget))
7189 gtk_widget_reset_rc_style (widget);
7192 /* Look up the RC style for this widget, unsetting any user style that
7193 * may be in effect currently
7196 gtk_widget_reset_rc_style (GtkWidget *widget)
7198 GtkWidgetPrivate *priv = widget->priv;
7199 GtkStyle *new_style = NULL;
7200 gboolean initial_emission;
7202 initial_emission = !gtk_widget_has_rc_style (widget) && !GTK_WIDGET_USER_STYLE (widget);
7204 GTK_PRIVATE_UNSET_FLAG (widget, GTK_USER_STYLE);
7205 GTK_OBJECT_FLAGS (widget) |= GTK_RC_STYLE;
7207 if (gtk_widget_has_screen (widget))
7208 new_style = gtk_rc_get_style (widget);
7210 new_style = gtk_widget_get_default_style ();
7212 if (initial_emission || new_style != priv->style)
7213 gtk_widget_set_style_internal (widget, new_style, initial_emission);
7217 * gtk_widget_get_style:
7218 * @widget: a #GtkWidget
7220 * Simply an accessor function that returns @widget->style.
7222 * Return value: (transfer none): the widget's #GtkStyle
7225 gtk_widget_get_style (GtkWidget *widget)
7227 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7229 return widget->priv->style;
7233 * gtk_widget_modify_style:
7234 * @widget: a #GtkWidget
7235 * @style: the #GtkRcStyle holding the style modifications
7237 * Modifies style values on the widget. Modifications made using this
7238 * technique take precedence over style values set via an RC file,
7239 * however, they will be overriden if a style is explicitely set on
7240 * the widget using gtk_widget_set_style(). The #GtkRcStyle structure
7241 * is designed so each field can either be set or unset, so it is
7242 * possible, using this function, to modify some style values and
7243 * leave the others unchanged.
7245 * Note that modifications made with this function are not cumulative
7246 * with previous calls to gtk_widget_modify_style() or with such
7247 * functions as gtk_widget_modify_fg(). If you wish to retain
7248 * previous values, you must first call gtk_widget_get_modifier_style(),
7249 * make your modifications to the returned style, then call
7250 * gtk_widget_modify_style() with that style. On the other hand,
7251 * if you first call gtk_widget_modify_style(), subsequent calls
7252 * to such functions gtk_widget_modify_fg() will have a cumulative
7253 * effect with the initial modifications.
7256 gtk_widget_modify_style (GtkWidget *widget,
7259 g_return_if_fail (GTK_IS_WIDGET (widget));
7260 g_return_if_fail (GTK_IS_RC_STYLE (style));
7262 g_object_set_qdata_full (G_OBJECT (widget),
7264 gtk_rc_style_copy (style),
7265 (GDestroyNotify) g_object_unref);
7267 /* note that "style" may be invalid here if it was the old
7268 * modifier style and the only reference was our own.
7271 if (gtk_widget_has_rc_style (widget))
7272 gtk_widget_reset_rc_style (widget);
7276 * gtk_widget_get_modifier_style:
7277 * @widget: a #GtkWidget
7279 * Returns the current modifier style for the widget. (As set by
7280 * gtk_widget_modify_style().) If no style has previously set, a new
7281 * #GtkRcStyle will be created with all values unset, and set as the
7282 * modifier style for the widget. If you make changes to this rc
7283 * style, you must call gtk_widget_modify_style(), passing in the
7284 * returned rc style, to make sure that your changes take effect.
7286 * Caution: passing the style back to gtk_widget_modify_style() will
7287 * normally end up destroying it, because gtk_widget_modify_style() copies
7288 * the passed-in style and sets the copy as the new modifier style,
7289 * thus dropping any reference to the old modifier style. Add a reference
7290 * to the modifier style if you want to keep it alive.
7292 * Return value: (transfer none): the modifier style for the widget. This rc style is
7293 * owned by the widget. If you want to keep a pointer to value this
7294 * around, you must add a refcount using g_object_ref().
7297 gtk_widget_get_modifier_style (GtkWidget *widget)
7299 GtkRcStyle *rc_style;
7301 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7303 rc_style = g_object_get_qdata (G_OBJECT (widget), quark_rc_style);
7307 rc_style = gtk_rc_style_new ();
7308 g_object_set_qdata_full (G_OBJECT (widget),
7311 (GDestroyNotify) g_object_unref);
7318 gtk_widget_modify_color_component (GtkWidget *widget,
7319 GtkRcFlags component,
7321 const GdkColor *color)
7323 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7330 rc_style->fg[state] = *color;
7333 rc_style->bg[state] = *color;
7336 rc_style->text[state] = *color;
7339 rc_style->base[state] = *color;
7342 g_assert_not_reached();
7345 rc_style->color_flags[state] |= component;
7348 rc_style->color_flags[state] &= ~component;
7350 gtk_widget_modify_style (widget, rc_style);
7354 * gtk_widget_modify_symbolic_color:
7355 * @widget: a #GtkWidget
7356 * @name: the name of the symbolic color to modify
7357 * @color: (allow-none): the color to assign (does not need to be allocated),
7358 * or %NULL to undo the effect of previous calls to
7359 * of gtk_widget_modify_symbolic_color().
7361 * Sets a symbolic color for a widget.
7362 * All other style values are left untouched. See also
7363 * gtk_widget_modify_style().
7368 gtk_widget_modify_symbolic_color (GtkWidget *widget,
7370 const GdkColor *color)
7372 GtkRcStyle *rc_style = gtk_widget_get_modifier_style (widget);
7374 _gtk_rc_style_set_symbolic_color (rc_style, name, color);
7376 gtk_widget_modify_style (widget, rc_style);
7380 * gtk_widget_modify_fg:
7381 * @widget: a #GtkWidget
7382 * @state: the state for which to set the foreground color
7383 * @color: (allow-none): the color to assign (does not need to be allocated),
7384 * or %NULL to undo the effect of previous calls to
7385 * of gtk_widget_modify_fg().
7387 * Sets the foreground color for a widget in a particular state.
7388 * All other style values are left untouched. See also
7389 * gtk_widget_modify_style().
7392 gtk_widget_modify_fg (GtkWidget *widget,
7394 const GdkColor *color)
7396 g_return_if_fail (GTK_IS_WIDGET (widget));
7397 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7399 gtk_widget_modify_color_component (widget, GTK_RC_FG, state, color);
7403 * gtk_widget_modify_bg:
7404 * @widget: a #GtkWidget
7405 * @state: the state for which to set the background color
7406 * @color: (allow-none): the color to assign (does not need to be allocated),
7407 * or %NULL to undo the effect of previous calls to
7408 * of gtk_widget_modify_bg().
7410 * Sets the background color for a widget in a particular state.
7411 * All other style values are left untouched. See also
7412 * gtk_widget_modify_style().
7414 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7415 * draw on their parent container's window and thus may not draw any
7416 * background themselves. This is the case for e.g. #GtkLabel. To modify
7417 * the background of such widgets, you have to set the background color
7418 * on their parent; if you want to set the background of a rectangular
7419 * area around a label, try placing the label in a #GtkEventBox widget
7420 * and setting the background color on that.
7423 gtk_widget_modify_bg (GtkWidget *widget,
7425 const GdkColor *color)
7427 g_return_if_fail (GTK_IS_WIDGET (widget));
7428 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7430 gtk_widget_modify_color_component (widget, GTK_RC_BG, state, color);
7434 * gtk_widget_modify_text:
7435 * @widget: a #GtkWidget
7436 * @state: the state for which to set the text color
7437 * @color: (allow-none): the color to assign (does not need to be allocated),
7438 * or %NULL to undo the effect of previous calls to
7439 * of gtk_widget_modify_text().
7441 * Sets the text color for a widget in a particular state. All other
7442 * style values are left untouched. The text color is the foreground
7443 * color used along with the base color (see gtk_widget_modify_base())
7444 * for widgets such as #GtkEntry and #GtkTextView. See also
7445 * gtk_widget_modify_style().
7448 gtk_widget_modify_text (GtkWidget *widget,
7450 const GdkColor *color)
7452 g_return_if_fail (GTK_IS_WIDGET (widget));
7453 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7455 gtk_widget_modify_color_component (widget, GTK_RC_TEXT, state, color);
7459 * gtk_widget_modify_base:
7460 * @widget: a #GtkWidget
7461 * @state: the state for which to set the base color
7462 * @color: (allow-none): the color to assign (does not need to be allocated),
7463 * or %NULL to undo the effect of previous calls to
7464 * of gtk_widget_modify_base().
7466 * Sets the base color for a widget in a particular state.
7467 * All other style values are left untouched. The base color
7468 * is the background color used along with the text color
7469 * (see gtk_widget_modify_text()) for widgets such as #GtkEntry
7470 * and #GtkTextView. See also gtk_widget_modify_style().
7472 * Note that "no window" widgets (which have the %GTK_NO_WINDOW flag set)
7473 * draw on their parent container's window and thus may not draw any
7474 * background themselves. This is the case for e.g. #GtkLabel. To modify
7475 * the background of such widgets, you have to set the base color on their
7476 * parent; if you want to set the background of a rectangular area around
7477 * a label, try placing the label in a #GtkEventBox widget and setting
7478 * the base color on that.
7481 gtk_widget_modify_base (GtkWidget *widget,
7483 const GdkColor *color)
7485 g_return_if_fail (GTK_IS_WIDGET (widget));
7486 g_return_if_fail (state >= GTK_STATE_NORMAL && state <= GTK_STATE_INSENSITIVE);
7488 gtk_widget_modify_color_component (widget, GTK_RC_BASE, state, color);
7492 modify_color_property (GtkWidget *widget,
7493 GtkRcStyle *rc_style,
7495 const GdkColor *color)
7497 GQuark type_name = g_type_qname (G_OBJECT_TYPE (widget));
7498 GQuark property_name = g_quark_from_string (name);
7502 GtkRcProperty rc_property = {0};
7505 rc_property.type_name = type_name;
7506 rc_property.property_name = property_name;
7507 rc_property.origin = NULL;
7509 color_name = gdk_color_to_string (color);
7510 g_value_init (&rc_property.value, G_TYPE_STRING);
7511 g_value_take_string (&rc_property.value, color_name);
7513 _gtk_rc_style_set_rc_property (rc_style, &rc_property);
7515 g_value_unset (&rc_property.value);
7518 _gtk_rc_style_unset_rc_property (rc_style, type_name, property_name);
7522 * gtk_widget_modify_cursor:
7523 * @widget: a #GtkWidget
7524 * @primary: the color to use for primary cursor (does not need to be
7525 * allocated), or %NULL to undo the effect of previous calls to
7526 * of gtk_widget_modify_cursor().
7527 * @secondary: the color to use for secondary cursor (does not need to be
7528 * allocated), or %NULL to undo the effect of previous calls to
7529 * of gtk_widget_modify_cursor().
7531 * Sets the cursor color to use in a widget, overriding the
7532 * #GtkWidget:cursor-color and #GtkWidget:secondary-cursor-color
7533 * style properties. All other style values are left untouched.
7534 * See also gtk_widget_modify_style().
7539 gtk_widget_modify_cursor (GtkWidget *widget,
7540 const GdkColor *primary,
7541 const GdkColor *secondary)
7543 GtkRcStyle *rc_style;
7545 g_return_if_fail (GTK_IS_WIDGET (widget));
7547 rc_style = gtk_widget_get_modifier_style (widget);
7549 modify_color_property (widget, rc_style, "cursor-color", primary);
7550 modify_color_property (widget, rc_style, "secondary-cursor-color", secondary);
7552 gtk_widget_modify_style (widget, rc_style);
7556 * gtk_widget_modify_font:
7557 * @widget: a #GtkWidget
7558 * @font_desc: (allow-none): the font description to use, or %NULL to undo
7559 * the effect of previous calls to gtk_widget_modify_font().
7561 * Sets the font to use for a widget. All other style values are left
7562 * untouched. See also gtk_widget_modify_style().
7565 gtk_widget_modify_font (GtkWidget *widget,
7566 PangoFontDescription *font_desc)
7568 GtkRcStyle *rc_style;
7570 g_return_if_fail (GTK_IS_WIDGET (widget));
7572 rc_style = gtk_widget_get_modifier_style (widget);
7574 if (rc_style->font_desc)
7575 pango_font_description_free (rc_style->font_desc);
7578 rc_style->font_desc = pango_font_description_copy (font_desc);
7580 rc_style->font_desc = NULL;
7582 gtk_widget_modify_style (widget, rc_style);
7586 gtk_widget_real_direction_changed (GtkWidget *widget,
7587 GtkTextDirection previous_direction)
7589 gtk_widget_queue_resize (widget);
7593 gtk_widget_real_style_set (GtkWidget *widget,
7594 GtkStyle *previous_style)
7596 GtkWidgetPrivate *priv = widget->priv;
7598 if (gtk_widget_get_realized (widget) &&
7599 gtk_widget_get_has_window (widget))
7600 gtk_style_set_background (priv->style, priv->window, priv->state);
7604 gtk_widget_set_style_internal (GtkWidget *widget,
7606 gboolean initial_emission)
7608 GtkWidgetPrivate *priv = widget->priv;
7610 g_object_ref (widget);
7611 g_object_freeze_notify (G_OBJECT (widget));
7613 if (priv->style != style)
7615 GtkStyle *previous_style;
7617 if (gtk_widget_get_realized (widget))
7619 gtk_widget_reset_shapes (widget);
7620 gtk_style_detach (priv->style);
7623 previous_style = priv->style;
7624 priv->style = style;
7625 g_object_ref (priv->style);
7627 if (gtk_widget_get_realized (widget))
7628 priv->style = gtk_style_attach (priv->style, priv->window);
7630 gtk_widget_update_pango_context (widget);
7631 g_signal_emit (widget,
7632 widget_signals[STYLE_SET],
7634 initial_emission ? NULL : previous_style);
7635 g_object_unref (previous_style);
7637 if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
7638 gtk_widget_queue_resize (widget);
7640 else if (initial_emission)
7642 gtk_widget_update_pango_context (widget);
7643 g_signal_emit (widget,
7644 widget_signals[STYLE_SET],
7648 g_object_notify (G_OBJECT (widget), "style");
7649 g_object_thaw_notify (G_OBJECT (widget));
7650 g_object_unref (widget);
7654 GtkWidget *previous_toplevel;
7655 GdkScreen *previous_screen;
7656 GdkScreen *new_screen;
7657 } HierarchyChangedInfo;
7660 do_screen_change (GtkWidget *widget,
7661 GdkScreen *old_screen,
7662 GdkScreen *new_screen)
7664 if (old_screen != new_screen)
7668 PangoContext *context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7670 g_object_set_qdata (G_OBJECT (widget), quark_pango_context, NULL);
7673 _gtk_tooltip_hide (widget);
7674 g_signal_emit (widget, widget_signals[SCREEN_CHANGED], 0, old_screen);
7679 gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
7680 gpointer client_data)
7682 GtkWidgetPrivate *priv = widget->priv;
7683 HierarchyChangedInfo *info = client_data;
7684 gboolean new_anchored = gtk_widget_is_toplevel (widget) ||
7685 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent));
7687 if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
7689 g_object_ref (widget);
7692 GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
7694 GTK_PRIVATE_UNSET_FLAG (widget, GTK_ANCHORED);
7696 g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
7697 do_screen_change (widget, info->previous_screen, info->new_screen);
7699 if (GTK_IS_CONTAINER (widget))
7700 gtk_container_forall (GTK_CONTAINER (widget),
7701 gtk_widget_propagate_hierarchy_changed_recurse,
7704 g_object_unref (widget);
7709 * _gtk_widget_propagate_hierarchy_changed:
7710 * @widget: a #GtkWidget
7711 * @previous_toplevel: Previous toplevel
7713 * Propagates changes in the anchored state to a widget and all
7714 * children, unsetting or setting the %ANCHORED flag, and
7715 * emitting #GtkWidget::hierarchy-changed.
7718 _gtk_widget_propagate_hierarchy_changed (GtkWidget *widget,
7719 GtkWidget *previous_toplevel)
7721 GtkWidgetPrivate *priv = widget->priv;
7722 HierarchyChangedInfo info;
7724 info.previous_toplevel = previous_toplevel;
7725 info.previous_screen = previous_toplevel ? gtk_widget_get_screen (previous_toplevel) : NULL;
7727 if (gtk_widget_is_toplevel (widget) ||
7728 (priv->parent && GTK_WIDGET_ANCHORED (priv->parent)))
7729 info.new_screen = gtk_widget_get_screen (widget);
7731 info.new_screen = NULL;
7733 if (info.previous_screen)
7734 g_object_ref (info.previous_screen);
7735 if (previous_toplevel)
7736 g_object_ref (previous_toplevel);
7738 gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
7740 if (previous_toplevel)
7741 g_object_unref (previous_toplevel);
7742 if (info.previous_screen)
7743 g_object_unref (info.previous_screen);
7747 gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
7748 gpointer client_data)
7750 HierarchyChangedInfo *info = client_data;
7752 g_object_ref (widget);
7754 do_screen_change (widget, info->previous_screen, info->new_screen);
7756 if (GTK_IS_CONTAINER (widget))
7757 gtk_container_forall (GTK_CONTAINER (widget),
7758 gtk_widget_propagate_screen_changed_recurse,
7761 g_object_unref (widget);
7765 * gtk_widget_is_composited:
7766 * @widget: a #GtkWidget
7768 * Whether @widget can rely on having its alpha channel
7769 * drawn correctly. On X11 this function returns whether a
7770 * compositing manager is running for @widget's screen.
7772 * Please note that the semantics of this call will change
7773 * in the future if used on a widget that has a composited
7774 * window in its hierarchy (as set by gdk_window_set_composited()).
7776 * Return value: %TRUE if the widget can rely on its alpha
7777 * channel being drawn correctly.
7782 gtk_widget_is_composited (GtkWidget *widget)
7786 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
7788 screen = gtk_widget_get_screen (widget);
7790 return gdk_screen_is_composited (screen);
7794 propagate_composited_changed (GtkWidget *widget,
7797 if (GTK_IS_CONTAINER (widget))
7799 gtk_container_forall (GTK_CONTAINER (widget),
7800 propagate_composited_changed,
7804 g_signal_emit (widget, widget_signals[COMPOSITED_CHANGED], 0);
7808 _gtk_widget_propagate_composited_changed (GtkWidget *widget)
7810 propagate_composited_changed (widget, NULL);
7814 * _gtk_widget_propagate_screen_changed:
7815 * @widget: a #GtkWidget
7816 * @previous_screen: Previous screen
7818 * Propagates changes in the screen for a widget to all
7819 * children, emitting #GtkWidget::screen-changed.
7822 _gtk_widget_propagate_screen_changed (GtkWidget *widget,
7823 GdkScreen *previous_screen)
7825 HierarchyChangedInfo info;
7827 info.previous_screen = previous_screen;
7828 info.new_screen = gtk_widget_get_screen (widget);
7830 if (previous_screen)
7831 g_object_ref (previous_screen);
7833 gtk_widget_propagate_screen_changed_recurse (widget, &info);
7835 if (previous_screen)
7836 g_object_unref (previous_screen);
7840 reset_rc_styles_recurse (GtkWidget *widget, gpointer data)
7842 if (gtk_widget_has_rc_style (widget))
7843 gtk_widget_reset_rc_style (widget);
7845 if (GTK_IS_CONTAINER (widget))
7846 gtk_container_forall (GTK_CONTAINER (widget),
7847 reset_rc_styles_recurse,
7853 * gtk_widget_reset_rc_styles:
7854 * @widget: a #GtkWidget.
7856 * Reset the styles of @widget and all descendents, so when
7857 * they are looked up again, they get the correct values
7858 * for the currently loaded RC file settings.
7860 * This function is not useful for applications.
7863 gtk_widget_reset_rc_styles (GtkWidget *widget)
7865 g_return_if_fail (GTK_IS_WIDGET (widget));
7867 reset_rc_styles_recurse (widget, NULL);
7871 * gtk_widget_get_default_style:
7873 * Returns the default style used by all widgets initially.
7875 * Returns: (transfer none): the default style. This #GtkStyle object is owned
7876 * by GTK+ and should not be modified or freed.
7879 gtk_widget_get_default_style (void)
7881 if (!gtk_default_style)
7883 gtk_default_style = gtk_style_new ();
7884 g_object_ref (gtk_default_style);
7887 return gtk_default_style;
7890 static PangoContext *
7891 gtk_widget_peek_pango_context (GtkWidget *widget)
7893 return g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7897 * gtk_widget_get_pango_context:
7898 * @widget: a #GtkWidget
7900 * Gets a #PangoContext with the appropriate font map, font description,
7901 * and base direction for this widget. Unlike the context returned
7902 * by gtk_widget_create_pango_context(), this context is owned by
7903 * the widget (it can be used until the screen for the widget changes
7904 * or the widget is removed from its toplevel), and will be updated to
7905 * match any changes to the widget's attributes.
7907 * If you create and keep a #PangoLayout using this context, you must
7908 * deal with changes to the context by calling pango_layout_context_changed()
7909 * on the layout in response to the #GtkWidget::style-set and
7910 * #GtkWidget::direction-changed signals for the widget.
7912 * Return value: (transfer none): the #PangoContext for the widget.
7915 gtk_widget_get_pango_context (GtkWidget *widget)
7917 PangoContext *context;
7919 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7921 context = g_object_get_qdata (G_OBJECT (widget), quark_pango_context);
7924 context = gtk_widget_create_pango_context (GTK_WIDGET (widget));
7925 g_object_set_qdata_full (G_OBJECT (widget),
7926 quark_pango_context,
7935 update_pango_context (GtkWidget *widget,
7936 PangoContext *context)
7938 GtkWidgetPrivate *priv = widget->priv;
7940 pango_context_set_font_description (context, priv->style->font_desc);
7941 pango_context_set_base_dir (context,
7942 gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
7943 PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL);
7947 gtk_widget_update_pango_context (GtkWidget *widget)
7949 PangoContext *context = gtk_widget_peek_pango_context (widget);
7955 update_pango_context (widget, context);
7957 screen = gtk_widget_get_screen_unchecked (widget);
7960 pango_cairo_context_set_resolution (context,
7961 gdk_screen_get_resolution (screen));
7962 pango_cairo_context_set_font_options (context,
7963 gdk_screen_get_font_options (screen));
7969 * gtk_widget_create_pango_context:
7970 * @widget: a #GtkWidget
7972 * Creates a new #PangoContext with the appropriate font map,
7973 * font description, and base direction for drawing text for
7974 * this widget. See also gtk_widget_get_pango_context().
7976 * Return value: (transfer full): the new #PangoContext
7979 gtk_widget_create_pango_context (GtkWidget *widget)
7982 PangoContext *context;
7984 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
7986 screen = gtk_widget_get_screen_unchecked (widget);
7989 GTK_NOTE (MULTIHEAD,
7990 g_warning ("gtk_widget_create_pango_context ()) called without screen"));
7992 screen = gdk_screen_get_default ();
7995 context = gdk_pango_context_get_for_screen (screen);
7997 update_pango_context (widget, context);
7998 pango_context_set_language (context, gtk_get_default_language ());
8004 * gtk_widget_create_pango_layout:
8005 * @widget: a #GtkWidget
8006 * @text: text to set on the layout (can be %NULL)
8008 * Creates a new #PangoLayout with the appropriate font map,
8009 * font description, and base direction for drawing text for
8012 * If you keep a #PangoLayout created in this way around, in order to
8013 * notify the layout of changes to the base direction or font of this
8014 * widget, you must call pango_layout_context_changed() in response to
8015 * the #GtkWidget::style-set and #GtkWidget::direction-changed signals
8018 * Return value: (transfer full): the new #PangoLayout
8021 gtk_widget_create_pango_layout (GtkWidget *widget,
8024 PangoLayout *layout;
8025 PangoContext *context;
8027 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8029 context = gtk_widget_get_pango_context (widget);
8030 layout = pango_layout_new (context);
8033 pango_layout_set_text (layout, text, -1);
8039 * gtk_widget_render_icon:
8040 * @widget: a #GtkWidget
8041 * @stock_id: a stock ID
8042 * @size: (type int): a stock size. A size of (GtkIconSize)-1 means
8043 * render at the size of the source and don't scale (if there are
8044 * multiple source sizes, GTK+ picks one of the available sizes).
8045 * @detail: (allow-none): render detail to pass to theme engine
8047 * A convenience function that uses the theme engine and RC file
8048 * settings for @widget to look up @stock_id and render it to
8049 * a pixbuf. @stock_id should be a stock icon ID such as
8050 * #GTK_STOCK_OPEN or #GTK_STOCK_OK. @size should be a size
8051 * such as #GTK_ICON_SIZE_MENU. @detail should be a string that
8052 * identifies the widget or code doing the rendering, so that
8053 * theme engines can special-case rendering for that widget or code.
8055 * The pixels in the returned #GdkPixbuf are shared with the rest of
8056 * the application and should not be modified. The pixbuf should be freed
8057 * after use with g_object_unref().
8059 * Return value: (transfer full): a new pixbuf, or %NULL if the
8060 * stock ID wasn't known
8063 gtk_widget_render_icon (GtkWidget *widget,
8064 const gchar *stock_id,
8066 const gchar *detail)
8068 GtkWidgetPrivate *priv;
8069 GtkIconSet *icon_set;
8072 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8073 g_return_val_if_fail (stock_id != NULL, NULL);
8074 g_return_val_if_fail (size > GTK_ICON_SIZE_INVALID || size == -1, NULL);
8076 priv = widget->priv;
8078 gtk_widget_ensure_style (widget);
8080 icon_set = gtk_style_lookup_icon_set (priv->style, stock_id);
8082 if (icon_set == NULL)
8085 retval = gtk_icon_set_render_icon (icon_set,
8087 gtk_widget_get_direction (widget),
8088 gtk_widget_get_state (widget),
8097 * gtk_widget_set_parent_window:
8098 * @widget: a #GtkWidget.
8099 * @parent_window: the new parent window.
8101 * Sets a non default parent window for @widget.
8104 gtk_widget_set_parent_window (GtkWidget *widget,
8105 GdkWindow *parent_window)
8107 GdkWindow *old_parent_window;
8109 g_return_if_fail (GTK_IS_WIDGET (widget));
8111 old_parent_window = g_object_get_qdata (G_OBJECT (widget),
8112 quark_parent_window);
8114 if (parent_window != old_parent_window)
8116 g_object_set_qdata (G_OBJECT (widget), quark_parent_window,
8118 if (old_parent_window)
8119 g_object_unref (old_parent_window);
8121 g_object_ref (parent_window);
8126 * gtk_widget_get_parent_window:
8127 * @widget: a #GtkWidget.
8129 * Gets @widget's parent window.
8131 * Returns: (transfer none): the parent window of @widget.
8134 gtk_widget_get_parent_window (GtkWidget *widget)
8136 GtkWidgetPrivate *priv;
8137 GdkWindow *parent_window;
8139 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8141 priv = widget->priv;
8143 parent_window = g_object_get_qdata (G_OBJECT (widget), quark_parent_window);
8145 return (parent_window != NULL) ? parent_window :
8146 (priv->parent != NULL) ? priv->parent->priv->window : NULL;
8151 * gtk_widget_set_child_visible:
8152 * @widget: a #GtkWidget
8153 * @is_visible: if %TRUE, @widget should be mapped along with its parent.
8155 * Sets whether @widget should be mapped along with its when its parent
8156 * is mapped and @widget has been shown with gtk_widget_show().
8158 * The child visibility can be set for widget before it is added to
8159 * a container with gtk_widget_set_parent(), to avoid mapping
8160 * children unnecessary before immediately unmapping them. However
8161 * it will be reset to its default state of %TRUE when the widget
8162 * is removed from a container.
8164 * Note that changing the child visibility of a widget does not
8165 * queue a resize on the widget. Most of the time, the size of
8166 * a widget is computed from all visible children, whether or
8167 * not they are mapped. If this is not the case, the container
8168 * can queue a resize itself.
8170 * This function is only useful for container implementations and
8171 * never should be called by an application.
8174 gtk_widget_set_child_visible (GtkWidget *widget,
8175 gboolean is_visible)
8177 GtkWidgetPrivate *priv;
8179 g_return_if_fail (GTK_IS_WIDGET (widget));
8180 g_return_if_fail (!gtk_widget_is_toplevel (widget));
8182 priv = widget->priv;
8184 g_object_ref (widget);
8187 GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
8190 GtkWidget *toplevel;
8192 GTK_PRIVATE_UNSET_FLAG (widget, GTK_CHILD_VISIBLE);
8194 toplevel = gtk_widget_get_toplevel (widget);
8195 if (toplevel != widget && gtk_widget_is_toplevel (toplevel))
8196 _gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
8199 if (priv->parent && gtk_widget_get_realized (priv->parent))
8201 if (gtk_widget_get_mapped (priv->parent) &&
8202 GTK_WIDGET_CHILD_VISIBLE (widget) &&
8203 gtk_widget_get_visible (widget))
8204 gtk_widget_map (widget);
8206 gtk_widget_unmap (widget);
8209 g_object_unref (widget);
8213 * gtk_widget_get_child_visible:
8214 * @widget: a #GtkWidget
8216 * Gets the value set with gtk_widget_set_child_visible().
8217 * If you feel a need to use this function, your code probably
8218 * needs reorganization.
8220 * This function is only useful for container implementations and
8221 * never should be called by an application.
8223 * Return value: %TRUE if the widget is mapped with the parent.
8226 gtk_widget_get_child_visible (GtkWidget *widget)
8228 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8230 return GTK_WIDGET_CHILD_VISIBLE (widget);
8234 gtk_widget_get_screen_unchecked (GtkWidget *widget)
8236 GtkWidget *toplevel;
8238 toplevel = gtk_widget_get_toplevel (widget);
8240 if (gtk_widget_is_toplevel (toplevel))
8242 if (GTK_IS_WINDOW (toplevel))
8243 return gtk_window_get_screen (GTK_WINDOW (toplevel));
8244 else if (GTK_IS_INVISIBLE (toplevel))
8245 return gtk_invisible_get_screen (GTK_INVISIBLE (widget));
8252 * gtk_widget_get_screen:
8253 * @widget: a #GtkWidget
8255 * Get the #GdkScreen from the toplevel window associated with
8256 * this widget. This function can only be called after the widget
8257 * has been added to a widget hierarchy with a #GtkWindow
8260 * In general, you should only create screen specific
8261 * resources when a widget has been realized, and you should
8262 * free those resources when the widget is unrealized.
8264 * Return value: (transfer none): the #GdkScreen for the toplevel for this widget.
8269 gtk_widget_get_screen (GtkWidget *widget)
8273 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8275 screen = gtk_widget_get_screen_unchecked (widget);
8282 g_warning (G_STRLOC ": Can't get associated screen"
8283 " for a widget unless it is inside a toplevel GtkWindow\n"
8284 " widget type is %s associated top level type is %s",
8285 g_type_name (G_OBJECT_TYPE(G_OBJECT (widget))),
8286 g_type_name (G_OBJECT_TYPE(G_OBJECT (toplevel))));
8288 return gdk_screen_get_default ();
8293 * gtk_widget_has_screen:
8294 * @widget: a #GtkWidget
8296 * Checks whether there is a #GdkScreen is associated with
8297 * this widget. All toplevel widgets have an associated
8298 * screen, and all widgets added into a hierarchy with a toplevel
8299 * window at the top.
8301 * Return value: %TRUE if there is a #GdkScreen associcated
8307 gtk_widget_has_screen (GtkWidget *widget)
8309 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8311 return (gtk_widget_get_screen_unchecked (widget) != NULL);
8315 * gtk_widget_get_display:
8316 * @widget: a #GtkWidget
8318 * Get the #GdkDisplay for the toplevel window associated with
8319 * this widget. This function can only be called after the widget
8320 * has been added to a widget hierarchy with a #GtkWindow at the top.
8322 * In general, you should only create display specific
8323 * resources when a widget has been realized, and you should
8324 * free those resources when the widget is unrealized.
8326 * Return value: (transfer none): the #GdkDisplay for the toplevel for this widget.
8331 gtk_widget_get_display (GtkWidget *widget)
8333 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8335 return gdk_screen_get_display (gtk_widget_get_screen (widget));
8339 * gtk_widget_get_root_window:
8340 * @widget: a #GtkWidget
8342 * Get the root window where this widget is located. This function can
8343 * only be called after the widget has been added to a widget
8344 * hierarchy with #GtkWindow at the top.
8346 * The root window is useful for such purposes as creating a popup
8347 * #GdkWindow associated with the window. In general, you should only
8348 * create display specific resources when a widget has been realized,
8349 * and you should free those resources when the widget is unrealized.
8351 * Return value: (transfer none): the #GdkWindow root window for the toplevel for this widget.
8356 gtk_widget_get_root_window (GtkWidget *widget)
8358 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8360 return gdk_screen_get_root_window (gtk_widget_get_screen (widget));
8364 * gtk_widget_child_focus:
8365 * @widget: a #GtkWidget
8366 * @direction: direction of focus movement
8368 * This function is used by custom widget implementations; if you're
8369 * writing an app, you'd use gtk_widget_grab_focus() to move the focus
8370 * to a particular widget, and gtk_container_set_focus_chain() to
8371 * change the focus tab order. So you may want to investigate those
8372 * functions instead.
8374 * gtk_widget_child_focus() is called by containers as the user moves
8375 * around the window using keyboard shortcuts. @direction indicates
8376 * what kind of motion is taking place (up, down, left, right, tab
8377 * forward, tab backward). gtk_widget_child_focus() emits the
8378 * #GtkWidget::focus signal; widgets override the default handler
8379 * for this signal in order to implement appropriate focus behavior.
8381 * The default ::focus handler for a widget should return %TRUE if
8382 * moving in @direction left the focus on a focusable location inside
8383 * that widget, and %FALSE if moving in @direction moved the focus
8384 * outside the widget. If returning %TRUE, widgets normally
8385 * call gtk_widget_grab_focus() to place the focus accordingly;
8386 * if returning %FALSE, they don't modify the current focus location.
8388 * Return value: %TRUE if focus ended up inside @widget
8391 gtk_widget_child_focus (GtkWidget *widget,
8392 GtkDirectionType direction)
8394 gboolean return_val;
8396 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8398 if (!gtk_widget_get_visible (widget) ||
8399 !gtk_widget_is_sensitive (widget))
8402 /* child widgets must set CAN_FOCUS, containers
8403 * don't have to though.
8405 if (!GTK_IS_CONTAINER (widget) &&
8406 !gtk_widget_get_can_focus (widget))
8409 g_signal_emit (widget,
8410 widget_signals[FOCUS],
8412 direction, &return_val);
8418 * gtk_widget_keynav_failed:
8419 * @widget: a #GtkWidget
8420 * @direction: direction of focus movement
8422 * This function should be called whenever keyboard navigation within
8423 * a single widget hits a boundary. The function emits the
8424 * #GtkWidget::keynav-failed signal on the widget and its return
8425 * value should be interpreted in a way similar to the return value of
8426 * gtk_widget_child_focus():
8428 * When %TRUE is returned, stay in the widget, the failed keyboard
8429 * navigation is Ok and/or there is nowhere we can/should move the
8432 * When %FALSE is returned, the caller should continue with keyboard
8433 * navigation outside the widget, e.g. by calling
8434 * gtk_widget_child_focus() on the widget's toplevel.
8436 * The default ::keynav-failed handler returns %TRUE for
8437 * %GTK_DIR_TAB_FORWARD and %GTK_DIR_TAB_BACKWARD. For the other
8438 * values of #GtkDirectionType, it looks at the
8439 * #GtkSettings:gtk-keynav-cursor-only setting and returns %FALSE
8440 * if the setting is %TRUE. This way the entire user interface
8441 * becomes cursor-navigatable on input devices such as mobile phones
8442 * which only have cursor keys but no tab key.
8444 * Whenever the default handler returns %TRUE, it also calls
8445 * gtk_widget_error_bell() to notify the user of the failed keyboard
8448 * A use case for providing an own implementation of ::keynav-failed
8449 * (either by connecting to it or by overriding it) would be a row of
8450 * #GtkEntry widgets where the user should be able to navigate the
8451 * entire row with the cursor keys, as e.g. known from user interfaces
8452 * that require entering license keys.
8454 * Return value: %TRUE if stopping keyboard navigation is fine, %FALSE
8455 * if the emitting widget should try to handle the keyboard
8456 * navigation attempt in its parent container(s).
8461 gtk_widget_keynav_failed (GtkWidget *widget,
8462 GtkDirectionType direction)
8464 gboolean return_val;
8466 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
8468 g_signal_emit (widget, widget_signals[KEYNAV_FAILED], 0,
8469 direction, &return_val);
8475 * gtk_widget_error_bell:
8476 * @widget: a #GtkWidget
8478 * Notifies the user about an input-related error on this widget.
8479 * If the #GtkSettings:gtk-error-bell setting is %TRUE, it calls
8480 * gdk_window_beep(), otherwise it does nothing.
8482 * Note that the effect of gdk_window_beep() can be configured in many
8483 * ways, depending on the windowing backend and the desktop environment
8484 * or window manager that is used.
8489 gtk_widget_error_bell (GtkWidget *widget)
8491 GtkWidgetPrivate *priv;
8492 GtkSettings* settings;
8495 g_return_if_fail (GTK_IS_WIDGET (widget));
8497 priv = widget->priv;
8499 settings = gtk_widget_get_settings (widget);
8503 g_object_get (settings,
8504 "gtk-error-bell", &beep,
8507 if (beep && priv->window)
8508 gdk_window_beep (priv->window);
8512 gtk_widget_set_usize_internal (GtkWidget *widget,
8516 GtkWidgetAuxInfo *aux_info;
8517 gboolean changed = FALSE;
8519 g_object_freeze_notify (G_OBJECT (widget));
8521 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
8523 if (width > -2 && aux_info->width != width)
8525 g_object_notify (G_OBJECT (widget), "width-request");
8526 aux_info->width = width;
8529 if (height > -2 && aux_info->height != height)
8531 g_object_notify (G_OBJECT (widget), "height-request");
8532 aux_info->height = height;
8536 if (gtk_widget_get_visible (widget) && changed)
8537 gtk_widget_queue_resize (widget);
8539 g_object_thaw_notify (G_OBJECT (widget));
8543 * gtk_widget_set_size_request:
8544 * @widget: a #GtkWidget
8545 * @width: width @widget should request, or -1 to unset
8546 * @height: height @widget should request, or -1 to unset
8548 * Sets the minimum size of a widget; that is, the widget's size
8549 * request will be @width by @height. You can use this function to
8550 * force a widget to be either larger or smaller than it normally
8553 * In most cases, gtk_window_set_default_size() is a better choice for
8554 * toplevel windows than this function; setting the default size will
8555 * still allow users to shrink the window. Setting the size request
8556 * will force them to leave the window at least as large as the size
8557 * request. When dealing with window sizes,
8558 * gtk_window_set_geometry_hints() can be a useful function as well.
8560 * Note the inherent danger of setting any fixed size - themes,
8561 * translations into other languages, different fonts, and user action
8562 * can all change the appropriate size for a given widget. So, it's
8563 * basically impossible to hardcode a size that will always be
8566 * The size request of a widget is the smallest size a widget can
8567 * accept while still functioning well and drawing itself correctly.
8568 * However in some strange cases a widget may be allocated less than
8569 * its requested size, and in many cases a widget may be allocated more
8570 * space than it requested.
8572 * If the size request in a given direction is -1 (unset), then
8573 * the "natural" size request of the widget will be used instead.
8575 * Widgets can't actually be allocated a size less than 1 by 1, but
8576 * you can pass 0,0 to this function to mean "as small as possible."
8578 * The size request set here does not include any margin from the
8579 * #GtkWidget properties margin-left, margin-right, margin-top, and
8580 * margin-bottom, but it does include pretty much all other padding
8581 * or border properties set by any subclass of #GtkWidget.
8584 gtk_widget_set_size_request (GtkWidget *widget,
8588 g_return_if_fail (GTK_IS_WIDGET (widget));
8589 g_return_if_fail (width >= -1);
8590 g_return_if_fail (height >= -1);
8597 gtk_widget_set_usize_internal (widget, width, height);
8602 * gtk_widget_get_size_request:
8603 * @widget: a #GtkWidget
8604 * @width: (out) (allow-none): return location for width, or %NULL
8605 * @height: (out) (allow-none): return location for height, or %NULL
8607 * Gets the size request that was explicitly set for the widget using
8608 * gtk_widget_set_size_request(). A value of -1 stored in @width or
8609 * @height indicates that that dimension has not been set explicitly
8610 * and the natural requisition of the widget will be used intead. See
8611 * gtk_widget_set_size_request(). To get the size a widget will
8612 * actually request, call gtk_size_request_get_preferred_size() instead of
8616 gtk_widget_get_size_request (GtkWidget *widget,
8620 const GtkWidgetAuxInfo *aux_info;
8622 g_return_if_fail (GTK_IS_WIDGET (widget));
8624 aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
8627 *width = aux_info->width;
8630 *height = aux_info->height;
8634 * gtk_widget_set_events:
8635 * @widget: a #GtkWidget
8636 * @events: event mask
8638 * Sets the event mask (see #GdkEventMask) for a widget. The event
8639 * mask determines which events a widget will receive. Keep in mind
8640 * that different widgets have different default event masks, and by
8641 * changing the event mask you may disrupt a widget's functionality,
8642 * so be careful. This function must be called while a widget is
8643 * unrealized. Consider gtk_widget_add_events() for widgets that are
8644 * already realized, or if you want to preserve the existing event
8645 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8646 * to get events on those widgets, place them inside a #GtkEventBox
8647 * and receive events on the event box.
8650 gtk_widget_set_events (GtkWidget *widget,
8653 g_return_if_fail (GTK_IS_WIDGET (widget));
8654 g_return_if_fail (!gtk_widget_get_realized (widget));
8656 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8657 GINT_TO_POINTER (events));
8658 g_object_notify (G_OBJECT (widget), "events");
8662 * gtk_widget_set_device_events:
8663 * @widget: a #GtkWidget
8664 * @device: a #GdkDevice
8665 * @events: event mask
8667 * Sets the device event mask (see #GdkEventMask) for a widget. The event
8668 * mask determines which events a widget will receive from @device. Keep
8669 * in mind that different widgets have different default event masks, and by
8670 * changing the event mask you may disrupt a widget's functionality,
8671 * so be careful. This function must be called while a widget is
8672 * unrealized. Consider gtk_widget_add_device_events() for widgets that are
8673 * already realized, or if you want to preserve the existing event
8674 * mask. This function can't be used with #GTK_NO_WINDOW widgets;
8675 * to get events on those widgets, place them inside a #GtkEventBox
8676 * and receive events on the event box.
8681 gtk_widget_set_device_events (GtkWidget *widget,
8683 GdkEventMask events)
8685 GHashTable *device_events;
8687 g_return_if_fail (GTK_IS_WIDGET (widget));
8688 g_return_if_fail (GDK_IS_DEVICE (device));
8689 g_return_if_fail (!gtk_widget_get_realized (widget));
8691 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8693 if (G_UNLIKELY (!device_events))
8695 device_events = g_hash_table_new (NULL, NULL);
8696 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8697 (GDestroyNotify) g_hash_table_unref);
8700 g_hash_table_insert (device_events, device, GUINT_TO_POINTER (events));
8704 gtk_widget_add_events_internal_list (GtkWidget *widget,
8711 for (l = window_list; l != NULL; l = l->next)
8713 GdkWindow *window = l->data;
8716 gdk_window_get_user_data (window, &user_data);
8717 if (user_data == widget)
8722 gdk_window_set_device_events (window, device, gdk_window_get_events (window) | events);
8724 gdk_window_set_events (window, gdk_window_get_events (window) | events);
8726 children = gdk_window_get_children (window);
8727 gtk_widget_add_events_internal_list (widget, device, events, children);
8728 g_list_free (children);
8734 gtk_widget_add_events_internal (GtkWidget *widget,
8738 GtkWidgetPrivate *priv = widget->priv;
8741 if (!gtk_widget_get_has_window (widget))
8742 window_list = gdk_window_get_children (priv->window);
8744 window_list = g_list_prepend (NULL, priv->window);
8746 gtk_widget_add_events_internal_list (widget, device, events, window_list);
8748 g_list_free (window_list);
8752 * gtk_widget_add_events:
8753 * @widget: a #GtkWidget
8754 * @events: an event mask, see #GdkEventMask
8756 * Adds the events in the bitfield @events to the event mask for
8757 * @widget. See gtk_widget_set_events() for details.
8760 gtk_widget_add_events (GtkWidget *widget,
8765 g_return_if_fail (GTK_IS_WIDGET (widget));
8767 old_events = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8768 g_object_set_qdata (G_OBJECT (widget), quark_event_mask,
8769 GINT_TO_POINTER (old_events | events));
8771 if (gtk_widget_get_realized (widget))
8772 gtk_widget_add_events_internal (widget, NULL, events);
8774 g_object_notify (G_OBJECT (widget), "events");
8778 * gtk_widget_add_device_events:
8779 * @widget: a #GtkWidget
8780 * @device: a #GdkDevice
8781 * @events: an event mask, see #GdkEventMask
8783 * Adds the device events in the bitfield @events to the event mask for
8784 * @widget. See gtk_widget_set_device_events() for details.
8789 gtk_widget_add_device_events (GtkWidget *widget,
8791 GdkEventMask events)
8793 GdkEventMask old_events;
8794 GHashTable *device_events;
8796 g_return_if_fail (GTK_IS_WIDGET (widget));
8797 g_return_if_fail (GDK_IS_DEVICE (device));
8799 old_events = gtk_widget_get_device_events (widget, device);
8801 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
8803 if (G_UNLIKELY (!device_events))
8805 device_events = g_hash_table_new (NULL, NULL);
8806 g_object_set_qdata_full (G_OBJECT (widget), quark_device_event_mask, device_events,
8807 (GDestroyNotify) g_hash_table_unref);
8810 g_hash_table_insert (device_events, device,
8811 GUINT_TO_POINTER (old_events | events));
8813 if (gtk_widget_get_realized (widget))
8814 gtk_widget_add_events_internal (widget, device, events);
8816 g_object_notify (G_OBJECT (widget), "events");
8820 * gtk_widget_set_extension_events:
8821 * @widget: a #GtkWidget
8822 * @mode: bitfield of extension events to receive
8824 * Sets the extension events mask to @mode. See #GdkExtensionMode
8825 * and gdk_input_set_extension_events().
8828 gtk_widget_set_extension_events (GtkWidget *widget,
8829 GdkExtensionMode mode)
8831 g_return_if_fail (GTK_IS_WIDGET (widget));
8833 if (gtk_widget_get_realized (widget))
8834 gtk_widget_set_extension_events_internal (widget, mode, NULL);
8836 g_object_set_qdata (G_OBJECT (widget), quark_extension_event_mode,
8837 GINT_TO_POINTER (mode));
8838 g_object_notify (G_OBJECT (widget), "extension-events");
8842 * gtk_widget_get_toplevel:
8843 * @widget: a #GtkWidget
8845 * This function returns the topmost widget in the container hierarchy
8846 * @widget is a part of. If @widget has no parent widgets, it will be
8847 * returned as the topmost widget. No reference will be added to the
8848 * returned widget; it should not be unreferenced.
8850 * Note the difference in behavior vs. gtk_widget_get_ancestor();
8851 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)</literal>
8853 * %NULL if @widget wasn't inside a toplevel window, and if the
8854 * window was inside a #GtkWindow-derived widget which was in turn
8855 * inside the toplevel #GtkWindow. While the second case may
8856 * seem unlikely, it actually happens when a #GtkPlug is embedded
8857 * inside a #GtkSocket within the same application.
8859 * To reliably find the toplevel #GtkWindow, use
8860 * gtk_widget_get_toplevel() and check if the %TOPLEVEL flags
8861 * is set on the result.
8863 * GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
8864 * if (gtk_widget_is_toplevel (toplevel))
8866 * /* Perform action on toplevel. */
8870 * Return value: (transfer none): the topmost ancestor of @widget, or @widget itself
8871 * if there's no ancestor.
8874 gtk_widget_get_toplevel (GtkWidget *widget)
8876 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8878 while (widget->priv->parent)
8879 widget = widget->priv->parent;
8885 * gtk_widget_get_ancestor:
8886 * @widget: a #GtkWidget
8887 * @widget_type: ancestor type
8889 * Gets the first ancestor of @widget with type @widget_type. For example,
8890 * <literal>gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)</literal> gets
8891 * the first #GtkBox that's an ancestor of @widget. No reference will be
8892 * added to the returned widget; it should not be unreferenced. See note
8893 * about checking for a toplevel #GtkWindow in the docs for
8894 * gtk_widget_get_toplevel().
8896 * Note that unlike gtk_widget_is_ancestor(), gtk_widget_get_ancestor()
8897 * considers @widget to be an ancestor of itself.
8899 * Return value: (transfer none): the ancestor widget, or %NULL if not found
8902 gtk_widget_get_ancestor (GtkWidget *widget,
8905 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8907 while (widget && !g_type_is_a (G_OBJECT_TYPE (widget), widget_type))
8908 widget = widget->priv->parent;
8910 if (!(widget && g_type_is_a (G_OBJECT_TYPE (widget), widget_type)))
8917 * gtk_widget_get_visual:
8918 * @widget: a #GtkWidget
8920 * Gets the visual that will be used to render @widget.
8922 * Return value: (transfer none): the visual for @widget
8925 gtk_widget_get_visual (GtkWidget *widget)
8929 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8931 for (w = widget; w != NULL; w = w->priv->parent)
8933 if (gtk_widget_get_has_window (w) &&
8935 return gdk_window_get_visual (w->priv->window);
8937 if (GTK_IS_WINDOW (w))
8938 return _gtk_window_get_visual (GTK_WINDOW (w));
8941 return gdk_screen_get_system_visual (gdk_screen_get_default ());
8945 * gtk_widget_get_settings:
8946 * @widget: a #GtkWidget
8948 * Gets the settings object holding the settings (global property
8949 * settings, RC file information, etc) used for this widget.
8951 * Note that this function can only be called when the #GtkWidget
8952 * is attached to a toplevel, since the settings object is specific
8953 * to a particular #GdkScreen.
8955 * Return value: (transfer none): the relevant #GtkSettings object
8958 gtk_widget_get_settings (GtkWidget *widget)
8960 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
8962 return gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
8966 * gtk_widget_get_events:
8967 * @widget: a #GtkWidget
8969 * Returns the event mask for the widget (a bitfield containing flags
8970 * from the #GdkEventMask enumeration). These are the events that the widget
8973 * Return value: event mask for @widget
8976 gtk_widget_get_events (GtkWidget *widget)
8978 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
8980 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_event_mask));
8984 * gtk_widget_get_device_events:
8985 * @widget: a #GtkWidget
8986 * @device: a #GdkDevice
8988 * Returns the events mask for the widget corresponding to an specific device. These
8989 * are the events that the widget will receive when @device operates on it.
8991 * Returns: device event mask for @widget
8996 gtk_widget_get_device_events (GtkWidget *widget,
8999 GHashTable *device_events;
9001 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9002 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
9004 device_events = g_object_get_qdata (G_OBJECT (widget), quark_device_event_mask);
9009 return GPOINTER_TO_UINT (g_hash_table_lookup (device_events, device));
9013 * gtk_widget_get_extension_events:
9014 * @widget: a #GtkWidget
9016 * Retrieves the extension events the widget will receive; see
9017 * gdk_input_set_extension_events().
9019 * Return value: extension events for @widget
9022 gtk_widget_get_extension_events (GtkWidget *widget)
9024 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
9026 return GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (widget), quark_extension_event_mode));
9030 * gtk_widget_get_pointer:
9031 * @widget: a #GtkWidget
9032 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9033 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9035 * Obtains the location of the mouse pointer in widget coordinates.
9036 * Widget coordinates are a bit odd; for historical reasons, they are
9037 * defined as @widget->window coordinates for widgets that are not
9038 * #GTK_NO_WINDOW widgets, and are relative to @widget->allocation.x,
9039 * @widget->allocation.y for widgets that are #GTK_NO_WINDOW widgets.
9042 gtk_widget_get_pointer (GtkWidget *widget,
9046 GtkWidgetPrivate *priv;
9048 g_return_if_fail (GTK_IS_WIDGET (widget));
9050 priv = widget->priv;
9057 if (gtk_widget_get_realized (widget))
9059 gdk_window_get_pointer (priv->window, x, y, NULL);
9061 if (!gtk_widget_get_has_window (widget))
9064 *x -= priv->allocation.x;
9066 *y -= priv->allocation.y;
9072 * gtk_widget_is_ancestor:
9073 * @widget: a #GtkWidget
9074 * @ancestor: another #GtkWidget
9076 * Determines whether @widget is somewhere inside @ancestor, possibly with
9077 * intermediate containers.
9079 * Return value: %TRUE if @ancestor contains @widget as a child,
9080 * grandchild, great grandchild, etc.
9083 gtk_widget_is_ancestor (GtkWidget *widget,
9084 GtkWidget *ancestor)
9086 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
9087 g_return_val_if_fail (ancestor != NULL, FALSE);
9091 if (widget->priv->parent == ancestor)
9093 widget = widget->priv->parent;
9099 static GQuark quark_composite_name = 0;
9102 * gtk_widget_set_composite_name:
9103 * @widget: a #GtkWidget.
9104 * @name: the name to set
9106 * Sets a widgets composite name. The widget must be
9107 * a composite child of its parent; see gtk_widget_push_composite_child().
9110 gtk_widget_set_composite_name (GtkWidget *widget,
9113 g_return_if_fail (GTK_IS_WIDGET (widget));
9114 g_return_if_fail ((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0);
9115 g_return_if_fail (name != NULL);
9117 if (!quark_composite_name)
9118 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
9120 g_object_set_qdata_full (G_OBJECT (widget),
9121 quark_composite_name,
9127 * gtk_widget_get_composite_name:
9128 * @widget: a #GtkWidget
9130 * Obtains the composite name of a widget.
9132 * Returns: the composite name of @widget, or %NULL if @widget is not
9133 * a composite child. The string should be freed when it is no
9137 gtk_widget_get_composite_name (GtkWidget *widget)
9139 GtkWidgetPrivate *priv;
9141 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9143 priv = widget->priv;
9145 if (((GTK_OBJECT_FLAGS (widget) & GTK_COMPOSITE_CHILD) != 0) && priv->parent)
9146 return _gtk_container_child_composite_name (GTK_CONTAINER (priv->parent),
9153 * gtk_widget_push_composite_child:
9155 * Makes all newly-created widgets as composite children until
9156 * the corresponding gtk_widget_pop_composite_child() call.
9158 * A composite child is a child that's an implementation detail of the
9159 * container it's inside and should not be visible to people using the
9160 * container. Composite children aren't treated differently by GTK (but
9161 * see gtk_container_foreach() vs. gtk_container_forall()), but e.g. GUI
9162 * builders might want to treat them in a different way.
9164 * Here is a simple example:
9166 * gtk_widget_push_composite_child ();
9167 * scrolled_window->hscrollbar = gtk_hscrollbar_new (hadjustment);
9168 * gtk_widget_set_composite_name (scrolled_window->hscrollbar, "hscrollbar");
9169 * gtk_widget_pop_composite_child ();
9170 * gtk_widget_set_parent (scrolled_window->hscrollbar,
9171 * GTK_WIDGET (scrolled_window));
9172 * g_object_ref (scrolled_window->hscrollbar);
9176 gtk_widget_push_composite_child (void)
9178 composite_child_stack++;
9182 * gtk_widget_pop_composite_child:
9184 * Cancels the effect of a previous call to gtk_widget_push_composite_child().
9187 gtk_widget_pop_composite_child (void)
9189 if (composite_child_stack)
9190 composite_child_stack--;
9194 gtk_widget_emit_direction_changed (GtkWidget *widget,
9195 GtkTextDirection old_dir)
9197 gtk_widget_update_pango_context (widget);
9199 g_signal_emit (widget, widget_signals[DIRECTION_CHANGED], 0, old_dir);
9203 * gtk_widget_set_direction:
9204 * @widget: a #GtkWidget
9205 * @dir: the new direction
9207 * Sets the reading direction on a particular widget. This direction
9208 * controls the primary direction for widgets containing text,
9209 * and also the direction in which the children of a container are
9210 * packed. The ability to set the direction is present in order
9211 * so that correct localization into languages with right-to-left
9212 * reading directions can be done. Generally, applications will
9213 * let the default reading direction present, except for containers
9214 * where the containers are arranged in an order that is explicitely
9215 * visual rather than logical (such as buttons for text justification).
9217 * If the direction is set to %GTK_TEXT_DIR_NONE, then the value
9218 * set by gtk_widget_set_default_direction() will be used.
9221 gtk_widget_set_direction (GtkWidget *widget,
9222 GtkTextDirection dir)
9224 GtkTextDirection old_dir;
9226 g_return_if_fail (GTK_IS_WIDGET (widget));
9227 g_return_if_fail (dir >= GTK_TEXT_DIR_NONE && dir <= GTK_TEXT_DIR_RTL);
9229 old_dir = gtk_widget_get_direction (widget);
9231 if (dir == GTK_TEXT_DIR_NONE)
9232 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_SET);
9235 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_SET);
9236 if (dir == GTK_TEXT_DIR_LTR)
9237 GTK_PRIVATE_SET_FLAG (widget, GTK_DIRECTION_LTR);
9239 GTK_PRIVATE_UNSET_FLAG (widget, GTK_DIRECTION_LTR);
9242 if (old_dir != gtk_widget_get_direction (widget))
9243 gtk_widget_emit_direction_changed (widget, old_dir);
9247 * gtk_widget_get_direction:
9248 * @widget: a #GtkWidget
9250 * Gets the reading direction for a particular widget. See
9251 * gtk_widget_set_direction().
9253 * Return value: the reading direction for the widget.
9256 gtk_widget_get_direction (GtkWidget *widget)
9258 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_TEXT_DIR_LTR);
9260 if (GTK_WIDGET_DIRECTION_SET (widget))
9261 return GTK_WIDGET_DIRECTION_LTR (widget) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
9263 return gtk_default_direction;
9267 gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
9269 GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
9271 g_object_ref (widget);
9273 if (!GTK_WIDGET_DIRECTION_SET (widget))
9274 gtk_widget_emit_direction_changed (widget, old_dir);
9276 if (GTK_IS_CONTAINER (widget))
9277 gtk_container_forall (GTK_CONTAINER (widget),
9278 gtk_widget_set_default_direction_recurse,
9281 g_object_unref (widget);
9285 * gtk_widget_set_default_direction:
9286 * @dir: the new default direction. This cannot be
9287 * %GTK_TEXT_DIR_NONE.
9289 * Sets the default reading direction for widgets where the
9290 * direction has not been explicitly set by gtk_widget_set_direction().
9293 gtk_widget_set_default_direction (GtkTextDirection dir)
9295 g_return_if_fail (dir == GTK_TEXT_DIR_RTL || dir == GTK_TEXT_DIR_LTR);
9297 if (dir != gtk_default_direction)
9299 GList *toplevels, *tmp_list;
9300 GtkTextDirection old_dir = gtk_default_direction;
9302 gtk_default_direction = dir;
9304 tmp_list = toplevels = gtk_window_list_toplevels ();
9305 g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
9309 gtk_widget_set_default_direction_recurse (tmp_list->data,
9310 GUINT_TO_POINTER (old_dir));
9311 g_object_unref (tmp_list->data);
9312 tmp_list = tmp_list->next;
9315 g_list_free (toplevels);
9320 * gtk_widget_get_default_direction:
9322 * Obtains the current default reading direction. See
9323 * gtk_widget_set_default_direction().
9325 * Return value: the current default direction.
9328 gtk_widget_get_default_direction (void)
9330 return gtk_default_direction;
9334 gtk_widget_dispose (GObject *object)
9336 GtkWidget *widget = GTK_WIDGET (object);
9337 GtkWidgetPrivate *priv = widget->priv;
9340 gtk_container_remove (GTK_CONTAINER (priv->parent), widget);
9341 else if (gtk_widget_get_visible (widget))
9342 gtk_widget_hide (widget);
9344 GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
9345 if (gtk_widget_get_realized (widget))
9346 gtk_widget_unrealize (widget);
9348 G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
9352 gtk_widget_real_destroy (GtkObject *object)
9354 /* gtk_object_destroy() will already hold a refcount on object */
9355 GtkWidget *widget = GTK_WIDGET (object);
9356 GtkWidgetPrivate *priv = widget->priv;
9358 /* wipe accelerator closures (keep order) */
9359 g_object_set_qdata (G_OBJECT (widget), quark_accel_path, NULL);
9360 g_object_set_qdata (G_OBJECT (widget), quark_accel_closures, NULL);
9362 /* Callers of add_mnemonic_label() should disconnect on ::destroy */
9363 g_object_set_qdata (G_OBJECT (widget), quark_mnemonic_labels, NULL);
9365 gtk_grab_remove (widget);
9367 g_object_unref (priv->style);
9368 priv->style = gtk_widget_get_default_style ();
9369 g_object_ref (priv->style);
9371 GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
9375 gtk_widget_finalize (GObject *object)
9377 GtkWidget *widget = GTK_WIDGET (object);
9378 GtkWidgetPrivate *priv = widget->priv;
9379 GtkWidgetAuxInfo *aux_info;
9380 GtkAccessible *accessible;
9382 gtk_grab_remove (widget);
9384 g_object_unref (priv->style);
9387 g_free (priv->name);
9389 aux_info =_gtk_widget_get_aux_info (widget, FALSE);
9391 gtk_widget_aux_info_destroy (aux_info);
9393 accessible = g_object_get_qdata (G_OBJECT (widget), quark_accessible_object);
9395 g_object_unref (accessible);
9397 G_OBJECT_CLASS (gtk_widget_parent_class)->finalize (object);
9400 /*****************************************
9401 * gtk_widget_real_map:
9406 *****************************************/
9409 gtk_widget_real_map (GtkWidget *widget)
9411 GtkWidgetPrivate *priv = widget->priv;
9413 g_assert (gtk_widget_get_realized (widget));
9415 if (!gtk_widget_get_mapped (widget))
9417 gtk_widget_set_mapped (widget, TRUE);
9419 if (gtk_widget_get_has_window (widget))
9420 gdk_window_show (priv->window);
9424 /*****************************************
9425 * gtk_widget_real_unmap:
9430 *****************************************/
9433 gtk_widget_real_unmap (GtkWidget *widget)
9435 GtkWidgetPrivate *priv = widget->priv;
9437 if (gtk_widget_get_mapped (widget))
9439 gtk_widget_set_mapped (widget, FALSE);
9441 if (gtk_widget_get_has_window (widget))
9442 gdk_window_hide (priv->window);
9446 /*****************************************
9447 * gtk_widget_real_realize:
9452 *****************************************/
9455 gtk_widget_real_realize (GtkWidget *widget)
9457 GtkWidgetPrivate *priv = widget->priv;
9459 g_assert (!gtk_widget_get_has_window (widget));
9461 gtk_widget_set_realized (widget, TRUE);
9464 priv->window = gtk_widget_get_parent_window (widget);
9465 g_object_ref (priv->window);
9467 priv->style = gtk_style_attach (priv->style, priv->window);
9470 /*****************************************
9471 * gtk_widget_real_unrealize:
9476 *****************************************/
9479 gtk_widget_real_unrealize (GtkWidget *widget)
9481 GtkWidgetPrivate *priv = widget->priv;
9483 if (gtk_widget_get_mapped (widget))
9484 gtk_widget_real_unmap (widget);
9486 gtk_widget_set_mapped (widget, FALSE);
9488 /* printf ("unrealizing %s\n", g_type_name (G_TYPE_FROM_INSTANCE (widget)));
9491 /* We must do unrealize child widget BEFORE container widget.
9492 * gdk_window_destroy() destroys specified xwindow and its sub-xwindows.
9493 * So, unrealizing container widget bofore its children causes the problem
9494 * (for example, gdk_ic_destroy () with destroyed window causes crash. )
9497 if (GTK_IS_CONTAINER (widget))
9498 gtk_container_forall (GTK_CONTAINER (widget),
9499 (GtkCallback) gtk_widget_unrealize,
9502 gtk_style_detach (priv->style);
9503 if (gtk_widget_get_has_window (widget))
9505 gdk_window_set_user_data (priv->window, NULL);
9506 gdk_window_destroy (priv->window);
9507 priv->window = NULL;
9511 g_object_unref (priv->window);
9512 priv->window = NULL;
9515 gtk_selection_remove_all (widget);
9517 gtk_widget_set_realized (widget, FALSE);
9521 gtk_widget_real_size_request (GtkWidget *widget,
9522 GtkRequisition *requisition)
9524 requisition->width = 0;
9525 requisition->height = 0;
9529 gtk_widget_real_adjust_size_request (GtkWidget *widget,
9530 GtkOrientation orientation,
9535 const GtkWidgetAuxInfo *aux_info;
9537 aux_info =_gtk_widget_get_aux_info_or_defaults (widget);
9539 if (orientation == GTK_ORIENTATION_HORIZONTAL &&
9540 aux_info->width > 0)
9542 *minimum_size = MAX (*minimum_size, aux_info->width);
9544 else if (orientation == GTK_ORIENTATION_VERTICAL &&
9545 aux_info->height > 0)
9547 *minimum_size = MAX (*minimum_size, aux_info->height);
9550 /* Fix it if set_size_request made natural size smaller than min size.
9551 * This would also silently fix broken widgets, but we warn about them
9552 * in gtksizerequest.c when calling their size request vfuncs.
9554 *natural_size = MAX (*natural_size, *minimum_size);
9556 if (orientation == GTK_ORIENTATION_HORIZONTAL)
9558 *minimum_size += (aux_info->margin.left + aux_info->margin.right);
9559 *natural_size += (aux_info->margin.left + aux_info->margin.right);
9563 *minimum_size += (aux_info->margin.top + aux_info->margin.bottom);
9564 *natural_size += (aux_info->margin.top + aux_info->margin.bottom);
9569 * _gtk_widget_peek_request_cache:
9571 * Returns the address of the widget's request cache (strictly for
9572 * internal use in gtksizerequest.c)
9574 * Return value: the address of @widget's size request cache.
9577 _gtk_widget_peek_request_cache (GtkWidget *widget)
9579 /* Don't bother slowing things down with the return_if_fail guards here */
9580 return &widget->priv->requests;
9584 * _gtk_widget_set_device_window:
9585 * @widget: a #GtkWidget.
9586 * @device: a #GdkDevice.
9587 * @window: the new device window.
9589 * Sets pointer window for @widget and @device. Does not ref @window.
9590 * Actually stores it on the #GdkScreen, but you don't need to know that.
9593 _gtk_widget_set_device_window (GtkWidget *widget,
9597 GtkWidgetPrivate *priv;
9599 GHashTable *device_window;
9601 g_return_if_fail (GTK_IS_WIDGET (widget));
9602 g_return_if_fail (GDK_IS_DEVICE (device));
9603 g_return_if_fail (!window || GDK_IS_WINDOW (window));
9605 priv = widget->priv;
9607 if (!gtk_widget_get_realized (widget))
9610 screen = gdk_window_get_screen (priv->window);
9611 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9613 if (G_UNLIKELY (!device_window))
9615 device_window = g_hash_table_new (NULL, NULL);
9616 g_object_set_qdata_full (G_OBJECT (screen),
9617 quark_pointer_window,
9619 (GDestroyNotify) g_hash_table_destroy);
9623 g_hash_table_insert (device_window, device, window);
9625 g_hash_table_remove (device_window, device);
9629 * _gtk_widget_get_device_window:
9630 * @widget: a #GtkWidget.
9631 * @device: a #GdkDevice.
9633 * Return value: the device window set on the #GdkScreen @widget is attached
9637 _gtk_widget_get_device_window (GtkWidget *widget,
9640 GtkWidgetPrivate *priv;
9642 GHashTable *device_window;
9646 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9647 g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
9649 priv = widget->priv;
9651 if (!gtk_widget_get_realized (widget))
9654 screen = gdk_window_get_screen (priv->window);
9655 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9657 if (G_UNLIKELY (!device_window))
9660 window = g_hash_table_lookup (device_window, device);
9665 gdk_window_get_user_data (window, (gpointer *) &w);
9674 * _gtk_widget_list_devices:
9675 * @widget: a #GtkWidget.
9677 * Returns the list of #GdkDevices that is currently on top of any widget #GdkWindow.
9678 * Free the list with g_list_free(), the elements are owned by GTK+ and must not
9682 _gtk_widget_list_devices (GtkWidget *widget)
9684 GtkWidgetPrivate *priv;
9686 GHashTableIter iter;
9687 GHashTable *device_window;
9688 GList *devices = NULL;
9689 gpointer key, value;
9691 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
9693 priv = widget->priv;
9695 if (!gtk_widget_get_realized (widget))
9698 screen = gdk_window_get_screen (priv->window);
9699 device_window = g_object_get_qdata (G_OBJECT (screen), quark_pointer_window);
9701 if (G_UNLIKELY (!device_window))
9704 g_hash_table_iter_init (&iter, device_window);
9706 while (g_hash_table_iter_next (&iter, &key, &value))
9708 GdkDevice *device = key;
9709 GdkWindow *window = value;
9714 gdk_window_get_user_data (window, (gpointer *) &w);
9717 devices = g_list_prepend (devices, device);
9725 synth_crossing (GtkWidget *widget,
9729 GdkCrossingMode mode,
9730 GdkNotifyType detail)
9734 event = gdk_event_new (type);
9736 event->crossing.window = g_object_ref (window);
9737 event->crossing.send_event = TRUE;
9738 event->crossing.subwindow = g_object_ref (window);
9739 event->crossing.time = GDK_CURRENT_TIME;
9740 event->crossing.x = event->crossing.y = 0;
9741 event->crossing.x_root = event->crossing.y_root = 0;
9742 event->crossing.mode = mode;
9743 event->crossing.detail = detail;
9744 event->crossing.focus = FALSE;
9745 event->crossing.state = 0;
9746 gdk_event_set_device (event, device);
9749 widget = gtk_get_event_widget (event);
9752 gtk_widget_event_internal (widget, event);
9754 gdk_event_free (event);
9758 * _gtk_widget_synthesize_crossing:
9759 * @from: the #GtkWidget the virtual pointer is leaving.
9760 * @to: the #GtkWidget the virtual pointer is moving to.
9761 * @mode: the #GdkCrossingMode to place on the synthesized events.
9763 * Generate crossing event(s) on widget state (sensitivity) or GTK+ grab change.
9765 * The real pointer window is the window that most recently received an enter notify
9766 * event. Windows that don't select for crossing events can't become the real
9767 * poiner window. The real pointer widget that owns the real pointer window. The
9768 * effective pointer window is the same as the real pointer window unless the real
9769 * pointer widget is either insensitive or there is a grab on a widget that is not
9770 * an ancestor of the real pointer widget (in which case the effective pointer
9771 * window should be the root window).
9773 * When the effective pointer window is the same as the real poiner window, we
9774 * receive crossing events from the windowing system. When the effective pointer
9775 * window changes to become different from the real pointer window we synthesize
9776 * crossing events, attempting to follow X protocol rules:
9778 * When the root window becomes the effective pointer window:
9779 * - leave notify on real pointer window, detail Ancestor
9780 * - leave notify on all of its ancestors, detail Virtual
9781 * - enter notify on root window, detail Inferior
9783 * When the root window ceases to be the effective pointer window:
9784 * - leave notify on root window, detail Inferior
9785 * - enter notify on all ancestors of real pointer window, detail Virtual
9786 * - enter notify on real pointer window, detail Ancestor
9789 _gtk_widget_synthesize_crossing (GtkWidget *from,
9792 GdkCrossingMode mode)
9794 GdkWindow *from_window = NULL, *to_window = NULL;
9796 g_return_if_fail (from != NULL || to != NULL);
9800 from_window = _gtk_widget_get_device_window (from, device);
9803 from_window = from->priv->window;
9808 to_window = _gtk_widget_get_device_window (to, device);
9811 to_window = to->priv->window;
9814 if (from_window == NULL && to_window == NULL)
9816 else if (from_window != NULL && to_window == NULL)
9818 GList *from_ancestors = NULL, *list;
9819 GdkWindow *from_ancestor = from_window;
9821 while (from_ancestor != NULL)
9823 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9824 if (from_ancestor == NULL)
9826 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9829 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9830 device, mode, GDK_NOTIFY_ANCESTOR);
9831 for (list = g_list_last (from_ancestors); list; list = list->prev)
9833 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9834 device, mode, GDK_NOTIFY_VIRTUAL);
9837 /* XXX: enter/inferior on root window? */
9839 g_list_free (from_ancestors);
9841 else if (from_window == NULL && to_window != NULL)
9843 GList *to_ancestors = NULL, *list;
9844 GdkWindow *to_ancestor = to_window;
9846 while (to_ancestor != NULL)
9848 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9849 if (to_ancestor == NULL)
9851 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9854 /* XXX: leave/inferior on root window? */
9856 for (list = to_ancestors; list; list = list->next)
9858 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9859 device, mode, GDK_NOTIFY_VIRTUAL);
9861 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9862 device, mode, GDK_NOTIFY_ANCESTOR);
9864 g_list_free (to_ancestors);
9866 else if (from_window == to_window)
9870 GList *from_ancestors = NULL, *to_ancestors = NULL, *list;
9871 GdkWindow *from_ancestor = from_window, *to_ancestor = to_window;
9873 while (from_ancestor != NULL || to_ancestor != NULL)
9875 if (from_ancestor != NULL)
9877 from_ancestor = gdk_window_get_effective_parent (from_ancestor);
9878 if (from_ancestor == to_window)
9881 from_ancestors = g_list_prepend (from_ancestors, from_ancestor);
9883 if (to_ancestor != NULL)
9885 to_ancestor = gdk_window_get_effective_parent (to_ancestor);
9886 if (to_ancestor == from_window)
9889 to_ancestors = g_list_prepend (to_ancestors, to_ancestor);
9892 if (to_ancestor == from_window)
9894 if (mode != GDK_CROSSING_GTK_UNGRAB)
9895 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9896 device, mode, GDK_NOTIFY_INFERIOR);
9897 for (list = to_ancestors; list; list = list->next)
9898 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9899 device, mode, GDK_NOTIFY_VIRTUAL);
9900 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9901 device, mode, GDK_NOTIFY_ANCESTOR);
9903 else if (from_ancestor == to_window)
9905 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9906 device, mode, GDK_NOTIFY_ANCESTOR);
9907 for (list = g_list_last (from_ancestors); list; list = list->prev)
9909 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9910 device, mode, GDK_NOTIFY_VIRTUAL);
9912 if (mode != GDK_CROSSING_GTK_GRAB)
9913 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9914 device, mode, GDK_NOTIFY_INFERIOR);
9918 while (from_ancestors != NULL && to_ancestors != NULL
9919 && from_ancestors->data == to_ancestors->data)
9921 from_ancestors = g_list_delete_link (from_ancestors,
9923 to_ancestors = g_list_delete_link (to_ancestors, to_ancestors);
9926 synth_crossing (from, GDK_LEAVE_NOTIFY, from_window,
9927 device, mode, GDK_NOTIFY_NONLINEAR);
9929 for (list = g_list_last (from_ancestors); list; list = list->prev)
9931 synth_crossing (NULL, GDK_LEAVE_NOTIFY, (GdkWindow *) list->data,
9932 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9934 for (list = to_ancestors; list; list = list->next)
9936 synth_crossing (NULL, GDK_ENTER_NOTIFY, (GdkWindow *) list->data,
9937 device, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
9939 synth_crossing (to, GDK_ENTER_NOTIFY, to_window,
9940 device, mode, GDK_NOTIFY_NONLINEAR);
9942 g_list_free (from_ancestors);
9943 g_list_free (to_ancestors);
9948 gtk_widget_propagate_state (GtkWidget *widget,
9951 GtkWidgetPrivate *priv = widget->priv;
9952 guint8 old_state = gtk_widget_get_state (widget);
9953 guint8 old_saved_state = priv->saved_state;
9955 /* don't call this function with state==GTK_STATE_INSENSITIVE,
9956 * parent_sensitive==TRUE on a sensitive widget
9960 if (data->parent_sensitive)
9961 GTK_OBJECT_FLAGS (widget) |= GTK_PARENT_SENSITIVE;
9963 GTK_OBJECT_FLAGS (widget) &= ~(GTK_PARENT_SENSITIVE);
9965 if (gtk_widget_is_sensitive (widget))
9967 if (data->state_restoration)
9968 priv->state = priv->saved_state;
9970 priv->state = data->state;
9974 if (!data->state_restoration)
9976 if (data->state != GTK_STATE_INSENSITIVE)
9977 priv->saved_state = data->state;
9979 else if (gtk_widget_get_state (widget) != GTK_STATE_INSENSITIVE)
9980 priv->saved_state = gtk_widget_get_state (widget);
9981 priv->state = GTK_STATE_INSENSITIVE;
9984 if (gtk_widget_is_focus (widget) && !gtk_widget_is_sensitive (widget))
9988 window = gtk_widget_get_toplevel (widget);
9989 if (window && gtk_widget_is_toplevel (window))
9990 gtk_window_set_focus (GTK_WINDOW (window), NULL);
9993 if (old_state != gtk_widget_get_state (widget) ||
9994 old_saved_state != priv->saved_state)
9996 g_object_ref (widget);
9998 if (!gtk_widget_is_sensitive (widget) && gtk_widget_has_grab (widget))
9999 gtk_grab_remove (widget);
10001 g_signal_emit (widget, widget_signals[STATE_CHANGED], 0, old_state);
10003 if (!GTK_WIDGET_SHADOWED (widget))
10005 GList *event_windows = NULL;
10006 GList *devices, *d;
10008 devices = _gtk_widget_list_devices (widget);
10010 for (d = devices; d; d = d->next)
10016 window = _gtk_widget_get_device_window (widget, device);
10018 /* Do not propagate more than once to the
10019 * same window if non-multidevice aware.
10021 if (!gdk_window_get_support_multidevice (window) &&
10022 g_list_find (event_windows, window))
10025 if (!gtk_widget_is_sensitive (widget))
10026 _gtk_widget_synthesize_crossing (widget, NULL, d->data,
10027 GDK_CROSSING_STATE_CHANGED);
10028 else if (old_state == GTK_STATE_INSENSITIVE)
10029 _gtk_widget_synthesize_crossing (NULL, widget, d->data,
10030 GDK_CROSSING_STATE_CHANGED);
10032 event_windows = g_list_prepend (event_windows, window);
10035 g_list_free (event_windows);
10036 g_list_free (devices);
10039 if (GTK_IS_CONTAINER (widget))
10041 data->parent_sensitive = (gtk_widget_is_sensitive (widget) != FALSE);
10042 if (data->use_forall)
10043 gtk_container_forall (GTK_CONTAINER (widget),
10044 (GtkCallback) gtk_widget_propagate_state,
10047 gtk_container_foreach (GTK_CONTAINER (widget),
10048 (GtkCallback) gtk_widget_propagate_state,
10051 g_object_unref (widget);
10055 static const GtkWidgetAuxInfo default_aux_info = {
10063 * _gtk_widget_get_aux_info:
10064 * @widget: a #GtkWidget
10065 * @create: if %TRUE, create the structure if it doesn't exist
10067 * Get the #GtkWidgetAuxInfo structure for the widget.
10069 * Return value: the #GtkAuxInfo structure for the widget, or
10070 * %NULL if @create is %FALSE and one doesn't already exist.
10073 _gtk_widget_get_aux_info (GtkWidget *widget,
10076 GtkWidgetAuxInfo *aux_info;
10078 aux_info = g_object_get_qdata (G_OBJECT (widget), quark_aux_info);
10079 if (!aux_info && create)
10081 aux_info = g_slice_new0 (GtkWidgetAuxInfo);
10083 *aux_info = default_aux_info;
10085 g_object_set_qdata (G_OBJECT (widget), quark_aux_info, aux_info);
10091 static const GtkWidgetAuxInfo*
10092 _gtk_widget_get_aux_info_or_defaults (GtkWidget *widget)
10094 GtkWidgetAuxInfo *aux_info;
10096 aux_info = _gtk_widget_get_aux_info (widget, FALSE);
10097 if (aux_info == NULL)
10099 return &default_aux_info;
10107 /*****************************************
10108 * gtk_widget_aux_info_destroy:
10113 *****************************************/
10116 gtk_widget_aux_info_destroy (GtkWidgetAuxInfo *aux_info)
10118 g_slice_free (GtkWidgetAuxInfo, aux_info);
10122 * gtk_widget_shape_combine_region:
10123 * @widget: a #GtkWidget
10124 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10126 * Sets a shape for this widget's GDK window. This allows for
10127 * transparent windows etc., see gdk_window_shape_combine_region()
10128 * for more information.
10133 gtk_widget_shape_combine_region (GtkWidget *widget,
10134 cairo_region_t *region)
10136 GtkWidgetPrivate *priv;
10138 g_return_if_fail (GTK_IS_WIDGET (widget));
10139 /* set_shape doesn't work on widgets without gdk window */
10140 g_return_if_fail (gtk_widget_get_has_window (widget));
10142 priv = widget->priv;
10144 if (region == NULL)
10146 GTK_PRIVATE_UNSET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10149 gdk_window_shape_combine_region (priv->window, NULL, 0, 0);
10151 g_object_set_qdata (G_OBJECT (widget), quark_shape_info, NULL);
10155 GTK_PRIVATE_SET_FLAG (widget, GTK_HAS_SHAPE_MASK);
10157 g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info,
10158 cairo_region_copy (region),
10159 (GDestroyNotify) cairo_region_destroy);
10161 /* set shape if widget has a gdk window already.
10162 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10165 gdk_window_shape_combine_region (priv->window, region, 0, 0);
10170 * gtk_widget_input_shape_combine_region:
10171 * @widget: a #GtkWidget
10172 * @region: (allow-none): shape to be added, or %NULL to remove an existing shape
10174 * Sets an input shape for this widget's GDK window. This allows for
10175 * windows which react to mouse click in a nonrectangular region, see
10176 * gdk_window_input_shape_combine_region() for more information.
10181 gtk_widget_input_shape_combine_region (GtkWidget *widget,
10182 cairo_region_t *region)
10184 GtkWidgetPrivate *priv;
10186 g_return_if_fail (GTK_IS_WIDGET (widget));
10187 /* set_shape doesn't work on widgets without gdk window */
10188 g_return_if_fail (gtk_widget_get_has_window (widget));
10190 priv = widget->priv;
10192 if (region == NULL)
10195 gdk_window_input_shape_combine_region (priv->window, NULL, 0, 0);
10197 g_object_set_qdata (G_OBJECT (widget), quark_input_shape_info, NULL);
10201 g_object_set_qdata_full (G_OBJECT (widget), quark_input_shape_info,
10202 cairo_region_copy (region),
10203 (GDestroyNotify) cairo_region_destroy);
10205 /* set shape if widget has a gdk window already.
10206 * otherwise the shape is scheduled to be set by gtk_widget_realize().
10209 gdk_window_input_shape_combine_region (priv->window, region, 0, 0);
10215 gtk_reset_shapes_recurse (GtkWidget *widget,
10221 gdk_window_get_user_data (window, &data);
10222 if (data != widget)
10225 gdk_window_shape_combine_region (window, NULL, 0, 0);
10226 for (list = gdk_window_peek_children (window); list; list = list->next)
10227 gtk_reset_shapes_recurse (widget, list->data);
10231 * gtk_widget_reset_shapes:
10232 * @widget: a #GtkWidget
10234 * Recursively resets the shape on this widget and its descendants.
10237 gtk_widget_reset_shapes (GtkWidget *widget)
10239 GtkWidgetPrivate *priv;
10241 g_return_if_fail (GTK_IS_WIDGET (widget));
10242 g_return_if_fail (gtk_widget_get_realized (widget));
10244 priv = widget->priv;
10246 if (!GTK_WIDGET_HAS_SHAPE_MASK (widget))
10247 gtk_reset_shapes_recurse (widget, priv->window);
10250 /* style properties
10254 * gtk_widget_class_install_style_property_parser:
10255 * @klass: a #GtkWidgetClass
10256 * @pspec: the #GParamSpec for the style property
10257 * @parser: the parser for the style property
10259 * Installs a style property on a widget class.
10262 gtk_widget_class_install_style_property_parser (GtkWidgetClass *klass,
10264 GtkRcPropertyParser parser)
10266 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10267 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10268 g_return_if_fail (pspec->flags & G_PARAM_READABLE);
10269 g_return_if_fail (!(pspec->flags & (G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT)));
10271 if (g_param_spec_pool_lookup (style_property_spec_pool, pspec->name, G_OBJECT_CLASS_TYPE (klass), FALSE))
10273 g_warning (G_STRLOC ": class `%s' already contains a style property named `%s'",
10274 G_OBJECT_CLASS_NAME (klass),
10279 g_param_spec_ref_sink (pspec);
10280 g_param_spec_set_qdata (pspec, quark_property_parser, (gpointer) parser);
10281 g_param_spec_pool_insert (style_property_spec_pool, pspec, G_OBJECT_CLASS_TYPE (klass));
10285 * gtk_widget_class_install_style_property:
10286 * @klass: a #GtkWidgetClass
10287 * @pspec: the #GParamSpec for the property
10289 * Installs a style property on a widget class. The parser for the
10290 * style property is determined by the value type of @pspec.
10293 gtk_widget_class_install_style_property (GtkWidgetClass *klass,
10296 GtkRcPropertyParser parser;
10298 g_return_if_fail (GTK_IS_WIDGET_CLASS (klass));
10299 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
10301 parser = _gtk_rc_property_parser_from_type (G_PARAM_SPEC_VALUE_TYPE (pspec));
10303 gtk_widget_class_install_style_property_parser (klass, pspec, parser);
10307 * gtk_widget_class_find_style_property:
10308 * @klass: a #GtkWidgetClass
10309 * @property_name: the name of the style property to find
10310 * @returns: (allow-none): the #GParamSpec of the style property or %NULL if @class has no
10311 * style property with that name.
10313 * Finds a style property of a widget class by name.
10318 gtk_widget_class_find_style_property (GtkWidgetClass *klass,
10319 const gchar *property_name)
10321 g_return_val_if_fail (property_name != NULL, NULL);
10323 return g_param_spec_pool_lookup (style_property_spec_pool,
10325 G_OBJECT_CLASS_TYPE (klass),
10330 * gtk_widget_class_list_style_properties:
10331 * @klass: a #GtkWidgetClass
10332 * @n_properties: location to return the number of style properties found
10333 * @returns: an newly allocated array of #GParamSpec*. The array must
10334 * be freed with g_free().
10336 * Returns all style properties of a widget class.
10341 gtk_widget_class_list_style_properties (GtkWidgetClass *klass,
10342 guint *n_properties)
10344 GParamSpec **pspecs;
10347 pspecs = g_param_spec_pool_list (style_property_spec_pool,
10348 G_OBJECT_CLASS_TYPE (klass),
10357 * gtk_widget_style_get_property:
10358 * @widget: a #GtkWidget
10359 * @property_name: the name of a style property
10360 * @value: location to return the property value
10362 * Gets the value of a style property of @widget.
10365 gtk_widget_style_get_property (GtkWidget *widget,
10366 const gchar *property_name,
10369 GtkWidgetPrivate *priv;
10372 g_return_if_fail (GTK_IS_WIDGET (widget));
10373 g_return_if_fail (property_name != NULL);
10374 g_return_if_fail (G_IS_VALUE (value));
10376 priv = widget->priv;
10378 g_object_ref (widget);
10379 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10381 G_OBJECT_TYPE (widget),
10384 g_warning ("%s: widget class `%s' has no property named `%s'",
10386 G_OBJECT_TYPE_NAME (widget),
10390 const GValue *peek_value;
10392 peek_value = _gtk_style_peek_property_value (priv->style,
10393 G_OBJECT_TYPE (widget),
10395 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10397 /* auto-conversion of the caller's value type
10399 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
10400 g_value_copy (peek_value, value);
10401 else if (g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
10402 g_value_transform (peek_value, value);
10404 g_warning ("can't retrieve style property `%s' of type `%s' as value of type `%s'",
10406 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
10407 G_VALUE_TYPE_NAME (value));
10409 g_object_unref (widget);
10413 * gtk_widget_style_get_valist:
10414 * @widget: a #GtkWidget
10415 * @first_property_name: the name of the first property to get
10416 * @var_args: a <type>va_list</type> of pairs of property names and
10417 * locations to return the property values, starting with the location
10418 * for @first_property_name.
10420 * Non-vararg variant of gtk_widget_style_get(). Used primarily by language
10424 gtk_widget_style_get_valist (GtkWidget *widget,
10425 const gchar *first_property_name,
10428 GtkWidgetPrivate *priv;
10431 g_return_if_fail (GTK_IS_WIDGET (widget));
10433 priv = widget->priv;
10435 g_object_ref (widget);
10437 name = first_property_name;
10440 const GValue *peek_value;
10444 pspec = g_param_spec_pool_lookup (style_property_spec_pool,
10446 G_OBJECT_TYPE (widget),
10450 g_warning ("%s: widget class `%s' has no property named `%s'",
10452 G_OBJECT_TYPE_NAME (widget),
10456 /* style pspecs are always readable so we can spare that check here */
10458 peek_value = _gtk_style_peek_property_value (priv->style,
10459 G_OBJECT_TYPE (widget),
10461 (GtkRcPropertyParser) g_param_spec_get_qdata (pspec, quark_property_parser));
10462 G_VALUE_LCOPY (peek_value, var_args, 0, &error);
10465 g_warning ("%s: %s", G_STRLOC, error);
10470 name = va_arg (var_args, gchar*);
10473 g_object_unref (widget);
10477 * gtk_widget_style_get:
10478 * @widget: a #GtkWidget
10479 * @first_property_name: the name of the first property to get
10480 * @Varargs: pairs of property names and locations to
10481 * return the property values, starting with the location for
10482 * @first_property_name, terminated by %NULL.
10484 * Gets the values of a multiple style properties of @widget.
10487 gtk_widget_style_get (GtkWidget *widget,
10488 const gchar *first_property_name,
10493 g_return_if_fail (GTK_IS_WIDGET (widget));
10495 va_start (var_args, first_property_name);
10496 gtk_widget_style_get_valist (widget, first_property_name, var_args);
10502 * @widget: a #GtkWidget
10503 * @path_length: (out) (allow-none): location to store length of the path, or %NULL
10504 * @path: (out) (allow-none): location to store allocated path string, or %NULL
10505 * @path_reversed: (out) (allow-none): location to store allocated reverse path string, or %NULL
10507 * Obtains the full path to @widget. The path is simply the name of a
10508 * widget and all its parents in the container hierarchy, separated by
10509 * periods. The name of a widget comes from
10510 * gtk_widget_get_name(). Paths are used to apply styles to a widget
10511 * in gtkrc configuration files. Widget names are the type of the
10512 * widget by default (e.g. "GtkButton") or can be set to an
10513 * application-specific value with gtk_widget_set_name(). By setting
10514 * the name of a widget, you allow users or theme authors to apply
10515 * styles to that specific widget in their gtkrc
10516 * file. @path_reversed_p fills in the path in reverse order,
10517 * i.e. starting with @widget's name instead of starting with the name
10518 * of @widget's outermost ancestor.
10521 gtk_widget_path (GtkWidget *widget,
10522 guint *path_length,
10524 gchar **path_reversed)
10526 static gchar *rev_path = NULL;
10527 static guint tmp_path_len = 0;
10530 g_return_if_fail (GTK_IS_WIDGET (widget));
10535 const gchar *string;
10540 string = gtk_widget_get_name (widget);
10541 l = strlen (string);
10542 while (tmp_path_len <= len + l + 1)
10544 tmp_path_len += INIT_PATH_SIZE;
10545 rev_path = g_realloc (rev_path, tmp_path_len);
10547 s = string + l - 1;
10548 d = rev_path + len;
10549 while (s >= string)
10553 widget = widget->priv->parent;
10556 rev_path[len++] = '.';
10558 rev_path[len++] = 0;
10563 *path_length = len - 1;
10565 *path_reversed = g_strdup (rev_path);
10568 *path = g_strdup (rev_path);
10569 g_strreverse (*path);
10574 * gtk_widget_class_path:
10575 * @widget: a #GtkWidget
10576 * @path_length: (out) (allow-none): location to store the length of the class path, or %NULL
10577 * @path: (out) (allow-none): location to store the class path as an allocated string, or %NULL
10578 * @path_reversed: (out) (allow-none): location to store the reverse class path as an allocated
10581 * Same as gtk_widget_path(), but always uses the name of a widget's type,
10582 * never uses a custom name set with gtk_widget_set_name().
10586 gtk_widget_class_path (GtkWidget *widget,
10587 guint *path_length,
10589 gchar **path_reversed)
10591 static gchar *rev_path = NULL;
10592 static guint tmp_path_len = 0;
10595 g_return_if_fail (GTK_IS_WIDGET (widget));
10600 const gchar *string;
10605 string = g_type_name (G_OBJECT_TYPE (widget));
10606 l = strlen (string);
10607 while (tmp_path_len <= len + l + 1)
10609 tmp_path_len += INIT_PATH_SIZE;
10610 rev_path = g_realloc (rev_path, tmp_path_len);
10612 s = string + l - 1;
10613 d = rev_path + len;
10614 while (s >= string)
10618 widget = widget->priv->parent;
10621 rev_path[len++] = '.';
10623 rev_path[len++] = 0;
10628 *path_length = len - 1;
10630 *path_reversed = g_strdup (rev_path);
10633 *path = g_strdup (rev_path);
10634 g_strreverse (*path);
10639 * gtk_requisition_new:
10641 * Allocates a new #GtkRequisition structure and initializes its elements to zero.
10643 * Returns: a new empty #GtkRequisition. The newly allocated #GtkRequisition should
10644 * be freed with gtk_requisition_free().
10649 gtk_requisition_new (void)
10651 return g_slice_new0 (GtkRequisition);
10655 * gtk_requisition_copy:
10656 * @requisition: a #GtkRequisition
10658 * Copies a #GtkRequisition.
10660 * Returns: a copy of @requisition
10663 gtk_requisition_copy (const GtkRequisition *requisition)
10665 return g_slice_dup (GtkRequisition, requisition);
10669 * gtk_requisition_free:
10670 * @requisition: a #GtkRequisition
10672 * Frees a #GtkRequisition.
10675 gtk_requisition_free (GtkRequisition *requisition)
10677 g_slice_free (GtkRequisition, requisition);
10680 G_DEFINE_BOXED_TYPE (GtkRequisition, gtk_requisition,
10681 gtk_requisition_copy,
10682 gtk_requisition_free)
10685 * gtk_widget_get_accessible:
10686 * @widget: a #GtkWidget
10688 * Returns the accessible object that describes the widget to an
10689 * assistive technology.
10691 * If no accessibility library is loaded (i.e. no ATK implementation library is
10692 * loaded via <envar>GTK_MODULES</envar> or via another application library,
10693 * such as libgnome), then this #AtkObject instance may be a no-op. Likewise,
10694 * if no class-specific #AtkObject implementation is available for the widget
10695 * instance in question, it will inherit an #AtkObject implementation from the
10696 * first ancestor class for which such an implementation is defined.
10698 * The documentation of the <ulink url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
10699 * library contains more information about accessible objects and their uses.
10701 * Returns: (transfer none): the #AtkObject associated with @widget
10704 gtk_widget_get_accessible (GtkWidget *widget)
10706 GtkWidgetClass *klass;
10708 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
10710 klass = GTK_WIDGET_GET_CLASS (widget);
10712 g_return_val_if_fail (klass->get_accessible != NULL, NULL);
10714 return klass->get_accessible (widget);
10718 gtk_widget_real_get_accessible (GtkWidget *widget)
10720 AtkObject* accessible;
10722 accessible = g_object_get_qdata (G_OBJECT (widget),
10723 quark_accessible_object);
10726 AtkObjectFactory *factory;
10727 AtkRegistry *default_registry;
10729 default_registry = atk_get_default_registry ();
10730 factory = atk_registry_get_factory (default_registry,
10731 G_TYPE_FROM_INSTANCE (widget));
10733 atk_object_factory_create_accessible (factory,
10734 G_OBJECT (widget));
10735 g_object_set_qdata (G_OBJECT (widget),
10736 quark_accessible_object,
10743 * Initialize a AtkImplementorIface instance's virtual pointers as
10744 * appropriate to this implementor's class (GtkWidget).
10747 gtk_widget_accessible_interface_init (AtkImplementorIface *iface)
10749 iface->ref_accessible = gtk_widget_ref_accessible;
10753 gtk_widget_ref_accessible (AtkImplementor *implementor)
10755 AtkObject *accessible;
10757 accessible = gtk_widget_get_accessible (GTK_WIDGET (implementor));
10759 g_object_ref (accessible);
10764 * GtkBuildable implementation
10766 static GQuark quark_builder_has_default = 0;
10767 static GQuark quark_builder_has_focus = 0;
10768 static GQuark quark_builder_atk_relations = 0;
10769 static GQuark quark_builder_set_name = 0;
10772 gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
10774 quark_builder_has_default = g_quark_from_static_string ("gtk-builder-has-default");
10775 quark_builder_has_focus = g_quark_from_static_string ("gtk-builder-has-focus");
10776 quark_builder_atk_relations = g_quark_from_static_string ("gtk-builder-atk-relations");
10777 quark_builder_set_name = g_quark_from_static_string ("gtk-builder-set-name");
10779 iface->set_name = gtk_widget_buildable_set_name;
10780 iface->get_name = gtk_widget_buildable_get_name;
10781 iface->get_internal_child = gtk_widget_buildable_get_internal_child;
10782 iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
10783 iface->parser_finished = gtk_widget_buildable_parser_finished;
10784 iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
10785 iface->custom_finished = gtk_widget_buildable_custom_finished;
10789 gtk_widget_buildable_set_name (GtkBuildable *buildable,
10792 g_object_set_qdata_full (G_OBJECT (buildable), quark_builder_set_name,
10793 g_strdup (name), g_free);
10796 static const gchar *
10797 gtk_widget_buildable_get_name (GtkBuildable *buildable)
10799 return g_object_get_qdata (G_OBJECT (buildable), quark_builder_set_name);
10803 gtk_widget_buildable_get_internal_child (GtkBuildable *buildable,
10804 GtkBuilder *builder,
10805 const gchar *childname)
10807 if (strcmp (childname, "accessible") == 0)
10808 return G_OBJECT (gtk_widget_get_accessible (GTK_WIDGET (buildable)));
10814 gtk_widget_buildable_set_buildable_property (GtkBuildable *buildable,
10815 GtkBuilder *builder,
10817 const GValue *value)
10819 if (strcmp (name, "has-default") == 0 && g_value_get_boolean (value))
10820 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_default,
10821 GINT_TO_POINTER (TRUE));
10822 else if (strcmp (name, "has-focus") == 0 && g_value_get_boolean (value))
10823 g_object_set_qdata (G_OBJECT (buildable), quark_builder_has_focus,
10824 GINT_TO_POINTER (TRUE));
10826 g_object_set_property (G_OBJECT (buildable), name, value);
10831 gchar *action_name;
10832 GString *description;
10834 gboolean translatable;
10844 free_action (AtkActionData *data, gpointer user_data)
10846 g_free (data->action_name);
10847 g_string_free (data->description, TRUE);
10848 g_free (data->context);
10849 g_slice_free (AtkActionData, data);
10853 free_relation (AtkRelationData *data, gpointer user_data)
10855 g_free (data->target);
10856 g_free (data->type);
10857 g_slice_free (AtkRelationData, data);
10861 gtk_widget_buildable_parser_finished (GtkBuildable *buildable,
10862 GtkBuilder *builder)
10864 GSList *atk_relations;
10866 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_default))
10867 gtk_widget_grab_default (GTK_WIDGET (buildable));
10868 if (g_object_get_qdata (G_OBJECT (buildable), quark_builder_has_focus))
10869 gtk_widget_grab_focus (GTK_WIDGET (buildable));
10871 atk_relations = g_object_get_qdata (G_OBJECT (buildable),
10872 quark_builder_atk_relations);
10875 AtkObject *accessible;
10876 AtkRelationSet *relation_set;
10879 AtkRelationType relation_type;
10880 AtkObject *target_accessible;
10882 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
10883 relation_set = atk_object_ref_relation_set (accessible);
10885 for (l = atk_relations; l; l = l->next)
10887 AtkRelationData *relation = (AtkRelationData*)l->data;
10889 target = gtk_builder_get_object (builder, relation->target);
10892 g_warning ("Target object %s in <relation> does not exist",
10896 target_accessible = gtk_widget_get_accessible (GTK_WIDGET (target));
10897 g_assert (target_accessible != NULL);
10899 relation_type = atk_relation_type_for_name (relation->type);
10900 if (relation_type == ATK_RELATION_NULL)
10902 g_warning ("<relation> type %s not found",
10906 atk_relation_set_add_relation_by_type (relation_set, relation_type,
10907 target_accessible);
10909 g_object_unref (relation_set);
10911 g_slist_foreach (atk_relations, (GFunc)free_relation, NULL);
10912 g_slist_free (atk_relations);
10913 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
10922 } AccessibilitySubParserData;
10925 accessibility_start_element (GMarkupParseContext *context,
10926 const gchar *element_name,
10927 const gchar **names,
10928 const gchar **values,
10929 gpointer user_data,
10932 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
10934 gint line_number, char_number;
10936 if (strcmp (element_name, "relation") == 0)
10938 gchar *target = NULL;
10939 gchar *type = NULL;
10940 AtkRelationData *relation;
10942 for (i = 0; names[i]; i++)
10944 if (strcmp (names[i], "target") == 0)
10945 target = g_strdup (values[i]);
10946 else if (strcmp (names[i], "type") == 0)
10947 type = g_strdup (values[i]);
10950 g_markup_parse_context_get_position (context,
10953 g_set_error (error,
10955 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
10956 "%s:%d:%d '%s' is not a valid attribute of <%s>",
10958 line_number, char_number, names[i], "relation");
10965 if (!target || !type)
10967 g_markup_parse_context_get_position (context,
10970 g_set_error (error,
10972 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
10973 "%s:%d:%d <%s> requires attribute \"%s\"",
10975 line_number, char_number, "relation",
10976 type ? "target" : "type");
10982 relation = g_slice_new (AtkRelationData);
10983 relation->target = target;
10984 relation->type = type;
10986 data->relations = g_slist_prepend (data->relations, relation);
10988 else if (strcmp (element_name, "action") == 0)
10990 const gchar *action_name = NULL;
10991 const gchar *description = NULL;
10992 const gchar *msg_context = NULL;
10993 gboolean translatable = FALSE;
10994 AtkActionData *action;
10996 for (i = 0; names[i]; i++)
10998 if (strcmp (names[i], "action_name") == 0)
10999 action_name = values[i];
11000 else if (strcmp (names[i], "description") == 0)
11001 description = values[i];
11002 else if (strcmp (names[i], "translatable") == 0)
11004 if (!_gtk_builder_boolean_from_string (values[i], &translatable, error))
11007 else if (strcmp (names[i], "comments") == 0)
11009 /* do nothing, comments are for translators */
11011 else if (strcmp (names[i], "context") == 0)
11012 msg_context = values[i];
11015 g_markup_parse_context_get_position (context,
11018 g_set_error (error,
11020 GTK_BUILDER_ERROR_INVALID_ATTRIBUTE,
11021 "%s:%d:%d '%s' is not a valid attribute of <%s>",
11023 line_number, char_number, names[i], "action");
11030 g_markup_parse_context_get_position (context,
11033 g_set_error (error,
11035 GTK_BUILDER_ERROR_MISSING_ATTRIBUTE,
11036 "%s:%d:%d <%s> requires attribute \"%s\"",
11038 line_number, char_number, "action",
11043 action = g_slice_new (AtkActionData);
11044 action->action_name = g_strdup (action_name);
11045 action->description = g_string_new (description);
11046 action->context = g_strdup (msg_context);
11047 action->translatable = translatable;
11049 data->actions = g_slist_prepend (data->actions, action);
11051 else if (strcmp (element_name, "accessibility") == 0)
11054 g_warning ("Unsupported tag for GtkWidget: %s\n", element_name);
11058 accessibility_text (GMarkupParseContext *context,
11061 gpointer user_data,
11064 AccessibilitySubParserData *data = (AccessibilitySubParserData*)user_data;
11066 if (strcmp (g_markup_parse_context_get_element (context), "action") == 0)
11068 AtkActionData *action = data->actions->data;
11070 g_string_append_len (action->description, text, text_len);
11074 static const GMarkupParser accessibility_parser =
11076 accessibility_start_element,
11078 accessibility_text,
11087 } AccelGroupParserData;
11090 accel_group_start_element (GMarkupParseContext *context,
11091 const gchar *element_name,
11092 const gchar **names,
11093 const gchar **values,
11094 gpointer user_data,
11099 guint modifiers = 0;
11100 gchar *signal = NULL;
11101 AccelGroupParserData *parser_data = (AccelGroupParserData*)user_data;
11103 for (i = 0; names[i]; i++)
11105 if (strcmp (names[i], "key") == 0)
11106 key = gdk_keyval_from_name (values[i]);
11107 else if (strcmp (names[i], "modifiers") == 0)
11109 if (!_gtk_builder_flags_from_string (GDK_TYPE_MODIFIER_TYPE,
11115 else if (strcmp (names[i], "signal") == 0)
11116 signal = g_strdup (values[i]);
11119 if (key == 0 || signal == NULL)
11121 g_warning ("<accelerator> requires key and signal attributes");
11124 parser_data->key = key;
11125 parser_data->modifiers = modifiers;
11126 parser_data->signal = signal;
11129 static const GMarkupParser accel_group_parser =
11131 accel_group_start_element,
11135 gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
11136 GtkBuilder *builder,
11138 const gchar *tagname,
11139 GMarkupParser *parser,
11142 g_assert (buildable);
11144 if (strcmp (tagname, "accelerator") == 0)
11146 AccelGroupParserData *parser_data;
11148 parser_data = g_slice_new0 (AccelGroupParserData);
11149 parser_data->object = g_object_ref (buildable);
11150 *parser = accel_group_parser;
11151 *data = parser_data;
11154 if (strcmp (tagname, "accessibility") == 0)
11156 AccessibilitySubParserData *parser_data;
11158 parser_data = g_slice_new0 (AccessibilitySubParserData);
11159 *parser = accessibility_parser;
11160 *data = parser_data;
11167 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
11168 GtkWidget *toplevel,
11169 gpointer user_data)
11171 AccelGroupParserData *accel_data;
11172 GSList *accel_groups;
11173 GtkAccelGroup *accel_group;
11175 g_return_if_fail (GTK_IS_WIDGET (widget));
11176 g_return_if_fail (GTK_IS_WIDGET (toplevel));
11177 g_return_if_fail (user_data != NULL);
11179 accel_data = (AccelGroupParserData*)user_data;
11180 accel_groups = gtk_accel_groups_from_object (G_OBJECT (toplevel));
11181 if (g_slist_length (accel_groups) == 0)
11183 accel_group = gtk_accel_group_new ();
11184 gtk_window_add_accel_group (GTK_WINDOW (toplevel), accel_group);
11188 g_assert (g_slist_length (accel_groups) == 1);
11189 accel_group = g_slist_nth_data (accel_groups, 0);
11192 gtk_widget_add_accelerator (GTK_WIDGET (accel_data->object),
11193 accel_data->signal,
11196 accel_data->modifiers,
11197 GTK_ACCEL_VISIBLE);
11199 g_object_unref (accel_data->object);
11200 g_free (accel_data->signal);
11201 g_slice_free (AccelGroupParserData, accel_data);
11205 gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
11206 GtkBuilder *builder,
11208 const gchar *tagname,
11209 gpointer user_data)
11211 AccelGroupParserData *accel_data;
11212 AccessibilitySubParserData *a11y_data;
11213 GtkWidget *toplevel;
11215 if (strcmp (tagname, "accelerator") == 0)
11217 accel_data = (AccelGroupParserData*)user_data;
11218 g_assert (accel_data->object);
11220 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (accel_data->object));
11222 _gtk_widget_buildable_finish_accelerator (GTK_WIDGET (buildable), toplevel, user_data);
11224 else if (strcmp (tagname, "accessibility") == 0)
11226 a11y_data = (AccessibilitySubParserData*)user_data;
11228 if (a11y_data->actions)
11230 AtkObject *accessible;
11235 accessible = gtk_widget_get_accessible (GTK_WIDGET (buildable));
11237 action = ATK_ACTION (accessible);
11238 n_actions = atk_action_get_n_actions (action);
11240 for (l = a11y_data->actions; l; l = l->next)
11242 AtkActionData *action_data = (AtkActionData*)l->data;
11244 for (i = 0; i < n_actions; i++)
11245 if (strcmp (atk_action_get_name (action, i),
11246 action_data->action_name) == 0)
11251 gchar *description;
11253 if (action_data->translatable && action_data->description->len)
11254 description = _gtk_builder_parser_translate (gtk_builder_get_translation_domain (builder),
11255 action_data->context,
11256 action_data->description->str);
11258 description = action_data->description->str;
11260 atk_action_set_description (action, i, description);
11264 g_slist_foreach (a11y_data->actions, (GFunc)free_action, NULL);
11265 g_slist_free (a11y_data->actions);
11268 if (a11y_data->relations)
11269 g_object_set_qdata (G_OBJECT (buildable), quark_builder_atk_relations,
11270 a11y_data->relations);
11272 g_slice_free (AccessibilitySubParserData, a11y_data);
11277 gtk_widget_real_get_width (GtkWidget *widget,
11278 gint *minimum_size,
11279 gint *natural_size)
11289 gtk_widget_real_get_height (GtkWidget *widget,
11290 gint *minimum_size,
11291 gint *natural_size)
11301 gtk_widget_real_get_height_for_width (GtkWidget *widget,
11303 gint *minimum_height,
11304 gint *natural_height)
11306 GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, minimum_height, natural_height);
11310 gtk_widget_real_get_width_for_height (GtkWidget *widget,
11312 gint *minimum_width,
11313 gint *natural_width)
11315 GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, minimum_width, natural_width);
11319 * gtk_widget_get_halign:
11320 * @widget: a #GtkWidget
11322 * Gets the value of the #GtkWidget:halign property.
11324 * Returns: the horizontal alignment of @widget
11327 gtk_widget_get_halign (GtkWidget *widget)
11329 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11330 return _gtk_widget_get_aux_info_or_defaults (widget)->halign;
11334 * gtk_widget_set_halign:
11335 * @widget: a #GtkWidget
11336 * @align: the horizontal alignment
11338 * Sets the horizontal alignment of @widget.
11339 * See the #GtkWidget:halign property.
11342 gtk_widget_set_halign (GtkWidget *widget,
11345 GtkWidgetAuxInfo *aux_info;
11347 g_return_if_fail (GTK_IS_WIDGET (widget));
11349 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11351 if (aux_info->halign == align)
11354 aux_info->halign = align;
11355 gtk_widget_queue_resize (widget);
11356 g_object_notify (G_OBJECT (widget), "halign");
11360 * gtk_widget_get_valign:
11361 * @widget: a #GtkWidget
11363 * Gets the value of the #GtkWidget:valign property.
11365 * Returns: the vertical alignment of @widget
11368 gtk_widget_get_valign (GtkWidget *widget)
11370 g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_ALIGN_FILL);
11371 return _gtk_widget_get_aux_info_or_defaults (widget)->valign;
11375 * gtk_widget_set_valign:
11376 * @widget: a #GtkWidget
11377 * @align: the vertical alignment
11379 * Sets the vertical alignment of @widget.
11380 * See the #GtkWidget:valign property.
11383 gtk_widget_set_valign (GtkWidget *widget,
11386 GtkWidgetAuxInfo *aux_info;
11388 g_return_if_fail (GTK_IS_WIDGET (widget));
11390 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11392 if (aux_info->valign == align)
11395 aux_info->valign = align;
11396 gtk_widget_queue_resize (widget);
11397 g_object_notify (G_OBJECT (widget), "valign");
11401 * gtk_widget_get_margin_left:
11402 * @widget: a #GtkWidget
11404 * Gets the value of the #GtkWidget:margin-left property.
11406 * Returns: The left margin of @widget
11409 gtk_widget_get_margin_left (GtkWidget *widget)
11411 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11413 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.left;
11417 * gtk_widget_set_margin_left:
11418 * @widget: a #GtkWidget
11419 * @margin: the left margin
11421 * Sets the left margin of @widget.
11422 * See the #GtkWidget:margin-left property.
11425 gtk_widget_set_margin_left (GtkWidget *widget,
11428 GtkWidgetAuxInfo *aux_info;
11430 g_return_if_fail (GTK_IS_WIDGET (widget));
11431 g_return_if_fail (margin <= G_MAXINT16);
11433 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11435 if (aux_info->margin.left == margin)
11438 aux_info->margin.left = margin;
11439 gtk_widget_queue_resize (widget);
11440 g_object_notify (G_OBJECT (widget), "margin-left");
11444 * gtk_widget_get_margin_right:
11445 * @widget: a #GtkWidget
11447 * Gets the value of the #GtkWidget:margin-right property.
11449 * Returns: The left margin of @widget
11452 gtk_widget_get_margin_right (GtkWidget *widget)
11454 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11456 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.right;
11460 * gtk_widget_set_margin_right:
11461 * @widget: a #GtkWidget
11462 * @margin: the right margin
11464 * Sets the right margin of @widget.
11465 * See the #GtkWidget:margin-right property.
11468 gtk_widget_set_margin_right (GtkWidget *widget,
11471 GtkWidgetAuxInfo *aux_info;
11473 g_return_if_fail (GTK_IS_WIDGET (widget));
11474 g_return_if_fail (margin <= G_MAXINT16);
11476 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11478 if (aux_info->margin.right == margin)
11481 aux_info->margin.right = margin;
11482 gtk_widget_queue_resize (widget);
11483 g_object_notify (G_OBJECT (widget), "margin-right");
11487 * gtk_widget_get_margin_top:
11488 * @widget: a #GtkWidget
11490 * Gets the value of the #GtkWidget:margin-top property.
11492 * Returns: The top margin of @widget
11495 gtk_widget_get_margin_top (GtkWidget *widget)
11497 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11499 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.top;
11503 * gtk_widget_set_margin_top:
11504 * @widget: a #GtkWidget
11505 * @margin: the top margin
11507 * Sets the top margin of @widget.
11508 * See the #GtkWidget:margin-top property.
11511 gtk_widget_set_margin_top (GtkWidget *widget,
11514 GtkWidgetAuxInfo *aux_info;
11516 g_return_if_fail (GTK_IS_WIDGET (widget));
11517 g_return_if_fail (margin <= G_MAXINT16);
11519 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11521 if (aux_info->margin.top == margin)
11524 aux_info->margin.top = margin;
11525 gtk_widget_queue_resize (widget);
11526 g_object_notify (G_OBJECT (widget), "margin-top");
11530 * gtk_widget_get_margin_bottom:
11531 * @widget: a #GtkWidget
11533 * Gets the value of the #GtkWidget:margin-bottom property.
11535 * Returns: The bottom margin of @widget
11538 gtk_widget_get_margin_bottom (GtkWidget *widget)
11540 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
11542 return _gtk_widget_get_aux_info_or_defaults (widget)->margin.bottom;
11546 * gtk_widget_set_margin_bottom:
11547 * @widget: a #GtkWidget
11548 * @margin: the bottom margin
11550 * Sets the bottom margin of @widget.
11551 * See the #GtkWidget:margin-bottom property.
11554 gtk_widget_set_margin_bottom (GtkWidget *widget,
11557 GtkWidgetAuxInfo *aux_info;
11559 g_return_if_fail (GTK_IS_WIDGET (widget));
11560 g_return_if_fail (margin <= G_MAXINT16);
11562 aux_info = _gtk_widget_get_aux_info (widget, TRUE);
11564 if (aux_info->margin.bottom == margin)
11567 aux_info->margin.bottom = margin;
11568 gtk_widget_queue_resize (widget);
11569 g_object_notify (G_OBJECT (widget), "margin-bottom");
11573 * gtk_widget_get_clipboard:
11574 * @widget: a #GtkWidget
11575 * @selection: a #GdkAtom which identifies the clipboard
11576 * to use. %GDK_SELECTION_CLIPBOARD gives the
11577 * default clipboard. Another common value
11578 * is %GDK_SELECTION_PRIMARY, which gives
11579 * the primary X selection.
11581 * Returns the clipboard object for the given selection to
11582 * be used with @widget. @widget must have a #GdkDisplay
11583 * associated with it, so must be attached to a toplevel
11586 * Return value: (transfer none): the appropriate clipboard object. If no
11587 * clipboard already exists, a new one will
11588 * be created. Once a clipboard object has
11589 * been created, it is persistent for all time.
11594 gtk_widget_get_clipboard (GtkWidget *widget, GdkAtom selection)
11596 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11597 g_return_val_if_fail (gtk_widget_has_screen (widget), NULL);
11599 return gtk_clipboard_get_for_display (gtk_widget_get_display (widget),
11604 * gtk_widget_list_mnemonic_labels:
11605 * @widget: a #GtkWidget
11607 * Returns a newly allocated list of the widgets, normally labels, for
11608 * which this widget is the target of a mnemonic (see for example,
11609 * gtk_label_set_mnemonic_widget()).
11611 * The widgets in the list are not individually referenced. If you
11612 * want to iterate through the list and perform actions involving
11613 * callbacks that might destroy the widgets, you
11614 * <emphasis>must</emphasis> call <literal>g_list_foreach (result,
11615 * (GFunc)g_object_ref, NULL)</literal> first, and then unref all the
11616 * widgets afterwards.
11618 * Return value: (element-type GtkWidget) (transfer container): the list of
11619 * mnemonic labels; free this list
11620 * with g_list_free() when you are done with it.
11625 gtk_widget_list_mnemonic_labels (GtkWidget *widget)
11627 GList *list = NULL;
11630 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11632 for (l = g_object_get_qdata (G_OBJECT (widget), quark_mnemonic_labels); l; l = l->next)
11633 list = g_list_prepend (list, l->data);
11639 * gtk_widget_add_mnemonic_label:
11640 * @widget: a #GtkWidget
11641 * @label: a #GtkWidget that acts as a mnemonic label for @widget
11643 * Adds a widget to the list of mnemonic labels for
11644 * this widget. (See gtk_widget_list_mnemonic_labels()). Note the
11645 * list of mnemonic labels for the widget is cleared when the
11646 * widget is destroyed, so the caller must make sure to update
11647 * its internal state at this point as well, by using a connection
11648 * to the #GtkWidget::destroy signal or a weak notifier.
11653 gtk_widget_add_mnemonic_label (GtkWidget *widget,
11656 GSList *old_list, *new_list;
11658 g_return_if_fail (GTK_IS_WIDGET (widget));
11659 g_return_if_fail (GTK_IS_WIDGET (label));
11661 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11662 new_list = g_slist_prepend (old_list, label);
11664 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11665 new_list, (GDestroyNotify) g_slist_free);
11669 * gtk_widget_remove_mnemonic_label:
11670 * @widget: a #GtkWidget
11671 * @label: a #GtkWidget that was previously set as a mnemnic label for
11672 * @widget with gtk_widget_add_mnemonic_label().
11674 * Removes a widget from the list of mnemonic labels for
11675 * this widget. (See gtk_widget_list_mnemonic_labels()). The widget
11676 * must have previously been added to the list with
11677 * gtk_widget_add_mnemonic_label().
11682 gtk_widget_remove_mnemonic_label (GtkWidget *widget,
11685 GSList *old_list, *new_list;
11687 g_return_if_fail (GTK_IS_WIDGET (widget));
11688 g_return_if_fail (GTK_IS_WIDGET (label));
11690 old_list = g_object_steal_qdata (G_OBJECT (widget), quark_mnemonic_labels);
11691 new_list = g_slist_remove (old_list, label);
11694 g_object_set_qdata_full (G_OBJECT (widget), quark_mnemonic_labels,
11695 new_list, (GDestroyNotify) g_slist_free);
11699 * gtk_widget_get_no_show_all:
11700 * @widget: a #GtkWidget
11702 * Returns the current value of the GtkWidget:no-show-all property,
11703 * which determines whether calls to gtk_widget_show_all() and
11704 * gtk_widget_hide_all() will affect this widget.
11706 * Return value: the current value of the "no-show-all" property.
11711 gtk_widget_get_no_show_all (GtkWidget *widget)
11713 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11715 return (GTK_OBJECT_FLAGS (widget) & GTK_NO_SHOW_ALL) != 0;
11719 * gtk_widget_set_no_show_all:
11720 * @widget: a #GtkWidget
11721 * @no_show_all: the new value for the "no-show-all" property
11723 * Sets the #GtkWidget:no-show-all property, which determines whether
11724 * calls to gtk_widget_show_all() and gtk_widget_hide_all() will affect
11727 * This is mostly for use in constructing widget hierarchies with externally
11728 * controlled visibility, see #GtkUIManager.
11733 gtk_widget_set_no_show_all (GtkWidget *widget,
11734 gboolean no_show_all)
11736 g_return_if_fail (GTK_IS_WIDGET (widget));
11738 no_show_all = (no_show_all != FALSE);
11740 if (no_show_all == gtk_widget_get_no_show_all (widget))
11744 GTK_OBJECT_FLAGS (widget) |= GTK_NO_SHOW_ALL;
11746 GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_SHOW_ALL);
11748 g_object_notify (G_OBJECT (widget), "no-show-all");
11753 gtk_widget_real_set_has_tooltip (GtkWidget *widget,
11754 gboolean has_tooltip,
11757 GtkWidgetPrivate *priv = widget->priv;
11758 gboolean priv_has_tooltip;
11760 priv_has_tooltip = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (widget),
11761 quark_has_tooltip));
11763 if (priv_has_tooltip != has_tooltip || force)
11765 priv_has_tooltip = has_tooltip;
11767 if (priv_has_tooltip)
11769 if (gtk_widget_get_realized (widget) && !gtk_widget_get_has_window (widget))
11770 gdk_window_set_events (priv->window,
11771 gdk_window_get_events (priv->window) |
11772 GDK_LEAVE_NOTIFY_MASK |
11773 GDK_POINTER_MOTION_MASK |
11774 GDK_POINTER_MOTION_HINT_MASK);
11776 if (gtk_widget_get_has_window (widget))
11777 gtk_widget_add_events (widget,
11778 GDK_LEAVE_NOTIFY_MASK |
11779 GDK_POINTER_MOTION_MASK |
11780 GDK_POINTER_MOTION_HINT_MASK);
11783 g_object_set_qdata (G_OBJECT (widget), quark_has_tooltip,
11784 GUINT_TO_POINTER (priv_has_tooltip));
11789 * gtk_widget_set_tooltip_window:
11790 * @widget: a #GtkWidget
11791 * @custom_window: (allow-none): a #GtkWindow, or %NULL
11793 * Replaces the default, usually yellow, window used for displaying
11794 * tooltips with @custom_window. GTK+ will take care of showing and
11795 * hiding @custom_window at the right moment, to behave likewise as
11796 * the default tooltip window. If @custom_window is %NULL, the default
11797 * tooltip window will be used.
11799 * If the custom window should have the default theming it needs to
11800 * have the name "gtk-tooltip", see gtk_widget_set_name().
11805 gtk_widget_set_tooltip_window (GtkWidget *widget,
11806 GtkWindow *custom_window)
11808 gboolean has_tooltip;
11809 gchar *tooltip_markup;
11811 g_return_if_fail (GTK_IS_WIDGET (widget));
11812 g_return_if_fail (custom_window == NULL || GTK_IS_WINDOW (custom_window));
11814 tooltip_markup = g_object_get_qdata (G_OBJECT (widget), quark_tooltip_markup);
11817 g_object_ref (custom_window);
11819 g_object_set_qdata_full (G_OBJECT (widget), quark_tooltip_window,
11820 custom_window, g_object_unref);
11822 has_tooltip = (custom_window != NULL || tooltip_markup != NULL);
11823 gtk_widget_real_set_has_tooltip (widget, has_tooltip, FALSE);
11825 if (has_tooltip && gtk_widget_get_visible (widget))
11826 gtk_widget_queue_tooltip_query (widget);
11830 * gtk_widget_get_tooltip_window:
11831 * @widget: a #GtkWidget
11833 * Returns the #GtkWindow of the current tooltip. This can be the
11834 * GtkWindow created by default, or the custom tooltip window set
11835 * using gtk_widget_set_tooltip_window().
11837 * Return value: (transfer none): The #GtkWindow of the current tooltip.
11842 gtk_widget_get_tooltip_window (GtkWidget *widget)
11844 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11846 return g_object_get_qdata (G_OBJECT (widget), quark_tooltip_window);
11850 * gtk_widget_trigger_tooltip_query:
11851 * @widget: a #GtkWidget
11853 * Triggers a tooltip query on the display where the toplevel of @widget
11854 * is located. See gtk_tooltip_trigger_tooltip_query() for more
11860 gtk_widget_trigger_tooltip_query (GtkWidget *widget)
11862 gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
11865 static guint tooltip_query_id;
11866 static GSList *tooltip_query_displays;
11869 tooltip_query_idle (gpointer data)
11871 g_slist_foreach (tooltip_query_displays, (GFunc)gtk_tooltip_trigger_tooltip_query, NULL);
11872 g_slist_foreach (tooltip_query_displays, (GFunc)g_object_unref, NULL);
11873 g_slist_free (tooltip_query_displays);
11875 tooltip_query_displays = NULL;
11876 tooltip_query_id = 0;
11882 gtk_widget_queue_tooltip_query (GtkWidget *widget)
11884 GdkDisplay *display;
11886 display = gtk_widget_get_display (widget);
11888 if (!g_slist_find (tooltip_query_displays, display))
11889 tooltip_query_displays = g_slist_prepend (tooltip_query_displays, g_object_ref (display));
11891 if (tooltip_query_id == 0)
11892 tooltip_query_id = gdk_threads_add_idle (tooltip_query_idle, NULL);
11896 * gtk_widget_set_tooltip_text:
11897 * @widget: a #GtkWidget
11898 * @text: the contents of the tooltip for @widget
11900 * Sets @text as the contents of the tooltip. This function will take
11901 * care of setting GtkWidget:has-tooltip to %TRUE and of the default
11902 * handler for the GtkWidget::query-tooltip signal.
11904 * See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
11909 gtk_widget_set_tooltip_text (GtkWidget *widget,
11912 g_return_if_fail (GTK_IS_WIDGET (widget));
11914 g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
11918 * gtk_widget_get_tooltip_text:
11919 * @widget: a #GtkWidget
11921 * Gets the contents of the tooltip for @widget.
11923 * Return value: the tooltip text, or %NULL. You should free the
11924 * returned string with g_free() when done.
11929 gtk_widget_get_tooltip_text (GtkWidget *widget)
11931 gchar *text = NULL;
11933 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11935 g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
11941 * gtk_widget_set_tooltip_markup:
11942 * @widget: a #GtkWidget
11943 * @markup: (allow-none): the contents of the tooltip for @widget, or %NULL
11945 * Sets @markup as the contents of the tooltip, which is marked up with
11946 * the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
11948 * This function will take care of setting GtkWidget:has-tooltip to %TRUE
11949 * and of the default handler for the GtkWidget::query-tooltip signal.
11951 * See also the GtkWidget:tooltip-markup property and
11952 * gtk_tooltip_set_markup().
11957 gtk_widget_set_tooltip_markup (GtkWidget *widget,
11958 const gchar *markup)
11960 g_return_if_fail (GTK_IS_WIDGET (widget));
11962 g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
11966 * gtk_widget_get_tooltip_markup:
11967 * @widget: a #GtkWidget
11969 * Gets the contents of the tooltip for @widget.
11971 * Return value: the tooltip text, or %NULL. You should free the
11972 * returned string with g_free() when done.
11977 gtk_widget_get_tooltip_markup (GtkWidget *widget)
11979 gchar *text = NULL;
11981 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
11983 g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
11989 * gtk_widget_set_has_tooltip:
11990 * @widget: a #GtkWidget
11991 * @has_tooltip: whether or not @widget has a tooltip.
11993 * Sets the has-tooltip property on @widget to @has_tooltip. See
11994 * GtkWidget:has-tooltip for more information.
11999 gtk_widget_set_has_tooltip (GtkWidget *widget,
12000 gboolean has_tooltip)
12002 g_return_if_fail (GTK_IS_WIDGET (widget));
12004 g_object_set (G_OBJECT (widget), "has-tooltip", has_tooltip, NULL);
12008 * gtk_widget_get_has_tooltip:
12009 * @widget: a #GtkWidget
12011 * Returns the current value of the has-tooltip property. See
12012 * GtkWidget:has-tooltip for more information.
12014 * Return value: current value of has-tooltip on @widget.
12019 gtk_widget_get_has_tooltip (GtkWidget *widget)
12021 gboolean has_tooltip = FALSE;
12023 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12025 g_object_get (G_OBJECT (widget), "has-tooltip", &has_tooltip, NULL);
12027 return has_tooltip;
12031 * gtk_widget_get_allocation:
12032 * @widget: a #GtkWidget
12033 * @allocation: (out): a pointer to a #GtkAllocation to copy to
12035 * Retrieves the widget's allocation.
12037 * Note, when implementing a #GtkContainer: a widget's allocation will
12038 * be its "adjusted" allocation, that is, the widget's parent
12039 * container typically calls gtk_widget_size_allocate() with an
12040 * allocation, and that allocation is then adjusted (to handle margin
12041 * and alignment for example) before assignment to the widget.
12042 * gtk_widget_get_allocation() returns the adjusted allocation that
12043 * was actually assigned to the widget. The adjusted allocation is
12044 * guaranteed to be completely contained within the
12045 * gtk_widget_size_allocate() allocation, however. So a #GtkContainer
12046 * is guaranteed that its children stay inside the assigned bounds,
12047 * but not that they have exactly the bounds the container assigned.
12048 * There is no way to get the original allocation assigned by
12049 * gtk_widget_size_allocate(), since it isn't stored; if a container
12050 * implementation needs that information it will have to track it itself.
12055 gtk_widget_get_allocation (GtkWidget *widget,
12056 GtkAllocation *allocation)
12058 GtkWidgetPrivate *priv;
12060 g_return_if_fail (GTK_IS_WIDGET (widget));
12061 g_return_if_fail (allocation != NULL);
12063 priv = widget->priv;
12065 *allocation = priv->allocation;
12069 * gtk_widget_set_allocation:
12070 * @widget: a #GtkWidget
12071 * @allocation: a pointer to a #GtkAllocation to copy from
12073 * Sets the widget's allocation. This should not be used
12074 * directly, but from within a widget's size_allocate method.
12076 * The allocation set should be the "adjusted" or actual
12077 * allocation. If you're implementing a #GtkContainer, you want to use
12078 * gtk_widget_size_allocate() instead of gtk_widget_set_allocation().
12079 * The GtkWidgetClass::adjust_size_allocation virtual method adjusts the
12080 * allocation inside gtk_widget_size_allocate() to create an adjusted
12086 gtk_widget_set_allocation (GtkWidget *widget,
12087 const GtkAllocation *allocation)
12089 GtkWidgetPrivate *priv;
12091 g_return_if_fail (GTK_IS_WIDGET (widget));
12092 g_return_if_fail (allocation != NULL);
12094 priv = widget->priv;
12096 priv->allocation = *allocation;
12100 * gtk_widget_get_allocated_width:
12101 * @widget: the widget to query
12103 * Returns the width that has currently been allocated to @widget.
12104 * This function is intended to be used when implementing handlers
12105 * for the GtkWidget::draw function.
12107 * Returns: the width of the @widget
12110 gtk_widget_get_allocated_width (GtkWidget *widget)
12112 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12114 return widget->priv->allocation.width;
12118 * gtk_widget_get_allocated_height:
12119 * @widget: the widget to query
12121 * Returns the height that has currently been allocated to @widget.
12122 * This function is intended to be used when implementing handlers
12123 * for the GtkWidget::draw function.
12125 * Returns: the height of the @widget
12128 gtk_widget_get_allocated_height (GtkWidget *widget)
12130 g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
12132 return widget->priv->allocation.height;
12136 * gtk_widget_get_requisition:
12137 * @widget: a #GtkWidget
12138 * @requisition: (out): a pointer to a #GtkRequisition to copy to
12140 * Retrieves the widget's requisition.
12142 * This function should only be used by widget implementations in
12143 * order to figure whether the widget's requisition has actually
12144 * changed after some internal state change (so that they can call
12145 * gtk_widget_queue_resize() instead of gtk_widget_queue_draw()).
12147 * Normally, gtk_widget_size_request() should be used.
12151 * Deprecated: 3.0: The #GtkRequisition cache on the widget was
12152 * removed, If you need to cache sizes across requests and allocations,
12153 * add an explicit cache to the widget in question instead.
12156 gtk_widget_get_requisition (GtkWidget *widget,
12157 GtkRequisition *requisition)
12159 g_return_if_fail (GTK_IS_WIDGET (widget));
12160 g_return_if_fail (requisition != NULL);
12162 gtk_widget_get_preferred_size (widget, requisition, NULL);
12166 * gtk_widget_set_window:
12167 * @widget: a #GtkWidget
12168 * @window: a #GdkWindow
12170 * Sets a widget's window. This function should only be used in a
12171 * widget's GtkWidget::realize() implementation. The %window passed is
12172 * usually either new window created with gdk_window_new(), or the
12173 * window of its parent widget as returned by
12174 * gtk_widget_get_parent_window().
12176 * Widgets must indicate whether they will create their own #GdkWindow
12177 * by calling gtk_widget_set_has_window(). This is usually done in the
12178 * widget's init() function.
12180 * <note><para>This function does not add any reference to @window.</para></note>
12185 gtk_widget_set_window (GtkWidget *widget,
12188 GtkWidgetPrivate *priv;
12190 g_return_if_fail (GTK_IS_WIDGET (widget));
12191 g_return_if_fail (window == NULL || GDK_IS_WINDOW (window));
12193 priv = widget->priv;
12195 if (priv->window != window)
12197 priv->window = window;
12198 g_object_notify (G_OBJECT (widget), "window");
12203 * gtk_widget_get_window:
12204 * @widget: a #GtkWidget
12206 * Returns the widget's window if it is realized, %NULL otherwise
12208 * Return value: (transfer none): @widget's window.
12213 gtk_widget_get_window (GtkWidget *widget)
12215 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
12217 return widget->priv->window;
12221 * gtk_widget_get_support_multidevice:
12222 * @widget: a #GtkWidget
12224 * Returns %TRUE if @widget is multiple pointer aware. See
12225 * gtk_widget_set_support_multidevice() for more information.
12227 * Returns: %TRUE is @widget is multidevice aware.
12230 gtk_widget_get_support_multidevice (GtkWidget *widget)
12232 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12234 return GTK_WIDGET_FLAGS (widget) & GTK_MULTIDEVICE;
12238 * gtk_widget_set_support_multidevice:
12239 * @widget: a #GtkWidget
12240 * @support_multidevice: %TRUE to support input from multiple devices.
12242 * Enables or disables multiple pointer awareness. If this setting is %TRUE,
12243 * @widget will start receiving multiple, per device enter/leave events. Note
12244 * that if custom #GdkWindow<!-- -->s are created in #GtkWidget::realize,
12245 * gdk_window_set_support_multidevice() will have to be called manually on them.
12250 gtk_widget_set_support_multidevice (GtkWidget *widget,
12251 gboolean support_multidevice)
12253 GtkWidgetPrivate *priv;
12255 g_return_if_fail (GTK_IS_WIDGET (widget));
12257 priv = widget->priv;
12259 if (support_multidevice)
12261 GTK_WIDGET_SET_FLAGS (widget, GTK_MULTIDEVICE);
12262 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_ALL);
12266 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MULTIDEVICE);
12267 gtk_widget_set_extension_events (widget, GDK_EXTENSION_EVENTS_NONE);
12270 if (gtk_widget_get_realized (widget))
12271 gdk_window_set_support_multidevice (priv->window, support_multidevice);
12275 _gtk_widget_set_has_focus (GtkWidget *widget,
12276 gboolean has_focus)
12279 GTK_OBJECT_FLAGS (widget) |= GTK_HAS_FOCUS;
12281 GTK_OBJECT_FLAGS (widget) &= ~(GTK_HAS_FOCUS);
12285 * gtk_widget_send_focus_change:
12286 * @widget: a #GtkWidget
12287 * @event: a #GdkEvent of type GDK_FOCUS_CHANGE
12289 * Sends the focus change @event to @widget
12291 * This function is not meant to be used by applications. The only time it
12292 * should be used is when it is necessary for a #GtkWidget to assign focus
12293 * to a widget that is semantically owned by the first widget even though
12294 * it's not a direct child - for instance, a search entry in a floating
12295 * window similar to the quick search in #GtkTreeView.
12297 * An example of its usage is:
12300 * GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
12302 * fevent->focus_change.type = GDK_FOCUS_CHANGE;
12303 * fevent->focus_change.in = TRUE;
12304 * fevent->focus_change.window = gtk_widget_get_window (widget);
12305 * if (fevent->focus_change.window != NULL)
12306 * g_object_ref (fevent->focus_change.window);
12308 * gtk_widget_send_focus_change (widget, fevent);
12310 * gdk_event_free (event);
12313 * Return value: the return value from the event signal emission: %TRUE
12314 * if the event was handled, and %FALSE otherwise
12319 gtk_widget_send_focus_change (GtkWidget *widget,
12324 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12325 g_return_val_if_fail (event != NULL && event->type == GDK_FOCUS_CHANGE, FALSE);
12327 g_object_ref (widget);
12329 _gtk_widget_set_has_focus (widget, event->focus_change.in);
12331 res = gtk_widget_event (widget, event);
12333 g_object_notify (G_OBJECT (widget), "has-focus");
12335 g_object_unref (widget);